/** * Add one or more components to the page. Output the <script> and/or <style> immediately * @param string $names comma separated list of components * */ static function GetComponents($names = '') { includeFile('combine.php'); $scripts = gp_combine::ScriptInfo($names); gpOutput::CombineFiles($scripts['css'], 'css', false); gpOutput::CombineFiles($scripts['js'], 'js', false); }
/** * 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('&', $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); }
static function ScriptInfo($components, $dependencies = true) { global $config; static $root_call = true; if (is_string($components)) { $components = explode(',', strtolower($components)); $components = array_unique($components); } self::$scripts['colorbox-css']['file'] = '/include/thirdparty/colorbox139/' . $config['colorbox_style'] . '/colorbox.css'; $all_scripts = array(); //get all scripts foreach ($components as $component) { if (!array_key_exists($component, self::$scripts)) { $all_scripts[$component] = false; continue; } $script_info = self::$scripts[$component]; if ($dependencies && isset($script_info['requires'])) { $is_root_call = $root_call; $root_call = false; $all_scripts += gp_combine::ScriptInfo($script_info['requires']); $root_call = $is_root_call; } $all_scripts[$component] = self::$scripts[$component]; } if (!$root_call) { return $all_scripts; } $all_scripts = array_filter($all_scripts); $first_scripts = array(); //make sure jquery is the first if (array_key_exists('jquery', $all_scripts)) { $first_scripts['jquery'] = $all_scripts['jquery']; } // move any bootstrap components to front to prevent conflicts // hack for conflict between jquery ui button and bootstrap button foreach ($all_scripts as $key => $script) { if (!array_key_exists('package', $script)) { continue; } if ($script['package'] == 'bootstrap' || $script['package'] == 'bootstrap3') { $first_scripts[$key] = $script; } } $all_scripts = $first_scripts + $all_scripts; //remove any excludes $excludes = array(); foreach ($all_scripts as $key => $script) { if (empty($script['exclude'])) { continue; } if (!is_array($script['exclude'])) { $script['exclude'] = explode(',', $script['exclude']); } $excludes = array_merge($excludes, $script['exclude']); } $all_scripts = array_diff_key($all_scripts, array_flip($excludes)); //return an organized array for the root call $return = array('js' => array(), 'css' => array()); foreach ($all_scripts as $key => $script) { if (empty($script['file'])) { continue; } if (gpdebug && !empty($script['dev'])) { $script['file'] = $script['dev']; } if (empty($script['type'])) { $script['type'] = pathinfo($script['file'], PATHINFO_EXTENSION); } if ($script['type'] == 'less') { $script['type'] = 'css'; } $return[$script['type']][$key] = $script; } return $return; }
function FileStat($file_path) { return gp_combine::FileStat_Static($file_path, $this->last_modified, $this->content_length); }