]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Enjit/enjitqueuehandler.php
f0e706b929fd2182a7735eae21ea82ad0067702b
[quix0rs-gnu-social.git] / plugins / Enjit / enjitqueuehandler.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
21     exit(1);
22 }
23
24 /**
25  * Queue handler for watching new notices and posting to enjit.
26  * @fixme is this actually being used/functional atm?
27  */
28 class EnjitQueueHandler extends QueueHandler
29 {
30     function transport()
31     {
32         return 'enjit';
33     }
34
35     function start()
36     {
37         $this->log(LOG_INFO, "Starting EnjitQueueHandler");
38         $this->log(LOG_INFO, "Broadcasting to ".common_config('enjit', 'apiurl'));
39         return true;
40     }
41
42     function handle_notice($notice)
43     {
44
45         $profile = Profile::staticGet($notice->profile_id);
46
47         $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname);
48
49         if ( ! $notice->is_local ) {
50             $this->log(LOG_INFO, "Skipping remote notice");
51             return "skipped";
52         }
53
54         #
55         # Build an Atom message from the notice
56         #
57         $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
58         $msg = $profile->nickname . ': ' . $notice->content;
59
60         $atom  = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
61         $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n";
62         $atom .= "<source>\n";
63         $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
64         $atom .= "<link href='" . $profile->profileurl . "'/>\n";
65         $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
66         $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
67         $atom .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n";
68         $atom .= "</source>\n";
69         $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
70         $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
71         $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
72         $atom .= "<id>". $notice->uri . "</id>\n";
73         $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
74         $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
75         $atom .= "</entry>\n";
76
77         $url  = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey');
78         $data = array(
79             'msg' => $atom,
80         );
81
82         #
83         # POST the message to $config['enjit']['apiurl']
84         #
85         $request = HTTPClient::start();
86         $response = $request->post($url, null, $data);
87
88         return $response->isOk();
89     }
90
91 }