本文整理汇总了PHP中gallery::allow_css_and_js_combining方法的典型用法代码示例。如果您正苦于以下问题:PHP gallery::allow_css_and_js_combining方法的具体用法?PHP gallery::allow_css_and_js_combining怎么用?PHP gallery::allow_css_and_js_combining使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gallery
的用法示例。
在下文中一共展示了gallery::allow_css_and_js_combining方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: start_combining
/**
* Begin gather up scripts or css files so that they can be combined into a single request.
*
* @param $types a comma separated list of types to combine, eg "script,css"
*/
public function start_combining($types)
{
if (gallery::allow_css_and_js_combining()) {
foreach (explode(",", $types) as $type) {
$this->combine_queue[$type] = array();
}
}
}
示例2: get_combined
/**
* Combine a series of files into a single one and cache it in the database.
* @param $type the data type (script or css)
* @param $group the group of scripts or css we want (null will combine all groups)
*/
public function get_combined($type, $group = null)
{
if (is_null($group)) {
$groups = array_keys($this->combine_queue[$type]);
} else {
$groups = array($group);
}
$buf = "";
foreach ($groups as $group) {
if (empty($this->combine_queue[$type][$group])) {
continue;
}
// Include the url in the cache key so that if the Gallery moves, we don't use old cached
// entries.
$key = array(url::abs_file(""));
foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
$stats = stat($path);
// 7 == size, 9 == mtime, see http://php.net/stat
$key[] = "{$path} {$stats['7']} {$stats['9']}";
}
$key = md5(join(" ", $key)) . ($type == "css" ? ".css" : ".js");
if (gallery::allow_css_and_js_combining()) {
// Combine enabled - if we're at the start of the buffer, add a comment.
if (!$buf) {
$type_text = $type == "css" ? "CSS" : "JS";
$buf .= "<!-- LOOKING FOR YOUR {$type_text}? It's all been combined into the link(s) below -->\n";
}
$cache = Cache::instance();
$contents = $cache->get($key);
if (empty($contents)) {
$combine_data = new stdClass();
$combine_data->type = $type;
$combine_data->contents = $this->combine_queue[$type][$group];
module::event("before_combine", $combine_data);
$contents = "";
foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
if ($type == "css") {
$contents .= "/* {$path} */\n" . $this->process_css($path) . "\n";
} else {
$contents .= "/* {$path} */\n" . file_get_contents($path) . "\n";
}
}
$combine_data = new stdClass();
$combine_data->type = $type;
$combine_data->contents = $contents;
module::event("after_combine", $combine_data);
$cache->set($key, $combine_data->contents, array($type), 30 * 84600);
$use_gzip = function_exists("gzencode") && (int) ini_get("zlib.output_compression") === 0;
if ($use_gzip) {
$cache->set("{$key}_gz", gzencode($combine_data->contents, 9, FORCE_GZIP), array($type, "gzip"), 30 * 84600);
}
}
if ($type == "css") {
$buf .= html::stylesheet("combined/css/{$key}", "screen,print,projection", true);
} else {
$buf .= html::script("combined/javascript/{$key}", true);
}
} else {
// Don't combine - just return the CSS and JS links (with the key as a cache buster).
$key_base = substr($key, 0, $type == "css" ? -4 : -3);
// key without extension
foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
if ($type == "css") {
$buf .= html::stylesheet("{$path}?m={$key_base}", "screen,print,projection", false);
} else {
$buf .= html::script("{$path}?m={$key_base}", false);
}
}
}
unset($this->combine_queue[$type][$group]);
if (empty($this->combine_queue[$type])) {
unset($this->combine_queue[$type]);
}
}
return $buf;
}