root/taggingreloaded/files/lib/system/event/listener/TaggingReloadedPageListener.class.php @ 203

Revision 203, 3.4 kB (checked in by d0nut, 5 years ago)

wrong wcf path

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