mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-07-31 20:20:36 -04:00
Merge pull request #202 from shadlaws/fix_2051
#2051 - Revise how Gallery_View returns combined JS and CSS.
This commit is contained in:
@@ -82,10 +82,9 @@ class Gallery_View_Core extends View {
|
|||||||
* @param $types a comma separated list of types to combine, eg "script,css"
|
* @param $types a comma separated list of types to combine, eg "script,css"
|
||||||
*/
|
*/
|
||||||
public function start_combining($types) {
|
public function start_combining($types) {
|
||||||
if (gallery::allow_css_and_js_combining()) {
|
foreach (explode(",", $types) as $type) {
|
||||||
foreach (explode(",", $types) as $type) {
|
// Initialize the core group so it gets included first.
|
||||||
$this->combine_queue[$type] = array();
|
$this->combine_queue[$type] = array("core" => array());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,70 +134,93 @@ class Gallery_View_Core extends View {
|
|||||||
/**
|
/**
|
||||||
* Combine a series of files into a single one and cache it in the database.
|
* Combine a series of files into a single one and cache it in the database.
|
||||||
* @param $type the data type (script or css)
|
* @param $type the data type (script or css)
|
||||||
* @param $group the group of scripts or css we want
|
* @param $group the group of scripts or css we want (null will combine all groups)
|
||||||
*/
|
*/
|
||||||
public function get_combined($type, $group="core") {
|
public function get_combined($type, $group=null) {
|
||||||
$links = array();
|
if (is_null($group)) {
|
||||||
|
$groups = array_keys($this->combine_queue[$type]);
|
||||||
if (empty($this->combine_queue[$type][$group])) {
|
} else {
|
||||||
return;
|
$groups = array($group);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include the url in the cache key so that if the Gallery moves, we don't use old cached
|
$buf = "";
|
||||||
// entries.
|
foreach ($groups as $group) {
|
||||||
$key = array(url::abs_file(""));
|
if (empty($this->combine_queue[$type][$group])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
|
// Include the url in the cache key so that if the Gallery moves, we don't use old cached
|
||||||
$stats = stat($path);
|
// entries.
|
||||||
// 7 == size, 9 == mtime, see http://php.net/stat
|
$key = array(url::abs_file(""));
|
||||||
$key[] = "$path $stats[7] $stats[9]";
|
|
||||||
}
|
|
||||||
|
|
||||||
$key = md5(join(" ", $key));
|
|
||||||
$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) {
|
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));
|
||||||
|
|
||||||
|
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") {
|
if ($type == "css") {
|
||||||
$contents .= "/* $path */\n" . $this->process_css($path) . "\n";
|
$buf .= html::stylesheet("combined/css/$key", "screen,print,projection", true);
|
||||||
} else {
|
} else {
|
||||||
$contents .= "/* $path */\n" . file_get_contents($path) . "\n";
|
$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).
|
||||||
|
foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
|
||||||
|
if ($type == "css") {
|
||||||
|
$buf .= html::stylesheet("$path?m=$key", "screen,print,projection", false);
|
||||||
|
} else {
|
||||||
|
$buf .= html::script("$path?m=$key", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$combine_data = new stdClass();
|
unset($this->combine_queue[$type][$group]);
|
||||||
$combine_data->type = $type;
|
if (empty($this->combine_queue[$type])) {
|
||||||
$combine_data->contents = $contents;
|
unset($this->combine_queue[$type]);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($this->combine_queue[$type][$group]);
|
|
||||||
if (empty($this->combine_queue[$type])) {
|
|
||||||
unset($this->combine_queue[$type]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type == "css") {
|
|
||||||
return html::stylesheet("combined/css/$key", "screen,print,projection", true);
|
|
||||||
} else {
|
|
||||||
return html::script("combined/javascript/$key", true);
|
|
||||||
}
|
}
|
||||||
|
return $buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -388,19 +388,19 @@ modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $url
|
|||||||
themes/admin_wind/views/admin.html.php 4 DIRTY $theme->html_attributes()
|
themes/admin_wind/views/admin.html.php 4 DIRTY $theme->html_attributes()
|
||||||
themes/admin_wind/views/admin.html.php 34 DIRTY $theme->admin_head()
|
themes/admin_wind/views/admin.html.php 34 DIRTY $theme->admin_head()
|
||||||
themes/admin_wind/views/admin.html.php 46 DIRTY_JS $theme->url()
|
themes/admin_wind/views/admin.html.php 46 DIRTY_JS $theme->url()
|
||||||
themes/admin_wind/views/admin.html.php 51 DIRTY $theme->get_combined("css")
|
themes/admin_wind/views/admin.html.php 50 DIRTY $theme->get_combined("css")
|
||||||
themes/admin_wind/views/admin.html.php 54 DIRTY $theme->get_combined("script")
|
themes/admin_wind/views/admin.html.php 51 DIRTY $theme->get_combined("script")
|
||||||
themes/admin_wind/views/admin.html.php 58 DIRTY $theme->admin_page_top()
|
themes/admin_wind/views/admin.html.php 55 DIRTY $theme->admin_page_top()
|
||||||
themes/admin_wind/views/admin.html.php 66 DIRTY $theme->admin_header_top()
|
themes/admin_wind/views/admin.html.php 63 DIRTY $theme->admin_header_top()
|
||||||
themes/admin_wind/views/admin.html.php 67 DIRTY_JS item::root()->url()
|
themes/admin_wind/views/admin.html.php 64 DIRTY_JS item::root()->url()
|
||||||
themes/admin_wind/views/admin.html.php 70 DIRTY $theme->user_menu()
|
themes/admin_wind/views/admin.html.php 67 DIRTY $theme->user_menu()
|
||||||
themes/admin_wind/views/admin.html.php 73 DIRTY $theme->admin_menu()
|
themes/admin_wind/views/admin.html.php 70 DIRTY $theme->admin_menu()
|
||||||
themes/admin_wind/views/admin.html.php 76 DIRTY $theme->admin_header_bottom()
|
themes/admin_wind/views/admin.html.php 73 DIRTY $theme->admin_header_bottom()
|
||||||
themes/admin_wind/views/admin.html.php 83 DIRTY $content
|
themes/admin_wind/views/admin.html.php 80 DIRTY $content
|
||||||
themes/admin_wind/views/admin.html.php 89 DIRTY $sidebar
|
themes/admin_wind/views/admin.html.php 86 DIRTY $sidebar
|
||||||
themes/admin_wind/views/admin.html.php 94 DIRTY $theme->admin_footer()
|
themes/admin_wind/views/admin.html.php 91 DIRTY $theme->admin_footer()
|
||||||
themes/admin_wind/views/admin.html.php 97 DIRTY $theme->admin_credits()
|
themes/admin_wind/views/admin.html.php 94 DIRTY $theme->admin_credits()
|
||||||
themes/admin_wind/views/admin.html.php 102 DIRTY $theme->admin_page_bottom()
|
themes/admin_wind/views/admin.html.php 99 DIRTY $theme->admin_page_bottom()
|
||||||
themes/admin_wind/views/block.html.php 3 DIRTY_ATTR $anchor
|
themes/admin_wind/views/block.html.php 3 DIRTY_ATTR $anchor
|
||||||
themes/admin_wind/views/block.html.php 5 DIRTY $id
|
themes/admin_wind/views/block.html.php 5 DIRTY $id
|
||||||
themes/admin_wind/views/block.html.php 5 DIRTY_ATTR $css_id
|
themes/admin_wind/views/block.html.php 5 DIRTY_ATTR $css_id
|
||||||
@@ -436,17 +436,17 @@ themes/wind/views/page.html.php 32 DIRTY $new_w
|
|||||||
themes/wind/views/page.html.php 33 DIRTY $new_height
|
themes/wind/views/page.html.php 33 DIRTY $new_height
|
||||||
themes/wind/views/page.html.php 34 DIRTY $thumb_proportion
|
themes/wind/views/page.html.php 34 DIRTY $thumb_proportion
|
||||||
themes/wind/views/page.html.php 68 DIRTY_JS $theme->url()
|
themes/wind/views/page.html.php 68 DIRTY_JS $theme->url()
|
||||||
themes/wind/views/page.html.php 73 DIRTY $theme->get_combined("css")
|
themes/wind/views/page.html.php 72 DIRTY $theme->get_combined("css")
|
||||||
themes/wind/views/page.html.php 76 DIRTY $theme->get_combined("script")
|
themes/wind/views/page.html.php 73 DIRTY $theme->get_combined("script")
|
||||||
themes/wind/views/page.html.php 86 DIRTY $header_text
|
themes/wind/views/page.html.php 83 DIRTY $header_text
|
||||||
themes/wind/views/page.html.php 88 DIRTY_JS item::root()->url()
|
themes/wind/views/page.html.php 85 DIRTY_JS item::root()->url()
|
||||||
themes/wind/views/page.html.php 92 DIRTY $theme->user_menu()
|
themes/wind/views/page.html.php 89 DIRTY $theme->user_menu()
|
||||||
themes/wind/views/page.html.php 107 DIRTY_ATTR $breadcrumb->last?"g-active":""
|
themes/wind/views/page.html.php 104 DIRTY_ATTR $breadcrumb->last?"g-active":""
|
||||||
themes/wind/views/page.html.php 108 DIRTY_ATTR $breadcrumb->first?"g-first":""
|
themes/wind/views/page.html.php 105 DIRTY_ATTR $breadcrumb->first?"g-first":""
|
||||||
themes/wind/views/page.html.php 109 DIRTY_JS $breadcrumb->url
|
themes/wind/views/page.html.php 106 DIRTY_JS $breadcrumb->url
|
||||||
themes/wind/views/page.html.php 122 DIRTY $content
|
themes/wind/views/page.html.php 119 DIRTY $content
|
||||||
themes/wind/views/page.html.php 128 DIRTY newView("sidebar.html")
|
themes/wind/views/page.html.php 125 DIRTY newView("sidebar.html")
|
||||||
themes/wind/views/page.html.php 135 DIRTY $footer_text
|
themes/wind/views/page.html.php 132 DIRTY $footer_text
|
||||||
themes/wind/views/paginator.html.php 33 DIRTY_JS $first_page_url
|
themes/wind/views/paginator.html.php 33 DIRTY_JS $first_page_url
|
||||||
themes/wind/views/paginator.html.php 42 DIRTY_JS $previous_page_url
|
themes/wind/views/paginator.html.php 42 DIRTY_JS $previous_page_url
|
||||||
themes/wind/views/paginator.html.php 70 DIRTY_JS $next_page_url
|
themes/wind/views/paginator.html.php 70 DIRTY_JS $next_page_url
|
||||||
|
|||||||
@@ -47,10 +47,7 @@
|
|||||||
media="screen,print,projection" />
|
media="screen,print,projection" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
<!-- LOOKING FOR YOUR CSS? It's all been combined into the link below -->
|
|
||||||
<?= $theme->get_combined("css") ?>
|
<?= $theme->get_combined("css") ?>
|
||||||
|
|
||||||
<!-- LOOKING FOR YOUR JAVASCRIPT? It's all been combined into the link below -->
|
|
||||||
<?= $theme->get_combined("script") ?>
|
<?= $theme->get_combined("script") ?>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<link rel="apple-touch-icon-precomposed"
|
<link rel="apple-touch-icon-precomposed"
|
||||||
href="<?= url::file(module::get_var("gallery", "apple_touch_icon_url")) ?>" />
|
href="<?= url::file(module::get_var("gallery", "apple_touch_icon_url")) ?>" />
|
||||||
<? if ($theme->page_type == "collection"): ?>
|
<? if ($theme->page_type == "collection"): ?>
|
||||||
<? if (($thumb_proportion = $theme->thumb_proportion($theme->item(), 100, "width")) != 1): ?>
|
<? if (($thumb_proportion = $theme->thumb_proportion($theme->item(), 100, "width")) != 1): ?>
|
||||||
<? $new_width = round($thumb_proportion * 213) ?>
|
<? $new_width = round($thumb_proportion * 213) ?>
|
||||||
<? $new_height = round($thumb_proportion * 240) ?>
|
<? $new_height = round($thumb_proportion * 240) ?>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
@@ -69,10 +69,7 @@
|
|||||||
media="screen,print,projection" />
|
media="screen,print,projection" />
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
<!-- LOOKING FOR YOUR CSS? It's all been combined into the link below -->
|
|
||||||
<?= $theme->get_combined("css") ?>
|
<?= $theme->get_combined("css") ?>
|
||||||
|
|
||||||
<!-- LOOKING FOR YOUR JAVASCRIPT? It's all been combined into the link below -->
|
|
||||||
<?= $theme->get_combined("script") ?>
|
<?= $theme->get_combined("script") ?>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user