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 * Depends on: WebFinger plugin
50 * @category Integration
52 * @author Zach Copley <zach@status.net>
53 * @copyright 2011 StatusNet, Inc.
54 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
55 * @link http://status.net/
57 class OMBPlugin extends Plugin
63 * @param Net_URL_Mapper $m path-to-action mapper
65 * @return boolean hook value; true means continue processing, false means stop.
67 function onRouterInitialized($m)
75 'finishremotesubscribe'
78 foreach ($bare as $action) {
80 'index.php?action=' . $action, array('action' => $action)
86 $m->connect('main/remote', array('action' => 'remotesubscribe'));
88 'main/remote?nickname=:nickname',
89 array('action' => 'remotesubscribe'),
90 array('nickname' => '[A-Za-z0-9_-]+')
95 array('action' => 'xrds', 'nickname' => $nickname)
102 * Put saved notices into the queue for OMB distribution
104 * @param Notice $notice the notice to broadcast
105 * @param array $transports queuehandler's list of transports
106 * @return boolean true if queing was successful
108 function onStartEnqueueNotice($notice, &$transports)
110 if ($notice->isLocal()) {
111 if ($notice->inScope(null)) {
112 array_unshift($transports, 'omb');
114 LOG_INFO, "Notice {$notice->id} queued for OMB processing"
117 // Note: We don't do privacy-controlled OMB updates.
120 "Not queueing notice {$notice->id} for OMB because of "
121 . "privacy; scope = {$notice->scope}",
128 "Not queueing notice {$notice->id} for OMB because it's not "
138 * Set up queue handlers for outgoing OMB pushes
140 * @param QueueManager $qm
141 * @return boolean hook return
143 function onEndInitializeQueueManager(QueueManager $qm)
145 // Prepare outgoing distributions after notice save.
146 $qm->connect('omb', 'OmbQueueHandler');
147 $qm->connect('profile', 'ProfileQueueHandler');
153 * Return OMB remote profile, if any
155 * @param Profile $profile
157 * @return boolen false if there's a remote profile
159 function onStartGetProfileUri($profile, &$uri)
161 $remote = Remote_profile::getKV('id', $this->id);
162 if (!empty($remote)) {
170 * We can't initiate subscriptions for a remote OMB profile; don't show
173 * @param type $action
175 function onStartShowProfileListSubscribeButton($action)
177 $remote = Remote_profile::getKV('id', $action->profile->id);
178 if (empty($remote)) {
185 * Check for illegal subscription attempts
187 * @param Profile $profile subscriber
188 * @param Profile $other subscribee
189 * @return hook return value
191 function onStartSubscribe(Profile $profile, Profile $other)
193 // OMB 0.1 doesn't have a mechanism for local-server-
194 // originated subscription.
196 $omb01 = Remote_profile::getKV('id', $other->id);
198 if (!empty($omb01)) {
199 throw new ClientException(
200 // TRANS: Client error displayed trying to subscribe to an OMB 0.1 remote profile.
201 _m('You cannot subscribe to an OMB 0.1 '
202 . 'remote profile with this action.'
210 * Throw an error if someone tries to tag a remote profile
212 * @param Profile $tagger_profile profile of the tagger
213 * @param Profile $tagged_profile profile of the taggee
218 function onStartTagProfile($tagger_profile, $tagged_profile, $tag)
220 // OMB 0.1 doesn't have a mechanism for local-server-
223 $omb01 = Remote_profile::getKV('id', $tagged_profile->id);
225 if (!empty($omb01)) {
227 // TRANS: Client error displayed when trying to add an OMB 0.1 remote profile to a list.
228 _m('You cannot list an OMB 0.1 '
229 .'remote profile with this action.')
236 * Check to make sure we're not tryng to untag an OMB profile
238 * // XXX: Should this ever happen?
240 * @param Profile_tag $ptag the profile tag
242 function onUntagProfile($ptag)
244 // OMB 0.1 doesn't have a mechanism for local-server-
247 $omb01 = Remote_profile::getKV('id', $ptag->tagged);
249 if (!empty($omb01)) {
251 // TRANS: Client error displayed when trying to (un)list an OMB 0.1 remote profile.
252 _m('You cannot (un)list an OMB 0.1 '
253 . 'remote profile with this action.')
260 * Remove old OMB subscription tokens
262 * @param Profile $profile subscriber
263 * @param Profile $other subscribee
264 * @return hook return value
266 function onEndUnsubscribe(Profile $profile, Profile $other)
268 $sub = Subscription::pkeyGet(
269 array('subscriber' => $profile->id, 'subscribed' => $other->id)
272 if (!empty($sub->token)) {
274 $token = new Token();
276 $token->tok = $sub->token;
278 if ($token->find(true)) {
280 $result = $token->delete();
283 common_log_db_error($token, 'DELETE', __FILE__);
285 // TRANS: Exception thrown when the OMB token for a subscription could not deleted on the server.
286 _m('Could not delete subscription OMB token.')
292 "Couldn't find credentials with token {$token->tok}",
302 * Search for an OMB remote profile by URI
304 * @param string $uri remote profile URI
305 * @param Profile $profile the profile to set
306 * @return boolean hook value
308 function onStartGetProfileFromURI($uri, &$profile)
310 $remote_profile = Remote_profile::getKV('uri', $uri);
311 if (!empty($remote_profile)) {
312 $profile = Profile::getKV('id', $remote_profile->profile_id);
320 * Return OMB remote profiles as well as regular profiles
323 * @param type $profile
326 function onStartCommonProfileURI($profile, &$uri)
328 $remote = Remote_profile::getKV($profile->id);
337 * Broadcast a profile over OMB
339 * @param Profile $profile to broadcast
342 function onBroadcastProfile($profile) {
343 $qm = QueueManager::get();
344 $qm->enqueue($profile, "profile");
348 function onStartProfileRemoteSubscribe($out, $profile)
350 $out->elementStart('li', 'entity_subscribe');
351 $url = common_local_url('remotesubscribe',
352 array('nickname' => $this->profile->nickname));
353 $out->element('a', array('href' => $url,
354 'class' => 'entity_remote_subscribe'),
355 // TRANS: Link text for link that will subscribe to a remote profile.
356 _m('BUTTON','Subscribe'));
357 $out->elementEnd('li');
363 * Plugin version info
365 * @param array $versions
366 * @return boolean hook value
368 function onPluginVersion(&$versions)
371 'name' => 'OpenMicroBlogging',
372 'version' => STATUSNET_VERSION,
373 'author' => 'Zach Copley',
374 'homepage' => 'http://status.net/wiki/Plugin:Sample',
375 // TRANS: Plugin description.
376 'rawdescription' => _m('A sample plugin to show basics of development for new hackers.')