| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: cache.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 6 * @license GNU/GPL, see LICENSE.php 7 * Joomla! is free software. This version may have been modified pursuant 8 * to the GNU General Public License, and as distributed it includes or 9 * is derivative of works licensed under the GNU General Public License or 10 * other free or open source software licenses. 11 * See COPYRIGHT.php for copyright notices and details. 12 */ 13 14 // no direct access 15 defined( '_JEXEC' ) or die( 'Restricted access' ); 16 17 jimport( 'joomla.plugin.plugin' ); 18 19 /** 20 * Joomla! Page Cache Plugin 21 * 22 * @package Joomla 23 * @subpackage System 24 */ 25 class plgSystemCache extends JPlugin 26 { 27 28 var $_cache = null; 29 30 /** 31 * Constructor 32 * 33 * For php4 compatability we must not use the __constructor as a constructor for plugins 34 * because func_get_args ( void ) returns a copy of all passed arguments NOT references. 35 * This causes problems with cross-referencing necessary for the observer design pattern. 36 * 37 * @access protected 38 * @param object $subject The object to observe 39 * @param array $config An array that holds the plugin configuration 40 * @since 1.0 41 */ 42 function plgSystemCache(& $subject, $config) 43 { 44 parent::__construct($subject, $config); 45 46 //Set the language in the class 47 $config =& JFactory::getConfig(); 48 $options = array( 49 'cachebase' => JPATH_BASE.DS.'cache', 50 'defaultgroup' => 'page', 51 'lifetime' => $this->params->get('cachetime', 15) * 60, 52 'browsercache' => $this->params->get('browsercache', false), 53 'caching' => false, 54 'language' => $config->getValue('config.language', 'en-GB') 55 ); 56 57 jimport('joomla.cache.cache'); 58 $this->_cache =& JCache::getInstance( 'page', $options ); 59 } 60 61 /** 62 * Converting the site URL to fit to the HTTP request 63 * 64 */ 65 function onAfterInitialise() 66 { 67 global $mainframe, $_PROFILER; 68 $user = &JFactory::getUser(); 69 70 if($mainframe->isAdmin() || JDEBUG) { 71 return; 72 } 73 74 if (!$user->get('aid') && $_SERVER['REQUEST_METHOD'] == 'GET') { 75 $this->_cache->setCaching(true); 76 } 77 78 $data = $this->_cache->get(); 79 80 if($data !== false) 81 { 82 // the following code searches for a token in the cached page and replaces it with the 83 // proper token. 84 $token = JUtility::getToken(); 85 $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#'; 86 $replacement = '<input type="hidden" name="'.$token.'" value="1" />'; 87 $data = preg_replace( $search, $replacement, $data ); 88 89 JResponse::setBody($data); 90 91 echo JResponse::toString($mainframe->getCfg('gzip')); 92 93 if(JDEBUG) 94 { 95 $_PROFILER->mark('afterCache'); 96 echo implode( '', $_PROFILER->getBuffer()); 97 } 98 99 $mainframe->close(); 100 } 101 } 102 103 function onAfterRender() 104 { 105 global $mainframe; 106 107 if($mainframe->isAdmin() || JDEBUG) { 108 return; 109 } 110 111 $user =& JFactory::getUser(); 112 if(!$user->get('aid')) { 113 //We need to check again here, because auto-login plugins have not been fired before the first aid check 114 $this->_cache->store(); 115 } 116 } 117 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |