/** * Constructor * * @param $template string * Template name * * @return void */ function __construct($template = null) { $this->template = T3_ACTIVE_TEMPLATE; $this->_params = T3Parameter::getInstance(); $this->_theme_info = T3Common::get_active_themes_info(); if ($template) { $this->_tpl = $template; $this->_extend(array($template)); } }
/** * 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; }
/** * Get list of theme name * * @return array */ public static function get_active_themes() { static $_themes = null; if (!isset($_themes)) { $_themes = array(); $themes = T3Parameter::_getParam('themes'); // Active themes $themes = preg_split('/,/', $themes); for ($i = 0; $i < count($themes); $i++) { $themes[$i] = trim($themes[$i]); $theme = array(); if (preg_match('/^(local)\\.(.*)$/', $themes[$i], $matches)) { $theme[0] = $matches[1]; $theme[1] = $matches[2]; //$themes[$i] = array('local', $matches[1]); } elseif (preg_match('/^(core)\\.(.*)$/', $themes[$i], $matches)) { $theme[0] = $matches[1]; $theme[1] = $matches[2]; //$themes[$i] = array('core', $matches[1]); } else { $theme[0] = 'core'; $theme[1] = $themes[$i]; //$themes[$i] = array('core', $themes[$i]); } $path = self::getThemePath($theme[1], $theme[0] == 'local'); if ($theme[1] && is_dir($path)) { $_themes[] = $theme; } } //if (T3Common::isRTL()) $_themes[] = array('core', 'default-rtl'); $_themes[] = array('template', 'default'); //if (T3Common::isRTL()) $_themes[] = array('engine', 'default-rtl'); $_themes[] = array('engine', 'default'); //if isRTL, and -rtl theme exists then add this theme automatically, before add the current theme to active list if (T3Common::isRTL()) { $_themesrtl = array(); foreach ($_themes as $theme) { $themertl = array(); $themertl[0] = $theme[0] == 'template' ? 'core' : $theme[0]; $themertl[1] = $theme[1] . '-rtl'; //$path = T3Path::path(T3_TEMPLATE) . DS . $themertl[0] . DS . 'themes' . DS . $themertl[1]; $path = self::getThemePath($themertl[1], $themertl[0] == 'local'); if ($themertl[0] == 'engine' || is_dir($path)) { $_themesrtl[] = $themertl; } } $_themes = array_merge($_themesrtl, $_themes); } } return $_themes; }
/** * Set value to parameter * * @param string $param Parameter name * @param string $value Setted value * * @return void */ function _setParam($param, $value) { $params = T3Parameter::getInstance(); return $params->setParam($param, $value); }
/** * Use a shorter and readable filename. use version to tell the browser that the file content is change. * Read content from array of files $files and write to one cached file if need update $needupdate or cached file not exists * * @param array $files List of file * @param string $ext Extension * @param bool $needupdate Indicate need to update file or not * * @return The new file url */ public static function store_file2($files, $ext, $needupdate) { $cache_path = T3Parameter::_getParam('optimize_folder', 't3-assets'); $optimize_level = T3Parameter::_getParam('optimize_' . $ext, 1); $path = T3Path::path($cache_path); if (!is_dir($path)) { if (!@JFolder::create($path)) { return false; //cannot create cache folder for js/css optimize } } if (!is_file($path . DS . 'index.html')) { $indexcontent = '<html><body></body></html>'; if (!@JFile::write($path . DS . 'index.html', $indexcontent)) { return false; //cannot create blank index.html to prevent list files } } static $filemap = array(); //data.php contain filename maps $datafile = $path . '/data.php'; if (is_file($datafile)) { include_once $datafile; } //get a salt if (!isset($filemap['salt']) || !$filemap['salt']) { $filemap['salt'] = rand(); } //build destination file $file = md5($filemap['salt'] . serialize($files)); $filename = $ext . '_' . substr($file, 0, 5) . ".{$ext}"; $destfile = $path . DS . $filename; //re-populate $needupdate in case $destfile exists & keep original (not minify) if ($optimize_level == 1 && is_file($destfile)) { foreach ($files as $f) { if (@filemtime($f[0]) > @filemtime($destfile)) { $needupdate = true; break; } } } //check if need update if (!$needupdate && is_file($destfile)) { $fileversion = isset($filemap[$ext]) && isset($filemap[$ext][$file]) ? $filemap[$ext][$file] : 1; $fileversion = $fileversion == 1 ? "" : "?v=" . $filemap[$ext][$file]; if ($optimize_level < 3) { return T3Path::url($cache_path) . '/' . $filename . $fileversion; } else { $url = "jat3action=gzip&jat3type={$ext}&jat3file=" . urlencode($cache_path . '/' . $filename); // Fix when enable languagefilter plugin $url = self::buildURL($url); return $url; } } //get files content $content = ''; foreach ($files as $f) { $media = count($f) > 2 ? trim($f[2]['media']) : ""; if ($ext == 'css') { if ($optimize_level == 1) { $content .= "@import url(\"{$f[1]}\") {$media};\n"; } elseif (!empty($media)) { $content .= "/* " . substr(basename($f[0]), 33) . " */\n" . "@media " . $f[2]['media'] . " {\n" . @JFile::read($f[0]) . "\n}\n\n"; } else { $content .= "/* " . substr(basename($f[0]), 33) . " */\n" . @JFile::read($f[0]) . "\n\n"; } } else { $content .= "/* " . basename($f[0]) . " */\n" . @JFile::read($f[0]) . ";\n\n"; } } if (!isset($filemap[$ext])) { $filemap[$ext] = array(); } if (!isset($filemap[$ext][$file])) { $filemap[$ext][$file] = 0; //store file version } //update file version $filemap[$ext][$file] = $filemap[$ext][$file] + 1; $fileversion = $filemap[$ext][$file] == 1 ? "" : "?v=" . $filemap[$ext][$file]; //update datafile $filemapdata = '<?php $filemap = ' . var_export($filemap, true) . '; ?>'; @JFile::write($datafile, $filemapdata); //create new file if (!@JFile::write($destfile, $content)) { return false; // Cannot create file } //return result //check if need compress if ($optimize_level == 3) { //compress $url = "jat3action=gzip&jat3type={$ext}&jat3file=" . urlencode($cache_path . '/' . $filename); // Fix when enable languagefilter plugin $url = self::buildURL($url); return $url; } return T3Path::url($cache_path) . '/' . $filename . $fileversion; }
function isRTL() { $doc =& JFactory::getDocument(); $params =& T3Parameter::getInstance(); return $doc->direction == 'rtl' || $params->getParam('direction', 'ltr') == 'rtl'; }
function getPageKey() { static $key = null; if ($key) { return $key; } $t3cache = T3Cache::getInstance(); if ($t3cache->_devmode) { return null; } //no cache in devmode $mainframe =& JFactory::getApplication(); $messages = $mainframe->getMessageQueue(); // Ignore cache when there're some message if (is_array($messages) && count($messages)) { $key = null; return null; } $user =& JFactory::getUser(); if ($user->get('aid') || $_SERVER['REQUEST_METHOD'] != 'GET') { $key = null; return null; //no cache for page } $string = 'page'; $uri = JRequest::getURI(); //t3import ('core.libs.Browser'); //$browser = new Browser(); //$string .= $browser->getBrowser().":".$browser->getVersion(); $browser = T3Common::getBrowserSortName() . "-" . T3Common::getBrowserMajorVersion(); $params = T3Parameter::getInstance(); $cparams = ''; foreach ($params->_params_cookie as $k => $v) { $cparams .= $k . "=" . $v . '&'; } $string = "page - URI: {$uri}; Browser: {$browser}; Params: {$cparams}"; $key = md5($string); //Insert into cache db /* $query = "insert `#__t3_cache` (`key`, `raw`, `uri`, `browser`, `params`, `counter`) values('$key', '$string', '$uri', '$browser', '$cparams', 1) ON DUPLICATE KEY UPDATE `counter`=`counter`+1;"; $db =& JFactory::getDBO(); @$db->setQuery( $query ); @$db->query(); */ return $key; }
function getKey($name, $level = 10) { //$uri = JURI::getInstance(); //$string = $uri->getQuery(); $string = $name; if ($level > 0) { $string .= JRequest::getURI(); } if ($level > 1) { $params = T3Parameter::getInstance(); $string .= T3_TOOL_THEMES . "=" . $params->getParam(T3_TOOL_THEMES); $string .= T3_TOOL_LAYOUTS . "=" . $params->getParam(T3_TOOL_LAYOUTS); } if ($level > 2) { t3import('core.libs.Browser'); $browser = new Browser(); $string .= $browser->getBrowser() . ":" . $browser->getVersion(); } if ($level > 3) { $params = T3Parameter::getInstance(); foreach ($params->_params_cookie as $k => $v) { $string .= $k . "=" . $v; } } return md5($string); }