diff --git a/core/imageboard.pack.php b/core/imageboard.pack.php index 7864bec6..b0d04bfe 100644 --- a/core/imageboard.pack.php +++ b/core/imageboard.pack.php @@ -255,13 +255,25 @@ class Image { // insert each new tags foreach($tags as $tag) { - $this->database->execute( - "INSERT IGNORE INTO tags(tag) VALUES (?)", + $id = $this->database->db->GetOne( + "SELECT id FROM tags WHERE tag = ?", array($tag)); - $this->database->execute( - "INSERT INTO image_tags(image_id, tag_id) ". - "VALUES(?, (SELECT id FROM tags WHERE tag = ?))", - array($this->id, $tag)); + if(empty($id)) { + // a new tag + $this->database->execute( + "INSERT INTO tags(tag) VALUES (?)", + array($tag)); + $this->database->execute( + "INSERT INTO image_tags(image_id, tag_id) + VALUES(?, (SELECT id FROM tags WHERE tag = ?))", + array($this->id, $tag)); + } + else { + // user of an existing tag + $this->database->execute( + "INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)", + array($this->id, $id)); + } $this->database->execute( "UPDATE tags SET count = count + 1 WHERE tag = ?", array($tag)); diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index ae36bd91..bb7f138b 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -210,7 +210,7 @@ class TagList implements Extension { global $config; $query = " - SELECT COUNT(it3.image_id) as count, t3.tag AS tag + SELECT COUNT(it3.image_id) as calc_count, t3.tag AS tag FROM image_tags AS it1, image_tags AS it2, @@ -226,7 +226,7 @@ class TagList implements Extension { AND t1.id = it1.tag_id AND t3.id = it3.tag_id GROUP BY it3.tag_id - ORDER BY count DESC + ORDER BY calc_count DESC LIMIT ? "; $args = array($image->id, $config->get_int('tag_list_length')); diff --git a/ext/tag_list/theme.php b/ext/tag_list/theme.php index 6bc0c050..0254f69d 100644 --- a/ext/tag_list/theme.php +++ b/ext/tag_list/theme.php @@ -40,7 +40,7 @@ class TagListTheme extends Themelet { $tag = $row['tag']; $h_tag = html_escape($tag); $h_tag_no_underscores = str_replace("_", " ", $h_tag); - $count = $row['count']; + $count = $row['calc_count']; if($n++) $html .= "\n
"; if(!is_null($config->get_string('info_link'))) { $link = str_replace('$tag', $tag, $config->get_string('info_link'));