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 $k = self::cacheKey();
131 $c = Cache::instance();
136 $this->m = $this->initialize();
137 $c->set($k, $this->m);
143 * Create a unique hashkey for the router.
145 * The router's url map can change based on the version of the software
146 * you're running and the plugins that are enabled. To avoid having bad routes
147 * get stuck in the cache, the key includes a list of plugins and the software
150 * There can still be problems with a) differences in versions of the plugins and
151 * b) people running code between official versions, but these tend to be more
152 * sophisticated users who can grok what's going on and clear their caches.
154 * @return string cache key string that should uniquely identify a router
157 static function cacheKey()
159 $plugins = StatusNet::getActivePlugins();
162 foreach ($plugins as $plugin) {
163 $names[] = $plugin[0];
166 $names = array_unique($names);
171 $uniq = crc32(implode(',', $names));
173 return Cache::key('router:'.STATUSNET_VERSION.':'.$uniq);
176 function initialize()
178 $m = StatusNet_URL_Mapper::getInstance();
180 if (Event::handle('StartInitializeRouter', array(&$m))) {
182 $m->connect('robots.txt', array('action' => 'robotstxt'));
184 $m->connect('opensearch/people', array('action' => 'opensearch',
185 'type' => 'people'));
186 $m->connect('opensearch/notice', array('action' => 'opensearch',
187 'type' => 'notice'));
191 $m->connect('doc/:title', array('action' => 'doc'));
193 $m->connect('main/otp/:user_id/:token',
194 array('action' => 'otp'),
195 array('user_id' => '[0-9]+',
198 // main stuff is repetitive
200 $main = array('login', 'logout', 'register', 'subscribe',
201 'unsubscribe', 'confirmaddress', 'recoverpassword',
202 'invite', 'favor', 'disfavor', 'sup',
203 'block', 'unblock', 'subedit',
204 'groupblock', 'groupunblock',
205 'sandbox', 'unsandbox',
206 'silence', 'unsilence',
207 'grantrole', 'revokerole',
214 foreach ($main as $a) {
215 $m->connect('main/'.$a, array('action' => $a));
218 // Also need a block variant accepting ID on URL for mail links
219 $m->connect('main/block/:profileid',
220 array('action' => 'block'),
221 array('profileid' => '[0-9]+'));
223 $m->connect('main/sup/:seconds', array('action' => 'sup'),
224 array('seconds' => '[0-9]+'));
226 $m->connect('main/tagother/:id', array('action' => 'tagother'));
228 $m->connect('main/oembed',
229 array('action' => 'oembed'));
231 $m->connect('main/xrds',
232 array('action' => 'publicxrds'));
236 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
237 $m->connect('main/'.$c.'/:code', array('action' => $c));
242 $m->connect('main/remote', array('action' => 'remotesubscribe'));
243 $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
245 foreach (Router::$bare as $action) {
246 $m->connect('index.php?action=' . $action, array('action' => $action));
251 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
252 'oauthapps', 'email', 'sms', 'userdesign', 'other') as $s) {
253 $m->connect('settings/'.$s, array('action' => $s.'settings'));
256 $m->connect('settings/oauthapps/show/:id',
257 array('action' => 'showapplication'),
258 array('id' => '[0-9]+')
260 $m->connect('settings/oauthapps/new',
261 array('action' => 'newapplication')
263 $m->connect('settings/oauthapps/edit/:id',
264 array('action' => 'editapplication'),
265 array('id' => '[0-9]+')
267 $m->connect('settings/oauthapps/delete/:id',
268 array('action' => 'deleteapplication'),
269 array('id' => '[0-9]+')
274 foreach (array('group', 'people', 'notice') as $s) {
275 $m->connect('search/'.$s, array('action' => $s.'search'));
276 $m->connect('search/'.$s.'?q=:q',
277 array('action' => $s.'search'),
281 // The second of these is needed to make the link work correctly
282 // when inserted into the page. The first is needed to match the
283 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
284 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
285 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
288 $m->connect('attachment/:attachment',
289 array('action' => 'attachment'),
290 array('attachment' => '[0-9]+'));
292 $m->connect('attachment/:attachment/ajax',
293 array('action' => 'attachment_ajax'),
294 array('attachment' => '[0-9]+'));
296 $m->connect('attachment/:attachment/thumbnail',
297 array('action' => 'attachment_thumbnail'),
298 array('attachment' => '[0-9]+'));
300 $m->connect('notice/new', array('action' => 'newnotice'));
301 $m->connect('notice/new?replyto=:replyto',
302 array('action' => 'newnotice'),
303 array('replyto' => '[A-Za-z0-9_-]+'));
304 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
305 array('action' => 'newnotice'),
306 array('replyto' => '[A-Za-z0-9_-]+'),
307 array('inreplyto' => '[0-9]+'));
309 $m->connect('notice/:notice/file',
310 array('action' => 'file'),
311 array('notice' => '[0-9]+'));
313 $m->connect('notice/:notice',
314 array('action' => 'shownotice'),
315 array('notice' => '[0-9]+'));
316 $m->connect('notice/delete', array('action' => 'deletenotice'));
317 $m->connect('notice/delete/:notice',
318 array('action' => 'deletenotice'),
319 array('notice' => '[0-9]+'));
321 $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
325 $m->connect('conversation/:id',
326 array('action' => 'conversation'),
327 array('id' => '[0-9]+'));
329 $m->connect('message/new', array('action' => 'newmessage'));
330 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
331 $m->connect('message/:message',
332 array('action' => 'showmessage'),
333 array('message' => '[0-9]+'));
335 $m->connect('user/:id',
336 array('action' => 'userbyid'),
337 array('id' => '[0-9]+'));
339 $m->connect('tags/', array('action' => 'publictagcloud'));
340 $m->connect('tag/', array('action' => 'publictagcloud'));
341 $m->connect('tags', array('action' => 'publictagcloud'));
342 $m->connect('tag', array('action' => 'publictagcloud'));
343 $m->connect('tag/:tag/rss',
344 array('action' => 'tagrss'),
345 array('tag' => '[\pL\pN_\-\.]{1,64}'));
346 $m->connect('tag/:tag',
347 array('action' => 'tag'),
348 array('tag' => '[\pL\pN_\-\.]{1,64}'));
350 $m->connect('peopletag/:tag',
351 array('action' => 'peopletag'),
352 array('tag' => '[a-zA-Z0-9]+'));
356 $m->connect('group/new', array('action' => 'newgroup'));
358 foreach (array('edit', 'join', 'leave', 'delete') as $v) {
359 $m->connect('group/:nickname/'.$v,
360 array('action' => $v.'group'),
361 array('nickname' => '[a-zA-Z0-9]+'));
362 $m->connect('group/:id/id/'.$v,
363 array('action' => $v.'group'),
364 array('id' => '[0-9]+'));
367 foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
368 $m->connect('group/:nickname/'.$n,
369 array('action' => 'group'.$n),
370 array('nickname' => '[a-zA-Z0-9]+'));
373 $m->connect('group/:nickname/foaf',
374 array('action' => 'foafgroup'),
375 array('nickname' => '[a-zA-Z0-9]+'));
377 $m->connect('group/:nickname/blocked',
378 array('action' => 'blockedfromgroup'),
379 array('nickname' => '[a-zA-Z0-9]+'));
381 $m->connect('group/:nickname/makeadmin',
382 array('action' => 'makeadmin'),
383 array('nickname' => '[a-zA-Z0-9]+'));
385 $m->connect('group/:id/id',
386 array('action' => 'groupbyid'),
387 array('id' => '[0-9]+'));
389 $m->connect('group/:nickname',
390 array('action' => 'showgroup'),
391 array('nickname' => '[a-zA-Z0-9]+'));
393 $m->connect('group/', array('action' => 'groups'));
394 $m->connect('group', array('action' => 'groups'));
395 $m->connect('groups/', array('action' => 'groups'));
396 $m->connect('groups', array('action' => 'groups'));
398 // Twitter-compatible API
402 $m->connect('api/statuses/public_timeline.:format',
403 array('action' => 'ApiTimelinePublic',
404 'format' => '(xml|json|rss|atom)'));
406 $m->connect('api/statuses/friends_timeline.:format',
407 array('action' => 'ApiTimelineFriends',
408 'format' => '(xml|json|rss|atom)'));
410 $m->connect('api/statuses/friends_timeline/:id.:format',
411 array('action' => 'ApiTimelineFriends',
412 'id' => '[a-zA-Z0-9]+',
413 'format' => '(xml|json|rss|atom)'));
415 $m->connect('api/statuses/home_timeline.:format',
416 array('action' => 'ApiTimelineHome',
417 'format' => '(xml|json|rss|atom)'));
419 $m->connect('api/statuses/home_timeline/:id.:format',
420 array('action' => 'ApiTimelineHome',
421 'id' => '[a-zA-Z0-9]+',
422 'format' => '(xml|json|rss|atom)'));
424 $m->connect('api/statuses/user_timeline.:format',
425 array('action' => 'ApiTimelineUser',
426 'format' => '(xml|json|rss|atom)'));
428 $m->connect('api/statuses/user_timeline/:id.:format',
429 array('action' => 'ApiTimelineUser',
430 'id' => '[a-zA-Z0-9]+',
431 'format' => '(xml|json|rss|atom)'));
433 $m->connect('api/statuses/mentions.:format',
434 array('action' => 'ApiTimelineMentions',
435 'format' => '(xml|json|rss|atom)'));
437 $m->connect('api/statuses/mentions/:id.:format',
438 array('action' => 'ApiTimelineMentions',
439 'id' => '[a-zA-Z0-9]+',
440 'format' => '(xml|json|rss|atom)'));
442 $m->connect('api/statuses/replies.:format',
443 array('action' => 'ApiTimelineMentions',
444 'format' => '(xml|json|rss|atom)'));
446 $m->connect('api/statuses/replies/:id.:format',
447 array('action' => 'ApiTimelineMentions',
448 'id' => '[a-zA-Z0-9]+',
449 'format' => '(xml|json|rss|atom)'));
451 $m->connect('api/statuses/retweeted_by_me.:format',
452 array('action' => 'ApiTimelineRetweetedByMe',
453 'format' => '(xml|json|atom)'));
455 $m->connect('api/statuses/retweeted_to_me.:format',
456 array('action' => 'ApiTimelineRetweetedToMe',
457 'format' => '(xml|json|atom)'));
459 $m->connect('api/statuses/retweets_of_me.:format',
460 array('action' => 'ApiTimelineRetweetsOfMe',
461 'format' => '(xml|json|atom)'));
463 $m->connect('api/statuses/friends.:format',
464 array('action' => 'ApiUserFriends',
465 'format' => '(xml|json)'));
467 $m->connect('api/statuses/friends/:id.:format',
468 array('action' => 'ApiUserFriends',
469 'id' => '[a-zA-Z0-9]+',
470 'format' => '(xml|json)'));
472 $m->connect('api/statuses/followers.:format',
473 array('action' => 'ApiUserFollowers',
474 'format' => '(xml|json)'));
476 $m->connect('api/statuses/followers/:id.:format',
477 array('action' => 'ApiUserFollowers',
478 'id' => '[a-zA-Z0-9]+',
479 'format' => '(xml|json)'));
481 $m->connect('api/statuses/show.:format',
482 array('action' => 'ApiStatusesShow',
483 'format' => '(xml|json)'));
485 $m->connect('api/statuses/show/:id.:format',
486 array('action' => 'ApiStatusesShow',
488 'format' => '(xml|json)'));
490 $m->connect('api/statuses/update.:format',
491 array('action' => 'ApiStatusesUpdate',
492 'format' => '(xml|json)'));
494 $m->connect('api/statuses/destroy.:format',
495 array('action' => 'ApiStatusesDestroy',
496 'format' => '(xml|json)'));
498 $m->connect('api/statuses/destroy/:id.:format',
499 array('action' => 'ApiStatusesDestroy',
501 'format' => '(xml|json)'));
503 $m->connect('api/statuses/retweet/:id.:format',
504 array('action' => 'ApiStatusesRetweet',
506 'format' => '(xml|json)'));
508 $m->connect('api/statuses/retweets/:id.:format',
509 array('action' => 'ApiStatusesRetweets',
511 'format' => '(xml|json)'));
515 $m->connect('api/users/show.:format',
516 array('action' => 'ApiUserShow',
517 'format' => '(xml|json)'));
519 $m->connect('api/users/show/:id.:format',
520 array('action' => 'ApiUserShow',
521 'id' => '[a-zA-Z0-9]+',
522 'format' => '(xml|json)'));
526 $m->connect('api/direct_messages.:format',
527 array('action' => 'ApiDirectMessage',
528 'format' => '(xml|json|rss|atom)'));
530 $m->connect('api/direct_messages/sent.:format',
531 array('action' => 'ApiDirectMessage',
532 'format' => '(xml|json|rss|atom)',
535 $m->connect('api/direct_messages/new.:format',
536 array('action' => 'ApiDirectMessageNew',
537 'format' => '(xml|json)'));
541 $m->connect('api/friendships/show.:format',
542 array('action' => 'ApiFriendshipsShow',
543 'format' => '(xml|json)'));
545 $m->connect('api/friendships/exists.:format',
546 array('action' => 'ApiFriendshipsExists',
547 'format' => '(xml|json)'));
549 $m->connect('api/friendships/create.:format',
550 array('action' => 'ApiFriendshipsCreate',
551 'format' => '(xml|json)'));
553 $m->connect('api/friendships/destroy.:format',
554 array('action' => 'ApiFriendshipsDestroy',
555 'format' => '(xml|json)'));
557 $m->connect('api/friendships/create/:id.:format',
558 array('action' => 'ApiFriendshipsCreate',
559 'id' => '[a-zA-Z0-9]+',
560 'format' => '(xml|json)'));
562 $m->connect('api/friendships/destroy/:id.:format',
563 array('action' => 'ApiFriendshipsDestroy',
564 'id' => '[a-zA-Z0-9]+',
565 'format' => '(xml|json)'));
569 $m->connect('api/friends/ids/:id.:format',
570 array('action' => 'ApiUserFriends',
571 'ids_only' => true));
573 $m->connect('api/followers/ids/:id.:format',
574 array('action' => 'ApiUserFollowers',
575 'ids_only' => true));
577 $m->connect('api/friends/ids.:format',
578 array('action' => 'ApiUserFriends',
579 'ids_only' => true));
581 $m->connect('api/followers/ids.:format',
582 array('action' => 'ApiUserFollowers',
583 'ids_only' => true));
587 $m->connect('api/account/verify_credentials.:format',
588 array('action' => 'ApiAccountVerifyCredentials'));
590 $m->connect('api/account/update_profile.:format',
591 array('action' => 'ApiAccountUpdateProfile'));
593 $m->connect('api/account/update_profile_image.:format',
594 array('action' => 'ApiAccountUpdateProfileImage'));
596 $m->connect('api/account/update_profile_background_image.:format',
597 array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
599 $m->connect('api/account/update_profile_colors.:format',
600 array('action' => 'ApiAccountUpdateProfileColors'));
602 $m->connect('api/account/update_delivery_device.:format',
603 array('action' => 'ApiAccountUpdateDeliveryDevice'));
605 // special case where verify_credentials is called w/out a format
607 $m->connect('api/account/verify_credentials',
608 array('action' => 'ApiAccountVerifyCredentials'));
610 $m->connect('api/account/rate_limit_status.:format',
611 array('action' => 'ApiAccountRateLimitStatus'));
615 $m->connect('api/favorites.:format',
616 array('action' => 'ApiTimelineFavorites',
617 'format' => '(xml|json|rss|atom)'));
619 $m->connect('api/favorites/:id.:format',
620 array('action' => 'ApiTimelineFavorites',
621 'id' => '[a-zA-Z0-9]+',
622 'format' => '(xml|json|rss|atom)'));
624 $m->connect('api/favorites/create/:id.:format',
625 array('action' => 'ApiFavoriteCreate',
626 'id' => '[a-zA-Z0-9]+',
627 'format' => '(xml|json)'));
629 $m->connect('api/favorites/destroy/:id.:format',
630 array('action' => 'ApiFavoriteDestroy',
631 'id' => '[a-zA-Z0-9]+',
632 'format' => '(xml|json)'));
635 $m->connect('api/blocks/create.:format',
636 array('action' => 'ApiBlockCreate',
637 'format' => '(xml|json)'));
639 $m->connect('api/blocks/create/:id.:format',
640 array('action' => 'ApiBlockCreate',
641 'id' => '[a-zA-Z0-9]+',
642 'format' => '(xml|json)'));
644 $m->connect('api/blocks/destroy.:format',
645 array('action' => 'ApiBlockDestroy',
646 'format' => '(xml|json)'));
648 $m->connect('api/blocks/destroy/:id.:format',
649 array('action' => 'ApiBlockDestroy',
650 'id' => '[a-zA-Z0-9]+',
651 'format' => '(xml|json)'));
654 $m->connect('api/help/test.:format',
655 array('action' => 'ApiHelpTest',
656 'format' => '(xml|json)'));
660 $m->connect('api/statusnet/version.:format',
661 array('action' => 'ApiStatusnetVersion',
662 'format' => '(xml|json)'));
664 $m->connect('api/statusnet/config.:format',
665 array('action' => 'ApiStatusnetConfig',
666 'format' => '(xml|json)'));
668 // For older methods, we provide "laconica" base action
670 $m->connect('api/laconica/version.:format',
671 array('action' => 'ApiStatusnetVersion',
672 'format' => '(xml|json)'));
674 $m->connect('api/laconica/config.:format',
675 array('action' => 'ApiStatusnetConfig',
676 'format' => '(xml|json)'));
678 // Groups and tags are newer than 0.8.1 so no backward-compatibility
682 //'list' has to be handled differently, as php will not allow a method to be named 'list'
684 $m->connect('api/statusnet/groups/timeline/:id.:format',
685 array('action' => 'ApiTimelineGroup',
686 'id' => '[a-zA-Z0-9]+',
687 'format' => '(xml|json|rss|atom)'));
689 $m->connect('api/statusnet/groups/show.:format',
690 array('action' => 'ApiGroupShow',
691 'format' => '(xml|json)'));
693 $m->connect('api/statusnet/groups/show/:id.:format',
694 array('action' => 'ApiGroupShow',
695 'id' => '[a-zA-Z0-9]+',
696 'format' => '(xml|json)'));
698 $m->connect('api/statusnet/groups/join.:format',
699 array('action' => 'ApiGroupJoin',
700 'id' => '[a-zA-Z0-9]+',
701 'format' => '(xml|json)'));
703 $m->connect('api/statusnet/groups/join/:id.:format',
704 array('action' => 'ApiGroupJoin',
705 'format' => '(xml|json)'));
707 $m->connect('api/statusnet/groups/leave.:format',
708 array('action' => 'ApiGroupLeave',
709 'id' => '[a-zA-Z0-9]+',
710 'format' => '(xml|json)'));
712 $m->connect('api/statusnet/groups/leave/:id.:format',
713 array('action' => 'ApiGroupLeave',
714 'format' => '(xml|json)'));
716 $m->connect('api/statusnet/groups/is_member.:format',
717 array('action' => 'ApiGroupIsMember',
718 'format' => '(xml|json)'));
720 $m->connect('api/statusnet/groups/list.:format',
721 array('action' => 'ApiGroupList',
722 'format' => '(xml|json|rss|atom)'));
724 $m->connect('api/statusnet/groups/list/:id.:format',
725 array('action' => 'ApiGroupList',
726 'id' => '[a-zA-Z0-9]+',
727 'format' => '(xml|json|rss|atom)'));
729 $m->connect('api/statusnet/groups/list_all.:format',
730 array('action' => 'ApiGroupListAll',
731 'format' => '(xml|json|rss|atom)'));
733 $m->connect('api/statusnet/groups/membership.:format',
734 array('action' => 'ApiGroupMembership',
735 'format' => '(xml|json)'));
737 $m->connect('api/statusnet/groups/membership/:id.:format',
738 array('action' => 'ApiGroupMembership',
739 'id' => '[a-zA-Z0-9]+',
740 'format' => '(xml|json)'));
742 $m->connect('api/statusnet/groups/create.:format',
743 array('action' => 'ApiGroupCreate',
744 'format' => '(xml|json)'));
746 $m->connect('api/statusnet/tags/timeline/:tag.:format',
747 array('action' => 'ApiTimelineTag',
748 'format' => '(xml|json|rss|atom)'));
752 'api/statusnet/media/upload',
753 array('action' => 'ApiMediaUpload')
757 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
758 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
759 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
761 $m->connect('api/oauth/request_token',
762 array('action' => 'ApiOauthRequestToken'));
764 $m->connect('api/oauth/access_token',
765 array('action' => 'ApiOauthAccessToken'));
767 $m->connect('api/oauth/authorize',
768 array('action' => 'ApiOauthAuthorize'));
772 $m->connect('admin/site', array('action' => 'siteadminpanel'));
773 $m->connect('admin/design', array('action' => 'designadminpanel'));
774 $m->connect('admin/user', array('action' => 'useradminpanel'));
775 $m->connect('admin/access', array('action' => 'accessadminpanel'));
776 $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
777 $m->connect('admin/sessions', array('action' => 'sessionsadminpanel'));
778 $m->connect('admin/sitenotice', array('action' => 'sitenoticeadminpanel'));
779 $m->connect('admin/snapshot', array('action' => 'snapshotadminpanel'));
780 $m->connect('admin/license', array('action' => 'licenseadminpanel'));
782 $m->connect('getfile/:filename',
783 array('action' => 'getfile'),
784 array('filename' => '[A-Za-z0-9._-]+'));
788 if (common_config('singleuser', 'enabled')) {
790 $user = User::singleUser();
791 $nickname = $user->nickname;
793 foreach (array('subscriptions', 'subscribers',
794 'all', 'foaf', 'xrds',
795 'replies', 'microsummary', 'hcard') as $a) {
797 array('action' => $a,
798 'nickname' => $nickname));
801 foreach (array('subscriptions', 'subscribers') as $a) {
802 $m->connect($a.'/:tag',
803 array('action' => $a,
804 'nickname' => $nickname),
805 array('tag' => '[a-zA-Z0-9]+'));
808 foreach (array('rss', 'groups') as $a) {
810 array('action' => 'user'.$a,
811 'nickname' => $nickname));
814 foreach (array('all', 'replies', 'favorites') as $a) {
815 $m->connect($a.'/rss',
816 array('action' => $a.'rss',
817 'nickname' => $nickname));
820 $m->connect('favorites',
821 array('action' => 'showfavorites',
822 'nickname' => $nickname));
824 $m->connect('avatar/:size',
825 array('action' => 'avatarbynickname',
826 'nickname' => $nickname),
827 array('size' => '(original|96|48|24)'));
829 $m->connect('tag/:tag/rss',
830 array('action' => 'userrss',
831 'nickname' => $nickname),
832 array('tag' => '[\pL\pN_\-\.]{1,64}'));
834 $m->connect('tag/:tag',
835 array('action' => 'showstream',
836 'nickname' => $nickname),
837 array('tag' => '[\pL\pN_\-\.]{1,64}'));
839 $m->connect('rsd.xml',
840 array('action' => 'rsd',
841 'nickname' => $nickname));
844 array('action' => 'showstream',
845 'nickname' => $nickname));
847 $m->connect('', array('action' => 'public'));
848 $m->connect('rss', array('action' => 'publicrss'));
849 $m->connect('featuredrss', array('action' => 'featuredrss'));
850 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
851 $m->connect('featured/', array('action' => 'featured'));
852 $m->connect('featured', array('action' => 'featured'));
853 $m->connect('favorited/', array('action' => 'favorited'));
854 $m->connect('favorited', array('action' => 'favorited'));
855 $m->connect('rsd.xml', array('action' => 'rsd'));
857 foreach (array('subscriptions', 'subscribers',
858 'nudge', 'all', 'foaf', 'xrds',
859 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
860 $m->connect(':nickname/'.$a,
861 array('action' => $a),
862 array('nickname' => '[a-zA-Z0-9]{1,64}'));
865 foreach (array('subscriptions', 'subscribers') as $a) {
866 $m->connect(':nickname/'.$a.'/:tag',
867 array('action' => $a),
868 array('tag' => '[a-zA-Z0-9]+',
869 'nickname' => '[a-zA-Z0-9]{1,64}'));
872 foreach (array('rss', 'groups') as $a) {
873 $m->connect(':nickname/'.$a,
874 array('action' => 'user'.$a),
875 array('nickname' => '[a-zA-Z0-9]{1,64}'));
878 foreach (array('all', 'replies', 'favorites') as $a) {
879 $m->connect(':nickname/'.$a.'/rss',
880 array('action' => $a.'rss'),
881 array('nickname' => '[a-zA-Z0-9]{1,64}'));
884 $m->connect(':nickname/favorites',
885 array('action' => 'showfavorites'),
886 array('nickname' => '[a-zA-Z0-9]{1,64}'));
888 $m->connect(':nickname/avatar/:size',
889 array('action' => 'avatarbynickname'),
890 array('size' => '(original|96|48|24)',
891 'nickname' => '[a-zA-Z0-9]{1,64}'));
893 $m->connect(':nickname/tag/:tag/rss',
894 array('action' => 'userrss'),
895 array('nickname' => '[a-zA-Z0-9]{1,64}'),
896 array('tag' => '[\pL\pN_\-\.]{1,64}'));
898 $m->connect(':nickname/tag/:tag',
899 array('action' => 'showstream'),
900 array('nickname' => '[a-zA-Z0-9]{1,64}'),
901 array('tag' => '[\pL\pN_\-\.]{1,64}'));
903 $m->connect(':nickname/rsd.xml',
904 array('action' => 'rsd'),
905 array('nickname' => '[a-zA-Z0-9]{1,64}'));
907 $m->connect(':nickname',
908 array('action' => 'showstream'),
909 array('nickname' => '[a-zA-Z0-9]{1,64}'));
914 Event::handle('RouterInitialized', array($m));
923 $match = $this->m->match($path);
924 } catch (Net_URL_Mapper_InvalidException $e) {
925 common_log(LOG_ERR, "Problem getting route for $path - " .
927 // TRANS: Client error on action trying to visit a non-existing page.
928 $cac = new ClientErrorAction(_('Page not found.'), 404);
935 function build($action, $args=null, $params=null, $fragment=null)
937 $action_arg = array('action' => $action);
940 $args = array_merge($action_arg, $args);
945 $url = $this->m->generate($args, $params, $fragment);
947 // Due to a bug in the Net_URL_Mapper code, the returned URL may
948 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
949 // repair that here rather than modifying the upstream code...
951 $qpos = strpos($url, '?');
952 if ($qpos !== false) {
953 $url = substr($url, 0, $qpos+1) .
954 str_replace('?', '&', substr($url, $qpos+1));
956 // @fixme this is a hacky workaround for http_build_query in the
957 // lower-level code and bad configs that set the default separator
958 // to & instead of &. Encoded &s in parameters will not be
960 $url = substr($url, 0, $qpos+1) .
961 str_replace('&', '&', substr($url, $qpos+1));