From 2d5c232c42ea52e0c1115dd93edafecf1978fbfe Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 25 Nov 2009 12:41:01 -0800 Subject: Refactor the album, movie and photo handling to remove the REST_Controller. Partial fix for ticket #917 --- modules/gallery/helpers/album.php | 4 ++-- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index 72a79a75..e9a0f6ec 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -92,7 +92,7 @@ class album_Core { } static function get_add_form($parent) { - $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "g-add-album-form")); + $form = new Forge("albums/create/{$parent->id}", "", "post", array("id" => "g-add-album-form")); $group = $form->group("add_album") ->label(t("Add an album to %album_title", array("album_title" => $parent->title))); $group->input("title")->label(t("Title")); @@ -114,7 +114,7 @@ class album_Core { } static function get_edit_form($parent) { - $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "g-edit-album-form")); + $form = new Forge("albums/update/{$parent->id}", "", "post", array("id" => "g-edit-album-form")); $form->hidden("_method")->value("put"); $group = $form->group("edit_item")->label(t("Edit Album")); diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index e84e8ea6..536d5143 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -129,7 +129,7 @@ class movie_Core { } static function get_edit_form($movie) { - $form = new Forge("movies/$movie->id", "", "post", array("id" => "g-edit-movie-form")); + $form = new Forge("movies/update/$movie->id", "", "post", array("id" => "g-edit-movie-form")); $form->hidden("_method")->value("put"); $group = $form->group("edit_item")->label(t("Edit Movie")); $group->input("title")->label(t("Title"))->value($movie->title); diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 01cf5278..3f41097c 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -157,7 +157,7 @@ class photo_Core { } static function get_edit_form($photo) { - $form = new Forge("photos/$photo->id", "", "post", array("id" => "g-edit-photo-form")); + $form = new Forge("photos/update/$photo->id", "", "post", array("id" => "g-edit-photo-form")); $form->hidden("_method")->value("put"); $group = $form->group("edit_item")->label(t("Edit Photo")); $group->input("title")->label(t("Title"))->value($photo->title); -- cgit v1.2.3 From 15cf6870d5a4fc4dae3c5b61b1cb16ccdc226821 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 25 Nov 2009 12:47:00 -0800 Subject: remove the photo::get_add_form method as its not used --- modules/gallery/helpers/photo.php | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 3f41097c..4188e192 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -137,25 +137,6 @@ class photo_Core { return $photo; } - static function get_add_form($parent) { - $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "g-add-photo-form")); - $group = $form->group("add_photo")->label( - t("Add Photo to %album_title", array("album_title" => $parent->title))); - $group->input("title")->label(t("Title")); - $group->textarea("description")->label(t("Description")); - $group->input("name")->label(t("Filename")); - $group->input("slug")->label(t("Internet Address"))->value($photo->slug) - ->callback("item::validate_url_safe") - ->error_messages( - "not_url_safe", - t("The internet address should contain only letters, numbers, hyphens and underscores")); - $group->upload("file")->label(t("File"))->rules("required|allow[jpg,png,gif,flv,mp4]"); - $group->hidden("type")->value("photo"); - $group->submit("")->value(t("Upload")); - $form->add_rules_from(ORM::factory("item")); - return $form; - } - static function get_edit_form($photo) { $form = new Forge("photos/update/$photo->id", "", "post", array("id" => "g-edit-photo-form")); $form->hidden("_method")->value("put"); -- cgit v1.2.3 From dc67cf64813361b34c366123f37d88ef6988fcc8 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 25 Nov 2009 13:02:14 -0800 Subject: Remove the REST_Controller and assorted baggage. Completes ticket #917 --- modules/gallery/controllers/rest.php | 183 ----------------------- modules/gallery/helpers/rest.php | 116 --------------- modules/gallery/tests/Controller_Auth_Test.php | 16 +- modules/gallery/tests/REST_Controller_Test.php | 197 ------------------------- modules/gallery/tests/REST_Helper_Test.php | 45 ------ modules/gallery/tests/controller_auth_data.txt | 11 -- modules/rss/controllers/rss.php | 2 +- modules/rss/helpers/rss.php | 2 +- 8 files changed, 3 insertions(+), 569 deletions(-) delete mode 100644 modules/gallery/controllers/rest.php delete mode 100644 modules/gallery/helpers/rest.php delete mode 100644 modules/gallery/tests/REST_Controller_Test.php delete mode 100644 modules/gallery/tests/REST_Helper_Test.php (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/controllers/rest.php b/modules/gallery/controllers/rest.php deleted file mode 100644 index 2edf079f..00000000 --- a/modules/gallery/controllers/rest.php +++ /dev/null @@ -1,183 +0,0 @@ -resource_type == null) { - throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE"); - } - parent::__construct(); - } - - /** - * Handle dispatching for all REST controllers. - */ - public function __call($function, $args) { - // If no parameter was provided after the controller name (eg "/albums") then $function will - // be set to "index". Otherwise, $function is the first parameter, and $args are all - // subsequent parameters. - $request_method = rest::request_method(); - if ($function == "index" && $request_method == "get") { - return $this->_index(); - } - - $resource = ORM::factory($this->resource_type, (int)$function); - if (!$resource->loaded && $request_method != "post") { - return Kohana::show_404(); - } - - switch ($request_method) { - case "get": - return $this->_show($resource); - - case "put": - access::verify_csrf(); - return $this->_update($resource); - - case "delete": - access::verify_csrf(); - return $this->_delete($resource); - - case "post": - access::verify_csrf(); - return $this->_create($resource); - } - } - - /* We're editing an existing item, load it from the database. */ - public function form_edit($resource_id) { - if ($this->resource_type == null) { - throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE"); - } - - $resource = ORM::factory($this->resource_type, $resource_id); - if (!$resource->loaded) { - return Kohana::show_404(); - } - - // Security checks must be performed in _form_edit - return $this->_form_edit($resource); - } - - /* We're adding a new item, pass along any additional parameters. */ - public function form_add($parameters) { - // Security checks must be performed in _form_add - return $this->_form_add($parameters); - } - - /** - * Perform a GET request on the controller root - * (e.g. http://www.example.com/gallery3/comments) - */ - public function _index() { - throw new Exception("@todo _create NOT IMPLEMENTED"); - } - - /** - * Perform a POST request on this resource - * @param ORM $resource the instance of this resource type - */ - public function _create($resource) { - throw new Exception("@todo _create NOT IMPLEMENTED"); - } - - /** - * Perform a GET request on this resource - * @param ORM $resource the instance of this resource type - */ - public function _show($resource) { - throw new Exception("@todo _show NOT IMPLEMENTED"); - } - - /** - * Perform a PUT request on this resource - * @param ORM $resource the instance of this resource type - */ - public function _update($resource) { - throw new Exception("@todo _update NOT IMPLEMENTED"); - } - - /** - * Perform a DELETE request on this resource - * @param ORM $resource the instance of this resource type - */ - public function _delete($resource) { - throw new Exception("@todo _delete NOT IMPLEMENTED"); - } - - /** - * Present a form for adding a new resource - * @param string part of the URI after the controller name - */ - public function _form_add($parameter) { - throw new Exception("@todo _form_add NOT IMPLEMENTED"); - } - - /** - * Present a form for editing an existing resource - * @param ORM $resource the resource container for instances of this resource type - */ - public function _form_edit($resource) { - throw new Exception("@todo _form_edit NOT IMPLEMENTED"); - } -} diff --git a/modules/gallery/helpers/rest.php b/modules/gallery/helpers/rest.php deleted file mode 100644 index a63b94c8..00000000 --- a/modules/gallery/helpers/rest.php +++ /dev/null @@ -1,116 +0,0 @@ -post("_method", $input->get("_method", request::method())))) { - case "put": return "put"; - case "delete": return "delete"; - default: return "post"; - } - } - } - - /** - * Choose an output format based on what the client prefers to accept. - * @return string "html", "xml" or "json" - */ - static function output_format() { - // Pick a format, but let it be overridden. - $input = Input::instance(); - $fmt = $input->get( - "_format", $input->post( - "_format", request::preferred_accept( - array("xhtml", "html", "xml", "json")))); - - // Some browsers (Chrome!) prefer xhtml over html, but we'll normalize this to html for now. - if ($fmt == "xhtml") { - $fmt = "html"; - } - return $fmt; - } - - /** - * Set HTTP response code. - * @param string Use one of the status code constants defined in this class. - */ - static function http_status($status_code) { - header("HTTP/1.1 " . $status_code); - } - - /** - * Set HTTP Location header. - * @param string URL - */ - static function http_location($url) { - header("Location: " . $url); - } - - /** - * Set HTTP Content-Type header. - * @param string content type - */ - static function http_content_type($type) { - header("Content-Type: " . $type); - } -} diff --git a/modules/gallery/tests/Controller_Auth_Test.php b/modules/gallery/tests/Controller_Auth_Test.php index 0a7076c6..124d8b4c 100644 --- a/modules/gallery/tests/Controller_Auth_Test.php +++ b/modules/gallery/tests/Controller_Auth_Test.php @@ -18,11 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Controller_Auth_Test extends Unit_Test_Case { - static $rest_methods = array("_index", "_show", "_form_edit", "_form_add", "_create", - "_update", "_delete"); - - static $rest_methods_with_csrf_check = array("_update", "_delete", "_create"); - public function find_missing_auth_test() { $found = array(); $controllers = explode("\n", `git ls-files '*/*/controllers/*.php'`); @@ -46,7 +41,6 @@ class Controller_Auth_Test extends Unit_Test_Case { } $is_admin_controller = false; - $is_rest_controller = false; $open_braces = 0; $function = null; @@ -64,7 +58,6 @@ class Controller_Auth_Test extends Unit_Test_Case { $function = null; } else if ($open_braces == 0) { $is_admin_controller = false; - $is_rest_controller = false; } } else if ($token == "{") { $open_braces++; @@ -75,8 +68,6 @@ class Controller_Auth_Test extends Unit_Test_Case { if ($open_braces == 0 && $token[0] == T_EXTENDS) { if (self::_token_matches(array(T_STRING, "Admin_Controller"), $tokens, $token_number + 1)) { $is_admin_controller = true; - } else if (self::_token_matches(array(T_STRING, "REST_Controller"), $tokens, $token_number + 1)) { - $is_rest_controller = true; } } else if ($open_braces == 1 && $token[0] == T_FUNCTION) { $line = $token[2]; @@ -101,13 +92,8 @@ class Controller_Auth_Test extends Unit_Test_Case { $is_rss_feed = $name == "feed" && strpos(basename($controller), "_rss.php"); - if ((!$is_static || $is_rss_feed) && - (!$is_private || - ($is_rest_controller && in_array($name, self::$rest_methods)))) { + if ((!$is_static || $is_rss_feed) && !$is_private) { $function = self::_function($name, $line, $is_admin_controller); - if ($is_rest_controller && in_array($name, self::$rest_methods_with_csrf_check)) { - $function->checks_csrf(true); - } } } diff --git a/modules/gallery/tests/REST_Controller_Test.php b/modules/gallery/tests/REST_Controller_Test.php deleted file mode 100644 index 8fb04d86..00000000 --- a/modules/gallery/tests/REST_Controller_Test.php +++ /dev/null @@ -1,197 +0,0 @@ -_post = $_POST; - $this->mock_controller = new Mock_RESTful_Controller("mock"); - $this->mock_not_loaded_controller = new Mock_RESTful_Controller("mock_not_loaded"); - $_POST = array(); - } - - public function teardown() { - $_POST = $this->_post; - } - - public function dispatch_index_test() { - $_SERVER["REQUEST_METHOD"] = "GET"; - $_POST["_method"] = ""; - $this->mock_controller->__call("index", ""); - $this->assert_equal("index", $this->mock_controller->method_called); - } - - public function dispatch_show_test() { - $_SERVER["REQUEST_METHOD"] = "GET"; - $_POST["_method"] = ""; - $this->mock_controller->__call("3", ""); - $this->assert_equal("show", $this->mock_controller->method_called); - $this->assert_equal("Mock_Model", get_class($this->mock_controller->resource)); - } - - public function dispatch_update_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; - $_POST["_method"] = "PUT"; - $_POST["csrf"] = access::csrf_token(); - $this->mock_controller->__call("3", ""); - $this->assert_equal("update", $this->mock_controller->method_called); - $this->assert_equal("Mock_Model", get_class($this->mock_controller->resource)); - } - - public function dispatch_update_fails_without_csrf_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; - $_POST["_method"] = "PUT"; - try { - $this->mock_controller->__call("3", ""); - $this->assert_false(true, "this should fail with a forbidden exception"); - } catch (Exception $e) { - // pass - } - } - - public function dispatch_delete_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; - $_POST["_method"] = "DELETE"; - $_POST["csrf"] = access::csrf_token(); - $this->mock_controller->__call("3", ""); - $this->assert_equal("delete", $this->mock_controller->method_called); - $this->assert_equal("Mock_Model", get_class($this->mock_controller->resource)); - } - - public function dispatch_delete_fails_without_csrf_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; - $_POST["_method"] = "DELETE"; - try { - $this->mock_controller->__call("3", ""); - $this->assert_false(true, "this should fail with a forbidden exception"); - } catch (Exception $e) { - // pass - } - } - - public function dispatch_404_test() { - /* The dispatcher should throw a 404 if the resource isn't loaded and the method isn't POST. */ - $methods = array( - array("GET", ""), - array("POST", "PUT"), - array("POST", "DELETE")); - - foreach ($methods as $method) { - $_SERVER["REQUEST_METHOD"] = $method[0]; - $_POST["_method"] = $method[1]; - $exception_caught = false; - try { - $this->mock_not_loaded_controller->__call(rand(), ""); - } catch (Kohana_404_Exception $e) { - $exception_caught = true; - } - $this->assert_true($exception_caught, "$method[0], $method[1]"); - } - } - - public function dispatch_create_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; - $_POST["_method"] = ""; - $_POST["csrf"] = access::csrf_token(); - $this->mock_not_loaded_controller->__call("", ""); - $this->assert_equal("create", $this->mock_not_loaded_controller->method_called); - $this->assert_equal( - "Mock_Not_Loaded_Model", get_class($this->mock_not_loaded_controller->resource)); - } - - public function dispatch_create_fails_without_csrf_test() { - $_SERVER["REQUEST_METHOD"] = "POST"; - $_POST["_method"] = ""; - try { - $this->mock_not_loaded_controller->__call("", ""); - $this->assert_false(true, "this should fail with a forbidden exception"); - } catch (Exception $e) { - // pass - } - } - - public function dispatch_form_test_add() { - $this->mock_controller->form_add("args"); - $this->assert_equal("form_add", $this->mock_controller->method_called); - $this->assert_equal("args", $this->mock_controller->resource); - } - - public function dispatch_form_test_edit() { - $this->mock_controller->form_edit("1"); - $this->assert_equal("form_edit", $this->mock_controller->method_called); - $this->assert_equal("Mock_Model", get_class($this->mock_controller->resource)); - } - - public function routes_test() { - $this->assert_equal("mock/form_add/args", router::routed_uri("form/add/mock/args")); - $this->assert_equal("mock/form_edit/args", router::routed_uri("form/edit/mock/args")); - $this->assert_equal(null, router::routed_uri("rest/args")); - } -} - -class Mock_RESTful_Controller extends REST_Controller { - public $method_called; - public $resource; - - public function __construct($type) { - $this->resource_type = $type; - parent::__construct(); - } - - public function _index() { - $this->method_called = "index"; - } - - public function _create($resource) { - $this->method_called = "create"; - $this->resource = $resource; - } - - public function _show($resource) { - $this->method_called = "show"; - $this->resource = $resource; - } - - public function _update($resource) { - $this->method_called = "update"; - $this->resource = $resource; - } - - public function _delete($resource) { - $this->method_called = "delete"; - $this->resource = $resource; - } - - public function _form_add($args) { - $this->method_called = "form_add"; - $this->resource = $args; - } - - public function _form_edit($resource) { - $this->method_called = "form_edit"; - $this->resource = $resource; - } -} - -class Mock_Model { - public $loaded = true; -} - -class Mock_Not_Loaded_Model { - public $loaded = false; -} diff --git a/modules/gallery/tests/REST_Helper_Test.php b/modules/gallery/tests/REST_Helper_Test.php deleted file mode 100644 index 1bfc63ab..00000000 --- a/modules/gallery/tests/REST_Helper_Test.php +++ /dev/null @@ -1,45 +0,0 @@ -_post = $_POST; - } - - public function teardown() { - $_POST = $this->_post; - } - - public function request_method_test() { - foreach (array("GET", "POST") as $method) { - foreach (array("", "PUT", "DELETE") as $tunnel) { - if ($method == "GET") { - $expected = "GET"; - } else { - $expected = $tunnel == "" ? $method : $tunnel; - } - $_SERVER["REQUEST_METHOD"] = $method; - $_POST["_method"] = $tunnel; - - $this->assert_equal(strtolower(rest::request_method()), strtolower($expected), - "Request method: {$method}, tunneled: {$tunnel}"); - } - } - } -} diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 73950d88..1fe29ffb 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -13,17 +13,6 @@ modules/gallery/controllers/login.php html modules/gallery/controllers/login.php auth_html DIRTY_AUTH modules/gallery/controllers/logout.php index DIRTY_CSRF|DIRTY_AUTH modules/gallery/controllers/maintenance.php index DIRTY_AUTH -modules/gallery/controllers/rest.php __construct DIRTY_AUTH -modules/gallery/controllers/rest.php __call DIRTY_AUTH -modules/gallery/controllers/rest.php form_edit DIRTY_AUTH -modules/gallery/controllers/rest.php form_add DIRTY_AUTH -modules/gallery/controllers/rest.php _index DIRTY_AUTH -modules/gallery/controllers/rest.php _create DIRTY_AUTH -modules/gallery/controllers/rest.php _show DIRTY_AUTH -modules/gallery/controllers/rest.php _update DIRTY_AUTH -modules/gallery/controllers/rest.php _delete DIRTY_AUTH -modules/gallery/controllers/rest.php _form_add DIRTY_AUTH -modules/gallery/controllers/rest.php _form_edit DIRTY_AUTH modules/gallery/controllers/simple_uploader.php start DIRTY_AUTH modules/gallery/controllers/simple_uploader.php finish DIRTY_AUTH modules/gallery/controllers/upgrader.php index DIRTY_AUTH diff --git a/modules/rss/controllers/rss.php b/modules/rss/controllers/rss.php index 1ecec9af..ed2acef8 100644 --- a/modules/rss/controllers/rss.php +++ b/modules/rss/controllers/rss.php @@ -62,7 +62,7 @@ class Rss_Controller extends Controller { url::abs_site(str_replace("&", "&", url::merge(array("page" => $page + 1)))); } - rest::http_content_type(rest::RSS); + header("Content-Type: application/rss+xml"); print $view; } } \ No newline at end of file diff --git a/modules/rss/helpers/rss.php b/modules/rss/helpers/rss.php index 81ff175f..4260206c 100644 --- a/modules/rss/helpers/rss.php +++ b/modules/rss/helpers/rss.php @@ -31,6 +31,6 @@ class rss_Core { */ static function feed_link($uri) { $url = url::site("rss/feed/$uri"); - return ""; + return ""; } } \ No newline at end of file -- cgit v1.2.3 From 22149b52c309152b3e0e186159df9e80ae5c28f8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 27 Nov 2009 17:12:13 -0800 Subject: Move the theme fallback checking into theme::load_themes() so that we're calling it once per request. --- modules/gallery/helpers/theme.php | 17 +++++++++++++---- modules/gallery/libraries/Admin_View.php | 6 ------ modules/gallery/libraries/Theme_View.php | 6 ------ 3 files changed, 13 insertions(+), 16 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 16ed104e..efc9b9e6 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -24,6 +24,8 @@ * Note: by design, this class does not do any permission checking. */ class theme_Core { + public static $active_theme; + /** * Load the active theme. This is called at bootstrap time. We will only ever have one theme * active for any given request. @@ -35,15 +37,22 @@ class theme_Core { $path = "/" . $input->get("kohana_uri"); } + $is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7); + $setting_name = $is_admin ? "active_admin_theme" : "active_site_theme"; if (!(identity::active_user()->admin && $theme_name = $input->get("theme"))) { - $theme_name = module::get_var( - "gallery", - $path == "/admin" || !strncmp($path, "/admin/", 7) ? - "active_admin_theme" : "active_site_theme"); + $theme_name = module::get_var("gallery", $setting_name); + + if (!file_exists(THEMEPATH . $theme_name)) { + Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); + $theme_name = $is_admin ? "admin_wind" : "wind"; + module::set_var("gallery", $setting_name, $theme_name); + } } $modules = Kohana::config("core.modules"); array_unshift($modules, THEMEPATH . $theme_name); Kohana::config_set("core.modules", $modules); + + self::$active_theme = $theme_name; } static function get_edit_form_admin() { diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index cbb781a1..a990e4ca 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -27,12 +27,6 @@ class Admin_View_Core extends Gallery_View { * @return void */ public function __construct($name) { - $theme_name = module::get_var("gallery", "active_admin_theme"); - if (!file_exists(THEMEPATH . $theme_name)) { - module::set_var("gallery", "active_admin_theme", "admin_wind"); - theme::load_themes(); - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); - } parent::__construct($name); $this->theme_name = module::get_var("gallery", "active_admin_theme"); diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index b64deab9..817a46ad 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -29,12 +29,6 @@ class Theme_View_Core extends Gallery_View { * @return void */ public function __construct($name, $page_type, $page_subtype) { - $theme_name = module::get_var("gallery", "active_site_theme"); - if (!file_exists(THEMEPATH . $theme_name)) { - module::set_var("gallery", "active_site_theme", "wind"); - theme::load_themes(); - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); - } parent::__construct($name); $this->theme_name = module::get_var("gallery", "active_site_theme"); -- cgit v1.2.3 From b677778253cdea89e19befbf04441a741010bfc2 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 28 Nov 2009 15:42:11 -0800 Subject: Expose theme::$is_admin --- modules/gallery/helpers/theme.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index efc9b9e6..19737c0e 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -25,6 +25,7 @@ */ class theme_Core { public static $active_theme; + public static $is_admin; /** * Load the active theme. This is called at bootstrap time. We will only ever have one theme @@ -37,14 +38,14 @@ class theme_Core { $path = "/" . $input->get("kohana_uri"); } - $is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7); - $setting_name = $is_admin ? "active_admin_theme" : "active_site_theme"; + self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7); + $setting_name = self::$is_admin ? "active_admin_theme" : "active_site_theme"; if (!(identity::active_user()->admin && $theme_name = $input->get("theme"))) { $theme_name = module::get_var("gallery", $setting_name); if (!file_exists(THEMEPATH . $theme_name)) { Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); - $theme_name = $is_admin ? "admin_wind" : "wind"; + $theme_name = self::$is_admin ? "admin_wind" : "wind"; module::set_var("gallery", $setting_name, $theme_name); } } -- cgit v1.2.3 From f3981bbaa9c9e72d147e164a3decea411b6dd54c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 28 Nov 2009 23:25:07 -0800 Subject: Rework the theme loading code to allow themes to be treated as Gallery modules, and have an admin subdirectory that is treated like a Kohana module (as distinct from a Gallery module). The main advantage of creating the separate admin subdirectory is that we will not load an admin theme and a site theme at the same time. We'll only load a few specialized bits of the site theme while the admin theme is active. Concrete examples. A site theme named "xxx": - will receive events at themes/xxx/helpers/xxx_event.php - will have working controllers at themes/xxx/controllers/xxx.php If theme xxx has an admin subdir, then in admin mode it: - will receive events at themes/xxx/admin/helpers/xxx_event.php - will have working controllers at themes/xxx/admin/controllers/xxx.php --- modules/gallery/helpers/module.php | 15 +++++++++++++++ modules/gallery/helpers/theme.php | 35 +++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 12 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index e6c196ce..50abdaae 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -335,6 +335,21 @@ class module_Core { call_user_func_array(array($class, $function), $args); } } + + // Give the admin theme a chance to respond, if we're in admin mode. + if (theme::$is_admin) { + $class = theme::$admin_theme_name . "_event"; + if (method_exists($class, $function)) { + call_user_func_array(array($class, $function), $args); + } + } + + // Give the site theme a chance to respond as well. It gets a chance even in admin mode, as + // long as the theme has an admin subdir. + $class = theme::$site_theme_name . "_event"; + if (method_exists($class, $function)) { + call_user_func_array(array($class, $function), $args); + } } /** diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 19737c0e..75b48bcc 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -24,7 +24,8 @@ * Note: by design, this class does not do any permission checking. */ class theme_Core { - public static $active_theme; + public static $admin_theme_name; + public static $site_theme_name; public static $is_admin; /** @@ -38,22 +39,32 @@ class theme_Core { $path = "/" . $input->get("kohana_uri"); } + $modules = Kohana::config("core.modules"); self::$is_admin = $path == "/admin" || !strncmp($path, "/admin/", 7); - $setting_name = self::$is_admin ? "active_admin_theme" : "active_site_theme"; - if (!(identity::active_user()->admin && $theme_name = $input->get("theme"))) { - $theme_name = module::get_var("gallery", $setting_name); + self::$site_theme_name = module::get_var("gallery", "active_site_theme"); + if (self::$is_admin) { + // Load the admin theme + self::$admin_theme_name = module::get_var("gallery", "active_admin_theme"); + array_unshift($modules, THEMEPATH . self::$admin_theme_name); - if (!file_exists(THEMEPATH . $theme_name)) { - Kohana::log("error", "Unable to locate theme '$theme_name', switching to default theme."); - $theme_name = self::$is_admin ? "admin_wind" : "wind"; - module::set_var("gallery", $setting_name, $theme_name); + // If the site theme has an admin subdir, load that as a module so that + // themes can provide their own code. + if (file_exists(THEMEPATH . self::$site_theme_name . "/admin")) { + array_unshift($modules, THEMEPATH . self::$site_theme_name . "/admin"); + } + } else { + // Admins can override the site theme, temporarily. This lets us preview themes. + if (identity::active_user()->admin && $override = $input->get("theme")) { + if (file_exists(THEMEPATH . $override)) { + self::$site_theme_name = $override; + } else { + Kohana::log("error", "Missing override theme: '$override'"); + } } + array_unshift($modules, THEMEPATH . self::$site_theme_name); } - $modules = Kohana::config("core.modules"); - array_unshift($modules, THEMEPATH . $theme_name); - Kohana::config_set("core.modules", $modules); - self::$active_theme = $theme_name; + Kohana::config_set("core.modules", $modules); } static function get_edit_form_admin() { -- cgit v1.2.3 From 01bad461df11e60f6c92ad68980203cb9ef8425d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 29 Nov 2009 12:39:21 -0800 Subject: Publish theme_edit_form and theme_edit_form_completed events so that themes can piggyback on the regular Admin > Appearance > Theme Options page. --- modules/gallery/controllers/admin_theme_options.php | 2 ++ modules/gallery/helpers/theme.php | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/controllers/admin_theme_options.php b/modules/gallery/controllers/admin_theme_options.php index 27a67bdb..9de54c78 100644 --- a/modules/gallery/controllers/admin_theme_options.php +++ b/modules/gallery/controllers/admin_theme_options.php @@ -58,6 +58,8 @@ class Admin_Theme_Options_Controller extends Admin_Controller { module::set_var("gallery", "footer_text", $form->edit_theme->footer_text->value); module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value); + module::event("theme_edit_form_completed", $form); + message::success(t("Updated theme details")); url::redirect("admin/theme_options"); } else { diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 75b48bcc..247aa5c4 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -85,6 +85,10 @@ class theme_Core { ->value(module::get_var("gallery", "footer_text")); $group->checkbox("show_credits")->label(t("Show site credits"))->id("g-footer-text") ->checked(module::get_var("gallery", "show_credits")); + + module::event("theme_edit_form", $form); + + $group = $form->group("buttons"); $group->submit("")->value(t("Save")); return $form; } -- cgit v1.2.3 From 1b41ad8c42ef02245147c75d8cb87e65712b1843 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 29 Nov 2009 22:47:33 -0800 Subject: Don't use PathInfo based urls to reroute access protection. Fixes ticket #922. --- modules/gallery/helpers/access.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index c1c1f9d1..f54afa10 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -609,7 +609,7 @@ class access_Core { $dirs[] = dirname($album->thumb_path()); } - $base_url = url::site("file_proxy"); + $base_url = url::site("?kohana_uri=/file_proxy"); foreach ($dirs as $dir) { if ($value === self::DENY) { $fp = fopen("$dir/.htaccess", "w+"); -- cgit v1.2.3 From 299da7b54f17408a53f7771305bcdd22ef94ec36 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 30 Nov 2009 10:59:00 -0800 Subject: Don't allow the extra "/?" sequence (ie: "/index.php/?kohana_uri=...") in the generated .htaccess files. --- modules/gallery/helpers/access.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php index f54afa10..88a02ce2 100644 --- a/modules/gallery/helpers/access.php +++ b/modules/gallery/helpers/access.php @@ -610,6 +610,7 @@ class access_Core { } $base_url = url::site("?kohana_uri=/file_proxy"); + $base_url = str_replace("/?", "?", $base_url); foreach ($dirs as $dir) { if ($value === self::DENY) { $fp = fopen("$dir/.htaccess", "w+"); -- cgit v1.2.3 From 852653ef2415dc070c27ce151ed399525ddfa5a0 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 30 Nov 2009 11:10:58 -0800 Subject: Clean up item routing a bit. 1) The new default route is "albums", and Albums_Controller::index() does the right thing 2) Items_Controller redirects to the appropriate specific controller 3) All item controllers now have show() instead of _show(), so that the routing code in url::parse_url() can get to it. But that code is protected against receiving bogus requests. --- modules/gallery/config/routes.php | 2 +- modules/gallery/controllers/albums.php | 11 ++++++++++- modules/gallery/controllers/items.php | 8 +++++--- modules/gallery/controllers/movies.php | 7 ++++++- modules/gallery/controllers/photos.php | 7 ++++++- modules/gallery/helpers/MY_url.php | 3 ++- 6 files changed, 30 insertions(+), 8 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/config/routes.php b/modules/gallery/config/routes.php index 503d6f5b..63cc6150 100644 --- a/modules/gallery/config/routes.php +++ b/modules/gallery/config/routes.php @@ -25,4 +25,4 @@ $config["^admin_.*"] = null; $config["^form/(edit|add)/(\w+)/(.*)$"] = "$2/form_$1/$3"; // Default page is the root album -$config["_default"] = "albums/1"; +$config["_default"] = "albums"; diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 43040b67..0cfee7cd 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -18,7 +18,16 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Albums_Controller extends Items_Controller { - public function _show($album) { + public function index() { + $this->_show(ORM::factory("item", 1)); + } + + public function show($album) { + if (!is_object($album)) { + // show() must be public because we route to it in url::parse_url(), so make + // sure that we're actually receiving an object + Kohana::show_404(); + } $page_size = module::get_var("gallery", "page_size", 9); if (!access::can("view", $album)) { if ($album->id == 1) { diff --git a/modules/gallery/controllers/items.php b/modules/gallery/controllers/items.php index ec3681a3..b350c5a2 100644 --- a/modules/gallery/controllers/items.php +++ b/modules/gallery/controllers/items.php @@ -23,10 +23,12 @@ class Items_Controller extends Controller { if (!$item->loaded) { return Kohana::show_404(); } + // Redirect to the more specific resource type, since it will render - // differently. We could also just delegate here, but it feels more appropriate - // to have a single canonical resource mapping. + // differently. We can't delegate here because we may have gotten to this + // page via /items/ which means that we don't have a type-specific controller. Also, we + // want to drive a single canonical resource mapping where possible. access::required("view", $item); - return $this->_show($item); + url::redirect($item->abs_url()); } } diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 3d5eac32..575b2b60 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -18,7 +18,12 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Movies_Controller extends Items_Controller { - public function _show($movie) { + public function show($movie) { + if (!is_object($movie)) { + // show() must be public because we route to it in url::parse_url(), so make + // sure that we're actually receiving an object + Kohana::show_404(); + } access::required("view", $movie); $where = array("type != " => "album"); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index f052eccd..ba4cfb83 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -18,7 +18,12 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Photos_Controller extends Items_Controller { - public function _show($photo) { + public function show($photo) { + if (!is_object($photo)) { + // show() must be public because we route to it in url::parse_url(), so make + // sure that we're actually receiving an object + Kohana::show_404(); + } access::required("view", $photo); $where = array("type != " => "album"); diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index 368c947e..139aec21 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -35,7 +35,8 @@ class url extends url_Core { if ($item && $item->loaded) { Router::$controller = "{$item->type}s"; Router::$controller_path = MODPATH . "gallery/controllers/{$item->type}s.php"; - Router::$method = $item->id; + Router::$method = "show"; + Router::$arguments = array($item); } } -- cgit v1.2.3 From c9e6869c681fa6579d1858cea45ec94eb0972f30 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 2 Dec 2009 19:08:13 -0800 Subject: Rename the "upload_limit" variable to "simultaneous_upload_limit" for clarity, since it only limits concurrency not the number of actual uploads. Move the default-setting code into the upgrader so that we avoid creating the variable as a side-effect of the view (personal preference to avoid side-effect code since it's led to problems in the past). --- modules/gallery/helpers/gallery_installer.php | 7 +++++++ modules/gallery/libraries/Form_Uploadify.php | 8 +------- modules/gallery/module.info | 3 +-- modules/gallery/views/form_uploadify.html.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 57a5ee9f..39859b36 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -432,6 +432,13 @@ class gallery_installer { module::clear_var("gallery", "blocks_site.sidebar"); module::set_version("gallery", $version = 19); } + + // Set a default for the number of simultaneous uploads + // Version 20 was reverted in 57adefc5baa7a2b0dfcd3e736e80c2fa86d3bfa2, so skip it. + if ($version == 19 || $version == 20) { + module::set_var("gallery", "simultaneous_upload_limit", 5); + module::set_version("gallery", $version = 21); + } } static function uninstall() { diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php index 52fa45f0..9d76153d 100644 --- a/modules/gallery/libraries/Form_Uploadify.php +++ b/modules/gallery/libraries/Form_Uploadify.php @@ -45,13 +45,7 @@ class Form_Uploadify_Core extends Form_Input { $v = new View("form_uploadify.html"); $v->album = $this->data["album"]; $v->script_data = $this->data["script_data"]; - $upload_limit = module::get_var("gallery", "upload_limit"); - if (empty($upload_limit)) { - $upload_limit = 5; - module::set_var("gallery", "upload_limit", 5); - } - - $v->upload_limit = $upload_limit; + $v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit"); return $v; } diff --git a/modules/gallery/module.info b/modules/gallery/module.info index ba1ee91d..b3366f7d 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,5 +1,4 @@ name = "Gallery 3" description = "Gallery core application" -; Note: skip version 20, use 21 as the next version -version = 19 +version = 21 diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php index c18bc8ca..d856c464 100644 --- a/modules/gallery/views/form_uploadify.html.php +++ b/modules/gallery/views/form_uploadify.html.php @@ -24,7 +24,7 @@ fileDesc: for_js() ?>, cancelImg: "", buttonText: for_js() ?>, - simUploadLimit: , + simUploadLimit: , wmode: "transparent", hideButton: true, /* should be true */ auto: true, -- cgit v1.2.3