Exemplo n.º 1
0
 /**
  * Get page key from URI, browser (version), params (cookie params)
  *
  * @return mixed  NULL if devmode/noncache or string key code
  */
 public static function getPageKey()
 {
     static $key = null;
     if ($key) {
         return $key;
     }
     // No cache in devmode
     $t3cache = T3Cache::getT3Cache();
     if ($t3cache->_devmode) {
         return null;
     }
     // No cache when disable T3 cache
     $config = T3Common::get_template_based_params();
     if ($config->get('cache', 0) == 0) {
         return null;
     }
     // TODO: need to move in cache page code at the end of onAfterRender
     $mainframe = JFactory::getApplication();
     $messages = $mainframe->getMessageQueue();
     // Ignore cache when there're some message
     if (is_array($messages) && count($messages)) {
         return null;
     }
     // If user log-in, ignore cache
     $user = JFactory::getUser();
     if (!$user->get('guest') || $_SERVER['REQUEST_METHOD'] != 'GET') {
         return null;
     }
     // If ie6, ignore cache
     $isIE6 = T3Template::isIE6();
     if ($isIE6) {
         return null;
     }
     // Don't cache when offline
     $cfg = JFactory::getConfig();
     if ($cfg->get('offline')) {
         return null;
     }
     $uri = JRequest::getURI();
     //$browser = T3Common::getBrowserSortName() . "-" . T3Common::getBrowserMajorVersion();
     $mobile = T3Common::mobile_device_detect();
     $params = T3Parameter::getInstance();
     $cparams = '';
     foreach ($params->_params_cookie as $k => $v) {
         $cparams .= $k . "=" . $v . '&';
     }
     //$key = "page - URI: $uri; Browser: $browser; Params: $cparams";
     $key = "page - URI: {$uri}; Mobile: {$mobile}; Params: {$cparams}";
     //T3Common::log($key . '  ' . T3Common::getBrowserSortName() . "-" . T3Common::getBrowserMajorVersion());
     return $key;
 }
Exemplo n.º 2
0
 function t3_init()
 {
     t3import('core.parameter');
     t3import('core.extendable');
     t3import('core.template');
     t3import('core.basetemplate');
     t3import('core.cache');
     t3import('core.head');
     t3import('core.hook');
     // Remove JDocumentHTML for compatible J1.6 & J1.7
     // if (!class_exists ('JDocumentHTML', false)) t3import ('core.joomla.documenthtml');
     if (!class_exists('JView', false)) {
         t3import('core.joomla.view');
     }
     if (!class_exists('JModuleHelper', false)) {
         t3import('core.joomla.modulehelper');
     }
     // if (! class_exists('JPagination', false)) t3import('core.joomla.pagination');
     //Load template language
     $this->loadLanguage('tpl_' . T3_ACTIVE_TEMPLATE, JPATH_SITE);
     $params = T3Common::get_template_based_params();
     //instance cache object.
     $devmode = $params ? $params->get('devmode', '0') == '1' : false;
     $t3cache = T3Cache::getT3Cache($devmode);
     //Check if enable T3 info mode. Enable by default (if not set)
     if ($params->get('infomode', 1) == 1) {
         if (!JRequest::getCmd('t3info') && JRequest::getCmd('tp') && JComponentHelper::getParams('com_templates')->get('template_positions_display')) {
             JRequest::setVar('t3info', JRequest::getCmd('tp'));
         }
     }
     $key = T3Cache::getPageKey();
     $user =& JFactory::getUser();
     $data = null;
     if ($devmode || JRequest::getCmd('cache') == 'no') {
         $t3cache->setCaching(false);
         JResponse::allowCache(false);
     } else {
         $t3cache->setCaching(true);
         JResponse::allowCache(true);
         //T3Common::log('allow cache');
     }
     // Check ie6
     $isIE6 = T3Template::isIE6();
     // Get cache
     $data = $t3cache->get($key);
     if ($data && !$isIE6) {
         $mainframe = JFactory::getApplication();
         // Check HTTP header
         $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : false;
         $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : false;
         $cache_time = (int) substr($data, 0, 20);
         $etag = md5($key);
         if ($if_modified_since && $if_none_match && $if_modified_since == $cache_time && $if_none_match == $etag) {
             header('HTTP/1.x 304 Not Modified', true);
             $mainframe->close();
         }
         $data = JString::substr($data, 20);
         // Check cached data
         if (!preg_match('#<jdoc:include\\ type="([^"]+)" (.*)\\/>#iU', $data)) {
             $token = JUtility::getToken();
             $search = '#<input type="hidden" name="[0-9a-f]{32}" value="1" />#';
             $replacement = '<input type="hidden" name="' . $token . '" value="1" />';
             $data = preg_replace($search, $replacement, $data);
             JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $cache_time) . ' GMT', true);
             JResponse::setHeader('ETag', $etag, true);
             JResponse::setBody($data);
             echo JResponse::toString($mainframe->getCfg('gzip'));
             if (JDEBUG) {
                 global $_PROFILER;
                 $_PROFILER->mark('afterCache');
                 echo implode('', $_PROFILER->getBuffer());
             }
             $mainframe->close();
         }
     }
     //Preload template
     t3import('core.preload');
     $preload = T3Preload::getInstance();
     $preload->load();
     $doc =& JFactory::getDocument();
     $t3 = T3Template::getInstance($doc);
     $t3->_html = $data;
     // Disable joomla cache when browsing by device
     $device = T3Common::mobile_device_detect();
     if ($device !== 'false') {
         $conf = JFactory::getConfig();
         $conf->set('caching', 0);
     }
     // Separate cache when browsing in each device
     /*
     $app = JFactory::getApplication();
     $registeredurlparams = $app->get('registeredurlparams');
     if (empty($registeredurlparams)) {
         $registeredurlparams = new stdClass;
     }
     $registeredurlparams->device = 'CMD';
     $app->set('registeredurlparams', $registeredurlparams);
     JRequest::setVar('device', T3Common::mobile_device_detect());
     */
 }