diff --git a/contrib/tag_editcloud/main.php b/contrib/tag_editcloud/main.php new file mode 100644 index 00000000..a75cb4fe --- /dev/null +++ b/contrib/tag_editcloud/main.php @@ -0,0 +1,107 @@ +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 implements Extension { + var $theme; + + public function receive_event(Event $event) { + global $config, $database, $page, $user; + //if(is_null($this->theme)) $this->theme = get_theme_object($this); + + if($event instanceof ImageInfoBoxBuildingEvent) { + if($this->can_tag($event->image)) { + $cfgstub_sortbyname=false; // FIXME + $cfgstub_showtop=40; // Derp + $cfgstub_minuse=2; // Derp + if($cfgstub_sortbyname) { + $event->add_part($this->build_tag_map($event->image,$cfgstub_minuse,false),40); + } else { + $event->add_part($this->build_tag_map($event->image,$cfgstub_showtop,4096),40); + } + } + } + } + + private function tag_link($tag) { + $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; + $html="";$cloud="";$precloud=""; + $itags=Array(); + $tags_min=1; + $alphasort=false; + if(!is_int($defcount)) $defcount=20; + if(!is_int($maxcount)) { // Derp this is pretty cheesy. + $maxcount=4096; // Hurrrr + $tags_min=$defcount; + $alphasort=true; + } + + if ((gettype($image) == 'object') && (isset($image->tag_array)) && ($itags=$image->tag_array)) $itags=array_fill_keys(array_values($itags),true); + + $result = $database->execute(" 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) + ); + + + + $tag_data = $result->GetArray(); + $counter=1; + foreach($tag_data as $row) { + if((!$alphasort)&&($counter==$defcount)) $cloud .= "
'.var_export($itags,true).''; + return "