3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
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.
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.
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/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) {
25 * Queue handler for watching new notices and posting to enjit.
26 * @fixme is this actually being used/functional atm?
28 class EnjitQueueHandler extends QueueHandler
37 $this->log(LOG_INFO, "Starting EnjitQueueHandler");
38 $this->log(LOG_INFO, "Broadcasting to ".common_config('enjit', 'apiurl'));
42 function handle_notice($notice)
45 $profile = Profile::staticGet($notice->profile_id);
47 $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname);
49 if ( ! $notice->is_local ) {
50 $this->log(LOG_INFO, "Skipping remote notice");
55 # Build an Atom message from the notice
57 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
58 $msg = $profile->nickname . ': ' . $notice->content;
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";
77 $url = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey');
83 # POST the message to $config['enjit']['apiurl']
85 $request = HTTPClient::start();
86 $response = $request->post($url, null, $data);
88 return $response->isOk();