From 9bb4c954bbc10e71a695b57f7e8979a140f4873f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 7 Apr 2010 08:07:41 -0700 Subject: Merge bharat_dev rest implementation --- modules/tag/helpers/item_tags_rest.php | 5 +++-- modules/tag/helpers/tag_item_rest.php | 2 +- modules/tag/helpers/tag_items_rest.php | 4 ++-- modules/tag/helpers/tag_rest.php | 27 ++++++++++++--------------- modules/tag/helpers/tags_rest.php | 6 +++--- 5 files changed, 21 insertions(+), 23 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/item_tags_rest.php b/modules/tag/helpers/item_tags_rest.php index 8a1b1e8b..02c79e5d 100644 --- a/modules/tag/helpers/item_tags_rest.php +++ b/modules/tag/helpers/item_tags_rest.php @@ -31,8 +31,8 @@ class item_tags_rest_Core { } static function post($request) { - $tag = rest::resolve($request->params->tag); - $item = rest::resolve($request->params->item); + $tag = rest::resolve($request->params->entity->tag); + $item = rest::resolve($request->params->entity->item); access::required("view", $item); tag::add($item, $tag->name); @@ -45,6 +45,7 @@ class item_tags_rest_Core { static function delete($request) { list ($tag, $item) = rest::resolve($request->url); + access::required("edit", $item); $tag->remove($item); $tag->save(); } diff --git a/modules/tag/helpers/tag_item_rest.php b/modules/tag/helpers/tag_item_rest.php index bce00a9f..17cb726e 100644 --- a/modules/tag/helpers/tag_item_rest.php +++ b/modules/tag/helpers/tag_item_rest.php @@ -22,7 +22,7 @@ class tag_item_rest_Core { list ($tag, $item) = rest::resolve($request->url); return array( "url" => $request->url, - "members" => array( + "entity" => array( "tag" => rest::url("tag", $tag), "item" => rest::url("item", $item))); } diff --git a/modules/tag/helpers/tag_items_rest.php b/modules/tag/helpers/tag_items_rest.php index 003c7c95..848c2cd3 100644 --- a/modules/tag/helpers/tag_items_rest.php +++ b/modules/tag/helpers/tag_items_rest.php @@ -33,8 +33,8 @@ class tag_items_rest_Core { } static function post($request) { - $tag = rest::resolve($request->params->tag); - $item = rest::resolve($request->params->item); + $tag = rest::resolve($request->params->entity->tag); + $item = rest::resolve($request->params->entity->item); access::required("view", $item); if (!$tag->loaded()) { diff --git a/modules/tag/helpers/tag_rest.php b/modules/tag/helpers/tag_rest.php index f30706bd..e0b7bd87 100644 --- a/modules/tag/helpers/tag_rest.php +++ b/modules/tag/helpers/tag_rest.php @@ -36,28 +36,25 @@ class tag_rest_Core { "members" => $tag_items))); } - static function post($request) { - if (empty($request->params->url)) { - throw new Rest_Exception("Bad request", 400); - } - - $tag = rest::resolve($request->url); - $item = rest::resolve($request->params->url); - access::required("edit", $item); - - tag::add($item, $tag->name); - return array("url" => rest::url("tag_item", $tag, $item)); - } - static function put($request) { + // Who can we allow to edit a tag name? If we allow anybody to do it then any logged in + // user can rename all your tags to something offensive. Right now limit renaming to admins. + if (!identity::active_user()->admin) { + access::forbidden(); + } $tag = rest::resolve($request->url); - if (isset($request->params->name)) { - $tag->name = $request->params->name; + if (isset($request->params->entity->name)) { + $tag->name = $request->params->entity->name; $tag->save(); } } static function delete($request) { + // Restrict deleting tags to admins. Otherwise, a logged in user can do great harm to an + // install. + if (!identity::active_user()->admin) { + access::forbidden(); + } $tag = rest::resolve($request->url); $tag->delete(); } diff --git a/modules/tag/helpers/tags_rest.php b/modules/tag/helpers/tags_rest.php index 82826d8e..434e774a 100644 --- a/modules/tag/helpers/tags_rest.php +++ b/modules/tag/helpers/tags_rest.php @@ -40,13 +40,13 @@ class tags_rest_Core { } } - if (empty($request->params->name)) { + if (empty($request->params->entity->name)) { throw new Rest_Exception("Bad Request", 400); } - $tag = ORM::factory("tag")->where("name", "=", $request->params->name)->find(); + $tag = ORM::factory("tag")->where("name", "=", $request->params->entity->name)->find(); if (!$tag->loaded()) { - $tag->name = $request->params->name; + $tag->name = $request->params->entity->name; $tag->count = 0; $tag->save(); } -- cgit v1.2.3 From bd496cc95c01d8058cacfd79347f626652d42464 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 16 Jun 2010 16:09:29 -0700 Subject: Add start/num query parameters to tags::get() --- modules/tag/helpers/tags_rest.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tags_rest.php b/modules/tag/helpers/tags_rest.php index 434e774a..975cf140 100644 --- a/modules/tag/helpers/tags_rest.php +++ b/modules/tag/helpers/tags_rest.php @@ -18,9 +18,22 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class tags_rest_Core { + /** + * Possible request parameters: + * start=# + * start at the Nth comment (zero based) + * + * num=# + * return up to N comments (max 100) + */ static function get($request) { $tags = array(); - foreach (ORM::factory("tag")->find_all() as $tag) { + + $p = $request->params; + $num = isset($p->num) ? min((int)$p->num, 100) : 10; + $start = isset($p->start) ? (int)$p->start : 0; + + foreach (ORM::factory("tag")->find_all($num, $start) as $tag) { $tags[] = rest::url("tag", $tag); } return array("url" => rest::url("tags"), -- cgit v1.2.3 From 84c8d1c79a07aa72bb0a22cd3c0673df6f5886f2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 18 Jun 2010 06:51:02 -0700 Subject: Fix ticket #1155. For compatibility with gallery2 increase the size of the tag name field from 64 bytes to 128 bytes. --- installer/install.sql | 2 +- modules/tag/helpers/tag_installer.php | 12 ++++++++++-- modules/tag/module.info | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'modules/tag/helpers') diff --git a/installer/install.sql b/installer/install.sql index 2d0cac0f..0e09101e 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -309,7 +309,7 @@ DROP TABLE IF EXISTS {tags}; /*!40101 SET character_set_client = utf8 */; CREATE TABLE {tags} ( `id` int(9) NOT NULL AUTO_INCREMENT, - `name` varchar(64) NOT NULL, + `name` varchar(128) NOT NULL, `count` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php index 6ccaf835..df6f0c65 100644 --- a/modules/tag/helpers/tag_installer.php +++ b/modules/tag/helpers/tag_installer.php @@ -22,7 +22,7 @@ class tag_installer { $db = Database::instance(); $db->query("CREATE TABLE IF NOT EXISTS {tags} ( `id` int(9) NOT NULL auto_increment, - `name` varchar(64) NOT NULL, + `name` varchar(128) NOT NULL, `count` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) @@ -36,7 +36,15 @@ class tag_installer { KEY(`tag_id`, `id`), KEY(`item_id`, `id`)) DEFAULT CHARSET=utf8;"); - module::set_version("tag", 1); + module::set_version("tag", 2); + } + + static function upgrade($version) { + $db = Database::instance(); + if ($version == 1) { + $db->query("ALTER TABLE {tags} MODIFY COLUMN `name` VARCHAR(128)"); + module::set_version("tag", $version = 2); + } } static function uninstall() { diff --git a/modules/tag/module.info b/modules/tag/module.info index e505dd81..8851d119 100644 --- a/modules/tag/module.info +++ b/modules/tag/module.info @@ -1,3 +1,3 @@ name = "Tags" description = "Allows users to tag photos and albums" -version = 1 +version = 2 -- cgit v1.2.3 From f451804c6d82bfbf214f08717c66684da66ca328 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 19 Jun 2010 15:00:44 -0700 Subject: $request->params might not exist. --- modules/tag/helpers/tags_rest.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tags_rest.php b/modules/tag/helpers/tags_rest.php index 975cf140..4f40e7f4 100644 --- a/modules/tag/helpers/tags_rest.php +++ b/modules/tag/helpers/tags_rest.php @@ -29,9 +29,13 @@ class tags_rest_Core { static function get($request) { $tags = array(); - $p = $request->params; - $num = isset($p->num) ? min((int)$p->num, 100) : 10; - $start = isset($p->start) ? (int)$p->start : 0; + $num = 10; + $start = 0; + if (isset($request->params)) { + $p = $request->params; + $num = isset($p->num) ? min((int)$p->num, 100) : 10; + $start = isset($p->start) ? (int)$p->start : 0; + } foreach (ORM::factory("tag")->find_all($num, $start) as $tag) { $tags[] = rest::url("tag", $tag); -- 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/tag/helpers') 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 5335e4c0b4bffeeeb8667ed706b5e8702de00ce9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 27 Jun 2010 11:25:31 -0700 Subject: Fix the autocomplete callback in item_edit_form(). We were incorrectly matching the form input in the jQuery selector. Did this ever work? Fixes ticket #1168 --- modules/tag/helpers/tag_event.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index a790b930..1a593d3f 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -67,8 +67,8 @@ class tag_event_Core { static function item_edit_form($item, $form) { $url = url::site("tags/autocomplete"); $form->script("") - ->text("$('form input[id=tags]').ready(function() { - $('form input[id=tags]').autocomplete( + ->text("$('form input[name=tags]').ready(function() { + $('form input[name=tags]').autocomplete( '$url', {max: 30, multiple: true, multipleSeparator: ',', cacheLength: 1}); });"); -- cgit v1.2.3 From f75ce45b6b6b848840d9a1688ca382a49de4f338 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 27 Jun 2010 12:14:56 -0700 Subject: When detecting encodings, give priority to ISO-8859-1 which seems to solve the umlaut problem in IPTC data. Fixes ticket #1144. --- modules/exif/helpers/exif.php | 6 ++++-- modules/tag/helpers/tag_event.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/exif/helpers/exif.php b/modules/exif/helpers/exif.php index 943feba7..aa77b42e 100644 --- a/modules/exif/helpers/exif.php +++ b/modules/exif/helpers/exif.php @@ -36,7 +36,8 @@ class exif_Core { foreach(self::_keys() as $field => $exifvar) { if (isset($exif_raw[$exifvar[0]][$exifvar[1]])) { $value = $exif_raw[$exifvar[0]][$exifvar[1]]; - if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { + if (function_exists("mb_detect_encoding") && + mb_detect_encoding($value, "ISO-8859-1, UTF-8") != "UTF-8") { $value = utf8_encode($value); } $keys[$field] = Input::clean($value); @@ -59,7 +60,8 @@ class exif_Core { foreach (array("Keywords" => "2#025", "Caption" => "2#120") as $keyword => $iptc_key) { if (!empty($iptc[$iptc_key])) { $value = implode(" ", $iptc[$iptc_key]); - if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") { + if (function_exists("mb_detect_encoding") && + mb_detect_encoding($value, "ISO-8859-1, UTF-8") != "UTF-8") { $value = utf8_encode($value); } $keys[$keyword] = Input::clean($value); diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 1a593d3f..7fe9fba3 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -36,7 +36,8 @@ class tag_event_Core { $tag = str_replace("\0", "", $tag); foreach (explode(",", $tag) as $word) { $word = trim($word); - if (function_exists("mb_detect_encoding") && mb_detect_encoding($word) != "UTF-8") { + if (function_exists("mb_detect_encoding") && + mb_detect_encoding($word, "ISO-8859-1, UTF-8") != "UTF-8") { $word = utf8_encode($word); } $tags[$word] = 1; -- cgit v1.2.3