Ticket #617: pluginCache.diff

File pluginCache.diff, 5.6 kB (added by hadrien, 5 months ago)

Voilà un diff. Je sais pas si j'ai mis les fichiers au bon endroit, mais je sais pas quoi faire de plus sans de plus amples informations… :/

  • lib/jelix-modules/jcache/module.xml

    old new  
     1<?xml version="1.0" encoding="UTF-8"?> 
     2<module xmlns="http://jelix.org/ns/module/1.0"> 
     3</module> 
  • lib/jelix-modules/jcache/controllers/default.classic.php

    old new  
     1<?php 
     2/** 
     3 * @package 
     4 * @subpackage  
     5 * @author 
     6 * @copyright 
     7 * @link 
     8 * @licence  http://www.gnu.org/licenses/gpl.html GNU General Public Licence, see LICENCE file 
     9*/ 
     10 
     11class defaultCtrl extends jController 
     12{ 
     13        /** 
     14         * 
     15         */ 
     16        public function index() 
     17        { 
     18                $this->_rep = $this->getResponse('html'); 
     19                 
     20                return $this->_rep; 
     21        } 
     22} 
     23?> 
  • lib/jelix-modules/jcache/install/var/cache.plugin.ini.php

    old new  
     1;<?php die(''); ?> 
     2;for security reasons , don't remove or modify the first line 
     3 
     4;============= Main parameters 
     5 
     6; Activate cache (deactivate on dev mode) 
     7cache = on 
     8 
     9; Path parameter from app temp folder  
     10;path = "cache" 
  • lib/jelix-modules/jcache/classes/jCache.class.php

    old new  
     1<?php 
     2/** 
     3* jCache : interact with cache plugin 
     4*/ 
     5class jCache 
     6{ 
     7        /** 
     8         * Clean cache for a particular selector 
     9         * 
     10         * @return boolean 
     11         * @author Hadrien 
     12         **/ 
     13        static function clean($actSel) 
     14        { 
     15                global $gJCoord; 
     16                 
     17                if (!isset($gJCoord->plugins['cache'])) 
     18                { 
     19                        return false; 
     20                } 
     21                 
     22                $sel = new jSelectorAct( 
     23                        $actSel, 
     24                        true 
     25                ); 
     26                 
     27                jFile::removeDir( 
     28                        $gJCoord->plugins['cache']->path . 
     29                        $sel->module . '/' . 
     30                                $sel->controller . '_' . 
     31                                $sel->method 
     32                ); 
     33                 
     34                return true; 
     35        } 
     36} 
  • lib/jelix-plugins/coord/cache/cache.coord.php

    old new  
     1<?php 
     2/** 
     3* @package    jelix 
     4* @subpackage coord_plugin 
     5* @author     Hadrien Lanneau (contact at hadrien dot eu) 
     6* @copyright  2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau, 2007 Frédéric Guillot, 2007 Antoine Detante 
     7* @copyright  2008 Hadrien.eu 
     8* 
     9* This class was get originally from an experimental branch of the Copix project 
     10* (PluginAuth, Copix 2.3dev20050901, http://www.copix.org) 
     11* Few lines of code are still copyrighted 2001-2005 CopixTeam (LGPL licence). 
     12* Initial authors of this Copix classes are Gerald Croes and Laurent Jouanneau, 
     13* and this class was adapted for Jelix by Laurent Jouanneau 
     14* 
     15* @licence  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 
     16*/ 
     17class CacheCoordPlugin implements jICoordPlugin 
     18{ 
     19        /** 
     20         * Activate cache 
     21         * 
     22         * @var boolean 
     23         **/ 
     24        public $activated = false; 
     25        /** 
     26         * time expiration (in milliseconds) 
     27         * 
     28         * @var Integer 
     29         **/ 
     30        private $_expires; 
     31         
     32        /** 
     33         * Cache filename 
     34         * 
     35         * @var string 
     36         **/ 
     37        private $_fileKey; 
     38         
     39        /** 
     40         * Cache folder path 
     41         * 
     42         * @var string 
     43         **/ 
     44        public $path; 
     45         
     46        /** 
     47         * path into cache folder 
     48         * 
     49         * @var string 
     50         **/ 
     51        private $_localPath; 
     52         
     53         
     54        public function __construct($config) 
     55        { 
     56                if (isset($config['cache']) and 
     57                        $config['cache'] == 1) 
     58                { 
     59                        $this->activated = true; 
     60                         
     61                        if (isset($config['path'])) 
     62                        { 
     63                                $this->path = JELIX_APP_TEMP_PATH . 
     64                                        $config['path'] . 
     65                                        DIRECTORY_SEPARATOR; 
     66                        } 
     67                        else 
     68                        { 
     69                                $this->path = JELIX_APP_TEMP_PATH . 'cache/'; 
     70                        } 
     71                } 
     72        } 
     73         
     74        /** 
     75         * Get request params and check file cached 
     76         * @param {array} $params Params array 
     77         * @return void 
     78         **/ 
     79        public function beforeAction($params) 
     80        { 
     81                // Check if cache is activated and if this request ask for cache 
     82                if ($this->activated and 
     83                        isset($params['cache.expires'])) 
     84                { 
     85                        global $gJCoord; 
     86                        // create a path from module/action 
     87                        $this->_localPath .=  
     88                                $gJCoord->request->params['module'] . '/' . 
     89                                str_replace( 
     90                                        ':', 
     91                                        '_', 
     92                                        $gJCoord->request->params['action'] 
     93                                ) . '/'; 
     94                         
     95                        jFile::createDir( 
     96                                $this->path . 
     97                                $this->_localPath 
     98                        ); 
     99                         
     100                        // get md5 key from get params 
     101                        $this->_fileKey = md5( 
     102                                serialize( 
     103                                        $gJCoord->request->params 
     104                                ) 
     105                        ); 
     106                         
     107                        // Test file time 
     108                        $this->_expires = $params['cache.expires']; 
     109                        if (@filemtime( 
     110                                        $this->path . 
     111                                        $this->_localPath . 
     112                                        $this->_fileKey 
     113                                ) < time() - $this->_expires) 
     114                        { 
     115                                // Start cache 
     116                                ob_start(); 
     117                        } 
     118                        else 
     119                        { 
     120                                // Include cached file 
     121                                include( 
     122                                        $this->path . 
     123                                        $this->_localPath . 
     124                                        $this->_fileKey 
     125                                ); 
     126                                exit(); 
     127                        } 
     128                } 
     129        } 
     130        public function beforeOutput() 
     131        { 
     132                 
     133        } 
     134        public function afterProcess() 
     135        { 
     136                if ($this->activated and 
     137                        $this->_expires) 
     138                { 
     139                        // end cache 
     140                        $cache = ob_get_contents(); 
     141                        ob_end_flush(); 
     142                         
     143                        // Write in file 
     144                        jFile::write( 
     145                                $this->path . 
     146                                        $this->_localPath . 
     147                                        $this->_fileKey, 
     148                                $cache 
     149                        ); 
     150                } 
     151        } 
     152} 
Download in other formats: Original Format