Esempio n. 1
0
 /**
  * Combine the files in $files into a combine.php request
  * If $page->head_force_inline is true, resources will be included inline in the document
  *
  * @param array $files Array of files relative to $dataDir
  * @param string $type The type of resource being combined
  *
  */
 static function CombineFiles($files, $type, $combine)
 {
     global $page;
     //only need file paths
     foreach ($files as $key => $script) {
         if (is_array($script)) {
             $files[$key] = $script['file'];
         }
     }
     $files = array_unique($files);
     $files = array_filter($files);
     //remove empty elements
     // Force resources to be included inline
     // CheckFile will fix the $file path if needed
     if ($page->head_force_inline) {
         if ($type == 'css') {
             echo '<style type="text/css">';
         } else {
             echo '<script type="text/javascript">';
         }
         foreach ($files as $file_key => $file) {
             $full_path = gp_combine::CheckFile($file);
             if (!$full_path) {
                 continue;
             }
             readfile($full_path);
             echo ";\n";
         }
         if ($type == 'css') {
             echo '</style>';
         } else {
             echo '</script>';
         }
         return;
     }
     //files not combined except for script components
     if (!$combine || isset($_REQUEST['no_combine']) && common::LoggedIn()) {
         foreach ($files as $file_key => $file) {
             $html = "\n" . '<script type="text/javascript" src="%s"></script>';
             if (strpos($file, '.less') !== false) {
                 $html = "\n" . '<link type="text/css" href="%s" rel="stylesheet/less" />';
             } elseif ($type == 'css') {
                 $html = "\n" . '<link type="text/css" href="%s" rel="stylesheet"/>';
             }
             gp_combine::CheckFile($file);
             if (common::LoggedIn()) {
                 $file .= '?v=' . rawurlencode(gpversion);
             }
             echo sprintf($html, common::GetDir($file, true));
         }
         return;
     }
     $html = "\n" . '<script type="text/javascript" src="%s"></script>';
     if ($type == 'css') {
         $html = "\n" . '<link rel="stylesheet" type="text/css" href="%s"/>';
     }
     //create combine request
     $combined_file = gp_combine::GenerateFile($files, $type);
     echo sprintf($html, common::GetDir($combined_file, true));
 }
Esempio n. 2
0
 /**
  * Combine the files in $files into a combine.php request
  * If $page->head_force_inline is true, resources will be included inline in the document
  *
  * @param array $files Array of files relative to $dataDir
  * @param string $type The type of resource being combined
  * @param string $theme_stylesheet The current theme identifier
  *
  */
 function CombineFiles($files, $type, $combine, $theme_stylesheet = false)
 {
     global $page;
     includeFile('combine.php');
     $html = "\n" . '<script type="text/javascript" src="%s" %s></script>';
     if ($type == 'css') {
         $html = "\n" . '<link rel="stylesheet" type="text/css" href="%s" %s/>';
     }
     //option to prevent combining files for debugging
     if (isset($_GET['no_combine']) && common::LoggedIn()) {
         $combine = false;
     }
     $files = array_unique($files);
     $combine_request = array();
     foreach ($files as $file) {
         $id = $file == $theme_stylesheet ? 'id="theme_stylesheet"' : '';
         // Force resources to be included inline
         // CheckFile will fix the $file path if needed
         if ($page->head_force_inline) {
             $full_path = gp_combine::CheckFile($file, false);
             if (!$full_path) {
                 continue;
             }
             echo "\n";
             if ($type == 'css') {
                 echo '<style type="text/css">';
                 readfile($full_path);
                 echo '</style>';
             } else {
                 echo '<script type="text/javascript">/* <![CDATA[ */';
                 readfile($full_path);
                 echo '/* ]]> */</script>';
             }
             continue;
         }
         // Combine multiple resources into one
         // CheckFile will be
         if ($combine) {
             $combine_request[] = $type . '%5B%5D=' . rawurlencode($file);
             continue;
         }
         // Include resources individually
         // CheckFile will fix the $file path if needed
         gp_combine::CheckFile($file, false);
         echo sprintf($html, common::GetDir($file, true), $id);
     }
     if (count($combine_request) == 0) {
         return;
     }
     $id = $type == 'css' ? 'id="theme_stylesheet"' : '';
     $combine_request[] = 'etag=' . gp_combine::GenerateEtag($files);
     $combine_request = implode('&amp;', $combine_request);
     //message('<a href="'.common::GetDir($combine_request).'">combined files: '.$type.'</a>');
     echo sprintf($html, common::GetDir('/include/combine.php', true) . '?' . $combine_request, $id);
 }
Esempio n. 3
0
 /**
  * Generate a file with all of the combined content
  *
  */
 static function GenerateFile($files, $type)
 {
     global $dataDir;
     //get etag
     $modified = $content_length = 0;
     $full_paths = array();
     foreach ($files as $file) {
         $full_path = gp_combine::CheckFile($file);
         if ($full_path === false) {
             continue;
         }
         gp_combine::FileStat_Static($full_path, $modified, $content_length);
         $full_paths[$file] = $full_path;
     }
     //check css imports
     if ($type == 'css') {
         $had_imported = false;
         $import_data = array();
         $imported_file = $dataDir . '/data/_cache/import_info.php';
         if (file_exists($imported_file)) {
             include_once $imported_file;
         }
         foreach ($full_paths as $file => $full_path) {
             if (!isset($import_data[$full_path])) {
                 continue;
             }
             $had_imported = true;
             foreach ($import_data[$full_path] as $imported_full) {
                 gp_combine::FileStat_Static($imported_full, $modified, $content_length);
             }
             unset($import_data[$full_path]);
         }
     }
     //check to see if file exists
     $etag = common::GenEtag(json_encode($files), $modified, $content_length);
     $cache_relative = '/data/_cache/combined_' . $etag . '.' . $type;
     $cache_file = $dataDir . $cache_relative;
     if (file_exists($cache_file)) {
         // change modified time to extend cache
         if (time() - filemtime($cache_file) > 604800) {
             touch($cache_file);
         }
         return $cache_relative;
     }
     //create file
     if ($type == 'js') {
         ob_start();
         common::jsStart();
         foreach ($full_paths as $full_path) {
             readfile($full_path);
             echo ";\n";
         }
         $combined_content = ob_get_clean();
     } else {
         $imports = $combined_content = '';
         $new_imported = array();
         foreach ($full_paths as $file => $full_path) {
             $temp = new gp_combine_css($file);
             $combined_content .= "\n/* " . $file . " */\n";
             $combined_content .= $temp->content;
             $imports .= $temp->imports;
             if (count($temp->imported)) {
                 $new_imported[$full_path] = $temp->imported;
             }
         }
         $combined_content = $imports . $combined_content;
         //save imported data
         if (count($new_imported) || $had_imported) {
             if (count($new_imported)) {
                 $import_data = $new_imported + $import_data;
             }
             gpFiles::SaveData($imported_file, 'import_data', $import_data);
         }
     }
     if (!gpFiles::Save($cache_file, $combined_content)) {
         return false;
     }
     includeFile('admin/admin_tools.php');
     admin_tools::CleanCache();
     return $cache_relative;
 }
Esempio n. 4
0
 function CacheInfo($file)
 {
     global $dataDir;
     $full_path = gp_combine::CheckFile($file);
     if ($full_path === false) {
         return false;
     }
     if (!isset($this->css_data[$file])) {
         return $this->CacheCSS($file);
     }
     $cache_info = $this->css_data[$file];
     $cache_file = $dataDir . '/data/_cache/' . $cache_info['min'];
     if (!file_exists($cache_file)) {
         return $this->CacheCSS($file);
     }
     //check size and mod time
     $orig_mod = filemtime($full_path);
     $orig_len = filesize($full_path);
     if ($cache_info['mod'] != $orig_mod || $cache_info['len'] != $orig_len) {
         return $this->CacheCSS($file);
     }
     return $cache_info;
 }