/** * Get parameter value * * @param string $param Parameter name * @param string $default Default value * * @return string Parameter value */ function get($param, $default = '') { return T3Parameter::_getParam($param, $default); }
/** * 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; }
/** * 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; }