From 44753c524996415f465f44d05be46e878911ce4a Mon Sep 17 00:00:00 2001 From: ckieffer Date: Sat, 8 May 2010 15:05:56 -0600 Subject: Deleted extra CSS class assignment for context_menu delete option. --- modules/gallery/helpers/gallery_event.php | 1 - 1 file changed, 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index d723cc1b..c77ed9d4 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -383,7 +383,6 @@ class gallery_event_Core { ->id("delete") ->label($delete_title) ->css_class("ui-icon-trash") - ->css_class("g-quick-delete") ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); } -- cgit v1.2.3 From d98b85f7d3142676e6b4f407a18ed81564823f88 Mon Sep 17 00:00:00 2001 From: ckieffer Date: Fri, 14 May 2010 17:14:34 -0600 Subject: Drop context_menu for wind's photo/resize view. Move photo edit options to the site_menu. --- modules/gallery/helpers/gallery_event.php | 54 +++++++++++++++++++++++++++++++ themes/wind/views/photo.html.php | 1 - 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index c77ed9d4..d01b2956 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -227,6 +227,60 @@ class gallery_event_Core { } } } + + if ($item->is_photo() && graphics::can("rotate")) { + $options_menu + ->append( + Menu::factory("ajax_link") + ->id("rotate_ccw") + ->label(t("Rotate 90° counter clockwise")) + ->css_class("ui-icon-rotate-ccw") + ->ajax_handler("function(data) { " . + "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") + ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))) + ->append( + Menu::factory("ajax_link") + ->id("rotate_cw") + ->label(t("Rotate 90° clockwise")) + ->css_class("ui-icon-rotate-cw") + ->ajax_handler("function(data) { " . + "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") + ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); + } + + if ($item->id != item::root()->id) { + $parent = $item->parent(); + if (access::can("edit", $parent)) { + // We can't make this item the highlight if it's an album with no album cover, or if it's + // already the album cover. + if (($item->type == "album" && empty($item->album_cover_item_id)) || + ($item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id) || + $parent->album_cover_item_id == $item->id) { + $disabledState = " ui-state-disabled"; + } else { + $disabledState = " "; + } + + if ($item->parent()->id != 1) { + $options_menu + ->append( + Menu::factory("ajax_link") + ->id("make_album_cover") + ->label(t("Choose as the album cover")) + ->css_class("ui-icon-star") + ->ajax_handler("function(data) { window.location.reload() }") + ->url(url::site("quick/make_album_cover/$item->id?csrf=$csrf"))); + } + $options_menu + ->append( + Menu::factory("dialog") + ->id("delete") + ->label(t("Delete this photo")) + ->css_class("ui-icon-trash") + ->css_class("g-quick-delete") + ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); + } + } } if (identity::active_user()->admin) { diff --git a/themes/wind/views/photo.html.php b/themes/wind/views/photo.html.php index e0fae3f1..07952c94 100644 --- a/themes/wind/views/photo.html.php +++ b/themes/wind/views/photo.html.php @@ -27,7 +27,6 @@ resize_bottom($item) ?> - context_menu($item, "#g-photo-id-{$item->id}") ?>
-- cgit v1.2.3 From 3422185938436b44ee48515cd3cfa3df55bca3c8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 14 May 2010 16:51:51 -0700 Subject: Remove "rnd=" param from quick changes since we have the m= cache-buster already. --- modules/gallery/controllers/quick.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 813d1a93..6cfbbc62 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -58,12 +58,12 @@ class Quick_Controller extends Controller { if (Input::instance()->get("page_type") == "collection") { print json_encode( - array("src" => $item->thumb_url() . "?rnd=" . rand(), + array("src" => $item->thumb_url(), "width" => $item->thumb_width, "height" => $item->thumb_height)); } else { print json_encode( - array("src" => $item->resize_url() . "?rnd=" . rand(), + array("src" => $item->resize_url(), "width" => $item->resize_width, "height" => $item->resize_height)); } -- cgit v1.2.3 From 1240878df0f4a2b0ad0cdb32814717038ff2773f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 14 May 2010 16:55:15 -0700 Subject: Fix-ups for d98b85f7d3142676e6b4f407a18ed81564823f88 - Pass the CSS selector of the active image in as an arg to site_menu so that quick operations know what they're operating on. - Change the ids from g-{photo,movie}-id to the generic g-item-id - Initialize ajax handlers for site menu on the photo and movie page - Drop the movie context menu, it's now in the site menu --- modules/gallery/helpers/gallery_event.php | 9 ++++++--- modules/gallery/libraries/Theme_View.php | 4 ++-- modules/gallery/models/item.php | 2 +- themes/wind/js/ui.init.js | 3 +++ themes/wind/views/movie.html.php | 3 +-- themes/wind/views/page.html.php | 2 +- themes/wind/views/photo.html.php | 2 +- 7 files changed, 15 insertions(+), 10 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 9b3aa82d..89ad6a4c 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -167,7 +167,7 @@ class gallery_event_Core { } } - static function site_menu($menu, $theme) { + static function site_menu($menu, $theme, $item_css_selector) { if ($theme->page_subtype != "login") { $menu->append(Menu::factory("link") ->id("home") @@ -239,6 +239,9 @@ class gallery_event_Core { } } + $csrf = access::csrf_token(); + $theme_item = $theme->item(); + $page_type = $theme->page_type(); if ($item->is_photo() && graphics::can("rotate")) { $options_menu ->append( @@ -247,7 +250,7 @@ class gallery_event_Core { ->label(t("Rotate 90° counter clockwise")) ->css_class("ui-icon-rotate-ccw") ->ajax_handler("function(data) { " . - "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") + "\$.gallery_replace_image(data, \$('$item_css_selector')) }") ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))) ->append( Menu::factory("ajax_link") @@ -255,7 +258,7 @@ class gallery_event_Core { ->label(t("Rotate 90° clockwise")) ->css_class("ui-icon-rotate-cw") ->ajax_handler("function(data) { " . - "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") + "\$.gallery_replace_image(data, \$('$item_css_selector')) }") ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); } diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 8b432fb6..6246c6f1 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -86,9 +86,9 @@ class Theme_View_Core extends Gallery_View { return $menu->render(); } - public function site_menu() { + public function site_menu($item_css_selector) { $menu = Menu::factory("root"); - module::event("site_menu", $menu, $this); + module::event("site_menu", $menu, $this, $item_css_selector); return $menu->render(); } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 7fc37325..409ed3cc 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -674,7 +674,7 @@ class Item_Model extends ORM_MPTT { $v->attrs = array_merge($extra_attrs, array("style" => "display:block;width:{$this->width}px;height:{$this->height}px")); if (empty($v->attrs["id"])) { - $v->attrs["id"] = "g-movie-id-{$this->id}"; + $v->attrs["id"] = "g-item-id-{$this->id}"; } return $v; } diff --git a/themes/wind/js/ui.init.js b/themes/wind/js/ui.init.js index 6edf6be4..53b58516 100644 --- a/themes/wind/js/ui.init.js +++ b/themes/wind/js/ui.init.js @@ -108,6 +108,9 @@ $(document).ready(function() { duration: 1000, hash: true }); + + $(this).find(".g-dialog-link").gallery_dialog(); + $(this).find(".g-ajax-link").gallery_ajax(); } // Initialize button hover effect diff --git a/themes/wind/views/movie.html.php b/themes/wind/views/movie.html.php index 27c293ce..8481c7ce 100644 --- a/themes/wind/views/movie.html.php +++ b/themes/wind/views/movie.html.php @@ -5,8 +5,7 @@ paginator() ?>
- movie_img(array("class" => "g-movie", "id" => "g-movie-id-{$item->id}")) ?> - context_menu($item, "#g-movie-id-{$item->id}") ?> + movie_img(array("class" => "g-movie", "id" => "g-item-id-{$item->id}")) ?>
diff --git a/themes/wind/views/page.html.php b/themes/wind/views/page.html.php index ebfbf700..4cc949ce 100644 --- a/themes/wind/views/page.html.php +++ b/themes/wind/views/page.html.php @@ -89,7 +89,7 @@ diff --git a/themes/wind/views/photo.html.php b/themes/wind/views/photo.html.php index 07952c94..f8b5511c 100644 --- a/themes/wind/views/photo.html.php +++ b/themes/wind/views/photo.html.php @@ -22,7 +22,7 @@ for_html_attr() ?>"> - resize_img(array("id" => "g-photo-id-{$item->id}", "class" => "g-resize")) ?> + resize_img(array("id" => "g-item-id-{$item->id}", "class" => "g-resize")) ?> -- cgit v1.2.3 From 48b66f2d675bf204b62909721cb398ceb0e2bd01 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 15 May 2010 23:42:55 -0700 Subject: Remove the item id from the rest/gallery/items url as that was inconsistent. Add the query parameter ancestors_for= to provide a restful way to retrieve the ancestors of an item. (cherry picked from commit e9c8a8ae532e785ab95e6b43864c93b485785d6c) Conflicts: modules/gallery/helpers/items_rest.php --- modules/gallery/helpers/items_rest.php | 60 ++++++++++--- modules/gallery/tests/Items_Rest_Helper_Test.php | 103 +++++++++++++++++++++++ 2 files changed, 149 insertions(+), 14 deletions(-) create mode 100644 modules/gallery/tests/Items_Rest_Helper_Test.php (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 5d8e80b2..4f50e434 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -18,28 +18,60 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class items_rest_Core { + /** + * To retrieve a collection of items, you can specify the following query parameters to specify the + * type of the collection. If both are specified, then the url parameter is used and the + * ancestor_for is ignored. + * + * urls=url1,url2,url3 + * return items that match the specified urls. Typically used to return the member detail + * + * ancestor_for=url + * return the ancestors of the specified item + */ static function get($request) { - $items = array(); - if (isset($request->params->url)) { - foreach (json_decode($request->params->url) as $url) { + if (isset($request->params->urls)) { + foreach (json_decode($request->params->urls) as $url) { $item = rest::resolve($url); if (access::can("view", $item)) { - $item_rest = array("url" => $url, - "entity" => $item->as_restful_array(), - "relationship" => rest::relationships("item", $item)); - if ($item->type == "album") { - $members = array(); - foreach ($item->children() as $child) { - $members[] = rest::url("item", $child); - } - $item_rest["members"] = $members; - } - $items[] = $item_rest; + $items[] = items_rest::format_restful_item($item); } } + } else if (isset($request->params->ancestor_for)) { + $item = rest::resolve($request->params->ancestor_for); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + $items[] = items_rest::format_restful_item($item); + while (($item = $item->parent()) != null) { + array_unshift($items, items_rest::format_restful_item($item)); + }; } return $items; } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + private static function format_restful_item($item) { + $item_rest = array("url" => rest::url("item", $item), + "entity" => $item->as_restful_array(), + "relationships" => rest::relationships("item", $item)); + if ($item->type == "album") { + $members = array(); + foreach ($item->children() as $child) { + $members[] = rest::url("item", $child); + } + $item_rest["members"] = $members; + } + + return $item_rest; + } } diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php new file mode 100644 index 00000000..cd01ae0c --- /dev/null +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -0,0 +1,103 @@ +reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $this->assert_equal_array( + array( + array("url" => rest::url("item", $photo1), + "entity" => $photo1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo1), + "members" => array()))), + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2)))), + items_rest::get($request)); + } + + public function get_ancestor_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $root = ORM::factory("item", 1); + $restful_root = array( + "url" => rest::url("item", $root), + "entity" => $root->as_restful_array(), + "relationships" => rest::relationships("item", $root)); + $restful_root["members"] = array(); + foreach ($root->children() as $child) { + $restful_root["members"][] = rest::url("item", $child); + } + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->ancestor_for = rest::url("item", $photo2); + $this->assert_equal_array( + array( + $restful_root, + array("url" => rest::url("item", $album1), + "entity" => $album1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array())), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + ), + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2))), + array("url" => rest::url("item", $photo2), + "entity" => $photo2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo2), + "members" => array())))), + items_rest::get($request)); + } +} -- cgit v1.2.3 From 83ce637ce3171a012515b2e20e8592d22e9929f8 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 10 May 2010 06:31:38 -0700 Subject: Allow the use of the type query parameter to filter the results of a rest/gallery/items?urls=... request. This allows the client to pass the entire list of member urls and have the rest server filter the results based on the specified types. (cherry picked from commit 3fe10b15cf9359b66452c24965df575203e8af8e) --- modules/gallery/helpers/items_rest.php | 22 ++++-- modules/gallery/tests/Items_Rest_Helper_Test.php | 85 ++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 4f50e434..32597a65 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -19,23 +19,37 @@ */ class items_rest_Core { /** - * To retrieve a collection of items, you can specify the following query parameters to specify the - * type of the collection. If both are specified, then the url parameter is used and the - * ancestor_for is ignored. + * To retrieve a collection of items, you can specify the following query parameters to specify + * the type of the collection. If both are specified, then the url parameter is used and the + * ancestor_for is ignored. Specifying the "type" parameter with the urls parameter, will + * filter the results based on the specified type. Using the type parameter with the + * ancestor_for parameter makes no sense and will be ignored. * * urls=url1,url2,url3 * return items that match the specified urls. Typically used to return the member detail * * ancestor_for=url * return the ancestors of the specified item + * + * type= + * limit the type to types in this list. eg, "type=photo,movie" */ static function get($request) { $items = array(); if (isset($request->params->urls)) { foreach (json_decode($request->params->urls) as $url) { + if (isset($request->params->type)) { + $types = explode(",", $request->params->type); + } $item = rest::resolve($url); if (access::can("view", $item)) { - $items[] = items_rest::format_restful_item($item); + if (isset($types)) { + if (in_array($item->type, $types)) { + $items[] = items_rest::format_restful_item($item); + } + } else { + $items[] = items_rest::format_restful_item($item); + } } } } else if (isset($request->params->ancestor_for)) { diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index cd01ae0c..94bf912a 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -50,6 +50,91 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { items_rest::get($request)); } + public function get_url_filter_album_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $request->params->type = "album"; + $this->assert_equal_array( + array( + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2)))), + items_rest::get($request)); + } + + public function get_url_filter_photo_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $request->params->type = "photo"; + $this->assert_equal_array( + array( + array("url" => rest::url("item", $photo1), + "entity" => $photo1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo1), + "members" => array())))), + items_rest::get($request)); + } + + public function get_url_filter_albums_photos_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $request->params->type = "photo,album"; + $this->assert_equal_array( + array( + array("url" => rest::url("item", $photo1), + "entity" => $photo1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo1), + "members" => array()))), + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2)))), + items_rest::get($request)); + } + public function get_ancestor_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); -- cgit v1.2.3 From 73c7ec53102c24de248d1424fdf8d5ba347c2200 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 18 May 2010 06:16:47 -0700 Subject: Save the item before updating the order of the children. Also always increment the weight count (even if it is equal to the weight of the current child) --- modules/gallery/helpers/item_rest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 36d2ca62..298c2f4a 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -126,18 +126,19 @@ class item_rest_Core { } } } + $item->save(); - $weight = 0; if (isset($request->params->members)) { + $weight = 0; foreach ($request->params->members as $url) { $child = rest::resolve($url); if ($child->parent_id == $item->id && $child->weight != $weight) { - $child->weight = $weight++; + $child->weight = $weight; $child->save(); } + $weight++; } } - $item->save(); } static function post($request) { -- cgit v1.2.3 From ae595795f09edbe0883d233a7a8483f6445b9ed7 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 28 May 2010 09:41:42 -0700 Subject: If the file is empty (i.e. the upload failed, then throw a 'bad request' exception before trying to create the item. --- modules/gallery/helpers/item_rest.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 298c2f4a..ec86ce93 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -160,6 +160,9 @@ class item_rest_Core { case "photo": case "movie": + if (empty($request->file)) { + throw new Rest_Exception("Bad Request: Upload failed", 400); + } $item->type = $entity->type; $item->parent_id = $parent->id; $item->set_data_file($request->file); -- cgit v1.2.3 From 04b90c3bdef9b2f4daf8bffc1e814b0bac9912f4 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 15 May 2010 23:42:55 -0700 Subject: Remove the item id from the rest/gallery/items url as that was inconsistent. Add the query parameter ancestors_for= to provide a restful way to retrieve the ancestors of an item. (cherry picked from commit e9c8a8ae532e785ab95e6b43864c93b485785d6c) Conflicts: modules/gallery/helpers/items_rest.php --- modules/gallery/helpers/items_rest.php | 60 ++++++++++--- modules/gallery/tests/Items_Rest_Helper_Test.php | 103 +++++++++++++++++++++++ 2 files changed, 149 insertions(+), 14 deletions(-) create mode 100644 modules/gallery/tests/Items_Rest_Helper_Test.php (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 5d8e80b2..4f50e434 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -18,28 +18,60 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class items_rest_Core { + /** + * To retrieve a collection of items, you can specify the following query parameters to specify the + * type of the collection. If both are specified, then the url parameter is used and the + * ancestor_for is ignored. + * + * urls=url1,url2,url3 + * return items that match the specified urls. Typically used to return the member detail + * + * ancestor_for=url + * return the ancestors of the specified item + */ static function get($request) { - $items = array(); - if (isset($request->params->url)) { - foreach (json_decode($request->params->url) as $url) { + if (isset($request->params->urls)) { + foreach (json_decode($request->params->urls) as $url) { $item = rest::resolve($url); if (access::can("view", $item)) { - $item_rest = array("url" => $url, - "entity" => $item->as_restful_array(), - "relationship" => rest::relationships("item", $item)); - if ($item->type == "album") { - $members = array(); - foreach ($item->children() as $child) { - $members[] = rest::url("item", $child); - } - $item_rest["members"] = $members; - } - $items[] = $item_rest; + $items[] = items_rest::format_restful_item($item); } } + } else if (isset($request->params->ancestor_for)) { + $item = rest::resolve($request->params->ancestor_for); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + $items[] = items_rest::format_restful_item($item); + while (($item = $item->parent()) != null) { + array_unshift($items, items_rest::format_restful_item($item)); + }; } return $items; } + + static function resolve($id) { + $item = ORM::factory("item", $id); + if (!access::can("view", $item)) { + throw new Kohana_404_Exception(); + } + return $item; + } + + private static function format_restful_item($item) { + $item_rest = array("url" => rest::url("item", $item), + "entity" => $item->as_restful_array(), + "relationships" => rest::relationships("item", $item)); + if ($item->type == "album") { + $members = array(); + foreach ($item->children() as $child) { + $members[] = rest::url("item", $child); + } + $item_rest["members"] = $members; + } + + return $item_rest; + } } diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php new file mode 100644 index 00000000..cd01ae0c --- /dev/null +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -0,0 +1,103 @@ +reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $this->assert_equal_array( + array( + array("url" => rest::url("item", $photo1), + "entity" => $photo1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo1), + "members" => array()))), + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2)))), + items_rest::get($request)); + } + + public function get_ancestor_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $root = ORM::factory("item", 1); + $restful_root = array( + "url" => rest::url("item", $root), + "entity" => $root->as_restful_array(), + "relationships" => rest::relationships("item", $root)); + $restful_root["members"] = array(); + foreach ($root->children() as $child) { + $restful_root["members"][] = rest::url("item", $child); + } + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->ancestor_for = rest::url("item", $photo2); + $this->assert_equal_array( + array( + $restful_root, + array("url" => rest::url("item", $album1), + "entity" => $album1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album1), + "members" => array())), + "members" => array( + rest::url("item", $photo1), + rest::url("item", $album2)), + ), + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2))), + array("url" => rest::url("item", $photo2), + "entity" => $photo2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo2), + "members" => array())))), + items_rest::get($request)); + } +} -- cgit v1.2.3 From a600185b605a37ca1b60cb6d9814d5441f54cd88 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 10 May 2010 06:31:38 -0700 Subject: Allow the use of the type query parameter to filter the results of a rest/gallery/items?urls=... request. This allows the client to pass the entire list of member urls and have the rest server filter the results based on the specified types. (cherry picked from commit 3fe10b15cf9359b66452c24965df575203e8af8e) --- modules/gallery/helpers/items_rest.php | 22 ++++-- modules/gallery/tests/Items_Rest_Helper_Test.php | 85 ++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 4 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 4f50e434..32597a65 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -19,23 +19,37 @@ */ class items_rest_Core { /** - * To retrieve a collection of items, you can specify the following query parameters to specify the - * type of the collection. If both are specified, then the url parameter is used and the - * ancestor_for is ignored. + * To retrieve a collection of items, you can specify the following query parameters to specify + * the type of the collection. If both are specified, then the url parameter is used and the + * ancestor_for is ignored. Specifying the "type" parameter with the urls parameter, will + * filter the results based on the specified type. Using the type parameter with the + * ancestor_for parameter makes no sense and will be ignored. * * urls=url1,url2,url3 * return items that match the specified urls. Typically used to return the member detail * * ancestor_for=url * return the ancestors of the specified item + * + * type= + * limit the type to types in this list. eg, "type=photo,movie" */ static function get($request) { $items = array(); if (isset($request->params->urls)) { foreach (json_decode($request->params->urls) as $url) { + if (isset($request->params->type)) { + $types = explode(",", $request->params->type); + } $item = rest::resolve($url); if (access::can("view", $item)) { - $items[] = items_rest::format_restful_item($item); + if (isset($types)) { + if (in_array($item->type, $types)) { + $items[] = items_rest::format_restful_item($item); + } + } else { + $items[] = items_rest::format_restful_item($item); + } } } } else if (isset($request->params->ancestor_for)) { diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index cd01ae0c..94bf912a 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -50,6 +50,91 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { items_rest::get($request)); } + public function get_url_filter_album_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $request->params->type = "album"; + $this->assert_equal_array( + array( + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2)))), + items_rest::get($request)); + } + + public function get_url_filter_photo_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $request->params->type = "photo"; + $this->assert_equal_array( + array( + array("url" => rest::url("item", $photo1), + "entity" => $photo1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo1), + "members" => array())))), + items_rest::get($request)); + } + + public function get_url_filter_albums_photos_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + $album2 = test::random_album($album1); + $photo2 = test::random_photo($album2); + $album1->reload(); + $album2->reload(); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->urls = json_encode(array( + rest::url("item", $photo1), + rest::url("item", $album2))); + $request->params->type = "photo,album"; + $this->assert_equal_array( + array( + array("url" => rest::url("item", $photo1), + "entity" => $photo1->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $photo1), + "members" => array()))), + array("url" => rest::url("item", $album2), + "entity" => $album2->as_restful_array(), + "relationships" => array( + "tags" => array( + "url" => rest::url("item_tags", $album2), + "members" => array())), + "members" => array( + rest::url("item", $photo2)))), + items_rest::get($request)); + } + public function get_ancestor_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); -- cgit v1.2.3 From 686da5a3e069d180e198fcc8dc3e2ed422f725b9 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 18 May 2010 06:16:47 -0700 Subject: Save the item before updating the order of the children. Also always increment the weight count (even if it is equal to the weight of the current child) --- modules/gallery/helpers/item_rest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 36d2ca62..298c2f4a 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -126,18 +126,19 @@ class item_rest_Core { } } } + $item->save(); - $weight = 0; if (isset($request->params->members)) { + $weight = 0; foreach ($request->params->members as $url) { $child = rest::resolve($url); if ($child->parent_id == $item->id && $child->weight != $weight) { - $child->weight = $weight++; + $child->weight = $weight; $child->save(); } + $weight++; } } - $item->save(); } static function post($request) { -- cgit v1.2.3 From ed1905d3f94847a64656e52858de8c363c001df7 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 4 Jun 2010 11:22:51 -0700 Subject: Change the name of the private format_restful_item to _format_restful_item so that the File_Structure_Test will pass. --- modules/gallery/helpers/items_rest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 32597a65..32f6c036 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -45,10 +45,10 @@ class items_rest_Core { if (access::can("view", $item)) { if (isset($types)) { if (in_array($item->type, $types)) { - $items[] = items_rest::format_restful_item($item); + $items[] = items_rest::_format_restful_item($item); } } else { - $items[] = items_rest::format_restful_item($item); + $items[] = items_rest::_format_restful_item($item); } } } @@ -57,9 +57,9 @@ class items_rest_Core { if (!access::can("view", $item)) { throw new Kohana_404_Exception(); } - $items[] = items_rest::format_restful_item($item); + $items[] = items_rest::_format_restful_item($item); while (($item = $item->parent()) != null) { - array_unshift($items, items_rest::format_restful_item($item)); + array_unshift($items, items_rest::_format_restful_item($item)); }; } @@ -74,7 +74,7 @@ class items_rest_Core { return $item; } - private static function format_restful_item($item) { + private static function _format_restful_item($item) { $item_rest = array("url" => rest::url("item", $item), "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item)); -- cgit v1.2.3 From fd437aec2bbd3e65b330b0790af970ca7e078636 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 4 Jun 2010 13:58:49 -0700 Subject: Correct XSS Security Test golden file for recent changes. Update the controller_auth data file for the rename of admin_comments to admin_manage_comments. --- modules/gallery/tests/controller_auth_data.txt | 2 +- modules/gallery/tests/xss_data.txt | 37 +++++++++++++------------- 2 files changed, 19 insertions(+), 20 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 0aa26057..94e7a07f 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -1,4 +1,4 @@ -modules/comment/controllers/admin_comments.php queue DIRTY_CSRF +modules/comment/controllers/admin_manage_comments.php queue 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 diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index afad9e13..0a75d6f7 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -4,21 +4,21 @@ modules/akismet/views/admin_akismet_stats.html.php 9 DIRTY_ATTR urle modules/comment/views/admin_block_recent_comments.html.php 4 DIRTY_ATTR text::alternate("g-even","g-odd") modules/comment/views/admin_block_recent_comments.html.php 5 DIRTY_ATTR $comment->author()->avatar_url(32,$theme->url(,true)) modules/comment/views/admin_block_recent_comments.html.php 10 DIRTY gallery::date_time($comment->created) -modules/comment/views/admin_comments.html.php 43 DIRTY $menu->render() -modules/comment/views/admin_comments.html.php 107 DIRTY_ATTR $comment->id -modules/comment/views/admin_comments.html.php 107 DIRTY_ATTR text::alternate("g-odd","g-even") -modules/comment/views/admin_comments.html.php 110 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) -modules/comment/views/admin_comments.html.php 123 DIRTY_JS $item->url() -modules/comment/views/admin_comments.html.php 125 DIRTY_ATTR $item->thumb_url() -modules/comment/views/admin_comments.html.php 127 DIRTY photo::img_dimensions($item->thumb_width,$item->thumb_height,75) -modules/comment/views/admin_comments.html.php 135 DIRTY gallery::date($comment->created) -modules/comment/views/admin_comments.html.php 142 DIRTY_JS $comment->id -modules/comment/views/admin_comments.html.php 151 DIRTY_JS $comment->id -modules/comment/views/admin_comments.html.php 160 DIRTY_JS $comment->id -modules/comment/views/admin_comments.html.php 169 DIRTY_JS $comment->id -modules/comment/views/admin_comments.html.php 176 DIRTY_JS $comment->id -modules/comment/views/admin_comments.html.php 184 DIRTY_JS $comment->id -modules/comment/views/admin_comments.html.php 197 DIRTY $pager +modules/comment/views/admin_manage_comments.html.php 43 DIRTY $menu->render() +modules/comment/views/admin_manage_comments.html.php 107 DIRTY_ATTR $comment->id +modules/comment/views/admin_manage_comments.html.php 107 DIRTY_ATTR text::alternate("g-odd","g-even") +modules/comment/views/admin_manage_comments.html.php 110 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) +modules/comment/views/admin_manage_comments.html.php 123 DIRTY_JS $item->url() +modules/comment/views/admin_manage_comments.html.php 125 DIRTY_ATTR $item->thumb_url() +modules/comment/views/admin_manage_comments.html.php 127 DIRTY photo::img_dimensions($item->thumb_width,$item->thumb_height,75) +modules/comment/views/admin_manage_comments.html.php 135 DIRTY gallery::date($comment->created) +modules/comment/views/admin_manage_comments.html.php 142 DIRTY_JS $comment->id +modules/comment/views/admin_manage_comments.html.php 151 DIRTY_JS $comment->id +modules/comment/views/admin_manage_comments.html.php 160 DIRTY_JS $comment->id +modules/comment/views/admin_manage_comments.html.php 169 DIRTY_JS $comment->id +modules/comment/views/admin_manage_comments.html.php 176 DIRTY_JS $comment->id +modules/comment/views/admin_manage_comments.html.php 184 DIRTY_JS $comment->id +modules/comment/views/admin_manage_comments.html.php 197 DIRTY $pager modules/comment/views/comment.html.php 2 DIRTY_ATTR $comment->id; modules/comment/views/comment.html.php 5 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) modules/comment/views/comment.mrss.php 10 DIRTY $feed->uri @@ -175,7 +175,7 @@ modules/gallery/views/move_tree.html.php 15 DIRTY_JS $child modules/gallery/views/movieplayer.html.php 2 DIRTY html::anchor($item->file_url(true),"",$attrs) modules/gallery/views/movieplayer.html.php 5 DIRTY_JS $attrs["id"] modules/gallery/views/movieplayer.html.php 7 DIRTY_JS url::abs_file("lib/flowplayer.swf") -modules/gallery/views/movieplayer.html.php 13 DIRTY_JS url::abs_file("lib/flowplayer.h264streaming.swf") +modules/gallery/views/movieplayer.html.php 14 DIRTY_JS url::abs_file("lib/flowplayer.pseudostreaming.swf") modules/gallery/views/permissions_browse.html.php 3 DIRTY_JS url::site("permissions/form/__ITEM__") modules/gallery/views/permissions_browse.html.php 16 DIRTY_JS url::site("permissions/change/__CMD__/__GROUP__/__PERM__/__ITEM__?csrf=$csrf") modules/gallery/views/permissions_browse.html.php 43 DIRTY_ATTR $parent->id @@ -320,7 +320,6 @@ modules/user/views/admin_users_group.html.php 24 DIRTY_JS $group modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $width modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $height modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $url -themes/admin_wind/views/admin.html.php 9 DIRTY $page_title themes/admin_wind/views/admin.html.php 22 DIRTY_JS $theme->url() themes/admin_wind/views/admin.html.php 39 DIRTY $theme->admin_head() themes/admin_wind/views/admin.html.php 43 DIRTY $theme->admin_page_top() @@ -363,7 +362,7 @@ themes/wind/views/dynamic.html.php 16 DIRTY_ATTR $chi themes/wind/views/dynamic.html.php 17 DIRTY_ATTR $child->thumb_height themes/wind/views/dynamic.html.php 29 DIRTY $theme->paginator() themes/wind/views/movie.html.php 5 DIRTY $theme->paginator() -themes/wind/views/movie.html.php 8 DIRTY $item->movie_img(array("class"=>"g-movie","id"=>"g-movie-id-{$item->id}")) +themes/wind/views/movie.html.php 8 DIRTY $item->movie_img(array("class"=>"g-movie","id"=>"g-item-id-{$item->id}")) themes/wind/views/page.html.php 9 DIRTY $page_title themes/wind/views/page.html.php 33 DIRTY_JS $theme->url() themes/wind/views/page.html.php 42 DIRTY $new_width @@ -384,4 +383,4 @@ themes/wind/views/photo.html.php 8 DIRTY_JS $theme themes/wind/views/photo.html.php 8 DIRTY_JS $theme->item()->height themes/wind/views/photo.html.php 18 DIRTY $theme->paginator() themes/wind/views/photo.html.php 23 DIRTY_JS $item->file_url() -themes/wind/views/photo.html.php 25 DIRTY $item->resize_img(array("id"=>"g-photo-id-{$item->id}","class"=>"g-resize")) +themes/wind/views/photo.html.php 25 DIRTY $item->resize_img(array("id"=>"g-item-id-{$item->id}","class"=>"g-resize")) -- cgit v1.2.3 From 0350cf3cd85d0ca89d3a9fb1385d43350d3df9aa Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 5 Jun 2010 22:50:20 -0700 Subject: Fix a comment typo. --- modules/gallery/helpers/module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 18d65ed5..12cec38c 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -215,7 +215,7 @@ class module_Core { } } - // Now the module is upgraded so deactivate it, but we can'it deactivae gallery or the + // Now the module is upgraded so deactivate it, but we can't deactivate gallery or the // current identity provider. $identity_provider = module::get_var("gallery", "identity_provider", "user"); if (!in_array($module_name, array("gallery", $identity_provider)) ) { -- cgit v1.2.3 From 10895ca5298dc71410cfd87fe8a28c4f976c2234 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 5 Jun 2010 23:04:23 -0700 Subject: Undo the change added in e4eedbce2298535540cb651d75ba6f1bf42cf02b which deactivates modules on upgrade. No idea why we did that, but it breaks upgrading because it deactivates any module that's been upgraded. --- modules/gallery/helpers/module.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 12cec38c..5134c7b3 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -214,13 +214,6 @@ class module_Core { throw new Exception("@todo UNKNOWN_MODULE"); } } - - // Now the module is upgraded so deactivate it, but we can't deactivate gallery or the - // current identity provider. - $identity_provider = module::get_var("gallery", "identity_provider", "user"); - if (!in_array($module_name, array("gallery", $identity_provider)) ) { - self::deactivate($module_name); - } module::load_modules(); $version_after = module::get_version($module_name); -- cgit v1.2.3 From 4e56176f35fe624d2d3a587636a4a45ea387be09 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 5 Jun 2010 23:47:47 -0700 Subject: item::random_query() doesn't need to take a "where" clause because it's returning a query, so the caller can add the where clause himself. This makes for a cleaner API. --- modules/gallery/helpers/item.php | 5 +---- modules/image_block/helpers/image_block_block.php | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 43c93225..bbbe1058 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -209,17 +209,14 @@ class item_Core { /** * Return a query to get a random Item_Model, with optional filters - * - * @param array (optional) where tuple */ - static function random_query($where=null) { + static function random_query() { // Pick a random number and find the item that's got nearest smaller number. // This approach works best when the random numbers in the system are roughly evenly // distributed so this is going to be more efficient with larger data sets. return ORM::factory("item") ->viewable() ->where("rand_key", "<", ((float)mt_rand()) / (float)mt_getrandmax()) - ->merge_where($where) ->order_by("rand_key", "DESC"); } } \ No newline at end of file diff --git a/modules/image_block/helpers/image_block_block.php b/modules/image_block/helpers/image_block_block.php index 51ccc4a0..da6e8782 100644 --- a/modules/image_block/helpers/image_block_block.php +++ b/modules/image_block/helpers/image_block_block.php @@ -31,7 +31,7 @@ class image_block_block_Core { // @todo Consider another fallback if further optimizations are necessary. $attempts = 0; do { - $item = item::random_query(array(array("type", "!=", "album")))->find_all(1)->current(); + $item = item::random_query()->where("type", "!=", "album")->find_all(1)->current(); } while (!$item && $attempts++ < 3); if ($item && $item->loaded()) { $block = new Block(); -- cgit v1.2.3 From e1d3b0295d0f6d098a7b5563aa1f5b6af247319f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Jun 2010 12:42:16 -0700 Subject: Change "ancestor_for" to "ancestors_for" for consistency. --- modules/gallery/helpers/items_rest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 32f6c036..9cca9a54 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -21,14 +21,14 @@ class items_rest_Core { /** * To retrieve a collection of items, you can specify the following query parameters to specify * the type of the collection. If both are specified, then the url parameter is used and the - * ancestor_for is ignored. Specifying the "type" parameter with the urls parameter, will + * ancestors_for is ignored. Specifying the "type" parameter with the urls parameter, will * filter the results based on the specified type. Using the type parameter with the - * ancestor_for parameter makes no sense and will be ignored. + * ancestors_for parameter makes no sense and will be ignored. * * urls=url1,url2,url3 * return items that match the specified urls. Typically used to return the member detail * - * ancestor_for=url + * ancestors_for=url * return the ancestors of the specified item * * type= @@ -52,8 +52,8 @@ class items_rest_Core { } } } - } else if (isset($request->params->ancestor_for)) { - $item = rest::resolve($request->params->ancestor_for); + } else if (isset($request->params->ancestors_for)) { + $item = rest::resolve($request->params->ancestors_for); if (!access::can("view", $item)) { throw new Kohana_404_Exception(); } -- cgit v1.2.3 From aeee88031fed7029c3320800d237b69993e8b6d4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Jun 2010 13:06:08 -0700 Subject: Fix an unused variable caused by converting straight query params to $entity based params. --- modules/gallery/helpers/item_rest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 298c2f4a..c88f92d9 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -152,7 +152,7 @@ class item_rest_Core { $item->type = "album"; $item->parent_id = $parent->id; $item->name = $entity->name; - $item->title = isset($entity->title) ? $entity->title : $name; + $item->title = isset($entity->title) ? $entity->title : $entity->name; $item->description = isset($entity->description) ? $entity->description : null; $item->slug = isset($entity->slug) ? $entity->slug : null; $item->save(); -- cgit v1.2.3 From ab0bef14be78701aedd647dd4eaccab641b6d01d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Jun 2010 21:08:10 -0700 Subject: Try to adjust for situations where /proc/loadavg is_readable() but generates an error if we call file() on it. Fixes ticket #1149. --- modules/gallery/helpers/gallery_block.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 08ce21b7..cb28cbcd 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -70,9 +70,9 @@ class gallery_block_Core { $block->css_id = "g-platform"; $block->title = t("Platform information"); $block->content = new View("admin_block_platform.html"); - if (@is_readable("/proc/loadavg")) { + if (@is_readable("/proc/loadavg") && $first_line = current(@file("/proc/loadavg"))) { $block->content->load_average = - join(" ", array_slice(explode(" ", current(file("/proc/loadavg"))), 0, 3)); + join(" ", array_slice(explode(" ", $first_line), 0, 3)); } else { $block->content->load_average = t("Unavailable"); } -- cgit v1.2.3 From 1d91e1b2dc8456681f9e38baaca1d191cff1ac7a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 6 Jun 2010 23:19:02 -0700 Subject: Don't show the rotate links if the active user can't edit the photo. Fixes ticket #1157. Thanks to psvo. --- modules/gallery/helpers/gallery_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 89ad6a4c..ae7131ae 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -242,7 +242,7 @@ class gallery_event_Core { $csrf = access::csrf_token(); $theme_item = $theme->item(); $page_type = $theme->page_type(); - if ($item->is_photo() && graphics::can("rotate")) { + if ($can_edit && $item->is_photo() && graphics::can("rotate")) { $options_menu ->append( Menu::factory("ajax_link") -- cgit v1.2.3 From 98fce83de5f772482382bfabdbcd94c25ecdbb1a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 7 Jun 2010 22:23:46 -0700 Subject: Add a "convert_ids" parameter to Item_Model::as_restful_array(), which we can turn on with a query parameter. --- modules/gallery/models/item.php | 20 ++++++++++++-------- modules/gallery/tests/Item_Model_Test.php | 12 ++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 409ed3cc..dfcbdd70 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -924,17 +924,21 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. */ - public function as_restful_array() { + public function as_restful_array($convert_ids=true) { // Convert item ids to rest URLs for consistency $data = $this->as_array(); - if ($tmp = $this->parent()) { - $data["parent"] = rest::url("item", $tmp); - } - unset($data["parent_id"]); - if ($tmp = $this->album_cover()) { - $data["album_cover"] = rest::url("item", $tmp); + + if ($convert_ids) { + if ($tmp = $this->parent()) { + $data["parent"] = rest::url("item", $tmp); + } + unset($data["parent_id"]); + + if ($tmp = $this->album_cover()) { + $data["album_cover"] = rest::url("item", $tmp); + } + unset($data["album_cover_item_id"]); } - unset($data["album_cover_item_id"]); if (access::can("view_full", $this) && $this->is_photo()) { $data["file_url"] = $this->file_url(true); diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 15aa2d8c..9d3f54f2 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -364,6 +364,18 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $this->assert_true(!array_key_exists("album_cover_item_id", $result)); } + public function as_restful_array_with_ids_test() { + $album = test::random_album(); + $photo = test::random_photo($album); + $album->reload(); + + $result = $album->as_restful_array(false); + $this->assert_same(item::root()->id, $result["parent_id"]); + $this->assert_same($photo->id, $result["album_cover_item_id"]); + $this->assert_true(!array_key_exists("parent", $result)); + $this->assert_true(!array_key_exists("album_cover_item", $result)); + } + public function first_photo_becomes_album_cover() { $album = test::random_album(); $photo = test::random_photo($album); -- cgit v1.2.3 From 6425d41eddd44091b2d83ba3c3734cc6990ca581 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 7 Jun 2010 23:12:52 -0700 Subject: Add a "preserve_ids" global query parameter for REST requests that indicates that we shouldn't opportunistically convert ids into REST urls. --- modules/gallery/helpers/item_rest.php | 3 +- modules/gallery/helpers/items_rest.php | 14 ++++++---- modules/gallery/models/item.php | 7 +++-- modules/gallery/tests/Item_Model_Test.php | 4 +-- modules/gallery/tests/Item_Rest_Helper_Test.php | 21 ++++++++++---- modules/gallery/tests/Items_Rest_Helper_Test.php | 35 ++++++++++++++++-------- 6 files changed, 57 insertions(+), 27 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index c88f92d9..1d19d9f1 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -78,9 +78,10 @@ class item_rest_Core { } $orm->order_by($order_by); + $preserve_ids = isset($p->preserve_ids) ? (bool)$p->preserve_ids : false; $result = array( "url" => $request->url, - "entity" => $item->as_restful_array(), + "entity" => $item->as_restful_array($preserve_ids), "relationships" => rest::relationships("item", $item)); if ($item->is_album()) { $result["members"] = array(); diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index 9cca9a54..e9773745 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -36,6 +36,8 @@ class items_rest_Core { */ static function get($request) { $items = array(); + $preserve_ids = isset($request->params->preserve_ids) ? + (bool)$request->params->preserve_ids : false; if (isset($request->params->urls)) { foreach (json_decode($request->params->urls) as $url) { if (isset($request->params->type)) { @@ -45,10 +47,10 @@ class items_rest_Core { if (access::can("view", $item)) { if (isset($types)) { if (in_array($item->type, $types)) { - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $preserve_ids); } } else { - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $preserve_ids); } } } @@ -57,9 +59,9 @@ class items_rest_Core { if (!access::can("view", $item)) { throw new Kohana_404_Exception(); } - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $preserve_ids); while (($item = $item->parent()) != null) { - array_unshift($items, items_rest::_format_restful_item($item)); + array_unshift($items, items_rest::_format_restful_item($item, $preserve_ids)); }; } @@ -74,9 +76,9 @@ class items_rest_Core { return $item; } - private static function _format_restful_item($item) { + private static function _format_restful_item($item, $preserve_ids) { $item_rest = array("url" => rest::url("item", $item), - "entity" => $item->as_restful_array(), + "entity" => $item->as_restful_array($preserve_ids), "relationships" => rest::relationships("item", $item)); if ($item->type == "album") { $members = array(); diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index dfcbdd70..f59caa65 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -923,12 +923,15 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. + * Convert any item ids into REST urls + * + * @param bool preserve_ids true if we should preserve ids */ - public function as_restful_array($convert_ids=true) { + public function as_restful_array($preserve_ids) { // Convert item ids to rest URLs for consistency $data = $this->as_array(); - if ($convert_ids) { + if (!$preserve_ids) { if ($tmp = $this->parent()) { $data["parent"] = rest::url("item", $tmp); } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 9d3f54f2..6c5882c4 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -357,7 +357,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(); + $result = $album->as_restful_array(false); $this->assert_same(rest::url("item", item::root()), $result["parent"]); $this->assert_same(rest::url("item", $photo), $result["album_cover"]); $this->assert_true(!array_key_exists("parent_id", $result)); @@ -369,7 +369,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(false); + $result = $album->as_restful_array(true); $this->assert_same(item::root()->id, $result["parent_id"]); $this->assert_same($photo->id, $result["album_cover_item_id"]); $this->assert_true(!array_key_exists("parent", $result)); diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 0b5e0471..5a80d66b 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -28,6 +28,17 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal($album->id, $resolved->id); } + public function get_with_ids_test() { + $photo1 = test::random_photo(item::root()); + $request = new stdClass(); + $request->url = rest::url("item", $photo1); + $request->params = new stdClass(); + $request->params->preserve_ids = 1; + + $response = item_rest::get($request); + $this->assert_equal(item::root()->id, $response["entity"]["parent_id"]); // Spot check + } + public function get_scope_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); @@ -41,7 +52,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params = new stdClass(); $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -56,7 +67,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "direct"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -71,7 +82,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "all"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -98,7 +109,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -121,7 +132,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index 94bf912a..3efd677d 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -34,13 +34,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -67,7 +67,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -94,7 +94,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), @@ -119,13 +119,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(), + "entity" => $photo1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -146,7 +146,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $root = ORM::factory("item", 1); $restful_root = array( "url" => rest::url("item", $root), - "entity" => $root->as_restful_array(), + "entity" => $root->as_restful_array(false), "relationships" => rest::relationships("item", $root)); $restful_root["members"] = array(); foreach ($root->children() as $child) { @@ -155,12 +155,12 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->params = new stdClass(); - $request->params->ancestor_for = rest::url("item", $photo2); + $request->params->ancestors_for = rest::url("item", $photo2); $this->assert_equal_array( array( $restful_root, array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(), + "entity" => $album1->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -170,7 +170,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $album2)), ), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(), + "entity" => $album2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -178,11 +178,24 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { "members" => array( rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), - "entity" => $photo2->as_restful_array(), + "entity" => $photo2->as_restful_array(false), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request)); } + + public function get_ancestor_with_ids_test() { + $album1 = test::random_album(); + $photo1 = test::random_photo($album1); + + $request = new stdClass(); + $request->params = new stdClass(); + $request->params->ancestors_for = rest::url("item", $photo1); + $request->params->preserve_ids = 1; + + $response = items_rest::get($request); + $this->assert_same(item::root()->id, $response[1]["entity"]["parent_id"]); // Spot check + } } -- cgit v1.2.3 From d5b80f29444e03aadc1130ab1624a09c0689fb93 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 8 Jun 2010 14:35:35 -0700 Subject: Don't use the standard error formatting for exceptions that have occurred as part of a REST request. Format the exception as a json encoded text string so the client can extract the fault information if they so choose. --- modules/gallery/helpers/item_rest.php | 2 +- modules/rest/controllers/rest.php | 102 ++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 38 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index f99afbc2..763e586f 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -161,7 +161,7 @@ class item_rest_Core { case "photo": case "movie": if (empty($request->file)) { - throw new Rest_Exception("Bad Request: Upload failed", 400); + throw new Rest_Exception("file: Upload failed", 400); } $item->type = $entity->type; $item->parent_id = $parent->id; diff --git a/modules/rest/controllers/rest.php b/modules/rest/controllers/rest.php index 38f28171..6392838f 100644 --- a/modules/rest/controllers/rest.php +++ b/modules/rest/controllers/rest.php @@ -39,54 +39,82 @@ class Rest_Controller extends Controller { } public function __call($function, $args) { - $input = Input::instance(); - $request = new stdClass(); - - switch ($method = strtolower($input->server("REQUEST_METHOD"))) { - case "get": - $request->params = (object) $input->get(); - break; - - default: - $request->params = (object) $input->post(); - if (isset($_FILES["file"])) { - $request->file = upload::save("file"); + try { + $input = Input::instance(); + $request = new stdClass(); + + switch ($method = strtolower($input->server("REQUEST_METHOD"))) { + case "get": + $request->params = (object) $input->get(); + break; + + default: + $request->params = (object) $input->post(); + if (isset($_FILES["file"])) { + $request->file = upload::save("file"); + } + break; } - break; - } - if (isset($request->params->entity)) { - $request->params->entity = json_decode($request->params->entity); - } - if (isset($request->params->members)) { - $request->params->members = json_decode($request->params->members); - } + if (isset($request->params->entity)) { + $request->params->entity = json_decode($request->params->entity); + } + if (isset($request->params->members)) { + $request->params->members = json_decode($request->params->members); + } - $request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method)); - $request->access_key = $input->server("HTTP_X_GALLERY_REQUEST_KEY"); + $request->method = strtolower($input->server("HTTP_X_GALLERY_REQUEST_METHOD", $method)); + $request->access_key = $input->server("HTTP_X_GALLERY_REQUEST_KEY"); - if (empty($request->access_key) && !empty($request->params->access_key)) { - $request->access_key = $request->params->access_key; - } + if (empty($request->access_key) && !empty($request->params->access_key)) { + $request->access_key = $request->params->access_key; + } + + $request->url = url::abs_current(true); - $request->url = url::abs_current(true); + rest::set_active_user($request->access_key); - rest::set_active_user($request->access_key); + $handler_class = "{$function}_rest"; + $handler_method = $request->method; - $handler_class = "{$function}_rest"; - $handler_method = $request->method; + if (!method_exists($handler_class, $handler_method)) { + throw new Rest_Exception("Bad Request", 400); + } - if (!method_exists($handler_class, $handler_method)) { - throw new Rest_Exception("Bad Request", 400); + $response = call_user_func(array($handler_class, $handler_method), $request); + } catch (Exception $e) { + $response = $this->_format_exception_response($e); } - try { - rest::reply(call_user_func(array($handler_class, $handler_method), $request)); - } catch (ORM_Validation_Exception $e) { - foreach ($e->validation->errors() as $key => $value) { - $msgs[] = "$key: $value"; + rest::reply($response); + } + + private function _format_exception_response($e) { + // Add this exception to the log + Kohana_Log::add('error', Kohana_Exception::text($e)); + + $e->sendHeaders(); + + $rest_exception = array(); + if ($e instanceof ORM_Validation_Exception) { + $detail_response = true; + $rest_exception["code"] = 400; + $rest_exception["message"] = t("Validation errors"); + $rest_exception["fields"] = $e->validation->errors; + } else if ($e instanceof Rest_Exception) { + $rest_exception["code"] = $e->getCode(); + if ($e->getMessage() != "Bad Request") { + $rest_exception["message"] = "Bad Request"; + $rest_exception["fields"] = array("type", $e->getMessage()); + } else { + $rest_exception["message"] = $e->getMessage(); } - throw new Rest_Exception("Bad Request: " . join(", ", $msgs), 400); + header("HTTP/1.1 400 Bad Request"); + } else { + $rest_exception["code"] = 500; + $rest_exception["message"] = t("Remote server call failed. Please contact the Adminstrator."); } + + return $rest_exception; } } \ No newline at end of file -- cgit v1.2.3 From b40057283e1dfbb3bbb41a6dfc8ccc8e2111d810 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 8 Jun 2010 20:59:24 -0700 Subject: Add a "can_edit" field to the Item_Model's REST output. It's applicable to the current user. --- modules/gallery/models/item.php | 1 + modules/gallery/tests/Item_Model_Test.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index f59caa65..a0866934 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -951,6 +951,7 @@ class Item_Model extends ORM_MPTT { $data["resize_url"] = $tmp; } $data["thumb_url"] = $this->thumb_url(true); + $data["can_edit"] = access::can("edit", $this); // Elide some internal-only data that is going to cause confusion in the client. foreach (array("relative_path_cache", "relative_url_cache", "left_ptr", "right_ptr", diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 6c5882c4..3df6197d 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Item_Model_Test extends Gallery_Unit_Test_Case { + public function teardown() { + identity::set_active_user(identity::admin_user()); + } + public function saving_sets_created_and_updated_dates_test() { $item = test::random_photo(); $this->assert_true(!empty($item->created)); @@ -376,6 +380,15 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $this->assert_true(!array_key_exists("album_cover_item", $result)); } + public function as_restful_array_with_edit_bit_test() { + $response = item::root()->as_restful_array(true); + $this->assert_true($response["can_edit"]); + + identity::set_active_user(identity::guest()); + $response = item::root()->as_restful_array(true); + $this->assert_false($response["can_edit"]); + } + public function first_photo_becomes_album_cover() { $album = test::random_album(); $photo = test::random_photo($album); -- cgit v1.2.3 From 3dacafb7182dd915c4c6d4e7d75722976e231465 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 9 Jun 2010 20:49:32 -0700 Subject: Revert the "preserve_ids" global query parameter. We decided that it was a bad idea. This reverts commit 6425d41eddd44091b2d83ba3c3734cc6990ca581. --- modules/gallery/helpers/item_rest.php | 3 +- modules/gallery/helpers/items_rest.php | 14 ++++------ modules/gallery/models/item.php | 7 ++--- modules/gallery/tests/Item_Model_Test.php | 4 +-- modules/gallery/tests/Item_Rest_Helper_Test.php | 21 ++++---------- modules/gallery/tests/Items_Rest_Helper_Test.php | 35 ++++++++---------------- 6 files changed, 27 insertions(+), 57 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 1d19d9f1..c88f92d9 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -78,10 +78,9 @@ class item_rest_Core { } $orm->order_by($order_by); - $preserve_ids = isset($p->preserve_ids) ? (bool)$p->preserve_ids : false; $result = array( "url" => $request->url, - "entity" => $item->as_restful_array($preserve_ids), + "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item)); if ($item->is_album()) { $result["members"] = array(); diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index e9773745..9cca9a54 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -36,8 +36,6 @@ class items_rest_Core { */ static function get($request) { $items = array(); - $preserve_ids = isset($request->params->preserve_ids) ? - (bool)$request->params->preserve_ids : false; if (isset($request->params->urls)) { foreach (json_decode($request->params->urls) as $url) { if (isset($request->params->type)) { @@ -47,10 +45,10 @@ class items_rest_Core { if (access::can("view", $item)) { if (isset($types)) { if (in_array($item->type, $types)) { - $items[] = items_rest::_format_restful_item($item, $preserve_ids); + $items[] = items_rest::_format_restful_item($item); } } else { - $items[] = items_rest::_format_restful_item($item, $preserve_ids); + $items[] = items_rest::_format_restful_item($item); } } } @@ -59,9 +57,9 @@ class items_rest_Core { if (!access::can("view", $item)) { throw new Kohana_404_Exception(); } - $items[] = items_rest::_format_restful_item($item, $preserve_ids); + $items[] = items_rest::_format_restful_item($item); while (($item = $item->parent()) != null) { - array_unshift($items, items_rest::_format_restful_item($item, $preserve_ids)); + array_unshift($items, items_rest::_format_restful_item($item)); }; } @@ -76,9 +74,9 @@ class items_rest_Core { return $item; } - private static function _format_restful_item($item, $preserve_ids) { + private static function _format_restful_item($item) { $item_rest = array("url" => rest::url("item", $item), - "entity" => $item->as_restful_array($preserve_ids), + "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item)); if ($item->type == "album") { $members = array(); diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index a0866934..009457c1 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -923,15 +923,12 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. - * Convert any item ids into REST urls - * - * @param bool preserve_ids true if we should preserve ids */ - public function as_restful_array($preserve_ids) { + public function as_restful_array($convert_ids=true) { // Convert item ids to rest URLs for consistency $data = $this->as_array(); - if (!$preserve_ids) { + if ($convert_ids) { if ($tmp = $this->parent()) { $data["parent"] = rest::url("item", $tmp); } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index 3df6197d..f9e6a4e3 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -361,7 +361,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(false); + $result = $album->as_restful_array(); $this->assert_same(rest::url("item", item::root()), $result["parent"]); $this->assert_same(rest::url("item", $photo), $result["album_cover"]); $this->assert_true(!array_key_exists("parent_id", $result)); @@ -373,7 +373,7 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $photo = test::random_photo($album); $album->reload(); - $result = $album->as_restful_array(true); + $result = $album->as_restful_array(false); $this->assert_same(item::root()->id, $result["parent_id"]); $this->assert_same($photo->id, $result["album_cover_item_id"]); $this->assert_true(!array_key_exists("parent", $result)); diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 5a80d66b..0b5e0471 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -28,17 +28,6 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal($album->id, $resolved->id); } - public function get_with_ids_test() { - $photo1 = test::random_photo(item::root()); - $request = new stdClass(); - $request->url = rest::url("item", $photo1); - $request->params = new stdClass(); - $request->params->preserve_ids = 1; - - $response = item_rest::get($request); - $this->assert_equal(item::root()->id, $response["entity"]["parent_id"]); // Spot check - } - public function get_scope_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); @@ -52,7 +41,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params = new stdClass(); $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -67,7 +56,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "direct"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -82,7 +71,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->scope = "all"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -109,7 +98,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->name = "foo"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -132,7 +121,7 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request->params->type = "album"; $this->assert_equal_array( array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index 3efd677d..94bf912a 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -34,13 +34,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(false), + "entity" => $photo1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -67,7 +67,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -94,7 +94,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(false), + "entity" => $photo1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), @@ -119,13 +119,13 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_equal_array( array( array("url" => rest::url("item", $photo1), - "entity" => $photo1->as_restful_array(false), + "entity" => $photo1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -146,7 +146,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $root = ORM::factory("item", 1); $restful_root = array( "url" => rest::url("item", $root), - "entity" => $root->as_restful_array(false), + "entity" => $root->as_restful_array(), "relationships" => rest::relationships("item", $root)); $restful_root["members"] = array(); foreach ($root->children() as $child) { @@ -155,12 +155,12 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->params = new stdClass(); - $request->params->ancestors_for = rest::url("item", $photo2); + $request->params->ancestor_for = rest::url("item", $photo2); $this->assert_equal_array( array( $restful_root, array("url" => rest::url("item", $album1), - "entity" => $album1->as_restful_array(false), + "entity" => $album1->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album1), @@ -170,7 +170,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { rest::url("item", $album2)), ), array("url" => rest::url("item", $album2), - "entity" => $album2->as_restful_array(false), + "entity" => $album2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $album2), @@ -178,24 +178,11 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { "members" => array( rest::url("item", $photo2))), array("url" => rest::url("item", $photo2), - "entity" => $photo2->as_restful_array(false), + "entity" => $photo2->as_restful_array(), "relationships" => array( "tags" => array( "url" => rest::url("item_tags", $photo2), "members" => array())))), items_rest::get($request)); } - - public function get_ancestor_with_ids_test() { - $album1 = test::random_album(); - $photo1 = test::random_photo($album1); - - $request = new stdClass(); - $request->params = new stdClass(); - $request->params->ancestors_for = rest::url("item", $photo1); - $request->params->preserve_ids = 1; - - $response = items_rest::get($request); - $this->assert_same(item::root()->id, $response[1]["entity"]["parent_id"]); // Spot check - } } -- cgit v1.2.3 From aff0f6eca85e1a9aec83e13c29746f58010a56f6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 9 Jun 2010 20:55:39 -0700 Subject: Fix get_ancestor_test() since the parameter was renamed to ancestors_for. --- modules/gallery/tests/Items_Rest_Helper_Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index 94bf912a..17e979a5 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -135,7 +135,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { items_rest::get($request)); } - public function get_ancestor_test() { + public function get_ancestors_test() { $album1 = test::random_album(); $photo1 = test::random_photo($album1); $album2 = test::random_album($album1); @@ -155,7 +155,7 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { $request = new stdClass(); $request->params = new stdClass(); - $request->params->ancestor_for = rest::url("item", $photo2); + $request->params->ancestors_for = rest::url("item", $photo2); $this->assert_equal_array( array( $restful_root, -- cgit v1.2.3 From 6556ca88339c78824f3de64c85a57e30a679431c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 9 Jun 2010 21:23:42 -0700 Subject: In GalleryCodeFilterIterator::accept(), ignore . and .., and stop caring about .svn --- modules/gallery/tests/Gallery_Filters.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/Gallery_Filters.php b/modules/gallery/tests/Gallery_Filters.php index 4e32553b..debbe846 100644 --- a/modules/gallery/tests/Gallery_Filters.php +++ b/modules/gallery/tests/Gallery_Filters.php @@ -28,8 +28,10 @@ class GalleryCodeFilterIterator extends FilterIterator { public function accept() { // Skip anything that we didn"t write $path_name = $this->getInnerIterator()->getPathName(); + $file_name = $this->getInnerIterator()->getFileName(); return !( - strpos($path_name, ".svn") || + $file_name == "." || + $file_name == ".." || strpos($path_name, DOCROOT . "test") !== false || strpos($path_name, DOCROOT . "var") !== false || strpos($path_name, MODPATH . "forge") !== false || -- cgit v1.2.3 From ab93767e4d39764f103545efb6ac64ff942eb187 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 9 Jun 2010 21:26:36 -0700 Subject: Update golden file --- modules/gallery/tests/xss_data.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 0a75d6f7..68dca9cb 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -4,6 +4,7 @@ modules/akismet/views/admin_akismet_stats.html.php 9 DIRTY_ATTR urle modules/comment/views/admin_block_recent_comments.html.php 4 DIRTY_ATTR text::alternate("g-even","g-odd") modules/comment/views/admin_block_recent_comments.html.php 5 DIRTY_ATTR $comment->author()->avatar_url(32,$theme->url(,true)) modules/comment/views/admin_block_recent_comments.html.php 10 DIRTY gallery::date_time($comment->created) +modules/comment/views/admin_comments.html.php 5 DIRTY $form modules/comment/views/admin_manage_comments.html.php 43 DIRTY $menu->render() modules/comment/views/admin_manage_comments.html.php 107 DIRTY_ATTR $comment->id modules/comment/views/admin_manage_comments.html.php 107 DIRTY_ATTR text::alternate("g-odd","g-even") @@ -32,8 +33,8 @@ modules/comment/views/comment.mrss.php 29 DIRTY $child modules/comment/views/comment.mrss.php 34 DIRTY_ATTR $child->thumb_url modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $child->thumb_height modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $child->thumb_width -modules/comment/views/comments.html.php 18 DIRTY_ATTR $comment->id -modules/comment/views/comments.html.php 21 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) +modules/comment/views/comments.html.php 21 DIRTY_ATTR $comment->id +modules/comment/views/comments.html.php 24 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) modules/comment/views/user_profile_comments.html.php 5 DIRTY_ATTR $comment->id modules/comment/views/user_profile_comments.html.php 10 DIRTY_JS $comment->item()->url() modules/comment/views/user_profile_comments.html.php 11 DIRTY $comment->item()->thumb_img(array(),50) -- cgit v1.2.3 From 58b21e909d8ba628ddb8a19e732989821abb0283 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 10 Jun 2010 18:49:29 -0700 Subject: Change the pattern used to convert the file name to a title. Fixes ticket#1061 --- modules/gallery/helpers/item.php | 2 +- modules/gallery/tests/Item_Helper_Test.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index bbbe1058..15bbe977 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -136,7 +136,7 @@ class item_Core { */ static function convert_filename_to_title($filename) { $title = strtr($filename, "_", " "); - $title = preg_replace("/\..*?$/", "", $title); + $title = preg_replace("/\..{3,4}$/", "", $title); $title = preg_replace("/ +/", " ", $title); return $title; } diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index 4771b11a..00229973 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -41,6 +41,11 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case { ORM::factory("item")->viewable()->where("id", "=", $item->id)->count_all()); } + public function convert_filename_to_title_test() { + $this->assert_equal("foo", item::convert_filename_to_title("foo.jpg")); + $this->assert_equal("foo.bar", item::convert_filename_to_title("foo.bar.jpg")); + } + public function convert_filename_to_slug_test() { $this->assert_equal("foo", item::convert_filename_to_slug("{[foo]}")); $this->assert_equal("foo-bar", item::convert_filename_to_slug("{[foo!@#!$@#^$@($!(@bar]}")); -- cgit v1.2.3 From 0ebc36b4e5ef5578791c00b8a64021d3aad96068 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 11 Jun 2010 08:15:25 -0700 Subject: Actually execute the database query that updates the album view count. Fixes ticket #1092. Thanks to shinta for pointing the way. --- modules/gallery/controllers/albums.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index ea15418f..eaa09be5 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -73,8 +73,8 @@ class Albums_Controller extends Items_Controller { // We can't use math in ORM or the query builder, so do this by hand. It's important // that we do this with math, otherwise concurrent accesses will damage accuracy. - db::query( - "UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id"); + db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id") + ->execute(); print $template; } -- cgit v1.2.3 From 30f4e143e8fbec928661dcbe75898465e7eff29c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 11 Jun 2010 08:15:25 -0700 Subject: Actually execute the database query that updates the album view count. Fixes ticket #1092. Thanks to shinta for pointing the way. --- modules/gallery/controllers/albums.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index ea15418f..eaa09be5 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -73,8 +73,8 @@ class Albums_Controller extends Items_Controller { // We can't use math in ORM or the query builder, so do this by hand. It's important // that we do this with math, otherwise concurrent accesses will damage accuracy. - db::query( - "UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id"); + db::query("UPDATE {items} SET `view_count` = `view_count` + 1 WHERE `id` = $album->id") + ->execute(); print $template; } -- cgit v1.2.3 From bbbb35675acefc6b0b1b78dea9fd3a983189d772 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 11 Jun 2010 15:40:54 -0700 Subject: Fix for ticket #1039. The problem was, as Bryan76 pointed out, with passing the full url in the continue parameter. In the logout controller, we tried to get the item from the url so we could check the permission of the item to insure that the guest user had access. But url::get_item_from_url expects a relative url. --- modules/gallery/controllers/logout.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index 967dad49..fdbadf1b 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -22,13 +22,16 @@ class Logout_Controller extends Controller { access::verify_csrf(); auth::logout(); if ($continue_url = Input::instance()->get("continue")) { - $item = url::get_item_from_uri($continue_url); + $components = explode("/", parse_url($continue_url, PHP_URL_PATH), 4); + $item = url::get_item_from_uri($components[3]); if (access::can("view", $item)) { // Don't use url::redirect() because it'll call url::site() and munge the continue url. - header("Location: $continue_url"); + header("Location: {$item->relative_url()}"); } else { url::redirect(item::root()->abs_url()); } + } else { + url::redirect(item::root()->abs_url()); } } } \ No newline at end of file -- cgit v1.2.3 From cb01f4017d70a7d73273052b424e8b78b794bc1c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 11 Jun 2010 16:37:45 -0700 Subject: Fix for ticket #1118. The item validation was flagging duplicate slugs as errors. There was already code in the item save to insure that any duplicates were made unique, so this patch removes the validation as unnecessary. --- modules/gallery/models/item.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 009457c1..a4f264bb 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -767,13 +767,6 @@ class Item_Model extends ORM_MPTT { public function valid_slug(Validation $v, $field) { if (preg_match("/[^A-Za-z0-9-_]/", $this->slug)) { $v->add_error("slug", "not_url_safe"); - } else if (db::build() - ->from("items") - ->where("parent_id", "=", $this->parent_id) - ->where("id", "<>", $this->id) - ->where("slug", "=", $this->slug) - ->count_records()) { - $v->add_error("slug", "conflict"); } } -- cgit v1.2.3 From a4586bc0c01fac6e86163fd119aaa64d95fb5e8e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 13:05:40 -0700 Subject: Revert "Fix for ticket #1118. The item validation was flagging duplicate slugs as errors. There was already code in the item save to insure that any" This introduces a bug where you can create two items with the same slug. This reverts commit cb01f4017d70a7d73273052b424e8b78b794bc1c. --- modules/gallery/models/item.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index a4f264bb..009457c1 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -767,6 +767,13 @@ class Item_Model extends ORM_MPTT { public function valid_slug(Validation $v, $field) { if (preg_match("/[^A-Za-z0-9-_]/", $this->slug)) { $v->add_error("slug", "not_url_safe"); + } else if (db::build() + ->from("items") + ->where("parent_id", "=", $this->parent_id) + ->where("id", "<>", $this->id) + ->where("slug", "=", $this->slug) + ->count_records()) { + $v->add_error("slug", "conflict"); } } -- cgit v1.2.3 From 63d95087bf0f24d4e880843cd2841906c6f91b38 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 13:35:12 -0700 Subject: Stop trying to parse the continue url in the logout controller because it requires us to reproduce a bunch of complex routing logic. Instead, just have the logout link generating code generate a link that's visible to guests. --- modules/gallery/controllers/logout.php | 12 ++---------- modules/gallery/helpers/gallery_event.php | 13 ++++++++++++- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index fdbadf1b..9caafec8 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -22,16 +22,8 @@ class Logout_Controller extends Controller { access::verify_csrf(); auth::logout(); if ($continue_url = Input::instance()->get("continue")) { - $components = explode("/", parse_url($continue_url, PHP_URL_PATH), 4); - $item = url::get_item_from_uri($components[3]); - if (access::can("view", $item)) { - // Don't use url::redirect() because it'll call url::site() and munge the continue url. - header("Location: {$item->relative_url()}"); - } else { - url::redirect(item::root()->abs_url()); - } - } else { - url::redirect(item::root()->abs_url()); + url::redirect($continue_url); } + url::redirect(item::root()->abs_url()); } } \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index ae7131ae..1b688843 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -157,11 +157,22 @@ class gallery_event_Core { ->view("login_current_user.html") ->url(user_profile::url($user->id)) ->label($user->display_name())); + + if (isset($theme->item)) { + if (access::user_can(identity::guest(), "view", $theme->item)) { + $continue_url = $theme->item->abs_url(); + } else { + $continue_url = item::root()->abs_url(); + } + } else { + $continue_url = url::abs_current(); + } + $menu->append(Menu::factory("link") ->id("user_menu_logout") ->css_id("g-logout-link") ->url(url::site("logout?csrf=$csrf&continue=" . - urlencode(url::abs_current()))) + urlencode($continue_url))) ->label(t("Logout"))); } } -- cgit v1.2.3 From b61b50604bfffc25a395df3a1aedf84d3c557ff4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 15:09:16 -0700 Subject: Push the continue url into the form for consistency with other login/continue code. --- modules/gallery/controllers/admin.php | 2 +- modules/gallery/controllers/reauthenticate.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index 787a2138..0aeaa876 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -78,7 +78,7 @@ class Admin_Controller extends Controller { private static function _prompt_for_reauth($controller_name, $args) { if (request::method() == "get" && !request::is_ajax()) { // Avoid anti-phishing protection by passing the url as session variable. - Session::instance()->set("continue_url", url::current(true)); + Session::instance()->set("continue_url", url::abs_current(true)); } url::redirect("reauthenticate"); } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 3503d80a..acb27f6a 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -37,8 +37,7 @@ class Reauthenticate_Controller extends Controller { if ($valid) { message::success(t("Successfully re-authenticated!")); module::event("user_auth", $user); - $continue_url = Session::instance()->get_once("continue_url", "admin"); - url::redirect($continue_url); + url::redirect($form->continue_url->value); } else { $name = $user->name; log::warning("user", t("Failed re-authentication for %name", array("name" => $name))); @@ -59,6 +58,7 @@ class Reauthenticate_Controller extends Controller { private static function _form() { $form = new Forge("reauthenticate/auth", "", "post", array("id" => "g-reauthenticate-form")); $form->set_attr('class', "g-narrow"); + $form->hidden("continue_url")->value(Session::instance()->get("continue_url", "admin")); $group = $form->group("reauthenticate")->label(t("Re-authenticate")); $group->password("password")->label(t("Password"))->id("g-password")->class(null) ->callback("auth::validate_too_many_failed_auth_attempts") -- cgit v1.2.3 From c026da85cdbac9e9566045f8de2718cae985f0ec Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 15:10:34 -0700 Subject: Use "continue_url" instead of "continue" for consistency with the reauth code. --- modules/gallery/controllers/logout.php | 2 +- modules/gallery/helpers/gallery_event.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/logout.php b/modules/gallery/controllers/logout.php index 9caafec8..20fa8074 100644 --- a/modules/gallery/controllers/logout.php +++ b/modules/gallery/controllers/logout.php @@ -21,7 +21,7 @@ class Logout_Controller extends Controller { public function index() { access::verify_csrf(); auth::logout(); - if ($continue_url = Input::instance()->get("continue")) { + if ($continue_url = Input::instance()->get("continue_url")) { url::redirect($continue_url); } url::redirect(item::root()->abs_url()); diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 1b688843..55db47ce 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -171,7 +171,7 @@ class gallery_event_Core { $menu->append(Menu::factory("link") ->id("user_menu_logout") ->css_id("g-logout-link") - ->url(url::site("logout?csrf=$csrf&continue=" . + ->url(url::site("logout?csrf=$csrf&continue_url=" . urlencode($continue_url))) ->label(t("Logout"))); } -- cgit v1.2.3 From dceecabbf1b736604ceb2e08e803b12c99dc4509 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 15:16:47 -0700 Subject: Make login/logout continuation url code consistent. Where necessary, we specify the continue_url in the session, but we store it in the login form so that we can propagate it across the session creation that happens at login time. --- modules/gallery/controllers/login.php | 4 ++-- modules/gallery/helpers/auth.php | 1 + modules/gallery/libraries/MY_Kohana_Exception.php | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index 40125476..19335d88 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -44,10 +44,10 @@ class Login_Controller extends Controller { public function auth_html() { access::verify_csrf(); - $continue_url = Session::instance()->get("continue_url", null); list ($valid, $form) = $this->_auth("login/auth_html"); if ($valid) { - url::redirect($continue_url ? $continue_url : item::root()->abs_url()); + url::redirect($form->continue_url->value ? $form->continue_url_value : + item::root()->abs_url()); } else { $view = new Theme_View("page.html", "other", "login"); $view->page_title = t("Log in to Gallery"); diff --git a/modules/gallery/helpers/auth.php b/modules/gallery/helpers/auth.php index 1a9fe869..48b5fc32 100644 --- a/modules/gallery/helpers/auth.php +++ b/modules/gallery/helpers/auth.php @@ -21,6 +21,7 @@ class auth_Core { static function get_login_form($url) { $form = new Forge($url, "", "post", array("id" => "g-login-form")); $form->set_attr("class", "g-narrow"); + $form->hidden("continue_url")->value(Session::instance()->get("continue_url")); $group = $form->group("login")->label(t("Login")); $group->input("name")->label(t("Username"))->id("g-username")->class(null) ->callback("auth::validate_too_many_failed_logins") diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php index e7ebdb1f..df7557ae 100644 --- a/modules/gallery/libraries/MY_Kohana_Exception.php +++ b/modules/gallery/libraries/MY_Kohana_Exception.php @@ -59,7 +59,7 @@ class Kohana_Exception extends Kohana_Exception_Core { private static function _show_themed_error_page(Exception $e) { // Create a text version of the exception $error = Kohana_Exception::text($e); - + // Add this exception to the log Kohana_Log::add('error', $error); @@ -83,8 +83,6 @@ class Kohana_Exception extends Kohana_Exception_Core { if ($view->content->is_guest) { $view->content->login_form = new View("login_ajax.html"); $view->content->login_form->form = auth::get_login_form("login/auth_html"); - // Avoid anti-phishing protection by passing the url as session variable. - Session::instance()->set("continue_url", url::current(true)); } } else { $view->page_title = t("Dang... Something went wrong!"); -- cgit v1.2.3 From 87f8b6ff0a76f51183f14515723a8345f7c14fa6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 15:28:03 -0700 Subject: Bounce the user to the login page if they try to get to part of the admin site as a guest. Also, theme the login/html page. --- modules/gallery/controllers/admin.php | 7 ++++++- modules/gallery/controllers/login.php | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index 0aeaa876..c460f58c 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -22,7 +22,12 @@ class Admin_Controller extends Controller { public function __construct($theme=null) { if (!identity::active_user()->admin) { - access::forbidden(); + if (identity::active_user()->guest) { + Session::instance()->set("continue_url", url::abs_current(true)); + url::redirect("login"); + } else { + access::forbidden(); + } } parent::__construct(); diff --git a/modules/gallery/controllers/login.php b/modules/gallery/controllers/login.php index 19335d88..2b60316b 100644 --- a/modules/gallery/controllers/login.php +++ b/modules/gallery/controllers/login.php @@ -38,7 +38,10 @@ class Login_Controller extends Controller { } public function html() { - print auth::get_login_form("login/auth_html"); + $view = new Theme_View("page.html", "other", "login"); + $view->page_title = t("Login"); + $view->content = auth::get_login_form("login/auth_html"); + print $view; } public function auth_html() { @@ -46,8 +49,8 @@ class Login_Controller extends Controller { list ($valid, $form) = $this->_auth("login/auth_html"); if ($valid) { - url::redirect($form->continue_url->value ? $form->continue_url_value : - item::root()->abs_url()); + $continue_url = $form->continue_url->value; + url::redirect($continue_url ? $continue_url : item::root()->abs_url()); } else { $view = new Theme_View("page.html", "other", "login"); $view->page_title = t("Log in to Gallery"); -- cgit v1.2.3 From db0966a9bce0396b0c98f3532bca8613f77cdb05 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 12 Jun 2010 15:39:38 -0700 Subject: Fix up some indentation and comment style. --- modules/gallery/js/l10n_client.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/js/l10n_client.js b/modules/gallery/js/l10n_client.js index a1170e2d..a1b970e7 100644 --- a/modules/gallery/js/l10n_client.js +++ b/modules/gallery/js/l10n_client.js @@ -60,25 +60,21 @@ jQuery.extend(Gallery, { $('#l10n-client').height('22em').removeClass('hidden'); //$('#l10n-client').slideUp(); $('#g-minimize-l10n').text("_"); - /* - * This CSS clashes with Gallery's CSS, probably due to - * YUI's grid / floats. - if(!$.browser.msie) { - $('body').css('border-bottom', '22em solid #fff'); - } - */ + // This CSS clashes with Gallery's CSS, probably due to + // YUI's grid / floats. + // if(!$.browser.msie) { + // $('body').css('border-bottom', '22em solid #fff'); + // } $.cookie('Gallery_l10n_client', '1', {expires: 7, path: '/'}); break; case 0: $('#l10n-client-string-select, #l10n-client-string-editor, #l10n-client .labels .label').hide(); $('#l10n-client').height('2em').addClass('hidden'); // TODO: Localize this message - $('#g-minimize-l10n').text(MSG_TRANSLATE_TEXT); - /* - if(!$.browser.msie) { - $('body').css('border-bottom', '0px'); - } - */ + $('#g-minimize-l10n').text(MSG_TRANSLATE_TEXT); + // if(!$.browser.msie) { + // $('body').css('border-bottom', '0px'); + // } $.cookie('Gallery_l10n_client', '0', {expires: 7, path: '/'}); break; } -- cgit v1.2.3 From 6f443a819b360a89c53004d3bf860fcedd88ae2e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 13 Jun 2010 20:49:50 -0700 Subject: Change single to double quotes. --- modules/gallery/helpers/site_status.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php index 759eb382..13c42dda 100644 --- a/modules/gallery/helpers/site_status.php +++ b/modules/gallery/helpers/site_status.php @@ -100,7 +100,7 @@ class site_status_Core { } $buf = array(); foreach (ORM::factory("message")->find_all() as $msg) { - $value = str_replace('__CSRF__', access::csrf_token(), $msg->value); + $value = str_replace("__CSRF__", access::csrf_token(), $msg->value); $buf[] = "
  • severity) . "\">$value
  • "; } -- cgit v1.2.3 From 793780daa7665f7f86994235c4263fcb63554eb8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 13 Jun 2010 20:51:11 -0700 Subject: Replace __CSRF__ with the actual csrf token. --- modules/gallery/helpers/message.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/message.php b/modules/gallery/helpers/message.php index 047eb2c7..1f69e2a9 100644 --- a/modules/gallery/helpers/message.php +++ b/modules/gallery/helpers/message.php @@ -78,6 +78,7 @@ class message_Core { $messages = Session::instance()->get_once("messages", array()); foreach ($messages as $msg) { + $msg[0] = str_replace("__CSRF__", access::csrf_token(), $msg[0]); $buf[] = "
  • $msg[0]
  • "; } if ($buf) { -- cgit v1.2.3 From 7e5661cf49aa2239fb71e7feb289e2dfee926e3d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 14 Jun 2010 22:42:32 -0700 Subject: Add a simple/cheap test to make sure that the database config is ok. Fixes ticket #1029. --- modules/gallery/hooks/init_gallery.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/hooks/init_gallery.php b/modules/gallery/hooks/init_gallery.php index 10383e9a..64e44b56 100644 --- a/modules/gallery/hooks/init_gallery.php +++ b/modules/gallery/hooks/init_gallery.php @@ -24,6 +24,15 @@ if (!file_exists(VARPATH . "database.php")) { url::redirect(url::abs_file("installer")); } +// Simple and cheap test to make sure that the database config is ok. Do this before we do +// anything else database related. +try { + Database::instance()->connect(); +} catch (Kohana_PHP_Exception $e) { + print "Database configuration error. Please check var/database.php"; + exit; +} + Event::add("system.ready", array("Gallery_I18n", "instance")); Event::add("system.ready", array("module", "load_modules")); Event::add("system.ready", array("gallery", "ready")); -- cgit v1.2.3 From 603d4640141a43350f50da747d747456b28fdd93 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 15 Jun 2010 11:20:04 -0700 Subject: Change the item rest update processing to call the itemm::move(source, target) helper when the parent member has changed. Using the move method insures that names and slugs that could conflict in the target album are resolved properly. Also, only change the weights of the album children if the item sort_column is set to weight. --- modules/gallery/helpers/item_rest.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 763e586f..27542dea 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -99,7 +99,7 @@ class item_rest_Core { if ($entity = $request->params->entity) { // Only change fields from a whitelist. foreach (array("album_cover", "captured", "description", - "height", "mime_type", "name", "parent", "rand_key", "resize_dirty", + "height", "mime_type", "name", "rand_key", "resize_dirty", "resize_height", "resize_width", "slug", "sort_column", "sort_order", "thumb_dirty", "thumb_height", "thumb_width", "title", "view_count", "width") as $key) { @@ -112,23 +112,21 @@ class item_rest_Core { } break; - case "parent": - if (property_exists($entity, "parent")) { - $parent = rest::resolve($entity->parent); - access::required("edit", $parent); - $item->parent_id = $parent->id; - } - break; default: if (property_exists($entity, $key)) { $item->$key = $entity->$key; } } } + + $item->save(); + if (property_exists($entity, "parent")) { + $parent = rest::resolve($entity->parent); + item::move($item, $parent); + } } - $item->save(); - if (isset($request->params->members)) { + if (isset($request->params->members) && $item->sort_column == "weight") { $weight = 0; foreach ($request->params->members as $url) { $child = rest::resolve($url); -- cgit v1.2.3 From 00c4cb3f6399319326cd3393ee2f15fc8b111088 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 15 Jun 2010 11:38:46 -0700 Subject: Revert "Change the item rest update processing to call the itemm::move(source, target) helper when the parent member has changed. Using the move method insures that names and slugs that could conflict in the target album are resolved properly. Also, only change the weights of the album children if the item sort_column is set to weight." This reverts commit 603d4640141a43350f50da747d747456b28fdd93. --- modules/gallery/helpers/item_rest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 27542dea..763e586f 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -99,7 +99,7 @@ class item_rest_Core { if ($entity = $request->params->entity) { // Only change fields from a whitelist. foreach (array("album_cover", "captured", "description", - "height", "mime_type", "name", "rand_key", "resize_dirty", + "height", "mime_type", "name", "parent", "rand_key", "resize_dirty", "resize_height", "resize_width", "slug", "sort_column", "sort_order", "thumb_dirty", "thumb_height", "thumb_width", "title", "view_count", "width") as $key) { @@ -112,21 +112,23 @@ class item_rest_Core { } break; + case "parent": + if (property_exists($entity, "parent")) { + $parent = rest::resolve($entity->parent); + access::required("edit", $parent); + $item->parent_id = $parent->id; + } + break; default: if (property_exists($entity, $key)) { $item->$key = $entity->$key; } } } - - $item->save(); - if (property_exists($entity, "parent")) { - $parent = rest::resolve($entity->parent); - item::move($item, $parent); - } } + $item->save(); - if (isset($request->params->members) && $item->sort_column == "weight") { + if (isset($request->params->members)) { $weight = 0; foreach ($request->params->members as $url) { $child = rest::resolve($url); -- cgit v1.2.3 From 207f6beb61cf2969d07bbc6f959bba967f54b271 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 15 Jun 2010 11:40:01 -0700 Subject: Only change the weights of the album children if the item sort_column is set to weight. --- modules/gallery/helpers/item_rest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 763e586f..0839b144 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -128,7 +128,7 @@ class item_rest_Core { } $item->save(); - if (isset($request->params->members)) { + if (isset($request->params->members) && $item->sort_column == "weight") { $weight = 0; foreach ($request->params->members as $url) { $child = rest::resolve($url); -- cgit v1.2.3 From 2492280cc0ec9eb64a8daeccc7b5698ece7fea66 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 15 Jun 2010 12:52:28 -0700 Subject: Change the item rest update processing to call the item::move(source, target) helper when the parent member has changed. Using the move method insures that names and slugs that could conflict in the target album are resolved properly. Changed the item::move method so it returns a message to be displayed if the caller chooses. And changed the move controller to display the message returned by the move if the item name was renamed as part of the move. --- modules/gallery/controllers/move.php | 10 ++++------ modules/gallery/helpers/item.php | 15 +++++++++------ modules/gallery/helpers/item_rest.php | 16 +++++++++------- 3 files changed, 22 insertions(+), 19 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index f8b85b6f..3ce44546 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -34,12 +34,10 @@ class Move_Controller extends Controller { $source = ORM::factory("item", $source_id); $target = ORM::factory("item", Input::instance()->post("target_id")); - access::required("view", $source); - access::required("edit", $source); - access::required("view", $target); - access::required("edit", $target); - - item::move($source, $target); + $message = item::move($source, $target); + if (!empty($message)) { + message.info($message); + } print json_encode( array("result" => "success", diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 15bbe977..6a740de4 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -47,27 +47,28 @@ class item_Core { $orig_name_filename = pathinfo($source->name, PATHINFO_FILENAME); $orig_name_extension = pathinfo($source->name, PATHINFO_EXTENSION); $orig_slug = $source->slug; + $message = ""; for ($i = 0; $i < 5; $i++) { try { $source->save(); if ($orig_name != $source->name) { switch ($source->type) { case "album": - message::info( + $message = t("Album %old_name renamed to %new_name to avoid a conflict", - array("old_name" => $orig_name, "new_name" => $source->name))); + array("old_name" => $orig_name, "new_name" => $source->name)); break; case "photo": - message::info( + $message = t("Photo %old_name renamed to %new_name to avoid a conflict", - array("old_name" => $orig_name, "new_name" => $source->name))); + array("old_name" => $orig_name, "new_name" => $source->name)); break; case "movie": - message::info( + $message = t("Movie %old_name renamed to %new_name to avoid a conflict", - array("old_name" => $orig_name, "new_name" => $source->name))); + array("old_name" => $orig_name, "new_name" => $source->name)); break; } } @@ -95,6 +96,8 @@ class item_Core { if ($target->album_cover_item_id == null) { item::make_album_cover($source); } + + return $message; } static function make_album_cover($item) { diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 0839b144..692d0895 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -99,7 +99,7 @@ class item_rest_Core { if ($entity = $request->params->entity) { // Only change fields from a whitelist. foreach (array("album_cover", "captured", "description", - "height", "mime_type", "name", "parent", "rand_key", "resize_dirty", + "height", "mime_type", "name", "rand_key", "resize_dirty", "resize_height", "resize_width", "slug", "sort_column", "sort_order", "thumb_dirty", "thumb_height", "thumb_width", "title", "view_count", "width") as $key) { @@ -113,11 +113,6 @@ class item_rest_Core { break; case "parent": - if (property_exists($entity, "parent")) { - $parent = rest::resolve($entity->parent); - access::required("edit", $parent); - $item->parent_id = $parent->id; - } break; default: if (property_exists($entity, $key)) { @@ -125,8 +120,15 @@ class item_rest_Core { } } } + + // There is an explicit save in item::move + if (property_exists($entity, "parent")) { + $parent = rest::resolve($entity->parent); + item::move($item, $parent); + } else { + $item->save(); + } } - $item->save(); if (isset($request->params->members) && $item->sort_column == "weight") { $weight = 0; -- cgit v1.2.3 From 9504f71efcadc7ed27f6f09e5d663e8025bf3b86 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 15 Jun 2010 14:18:23 -0700 Subject: Fix for ticket #1118. Create a item::save_with_retries helper method, which encapsulates saving an item and handling name and slug conflicts. Call this instead of doing a save directly. --- modules/gallery/controllers/simple_uploader.php | 10 +++++++--- modules/gallery/helpers/item.php | 17 +++++++++++------ modules/gallery/helpers/item_rest.php | 8 +++----- 3 files changed, 21 insertions(+), 14 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php index c7e5031b..8ac1fc8b 100644 --- a/modules/gallery/controllers/simple_uploader.php +++ b/modules/gallery/controllers/simple_uploader.php @@ -65,12 +65,16 @@ class Simple_Uploader_Controller extends Controller { if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) { $item->type = "movie"; - $item->save(); + } else { + $item->type = "photo"; + } + + item::save_with_retries($item); + + if ($item->type == "movie") { log::success("content", t("Added a movie"), html::anchor("movies/$item->id", t("view movie"))); } else { - $item->type = "photo"; - $item->save(); log::success("content", t("Added a photo"), html::anchor("photos/$item->id", t("view photo"))); } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 6a740de4..0710d8b2 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -43,6 +43,17 @@ class item_Core { // Moving may result in name or slug conflicts. If that happens, try up to 5 times to pick a // random name (or slug) to avoid the conflict. + $message = item::save_with_retries($source); + + // If the target has no cover item, make this it. + if ($target->album_cover_item_id == null) { + item::make_album_cover($source); + } + + return $message; + } + + static function save_with_retries($source, $retries=5) { $orig_name = $source->name; $orig_name_filename = pathinfo($source->name, PATHINFO_FILENAME); $orig_name_extension = pathinfo($source->name, PATHINFO_EXTENSION); @@ -91,12 +102,6 @@ class item_Core { } } } - - // If the target has no cover item, make this it. - if ($target->album_cover_item_id == null) { - item::make_album_cover($source); - } - return $message; } diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 692d0895..74fab2e7 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -112,8 +112,6 @@ class item_rest_Core { } break; - case "parent": - break; default: if (property_exists($entity, $key)) { $item->$key = $entity->$key; @@ -126,7 +124,7 @@ class item_rest_Core { $parent = rest::resolve($entity->parent); item::move($item, $parent); } else { - $item->save(); + $item::save_with_retries($item); } } @@ -157,7 +155,7 @@ class item_rest_Core { $item->title = isset($entity->title) ? $entity->title : $entity->name; $item->description = isset($entity->description) ? $entity->description : null; $item->slug = isset($entity->slug) ? $entity->slug : null; - $item->save(); + $item::save_with_retries($item); break; case "photo": @@ -172,7 +170,7 @@ class item_rest_Core { $item->title = isset($entity->title) ? $entity->title : $entity->name; $item->description = isset($entity->description) ? $entity->description : null; $item->slug = isset($entity->slug) ? $entity->slug : null; - $item->save(); + $item::save_with_retries($item); break; default: -- cgit v1.2.3 From 4d40cf62e98e7e2f103740a401a08606c73fe72d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 Jun 2010 15:50:10 -0700 Subject: Sort files by path in _dump_var() for consistent output. Skip . and .. (PHP 5.3 iterators seem to include those now). --- modules/gallery/controllers/packager.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index 6eafd9df..0ccfe743 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -163,9 +163,11 @@ class Packager_Controller extends Controller { $paths = array(); foreach($objects as $name => $file){ - if ($file->getBasename() == "database.php") { + $path = $file->getPath(); + $basename = $file->getBasename(); + if ($basename == "database.php" || $basename == "." || $basename == "..") { continue; - } else if (basename($file->getPath()) == "logs" && $file->getBasename() != ".htaccess") { + } else if (basename($path) == "logs" && $basename != ".htaccess") { continue; } @@ -186,6 +188,7 @@ class Packager_Controller extends Controller { foreach ($paths as $path) { fwrite($fd, "!file_exists($path) && mkdir($path);\n"); } + ksort($files); foreach ($files as $file => $contents) { fwrite($fd, "file_put_contents($file, base64_decode(\"$contents\"));\n"); } -- cgit v1.2.3 From ae6af2f9b61d69a3adc36f52257cdbd9c4fedf4e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 Jun 2010 16:01:41 -0700 Subject: Install the rest module by default. --- installer/install.sql | 26 ++++++++++++++++++++------ modules/gallery/controllers/packager.php | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'modules/gallery') diff --git a/installer/install.sql b/installer/install.sql index d3ba4419..2d0cac0f 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -238,17 +238,18 @@ CREATE TABLE {modules} ( `version` int(9) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; +) AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; INSERT INTO {modules} VALUES (1,1,'gallery',30); INSERT INTO {modules} VALUES (2,1,'user',3); INSERT INTO {modules} VALUES (3,1,'comment',3); INSERT INTO {modules} VALUES (4,1,'organize',1); INSERT INTO {modules} VALUES (5,1,'info',1); -INSERT INTO {modules} VALUES (6,1,'rss',1); -INSERT INTO {modules} VALUES (7,1,'search',1); -INSERT INTO {modules} VALUES (8,1,'slideshow',2); -INSERT INTO {modules} VALUES (9,1,'tag',1); +INSERT INTO {modules} VALUES (6,1,'rest',3); +INSERT INTO {modules} VALUES (7,1,'rss',1); +INSERT INTO {modules} VALUES (8,1,'search',1); +INSERT INTO {modules} VALUES (9,1,'slideshow',2); +INSERT INTO {modules} VALUES (10,1,'tag',1); DROP TABLE IF EXISTS {outgoing_translations}; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; @@ -345,6 +346,18 @@ CREATE TABLE {themes} ( /*!40101 SET character_set_client = @saved_cs_client */; INSERT INTO {themes} VALUES (1,'wind',1); INSERT INTO {themes} VALUES (2,'admin_wind',1); +DROP TABLE IF EXISTS {user_access_keys}; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE {user_access_keys} ( + `id` int(9) NOT NULL AUTO_INCREMENT, + `user_id` int(9) NOT NULL, + `access_key` char(32) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `access_key` (`access_key`), + UNIQUE KEY `user_id` (`user_id`) +) DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; DROP TABLE IF EXISTS {users}; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; @@ -378,7 +391,7 @@ CREATE TABLE {vars} ( `value` text, PRIMARY KEY (`id`), UNIQUE KEY `module_name` (`module_name`,`name`) -) AUTO_INCREMENT=41 DEFAULT CHARSET=utf8; +) AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; INSERT INTO {vars} VALUES (NULL,'gallery','active_site_theme','wind'); INSERT INTO {vars} VALUES (NULL,'gallery','active_admin_theme','admin_wind'); @@ -402,5 +415,6 @@ INSERT INTO {vars} VALUES (NULL,'gallery','identity_provider','user'); INSERT INTO {vars} VALUES (NULL,'user','mininum_password_length','5'); INSERT INTO {vars} VALUES (NULL,'comment','access_permissions','everybody'); INSERT INTO {vars} VALUES (NULL,'comment','spam_caught','0'); +INSERT INTO {vars} VALUES (NULL,'rest','allow_guest_access','0'); INSERT INTO {vars} VALUES (NULL,'gallery','blocks_site_sidebar','a:3:{i:9;a:2:{i:0;s:4:\"info\";i:1;s:8:\"metadata\";}i:10;a:2:{i:0;s:3:\"rss\";i:1;s:9:\"rss_feeds\";}i:11;a:2:{i:0;s:3:\"tag\";i:1;s:3:\"tag\";}}'); INSERT INTO {vars} VALUES (NULL,'slideshow','max_scale','0'); diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index 0ccfe743..835cb903 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -63,8 +63,8 @@ class Packager_Controller extends Controller { module::load_modules(); - foreach (array("user", "comment", "organize", "info", "rss", - "search", "slideshow", "tag") as $module_name) { + foreach (array("user", "comment", "organize", "info", "rest", + "rss", "search", "slideshow", "tag") as $module_name) { module::install($module_name); module::activate($module_name); } -- cgit v1.2.3 From 1df752a2f2aba75358d9bb627bc6da9fad7ca889 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 Jun 2010 16:11:21 -0700 Subject: Make the "name" column a little wider. --- modules/gallery/views/admin_modules.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/views/admin_modules.html.php b/modules/gallery/views/admin_modules.html.php index c5015e68..4d6fe5f0 100644 --- a/modules/gallery/views/admin_modules.html.php +++ b/modules/gallery/views/admin_modules.html.php @@ -52,7 +52,7 @@ - + -- cgit v1.2.3 From 48dc07dbc8189eb16f97b7013b0481982286ab2c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 Jun 2010 17:17:25 -0700 Subject: Revert "Fix for ticket #1118. Create a item::save_with_retries helper method, which encapsulates saving an item and handling name and slug conflicts. Call this instead of doing a save directly." Rolled this back because it fails KISS. We already have an API for saving models with Item_Model::save() that's consistent with all of our other model code. Adding a new way to save items is confusing and inconsistent. This reverts commit 9504f71efcadc7ed27f6f09e5d663e8025bf3b86. --- modules/gallery/controllers/simple_uploader.php | 10 +++------- modules/gallery/helpers/item.php | 17 ++++++----------- modules/gallery/helpers/item_rest.php | 8 +++++--- 3 files changed, 14 insertions(+), 21 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php index 8ac1fc8b..c7e5031b 100644 --- a/modules/gallery/controllers/simple_uploader.php +++ b/modules/gallery/controllers/simple_uploader.php @@ -65,16 +65,12 @@ class Simple_Uploader_Controller extends Controller { if (array_key_exists("extension", $path_info) && in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) { $item->type = "movie"; - } else { - $item->type = "photo"; - } - - item::save_with_retries($item); - - if ($item->type == "movie") { + $item->save(); log::success("content", t("Added a movie"), html::anchor("movies/$item->id", t("view movie"))); } else { + $item->type = "photo"; + $item->save(); log::success("content", t("Added a photo"), html::anchor("photos/$item->id", t("view photo"))); } diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 0710d8b2..6a740de4 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -43,17 +43,6 @@ class item_Core { // Moving may result in name or slug conflicts. If that happens, try up to 5 times to pick a // random name (or slug) to avoid the conflict. - $message = item::save_with_retries($source); - - // If the target has no cover item, make this it. - if ($target->album_cover_item_id == null) { - item::make_album_cover($source); - } - - return $message; - } - - static function save_with_retries($source, $retries=5) { $orig_name = $source->name; $orig_name_filename = pathinfo($source->name, PATHINFO_FILENAME); $orig_name_extension = pathinfo($source->name, PATHINFO_EXTENSION); @@ -102,6 +91,12 @@ class item_Core { } } } + + // If the target has no cover item, make this it. + if ($target->album_cover_item_id == null) { + item::make_album_cover($source); + } + return $message; } diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 74fab2e7..692d0895 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -112,6 +112,8 @@ class item_rest_Core { } break; + case "parent": + break; default: if (property_exists($entity, $key)) { $item->$key = $entity->$key; @@ -124,7 +126,7 @@ class item_rest_Core { $parent = rest::resolve($entity->parent); item::move($item, $parent); } else { - $item::save_with_retries($item); + $item->save(); } } @@ -155,7 +157,7 @@ class item_rest_Core { $item->title = isset($entity->title) ? $entity->title : $entity->name; $item->description = isset($entity->description) ? $entity->description : null; $item->slug = isset($entity->slug) ? $entity->slug : null; - $item::save_with_retries($item); + $item->save(); break; case "photo": @@ -170,7 +172,7 @@ class item_rest_Core { $item->title = isset($entity->title) ? $entity->title : $entity->name; $item->description = isset($entity->description) ? $entity->description : null; $item->slug = isset($entity->slug) ? $entity->slug : null; - $item::save_with_retries($item); + $item->save(); break; default: -- cgit v1.2.3 From a432a43b3b39fbec70d4cece1eb0ba5625b2679c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 Jun 2010 17:18:22 -0700 Subject: Revert "Change the item rest update processing to call the item::move(source, target) helper when the parent member has changed. Using the move method insures that names and slugs that could conflict in the target album are resolved properly. Changed the item::move method so it returns a message to be displayed if the caller chooses. And changed the move controller to display the message returned by the move if the item name was renamed as part of the move." Rolling this back for a couple of reasons: 1) Bug in move.php ("message.info" is not a function name) 2) Having the message come back from the API call as a side-effect is sloppy. We should find a cleaner way to do this checking. 3) having item::move() call save() on any changed values in the ORM is counter-intuitive. Move should move, save should save. I think the right approach here is to roll the move() code properly into save(). This reverts commit 2492280cc0ec9eb64a8daeccc7b5698ece7fea66. --- modules/gallery/controllers/move.php | 10 ++++++---- modules/gallery/helpers/item.php | 15 ++++++--------- modules/gallery/helpers/item_rest.php | 16 +++++++--------- 3 files changed, 19 insertions(+), 22 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/move.php b/modules/gallery/controllers/move.php index 3ce44546..f8b85b6f 100644 --- a/modules/gallery/controllers/move.php +++ b/modules/gallery/controllers/move.php @@ -34,10 +34,12 @@ class Move_Controller extends Controller { $source = ORM::factory("item", $source_id); $target = ORM::factory("item", Input::instance()->post("target_id")); - $message = item::move($source, $target); - if (!empty($message)) { - message.info($message); - } + access::required("view", $source); + access::required("edit", $source); + access::required("view", $target); + access::required("edit", $target); + + item::move($source, $target); print json_encode( array("result" => "success", diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 6a740de4..15bbe977 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -47,28 +47,27 @@ class item_Core { $orig_name_filename = pathinfo($source->name, PATHINFO_FILENAME); $orig_name_extension = pathinfo($source->name, PATHINFO_EXTENSION); $orig_slug = $source->slug; - $message = ""; for ($i = 0; $i < 5; $i++) { try { $source->save(); if ($orig_name != $source->name) { switch ($source->type) { case "album": - $message = + message::info( t("Album %old_name renamed to %new_name to avoid a conflict", - array("old_name" => $orig_name, "new_name" => $source->name)); + array("old_name" => $orig_name, "new_name" => $source->name))); break; case "photo": - $message = + message::info( t("Photo %old_name renamed to %new_name to avoid a conflict", - array("old_name" => $orig_name, "new_name" => $source->name)); + array("old_name" => $orig_name, "new_name" => $source->name))); break; case "movie": - $message = + message::info( t("Movie %old_name renamed to %new_name to avoid a conflict", - array("old_name" => $orig_name, "new_name" => $source->name)); + array("old_name" => $orig_name, "new_name" => $source->name))); break; } } @@ -96,8 +95,6 @@ class item_Core { if ($target->album_cover_item_id == null) { item::make_album_cover($source); } - - return $message; } static function make_album_cover($item) { diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 692d0895..0839b144 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -99,7 +99,7 @@ class item_rest_Core { if ($entity = $request->params->entity) { // Only change fields from a whitelist. foreach (array("album_cover", "captured", "description", - "height", "mime_type", "name", "rand_key", "resize_dirty", + "height", "mime_type", "name", "parent", "rand_key", "resize_dirty", "resize_height", "resize_width", "slug", "sort_column", "sort_order", "thumb_dirty", "thumb_height", "thumb_width", "title", "view_count", "width") as $key) { @@ -113,6 +113,11 @@ class item_rest_Core { break; case "parent": + if (property_exists($entity, "parent")) { + $parent = rest::resolve($entity->parent); + access::required("edit", $parent); + $item->parent_id = $parent->id; + } break; default: if (property_exists($entity, $key)) { @@ -120,15 +125,8 @@ class item_rest_Core { } } } - - // There is an explicit save in item::move - if (property_exists($entity, "parent")) { - $parent = rest::resolve($entity->parent); - item::move($item, $parent); - } else { - $item->save(); - } } + $item->save(); if (isset($request->params->members) && $item->sort_column == "weight") { $weight = 0; -- cgit v1.2.3 From e3535349abb6e955a75d97f57971f4ea4913da6f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 15 Jun 2010 20:25:35 -0700 Subject: Revert "Add a "convert_ids" parameter to Item_Model::as_restful_array(), which" This reverts commit 98fce83de5f772482382bfabdbcd94c25ecdbb1a. Conflicts: modules/gallery/tests/Item_Model_Test.php --- modules/gallery/models/item.php | 20 ++++++++------------ modules/gallery/tests/Item_Model_Test.php | 12 ------------ 2 files changed, 8 insertions(+), 24 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 009457c1..e42430bf 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -924,21 +924,17 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. */ - public function as_restful_array($convert_ids=true) { + public function as_restful_array() { // Convert item ids to rest URLs for consistency $data = $this->as_array(); - - if ($convert_ids) { - if ($tmp = $this->parent()) { - $data["parent"] = rest::url("item", $tmp); - } - unset($data["parent_id"]); - - if ($tmp = $this->album_cover()) { - $data["album_cover"] = rest::url("item", $tmp); - } - unset($data["album_cover_item_id"]); + if ($tmp = $this->parent()) { + $data["parent"] = rest::url("item", $tmp); + } + unset($data["parent_id"]); + if ($tmp = $this->album_cover()) { + $data["album_cover"] = rest::url("item", $tmp); } + unset($data["album_cover_item_id"]); if (access::can("view_full", $this) && $this->is_photo()) { $data["file_url"] = $this->file_url(true); diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index f9e6a4e3..907cfe24 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -368,18 +368,6 @@ class Item_Model_Test extends Gallery_Unit_Test_Case { $this->assert_true(!array_key_exists("album_cover_item_id", $result)); } - public function as_restful_array_with_ids_test() { - $album = test::random_album(); - $photo = test::random_photo($album); - $album->reload(); - - $result = $album->as_restful_array(false); - $this->assert_same(item::root()->id, $result["parent_id"]); - $this->assert_same($photo->id, $result["album_cover_item_id"]); - $this->assert_true(!array_key_exists("parent", $result)); - $this->assert_true(!array_key_exists("album_cover_item", $result)); - } - public function as_restful_array_with_edit_bit_test() { $response = item::root()->as_restful_array(true); $this->assert_true($response["can_edit"]); -- cgit v1.2.3 From 1fb33393269d3a1d32048898545c5ef812383f2e Mon Sep 17 00:00:00 2001 From: Jan Koprowski Date: Wed, 16 Jun 2010 14:29:28 +0800 Subject: Fix issue1068. Fill from_id field in photo with indetificator --- modules/gallery/helpers/photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index f20d37a3..73cd60c0 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -26,7 +26,7 @@ class photo_Core { static function get_edit_form($photo) { $form = new Forge("photos/update/$photo->id", "", "post", array("id" => "g-edit-photo-form")); - $form->hidden("from_id"); + $form->hidden("from_id")->value($photo->id); $group = $form->group("edit_item")->label(t("Edit Photo")); $group->input("title")->label(t("Title"))->value($photo->title) ->error_messages("required", t("You must provide a title")) -- cgit v1.2.3 From 38d09c5d1adae211d61b16d82448b616318b951e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 17 Jun 2010 08:03:08 -0700 Subject: Scale a movie to the resize size so that it doesn't overflow into the sidebar. --- modules/gallery/models/item.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index e42430bf..5e8a2d09 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -671,8 +671,21 @@ class Item_Model extends ORM_MPTT { */ public function movie_img($extra_attrs) { $v = new View("movieplayer.html"); + $max_size = module::get_var("gallery", "resize_size", 640); + $width = $this->width; + $height = $this->height; + if ($width > $max_size || $height > $max_size) { + if ($width > $height) { + $height *= $max_size / $width; + $width = $max_size; + } else { + $width *= $max_size / $height; + $height = $max_size; + } + } + $v->attrs = array_merge($extra_attrs, - array("style" => "display:block;width:{$this->width}px;height:{$this->height}px")); + array("style" => "display:block;width:{$width}px;height:{$height}px")); if (empty($v->attrs["id"])) { $v->attrs["id"] = "g-item-id-{$this->id}"; } -- cgit v1.2.3 From 2bbce8dddb0ab0a00aee727e2f639b793988a1d1 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 17 Jun 2010 09:10:01 -0700 Subject: Fix for ticket #1117 align videos to the center. --- modules/gallery/models/item.php | 4 ++-- themes/wind/css/screen.css | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 5e8a2d09..4d05e4da 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -684,8 +684,8 @@ class Item_Model extends ORM_MPTT { } } - $v->attrs = array_merge($extra_attrs, - array("style" => "display:block;width:{$width}px;height:{$height}px")); + $v->attrs = array_merge($extra_attrs, array("style" => "width:{$width}px;height:{$height}px", + "class" => "g-movie")); if (empty($v->attrs["id"])) { $v->attrs["id"] = "g-item-id-{$this->id}"; } diff --git a/themes/wind/css/screen.css b/themes/wind/css/screen.css index f8e26073..1e55a967 100644 --- a/themes/wind/css/screen.css +++ b/themes/wind/css/screen.css @@ -302,7 +302,7 @@ td { } #g-item img.g-resize, -#g-item a.g-movie object { +#g-item a.g-movie { display: block; margin: 0 auto; } -- cgit v1.2.3 From a03e3d1dc1b59e45e5b0dbf4cf23eed91d545c25 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 17 Jun 2010 09:38:36 -0700 Subject: Fix for ticket #1110. Need to use the encode_path with a movie extension to find the item. Thanks to samdavidoff for the initial fix. --- modules/gallery/controllers/file_proxy.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php index fff90ec5..32690fc0 100644 --- a/modules/gallery/controllers/file_proxy.php +++ b/modules/gallery/controllers/file_proxy.php @@ -60,12 +60,12 @@ class File_Proxy_Controller extends Controller { foreach (explode("/", $path) as $path_part) { $encoded_path[] = rawurlencode($path_part); } - + $encoded_path = implode("/", $encoded_path); // We now have the relative path to the item. Search for it in the path cache // The patch cache is urlencoded so re-encode the path. (it was decoded earlier to // insure that the paths are normalized. $item = ORM::factory("item") - ->where("relative_path_cache", "=", implode("/", $encoded_path))->find(); + ->where("relative_path_cache", "=", $encoded_path)->find(); if (!$item->loaded()) { // We didn't turn it up. It's possible that the relative_path_cache is out of date here. // There was fallback code, but bharat deleted it in 8f1bca74. If it turns out to be @@ -76,7 +76,7 @@ class File_Proxy_Controller extends Controller { // So try some alternate types: if (preg_match('/.jpg$/', $path)) { foreach (array("flv", "mp4") as $ext) { - $movie_path = preg_replace('/.jpg$/', ".$ext", $path); + $movie_path = preg_replace('/.jpg$/', ".$ext", $encoded_path); $item = ORM::factory("item")->where("relative_path_cache", "=", $movie_path)->find(); if ($item->loaded()) { break; -- cgit v1.2.3 From e82aa6dcd80ce0c41a04e3331b0a63e25c25216f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 17 Jun 2010 10:22:19 -0700 Subject: Update the xss gold file with changes to views in the last couple of commits. --- modules/gallery/tests/xss_data.txt | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 68dca9cb..7fce42a1 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -235,27 +235,16 @@ modules/notification/views/item_updated.html.php 20 DIRTY_JS $item- modules/notification/views/item_updated.html.php 20 DIRTY $item->abs_url() modules/notification/views/user_profile_notification.html.php 5 DIRTY_ATTR $subscription->id modules/notification/views/user_profile_notification.html.php 6 DIRTY_JS $subscription->url -modules/organize/views/organize_dialog.html.php 3 DIRTY_JS url::site("organize/move_to/__ALBUM_ID__?csrf=$csrf") -modules/organize/views/organize_dialog.html.php 4 DIRTY_JS url::site("organize/rearrange/__TARGET_ID__/__BEFORE__?csrf=$csrf") -modules/organize/views/organize_dialog.html.php 5 DIRTY_JS url::site("organize/sort_order/__ALBUM_ID__/__COL__/__DIR__?csrf=$csrf") -modules/organize/views/organize_dialog.html.php 6 DIRTY_JS url::site("organize/tree/__ALBUM_ID__") -modules/organize/views/organize_dialog.html.php 14 DIRTY $album_tree -modules/organize/views/organize_dialog.html.php 23 DIRTY $micro_thumb_grid -modules/organize/views/organize_dialog.html.php 32 DIRTY form::dropdown(array("id"=>"g-organize-sort-column"),album::get_sort_order_options(),$album->sort_column) -modules/organize/views/organize_thumb_grid.html.php 3 DIRTY_ATTR $child->is_album()?"g-album":"g-photo" -modules/organize/views/organize_thumb_grid.html.php 4 DIRTY_ATTR $child->id -modules/organize/views/organize_thumb_grid.html.php 5 DIRTY $child->thumb_img(array("class"=>"g-thumbnail","ref"=>$child->id),90,true) -modules/organize/views/organize_thumb_grid.html.php 6 DIRTY $child->is_album()?" class=\"ui-icon ui-icon-note\"":"" -modules/organize/views/organize_thumb_grid.html.php 13 DIRTY_JS url::site("organize/album/$album->id/".($offset+25)) -modules/organize/views/organize_tree.html.php 2 DIRTY_ATTR access::can("edit",$album)?"":"g-view-only" -modules/organize/views/organize_tree.html.php 3 DIRTY_ATTR $album->id -modules/organize/views/organize_tree.html.php 6 DIRTY_ATTR $selected&&$album->id==$selected->id?"ui-state-focus":"" -modules/organize/views/organize_tree.html.php 7 DIRTY_ATTR $album->id -modules/organize/views/organize_tree.html.php 15 DIRTY View::factory("organize_tree.html",array("selected"=>$selected,"album"=>$child)); -modules/organize/views/organize_tree.html.php 17 DIRTY_ATTR access::can("edit",$child)?"":"g-view-only" -modules/organize/views/organize_tree.html.php 18 DIRTY_ATTR $child->id -modules/organize/views/organize_tree.html.php 20 DIRTY_ATTR $selected&&$child->id==$selected->id?"ui-state-focus":"" -modules/organize/views/organize_tree.html.php 20 DIRTY_ATTR $child->id +modules/organize/views/organize_dialog.html.php 92 DIRTY_JS $domain +modules/organize/views/organize_dialog.html.php 93 DIRTY_JS $access_key +modules/organize/views/organize_dialog.html.php 94 DIRTY_JS $protocol +modules/organize/views/organize_dialog.html.php 95 DIRTY_JS $file_filter +modules/organize/views/organize_dialog.html.php 96 DIRTY_JS $sort_order +modules/organize/views/organize_dialog.html.php 97 DIRTY_JS $sort_fields +modules/organize/views/organize_dialog.html.php 98 DIRTY_JS $album->id +modules/organize/views/organize_dialog.html.php 99 DIRTY_JS $rest_uri +modules/organize/views/organize_dialog.html.php 100 DIRTY_JS $controller_uri +modules/organize/views/organize_dialog.html.php 124 DIRTY_JS $swf_url modules/recaptcha/views/admin_recaptcha.html.php 11 DIRTY $form modules/recaptcha/views/admin_recaptcha.html.php 23 DIRTY_JS $public_key modules/recaptcha/views/form_recaptcha.html.php 7 DIRTY_JS $public_key @@ -363,7 +352,7 @@ themes/wind/views/dynamic.html.php 16 DIRTY_ATTR $chi themes/wind/views/dynamic.html.php 17 DIRTY_ATTR $child->thumb_height themes/wind/views/dynamic.html.php 29 DIRTY $theme->paginator() themes/wind/views/movie.html.php 5 DIRTY $theme->paginator() -themes/wind/views/movie.html.php 8 DIRTY $item->movie_img(array("class"=>"g-movie","id"=>"g-item-id-{$item->id}")) +themes/wind/views/movie.html.php 9 DIRTY $item->movie_img(array("class"=>"g-movie","id"=>"g-item-id-{$item->id}")) themes/wind/views/page.html.php 9 DIRTY $page_title themes/wind/views/page.html.php 33 DIRTY_JS $theme->url() themes/wind/views/page.html.php 42 DIRTY $new_width -- cgit v1.2.3 From 562fb174a763aef748842aae2903e1c0f77deefd Mon Sep 17 00:00:00 2001 From: mamouneyya Date: Fri, 18 Jun 2010 14:08:08 +0300 Subject: Flip some margin/padding values for RTL --- modules/gallery/css/gallery.css | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/css/gallery.css b/modules/gallery/css/gallery.css index c2fb97e8..e2ad7458 100644 --- a/modules/gallery/css/gallery.css +++ b/modules/gallery/css/gallery.css @@ -197,3 +197,11 @@ .rtl #g-user-profile .g-avatar { margin-left: .6em; } + +.rtl #g-languages-form table { + margin: 0 0 1em 3em; +} + +.rtl #g-translations ol { + margin: 0 2em 1em 0; +} \ No newline at end of file -- cgit v1.2.3 From bc70ff498d73e0f38f749ea6cd28484ca1a05f83 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 18 Jun 2010 15:25:33 -0700 Subject: Use request::protocol() --- modules/gallery/helpers/MY_url.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php index 57ce9623..877c5ada 100644 --- a/modules/gallery/helpers/MY_url.php +++ b/modules/gallery/helpers/MY_url.php @@ -70,8 +70,7 @@ class url extends url_Core { * Just like url::file() except that it returns an absolute URI */ static function abs_file($path) { - return url::base( - false, (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? 'http' : 'https') . $path; + return url::base(false, request::protocol()) . $path; } /** @@ -79,8 +78,7 @@ class url extends url_Core { * doesn't take a protocol parameter. */ static function abs_site($path) { - return url::site( - $path, (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? 'http' : 'https'); + return url::site($path, request::protocol()); } /** -- cgit v1.2.3 From 5736698b4ba17e382468ed9fdfed4b46e37f763e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 19 Jun 2010 10:51:05 -0700 Subject: single -> double quotes. --- modules/gallery/libraries/MY_Kohana_Exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php index df7557ae..11556f7a 100644 --- a/modules/gallery/libraries/MY_Kohana_Exception.php +++ b/modules/gallery/libraries/MY_Kohana_Exception.php @@ -61,7 +61,7 @@ class Kohana_Exception extends Kohana_Exception_Core { $error = Kohana_Exception::text($e); // Add this exception to the log - Kohana_Log::add('error', $error); + Kohana_Log::add("error", $error); // Manually save logs after exceptions Kohana_Log::save(); -- cgit v1.2.3 From 41ca2b0195bf6a29429dfc5405f3c2073b1c3aba Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 19 Jun 2010 13:52:48 -0700 Subject: Rework our exception framework to fit into Kohana's model better. Instead of overwriting Kohana_Exception::handle() (which we were doing in MY_Kohana_Exception) we instead use their existing template system. gallery/views/kohana/error.php overrides system/views/kohana/error.php and is the standard error template for all exceptions. Our version of error.php figures out the appropriate view based on context (cli, authenticated admin, guest viewing a 404, guest viewing a system error) and delegates appropriately. Each delegated view has a narrow responsibility. This paves the way for us to add new error views per module. For example, the rest module will define its own template in Rest_Exception and then its exceptions can be rendered the way that it wants (json encoded, in that case). --- modules/gallery/helpers/item_rest.php | 24 +- modules/gallery/libraries/MY_Kohana_Exception.php | 62 ----- modules/gallery/views/error_admin.html.php | 272 ++++++++++++++++++ modules/gallery/views/error_cli.txt.php | 3 + modules/gallery/views/error_user.html.php | 42 +++ modules/gallery/views/kohana/error.php | 321 +++------------------- 6 files changed, 372 insertions(+), 352 deletions(-) create mode 100644 modules/gallery/views/error_admin.html.php create mode 100644 modules/gallery/views/error_cli.txt.php create mode 100644 modules/gallery/views/error_user.html.php (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 0839b144..6869181d 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -161,20 +161,22 @@ class item_rest_Core { case "photo": case "movie": if (empty($request->file)) { - throw new Rest_Exception("file: Upload failed", 400); + throw new Rest_Exception( + "Bad Request", 400, array("errors" => array("file" => t("Upload failed")))); } - $item->type = $entity->type; - $item->parent_id = $parent->id; - $item->set_data_file($request->file); - $item->name = $entity->name; - $item->title = isset($entity->title) ? $entity->title : $entity->name; - $item->description = isset($entity->description) ? $entity->description : null; - $item->slug = isset($entity->slug) ? $entity->slug : null; - $item->save(); - break; + $item->type = $entity->type; + $item->parent_id = $parent->id; + $item->set_data_file($request->file); + $item->name = $entity->name; + $item->title = isset($entity->title) ? $entity->title : $entity->name; + $item->description = isset($entity->description) ? $entity->description : null; + $item->slug = isset($entity->slug) ? $entity->slug : null; + $item->save(); + break; default: - throw new Rest_Exception("Invalid type: $entity->type", 400); + throw new Rest_Exception( + "Bad Request", 400, array("errors" => array("type" => "invalid"))); } return array("url" => rest::url("item", $item)); diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php index 11556f7a..72cb2ac0 100644 --- a/modules/gallery/libraries/MY_Kohana_Exception.php +++ b/modules/gallery/libraries/MY_Kohana_Exception.php @@ -29,68 +29,6 @@ class Kohana_Exception extends Kohana_Exception_Core { $e->getTraceAsString()); } - public static function handle(Exception $e) { - if ($e instanceof ORM_Validation_Exception) { - Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1)); - } - try { - $user = identity::active_user(); - $try_themed_view = $user && !$user->admin; - } catch (Exception $e2) { - $try_themed_view = false; - } - - if ($try_themed_view) { - try { - return self::_show_themed_error_page($e); - } catch (Exception $e3) { - Kohana_Log::add("error", "Exception in exception handling code: " . self::text($e3)); - return parent::handle($e); - } - } else { - return parent::handle($e); - } - } - - /** - * Shows a themed error page. - * @see Kohana_Exception::handle - */ - private static function _show_themed_error_page(Exception $e) { - // Create a text version of the exception - $error = Kohana_Exception::text($e); - - // Add this exception to the log - Kohana_Log::add("error", $error); - - // Manually save logs after exceptions - Kohana_Log::save(); - - if (!headers_sent()) { - if ($e instanceof Kohana_Exception) { - $e->sendHeaders(); - } else { - header("HTTP/1.1 500 Internal Server Error"); - } - } - - $view = new Theme_View("page.html", "other", "error"); - if ($e instanceof Kohana_404_Exception) { - $view->page_title = t("Dang... Page not found!"); - $view->content = new View("error_404.html"); - $user = identity::active_user(); - $view->content->is_guest = $user && $user->guest; - if ($view->content->is_guest) { - $view->content->login_form = new View("login_ajax.html"); - $view->content->login_form->form = auth::get_login_form("login/auth_html"); - } - } else { - $view->page_title = t("Dang... Something went wrong!"); - $view->content = new View("error.html"); - } - print $view; - } - /** * @see Kohana_Exception::dump() */ diff --git a/modules/gallery/views/error_admin.html.php b/modules/gallery/views/error_admin.html.php new file mode 100644 index 00000000..40eb7374 --- /dev/null +++ b/modules/gallery/views/error_admin.html.php @@ -0,0 +1,272 @@ + + + + + + + + <?= t("Something went wrong!") ?> + + + + + +
    +

    + +

    +

    + +

    +
    +
    +

    + +

    +
    +

    + + [ ]: + + + + +

    +
    +
      +
    1. +

      + + [ ] + +

      + +
      + $row): ?>"> + +
      +
    2. + + + $step): ?> +
    3. +

      + + + + [ ] + + [ ] + + + {} + + + » + ( + + ) +

      + +
    + $arg): ?> + + + + + +
    +
    +
    +
    +
    +
    + + + + + + + + + + +
    +

    + " onclick="return koggle('')"> +

    + + + + + diff --git a/modules/gallery/views/error_cli.txt.php b/modules/gallery/views/error_cli.txt.php new file mode 100644 index 00000000..b4f87fa6 --- /dev/null +++ b/modules/gallery/views/error_cli.txt.php @@ -0,0 +1,3 @@ + + + diff --git a/modules/gallery/views/error_user.html.php b/modules/gallery/views/error_user.html.php new file mode 100644 index 00000000..74c6a8fb --- /dev/null +++ b/modules/gallery/views/error_user.html.php @@ -0,0 +1,42 @@ + + + + + + + <?= t("Something went wrong!") ?> + + +
    +

    + +

    +

    + +

    +

    + +

    +
    + + diff --git a/modules/gallery/views/kohana/error.php b/modules/gallery/views/kohana/error.php index d55105a0..b0f0e907 100644 --- a/modules/gallery/views/kohana/error.php +++ b/modules/gallery/views/kohana/error.php @@ -1,280 +1,43 @@ - - - - - - - <?= t("Something went wrong!") ?> - - - - - - admin) ?> -
    -

    - -

    -

    - -

    - -

    - -

    - -
    - -
    -

    - -

    -
    -

    - - [ ]: - - - - -

    -
    -
      -
    1. -

      - - [ ] - -

      - -
      - $row): ?>"> - -
      -
    2. - - - $step): ?> -
    3. -

      - - - - [ ] - - [ ] - - - {} - - - » - ( - - ) -

      - - - - - - -
    4. - - -
    - - -
    -

    - " onclick="return koggle('')"> -

    - -
    -
    - - - +validation->errors(), 1)); +} + +if (php_sapi_name() == "cli") { + include Kohana::find_file("views", "error_cli.txt"); + return; +} + +try { + // Admins get a special error page + $user = identity::active_user(); + if ($user && $user->admin) { + include Kohana::find_file("views", "error_admin.html"); + return; + } +} catch (Exception $ignored) { +} + +// Try to show a themed error page for 404 errors +if ($e instanceof Kohana_404_Exception) { + $view = new Theme_View("page.html", "other", "error"); + $view->page_title = t("Dang... Page not found!"); + $view->content = new View("error_404.html"); + $user = identity::active_user(); + $view->content->is_guest = $user && $user->guest; + if ($view->content->is_guest) { + $view->content->login_form = new View("login_ajax.html"); + $view->content->login_form->form = auth::get_login_form("login/auth_html"); + } + print $view; + return; +} + +header("HTTP/1.1 500 Internal Server Error"); +include Kohana::find_file("views", "error_user.html"); +?> -- cgit v1.2.3 From d86d1a32e8fc0feeaea3fa29a07035e0edfc7b90 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 19 Jun 2010 15:12:58 -0700 Subject: Updated for comment REST relationships. --- modules/gallery/tests/Item_Rest_Helper_Test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php index 0b5e0471..a2ab534b 100644 --- a/modules/gallery/tests/Item_Rest_Helper_Test.php +++ b/modules/gallery/tests/Item_Rest_Helper_Test.php @@ -43,6 +43,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album1)), "tags" => array( "url" => rest::url("item_tags", $album1), "members" => array())), @@ -58,6 +60,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album1)), "tags" => array( "url" => rest::url("item_tags", $album1), "members" => array())), @@ -73,6 +77,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album1)), "tags" => array( "url" => rest::url("item_tags", $album1), "members" => array())), @@ -100,6 +106,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album1)), "tags" => array( "url" => rest::url("item_tags", $album1), "members" => array())), @@ -123,6 +131,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album1)), "tags" => array( "url" => rest::url("item_tags", $album1), "members" => array())), -- cgit v1.2.3 From 719328a5a7c0086fb97f0dd6b54d5db839696d33 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 09:02:59 -0700 Subject: If we use on the last line, it looks like we've got a trailing ?> and that causes File_Structure_Test to be sad. So instead use echo and tack on our own newline. But this also requires a semicolon. Weird, I know but still easier than fixing up the test. --- modules/gallery/views/error_cli.txt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/views/error_cli.txt.php b/modules/gallery/views/error_cli.txt.php index b4f87fa6..9f476f54 100644 --- a/modules/gallery/views/error_cli.txt.php +++ b/modules/gallery/views/error_cli.txt.php @@ -1,3 +1,3 @@ - + Date: Sun, 20 Jun 2010 09:03:23 -0700 Subject: Add "json" as a valid view suffix. --- modules/gallery/tests/File_Structure_Test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/File_Structure_Test.php b/modules/gallery/tests/File_Structure_Test.php index 39df9f06..1c3356d9 100644 --- a/modules/gallery/tests/File_Structure_Test.php +++ b/modules/gallery/tests/File_Structure_Test.php @@ -42,8 +42,8 @@ class File_Structure_Test extends Gallery_Unit_Test_Case { if (strpos($file, "views")) { $this->assert_true( - preg_match("#/views/.*?(\.html|mrss|txt)\.php$#", $file->getPathname()), - "{$file->getPathname()} should end in .{html,mrss,txt}.php"); + preg_match("#/views/.*?\.(html|mrss|txt|json)\.php$#", $file->getPathname()), + "{$file->getPathname()} should end in .{html,mrss,txt,json}.php"); } } } -- cgit v1.2.3 From ab9049d5313d589cee696d0e082ac4f20c830cf1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 09:05:25 -0700 Subject: Remove trailing ?> --- modules/gallery/views/kohana/error.php | 1 - modules/rest/views/error_rest.json.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/views/kohana/error.php b/modules/gallery/views/kohana/error.php index b0f0e907..cc9d2e84 100644 --- a/modules/gallery/views/kohana/error.php +++ b/modules/gallery/views/kohana/error.php @@ -40,4 +40,3 @@ if ($e instanceof Kohana_404_Exception) { header("HTTP/1.1 500 Internal Server Error"); include Kohana::find_file("views", "error_user.html"); -?> diff --git a/modules/rest/views/error_rest.json.php b/modules/rest/views/error_rest.json.php index c018378e..179ce7f9 100644 --- a/modules/rest/views/error_rest.json.php +++ b/modules/rest/views/error_rest.json.php @@ -1,2 +1,2 @@ -response) ?> \ No newline at end of file +response); \ No newline at end of file -- cgit v1.2.3 From 9f9d3866e86d4b50fc1315c7db2687a5f0b8ce8d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 09:28:36 -0700 Subject: Exclude the .git directory. --- modules/gallery/tests/Gallery_Filters.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/Gallery_Filters.php b/modules/gallery/tests/Gallery_Filters.php index debbe846..052990d5 100644 --- a/modules/gallery/tests/Gallery_Filters.php +++ b/modules/gallery/tests/Gallery_Filters.php @@ -32,6 +32,7 @@ class GalleryCodeFilterIterator extends FilterIterator { return !( $file_name == "." || $file_name == ".." || + strpos($path_name, DOCROOT . ".git") !== false || strpos($path_name, DOCROOT . "test") !== false || strpos($path_name, DOCROOT . "var") !== false || strpos($path_name, MODPATH . "forge") !== false || -- cgit v1.2.3 From ec052d71301acbf519947897f8adda7fdcf7fefb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 09:36:56 -0700 Subject: Assert how many files we analyze so that we can tell if we're suddenly analzying too many or too few. --- modules/gallery/tests/File_Structure_Test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/File_Structure_Test.php b/modules/gallery/tests/File_Structure_Test.php index 1c3356d9..96e0b758 100644 --- a/modules/gallery/tests/File_Structure_Test.php +++ b/modules/gallery/tests/File_Structure_Test.php @@ -23,13 +23,18 @@ class File_Structure_Test extends Gallery_Unit_Test_Case { public function no_trailing_closing_php_tag_test() { $dir = new GalleryCodeFilterIterator( new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DOCROOT))); + $count = 0; foreach ($dir as $file) { + $count++; if (!preg_match("|\.html\.php$|", $file->getPathname())) { $this->assert_false( preg_match('/\?\>\s*$/', file_get_contents($file)), "{$file->getPathname()} ends in ?>"); } } + + $this->assert_true($count > 500, "We should have analyzed at least this 500 files"); + $this->assert_true($count < 1000, "We shouldn't be shipping 1000 files!"); } public function view_files_correct_suffix_test() { -- cgit v1.2.3 From 2e016855532962ea3e03700879be70f1ad3a8911 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 09:40:35 -0700 Subject: Add "comments" relationship support. --- modules/gallery/tests/Items_Rest_Helper_Test.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/Items_Rest_Helper_Test.php b/modules/gallery/tests/Items_Rest_Helper_Test.php index 17e979a5..8e53110a 100644 --- a/modules/gallery/tests/Items_Rest_Helper_Test.php +++ b/modules/gallery/tests/Items_Rest_Helper_Test.php @@ -36,12 +36,16 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $photo1), "entity" => $photo1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $photo1)), "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), "entity" => $album2->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album2)), "tags" => array( "url" => rest::url("item_tags", $album2), "members" => array())), @@ -69,6 +73,8 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album2), "entity" => $album2->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album2)), "tags" => array( "url" => rest::url("item_tags", $album2), "members" => array())), @@ -96,6 +102,8 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $photo1), "entity" => $photo1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $photo1)), "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array())))), @@ -121,12 +129,16 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $photo1), "entity" => $photo1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $photo1)), "tags" => array( "url" => rest::url("item_tags", $photo1), "members" => array()))), array("url" => rest::url("item", $album2), "entity" => $album2->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album2)), "tags" => array( "url" => rest::url("item_tags", $album2), "members" => array())), @@ -162,6 +174,8 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album1), "entity" => $album1->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album1)), "tags" => array( "url" => rest::url("item_tags", $album1), "members" => array())), @@ -172,6 +186,8 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $album2), "entity" => $album2->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $album2)), "tags" => array( "url" => rest::url("item_tags", $album2), "members" => array())), @@ -180,6 +196,8 @@ class Items_Rest_Helper_Test extends Gallery_Unit_Test_Case { array("url" => rest::url("item", $photo2), "entity" => $photo2->as_restful_array(), "relationships" => array( + "comments" => array( + "url" => rest::url("item_comments", $photo2)), "tags" => array( "url" => rest::url("item_tags", $photo2), "members" => array())))), -- cgit v1.2.3 From 6ebbb4fbf5cc5559f433300871078be41d615cf6 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 09:51:39 -0700 Subject: Updated golden files. --- modules/gallery/tests/controller_auth_data.txt | 2 + modules/gallery/tests/xss_data.txt | 82 ++++++++++++++++++++------ 2 files changed, 65 insertions(+), 19 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 94e7a07f..8263f79d 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -23,6 +23,8 @@ modules/gallery/controllers/user_profile.php show modules/gallery/controllers/user_profile.php contact DIRTY_AUTH modules/gallery/controllers/user_profile.php send DIRTY_AUTH modules/gallery/controllers/welcome_message.php index DIRTY_AUTH +modules/organize/controllers/organize.php dialog DIRTY_CSRF +modules/organize/controllers/organize.php add_album_fields DIRTY_AUTH modules/rest/controllers/rest.php index DIRTY_CSRF|DIRTY_AUTH modules/rest/controllers/rest.php __call DIRTY_CSRF|DIRTY_AUTH modules/rss/controllers/rss.php feed DIRTY_CSRF|DIRTY_AUTH diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 7fce42a1..4ead8a3f 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -33,8 +33,8 @@ modules/comment/views/comment.mrss.php 29 DIRTY $child modules/comment/views/comment.mrss.php 34 DIRTY_ATTR $child->thumb_url modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $child->thumb_height modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $child->thumb_width -modules/comment/views/comments.html.php 21 DIRTY_ATTR $comment->id -modules/comment/views/comments.html.php 24 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) +modules/comment/views/comments.html.php 28 DIRTY_ATTR $comment->id +modules/comment/views/comments.html.php 31 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) modules/comment/views/user_profile_comments.html.php 5 DIRTY_ATTR $comment->id modules/comment/views/user_profile_comments.html.php 10 DIRTY_JS $comment->item()->url() modules/comment/views/user_profile_comments.html.php 11 DIRTY $comment->item()->thumb_img(array(),50) @@ -122,6 +122,50 @@ modules/gallery/views/admin_themes.html.php 76 DIRTY $info- modules/gallery/views/admin_themes.html.php 78 DIRTY $info->description modules/gallery/views/admin_themes_preview.html.php 7 DIRTY_ATTR $url modules/gallery/views/error_404.html.php 14 DIRTY $login_form +modules/gallery/views/error_admin.html.php 150 DIRTY $type +modules/gallery/views/error_admin.html.php 150 DIRTY $code +modules/gallery/views/error_admin.html.php 153 DIRTY $message +modules/gallery/views/error_admin.html.php 156 DIRTY_ATTR $error_id +modules/gallery/views/error_admin.html.php 161 DIRTY Kohana_Exception::debug_path($file) +modules/gallery/views/error_admin.html.php 161 DIRTY $line +modules/gallery/views/error_admin.html.php 166 DIRTY_ATTR ($num==$line)?"highlight":"" +modules/gallery/views/error_admin.html.php 166 DIRTY $num +modules/gallery/views/error_admin.html.php 166 DIRTY htmlspecialchars($row,ENT_NOQUOTES,Kohana::CHARSET) +modules/gallery/views/error_admin.html.php 178 DIRTY_ATTR $source_id +modules/gallery/views/error_admin.html.php 178 DIRTY_JS $source_id +modules/gallery/views/error_admin.html.php 178 DIRTY Kohana_Exception::debug_path($step["file"]) +modules/gallery/views/error_admin.html.php 178 DIRTY $step["line"] +modules/gallery/views/error_admin.html.php 180 DIRTY Kohana_Exception::debug_path($step["file"]) +modules/gallery/views/error_admin.html.php 180 DIRTY $step["line"] +modules/gallery/views/error_admin.html.php 187 DIRTY $step["function"] +modules/gallery/views/error_admin.html.php 188 DIRTY_ATTR $args_id +modules/gallery/views/error_admin.html.php 188 DIRTY_JS $args_id +modules/gallery/views/error_admin.html.php 192 DIRTY_ATTR $args_id +modules/gallery/views/error_admin.html.php 197 DIRTY $name +modules/gallery/views/error_admin.html.php 200 DIRTY Kohana_Exception::safe_dump($arg,$name) +modules/gallery/views/error_admin.html.php 208 DIRTY_ATTR $source_id +modules/gallery/views/error_admin.html.php 208 DIRTY_ATTR ($num==$step["line"])?"highlight":"" +modules/gallery/views/error_admin.html.php 208 DIRTY $num +modules/gallery/views/error_admin.html.php 208 DIRTY htmlspecialchars($row,ENT_NOQUOTES,Kohana::CHARSET) +modules/gallery/views/error_admin.html.php 218 DIRTY_ATTR $env_id=$error_id."environment" +modules/gallery/views/error_admin.html.php 218 DIRTY_JS $env_id +modules/gallery/views/error_admin.html.php 220 DIRTY_ATTR $env_id +modules/gallery/views/error_admin.html.php 222 DIRTY_ATTR $env_id=$error_id."environment_included" +modules/gallery/views/error_admin.html.php 222 DIRTY_JS $env_id +modules/gallery/views/error_admin.html.php 222 DIRTY count($included) +modules/gallery/views/error_admin.html.php 223 DIRTY_ATTR $env_id +modules/gallery/views/error_admin.html.php 228 DIRTY Kohana_Exception::debug_path($file) +modules/gallery/views/error_admin.html.php 235 DIRTY_ATTR $env_id=$error_id."environment_loaded" +modules/gallery/views/error_admin.html.php 235 DIRTY_JS $env_id +modules/gallery/views/error_admin.html.php 235 DIRTY count($included) +modules/gallery/views/error_admin.html.php 236 DIRTY_ATTR $env_id +modules/gallery/views/error_admin.html.php 241 DIRTY Kohana_Exception::debug_path($file) +modules/gallery/views/error_admin.html.php 249 DIRTY_ATTR $env_id="$error_id.environment".strtolower($var) +modules/gallery/views/error_admin.html.php 250 DIRTY_JS $env_id +modules/gallery/views/error_admin.html.php 250 DIRTY $var +modules/gallery/views/error_admin.html.php 251 DIRTY_ATTR $env_id +modules/gallery/views/error_admin.html.php 257 DIRTY $key +modules/gallery/views/error_admin.html.php 261 DIRTY Kohana_Exception::safe_dump($value,$key) modules/gallery/views/form_uploadify.html.php 9 DIRTY_JS url::file("lib/uploadify/uploadify.swf") modules/gallery/views/form_uploadify.html.php 10 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") modules/gallery/views/form_uploadify.html.php 14 DIRTY_JS url::file("lib/uploadify/cancel.png") @@ -235,16 +279,16 @@ modules/notification/views/item_updated.html.php 20 DIRTY_JS $item- modules/notification/views/item_updated.html.php 20 DIRTY $item->abs_url() modules/notification/views/user_profile_notification.html.php 5 DIRTY_ATTR $subscription->id modules/notification/views/user_profile_notification.html.php 6 DIRTY_JS $subscription->url -modules/organize/views/organize_dialog.html.php 92 DIRTY_JS $domain -modules/organize/views/organize_dialog.html.php 93 DIRTY_JS $access_key -modules/organize/views/organize_dialog.html.php 94 DIRTY_JS $protocol -modules/organize/views/organize_dialog.html.php 95 DIRTY_JS $file_filter -modules/organize/views/organize_dialog.html.php 96 DIRTY_JS $sort_order -modules/organize/views/organize_dialog.html.php 97 DIRTY_JS $sort_fields -modules/organize/views/organize_dialog.html.php 98 DIRTY_JS $album->id -modules/organize/views/organize_dialog.html.php 99 DIRTY_JS $rest_uri -modules/organize/views/organize_dialog.html.php 100 DIRTY_JS $controller_uri -modules/organize/views/organize_dialog.html.php 124 DIRTY_JS $swf_url +modules/organize/views/organize_dialog.html.php 90 DIRTY_JS $domain +modules/organize/views/organize_dialog.html.php 91 DIRTY_JS $access_key +modules/organize/views/organize_dialog.html.php 92 DIRTY_JS request::protocol() +modules/organize/views/organize_dialog.html.php 93 DIRTY_JS $file_filter +modules/organize/views/organize_dialog.html.php 94 DIRTY_JS $sort_order +modules/organize/views/organize_dialog.html.php 95 DIRTY_JS $sort_fields +modules/organize/views/organize_dialog.html.php 96 DIRTY_JS $album->id +modules/organize/views/organize_dialog.html.php 97 DIRTY_JS $rest_uri +modules/organize/views/organize_dialog.html.php 98 DIRTY_JS $controller_uri +modules/organize/views/organize_dialog.html.php 122 DIRTY_JS $swf_uri modules/recaptcha/views/admin_recaptcha.html.php 11 DIRTY $form modules/recaptcha/views/admin_recaptcha.html.php 23 DIRTY_JS $public_key modules/recaptcha/views/form_recaptcha.html.php 7 DIRTY_JS $public_key @@ -316,13 +360,13 @@ themes/admin_wind/views/admin.html.php 43 DIRTY $theme themes/admin_wind/views/admin.html.php 51 DIRTY $theme->admin_header_top() themes/admin_wind/views/admin.html.php 52 DIRTY_JS item::root()->url() themes/admin_wind/views/admin.html.php 55 DIRTY $theme->user_menu() -themes/admin_wind/views/admin.html.php 57 DIRTY $theme->admin_menu() -themes/admin_wind/views/admin.html.php 59 DIRTY $theme->admin_header_bottom() -themes/admin_wind/views/admin.html.php 66 DIRTY $content -themes/admin_wind/views/admin.html.php 72 DIRTY $sidebar -themes/admin_wind/views/admin.html.php 77 DIRTY $theme->admin_footer() -themes/admin_wind/views/admin.html.php 79 DIRTY $theme->admin_credits() -themes/admin_wind/views/admin.html.php 83 DIRTY $theme->admin_page_bottom() +themes/admin_wind/views/admin.html.php 58 DIRTY $theme->admin_menu() +themes/admin_wind/views/admin.html.php 61 DIRTY $theme->admin_header_bottom() +themes/admin_wind/views/admin.html.php 68 DIRTY $content +themes/admin_wind/views/admin.html.php 74 DIRTY $sidebar +themes/admin_wind/views/admin.html.php 79 DIRTY $theme->admin_footer() +themes/admin_wind/views/admin.html.php 81 DIRTY $theme->admin_credits() +themes/admin_wind/views/admin.html.php 85 DIRTY $theme->admin_page_bottom() themes/admin_wind/views/block.html.php 3 DIRTY_ATTR $anchor themes/admin_wind/views/block.html.php 5 DIRTY $id themes/admin_wind/views/block.html.php 5 DIRTY_ATTR $css_id -- cgit v1.2.3 From 892727830d873a9f0a1a49f10ee14b0890088b23 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 16:52:10 -0700 Subject: Add a loading indicator to the delete form by tagging some JS on at the end which triggers .gallery_show_loading(). Not a complete fix for #817 but it's a start and it takes care of one place where we have a long running process. --- modules/gallery/helpers/item.php | 2 ++ modules/gallery/js/item_form_delete.js | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 modules/gallery/js/item_form_delete.js (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php index 15bbe977..aef68c6e 100644 --- a/modules/gallery/helpers/item.php +++ b/modules/gallery/helpers/item.php @@ -162,6 +162,8 @@ class item_Core { "quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "g-confirm-delete")); $group = $form->group("confirm_delete")->label(t("Confirm Deletion")); $group->submit("")->value(t("Delete")); + $form->script("") + ->url(url::abs_file("modules/gallery/js/item_form_delete.js")); return $form; } diff --git a/modules/gallery/js/item_form_delete.js b/modules/gallery/js/item_form_delete.js new file mode 100644 index 00000000..fa3f24a2 --- /dev/null +++ b/modules/gallery/js/item_form_delete.js @@ -0,0 +1,5 @@ +$("#g-confirm-delete").submit( + function() { + $("#g-confirm-delete input[type=submit]").gallery_show_loading(); + } +); -- cgit v1.2.3 From 7bdb9a49e5b038b21445d77c21f63b18619f8fb8 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 16:58:38 -0700 Subject: Focus on the username field by default. --- modules/gallery/views/error_404.html.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/views/error_404.html.php b/modules/gallery/views/error_404.html.php index 4b037a79..42f62b6c 100644 --- a/modules/gallery/views/error_404.html.php +++ b/modules/gallery/views/error_404.html.php @@ -12,10 +12,15 @@

    +

    - \ No newline at end of file + -- cgit v1.2.3 From 261da7b1c362fe329fe97ca8478a0c6b3721dedf Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 17:18:11 -0700 Subject: Set the focus on the username field (and the name field when we reset the password) properly on IE7 using a setTimeout() hack. Fixes ticket #807. --- modules/gallery/views/login_ajax.html.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/views/login_ajax.html.php b/modules/gallery/views/login_ajax.html.php index 36647f9d..88fe2389 100644 --- a/modules/gallery/views/login_ajax.html.php +++ b/modules/gallery/views/login_ajax.html.php @@ -10,9 +10,16 @@ $(".submit").addClass("g-button ui-state-default ui-corner-all"); $(".submit").gallery_hover_init(); ajaxify_login_reset_form(); + + // See comment about IE7 below + setTimeout('$("#g-name").focus()', 100); } }); }); + + // Setting the focus here doesn't work on IE7, perhaps because the field is + // not ready yet? So set a timeout and do it the next time we're idle + setTimeout('$("#g-username").focus()', 100); }); function ajaxify_login_reset_form() { -- cgit v1.2.3 From 48af5e6b5039839f93345bef92e1acf7952c50a1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 17:25:23 -0700 Subject: Rename "children" to "items" in our feed view because it makes more semantic sense. --- modules/gallery/helpers/gallery_rss.php | 8 ++-- modules/rss/views/feed.mrss.php | 66 ++++++++++++++++----------------- modules/tag/helpers/tag_rss.php | 2 +- 3 files changed, 38 insertions(+), 38 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php index 9c528c0e..bec34912 100644 --- a/modules/gallery/helpers/gallery_rss.php +++ b/modules/gallery/helpers/gallery_rss.php @@ -28,18 +28,18 @@ class gallery_rss_Core { $feed = new stdClass(); switch ($feed_id) { case "latest": - $feed->children = ORM::factory("item") + $feed->items = ORM::factory("item") ->viewable() ->where("type", "<>", "album") ->order_by("created", "DESC") ->find_all($limit, $offset); - $all_children = ORM::factory("item") + $all_items = ORM::factory("item") ->viewable() ->where("type", "<>", "album") ->order_by("created", "DESC"); - $feed->max_pages = ceil($all_children->find_all()->count() / $limit); + $feed->max_pages = ceil($all_items->find_all()->count() / $limit); $feed->title = t("Recent updates"); $feed->description = t("Recent updates"); return $feed; @@ -48,7 +48,7 @@ class gallery_rss_Core { $item = ORM::factory("item", $id); access::required("view", $item); - $feed->children = $item + $feed->items = $item ->viewable() ->descendants($limit, $offset, array(array("type", "=", "photo"))); $feed->max_pages = ceil( diff --git a/modules/rss/views/feed.mrss.php b/modules/rss/views/feed.mrss.php index 0fd8095d..3f0010bb 100644 --- a/modules/rss/views/feed.mrss.php +++ b/modules/rss/views/feed.mrss.php @@ -20,57 +20,57 @@ - children as $child): ?> + items as $item): ?> - <?= html::purify($child->title) ?> - type}s/{$child->id}") ?> - type}s/{$child->id}") ?> - created); ?> - description) ?> + <?= html::purify($item->title) ?> + type}s/{$item->id}") ?> + type}s/{$item->id}") ?> + created); ?> + description) ?> description) ?> + description) ?>

    - type == "photo"): ?> -
    + type == "photo"): ?> +
    - type}s/{$child->id}") ?>"> -
    + type}s/{$item->id}") ?>"> +
    - description) ?> + description) ?>

    ]]>
    - - - type == "photo" && $view_full): ?> + + type == "photo" && $view_full): ?> - type == "photo"): ?> - type == "photo"): ?> + - - type == "photo" && $view_full): ?> + type == "photo" && $view_full): ?>
    diff --git a/modules/tag/helpers/tag_rss.php b/modules/tag/helpers/tag_rss.php index 7d52814b..ea3865be 100644 --- a/modules/tag/helpers/tag_rss.php +++ b/modules/tag/helpers/tag_rss.php @@ -36,7 +36,7 @@ class tag_rss_Core { } $feed = new stdClass(); - $feed->children = $tag->items($limit, $offset, "photo"); + $feed->items = $tag->items($limit, $offset, "photo"); $feed->max_pages = ceil($tag->count / $limit); $feed->title = $tag->name; $feed->description = t("Photos related to %tag_name", array("tag_name" => $tag->name)); -- cgit v1.2.3 From d82863421df3e7c8d500ab32c11c556a50691dbd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 20 Jun 2010 21:10:22 -0700 Subject: Rename "simple_uploader" to "flash_uploader" to make room for an HTML uploader. --- modules/gallery/controllers/flash_uploader.php | 124 ++++++++++++++++++++++++ modules/gallery/controllers/simple_uploader.php | 124 ------------------------ modules/gallery/helpers/gallery_event.php | 4 +- modules/gallery/views/form_uploadify.html.php | 2 +- themes/wind/views/album.html.php | 2 +- 5 files changed, 128 insertions(+), 128 deletions(-) create mode 100644 modules/gallery/controllers/flash_uploader.php delete mode 100644 modules/gallery/controllers/simple_uploader.php (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/flash_uploader.php b/modules/gallery/controllers/flash_uploader.php new file mode 100644 index 00000000..f7da5124 --- /dev/null +++ b/modules/gallery/controllers/flash_uploader.php @@ -0,0 +1,124 @@ +is_album()) { + $item = $item->parent(); + } + + print $this->_get_add_form($item); + } + + public function start() { + access::verify_csrf(); + batch::start(); + } + + public function add_photo($id) { + $album = ORM::factory("item", $id); + access::required("view", $album); + access::required("add", $album); + access::verify_csrf(); + + // The Flash uploader not call /start directly, so simulate it here for now. + if (!batch::in_progress()) { + batch::start(); + } + + $form = $this->_get_add_form($album); + + // Uploadify adds its own field to the form, so validate that separately. + $file_validation = new Validation($_FILES); + $file_validation->add_rules( + "Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]"); + + if ($form->validate() && $file_validation->validate()) { + $temp_filename = upload::save("Filedata"); + try { + $item = ORM::factory("item"); + $item->name = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds + $item->title = item::convert_filename_to_title($item->name); + $item->parent_id = $album->id; + $item->set_data_file($temp_filename); + + $path_info = @pathinfo($temp_filename); + if (array_key_exists("extension", $path_info) && + in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) { + $item->type = "movie"; + $item->save(); + log::success("content", t("Added a movie"), + html::anchor("movies/$item->id", t("view movie"))); + } else { + $item->type = "photo"; + $item->save(); + log::success("content", t("Added a photo"), + html::anchor("photos/$item->id", t("view photo"))); + } + + module::event("add_photos_form_completed", $item, $form); + } catch (Exception $e) { + // The Flash uploader has no good way of reporting complex errors, so just keep it simple. + Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); + + // Ugh. I hate to use instanceof, But this beats catching the exception separately since + // we mostly want to treat it the same way as all other exceptions + if ($e instanceof ORM_Validation_Exception) { + Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1)); + } + + if (file_exists($temp_filename)) { + unlink($temp_filename); + } + header("HTTP/1.1 500 Internal Server Error"); + print "ERROR: " . $e->getMessage(); + return; + } + unlink($temp_filename); + print "FILEID: $item->id"; + } else { + header("HTTP/1.1 400 Bad Request"); + print "ERROR: " . t("Invalid upload"); + } + } + + public function finish() { + access::verify_csrf(); + + batch::stop(); + print json_encode(array("result" => "success")); + } + + private function _get_add_form($album) { + $form = new Forge("flash_uploader/finish", "", "post", array("id" => "g-add-photos-form")); + $group = $form->group("add_photos") + ->label(t("Add photos to %album_title", array("album_title" => html::purify($album->title)))); + $group->uploadify("uploadify")->album($album); + + $group = $form->group("actions"); + $group->uploadify_buttons(""); + + module::event("add_photos_form", $album, $form); + + return $form; + } +} diff --git a/modules/gallery/controllers/simple_uploader.php b/modules/gallery/controllers/simple_uploader.php deleted file mode 100644 index c7e5031b..00000000 --- a/modules/gallery/controllers/simple_uploader.php +++ /dev/null @@ -1,124 +0,0 @@ -is_album()) { - $item = $item->parent(); - } - - print $this->_get_add_form($item); - } - - public function start() { - access::verify_csrf(); - batch::start(); - } - - public function add_photo($id) { - $album = ORM::factory("item", $id); - access::required("view", $album); - access::required("add", $album); - access::verify_csrf(); - - // The Flash uploader not call /start directly, so simulate it here for now. - if (!batch::in_progress()) { - batch::start(); - } - - $form = $this->_get_add_form($album); - - // Uploadify adds its own field to the form, so validate that separately. - $file_validation = new Validation($_FILES); - $file_validation->add_rules( - "Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]"); - - if ($form->validate() && $file_validation->validate()) { - $temp_filename = upload::save("Filedata"); - try { - $item = ORM::factory("item"); - $item->name = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds - $item->title = item::convert_filename_to_title($item->name); - $item->parent_id = $album->id; - $item->set_data_file($temp_filename); - - $path_info = @pathinfo($temp_filename); - if (array_key_exists("extension", $path_info) && - in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) { - $item->type = "movie"; - $item->save(); - log::success("content", t("Added a movie"), - html::anchor("movies/$item->id", t("view movie"))); - } else { - $item->type = "photo"; - $item->save(); - log::success("content", t("Added a photo"), - html::anchor("photos/$item->id", t("view photo"))); - } - - module::event("add_photos_form_completed", $item, $form); - } catch (Exception $e) { - // The Flash uploader has no good way of reporting complex errors, so just keep it simple. - Kohana_Log::add("error", $e->getMessage() . "\n" . $e->getTraceAsString()); - - // Ugh. I hate to use instanceof, But this beats catching the exception separately since - // we mostly want to treat it the same way as all other exceptions - if ($e instanceof ORM_Validation_Exception) { - Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1)); - } - - if (file_exists($temp_filename)) { - unlink($temp_filename); - } - header("HTTP/1.1 500 Internal Server Error"); - print "ERROR: " . $e->getMessage(); - return; - } - unlink($temp_filename); - print "FILEID: $item->id"; - } else { - header("HTTP/1.1 400 Bad Request"); - print "ERROR: " . t("Invalid upload"); - } - } - - public function finish() { - access::verify_csrf(); - - batch::stop(); - print json_encode(array("result" => "success")); - } - - private function _get_add_form($album) { - $form = new Forge("simple_uploader/finish", "", "post", array("id" => "g-add-photos-form")); - $group = $form->group("add_photos") - ->label(t("Add photos to %album_title", array("album_title" => html::purify($album->title)))); - $group->uploadify("uploadify")->album($album); - - $group = $form->group("actions"); - $group->uploadify_buttons(""); - - module::event("add_photos_form", $album, $form); - - return $form; - } -} diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 55db47ce..82f42d98 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -202,7 +202,7 @@ class gallery_event_Core { $add_menu->append(Menu::factory("dialog") ->id("add_photos_item") ->label(t("Add photos")) - ->url(url::site("simple_uploader/app/$item->id"))); + ->url(url::site("flash_uploader/app/$item->id"))); if ($item->is_album()) { $add_menu->append(Menu::factory("dialog") ->id("add_album_item") @@ -471,7 +471,7 @@ class gallery_event_Core { ->id("add_item") ->label(t("Add a photo")) ->css_class("ui-icon-plus") - ->url(url::site("simple_uploader/app/$item->id"))) + ->url(url::site("flash_uploader/app/$item->id"))) ->append(Menu::factory("dialog") ->id("add_album") ->label(t("Add an album")) diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php index d811f913..588fa16d 100644 --- a/modules/gallery/views/form_uploadify.html.php +++ b/modules/gallery/views/form_uploadify.html.php @@ -7,7 +7,7 @@ width: 150, height: 33, uploader: "", - script: "id}") ?>", + script: "id}") ?>", scriptData: , fileExt: "*.gif;*.jpg;*.jpeg;*.png;*.flv;*.mp4;*.GIF;*.JPG;*.JPEG;*.PNG;*.FLV;*.MP4", fileDesc: for_js() ?>, diff --git a/themes/wind/views/album.html.php b/themes/wind/views/album.html.php index eabe07c3..b9072e2b 100644 --- a/themes/wind/views/album.html.php +++ b/themes/wind/views/album.html.php @@ -29,7 +29,7 @@ admin || access::can("add", $item)): ?> - id") ?> + id") ?>
  • Add some.", array("attrs" => html::mark_clean("href=\"$addurl\" class=\"g-dialog-link\""))) ?>
  • -- cgit v1.2.3 From a804c115138172634123ebebc9b055d6a26e6189 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 21 Jun 2010 10:11:38 -0700 Subject: 1) revert e468ed7bd3f1e29b267e3902ef9c91273787d58f 2) Add the padding to both the button and flash object so they always line up 3) Add some top padding to the uploadifyQueue panel to seprate it from the button. --- modules/gallery/css/gallery.css | 9 ++++++--- themes/wind/css/screen.css | 6 ------ 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/css/gallery.css b/modules/gallery/css/gallery.css index e2ad7458..282ebec2 100644 --- a/modules/gallery/css/gallery.css +++ b/modules/gallery/css/gallery.css @@ -30,7 +30,7 @@ #g-add-photos-canvas object, #g-add-photos-button { left: 137px; - margin: 0 0 .5em 0; + margin: .5em 0; padding: .4em 1em; position: absolute; top: 0; @@ -38,10 +38,13 @@ } #g-add-photos-canvas object { - margin: 0; z-index: 100; } +#g-add-photos-canvas .uploadifyQueue { + margin-top: .5em; +} + #g-add-photos-canvas .uploadifyQueueItem { margin: 0; } @@ -204,4 +207,4 @@ .rtl #g-translations ol { margin: 0 2em 1em 0; -} \ No newline at end of file +} diff --git a/themes/wind/css/screen.css b/themes/wind/css/screen.css index bc9f3e59..1e55a967 100644 --- a/themes/wind/css/screen.css +++ b/themes/wind/css/screen.css @@ -319,12 +319,6 @@ td { background-color: #fff; } -/* Add dialog ~~~~~~~~~~~~~~~~~~~~~~~~ */ - -#g-add-photos-button { - margin-top: 6px !important; -} - /** ******************************************************************* * 5) Navigation and menus *********************************************************************/ -- cgit v1.2.3 From ca09e9889004438090b4d9c8410cb746c135f163 Mon Sep 17 00:00:00 2001 From: mamouneyya Date: Wed, 23 Jun 2010 22:12:25 +0800 Subject: centerize the group labels in Edit Permission window.. i think it's much cleaner this way --- modules/gallery/css/gallery.css | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/css/gallery.css b/modules/gallery/css/gallery.css index 282ebec2..08bd4749 100644 --- a/modules/gallery/css/gallery.css +++ b/modules/gallery/css/gallery.css @@ -84,6 +84,10 @@ clear: both; } +#g-edit-permissions-form th { + text-align: center; +} + #g-edit-permissions-form td { background-image: none; } -- cgit v1.2.3 From d66c496fb1007bbd0b1640496808000c573d95fd Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 25 Jun 2010 06:45:09 -0700 Subject: Change the theme option page to display using tabs if the site theme has an admin page. --- modules/gallery/helpers/theme.php | 5 ++-- modules/gallery/views/admin_theme_options.html.php | 31 ++++++++++++++++++++++ themes/admin_wind/css/screen.css | 22 ++++++++++++++- 3 files changed, 55 insertions(+), 3 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 980ee11a..a390645f 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -70,7 +70,7 @@ class theme_Core { static function get_edit_form_admin() { $form = new Forge("admin/theme_options/save/", "", null, array("id" =>"g-theme-options-form")); - $group = $form->group("edit_theme"); + $group = $form->group("edit_theme")->label(t("Theme Layout")); $group->input("page_size")->label(t("Items per page"))->id("g-page-size") ->rules("required|valid_digit") ->error_messages("required", t("You must enter a number")) @@ -95,7 +95,8 @@ class theme_Core { module::event("theme_edit_form", $form); - $group = $form->group("buttons"); + $group = $form->group("buttons") + ->set_attr("style","border: none"); $group->submit("")->value(t("Save")); return $form; } diff --git a/modules/gallery/views/admin_theme_options.html.php b/modules/gallery/views/admin_theme_options.html.php index a4bf1c4e..2cf97713 100644 --- a/modules/gallery/views/admin_theme_options.html.php +++ b/modules/gallery/views/admin_theme_options.html.php @@ -1,4 +1,35 @@ + +

    diff --git a/themes/admin_wind/css/screen.css b/themes/admin_wind/css/screen.css index dbfb59e8..937c4d15 100644 --- a/themes/admin_wind/css/screen.css +++ b/themes/admin_wind/css/screen.css @@ -399,6 +399,26 @@ th { background-color: #FFF; } +/* Theme options ~~~~~~~~~~~~~~~~~~~~~~~~ */ +#g-theme-options-form { + border: 1px solid #a6c9e2; +} +#g-theme-options-form-tabs { + border: none !important; +} +#g-theme-options-form fieldset { + border: none; +} + +.ui-tabs .ui-tabs-nav li a { + padding: 0 1em; +} + +.ui-tabs .ui-tabs-nav li a.g-error { + background: none no-repeat scroll 0 0 transparent; + color: #FF0000 !important; +} + /** ******************************************************************* * 5) Navigation and menus *********************************************************************/ @@ -487,4 +507,4 @@ th { .rtl .g-selected img, .rtl .g-available .g-block img { margin: 0 0 1em 1em; -} \ No newline at end of file +} -- cgit v1.2.3 From 8bc7eec60f8be5219bed64d95cf7e6efb85941f1 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 25 Jun 2010 09:56:44 -0700 Subject: Add a

    title saying that this is a preview. --- modules/gallery/views/admin_themes_preview.html.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery') diff --git a/modules/gallery/views/admin_themes_preview.html.php b/modules/gallery/views/admin_themes_preview.html.php index a7aea172..80a6158b 100644 --- a/modules/gallery/views/admin_themes_preview.html.php +++ b/modules/gallery/views/admin_themes_preview.html.php @@ -1,4 +1,5 @@ +

    $info->name)) ?>

    "> %theme_name", array("theme_name" => $info->name)) ?> -- cgit v1.2.3 From e380f19ee29ee1f524aee2d4ebbf4c49f120fb19 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 25 Jun 2010 10:17:06 -0700 Subject: Fix an issue where a preview of the admin view would not work. --- modules/gallery/helpers/theme.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index a390645f..4730d296 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -53,6 +53,15 @@ class theme_Core { if (file_exists(THEMEPATH . self::$site_theme_name . "/admin")) { array_unshift($modules, THEMEPATH . self::$site_theme_name . "/admin"); } + // 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::$admin_theme_name = $override; + } else { + Kohana_Log::add("error", "Missing override theme: '$override'"); + } + } + array_unshift($modules, THEMEPATH . self::$admin_theme_name); } else { // Admins can override the site theme, temporarily. This lets us preview themes. if (identity::active_user()->admin && $override = $input->get("theme")) { -- cgit v1.2.3 From 8ecf28d3efa258d790d6cb31947407deb7149797 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 25 Jun 2010 10:23:11 -0700 Subject: Better fix for the problem that a preview of an admin theme was not showing up. --- modules/gallery/helpers/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 4730d296..419d986f 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -57,11 +57,11 @@ class theme_Core { if (identity::active_user()->admin && $override = $input->get("theme")) { if (file_exists(THEMEPATH . $override)) { self::$admin_theme_name = $override; + array_unshift($modules, THEMEPATH . self::$admin_theme_name); } else { Kohana_Log::add("error", "Missing override theme: '$override'"); } } - array_unshift($modules, THEMEPATH . self::$admin_theme_name); } else { // Admins can override the site theme, temporarily. This lets us preview themes. if (identity::active_user()->admin && $override = $input->get("theme")) { -- cgit v1.2.3 From 6b619e1098d770670b50553564b96bacec4a3f0c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 26 Jun 2010 12:00:14 -0700 Subject: Differentiate in our logs between missing site and admin theme overrides. --- modules/gallery/helpers/theme.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index 419d986f..c2980149 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -59,7 +59,7 @@ class theme_Core { self::$admin_theme_name = $override; array_unshift($modules, THEMEPATH . self::$admin_theme_name); } else { - Kohana_Log::add("error", "Missing override theme: '$override'"); + Kohana_Log::add("error", "Missing override admin theme: '$override'"); } } } else { @@ -68,7 +68,7 @@ class theme_Core { if (file_exists(THEMEPATH . $override)) { self::$site_theme_name = $override; } else { - Kohana_Log::add("error", "Missing override theme: '$override'"); + Kohana_Log::add("error", "Missing override site theme: '$override'"); } } array_unshift($modules, THEMEPATH . self::$site_theme_name); -- cgit v1.2.3 From 5767971f433ca22f152fb348901d2f4336913038 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 26 Jun 2010 12:00:55 -0700 Subject: Sentence casing. --- modules/gallery/helpers/theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php index c2980149..3589a5b7 100644 --- a/modules/gallery/helpers/theme.php +++ b/modules/gallery/helpers/theme.php @@ -79,7 +79,7 @@ class theme_Core { static function get_edit_form_admin() { $form = new Forge("admin/theme_options/save/", "", null, array("id" =>"g-theme-options-form")); - $group = $form->group("edit_theme")->label(t("Theme Layout")); + $group = $form->group("edit_theme")->label(t("Theme layout")); $group->input("page_size")->label(t("Items per page"))->id("g-page-size") ->rules("required|valid_digit") ->error_messages("required", t("You must enter a number")) -- cgit v1.2.3 From e5ae2c91bc58518c977afdc134d5a59cb7ed9b71 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 26 Jun 2010 12:14:02 -0700 Subject: Style cleanup. --- modules/gallery/views/admin_theme_options.html.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/views/admin_theme_options.html.php b/modules/gallery/views/admin_theme_options.html.php index 2cf97713..b4a90682 100644 --- a/modules/gallery/views/admin_theme_options.html.php +++ b/modules/gallery/views/admin_theme_options.html.php @@ -10,17 +10,17 @@ var text = $("legend", this).text(); var tabId = "tab_" + index; var tabContentId = "tab_content_" + index; - console.log(tabId+": text='"+text+"'"); if (text == "") { text = for_js() ?> + index; } - $(".tabnav").append("

  • "+text+"
  • "); - $("#g-theme-options-form-tabs").append("
    "); - + $(".tabnav").append( + "
  • " + text + "
  • "); + $("#g-theme-options-form-tabs").append( + "
    "); if ($("li.g-error", this).length > 0) { - $("#"+tabId).addClass("g-error"); + $("#" + tabId).addClass("g-error"); } - $("#"+tabContentId).append($("ul", this)); + $("#" + tabContentId).append($("ul", this)); $(this).remove(); }); $("#g-theme-options-form-tabs").tabs({}); @@ -31,8 +31,7 @@
    -

    - +

    -- cgit v1.2.3 From 0d424a635d12eee59d2080fa7ffa32a248b0fd5c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 3 Jul 2010 14:25:33 -0700 Subject: When we delete an item, make sure that we scrub it from any other items that may have it in the album_cover_item_id column. Fixes ticket #1172. --- modules/gallery/helpers/gallery_event.php | 9 +++++++++ modules/gallery/tests/Item_Helper_Test.php | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 82f42d98..40ea50fa 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -98,6 +98,15 @@ class gallery_event_Core { static function item_deleted($item) { access::delete_item($item); + // Find any other albums that had the deleted item as the album cover and null it out. + // In some cases this may leave us with a missing album cover up in this item's parent + // hierarchy, but in most cases it'll work out fine. + foreach (ORM::factory("item") + ->where("album_cover_item_id", "=", $item->id) + ->find_all() as $parent) { + item::remove_album_cover($parent); + } + $parent = $item->parent(); if (!$parent->album_cover_item_id) { // Assume we deleted the album cover and pick a new one. Choosing the first photo in the diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php index 00229973..eb2458cb 100644 --- a/modules/gallery/tests/Item_Helper_Test.php +++ b/modules/gallery/tests/Item_Helper_Test.php @@ -111,15 +111,18 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case { $this->assert_not_same($rand, $photo2->slug); } - public function delete_cover_photo_picks_new_album_cover() { - $album = test::random_album(); + public function delete_cover_photo_picks_new_album_cover_test() { + $parent = test::random_album(); + $album = test::random_album($parent); $photo1 = test::random_photo($album); // At this point, $photo1 is the album cover. We verify this in // Item_Model_Test::first_photo_becomes_album_cover $photo2 = test::random_photo($album); $photo1->delete(); $album->reload(); + $parent->reload(); $this->assert_same($photo2->id, $album->album_cover_item_id); + $this->assert_same($photo2->id, $parent->album_cover_item_id); } } -- cgit v1.2.3 From 60126adc7e73ec6e70ee5033abf5032ac6b88305 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 4 Jul 2010 20:40:50 -0700 Subject: In the site menu, say "Delete album", "Delete photo" or "Delete movie" as appropriate for the item type. Fixes ticket #1175. --- modules/gallery/helpers/gallery_event.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'modules/gallery') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 40ea50fa..272fd205 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -228,14 +228,17 @@ class gallery_event_Core { case "album": $option_text = t("Album options"); $edit_text = t("Edit album"); + $delete_text = t("Delete album"); break; case "movie": $option_text = t("Movie options"); $edit_text = t("Edit movie"); + $delete_text = t("Delete movie"); break; default: $option_text = t("Photo options"); $edit_text = t("Edit photo"); + $delete_text = t("Delete photo"); } $menu->append($options_menu = Menu::factory("submenu") @@ -309,7 +312,7 @@ class gallery_event_Core { ->append( Menu::factory("dialog") ->id("delete") - ->label(t("Delete this photo")) + ->label($delete_text) ->css_class("ui-icon-trash") ->css_class("g-quick-delete") ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); -- cgit v1.2.3 From e4d397d30118a3d673b146c44ed329efa08bbefe Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 5 Jul 2010 08:21:14 -0700 Subject: Make the trailing slash on the url optional. Sometimes it is not there, so the regex doesn't match --- modules/gallery/config/routes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/config/routes.php b/modules/gallery/config/routes.php index 55d3cf6c..e1ea9612 100644 --- a/modules/gallery/config/routes.php +++ b/modules/gallery/config/routes.php @@ -23,10 +23,10 @@ $config["^admin_.*"] = null; // Redirect /form/add/admin/controller and /form/edit/admin/controller to // admin/controller/form_(add|edit)/parms. provides the same as below for admin pages -$config["^form/(edit|add)/admin/(\w+)/(.*)$"] = "admin/$2/form_$1/$3"; +$config["^form/(edit|add)/admin/(\w+)/?(.*)$"] = "admin/$2/form_$1/$3"; // Redirect /form/add and /form/edit to the module/form_(add|edit)/parms. -$config["^form/(edit|add)/(\w+)/(.*)$"] = "$2/form_$1/$3"; +$config["^form/(edit|add)/(\w+)/?(.*)$"] = "$2/form_$1/$3"; // Default page is the root album $config["_default"] = "albums"; -- cgit v1.2.3 From 8493a3d36f597e183490ae880b35a3d98f50a045 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 5 Jul 2010 08:23:17 -0700 Subject: If the admin request originates as a dialog link, don't display the entire page when reauthenticating the administrator. Just put the form in the dialog. --- lib/gallery.dialog.js | 3 ++- modules/gallery/controllers/admin.php | 11 ++++++-- modules/gallery/controllers/reauthenticate.php | 20 ++------------ modules/gallery/helpers/reauthenticate.php | 36 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 modules/gallery/helpers/reauthenticate.php (limited to 'modules/gallery') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index 6ec8c634..dd1a5663 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -26,7 +26,8 @@ $("#g-dialog").gallery_show_loading(); - $.get(sHref, function(data) { + var url = sHref + (sHref.indexOf("?") == -1 ? "?" : "&") + "g-in-dialog"; + $.get(url, function(data) { $("#g-dialog").html(data).gallery_show_loading(); if ($("#g-dialog form").length) { diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index c460f58c..d9bee284 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -38,7 +38,8 @@ class Admin_Controller extends Controller { return self::_reauth_check(); } if (auth::must_reauth_for_admin_area()) { - return self::_prompt_for_reauth($controller_name, $args); + print self::_prompt_for_reauth($controller_name, $args); + return; } if (request::method() == "post") { @@ -85,7 +86,13 @@ class Admin_Controller extends Controller { // Avoid anti-phishing protection by passing the url as session variable. Session::instance()->set("continue_url", url::abs_current(true)); } - url::redirect("reauthenticate"); + + // Check that we we not in a dialog. If we are, then use an ajax response. + if (strpos(Router::$query_string, "g-in-dialog") === false) { + url::redirect("reauthenticate"); + } else { + return reauthenticate::get_authenticate_form(); + } } } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index acb27f6a..9ddaff2e 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -22,7 +22,7 @@ class Reauthenticate_Controller extends Controller { if (!identity::active_user()->admin) { access::forbidden(); } - return self::_show_form(self::_form()); + return self::_show_form(reauthenticate::get_authenticate_form()); } public function auth() { @@ -31,7 +31,7 @@ class Reauthenticate_Controller extends Controller { } access::verify_csrf(); - $form = self::_form(); + $form = reauthenticate::get_authenticate_form(); $valid = $form->validate(); $user = identity::active_user(); if ($valid) { @@ -54,20 +54,4 @@ class Reauthenticate_Controller extends Controller { $view->content->user_name = identity::active_user()->name; print $view; } - - private static function _form() { - $form = new Forge("reauthenticate/auth", "", "post", array("id" => "g-reauthenticate-form")); - $form->set_attr('class', "g-narrow"); - $form->hidden("continue_url")->value(Session::instance()->get("continue_url", "admin")); - $group = $form->group("reauthenticate")->label(t("Re-authenticate")); - $group->password("password")->label(t("Password"))->id("g-password")->class(null) - ->callback("auth::validate_too_many_failed_auth_attempts") - ->callback("user::valid_password") - ->error_messages("invalid_password", t("Incorrect password")) - ->error_messages( - "too_many_failed_auth_attempts", - t("Too many incorrect passwords. Try again later")); - $group->submit("")->value(t("Submit")); - return $form; - } } diff --git a/modules/gallery/helpers/reauthenticate.php b/modules/gallery/helpers/reauthenticate.php new file mode 100644 index 00000000..1ad90e15 --- /dev/null +++ b/modules/gallery/helpers/reauthenticate.php @@ -0,0 +1,36 @@ + "g-reauthenticate-form")); + $form->set_attr('class', "g-narrow"); + $form->hidden("continue_url")->value(Session::instance()->get("continue_url", "admin")); + $group = $form->group("reauthenticate")->label(t("Re-authenticate")); + $group->password("password")->label(t("Password"))->id("g-password")->class(null) + ->callback("auth::validate_too_many_failed_auth_attempts") + ->callback("user::valid_password") + ->error_messages("invalid_password", t("Incorrect password")) + ->error_messages( + "too_many_failed_auth_attempts", + t("Too many incorrect passwords. Try again later")); + $group->submit("")->value(t("Submit")); + return $form; + } +} -- cgit v1.2.3 From 45b210c2879d93067f3d903b83cd56d392c75156 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 5 Jul 2010 08:44:46 -0700 Subject: Add maessage when we automatically log you out of the admin area. --- modules/gallery/controllers/admin.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery') diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index c460f58c..40dd260b 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -74,6 +74,7 @@ class Admin_Controller extends Controller { $result = new stdClass(); $result->result = "success"; if ($time_remaining < 30) { + message::success(t("Automatically logged out of the admin area for your security")); $result->location = url::abs_site(""); } -- cgit v1.2.3 From 226d1f714635995722fe7927f8ec049fe3890011 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 5 Jul 2010 08:58:36 -0700 Subject: Revert "If the admin request originates as a dialog link, don't display the entire page when reauthenticating the administrator. Just put the form in the dialog." This reverts commit 8493a3d36f597e183490ae880b35a3d98f50a045. --- lib/gallery.dialog.js | 3 +-- modules/gallery/controllers/admin.php | 11 ++------ modules/gallery/controllers/reauthenticate.php | 20 ++++++++++++-- modules/gallery/helpers/reauthenticate.php | 36 -------------------------- 4 files changed, 21 insertions(+), 49 deletions(-) delete mode 100644 modules/gallery/helpers/reauthenticate.php (limited to 'modules/gallery') diff --git a/lib/gallery.dialog.js b/lib/gallery.dialog.js index dd1a5663..6ec8c634 100644 --- a/lib/gallery.dialog.js +++ b/lib/gallery.dialog.js @@ -26,8 +26,7 @@ $("#g-dialog").gallery_show_loading(); - var url = sHref + (sHref.indexOf("?") == -1 ? "?" : "&") + "g-in-dialog"; - $.get(url, function(data) { + $.get(sHref, function(data) { $("#g-dialog").html(data).gallery_show_loading(); if ($("#g-dialog form").length) { diff --git a/modules/gallery/controllers/admin.php b/modules/gallery/controllers/admin.php index d9bee284..c460f58c 100644 --- a/modules/gallery/controllers/admin.php +++ b/modules/gallery/controllers/admin.php @@ -38,8 +38,7 @@ class Admin_Controller extends Controller { return self::_reauth_check(); } if (auth::must_reauth_for_admin_area()) { - print self::_prompt_for_reauth($controller_name, $args); - return; + return self::_prompt_for_reauth($controller_name, $args); } if (request::method() == "post") { @@ -86,13 +85,7 @@ class Admin_Controller extends Controller { // Avoid anti-phishing protection by passing the url as session variable. Session::instance()->set("continue_url", url::abs_current(true)); } - - // Check that we we not in a dialog. If we are, then use an ajax response. - if (strpos(Router::$query_string, "g-in-dialog") === false) { - url::redirect("reauthenticate"); - } else { - return reauthenticate::get_authenticate_form(); - } + url::redirect("reauthenticate"); } } diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php index 9ddaff2e..acb27f6a 100644 --- a/modules/gallery/controllers/reauthenticate.php +++ b/modules/gallery/controllers/reauthenticate.php @@ -22,7 +22,7 @@ class Reauthenticate_Controller extends Controller { if (!identity::active_user()->admin) { access::forbidden(); } - return self::_show_form(reauthenticate::get_authenticate_form()); + return self::_show_form(self::_form()); } public function auth() { @@ -31,7 +31,7 @@ class Reauthenticate_Controller extends Controller { } access::verify_csrf(); - $form = reauthenticate::get_authenticate_form(); + $form = self::_form(); $valid = $form->validate(); $user = identity::active_user(); if ($valid) { @@ -54,4 +54,20 @@ class Reauthenticate_Controller extends Controller { $view->content->user_name = identity::active_user()->name; print $view; } + + private static function _form() { + $form = new Forge("reauthenticate/auth", "", "post", array("id" => "g-reauthenticate-form")); + $form->set_attr('class', "g-narrow"); + $form->hidden("continue_url")->value(Session::instance()->get("continue_url", "admin")); + $group = $form->group("reauthenticate")->label(t("Re-authenticate")); + $group->password("password")->label(t("Password"))->id("g-password")->class(null) + ->callback("auth::validate_too_many_failed_auth_attempts") + ->callback("user::valid_password") + ->error_messages("invalid_password", t("Incorrect password")) + ->error_messages( + "too_many_failed_auth_attempts", + t("Too many incorrect passwords. Try again later")); + $group->submit("")->value(t("Submit")); + return $form; + } } diff --git a/modules/gallery/helpers/reauthenticate.php b/modules/gallery/helpers/reauthenticate.php deleted file mode 100644 index 1ad90e15..00000000 --- a/modules/gallery/helpers/reauthenticate.php +++ /dev/null @@ -1,36 +0,0 @@ - "g-reauthenticate-form")); - $form->set_attr('class', "g-narrow"); - $form->hidden("continue_url")->value(Session::instance()->get("continue_url", "admin")); - $group = $form->group("reauthenticate")->label(t("Re-authenticate")); - $group->password("password")->label(t("Password"))->id("g-password")->class(null) - ->callback("auth::validate_too_many_failed_auth_attempts") - ->callback("user::valid_password") - ->error_messages("invalid_password", t("Incorrect password")) - ->error_messages( - "too_many_failed_auth_attempts", - t("Too many incorrect passwords. Try again later")); - $group->submit("")->value(t("Submit")); - return $form; - } -} -- cgit v1.2.3 From 67223fc43d1cfd5f33d4fc007935eaadb79a112e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 5 Jul 2010 08:59:08 -0700 Subject: Revert "Make the trailing slash on the url optional. Sometimes it is not there, so the regex doesn't match" This reverts commit e4d397d30118a3d673b146c44ed329efa08bbefe. --- modules/gallery/config/routes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/config/routes.php b/modules/gallery/config/routes.php index e1ea9612..55d3cf6c 100644 --- a/modules/gallery/config/routes.php +++ b/modules/gallery/config/routes.php @@ -23,10 +23,10 @@ $config["^admin_.*"] = null; // Redirect /form/add/admin/controller and /form/edit/admin/controller to // admin/controller/form_(add|edit)/parms. provides the same as below for admin pages -$config["^form/(edit|add)/admin/(\w+)/?(.*)$"] = "admin/$2/form_$1/$3"; +$config["^form/(edit|add)/admin/(\w+)/(.*)$"] = "admin/$2/form_$1/$3"; // Redirect /form/add and /form/edit to the module/form_(add|edit)/parms. -$config["^form/(edit|add)/(\w+)/?(.*)$"] = "$2/form_$1/$3"; +$config["^form/(edit|add)/(\w+)/(.*)$"] = "$2/form_$1/$3"; // Default page is the root album $config["_default"] = "albums"; -- cgit v1.2.3 From 1d40c62f53b37445b5f62a65ce76f4b3ecfb2d4f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 5 Jul 2010 19:46:19 -0700 Subject: Updated version for RC2 --- README | 9 +++++---- modules/gallery/helpers/gallery.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'modules/gallery') diff --git a/README b/README index a00d18cb..67efff4b 100644 --- a/README +++ b/README @@ -9,10 +9,11 @@ interface. SECURITY (& INTENDED AUDIENCE): -This is the second release candidate of Gallery 3.0. We're putting it -out there so that we can find out if we overlooked any small things. -We expect the final version to be virtually identical. You can -install it on public websites and use it freely -- we recommend it! +This is the second (and hopefully final) release candidate of Gallery +3.0. We're putting it out there so that we can find out if we +overlooked any small things. We expect the final version to be +virtually identical. You can install it on public websites and use it +freely -- we recommend it! Note: - We've contracted a professional security audit, received their results diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 7f7db10b..d4078209 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class gallery_Core { - const VERSION = "3.0 RC1 (Santa Fe)"; + const VERSION = "3.0 RC2 (Santa Fe)"; /** * If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is -- cgit v1.2.3 From eee8c27f2666d65c03c36698a612a055e9b55d5e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 6 Jul 2010 08:43:02 -0700 Subject: Correct the controller auth golden file from when the simple_uploader was renamed to flash_uploader --- modules/gallery/tests/controller_auth_data.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/controller_auth_data.txt b/modules/gallery/tests/controller_auth_data.txt index 8263f79d..f7ceed90 100644 --- a/modules/gallery/tests/controller_auth_data.txt +++ b/modules/gallery/tests/controller_auth_data.txt @@ -9,6 +9,8 @@ modules/gallery/controllers/albums.php show 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 +modules/gallery/controllers/flash_uploader.php start DIRTY_AUTH +modules/gallery/controllers/flash_uploader.php finish DIRTY_AUTH modules/gallery/controllers/login.php ajax DIRTY_AUTH modules/gallery/controllers/login.php auth_ajax DIRTY_AUTH modules/gallery/controllers/login.php html DIRTY_AUTH @@ -16,8 +18,6 @@ modules/gallery/controllers/login.php auth_html modules/gallery/controllers/logout.php index DIRTY_AUTH modules/gallery/controllers/maintenance.php index DIRTY_AUTH modules/gallery/controllers/quick.php form_edit DIRTY_CSRF -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 modules/gallery/controllers/user_profile.php show DIRTY_AUTH modules/gallery/controllers/user_profile.php contact DIRTY_AUTH -- cgit v1.2.3 From 9d66783f47636153bf3661d1d89e694dd5188c36 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 6 Jul 2010 09:48:37 -0700 Subject: Update the xss golden file --- modules/gallery/tests/xss_data.txt | 64 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'modules/gallery') diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt index 4ead8a3f..26edaebc 100644 --- a/modules/gallery/tests/xss_data.txt +++ b/modules/gallery/tests/xss_data.txt @@ -28,11 +28,11 @@ modules/comment/views/comment.mrss.php 16 DIRTY_JS $feed- modules/comment/views/comment.mrss.php 19 DIRTY_JS $feed->next_page_uri modules/comment/views/comment.mrss.php 21 DIRTY $pub_date modules/comment/views/comment.mrss.php 22 DIRTY $pub_date -modules/comment/views/comment.mrss.php 28 DIRTY $child->item_uri -modules/comment/views/comment.mrss.php 29 DIRTY $child->pub_date -modules/comment/views/comment.mrss.php 34 DIRTY_ATTR $child->thumb_url -modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $child->thumb_height -modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $child->thumb_width +modules/comment/views/comment.mrss.php 28 DIRTY $comment->item_uri +modules/comment/views/comment.mrss.php 29 DIRTY $comment->pub_date +modules/comment/views/comment.mrss.php 34 DIRTY_ATTR $comment->thumb_url +modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $comment->thumb_height +modules/comment/views/comment.mrss.php 35 DIRTY_ATTR $comment->thumb_width modules/comment/views/comments.html.php 28 DIRTY_ATTR $comment->id modules/comment/views/comments.html.php 31 DIRTY_ATTR $comment->author()->avatar_url(40,$theme->url(,true)) modules/comment/views/user_profile_comments.html.php 5 DIRTY_ATTR $comment->id @@ -109,7 +109,7 @@ modules/gallery/views/admin_sidebar.html.php 50 DIRTY $avail modules/gallery/views/admin_sidebar.html.php 58 DIRTY $active modules/gallery/views/admin_sidebar_blocks.html.php 4 DIRTY_ATTR $ref modules/gallery/views/admin_sidebar_blocks.html.php 4 DIRTY $text -modules/gallery/views/admin_theme_options.html.php 6 DIRTY $form +modules/gallery/views/admin_theme_options.html.php 36 DIRTY $form modules/gallery/views/admin_themes.html.php 3 DIRTY_JS url::site("admin/themes/choose") modules/gallery/views/admin_themes.html.php 5 DIRTY_JS $csrf modules/gallery/views/admin_themes.html.php 22 DIRTY $themes[$site]->name @@ -120,7 +120,7 @@ modules/gallery/views/admin_themes.html.php 60 DIRTY $theme modules/gallery/views/admin_themes.html.php 62 DIRTY $themes[$admin]->description modules/gallery/views/admin_themes.html.php 76 DIRTY $info->name modules/gallery/views/admin_themes.html.php 78 DIRTY $info->description -modules/gallery/views/admin_themes_preview.html.php 7 DIRTY_ATTR $url +modules/gallery/views/admin_themes_preview.html.php 8 DIRTY_ATTR $url modules/gallery/views/error_404.html.php 14 DIRTY $login_form modules/gallery/views/error_admin.html.php 150 DIRTY $type modules/gallery/views/error_admin.html.php 150 DIRTY $code @@ -167,7 +167,7 @@ modules/gallery/views/error_admin.html.php 251 DIRTY_ATTR $env modules/gallery/views/error_admin.html.php 257 DIRTY $key modules/gallery/views/error_admin.html.php 261 DIRTY Kohana_Exception::safe_dump($value,$key) modules/gallery/views/form_uploadify.html.php 9 DIRTY_JS url::file("lib/uploadify/uploadify.swf") -modules/gallery/views/form_uploadify.html.php 10 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}") +modules/gallery/views/form_uploadify.html.php 10 DIRTY_JS url::site("flash_uploader/add_photo/{$album->id}") modules/gallery/views/form_uploadify.html.php 14 DIRTY_JS url::file("lib/uploadify/cancel.png") modules/gallery/views/form_uploadify.html.php 15 DIRTY_JS $simultaneous_upload_limit modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form")) @@ -190,7 +190,7 @@ modules/gallery/views/l10n_client.html.php 58 DIRTY form:: modules/gallery/views/l10n_client.html.php 62 DIRTY form::textarea("l10n-edit-plural-translation-many","",' rows="2"') modules/gallery/views/l10n_client.html.php 67 DIRTY form::textarea("l10n-edit-plural-translation-other","",' rows="2"') modules/gallery/views/login_ajax.html.php 6 DIRTY_JS url::site("password/reset") -modules/gallery/views/login_ajax.html.php 37 DIRTY $form +modules/gallery/views/login_ajax.html.php 44 DIRTY $form modules/gallery/views/maintenance.html.php 46 DIRTY auth::get_login_form("login/auth_html") modules/gallery/views/menu.html.php 4 DIRTY $menu->css_id?"id='$menu->css_id'":"" modules/gallery/views/menu.html.php 4 DIRTY_ATTR $menu->css_class @@ -298,26 +298,26 @@ modules/rss/views/feed.mrss.php 16 DIRTY_JS $feed- modules/rss/views/feed.mrss.php 19 DIRTY_JS $feed->next_page_uri modules/rss/views/feed.mrss.php 21 DIRTY $pub_date modules/rss/views/feed.mrss.php 22 DIRTY $pub_date -modules/rss/views/feed.mrss.php 28 DIRTY date("D, d M Y H:i:s T",$child->created); -modules/rss/views/feed.mrss.php 35 DIRTY_ATTR $child->resize_url(true) -modules/rss/views/feed.mrss.php 37 DIRTY_ATTR $child->resize_height -modules/rss/views/feed.mrss.php 37 DIRTY_ATTR $child->resize_width -modules/rss/views/feed.mrss.php 40 DIRTY_ATTR $child->thumb_url(true) -modules/rss/views/feed.mrss.php 42 DIRTY_ATTR $child->thumb_height -modules/rss/views/feed.mrss.php 42 DIRTY_ATTR $child->thumb_width -modules/rss/views/feed.mrss.php 48 DIRTY_ATTR $child->thumb_url(true) -modules/rss/views/feed.mrss.php 49 DIRTY_ATTR $child->thumb_height -modules/rss/views/feed.mrss.php 50 DIRTY_ATTR $child->thumb_width -modules/rss/views/feed.mrss.php 57 DIRTY_ATTR $child->resize_url(true) -modules/rss/views/feed.mrss.php 58 DIRTY_ATTR @filesize($child->resize_path()) -modules/rss/views/feed.mrss.php 59 DIRTY_ATTR $child->mime_type -modules/rss/views/feed.mrss.php 60 DIRTY_ATTR $child->resize_height -modules/rss/views/feed.mrss.php 61 DIRTY_ATTR $child->resize_width -modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $child->file_url(true) -modules/rss/views/feed.mrss.php 66 DIRTY_ATTR @filesize($child->file_path()) -modules/rss/views/feed.mrss.php 67 DIRTY_ATTR $child->mime_type -modules/rss/views/feed.mrss.php 68 DIRTY_ATTR $child->height -modules/rss/views/feed.mrss.php 69 DIRTY_ATTR $child->width +modules/rss/views/feed.mrss.php 28 DIRTY date("D, d M Y H:i:s T",$item->created); +modules/rss/views/feed.mrss.php 35 DIRTY_ATTR $item->resize_url(true) +modules/rss/views/feed.mrss.php 37 DIRTY_ATTR $item->resize_height +modules/rss/views/feed.mrss.php 37 DIRTY_ATTR $item->resize_width +modules/rss/views/feed.mrss.php 40 DIRTY_ATTR $item->thumb_url(true) +modules/rss/views/feed.mrss.php 42 DIRTY_ATTR $item->thumb_height +modules/rss/views/feed.mrss.php 42 DIRTY_ATTR $item->thumb_width +modules/rss/views/feed.mrss.php 48 DIRTY_ATTR $item->thumb_url(true) +modules/rss/views/feed.mrss.php 49 DIRTY_ATTR $item->thumb_height +modules/rss/views/feed.mrss.php 50 DIRTY_ATTR $item->thumb_width +modules/rss/views/feed.mrss.php 57 DIRTY_ATTR $item->resize_url(true) +modules/rss/views/feed.mrss.php 58 DIRTY_ATTR @filesize($item->resize_path()) +modules/rss/views/feed.mrss.php 59 DIRTY_ATTR $item->mime_type +modules/rss/views/feed.mrss.php 60 DIRTY_ATTR $item->resize_height +modules/rss/views/feed.mrss.php 61 DIRTY_ATTR $item->resize_width +modules/rss/views/feed.mrss.php 65 DIRTY_ATTR $item->file_url(true) +modules/rss/views/feed.mrss.php 66 DIRTY_ATTR @filesize($item->file_path()) +modules/rss/views/feed.mrss.php 67 DIRTY_ATTR $item->mime_type +modules/rss/views/feed.mrss.php 68 DIRTY_ATTR $item->height +modules/rss/views/feed.mrss.php 69 DIRTY_ATTR $item->width modules/rss/views/rss_block.html.php 6 DIRTY_JS rss::url($url) modules/search/views/search.html.php 27 DIRTY_ATTR $item_class modules/search/views/search.html.php 28 DIRTY_JS $item->url() @@ -406,9 +406,9 @@ themes/wind/views/page.html.php 81 DIRTY $heade themes/wind/views/page.html.php 83 DIRTY_JS item::root()->url() themes/wind/views/page.html.php 87 DIRTY $theme->user_menu() themes/wind/views/page.html.php 108 DIRTY_JS $parent->url($parent==$theme->item()->parent()?"show={$theme->item()->id}":null) -themes/wind/views/page.html.php 124 DIRTY $content -themes/wind/views/page.html.php 130 DIRTY newView("sidebar.html") -themes/wind/views/page.html.php 137 DIRTY $footer_text +themes/wind/views/page.html.php 126 DIRTY $content +themes/wind/views/page.html.php 132 DIRTY newView("sidebar.html") +themes/wind/views/page.html.php 139 DIRTY $footer_text themes/wind/views/paginator.html.php 33 DIRTY_JS $first_page_url themes/wind/views/paginator.html.php 42 DIRTY_JS $previous_page_url themes/wind/views/paginator.html.php 70 DIRTY_JS $next_page_url -- cgit v1.2.3