root/twitter.retweet/files/lib/system/event/listener/TwitterRetweetListener.class.php @ 1337

Revision 1337, 1.7 kB (checked in by Torben Brodt, 2 years ago)

begin retweet extension: This plugin will show a box of users under the content they retweeted

RevLine 
[1337]1<?php
2require_once(WCF_DIR.'lib/util/TwitterUtil.class.php');
3
4/**
5 *
6 *
7 * @author      Torben Brodt
8 * @url         http://trac.easy-coding.de/trac/wcf/wiki/twitter
9 * @license     GNU General Public License <http://opensource.org/licenses/gpl-3.0.html>
10 */
11class TwitterRetweetListener implements EventListener {
12
13        /**
14         * @see EventListener::execute()
15         */
16        public function execute($eventObj, $className, $eventName) {
17       
18                //TODO: display retweets
19       
20                foreach($eventObj->links as $link) {
21               
22       
23                        $link = $this->rdfAutoDiscover($link);
24               
25                        if($this->isHomeLink($link)) {
26                                $query = parse_url($link, PHP_URL_QUERY);
27                                parse_str($query, $output);
28                               
29                                $this->link($eventObj, $output['action'], $output['objectID'], $output['objectType'], $output['packageID']);
30                        }
31                }
32        }
33
34        /**
35         *
36         */
37        protected function isHomeLink($link) {
38                if(empty($link)) {
39                        return false;
40                }
41
42                // TODO: does this link point to PAGE_URL ?
43
44                return true;
45        }
46
47        protected function link() {
48                // TODO: insert wcf1_twitter_message_retweet
49        }
50       
51        /**
52         * @return string
53         */
54        protected function rdfAutoDiscover($trackbackURL) {
55                // fetch page content
56                $pageContent = @file_get_contents($trackbackURL);
57                $didDiscover = false;
58               
59                if ($pageContent !== false) {
60                        // search for RDF instructions
61                        if (preg_match_all('/(<rdf:RDF.*?<\/rdf:RDF>)/sm', $pageContent, $matches)) {
62                                foreach($matches[0] as $rdfInstructions) {
63                                        if (preg_match('|dc\:identifier\=\"'.preg_quote($trackbackURL).'\"|isU', $rdfInstructions)) {
64                                                // get pingback URL
65                                                if (preg_match('/trackback\:ping\=\"([^"]+)\"/isU', $rdfInstructions, $pingbackURL)) {
66                                                       
67                                                        return $pingbackURL[1];
68                                                }
69                                        }
70                                }
71                        }
72                }
73                return '';
74        }
75}
76?>
Note: See TracBrowser for help on using the browser.