root/trackback/files/lib/system/event/listener/ThreadAddFormTrackbackListener.class.php @ 134

Revision 134, 3.3 kB (checked in by d0nut, 5 years ago)

bugfixed reply mechanism

  • Property svn:executable set to *
Line 
1<?php
2// WCF include
3require_once(WCF_DIR.'lib/system/event/EventListener.class.php');
4
5// Utils
6require_once(WBB_DIR.'lib/util/TrackbackUtil.class.php');
7
8/**
9 * Handles activation of the trackback in threadcreation
10 *
11 * @author      Torben Brodt
12 * @package     de.easy-coding.wbb.trackback
13 * @license     GNU General Public License <http://opensource.org/licenses/gpl-3.0.html>
14 */
15class ThreadAddFormTrackbackListener implements EventListener {
16        protected $eventObj;
17        protected $className;
18
19        protected $hasTrackback = 0;
20
21        /**
22         * @see EventListener::execute()
23         */
24        public function execute($eventObj, $className, $eventName) {   
25                $this->eventObj = $eventObj;
26                $this->className = $className;
27
28                switch ($eventName) {
29                        case 'readData':
30                                $this->readData();
31                                break;
32                        case 'readFormParameters':
33                                $this->readFormParameters();
34                                break;
35                        case 'assignVariables':
36                                $this->assignVariables();
37                                break;
38                        case 'saved':
39                                $this->saved();
40                                break;
41                }
42        }
43
44        /**
45         * @see Form::readData()
46         */
47        protected function readData () {
48                if(isset($this->eventObj->post)) {
49                        $this->hasTrackback = $this->eventObj->post->hasTrackback;
50                }
51        }
52
53        /**
54         * @see Form::readFormParameters()
55         */
56        protected function readFormParameters () {
57                if (isset($_REQUEST['hasTrackback'])) $this->hasTrackback = intval($_REQUEST['hasTrackback']);
58        }
59       
60        /**
61         * @see Form::assignVariables()
62         */
63        protected function assignVariables () {
64                WBBCore::getTPL()->assign('hasTrackback', $this->hasTrackback);
65                WBBCore::getTPL()->append('additionalSettings', WBBCore::getTPL()->fetch('postTrackbackSetting'));
66        }
67
68        /**
69         * @see Form::saved()
70         */
71        protected function saved () {
72                $postID = 0;
73               
74                switch ($this->className) {
75                        case 'ThreadAddForm':
76                                $postID = $this->eventObj->newThread->firstPostID;
77                                $this->data = $this->eventObj->newThread->firstPostID;
78                                break;
79                        case 'PostEditForm':
80                                $postID = $this->eventObj->postID;
81                                break;
82                        case 'PostAddForm':
83                                $postID = $this->eventObj->newPost->getID();
84                        break;
85                }
86               
87                // send trackbacks
88                $this->sendTrackbackData($postID);
89
90                // UPDATE
91                $sql = "UPDATE          wbb".WBB_N."_post
92                        SET             hasTrackback    = {$this->hasTrackback}
93                        WHERE           postID          = {$postID};";
94
95                WBBCore::getDB()->sendQuery($sql);
96        }
97       
98        /**
99         * fetch trackback data from database (maybe an event would be faster)
100         * @param postID
101         */
102        protected function sendTrackbackData($postID) {
103                // fetch data
104                $row = TrackbackUtil::getPost($postID);
105               
106                $patterns = array();
107                $patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
108                $patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
109               
110                // fetch current postings
111                $urls = array();
112                foreach($patterns as $p) {
113                        preg_match_all($p, $this->eventObj->text, $res);
114                        $urls = array_merge($urls, $res[1]);
115                }
116
117                // fetch made postings
118                $oldurls = array();
119                $sql = "SELECT          alienURL
120                        FROM            wbb".WBB_N."_trackbackLog
121                        WHERE           postID = ".$postID;
122                $result = WCF::getDB()->sendQuery($sql);
123                while ($row = WCF::getDB()->fetchArray($result)) {
124                        $oldurls[] = $row['alienURL'];
125                }
126
127                // send pings
128                foreach(array_diff($urls, $oldurls) as $url) {
129                        TrackbackUtil::trackAndPing($postID, $url, PAGE_TITLE, $row['username'], $row['url'], $row['topic'], substr($row['firstPostPreview'],0,255));
130                }
131        }
132}
133?>
Note: See TracBrowser for help on using the browser.