source: trunk/common/db/blog.php @ 1184

Revision 1079, 2.2 KB checked in by bogdan2412, 2 years ago (diff)

Updated tagging backend again.

Added a column in ia_tags for a tag's parent and got rid of the string prefixes we used before.
Review URL: http://reviewboard.infoarena.ro/r/118/

  • Property svn:eol-style set to native
Line 
1<?php
2
3require_once(IA_ROOT_DIR."common/db/tags.php");
4
5function blog_get_range($tag_name, $start, $range) {
6    if (is_tag_name($tag_name)) {
7        $tag_id = tag_get_id(array(
8            "name" => $tag_name, "type" => "tag", "parent" => 0));
9        if (is_null($tag_id)) {
10            $tag_id = -1;
11        }
12        $where = tag_build_where("textblock", array($tag_id));
13    } else {
14        $where = "TRUE";
15    }
16    $query = sprintf("SELECT * FROM ia_textblock
17                      WHERE %s AND name LIKE 'blog/%%'
18                      AND security <> 'private'
19                      ORDER BY ia_textblock.creation_timestamp DESC
20                      LIMIT %s, %s",
21                     $where, db_quote((int)$start), db_quote((int)$range));
22    return db_fetch_all($query);
23}
24
25function blog_get_forum_topic($name) {
26    $query = sprintf("SELECT `forum_topic` FROM ia_textblock
27                      WHERE name = '%s'", db_escape($name));
28    $result = db_fetch($query);
29    return $result['forum_topic'];
30}
31
32function blog_get_comment_count($topic_id) {
33    $query = sprintf("SELECT `numReplies` FROM ia_smf_topics
34                      WHERE ID_TOPIC = %d", db_escape($topic_id));
35    $result = db_fetch($query);
36    return $result['numReplies'];
37}
38
39function blog_count($tag_name) {
40    if (is_tag_name($tag_name)) {
41        $tag_id = tag_get_id(array(
42            "name" => $tag_name, "type" => "tag", "parent" => 0));
43        if (is_null($tag_id)) {
44            $tag_id = -1;
45        }
46        $where = tag_build_where("textblock", array($tag_id));
47    } else {
48        $where = "TRUE";
49    }
50    $query = sprintf("SELECT COUNT(*) as `cnt` FROM ia_textblock WHERE %s
51                      AND name LIKE 'blog/%%'
52                      AND security <> 'private'", $where);
53    $result = db_fetch($query);
54    return $result['cnt'];
55}
56
57function blog_get_tags() {
58    $query = "SELECT name,
59                     (SELECT COUNT(*) FROM ia_textblock_tags WHERE tag_id = id AND textblock_id LIKE 'blog/%%') AS cnt
60              FROM ia_tags WHERE id IN
61              (SELECT DISTINCT tag_id FROM ia_textblock_tags WHERE textblock_id LIKE 'blog/%%')
62              ORDER BY name";
63    return db_fetch_all($query);
64}
65?>
Note: See TracBrowser for help on using the repository browser.