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(-) (limited to 'modules') 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