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.php17
-rw-r--r--modules/gallery/libraries/Gallery_View.php61
-rw-r--r--modules/gallery/libraries/MY_View.php10
-rw-r--r--modules/gallery/libraries/Menu.php4
-rw-r--r--modules/gallery/libraries/ORM_MPTT.php22
-rw-r--r--modules/gallery/libraries/Theme_View.php24
-rw-r--r--modules/gallery/libraries/drivers/Cache/Database.php37
7 files changed, 86 insertions, 89 deletions
diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php
index 11f8ad14..1a633a34 100644
--- a/modules/gallery/libraries/Admin_View.php
+++ b/modules/gallery/libraries/Admin_View.php
@@ -34,11 +34,11 @@ class Admin_View_Core extends Gallery_View {
$this->theme_name = Input::instance()->get("theme", $this->theme_name);
}
$this->sidebar = "";
- $this->set_global("theme", $this);
- $this->set_global("user", identity::active_user());
- $this->set_global("page_type", "admin");
- $this->set_global("page_subtype", $name);
- $this->set_global("page_title", null);
+ $this->set_global(array("theme" => $this,
+ "user" => identity::active_user(),
+ "page_type" => "admin",
+ "page_subtype" => $name,
+ "page_title" => null));
}
public function admin_menu() {
@@ -46,7 +46,7 @@ class Admin_View_Core extends Gallery_View {
module::event("admin_menu", $menu, $this);
$settings_menu = $menu->get("settings_menu");
- sort($settings_menu->elements);
+ uasort($settings_menu->elements, array("Menu", "title_comparator"));
return $menu->render();
}
@@ -96,11 +96,6 @@ class Admin_View_Core extends Gallery_View {
}
}
- if ($function == "admin_head") {
- array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
- array_unshift($blocks, $this->combine_files($this->css, "css"));
- }
-
if (Session::instance()->get("debug")) {
if ($function != "admin_head") {
array_unshift(
diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php
index b45bb94a..8befda95 100644
--- a/modules/gallery/libraries/Gallery_View.php
+++ b/modules/gallery/libraries/Gallery_View.php
@@ -19,18 +19,35 @@
*/
class Gallery_View_Core extends View {
protected $theme_name = null;
- protected $scripts = array();
- protected $css = array();
+ protected $combine_queue = array();
/**
- * Add a script to the combined scripts list.
+ * 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) {
+ foreach (explode(",", $types) as $type) {
+ $this->combine_queue[$type] = array();
+ }
+ }
+
+ /**
+ * If script combining is enabled, add this script to the list of scripts that will be
+ * combined into a single script element. When combined, the order of scripts is preserved.
+ *
* @param $file the file name or path of the script to include. If a path is specified then
* it needs to be relative to DOCROOT. Just specifying a file name will result
* in searching Kohana's cascading file system.
+ * @param $group the group of scripts to combine this with. defaults to "core"
*/
- public function script($file) {
+ public function script($file, $group="core") {
if (($path = gallery::find_file("js", $file, false))) {
- $this->scripts[$path] = 1;
+ if (isset($this->combine_queue["script"])) {
+ $this->combine_queue["script"][$group][$path] = 1;
+ } else {
+ return html::script($path);
+ }
} else {
Kohana_Log::add("error", "Can't find script file: $file");
}
@@ -46,14 +63,22 @@ class Gallery_View_Core extends View {
}
/**
- * Add a css file to the combined css list.
- * @param $file the file name or path of the script to include. If a path is specified then
+ * If css combining is enabled, add this css to the list of css that will be
+ * combined into a single style element. When combined, the order of style elements
+ * is preserved.
+ *
+ * @param $file the file name or path of the css to include. If a path is specified then
* it needs to be relative to DOCROOT. Just specifying a file name will result
* in searching Kohana's cascading file system.
+ * @param $group the group of css to combine this with. defaults to "core"
*/
- public function css($file) {
+ public function css($file, $group="core") {
if (($path = gallery::find_file("css", $file, false))) {
- $this->css[$path] = 1;
+ if (isset($this->combine_queue["css"])) {
+ $this->combine_queue["css"][$group][$path] = 1;
+ } else {
+ return html::stylesheet($path);
+ }
} else {
Kohana_Log::add("error", "Can't find css file: $file");
}
@@ -61,11 +86,13 @@ 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
*/
- protected function combine_files($paths, $type) {
+ public function get_combined($type, $group="core") {
$links = array();
- if (empty($paths)) {
+ if (empty($this->combine_queue[$type][$group])) {
return;
}
@@ -73,7 +100,7 @@ class Gallery_View_Core extends View {
// entries.
$key = array(url::abs_file(""));
- foreach (array_keys($paths) 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]";
@@ -85,7 +112,7 @@ class Gallery_View_Core extends View {
if (empty($contents)) {
$contents = "";
- foreach (array_keys($paths) as $path) {
+ foreach (array_keys($this->combine_queue[$type][$group]) as $path) {
if ($type == "css") {
$contents .= "/* $path */\n" . $this->process_css($path) . "\n";
} else {
@@ -103,12 +130,12 @@ class Gallery_View_Core extends View {
}
}
+ unset($this->combine_queue[$type][$group]);
+
if ($type == "css") {
- return "<!-- LOOKING FOR YOUR CSS? It's all been combined into the link below -->\n" .
- html::stylesheet("combined/css/$key", "screen,print,projection", true);
+ return html::stylesheet("combined/css/$key", "screen,print,projection", true);
} else {
- return "<!-- LOOKING FOR YOUR JAVASCRIPT? It's all been combined into the link below -->\n" .
- html::script("combined/javascript/$key", true);
+ return html::script("combined/javascript/$key", true);
}
}
diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php
index ded77792..2230203a 100644
--- a/modules/gallery/libraries/MY_View.php
+++ b/modules/gallery/libraries/MY_View.php
@@ -23,8 +23,14 @@ class View extends View_Core {
/**
* Reimplement Kohana 2.3's View::set_global() functionality.
*/
- public function set_global($key, $value) {
- View::$global_data[$key] = $value;
+ public function set_global($key, $value = NULL) {
+ if (is_array($key)) {
+ foreach ($key as $key2 => $value) {
+ View::$global_data[$key2] = $value;
+ }
+ } else {
+ View::$global_data[$key] = $value;
+ }
}
public function is_set($key=null) {
diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php
index 58852a72..78b60196 100644
--- a/modules/gallery/libraries/Menu.php
+++ b/modules/gallery/libraries/Menu.php
@@ -250,4 +250,8 @@ class Menu_Core extends Menu_Element {
$view->menu = $this;
return $view;
}
+
+ static function title_comparator($a, $b) {
+ return strnatcasecmp((string)$a->label, (string)$b->label);
+ }
}
diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php
index f20fafa0..4556273c 100644
--- a/modules/gallery/libraries/ORM_MPTT.php
+++ b/modules/gallery/libraries/ORM_MPTT.php
@@ -54,12 +54,12 @@ class ORM_MPTT_Core extends ORM {
// Make a hole in the parent for this new item
db::build()
->update($this->table_name)
- ->set("left_ptr", new Database_Expression("`left_ptr` + 2"))
+ ->set("left_ptr", db::expr("`left_ptr` + 2"))
->where("left_ptr", ">=", $parent->right_ptr)
->execute();
db::build()
->update($this->table_name)
- ->set("right_ptr", new Database_Expression("`right_ptr` + 2"))
+ ->set("right_ptr", db::expr("`right_ptr` + 2"))
->where("right_ptr", ">=", $parent->right_ptr)
->execute();
$parent->right_ptr += 2;
@@ -109,12 +109,12 @@ class ORM_MPTT_Core extends ORM {
try {
db::build()
->update($this->table_name)
- ->set("left_ptr", new Database_Expression("`left_ptr` - 2"))
+ ->set("left_ptr", db::expr("`left_ptr` - 2"))
->where("left_ptr", ">", $this->right_ptr)
->execute();
db::build()
->update($this->table_name)
- ->set("right_ptr", new Database_Expression("`right_ptr` - 2"))
+ ->set("right_ptr", db::expr("`right_ptr` - 2"))
->where("right_ptr", ">", $this->right_ptr)
->execute();
} catch (Exception $e) {
@@ -253,7 +253,7 @@ class ORM_MPTT_Core extends ORM {
// Update the levels for the to-be-moved items
db::build()
->update($this->table_name)
- ->set("level", new Database_Expression("`level` + $level_delta"))
+ ->set("level", db::expr("`level` + $level_delta"))
->where("left_ptr", ">=", $original_left_ptr)
->where("right_ptr", "<=", $original_right_ptr)
->execute();
@@ -262,12 +262,12 @@ class ORM_MPTT_Core extends ORM {
// Make a hole in the target for the move
db::build()
->update($this->table_name)
- ->set("left_ptr", new Database_Expression("`left_ptr` + $size_of_hole"))
+ ->set("left_ptr", db::expr("`left_ptr` + $size_of_hole"))
->where("left_ptr", ">=", $target_right_ptr)
->execute();
db::build()
->update($this->table_name)
- ->set("right_ptr", new Database_Expression("`right_ptr` + $size_of_hole"))
+ ->set("right_ptr", db::expr("`right_ptr` + $size_of_hole"))
->where("right_ptr", ">=", $target_right_ptr)
->execute();
@@ -290,8 +290,8 @@ class ORM_MPTT_Core extends ORM {
$new_offset = $target->right_ptr - $left_ptr;
db::build()
->update($this->table_name)
- ->set("left_ptr", new Database_Expression("`left_ptr` + $new_offset"))
- ->set("right_ptr", new Database_Expression("`right_ptr` + $new_offset"))
+ ->set("left_ptr", db::expr("`left_ptr` + $new_offset"))
+ ->set("right_ptr", db::expr("`right_ptr` + $new_offset"))
->where("left_ptr", ">=", $left_ptr)
->where("right_ptr", "<=", $right_ptr)
->execute();
@@ -299,12 +299,12 @@ class ORM_MPTT_Core extends ORM {
// Close the hole in the source's parent after the move
db::build()
->update($this->table_name)
- ->set("left_ptr", new Database_Expression("`left_ptr` - $size_of_hole"))
+ ->set("left_ptr", db::expr("`left_ptr` - $size_of_hole"))
->where("left_ptr", ">", $right_ptr)
->execute();
db::build()
->update($this->table_name)
- ->set("right_ptr", new Database_Expression("`right_ptr` - $size_of_hole"))
+ ->set("right_ptr", db::expr("`right_ptr` - $size_of_hole"))
->where("right_ptr", ">", $right_ptr)
->execute();
} catch (Exception $e) {
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php
index d22bb03a..04784ca1 100644
--- a/modules/gallery/libraries/Theme_View.php
+++ b/modules/gallery/libraries/Theme_View.php
@@ -37,11 +37,11 @@ class Theme_View_Core extends Gallery_View {
}
$this->item = null;
$this->tag = null;
- $this->set_global("theme", $this);
- $this->set_global("user", identity::active_user());
- $this->set_global("page_type", $page_type);
- $this->set_global("page_subtype", $page_subtype);
- $this->set_global("page_title", null);
+ $this->set_global(array("theme" => $this,
+ "user" => identity::active_user(),
+ "page_type" => $page_type,
+ "page_subtype" => $page_subtype,
+ "page_title" => null));
if ($page_type == "collection") {
$this->set_global("thumb_proportion", $this->thumb_proportion());
}
@@ -236,13 +236,6 @@ class Theme_View_Core extends Gallery_View {
case "thumb_bottom":
case "thumb_info":
case "thumb_top":
- if ($function == "head") {
- // Stash any CSS we have already; that came from the theme and we want theme CSS to
- // override module CSs
- $save_css = $this->css;
- $this->css = array();
- }
-
$blocks = array();
if (method_exists("gallery_theme", $function)) {
switch (count($args)) {
@@ -281,13 +274,6 @@ class Theme_View_Core extends Gallery_View {
array_merge(array($this), $args));
}
- if ($function == "head") {
- // Merge the theme CSS/JS at the end
- $this->css = array_merge($this->css, $save_css);
- array_unshift($blocks, $this->combine_files($this->scripts, "javascript"));
- array_unshift($blocks, $this->combine_files($this->css, "css"));
- }
-
if (Session::instance()->get("debug")) {
if ($function != "head" && $function != "body_attributes") {
array_unshift(
diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php
index b7822811..2e773ca4 100644
--- a/modules/gallery/libraries/drivers/Cache/Database.php
+++ b/modules/gallery/libraries/drivers/Cache/Database.php
@@ -25,20 +25,6 @@ class Cache_Database_Driver extends Cache_Driver {
protected $db;
/**
- * Checks if a cache id is already set.
- *
- * @param string cache id
- * @return boolean
- */
- public function exists($id) {
- $count = db::build()
- ->where("key", "=", $id)
- ->where("expiration", ">=", time())
- ->count_records("caches");
- return $count > 0;
- }
-
- /**
* Sets a cache item to the given data, tags, and lifetime.
*
* @param array assoc array of key => value pairs
@@ -59,22 +45,15 @@ class Cache_Database_Driver extends Cache_Driver {
$lifetime += time();
}
+ $db = Database::instance();
+ $tags = $db->escape($tags);
foreach ($items as $id => $data) {
- if ($this->exists($id)) {
- $status = db::build()
- ->update("caches")
- ->set("tags", $tags)
- ->set("expiration", $lifetime)
- ->set("cache", serialize($data))
- ->where("key", "=", $id)
- ->execute();
- } else {
- $status = db::build()
- ->insert("caches")
- ->columns("key", "tags", "expiration", "cache")
- ->values($id, $tags, $lifetime, serialize($data))
- ->execute();
- }
+ $id = $db->escape($id);
+ $data = $db->escape(serialize($data));
+ $db->query("INSERT INTO {caches} (`key`, `tags`, `expiration`, `cache`)
+ VALUES ('$id', '$tags', $lifetime, '$data')
+ ON DUPLICATE KEY UPDATE `tags` = VALUES(tags), `expiration` = VALUES(expiration),
+ `cache` = VALUES(cache)");
}
return true;