3 * StatusNet, the distributed open-source microblogging tool
5 * URL routing utilities
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once 'Net/URL/Mapper.php';
36 class StatusNet_URL_Mapper extends Net_URL_Mapper
38 private static $_singleton = null;
39 private $_actionToPath = array();
41 private function __construct()
45 public static function getInstance($id = '__default__')
47 if (empty(self::$_singleton)) {
48 self::$_singleton = new StatusNet_URL_Mapper();
50 return self::$_singleton;
53 public function connect($path, $defaults = array(), $rules = array())
56 if (Event::handle('StartConnectPath', array(&$path, &$defaults, &$rules, &$result))) {
57 $result = parent::connect($path, $defaults, $rules);
58 if (array_key_exists('action', $defaults)) {
59 $action = $defaults['action'];
60 } elseif (array_key_exists('action', $rules)) {
61 $action = $rules['action'];
65 $this->_mapAction($action, $result);
66 Event::handle('EndConnectPath', array($path, $defaults, $rules, $result));
71 protected function _mapAction($action, $path)
73 if (!array_key_exists($action, $this->_actionToPath)) {
74 $this->_actionToPath[$action] = array();
76 $this->_actionToPath[$action][] = $path;
80 public function generate($values = array(), $qstring = array(), $anchor = '')
82 if (!array_key_exists('action', $values)) {
83 return parent::generate($values, $qstring, $anchor);
86 $action = $values['action'];
88 if (!array_key_exists($action, $this->_actionToPath)) {
89 return parent::generate($values, $qstring, $anchor);
92 $oldPaths = $this->paths;
93 $this->paths = $this->_actionToPath[$action];
94 $result = parent::generate($values, $qstring, $anchor);
95 $this->paths = $oldPaths;
104 * Cheap wrapper around Net_URL_Mapper
108 * @author Evan Prodromou <evan@status.net>
109 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
110 * @link http://status.net/
116 static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
117 'postnotice', 'updateprofile', 'finishremotesubscribe');
119 static function get()
121 if (!Router::$inst) {
122 Router::$inst = new Router();
124 return Router::$inst;
127 function __construct()
129 if (empty($this->m)) {
130 if (!common_config('router', 'cache')) {
131 $this->m = $this->initialize();
133 $k = self::cacheKey();
134 $c = Cache::instance();
139 $this->m = $this->initialize();
140 $c->set($k, $this->m);
147 * Create a unique hashkey for the router.
149 * The router's url map can change based on the version of the software
150 * you're running and the plugins that are enabled. To avoid having bad routes
151 * get stuck in the cache, the key includes a list of plugins and the software
154 * There can still be problems with a) differences in versions of the plugins and
155 * b) people running code between official versions, but these tend to be more
156 * sophisticated users who can grok what's going on and clear their caches.
158 * @return string cache key string that should uniquely identify a router
161 static function cacheKey()
163 return Cache::codeKey('router');
166 function initialize()
168 $m = StatusNet_URL_Mapper::getInstance();
170 if (Event::handle('StartInitializeRouter', array(&$m))) {
172 $m->connect('robots.txt', array('action' => 'robotstxt'));
174 $m->connect('opensearch/people', array('action' => 'opensearch',
175 'type' => 'people'));
176 $m->connect('opensearch/notice', array('action' => 'opensearch',
177 'type' => 'notice'));
181 $m->connect('doc/:title', array('action' => 'doc'));
183 $m->connect('main/otp/:user_id/:token',
184 array('action' => 'otp'),
185 array('user_id' => '[0-9]+',
188 // main stuff is repetitive
190 $main = array('login', 'logout', 'register', 'subscribe',
191 'unsubscribe', 'confirmaddress', 'recoverpassword',
192 'invite', 'favor', 'disfavor', 'sup',
193 'block', 'unblock', 'subedit',
194 'groupblock', 'groupunblock',
195 'sandbox', 'unsandbox',
196 'silence', 'unsilence',
197 'grantrole', 'revokerole',
204 foreach ($main as $a) {
205 $m->connect('main/'.$a, array('action' => $a));
208 // Also need a block variant accepting ID on URL for mail links
209 $m->connect('main/block/:profileid',
210 array('action' => 'block'),
211 array('profileid' => '[0-9]+'));
213 $m->connect('main/sup/:seconds', array('action' => 'sup'),
214 array('seconds' => '[0-9]+'));
216 $m->connect('main/tagother/:id', array('action' => 'tagother'));
218 $m->connect('main/oembed',
219 array('action' => 'oembed'));
221 $m->connect('main/xrds',
222 array('action' => 'publicxrds'));
223 $m->connect('.well-known/host-meta',
224 array('action' => 'hostmeta'));
225 $m->connect('main/xrd',
226 array('action' => 'userxrd'));
230 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
231 $m->connect('main/'.$c.'/:code', array('action' => $c));
236 $m->connect('main/remote', array('action' => 'remotesubscribe'));
237 $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
239 foreach (Router::$bare as $action) {
240 $m->connect('index.php?action=' . $action, array('action' => $action));
245 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
246 'oauthapps', 'email', 'sms', 'userdesign', 'other') as $s) {
247 $m->connect('settings/'.$s, array('action' => $s.'settings'));
250 $m->connect('settings/oauthapps/show/:id',
251 array('action' => 'showapplication'),
252 array('id' => '[0-9]+')
254 $m->connect('settings/oauthapps/new',
255 array('action' => 'newapplication')
257 $m->connect('settings/oauthapps/edit/:id',
258 array('action' => 'editapplication'),
259 array('id' => '[0-9]+')
261 $m->connect('settings/oauthapps/delete/:id',
262 array('action' => 'deleteapplication'),
263 array('id' => '[0-9]+')
268 foreach (array('group', 'people', 'notice') as $s) {
269 $m->connect('search/'.$s, array('action' => $s.'search'));
270 $m->connect('search/'.$s.'?q=:q',
271 array('action' => $s.'search'),
275 // The second of these is needed to make the link work correctly
276 // when inserted into the page. The first is needed to match the
277 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
278 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
279 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
282 $m->connect('attachment/:attachment',
283 array('action' => 'attachment'),
284 array('attachment' => '[0-9]+'));
286 $m->connect('attachment/:attachment/ajax',
287 array('action' => 'attachment_ajax'),
288 array('attachment' => '[0-9]+'));
290 $m->connect('attachment/:attachment/thumbnail',
291 array('action' => 'attachment_thumbnail'),
292 array('attachment' => '[0-9]+'));
294 $m->connect('notice/new', array('action' => 'newnotice'));
295 $m->connect('notice/new?replyto=:replyto',
296 array('action' => 'newnotice'),
297 array('replyto' => Nickname::DISPLAY_FMT));
298 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
299 array('action' => 'newnotice'),
300 array('replyto' => Nickname::DISPLAY_FMT),
301 array('inreplyto' => '[0-9]+'));
303 $m->connect('notice/:notice/file',
304 array('action' => 'file'),
305 array('notice' => '[0-9]+'));
307 $m->connect('notice/:notice',
308 array('action' => 'shownotice'),
309 array('notice' => '[0-9]+'));
310 $m->connect('notice/delete', array('action' => 'deletenotice'));
311 $m->connect('notice/delete/:notice',
312 array('action' => 'deletenotice'),
313 array('notice' => '[0-9]+'));
315 $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
319 $m->connect('conversation/:id',
320 array('action' => 'conversation'),
321 array('id' => '[0-9]+'));
323 $m->connect('message/new', array('action' => 'newmessage'));
324 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => Nickname::DISPLAY_FMT));
325 $m->connect('message/:message',
326 array('action' => 'showmessage'),
327 array('message' => '[0-9]+'));
329 $m->connect('user/:id',
330 array('action' => 'userbyid'),
331 array('id' => '[0-9]+'));
333 $m->connect('tags/', array('action' => 'publictagcloud'));
334 $m->connect('tag/', array('action' => 'publictagcloud'));
335 $m->connect('tags', array('action' => 'publictagcloud'));
336 $m->connect('tag', array('action' => 'publictagcloud'));
337 $m->connect('tag/:tag/rss',
338 array('action' => 'tagrss'),
339 array('tag' => '[\pL\pN_\-\.]{1,64}'));
340 $m->connect('tag/:tag',
341 array('action' => 'tag'),
342 array('tag' => '[\pL\pN_\-\.]{1,64}'));
344 $m->connect('peopletag/:tag',
345 array('action' => 'peopletag'),
346 array('tag' => '[a-zA-Z0-9]+'));
350 $m->connect('group/new', array('action' => 'newgroup'));
352 foreach (array('edit', 'join', 'leave', 'delete') as $v) {
353 $m->connect('group/:nickname/'.$v,
354 array('action' => $v.'group'),
355 array('nickname' => Nickname::DISPLAY_FMT));
356 $m->connect('group/:id/id/'.$v,
357 array('action' => $v.'group'),
358 array('id' => '[0-9]+'));
361 foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
362 $m->connect('group/:nickname/'.$n,
363 array('action' => 'group'.$n),
364 array('nickname' => Nickname::DISPLAY_FMT));
367 $m->connect('group/:nickname/foaf',
368 array('action' => 'foafgroup'),
369 array('nickname' => Nickname::DISPLAY_FMT));
371 $m->connect('group/:nickname/blocked',
372 array('action' => 'blockedfromgroup'),
373 array('nickname' => Nickname::DISPLAY_FMT));
375 $m->connect('group/:nickname/makeadmin',
376 array('action' => 'makeadmin'),
377 array('nickname' => Nickname::DISPLAY_FMT));
379 $m->connect('group/:id/id',
380 array('action' => 'groupbyid'),
381 array('id' => '[0-9]+'));
383 $m->connect('group/:nickname',
384 array('action' => 'showgroup'),
385 array('nickname' => Nickname::DISPLAY_FMT));
387 $m->connect('group/', array('action' => 'groups'));
388 $m->connect('group', array('action' => 'groups'));
389 $m->connect('groups/', array('action' => 'groups'));
390 $m->connect('groups', array('action' => 'groups'));
392 // Twitter-compatible API
396 $m->connect('api/statuses/public_timeline.:format',
397 array('action' => 'ApiTimelinePublic',
398 'format' => '(xml|json|rss|atom)'));
400 $m->connect('api/statuses/friends_timeline.:format',
401 array('action' => 'ApiTimelineFriends',
402 'format' => '(xml|json|rss|atom)'));
404 $m->connect('api/statuses/friends_timeline/:id.:format',
405 array('action' => 'ApiTimelineFriends',
406 'id' => Nickname::INPUT_FMT,
407 'format' => '(xml|json|rss|atom)'));
409 $m->connect('api/statuses/home_timeline.:format',
410 array('action' => 'ApiTimelineHome',
411 'format' => '(xml|json|rss|atom)'));
413 $m->connect('api/statuses/home_timeline/:id.:format',
414 array('action' => 'ApiTimelineHome',
415 'id' => Nickname::INPUT_FMT,
416 'format' => '(xml|json|rss|atom)'));
418 $m->connect('api/statuses/user_timeline.:format',
419 array('action' => 'ApiTimelineUser',
420 'format' => '(xml|json|rss|atom)'));
422 $m->connect('api/statuses/user_timeline/:id.:format',
423 array('action' => 'ApiTimelineUser',
424 'id' => Nickname::INPUT_FMT,
425 'format' => '(xml|json|rss|atom)'));
427 $m->connect('api/statuses/mentions.:format',
428 array('action' => 'ApiTimelineMentions',
429 'format' => '(xml|json|rss|atom)'));
431 $m->connect('api/statuses/mentions/:id.:format',
432 array('action' => 'ApiTimelineMentions',
433 'id' => Nickname::INPUT_FMT,
434 'format' => '(xml|json|rss|atom)'));
436 $m->connect('api/statuses/replies.:format',
437 array('action' => 'ApiTimelineMentions',
438 'format' => '(xml|json|rss|atom)'));
440 $m->connect('api/statuses/replies/:id.:format',
441 array('action' => 'ApiTimelineMentions',
442 'id' => Nickname::INPUT_FMT,
443 'format' => '(xml|json|rss|atom)'));
445 $m->connect('api/statuses/retweeted_by_me.:format',
446 array('action' => 'ApiTimelineRetweetedByMe',
447 'format' => '(xml|json|atom)'));
449 $m->connect('api/statuses/retweeted_to_me.:format',
450 array('action' => 'ApiTimelineRetweetedToMe',
451 'format' => '(xml|json|atom)'));
453 $m->connect('api/statuses/retweets_of_me.:format',
454 array('action' => 'ApiTimelineRetweetsOfMe',
455 'format' => '(xml|json|atom)'));
457 $m->connect('api/statuses/friends.:format',
458 array('action' => 'ApiUserFriends',
459 'format' => '(xml|json)'));
461 $m->connect('api/statuses/friends/:id.:format',
462 array('action' => 'ApiUserFriends',
463 'id' => Nickname::INPUT_FMT,
464 'format' => '(xml|json)'));
466 $m->connect('api/statuses/followers.:format',
467 array('action' => 'ApiUserFollowers',
468 'format' => '(xml|json)'));
470 $m->connect('api/statuses/followers/:id.:format',
471 array('action' => 'ApiUserFollowers',
472 'id' => Nickname::INPUT_FMT,
473 'format' => '(xml|json)'));
475 $m->connect('api/statuses/show.:format',
476 array('action' => 'ApiStatusesShow',
477 'format' => '(xml|json|atom)'));
479 $m->connect('api/statuses/show/:id.:format',
480 array('action' => 'ApiStatusesShow',
482 'format' => '(xml|json|atom)'));
484 $m->connect('api/statuses/update.:format',
485 array('action' => 'ApiStatusesUpdate',
486 'format' => '(xml|json)'));
488 $m->connect('api/statuses/destroy.:format',
489 array('action' => 'ApiStatusesDestroy',
490 'format' => '(xml|json)'));
492 $m->connect('api/statuses/destroy/:id.:format',
493 array('action' => 'ApiStatusesDestroy',
495 'format' => '(xml|json)'));
497 $m->connect('api/statuses/retweet/:id.:format',
498 array('action' => 'ApiStatusesRetweet',
500 'format' => '(xml|json)'));
502 $m->connect('api/statuses/retweets/:id.:format',
503 array('action' => 'ApiStatusesRetweets',
505 'format' => '(xml|json)'));
509 $m->connect('api/users/show.:format',
510 array('action' => 'ApiUserShow',
511 'format' => '(xml|json)'));
513 $m->connect('api/users/show/:id.:format',
514 array('action' => 'ApiUserShow',
515 'id' => Nickname::INPUT_FMT,
516 'format' => '(xml|json)'));
520 $m->connect('api/direct_messages.:format',
521 array('action' => 'ApiDirectMessage',
522 'format' => '(xml|json|rss|atom)'));
524 $m->connect('api/direct_messages/sent.:format',
525 array('action' => 'ApiDirectMessage',
526 'format' => '(xml|json|rss|atom)',
529 $m->connect('api/direct_messages/new.:format',
530 array('action' => 'ApiDirectMessageNew',
531 'format' => '(xml|json)'));
535 $m->connect('api/friendships/show.:format',
536 array('action' => 'ApiFriendshipsShow',
537 'format' => '(xml|json)'));
539 $m->connect('api/friendships/exists.:format',
540 array('action' => 'ApiFriendshipsExists',
541 'format' => '(xml|json)'));
543 $m->connect('api/friendships/create.:format',
544 array('action' => 'ApiFriendshipsCreate',
545 'format' => '(xml|json)'));
547 $m->connect('api/friendships/destroy.:format',
548 array('action' => 'ApiFriendshipsDestroy',
549 'format' => '(xml|json)'));
551 $m->connect('api/friendships/create/:id.:format',
552 array('action' => 'ApiFriendshipsCreate',
553 'id' => Nickname::INPUT_FMT,
554 'format' => '(xml|json)'));
556 $m->connect('api/friendships/destroy/:id.:format',
557 array('action' => 'ApiFriendshipsDestroy',
558 'id' => Nickname::INPUT_FMT,
559 'format' => '(xml|json)'));
563 $m->connect('api/friends/ids/:id.:format',
564 array('action' => 'ApiUserFriends',
565 'ids_only' => true));
567 $m->connect('api/followers/ids/:id.:format',
568 array('action' => 'ApiUserFollowers',
569 'ids_only' => true));
571 $m->connect('api/friends/ids.:format',
572 array('action' => 'ApiUserFriends',
573 'ids_only' => true));
575 $m->connect('api/followers/ids.:format',
576 array('action' => 'ApiUserFollowers',
577 'ids_only' => true));
581 $m->connect('api/account/verify_credentials.:format',
582 array('action' => 'ApiAccountVerifyCredentials'));
584 $m->connect('api/account/update_profile.:format',
585 array('action' => 'ApiAccountUpdateProfile'));
587 $m->connect('api/account/update_profile_image.:format',
588 array('action' => 'ApiAccountUpdateProfileImage'));
590 $m->connect('api/account/update_profile_background_image.:format',
591 array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
593 $m->connect('api/account/update_profile_colors.:format',
594 array('action' => 'ApiAccountUpdateProfileColors'));
596 $m->connect('api/account/update_delivery_device.:format',
597 array('action' => 'ApiAccountUpdateDeliveryDevice'));
599 // special case where verify_credentials is called w/out a format
601 $m->connect('api/account/verify_credentials',
602 array('action' => 'ApiAccountVerifyCredentials'));
604 $m->connect('api/account/rate_limit_status.:format',
605 array('action' => 'ApiAccountRateLimitStatus'));
609 $m->connect('api/favorites.:format',
610 array('action' => 'ApiTimelineFavorites',
611 'format' => '(xml|json|rss|atom)'));
613 $m->connect('api/favorites/:id.:format',
614 array('action' => 'ApiTimelineFavorites',
615 'id' => Nickname::INPUT_FMT,
616 'format' => '(xml|json|rss|atom)'));
618 $m->connect('api/favorites/create/:id.:format',
619 array('action' => 'ApiFavoriteCreate',
621 'format' => '(xml|json)'));
623 $m->connect('api/favorites/destroy/:id.:format',
624 array('action' => 'ApiFavoriteDestroy',
626 'format' => '(xml|json)'));
629 $m->connect('api/blocks/create.:format',
630 array('action' => 'ApiBlockCreate',
631 'format' => '(xml|json)'));
633 $m->connect('api/blocks/create/:id.:format',
634 array('action' => 'ApiBlockCreate',
635 'id' => Nickname::INPUT_FMT,
636 'format' => '(xml|json)'));
638 $m->connect('api/blocks/destroy.:format',
639 array('action' => 'ApiBlockDestroy',
640 'format' => '(xml|json)'));
642 $m->connect('api/blocks/destroy/:id.:format',
643 array('action' => 'ApiBlockDestroy',
644 'id' => Nickname::INPUT_FMT,
645 'format' => '(xml|json)'));
648 $m->connect('api/help/test.:format',
649 array('action' => 'ApiHelpTest',
650 'format' => '(xml|json)'));
654 $m->connect('api/statusnet/version.:format',
655 array('action' => 'ApiStatusnetVersion',
656 'format' => '(xml|json)'));
658 $m->connect('api/statusnet/config.:format',
659 array('action' => 'ApiStatusnetConfig',
660 'format' => '(xml|json)'));
662 // For older methods, we provide "laconica" base action
664 $m->connect('api/laconica/version.:format',
665 array('action' => 'ApiStatusnetVersion',
666 'format' => '(xml|json)'));
668 $m->connect('api/laconica/config.:format',
669 array('action' => 'ApiStatusnetConfig',
670 'format' => '(xml|json)'));
672 // Groups and tags are newer than 0.8.1 so no backward-compatibility
676 //'list' has to be handled differently, as php will not allow a method to be named 'list'
678 $m->connect('api/statusnet/groups/timeline/:id.:format',
679 array('action' => 'ApiTimelineGroup',
680 'id' => Nickname::INPUT_FMT,
681 'format' => '(xml|json|rss|atom)'));
683 $m->connect('api/statusnet/groups/show.:format',
684 array('action' => 'ApiGroupShow',
685 'format' => '(xml|json)'));
687 $m->connect('api/statusnet/groups/show/:id.:format',
688 array('action' => 'ApiGroupShow',
689 'id' => Nickname::INPUT_FMT,
690 'format' => '(xml|json)'));
692 $m->connect('api/statusnet/groups/join.:format',
693 array('action' => 'ApiGroupJoin',
694 'id' => Nickname::INPUT_FMT,
695 'format' => '(xml|json)'));
697 $m->connect('api/statusnet/groups/join/:id.:format',
698 array('action' => 'ApiGroupJoin',
699 'format' => '(xml|json)'));
701 $m->connect('api/statusnet/groups/leave.:format',
702 array('action' => 'ApiGroupLeave',
703 'id' => Nickname::INPUT_FMT,
704 'format' => '(xml|json)'));
706 $m->connect('api/statusnet/groups/leave/:id.:format',
707 array('action' => 'ApiGroupLeave',
708 'format' => '(xml|json)'));
710 $m->connect('api/statusnet/groups/is_member.:format',
711 array('action' => 'ApiGroupIsMember',
712 'format' => '(xml|json)'));
714 $m->connect('api/statusnet/groups/list.:format',
715 array('action' => 'ApiGroupList',
716 'format' => '(xml|json|rss|atom)'));
718 $m->connect('api/statusnet/groups/list/:id.:format',
719 array('action' => 'ApiGroupList',
720 'id' => Nickname::INPUT_FMT,
721 'format' => '(xml|json|rss|atom)'));
723 $m->connect('api/statusnet/groups/list_all.:format',
724 array('action' => 'ApiGroupListAll',
725 'format' => '(xml|json|rss|atom)'));
727 $m->connect('api/statusnet/groups/membership.:format',
728 array('action' => 'ApiGroupMembership',
729 'format' => '(xml|json)'));
731 $m->connect('api/statusnet/groups/membership/:id.:format',
732 array('action' => 'ApiGroupMembership',
733 'id' => Nickname::INPUT_FMT,
734 'format' => '(xml|json)'));
736 $m->connect('api/statusnet/groups/create.:format',
737 array('action' => 'ApiGroupCreate',
738 'format' => '(xml|json)'));
740 $m->connect('api/statusnet/tags/timeline/:tag.:format',
741 array('action' => 'ApiTimelineTag',
742 'format' => '(xml|json|rss|atom)'));
746 'api/statusnet/media/upload',
747 array('action' => 'ApiMediaUpload')
751 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
752 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
753 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
755 $m->connect('api/oauth/request_token',
756 array('action' => 'ApiOauthRequestToken'));
758 $m->connect('api/oauth/access_token',
759 array('action' => 'ApiOauthAccessToken'));
761 $m->connect('api/oauth/authorize',
762 array('action' => 'ApiOauthAuthorize'));
766 $m->connect('admin/site', array('action' => 'siteadminpanel'));
767 $m->connect('admin/design', array('action' => 'designadminpanel'));
768 $m->connect('admin/user', array('action' => 'useradminpanel'));
769 $m->connect('admin/access', array('action' => 'accessadminpanel'));
770 $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
771 $m->connect('admin/sessions', array('action' => 'sessionsadminpanel'));
772 $m->connect('admin/sitenotice', array('action' => 'sitenoticeadminpanel'));
773 $m->connect('admin/snapshot', array('action' => 'snapshotadminpanel'));
774 $m->connect('admin/license', array('action' => 'licenseadminpanel'));
776 $m->connect('getfile/:filename',
777 array('action' => 'getfile'),
778 array('filename' => '[A-Za-z0-9._-]+'));
782 if (common_config('singleuser', 'enabled')) {
784 $nickname = User::singleUserNickname();
786 foreach (array('subscriptions', 'subscribers',
787 'all', 'foaf', 'xrds',
788 'replies', 'microsummary', 'hcard') as $a) {
790 array('action' => $a,
791 'nickname' => $nickname));
794 foreach (array('subscriptions', 'subscribers') as $a) {
795 $m->connect($a.'/:tag',
796 array('action' => $a,
797 'nickname' => $nickname),
798 array('tag' => '[a-zA-Z0-9]+'));
801 foreach (array('rss', 'groups') as $a) {
803 array('action' => 'user'.$a,
804 'nickname' => $nickname));
807 foreach (array('all', 'replies', 'favorites') as $a) {
808 $m->connect($a.'/rss',
809 array('action' => $a.'rss',
810 'nickname' => $nickname));
813 $m->connect('favorites',
814 array('action' => 'showfavorites',
815 'nickname' => $nickname));
817 $m->connect('avatar/:size',
818 array('action' => 'avatarbynickname',
819 'nickname' => $nickname),
820 array('size' => '(original|96|48|24)'));
822 $m->connect('tag/:tag/rss',
823 array('action' => 'userrss',
824 'nickname' => $nickname),
825 array('tag' => '[\pL\pN_\-\.]{1,64}'));
827 $m->connect('tag/:tag',
828 array('action' => 'showstream',
829 'nickname' => $nickname),
830 array('tag' => '[\pL\pN_\-\.]{1,64}'));
832 $m->connect('rsd.xml',
833 array('action' => 'rsd',
834 'nickname' => $nickname));
837 array('action' => 'showstream',
838 'nickname' => $nickname));
840 $m->connect('', array('action' => 'public'));
841 $m->connect('rss', array('action' => 'publicrss'));
842 $m->connect('featuredrss', array('action' => 'featuredrss'));
843 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
844 $m->connect('featured/', array('action' => 'featured'));
845 $m->connect('featured', array('action' => 'featured'));
846 $m->connect('favorited/', array('action' => 'favorited'));
847 $m->connect('favorited', array('action' => 'favorited'));
848 $m->connect('rsd.xml', array('action' => 'rsd'));
850 foreach (array('subscriptions', 'subscribers',
851 'nudge', 'all', 'foaf', 'xrds',
852 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
853 $m->connect(':nickname/'.$a,
854 array('action' => $a),
855 array('nickname' => Nickname::DISPLAY_FMT));
858 foreach (array('subscriptions', 'subscribers') as $a) {
859 $m->connect(':nickname/'.$a.'/:tag',
860 array('action' => $a),
861 array('tag' => '[a-zA-Z0-9]+',
862 'nickname' => Nickname::DISPLAY_FMT));
865 foreach (array('rss', 'groups') as $a) {
866 $m->connect(':nickname/'.$a,
867 array('action' => 'user'.$a),
868 array('nickname' => Nickname::DISPLAY_FMT));
871 foreach (array('all', 'replies', 'favorites') as $a) {
872 $m->connect(':nickname/'.$a.'/rss',
873 array('action' => $a.'rss'),
874 array('nickname' => Nickname::DISPLAY_FMT));
877 $m->connect(':nickname/favorites',
878 array('action' => 'showfavorites'),
879 array('nickname' => Nickname::DISPLAY_FMT));
881 $m->connect(':nickname/avatar/:size',
882 array('action' => 'avatarbynickname'),
883 array('size' => '(original|96|48|24)',
884 'nickname' => Nickname::DISPLAY_FMT));
886 $m->connect(':nickname/tag/:tag/rss',
887 array('action' => 'userrss'),
888 array('nickname' => Nickname::DISPLAY_FMT),
889 array('tag' => '[\pL\pN_\-\.]{1,64}'));
891 $m->connect(':nickname/tag/:tag',
892 array('action' => 'showstream'),
893 array('nickname' => Nickname::DISPLAY_FMT),
894 array('tag' => '[\pL\pN_\-\.]{1,64}'));
896 $m->connect(':nickname/rsd.xml',
897 array('action' => 'rsd'),
898 array('nickname' => Nickname::DISPLAY_FMT));
900 $m->connect(':nickname',
901 array('action' => 'showstream'),
902 array('nickname' => Nickname::DISPLAY_FMT));
907 $m->connect('api/statusnet/app/service/:id.xml',
908 array('action' => 'ApiAtomService',
909 'id' => Nickname::DISPLAY_FMT));
911 $m->connect('api/statusnet/app/service.xml',
912 array('action' => 'ApiAtomService'));
914 $m->connect('api/statusnet/app/subscriptions/:subscriber/:subscribed.atom',
915 array('action' => 'AtomPubShowSubscription'),
916 array('subscriber' => '[0-9]+',
917 'subscribed' => '[0-9]+'));
919 $m->connect('api/statusnet/app/subscriptions/:subscriber.atom',
920 array('action' => 'AtomPubSubscriptionFeed'),
921 array('subscriber' => '[0-9]+'));
923 $m->connect('api/statusnet/app/favorites/:profile/:notice.atom',
924 array('action' => 'AtomPubShowFavorite'),
925 array('profile' => '[0-9]+',
926 'notice' => '[0-9]+'));
928 $m->connect('api/statusnet/app/favorites/:profile.atom',
929 array('action' => 'AtomPubFavoriteFeed'),
930 array('profile' => '[0-9]+'));
932 $m->connect('api/statusnet/app/memberships/:profile/:group.atom',
933 array('action' => 'AtomPubShowMembership'),
934 array('profile' => '[0-9]+',
935 'group' => '[0-9]+'));
937 $m->connect('api/statusnet/app/membership/:profile.atom',
938 array('action' => 'AtomPubMembershipFeed'),
939 array('profile' => '[0-9]+'));
943 Event::handle('RouterInitialized', array($m));
952 $match = $this->m->match($path);
953 } catch (Net_URL_Mapper_InvalidException $e) {
954 common_log(LOG_ERR, "Problem getting route for $path - " .
956 // TRANS: Client error on action trying to visit a non-existing page.
957 $cac = new ClientErrorAction(_('Page not found.'), 404);
964 function build($action, $args=null, $params=null, $fragment=null)
966 $action_arg = array('action' => $action);
969 $args = array_merge($action_arg, $args);
974 $url = $this->m->generate($args, $params, $fragment);
976 // Due to a bug in the Net_URL_Mapper code, the returned URL may
977 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
978 // repair that here rather than modifying the upstream code...
980 $qpos = strpos($url, '?');
981 if ($qpos !== false) {
982 $url = substr($url, 0, $qpos+1) .
983 str_replace('?', '&', substr($url, $qpos+1));
985 // @fixme this is a hacky workaround for http_build_query in the
986 // lower-level code and bad configs that set the default separator
987 // to & instead of &. Encoded &s in parameters will not be
989 $url = substr($url, 0, $qpos+1) .
990 str_replace('&', '&', substr($url, $qpos+1));