3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * OpenMicroBlogging plugin - add OpenMicroBloggin 0.1 support to
9 * Note: the OpenMicroBlogging protocol has been deprecated in favor of OStatus.
10 * This plugin is provided for backwards compatibility and experimentation.
12 * Please see the README and the OStatus plugin.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU Affero General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Affero General Public License for more details.
26 * You should have received a copy of the GNU Affero General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * @copyright 2011 StatusNet, Inc.
33 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
34 * @link http://status.net/
37 set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/extlib/');
39 if (!defined('STATUSNET')) {
40 // This check helps protect against security problems;
41 // your code file can't be executed directly from the web.
46 * OMB plugin main class
48 * @category Integration
50 * @author Zach Copley <zach@status.net>
51 * @copyright 2011 StatusNet, Inc.
52 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
53 * @link http://status.net/
55 class OMBPlugin extends Plugin
61 * @param Net_URL_Mapper $m path-to-action mapper
63 * @return boolean hook value; true means continue processing, false means stop.
65 function onRouterInitialized($m)
73 'finishremotesubscribe'
76 foreach ($bare as $action) {
78 'index.php?action=' . $action, array('action' => $action)
84 $m->connect('main/remote', array('action' => 'remotesubscribe'));
86 'main/remote?nickname=:nickname',
87 array('action' => 'remotesubscribe'),
88 array('nickname' => '[A-Za-z0-9_-]+')
93 array('action' => 'xrds', 'nickname' => $nickname)
100 * Put saved notices into the queue for OMB distribution
102 * @param Notice $notice the notice to broadcast
103 * @param array $transports queuehandler's list of transports
104 * @return boolean true if queing was successful
106 function onStartEnqueueNotice($notice, &$transports)
108 if ($notice->isLocal()) {
109 if ($notice->inScope(null)) {
110 array_unshift($transports, 'omb');
112 LOG_INFO, "Notice {$notice->id} queued for OMB processing"
115 // Note: We don't do privacy-controlled OMB updates.
118 "Not queueing notice {$notice->id} for OMB because of "
119 . "privacy; scope = {$notice->scope}",
126 "Not queueing notice {$notice->id} for OMB because it's not "
136 * Set up queue handlers for outgoing OMB pushes
138 * @param QueueManager $qm
139 * @return boolean hook return
141 function onEndInitializeQueueManager(QueueManager $qm)
143 // Prepare outgoing distributions after notice save.
144 $qm->connect('omb', 'OmbQueueHandler');
145 $qm->connect('profile', 'ProfileQueueHandler');
151 * Return OMB remote profile, if any
153 * @param Profile $profile
155 * @return boolen false if there's a remote profile
157 function onStartGetProfileUri($profile, &$uri)
159 $remote = Remote_profile::getKV('id', $this->id);
160 if (!empty($remote)) {
168 * We can't initiate subscriptions for a remote OMB profile; don't show
171 * @param type $action
173 function onStartShowProfileListSubscribeButton($action)
175 $remote = Remote_profile::getKV('id', $action->profile->id);
176 if (empty($remote)) {
183 * Check for illegal subscription attempts
185 * @param Profile $profile subscriber
186 * @param Profile $other subscribee
187 * @return hook return value
189 function onStartSubscribe(Profile $profile, Profile $other)
191 // OMB 0.1 doesn't have a mechanism for local-server-
192 // originated subscription.
194 $omb01 = Remote_profile::getKV('id', $other->id);
196 if (!empty($omb01)) {
197 throw new ClientException(
198 // TRANS: Client error displayed trying to subscribe to an OMB 0.1 remote profile.
199 _m('You cannot subscribe to an OMB 0.1 '
200 . 'remote profile with this action.'
208 * Throw an error if someone tries to tag a remote profile
210 * @param Profile $tagger_profile profile of the tagger
211 * @param Profile $tagged_profile profile of the taggee
216 function onStartTagProfile($tagger_profile, $tagged_profile, $tag)
218 // OMB 0.1 doesn't have a mechanism for local-server-
221 $omb01 = Remote_profile::getKV('id', $tagged_profile->id);
223 if (!empty($omb01)) {
225 // TRANS: Client error displayed when trying to add an OMB 0.1 remote profile to a list.
226 _m('You cannot list an OMB 0.1 '
227 .'remote profile with this action.')
234 * Check to make sure we're not tryng to untag an OMB profile
236 * // XXX: Should this ever happen?
238 * @param Profile_tag $ptag the profile tag
240 function onUntagProfile($ptag)
242 // OMB 0.1 doesn't have a mechanism for local-server-
245 $omb01 = Remote_profile::getKV('id', $ptag->tagged);
247 if (!empty($omb01)) {
249 // TRANS: Client error displayed when trying to (un)list an OMB 0.1 remote profile.
250 _m('You cannot (un)list an OMB 0.1 '
251 . 'remote profile with this action.')
258 * Remove old OMB subscription tokens
260 * @param Profile $profile subscriber
261 * @param Profile $other subscribee
262 * @return hook return value
264 function onEndUnsubscribe(Profile $profile, Profile $other)
266 $sub = Subscription::pkeyGet(
267 array('subscriber' => $profile->id, 'subscribed' => $other->id)
270 if (!empty($sub->token)) {
272 $token = new Token();
274 $token->tok = $sub->token;
276 if ($token->find(true)) {
278 $result = $token->delete();
281 common_log_db_error($token, 'DELETE', __FILE__);
283 // TRANS: Exception thrown when the OMB token for a subscription could not deleted on the server.
284 _m('Could not delete subscription OMB token.')
290 "Couldn't find credentials with token {$token->tok}",
300 * Search for an OMB remote profile by URI
302 * @param string $uri remote profile URI
303 * @param Profile $profile the profile to set
304 * @return boolean hook value
306 function onStartGetProfileFromURI($uri, &$profile)
308 $remote_profile = Remote_profile::getKV('uri', $uri);
309 if (!empty($remote_profile)) {
310 $profile = Profile::getKV('id', $remote_profile->profile_id);
318 * Return OMB remote profiles as well as regular profiles
321 * @param type $profile
324 function onStartCommonProfileURI($profile, &$uri)
326 $remote = Remote_profile::getKV($profile->id);
335 * Broadcast a profile over OMB
337 * @param Profile $profile to broadcast
340 function onBroadcastProfile($profile) {
341 $qm = QueueManager::get();
342 $qm->enqueue($profile, "profile");
346 function onStartProfileRemoteSubscribe($out, $profile)
348 $out->elementStart('li', 'entity_subscribe');
349 $url = common_local_url('remotesubscribe',
350 array('nickname' => $this->profile->nickname));
351 $out->element('a', array('href' => $url,
352 'class' => 'entity_remote_subscribe'),
353 // TRANS: Link text for link that will subscribe to a remote profile.
354 _m('BUTTON','Subscribe'));
355 $out->elementEnd('li');
361 * Plugin version info
363 * @param array $versions
364 * @return boolean hook value
366 function onPluginVersion(&$versions)
369 'name' => 'OpenMicroBlogging',
370 'version' => STATUSNET_VERSION,
371 'author' => 'Zach Copley',
372 'homepage' => 'http://status.net/wiki/Plugin:Sample',
373 // TRANS: Plugin description.
374 'rawdescription' => _m('A sample plugin to show basics of development for new hackers.')