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
  * @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);
 }