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