]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Enjit/enjitqueuehandler.php
Profile::current() suits better here.
[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  * @todo 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 handle($notice)
36     {
37
38         $profile = Profile::getKV($notice->profile_id);
39
40         $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname);
41
42         if ( ! $notice->is_local ) {
43             $this->log(LOG_INFO, "Skipping remote notice");
44             return "skipped";
45         }
46
47         #
48         // Build an Atom message from the notice
49         #
50         $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
51         $msg = $profile->nickname . ': ' . $notice->content;
52
53         $atom  = "<entry xmlns='http://www.w3.org/2005/Atom'>\n";
54         $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n";
55         $atom .= "<source>\n";
56         $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
57         $atom .= "<link href='" . $profile->profileurl . "'/>\n";
58         $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
59         $atom .= "<author><name>" . $profile->nickname . "</name></author>\n";
60         $atom .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n";
61         $atom .= "</source>\n";
62         $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n";
63         $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
64         $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
65         $atom .= "<id>". $notice->uri . "</id>\n";
66         $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
67         $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
68         $atom .= "</entry>\n";
69
70         $url  = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey');
71         $data = array(
72             'msg' => $atom,
73         );
74
75         #
76         // POST the message to $config['enjit']['apiurl']
77         #
78         $request = HTTPClient::start();
79         $response = $request->post($url, null, $data);
80
81         return $response->isOk();
82     }
83 }