summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/MY_url.php10
-rw-r--r--modules/gallery/helpers/access.php153
-rw-r--r--modules/gallery/helpers/album.php13
-rw-r--r--modules/gallery/helpers/auth.php2
-rw-r--r--modules/gallery/helpers/gallery_block.php15
-rw-r--r--modules/gallery/helpers/gallery_event.php69
-rw-r--r--modules/gallery/helpers/gallery_graphics.php2
-rw-r--r--modules/gallery/helpers/gallery_rest.php248
-rw-r--r--modules/gallery/helpers/gallery_rss.php12
-rw-r--r--modules/gallery/helpers/gallery_task.php6
-rw-r--r--modules/gallery/helpers/graphics.php76
-rw-r--r--modules/gallery/helpers/identity.php6
-rw-r--r--modules/gallery/helpers/item.php31
-rw-r--r--modules/gallery/helpers/l10n_client.php17
-rw-r--r--modules/gallery/helpers/l10n_scanner.php12
-rw-r--r--modules/gallery/helpers/locales.php6
-rw-r--r--modules/gallery/helpers/model_cache.php4
-rw-r--r--modules/gallery/helpers/module.php92
-rw-r--r--modules/gallery/helpers/movie.php13
-rw-r--r--modules/gallery/helpers/photo.php13
-rw-r--r--modules/gallery/helpers/site_status.php8
-rw-r--r--modules/gallery/helpers/task.php8
-rw-r--r--modules/gallery/helpers/theme.php7
23 files changed, 564 insertions, 259 deletions
diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php
index 139aec21..74284951 100644
--- a/modules/gallery/helpers/MY_url.php
+++ b/modules/gallery/helpers/MY_url.php
@@ -32,7 +32,7 @@ class url extends url_Core {
}
$item = self::get_item_from_uri(Router::$current_uri);
- if ($item && $item->loaded) {
+ if ($item && $item->loaded()) {
Router::$controller = "{$item->type}s";
Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php";
Router::$method = "show";
@@ -51,12 +51,12 @@ class url extends url_Core {
// In most cases, we'll have an exact match in the relative_url_cache item field.
// but failing that, walk down the tree until we find it. The fallback code will fix caches
// as it goes, so it'll never be run frequently.
- $item = ORM::factory("item")->where("relative_url_cache", $current_uri)->find();
- if (!$item->loaded) {
+ $item = ORM::factory("item")->where("relative_url_cache", "=", $current_uri)->find();
+ if (!$item->loaded()) {
$count = count(Router::$segments);
foreach (ORM::factory("item")
- ->where("slug", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES))
- ->where("level", $count + 1)
+ ->where("slug", "=", html_entity_decode(Router::$segments[$count - 1], ENT_QUOTES))
+ ->where("level", "=", $count + 1)
->find_all() as $match) {
if ($match->relative_url() == $current_uri) {
$item = $match;
diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php
index 88a02ce2..8ce7e436 100644
--- a/modules/gallery/helpers/access.php
+++ b/modules/gallery/helpers/access.php
@@ -91,7 +91,7 @@ class access_Core {
* @return boolean
*/
static function user_can($user, $perm_name, $item) {
- if (!$item->loaded) {
+ if (!$item->loaded()) {
return false;
}
@@ -101,7 +101,7 @@ class access_Core {
$resource = $perm_name == "view" ?
$item : model_cache::get("access_cache", $item->id, "item_id");
- foreach ($user->groups as $group) {
+ foreach ($user->groups() as $group) {
if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) {
return true;
}
@@ -166,16 +166,16 @@ class access_Core {
// For view permissions, if any parent is self::DENY, then those parents lock this one.
// Return
$lock = ORM::factory("item")
- ->where("`left_ptr` <= $item->left_ptr")
- ->where("`right_ptr` >= $item->right_ptr")
- ->where("items.id <> $item->id")
+ ->where("left_ptr", "<=", $item->left_ptr)
+ ->where("right_ptr", ">=", $item->right_ptr)
+ ->where("items.id", "<>", $item->id)
->join("access_intents", "items.id", "access_intents.item_id")
- ->where("access_intents.view_$group->id", self::DENY)
- ->orderby("level", "DESC")
+ ->where("access_intents.view_$group->id", "=", self::DENY)
+ ->order_by("level", "DESC")
->limit(1)
->find();
- if ($lock->loaded) {
+ if ($lock->loaded()) {
return $lock;
} else {
return null;
@@ -201,7 +201,7 @@ class access_Core {
if (!($group instanceof Group_Definition)) {
throw new Exception("@todo PERMISSIONS_ONLY_WORK_ON_GROUPS");
}
- if (!$album->loaded) {
+ if (!$album->loaded()) {
throw new Exception("@todo INVALID_ALBUM $album->id");
}
if (!$album->is_album()) {
@@ -282,7 +282,7 @@ class access_Core {
*/
static function register_permission($name, $display_name) {
$permission = ORM::factory("permission", $name);
- if ($permission->loaded) {
+ if ($permission->loaded()) {
throw new Exception("@todo PERMISSION_ALREADY_EXISTS $name");
}
$permission->name = $name;
@@ -304,8 +304,8 @@ class access_Core {
foreach (self::_get_all_groups() as $group) {
self::_drop_columns($name, $group);
}
- $permission = ORM::factory("permission")->where("name", $name)->find();
- if ($permission->loaded) {
+ $permission = ORM::factory("permission")->where("name", "=", $name)->find();
+ if ($permission->loaded()) {
$permission->delete();
}
}
@@ -342,7 +342,7 @@ class access_Core {
*/
static function add_item($item) {
$access_intent = ORM::factory("access_intent", $item->id);
- if ($access_intent->loaded) {
+ if ($access_intent->loaded()) {
throw new Exception("@todo ITEM_ALREADY_ADDED $item->id");
}
$access_intent = ORM::factory("access_intent");
@@ -354,7 +354,7 @@ class access_Core {
$access_cache->item_id = $item->id;
if ($item->id != 1) {
$parent_access_cache =
- ORM::factory("access_cache")->where("item_id", $item->parent()->id)->find();
+ ORM::factory("access_cache")->where("item_id", "=", $item->parent()->id)->find();
foreach (self::_get_all_groups() as $group) {
foreach (ORM::factory("permission")->find_all() as $perm) {
$field = "{$perm->name}_{$group->id}";
@@ -377,8 +377,8 @@ class access_Core {
* @return void
*/
static function delete_item($item) {
- ORM::factory("access_intent")->where("item_id", $item->id)->find()->delete();
- ORM::factory("access_cache")->where("item_id", $item->id)->find()->delete();
+ ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->delete();
+ ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->delete();
}
/**
@@ -419,8 +419,8 @@ class access_Core {
* @return ORM_Iterator
*/
private static function _get_all_groups() {
- // When we build the gallery package, it's possible that there is no identity provider installed yet.
- // This is ok at packaging time, so work around it.
+ // When we build the gallery package, it's possible that there is no identity provider
+ // installed yet. This is ok at packaging time, so work around it.
if (module::is_active(module::get_var("gallery", "identity_provider", "user"))) {
return identity::groups();
} else {
@@ -436,11 +436,10 @@ class access_Core {
* @return void
*/
private static function _drop_columns($perm_name, $group) {
- $db = Database::instance();
$field = "{$perm_name}_{$group->id}";
$cache_table = $perm_name == "view" ? "items" : "access_caches";
- $db->query("ALTER TABLE {{$cache_table}} DROP `$field`");
- $db->query("ALTER TABLE {access_intents} DROP `$field`");
+ Database::instance()->query("ALTER TABLE {{$cache_table}} DROP `$field`");
+ Database::instance()->query("ALTER TABLE {access_intents} DROP `$field`");
model_cache::clear();
ORM::factory("access_intent")->clear_cache();
}
@@ -453,13 +452,18 @@ class access_Core {
* @return void
*/
private static function _add_columns($perm_name, $group) {
- $db = Database::instance();
$field = "{$perm_name}_{$group->id}";
$cache_table = $perm_name == "view" ? "items" : "access_caches";
$not_null = $cache_table == "items" ? "" : "NOT NULL";
- $db->query("ALTER TABLE {{$cache_table}} ADD `$field` BINARY $not_null DEFAULT FALSE");
- $db->query("ALTER TABLE {access_intents} ADD `$field` BINARY DEFAULT NULL");
- $db->update("access_intents", array($field => self::DENY), array("item_id" => 1));
+ Database::instance()->query(
+ "ALTER TABLE {{$cache_table}} ADD `$field` BINARY $not_null DEFAULT FALSE");
+ Database::instance()->query(
+ "ALTER TABLE {access_intents} ADD `$field` BINARY DEFAULT NULL");
+ db::build()
+ ->update("access_intents")
+ ->set($field, self::DENY)
+ ->where("item_id", "=", 1)
+ ->execute();
model_cache::clear();
ORM::factory("access_intent")->clear_cache();
}
@@ -475,9 +479,7 @@ class access_Core {
* @return void
*/
private static function _update_access_view_cache($group, $item) {
- $access = ORM::factory("access_intent")->where("item_id", $item->id)->find();
-
- $db = Database::instance();
+ $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find();
$field = "view_{$group->id}";
// With view permissions, deny values in the parent can override allow values in the child,
@@ -490,14 +492,14 @@ class access_Core {
// item, then its safe to propagate from here.
if ($access->$field !== self::DENY) {
$tmp_item = ORM::factory("item")
- ->where("left_ptr <", $item->left_ptr)
- ->where("right_ptr >", $item->right_ptr)
+ ->where("left_ptr", "<", $item->left_ptr)
+ ->where("right_ptr", ">", $item->right_ptr)
->join("access_intents", "access_intents.item_id", "items.id")
- ->where("access_intents.$field", self::DENY)
- ->orderby("left_ptr", "DESC")
+ ->where("access_intents.$field", "=", self::DENY)
+ ->order_by("left_ptr", "DESC")
->limit(1)
->find();
- if ($tmp_item->loaded) {
+ if ($tmp_item->loaded()) {
$item = $tmp_item;
}
}
@@ -506,35 +508,53 @@ class access_Core {
// access_caches table will already contain DENY values and we won't be able to overwrite
// them according the rule above. So mark every permission below this level as UNKNOWN so
// that we can tell which permissions have been changed, and which ones need to be updated.
- $db->update("items", array($field => self::UNKNOWN),
- array("left_ptr >=" => $item->left_ptr, "right_ptr <=" => $item->right_ptr));
+ db::build()
+ ->update("items")
+ ->set($field, self::UNKNOWN)
+ ->where("left_ptr", ">=", $item->left_ptr)
+ ->where("right_ptr", "<=", $item->right_ptr)
+ ->execute();
$query = ORM::factory("access_intent")
->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr", "items.id"))
->join("items", "items.id", "access_intents.item_id")
- ->where("left_ptr >=", $item->left_ptr)
- ->where("right_ptr <=", $item->right_ptr)
- ->where("type", "album")
- ->where("access_intents.$field IS NOT", self::INHERIT)
- ->orderby("level", "DESC")
+ ->where("left_ptr", ">=", $item->left_ptr)
+ ->where("right_ptr", "<=", $item->right_ptr)
+ ->where("type", "=", "album")
+ ->where("access_intents.$field", "IS NOT", self::INHERIT)
+ ->order_by("level", "DESC")
->find_all();
foreach ($query as $row) {
if ($row->$field == self::ALLOW) {
// Propagate ALLOW for any row that is still UNKNOWN.
- $db->update("items", array($field => $row->$field),
- array($field => self::UNKNOWN, "left_ptr >=" => $row->left_ptr, "right_ptr <=" => $row->right_ptr));
+ db::build()
+ ->update("items")
+ ->set($field, $row->$field)
+ ->where($field, "IS", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS
+ ->where("left_ptr", ">=", $row->left_ptr)
+ ->where("right_ptr", "<=", $row->right_ptr)
+ ->execute();
} else if ($row->$field == self::DENY) {
// DENY overwrites everything below it
- $db->update("items", array($field => $row->$field),
- array("left_ptr >=" => $row->left_ptr, "right_ptr <=" => $row->right_ptr));
+ db::build()
+ ->update("items")
+ ->set($field, $row->$field)
+ ->where("left_ptr", ">=", $row->left_ptr)
+ ->where("right_ptr", "<=", $row->right_ptr)
+ ->execute();
}
}
// Finally, if our intent is DEFAULT at this point it means that we were unable to find a
// DENY parent in the hierarchy to propagate from. So we'll still have a UNKNOWN values in
// the hierarchy, and all of those are safe to change to ALLOW.
- $db->update("items", array($field => self::ALLOW),
- array($field => self::UNKNOWN, "left_ptr >=" => $item->left_ptr, "right_ptr <=" => $item->right_ptr));
+ db::build()
+ ->update("items")
+ ->set($field, self::ALLOW)
+ ->where($field, "IS", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS
+ ->where("left_ptr", ">=", $item->left_ptr)
+ ->where("right_ptr", "<=", $item->right_ptr)
+ ->execute();
}
/**
@@ -549,9 +569,8 @@ class access_Core {
* @return void
*/
private static function _update_access_non_view_cache($group, $perm_name, $item) {
- $access = ORM::factory("access_intent")->where("item_id", $item->id)->find();
+ $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find();
- $db = Database::instance();
$field = "{$perm_name}_{$group->id}";
// If the item's intent is DEFAULT, then we need to back up the chain to find the nearest
@@ -562,13 +581,13 @@ class access_Core {
if ($access->$field === self::INHERIT) {
$tmp_item = ORM::factory("item")
->join("access_intents", "items.id", "access_intents.item_id")
- ->where("left_ptr <", $item->left_ptr)
- ->where("right_ptr >", $item->right_ptr)
- ->where("$field IS NOT", self::UNKNOWN)
- ->orderby("left_ptr", "DESC")
+ ->where("left_ptr", "<", $item->left_ptr)
+ ->where("right_ptr", ">", $item->right_ptr)
+ ->where($field, "IS NOT", self::UNKNOWN) // UNKNOWN is NULL so we have to use IS NOT
+ ->order_by("left_ptr", "DESC")
->limit(1)
->find();
- if ($tmp_item->loaded) {
+ if ($tmp_item->loaded()) {
$item = $tmp_item;
}
}
@@ -578,19 +597,23 @@ class access_Core {
$query = ORM::factory("access_intent")
->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr"))
->join("items", "items.id", "access_intents.item_id")
- ->where("left_ptr >=", $item->left_ptr)
- ->where("right_ptr <=", $item->right_ptr)
- ->where("$field IS NOT", self::INHERIT)
- ->orderby("level", "ASC")
+ ->where("left_ptr", ">=", $item->left_ptr)
+ ->where("right_ptr", "<=", $item->right_ptr)
+ ->where($field, "IS NOT", self::INHERIT)
+ ->order_by("level", "ASC")
->find_all();
- foreach ($query as $row) {
- $value = ($row->$field === self::ALLOW) ? "TRUE" : "FALSE";
- $db->query(
- "UPDATE {access_caches} SET `$field` = $value " .
- "WHERE `item_id` IN " .
- " (SELECT `id` FROM {items} " .
- " WHERE `left_ptr` >= $row->left_ptr " .
- " AND `right_ptr` <= $row->right_ptr)");
+ foreach ($query as $row) {
+ $value = ($row->$field === self::ALLOW) ? true : false;
+ db::build()
+ ->update("access_caches")
+ ->set($field, $value)
+ ->where("item_id", "IN",
+ db::build()
+ ->select("id")
+ ->from("items")
+ ->where("left_ptr", ">=", $row->left_ptr)
+ ->where("right_ptr", "<=", $row->right_ptr))
+ ->execute();
}
}
diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php
index cc631be4..feaf74cc 100644
--- a/modules/gallery/helpers/album.php
+++ b/modules/gallery/helpers/album.php
@@ -34,7 +34,7 @@ class album_Core {
* @return Item_Model
*/
static function create($parent, $name, $title, $description=null, $owner_id=null, $slug=null) {
- if (!$parent->loaded || !$parent->is_album()) {
+ if (!$parent->loaded() || !$parent->is_album()) {
throw new Exception("@todo INVALID_PARENT");
}
@@ -68,11 +68,11 @@ class album_Core {
// Randomize the name or slug if there's a conflict
// @todo Improve this. Random numbers are not user friendly
while (ORM::factory("item")
- ->where("parent_id", $parent->id)
- ->open_paren()
- ->where("name", $album->name)
- ->orwhere("slug", $album->slug)
- ->close_paren()
+ ->where("parent_id", "=", $parent->id)
+ ->and_open()
+ ->where("name", "=", $album->name)
+ ->or_where("slug", "=", $album->slug)
+ ->close()
->find()->id) {
$rand = rand();
$album->name = "{$name}-$rand";
@@ -115,6 +115,7 @@ class album_Core {
static function get_edit_form($parent) {
$form = new Forge("albums/update/{$parent->id}", "", "post", array("id" => "g-edit-album-form"));
+ $form->hidden("from_id");
$group = $form->group("edit_item")->label(t("Edit Album"));
$group->input("title")->label(t("Title"))->value($parent->title);
diff --git a/modules/gallery/helpers/auth.php b/modules/gallery/helpers/auth.php
index 9c69cecd..21a39bfb 100644
--- a/modules/gallery/helpers/auth.php
+++ b/modules/gallery/helpers/auth.php
@@ -46,7 +46,7 @@ class auth_Core {
try {
Session::instance()->destroy();
} catch (Exception $e) {
- Kohana::log("error", $e);
+ Kohana_Log::add("error", $e);
}
module::event("user_logout", $user);
}
diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index b5c32ad2..9d4e81b6 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -34,7 +34,7 @@ class gallery_block_Core {
static function get($block_id) {
$block = new Block();
- switch($block_id) {
+ switch ($block_id) {
case "welcome":
$block->css_id = "g-welcome";
$block->title = t("Welcome to Gallery 3");
@@ -45,8 +45,8 @@ class gallery_block_Core {
$block->css_id = "g-photo-stream";
$block->title = t("Photo stream");
$block->content = new View("admin_block_photo_stream.html");
- $block->content->photos =
- ORM::factory("item")->where("type", "photo")->orderby("created", "DESC")->find_all(10);
+ $block->content->photos = ORM::factory("item")
+ ->where("type", "=", "photo")->order_by("created", "DESC")->find_all(10);
break;
case "log_entries":
@@ -54,7 +54,7 @@ class gallery_block_Core {
$block->title = t("Log entries");
$block->content = new View("admin_block_log_entries.html");
$block->content->entries = ORM::factory("log")
- ->orderby(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5);
+ ->order_by(array("timestamp" => "DESC", "id" => "DESC"))->find_all(5);
break;
case "stats":
@@ -62,8 +62,8 @@ class gallery_block_Core {
$block->title = t("Gallery stats");
$block->content = new View("admin_block_stats.html");
$block->content->album_count =
- ORM::factory("item")->where("type", "album")->where("id <>", 1)->count_all();
- $block->content->photo_count = ORM::factory("item")->where("type", "photo")->count_all();
+ ORM::factory("item")->where("type", "=", "album")->where("id", "<>", 1)->count_all();
+ $block->content->photo_count = ORM::factory("item")->where("type", "=", "photo")->count_all();
break;
case "platform_info":
@@ -101,8 +101,7 @@ class gallery_block_Core {
$block->css_id = "g-user-language-block";
$block->title = t("Language preference");
$block->content = new View("user_languages_block.html");
- $block->content->installed_locales =
- array_merge(array("" => t("« none »")), $locales);
+ $block->content->installed_locales = array_merge(array("" => t("« none »")), $locales);
$block->content->selected = (string) locales::cookie_locale();
} else {
$block = "";
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 02bfdf28..5565850d 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -30,36 +30,37 @@ class gallery_event_Core {
static function user_deleted($user) {
$admin = identity::admin_user();
- $db = Database::instance();
- $db->from("tasks")
- ->set(array("owner_id" => $admin->id))
- ->where(array("owner_id" => $user->id))
- ->update();
- $db->from("items")
- ->set(array("owner_id" => $admin->id))
- ->where(array("owner_id" => $user->id))
- ->update();
- $db->from("logs")
- ->set(array("user_id" => $admin->id))
- ->where(array("user_id" => $user->id))
- ->update();
+ db::build()
+ ->update("tasks")
+ ->set("owner_id", $admin->id)
+ ->where("owner_id", "=", $user->id)
+ ->execute();
+ db::build()
+ ->update("items")
+ ->set("owner_id", $admin->id)
+ ->where("owner_id", "=", $user->id)
+ ->execute();
+ db::build()
+ ->update("logs")
+ ->set("user_id", $admin->id)
+ ->where("user_id", "=", $user->id)
+ ->execute();
}
static function identity_provider_changed($old_provider, $new_provider) {
$admin = identity::admin_user();
- $db = Database::instance();
- $db->from("tasks")
- ->set(array("owner_id" => $admin->id))
- ->where("1 = 1")
- ->update();
- $db->from("items")
- ->set(array("owner_id" => $admin->id))
- ->where("1 = 1")
- ->update();
- $db->from("logs")
- ->set(array("user_id" => $admin->id))
- ->where("1 = 1")
- ->update();
+ db::build()
+ ->update("tasks")
+ ->set("owner_id", $admin->id)
+ ->execute();
+ db::build()
+ ->update("items")
+ ->set("owner_id", $admin->id)
+ ->execute();
+ db::build()
+ ->update("logs")
+ ->set("user_id", $admin->id)
+ ->execute();
}
static function group_created($group) {
@@ -108,6 +109,7 @@ class gallery_event_Core {
->label(t("Login")));
} else {
$csrf = access::csrf_token();
+ $item = $theme->item();
$menu->append(Menu::factory("dialog")
->id("user_menu_edit_profile")
->css_id("g-user-profile-link")
@@ -118,7 +120,7 @@ class gallery_event_Core {
->id("user_menu_logout")
->css_id("g-logout-link")
->url(url::site("logout?csrf=$csrf&amp;continue=" .
- urlencode(url::current(true))))
+ urlencode($item->url())))
->label(t("Logout")));
}
}
@@ -270,8 +272,6 @@ class gallery_event_Core {
->css_class("ui-icon-carat-1-n"));
if (access::can("edit", $item)) {
- $page_type = $theme->page_type();
- $page_subtype = $theme->page_subtype();
switch ($item->type) {
case "movie":
$edit_title = t("Edit this movie");
@@ -293,11 +293,12 @@ class gallery_event_Core {
$csrf = access::csrf_token();
+ $theme_item = $theme->item();
$options_menu->append(Menu::factory("dialog")
->id("edit")
->label($edit_title)
->css_class("ui-icon-pencil")
- ->url(url::site("quick/form_edit/$item->id?page_type=$page_type")));
+ ->url(url::site("quick/form_edit/$item->id?from_id=$theme_item->id")));
if ($item->is_photo() && graphics::can("rotate")) {
$options_menu
@@ -308,7 +309,7 @@ class gallery_event_Core {
->css_class("ui-icon-rotate-ccw")
->ajax_handler("function(data) { " .
"\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
- ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type")))
+ ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&from_id=$theme_item->id")))
->append(
Menu::factory("ajax_link")
->id("rotate_cw")
@@ -316,12 +317,12 @@ class gallery_event_Core {
->css_class("ui-icon-rotate-cw")
->ajax_handler("function(data) { " .
"\$.gallery_replace_image(data, \$('$thumb_css_selector')) }")
- ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type")));
+ ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id")));
}
// @todo Don't move photos from the photo page; we don't yet have a good way of redirecting
// after move
- if ($page_subtype == "album") {
+ if ($theme->page_subtype() == "album") {
$options_menu
->append(Menu::factory("dialog")
->id("move")
@@ -356,7 +357,7 @@ class gallery_event_Core {
->label($delete_title)
->css_class("ui-icon-trash")
->css_id("g-quick-delete")
- ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type")));
+ ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id")));
}
if ($item->is_album()) {
diff --git a/modules/gallery/helpers/gallery_graphics.php b/modules/gallery/helpers/gallery_graphics.php
index c24d2bde..ce08bbd7 100644
--- a/modules/gallery/helpers/gallery_graphics.php
+++ b/modules/gallery/helpers/gallery_graphics.php
@@ -123,7 +123,7 @@ class gallery_graphics_Core {
module::event("graphics_composite_completed", $input_file, $output_file, $options);
} catch (ErrorException $e) {
- Kohana::log("error", $e->get_message());
+ Kohana_Log::add("error", $e->get_message());
}
}
}
diff --git a/modules/gallery/helpers/gallery_rest.php b/modules/gallery/helpers/gallery_rest.php
new file mode 100644
index 00000000..a87ebb4e
--- /dev/null
+++ b/modules/gallery/helpers/gallery_rest.php
@@ -0,0 +1,248 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class gallery_rest_Core {
+ static function get($request) {
+ $path = implode("/", $request->arguments);
+
+ $item = gallery_rest::_get_item($path);
+
+ $parent = $item->parent();
+ $response_data = array("type" => $item->type,
+ "name" => $item->name,
+ "path" => $item->relative_url(),
+ "parent_path" => empty($parent) ? null : $parent->relative_url(),
+ "title" => $item->title,
+ "thumb_url" => $item->thumb_url(true),
+ "thumb_size" => array("height" => $item->thumb_height,
+ "width" => $item->thumb_width),
+ "resize_url" => $item->resize_url(true),
+ "resize_size" => array("height" => (int)$item->resize_height,
+ "width" => (int)$item->resize_width),
+ "url" => $item->file_url(true),
+ "size" => array("height" => $item->height,
+ "width" => $item->width),
+ "description" => $item->description,
+ "slug" => $item->slug);
+
+ $children = self::_get_children($item, $request);
+ if (!empty($children) || $item->is_album()) {
+ $response_data["children"] = $children;
+ }
+ return rest::success(array("resource" => $response_data));
+ }
+
+ static function put($request) {
+ if (empty($request->arguments)) {
+ throw new Rest_Exception(400, "Bad request");
+ }
+ $path = implode("/", $request->arguments);
+ $item = gallery_rest::_get_item($path, "edit");
+
+ // Validate the request data
+ $new_values = gallery_rest::_validate($request, $item->parent_id, $item->id);
+ $errors = $new_values->errors();
+ if (empty($errors)) {
+ $item->title = $new_values->title;
+ $item->description = $new_values->description;
+ if ($item->id != 1) {
+ $item->rename($new_values->name);
+ }
+ $item->slug = $new_values->slug;
+ $item->save();
+
+ log::success("content", "Updated $item->type",
+ "<a href=\"{$item->type}s/$item->id\">view</a>");
+
+ return rest::success();
+ } else {
+ return rest::validation_error($errors);
+ }
+ }
+
+ static function post($request) {
+ if (empty($request->arguments)) {
+ throw new Rest_Exception(400, "Bad request");
+ }
+
+ $components = $request->arguments;
+ $name = urldecode(array_pop($components));
+
+ $parent = gallery_rest::_get_item(implode("/", $components), "edit");
+
+ // Validate the request data
+ $request->name = $name;
+ $new_values = gallery_rest::_validate($request, $parent->id);
+ $errors = $new_values->errors();
+ if (!empty($errors)) {
+ return rest::validation_error($errors);
+ }
+
+ if (empty($new_values["image"])) {
+ $new_item = album::create(
+ $parent,
+ $name,
+ empty($new_values["title"]) ? $name : $new_values["title"],
+ empty($new_values["description"]) ? null : $new_values["description"],
+ identity::active_user()->id,
+ empty($new_values["slug"]) ? $name : $new_values["slug"]);
+ $log_message = t("Added an album");
+ } else {
+ $temp_filename = upload::save("image");
+ $path_info = @pathinfo($temp_filename);
+ if (array_key_exists("extension", $path_info) &&
+ in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
+ $new_item =
+ movie::create($parent, $temp_filename, $new_values["name"], $new_values["title"]);
+ $log_message = t("Added a movie");
+ } else {
+ $new_item =
+ photo::create($parent, $temp_filename, $new_values["name"], $new_values["title"]);
+ $log_message = t("Added a photo");
+ }
+ }
+
+ log::success("content", $log_message, "<a href=\"{$new_item->type}s/$new_item->id\">view</a>");
+
+ return rest::success(array("path" => $new_item->relative_url()));
+ }
+
+ static function delete($request) {
+ if (empty($request->arguments)) {
+ throw new Rest_Exception(400, "Bad request");
+ }
+ $path = implode("/", $request->arguments);
+
+ $item = gallery_rest::_get_item($path, "edit");
+
+ if ($item->id == 1) {
+ throw new Rest_Exception(400, "Bad request");
+ }
+
+ $parent = $item->parent();
+ $item->delete();
+
+ if ($item->is_album()) {
+ $msg = t("Deleted album <b>%title</b>", array("title" => html::purify($item->title)));
+ } else {
+ $msg = t("Deleted photo <b>%title</b>", array("title" => html::purify($item->title)));
+ }
+ log::success("content", $msg);
+
+ return rest::success(array("resource" => array("parent_path" => $parent->relative_url())));
+ }
+
+ private static function _get_item($path, $permission="view") {
+ $item = url::get_item_from_uri($path);
+
+ if (!$item->loaded()) {
+ throw new Kohana_404_Exception();
+ }
+
+ if (!access::can($permission, $item)) {
+ throw new Kohana_404_Exception();
+ }
+
+ return $item;
+ }
+
+ private static function _get_children($item, $request) {
+ $children = array();
+ $limit = empty($request->limit) ? null : $request->limit;
+ $offset = empty($request->offset) ? null : $request->offset;
+ $where = empty($request->filter) ? array() : array("type" => $request->filter);
+ foreach ($item->viewable()->children($limit, $offset, $where) as $child) {
+ $children[] = array("type" => $child->type,
+ "has_children" => $child->children_count() > 0,
+ "path" => $child->relative_url(),
+ "thumb_url" => $child->thumb_url(true),
+ "thumb_dimensions" => array("width" => $child->thumb_width,
+ "height" => $child->thumb_height),
+ "has_thumb" => $child->has_thumb(),
+ "title" => $child->title);
+ }
+
+ return $children;
+ }
+
+ private static function _validate($request, $parent_id, $item_id=0) {
+ $item = ORM::factory("item", $item_id);
+
+ // Normalize the inputs so all fields have a value
+ $new_values = Validation::factory(array());
+ foreach ($item->form_rules as $field => $rule_set) {
+ if (isset($request->$field)) {
+ $new_values[$field] = $request->$field;
+ } else if (isset($item->$field)) {
+ $new_values[$field] = $item->$field;
+ }
+ foreach (explode("|", $rule_set) as $rule) {
+ $new_values->add_rules($field, $rule);
+ }
+ }
+ $name = $new_values["name"];
+ $new_values["title"] = empty($new_values["title"]) ? $name : $new_values["title"];
+ $new_values["description"] =
+ empty($new_values["description"]) ? null : $new_values["description"];
+ $new_values["slug"] = empty($new_values["slug"]) ? $name : $new_values["slug"];
+
+ if (!empty($request->image)) {
+ $new_values["image"] = $request->image;
+ $new_values->add_rules(
+ "image", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]");
+ }
+
+ if ($new_values->validate() && $item_id != 1) {
+ $errors = gallery_rest::_check_for_conflicts($parent_id, $item_id,
+ $new_values["name"], $new_values["slug"]);
+ if (!empty($errors)) {
+ !empty($errors["name_conflict"]) OR $new_values->add_error("name", "Duplicate name");
+ !empty($errors["slug_conflict"]) OR
+ $new_values->add_error("slug", "Duplicate Internet address");
+ }
+ }
+
+ return $new_values;
+ }
+
+ private static function _check_for_conflicts($parent_id, $item_id, $new_name, $new_slug) {
+ $errors = array();
+
+ if ($row = db::build()
+ ->select(array("name", "slug"))
+ ->from("items")
+ ->where("parent_id", "=", $parent_id)
+ ->where("id", "<>", $item_id)
+ ->and_open()
+ ->where("name", "=", $new_name)
+ ->or_where("slug", "=", $new_slug)
+ ->close()
+ ->execute()
+ ->current()) {
+ if ($row->name == $new_name) {
+ $errors["name_conflict"] = 1;
+ }
+ if ($row->slug == $new_slug) {
+ $errors["slug_conflict"] = 1;
+ }
+ }
+
+ return $errors;
+ }
+}
diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php
index 155edfb5..d422636f 100644
--- a/modules/gallery/helpers/gallery_rss.php
+++ b/modules/gallery/helpers/gallery_rss.php
@@ -29,14 +29,14 @@ class gallery_rss_Core {
case "latest":
$feed->children = ORM::factory("item")
->viewable()
- ->where("type !=", "album")
- ->orderby("created", "DESC")
+ ->where("type", "<>", "album")
+ ->order_by("created", "DESC")
->find_all($limit, $offset);
$all_children = ORM::factory("item")
->viewable()
- ->where("type !=", "album")
- ->orderby("created", "DESC");
+ ->where("type", "<>", "album")
+ ->order_by("created", "DESC");
$feed->max_pages = ceil($all_children->find_all()->count() / $limit);
$feed->title = t("Recent updates");
@@ -49,9 +49,9 @@ class gallery_rss_Core {
$feed->children = $item
->viewable()
- ->descendants($limit, $offset, array("type" => "photo"));
+ ->descendants($limit, $offset, array(array("type", "=", "photo")));
$feed->max_pages = ceil(
- $item->viewable()->descendants_count(array("type" => "photo")) / $limit);
+ $item->viewable()->descendants_count(array(array("type", "=", "photo"))) / $limit);
$feed->title = html::purify($item->title);
$feed->description = nl2br(html::purify($item->description));
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index e0b03682..3a705027 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -19,7 +19,7 @@
*/
class gallery_task_Core {
static function available_tasks() {
- $dirty_count = graphics::find_dirty_images_query()->count();
+ $dirty_count = graphics::find_dirty_images_query()->count_records();
$tasks = array();
$tasks[] = Task_Definition::factory()
->callback("gallery_task::rebuild_dirty_images")
@@ -47,7 +47,7 @@ class gallery_task_Core {
static function rebuild_dirty_images($task) {
$errors = array();
try {
- $result = graphics::find_dirty_images_query();
+ $result = graphics::find_dirty_images_query()->select("id")->execute();
$total_count = $task->get("total_count", $result->count());
$mode = $task->get("mode", "init");
if ($mode == "init") {
@@ -66,7 +66,7 @@ class gallery_task_Core {
}
$item = ORM::factory("item", $row->id);
- if ($item->loaded) {
+ if ($item->loaded()) {
try {
graphics::generate($item);
$completed++;
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index d6a2f00c..7577d7ac 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -61,9 +61,9 @@ class graphics_Core {
*/
static function remove_rule($module_name, $target, $operation) {
ORM::factory("graphics_rule")
- ->where("module_name", $module_name)
- ->where("target", $target)
- ->where("operation", $operation)
+ ->where("module_name", "=", $module_name)
+ ->where("target", "=", $target)
+ ->where("operation", "=", $operation)
->delete_all();
self::mark_dirty($target == "thumb", $target == "resize");
@@ -74,7 +74,10 @@ class graphics_Core {
* @param string $module_name
*/
static function remove_rules($module_name) {
- $status = Database::instance()->delete("graphics_rules", array("module_name" => $module_name));
+ $status = db::build()
+ ->delete("graphics_rules")
+ ->where("module_name", "=", $module_name)
+ ->execute();
if (count($status)) {
self::mark_dirty(true, true);
}
@@ -86,8 +89,11 @@ class graphics_Core {
* module it won't cause all of your images to suddenly require a rebuild.
*/
static function activate_rules($module_name) {
- Database::instance()
- ->update("graphics_rules",array("active" => true), array("module_name" => $module_name));
+ db::build()
+ ->update("graphics_rules")
+ ->set("active", true)
+ ->where("module_name", "=", $module_name)
+ ->execute();
}
/**
@@ -96,8 +102,11 @@ class graphics_Core {
* module it won't cause all of your images to suddenly require a rebuild.
*/
static function deactivate_rules($module_name) {
- Database::instance()
- ->update("graphics_rules",array("active" => false), array("module_name" => $module_name));
+ db::build()
+ ->update("graphics_rules")
+ ->set("active", false)
+ ->where("module_name", "=", $module_name)
+ ->execute();
}
/**
@@ -171,7 +180,7 @@ class graphics_Core {
} catch (Exception $e) {
// Something went wrong rebuilding the image. Leave it dirty and move on.
// @todo we should handle this better.
- Kohana::log("error", "Caught exception rebuilding image: {$item->title}\n" .
+ Kohana_Log::add("error", "Caught exception rebuilding image: {$item->title}\n" .
$e->getMessage() . "\n" . $e->getTraceAsString());
throw $e;
}
@@ -181,9 +190,9 @@ class graphics_Core {
if (empty(self::$_rules_cache[$target])) {
$rules = array();
foreach (ORM::factory("graphics_rule")
- ->where("target", $target)
- ->where("active", true)
- ->orderby("priority", "asc")
+ ->where("target", "=", $target)
+ ->where("active", "=", true)
+ ->order_by("priority", "asc")
->find_all() as $rule) {
$rules[] = (object)$rule->as_array();
}
@@ -197,11 +206,22 @@ class graphics_Core {
* @return Database_Result Query result
*/
static function find_dirty_images_query() {
- return Database::instance()->query(
- "SELECT `id` FROM {items} " .
- "WHERE ((`thumb_dirty` = 1 AND (`type` <> 'album' OR `album_cover_item_id` IS NOT NULL))" .
- " OR (`resize_dirty` = 1 AND `type` = 'photo')) " .
- " AND `id` != 1");
+ return db::build()
+ ->from("items")
+ ->and_open()
+ ->and_open()
+ ->where("thumb_dirty", "=", 1)
+ ->and_open()
+ ->where("type", "<>", "album")
+ ->or_where("album_cover_item_id", "IS NOT", null)
+ ->close()
+ ->or_open()
+ ->where("resize_dirty", "=", 1)
+ ->where("type", "=", "photo")
+ ->close()
+ ->close()
+ ->where("id", "<>", 1)
+ ->close();
}
/**
@@ -209,18 +229,18 @@ class graphics_Core {
*/
static function mark_dirty($thumbs, $resizes) {
if ($thumbs || $resizes) {
- $db = Database::instance();
- $fields = array();
+ $db = db::build()
+ ->update("items");
if ($thumbs) {
- $fields["thumb_dirty"] = 1;
+ $db->set("thumb_dirty", 1);
}
if ($resizes) {
- $fields["resize_dirty"] = 1;
+ $db->set("resize_dirty", 1);
}
- $db->update("items", $fields, true);
+ $db->execute();
}
- $count = self::find_dirty_images_query()->count();
+ $count = self::find_dirty_images_query()->count_records();
if ($count) {
site_status::warning(
t2("One of your photos is out of date. <a %attrs>Click here to fix it</a>",
@@ -371,18 +391,18 @@ class graphics_Core {
}
switch(module::get_var("gallery", "graphics_toolkit")) {
case "gd":
- Kohana::config_set("image.driver", "GD");
+ Kohana_Config::instance()->set("image.driver", "GD");
break;
case "imagemagick":
- Kohana::config_set("image.driver", "ImageMagick");
- Kohana::config_set(
+ Kohana_Config::instance()->set("image.driver", "ImageMagick");
+ Kohana_Config::instance()->set(
"image.params.directory", module::get_var("gallery", "graphics_toolkit_path"));
break;
case "graphicsmagick":
- Kohana::config_set("image.driver", "GraphicsMagick");
- Kohana::config_set(
+ Kohana_Config::instance()->set("image.driver", "GraphicsMagick");
+ Kohana_Config::instance()->set(
"image.params.directory", module::get_var("gallery", "graphics_toolkit_path"));
break;
}
diff --git a/modules/gallery/helpers/identity.php b/modules/gallery/helpers/identity.php
index 83ba9e1e..eae0ea3e 100644
--- a/modules/gallery/helpers/identity.php
+++ b/modules/gallery/helpers/identity.php
@@ -75,15 +75,15 @@ class identity_Core {
if (!$session->get("group_ids")) {
$ids = array();
- foreach ($user->groups as $group) {
+ foreach ($user->groups() as $group) {
$ids[] = $group->id;
}
$session->set("group_ids", $ids);
}
} catch (Exception $e) {
// Log it, so we at least have so notification that we swallowed the exception.
- Kohana::log("error", "Load_user Exception: " .
- $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "Load_user Exception: " .
+ $e->getMessage() . "\n" . $e->getTraceAsString());
try {
Session::instance()->destroy();
} catch (Exception $e) {
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index f8e6534e..f6181f8a 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -139,10 +139,10 @@ class item_Core {
// Guard against an empty result when we create the first item. It's unfortunate that we
// have to check this every time.
// @todo: figure out a better way to bootstrap the weight.
- $result = Database::instance()
+ $result = db::build()
->select("weight")->from("items")
- ->orderby("weight", "desc")->limit(1)
- ->get()->current();
+ ->order_by("weight", "desc")->limit(1)
+ ->execute()->current();
return ($result ? $result->weight : 0) + 1;
}
@@ -155,29 +155,12 @@ class item_Core {
$view_restrictions = array();
if (!identity::active_user()->admin) {
foreach (identity::group_ids_for_active_user() as $id) {
- // Separate the first restriction from the rest to make it easier for us to formulate
- // our where clause below
- if (empty($view_restrictions)) {
- $view_restrictions[0] = "items.view_$id";
- } else {
- $view_restrictions[1]["items.view_$id"] = access::ALLOW;
- }
+ $view_restrictions[] = array("items.view_$id", "=", access::ALLOW);
}
}
- switch (count($view_restrictions)) {
- case 0:
- break;
-
- case 1:
- $model->where($view_restrictions[0], access::ALLOW);
- break;
-
- default:
- $model->open_paren();
- $model->where($view_restrictions[0], access::ALLOW);
- $model->orwhere($view_restrictions[1]);
- $model->close_paren();
- break;
+
+ if (count($view_restrictions)) {
+ $model->and_open()->merge_or_where($view_restrictions)->close();
}
return $model;
diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php
index 3460cc65..fe70933d 100644
--- a/modules/gallery/helpers/l10n_client.php
+++ b/modules/gallery/helpers/l10n_client.php
@@ -80,11 +80,10 @@ class l10n_client_Core {
}
// @todo Batch requests (max request size)
- foreach (Database::instance()
+ foreach (db::build()
->select("key", "locale", "revision", "translation")
->from("incoming_translations")
- ->get()
- ->as_array() as $row) {
+ ->execute() as $row) {
if (!isset($request->messages->{$row->key})) {
$request->messages->{$row->key} = 1;
}
@@ -134,12 +133,14 @@ class l10n_client_Core {
// incoming_translations.message to be NULL?
$locale = $message_data->locale;
$entry = ORM::factory("incoming_translation")
- ->where(array("key" => $key, "locale" => $locale))
+ ->where("key", "=", $key)
+ ->where("locale", "=", $locale)
->find();
- if (!$entry->loaded) {
+ if (!$entry->loaded()) {
// @todo Load a message key -> message (text) dict into memory outside of this loop
$root_entry = ORM::factory("incoming_translation")
- ->where(array("key" => $key, "locale" => "root"))
+ ->where("key", "=", $key)
+ ->where("locale", "=", "root")
->find();
$entry->key = $key;
$entry->message = $root_entry->message;
@@ -166,10 +167,10 @@ class l10n_client_Core {
// @todo Batch requests (max request size)
// @todo include base_revision in submission / how to handle resubmissions / edit fights?
- foreach (Database::instance()
+ foreach (db::build()
->select("key", "message", "locale", "base_revision", "translation")
->from("outgoing_translations")
- ->get() as $row) {
+ ->execute() as $row) {
$key = $row->key;
if (!isset($request->{$key})) {
$request->{$key}->message = json_encode(unserialize($row->message));
diff --git a/modules/gallery/helpers/l10n_scanner.php b/modules/gallery/helpers/l10n_scanner.php
index a8059b3a..bb7cb449 100644
--- a/modules/gallery/helpers/l10n_scanner.php
+++ b/modules/gallery/helpers/l10n_scanner.php
@@ -28,22 +28,22 @@ class l10n_scanner_Core {
static function process_message($message, &$cache) {
if (empty($cache)) {
- foreach (Database::instance()
+ foreach (db::build()
->select("key")
->from("incoming_translations")
- ->where("locale", "root")
- ->get() as $row) {
+ ->where("locale", "=", "root")
+ ->execute() as $row) {
$cache[$row->key] = true;
}
}
- $key = I18n::get_message_key($message);
+ $key = Gallery_I18n::get_message_key($message);
if (array_key_exists($key, $cache)) {
return $cache[$key];
}
- $entry = ORM::factory("incoming_translation", array("key" => $key));
- if (!$entry->loaded) {
+ $entry = ORM::factory("incoming_translation")->where("key", "=", $key)->find();
+ if (!$entry->loaded()) {
$entry->key = $key;
$entry->message = serialize($message);
$entry->locale = "root";
diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php
index 2de029ff..8d76e333 100644
--- a/modules/gallery/helpers/locales.php
+++ b/modules/gallery/helpers/locales.php
@@ -125,13 +125,13 @@ class locales_Core {
if (empty(self::$locales)) {
self::_init_language_data();
}
- $locale or $locale = I18n::instance()->locale();
+ $locale or $locale = Gallery_I18n::instance()->locale();
return self::$locales["$locale"];
}
static function is_rtl($locale=null) {
- $locale or $locale = I18n::instance()->locale();
+ $locale or $locale = Gallery_I18n::instance()->locale();
list ($language, $territory) = explode('_', $locale . "_");
return in_array($language, array("he", "fa", "ar"));
}
@@ -233,7 +233,7 @@ class locales_Core {
}
// If we have any preference, override the site's default locale
if ($locale) {
- I18n::instance()->locale($locale);
+ Gallery_I18n::instance()->locale($locale);
}
}
diff --git a/modules/gallery/helpers/model_cache.php b/modules/gallery/helpers/model_cache.php
index a3e09862..302e42d9 100644
--- a/modules/gallery/helpers/model_cache.php
+++ b/modules/gallery/helpers/model_cache.php
@@ -22,8 +22,8 @@ class model_cache_Core {
static function get($model_name, $id, $field_name="id") {
if (TEST_MODE || empty(self::$cache->$model_name->$field_name->$id)) {
- $model = ORM::factory($model_name)->where($field_name, $id)->find();
- if (!$model->loaded) {
+ $model = ORM::factory($model_name)->where($field_name, "=", $id)->find();
+ if (!$model->loaded()) {
throw new Exception("@todo MISSING_MODEL $model_name:$id");
}
self::$cache->$model_name->$field_name->$id = $model;
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 50abdaae..6c7078a3 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -36,13 +36,13 @@ class module_Core {
*/
static function set_version($module_name, $version) {
$module = self::get($module_name);
- if (!$module->loaded) {
+ if (!$module->loaded()) {
$module->name = $module_name;
$module->active = $module_name == "gallery"; // only gallery is active by default
}
$module->version = $version;
$module->save();
- Kohana::log("debug", "$module_name: version is now $version");
+ Kohana_Log::add("debug", "$module_name: version is now $version");
}
/**
@@ -51,7 +51,7 @@ class module_Core {
*/
static function get($module_name) {
if (empty(self::$modules[$module_name])) {
- return ORM::factory("module", array("name" => $module_name));
+ return ORM::factory("module")->where("name", "=", $module_name)->find();
}
return self::$modules[$module_name];
}
@@ -126,9 +126,10 @@ class module_Core {
* @param string $module_name
*/
static function install($module_name) {
- $kohana_modules = Kohana::config("core.modules");
+ $config = Kohana_Config::instance();
+ $kohana_modules = $config->get("core.modules");
array_unshift($kohana_modules, MODPATH . $module_name);
- Kohana::config_set("core.modules", $kohana_modules);
+ $config->set("core.modules", $kohana_modules);
// Rebuild the include path so the module installer can benefit from auto loading
Kohana::include_paths(true);
@@ -142,7 +143,7 @@ class module_Core {
// Now the module is installed but inactive, so don't leave it in the active path
array_shift($kohana_modules);
- Kohana::config_set("core.modules", $kohana_modules);
+ $config->set("core.modules", $kohana_modules);
log::success(
"module", t("Installed module %module_name", array("module_name" => $module_name)));
@@ -193,9 +194,10 @@ class module_Core {
* @param string $module_name
*/
static function activate($module_name) {
- $kohana_modules = Kohana::config("core.modules");
+ $config = Kohana_Config::instance();
+ $kohana_modules = $config->get("core.modules");
array_unshift($kohana_modules, MODPATH . $module_name);
- Kohana::config_set("core.modules", $kohana_modules);
+ $config->set("core.modules", $kohana_modules);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "activate")) {
@@ -203,7 +205,7 @@ class module_Core {
}
$module = self::get($module_name);
- if ($module->loaded) {
+ if ($module->loaded()) {
$module->active = true;
$module->save();
}
@@ -230,7 +232,7 @@ class module_Core {
}
$module = self::get($module_name);
- if ($module->loaded) {
+ if ($module->loaded()) {
$module->active = false;
$module->save();
}
@@ -257,7 +259,7 @@ class module_Core {
graphics::remove_rules($module_name);
$module = self::get($module_name);
- if ($module->loaded) {
+ if ($module->loaded()) {
$module->delete();
}
module::load_modules();
@@ -290,8 +292,9 @@ class module_Core {
}
}
self::$active[] = $gallery; // put gallery last in the module list to match core.modules
- Kohana::config_set(
- "core.modules", array_merge($kohana_modules, Kohana::config("core.modules")));
+ $config = Kohana_Config::instance();
+ $config->set(
+ "core.modules", array_merge($kohana_modules, $config->get("core.modules")));
}
/**
@@ -363,21 +366,23 @@ class module_Core {
// We cache all vars in gallery._cache so that we can load all vars at once for
// performance.
if (empty(self::$var_cache)) {
- $row = Database::instance()
+ $row = db::build()
->select("value")
->from("vars")
- ->where(array("module_name" => "gallery", "name" => "_cache"))
- ->get()
+ ->where("module_name", "=", "gallery")
+ ->where("name", "=", "_cache")
+ ->execute()
->current();
if ($row) {
self::$var_cache = unserialize($row->value);
} else {
// gallery._cache doesn't exist. Create it now.
- foreach (Database::instance()
+ foreach (db::build()
->select("module_name", "name", "value")
->from("vars")
- ->orderby("module_name", "name")
- ->get() as $row) {
+ ->order_by("module_name")
+ ->order_by("name")
+ ->execute() as $row) {
if ($row->module_name == "gallery" && $row->name == "_cache") {
// This could happen if there's a race condition
continue;
@@ -407,33 +412,50 @@ class module_Core {
*/
static function set_var($module_name, $name, $value) {
$var = ORM::factory("var")
- ->where("module_name", $module_name)
- ->where("name", $name)
+ ->where("module_name", "=", $module_name)
+ ->where("name", "=", $name)
->find();
- if (!$var->loaded) {
+ if (!$var->loaded()) {
$var->module_name = $module_name;
$var->name = $name;
}
$var->value = $value;
$var->save();
- Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache"));
+ db::build()
+ ->delete("vars")
+ ->where("module_name", "=", "gallery")
+ ->where("name", "=", "_cache")
+ ->execute();
self::$var_cache = null;
}
/**
* Increment the value of a variable for this module
+ *
+ * Note: Frequently updating counters is very inefficient because it invalidates the cache value
+ * which has to be rebuilt every time we make a change.
+ *
+ * @todo Get rid of this and find an alternate approach for all callers (currently only Akismet)
+ *
+ * @deprecated
* @param string $module_name
* @param string $name
* @param string $increment (optional, default is 1)
*/
static function incr_var($module_name, $name, $increment=1) {
- Database::instance()->query(
- "UPDATE {vars} SET `value` = `value` + $increment " .
- "WHERE `module_name` = '$module_name' " .
- "AND `name` = '$name'");
-
- Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache"));
+ db::build()
+ ->update("vars")
+ ->set("value", new Database_Expression("`value` + $increment"))
+ ->where("module_name", "=", $module_name)
+ ->where("name", "=", $name)
+ ->execute();
+
+ db::build()
+ ->delete("vars")
+ ->where("module_name", "=", "gallery")
+ ->where("name", "=", "_cache")
+ ->execute();
self::$var_cache = null;
}
@@ -444,14 +466,18 @@ class module_Core {
*/
static function clear_var($module_name, $name) {
$var = ORM::factory("var")
- ->where("module_name", $module_name)
- ->where("name", $name)
+ ->where("module_name", "=", $module_name)
+ ->where("name", "=", $name)
->find();
- if ($var->loaded) {
+ if ($var->loaded()) {
$var->delete();
}
- Database::instance()->delete("vars", array("module_name" => "gallery", "name" => "_cache"));
+ db::build()
+ ->delete("vars")
+ ->where("module_name", "=", "gallery")
+ ->where("name", "=", "_cache")
+ ->execute();
self::$var_cache = null;
}
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index 20ac8592..01859924 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -36,7 +36,7 @@ class movie_Core {
*/
static function create($parent, $filename, $name, $title,
$description=null, $owner_id=null, $slug=null) {
- if (!$parent->loaded || !$parent->is_album()) {
+ if (!$parent->loaded() || !$parent->is_album()) {
throw new Exception("@todo INVALID_PARENT");
}
@@ -90,11 +90,11 @@ class movie_Core {
// Randomize the name if there's a conflict
// @todo Improve this. Random numbers are not user friendly
while (ORM::factory("item")
- ->where("parent_id", $parent->id)
- ->open_paren()
- ->where("name", $movie->name)
- ->orwhere("slug", $movie->slug)
- ->close_paren()
+ ->where("parent_id", "=", $parent->id)
+ ->and_open()
+ ->where("name", "=", $movie->name)
+ ->or_where("slug", "=", $movie->slug)
+ ->close()
->find()->id) {
$rand = rand();
$movie->name = "{$name}.$rand.{$pi['extension']}";
@@ -130,6 +130,7 @@ class movie_Core {
static function get_edit_form($movie) {
$form = new Forge("movies/update/$movie->id", "", "post", array("id" => "g-edit-movie-form"));
+ $form->hidden("from_id");
$group = $form->group("edit_item")->label(t("Edit Movie"));
$group->input("title")->label(t("Title"))->value($movie->title);
$group->textarea("description")->label(t("Description"))->value($movie->description);
diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php
index dab98436..4e20e610 100644
--- a/modules/gallery/helpers/photo.php
+++ b/modules/gallery/helpers/photo.php
@@ -36,7 +36,7 @@ class photo_Core {
*/
static function create($parent, $filename, $name, $title,
$description=null, $owner_id=null, $slug=null) {
- if (!$parent->loaded || !$parent->is_album()) {
+ if (!$parent->loaded() || !$parent->is_album()) {
throw new Exception("@todo INVALID_PARENT");
}
@@ -89,11 +89,11 @@ class photo_Core {
// Randomize the name or slug if there's a conflict
// @todo Improve this. Random numbers are not user friendly
while (ORM::factory("item")
- ->where("parent_id", $parent->id)
- ->open_paren()
- ->where("name", $photo->name)
- ->orwhere("slug", $photo->slug)
- ->close_paren()
+ ->where("parent_id", "=", $parent->id)
+ ->and_open()
+ ->where("name", "=", $photo->name)
+ ->or_where("slug", "=", $photo->slug)
+ ->close()
->find()->id) {
$rand = rand();
$photo->name = "{$name}.$rand.{$pi['extension']}";
@@ -139,6 +139,7 @@ class photo_Core {
static function get_edit_form($photo) {
$form = new Forge("photos/update/$photo->id", "", "post", array("id" => "g-edit-photo-form"));
+ $form->hidden("from_id");
$group = $form->group("edit_item")->label(t("Edit Photo"));
$group->input("title")->label(t("Title"))->value($photo->title);
$group->textarea("description")->label(t("Description"))->value($photo->description);
diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php
index 2b090776..04316fff 100644
--- a/modules/gallery/helpers/site_status.php
+++ b/modules/gallery/helpers/site_status.php
@@ -67,9 +67,9 @@ class site_status_Core {
*/
private static function _add($msg, $severity, $permanent_key) {
$message = ORM::factory("message")
- ->where("key", $permanent_key)
+ ->where("key", "=", $permanent_key)
->find();
- if (!$message->loaded) {
+ if (!$message->loaded()) {
$message->key = $permanent_key;
}
$message->severity = $severity;
@@ -82,8 +82,8 @@ class site_status_Core {
* @param string $permanent_key
*/
static function clear($permanent_key) {
- $message = ORM::factory("message")->where("key", $permanent_key)->find();
- if ($message->loaded) {
+ $message = ORM::factory("message")->where("key", "=", $permanent_key)->find();
+ if ($message->loaded()) {
$message->delete();
}
}
diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php
index dac5f9d3..4aa95f33 100644
--- a/modules/gallery/helpers/task.php
+++ b/modules/gallery/helpers/task.php
@@ -51,7 +51,7 @@ class task_Core {
static function cancel($task_id) {
$task = ORM::factory("task", $task_id);
- if (!$task->loaded) {
+ if (!$task->loaded()) {
throw new Exception("@todo MISSING_TASK");
}
$task->done = 1;
@@ -65,14 +65,14 @@ class task_Core {
static function remove($task_id) {
$task = ORM::factory("task", $task_id);
- if ($task->loaded) {
+ if ($task->loaded()) {
$task->delete();
}
}
static function run($task_id) {
$task = ORM::factory("task", $task_id);
- if (!$task->loaded) {
+ if (!$task->loaded()) {
throw new Exception("@todo MISSING_TASK");
}
@@ -84,7 +84,7 @@ class task_Core {
}
$task->save();
} catch (Exception $e) {
- Kohana::log("error", $e->__toString());
+ Kohana_Log::add("error", $e->__toString());
$task->log($e->__toString());
$task->state = "error";
$task->done = true;
diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php
index 247aa5c4..b836292f 100644
--- a/modules/gallery/helpers/theme.php
+++ b/modules/gallery/helpers/theme.php
@@ -39,7 +39,8 @@ class theme_Core {
$path = "/" . $input->get("kohana_uri");
}
- $modules = Kohana::config("core.modules");
+ $config = Kohana_Config::instance();
+ $modules = $config->get("core.modules");
self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7);
self::$site_theme_name = module::get_var("gallery", "active_site_theme");
if (self::$is_admin) {
@@ -58,13 +59,13 @@ class theme_Core {
if (file_exists(THEMEPATH . $override)) {
self::$site_theme_name = $override;
} else {
- Kohana::log("error", "Missing override theme: '$override'");
+ Kohana_Log::add("error", "Missing override theme: '$override'");
}
}
array_unshift($modules, THEMEPATH . self::$site_theme_name);
}
- Kohana::config_set("core.modules", $modules);
+ $config->set("core.modules", $modules);
}
static function get_edit_form_admin() {