Changeset 1008
- Timestamp:
- 07/09/08 10:40:21 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jelix/plugins/coord/history/history.coord.php
r902 r1008 1 1 <?php 2 2 /** 3 * @package jelix 4 * @subpackage coord_plugin 5 * @author Lepeltier Kévin 6 * @copyright 2008 Lepeltier Kévin 3 * @package jelix 4 * @subpackage coord_plugin 5 * @author Lepeltier Kévin 6 * @contributor Dominique Papin 7 * @copyright 2008 Lepeltier Kévin, 2008 Dominique Papin 7 8 * 8 9 * The plugin History is a plugin coord, … … 12 13 */ 13 14 class historyCoordPlugin implements jICoordPlugin { 14 15 15 16 public $config; 16 17 17 18 function __construct( $conf ){ 18 19 $this->config = $conf; 19 20 20 21 if( $this->config['time'] && !isset($_SESSION[$this->config['session_time_name']]) ) 21 22 $_SESSION[$this->config['session_time_name']] = microtime(true); 22 23 23 24 } 24 25 25 26 public function beforeAction ($params) { 26 27 27 28 if( !empty($params['history.add']) && $params['history.add'] ) { 28 29 if( !isset($_SESSION[$this->config['session_name']]) ) 29 30 $_SESSION[$this->config['session_name']] = array(); 30 31 31 32 global $gJCoord; 32 33 $page['params'] = $gJCoord->request->params; 33 34 unset( $page['params']['module'] ); 34 35 unset( $page['params']['action'] ); 35 36 36 37 $page['action'] = $gJCoord->action->toString(); 37 38 $page['label'] = ( !empty($params['history.label']) )? $params['history.label']:''; 38 39 $page['title'] = ( !empty($params['history.title']) )? $params['history.title']:''; 39 40 40 41 if( !count($_SESSION[$this->config['session_name']]) ) { 41 42 $_SESSION[$this->config['session_name']][] = $page; 42 } else if ( count($_SESSION[$this->config['session_name']]) < $this->config['maxsize'] && ( $this->config['double'] || end($_SESSION[$this->config['session_name']]) != $page) ) {43 if( $this->config['single'] ) 43 } else if ( $this->config['double'] || !$this->isLast( $page['action'], $page['params'] ) ) { 44 if( $this->config['single'] ) { 44 45 foreach( $_SESSION[$this->config['session_name']] as $key=>$valu ) if( $valu == $page ) 45 46 array_splice( $_SESSION[$this->config['session_name']], $key, 1 ); 47 } 46 48 $_SESSION[$this->config['session_name']][] = $page; 47 49 } 48 50 51 if( count($_SESSION[$this->config['session_name']]) > $this->config['maxsize'] ) { 52 array_shift( $_SESSION[$this->config['session_name']] ); 53 } 49 54 } 50 55 51 56 } 52 57 58 public function isLast($action, $params = NULL) { 59 60 if (!isset($_SESSION[$this->config['session_name']])) 61 return false ; 62 63 $lastPage = end($_SESSION[$this->config['session_name']]); 64 $isLast = $action == $lastPage['action']; 65 if ( $params !== NULL ) { 66 $isLast = $isLast && $params == $lastPage['params']; 67 } 68 return $isLast; 69 } 70 71 53 72 public function change( $key, $val ) { 54 73 55 74 $page = array_pop($_SESSION[$this->config['session_name']]); 56 75 $page[$key] = $val; 57 76 58 77 if( $this->config['double'] || end($_SESSION[$this->config['session_name']]) != $page ) { 59 78 if( $this->config['single'] ) 60 foreach( $_SESSION[$this->config['session_name']] as $key=>$valu ) if( $valu== $page )79 foreach( $_SESSION[$this->config['session_name']] as $key=>$value ) if( $value == $page ) 61 80 array_splice( $_SESSION[$this->config['session_name']], $key, 1 ); 62 81 $_SESSION[$this->config['session_name']][] = $page; 63 82 } 64 83 65 84 } 66 85 67 86 public function beforeOutput(){} 68 87 69 88 public function afterProcess (){} 70 89 71 90 public function reload( $rep ) { 72 91 $last = end($_SESSION[$this->config['session_name']]); … … 75 94 return $rep; 76 95 } 77 96 78 97 public function back( $rep ) { 79 98 array_pop($_SESSION[$this->config['session_name']]); … … 83 102 return $rep; 84 103 } 85 104 86 105 public function time() { 87 106 if( $this->config['time'] && isset($_SESSION[$this->config['session_time_name']]) ) … … 89 108 return 0; 90 109 } 91 110 92 111 } 93 112
