root/taggingreloaded/optionals/de.easy-coding.wcf.sitemaps.taggingreloaded/files/lib/system/event/listener/TaggingReloadedSitemapsPageListener.class.php @ 207

Revision 207, 2.3 kB (checked in by d0nut, 5 years ago)

fixed incompatblity with mysql 4.*

Line 
1<?php
2// wcf imports
3require_once(WCF_DIR.'lib/system/event/EventListener.class.php');
4
5require_once(WCF_DIR.'lib/page/PublicSEORewriterTagging.class.php');
6
7/**
8 * extends the sitemap
9 *
10 * @author      Torben Brodt
11 * @package     de.easy-coding.wcf.sitemaps.taggingreloaded
12 * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-3.0.html>
13 */
14class TaggingReloadedSitemapsPageListener implements EventListener {
15        protected $taggingReloaded = false; //param
16       
17        protected $tags = array(); //data
18
19        protected $eventObj;
20        protected $className;
21        protected $rewriter;
22
23        /**
24         * @see EventListener::execute()
25         */
26        public function execute($eventObj, $className, $eventName) {
27                $this->eventObj = $eventObj;
28                $this->className = $className;
29                $this->rewriter = new PublicSEORewriterTagging();
30
31                switch ($eventName) {
32                        case 'readParameters':
33                                $this->readParameters();
34                                break;
35                        case 'readData':
36                                $this->readData();
37                                break;
38                        case 'assignVariables':
39                                $this->assignVariables();
40                                break;
41                }
42        }
43       
44        /**
45         *
46         */
47        protected function readTags () {
48                $sql = "SELECT          tag,
49                                        SUM(weight) AS n
50                        FROM            wcf".WCF_N."_taggingreloaded
51                        GROUP BY        tag
52                        ORDER BY        n DESC;";
53                $result = WCF::getDB()->sendQuery($sql);
54                while ($row = WCF::getDB()->fetchArray($result)) {
55                        $this->tags[] = $row['tag'];
56                }
57        }
58       
59        /**
60         * @see Page::readParameters()
61         */
62        protected function readParameters () {
63                if(isset($_GET['extension']) && $_GET['extension'] == 'TaggingReloaded') $this->taggingReloaded = true;
64        }
65       
66        /**
67         * @see Page::readData()
68         */
69        protected function readData () {
70                if($this->eventObj->index) {
71                        //index
72                        $this->eventObj->setType('sitemapindex');
73                }
74               
75                else if($this->taggingReloaded) {
76                        $this->eventObj->setType('urlset');
77                }
78        }
79       
80        /**
81         * @see Page::assignVariables()
82         */
83        protected function assignVariables () {
84                if($this->eventObj->index) {
85                        //index
86                        print '<sitemap><loc>'.PAGE_URL.'/index.php?page=Sitemaps&amp;extension=TaggingReloaded</loc></sitemap>';
87                }
88               
89                else if($this->taggingReloaded) {
90                        $this->readTags();
91                       
92                        $tpl = '<url><loc>'.PAGE_URL.'/%s</loc></url>'; 
93                        foreach($this->tags as $tag) {
94                                printf($tpl, $this->rewriter->publicParseTagURLs($tag));
95                        }
96                }
97        }
98}
99?>
Note: See TracBrowser for help on using the browser.