From b0369ffd222b868ae742ec6309f0bb3a9f9f5d1a Mon Sep 17 00:00:00 2001 From: shish Date: Tue, 1 May 2007 12:39:20 +0000 Subject: [PATCH] shared code for tag lists, and work on refine search starts git-svn-id: file:///home/shish/svn/shimmie2/trunk@40 7f39781d-f577-437e-ae19-be835c7a54ca --- ext/tag_list.ext.php | 136 +++++++++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 58 deletions(-) diff --git a/ext/tag_list.ext.php b/ext/tag_list.ext.php index 2757e08c..4bc7213e 100644 --- a/ext/tag_list.ext.php +++ b/ext/tag_list.ext.php @@ -162,6 +162,43 @@ class TagList extends Extension { return $html; } // }}} +// common {{{ + private function build_tag_list_html($query, $args, $callback=null, $cbdata=null) { + global $database; + global $config; + + $n = 0; + $html = ""; + $result = $database->db->Execute($query, $args); + $show_count = $config->get_bool('tag_list_numbers'); + while(!$result->EOF) { + $row = $result->fields; + $tag = $row['tag']; + $h_tag = html_escape($tag); + $h_tag_no_underscores = str_replace("_", " ", $h_tag); + $count = $row['count']; + if($n++) $html .= "
"; + $link = $this->tag_link($row['tag']); + $html .= "$h_tag_no_underscores\n"; + if($show_count) { + $html .= " ($count)"; + } + if(!is_null($callback)) { + $html .= $this->$callback($tag, $cbdata); + } + else { + if(!is_null($config->get_string('info_link'))) { + $link = str_replace('$tag', $tag, $config->get_string('info_link')); + $html .= " ?\n"; + } + } + $result->MoveNext(); + } + $result->Close(); + + return $html; + } +// }}} // get related {{{ private function get_related_tags($image) { global $database; @@ -183,26 +220,9 @@ class TagList extends Extension { ORDER by count DESC LIMIT ? "; + $args = array($image->id, $config->get_int('tag_list_length')); - $n = 0; - $html = ""; - $result = $database->db->Execute($query, array($image->id, $config->get_int('tag_list_length'))); - $show_count = $config->get_bool('tag_list_numbers'); - while(!$result->EOF) { - $row = $result->fields; - $h_tag = html_escape($row['tag']); - $count = $row['count']; - if($n++) $html .= "
"; - $link = $this->tag_link($row['tag']); - $html .= "$h_tag\n"; - if($show_count) { - $html .= " ($count)"; - } - $result->MoveNext(); - } - $result->Close(); - - return $html; + return $this->build_tag_list_html($query, $args); } // }}} // get popular {{{ @@ -217,29 +237,9 @@ class TagList extends Extension { ORDER BY count DESC LIMIT ? "; + $args = array($config->get_int('tag_list_length')); - $n = 0; - $result = $database->db->Execute($query, array($config->get_int('tag_list_length'))); - $html = ""; - $show_count = $config->get_bool('tag_list_numbers'); - while(!$result->EOF) { - $row = $result->fields; - $tag = html_escape($row['tag']); - $count = $row['count']; - if($n++) $html .= "
"; - $link = $this->tag_link($row['tag']); - $html .= "$tag\n"; - if($show_count) { - $html .= " ($count)"; - } - if(!is_null($config->get_string('info_link'))) { - $link = str_replace('$tag', $tag, $config->get_string('info_link')); - $html .= " ?\n"; - } - $result->MoveNext(); - } - $result->Close(); - + $html = $this->build_tag_list_html($query, $args); $html .= "

Full List >>>\n"; return $html; @@ -266,27 +266,47 @@ class TagList extends Extension { ORDER BY count DESC LIMIT ? "; + $args = array($config->get_int('tag_list_length')); - $n = 0; + return $this->build_tag_list_html($query, $args, "ars", $tags); + } + + private function ars($tag, $tags) { $html = ""; - $result = $database->db->Execute($query, array($config->get_int('tag_list_length'))); - $show_count = $config->get_bool('tag_list_numbers'); - while(!$result->EOF) { - $row = $result->fields; - $h_tag = html_escape($row['tag']); - $count = $row['count']; - if($n++) $html .= "
"; - $link = $this->tag_link($row['tag']); - $html .= "$h_tag\n"; - if($show_count) { - $html .= " ($count)"; - } - $result->MoveNext(); - } - $result->Close(); - + $html .= " ("; + $html .= $this->get_add_link($tags, $tag); + $html .= $this->get_remove_link($tags, $tag); + $html .= $this->get_subtract_link($tags, $tag); + $html .= ")"; return $html; } + + private function get_remove_link($tags, $tag) { + if(!in_array($tag, $tags) && !in_array("-$tag", $tags)) { + return ""; + } + else { + return "r"; + } + } + + private function get_add_link($tags, $tag) { + if(in_array($tag, $tags)) { + return ""; + } + else { + return "a"; + } + } + + private function get_subtract_link($tags, $tag) { + if(in_array("-$tag", $tags)) { + return ""; + } + else { + return "s"; + } + } // }}} } add_event_listener(new TagList());