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
58 * Load related modules when needed
60 * @param string $cls Name of the class to be loaded
62 * @return boolean hook value; true means continue processing, false means stop.
64 function onAutoload($cls)
66 $dir = dirname(__FILE__);
70 case 'Requesttokenaction':
71 case 'Accesstokenaction':
72 case 'Userauthorizationaction':
73 case 'Postnoticeaction':
74 case 'Updateprofileaction':
75 case 'Finishremotesubscribeaction':
76 case 'Remotesubscribeaction':
78 include_once $dir . '/action/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
81 case 'OmbQueueHandler':
82 case 'ProfileQueueHandler':
83 include_once $dir . '/lib/' . strtolower($cls) . '.php';
85 case 'OMBOAuthDataStore':
86 include_once $dir . '/lib/omboauthstore.php';
95 * @param Net_URL_Mapper $m path-to-action mapper
97 * @return boolean hook value; true means continue processing, false means stop.
99 function onRouterInitialized($m)
107 'finishremotesubscribe'
110 foreach ($bare as $action) {
112 'index.php?action=' . $action, array('action' => $action)
118 $m->connect('main/remote', array('action' => 'remotesubscribe'));
120 'main/remote?nickname=:nickname',
121 array('action' => 'remotesubscribe'),
122 array('nickname' => '[A-Za-z0-9_-]+')
127 array('action' => 'xrds', 'nickname' => $nickname)
134 * Put saved notices into the queue for OMB distribution
136 * @param Notice $notice the notice to broadcast
137 * @param array $transports queuehandler's list of transports
138 * @return boolean true if queing was successful
140 function onStartEnqueueNotice($notice, &$transports)
142 if ($notice->isLocal()) {
143 if ($notice->inScope(null)) {
144 array_unshift($transports, 'omb');
146 LOG_INFO, "Notice {$notice->id} queued for OMB processing"
149 // Note: We don't do privacy-controlled OMB updates.
152 "Not queueing notice {$notice->id} for OMB because of "
153 . "privacy; scope = {$notice->scope}",
160 "Not queueing notice {$notice->id} for OMB because it's not "
170 * Set up queue handlers for outgoing OMB pushes
172 * @param QueueManager $qm
173 * @return boolean hook return
175 function onEndInitializeQueueManager(QueueManager $qm)
177 // Prepare outgoing distributions after notice save.
178 $qm->connect('omb', 'OmbQueueHandler');
179 $qm->connect('profile', 'ProfileQueueHandler');
185 * Return OMB remote profile, if any
187 * @param Profile $profile
189 * @return boolen false if there's a remote profile
191 function onStartGetProfileUri($profile, &$uri)
193 $remote = Remote_profile::staticGet('id', $this->id);
194 if (!empty($remote)) {
202 * We can't initiate subscriptions for a remote OMB profile; don't show
205 * @param type $action
207 function onStartShowProfileListSubscribeButton($action)
209 $remote = Remote_profile::staticGet('id', $action->profile->id);
210 if (empty($remote)) {
217 * Check for illegal subscription attempts
219 * @param User $user subscriber
220 * @param Profile $other subscribee
221 * @return hook return value
223 function onStartSubscribe($profile, $other)
225 // OMB 0.1 doesn't have a mechanism for local-server-
226 // originated subscription.
228 $omb01 = Remote_profile::staticGet('id', $other_id);
230 if (!empty($omb01)) {
231 throw new ClientException(
232 // TRANS: Client error displayed trying to subscribe to an OMB 0.1 remote profile.
233 _m('You cannot subscribe to an OMB 0.1 '
234 . 'remote profile with this action.'
242 * Throw an error if someone tries to tag a remote profile
244 * @param Profile $tagger_profile profile of the tagger
245 * @param Profile $tagged_profile profile of the taggee
250 function onStartTagProfile($tagger_profile, $tagged_profile, $tag)
252 // OMB 0.1 doesn't have a mechanism for local-server-
255 $omb01 = Remote_profile::staticGet('id', $tagged_profile->id);
257 if (!empty($omb01)) {
259 // TRANS: Client error displayed when trying to add an OMB 0.1 remote profile to a list.
260 _m('You cannot list an OMB 0.1 '
261 .'remote profile with this action.')
268 * Check to make sure we're not tryng to untag an OMB profile
270 * // XXX: Should this ever happen?
272 * @param Profile_tag $ptag the profile tag
274 function onUntagProfile($ptag)
276 // OMB 0.1 doesn't have a mechanism for local-server-
279 $omb01 = Remote_profile::staticGet('id', $ptag->tagged);
281 if (!empty($omb01)) {
283 // TRANS: Client error displayed when trying to (un)list an OMB 0.1 remote profile.
284 _m('You cannot (un)list an OMB 0.1 '
285 . 'remote profile with this action.')
292 * Remove old OMB subscription tokens
294 * @param User $user subscriber
295 * @param Profile $other subscribee
296 * @return hook return value
298 function onEndUnsubscribe($profile, $other)
300 $sub = Subscription::pkeyGet(
301 array('subscriber' => $subscriber->id, 'subscribed' => $other->id)
304 if (!empty($sub->token)) {
306 $token = new Token();
308 $token->tok = $sub->token;
310 if ($token->find(true)) {
312 $result = $token->delete();
315 common_log_db_error($token, 'DELETE', __FILE__);
317 // TRANS: Exception thrown when the OMB token for a subscription could not deleted on the server.
318 _m('Could not delete subscription OMB token.')
324 "Couldn't find credentials with token {$token->tok}",
334 * Search for an OMB remote profile by URI
336 * @param string $uri remote profile URI
337 * @param Profile $profile the profile to set
338 * @return boolean hook value
340 function onStartGetProfileFromURI($uri, &$profile)
342 $remote_profile = Remote_profile::staticGet('uri', $uri);
343 if (!empty($remote_profile)) {
344 $profile = Profile::staticGet('id', $remote_profile->profile_id);
352 * Return OMB remote profiles as well as regular profiles
355 * @param type $profile
358 function onStartCommonProfileURI($profile, &$uri)
360 $remote = Remote_profile::staticGet($profile->id);
369 * Broadcast a profile over OMB
371 * @param Profile $profile to broadcast
374 function onBroadcastProfile($profile) {
375 $qm = QueueManager::get();
376 $qm->enqueue($profile, "profile");
380 function onStartProfileRemoteSubscribe($out, $profile)
382 $out->elementStart('li', 'entity_subscribe');
383 $url = common_local_url('remotesubscribe',
384 array('nickname' => $this->profile->nickname));
385 $out->element('a', array('href' => $url,
386 'class' => 'entity_remote_subscribe'),
387 // TRANS: Link text for link that will subscribe to a remote profile.
388 _m('BUTTON','Subscribe'));
389 $out->elementEnd('li');
395 * Plugin version info
397 * @param array $versions
398 * @return boolean hook value
400 function onPluginVersion(&$versions)
403 'name' => 'OpenMicroBlogging',
404 'version' => STATUSNET_VERSION,
405 'author' => 'Zach Copley',
406 'homepage' => 'http://status.net/wiki/Plugin:Sample',
407 // TRANS: Plugin description.
408 'rawdescription' => _m('A sample plugin to show basics of development for new hackers.')