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 // TRANS: Client error displayed trying to subscribe to an OMB 0.1 remote profile.
232 throw new ClientException(
234 'You cannot subscribe to an OMB 0.1 '
235 . 'remote profile with this action.'
244 * Throw an error if someone tries to tag a remote profile
246 * @param Profile $tagger_profile profile of the tagger
247 * @param Profile $tagged_profile profile of the taggee
252 function onStartTagProfile($tagger_profile, $tagged_profile, $tag)
254 // OMB 0.1 doesn't have a mechanism for local-server-
257 $omb01 = Remote_profile::staticGet('id', $tagged_profile->id);
259 if (!empty($omb01)) {
260 // TRANS: Client error displayed when trying to add an OMB 0.1 remote profile to a list.
263 'You cannot list an OMB 0.1 '
264 .'remote profile with this action.')
271 * Check to make sure we're not tryng to untag an OMB profile
273 * // XXX: Should this ever happen?
275 * @param Profile_tag $ptag the profile tag
277 function onUntagProfile($ptag)
279 // OMB 0.1 doesn't have a mechanism for local-server-
282 $omb01 = Remote_profile::staticGet('id', $ptag->tagged);
284 if (!empty($omb01)) {
285 // TRANS: Client error displayed when trying to (un)list an OMB 0.1 remote profile.
288 'You cannot (un)list an OMB 0.1 '
289 . 'remote profile with this action.')
296 * Remove old OMB subscription tokens
298 * @param User $user subscriber
299 * @param Profile $other subscribee
300 * @return hook return value
302 function onEndUnsubscribe($profile, $other)
304 $sub = Subscription::pkeyGet(
305 array('subscriber' => $subscriber->id, 'subscribed' => $other->id)
308 if (!empty($sub->token)) {
310 $token = new Token();
312 $token->tok = $sub->token;
314 if ($token->find(true)) {
316 $result = $token->delete();
319 common_log_db_error($token, 'DELETE', __FILE__);
320 // TRANS: Exception thrown when the OMB token for a subscription could not deleted on the server.
322 _m('Could not delete subscription OMB token.')
328 "Couldn't find credentials with token {$token->tok}",
338 * Search for an OMB remote profile by URI
340 * @param string $uri remote profile URI
341 * @param Profile $profile the profile to set
342 * @return boolean hook value
344 function onStartGetProfileFromURI($uri, &$profile)
346 $remote_profile = Remote_profile::staticGet('uri', $uri);
347 if (!empty($remote_profile)) {
348 $profile = Profile::staticGet('id', $remote_profile->profile_id);
356 * Return OMB remote profiles as well as regular profiles
359 * @param type $profile
362 function onStartCommonProfileURI($profile, &$uri)
364 $remote = Remote_profile::staticGet($profile->id);
373 * Plugin version info
375 * @param array $versions
376 * @return boolean hook value
378 function onPluginVersion(&$versions)
381 'name' => 'OpenMicroBlogging',
382 'version' => STATUSNET_VERSION,
383 'author' => 'Zach Copley',
384 'homepage' => 'http://status.net/wiki/Plugin:Sample',
386 // TRANS: Plugin description.
387 _m('A sample plugin to show basics of development for new hackers.')