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'));
233 $m->connect('.well-known/host-meta',
234 array('action' => 'hostmeta'));
235 $m->connect('main/xrd',
236 array('action' => 'userxrd'));
240 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
241 $m->connect('main/'.$c.'/:code', array('action' => $c));
246 $m->connect('main/remote', array('action' => 'remotesubscribe'));
247 $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
249 foreach (Router::$bare as $action) {
250 $m->connect('index.php?action=' . $action, array('action' => $action));
255 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
256 'oauthapps', 'email', 'sms', 'userdesign', 'other') as $s) {
257 $m->connect('settings/'.$s, array('action' => $s.'settings'));
260 $m->connect('settings/oauthapps/show/:id',
261 array('action' => 'showapplication'),
262 array('id' => '[0-9]+')
264 $m->connect('settings/oauthapps/new',
265 array('action' => 'newapplication')
267 $m->connect('settings/oauthapps/edit/:id',
268 array('action' => 'editapplication'),
269 array('id' => '[0-9]+')
271 $m->connect('settings/oauthapps/delete/:id',
272 array('action' => 'deleteapplication'),
273 array('id' => '[0-9]+')
278 foreach (array('group', 'people', 'notice') as $s) {
279 $m->connect('search/'.$s, array('action' => $s.'search'));
280 $m->connect('search/'.$s.'?q=:q',
281 array('action' => $s.'search'),
285 // The second of these is needed to make the link work correctly
286 // when inserted into the page. The first is needed to match the
287 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
288 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
289 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
292 $m->connect('attachment/:attachment',
293 array('action' => 'attachment'),
294 array('attachment' => '[0-9]+'));
296 $m->connect('attachment/:attachment/ajax',
297 array('action' => 'attachment_ajax'),
298 array('attachment' => '[0-9]+'));
300 $m->connect('attachment/:attachment/thumbnail',
301 array('action' => 'attachment_thumbnail'),
302 array('attachment' => '[0-9]+'));
304 $m->connect('notice/new', array('action' => 'newnotice'));
305 $m->connect('notice/new?replyto=:replyto',
306 array('action' => 'newnotice'),
307 array('replyto' => Nickname::DISPLAY_FMT));
308 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
309 array('action' => 'newnotice'),
310 array('replyto' => Nickname::DISPLAY_FMT),
311 array('inreplyto' => '[0-9]+'));
313 $m->connect('notice/:notice/file',
314 array('action' => 'file'),
315 array('notice' => '[0-9]+'));
317 $m->connect('notice/:notice',
318 array('action' => 'shownotice'),
319 array('notice' => '[0-9]+'));
320 $m->connect('notice/delete', array('action' => 'deletenotice'));
321 $m->connect('notice/delete/:notice',
322 array('action' => 'deletenotice'),
323 array('notice' => '[0-9]+'));
325 $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
329 $m->connect('conversation/:id',
330 array('action' => 'conversation'),
331 array('id' => '[0-9]+'));
333 $m->connect('message/new', array('action' => 'newmessage'));
334 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => Nickname::DISPLAY_FMT));
335 $m->connect('message/:message',
336 array('action' => 'showmessage'),
337 array('message' => '[0-9]+'));
339 $m->connect('user/:id',
340 array('action' => 'userbyid'),
341 array('id' => '[0-9]+'));
343 $m->connect('tags/', array('action' => 'publictagcloud'));
344 $m->connect('tag/', array('action' => 'publictagcloud'));
345 $m->connect('tags', array('action' => 'publictagcloud'));
346 $m->connect('tag', array('action' => 'publictagcloud'));
347 $m->connect('tag/:tag/rss',
348 array('action' => 'tagrss'),
349 array('tag' => '[\pL\pN_\-\.]{1,64}'));
350 $m->connect('tag/:tag',
351 array('action' => 'tag'),
352 array('tag' => '[\pL\pN_\-\.]{1,64}'));
354 $m->connect('peopletag/:tag',
355 array('action' => 'peopletag'),
356 array('tag' => '[a-zA-Z0-9]+'));
360 $m->connect('group/new', array('action' => 'newgroup'));
362 foreach (array('edit', 'join', 'leave', 'delete') as $v) {
363 $m->connect('group/:nickname/'.$v,
364 array('action' => $v.'group'),
365 array('nickname' => Nickname::DISPLAY_FMT));
366 $m->connect('group/:id/id/'.$v,
367 array('action' => $v.'group'),
368 array('id' => '[0-9]+'));
371 foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
372 $m->connect('group/:nickname/'.$n,
373 array('action' => 'group'.$n),
374 array('nickname' => Nickname::DISPLAY_FMT));
377 $m->connect('group/:nickname/foaf',
378 array('action' => 'foafgroup'),
379 array('nickname' => Nickname::DISPLAY_FMT));
381 $m->connect('group/:nickname/blocked',
382 array('action' => 'blockedfromgroup'),
383 array('nickname' => Nickname::DISPLAY_FMT));
385 $m->connect('group/:nickname/makeadmin',
386 array('action' => 'makeadmin'),
387 array('nickname' => Nickname::DISPLAY_FMT));
389 $m->connect('group/:id/id',
390 array('action' => 'groupbyid'),
391 array('id' => '[0-9]+'));
393 $m->connect('group/:nickname',
394 array('action' => 'showgroup'),
395 array('nickname' => Nickname::DISPLAY_FMT));
397 $m->connect('group/', array('action' => 'groups'));
398 $m->connect('group', array('action' => 'groups'));
399 $m->connect('groups/', array('action' => 'groups'));
400 $m->connect('groups', array('action' => 'groups'));
402 // Twitter-compatible API
406 $m->connect('api/statuses/public_timeline.:format',
407 array('action' => 'ApiTimelinePublic',
408 'format' => '(xml|json|rss|atom)'));
410 $m->connect('api/statuses/friends_timeline.:format',
411 array('action' => 'ApiTimelineFriends',
412 'format' => '(xml|json|rss|atom)'));
414 $m->connect('api/statuses/friends_timeline/:id.:format',
415 array('action' => 'ApiTimelineFriends',
416 'id' => Nickname::DISPLAY_FMT,
417 'format' => '(xml|json|rss|atom)'));
419 $m->connect('api/statuses/home_timeline.:format',
420 array('action' => 'ApiTimelineHome',
421 'format' => '(xml|json|rss|atom)'));
423 $m->connect('api/statuses/home_timeline/:id.:format',
424 array('action' => 'ApiTimelineHome',
425 'id' => Nickname::DISPLAY_FMT,
426 'format' => '(xml|json|rss|atom)'));
428 $m->connect('api/statuses/user_timeline.:format',
429 array('action' => 'ApiTimelineUser',
430 'format' => '(xml|json|rss|atom)'));
432 $m->connect('api/statuses/user_timeline/:id.:format',
433 array('action' => 'ApiTimelineUser',
434 'id' => Nickname::DISPLAY_FMT,
435 'format' => '(xml|json|rss|atom)'));
437 $m->connect('api/statuses/mentions.:format',
438 array('action' => 'ApiTimelineMentions',
439 'format' => '(xml|json|rss|atom)'));
441 $m->connect('api/statuses/mentions/:id.:format',
442 array('action' => 'ApiTimelineMentions',
443 'id' => Nickname::DISPLAY_FMT,
444 'format' => '(xml|json|rss|atom)'));
446 $m->connect('api/statuses/replies.:format',
447 array('action' => 'ApiTimelineMentions',
448 'format' => '(xml|json|rss|atom)'));
450 $m->connect('api/statuses/replies/:id.:format',
451 array('action' => 'ApiTimelineMentions',
452 'id' => Nickname::DISPLAY_FMT,
453 'format' => '(xml|json|rss|atom)'));
455 $m->connect('api/statuses/retweeted_by_me.:format',
456 array('action' => 'ApiTimelineRetweetedByMe',
457 'format' => '(xml|json|atom)'));
459 $m->connect('api/statuses/retweeted_to_me.:format',
460 array('action' => 'ApiTimelineRetweetedToMe',
461 'format' => '(xml|json|atom)'));
463 $m->connect('api/statuses/retweets_of_me.:format',
464 array('action' => 'ApiTimelineRetweetsOfMe',
465 'format' => '(xml|json|atom)'));
467 $m->connect('api/statuses/friends.:format',
468 array('action' => 'ApiUserFriends',
469 'format' => '(xml|json)'));
471 $m->connect('api/statuses/friends/:id.:format',
472 array('action' => 'ApiUserFriends',
473 'id' => Nickname::DISPLAY_FMT,
474 'format' => '(xml|json)'));
476 $m->connect('api/statuses/followers.:format',
477 array('action' => 'ApiUserFollowers',
478 'format' => '(xml|json)'));
480 $m->connect('api/statuses/followers/:id.:format',
481 array('action' => 'ApiUserFollowers',
482 'id' => Nickname::DISPLAY_FMT,
483 'format' => '(xml|json)'));
485 $m->connect('api/statuses/show.:format',
486 array('action' => 'ApiStatusesShow',
487 'format' => '(xml|json|atom)'));
489 $m->connect('api/statuses/show/:id.:format',
490 array('action' => 'ApiStatusesShow',
492 'format' => '(xml|json|atom)'));
494 $m->connect('api/statuses/update.:format',
495 array('action' => 'ApiStatusesUpdate',
496 'format' => '(xml|json)'));
498 $m->connect('api/statuses/destroy.:format',
499 array('action' => 'ApiStatusesDestroy',
500 'format' => '(xml|json)'));
502 $m->connect('api/statuses/destroy/:id.:format',
503 array('action' => 'ApiStatusesDestroy',
505 'format' => '(xml|json)'));
507 $m->connect('api/statuses/retweet/:id.:format',
508 array('action' => 'ApiStatusesRetweet',
510 'format' => '(xml|json)'));
512 $m->connect('api/statuses/retweets/:id.:format',
513 array('action' => 'ApiStatusesRetweets',
515 'format' => '(xml|json)'));
519 $m->connect('api/users/show.:format',
520 array('action' => 'ApiUserShow',
521 'format' => '(xml|json)'));
523 $m->connect('api/users/show/:id.:format',
524 array('action' => 'ApiUserShow',
525 'id' => Nickname::DISPLAY_FMT,
526 'format' => '(xml|json)'));
530 $m->connect('api/direct_messages.:format',
531 array('action' => 'ApiDirectMessage',
532 'format' => '(xml|json|rss|atom)'));
534 $m->connect('api/direct_messages/sent.:format',
535 array('action' => 'ApiDirectMessage',
536 'format' => '(xml|json|rss|atom)',
539 $m->connect('api/direct_messages/new.:format',
540 array('action' => 'ApiDirectMessageNew',
541 'format' => '(xml|json)'));
545 $m->connect('api/friendships/show.:format',
546 array('action' => 'ApiFriendshipsShow',
547 'format' => '(xml|json)'));
549 $m->connect('api/friendships/exists.:format',
550 array('action' => 'ApiFriendshipsExists',
551 'format' => '(xml|json)'));
553 $m->connect('api/friendships/create.:format',
554 array('action' => 'ApiFriendshipsCreate',
555 'format' => '(xml|json)'));
557 $m->connect('api/friendships/destroy.:format',
558 array('action' => 'ApiFriendshipsDestroy',
559 'format' => '(xml|json)'));
561 $m->connect('api/friendships/create/:id.:format',
562 array('action' => 'ApiFriendshipsCreate',
563 'id' => Nickname::DISPLAY_FMT,
564 'format' => '(xml|json)'));
566 $m->connect('api/friendships/destroy/:id.:format',
567 array('action' => 'ApiFriendshipsDestroy',
568 'id' => Nickname::DISPLAY_FMT,
569 'format' => '(xml|json)'));
573 $m->connect('api/friends/ids/:id.:format',
574 array('action' => 'ApiUserFriends',
575 'ids_only' => true));
577 $m->connect('api/followers/ids/:id.:format',
578 array('action' => 'ApiUserFollowers',
579 'ids_only' => true));
581 $m->connect('api/friends/ids.:format',
582 array('action' => 'ApiUserFriends',
583 'ids_only' => true));
585 $m->connect('api/followers/ids.:format',
586 array('action' => 'ApiUserFollowers',
587 'ids_only' => true));
591 $m->connect('api/account/verify_credentials.:format',
592 array('action' => 'ApiAccountVerifyCredentials'));
594 $m->connect('api/account/update_profile.:format',
595 array('action' => 'ApiAccountUpdateProfile'));
597 $m->connect('api/account/update_profile_image.:format',
598 array('action' => 'ApiAccountUpdateProfileImage'));
600 $m->connect('api/account/update_profile_background_image.:format',
601 array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
603 $m->connect('api/account/update_profile_colors.:format',
604 array('action' => 'ApiAccountUpdateProfileColors'));
606 $m->connect('api/account/update_delivery_device.:format',
607 array('action' => 'ApiAccountUpdateDeliveryDevice'));
609 // special case where verify_credentials is called w/out a format
611 $m->connect('api/account/verify_credentials',
612 array('action' => 'ApiAccountVerifyCredentials'));
614 $m->connect('api/account/rate_limit_status.:format',
615 array('action' => 'ApiAccountRateLimitStatus'));
619 $m->connect('api/favorites.:format',
620 array('action' => 'ApiTimelineFavorites',
621 'format' => '(xml|json|rss|atom)'));
623 $m->connect('api/favorites/:id.:format',
624 array('action' => 'ApiTimelineFavorites',
625 'id' => Nickname::DISPLAY_FMT,
626 'format' => '(xml|json|rss|atom)'));
628 $m->connect('api/favorites/create/:id.:format',
629 array('action' => 'ApiFavoriteCreate',
630 'id' => Nickname::DISPLAY_FMT,
631 'format' => '(xml|json)'));
633 $m->connect('api/favorites/destroy/:id.:format',
634 array('action' => 'ApiFavoriteDestroy',
635 'id' => Nickname::DISPLAY_FMT,
636 'format' => '(xml|json)'));
639 $m->connect('api/blocks/create.:format',
640 array('action' => 'ApiBlockCreate',
641 'format' => '(xml|json)'));
643 $m->connect('api/blocks/create/:id.:format',
644 array('action' => 'ApiBlockCreate',
645 'id' => Nickname::DISPLAY_FMT,
646 'format' => '(xml|json)'));
648 $m->connect('api/blocks/destroy.:format',
649 array('action' => 'ApiBlockDestroy',
650 'format' => '(xml|json)'));
652 $m->connect('api/blocks/destroy/:id.:format',
653 array('action' => 'ApiBlockDestroy',
654 'id' => Nickname::DISPLAY_FMT,
655 'format' => '(xml|json)'));
658 $m->connect('api/help/test.:format',
659 array('action' => 'ApiHelpTest',
660 'format' => '(xml|json)'));
664 $m->connect('api/statusnet/version.:format',
665 array('action' => 'ApiStatusnetVersion',
666 'format' => '(xml|json)'));
668 $m->connect('api/statusnet/config.:format',
669 array('action' => 'ApiStatusnetConfig',
670 'format' => '(xml|json)'));
672 // For older methods, we provide "laconica" base action
674 $m->connect('api/laconica/version.:format',
675 array('action' => 'ApiStatusnetVersion',
676 'format' => '(xml|json)'));
678 $m->connect('api/laconica/config.:format',
679 array('action' => 'ApiStatusnetConfig',
680 'format' => '(xml|json)'));
682 // Groups and tags are newer than 0.8.1 so no backward-compatibility
686 //'list' has to be handled differently, as php will not allow a method to be named 'list'
688 $m->connect('api/statusnet/groups/timeline/:id.:format',
689 array('action' => 'ApiTimelineGroup',
690 'id' => Nickname::DISPLAY_FMT,
691 'format' => '(xml|json|rss|atom)'));
693 $m->connect('api/statusnet/groups/show.:format',
694 array('action' => 'ApiGroupShow',
695 'format' => '(xml|json)'));
697 $m->connect('api/statusnet/groups/show/:id.:format',
698 array('action' => 'ApiGroupShow',
699 'id' => Nickname::DISPLAY_FMT,
700 'format' => '(xml|json)'));
702 $m->connect('api/statusnet/groups/join.:format',
703 array('action' => 'ApiGroupJoin',
704 'id' => Nickname::DISPLAY_FMT,
705 'format' => '(xml|json)'));
707 $m->connect('api/statusnet/groups/join/:id.:format',
708 array('action' => 'ApiGroupJoin',
709 'format' => '(xml|json)'));
711 $m->connect('api/statusnet/groups/leave.:format',
712 array('action' => 'ApiGroupLeave',
713 'id' => Nickname::DISPLAY_FMT,
714 'format' => '(xml|json)'));
716 $m->connect('api/statusnet/groups/leave/:id.:format',
717 array('action' => 'ApiGroupLeave',
718 'format' => '(xml|json)'));
720 $m->connect('api/statusnet/groups/is_member.:format',
721 array('action' => 'ApiGroupIsMember',
722 'format' => '(xml|json)'));
724 $m->connect('api/statusnet/groups/list.:format',
725 array('action' => 'ApiGroupList',
726 'format' => '(xml|json|rss|atom)'));
728 $m->connect('api/statusnet/groups/list/:id.:format',
729 array('action' => 'ApiGroupList',
730 'id' => Nickname::DISPLAY_FMT,
731 'format' => '(xml|json|rss|atom)'));
733 $m->connect('api/statusnet/groups/list_all.:format',
734 array('action' => 'ApiGroupListAll',
735 'format' => '(xml|json|rss|atom)'));
737 $m->connect('api/statusnet/groups/membership.:format',
738 array('action' => 'ApiGroupMembership',
739 'format' => '(xml|json)'));
741 $m->connect('api/statusnet/groups/membership/:id.:format',
742 array('action' => 'ApiGroupMembership',
743 'id' => Nickname::DISPLAY_FMT,
744 'format' => '(xml|json)'));
746 $m->connect('api/statusnet/groups/create.:format',
747 array('action' => 'ApiGroupCreate',
748 'format' => '(xml|json)'));
750 $m->connect('api/statusnet/tags/timeline/:tag.:format',
751 array('action' => 'ApiTimelineTag',
752 'format' => '(xml|json|rss|atom)'));
756 'api/statusnet/media/upload',
757 array('action' => 'ApiMediaUpload')
761 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
762 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
763 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
765 $m->connect('api/oauth/request_token',
766 array('action' => 'ApiOauthRequestToken'));
768 $m->connect('api/oauth/access_token',
769 array('action' => 'ApiOauthAccessToken'));
771 $m->connect('api/oauth/authorize',
772 array('action' => 'ApiOauthAuthorize'));
774 $m->connect('api/statusnet/app/service/:id.xml',
775 array('action' => 'ApiAtomService',
776 'id' => Nickname::DISPLAY_FMT));
778 $m->connect('api/statusnet/app/service.xml',
779 array('action' => 'ApiAtomService'));
783 $m->connect('admin/site', array('action' => 'siteadminpanel'));
784 $m->connect('admin/design', array('action' => 'designadminpanel'));
785 $m->connect('admin/user', array('action' => 'useradminpanel'));
786 $m->connect('admin/access', array('action' => 'accessadminpanel'));
787 $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
788 $m->connect('admin/sessions', array('action' => 'sessionsadminpanel'));
789 $m->connect('admin/sitenotice', array('action' => 'sitenoticeadminpanel'));
790 $m->connect('admin/snapshot', array('action' => 'snapshotadminpanel'));
791 $m->connect('admin/license', array('action' => 'licenseadminpanel'));
793 $m->connect('getfile/:filename',
794 array('action' => 'getfile'),
795 array('filename' => '[A-Za-z0-9._-]+'));
799 if (common_config('singleuser', 'enabled')) {
801 $user = User::singleUser();
802 $nickname = $user->nickname;
804 foreach (array('subscriptions', 'subscribers',
805 'all', 'foaf', 'xrds',
806 'replies', 'microsummary', 'hcard') as $a) {
808 array('action' => $a,
809 'nickname' => $nickname));
812 foreach (array('subscriptions', 'subscribers') as $a) {
813 $m->connect($a.'/:tag',
814 array('action' => $a,
815 'nickname' => $nickname),
816 array('tag' => '[a-zA-Z0-9]+'));
819 foreach (array('rss', 'groups') as $a) {
821 array('action' => 'user'.$a,
822 'nickname' => $nickname));
825 foreach (array('all', 'replies', 'favorites') as $a) {
826 $m->connect($a.'/rss',
827 array('action' => $a.'rss',
828 'nickname' => $nickname));
831 $m->connect('favorites',
832 array('action' => 'showfavorites',
833 'nickname' => $nickname));
835 $m->connect('avatar/:size',
836 array('action' => 'avatarbynickname',
837 'nickname' => $nickname),
838 array('size' => '(original|96|48|24)'));
840 $m->connect('tag/:tag/rss',
841 array('action' => 'userrss',
842 'nickname' => $nickname),
843 array('tag' => '[\pL\pN_\-\.]{1,64}'));
845 $m->connect('tag/:tag',
846 array('action' => 'showstream',
847 'nickname' => $nickname),
848 array('tag' => '[\pL\pN_\-\.]{1,64}'));
850 $m->connect('rsd.xml',
851 array('action' => 'rsd',
852 'nickname' => $nickname));
855 array('action' => 'showstream',
856 'nickname' => $nickname));
858 $m->connect('', array('action' => 'public'));
859 $m->connect('rss', array('action' => 'publicrss'));
860 $m->connect('featuredrss', array('action' => 'featuredrss'));
861 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
862 $m->connect('featured/', array('action' => 'featured'));
863 $m->connect('featured', array('action' => 'featured'));
864 $m->connect('favorited/', array('action' => 'favorited'));
865 $m->connect('favorited', array('action' => 'favorited'));
866 $m->connect('rsd.xml', array('action' => 'rsd'));
868 foreach (array('subscriptions', 'subscribers',
869 'nudge', 'all', 'foaf', 'xrds',
870 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
871 $m->connect(':nickname/'.$a,
872 array('action' => $a),
873 array('nickname' => Nickname::DISPLAY_FMT));
876 foreach (array('subscriptions', 'subscribers') as $a) {
877 $m->connect(':nickname/'.$a.'/:tag',
878 array('action' => $a),
879 array('tag' => '[a-zA-Z0-9]+',
880 'nickname' => Nickname::DISPLAY_FMT));
883 foreach (array('rss', 'groups') as $a) {
884 $m->connect(':nickname/'.$a,
885 array('action' => 'user'.$a),
886 array('nickname' => Nickname::DISPLAY_FMT));
889 foreach (array('all', 'replies', 'favorites') as $a) {
890 $m->connect(':nickname/'.$a.'/rss',
891 array('action' => $a.'rss'),
892 array('nickname' => Nickname::DISPLAY_FMT));
895 $m->connect(':nickname/favorites',
896 array('action' => 'showfavorites'),
897 array('nickname' => Nickname::DISPLAY_FMT));
899 $m->connect(':nickname/avatar/:size',
900 array('action' => 'avatarbynickname'),
901 array('size' => '(original|96|48|24)',
902 'nickname' => Nickname::DISPLAY_FMT));
904 $m->connect(':nickname/tag/:tag/rss',
905 array('action' => 'userrss'),
906 array('nickname' => Nickname::DISPLAY_FMT),
907 array('tag' => '[\pL\pN_\-\.]{1,64}'));
909 $m->connect(':nickname/tag/:tag',
910 array('action' => 'showstream'),
911 array('nickname' => Nickname::DISPLAY_FMT),
912 array('tag' => '[\pL\pN_\-\.]{1,64}'));
914 $m->connect(':nickname/rsd.xml',
915 array('action' => 'rsd'),
916 array('nickname' => Nickname::DISPLAY_FMT));
918 $m->connect(':nickname',
919 array('action' => 'showstream'),
920 array('nickname' => Nickname::DISPLAY_FMT));
925 Event::handle('RouterInitialized', array($m));
934 $match = $this->m->match($path);
935 } catch (Net_URL_Mapper_InvalidException $e) {
936 common_log(LOG_ERR, "Problem getting route for $path - " .
938 // TRANS: Client error on action trying to visit a non-existing page.
939 $cac = new ClientErrorAction(_('Page not found.'), 404);
946 function build($action, $args=null, $params=null, $fragment=null)
948 $action_arg = array('action' => $action);
951 $args = array_merge($action_arg, $args);
956 $url = $this->m->generate($args, $params, $fragment);
958 // Due to a bug in the Net_URL_Mapper code, the returned URL may
959 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
960 // repair that here rather than modifying the upstream code...
962 $qpos = strpos($url, '?');
963 if ($qpos !== false) {
964 $url = substr($url, 0, $qpos+1) .
965 str_replace('?', '&', substr($url, $qpos+1));
967 // @fixme this is a hacky workaround for http_build_query in the
968 // lower-level code and bad configs that set the default separator
969 // to & instead of &. Encoded &s in parameters will not be
971 $url = substr($url, 0, $qpos+1) .
972 str_replace('&', '&', substr($url, $qpos+1));