/** * Get theme key from active layout & active themes * * @return mixed NULL if devmode or keycode string */ public static function getThemeKey() { $t3cache = T3Cache::getT3Cache(); if ($t3cache->_devmode) { return null; } //no cache in devmode $themes = T3Common::get_active_themes(); $layout = T3Common::get_active_layout(); $string = 'theme-infos-' . $layout; if (is_array($themes)) { $string .= serialize($themes); } return $string; }
/** * Implement after render event * * @return null */ function onAfterRender() { $app = JFactory::getApplication(); t3import('core.admin.util'); $util = new JAT3_AdminUtil(); if ($app->isAdmin()) { ob_start(); $util->show_button_clearCache(); $content = ob_get_clean(); $buffer = JResponse::getBody(); $buffer = str_replace('</body>', $content . "\n</body>", $buffer); JResponse::setBody($buffer); } if ($util->checkPermission()) { if (JAT3_AdminUtil::checkCondition_for_Menu()) { // HTML= Parser lib include_once T3Path::path(T3_CORE) . DS . 'libs' . DS . "html_parser.php"; include_once T3Path::path(T3_CORE) . DS . 'admin' . DS . "util.php"; $_body = JResponse::getBody(); // Replace content $jat3core = new JAT3_AdminUtil(); $_body = $jat3core->replaceContent($_body); if ($_body) { JResponse::setBody($_body); } } } if (!T3Common::detect()) { return; } if ($util->checkPermission()) { if ($util->checkCondition()) { // Load t3 language file for template admin to avoid to be override by other extensions language $extension = 'plg_' . $this->_type . '_' . $this->_name; $lang = JFactory::getLanguage(); $lang->load(strtolower($extension), JPATH_ADMINISTRATOR, null, true, false); $params = T3Path::path(T3_CORE) . DS . 'admin' . DS . 'index.php'; if (file_exists($params)) { ob_start(); include $params; $content = ob_get_clean(); $buffer = JResponse::getBody(); $buffer = preg_replace('/<\\/body>/', $content . "\n</body>", $buffer); JResponse::setBody($buffer); } } return; } if (!$app->isAdmin()) { //Expires date set to very long //JResponse::setHeader( 'Expires', gmdate( 'D, d M Y H:i:s', time() + 3600000 ) . ' GMT', true ); //JResponse::setHeader( 'Last-Modified', gmdate( 'D, d M Y H:i:s', time()) . ' GMT', true ); JResponse::setHeader('Expires', '', true); JResponse::setHeader('Cache-Control', 'private', true); //Update cache in case of the whole page is cached $t3template = T3Template::getInstance(); $key = T3Cache::getPageKey(); //if (($data = T3Cache::get ( $key )) && !preg_match('#<jdoc:include\ type="([^"]+)" (.*)\/>#iU', $data)) { if ($key != null && $t3template->nonecache == false) { $time = time(); JResponse::setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $time) . ' GMT', true); JResponse::setHeader('ETag', md5($key), true); $time = sprintf('%20d', $time); $buffer = $time . JResponse::getBody(); $t3cache = T3Cache::getT3Cache(); $t3cache->store($buffer, $key); } } }
/** * Get active themes info * * @return array Themes information */ public static function get_active_themes_info() { $key = T3Cache::getThemeKey(); $t3cache = T3Cache::getT3Cache(); $themes_info = $t3cache->getObject($key); if ($themes_info && isset($themes_info['layout']) && $themes_info['layout']) { return $themes_info; } $themes = T3Common::get_active_themes(); $themes[] = array('engine', 'default'); $themes_info = null; foreach ($themes as $theme) { //$theme_info = T3Common::get_themes (implode('.', $theme)); $theme_info = T3Common::get_theme_info($theme); if (!$theme_info) { continue; } if (!$themes_info) { $themes_info = $theme_info; } else { //merge info $themes_info = T3Common::merge_info($theme_info, $themes_info); } } //Get layout if tmpl is not component $themes_info['layout'] = null; $tmpl = JRequest::getCmd('tmpl'); if ($tmpl != 'component') { $themes_info['layout'] = T3Common::get_layout_info(); } $t3cache->storeObject($themes_info, $key); return $themes_info; }
function t3_init() { t3import('core.parameter'); t3import('core.extendable'); t3import('core.template'); 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); } // Get cache $data = $t3cache->get($key); if ($data) { $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 = 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()); */ }
/** * Set object * * @param string $name Object name * @param string $object Instance of object * * @return void */ function setObject($name, $object) { $template = T3_ACTIVE_TEMPLATE; $preload = T3Preload::getInstance(); $preload->data[$template][$name] = $object; //$key = T3Parameter::getKey ('preload-'.$template, 0); $key = T3Cache::getPreloadKey($template); $t3cache = T3Cache::getT3Cache(); $t3cache->storeObject($preload->data[$template], $key); }