public static function processJsFiles() { /** @global $gantry Gantry */ global $gantry; $path = $gantry->basePath; $cache_time = $gantry->get("gzipper-time"); $expires_time = $gantry->get("gzipper-expirestime", 1440); $ordered_files = array(); $output = array(); $md5sum = ""; $script_tags = $gantry->_scripts; foreach ($script_tags as $filepath => $file) { $md5sum .= md5($filepath); $ordered_files[] = array(dirname($filepath), basename($filepath), $file); } if (!is_writable(JPATH_CACHE)) { foreach ($gantry->_scripts as $js_file) { $gantry->document->addScript($js_file); } return; } if (count($ordered_files) > 0) { $cache_filename = "js-" . md5($md5sum) . ".php"; $cache_fullpath = JPATH_CACHE . '/' . $cache_filename; //see if file is stale if (JFile::exists($cache_fullpath)) { $diff = time() - filectime($cache_fullpath); } else { $diff = $cache_time + 1; } if ($diff > $cache_time) { $outfile = GantryGZipper::_getOutHeader("js", $expires_time); foreach ($ordered_files as $files) { $dir = $files[0]; $filename = $files[1]; $details = $files[2]; $detailspath = $dir . '/' . $filename; if (JFile::exists($detailspath)) { $jsfile = JFile::read($detailspath); // fix for stupid joolma code if (strpos($filename, 'joomla.javascript.js') !== false or strpos($filename, 'mambojavascript.js') !== false) { $jsfile = str_replace("// <?php !!", "// ", $jsfile); } $jsfile = self::cleanEndLines($jsfile); $outfile .= "\n\n/*** " . $filename . " ***/\n\n" . $jsfile; } } JFile::write($cache_fullpath, $outfile); } $cache_file_name = $path . "/cache/" . $cache_filename; $cache_url_name = $gantry->baseUrl . "cache/" . $cache_filename; $gantry->document->addScript($cache_url_name); } }
/** * */ public function finalize() { if (!defined('GANTRY_FINALIZED')) { // Run the admin init if ($this->isAdmin()) { $this->adminFinalize(); return; } $this->addStyle($this->templateName . '-custom.css', 1000); gantry_import('core.params.overrides.gantrycookieparamoverride'); gantry_import('core.params.overrides.gantrysessionparamoverride'); $cache = GantryCache::getInstance(); if (!$this->_parts_cached) { $parts_cache = array(); foreach ($this->_parts_to_cache as $part) { $parts_cache[$part] = $this->{$part}; } if ($parts_cache) { $cache->set($this->cacheKey('parts'), $parts_cache); } } // Finalize all features foreach ($this->getFeatures() as $feature) { $feature_instance = $this->getFeature($feature); if ($feature_instance->isEnabled() && method_exists($feature_instance, 'finalize')) { $feature_instance->finalize(); } } $this->renderCombinesInlines(); if (isset($_REQUEST['reset-settings'])) { GantrySessionParamOverride::clean(); GantryCookieParamOverride::clean(); } else { GantrySessionParamOverride::store(); GantryCookieParamOverride::store(); } if ($this->get("gzipper-enabled", false)) { gantry_import('core.gantrygzipper'); GantryGZipper::processCSSFiles(); GantryGZipper::processJsFiles(); } else { ksort($this->_styles); foreach ($this->_styles as $priorities) { foreach ($priorities as $css_file) { /** @var $css_file GantryStyleLink */ $this->document->addStyleSheet($css_file->getUrl()); } } foreach ($this->_scripts as $js_file) { $this->document->addScript($js_file); } } define('GANTRY_FINALIZED', true); } if ($this->altindex !== false) { $contents = ob_get_contents(); ob_end_clean(); ob_start(); echo $this->altindex; } }
function finalize() { if (!defined('GANTRY_FINALIZED')) { gantry_import('core.params.gantrycookieparams'); gantry_import('core.params.gantrysessionparams'); // Finalize all features foreach ($this->_features as $feature) { $feature_instance = $this->_getFeature($feature); if ($feature_instance->isEnabled() && method_exists($feature_instance, 'finalize')) { $feature_instance->finalize(); } } if (isset($_REQUEST['reset-settings'])) { GantrySessionParams::clean(); GantryCookieParams::clean(); } else { GantrySessionParams::store(); GantryCookieParams::store(); } if ($this->get("gzipper-enabled", false)) { gantry_import('core.gantrygzipper'); GantryGZipper::processCSSFiles(); GantryGZipper::processJsFiles(); } else { ksort($this->_styles); foreach ($this->_styles as $priorities) { foreach ($priorities as $css_file) { $this->document->addStyleSheet($css_file->url); } } foreach ($this->_scripts as $js_file) { $this->document->addScript($js_file); } } define('GANTRY_FINALIZED', true); } if ($this->altindex !== false) { $contents = ob_get_contents(); ob_end_clean(); ob_start(); echo $this->altindex; } }
function processJsFiles() { global $gantry; $path = $gantry->basePath; $cache_time = $gantry->get("gzipper-time"); $expires_time = $gantry->get("gzipper-expirestime", 1440); $cache_dir = $gantry->templatePath . DS . 'cache'; $ordered_files = array(); $output = array(); $md5sum = ""; $script_tags = $gantry->_scripts; foreach ($script_tags as $filepath => $file) { $md5sum .= md5($filepath); $ordered_files[] = array(dirname($filepath), basename($filepath), $file); } if (!is_writable($cache_dir)) { foreach ($this->_scripts as $js_file) { $output[] = $js_file; } return; } if (count($ordered_files) > 0) { $cache_filename = "js-" . md5($md5sum) . ".php"; $cache_fullpath = $cache_dir . DS . $cache_filename; //see if file is stale if (file_exists($cache_fullpath)) { $diff = time() - filectime($cache_fullpath); } else { $diff = $cache_time + 1; } if ($diff > $cache_time) { $outfile = GantryGZipper::_getOutHeader("js", $expires_time); foreach ($ordered_files as $files) { $dir = $files[0]; $filename = $files[1]; $details = $files[2]; $detailspath = $dir . DS . $filename; if (file_exists($detailspath)) { $jsfile = file_get_contents($detailspath); // fix for stupid joolma code if (strpos($filename, 'joomla.javascript.js') !== false or strpos($filename, 'mambojavascript.js') !== false) { $jsfile = str_replace("// <?php !!", "// ", $jsfile); } $outfile .= "\n\n/*** " . $filename . " ***/\n\n" . $jsfile; } } file_put_contents($cache_fullpath, $outfile); } $cache_file_name = $path . "/cache/" . $cache_filename; $cache_url_name = $gantry->templateUrl . "/cache/" . $cache_filename; $output[] = $cache_url_name; } $gantry->_scripts =& $output; }
function finalize() { gantry_import('core.params.gantrycookieparams'); gantry_import('core.params.gantrysessionparams'); // Finalize all features foreach ($this->_features as $feature) { $feature_instance = $this->_getFeature($feature); if ($feature_instance->isEnabled() && method_exists($feature_instance, 'finalize')) { $feature_instance->finalize(); } } if (isset($_REQUEST['reset-settings'])) { GantrySessionParams::clean(); GantryCookieParams::clean(); } else { GantrySessionParams::store(); GantryCookieParams::store(); } if ($this->get("gzipper-enabled", false)) { gantry_import('core.gantrygzipper'); GantryGZipper::processCSSFiles(); GantryGZipper::processJsFiles(); } else { foreach ($this->_styles as $css_file) { $this->document->addStyleSheet($css_file); } foreach ($this->_scripts as $js_file) { $this->document->addScript($js_file); } } }
function finalizeAdmin() { if (!defined('GANTRY_FINALIZED')) { // Apply compression if enabled if ($this->get("gzipper-enabled", false)) { gantry_import('core.gantrygzipper'); GantryGZipper::processCSSFiles(); GantryGZipper::processJsFiles(); } define('GANTRY_FINALIZED', true); } $output = ob_get_clean(); // process page output to add header in $this->_displayHead($output); $this->_displayFooter($output); $this->_displayBodyTag($output); echo $output; }