From 4c3b9e363ab1501bf3169d92f5606abf464c2d5e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 25 Nov 2009 08:05:21 -0800 Subject: Refactor the comment module as part of ticket: #917 "Remove Rest Controller" * Remove the methods create, update, delete, get_edit_form as there are not used * Change the return when a comment is created to return the html for the new comment. This saves a second get request to down load the comment. --- modules/comment/controllers/comments.php | 129 ++----------------------- modules/comment/helpers/comment.php | 26 +---- modules/comment/js/comment.js | 21 ++-- modules/comment/views/comment.html.php | 4 +- modules/gallery/tests/controller_auth_data.txt | 1 - 5 files changed, 20 insertions(+), 161 deletions(-) diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index 74e0c974..068152a2 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -17,49 +17,12 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Comments_Controller extends REST_Controller { - protected $resource_type = "comment"; - - /** - * Display comments based on criteria. - * @see REST_Controller::_index() - */ - public function _index() { - $item = ORM::factory("item", $this->input->get('item_id')); - access::required("view", $item); - - $comments = ORM::factory("comment") - ->where("item_id", $item->id) - ->where("state", "published") - ->orderby("created", "DESC") - ->find_all(); - - switch (rest::output_format()) { - case "json": - foreach ($comments as $comment) { - $data[] = array( - "id" => $comment->id, - "author_name" => html::clean($comment->author_name()), - "created" => $comment->created, - "text" => nl2br(html::purify($comment->text))); - } - print json_encode($data); - break; - - case "html": - $view = new Theme_View("comments.html", "other", "comment"); - $view->comments = $comments; - print $view; - break; - } - } - +class Comments_Controller extends Controller { /** * Add a new comment to the collection. - * @see REST_Controller::_create($resource) */ - public function _create($comment) { - $item = ORM::factory("item", $this->input->post("item_id")); + public function create($id) { + $item = ORM::factory("item", $id); access::required("view", $item); $form = comment::get_add_form($item); @@ -96,105 +59,27 @@ class Comments_Controller extends REST_Controller { } $form->add_comment->text->value(""); - print json_encode( - array("result" => "success", - "resource" => ($comment->state == "published" - ? url::site("comments/{$comment->id}") - : null), - "form" => $form->__toString())); - } else { - print json_encode( - array("result" => "error", - "form" => $form->__toString())); - } - } - - /** - * Display an existing comment. - * @todo Set proper Content-Type in a central place (REST_Controller::dispatch?). - * @see REST_Controller::_show($resource) - */ - public function _show($comment) { - $item = ORM::factory("item", $comment->item_id); - access::required("view", $item); - if ($comment->state != "published") { - return; - } - - if (rest::output_format() == "json") { - print json_encode( - array("result" => "success", - "data" => array( - "id" => $comment->id, - "author_name" => html::clean($comment->author_name()), - "created" => $comment->created, - "text" => nl2br(html::purify($comment->text))))); - } else { $view = new Theme_View("comment.html", "other", "comment-fragment"); $view->comment = $comment; - print $view; - } - } - - /** - * Change an existing comment. - * @see REST_Controller::_update($resource) - */ - public function _update($comment) { - $item = ORM::factory("item", $comment->item_id); - access::required("view", $item); - access::required("edit", $item); - - $form = comment::get_edit_form($comment); - if ($form->validate()) { - $comment->guest_name = $form->edit_comment->inputs["name"]->value; - $comment->guest_email = $form->edit_comment->email->value; - $comment->url = $form->edit_comment->url->value; - $comment->text = $form->edit_comment->text->value; - $comment->save(); print json_encode( array("result" => "success", - "resource" => url::site("comments/{$comment->id}"))); + "view" => $view->__toString(), + "form" => $form->__toString())); } else { print json_encode( array("result" => "error", - "html" => $form->__toString())); + "form" => $form->__toString())); } } - /** - * Delete existing comment. - * @see REST_Controller::_delete($resource) - */ - public function _delete($comment) { - $item = ORM::factory("item", $comment->item_id); - access::required("view", $item); - access::required("edit", $item); - - $comment->delete(); - print json_encode(array("result" => "success")); - } - /** * Present a form for adding a new comment to this item or editing an existing comment. - * @see REST_Controller::form_add($resource) */ - public function _form_add($item_id) { + public function form_add($item_id) { $item = ORM::factory("item", $item_id); access::required("view", $item); print comment::get_add_form($item); } - - /** - * Present a form for editing an existing comment. - * @see REST_Controller::form_edit($resource) - */ - public function _form_edit($comment) { - if (!identity::active_user()->admin) { - access::forbidden(); - } - print comment::get_edit_form($comment); - } } diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index 35685d8c..1e1e7d2f 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -65,7 +65,7 @@ class comment_Core { } static function get_add_form($item) { - $form = new Forge("comments", "", "post", array("id" => "g-comment-form")); + $form = new Forge("comments/create/{$item->id}", "", "post", array("id" => "g-comment-form")); $group = $form->group("add_comment")->label(t("Add comment")); $group->input("name") ->label(t("Name")) ->id("g-author"); $group->input("email") ->label(t("Email (hidden)")) ->id("g-email"); @@ -87,29 +87,5 @@ class comment_Core { return $form; } - - static function get_edit_form($comment) { - $form = new Forge("comments/{$comment->id}?_method=put", "", "post", - array("id" => "g-edit-comment-form")); - $group = $form->group("edit_comment")->label(t("Edit comment")); - $group->input("name") ->label(t("Author")) ->id("g-author"); - $group->input("email") ->label(t("Email (hidden)")) ->id("g-email"); - $group->input("url") ->label(t("Website (hidden)"))->id("g-url"); - $group->textarea("text")->label(t("Comment")) ->id("g-text"); - $group->submit("")->value(t("Edit")); - - $group->text = $comment->text; - $author = $comment->author(); - if ($author->guest) { - $group->inputs["name"]->value = $comment->guest_name; - $group->email = $comment->guest_email; - $group->url = $comment->guest_url; - } else { - $group->inputs["name"]->value($author->full_name)->disabled("disabled"); - $group->email->value($author->email)->disabled("disabled"); - $group->url->value($author->url)->disabled("disabled"); - } - return $form; - } } diff --git a/modules/comment/js/comment.js b/modules/comment/js/comment.js index 3f058062..bb204b78 100644 --- a/modules/comment/js/comment.js +++ b/modules/comment/js/comment.js @@ -28,17 +28,16 @@ function ajaxify_comment_form() { $("#g-comments form").ajaxForm({ dataType: "json", success: function(data) { - if (data.form) { - $("#g-comments form").replaceWith(data.form); - ajaxify_comment_form(); - } - if (data.result == "success" && data.resource) { - $.get(data.resource, function(data, textStatus) { - $("#g-comments .g-block-content ul:first").append("
  • "+data+"
  • "); - $("#g-comments .g-block-content ul:first li:last").effect("highlight", {color: "#cfc"}, 8000); - $("#g-comment-form").hide(2000).remove(); - $("#g-no-comments-yet").hide(2000); - }); + if (data.result == "success") { + $("#g-comments #g-comment-detail ul").append(data.view); + $("#g-comments #g-comment-detail ul li:last").effect("highlight", {color: "#cfc"}, 8000); + $("#g-comment-form").hide(2000).remove(); + $("#g-no-comments-yet").hide(2000); + } else { + if (data.form) { + $("#g-comments form").replaceWith(data.form); + ajaxify_comment_form(); + } } } }); diff --git a/modules/comment/views/comment.html.php b/modules/comment/views/comment.html.php index c7957c15..2c485b53 100644 --- a/modules/comment/views/comment.html.php +++ b/modules/comment/views/comment.html.php @@ -8,9 +8,9 @@ width="40" height="40" /> - %name said", array("date_time" => gallery::date_time($comment->created), - "author_name" => html::clean($comment->author_name()))) ?> + "name" => html::clean($comment->author_name()))) ?>

    text)) ?> diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 30102538..c06ddcbf 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -1,5 +1,4 @@ modules/comment/controllers/admin_comments.php queue DIRTY_CSRF -modules/comment/controllers/comments.php _index DIRTY_CSRF modules/comment/helpers/comment_rss.php feed DIRTY_AUTH modules/digibug/controllers/digibug.php print_proxy DIRTY_CSRF|DIRTY_AUTH modules/digibug/controllers/digibug.php close_window DIRTY_AUTH -- cgit v1.2.3 From 454a96f48fbfbf5764cf586c02539e2d01b56101 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 25 Nov 2009 09:08:33 -0800 Subject: Refactor the tags to remove the REST_Controller. Partial fix for ticket #917 --- modules/gallery/tests/controller_auth_data.txt | 3 ++- modules/gallery/tests/xss_data.txt | 4 ++-- modules/tag/controllers/tags.php | 24 +++++++----------------- modules/tag/helpers/tag.php | 2 +- modules/tag/models/tag.php | 2 +- modules/tag/views/tag_block.html.php | 4 +--- 6 files changed, 14 insertions(+), 25 deletions(-) diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index c06ddcbf..b1ad6347 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -34,6 +34,7 @@ modules/search/controllers/search.php index modules/server_add/controllers/admin_server_add.php autocomplete DIRTY_CSRF modules/server_add/controllers/server_add.php children DIRTY_CSRF modules/tag/controllers/admin_tags.php index DIRTY_CSRF -modules/tag/controllers/tags.php _show DIRTY_CSRF|DIRTY_AUTH +modules/tag/controllers/tags.php show DIRTY_CSRF|DIRTY_AUTH +modules/tag/controllers/tags.php autocomplete DIRTY_CSRF|DIRTY_AUTH modules/user/controllers/password.php reset DIRTY_AUTH modules/user/controllers/password.php do_reset DIRTY_CSRF|DIRTY_AUTH diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index fa818636..3708bc6d 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -298,8 +298,8 @@ modules/server_add/views/server_add_tree_dialog.html.php 4 DIRTY_JS url::s modules/server_add/views/server_add_tree_dialog.html.php 21 DIRTY $tree modules/tag/views/admin_tags.html.php 45 DIRTY_ATTR $tag->id modules/tag/views/admin_tags.html.php 46 DIRTY $tag->count -modules/tag/views/tag_block.html.php 27 DIRTY $cloud -modules/tag/views/tag_block.html.php 29 DIRTY $form +modules/tag/views/tag_block.html.php 25 DIRTY $cloud +modules/tag/views/tag_block.html.php 27 DIRTY $form modules/tag/views/tag_cloud.html.php 4 DIRTY_ATTR (int)(($tag->count/$max_count)*7) modules/tag/views/tag_cloud.html.php 5 DIRTY $tag->count modules/tag/views/tag_cloud.html.php 6 DIRTY_JS $tag->url() diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 52001719..9f9e45d9 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -17,10 +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 Tags_Controller extends REST_Controller { - protected $resource_type = "tag"; - - public function _show($tag) { +class Tags_Controller extends Controller { + public function show($tag_id) { + $tag = ORM::factory("tag", $tag_id); $page_size = module::get_var("gallery", "page_size", 9); $page = (int) $this->input->get("page", "1"); $children_count = $tag->items_count(); @@ -47,15 +46,15 @@ class Tags_Controller extends REST_Controller { print $template; } - public function _index() { + public function index() { // Far from perfection, but at least require view permission for the root album $album = ORM::factory("item", 1); access::required("view", $album); print tag::cloud(30); } - public function _create($tag) { - $item = ORM::factory("item", $this->input->post("item_id")); + public function create($item_id) { + $item = ORM::factory("item", $item_id); access::required("view", $item); access::required("edit", $item); @@ -70,8 +69,7 @@ class Tags_Controller extends REST_Controller { print json_encode( array("result" => "success", - "resource" => url::site("tags/{$tag->id}"), - "form" => tag::get_add_form($item)->__toString())); + "cloud" => tag::cloud(30)->__toString())); } else { print json_encode( array("result" => "error", @@ -79,14 +77,6 @@ class Tags_Controller extends REST_Controller { } } - public function _form_add($item_id) { - $item = ORM::factory("item", $item_id); - access::required("view", $item); - access::required("edit", $item); - - return tag::get_add_form($item); - } - public function autocomplete() { $tags = array(); $tag_parts = preg_split("#,#", $this->input->get("q")); diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index feaf40c5..89a27034 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -101,7 +101,7 @@ class tag_Core { } static function get_add_form($item) { - $form = new Forge("tags", "", "post", array("id" => "g-add-tag-form", "class" => "g-short-form")); + $form = new Forge("tags/create/{$item->id}", "", "post", array("id" => "g-add-tag-form", "class" => "g-short-form")); $label = $item->is_album() ? t("Add tag to album") : ($item->is_photo() ? t("Add tag to photo") : t("Add tag to movie")); diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index 49512daa..be020f5f 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -110,7 +110,7 @@ class Tag_Model extends ORM { * @param string $query the query string (eg "page=3") */ public function url($query=null) { - $url = url::site("tags/$this->id"); + $url = url::site("tags/show/$this->id"); if ($query) { $url .= "?$query"; } diff --git a/modules/tag/views/tag_block.html.php b/modules/tag/views/tag_block.html.php index 00b57360..8b887282 100644 --- a/modules/tag/views/tag_block.html.php +++ b/modules/tag/views/tag_block.html.php @@ -14,9 +14,7 @@ dataType: "json", success: function(data) { if (data.result == "success") { - $.get($("#g-tag-cloud").attr("ref"), function(data, textStatus) { - $("#g-tag-cloud").html(data); - }); + $("#g-tag-cloud").html(data.cloud); } $("#g-add-tag-form").resetForm(); } -- cgit v1.2.3 From 0bf81f0381ddde2efde55b10e2d73dfdbdca1e73 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 25 Nov 2009 09:16:49 -0800 Subject: Remove a debugging statement --- modules/gallery/tests/Database_Test.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php index ad2bbba1..98bd4046 100644 --- a/modules/gallery/tests/Database_Test.php +++ b/modules/gallery/tests/Database_Test.php @@ -138,7 +138,6 @@ class Database_For_Test extends Database { public function query($sql = '') { if (!empty($sql)) { - print " query($sql)\n"; $sql = $this->add_table_prefixes($sql); } return $sql; -- cgit v1.2.3 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/controllers/albums.php | 91 +++--------------------- modules/gallery/controllers/items.php | 12 ++-- modules/gallery/controllers/movies.php | 16 ++--- modules/gallery/controllers/photos.php | 17 ++--- modules/gallery/helpers/album.php | 4 +- modules/gallery/helpers/movie.php | 2 +- modules/gallery/helpers/photo.php | 2 +- modules/gallery/tests/Albums_Controller_Test.php | 3 +- modules/gallery/tests/Photos_Controller_Test.php | 3 +- modules/gallery/tests/controller_auth_data.txt | 1 - 10 files changed, 32 insertions(+), 119 deletions(-) diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index e67df6f6..43040b67 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -18,10 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Albums_Controller extends Items_Controller { - - /** - * @see REST_Controller::_show($resource) - */ public function _show($album) { $page_size = module::get_var("gallery", "page_size", 9); if (!access::can("view", $album)) { @@ -82,27 +78,9 @@ class Albums_Controller extends Items_Controller { print $template; } - /** - * @see REST_Controller::_create($resource) - */ - public function _create($album) { + public function create($parent_id) { access::verify_csrf(); - access::required("view", $album); - access::required("add", $album); - - switch ($this->input->post("type")) { - case "album": - return $this->_create_album($album); - - case "photo": - return $this->_create_photo($album); - - default: - access::forbidden(); - } - } - - private function _create_album($album) { + $album = ORM::factory("item", $parent_id); access::required("view", $album); access::required("add", $album); @@ -123,8 +101,7 @@ class Albums_Controller extends Items_Controller { print json_encode( array("result" => "success", - "location" => $new_album->url(), - "resource" => $new_album->url())); + "location" => $new_album->url())); } else { print json_encode( array( @@ -133,43 +110,9 @@ class Albums_Controller extends Items_Controller { } } - private function _create_photo($album) { - access::required("view", $album); - access::required("add", $album); - - // If we set the content type as JSON, it triggers saving the result as - // a document in the browser (well, in Chrome at least). - // @todo figure out why and fix this. - $form = photo::get_add_form($album); - if ($form->validate()) { - $photo = photo::create( - $album, - $this->input->post("file"), - $_FILES["file"]["name"], - $this->input->post("title", $this->input->post("name")), - $this->input->post("description"), - identity::active_user()->id); - - log::success("content", "Added a photo", html::anchor("photos/$photo->id", "view photo")); - message::success(t("Added photo %photo_title", - array("photo_title" => html::purify($photo->title)))); - - print json_encode( - array("result" => "success", - "resource" => $photo->url(), - "location" => $photo->url())); - } else { - print json_encode( - array("result" => "error", - "form" => $form->__toString())); - } - } - - /** - * @see REST_Controller::_update($resource) - */ - public function _update($album) { + public function update($album_id) { access::verify_csrf(); + $album = ORM::factory("item", $album_id); access::required("view", $album); access::required("edit", $album); @@ -229,32 +172,16 @@ class Albums_Controller extends Items_Controller { } } - /** - * @see REST_Controller::_form_add($parameters) - */ - public function _form_add($album_id) { + public function form_add($album_id) { $album = ORM::factory("item", $album_id); access::required("view", $album); access::required("add", $album); - switch ($this->input->get("type")) { - case "album": - print album::get_add_form($album); - break; - - case "photo": - print photo::get_add_form($album); - break; - - default: - kohana::show_404(); - } + print album::get_add_form($album); } - /** - * @see REST_Controller::_form_add($parameters) - */ - public function _form_edit($album) { + public function form_edit($album_id) { + $album = ORM::factory("item", $album_id); access::required("view", $album); access::required("edit", $album); diff --git a/modules/gallery/controllers/items.php b/modules/gallery/controllers/items.php index 7f60f2b7..ec3681a3 100644 --- a/modules/gallery/controllers/items.php +++ b/modules/gallery/controllers/items.php @@ -17,14 +17,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Items_Controller extends REST_Controller { - protected $resource_type = "item"; - - public function _show($item) { +class Items_Controller extends Controller { + public function __call($function, $args) { + $item = ORM::factory("item", (int)$function); + 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. access::required("view", $item); - return url::redirect($item->abs_url()); + return $this->_show($item); } } diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 2e2e837c..3d5eac32 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -18,10 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Movies_Controller extends Items_Controller { - - /** - * @see REST_Controller::_show($resource) - */ public function _show($movie) { access::required("view", $movie); @@ -53,11 +49,9 @@ class Movies_Controller extends Items_Controller { print $template; } - /** - * @see REST_Controller::_update($resource) - */ - public function _update($movie) { + public function update($movie_id) { access::verify_csrf(); + $movie = ORM::factory("item", $movie_id); access::required("view", $movie); access::required("edit", $movie); @@ -120,10 +114,8 @@ class Movies_Controller extends Items_Controller { } } - /** - * @see REST_Controller::_form_edit($resource) - */ - public function _form_edit($movie) { + public function form_edit($movie_id) { + $movie = ORM::factory("item", $movie_id); access::required("view", $movie); access::required("edit", $movie); print movie::get_edit_form($movie); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 0c2ff6ee..f052eccd 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -18,10 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Photos_Controller extends Items_Controller { - - /** - * @see REST_Controller::_show($resource) - */ public function _show($photo) { access::required("view", $photo); @@ -53,12 +49,9 @@ class Photos_Controller extends Items_Controller { print $template; } - - /** - * @see REST_Controller::_update($resource) - */ - public function _update($photo) { + public function update($photo_id) { access::verify_csrf(); + $photo = ORM::factory("item", $photo_id); access::required("view", $photo); access::required("edit", $photo); @@ -125,10 +118,8 @@ class Photos_Controller extends Items_Controller { } } - /** - * @see REST_Controller::_form_edit($resource) - */ - public function _form_edit($photo) { + public function form_edit($photo_id) { + $photo = ORM::factory("item", $photo_id); access::required("view", $photo); access::required("edit", $photo); 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); diff --git a/modules/gallery/tests/Albums_Controller_Test.php b/modules/gallery/tests/Albums_Controller_Test.php index 8562355c..9b904387 100644 --- a/modules/gallery/tests/Albums_Controller_Test.php +++ b/modules/gallery/tests/Albums_Controller_Test.php @@ -48,7 +48,8 @@ class Albums_Controller_Test extends Unit_Test_Case { access::allow(identity::everybody(), "edit", $root); ob_start(); - $controller->_update($this->_album); + $controller->update($this->_album->id); + $this->_album->reload(); $results = ob_get_contents(); ob_end_clean(); diff --git a/modules/gallery/tests/Photos_Controller_Test.php b/modules/gallery/tests/Photos_Controller_Test.php index 624e6878..fa4f101a 100644 --- a/modules/gallery/tests/Photos_Controller_Test.php +++ b/modules/gallery/tests/Photos_Controller_Test.php @@ -44,7 +44,8 @@ class Photos_Controller_Test extends Unit_Test_Case { access::allow(identity::everybody(), "edit", $root); ob_start(); - $controller->_update($photo); + $controller->update($photo->id); + $photo->reload(); $results = ob_get_contents(); ob_end_clean(); diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index b1ad6347..73950d88 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -4,7 +4,6 @@ modules/digibug/controllers/digibug.php print_proxy modules/digibug/controllers/digibug.php close_window DIRTY_AUTH modules/gallery/controllers/admin.php __call DIRTY_AUTH modules/gallery/controllers/albums.php _show DIRTY_CSRF -modules/gallery/controllers/albums.php _form_add DIRTY_CSRF modules/gallery/controllers/combined.php javascript DIRTY_AUTH modules/gallery/controllers/combined.php css DIRTY_AUTH modules/gallery/controllers/file_proxy.php __call DIRTY_CSRF|DIRTY_AUTH -- 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(-) 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 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 ce183e5a698cf0611a68d11fad5a490a91aa9350 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 25 Nov 2009 13:45:58 -0800 Subject: Forgot to remove the rest references from config/route.php --- modules/gallery/config/routes.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/gallery/config/routes.php b/modules/gallery/config/routes.php index 0272ca15..503d6f5b 100644 --- a/modules/gallery/config/routes.php +++ b/modules/gallery/config/routes.php @@ -18,13 +18,10 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -// The abstract REST_Controller is not directly routable. -$config["^rest\b.*"] = null; - // Admin controllers are not available, except via /admin $config["^admin_.*"] = null; -// Redirect /form/add and /form/edit to REST_Controller. +// Redirect /form/add and /form/edit to the module/form_(add|edit)/parms. $config["^form/(edit|add)/(\w+)/(.*)$"] = "$2/form_$1/$3"; // Default page is the root album -- 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(-) 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(-) 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(-) 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 3d4672ba88e2ef8cb47a9769e94fb3a45bdb3882 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 28 Nov 2009 23:48:38 -0800 Subject: Give the theme a chance to handle theme function callbacks as well. --- modules/gallery/libraries/Theme_View.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 817a46ad..f78a7018 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -265,6 +265,13 @@ class Theme_View_Core extends Gallery_View { } } + $helper_class = theme::$site_theme_name . "_theme"; + if (method_exists($helper_class, $function)) { + $blocks[] = call_user_func_array( + array($helper_class, $function), + array_merge(array($this), $args)); + } + if ($function == "head") { array_unshift($blocks, $this->combine_files($this->css, "css")); array_unshift($blocks, $this->combine_files($this->scripts, "javascript")); -- 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(+) 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(-) 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(+) 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(-) 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 883fda313d3d7e76ae98cba7735c4c474b6f517c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 1 Dec 2009 00:08:12 -0800 Subject: Fix a typo that was breaking the home page (doh!) $this->_show() -> $this->show() --- modules/gallery/controllers/albums.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 0cfee7cd..3c1a0adf 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -19,7 +19,7 @@ */ class Albums_Controller extends Items_Controller { public function index() { - $this->_show(ORM::factory("item", 1)); + $this->show(ORM::factory("item", 1)); } public function show($album) { -- cgit v1.2.3 From f9ebe009c306eecf7480cc7778266b61d53b077e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 1 Dec 2009 13:34:40 -0800 Subject: Use the real mime type for movies when we're requesting the full movie instead of a thumbnail. Fixes ticket #925, thanks to lsowen. --- modules/gallery/controllers/file_proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index acfd6eb9..ef4f302c 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -112,7 +112,7 @@ class File_Proxy_Controller extends Controller { Session::abort_save(); // Dump out the image. If the item is a movie, then its thumbnail will be a JPG. - if (in_array($item->mime_type, array("video/x-flv", "video/mp4"))) { + if ($type != "albums" && in_array($item->mime_type, array("video/x-flv", "video/mp4"))) { header("Content-type: image/jpeg"); } else { header("Content-Type: $item->mime_type"); -- cgit v1.2.3 From 6fa880777cb3b61c0e380ebd5e7b83de55a8d6d4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 1 Dec 2009 13:37:07 -0800 Subject: Beter fix for #925. --- modules/gallery/controllers/file_proxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index ef4f302c..8fde1132 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -112,7 +112,7 @@ class File_Proxy_Controller extends Controller { Session::abort_save(); // Dump out the image. If the item is a movie, then its thumbnail will be a JPG. - if ($type != "albums" && in_array($item->mime_type, array("video/x-flv", "video/mp4"))) { + if ($item->is_movie() && $type != "albums") { header("Content-type: image/jpeg"); } else { header("Content-Type: $item->mime_type"); -- cgit v1.2.3 From 714c97763ad9af0bbc5fab97144246b3137d5350 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 2 Dec 2009 11:57:02 -0800 Subject: Extend the background of the status message across the entire status row. --- lib/gallery.common.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/gallery.common.css b/lib/gallery.common.css index 8aa21193..e586f29a 100644 --- a/lib/gallery.common.css +++ b/lib/gallery.common.css @@ -621,10 +621,12 @@ div#g-action-status { #g-add-photos-status li.g-success { background: #d9efc2 url('images/ico-success.png') no-repeat .4em 50%; + width: 429px; } #g-add-photos-status li.g-error { background: #f6cbca url('images/ico-error.png') no-repeat .4em 50%; + width: 429px; /* color: #f00;*/ } @@ -818,4 +820,4 @@ div#g-action-status { .rtl .g-paginator .ui-icon-seek-first { background-position: -64px -160px; -} \ No newline at end of file +} -- cgit v1.2.3 From 1ab8ac305bf53bae8c05b917b06f035b9b700937 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 2 Dec 2009 12:09:34 -0800 Subject: Allow users to override the number of simulatenous uploads. This setting won't appear until after they have attempted to upload at least once and have issues. --- modules/gallery/libraries/Form_Uploadify.php | 7 +++++++ modules/gallery/views/form_uploadify.html.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php index b1d9fa74..52fa45f0 100644 --- a/modules/gallery/libraries/Form_Uploadify.php +++ b/modules/gallery/libraries/Form_Uploadify.php @@ -45,6 +45,13 @@ 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; return $v; } diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php index 5e99c8d5..c18bc8ca 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: 10, + simUploadLimit: , wmode: "transparent", hideButton: true, /* should be true */ auto: true, -- 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(-) 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 From 5c107be9033ae48f781c8430702458f613e791ee Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 4 Dec 2009 11:12:24 -0800 Subject: Reload relevant models after acquiring a lock so that we don't make database calls based on obsolete data, which can lead to data corruption. Fixes ticket #926. --- modules/gallery/libraries/ORM_MPTT.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php index 83d2445c..ebd7abc2 100644 --- a/modules/gallery/libraries/ORM_MPTT.php +++ b/modules/gallery/libraries/ORM_MPTT.php @@ -48,6 +48,7 @@ class ORM_MPTT_Core extends ORM { */ function add_to_parent($parent) { $this->lock(); + $parent->reload(); // Assume that the prior lock holder may have changed the parent try { // Make a hole in the parent for this new item @@ -91,6 +92,7 @@ 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}"); @@ -224,6 +226,8 @@ class ORM_MPTT_Core extends ORM { $level_delta = ($target->level + 1) - $this->level; $this->lock(); + $this->reload(); // Assume that the prior lock holder may have changed this entry + $target->reload(); try { if ($level_delta) { // Update the levels for the to-be-moved items -- cgit v1.2.3