From d27079ca9f101b9b7b3743f2caeefb3fc9acdd48 Mon Sep 17 00:00:00 2001 From: Justin Brewer Date: Wed, 7 Aug 2013 14:15:04 -0500 Subject: [PATCH 01/10] Cleanup build_tag_map Millions of temp variables. Assuming there's only two sorting methods. Grammar. [show 100 more problems] --- ext/tag_editcloud/main.php | 98 +++++++++++++++++-------------------- ext/tag_editcloud/script.js | 11 +++-- 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index 233dcf68..bacc0592 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -9,24 +9,14 @@ * Be less kludgy * $cfgstub->board prefs * toggle sorting method via javascript || usepref(todo2: port userpref) - * colorize used tags in cloud || always show used tags in front of cloud * theme junk */ class TagEditCloud extends Extension { public function onImageInfoBoxBuilding(ImageInfoBoxBuildingEvent $event) { global $config; - if(!$config->get_bool("tageditcloud_disable")) { - if($this->can_tag($event->image)) { - if(!$cfg_minusage=$config->get_int("tageditcloud_minusage")) $cfg_minusage=2; - if(!$cfg_defcount=$config->get_int("tageditcloud_defcount")) $cfg_defcount=40; - if(!$cfg_maxcount=$config->get_int("tageditcloud_maxcount")) $cfg_maxcount=4096; - if($config->get_string("tageditcloud_sort") != "p") { - $event->add_part($this->build_tag_map($event->image,$cfg_minusage,false),40); - } else { - $event->add_part($this->build_tag_map($event->image,$cfg_defcount,$cfg_maxcount),40); - } - } + if(!$config->get_bool("tageditcloud_disable") && $this->can_tag($event->image)) { + $event->add_part($this->build_tag_map($event->image),40); } } @@ -62,61 +52,63 @@ class TagEditCloud extends Extension { $u_tag = url_escape($tag); return make_link("post/list/$u_tag/1"); } -///// build_tag_map: output cloud of clickable tags -// build_tag_map($image|false, $defcount, $maxcount|false) -- taglist sorted by usage, displaying $defcount by default, up to $maxcount via toggle. -// build_tag_map($image|false, $minusage|false) -- taglist sorted by alpha, only showing tags with usage >= $minusage - private function build_tag_map($image,$defcount,$maxcount) { // - global $database,$config; - $html="";$cloud="";$precloud=""; - $itags=Array(); - $tags_min=1; - $alphasort=false; - $usedfirst=$config->get_bool("tageditcloud_usedfirst"); + private function build_tag_map($image) { // + global $database, $config; - if(!is_int($defcount)) $defcount=20; - if(!is_int($maxcount)) { // Derp this is pretty cheesy. - $maxcount=4096; // Hurrrr - $tags_min=$defcount; - $alphasort=true; + $html = ""; + $cloud = ""; + $precloud = ""; + + $sort_method = $config->get_string("tageditcloud_sort"); + $tags_min = $config->get_int("tageditcloud_minusage"); + $used_first = $config->get_bool("tageditcloud_usedfirst"); + $max_count = $config->get_int("tageditcloud_maxcount"); + $def_count = $config->get_int("tageditcloud_defcount"); + + switch($sort_method){ + case 'a': + case 'p': + $tag_data = $database->get_all("SELECT tag, FLOOR(LN(LN(count - :tag_min1 + 1)+1)*150)/200 AS scaled, count + FROM tags WHERE count >= :tag_min2 ORDER BY ".($sort_method == 'a' ? "tag" : "count DESC")." LIMIT :limit", + array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); + break; } - - if ((gettype($image) == 'object') && (isset($image->tag_array)) && ($itags=$image->tag_array)) $itags=array_fill_keys(array_values($itags),true); - - $tag_data = $database->get_all(" SELECT tag, FLOOR(LOG(2.7, LOG(2.7, count - ? + 1)+1)*1.5*100)/100 AS scaled, count - FROM tags WHERE count >= ? ORDER BY ". - (!$alphasort ? "count DESC":"tag"). - " limit $maxcount", - array($tags_min,$tags_min) - ); - $counter=1; + $counter = 1; foreach($tag_data as $row) { - if((!$alphasort)&&($counter==$defcount)) $cloud .= "
"; + if($sort_method != 'a' && $counter == $def_count) { + $cloud .= "
[show $rem more tags]"; -// $html.='
'.var_export($itags,true).'
'; - return "
$html
"; // FIXME: stupidasallhell + + if($precloud != '') { + $html .= "
$precloud
"; + } + + $html .= "
$cloud
"; + + $rem = count($tag_data) - $def_count; + if($sort_method != 'a' && $counter >= $defcount) { + $html .= "

[show $rem more tags]"; + } + + return "
$html
"; // FIXME: stupidasallhell } diff --git a/ext/tag_editcloud/script.js b/ext/tag_editcloud/script.js index b0384a88..f7c84d94 100644 --- a/ext/tag_editcloud/script.js +++ b/ext/tag_editcloud/script.js @@ -18,10 +18,15 @@ Array.prototype.editcloud_remove = function (ele) { return arr; }; -function tageditcloud_toggle_extra(obj,hide) { - var el = document.getElementById(obj); +var hide_text = null; +function tageditcloud_toggle_extra(hide) { + if (hide_text == null) { + hide_text = hide.innerHTML; + } + + var el = document.getElementById('tagcloud_extra'); el.style.display = (el.style.display != 'none' ? 'none' : '' ); - hide.innerHTML=(el.style.display != 'none' ? 'show less tags' : 'show more tags' ); + hide.innerHTML = (el.style.display != 'none' ? 'show fewer tags' : hide_text ); } function tageditcloud_toggle_tag(ele) { From 905dc2df31e5dcbfd4afa57c24fb4e762283af71 Mon Sep 17 00:00:00 2001 From: Justin Brewer Date: Wed, 7 Aug 2013 14:47:44 -0500 Subject: [PATCH 02/10] Relevance sorting method --- ext/tag_editcloud/main.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index bacc0592..2c39750e 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -31,7 +31,7 @@ class TagEditCloud extends Extension { } public function onSetupBuilding(SetupBuildingEvent $event) { - $sort_by = array('Alphabetical'=>'a','Popularity'=>'p'); + $sort_by = array('Alphabetical'=>'a','Popularity'=>'p','Relevance'=>'r'); $sb = new SetupBlock("Tag Edit Cloud"); $sb->add_bool_option("tageditcloud_disable", "Disable Tag Selection Cloud: "); @@ -73,6 +73,13 @@ class TagEditCloud extends Extension { FROM tags WHERE count >= :tag_min2 ORDER BY ".($sort_method == 'a' ? "tag" : "count DESC")." LIMIT :limit", array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); break; + case 'r': + $relevant_tags = "'".implode("','",array_diff($image->tag_array,array('tagme')))."'"; //TODO: Make this configurable + $tag_data = $database->get_all("SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled + FROM image_tags it1 JOIN image_tags it2 USING(image_id) JOIN tags t1 ON it1.tag_id = t1.id JOIN tags t2 ON it2.tag_id = t2.id + WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags) GROUP BY t2.tag ORDER BY count DESC LIMIT :limit", + array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); + break; } $counter = 1; From e133138be260f97493b1e8f96806a8d824b39ef3 Mon Sep 17 00:00:00 2001 From: Justin Brewer Date: Wed, 7 Aug 2013 15:25:11 -0500 Subject: [PATCH 03/10] Config option for which tags to ignore --- ext/tag_editcloud/main.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index 2c39750e..56a5ec51 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -28,6 +28,7 @@ class TagEditCloud extends Extension { $config->set_default_int("tageditcloud_minusage",2); $config->set_default_int("tageditcloud_defcount",40); $config->set_default_int("tageditcloud_maxcount",4096); + $config->set_default_string("tageditcloud_ignoretags",'tagme'); } public function onSetupBuilding(SetupBuildingEvent $event) { @@ -39,11 +40,13 @@ class TagEditCloud extends Extension { $sb->add_bool_option("tageditcloud_usedfirst","
Always show used tags first: "); $sb->add_label("
Alpha sort:
Only show tags used at least "); $sb->add_int_option("tageditcloud_minusage"); - $sb->add_label(" times.
Popularity sort:
Show "); + $sb->add_label(" times.
Popularity/Relevance sort:
Show "); $sb->add_int_option("tageditcloud_defcount"); $sb->add_label(" tags by default.
Show a maximum of "); $sb->add_int_option("tageditcloud_maxcount"); $sb->add_label(" tags."); + $sb->add_label("
Relevance sort:
Ignore tags (space separated): "); + $sb->add_text_option("tageditcloud_ignoretags"); $event->panel->add_block($sb); } @@ -66,6 +69,8 @@ class TagEditCloud extends Extension { $max_count = $config->get_int("tageditcloud_maxcount"); $def_count = $config->get_int("tageditcloud_defcount"); + $ignore_tags = explode(' ',$config->get_string("tageditcloud_ignoretags")); + switch($sort_method){ case 'a': case 'p': @@ -74,7 +79,7 @@ class TagEditCloud extends Extension { array("tag_min1" => $tags_min, "tag_min2" => $tags_min, "limit" => $max_count)); break; case 'r': - $relevant_tags = "'".implode("','",array_diff($image->tag_array,array('tagme')))."'"; //TODO: Make this configurable + $relevant_tags = "'".implode("','",array_diff($image->tag_array,$ignore_tags))."'"; $tag_data = $database->get_all("SELECT t2.tag AS tag, COUNT(image_id) AS count, FLOOR(LN(LN(COUNT(image_id) - :tag_min1 + 1)+1)*150)/200 AS scaled FROM image_tags it1 JOIN image_tags it2 USING(image_id) JOIN tags t1 ON it1.tag_id = t1.id JOIN tags t2 ON it2.tag_id = t2.id WHERE t1.count >= :tag_min2 AND t1.tag IN($relevant_tags) GROUP BY t2.tag ORDER BY count DESC LIMIT :limit", From 03e78bd19f045aee7d9c304f1991f479c99dce7c Mon Sep 17 00:00:00 2001 From: Justin Brewer Date: Wed, 7 Aug 2013 15:58:58 -0500 Subject: [PATCH 04/10] Tag Category integration --- ext/tag_editcloud/main.php | 31 +++++++++++++++++++++++++++---- ext/tag_editcloud/script.js | 17 ++++++----------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index 56a5ec51..a1e790d0 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -71,6 +71,14 @@ class TagEditCloud extends Extension { $ignore_tags = explode(' ',$config->get_string("tageditcloud_ignoretags")); + if(class_exists("TagCategories")){ + $categories = $database->get_all("SELECT category, color FROM image_tag_categories"); + $cat_color = array(); + foreach($categories as $row){ + $cat_color[$row['category']] = $row['color']; + } + } + switch($sort_method){ case 'a': case 'p': @@ -93,19 +101,34 @@ class TagEditCloud extends Extension { $cloud .= "
[show $rem more tags]"; } From e93785339f87512ae997b2dda600e6497a429503 Mon Sep 17 00:00:00 2001 From: Justin Brewer Date: Mon, 26 Aug 2013 23:32:44 -0500 Subject: [PATCH 07/10] Fix another corner case If $counter == $def_count and the next tag in the list is a used tag, the tagcloud_extra div would be printed twice, breaking the list. This solution feels ugly, perhaps there's a better way to do this? --- ext/tag_editcloud/main.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ext/tag_editcloud/main.php b/ext/tag_editcloud/main.php index 30750b3a..0286b890 100644 --- a/ext/tag_editcloud/main.php +++ b/ext/tag_editcloud/main.php @@ -57,6 +57,7 @@ class TagEditCloud extends Extension { $html = ""; $cloud = ""; $precloud = ""; + $postcloud = ""; $sort_method = $config->get_string("tageditcloud_sort"); $tags_min = $config->get_int("tageditcloud_minusage"); @@ -92,10 +93,6 @@ class TagEditCloud extends Extension { $counter = 1; foreach($tag_data as $row) { - if($sort_method != 'a' && $counter == $def_count) { - $cloud .= "