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);
     }
 }
示例#2
0
 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;
 }