root/taggingreloaded/optionals/de.easy-coding.wbb.taggingreloaded/files/lib/system/event/listener/TaggingReloadedWBBPageListener.class.php @ 330

Revision 330, 5.4 kB (checked in by d0nut, 5 years ago)

first caching approaches for tagger

Line 
1<?php
2// wbb imports
3require_once(WBB_DIR.'lib/data/thread/ViewableThreadTagging.class.php');
4require_once(WBB_DIR.'lib/data/board/Board.class.php');
5
6// tagging imports
7require_once(WCF_DIR.'lib/util/TaggingReloadedUtil.class.php');
8require_once(WCF_DIR.'lib/system/event/listener/TaggingReloadedPageListener.class.php');
9
10// seo imports
11require_once(WCF_DIR.'lib/page/PublicSEORewriterTagging.class.php');
12
13/**
14 * Displays the tags for threads/boards
15 *
16 * @author      Torben Brodt
17 * @package     de.easy-coding.wbb.taggingreloaded
18 * @license     GNU General Public License <http://opensource.org/licenses/gpl-3.0.html>
19 */
20class TaggingReloadedWBBPageListener extends TaggingReloadedPageListener {
21        protected $postID=0, $threadID=0, $boards=array(), $tag; // params
22       
23        // data
24        protected $threadList = array();
25
26        /**
27         * reads similar tags
28         */
29        protected function queryTagsByTag() {
30                // order by weight and cut
31                $sql = "SELECT          wcf2.tag,
32                                        SUM(wcf2.weight) AS weight
33                        FROM            wcf".WCF_N."_taggingreloaded wcf
34                        NATURAL JOIN    wbb".WBB_N."_taggingreloaded wbb
35                        JOIN            wbb".WBB_N."_post p
36                        ON              wbb.postID = p.postID
37                        JOIN            wbb".WBB_N."_taggingreloaded wbb2
38                        ON              p.postID = wbb2.postID
39                        JOIN            wcf".WCF_N."_taggingreloaded wcf2
40                        ON              wbb2.taggingID = wcf2.taggingID
41                        WHERE           wcf.tag = '".escapeString($this->tag)."'
42                        GROUP BY        wcf2.tag
43                        ORDER BY        weight DESC
44                        LIMIT           50";
45
46                return $sql;
47        }
48       
49        /**
50         * reads (threaddata) by post
51         */
52        protected function queryTagsByPost() {
53                // order by weight and cut
54                $sql = "SELECT          tag,
55                                        SUM(weight) AS weight
56                        FROM            wcf".WCF_N."_taggingreloaded wcf
57                        NATURAL JOIN    wbb".WBB_N."_taggingreloaded wbb
58                        NATURAL JOIN    wbb".WBB_N."_post p
59                        JOIN            wbb".WBB_N."_post p2
60                        ON              p.threadID = p2.threadID
61                        WHERE           p.postID = {$this->postID}
62                        GROUP BY        tag
63                        ORDER BY        weight DESC
64                        LIMIT           50";
65                //      SUM( weight ) * IF(COUNT(tag), 1.2, 1 )
66
67                return $sql;
68        }
69       
70        /**
71         * reads by thread
72         */
73        protected function queryTagsByThread() {
74                // order by weight and cut
75                $sql = "SELECT          tag,
76                                        SUM(weight) AS weight
77                        FROM            wcf".WCF_N."_taggingreloaded wcf
78                        NATURAL JOIN    wbb".WBB_N."_taggingreloaded wbb
79                        NATURAL JOIN    wbb".WBB_N."_post p
80                        WHERE           p.threadID = {$this->threadID}
81                        GROUP BY        tag
82                        ORDER BY        weight DESC
83                        LIMIT           50";
84                //      SUM( weight ) * IF(COUNT(tag), 1.2, 1 )
85
86                return $sql;
87        }
88       
89        /**
90         * reads threads by tag
91         */
92        protected function readThreadsByTag() {
93                $sql = "SELECT          t.*,
94                                        tag,
95                                        SUM(weight) AS weight
96                        FROM            wcf".WCF_N."_taggingreloaded wcf
97                        NATURAL JOIN    wbb".WBB_N."_taggingreloaded wbb
98                        JOIN            wbb".WBB_N."_post p
99                        ON              wbb.postID = p.postID
100                        JOIN            wbb".WBB_N."_thread t
101                        ON              p.threadID = t.threadID
102                        WHERE           tag = '".escapeString($this->tag)."'
103                        GROUP BY        p.threadID
104                        ORDER BY        weight DESC
105                        LIMIT           15";
106
107                $result = WCF::getDB()->sendQuery($sql);
108                while ($row = WCF::getDB()->fetchArray($result)) {
109                        $row['permission'] = Board::getBoard($row['boardID'])->getPermission('canReadThread');
110                        $this->threadList[] = new ViewableThreadTagging(null, $row);
111                }
112        }
113       
114        /**
115         * @see Page::readData()
116         */
117        protected function readData () {
118                switch($this->className) {
119                        case 'ThreadPage':
120                                $this->threadID = $this->eventObj->threadID;
121
122                                $sql = $this->queryTagsByThread();
123                                break;
124                        case 'BoardPage':
125                                $minLifetime = 0;
126                                $maxLifetime = 43200; //12 h
127
128                                WCF::getCache()->addResource(
129                                        'taggingreloaded.wbb.boards', 
130                                        WCF_DIR.'cache/cache.taggingreloaded.wbb.boards.php',
131                                        WCF_DIR.'lib/system/cache/CacheBuilderTaggingReloadedBoards.class.php',
132                                        $minLifetime,
133                                        $maxLifetime
134                                );
135                                break;
136                        case 'TaggingPage':
137                                if(isset($_GET['tag'])) {
138                                        $this->tag = $_GET['tag'];
139                                        $check = true;
140                                        $this->readThreadsByTag();
141                                        $sql = $this->queryTagsByTag();
142                                }
143                                break;
144                }
145               
146                // break
147                if(!isset($sql)) return;
148
149                // order by tag
150                $sql = "SELECT tag,weight FROM ($sql) A ORDER BY tag ASC";
151               
152                // query
153                $result = WCF::getDB()->sendQuery($sql);
154                while ($row = WCF::getDB()->fetchArray($result)) {
155                        $this->tags[$row['tag']] = array(
156                                        'weight'=> $row['weight'],
157                                        'color'=> 0,
158                                        'size'=> 0,
159                                        'url' => $this->rewriter->publicParseTagURLs($row['tag'])
160                                       
161                                );
162                }
163               
164                $this->tags = TaggingReloadedUtil::beautify($this->tags);
165               
166                // are there any threads?
167                if(isset($check) && count($this->threadList) == 0) {
168                        require_once(WCF_DIR.'lib/system/exception/IllegalLinkException.class.php');
169                        throw new IllegalLinkException();
170                }
171        }
172       
173        /**
174         * fetch recursive all child boardIDs
175         * @param arr
176         */
177        protected function readSubBoards($arr) {
178                foreach($arr as $boardID => $next) {
179                        $this->boards[] = $boardID;
180                        $this->readSubBoards($next);
181                }
182        }
183       
184        /**
185         * @see Page::assignVariables()
186         */
187        protected function assignVariables () {
188                WCF::getTPL()->assign('tags', $this->tags);
189                WCF::getTPL()->append('specialStyles', '<link rel="stylesheet" type="text/css" href="'.RELATIVE_WCF_DIR.'style/taggingreloaded.css" />');
190               
191                if(count($this->tags) > 0 && ($this->threadID || $this->postID || count($this->boards)>0)) {
192                        WCF::getTPL()->append('additionalBoxes', WCF::getTPL()->fetch('taggingCloudContainer'));
193                } else if($this->tag) {
194                        WCF::getTPL()->assign('threads', $this->threadList);
195                        WCF::getTPL()->append('additionalTaggingContents', WCF::getTPL()->fetch('taggingCloud'));
196                        WCF::getTPL()->append('additionalTaggingContents', WCF::getTPL()->fetch('threadListTagging'));
197                }
198        }
199}
200?>
Note: See TracBrowser for help on using the browser.