From fa6f233603267505c216abc4f12663d245cd23e7 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 27 Mar 2011 11:31:34 -0700 Subject: Centralize our encoding code into a new helpers and use mb_convert_encoding if possible. Build on the work in c791ae96d5bb28f39b26a0e556e10e636f97436c by momo-i. Fixes #1660. --- modules/tag/helpers/tag_event.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index cd79f734..efef916f 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -36,10 +36,7 @@ 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, "ISO-8859-1, UTF-8") != "UTF-8") { - $word = utf8_encode($word); - } + $word = encoding::convert_to_utf8($word); $tags[$word] = 1; } } -- cgit v1.2.3 From 074f801acdd7d7b1a0a0a5e4ac8c5badfc253cad Mon Sep 17 00:00:00 2001 From: Joe7 Date: Sat, 2 Apr 2011 18:52:54 +0200 Subject: Fix against Ticket #1666 --- modules/tag/helpers/tag_event.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index efef916f..df81ae65 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -110,11 +110,11 @@ class tag_event_Core { } static function add_photos_form($album, $form) { - if (!isset($group->uploadify)) { + $group = $form->add_photos; + if (!is_object($group->uploadify)) { return; } - $group = $form->add_photos; $group->input("tags") ->label(t("Add tags to all uploaded files")) ->value(""); @@ -133,7 +133,8 @@ class tag_event_Core { } static function add_photos_form_completed($album, $form) { - if (!isset($group->uploadify)) { + $group = $form->add_photos; + if (!is_object($group->uploadify)) { return; } -- cgit v1.2.3 From 5b927a7083c8886a42519f9199666431bac0b650 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 4 Apr 2011 17:45:09 -0700 Subject: Guard against registered users removing tags from items they don't own. Fixes #1671. --- modules/tag/helpers/tag_item_rest.php | 1 + modules/tag/helpers/tag_items_rest.php | 1 + 2 files changed, 2 insertions(+) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag_item_rest.php b/modules/tag/helpers/tag_item_rest.php index a8d3d0bc..be1fa653 100644 --- a/modules/tag/helpers/tag_item_rest.php +++ b/modules/tag/helpers/tag_item_rest.php @@ -29,6 +29,7 @@ class tag_item_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_items_rest.php b/modules/tag/helpers/tag_items_rest.php index 535ab513..8ed07276 100644 --- a/modules/tag/helpers/tag_items_rest.php +++ b/modules/tag/helpers/tag_items_rest.php @@ -51,6 +51,7 @@ class tag_items_rest_Core { static function delete($request) { list ($tag, $item) = rest::resolve($request->url); + access::required("edit", $item); $tag->remove($item); $tag->save(); } -- cgit v1.2.3 From 8cf066b838a98ace3cfa81e02ccc7a8570d1ba7f Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 21 Apr 2011 15:43:48 -0700 Subject: Use Tag_Model::url() instead of hand creating tag urls, since the API changed and that broke. Fixe #1680. --- modules/tag/helpers/tag_event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index df81ae65..b415b42d 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -149,7 +149,7 @@ class tag_event_Core { static function info_block_get_metadata($block, $item) { $tags = array(); foreach (tag::item_tags($item) as $tag) { - $tags[] = "name}") . "\">{$tag->name}"; + $tags[] = "url()}\">{$tag->name}"; } if ($tags) { $info = $block->content->metadata; -- cgit v1.2.3 From b07bc1af082ea097adb77d2e78e69af3e20d8d29 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Apr 2011 16:15:56 -0700 Subject: Allow the administrator to set the number of tags to display in the cloud via the advanced settings. Fixes ticket #1649. --- installer/install.sql | 143 +++++++++++++++++----------------- modules/tag/controllers/tags.php | 3 +- modules/tag/helpers/tag_block.php | 2 +- modules/tag/helpers/tag_installer.php | 7 +- modules/tag/module.info | 2 +- 5 files changed, 82 insertions(+), 75 deletions(-) (limited to 'modules/tag/helpers') diff --git a/installer/install.sql b/installer/install.sql index 5dc09cca..ff29e1a0 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -1,6 +1,6 @@ DROP TABLE IF EXISTS {access_caches}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {access_caches} ( `id` int(9) NOT NULL AUTO_INCREMENT, `item_id` int(9) DEFAULT NULL, @@ -13,11 +13,11 @@ CREATE TABLE {access_caches} ( PRIMARY KEY (`id`), KEY `item_id` (`item_id`) ) AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {access_caches} VALUES (1,1,'1','0','0','1','0','0'); DROP TABLE IF EXISTS {access_intents}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {access_intents} ( `id` int(9) NOT NULL AUTO_INCREMENT, `item_id` int(9) DEFAULT NULL, @@ -31,11 +31,11 @@ CREATE TABLE {access_intents} ( `add_2` binary(1) DEFAULT NULL, PRIMARY KEY (`id`) ) AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {access_intents} VALUES (1,1,'1','1','0','0','1','1','0','0'); DROP TABLE IF EXISTS {caches}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {caches} ( `id` int(9) NOT NULL AUTO_INCREMENT, `key` varchar(255) NOT NULL, @@ -46,10 +46,10 @@ CREATE TABLE {caches} ( UNIQUE KEY `key` (`key`), KEY `tags` (`tags`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {comments}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {comments} ( `author_id` int(9) DEFAULT NULL, `created` int(9) NOT NULL, @@ -75,10 +75,10 @@ CREATE TABLE {comments} ( `updated` int(9) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {failed_auths}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {failed_auths} ( `id` int(9) NOT NULL AUTO_INCREMENT, `count` int(9) NOT NULL, @@ -86,10 +86,10 @@ CREATE TABLE {failed_auths} ( `time` int(9) NOT NULL, PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {graphics_rules}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {graphics_rules} ( `id` int(9) NOT NULL AUTO_INCREMENT, `active` tinyint(1) DEFAULT '0', @@ -100,12 +100,12 @@ CREATE TABLE {graphics_rules} ( `target` varchar(32) NOT NULL, PRIMARY KEY (`id`) ) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'thumb'); INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:640;s:6:\"master\";i:2;}','gallery','gallery_graphics::resize',100,'resize'); DROP TABLE IF EXISTS {groups}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {groups} ( `id` int(9) NOT NULL AUTO_INCREMENT, `name` char(64) DEFAULT NULL, @@ -113,25 +113,25 @@ CREATE TABLE {groups} ( PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {groups} VALUES (1,'Everybody',1); INSERT INTO {groups} VALUES (2,'Registered Users',1); DROP TABLE IF EXISTS {groups_users}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {groups_users} ( `group_id` int(9) NOT NULL, `user_id` int(9) NOT NULL, PRIMARY KEY (`group_id`,`user_id`), UNIQUE KEY `user_id` (`user_id`,`group_id`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {groups_users} VALUES (1,1); INSERT INTO {groups_users} VALUES (1,2); INSERT INTO {groups_users} VALUES (2,2); DROP TABLE IF EXISTS {incoming_translations}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {incoming_translations} ( `id` int(9) NOT NULL AUTO_INCREMENT, `key` char(32) NOT NULL, @@ -143,10 +143,10 @@ CREATE TABLE {incoming_translations} ( UNIQUE KEY `key` (`key`,`locale`), KEY `locale_key` (`locale`,`key`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {items}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {items} ( `id` int(9) NOT NULL AUTO_INCREMENT, `album_cover_item_id` int(9) DEFAULT NULL, @@ -188,11 +188,11 @@ CREATE TABLE {items} ( KEY `weight` (`weight`), KEY `left_ptr` (`left_ptr`) ) AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {items} VALUES (1,NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,NULL,NULL,2,0,NULL,'','',1,NULL,NULL,2,NULL,'weight','ASC',1,NULL,NULL,'Gallery','album',UNIX_TIMESTAMP(),0,1,NULL,'1','1'); DROP TABLE IF EXISTS {items_tags}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {items_tags} ( `id` int(9) NOT NULL AUTO_INCREMENT, `item_id` int(9) NOT NULL, @@ -201,10 +201,10 @@ CREATE TABLE {items_tags} ( KEY `tag_id` (`tag_id`,`id`), KEY `item_id` (`item_id`,`id`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {logs}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {logs} ( `id` int(9) NOT NULL AUTO_INCREMENT, `category` varchar(64) DEFAULT NULL, @@ -217,10 +217,10 @@ CREATE TABLE {logs} ( `user_id` int(9) DEFAULT '0', PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {messages}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {messages} ( `id` int(9) NOT NULL AUTO_INCREMENT, `key` varchar(255) DEFAULT NULL, @@ -229,10 +229,10 @@ CREATE TABLE {messages} ( PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {modules}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {modules} ( `id` int(9) NOT NULL AUTO_INCREMENT, `active` tinyint(1) DEFAULT '0', @@ -243,7 +243,7 @@ CREATE TABLE {modules} ( UNIQUE KEY `name` (`name`), KEY `weight` (`weight`) ) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {modules} VALUES (1,1,'gallery',47,1); INSERT INTO {modules} VALUES (2,1,'user',3,2); INSERT INTO {modules} VALUES (3,1,'comment',4,3); @@ -252,10 +252,10 @@ INSERT INTO {modules} VALUES (5,1,'info',2,5); INSERT INTO {modules} VALUES (6,1,'rss',1,6); INSERT INTO {modules} VALUES (7,1,'search',1,7); INSERT INTO {modules} VALUES (8,1,'slideshow',2,8); -INSERT INTO {modules} VALUES (9,1,'tag',2,9); +INSERT INTO {modules} VALUES (9,1,'tag',3,9); DROP TABLE IF EXISTS {outgoing_translations}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {outgoing_translations} ( `id` int(9) NOT NULL AUTO_INCREMENT, `base_revision` int(9) DEFAULT NULL, @@ -267,10 +267,10 @@ CREATE TABLE {outgoing_translations} ( UNIQUE KEY `key` (`key`,`locale`), KEY `locale_key` (`locale`,`key`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {permissions}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {permissions} ( `id` int(9) NOT NULL AUTO_INCREMENT, `display_name` varchar(64) DEFAULT NULL, @@ -278,14 +278,14 @@ CREATE TABLE {permissions} ( PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {permissions} VALUES (1,'View','view'); INSERT INTO {permissions} VALUES (2,'View full size','view_full'); INSERT INTO {permissions} VALUES (3,'Edit','edit'); INSERT INTO {permissions} VALUES (4,'Add','add'); DROP TABLE IF EXISTS {search_records}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {search_records} ( `id` int(9) NOT NULL AUTO_INCREMENT, `item_id` int(9) DEFAULT NULL, @@ -295,21 +295,21 @@ CREATE TABLE {search_records} ( KEY `item_id` (`item_id`), FULLTEXT KEY `data` (`data`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {search_records} VALUES (1,1,0,' Gallery'); DROP TABLE IF EXISTS {sessions}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {sessions} ( `session_id` varchar(127) NOT NULL, `data` text NOT NULL, `last_activity` int(10) unsigned NOT NULL, PRIMARY KEY (`session_id`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {tags}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {tags} ( `id` int(9) NOT NULL AUTO_INCREMENT, `name` varchar(128) NOT NULL, @@ -317,10 +317,10 @@ CREATE TABLE {tags} ( PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {tasks}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {tasks} ( `id` int(9) NOT NULL AUTO_INCREMENT, `callback` varchar(128) DEFAULT NULL, @@ -335,10 +335,10 @@ CREATE TABLE {tasks} ( PRIMARY KEY (`id`), KEY `owner_id` (`owner_id`) ) DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {themes}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {themes} ( `id` int(9) NOT NULL AUTO_INCREMENT, `name` varchar(64) DEFAULT NULL, @@ -346,12 +346,12 @@ CREATE TABLE {themes} ( PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +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 {users}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {users} ( `id` int(9) NOT NULL AUTO_INCREMENT, `name` varchar(32) NOT NULL, @@ -369,12 +369,12 @@ CREATE TABLE {users} ( UNIQUE KEY `name` (`name`), UNIQUE KEY `hash` (`hash`) ) AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +SET character_set_client = @saved_cs_client; INSERT INTO {users} VALUES (1,'guest','Guest User','',0,0,NULL,0,1,NULL,NULL,NULL); INSERT INTO {users} VALUES (2,'admin','Gallery Administrator','',0,0,'unknown@unknown.com',1,0,NULL,NULL,NULL); DROP TABLE IF EXISTS {vars}; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; CREATE TABLE {vars} ( `id` int(9) NOT NULL AUTO_INCREMENT, `module_name` varchar(64) NOT NULL, @@ -382,8 +382,8 @@ CREATE TABLE {vars} ( `value` text, PRIMARY KEY (`id`), UNIQUE KEY `module_name` (`module_name`,`name`) -) AUTO_INCREMENT=41 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; +) AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; +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'); INSERT INTO {vars} VALUES (NULL,'gallery','page_size','9'); @@ -424,3 +424,4 @@ INSERT INTO {vars} VALUES (NULL,'info','show_owner','1'); INSERT INTO {vars} VALUES (NULL,'info','show_name','1'); INSERT INTO {vars} VALUES (NULL,'info','show_captured','1'); INSERT INTO {vars} VALUES (NULL,'slideshow','max_scale','0'); +INSERT INTO {vars} VALUES (NULL,'tag','tag_cloud_size','30'); diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index fe6d747b..bf41c4df 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -22,7 +22,8 @@ class Tags_Controller extends Controller { // Far from perfection, but at least require view permission for the root album $album = ORM::factory("item", 1); access::required("view", $album); - print tag::cloud(30); + + print tag::cloud(module::get_var("tag", "tag_cloud_size", 30)); } public function create($item_id) { diff --git a/modules/tag/helpers/tag_block.php b/modules/tag/helpers/tag_block.php index 8df58a6e..69a9a1c4 100644 --- a/modules/tag/helpers/tag_block.php +++ b/modules/tag/helpers/tag_block.php @@ -30,7 +30,7 @@ class tag_block_Core { $block->css_id = "g-tag"; $block->title = t("Popular tags"); $block->content = new View("tag_block.html"); - $block->content->cloud = tag::cloud(30); + $block->content->cloud = tag::cloud(module::get_var("tag", "tag_cloud_size", 30)); if ($theme->item() && $theme->page_subtype() != "tag" && access::can("edit", $theme->item())) { $controller = new Tags_Controller(); diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php index 16ad1239..66a78b91 100644 --- a/modules/tag/helpers/tag_installer.php +++ b/modules/tag/helpers/tag_installer.php @@ -36,7 +36,8 @@ class tag_installer { KEY(`tag_id`, `id`), KEY(`item_id`, `id`)) DEFAULT CHARSET=utf8;"); - module::set_version("tag", 2); + module::set_var("tag", "tag_cloud_size", 30); + module::set_version("tag", 3); } static function upgrade($version) { @@ -45,6 +46,10 @@ class tag_installer { $db->query("ALTER TABLE {tags} MODIFY COLUMN `name` VARCHAR(128)"); module::set_version("tag", $version = 2); } + if ($version == 2) { + module::set_var("tag", "tag_cloud_size", 30); + module::set_version("tag", $version = 3); + } } static function uninstall() { diff --git a/modules/tag/module.info b/modules/tag/module.info index 8851d119..d9d34386 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 = 2 +version = 3 -- cgit v1.2.3 From 9dd91b55b03923ef3058fb965b0c927d101a396f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 23 Apr 2011 07:42:28 -0700 Subject: Insure that the tag count to display is always greater than 1. Refixes #1649. --- modules/tag/helpers/tag.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 733215b3..742783d1 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -48,6 +48,7 @@ class tag_Core { * @return ORM_Iterator of Tag_Model in descending tag count order */ static function popular_tags($count) { + $count = $count >= 1 ? $count : 30; return ORM::factory("tag") ->order_by("count", "DESC") ->limit($count) -- cgit v1.2.3 From 0ec819d38161ead063c4dbd953b4b55a33a42f80 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 23 Apr 2011 07:46:38 -0700 Subject: Insure that the tag count to display is always greater than 0. Refixes #1649. --- modules/tag/helpers/tag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/tag/helpers') diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index 742783d1..c21104ee 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -48,7 +48,7 @@ class tag_Core { * @return ORM_Iterator of Tag_Model in descending tag count order */ static function popular_tags($count) { - $count = $count >= 1 ? $count : 30; + $count = max($count, 1); return ORM::factory("tag") ->order_by("count", "DESC") ->limit($count) -- cgit v1.2.3 From 933a34986dbca248f388e8aa3c3aea4a6d71a94b Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 11 Aug 2011 22:04:20 -0700 Subject: Patch for tickets #1428 and #1760 Create the concept of a Photo_Display_Context. If the user is browsing a dynamic album (i.e. tags) and chooses to look at an image in that album. The display of the image happens correctly, but the 'next' and 'previous' buttons are no longer consistent. When one of these is clicked, Gallery will open the adjacent image in the actuall album, not the dynamic album. --- modules/gallery/controllers/albums.php | 3 + modules/gallery/controllers/movies.php | 23 ++----- modules/gallery/controllers/photos.php | 23 ++----- modules/gallery/libraries/Display_Context.php | 71 ++++++++++++++++++++++ modules/gallery/libraries/Item_Display_Context.php | 44 ++++++++++++++ modules/search/controllers/search.php | 21 ++++++- modules/search/helpers/search.php | 45 +++++++++++--- .../search/libraries/Search_Display_Context.php | 52 ++++++++++++++++ modules/tag/controllers/tag.php | 22 ++++++- modules/tag/helpers/tag.php | 19 ++++++ modules/tag/libraries/Tag_Display_Context.php | 49 +++++++++++++++ modules/tag/models/tag.php | 38 ++++++------ 12 files changed, 344 insertions(+), 66 deletions(-) create mode 100644 modules/gallery/libraries/Display_Context.php create mode 100644 modules/gallery/libraries/Item_Display_Context.php create mode 100644 modules/search/libraries/Search_Display_Context.php create mode 100644 modules/tag/libraries/Tag_Display_Context.php (limited to 'modules/tag/helpers') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 1c48c734..9bf7b9bf 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -60,6 +60,9 @@ class Albums_Controller extends Items_Controller { url::redirect($album->abs_url("page=$max_pages")); } + Display_Context::factory("item") + ->save(); + $template = new Theme_View("page.html", "collection", "album"); $template->set_global( array("page" => $page, diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 0f12c3fb..bbf89f17 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -27,27 +27,12 @@ class Movies_Controller extends Items_Controller { access::required("view", $movie); - $where = array(array("type", "!=", "album")); - $position = item::get_position($movie, $where); - if ($position > 1) { - list ($previous_item, $ignore, $next_item) = - $movie->parent()->viewable()->children(3, $position - 2, $where); - } else { - $previous_item = null; - list ($next_item) = $movie->parent()->viewable()->children(1, $position, $where); - } - $template = new Theme_View("page.html", "item", "movie"); $template->set_global( - array("item" => $movie, - "children" => array(), - "children_count" => 0, - "parents" => $movie->parents()->as_array(), - "breadcrumbs" => Breadcrumb::array_from_item_parents($movie), - "next_item" => $next_item, - "previous_item" => $previous_item, - "sibling_count" => $movie->parent()->viewable()->children_count($where), - "position" => $position)); + array_merge(array("item" => $movie, + "children" => array(), + "children_count" => 0), + Display_Context::factory()->display_context($movie))); $template->content = new View("movie.html"); diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index af8aed16..49bb5a25 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -27,27 +27,12 @@ class Photos_Controller extends Items_Controller { access::required("view", $photo); - $where = array(array("type", "!=", "album")); - $position = item::get_position($photo, $where); - if ($position > 1) { - list ($previous_item, $ignore, $next_item) = - $photo->parent()->viewable()->children(3, $position - 2, $where); - } else { - $previous_item = null; - list ($next_item) = $photo->parent()->viewable()->children(1, $position, $where); - } - $template = new Theme_View("page.html", "item", "photo"); $template->set_global( - array("item" => $photo, - "children" => array(), - "children_count" => 0, - "parents" => $photo->parents()->as_array(), - "breadcrumbs" => Breadcrumb::array_from_item_parents($photo), - "next_item" => $next_item, - "previous_item" => $previous_item, - "sibling_count" => $photo->parent()->viewable()->children_count($where), - "position" => $position)); + array_merge(array("item" => $photo, + "children" => array(), + "children_count" => 0), + Display_Context::factory()->display_context($photo))); $template->content = new View("photo.html"); diff --git a/modules/gallery/libraries/Display_Context.php b/modules/gallery/libraries/Display_Context.php new file mode 100644 index 00000000..5054cffb --- /dev/null +++ b/modules/gallery/libraries/Display_Context.php @@ -0,0 +1,71 @@ +get("display_context_id", ""); + $context = Cache::instance()->get($display_context_id, null); + $context = empty($context) ? new Item_Display_Context() : unserialize($context); + } else { + $class_prefix = ucfirst(strtolower($display_context_name)); + $class_name = "{$class_prefix}_Display_Context"; + $context = new $class_name(); + } + + return $context; + } + + protected function __construct($display_context_name) { + // $this->reset($display_context_name); + $this->_data = array(); + $this->_display_context_name = $display_context_name; + } + + final function get($key) { + return empty($this->_data[$key]) ? null : $this->_data[$key]; + } + + final function set($key, $value=null) { + if (is_array($key)) { + if ((array)$key == $key) { + $this->_data = array_merge($this->_data, $key); + } else { + $this->_data = array_merge($this->_data, array_fill_keys($key, $value)); + } + } else { + $this->_data[$key] = $value; + } + return $this; + } + + final function save() { + $context_data = serialize($this); + $display_context_id = "display_context_" . md5($context_data); + Session::instance()->set("display_context_id", $display_context_id); + Cache::instance()->set($display_context_id, $context_data); + return $this; + } + + abstract function display_context($item); +} diff --git a/modules/gallery/libraries/Item_Display_Context.php b/modules/gallery/libraries/Item_Display_Context.php new file mode 100644 index 00000000..d0562790 --- /dev/null +++ b/modules/gallery/libraries/Item_Display_Context.php @@ -0,0 +1,44 @@ + 1) { + list ($previous_item, $ignore, $next_item) = + $item->parent()->viewable()->children(3, $position - 2, $where); + } else { + $previous_item = null; + list ($next_item) = $item->parent()->viewable()->children(1, $position, $where); + } + + return array("position" =>$position, + "previous_item" => $previous_item, + "next_item" =>$next_item, + "sibling_count" => $item->parent()->viewable()->children_count($where), + "parents" => $item->parents()->as_array(), + "breadcrumbs" => Breadcrumb::array_from_item_parents($item)); + } +} diff --git a/modules/search/controllers/search.php b/modules/search/controllers/search.php index 5db63ab0..1d5a55bf 100644 --- a/modules/search/controllers/search.php +++ b/modules/search/controllers/search.php @@ -21,6 +21,18 @@ class Search_Controller extends Controller { public function index() { $page_size = module::get_var("gallery", "page_size", 9); $q = Input::instance()->get("q"); + $q_with_more_terms = search::add_query_terms($q); + $show = Input::instance()->get("show"); + + if ($show) { + $child = ORM::factory("item", $show); + $index = search::get_position($child, $q_with_more_terms); + if ($index) { + $page = ceil($index / $page_size); + url::redirect( url::abs_site("search?q=" . urlencode($q) . ($page == 1 ? "" : "&page=$page"))); + } + } + $page = Input::instance()->get("page", 1); // Make sure that the page references a valid offset @@ -30,11 +42,18 @@ class Search_Controller extends Controller { $offset = ($page - 1) * $page_size; - $q_with_more_terms = search::add_query_terms($q); list ($count, $result) = search::search($q_with_more_terms, $page_size, $offset); + $title = t("Search: %q", array("q" => $q_with_more_terms)); + $max_pages = max(ceil($count / $page_size), 1); + Display_Context::factory("search") + ->set(array("title" => $title, + "query_terms" => $q_with_more_terms, + "q" => $q)) + ->save(); + $template = new Theme_View("page.html", "collection", "search"); $root = item::root(); $template->set_global( diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php index a3fd795a..a77a2433 100644 --- a/modules/search/helpers/search.php +++ b/modules/search/helpers/search.php @@ -36,8 +36,19 @@ class search_Core { static function search($q, $limit, $offset) { $db = Database::instance(); - $q = $db->escape($q); + $query = self::_build_query_base($q) . + "ORDER BY `score` DESC " . + "LIMIT $limit OFFSET " . (int)$offset; + + $data = $db->query($query); + $count = $db->query("SELECT FOUND_ROWS() as c")->current()->c; + + return array($count, new ORM_Iterator(ORM::factory("item"), $data)); + } + + private static function _build_query_base($q, $where=array()) { + $q = Database::instance()->escape($q); if (!identity::active_user()->admin) { foreach (identity::group_ids_for_active_user() as $id) { $fields[] = "`view_$id` = TRUE"; // access::ALLOW @@ -47,18 +58,13 @@ class search_Core { $access_sql = ""; } - $query = + return "SELECT SQL_CALC_FOUND_ROWS {items}.*, " . " MATCH({search_records}.`data`) AGAINST ('$q') AS `score` " . "FROM {items} JOIN {search_records} ON ({items}.`id` = {search_records}.`item_id`) " . "WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " . - $access_sql . - "ORDER BY `score` DESC " . - "LIMIT $limit OFFSET " . (int)$offset; - $data = $db->query($query); - $count = $db->query("SELECT FOUND_ROWS() as c")->current()->c; - - return array($count, new ORM_Iterator(ORM::factory("item"), $data)); + (empty($where) ? "" : " AND " . join(" AND ", $where)) . + $access_sql; } /** @@ -103,4 +109,25 @@ class search_Core { return array($remaining, $total, $percent); } + + static function get_position($item, $q) { + $page_size = module::get_var("gallery", "page_size", 9); + + $query = self::_build_query_base($q, array("{items}.id = " . $item->id)); + + $db = Database::instance(); + + // Truncate the score by two decimal places as this resolves the issues + // that arise due to in exact numeric conversions. + $score = $db->query($query)->current()->score; + $score = substr($score, 0, strlen($score) - 2); + + $data = $db->query(self::_build_query_base($q) . "having `score` >= " . $score); + + $data->seek($data->count() - 1); + + while ($data->get("id") != $item->id && $data->prev()->valid()); + + return $data->key() + 1; + } } diff --git a/modules/search/libraries/Search_Display_Context.php b/modules/search/libraries/Search_Display_Context.php new file mode 100644 index 00000000..aed3a125 --- /dev/null +++ b/modules/search/libraries/Search_Display_Context.php @@ -0,0 +1,52 @@ +get("query_terms")); + + if ($position > 1) { + list ($count, $result_data) = + search::search($this->get("query_terms"), 3, $position - 2); + list ($previous_item, $ignore, $next_item) = $result_data; + } else { + $previous_item = null; + list ($count, $result_data) = search::search($this->get("query_terms"), 1, $position); + list ($next_item) = $result_data; + } + + $q = $this->get("q"); + $search_url = url::abs_site("search?q=" . urlencode($q) . "&show={$item->id}"); + $root = item::root(); + + return array("position" =>$position, + "previous_item" => $previous_item, + "next_item" =>$next_item, + "sibling_count" => $count, + "breadcrumbs" => array( + Breadcrumb::instance($root->title, "/", $root->id), + Breadcrumb::instance($q, $search_url), + Breadcrumb::instance($item->title, $item->url()))); + } +} diff --git a/modules/tag/controllers/tag.php b/modules/tag/controllers/tag.php index 7786daa1..06e2b5ed 100644 --- a/modules/tag/controllers/tag.php +++ b/modules/tag/controllers/tag.php @@ -22,7 +22,22 @@ class Tag_Controller extends Controller { $tag_id = $function; $tag = ORM::factory("tag")->where("id", "=", $tag_id)->find(); $page_size = module::get_var("gallery", "page_size", 9); - $page = (int) Input::instance()->get("page", "1"); + + $input = Input::instance(); + $show = $input->get("show"); + + if ($show) { + $child = ORM::factory("item", $show); + $index = tag::get_position($tag, $child); + if ($index) { + $page = ceil($index / $page_size); + $uri = "tag/$tag_id/" . urlencode($tag->name); + url::redirect($uri . ($page == 1 ? "" : "?page=$page")); + } + } else { + $page = (int) $input->get("page", "1"); + } + $children_count = $tag->items_count(); $offset = ($page-1) * $page_size; $max_pages = max(ceil($children_count / $page_size), 1); @@ -35,6 +50,11 @@ class Tag_Controller extends Controller { } $root = item::root(); + $title = t("Tag: %tag_name", array("tag_name" => $tag->name)); + Display_Context::factory("tag") + ->set(array("tag" => $tag)) + ->save(); + $template = new Theme_View("page.html", "collection", "tag"); $template->set_global( array("page" => $page, diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index c21104ee..83a00080 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -136,4 +136,23 @@ class tag_Core { // extremely rare case. db::build()->delete("tags")->where("count", "=", 0)->execute(); } + + /** + * Find the position of the given item in the tag collection. The resulting + * value is 1-indexed, so the first child in the album is at position 1. + * + * @param Tag_Model $tag + * @param Item_Model $item + * @param array $where an array of arrays, each compatible with ORM::where() + */ + static function get_position($tag, $item, $where=array()) { + return ORM::factory("item") + ->viewable() + ->join("items_tags", "items.id", "items_tags.item_id") + ->where("items_tags.tag_id", "=", $tag->id) + ->where("items.id", "<=", $item->id) + ->merge_where($where) + ->order_by("items.id") + ->count_all(); + } } \ No newline at end of file diff --git a/modules/tag/libraries/Tag_Display_Context.php b/modules/tag/libraries/Tag_Display_Context.php new file mode 100644 index 00000000..47c79088 --- /dev/null +++ b/modules/tag/libraries/Tag_Display_Context.php @@ -0,0 +1,49 @@ +get("tag"); + + $where = array(array("type", "!=", "album")); + + $position = tag::get_position($tag, $item, $where); + if ($position > 1) { + list ($previous_item, $ignore, $next_item) = $tag->items(3, $position - 2, $where); + } else { + $previous_item = null; + list ($next_item) = $tag->items(1, $position, $where); + } + + $root = item::root(); + return array("position" =>$position, + "previous_item" => $previous_item, + "next_item" =>$next_item, + "sibling_count" => $tag->items_count($where), + "breadcrumbs" => array( + Breadcrumb::instance($root->title, $root->url())->set_first(), + Breadcrumb::instance($tag->name, $tag->url("show={$item->id}")), + Breadcrumb::instance($item->title, $item->url())->set_last())); + } +} diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index bb79e707..a7150df8 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -33,35 +33,39 @@ class Tag_Model_Core extends ORM { * Return all viewable items associated with this tag. * @param integer $limit number of rows to limit result to * @param integer $offset offset in result to start returning rows from - * @param string $type the type of item (album, photo) + * @param string $where an array of arrays, each compatible with ORM::where() * @return ORM_Iterator */ - public function items($limit=null, $offset=null, $type=null) { - $model = ORM::factory("item") + public function items($limit=null, $offset=null, $where=array()) { + if (is_scalar($where)) { + // backwards compatibility + $where = array(array("items.type", "=", $where)); + } + return ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", "=", $this->id); - if ($type) { - $model->where("items.type", "=", $type); - } - return $model->find_all($limit, $offset); + ->where("items_tags.tag_id", "=", $this->id) + ->merge_where($where) + ->order_by("items.id") + ->find_all($limit, $offset); } /** * Return the count of all viewable items associated with this tag. - * @param string $type the type of item (album, photo) + * @param string $where an array of arrays, each compatible with ORM::where() * @return integer */ - public function items_count($type=null) { - $model = ORM::factory("item") + public function items_count($where=array()) { + if (is_scalar($where)) { + // backwards compatibility + $where = array(array("items.type", "=", $where)); + } + return $model = ORM::factory("item") ->viewable() ->join("items_tags", "items.id", "items_tags.item_id") - ->where("items_tags.tag_id", "=", $this->id); - - if ($type) { - $model->where("items.type", "=", $type); - } - return $model->count_all(); + ->where("items_tags.tag_id", "=", $this->id) + ->merge_where($where) + ->count_all(); } /** -- cgit v1.2.3