diff options
Diffstat (limited to 'modules/gallery/controllers')
20 files changed, 97 insertions, 92 deletions
diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index 98cac557..e4216991 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -44,7 +44,7 @@ class Admin_Controller extends Controller { } if (!method_exists($controller_name, $method)) { - return kohana::show_404(); + throw new Kohana_404_Exception(); } call_user_func_array(array(new $controller_name, $method), $args); 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_dashboard.php b/modules/gallery/controllers/admin_dashboard.php index 7e28f625..5f2cb41d 100644 --- a/modules/gallery/controllers/admin_dashboard.php +++ b/modules/gallery/controllers/admin_dashboard.php @@ -86,7 +86,7 @@ class Admin_Dashboard_Controller extends Admin_Controller { foreach (array("dashboard_sidebar", "dashboard_center") as $location) { $new_blocks = array(); - foreach ($this->input->get($location, array()) as $id) { + foreach (Input::instance()->get($location, array()) as $id) { $new_blocks[$id] = $active_set[$id]; } block_manager::set_active($location, $new_blocks); diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php index acf71665..354e6c0c 100644 --- a/modules/gallery/controllers/admin_identity.php +++ b/modules/gallery/controllers/admin_identity.php @@ -30,7 +30,7 @@ class Admin_Identity_Controller extends Admin_Controller { access::verify_csrf(); $v = new View("admin_identity_confirm.html"); - $v->new_provider = $this->input->post("provider"); + $v->new_provider = Input::instance()->post("provider"); print $v; } @@ -40,7 +40,7 @@ class Admin_Identity_Controller extends Admin_Controller { $active_provider = module::get_var("gallery", "identity_provider", "user"); $providers = identity::providers(); - $new_provider = $this->input->post("provider"); + $new_provider = Input::instance()->post("provider"); if ($new_provider != $active_provider) { diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php index 27537c7f..41523023 100644 --- a/modules/gallery/controllers/admin_languages.php +++ b/modules/gallery/controllers/admin_languages.php @@ -36,10 +36,11 @@ class Admin_Languages_Controller extends Admin_Controller { public function save() { access::verify_csrf(); - locales::update_installed($this->input->post("installed_locales")); + $input = Input::instance(); + locales::update_installed($input->post("installed_locales")); $installed_locales = array_keys(locales::installed()); - $new_default_locale = $this->input->post("default_locale"); + $new_default_locale = $input->post("default_locale"); if (!in_array($new_default_locale, $installed_locales)) { if (!empty($installed_locales)) { $new_default_locale = $installed_locales[0]; @@ -61,7 +62,7 @@ class Admin_Languages_Controller extends Admin_Controller { return $this->index($form); } - if ($this->input->post("share")) { + if (Input::instance()->post("share")) { l10n_client::submit_translations(); message::success(t("Translations submitted")); } else { 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/admin_modules.php b/modules/gallery/controllers/admin_modules.php index af6dbbdc..549718e7 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -37,7 +37,7 @@ class Admin_Modules_Controller extends Admin_Controller { continue; } - $desired = $this->input->post($module_name) == 1; + $desired = Input::instance()->post($module_name) == 1; if ($info->active && !$desired && module::is_active($module_name)) { $changes->deactivate[] = $module_name; $deactivated_names[] = t($info->name); diff --git a/modules/gallery/controllers/admin_sidebar.php b/modules/gallery/controllers/admin_sidebar.php index 77e83bc2..4c55bf89 100644 --- a/modules/gallery/controllers/admin_sidebar.php +++ b/modules/gallery/controllers/admin_sidebar.php @@ -34,7 +34,7 @@ class Admin_Sidebar_Controller extends Admin_Controller { $available_blocks = block_manager::get_available_site_blocks(); $active_blocks = array(); - foreach ($this->input->get("block", array()) as $block_id) { + foreach (Input::instance()->get("block", array()) as $block_id) { $active_blocks[md5($block_id)] = explode(":", (string) $block_id); } block_manager::set_active("site_sidebar", $active_blocks); diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index feaea76d..fde5c02d 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -42,7 +42,8 @@ class Albums_Controller extends Items_Controller { } } - $show = $this->input->get("show"); + $input = Input::instance(); + $show = $input->get("show"); if ($show) { $child = ORM::factory("item", $show); @@ -57,7 +58,7 @@ class Albums_Controller extends Items_Controller { } } - $page = $this->input->get("page", "1"); + $page = $input->get("page", "1"); $children_count = $album->viewable()->children_count(); $offset = ($page - 1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); @@ -71,6 +72,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 +83,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; @@ -93,15 +95,16 @@ class Albums_Controller extends Items_Controller { access::required("view", $album); access::required("add", $album); + $input = Input::instance(); $form = album::get_add_form($album); if ($form->validate()) { $new_album = album::create( $album, - $this->input->post("name"), - $this->input->post("title", $this->input->post("name")), - $this->input->post("description"), + $input->post("name"), + $input->post("title", $input->post("name")), + $input->post("description"), identity::active_user()->id, - $this->input->post("slug")); + $input->post("slug")); log::success("content", "Created an album", html::anchor("albums/$new_album->id", "view album")); 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..65c0cb50 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -29,7 +29,7 @@ class File_Proxy_Controller extends Controller { public function __call($function, $args) { // request_uri: http://example.com/gallery3/var/trunk/albums/foo/bar.jpg - $request_uri = $this->input->server("REQUEST_URI"); + $request_uri = Input::instance()->server("REQUEST_URI"); $request_uri = preg_replace("/\?.*/", "", $request_uri); // var_uri: http://example.com/gallery3/var/ @@ -38,27 +38,27 @@ class File_Proxy_Controller extends Controller { // Make sure that the request is for a file inside var $offset = strpos($request_uri, $var_uri); if ($offset === false) { - kohana::show_404(); + throw new Kohana_404_Exception(); } $file_uri = substr($request_uri, strlen($var_uri)); // Make sure that we don't leave the var dir if (strpos($file_uri, "..") !== false) { - kohana::show_404(); + throw new Kohana_404_Exception(); } list ($type, $path) = explode("/", $file_uri, 2); if ($type != "resizes" && $type != "albums" && $type != "thumbs") { - kohana::show_404(); + throw new Kohana_404_Exception(); } // If the last element is .album.jpg, pop that off since it's not a real item $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,16 +69,16 @@ 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) { - kohana::show_404(); + if (!$item->loaded()) { + throw new Kohana_404_Exception(); } if ($type == "albums") { @@ -91,21 +91,21 @@ class File_Proxy_Controller extends Controller { // Make sure we have access to the item if (!access::can("view", $item)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } // Make sure we have view_full access to the original if ($type == "albums" && !access::can("view_full", $item)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } // Don't try to load a directory if ($type == "albums" && $item->is_album()) { - kohana::show_404(); + throw new Kohana_404_Exception(); } if (!file_exists($file)) { - kohana::show_404(); + throw new Kohana_404_Exception(); } // We don't need to save the session for this request 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..71df1cf1 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; } @@ -113,36 +113,33 @@ class L10n_Client_Controller extends Controller { public static function l10n_form() { if (Input::instance()->get("show_all_l10n_messages")) { $calls = array(); - foreach (Database::instance() + foreach (db::build() ->select("key", "message") ->from("incoming_translations") - ->where(array("locale" => 'root')) - ->get() - ->as_array() as $row) { + ->where("locale", "=", "root") + ->execute() 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() + foreach (db::build() ->select("key", "translation") ->from("incoming_translations") - ->where(array("locale" => $locale)) - ->get() - ->as_array() as $row) { + ->where("locale", "=", $locale) + ->execute() as $row) { $translations[$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() - ->as_array() as $row) { + ->where("locale", "=", $locale) + ->execute() as $row) { $translations[$row->key] = unserialize($row->translation); } diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index 2b93655d..fe9c48ba 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -20,7 +20,7 @@ class Logout_Controller extends Controller { public function index() { auth::logout(); - if ($continue_url = $this->input->get("continue")) { + if ($continue_url = Input::instance()->get("continue")) { $item = url::get_item_from_uri($continue_url); if (access::can("view", $item)) { // Don't use url::redirect() because it'll call url::site() and munge the continue url. diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index 87b73436..14513fdc 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -32,7 +32,7 @@ class Move_Controller extends Controller { public function save($source_id) { access::verify_csrf(); $source = ORM::factory("item", $source_id); - $target = ORM::factory("item", $this->input->post("target_id")); + $target = ORM::factory("item", Input::instance()->post("target_id")); access::required("view", $source); access::required("edit", $source); @@ -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 4e0916b3..2d429910 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) = diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index 1354a01b..2592da31 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -30,7 +30,7 @@ class Packager_Controller extends Controller { $this->_dump_database(); // Dump the database $this->_dump_var(); // Dump the var directory } catch (Exception $e) { - print $e->getTraceAsString(); + print $e->getMessage() . "\n" . $e->getTraceAsString(); return; } @@ -38,11 +38,9 @@ class Packager_Controller extends Controller { } private function _reset() { - $db = Database::instance(); - // Drop all tables - foreach ($db->list_tables() as $table) { - $db->query("DROP TABLE IF EXISTS `$table`"); + foreach (Database::instance()->list_tables() as $table) { + Database::instance()->query("DROP TABLE IF EXISTS {{$table}}"); } // Clean out data @@ -53,7 +51,7 @@ class Packager_Controller extends Controller { dir::unlink(VARPATH . "modules"); dir::unlink(VARPATH . "tmp"); - $db->clear_cache(); + Database::instance()->clear_cache(); module::$modules = array(); module::$active = array(); @@ -84,12 +82,15 @@ class Packager_Controller extends Controller { module::set_var("gallery", "blocks_{$key}", serialize($blocks)); } - $db = Database::instance(); - $db->query("TRUNCATE {sessions}"); - $db->query("TRUNCATE {logs}"); - $db->query("DELETE FROM {vars} WHERE `module_name` = 'gallery' AND `name` = '_cache'"); - $db->update("users", array("password" => ""), array("id" => 1)); - $db->update("users", array("password" => ""), array("id" => 2)); + Database::instance()->query("TRUNCATE {sessions}"); + Database::instance()->query("TRUNCATE {logs}"); + db::build() + ->delete("vars") + ->where("module_name", "=", "gallery") + ->where("name", "=", "_cache") + ->execute(); + db::build()->update("users", array("password" => ""), array("id" => 1))->execute(); + db::build()->update("users", array("password" => ""), array("id" => 2))->execute(); $dbconfig = Kohana::config('database.default'); $conn = $dbconfig["connection"]; 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 455ac25c..7c2c266c 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) = 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); } |