| 1 | <?php |
|---|
| 2 | // wcf imports |
|---|
| 3 | require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); |
|---|
| 4 | |
|---|
| 5 | // tagging imports |
|---|
| 6 | require_once(WCF_DIR.'lib/util/TaggingReloadedUtil.class.php'); |
|---|
| 7 | |
|---|
| 8 | // seo imports |
|---|
| 9 | require_once(WCF_DIR.'lib/page/PublicSEORewriterTagging.class.php'); |
|---|
| 10 | |
|---|
| 11 | /** |
|---|
| 12 | * Displays the tags for threads/boards |
|---|
| 13 | * |
|---|
| 14 | * @author Torben Brodt |
|---|
| 15 | * @package de.easy-coding.wcf.taggingreloaded |
|---|
| 16 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-3.0.html> |
|---|
| 17 | */ |
|---|
| 18 | class TaggingReloadedPageListener implements EventListener { |
|---|
| 19 | protected static $constructed = false; |
|---|
| 20 | |
|---|
| 21 | protected $userID=0; // params |
|---|
| 22 | |
|---|
| 23 | // data |
|---|
| 24 | protected $tags = array(); |
|---|
| 25 | |
|---|
| 26 | protected $eventObj; |
|---|
| 27 | protected $className; |
|---|
| 28 | protected $rewriter; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * @see EventListener::execute() |
|---|
| 32 | */ |
|---|
| 33 | public function execute($eventObj, $className, $eventName) { |
|---|
| 34 | // abort if user deactivated tagging |
|---|
| 35 | if(!WCF::getUser()->getUserOption('tagging_enable')) |
|---|
| 36 | return; |
|---|
| 37 | |
|---|
| 38 | // is style black? |
|---|
| 39 | if(!self::$constructed) { |
|---|
| 40 | require_once(WCF_DIR.'lib/system/style/Style.class.php'); |
|---|
| 41 | $style = new Style(WCF::getUser()->styleID); |
|---|
| 42 | $check = !in_array($style->getVariable('page.background.color'),array('#000','#000000')); |
|---|
| 43 | TaggingReloadedUtil::setBlack($check); |
|---|
| 44 | self::$constructed = false; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | $this->eventObj = $eventObj; |
|---|
| 48 | $this->className = $className; |
|---|
| 49 | $this->rewriter = new PublicSEORewriterTagging(); |
|---|
| 50 | |
|---|
| 51 | switch ($eventName) { |
|---|
| 52 | case 'readData': |
|---|
| 53 | $this->readData(); |
|---|
| 54 | break; |
|---|
| 55 | case 'readParameters': |
|---|
| 56 | $this->readParameters(); |
|---|
| 57 | break; |
|---|
| 58 | case 'assignVariables': |
|---|
| 59 | $this->assignVariables(); |
|---|
| 60 | break; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | /** |
|---|
| 65 | * reads by user |
|---|
| 66 | */ |
|---|
| 67 | protected function queryTagsByUser() { |
|---|
| 68 | // order by weight and cut |
|---|
| 69 | $sql = "SELECT tag, |
|---|
| 70 | SUM(weight) AS weight |
|---|
| 71 | FROM wcf".WCF_N."_taggingreloaded wcf |
|---|
| 72 | WHERE userID = ".$this->userID." |
|---|
| 73 | GROUP BY tag |
|---|
| 74 | ORDER BY weight DESC |
|---|
| 75 | LIMIT 50"; |
|---|
| 76 | |
|---|
| 77 | return $sql; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /** |
|---|
| 81 | * @see Page::readData() |
|---|
| 82 | */ |
|---|
| 83 | protected function readData () { |
|---|
| 84 | if($this->userID) { |
|---|
| 85 | $sql = $this->queryTagsByUser(); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | // break |
|---|
| 89 | if(!isset($sql)) return; |
|---|
| 90 | |
|---|
| 91 | // order by tag |
|---|
| 92 | $sql = "SELECT tag,weight FROM ($sql) A ORDER BY tag ASC"; |
|---|
| 93 | |
|---|
| 94 | // query |
|---|
| 95 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 96 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 97 | $this->tags[$row['tag']] = array( |
|---|
| 98 | 'weight'=> $row['weight'], |
|---|
| 99 | 'color'=> 0, |
|---|
| 100 | 'size'=> 0, |
|---|
| 101 | 'url' => $this->rewriter->publicParseTagURLs($row['tag']) |
|---|
| 102 | ); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | $this->tags = TaggingReloadedUtil::beautify($this->tags); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | /** |
|---|
| 109 | * @see Page::readParameters() |
|---|
| 110 | */ |
|---|
| 111 | protected function readParameters () { |
|---|
| 112 | if (isset($_GET['userID'])) $this->userID = intval($_GET['userID']); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | /** |
|---|
| 116 | * creates a new tagging category |
|---|
| 117 | */ |
|---|
| 118 | protected function assignCategory () { |
|---|
| 119 | $script = '<script type="text/javascript"> |
|---|
| 120 | //<![CDATA[ |
|---|
| 121 | if(document.getElementsByName("taggingCloud").length > 0) { |
|---|
| 122 | var taggingroot = document.getElementsByName("taggingCloud")[0].parentNode; |
|---|
| 123 | taggingroot.parentNode.removeChild(taggingroot.previousSibling.previousSibling); |
|---|
| 124 | taggingroot.className = ""; |
|---|
| 125 | } |
|---|
| 126 | //]]> |
|---|
| 127 | </script>'; |
|---|
| 128 | |
|---|
| 129 | $this->eventObj->categories['profile.tagging'] = array( |
|---|
| 130 | 'categoryName' => 'tagging', |
|---|
| 131 | 'categoryIconM' => RELATIVE_WCF_DIR.'icon/tagging24.png', |
|---|
| 132 | 'parentCategoryName' => 'profile', |
|---|
| 133 | 'options' => array( |
|---|
| 134 | array( |
|---|
| 135 | 'optionName'=> 'tagging', |
|---|
| 136 | 'categoryName'=> 'profile.tagging', |
|---|
| 137 | 'optionValue'=> WCF::getTPL()->fetch('taggingCloud').$script |
|---|
| 138 | ) |
|---|
| 139 | ) |
|---|
| 140 | ); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | /** |
|---|
| 144 | * @see Page::assignVariables() |
|---|
| 145 | */ |
|---|
| 146 | protected function assignVariables () { |
|---|
| 147 | if(count($this->tags) > 0) { |
|---|
| 148 | WCF::getTPL()->assign('tags', $this->tags); |
|---|
| 149 | $this->assignCategory(); |
|---|
| 150 | WCF::getTPL()->append('specialStyles', '<link rel="stylesheet" type="text/css" href="'.RELATIVE_WCF_DIR.'style/taggingreloaded.css" />'); |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | } |
|---|
| 154 | ?> |
|---|