summaryrefslogtreecommitdiff
path: root/modules/gallery/libraries
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-02-26 09:58:57 -0800
committerTim Almdal <tnalmdal@shaw.ca>2010-02-26 09:58:57 -0800
commitf28b80fcf43e02ca65f419eb6774321dc30a2a37 (patch)
tree34d3e44e5716751f71d10de623228bd541b487ae /modules/gallery/libraries
parent9f810150532a2511bfc5f03c9d24fd592d2f803f (diff)
parentb4922f4d176662976c9d2b249edf0e50a0cdfdf1 (diff)
Merge branch 'master' into talmdal_dev
Diffstat (limited to 'modules/gallery/libraries')
-rw-r--r--modules/gallery/libraries/Gallery_I18n.php46
-rw-r--r--modules/gallery/libraries/Menu.php17
-rw-r--r--modules/gallery/libraries/drivers/Cache/Database.php14
3 files changed, 57 insertions, 20 deletions
diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php
index ac0588e3..f1e77744 100644
--- a/modules/gallery/libraries/Gallery_I18n.php
+++ b/modules/gallery/libraries/Gallery_I18n.php
@@ -150,33 +150,44 @@ class Gallery_I18n_Core {
private function lookup($locale, $message) {
if (!isset($this->_cache[$locale])) {
- $this->_cache[$locale] = array();
- // TODO: Load data from locale file instead of the DB.
+ $this->_cache[$locale] = self::load_translations($locale);
+ }
+
+ $key = self::get_message_key($message);
+
+ if (isset($this->_cache[$locale][$key])) {
+ return $this->_cache[$locale][$key];
+ } else {
+ return null;
+ }
+ }
+
+ private static function load_translations($locale) {
+ $cache_key = "translation|" . $locale;
+ $cache = Cache::instance();
+ $translations = $cache->get($cache_key);
+ if (!isset($translations) || !is_array($translations)) {
+ $translations = array();
foreach (db::build()
->select("key", "translation")
->from("incoming_translations")
->where("locale", "=", $locale)
->execute() as $row) {
- $this->_cache[$locale][$row->key] = unserialize($row->translation);
+ $translations[$row->key] = unserialize($row->translation);
}
-
+
// Override incoming with outgoing...
foreach (db::build()
->select("key", "translation")
->from("outgoing_translations")
->where("locale", "=", $locale)
->execute() as $row) {
- $this->_cache[$locale][$row->key] = unserialize($row->translation);
+ $translations[$row->key] = unserialize($row->translation);
}
+
+ $cache->set($cache_key, $translations, array("translation"), 0);
}
-
- $key = self::get_message_key($message);
-
- if (isset($this->_cache[$locale][$key])) {
- return $this->_cache[$locale][$key];
- } else {
- return null;
- }
+ return $translations;
}
public function has_translation($message, $options=null) {
@@ -256,6 +267,15 @@ class Gallery_I18n_Core {
return $this->_call_log;
}
+ public static function clear_cache($locale=null) {
+ $cache = Cache::instance();
+ if ($locale) {
+ $cache->delete("translation|" . $locale);
+ } else {
+ $cache->delete_tag("translation");
+ }
+ }
+
private static function get_plural_key($locale, $count) {
$parts = explode('_', $locale);
$language = $parts[0];
diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php
index 7c76ab04..fef07916 100644
--- a/modules/gallery/libraries/Menu.php
+++ b/modules/gallery/libraries/Menu.php
@@ -184,7 +184,7 @@ class Menu_Core extends Menu_Element {
}
/**
- * Add a new element to this menu
+ * Add a new element to this menu, after the specific element
*/
public function add_after($target_id, $new_menu_element) {
$copy = array();
@@ -199,6 +199,21 @@ class Menu_Core extends Menu_Element {
}
/**
+ * Add a new element to this menu, before the specific element
+ */
+ public function add_before($target_id, $new_menu_element) {
+ $copy = array();
+ foreach ($this->elements as $id => $menu_element) {
+ if ($id == $target_id) {
+ $copy[$new_menu_element->id] = $new_menu_element;
+ }
+ $copy[$id] = $menu_element;
+ }
+ $this->elements = $copy;
+ return $this;
+ }
+
+ /**
* Remove an element from the menu
*/
public function remove($target_id) {
diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php
index 82a09ab9..ff982396 100644
--- a/modules/gallery/libraries/drivers/Cache/Database.php
+++ b/modules/gallery/libraries/drivers/Cache/Database.php
@@ -130,7 +130,7 @@ class Cache_Database_Driver extends Cache_Driver {
// Make sure the expiration is valid and that the hash matches
if ($cache->expiration != 0 && $cache->expiration <= time()) {
// Cache is not valid, delete it now
- $this->delete($cache->id);
+ $this->delete(array($cache->id));
} else {
// Disable notices for unserializing
$ER = error_reporting(~E_NOTICE);
@@ -153,15 +153,17 @@ class Cache_Database_Driver extends Cache_Driver {
* @param bool delete a tag
* @return bool
*/
- public function delete($id, $tag=false) {
+ public function delete($keys, $is_tag=false) {
$db = db::build()
->delete("caches");
- if ($id === true) {
+ if ($keys === true) {
// Delete all caches
- } else if ($tag === true) {
- $db->where("tags", "LIKE", "%<$id>%");
+ } else if ($is_tag === true) {
+ foreach ($keys as $tag) {
+ $db->where("tags", "LIKE", "%<$tag>%");
+ }
} else {
- $db->where("key", "=", $id);
+ $db->where("key", "IN", $keys);
}
$status = $db->execute();