developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #507: history.2.diff

File history.2.diff, 5.8 KB (added by Lipki, 13 years ago)
  • build/manifests/jelix-lib.mn

     
    444444  plugin.xml
    445445  jacl2.coord.ini.php.dist
    446446
     447cd lib/jelix/plugins/coord/history
     448! history.coord.php
     449  plugin.xml
     450  history.coord.ini.php.dist
     451
    447452cd lib/jelix/plugins/jforms/html
    448453  html.jformscompiler.php
    449454  html.jformsbuilder.php
  • lib/jelix/plugins/coord/history/history.coord.ini.php.dist

     
     1;<?php die(''); ?>
     2;for security reasons , don't remove or modify the first line
     3
     4;============ Parameters for the plugin
     5; session variable name
     6session_name = "HISTORY"
     7
     8; max size of the history
     9maxsize = 10
     10
     11; if single = true if each page will be registered only once in history
     12; the latter will be retained.
     13single = false
     14
     15; If double = false pages will not appear twice a follow time in history.
     16double = false
     17
     18; if time = true a variable record time spent on site
     19time = true
     20; the name of this variable
     21session_time_name = "HISTORYTIME"
     22 No newline at end of file
  • lib/jelix/plugins/coord/history/history.coord.php

     
     1<?php
     2/**
     3* @package    jelix
     4* @subpackage coord_plugin
     5* @author     Lepeltier Kévin
     6* @copyright  2008 Lepeltier Kévin
     7*
     8* The plugin History is a plugin coord,
     9* it records the action / settings made during a session and allows for reuse.
     10*
     11* @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
     12*/
     13class historyCoordPlugin implements jICoordPlugin {
     14   
     15    public $config;
     16   
     17    function __construct( $conf ){
     18        $this->config = $conf;
     19       
     20        if( $this->config['time'] && !isset($_SESSION[$this->config['session_time_name']]) )
     21            $_SESSION[$this->config['session_time_name']] = microtime(true);
     22       
     23    }
     24   
     25    public function beforeAction ($params) {
     26       
     27        if( !empty($params['history.add']) && $params['history.add'] ) {
     28            if( !isset($_SESSION[$this->config['session_name']]) )
     29                $_SESSION[$this->config['session_name']] = array();
     30           
     31            global $gJCoord;
     32            $page['params'] = $gJCoord->request->params;
     33            unset( $page['params']['module'] );
     34            unset( $page['params']['action'] );
     35           
     36            $page['action'] = $gJCoord->action->toString();
     37            $page['label'] = ( !empty($params['history.label']) )? $params['history.label']:'';
     38            $page['title'] = ( !empty($params['history.title']) )? $params['history.title']:'';
     39           
     40            if( !count($_SESSION[$this->config['session_name']]) ) {
     41                $_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'] )
     44                    foreach( $_SESSION[$this->config['session_name']] as $key=>$valu ) if( $valu == $page )
     45                        array_splice( $_SESSION[$this->config['session_name']], $key, 1 );
     46                $_SESSION[$this->config['session_name']][] = $page;
     47            }
     48           
     49        }
     50       
     51    }
     52   
     53    public function change( $key, $val ) {
     54       
     55        $page = array_pop($_SESSION[$this->config['session_name']]);
     56        $page[$key] = $val;
     57       
     58        if( $this->config['double'] || end($_SESSION[$this->config['session_name']]) != $page ) {
     59            if( $this->config['single'] )
     60                foreach( $_SESSION[$this->config['session_name']] as $key=>$valu ) if( $valu == $page )
     61                    array_splice( $_SESSION[$this->config['session_name']], $key, 1 );
     62            $_SESSION[$this->config['session_name']][] = $page;
     63        }
     64       
     65    }
     66   
     67    public function beforeOutput(){}
     68   
     69    public function afterProcess (){}
     70   
     71    public function reload( $rep ) {
     72        $last = end($_SESSION[$this->config['session_name']]);
     73        $rep->action = $last['action'];
     74        $rep->params = $last['params'];
     75        return $rep;
     76    }
     77   
     78    public function back( $rep ) {
     79        array_pop($_SESSION[$this->config['session_name']]);
     80        $last = end($_SESSION[$this->config['session_name']]);
     81        $rep->action = $last['action'];
     82        $rep->params = $last['params'];
     83        return $rep;
     84    }
     85   
     86    public function time() {
     87        if( $this->config['time'] && isset($_SESSION[$this->config['session_time_name']]) )
     88            return microtime(true) - $_SESSION[$this->config['session_time_name']];
     89        return 0;
     90    }
     91   
     92}
     93
     94?>
     95 No newline at end of file
  • lib/jelix/plugins/coord/history/plugin.xml

     
     1<?xml version="1.0" encoding="UTF-8"?>
     2<plugin name="history">
     3   <version major="0" minor="1" status="" date="03/2008" />
     4   <author name="Lepeltier kévin" email="kevin@lepeltier.info" website="" role="creator" />
     5   <description></description>
     6   <infos />
     7</plugin>
     8 No newline at end of file