summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/akismet/helpers/akismet.php4
-rw-r--r--modules/comment/controllers/admin_comments.php26
-rw-r--r--modules/comment/helpers/comment_block.php2
-rw-r--r--modules/comment/helpers/comment_event.php40
-rw-r--r--modules/comment/helpers/comment_rss.php6
-rw-r--r--modules/comment/helpers/comment_theme.php6
-rw-r--r--modules/comment/models/comment.php2
-rw-r--r--modules/comment/tests/Comment_Event_Test.php2
-rw-r--r--modules/comment/tests/Comment_Model_Test.php4
-rw-r--r--modules/digibug/controllers/digibug.php8
-rw-r--r--modules/exif/helpers/exif.php28
-rw-r--r--modules/exif/helpers/exif_event.php5
-rw-r--r--modules/exif/helpers/exif_task.php19
-rw-r--r--modules/exif/helpers/exif_theme.php6
-rw-r--r--modules/forge/libraries/Forge.php5
-rw-r--r--modules/forge/libraries/Form_Input.php14
-rw-r--r--modules/g2_import/helpers/g2_import.php16
-rw-r--r--modules/g2_import/helpers/g2_import_event.php5
-rw-r--r--modules/g2_import/helpers/g2_import_task.php4
-rw-r--r--modules/gallery/config/log_file.php11
-rw-r--r--modules/gallery/controllers/admin_advanced_settings.php3
-rw-r--r--modules/gallery/controllers/admin_maintenance.php36
-rw-r--r--modules/gallery/controllers/albums.php15
-rw-r--r--modules/gallery/controllers/combined.php6
-rw-r--r--modules/gallery/controllers/file_proxy.php10
-rw-r--r--modules/gallery/controllers/items.php4
-rw-r--r--modules/gallery/controllers/l10n_client.php20
-rw-r--r--modules/gallery/controllers/move.php4
-rw-r--r--modules/gallery/controllers/movies.php12
-rw-r--r--modules/gallery/controllers/permissions.php2
-rw-r--r--modules/gallery/controllers/photos.php14
-rw-r--r--modules/gallery/controllers/simple_uploader.php2
-rw-r--r--modules/gallery/helpers/MY_url.php10
-rw-r--r--modules/gallery/helpers/access.php74
-rw-r--r--modules/gallery/helpers/album.php12
-rw-r--r--modules/gallery/helpers/auth.php2
-rw-r--r--modules/gallery/helpers/gallery_block.php10
-rw-r--r--modules/gallery/helpers/gallery_event.php34
-rw-r--r--modules/gallery/helpers/gallery_graphics.php2
-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.php4
-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.php10
-rw-r--r--modules/gallery/helpers/locales.php6
-rw-r--r--modules/gallery/helpers/model_cache.php4
-rw-r--r--modules/gallery/helpers/module.php65
-rw-r--r--modules/gallery/helpers/movie.php12
-rw-r--r--modules/gallery/helpers/photo.php12
-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
-rw-r--r--modules/gallery/hooks/init_gallery.php4
-rw-r--r--modules/gallery/libraries/Gallery_I18n.php (renamed from modules/gallery/libraries/I18n.php)20
-rw-r--r--modules/gallery/libraries/Gallery_View.php6
-rw-r--r--modules/gallery/libraries/IdentityProvider.php4
-rw-r--r--modules/gallery/libraries/MY_Database.php27
-rw-r--r--modules/gallery/libraries/MY_Forge.php7
-rw-r--r--modules/gallery/libraries/MY_Kohana_Exception.php31
-rw-r--r--modules/gallery/libraries/MY_ORM.php10
-rw-r--r--modules/gallery/libraries/MY_View.php36
-rw-r--r--modules/gallery/libraries/ORM_MPTT.php146
-rw-r--r--modules/gallery/libraries/SafeString.php2
-rw-r--r--modules/gallery/libraries/Sendmail.php4
-rw-r--r--modules/gallery/libraries/drivers/Cache/Database.php121
-rw-r--r--modules/gallery/models/item.php82
-rw-r--r--modules/gallery/models/log.php2
-rw-r--r--modules/gallery/tests/Access_Helper_Test.php16
-rw-r--r--modules/gallery/tests/Cache_Test.php2
-rw-r--r--modules/gallery/tests/Database_Test.php49
-rw-r--r--modules/gallery/tests/Gallery_Installer_Test.php2
-rw-r--r--modules/gallery/tests/I18n_Test.php10
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php4
-rw-r--r--modules/gallery/tests/ORM_MPTT_Test.php4
-rw-r--r--modules/gallery/views/kohana_error_page.php2
-rw-r--r--modules/gallery_unit_test/controllers/gallery_unit_test.php2
-rw-r--r--modules/image_block/helpers/image_block_block.php12
-rw-r--r--modules/kohana23_compat/config/pagination.php25
-rw-r--r--modules/kohana23_compat/libraries/MY_Database_Builder.php31
-rw-r--r--modules/kohana23_compat/libraries/Pagination.php234
-rw-r--r--modules/notification/helpers/notification.php26
-rw-r--r--modules/notification/helpers/notification_event.php42
-rw-r--r--modules/organize/views/organize_tree.html.php2
-rw-r--r--modules/rss/controllers/rss.php2
-rw-r--r--modules/search/helpers/search.php18
-rw-r--r--modules/search/helpers/search_event.php2
-rw-r--r--modules/search/helpers/search_task.php12
-rw-r--r--modules/server_add/controllers/server_add.php14
-rw-r--r--modules/slideshow/helpers/slideshow_event.php2
-rw-r--r--modules/tag/controllers/admin_tags.php14
-rw-r--r--modules/tag/controllers/tags.php4
-rw-r--r--modules/tag/helpers/tag.php28
-rw-r--r--modules/tag/helpers/tag_event.php2
-rw-r--r--modules/tag/helpers/tag_rss.php4
-rw-r--r--modules/tag/models/tag.php31
-rw-r--r--modules/tag/tests/Tag_Test.php6
-rw-r--r--modules/user/controllers/admin_users.php6
-rw-r--r--modules/user/controllers/password.php2
-rw-r--r--modules/user/helpers/group.php6
-rw-r--r--modules/user/helpers/user.php6
-rw-r--r--modules/user/models/group.php4
-rw-r--r--modules/user/models/user.php4
-rw-r--r--modules/user/tests/User_Groups_Test.php8
105 files changed, 1172 insertions, 731 deletions
diff --git a/modules/akismet/helpers/akismet.php b/modules/akismet/helpers/akismet.php
index 43549ffa..46a305b2 100644
--- a/modules/akismet/helpers/akismet.php
+++ b/modules/akismet/helpers/akismet.php
@@ -166,7 +166,7 @@ class akismet_Core {
}
$response = "";
- Kohana::log("debug", "Send request\n" . print_r($http_request, 1));
+ Kohana_Log::add("debug", "Send request\n" . print_r($http_request, 1));
if (false !== ($fs = @fsockopen($host, 80, $errno, $errstr, 5))) {
fwrite($fs, $http_request);
while ( !feof($fs) ) {
@@ -181,7 +181,7 @@ class akismet_Core {
} else {
throw new Exception("@todo CONNECTION TO SPAM SERVICE FAILED");
}
- Kohana::log("debug", "Received response\n" . print_r($response, 1));
+ Kohana_Log::add("debug", "Received response\n" . print_r($response, 1));
return $response;
}
diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php
index 13532c4e..880c33a7 100644
--- a/modules/comment/controllers/admin_comments.php
+++ b/modules/comment/controllers/admin_comments.php
@@ -22,10 +22,11 @@ class Admin_Comments_Controller extends Admin_Controller {
public function index() {
// Get rid of old deleted/spam comments once in a while
- Database::instance()->query(
- "DELETE FROM {comments} " .
- "WHERE state IN ('deleted', 'spam') " .
- "AND unix_timestamp(now()) - updated > 86400 * 7");
+ db::build()
+ ->delete("comments")
+ ->where("state", "IN", array("deleted", "spam"))
+ ->where("updated", "<", "UNIX_TIMESTAMP() - 86400 * 7")
+ ->execute();
// Redirect to the appropriate queue
url::redirect("admin/comments/queue/unpublished");
@@ -48,8 +49,8 @@ class Admin_Comments_Controller extends Admin_Controller {
$view->content->menu = $this->_menu($view->content->counts);
$view->content->state = $state;
$view->content->comments = ORM::factory("comment")
- ->orderby("created", "DESC")
- ->where("state", $state)
+ ->order_by("created", "DESC")
+ ->where("state", "=", $state)
->limit(self::$items_per_page, ($page - 1) * self::$items_per_page)
->find_all();
$view->content->pager = new Pagination();
@@ -95,11 +96,12 @@ class Admin_Comments_Controller extends Admin_Controller {
$counts->published = 0;
$counts->spam = 0;
$counts->deleted = 0;
- foreach (Database::instance()
- ->select("state", "count(*) as c")
+ foreach (db::build()
+ ->select("state")
+ ->select(array("c" => 'COUNT("*")'))
->from("comments")
- ->groupby("state")
- ->get() as $row) {
+ ->group_by("state")
+ ->execute() as $row) {
$counts->{$row->state} = $row->c;
}
return $counts;
@@ -110,7 +112,7 @@ class Admin_Comments_Controller extends Admin_Controller {
$comment = ORM::factory("comment", $id);
$orig = clone $comment;
- if ($comment->loaded) {
+ if ($comment->loaded()) {
$comment->state = $state;
$comment->save();
}
@@ -120,7 +122,7 @@ class Admin_Comments_Controller extends Admin_Controller {
access::verify_csrf();
ORM::factory("comment")
- ->where("state", "spam")
+ ->where("state", "=", "spam")
->delete_all();
url::redirect("admin/comments/queue/spam");
}
diff --git a/modules/comment/helpers/comment_block.php b/modules/comment/helpers/comment_block.php
index 7cd5d429..ab86b90a 100644
--- a/modules/comment/helpers/comment_block.php
+++ b/modules/comment/helpers/comment_block.php
@@ -30,7 +30,7 @@ class comment_block_Core {
$block->title = t("Recent comments");
$block->content = new View("admin_block_recent_comments.html");
$block->content->comments =
- ORM::factory("comment")->orderby("created", "DESC")->limit(5)->find_all();
+ ORM::factory("comment")->order_by("created", "DESC")->limit(5)->find_all();
break;
}
diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php
index a72102b9..576e041d 100644
--- a/modules/comment/helpers/comment_event.php
+++ b/modules/comment/helpers/comment_event.php
@@ -19,29 +19,32 @@
*/
class comment_event_Core {
static function item_deleted($item) {
- Database::instance()->delete("comments", array("item_id" => $item->id));
+ db::build()
+ ->delete("comments")
+ ->where("item_id", "=", $item->id);
}
static function user_deleted($user) {
$guest = identity::guest();
- Database::instance()->from("comments")
- ->set(array("author_id" => $guest->id,
- "guest_email" => null,
- "guest_name" => "guest",
- "guest_url" => null))
- ->where(array("author_id" => $user->id))
- ->update();
+ db::build()
+ ->update("comments")
+ ->set("author_id", $guest->id)
+ ->set("guest_email", null)
+ ->set("guest_name", "guest")
+ ->set("guest_url", null)
+ ->where("author_id", "=", $user->id)
+ ->execute();
}
static function identity_provider_changed($old_provider, $new_provider) {
$guest = identity::guest();
- Database::instance()->from("comments")
- ->set(array("author_id" => $guest->id,
- "guest_email" => null,
- "guest_name" => "guest",
- "guest_url" => null))
- ->where("1 = 1")
- ->update();
+ db::build()
+ ->update("comments")
+ ->set("author_id", $guest->id)
+ ->set("guest_email", null)
+ ->set("guest_name", "guest")
+ ->set("guest_url", null)
+ ->execute();
}
static function admin_menu($menu, $theme) {
@@ -62,12 +65,11 @@ class comment_event_Core {
}
static function item_index_data($item, $data) {
- foreach (Database::instance()
+ foreach (db::build()
->select("text")
->from("comments")
- ->where("item_id", $item->id)
- ->get()
- ->as_array() as $row) {
+ ->where("item_id", "=", $item->id)
+ ->execute() as $row) {
$data[] = $row->text;
}
}
diff --git a/modules/comment/helpers/comment_rss.php b/modules/comment/helpers/comment_rss.php
index 3692a30d..77044884 100644
--- a/modules/comment/helpers/comment_rss.php
+++ b/modules/comment/helpers/comment_rss.php
@@ -35,11 +35,11 @@ class comment_rss_Core {
$comments = ORM::factory("comment")
->viewable()
- ->where("state", "published")
- ->orderby("created", "DESC");
+ ->where("state", "=", "published")
+ ->order_by("created", "DESC");
if ($feed_id == "item") {
- $comments->where("item_id", $id);
+ $comments->where("item_id", "=", $id);
}
$feed->view = "comment.mrss";
diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php
index af0e1ca4..ebcc1c42 100644
--- a/modules/comment/helpers/comment_theme.php
+++ b/modules/comment/helpers/comment_theme.php
@@ -37,9 +37,9 @@ class comment_theme_Core {
$view = new View("comments.html");
$view->comments = ORM::factory("comment")
- ->where("item_id", $theme->item()->id)
- ->where("state", "published")
- ->orderby("created", "ASC")
+ ->where("item_id", "=", $theme->item()->id)
+ ->where("state", "=", "published")
+ ->order_by("created", "ASC")
->find_all();
$block->content = $view;
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index bb9b8833..59b85233 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -59,7 +59,7 @@ class Comment_Model extends ORM {
public function save() {
if (!empty($this->changed)) {
$this->updated = time();
- if (!$this->loaded && empty($this->created)) {
+ if (!$this->loaded() && empty($this->created)) {
$this->created = $this->updated;
$created = true;
}
diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php
index f650cabf..ff7f1c26 100644
--- a/modules/comment/tests/Comment_Event_Test.php
+++ b/modules/comment/tests/Comment_Event_Test.php
@@ -27,6 +27,6 @@ class Comment_Event_Test extends Unit_Test_Case {
$album->delete();
$deleted_comment = ORM::factory("comment", $comment->id);
- $this->assert_false($deleted_comment->loaded);
+ $this->assert_false($deleted_comment->loaded());
}
}
diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php
index de19648d..aa91d6f2 100644
--- a/modules/comment/tests/Comment_Model_Test.php
+++ b/modules/comment/tests/Comment_Model_Test.php
@@ -29,12 +29,12 @@ class Comment_Model_Test extends Unit_Test_Case {
access::allow(identity::everybody(), "view", $album);
$this->assert_equal(
1,
- ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all());
+ ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
// We can't see the comment when permissions are denied on the album
access::deny(identity::everybody(), "view", $album);
$this->assert_equal(
0,
- ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all());
+ ORM::factory("comment")->viewable()->where("comments.id", "=", $comment->id)->count_all());
}
}
diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php
index 1bb2691b..25f1ca3e 100644
--- a/modules/digibug/controllers/digibug.php
+++ b/modules/digibug/controllers/digibug.php
@@ -61,7 +61,7 @@ class Digibug_Controller extends Controller {
if ($type == "full") {
$remote_addr = ip2long($this->input->server("REMOTE_ADDR"));
if ($remote_addr === false) {
- Kohana::show_404();
+ throw new Kohana_404_Exception();
}
$config = Kohana::config("digibug");
@@ -76,13 +76,13 @@ class Digibug_Controller extends Controller {
}
}
if (!$authorized) {
- Kohana::show_404();
+ throw new Kohana_404_Exception();
}
}
$proxy = ORM::factory("digibug_proxy", array("uuid" => $id));
- if (!$proxy->loaded || !$proxy->item->loaded) {
- Kohana::show_404();
+ if (!$proxy->loaded() || !$proxy->item->loaded()) {
+ throw new Kohana_404_Exception();
}
$file = $type == "full" ? $proxy->item->file_path() : $proxy->item->thumb_path();
diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php
index 5ddd09d4..3baed177 100644
--- a/modules/exif/helpers/exif.php
+++ b/modules/exif/helpers/exif.php
@@ -39,7 +39,7 @@ class exif_Core {
if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
$value = utf8_encode($value);
}
- $keys[$field] = utf8::clean($value);
+ $keys[$field] = Input::clean($value);
if ($field == "DateTime") {
$time = strtotime($value);
@@ -62,7 +62,7 @@ class exif_Core {
if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
$value = utf8_encode($value);
}
- $keys[$keyword] = utf8::clean($value);
+ $keys[$keyword] = Input::clean($value);
if ($keyword == "Caption" && !$item->description) {
$item->description = $value;
@@ -73,8 +73,8 @@ class exif_Core {
}
$item->save();
- $record = ORM::factory("exif_record")->where("item_id", $item->id)->find();
- if (!$record->loaded) {
+ $record = ORM::factory("exif_record")->where("item_id", "=", $item->id)->find();
+ if (!$record->loaded()) {
$record->item_id = $item->id;
}
$record->data = serialize($keys);
@@ -86,9 +86,9 @@ class exif_Core {
static function get($item) {
$exif = array();
$record = ORM::factory("exif_record")
- ->where("item_id", $item->id)
+ ->where("item_id", "=", $item->id)
->find();
- if (!$record->loaded) {
+ if (!$record->loaded()) {
return array();
}
@@ -139,19 +139,19 @@ class exif_Core {
}
static function stats() {
- $missing_exif = Database::instance()
+ $missing_exif = db::build()
->select("items.id")
->from("items")
->join("exif_records", "items.id", "exif_records.item_id", "left")
- ->where("type", "photo")
- ->open_paren()
- ->where("exif_records.item_id", null)
- ->orwhere("exif_records.dirty", 1)
- ->close_paren()
- ->get()
+ ->where("type", "=", "photo")
+ ->and_open()
+ ->where("exif_records.item_id", "IS", null)
+ ->or_where("exif_records.dirty", "=", 1)
+ ->close()
+ ->execute()
->count();
- $total_items = ORM::factory("item")->where("type", "photo")->count_all();
+ $total_items = ORM::factory("item")->where("type", "=", "photo")->count_all();
if (!$total_items) {
return array(0, 0, 0);
}
diff --git a/modules/exif/helpers/exif_event.php b/modules/exif/helpers/exif_event.php
index 826ec959..6490d11f 100644
--- a/modules/exif/helpers/exif_event.php
+++ b/modules/exif/helpers/exif_event.php
@@ -25,6 +25,9 @@ class exif_event_Core {
}
static function item_deleted($item) {
- Database::instance()->delete("exif_records", array("item_id" => $item->id));
+ db::build()
+ ->delete("exif_records")
+ ->where("item_id", "=", $item->id)
+ ->execute();
}
}
diff --git a/modules/exif/helpers/exif_task.php b/modules/exif/helpers/exif_task.php
index 7c4c97c4..27352643 100644
--- a/modules/exif/helpers/exif_task.php
+++ b/modules/exif/helpers/exif_task.php
@@ -20,10 +20,11 @@
class exif_task_Core {
static function available_tasks() {
// Delete extra exif_records
- Database::instance()->query(
- "DELETE FROM {exif_records} " .
- "WHERE {exif_records}.`item_id` NOT IN " .
- "(SELECT `id` FROM {items} WHERE {items}.`type` = 'photo')");
+ db::build()
+ ->delete("exif_records")
+ ->where("item_id", "NOT IN",
+ db::build()->select("id")->from("items")->where("type", "=", "photo"))
+ ->execute();
list ($remaining, $total, $percent) = exif::stats();
return array(Task_Definition::factory()
@@ -44,11 +45,11 @@ class exif_task_Core {
$start = microtime(true);
foreach (ORM::factory("item")
->join("exif_records", "items.id", "exif_records.item_id", "left")
- ->where("type", "photo")
- ->open_paren()
- ->where("exif_records.item_id", null)
- ->orwhere("exif_records.dirty", 1)
- ->close_paren()
+ ->where("type", "=", "photo")
+ ->and_open()
+ ->where("exif_records.item_id", "IS", null)
+ ->or_where("exif_records.dirty", "=", 1)
+ ->close()
->find_all() as $item) {
// The query above can take a long time, so start the timer after its done
// to give ourselves a little time to actually process rows.
diff --git a/modules/exif/helpers/exif_theme.php b/modules/exif/helpers/exif_theme.php
index bb6926d3..23dc95c2 100644
--- a/modules/exif/helpers/exif_theme.php
+++ b/modules/exif/helpers/exif_theme.php
@@ -21,11 +21,11 @@ class exif_theme_Core {
static function sidebar_bottom($theme) {
$item = $theme->item();
if ($item && $item->is_photo()) {
- $record = Database::instance()
+ $record = db::build()
->select("key_count")
->from("exif_records")
- ->where("item_id", $item->id)
- ->get()
+ ->where("item_id", "=", $item->id)
+ ->execute()
->current();
if ($record && $record->key_count) {
$view = new View("exif_sidebar.html");
diff --git a/modules/forge/libraries/Forge.php b/modules/forge/libraries/Forge.php
index d9da4c7d..5807c849 100644
--- a/modules/forge/libraries/Forge.php
+++ b/modules/forge/libraries/Forge.php
@@ -277,7 +277,8 @@ class Forge_Core {
{
foreach ($this->hidden as $input)
{
- $hidden[$input->name] = $input->value;
+ $hidden['name'] = $input->name;
+ $hidden['value'] = $input->value;
}
}
@@ -299,7 +300,7 @@ class Forge_Core {
// Set the form open and close
$form->open = form::$form_type(arr::remove('action', $this->attr), $this->attr, $hidden);
- $form->close = form::close();
+ $form->close = "</form>";
// Set the inputs
$form->inputs = $this->inputs;
diff --git a/modules/forge/libraries/Form_Input.php b/modules/forge/libraries/Form_Input.php
index 30311941..0c578011 100644
--- a/modules/forge/libraries/Form_Input.php
+++ b/modules/forge/libraries/Form_Input.php
@@ -317,7 +317,7 @@ class Form_Input_Core {
$args = is_array($args) ? $args : array();
// Add the label or name to the beginning of the args
- array_unshift($args, $this->label ? utf8::strtolower($this->label) : $this->name);
+ array_unshift($args, $this->label ? mb_strtolower($this->label) : $this->name);
if (isset($this->error_messages[$func]))
{
@@ -333,7 +333,7 @@ class Form_Input_Core {
case 'valid_email':
case 'valid_ip':
// Fetch an i18n error message
- $error = Kohana::lang('validation.'.$func, $args);
+ $error = 'validation.'.$func;
break;
case substr($func, 0, 6) === 'valid_':
// Strip 'valid_' from func name
@@ -343,11 +343,11 @@ class Form_Input_Core {
case 'digit':
case 'numeric':
// i18n strings have to be inserted into valid_type
- $args[] = Kohana::lang('validation.'.$func);
- $error = Kohana::lang('validation.valid_type', $args);
+ $args[] = 'validation.'.$func;
+ $error = 'validation.valid_type';
break;
default:
- $error = Kohana::lang('validation.'.$func, $args);
+ $error = 'validation.'.$func;
}
}
}
@@ -490,7 +490,7 @@ class Form_Input_Core {
if ($this->value != $input->value)
{
// Field does not match
- $this->errors['matches'] = array($input->label ? utf8::strtolower($input->label) : $input->name);
+ $this->errors['matches'] = array($input->label ? mb_strtolower($input->label) : $input->name);
break;
}
}
@@ -529,7 +529,7 @@ class Form_Input_Core {
protected function rule_length($min, $max = NULL)
{
// Get the length, return if zero
- if (($length = utf8::strlen($this->value)) === 0)
+ if (($length = mb_strlen($this->value)) === 0)
return;
if ($max == NULL)
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 202a0e92..3cf7eb80 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -458,7 +458,7 @@ class g2_import_Core {
switch ($g2_type) {
case "GalleryPhotoItem":
if (!in_array($g2_item->getMimeType(), array("image/jpeg", "image/gif", "image/png"))) {
- Kohana::log("alert", "$g2_path is an unsupported image type; using a placeholder gif");
+ Kohana_Log::add("alert", "$g2_path is an unsupported image type; using a placeholder gif");
$message[] = t("'%path' is an unsupported image type, using a placeholder",
array("path" => $g2_path));
$g2_path = MODPATH . "g2_import/data/broken-image.gif";
@@ -473,7 +473,7 @@ class g2_import_Core {
self::_decode_html_special_chars(self::extract_description($g2_item)),
self::map($g2_item->getOwnerId()));
} catch (Exception $e) {
- Kohana::log(
+ Kohana_Log::add(
"alert", "Corrupt image $g2_path\n" . $e->__toString());
$message[] = t("Corrupt image '%path'", array("path" => $g2_path));
$message[] = $e->__toString();
@@ -493,13 +493,13 @@ class g2_import_Core {
self::_decode_html_special_chars(self::extract_description($g2_item)),
self::map($g2_item->getOwnerId()));
} catch (Exception $e) {
- Kohana::log("alert", "Corrupt movie $g2_path\n" . $e->__toString());
+ Kohana_Log::add("alert", "Corrupt movie $g2_path\n" . $e->__toString());
$message[] = t("Corrupt movie '%path'", array("path" => $g2_path));
$message[] = $e->__toString();
$corrupt = 1;
}
} else {
- Kohana::log("alert", "$g2_path is an unsupported movie type");
+ Kohana_Log::add("alert", "$g2_path is an unsupported movie type");
$message[] = t("'%path' is an unsupported movie type", array("path" => $g2_path));
$corrupt = 1;
}
@@ -867,8 +867,8 @@ class g2_import_Core {
*/
static function map($g2_id) {
if (!array_key_exists($g2_id, self::$map)) {
- $g2_map = ORM::factory("g2_map")->where("g2_id", $g2_id)->find();
- self::$map[$g2_id] = $g2_map->loaded ? $g2_map->g3_id : null;
+ $g2_map = ORM::factory("g2_map")->where("g2_id", "=", $g2_id)->find();
+ self::$map[$g2_id] = $g2_map->loaded() ? $g2_map->g3_id : null;
}
return self::$map[$g2_id];
@@ -887,7 +887,7 @@ class g2_import_Core {
static function log($msg) {
message::warning($msg);
- Kohana::log("alert", $msg);
+ Kohana_Log::add("alert", $msg);
}
}
@@ -906,7 +906,7 @@ function g2() {
$args = func_get_arg(0);
$ret = array_shift($args);
if ($ret) {
- Kohana::log("error", "Gallery 2 call failed with: " . $ret->getAsText());
+ Kohana_Log::add("error", "Gallery 2 call failed with: " . $ret->getAsText());
throw new Exception("@todo G2_FUNCTION_FAILED");
}
if (count($args) == 1) {
diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php
index 609e1a45..02a2126d 100644
--- a/modules/g2_import/helpers/g2_import_event.php
+++ b/modules/g2_import/helpers/g2_import_event.php
@@ -19,7 +19,10 @@
*/
class g2_import_event_Core {
static function item_deleted($item) {
- Database::instance()->delete("g2_maps", array("g3_id" => $item->id));
+ db::build()
+ ->delete("g2_maps")
+ ->where("g3_id", "=", $item->id)
+ ->execute();
}
static function item_created($item) {
diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php
index 47a205bd..e80b88b9 100644
--- a/modules/g2_import/helpers/g2_import_task.php
+++ b/modules/g2_import/helpers/g2_import_task.php
@@ -65,8 +65,8 @@ class g2_import_task_Core {
$task->set("done", $done);
$root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId());
- $root = ORM::factory("g2_map")->where("g2_id", $root_g2_id)->find();
- if (!$root->loaded) {
+ $root = ORM::factory("g2_map")->where("g2_id", "=", $root_g2_id)->find();
+ if (!$root->loaded()) {
$root->g2_id = $root_g2_id;
$root->g3_id = 1;
$root->save();
diff --git a/modules/gallery/config/log_file.php b/modules/gallery/config/log_file.php
new file mode 100644
index 00000000..3d3f8edd
--- /dev/null
+++ b/modules/gallery/config/log_file.php
@@ -0,0 +1,11 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+
+/**
+ * Message logging directory.
+ */
+$config['log_directory'] = VARPATH.'logs';
+
+/**
+ * Permissions of the log file
+ */
+$config['posix_permissions'] = 0644; \ No newline at end of file
diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php
index 79bc1183..391d2598 100644
--- a/modules/gallery/controllers/admin_advanced_settings.php
+++ b/modules/gallery/controllers/admin_advanced_settings.php
@@ -22,7 +22,8 @@ class Admin_Advanced_Settings_Controller extends Admin_Controller {
$view = new Admin_View("admin.html");
$view->content = new View("admin_advanced_settings.html");
$view->content->vars = ORM::factory("var")
- ->orderby("module_name", "name")
+ ->order_by("module_name")
+ ->order_by("name")
->find_all();
print $view;
}
diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php
index 66bcce55..213e4fe2 100644
--- a/modules/gallery/controllers/admin_maintenance.php
+++ b/modules/gallery/controllers/admin_maintenance.php
@@ -22,11 +22,13 @@ class Admin_Maintenance_Controller extends Admin_Controller {
* Show a list of all available, running and finished tasks.
*/
public function index() {
- $query = Database::instance()->query(
- "UPDATE {tasks} SET `state` = 'stalled' " .
- "WHERE done = 0 " .
- "AND state <> 'stalled' " .
- "AND unix_timestamp(now()) - updated > 15");
+ $query = db::build()
+ ->update("tasks")
+ ->set("state", "stalled")
+ ->where("done", "=", 0)
+ ->where("state", "<>", "stalled")
+ ->where(new Database_Expression("UNIX_TIMESTAMP(NOW()) - `updated` > 15"))
+ ->execute();
$stalled_count = $query->count();
if ($stalled_count) {
log::warning("tasks",
@@ -41,9 +43,9 @@ class Admin_Maintenance_Controller extends Admin_Controller {
$view->content = new View("admin_maintenance.html");
$view->content->task_definitions = task::get_definitions();
$view->content->running_tasks = ORM::factory("task")
- ->where("done", 0)->orderby("updated", "DESC")->find_all();
+ ->where("done", "=", 0)->order_by("updated", "DESC")->find_all();
$view->content->finished_tasks = ORM::factory("task")
- ->where("done", 1)->orderby("updated", "DESC")->find_all();
+ ->where("done", "=", 1)->order_by("updated", "DESC")->find_all();
print $view;
}
@@ -75,7 +77,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
access::verify_csrf();
$task = ORM::factory("task", $task_id);
- if (!$task->loaded) {
+ if (!$task->loaded()) {
throw new Exception("@todo MISSING_TASK");
}
$view = new View("admin_maintenance_task.html");
@@ -97,7 +99,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
access::verify_csrf();
$task = ORM::factory("task", $task_id);
- if (!$task->loaded) {
+ if (!$task->loaded()) {
throw new Exception("@todo MISSING_TASK");
}
$view = new View("admin_maintenance_show_log.html");
@@ -114,7 +116,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
access::verify_csrf();
$task = ORM::factory("task", $task_id);
- if (!$task->loaded) {
+ if (!$task->loaded()) {
throw new Exception("@todo MISSING_TASK");
}
@@ -138,10 +140,12 @@ class Admin_Maintenance_Controller extends Admin_Controller {
public function cancel_running_tasks() {
access::verify_csrf();
- Database::instance()->update(
- "tasks",
- array("done" => 1, "state" => "cancelled"),
- array("done" => 0));
+ db::build()
+ ->update("tasks")
+ ->set("done", 1)
+ ->set("state", "cancelled")
+ ->where("done", "=", 0)
+ ->execute();
message::success(t("All running tasks cancelled"));
url::redirect("admin/maintenance");
}
@@ -164,7 +168,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
// Do it the long way so we can call delete and remove the cache.
$finished = ORM::factory("task")
- ->where(array("done" => 1))
+ ->where("done", "=", 1)
->find_all();
foreach ($finished as $task) {
task::remove($task->id);
@@ -184,7 +188,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
try {
$task = task::run($task_id);
} catch (Exception $e) {
- Kohana::log(
+ Kohana_Log::add(
"error",
sprintf(
"%s in %s at line %s:\n%s", $e->getMessage(), $e->getFile(),
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index 3c1a0adf..76032655 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -71,6 +71,7 @@ class Albums_Controller extends Items_Controller {
$template = new Theme_View("page.html", "collection", "album");
$template->set_global("page", $page);
+ $template->set_global("page_title", null);
$template->set_global("max_pages", $max_pages);
$template->set_global("page_size", $page_size);
$template->set_global("item", $album);
@@ -81,7 +82,7 @@ class Albums_Controller extends Items_Controller {
// We can't use math in ORM or the query builder, so do this by hand. It's important
// that we do this with math, otherwise concurrent accesses will damage accuracy.
- Database::instance()->query(
+ db::query(
"UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id");
print $template;
@@ -134,12 +135,12 @@ class Albums_Controller extends Items_Controller {
if ($row = Database::instance()
->select(array("name", "slug"))
->from("items")
- ->where("parent_id", $album->parent_id)
- ->where("id <>", $album->id)
- ->open_paren()
- ->where("name", $form->edit_item->dirname->value)
- ->orwhere("slug", $form->edit_item->slug->value)
- ->close_paren()
+ ->where("parent_id", "=", $album->parent_id)
+ ->where("id", "<>", $album->id)
+ ->and_open()
+ ->where("name", "=", $form->edit_item->dirname->value)
+ ->or_where("slug", "=", $form->edit_item->slug->value)
+ ->close()
->get()
->current()) {
if ($row->name == $form->edit_item->dirname->value) {
diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php
index c1f42bfe..e90a2f1a 100644
--- a/modules/gallery/controllers/combined.php
+++ b/modules/gallery/controllers/combined.php
@@ -22,7 +22,6 @@ class Combined_Controller extends Controller {
* Return the combined Javascript bundle associated with the given key.
*/
public function javascript($key) {
- $key = substr($key, 0, strlen($key) - 3); // strip off the trailing .js
return $this->_emit("javascript", $key);
}
@@ -30,7 +29,6 @@ class Combined_Controller extends Controller {
* Return the combined CSS bundle associated with the given key.
*/
public function css($key) {
- $key = substr($key, 0, strlen($key) - 4); // strip off the trailing .css
return $this->_emit("css", $key);
}
@@ -56,7 +54,7 @@ class Combined_Controller extends Controller {
}
if (empty($key)) {
- Kohana::show_404();
+ throw new Kohana_404_Exception();
}
$cache = Cache::instance();
@@ -71,7 +69,7 @@ class Combined_Controller extends Controller {
$content = $cache->get($key);
}
if (empty($content)) {
- Kohana::show_404();
+ throw new Kohana_404_Exception();
}
// $type is either 'javascript' or 'css'
diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php
index 8fde1132..8c46de08 100644
--- a/modules/gallery/controllers/file_proxy.php
+++ b/modules/gallery/controllers/file_proxy.php
@@ -57,8 +57,8 @@ class File_Proxy_Controller extends Controller {
$path = preg_replace("|/.album.jpg$|", "", $path);
// We now have the relative path to the item. Search for it in the path cache
- $item = ORM::factory("item")->where("relative_path_cache", $path)->find();
- if (!$item->loaded) {
+ $item = ORM::factory("item")->where("relative_path_cache", "=", $path)->find();
+ if (!$item->loaded()) {
// We didn't turn it up. It's possible that the relative_path_cache is out of date here.
// There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be
// necessary, it's easily resurrected.
@@ -69,15 +69,15 @@ class File_Proxy_Controller extends Controller {
if (preg_match('/.jpg$/', $path)) {
foreach (array("flv", "mp4") as $ext) {
$movie_path = preg_replace('/.jpg$/', ".$ext", $path);
- $item = ORM::factory("item")->where("relative_path_cache", $movie_path)->find();
- if ($item->loaded) {
+ $item = ORM::factory("item")->where("relative_path_cache", "=", $movie_path)->find();
+ if ($item->loaded()) {
break;
}
}
}
}
- if (!$item->loaded) {
+ if (!$item->loaded()) {
kohana::show_404();
}
diff --git a/modules/gallery/controllers/items.php b/modules/gallery/controllers/items.php
index b350c5a2..f261e3a9 100644
--- a/modules/gallery/controllers/items.php
+++ b/modules/gallery/controllers/items.php
@@ -20,8 +20,8 @@
class Items_Controller extends Controller {
public function __call($function, $args) {
$item = ORM::factory("item", (int)$function);
- if (!$item->loaded) {
- return Kohana::show_404();
+ if (!$item->loaded()) {
+ throw new Kohana_404_Exception();
}
// Redirect to the more specific resource type, since it will render
diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php
index 6db67d3b..30a18631 100644
--- a/modules/gallery/controllers/l10n_client.php
+++ b/modules/gallery/controllers/l10n_client.php
@@ -24,7 +24,7 @@ class L10n_Client_Controller extends Controller {
access::forbidden();
}
- $locale = I18n::instance()->locale();
+ $locale = Gallery_I18n::instance()->locale();
$input = Input::instance();
$key = $input->post("l10n-message-key");
@@ -33,10 +33,10 @@ class L10n_Client_Controller extends Controller {
"locale" => "root"))
->find();
- if (!$root_message->loaded) {
+ if (!$root_message->loaded()) {
throw new Exception("@todo bad request data / illegal state");
}
- $is_plural = I18n::is_plural_message(unserialize($root_message->message));
+ $is_plural = Gallery_I18n::is_plural_message(unserialize($root_message->message));
if ($is_plural) {
$plural_forms = l10n_client::plural_forms($locale);
@@ -60,7 +60,7 @@ class L10n_Client_Controller extends Controller {
"locale" => $locale))
->find();
- if (!$entry->loaded) {
+ if (!$entry->loaded()) {
$entry->key = $key;
$entry->locale = $locale;
$entry->message = $root_message->message;
@@ -74,7 +74,7 @@ class L10n_Client_Controller extends Controller {
"locale" => $locale))
->find();
- if (!$entry_from_incoming->loaded) {
+ if (!$entry_from_incoming->loaded()) {
$entry->base_revision = $entry_from_incoming->revision;
}
@@ -116,22 +116,22 @@ class L10n_Client_Controller extends Controller {
foreach (Database::instance()
->select("key", "message")
->from("incoming_translations")
- ->where(array("locale" => 'root'))
+ ->where("locale", "=", "root"))
->get()
->as_array() as $row) {
$calls[$row->key] = array(unserialize($row->message), array());
}
} else {
- $calls = I18n::instance()->call_log();
+ $calls = Gallery_I18n::instance()->call_log();
}
- $locale = I18n::instance()->locale();
+ $locale = Gallery_I18n::instance()->locale();
if ($calls) {
$translations = array();
foreach (Database::instance()
->select("key", "translation")
->from("incoming_translations")
- ->where(array("locale" => $locale))
+ ->where("locale", "=", $locale)
->get()
->as_array() as $row) {
$translations[$row->key] = unserialize($row->translation);
@@ -140,7 +140,7 @@ class L10n_Client_Controller extends Controller {
foreach (Database::instance()
->select("key", "translation")
->from("outgoing_translations")
- ->where(array("locale" => $locale))
+ ->where("locale", "=", $locale)
->get()
->as_array() as $row) {
$translations[$row->key] = unserialize($row->translation);
diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php
index 87b73436..863b13bb 100644
--- a/modules/gallery/controllers/move.php
+++ b/modules/gallery/controllers/move.php
@@ -64,8 +64,8 @@ class Move_Controller extends Controller {
$view->parent = $target;
$view->children = ORM::factory("item")
->viewable()
- ->where("type", "album")
- ->where("parent_id", $target->id)
+ ->where("type", "=", "album")
+ ->where("parent_id", "=", $target->id)
->find_all();
return $view;
}
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php
index 575b2b60..6e25e6ea 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -26,7 +26,7 @@ class Movies_Controller extends Items_Controller {
}
access::required("view", $movie);
- $where = array("type != " => "album");
+ $where = array(array("type", "!=", "album"));
$position = $movie->parent()->get_position($movie, $where);
if ($position > 1) {
list ($previous_item, $ignore, $next_item) =
@@ -79,12 +79,12 @@ class Movies_Controller extends Items_Controller {
if ($row = Database::instance()
->select(array("name", "slug"))
->from("items")
- ->where("parent_id", $movie->parent_id)
+ ->where("parent_id", "=", $movie->parent_id)
->where("id <>", $movie->id)
- ->open_paren()
- ->where("name", $form->edit_item->filename->value)
- ->orwhere("slug", $form->edit_item->slug->value)
- ->close_paren()
+ ->and_open()
+ ->where("name", "=", $form->edit_item->filename->value)
+ ->or_where("slug", "=", $form->edit_item->slug->value)
+ ->close()
->get()
->current()) {
if ($row->name == $form->edit_item->filename->value) {
diff --git a/modules/gallery/controllers/permissions.php b/modules/gallery/controllers/permissions.php
index 99943fbb..e03f41a9 100644
--- a/modules/gallery/controllers/permissions.php
+++ b/modules/gallery/controllers/permissions.php
@@ -57,7 +57,7 @@ class Permissions_Controller extends Controller {
access::required("view", $item);
access::required("edit", $item);
- if (!empty($group) && $perm->loaded && $item->loaded) {
+ if (!empty($group) && $perm->loaded() && $item->loaded()) {
switch($command) {
case "allow":
access::allow($group, $perm->name, $item);
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index ba4cfb83..f7c5039e 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -26,7 +26,7 @@ class Photos_Controller extends Items_Controller {
}
access::required("view", $photo);
- $where = array("type != " => "album");
+ $where = array(array("type", "!=", "album"));
$position = $photo->parent()->get_position($photo, $where);
if ($position > 1) {
list ($previous_item, $ignore, $next_item) =
@@ -79,12 +79,12 @@ class Photos_Controller extends Items_Controller {
if ($row = Database::instance()
->select(array("name", "slug"))
->from("items")
- ->where("parent_id", $photo->parent_id)
- ->where("id <>", $photo->id)
- ->open_paren()
- ->where("name", $form->edit_item->filename->value)
- ->orwhere("slug", $form->edit_item->slug->value)
- ->close_paren()
+ ->where("parent_id", "=", $photo->parent_id)
+ ->where("id", "<>", $photo->id)
+ ->and_open()
+ ->where("name", "=", $form->edit_item->filename->value)
+ ->or_where("slug", "=", $form->edit_item->slug->value)
+ ->close()
->get()
->current()) {
if ($row->name == $form->edit_item->filename->value) {
diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php
index 37753ff3..5d32e35f 100644
--- a/modules/gallery/controllers/simple_uploader.php
+++ b/modules/gallery/controllers/simple_uploader.php
@@ -72,7 +72,7 @@ class Simple_Uploader_Controller extends Controller {
module::event("add_photos_form_completed", $item, $form);
}
} catch (Exception $e) {
- Kohana::log("alert", $e->__toString());
+ Kohana_Log::add("alert", $e->__toString());
if (file_exists($temp_filename)) {
unlink($temp_filename);
}
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..0d197597 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->find_all() 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();
}
/**
@@ -475,7 +475,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();
+ $access = ORM::factory("access_intent")->where("item_id", "=", $item->id)->find();
$db = Database::instance();
$field = "view_{$group->id}";
@@ -490,14 +490,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;
}
}
@@ -512,11 +512,11 @@ class access_Core {
$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) {
@@ -549,7 +549,7 @@ 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}";
@@ -562,13 +562,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)
+ ->order_by("left_ptr", "DESC")
->limit(1)
->find();
- if ($tmp_item->loaded) {
+ if ($tmp_item->loaded()) {
$item = $tmp_item;
}
}
@@ -578,10 +578,10 @@ 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";
diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php
index cc631be4..da42bf28 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";
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..40660874 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -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":
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 02bfdf28..37f39d15 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -30,19 +30,21 @@ 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) {
@@ -50,15 +52,15 @@ class gallery_event_Core {
$db = Database::instance();
$db->from("tasks")
->set(array("owner_id" => $admin->id))
- ->where("1 = 1")
+ ->where("1", "=", "1") // @todo why do we need this?
->update();
$db->from("items")
->set(array("owner_id" => $admin->id))
- ->where("1 = 1")
+ ->where("1", "=", "1") // @todo why do we need this?
->update();
$db->from("logs")
->set(array("user_id" => $admin->id))
- ->where("1 = 1")
+ ->where("1", "=", "1") // @todo why do we need this?
->update();
}
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_rss.php b/modules/gallery/helpers/gallery_rss.php
index 155edfb5..4aef27ad 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("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 72e3312d..05614559 100644
--- a/modules/gallery/helpers/identity.php
+++ b/modules/gallery/helpers/identity.php
@@ -75,14 +75,14 @@ class identity_Core {
if (!$session->get("group_ids")) {
$ids = array();
- foreach ($user->groups as $group) {
+ foreach ($user->groups->find_all() 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->__toString());
+ Kohana_Log::add("error", "Load_user Exception: " . $e->__toString());
try {
Session::instance()->destroy();
} catch (Exception $e) {
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index f8e6534e..b7be23cd 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["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()->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..d76c4d19 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) {
+ 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..b8928f7b 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");
}
/**
@@ -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,17 +412,21 @@ 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;
}
@@ -444,14 +453,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..60059c61 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']}";
diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php
index dab98436..ceffac65 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']}";
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() {
diff --git a/modules/gallery/hooks/init_gallery.php b/modules/gallery/hooks/init_gallery.php
index b2d9c4de..c7355260 100644
--- a/modules/gallery/hooks/init_gallery.php
+++ b/modules/gallery/hooks/init_gallery.php
@@ -24,7 +24,7 @@ if (!file_exists(VARPATH . "database.php")) {
url::redirect(url::abs_file("installer"));
}
-Event::add("system.ready", array("I18n", "instance"));
+Event::add("system.ready", array("Gallery_I18n", "instance"));
Event::add("system.ready", array("module", "load_modules"));
Event::add("system.ready", array("gallery", "ready"));
Event::add("system.post_routing", array("url", "parse_url"));
@@ -42,5 +42,5 @@ if ($g3sid = $input->post("g3sid", $input->get("g3sid"))) {
}
if ($user_agent = $input->post("user_agent", $input->get("user_agent"))) {
- Kohana::$user_agent = $user_agent;
+ $_SERVER["HTTP_USER_AGENT"] = $user_agent;
}
diff --git a/modules/gallery/libraries/I18n.php b/modules/gallery/libraries/Gallery_I18n.php
index c3336052..9a5e7dc1 100644
--- a/modules/gallery/libraries/I18n.php
+++ b/modules/gallery/libraries/Gallery_I18n.php
@@ -27,7 +27,7 @@
* @return String The translated message string.
*/
function t($message, $options=array()) {
- return I18n::instance()->translate($message, $options);
+ return Gallery_I18n::instance()->translate($message, $options);
}
/**
@@ -43,11 +43,11 @@ function t($message, $options=array()) {
* @return String The translated message string.
*/
function t2($singular, $plural, $count, $options=array()) {
- return I18n::instance()->translate(array("one" => $singular, "other" => $plural),
+ return Gallery_I18n::instance()->translate(array("one" => $singular, "other" => $plural),
array_merge($options, array("count" => $count)));
}
-class I18n_Core {
+class Gallery_I18n_Core {
private static $_instance;
private $_config = array();
private $_call_log = array();
@@ -64,7 +64,7 @@ class I18n_Core {
if (empty($config['default_locale'])) {
$config['default_locale'] = module::get_var('gallery', 'default_locale');
}
- self::$_instance = new I18n_Core($config);
+ self::$_instance = new Gallery_I18n_Core($config);
}
return self::$_instance;
@@ -128,21 +128,21 @@ class I18n_Core {
if (!isset($this->_cache[$locale])) {
$this->_cache[$locale] = array();
// TODO: Load data from locale file instead of the DB.
- foreach (Database::instance()
+ foreach (db::build()
->select("key", "translation")
->from("incoming_translations")
- ->where(array("locale" => $locale))
- ->get()
+ ->where("locale", "=", $locale)
+ ->execute()
->as_array() as $row) {
$this->_cache[$locale][$row->key] = unserialize($row->translation);
}
// Override incoming with outgoing...
- foreach (Database::instance()
+ foreach (db::build()
->select("key", "translation")
->from("outgoing_translations")
- ->where(array("locale" => $locale))
- ->get()
+ ->where("locale", "=", $locale)
+ ->execute()
->as_array() as $row) {
$this->_cache[$locale][$row->key] = unserialize($row->translation);
}
diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php
index 3bf56d0f..940c5321 100644
--- a/modules/gallery/libraries/Gallery_View.php
+++ b/modules/gallery/libraries/Gallery_View.php
@@ -32,7 +32,7 @@ class Gallery_View_Core extends View {
if (($path = gallery::find_file("js", $file, false))) {
$this->scripts[$path] = 1;
} else {
- Kohana::log("error", "Can't find script file: $file");
+ Kohana_Log::add("error", "Can't find script file: $file");
}
}
@@ -55,7 +55,7 @@ class Gallery_View_Core extends View {
if (($path = gallery::find_file("css", $file, false))) {
$this->css[$path] = 1;
} else {
- Kohana::log("error", "Can't find css file: $file");
+ Kohana_Log::add("error", "Can't find css file: $file");
}
}
@@ -130,7 +130,7 @@ class Gallery_View_Core extends View {
$search[] = $match[0];
$replace[] = "url('" . url::abs_file($relative) . "')";
} else {
- Kohana::log("error", "Missing URL reference '{$match[1]}' in CSS file '$css_file'");
+ Kohana_Log::add("error", "Missing URL reference '{$match[1]}' in CSS file '$css_file'");
}
}
$replace = str_replace(DIRECTORY_SEPARATOR, "/", $replace);
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php
index e213ae97..bcb3056a 100644
--- a/modules/gallery/libraries/IdentityProvider.php
+++ b/modules/gallery/libraries/IdentityProvider.php
@@ -54,7 +54,7 @@ class IdentityProvider_Core {
*/
static function reset() {
self::$instance = null;
- Kohana::config_clear("identity");
+ Kohana_Config::instance()->clear("identity");
}
/**
@@ -90,7 +90,7 @@ class IdentityProvider_Core {
get_class($this), "IdentityProvider_Driver");
}
- Kohana::log("debug", "Identity Library initialized");
+ Kohana_Log::add("debug", "Identity Library initialized");
}
/**
diff --git a/modules/gallery/libraries/MY_Database.php b/modules/gallery/libraries/MY_Database.php
index c56f16e8..52bc46d6 100644
--- a/modules/gallery/libraries/MY_Database.php
+++ b/modules/gallery/libraries/MY_Database.php
@@ -17,34 +17,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class Database extends Database_Core {
+abstract class Database extends Database_Core {
protected $_table_names;
- public function open_paren() {
- $this->where[] = "(";
- return $this;
- }
-
- public function close_paren() {
- // Search backwards for the last opening paren and resolve it
- $i = count($this->where) - 1;
- $this->where[$i] .= ")";
- while (--$i >= 0) {
- if ($this->where[$i] == "(") {
- // Remove the paren from the where clauses, and add it to the right of the operator of the
- // next where clause. If removing the paren makes the next where clause the first element
- // in the where list, then the operator shouldn't be there. It's there because we
- // calculate whether or not we need an operator based on the number of where clauses, and
- // the open paren seems like a where clause even though it isn't.
- array_splice($this->where, $i, 1);
- $this->where[$i] = preg_replace("/^(AND|OR) /", $i ? "\\1 (" : "(", $this->where[$i]);
- return $this;
- }
- }
-
- throw new Kohana_Database_Exception('database.missing_open_paren');
- }
-
/**
* Parse the query string and convert any strings of the form `\([a-zA-Z0-9_]*?)\]
* table prefix . $1
diff --git a/modules/gallery/libraries/MY_Forge.php b/modules/gallery/libraries/MY_Forge.php
index b40d067d..9564f941 100644
--- a/modules/gallery/libraries/MY_Forge.php
+++ b/modules/gallery/libraries/MY_Forge.php
@@ -24,14 +24,13 @@ class Forge extends Forge_Core {
*/
public function __construct($action=null, $title='', $method=null, $attr=array()) {
parent::__construct($action, $title, $method, $attr);
- $this->hidden("csrf")->value("");
+ $this->hidden("csrf")->value(access::csrf_token());
}
/**
* Use our own template
*/
public function render($template="form.html", $custom=false) {
- $this->hidden["csrf"]->value(access::csrf_token());
return parent::render($template, $custom);
}
@@ -43,8 +42,8 @@ class Forge extends Forge_Core {
if (isset($input->inputs)) {
$input->add_rules_from($model);
}
- if (isset($model->rules[$name])) {
- $input->rules($model->rules[$name]);
+ if (isset($model->form_rules[$name])) {
+ $input->rules($model->form_rules[$name]);
}
}
}
diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php
new file mode 100644
index 00000000..dd5998a1
--- /dev/null
+++ b/modules/gallery/libraries/MY_Kohana_Exception.php
@@ -0,0 +1,31 @@
+<?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 Kohana_Exception extends Kohana_Exception_Core {
+ /**
+ * Dump out the full stack trace as part of the text representation of the exception.
+ */
+ public static function text($e) {
+ return sprintf(
+ "%s [ %s ]: %s\n%s [ %s ]\n%s",
+ get_class($e), $e->getCode(), strip_tags($e->getMessage()),
+ $e->getFile(), $e->getLine(),
+ $e->getTraceAsString());
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php
index 2c9ad1d7..56c776aa 100644
--- a/modules/gallery/libraries/MY_ORM.php
+++ b/modules/gallery/libraries/MY_ORM.php
@@ -21,16 +21,6 @@ class ORM extends ORM_Core {
// Track the original value of this ORM so that we can look it up in ORM::original()
protected $original = null;
- public function open_paren() {
- $this->db->open_paren();
- return $this;
- }
-
- public function close_paren() {
- $this->db->close_paren();
- return $this;
- }
-
public function save() {
model_cache::clear();
$result = parent::save();
diff --git a/modules/gallery/libraries/MY_View.php b/modules/gallery/libraries/MY_View.php
index eb55aca6..cec59ec1 100644
--- a/modules/gallery/libraries/MY_View.php
+++ b/modules/gallery/libraries/MY_View.php
@@ -18,6 +18,35 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class View extends View_Core {
+ static $global_data = array();
+
+ /**
+ * Reimplement Kohana 2.3's View::set_global() functionality.
+ */
+ public function set_global($key, $value) {
+ View::$global_data[$key] = $value;
+ }
+
+ public function is_set($key) {
+ return parent::is_set($key) ? true : array_key_exists($key, View::$global_data);
+ }
+
+ /**
+ * Completely replace View_Core::__get() so that local data trumps global data, trumps members.
+ * This simulates the Kohana 2.3 behavior.
+ */
+ public function &__get($key) {
+ if (isset($this->kohana_local_data[$key])) {
+ return $this->kohana_local_data[$key];
+ } else if (isset(View::$global_data[$key])) {
+ return View::$global_data[$key];
+ } else if (isset($this->$key)) {
+ return $this->$key;
+ } else {
+ throw new Kohana_Exception('Undefined view variable: :var', array(':var' => $key));
+ }
+ }
+
/**
* Override View_Core::__construct so that we can set the csrf value into all views.
*
@@ -34,11 +63,12 @@ class View extends View_Core {
*
* @see View_Core::render
*/
- public function render($print=false, $renderer=false) {
+ public function render($print=false, $renderer=false, $modifier=false) {
try {
- return parent::render($print, $renderer);
+ $this->kohana_local_data = array_merge(View::$global_data, $this->kohana_local_data);
+ return parent::render($print, $renderer, $modifier);
} catch (Exception $e) {
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
return "";
}
}
diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php
index ebd7abc2..949ca48c 100644
--- a/modules/gallery/libraries/ORM_MPTT.php
+++ b/modules/gallery/libraries/ORM_MPTT.php
@@ -52,10 +52,16 @@ class ORM_MPTT_Core extends ORM {
try {
// Make a hole in the parent for this new item
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + 2 WHERE `left_ptr` >= {$parent->right_ptr}");
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + 2 WHERE `right_ptr` >= {$parent->right_ptr}");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` + 2"))
+ ->where("left_ptr", ">=", $parent->right_ptr)
+ ->execute();
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` + 2"))
+ ->where("right_ptr", ">=", $parent->right_ptr)
+ ->execute();
$parent->right_ptr += 2;
// Insert this item into the hole
@@ -94,10 +100,16 @@ class ORM_MPTT_Core extends ORM {
$this->lock();
$this->reload(); // Assume that the prior lock holder may have changed this entry
try {
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - 2 WHERE `left_ptr` > {$this->right_ptr}");
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - 2 WHERE `right_ptr` > {$this->right_ptr}");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` - 2"))
+ ->where("left_ptr", ">", $this->right_ptr)
+ ->execute();
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` - 2"))
+ ->where("right_ptr", ">", $this->right_ptr)
+ ->execute();
} catch (Exception $e) {
$this->unlock();
throw $e;
@@ -135,10 +147,10 @@ class ORM_MPTT_Core extends ORM {
*/
function parents() {
return $this
- ->where("`left_ptr` <= {$this->left_ptr}")
- ->where("`right_ptr` >= {$this->right_ptr}")
- ->where("id <> {$this->id}")
- ->orderby("left_ptr", "ASC")
+ ->where("left_ptr", "<=", $this->left_ptr)
+ ->where("right_ptr", ">=", $this->right_ptr)
+ ->where("id", "<>", $this->id)
+ ->order_by("left_ptr", "ASC")
->find_all();
}
@@ -149,14 +161,17 @@ class ORM_MPTT_Core extends ORM {
* @param integer SQL limit
* @param integer SQL offset
* @param array additional where clauses
- * @param array orderby
+ * @param array order_by
* @return array ORM
*/
- function children($limit=null, $offset=0, $where=array(), $orderby=array("id" => "ASC")) {
+ function children($limit=null, $offset=null, $where=null, $order_by=array("id" => "ASC")) {
+ if ($where) {
+ $this->merge_where($where);
+ }
+
return $this
- ->where("parent_id", $this->id)
- ->where($where)
- ->orderby($orderby)
+ ->where("parent_id", "=", $this->id)
+ ->order_by($order_by)
->find_all($limit, $offset);
}
@@ -167,10 +182,13 @@ class ORM_MPTT_Core extends ORM {
* @param array additional where clauses
* @return array ORM
*/
- function children_count($where=array()) {
+ function children_count($where=null) {
+ if ($where) {
+ $this->merge_where($where);
+ }
+
return $this
- ->where($where)
- ->where("parent_id", $this->id)
+ ->where("parent_id", "=", $this->id)
->count_all();
}
@@ -180,15 +198,18 @@ class ORM_MPTT_Core extends ORM {
* @param integer SQL limit
* @param integer SQL offset
* @param array additional where clauses
- * @param array orderby
+ * @param array order_by
* @return object ORM_Iterator
*/
- function descendants($limit=null, $offset=0, $where=array(), $orderby=array("id" => "ASC")) {
+ function descendants($limit=null, $offset=0, $where=null, $order_by=array("id" => "ASC")) {
+ if ($where) {
+ $this->merge_where($where);
+ }
+
return $this
- ->where("left_ptr >", $this->left_ptr)
- ->where("right_ptr <=", $this->right_ptr)
- ->where($where)
- ->orderby($orderby)
+ ->where("left_ptr", ">", $this->left_ptr)
+ ->where("right_ptr", "<=", $this->right_ptr)
+ ->order_by($order_by)
->find_all($limit, $offset);
}
@@ -198,11 +219,14 @@ class ORM_MPTT_Core extends ORM {
* @param array additional where clauses
* @return integer child count
*/
- function descendants_count($where=array()) {
+ function descendants_count($where=null) {
+ if ($where) {
+ $this->merge_where($where);
+ }
+
return $this
- ->where("left_ptr >", $this->left_ptr)
- ->where("right_ptr <=", $this->right_ptr)
- ->where($where)
+ ->where("left_ptr", ">", $this->left_ptr)
+ ->where("right_ptr", "<=", $this->right_ptr)
->count_all();
}
@@ -231,23 +255,32 @@ class ORM_MPTT_Core extends ORM {
try {
if ($level_delta) {
// Update the levels for the to-be-moved items
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `level` = `level` + $level_delta" .
- " WHERE `left_ptr` >= $original_left_ptr AND `right_ptr` <= $original_right_ptr");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("level", new Database_Expression("`level` + $level_delta"))
+ ->where("left_ptr", ">=", $original_left_ptr)
+ ->where("right_ptr", "<=", $original_right_ptr)
+ ->execute();
}
// Make a hole in the target for the move
- $target->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + $size_of_hole" .
- " WHERE `left_ptr` >= $target_right_ptr");
- $target->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + $size_of_hole" .
- " WHERE `right_ptr` >= $target_right_ptr");
+ $target->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` + $size_of_hole"))
+ ->where("left_ptr", ">=", $target_right_ptr)
+ ->execute();
+ $target->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` + $size_of_hole"))
+ ->where("right_ptr", ">=", $target_right_ptr)
+ ->execute();
// Change the parent.
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `parent_id` = {$target->id}" .
- " WHERE `id` = {$this->id}");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("parent_id", $target->id)
+ ->where("id", "=", $this->id)
+ ->execute();
// If the source is to the right of the target then we just adjusted its left_ptr and right_ptr above.
$left_ptr = $original_left_ptr;
@@ -258,20 +291,25 @@ class ORM_MPTT_Core extends ORM {
}
$new_offset = $target->right_ptr - $left_ptr;
- $this->db->query(
- "UPDATE {{$this->table_name}}" .
- " SET `left_ptr` = `left_ptr` + $new_offset," .
- " `right_ptr` = `right_ptr` + $new_offset" .
- " WHERE `left_ptr` >= $left_ptr" .
- " AND `right_ptr` <= $right_ptr");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` + $new_offset"))
+ ->set("right_ptr", new Database_Expression("`right_ptr` + $new_offset"))
+ ->where("left_ptr", ">=", $left_ptr)
+ ->where("right_ptr", "<=", $right_ptr)
+ ->execute();
// Close the hole in the source's parent after the move
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - $size_of_hole" .
- " WHERE `left_ptr` > $right_ptr");
- $this->db->query(
- "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - $size_of_hole" .
- " WHERE `right_ptr` > $right_ptr");
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("left_ptr", new Database_Expression("`left_ptr` - $size_of_hole"))
+ ->where("left_ptr", ">", $right_ptr)
+ ->execute();
+ $this->db_builder
+ ->update($this->table_name)
+ ->set("right_ptr", new Database_Expression("`right_ptr` - $size_of_hole"))
+ ->where("right_ptr", ">", $right_ptr)
+ ->execute();
} catch (Exception $e) {
$this->unlock();
throw $e;
diff --git a/modules/gallery/libraries/SafeString.php b/modules/gallery/libraries/SafeString.php
index ba3a8ffd..cc63f3a7 100644
--- a/modules/gallery/libraries/SafeString.php
+++ b/modules/gallery/libraries/SafeString.php
@@ -146,7 +146,7 @@ class SafeString_Core {
* Escape special HTML chars ("<", ">", "&", etc.) to HTML entities.
*/
private static function _escape_for_html($dirty_html) {
- return html::specialchars($dirty_html);
+ return html::chars($dirty_html);
}
/**
diff --git a/modules/gallery/libraries/Sendmail.php b/modules/gallery/libraries/Sendmail.php
index 7bc21a67..aa2b51a9 100644
--- a/modules/gallery/libraries/Sendmail.php
+++ b/modules/gallery/libraries/Sendmail.php
@@ -52,7 +52,7 @@ class Sendmail_Core {
break;
case "header":
if (count($value) != 2) {
- Kohana::log("error", wordwrap("Invalid header parameters\n" . Kohana::debug($value)));
+ Kohana_Log::add("error", wordwrap("Invalid header parameters\n" . Kohana::debug($value)));
throw new Exception("@todo INVALID_HEADER_PARAMETERS");
}
$this->headers[$value[0]] = $value[1];
@@ -71,7 +71,7 @@ class Sendmail_Core {
public function send() {
if (empty($this->to)) {
- Kohana::log("error", wordwrap("Sending mail failed:\nNo to address specified"));
+ Kohana_Log::add("error", wordwrap("Sending mail failed:\nNo to address specified"));
throw new Exception("@todo TO_IS_REQUIRED_FOR_MAIL");
}
$to = implode(", ", $this->to);
diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php
index 7e2aeabc..5c453f28 100644
--- a/modules/gallery/libraries/drivers/Cache/Database.php
+++ b/modules/gallery/libraries/drivers/Cache/Database.php
@@ -20,43 +20,33 @@
/*
* Based on the Cache_Sqlite_Driver developed by the Kohana Team
*/
-class Cache_Database_Driver implements Cache_Driver {
+class Cache_Database_Driver extends Cache_Driver {
// Kohana database instance
protected $db;
/**
- * Tests that the storage location is a directory and is writable.
- */
- public function __construct() {
- // Open up an instance of the database
- $this->db = Database::instance();
-
- if (!$this->db->table_exists("caches")) {
- throw new Exception("@todo Cache table is not defined");
- }
- }
-
- /**
* Checks if a cache id is already set.
*
* @param string cache id
* @return boolean
*/
public function exists($id) {
- $count = $this->db->count_records("caches", array("key" => $id, "expiration >=" => time()));
+ $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 string cache id to set
- * @param string data in the cache
+ * @param array assoc array of key => value pairs
* @param array cache tags
* @param integer lifetime
* @return bool
*/
- public function set($id, $data, array $tags = NULL, $lifetime) {
+ public function set($items, $tags=null, $lifetime=null) {
if (!empty($tags)) {
// Escape the tags, adding brackets so the tag can be explicitly matched
$tags = "<" . implode(">,<", $tags) . ">";
@@ -69,46 +59,53 @@ class Cache_Database_Driver implements Cache_Driver {
$lifetime += time();
}
- if ($this->exists($id)) {
- $status = $this->db->update(
- "caches",
- array("tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)), array("key" => $id));
- } else {
- $status = $this->db->insert(
- "caches",
- array("key" => $id, "tags" => $tags, "expiration" => $lifetime, "cache" => serialize($data)));
+ 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();
+ }
}
- return count($status) > 0;
+ return true;
}
/**
- * Finds an array of ids for a given tag.
- *
- * @param string tag name
- * @return array of ids that match the tag
+ * Get cache items by tag
+ * @param array cache tags
+ * @return array cached data
*/
- public function find($tag) {
- $db_result = $this->db->from("caches")
- ->like("tags", "<$tag>")
- ->get()
- ->result(true);
+ public function get_tag($tags) {
+ $db = db::build()
+ ->select()
+ ->from("caches");
+ foreach ($tags as $tag) {
+ $db->where("tags", "LIKE", "<$tag>");
+ }
+ $db_result = $db->execute();
// An array will always be returned
$result = array();
+ // Disable notices for unserializing
+ $ER = error_reporting(~E_NOTICE);
if ($db_result->count() > 0) {
- // Disable notices for unserializing
- $ER = error_reporting(~E_NOTICE);
-
foreach ($db_result as $row) {
// Add each cache to the array
$result[$row->key] = unserialize($row->cache);
}
-
- // Turn notices back on
- error_reporting($ER);
}
+ error_reporting($ER);
return $result;
}
@@ -120,9 +117,13 @@ class Cache_Database_Driver implements Cache_Driver {
* @param string cache id
* @return mixed|NULL
*/
- public function get($id) {
+ public function get($keys, $single=false) {
$data = null;
- $result = $this->db->getwhere("caches", array("key" => $id));
+ $result = db::build()
+ ->select()
+ ->from("caches")
+ ->where("key", "IN", $keys)
+ ->execute();
if (count($result) > 0) {
$cache = $result->current();
@@ -153,31 +154,47 @@ class Cache_Database_Driver implements Cache_Driver {
* @return bool
*/
public function delete($id, $tag = false) {
- $this->db->from("caches");
+ $db = db::build()
+ ->delete("caches");
if ($id === true) {
- $this->db->where(1);
// Delete all caches
+ $db->where("1", "=", "1");
} else if ($tag === true) {
- $this->db->like("tags", "<$id>");
+ $db->where("tags", "LIKE", "<$id>");
} else {
- $this->db->where("key", $id);
+ $db->where("key", "=", $id);
}
- $status = $this->db->delete();
+ $status = $db->execute();
return count($status) > 0;
}
/**
+ * Delete cache items by tag
+ */
+ public function delete_tag($tags) {
+ return $this->delete($tags, true);
+ }
+
+ /**
* Deletes all cache files that are older than the current time.
*/
public function delete_expired() {
// Delete all expired caches
- $status = $this->db->from("caches")
- ->where(array("expiration !=" => 0, "expiration <=" => time()))
- ->delete();
+ $status = db::build()
+ ->delete("caches")
+ ->where("expiration", "<>", 0)
+ ->where("expiration", "<=", time())
+ ->execute();
return count($status) > 0;
}
-} // End Cache Database Driver \ No newline at end of file
+ /**
+ * Empty the cache
+ */
+ public function delete_all() {
+ Database::instance()->query("TRUNCATE {caches}");
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index d27e331b..8a42cc1e 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -21,7 +21,7 @@ class Item_Model extends ORM_MPTT {
protected $children = 'items';
protected $sorting = array();
- var $rules = array(
+ var $form_rules = array(
"name" => "required|length[0,255]",
"title" => "required|length[0,255]",
"description" => "length[0,65535]",
@@ -285,14 +285,14 @@ class Item_Model extends ORM_MPTT {
private function _build_relative_caches() {
$names = array();
$slugs = array();
- foreach (Database::instance()
+ foreach (db::build()
->select(array("name", "slug"))
->from("items")
- ->where("left_ptr <=", $this->left_ptr)
- ->where("right_ptr >=", $this->right_ptr)
- ->where("id <>", 1)
- ->orderby("left_ptr", "ASC")
- ->get() as $row) {
+ ->where("left_ptr", "<=", $this->left_ptr)
+ ->where("right_ptr", ">=", $this->right_ptr)
+ ->where("id", "<>", 1)
+ ->order_by("left_ptr", "ASC")
+ ->execute() as $row) {
// Don't encode the names segment
$names[] = rawurlencode($row->name);
$slugs[] = rawurlencode($row->slug);
@@ -309,7 +309,7 @@ class Item_Model extends ORM_MPTT {
* @return string
*/
public function relative_path() {
- if (!$this->loaded) {
+ if (!$this->loaded()) {
return;
}
@@ -324,7 +324,7 @@ class Item_Model extends ORM_MPTT {
* @return string
*/
public function relative_url() {
- if (!$this->loaded) {
+ if (!$this->loaded()) {
return;
}
@@ -383,7 +383,7 @@ class Item_Model extends ORM_MPTT {
if (!empty($this->changed) && $significant_changes) {
$this->updated = time();
- if (!$this->loaded) {
+ if (!$this->loaded()) {
$this->created = $this->updated;
$this->weight = item::get_max_weight();
} else {
@@ -428,14 +428,14 @@ class Item_Model extends ORM_MPTT {
} else {
$comp = "<";
}
- $db = Database::instance();
+ $db = db::build();
// If the comparison column has NULLs in it, we can't use comparators on it and will have to
// deal with it the hard way.
$count = $db->from("items")
- ->where("parent_id", $this->id)
- ->where($this->sort_column, NULL)
- ->where($where)
+ ->where("parent_id", "=", $this->id)
+ ->where($this->sort_column, "=", NULL)
+ ->merge_where($where)
->count_records();
if (empty($count)) {
@@ -443,9 +443,9 @@ class Item_Model extends ORM_MPTT {
$sort_column = $this->sort_column;
$position = $db->from("items")
- ->where("parent_id", $this->id)
- ->where("$sort_column $comp ", $child->$sort_column)
- ->where($where)
+ ->where("parent_id", "=", $this->id)
+ ->where($sort_column, $comp, $child->$sort_column)
+ ->merge_where($where)
->count_records();
// We stopped short of our target value in the sort (notice that we're using a < comparator
@@ -456,12 +456,14 @@ class Item_Model extends ORM_MPTT {
//
// Fix this by doing a 2nd query where we iterate over the equivalent columns and add them to
// our base value.
- foreach ($db->from("items")
- ->where("parent_id", $this->id)
- ->where($sort_column, $child->$sort_column)
- ->where($where)
- ->orderby(array("id" => "ASC"))
- ->get() as $row) {
+ foreach ($db
+ ->select("id")
+ ->from("items")
+ ->where("parent_id", "=", $this->id)
+ ->where($sort_column, "=", $child->$sort_column)
+ ->merge_where($where)
+ ->order_by(array("id" => "ASC"))
+ ->execute() as $row) {
$position++;
if ($row->id == $child->id) {
break;
@@ -475,19 +477,19 @@ class Item_Model extends ORM_MPTT {
//
// Reproduce the children() functionality here using Database directly to avoid loading the
// whole ORM for each row.
- $orderby = array($this->sort_column => $this->sort_order);
+ $order_by = array($this->sort_column => $this->sort_order);
// Use id as a tie breaker
if ($this->sort_column != "id") {
- $orderby["id"] = "ASC";
+ $order_by["id"] = "ASC";
}
$position = 0;
foreach ($db->select("id")
->from("items")
- ->where("parent_id", $this->id)
- ->where($where)
- ->orderby($orderby)
- ->get() as $row) {
+ ->where("parent_id", "=", $this->id)
+ ->merge_where($where)
+ ->order_by($order_by)
+ ->execute() as $row) {
$position++;
if ($row->id == $child->id) {
break;
@@ -592,18 +594,18 @@ class Item_Model extends ORM_MPTT {
* @param integer SQL limit
* @param integer SQL offset
* @param array additional where clauses
- * @param array orderby
+ * @param array order_by
* @return array ORM
*/
- function children($limit=null, $offset=0, $where=array(), $orderby=null) {
- if (empty($orderby)) {
- $orderby = array($this->sort_column => $this->sort_order);
+ function children($limit=null, $offset=null, $where=array(), $order_by=null) {
+ if (empty($order_by)) {
+ $order_by = array($this->sort_column => $this->sort_order);
// Use id as a tie breaker
if ($this->sort_column != "id") {
- $orderby["id"] = "ASC";
+ $order_by["id"] = "ASC";
}
}
- return parent::children($limit, $offset, $where, $orderby);
+ return parent::children($limit, $offset, $where, $order_by);
}
/**
@@ -617,14 +619,14 @@ class Item_Model extends ORM_MPTT {
* @param array additional where clauses
* @return object ORM_Iterator
*/
- function descendants($limit=null, $offset=0, $where=array(), $orderby=null) {
- if (empty($orderby)) {
- $orderby = array($this->sort_column => $this->sort_order);
+ function descendants($limit=null, $offset=0, $where=array(), $order_by=null) {
+ if (empty($order_by)) {
+ $order_by = array($this->sort_column => $this->sort_order);
// Use id as a tie breaker
if ($this->sort_column != "id") {
- $orderby["id"] = "ASC";
+ $order_by["id"] = "ASC";
}
}
- return parent::descendants($limit, $offset, $where, $orderby);
+ return parent::descendants($limit, $offset, $where, $order_by);
}
}
diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php
index c816a4a7..a2044325 100644
--- a/modules/gallery/models/log.php
+++ b/modules/gallery/models/log.php
@@ -28,7 +28,7 @@ class Log_Model extends ORM {
try {
return identity::lookup_user($this->user_id);
} catch (Exception $e) {
- Kohana::log("alert", "Unable to load user with id $this->user_id");
+ Kohana_Log::add("alert", "Unable to load user with id $this->user_id");
return null;
}
} else {
diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php
index e9e5cb26..771c6a85 100644
--- a/modules/gallery/tests/Access_Helper_Test.php
+++ b/modules/gallery/tests/Access_Helper_Test.php
@@ -106,15 +106,15 @@ class Access_Helper_Test extends Unit_Test_Case {
$item = album::create($root, rand(), "test album");
// New rows exist
- $this->assert_true(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded);
- $this->assert_true(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded);
+ $this->assert_true(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded());
+ $this->assert_true(ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->loaded());
// Delete the item
$item->delete();
// Rows are gone
- $this->assert_false(ORM::factory("access_cache")->where("item_id", $item->id)->find()->loaded);
- $this->assert_false(ORM::factory("access_intent")->where("item_id", $item->id)->find()->loaded);
+ $this->assert_false(ORM::factory("access_cache")->where("item_id", "=", $item->id)->find()->loaded());
+ $this->assert_false(ORM::factory("access_intent")->where("item_id", "=", $item->id)->find()->loaded());
}
public function new_photos_inherit_parent_permissions_test() {
@@ -131,7 +131,7 @@ class Access_Helper_Test extends Unit_Test_Case {
public function can_allow_deny_and_reset_intent_test() {
$root = ORM::factory("item", 1);
$album = album::create($root, rand(), "test album");
- $intent = ORM::factory("access_intent")->where("item_id", $album)->find();
+ $intent = ORM::factory("access_intent")->where("item_id", "=", $album)->find();
// Allow
access::allow(identity::everybody(), "view", $album);
@@ -141,19 +141,19 @@ class Access_Helper_Test extends Unit_Test_Case {
access::deny(identity::everybody(), "view", $album);
$this->assert_same(
access::DENY,
- ORM::factory("access_intent")->where("item_id", $album)->find()->view_1);
+ ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1);
// Allow again. If the initial value was allow, then the first Allow clause above may not
// have actually changed any values.
access::allow(identity::everybody(), "view", $album);
$this->assert_same(
access::ALLOW,
- ORM::factory("access_intent")->where("item_id", $album)->find()->view_1);
+ ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1);
access::reset(identity::everybody(), "view", $album);
$this->assert_same(
null,
- ORM::factory("access_intent")->where("item_id", $album)->find()->view_1);
+ ORM::factory("access_intent")->where("item_id", "=", $album)->find()->view_1);
}
public function cant_reset_root_item_test() {
diff --git a/modules/gallery/tests/Cache_Test.php b/modules/gallery/tests/Cache_Test.php
index 6b525265..776c6625 100644
--- a/modules/gallery/tests/Cache_Test.php
+++ b/modules/gallery/tests/Cache_Test.php
@@ -20,7 +20,7 @@
class Cache_Test extends Unit_Test_Case {
private $_driver;
public function setup() {
- Database::instance()->from("caches")->where(1)->delete();
+ Database::instance()->from("caches")->where("1", "=", "1")->delete();
$this->_driver = new Cache_Database_Driver();
}
diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php
index 98bd4046..9b428379 100644
--- a/modules/gallery/tests/Database_Test.php
+++ b/modules/gallery/tests/Database_Test.php
@@ -20,8 +20,8 @@
class Database_Test extends Unit_Test_Case {
function simple_where_test() {
$sql = Database::instance()
- ->where("a", 1)
- ->where("b", 2)
+ ->where("a", "=", 1)
+ ->where("b", "=", 2)
->compile();
$sql = str_replace("\n", " ", $sql);
$this->assert_same("SELECT * WHERE `a` = 1 AND `b` = 2", $sql);
@@ -29,12 +29,12 @@ class Database_Test extends Unit_Test_Case {
function compound_where_test() {
$sql = Database::instance()
- ->where("outer1", 1)
- ->open_paren()
- ->where("inner1", 1)
- ->orwhere("inner2", 2)
- ->close_paren()
- ->where("outer2", 2)
+ ->where("outer1", "=", 1)
+ ->and_open()
+ ->where("inner1", "=", 1)
+ ->or_where("inner2", "=", 2)
+ ->close()
+ ->where("outer2", "=", 2)
->compile();
$sql = str_replace("\n", " ", $sql);
$this->assert_same(
@@ -44,12 +44,12 @@ class Database_Test extends Unit_Test_Case {
function group_first_test() {
$sql = Database::instance()
- ->open_paren()
- ->where("inner1", 1)
- ->orwhere("inner2", 2)
- ->close_paren()
- ->where("outer1", 1)
- ->where("outer2", 2)
+ ->and_open()
+ ->where("inner1", "=", 1)
+ ->or_where("inner2", "=", 2)
+ ->close()
+ ->where("outer1", "=", 1)
+ ->where("outer2", "=", 2)
->compile();
$sql = str_replace("\n", " ", $sql);
$this->assert_same(
@@ -59,11 +59,12 @@ class Database_Test extends Unit_Test_Case {
function where_array_test() {
$sql = Database::instance()
- ->where("outer1", 1)
- ->open_paren()
- ->where("inner1", 1)
- ->orwhere(array("inner2" => 2, "inner3" => 3))
- ->close_paren()
+ ->where("outer1", "=", 1)
+ ->and_open()
+ ->where("inner1", "=", 1)
+ ->or_where("inner2", "=", 2)
+ ->or_where("inner3", "=", 3))
+ ->close()
->compile();
$sql = str_replace("\n", " ", $sql);
$this->assert_same(
@@ -73,10 +74,10 @@ class Database_Test extends Unit_Test_Case {
function notlike_test() {
$sql = Database::instance()
- ->where("outer1", 1)
- ->open_paren()
- ->ornotlike("inner1", 1)
- ->close_paren()
+ ->where("outer1", "=", 1)
+ ->or_open()
+ ->where("inner1", "NOT LIKE", 1)
+ ->close()
->compile();
$sql = str_replace("\n", " ", $sql);
$this->assert_same(
@@ -118,7 +119,7 @@ class Database_Test extends Unit_Test_Case {
function prefix_no_replacement_test() {
$update = Database_For_Test::instance()->from("test_tables")
- ->where("1 = 1")
+ ->where("1", "=", "1")
->set(array("name" => "Test Name"))
->update();
diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php
index 36ced2bb..f36f638f 100644
--- a/modules/gallery/tests/Gallery_Installer_Test.php
+++ b/modules/gallery/tests/Gallery_Installer_Test.php
@@ -29,7 +29,7 @@ class Gallery_Installer_Test extends Unit_Test_Case {
}
public function install_registers_gallery_module_test() {
- $gallery = ORM::factory("module")->where("name", "gallery")->find();
+ $gallery = ORM::factory("module")->where("name", "=", "gallery")->find();
$this->assert_equal("gallery", $gallery->name);
}
diff --git a/modules/gallery/tests/I18n_Test.php b/modules/gallery/tests/I18n_Test.php
index 9010606a..895e3051 100644
--- a/modules/gallery/tests/I18n_Test.php
+++ b/modules/gallery/tests/I18n_Test.php
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class I18n_Test extends Unit_Test_Case {
+class Gallery_I18n_Test extends Unit_Test_Case {
private $i18n;
public function setup() {
@@ -26,10 +26,10 @@ class I18n_Test extends Unit_Test_Case {
'root_locale' => 'en',
'default_locale' => 'te_ST',
'locale_dir' => VARPATH . 'locale/');
- $this->i18n = I18n::instance($config);
+ $this->i18n = Gallery_I18n::instance($config);
ORM::factory("incoming_translation")
- ->where("locale", "te_ST")
+ ->where("locale", "=", "te_ST")
->delete_all();
$messages_te_ST = array(
@@ -43,7 +43,7 @@ class I18n_Test extends Unit_Test_Case {
foreach ($messages_te_ST as $data) {
list ($message, $translation) = $data;
$entry = ORM::factory("incoming_translation");
- $entry->key = I18n::get_message_key($message);
+ $entry->key = Gallery_I18n::get_message_key($message);
$entry->message = serialize($message);
$entry->translation = serialize($translation);
$entry->locale = 'te_ST';
@@ -62,7 +62,7 @@ class I18n_Test extends Unit_Test_Case {
$locale = $this->i18n->locale();
$this->assert_equal("de_DE", $locale);
}
-
+
public function translate_simple_test() {
$result = $this->i18n->translate('Hello world');
$this->assert_equal('Hallo Welt', $result);
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index a364423a..f0c653c0 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -29,13 +29,13 @@ class Item_Helper_Test extends Unit_Test_Case {
access::allow(identity::everybody(), "view", $album);
$this->assert_equal(
1,
- ORM::factory("item")->viewable()->where("id", $item->id)->count_all());
+ ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all());
// We can't see the item when permissions are denied
access::deny(identity::everybody(), "view", $album);
$this->assert_equal(
0,
- ORM::factory("item")->viewable()->where("id", $item->id)->count_all());
+ ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all());
}
public function validate_url_safe_test() {
diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php
index a749542b..36a81d2c 100644
--- a/modules/gallery/tests/ORM_MPTT_Test.php
+++ b/modules/gallery/tests/ORM_MPTT_Test.php
@@ -228,7 +228,7 @@ class ORM_MPTT_Test extends Unit_Test_Case {
$parent->reload();
$this->assert_equal(3, $parent->descendants_count());
- $this->assert_equal(2, $parent->descendants_count(array("type" => "photo")));
- $this->assert_equal(1, $parent->descendants_count(array("type" => "album")));
+ $this->assert_equal(2, $parent->descendants_count(array(array("type", "=", "photo"))));
+ $this->assert_equal(1, $parent->descendants_count(array(array("type", "=", "album"))));
}
}
diff --git a/modules/gallery/views/kohana_error_page.php b/modules/gallery/views/kohana_error_page.php
index 0d8801e5..b9fdcc19 100644
--- a/modules/gallery/views/kohana_error_page.php
+++ b/modules/gallery/views/kohana_error_page.php
@@ -120,7 +120,7 @@
<? else: ?>
<? $trace = $PHP_ERROR ? array_slice(debug_backtrace(), 1) : $exception->getTraceAsString(); ?>
<? if (!empty($trace)): ?>
- <? Kohana::Log("error", print_r($trace, 1)); ?>
+ <? Kohana_Log::add("error", print_r($trace, 1)); ?>
<? endif ?>
<? endif ?>
</body>
diff --git a/modules/gallery_unit_test/controllers/gallery_unit_test.php b/modules/gallery_unit_test/controllers/gallery_unit_test.php
index 58e0d9c5..391ad029 100644
--- a/modules/gallery_unit_test/controllers/gallery_unit_test.php
+++ b/modules/gallery_unit_test/controllers/gallery_unit_test.php
@@ -20,7 +20,7 @@
class Gallery_Unit_Test_Controller extends Controller {
function Index() {
if (!TEST_MODE) {
- print Kohana::show_404();
+ print throw new Kohana_404_Exception();
}
// Jump through some hoops to satisfy the way that we check for the site_domain in
diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php
index 79bd92ba..f591e8d1 100644
--- a/modules/image_block/helpers/image_block_block.php
+++ b/modules/image_block/helpers/image_block_block.php
@@ -35,18 +35,18 @@ class image_block_block_Core {
$items = ORM::factory("item")
->viewable()
- ->where("type !=", "album")
- ->where("rand_key < ", $random)
- ->orderby(array("rand_key" => "DESC"))
+ ->where("type", "!=", "album")
+ ->where("rand_key", "<", $random)
+ ->order_by(array("rand_key" => "DESC"))
->find_all(1);
if ($items->count() == 0) {
// Try once more. If this fails, just ditch the block altogether
$items = ORM::factory("item")
->viewable()
- ->where("type !=", "album")
- ->where("rand_key >= ", $random)
- ->orderby(array("rand_key" => "DESC"))
+ ->where("type", "!=", "album")
+ ->where("rand_key", ">=", $random)
+ ->order_by(array("rand_key" => "DESC"))
->find_all(1);
}
diff --git a/modules/kohana23_compat/config/pagination.php b/modules/kohana23_compat/config/pagination.php
new file mode 100644
index 00000000..808fc315
--- /dev/null
+++ b/modules/kohana23_compat/config/pagination.php
@@ -0,0 +1,25 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+/**
+ * @package Pagination
+ *
+ * Pagination configuration is defined in groups which allows you to easily switch
+ * between different pagination settings for different website sections.
+ * Note: all groups inherit and overwrite the default group.
+ *
+ * Group Options:
+ * directory - Views folder in which your pagination style templates reside
+ * style - Pagination style template (matches view filename)
+ * uri_segment - URI segment (int or 'label') in which the current page number can be found
+ * query_string - Alternative to uri_segment: query string key that contains the page number
+ * items_per_page - Number of items to display per page
+ * auto_hide - Automatically hides pagination for single pages
+ */
+$config['default'] = array
+(
+ 'directory' => 'pagination',
+ 'style' => 'classic',
+ 'uri_segment' => 3,
+ 'query_string' => '',
+ 'items_per_page' => 20,
+ 'auto_hide' => FALSE,
+);
diff --git a/modules/kohana23_compat/libraries/MY_Database_Builder.php b/modules/kohana23_compat/libraries/MY_Database_Builder.php
new file mode 100644
index 00000000..974f9c6d
--- /dev/null
+++ b/modules/kohana23_compat/libraries/MY_Database_Builder.php
@@ -0,0 +1,31 @@
+<?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 Database_Builder extends Database_Builder_Core {
+ /**
+ * Merge in a series of where clause tuples and call where() on each one.
+ * @chainable
+ */
+ public function merge_where($tuples) {
+ foreach ($tuples as $tuple) {
+ $this->where($tuple[0], $tuple[1], $tuple[2]);
+ }
+ return $this;
+ }
+} \ No newline at end of file
diff --git a/modules/kohana23_compat/libraries/Pagination.php b/modules/kohana23_compat/libraries/Pagination.php
new file mode 100644
index 00000000..8ff8bf94
--- /dev/null
+++ b/modules/kohana23_compat/libraries/Pagination.php
@@ -0,0 +1,234 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+/**
+ * Pagination library.
+ *
+ * $Id: Pagination.php 3769 2008-12-15 00:48:56Z zombor $
+ *
+ * @package Core
+ * @author Kohana Team
+ * @copyright (c) 2007-2008 Kohana Team
+ * @license http://kohanaphp.com/license.html
+ */
+class Pagination_Core {
+
+ // Config values
+ protected $base_url = '';
+ protected $directory = 'pagination';
+ protected $style = 'classic';
+ protected $uri_segment = 3;
+ protected $query_string = '';
+ protected $items_per_page = 20;
+ protected $total_items = 0;
+ protected $auto_hide = FALSE;
+
+ // Autogenerated values
+ protected $url;
+ protected $current_page;
+ protected $total_pages;
+ protected $current_first_item;
+ protected $current_last_item;
+ protected $first_page;
+ protected $last_page;
+ protected $previous_page;
+ protected $next_page;
+ protected $sql_offset;
+ protected $sql_limit;
+
+ /**
+ * Constructs and returns a new Pagination object.
+ *
+ * @param array configuration settings
+ * @return object
+ */
+ public function factory($config = array())
+ {
+ return new Pagination($config);
+ }
+
+ /**
+ * Constructs a new Pagination object.
+ *
+ * @param array configuration settings
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ // No custom group name given
+ if ( ! isset($config['group']))
+ {
+ $config['group'] = 'default';
+ }
+
+ // Pagination setup
+ $this->initialize($config);
+ }
+
+ /**
+ * Sets config values.
+ *
+ * @throws Kohana_Exception
+ * @param array configuration settings
+ * @return void
+ */
+ public function initialize($config = array())
+ {
+ // Load config group
+ if (isset($config['group']))
+ {
+ // Load and validate config group
+ if ( ! is_array($group_config = Kohana::config('pagination.'.$config['group'])))
+ throw new Kohana_Exception('pagination.undefined_group: ' . $config['group']);
+
+ // All pagination config groups inherit default config group
+ if ($config['group'] !== 'default')
+ {
+ // Load and validate default config group
+ if ( ! is_array($default_config = Kohana::config('pagination.default')))
+ throw new Kohana_Exception('pagination.undefined_group: default');
+
+ // Merge config group with default config group
+ $group_config += $default_config;
+ }
+
+ // Merge custom config items with config group
+ $config += $group_config;
+ }
+
+ // Assign config values to the object
+ foreach ($config as $key => $value)
+ {
+ if (property_exists($this, $key))
+ {
+ $this->$key = $value;
+ }
+ }
+
+ // Clean view directory
+ $this->directory = trim($this->directory, '/').'/';
+
+ // Build generic URL with page in query string
+ if ($this->query_string !== '')
+ {
+ // Extract current page
+ $this->current_page = isset($_GET[$this->query_string]) ? (int) $_GET[$this->query_string] : 1;
+
+ // Insert {page} placeholder
+ $_GET[$this->query_string] = '{page}';
+
+ // Create full URL
+ $base_url = ($this->base_url === '') ? Router::$current_uri : $this->base_url;
+ $this->url = url::site($base_url).'?'.str_replace('%7Bpage%7D', '{page}', http_build_query($_GET));
+
+ // Reset page number
+ $_GET[$this->query_string] = $this->current_page;
+ }
+
+ // Build generic URL with page as URI segment
+ else
+ {
+ // Use current URI if no base_url set
+ $this->url = ($this->base_url === '') ? Router::$segments : explode('/', trim($this->base_url, '/'));
+
+ // Convert uri 'label' to corresponding integer if needed
+ if (is_string($this->uri_segment))
+ {
+ if (($key = array_search($this->uri_segment, $this->url)) === FALSE)
+ {
+ // If uri 'label' is not found, auto add it to base_url
+ $this->url[] = $this->uri_segment;
+ $this->uri_segment = count($this->url) + 1;
+ }
+ else
+ {
+ $this->uri_segment = $key + 2;
+ }
+ }
+
+ // Insert {page} placeholder
+ $this->url[$this->uri_segment - 1] = '{page}';
+
+ // Create full URL
+ $this->url = url::site(implode('/', $this->url)).Router::$query_string;
+
+ // Extract current page
+ $this->current_page = URI::instance()->segment($this->uri_segment);
+ }
+
+ // Core pagination values
+ $this->total_items = (int) max(0, $this->total_items);
+ $this->items_per_page = (int) max(1, $this->items_per_page);
+ $this->total_pages = (int) ceil($this->total_items / $this->items_per_page);
+ $this->current_page = (int) min(max(1, $this->current_page), max(1, $this->total_pages));
+ $this->current_first_item = (int) min((($this->current_page - 1) * $this->items_per_page) + 1, $this->total_items);
+ $this->current_last_item = (int) min($this->current_first_item + $this->items_per_page - 1, $this->total_items);
+
+ // If there is no first/last/previous/next page, relative to the
+ // current page, value is set to FALSE. Valid page number otherwise.
+ $this->first_page = ($this->current_page === 1) ? FALSE : 1;
+ $this->last_page = ($this->current_page >= $this->total_pages) ? FALSE : $this->total_pages;
+ $this->previous_page = ($this->current_page > 1) ? $this->current_page - 1 : FALSE;
+ $this->next_page = ($this->current_page < $this->total_pages) ? $this->current_page + 1 : FALSE;
+
+ // SQL values
+ $this->sql_offset = (int) ($this->current_page - 1) * $this->items_per_page;
+ $this->sql_limit = sprintf(' LIMIT %d OFFSET %d ', $this->items_per_page, $this->sql_offset);
+ }
+
+ /**
+ * Generates the HTML for the chosen pagination style.
+ *
+ * @param string pagination style
+ * @return string pagination html
+ */
+ public function render($style = NULL)
+ {
+ // Hide single page pagination
+ if ($this->auto_hide === TRUE AND $this->total_pages <= 1)
+ return '';
+
+ if ($style === NULL)
+ {
+ // Use default style
+ $style = $this->style;
+ }
+
+ // Return rendered pagination view
+ return View::factory($this->directory.$style, get_object_vars($this))->render();
+ }
+
+ /**
+ * Magically converts Pagination object to string.
+ *
+ * @return string pagination html
+ */
+ public function __toString()
+ {
+ return $this->render();
+ }
+
+ /**
+ * Magically gets a pagination variable.
+ *
+ * @param string variable key
+ * @return mixed variable value if the key is found
+ * @return void if the key is not found
+ */
+ public function __get($key)
+ {
+ if (isset($this->$key))
+ return $this->$key;
+ }
+
+ /**
+ * Adds a secondary interface for accessing properties, e.g. $pagination->total_pages().
+ * Note that $pagination->total_pages is the recommended way to access properties.
+ *
+ * @param string function name
+ * @return string
+ */
+ public function __call($func, $args = NULL)
+ {
+ return $this->__get($func);
+ }
+
+} // End Pagination Class \ No newline at end of file
diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php
index 9a40b0b9..e9fc3f33 100644
--- a/modules/notification/helpers/notification.php
+++ b/modules/notification/helpers/notification.php
@@ -24,8 +24,8 @@ class notification {
}
return ORM::factory("subscription")
- ->where("item_id", $item_id)
- ->where("user_id", $user->id)
+ ->where("item_id", "=", $item_id)
+ ->where("user_id", "=", $user->id)
->find();
}
@@ -35,10 +35,10 @@ class notification {
}
return ORM::factory("subscription")
- ->where("item_id", $item->id)
- ->where("user_id", $user->id)
+ ->where("item_id", "=", $item->id)
+ ->where("user_id", "=", $user->id)
->find()
- ->loaded;
+ ->loaded();
}
static function add_watch($item, $user=null) {
@@ -60,8 +60,8 @@ class notification {
}
$subscription = ORM::factory("subscription")
- ->where("item_id", $item->id)
- ->where("user_id", $user->id)
+ ->where("item_id", "=", $item->id)
+ ->where("user_id", "=", $user->id)
->find()->delete();
}
}
@@ -71,8 +71,8 @@ class notification {
foreach (ORM::factory("subscription")
->select("user_id")
->join("items", "subscriptions.item_id", "items.id")
- ->where("items.left_ptr <=", $item->left_ptr)
- ->where("items.right_ptr >", $item->right_ptr)
+ ->where("items.left_ptr", "<=", $item->left_ptr)
+ ->where("items.right_ptr", ">", $item->right_ptr)
->find_all()
->as_array() as $subscriber) {
$subscriber_ids[] = $subscriber->user_id;
@@ -170,13 +170,13 @@ class notification {
}
static function send_pending_notifications() {
- foreach (Database::instance()
- ->select("DISTINCT email")
+ foreach (db::build()
+ ->select(new Database_Expression("DISTINCT `email`"))
->from("pending_notifications")
- ->get() as $row) {
+ ->execute() as $row) {
$email = $row->email;
$result = ORM::factory("pending_notification")
- ->where("email", $email)
+ ->where("email", "=", $email)
->find_all();
if ($result->count() == 1) {
$pending = $result->current();
diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php
index 6b2df574..2c7ede27 100644
--- a/modules/notification/helpers/notification_event.php
+++ b/modules/notification/helpers/notification_event.php
@@ -25,8 +25,8 @@ class notification_event_Core {
try {
notification::send_item_updated($new);
} catch (Exception $e) {
- Kohana::log("error", "@todo notification_event::item_updated() failed");
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "@todo notification_event::item_updated() failed");
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
@@ -34,8 +34,8 @@ class notification_event_Core {
try {
notification::send_item_add($item);
} catch (Exception $e) {
- Kohana::log("error", "@todo notification_event::item_created() failed");
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "@todo notification_event::item_created() failed");
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
@@ -47,20 +47,22 @@ class notification_event_Core {
notification::remove_watch($item);
}
} catch (Exception $e) {
- Kohana::log("error", "@todo notification_event::item_deleted() failed");
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "@todo notification_event::item_deleted() failed");
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
static function user_deleted($user) {
- ORM::factory("subscriptions")
- ->where(array("user_id", $user->id))
- ->delete_all();
+ db::build()
+ ->delete("subscriptions")
+ ->where("user_id", "=", $user->id)
+ ->execute();
}
static function identity_provider_changed($old_provider, $new_provider) {
- ORM::factory("subscriptions")
- ->delete_all();
+ db::build()
+ ->delete("subscriptions")
+ ->execute();
}
static function comment_created($comment) {
@@ -69,8 +71,8 @@ class notification_event_Core {
notification::send_comment_published($comment);
}
} catch (Exception $e) {
- Kohana::log("error", "@todo notification_event::comment_created() failed");
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "@todo notification_event::comment_created() failed");
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
@@ -80,19 +82,19 @@ class notification_event_Core {
notification::send_comment_published($new);
}
} catch (Exception $e) {
- Kohana::log("error", "@todo notification_event::comment_updated() failed");
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "@todo notification_event::comment_updated() failed");
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
static function user_before_delete($user) {
try {
ORM::factory("subscription")
- ->where("user_id", $user->id)
+ ->where("user_id", "=", $user->id)
->delete_all();
} catch (Exception $e) {
- Kohana::log("error", "@todo notification_event::user_before_delete() failed");
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "@todo notification_event::user_before_delete() failed");
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
@@ -100,8 +102,8 @@ class notification_event_Core {
try {
notification::send_pending_notifications();
} catch (Exception $e) {
- Kohana::log("error", "@todo notification_event::batch_complete() failed");
- Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString());
+ Kohana_Log::add("error", "@todo notification_event::batch_complete() failed");
+ Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php
index 740c2521..c5257956 100644
--- a/modules/organize/views/organize_tree.html.php
+++ b/modules/organize/views/organize_tree.html.php
@@ -8,7 +8,7 @@
<?= html::clean($album->title) ?>
</span>
<ul>
- <? foreach ($album->children(null, 0, array("type" => "album")) as $child): ?>
+ <? foreach ($album->children(null, null, array(array("type", "=", "album"))) as $child): ?>
<? if ($selected && $child->contains($selected)): ?>
<?= View::factory("organize_tree.html", array("selected" => $selected, "album" => $child)); ?>
<? else: ?>
diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php
index ed2acef8..a963a1dc 100644
--- a/modules/rss/controllers/rss.php
+++ b/modules/rss/controllers/rss.php
@@ -39,7 +39,7 @@ class Rss_Controller extends Controller {
}
}
if (empty($feed)) {
- Kohana::show_404();
+ throw new Kohana_404_Exception();
}
if ($feed->max_pages && $page > $feed->max_pages) {
diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php
index 8c3bd3ab..70a39272 100644
--- a/modules/search/helpers/search.php
+++ b/modules/search/helpers/search.php
@@ -60,8 +60,8 @@ class search_Core {
static function update($item) {
$data = new ArrayObject();
- $record = ORM::factory("search_record")->where("item_id", $item->id)->find();
- if (!$record->loaded) {
+ $record = ORM::factory("search_record")->where("item_id", "=", $item->id)->find();
+ if (!$record->loaded()) {
$record->item_id = $item->id;
}
@@ -72,16 +72,14 @@ class search_Core {
}
static function stats() {
- $remaining = Database::instance()
- ->select("items.id")
+ $remaining = db::build()
->from("items")
->join("search_records", "items.id", "search_records.item_id", "left")
- ->open_paren()
- ->where("search_records.item_id", null)
- ->orwhere("search_records.dirty", 1)
- ->close_paren()
- ->get()
- ->count();
+ ->and_open()
+ ->where("search_records.item_id", "IS", null)
+ ->or_where("search_records.dirty", "=", 1)
+ ->close()
+ ->count_records();
$total = ORM::factory("item")->count_all();
$percent = round(100 * ($total - $remaining) / $total);
diff --git a/modules/search/helpers/search_event.php b/modules/search/helpers/search_event.php
index 836bbe15..1add6e5f 100644
--- a/modules/search/helpers/search_event.php
+++ b/modules/search/helpers/search_event.php
@@ -28,7 +28,7 @@ class search_event_Core {
static function item_deleted($item) {
ORM::factory("search_record")
- ->where("item_id", $item->id)
+ ->where("item_id", "=", $item->id)
->delete_all();
}
diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php
index 9508f420..e039e493 100644
--- a/modules/search/helpers/search_task.php
+++ b/modules/search/helpers/search_task.php
@@ -20,10 +20,10 @@
class search_task_Core {
static function available_tasks() {
// Delete extra search_records
- Database::instance()->query(
- "DELETE FROM {search_records} " .
- "WHERE {search_records}.`item_id` NOT IN " .
- "(SELECT `id` FROM {items})");
+ db::build()
+ ->delete("search_records")
+ ->where("item_id", "NOT IN", db::build()->select("id")->from("items"))
+ ->execute();
list ($remaining, $total, $percent) = search::stats();
return array(Task_Definition::factory()
@@ -45,8 +45,8 @@ class search_task_Core {
$start = microtime(true);
foreach (ORM::factory("item")
->join("search_records", "items.id", "search_records.item_id", "left")
- ->where("search_records.item_id", null)
- ->orwhere("search_records.dirty", 1)
+ ->where("search_records.item_id", "IS", null)
+ ->or_where("search_records.dirty", "=", 1)
->find_all() as $item) {
// The query above can take a long time, so start the timer after its done
// to give ourselves a little time to actually process rows.
diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php
index 53a3d091..78e1620c 100644
--- a/modules/server_add/controllers/server_add.php
+++ b/modules/server_add/controllers/server_add.php
@@ -103,7 +103,7 @@ class Server_Add_Controller extends Admin_Controller {
access::verify_csrf();
$task = ORM::factory("task", $task_id);
- if (!$task->loaded || $task->owner_id != identity::active_user()->id) {
+ if (!$task->loaded() || $task->owner_id != identity::active_user()->id) {
access::forbidden();
}
@@ -177,7 +177,7 @@ class Server_Add_Controller extends Admin_Controller {
$task->percent_complete = min($task->percent_complete + 0.1, 10);
$task->status = t2("Found one file", "Found %count files",
Database::instance()
- ->where("task_id", $task->id)
+ ->where("task_id", "=", $task->id)
->count_records("server_add_files"));
if (!$queue) {
@@ -197,9 +197,9 @@ class Server_Add_Controller extends Admin_Controller {
// will create albums first. Ignore entries which already have an Item_Model attached,
// they're done.
$entries = ORM::factory("server_add_file")
- ->where("task_id", $task->id)
- ->where("item_id", null)
- ->orderby("id", "ASC")
+ ->where("task_id", "=", $task->id)
+ ->where("item_id", "IS", null)
+ ->order_by("id", "ASC")
->limit(10)
->find_all();
if ($entries->count() == 0) {
@@ -216,7 +216,7 @@ class Server_Add_Controller extends Admin_Controller {
// Look up the parent item for this entry. By now it should exist, but if none was
// specified, then this belongs as a child of the current item.
$parent_entry = ORM::factory("server_add_file", $entry->parent_id);
- if (!$parent_entry->loaded) {
+ if (!$parent_entry->loaded()) {
$parent = ORM::factory("item", $task->get("item_id"));
} else {
$parent = ORM::factory("item", $parent_entry->item_id);
@@ -265,7 +265,7 @@ class Server_Add_Controller extends Admin_Controller {
$task->done = true;
$task->state = "success";
$task->percent_complete = 100;
- ORM::factory("server_add_file")->where("task_id", $task->id)->delete_all();
+ ORM::factory("server_add_file")->where("task_id", "=", $task->id)->delete_all();
message::info(t2("Successfully added one photo / album",
"Successfully added %count photos / albums",
$task->get("completed_files")));
diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php
index 0afe8126..9b77dd42 100644
--- a/modules/slideshow/helpers/slideshow_event.php
+++ b/modules/slideshow/helpers/slideshow_event.php
@@ -32,7 +32,7 @@ class slideshow_event_Core {
static function album_menu($menu, $theme) {
$descendants_count = ORM::factory("item", $theme->item()->id)
- ->descendants_count(array("type" => "photo"));
+ ->descendants_count(array(array("type", "=", "photo")));
if ($descendants_count > 1) {
$menu->append(Menu::factory("link")
->id("slideshow")
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php
index 67587c2e..ed4a0366 100644
--- a/modules/tag/controllers/admin_tags.php
+++ b/modules/tag/controllers/admin_tags.php
@@ -29,13 +29,13 @@ class Admin_Tags_Controller extends Admin_Controller {
if ($filter) {
$query->like("name", $filter);
}
- $view->content->tags = $query->orderby("name", "ASC")->find_all();
+ $view->content->tags = $query->order_by("name", "ASC")->find_all();
print $view;
}
public function form_delete($id) {
$tag = ORM::factory("tag", $id);
- if ($tag->loaded) {
+ if ($tag->loaded()) {
print tag::get_delete_form($tag);
}
}
@@ -44,14 +44,14 @@ class Admin_Tags_Controller extends Admin_Controller {
access::verify_csrf();
$tag = ORM::factory("tag", $id);
- if (!$tag->loaded) {
+ if (!$tag->loaded()) {
kohana::show_404();
}
$form = tag::get_delete_form($tag);
if ($form->validate()) {
$name = $tag->name;
- Database::instance()->delete("items_tags", array("tag_id" => "$tag->id"));
+ db::build()->delete("items_tags")->where("tag_id", "=", $tag->id)->execute();
$tag->delete();
message::success(t("Deleted tag %tag_name", array("tag_name" => $name)));
log::success("tags", t("Deleted tag %tag_name", array("tag_name" => $name)));
@@ -68,7 +68,7 @@ class Admin_Tags_Controller extends Admin_Controller {
public function form_rename($id) {
$tag = ORM::factory("tag", $id);
- if ($tag->loaded) {
+ if ($tag->loaded()) {
print InPlaceEdit::factory($tag->name)
->action("admin/tags/rename/$id")
->render();
@@ -79,7 +79,7 @@ class Admin_Tags_Controller extends Admin_Controller {
access::verify_csrf();
$tag = ORM::factory("tag", $id);
- if (!$tag->loaded) {
+ if (!$tag->loaded()) {
kohana::show_404();
}
@@ -106,7 +106,7 @@ class Admin_Tags_Controller extends Admin_Controller {
}
public function check_for_duplicate(Validation $post_data, $field) {
- $tag_exists = ORM::factory("tag")->where("name", $post_data[$field])->count_all();
+ $tag_exists = ORM::factory("tag")->where("name", "=", $post_data[$field])->count_all();
if ($tag_exists) {
$post_data->add_error($field, "in_use");
}
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index 9f9e45d9..a44f6aa3 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -83,8 +83,8 @@ class Tags_Controller extends Controller {
$limit = $this->input->get("limit");
$tag_part = end($tag_parts);
$tag_list = ORM::factory("tag")
- ->like("name", "{$tag_part}%", false)
- ->orderby("name", "ASC")
+ ->where("name", "LIKE", "{$tag_part}%")
+ ->order_by("name", "ASC")
->limit($limit)
->find_all();
foreach ($tag_list as $tag) {
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index 89a27034..8075afe4 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -33,8 +33,8 @@ class tag_Core {
throw new exception("@todo MISSING_TAG_NAME");
}
- $tag = ORM::factory("tag")->where("name", $tag_name)->find();
- if (!$tag->loaded) {
+ $tag = ORM::factory("tag")->where("name", "=", $tag_name)->find();
+ if (!$tag->loaded()) {
$tag->name = $tag_name;
$tag->count = 0;
$tag->save();
@@ -57,7 +57,7 @@ class tag_Core {
*/
static function popular_tags($count) {
return ORM::factory("tag")
- ->orderby("count", "DESC")
+ ->order_by("count", "DESC")
->limit($count)
->find_all();
}
@@ -89,12 +89,12 @@ class tag_Core {
*/
static function item_tags($item) {
$tags = array();
- foreach (Database::instance()
+ foreach (db::build()
->select("name")
->from("tags")
->join("items_tags", "tags.id", "items_tags.tag_id", "left")
- ->where("items_tags.item_id", $item->id)
- ->get() as $row) {
+ ->where("items_tags.item_id", "=", $item->id)
+ ->execute() as $row) {
$tags[] = $row->name;
}
return $tags;
@@ -125,10 +125,16 @@ class tag_Core {
* Delete all tags associated with an item
*/
static function clear_all($item) {
- $db = Database::instance();
- $db->query("UPDATE {tags} SET `count` = `count` - 1 WHERE `count` > 0 " .
- "AND `id` IN (SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)");
- $db->delete("items_tags", array("item_id" => "$item->id"));
+ db::build()
+ ->update("tags")
+ ->set("count", new Database_Expression("`count` - 1"))
+ ->where("count", ">", 0)
+ ->where("id", "IN", db::build()->select("tag_id")->from("items_tags")->where("item_id", "=", $item->id))
+ ->execute();
+ db::build()
+ ->delete("items_tags")
+ ->where("item_id", "=", $item->id)
+ ->execute();
}
/**
@@ -138,6 +144,6 @@ class tag_Core {
// @todo There's a potential race condition here which we can solve by adding a lock around
// this and all the cases where we create/update tags. I'm loathe to do that since it's an
// extremely rare case.
- Database::instance() ->delete("tags", array("count" => 0));
+ db::build()->delete("tags")->where("count", "=", 0)->execute();
}
} \ No newline at end of file
diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php
index a857a99d..6ee8e708 100644
--- a/modules/tag/helpers/tag_event.php
+++ b/modules/tag/helpers/tag_event.php
@@ -51,7 +51,7 @@ class tag_event_Core {
try {
tag::add($photo, $tag);
} catch (Exception $e) {
- Kohana::log("error", "Error adding tag: $tag\n" .
+ Kohana_Log::add("error", "Error adding tag: $tag\n" .
$e->getMessage() . "\n" . $e->getTraceAsString());
}
}
diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php
index de5d6c72..f09a4530 100644
--- a/modules/tag/helpers/tag_rss.php
+++ b/modules/tag/helpers/tag_rss.php
@@ -31,8 +31,8 @@ class tag_rss_Core {
static function feed($feed_id, $offset, $limit, $id) {
if ($feed_id == "tag") {
$tag = ORM::factory("tag", $id);
- if (!$tag->loaded) {
- Kohana::show_404();
+ if (!$tag->loaded()) {
+ throw new Kohana_404_Exception();
}
$feed->children = $tag->items($limit, $offset, "photo");
$feed->max_pages = ceil($tag->count / $limit);
diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php
index be020f5f..f6cc6144 100644
--- a/modules/tag/models/tag.php
+++ b/modules/tag/models/tag.php
@@ -31,9 +31,9 @@ class Tag_Model extends ORM {
$model = ORM::factory("item")
->viewable()
->join("items_tags", "items.id", "items_tags.item_id")
- ->where("items_tags.tag_id", $this->id);
+ ->where("items_tags.tag_id", "=", $this->id);
if ($type) {
- $model->where("items.type", $type);
+ $model->where("items.type", "=", $type);
}
return $model->find_all($limit, $offset);
}
@@ -47,10 +47,10 @@ class Tag_Model extends ORM {
$model = ORM::factory("item")
->viewable()
->join("items_tags", "items.id", "items_tags.item_id")
- ->where("items_tags.tag_id", $this->id);
+ ->where("items_tags.tag_id", "=", $this->id);
if ($type) {
- $model->where("items.type", $type);
+ $model->where("items.type", "=", $type);
}
return $model->count_all();
}
@@ -63,18 +63,28 @@ class Tag_Model extends ORM {
public function save() {
$db = Database::instance();
$related_item_ids = array();
- foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {
+ foreach (db::build()
+ ->select("item_id")
+ ->from("items_tags")
+ ->where("tag_id", "=", $this->id)
+ ->execute() as $row) {
$related_item_ids[$row->item_id] = 1;
}
$result = parent::save();
- foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {
+ foreach (db::build()
+ ->select("item_id")
+ ->from("items_tags")
+ ->where("tag_id", "=", $this->id)
+ ->execute() as $row) {
$related_item_ids[$row->item_id] = 1;
}
if ($related_item_ids) {
- foreach (ORM::factory("item")->in("id", array_keys($related_item_ids))->find_all() as $item) {
+ foreach (ORM::factory("item")
+ ->where("id", "IN", array_keys($related_item_ids))
+ ->find_all() as $item) {
module::event("item_related_update", $item);
}
}
@@ -89,7 +99,12 @@ class Tag_Model extends ORM {
public function delete() {
$related_item_ids = array();
$db = Database::Instance();
- foreach ($db->getwhere("items_tags", array("tag_id" => $this->id)) as $row) {
+
+ foreach (db::build()
+ ->select("item_id")
+ ->from("items_tags")
+ ->where("tag_id", "=", $this->id)
+ ->execute() as $row) {
$related_item_ids[$row->item_id] = 1;
}
diff --git a/modules/tag/tests/Tag_Test.php b/modules/tag/tests/Tag_Test.php
index c9a96286..c96e7f2b 100644
--- a/modules/tag/tests/Tag_Test.php
+++ b/modules/tag/tests/Tag_Test.php
@@ -25,18 +25,18 @@ class Tag_Test extends Unit_Test_Case {
$tag1 = "tag1";
tag::add($album, $tag1);
- $tag = ORM::factory("tag")->where("name", $tag1)->find();
+ $tag = ORM::factory("tag")->where("name", "=", $tag1)->find();
$this->assert_true(1, $tag->count);
// Make sure adding the tag again doesn't increase the count
tag::add($album, $tag1);
- $tag = ORM::factory("tag")->where("name", $tag1)->find();
+ $tag = ORM::factory("tag")->where("name", "=", $tag1)->find();
$this->assert_true(1, $tag->count);
$rand = rand();
$album = album::create($root, $rand, $rand, $rand);
tag::add($album, $tag1);
- $tag = ORM::factory("tag")->where("name", $tag1)->find();
+ $tag = ORM::factory("tag")->where("name", "=", $tag1)->find();
$this->assert_true(2, $tag->count);
}
} \ No newline at end of file
diff --git a/modules/user/controllers/admin_users.php b/modules/user/controllers/admin_users.php
index b3284385..ee65efd2 100644
--- a/modules/user/controllers/admin_users.php
+++ b/modules/user/controllers/admin_users.php
@@ -22,10 +22,10 @@ class Admin_Users_Controller extends Admin_Controller {
$view = new Admin_View("admin.html");
$view->content = new View("admin_users.html");
$view->content->users = ORM::factory("user")
- ->orderby("name", "ASC")
+ ->order_by("name", "ASC")
->find_all();
$view->content->groups = ORM::factory("group")
- ->orderby("name", "ASC")
+ ->order_by("name", "ASC")
->find_all();
print $view;
}
@@ -265,7 +265,7 @@ class Admin_Users_Controller extends Admin_Controller {
if ($valid) {
$new_name = $form->edit_group->inputs["name"]->value;
$group = group::lookup_by_name($name);
- if ($group->loaded) {
+ if ($group->loaded()) {
$form->edit_group->inputs["name"]->add_error("in_use", 1);
$valid = false;
}
diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php
index e18e76b6..8309d2cc 100644
--- a/modules/user/controllers/password.php
+++ b/modules/user/controllers/password.php
@@ -47,7 +47,7 @@ class Password_Controller extends Controller {
$valid = $form->validate();
if ($valid) {
$user = user::lookup_by_name($form->reset->inputs["name"]->value);
- if (!$user->loaded || empty($user->email)) {
+ if (!$user->loaded() || empty($user->email)) {
$form->reset->inputs["name"]->add_error("no_email", 1);
$valid = false;
}
diff --git a/modules/user/helpers/group.php b/modules/user/helpers/group.php
index 3aaf1b11..2ada0ac1 100644
--- a/modules/user/helpers/group.php
+++ b/modules/user/helpers/group.php
@@ -31,8 +31,8 @@ class group_Core {
* @return Group_Definition the group object
*/
static function create($name) {
- $group = ORM::factory("group")->where("name", $name)->find();
- if ($group->loaded) {
+ $group = ORM::factory("group")->where("name", "=", $name)->find();
+ if ($group->loaded()) {
throw new Exception("@todo GROUP_ALREADY_EXISTS $name");
}
@@ -86,7 +86,7 @@ class group_Core {
private static function _lookup_by_field($field_name, $value) {
try {
$user = model_cache::get("group", $value, $field_name);
- if ($user->loaded) {
+ if ($user->loaded()) {
return $user;
}
} catch (Exception $e) {
diff --git a/modules/user/helpers/user.php b/modules/user/helpers/user.php
index f9f16da5..5027580c 100644
--- a/modules/user/helpers/user.php
+++ b/modules/user/helpers/user.php
@@ -44,8 +44,8 @@ class user_Core {
* @return User_Model
*/
static function create($name, $full_name, $password) {
- $user = ORM::factory("user")->where("name", $name)->find();
- if ($user->loaded) {
+ $user = ORM::factory("user")->where("name", "=", $name)->find();
+ if ($user->loaded()) {
throw new Exception("@todo USER_ALREADY_EXISTS $name");
}
@@ -163,7 +163,7 @@ class user_Core {
private static function _lookup_user_by_field($field_name, $value) {
try {
$user = model_cache::get("user", $value, $field_name);
- if ($user->loaded) {
+ if ($user->loaded()) {
return $user;
}
} catch (Exception $e) {
diff --git a/modules/user/models/group.php b/modules/user/models/group.php
index 4432fc69..3a084684 100644
--- a/modules/user/models/group.php
+++ b/modules/user/models/group.php
@@ -20,7 +20,7 @@
class Group_Model extends ORM implements Group_Definition {
protected $has_and_belongs_to_many = array("users");
- var $rules = array(
+ var $form_rules = array(
"name" => "required|length[4,255]");
/**
@@ -34,7 +34,7 @@ class Group_Model extends ORM implements Group_Definition {
}
public function save() {
- if (!$this->loaded) {
+ if (!$this->loaded()) {
$created = 1;
}
parent::save();
diff --git a/modules/user/models/user.php b/modules/user/models/user.php
index bd61def8..e14d9b31 100644
--- a/modules/user/models/user.php
+++ b/modules/user/models/user.php
@@ -20,7 +20,7 @@
class User_Model extends ORM implements User_Definition {
protected $has_and_belongs_to_many = array("groups");
- var $rules = array(
+ var $form_rules = array(
"name" => "required|length[1,32]",
"full_name" => "length[0,255]",
"email" => "required|valid_email|length[1,255]",
@@ -62,7 +62,7 @@ class User_Model extends ORM implements User_Definition {
}
public function save() {
- if (!$this->loaded) {
+ if (!$this->loaded()) {
$created = 1;
}
parent::save();
diff --git a/modules/user/tests/User_Groups_Test.php b/modules/user/tests/User_Groups_Test.php
index 3da8dd34..163b7d79 100644
--- a/modules/user/tests/User_Groups_Test.php
+++ b/modules/user/tests/User_Groups_Test.php
@@ -21,15 +21,15 @@
class User_Groups_Test extends Unit_Test_Case {
public function teardown() {
try {
- $group = ORM::factory("group")->where("name", "user_groups_test")->find();
- if ($group->loaded) {
+ $group = ORM::factory("group")->where("name", "=", "user_groups_test")->find();
+ if ($group->loaded()) {
$group->delete();
}
} catch (Exception $e) { }
try {
- $user = ORM::factory("user")->where("name", "user_groups_test")->find();
- if ($user->loaded) {
+ $user = ORM::factory("user")->where("name", "=", "user_groups_test")->find();
+ if ($user->loaded()) {
$user->delete();
}
} catch (Exception $e) { }