summaryrefslogtreecommitdiff
path: root/modules/gallery/libraries
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/libraries')
-rw-r--r--modules/gallery/libraries/Admin_View.php36
-rw-r--r--modules/gallery/libraries/Gallery_View.php130
-rw-r--r--modules/gallery/libraries/IdentityProvider.php3
-rw-r--r--modules/gallery/libraries/SafeString.php2
-rw-r--r--modules/gallery/libraries/Theme_View.php30
5 files changed, 133 insertions, 68 deletions
diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php
index 83163868..ba348d7a 100644
--- a/modules/gallery/libraries/Admin_View.php
+++ b/modules/gallery/libraries/Admin_View.php
@@ -93,24 +93,52 @@ class Admin_View_Core extends Gallery_View {
case "body_attributes":
case "html_attributes":
$blocks = array();
+ if (method_exists("gallery_theme", $function)) {
+ switch (count($args)) {
+ case 0:
+ $blocks[] = gallery_theme::$function($this);
+ break;
+ case 1:
+ $blocks[] = gallery_theme::$function($this, $args[0]);
+ break;
+ case 2:
+ $blocks[] = gallery_theme::$function($this, $args[0], $args[1]);
+ break;
+ default:
+ $blocks[] = call_user_func_array(
+ array("gallery_theme", $function),
+ array_merge(array($this), $args));
+ }
+ }
+
foreach (module::active() as $module) {
+ if ($module->name == "gallery") {
+ continue;
+ }
$helper_class = "{$module->name}_theme";
- if (method_exists($helper_class, $function)) {
+ if (class_exists($helper_class) && method_exists($helper_class, $function)) {
$blocks[] = call_user_func_array(
array($helper_class, $function),
array_merge(array($this), $args));
}
}
+ $helper_class = theme::$admin_theme_name . "_theme";
+ if (class_exists($helper_class) && method_exists($helper_class, $function)) {
+ $blocks[] = call_user_func_array(
+ array($helper_class, $function),
+ array_merge(array($this), $args));
+ }
+
if (Session::instance()->get("debug")) {
- if ($function != "admin_head") {
+ if ($function != "admin_head" && $function != "body_attributes") {
array_unshift(
- $blocks, "<div class=\"g-annotated-theme-block g-annotated-theme-block_$function\">" .
+ $blocks,
+ "<div class=\"g-annotated-theme-block g-annotated-theme-block_$function g-clear-fix\">" .
"<div class=\"title\">$function</div>");
$blocks[] = "</div>";
}
}
-
return implode("\n", $blocks);
default:
diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php
index 8f02b53c..3f59db6a 100644
--- a/modules/gallery/libraries/Gallery_View.php
+++ b/modules/gallery/libraries/Gallery_View.php
@@ -82,10 +82,9 @@ class Gallery_View_Core extends View {
* @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();
- }
+ foreach (explode(",", $types) as $type) {
+ // Initialize the core group so it gets included first.
+ $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.
* @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") {
- $links = array();
-
- if (empty($this->combine_queue[$type][$group])) {
- return;
+ public function get_combined($type, $group=null) {
+ if (is_null($group)) {
+ $groups = array_keys($this->combine_queue[$type]);
+ } else {
+ $groups = array($group);
}
- // 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(""));
+ $buf = "";
+ foreach ($groups as $group) {
+ if (empty($this->combine_queue[$type][$group])) {
+ continue;
+ }
- 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]";
- }
+ // 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));
- $key = md5(join(" ", $key));
- $cache = Cache::instance();
- $contents = $cache->get($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";
+ }
- 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);
+ $cache = Cache::instance();
+ $contents = $cache->get($key);
- $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";
- }
- }
+ 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);
- $combine_data = new stdClass();
- $combine_data->type = $type;
- $combine_data->contents = $contents;
- module::event("after_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";
+ }
+ }
- $cache->set($key, $combine_data->contents, array($type), 30 * 84600);
+ $combine_data = new stdClass();
+ $combine_data->type = $type;
+ $combine_data->contents = $contents;
+ module::event("after_combine", $combine_data);
- $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);
- }
+ $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") {
+ $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).
+ 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);
+ }
+ }
+ }
- if ($type == "css") {
- return html::stylesheet("combined/css/$key", "screen,print,projection", true);
- } else {
- return html::script("combined/javascript/$key", true);
+ unset($this->combine_queue[$type][$group]);
+ if (empty($this->combine_queue[$type])) {
+ unset($this->combine_queue[$type]);
+ }
}
+ return $buf;
}
/**
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php
index 23368a6a..525e1695 100644
--- a/modules/gallery/libraries/IdentityProvider.php
+++ b/modules/gallery/libraries/IdentityProvider.php
@@ -81,7 +81,8 @@ class IdentityProvider_Core {
module::set_var("gallery", "identity_provider", $new_provider);
- if (method_exists("{$new_provider}_installer", "initialize")) {
+ if (class_exists("{$new_provider}_installer") &&
+ method_exists("{$new_provider}_installer", "initialize")) {
call_user_func("{$new_provider}_installer::initialize");
}
diff --git a/modules/gallery/libraries/SafeString.php b/modules/gallery/libraries/SafeString.php
index 31e9d31b..179cbd41 100644
--- a/modules/gallery/libraries/SafeString.php
+++ b/modules/gallery/libraries/SafeString.php
@@ -153,7 +153,7 @@ class SafeString_Core {
* Purify the string, removing any potentially malicious or unsafe HTML / JavaScript.
*/
private static function _purify_for_html($dirty_html) {
- if (method_exists("purifier", "purify")) {
+ if (class_exists("purifier") && method_exists("purifier", "purify")) {
return purifier::purify($dirty_html);
} else {
return self::_escape_for_html($dirty_html);
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php
index 986fc8a2..fbc58258 100644
--- a/modules/gallery/libraries/Theme_View.php
+++ b/modules/gallery/libraries/Theme_View.php
@@ -58,23 +58,37 @@ class Theme_View_Core extends Gallery_View {
}
/**
- * Proportion of the current thumb_size's to default
+ * Proportion of the current thumb_size's to default.
+ *
+ * Themes can optionally use the $dimension parameter to choose which of the album's
+ * children will be used to determine the proportion. If set, the proportion will be
+ * calculated based on the child item with the largest width or height.
+ *
* @param object Item_Model (optional) check the proportions for this item
+ * @param int (optional) minimum thumbnail width
+ * @param string (optional) "width" or "height"
* @return int
*/
- public function thumb_proportion($item=null) {
- // If the item is an album with children, grab the first item in that album instead. We're
+ public function thumb_proportion($item=null, $minimum_size=0, $dimension=null) {
+ if (!in_array($dimension, array("height", "width"))) {
+ $dimension = null;
+ }
+
+ // If the item is an album with children, grab an item from that album instead. We're
// interested in the size of the thumbnails in this album, not the thumbnail of the
// album itself.
if ($item && $item->is_album() && $item->children_count()) {
- $item = $item->children(1)->current();
+ $orderBy = (is_null($dimension)) ? array()
+ : array("thumb_".$dimension => "desc");
+
+ $item = $item->children(1, null, array(), $orderBy)->current();
}
// By default we have a globally fixed thumbnail size In core code, we just return a fixed
// proportion based on the global thumbnail size, but since modules can override that, we
// return the actual proportions when we have them.
if ($item && $item->has_thumb()) {
- return max($item->thumb_width, $item->thumb_height) / 200;
+ return max($item->thumb_width, $item->thumb_height, $minimum_size) / 200;
} else {
// @TODO change the 200 to a theme supplied value when and if we come up with an
// API to allow the theme to set defaults.
@@ -89,7 +103,7 @@ class Theme_View_Core extends Gallery_View {
public function siblings($limit=null, $offset=null) {
return call_user_func_array(
$this->siblings_callback[0],
- array_merge($this->siblings_callback[1], array($offset, $limit)));
+ array_merge($this->siblings_callback[1], array($limit, $offset)));
}
public function tag() {
@@ -239,7 +253,7 @@ class Theme_View_Core extends Gallery_View {
continue;
}
$helper_class = "{$module->name}_theme";
- if (method_exists($helper_class, $function)) {
+ if (class_exists($helper_class) && method_exists($helper_class, $function)) {
$blocks[] = call_user_func_array(
array($helper_class, $function),
array_merge(array($this), $args));
@@ -247,7 +261,7 @@ class Theme_View_Core extends Gallery_View {
}
$helper_class = theme::$site_theme_name . "_theme";
- if (method_exists($helper_class, $function)) {
+ if (class_exists($helper_class) && method_exists($helper_class, $function)) {
$blocks[] = call_user_func_array(
array($helper_class, $function),
array_merge(array($this), $args));