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',
207 foreach ($main as $a) {
208 $m->connect('main/'.$a, array('action' => $a));
211 // Also need a block variant accepting ID on URL for mail links
212 $m->connect('main/block/:profileid',
213 array('action' => 'block'),
214 array('profileid' => '[0-9]+'));
216 $m->connect('main/sup/:seconds', array('action' => 'sup'),
217 array('seconds' => '[0-9]+'));
219 $m->connect('main/tagother/:id', array('action' => 'tagother'));
221 $m->connect('main/oembed',
222 array('action' => 'oembed'));
224 $m->connect('main/xrds',
225 array('action' => 'publicxrds'));
226 $m->connect('.well-known/host-meta',
227 array('action' => 'hostmeta'));
228 $m->connect('main/xrd',
229 array('action' => 'userxrd'));
233 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
234 $m->connect('main/'.$c.'/:code', array('action' => $c));
239 $m->connect('main/remote', array('action' => 'remotesubscribe'));
240 $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
242 foreach (Router::$bare as $action) {
243 $m->connect('index.php?action=' . $action, array('action' => $action));
248 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
249 'oauthapps', 'email', 'sms', 'userdesign', 'other') as $s) {
250 $m->connect('settings/'.$s, array('action' => $s.'settings'));
253 $m->connect('settings/oauthapps/show/:id',
254 array('action' => 'showapplication'),
255 array('id' => '[0-9]+')
257 $m->connect('settings/oauthapps/new',
258 array('action' => 'newapplication')
260 $m->connect('settings/oauthapps/edit/:id',
261 array('action' => 'editapplication'),
262 array('id' => '[0-9]+')
264 $m->connect('settings/oauthapps/delete/:id',
265 array('action' => 'deleteapplication'),
266 array('id' => '[0-9]+')
271 foreach (array('group', 'people', 'notice') as $s) {
272 $m->connect('search/'.$s, array('action' => $s.'search'));
273 $m->connect('search/'.$s.'?q=:q',
274 array('action' => $s.'search'),
278 // The second of these is needed to make the link work correctly
279 // when inserted into the page. The first is needed to match the
280 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
281 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
282 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
285 $m->connect('attachment/:attachment',
286 array('action' => 'attachment'),
287 array('attachment' => '[0-9]+'));
289 $m->connect('attachment/:attachment/ajax',
290 array('action' => 'attachment_ajax'),
291 array('attachment' => '[0-9]+'));
293 $m->connect('attachment/:attachment/thumbnail',
294 array('action' => 'attachment_thumbnail'),
295 array('attachment' => '[0-9]+'));
297 $m->connect('notice/new', array('action' => 'newnotice'));
298 $m->connect('notice/new?replyto=:replyto',
299 array('action' => 'newnotice'),
300 array('replyto' => Nickname::DISPLAY_FMT));
301 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
302 array('action' => 'newnotice'),
303 array('replyto' => Nickname::DISPLAY_FMT),
304 array('inreplyto' => '[0-9]+'));
306 $m->connect('notice/:notice/file',
307 array('action' => 'file'),
308 array('notice' => '[0-9]+'));
310 $m->connect('notice/:notice',
311 array('action' => 'shownotice'),
312 array('notice' => '[0-9]+'));
313 $m->connect('notice/delete', array('action' => 'deletenotice'));
314 $m->connect('notice/delete/:notice',
315 array('action' => 'deletenotice'),
316 array('notice' => '[0-9]+'));
318 $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
322 $m->connect('conversation/:id',
323 array('action' => 'conversation'),
324 array('id' => '[0-9]+'));
326 $m->connect('message/new', array('action' => 'newmessage'));
327 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => Nickname::DISPLAY_FMT));
328 $m->connect('message/:message',
329 array('action' => 'showmessage'),
330 array('message' => '[0-9]+'));
332 $m->connect('user/:id',
333 array('action' => 'userbyid'),
334 array('id' => '[0-9]+'));
336 $m->connect('tags/', array('action' => 'publictagcloud'));
337 $m->connect('tag/', array('action' => 'publictagcloud'));
338 $m->connect('tags', array('action' => 'publictagcloud'));
339 $m->connect('tag', array('action' => 'publictagcloud'));
340 $m->connect('tag/:tag/rss',
341 array('action' => 'tagrss'),
342 array('tag' => '[\pL\pN_\-\.]{1,64}'));
343 $m->connect('tag/:tag',
344 array('action' => 'tag'),
345 array('tag' => '[\pL\pN_\-\.]{1,64}'));
347 $m->connect('peopletag/:tag',
348 array('action' => 'peopletag'),
349 array('tag' => '[a-zA-Z0-9]+'));
353 $m->connect('group/new', array('action' => 'newgroup'));
355 foreach (array('edit', 'join', 'leave', 'delete') as $v) {
356 $m->connect('group/:nickname/'.$v,
357 array('action' => $v.'group'),
358 array('nickname' => Nickname::DISPLAY_FMT));
359 $m->connect('group/:id/id/'.$v,
360 array('action' => $v.'group'),
361 array('id' => '[0-9]+'));
364 foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
365 $m->connect('group/:nickname/'.$n,
366 array('action' => 'group'.$n),
367 array('nickname' => Nickname::DISPLAY_FMT));
370 $m->connect('group/:nickname/foaf',
371 array('action' => 'foafgroup'),
372 array('nickname' => Nickname::DISPLAY_FMT));
374 $m->connect('group/:nickname/blocked',
375 array('action' => 'blockedfromgroup'),
376 array('nickname' => Nickname::DISPLAY_FMT));
378 $m->connect('group/:nickname/makeadmin',
379 array('action' => 'makeadmin'),
380 array('nickname' => Nickname::DISPLAY_FMT));
382 $m->connect('group/:id/id',
383 array('action' => 'groupbyid'),
384 array('id' => '[0-9]+'));
386 $m->connect('group/:nickname',
387 array('action' => 'showgroup'),
388 array('nickname' => Nickname::DISPLAY_FMT));
390 $m->connect('group/', array('action' => 'groups'));
391 $m->connect('group', array('action' => 'groups'));
392 $m->connect('groups/', array('action' => 'groups'));
393 $m->connect('groups', array('action' => 'groups'));
395 // Twitter-compatible API
399 $m->connect('api/statuses/public_timeline.:format',
400 array('action' => 'ApiTimelinePublic',
401 'format' => '(xml|json|rss|atom)'));
403 $m->connect('api/statuses/friends_timeline.:format',
404 array('action' => 'ApiTimelineFriends',
405 'format' => '(xml|json|rss|atom)'));
407 $m->connect('api/statuses/friends_timeline/:id.:format',
408 array('action' => 'ApiTimelineFriends',
409 'id' => Nickname::INPUT_FMT,
410 'format' => '(xml|json|rss|atom)'));
412 $m->connect('api/statuses/home_timeline.:format',
413 array('action' => 'ApiTimelineHome',
414 'format' => '(xml|json|rss|atom)'));
416 $m->connect('api/statuses/home_timeline/:id.:format',
417 array('action' => 'ApiTimelineHome',
418 'id' => Nickname::INPUT_FMT,
419 'format' => '(xml|json|rss|atom)'));
421 $m->connect('api/statuses/user_timeline.:format',
422 array('action' => 'ApiTimelineUser',
423 'format' => '(xml|json|rss|atom)'));
425 $m->connect('api/statuses/user_timeline/:id.:format',
426 array('action' => 'ApiTimelineUser',
427 'id' => Nickname::INPUT_FMT,
428 'format' => '(xml|json|rss|atom)'));
430 $m->connect('api/statuses/mentions.:format',
431 array('action' => 'ApiTimelineMentions',
432 'format' => '(xml|json|rss|atom)'));
434 $m->connect('api/statuses/mentions/:id.:format',
435 array('action' => 'ApiTimelineMentions',
436 'id' => Nickname::INPUT_FMT,
437 'format' => '(xml|json|rss|atom)'));
439 $m->connect('api/statuses/replies.:format',
440 array('action' => 'ApiTimelineMentions',
441 'format' => '(xml|json|rss|atom)'));
443 $m->connect('api/statuses/replies/:id.:format',
444 array('action' => 'ApiTimelineMentions',
445 'id' => Nickname::INPUT_FMT,
446 'format' => '(xml|json|rss|atom)'));
448 $m->connect('api/statuses/retweeted_by_me.:format',
449 array('action' => 'ApiTimelineRetweetedByMe',
450 'format' => '(xml|json|atom)'));
452 $m->connect('api/statuses/retweeted_to_me.:format',
453 array('action' => 'ApiTimelineRetweetedToMe',
454 'format' => '(xml|json|atom)'));
456 $m->connect('api/statuses/retweets_of_me.:format',
457 array('action' => 'ApiTimelineRetweetsOfMe',
458 'format' => '(xml|json|atom)'));
460 $m->connect('api/statuses/friends.:format',
461 array('action' => 'ApiUserFriends',
462 'format' => '(xml|json)'));
464 $m->connect('api/statuses/friends/:id.:format',
465 array('action' => 'ApiUserFriends',
466 'id' => Nickname::INPUT_FMT,
467 'format' => '(xml|json)'));
469 $m->connect('api/statuses/followers.:format',
470 array('action' => 'ApiUserFollowers',
471 'format' => '(xml|json)'));
473 $m->connect('api/statuses/followers/:id.:format',
474 array('action' => 'ApiUserFollowers',
475 'id' => Nickname::INPUT_FMT,
476 'format' => '(xml|json)'));
478 $m->connect('api/statuses/show.:format',
479 array('action' => 'ApiStatusesShow',
480 'format' => '(xml|json|atom)'));
482 $m->connect('api/statuses/show/:id.:format',
483 array('action' => 'ApiStatusesShow',
485 'format' => '(xml|json|atom)'));
487 $m->connect('api/statuses/update.:format',
488 array('action' => 'ApiStatusesUpdate',
489 'format' => '(xml|json)'));
491 $m->connect('api/statuses/destroy.:format',
492 array('action' => 'ApiStatusesDestroy',
493 'format' => '(xml|json)'));
495 $m->connect('api/statuses/destroy/:id.:format',
496 array('action' => 'ApiStatusesDestroy',
498 'format' => '(xml|json)'));
500 $m->connect('api/statuses/retweet/:id.:format',
501 array('action' => 'ApiStatusesRetweet',
503 'format' => '(xml|json)'));
505 $m->connect('api/statuses/retweets/:id.:format',
506 array('action' => 'ApiStatusesRetweets',
508 'format' => '(xml|json)'));
512 $m->connect('api/users/show.:format',
513 array('action' => 'ApiUserShow',
514 'format' => '(xml|json)'));
516 $m->connect('api/users/show/:id.:format',
517 array('action' => 'ApiUserShow',
518 'id' => Nickname::INPUT_FMT,
519 'format' => '(xml|json)'));
523 $m->connect('api/direct_messages.:format',
524 array('action' => 'ApiDirectMessage',
525 'format' => '(xml|json|rss|atom)'));
527 $m->connect('api/direct_messages/sent.:format',
528 array('action' => 'ApiDirectMessage',
529 'format' => '(xml|json|rss|atom)',
532 $m->connect('api/direct_messages/new.:format',
533 array('action' => 'ApiDirectMessageNew',
534 'format' => '(xml|json)'));
538 $m->connect('api/friendships/show.:format',
539 array('action' => 'ApiFriendshipsShow',
540 'format' => '(xml|json)'));
542 $m->connect('api/friendships/exists.:format',
543 array('action' => 'ApiFriendshipsExists',
544 'format' => '(xml|json)'));
546 $m->connect('api/friendships/create.:format',
547 array('action' => 'ApiFriendshipsCreate',
548 'format' => '(xml|json)'));
550 $m->connect('api/friendships/destroy.:format',
551 array('action' => 'ApiFriendshipsDestroy',
552 'format' => '(xml|json)'));
554 $m->connect('api/friendships/create/:id.:format',
555 array('action' => 'ApiFriendshipsCreate',
556 'id' => Nickname::INPUT_FMT,
557 'format' => '(xml|json)'));
559 $m->connect('api/friendships/destroy/:id.:format',
560 array('action' => 'ApiFriendshipsDestroy',
561 'id' => Nickname::INPUT_FMT,
562 'format' => '(xml|json)'));
566 $m->connect('api/friends/ids/:id.:format',
567 array('action' => 'ApiUserFriends',
568 'ids_only' => true));
570 $m->connect('api/followers/ids/:id.:format',
571 array('action' => 'ApiUserFollowers',
572 'ids_only' => true));
574 $m->connect('api/friends/ids.:format',
575 array('action' => 'ApiUserFriends',
576 'ids_only' => true));
578 $m->connect('api/followers/ids.:format',
579 array('action' => 'ApiUserFollowers',
580 'ids_only' => true));
584 $m->connect('api/account/verify_credentials.:format',
585 array('action' => 'ApiAccountVerifyCredentials'));
587 $m->connect('api/account/update_profile.:format',
588 array('action' => 'ApiAccountUpdateProfile'));
590 $m->connect('api/account/update_profile_image.:format',
591 array('action' => 'ApiAccountUpdateProfileImage'));
593 $m->connect('api/account/update_profile_background_image.:format',
594 array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
596 $m->connect('api/account/update_profile_colors.:format',
597 array('action' => 'ApiAccountUpdateProfileColors'));
599 $m->connect('api/account/update_delivery_device.:format',
600 array('action' => 'ApiAccountUpdateDeliveryDevice'));
602 // special case where verify_credentials is called w/out a format
604 $m->connect('api/account/verify_credentials',
605 array('action' => 'ApiAccountVerifyCredentials'));
607 $m->connect('api/account/rate_limit_status.:format',
608 array('action' => 'ApiAccountRateLimitStatus'));
612 $m->connect('api/favorites.:format',
613 array('action' => 'ApiTimelineFavorites',
614 'format' => '(xml|json|rss|atom)'));
616 $m->connect('api/favorites/:id.:format',
617 array('action' => 'ApiTimelineFavorites',
618 'id' => Nickname::INPUT_FMT,
619 'format' => '(xml|json|rss|atom)'));
621 $m->connect('api/favorites/create/:id.:format',
622 array('action' => 'ApiFavoriteCreate',
624 'format' => '(xml|json)'));
626 $m->connect('api/favorites/destroy/:id.:format',
627 array('action' => 'ApiFavoriteDestroy',
629 'format' => '(xml|json)'));
632 $m->connect('api/blocks/create.:format',
633 array('action' => 'ApiBlockCreate',
634 'format' => '(xml|json)'));
636 $m->connect('api/blocks/create/:id.:format',
637 array('action' => 'ApiBlockCreate',
638 'id' => Nickname::INPUT_FMT,
639 'format' => '(xml|json)'));
641 $m->connect('api/blocks/destroy.:format',
642 array('action' => 'ApiBlockDestroy',
643 'format' => '(xml|json)'));
645 $m->connect('api/blocks/destroy/:id.:format',
646 array('action' => 'ApiBlockDestroy',
647 'id' => Nickname::INPUT_FMT,
648 'format' => '(xml|json)'));
651 $m->connect('api/help/test.:format',
652 array('action' => 'ApiHelpTest',
653 'format' => '(xml|json)'));
657 $m->connect('api/statusnet/version.:format',
658 array('action' => 'ApiStatusnetVersion',
659 'format' => '(xml|json)'));
661 $m->connect('api/statusnet/config.:format',
662 array('action' => 'ApiStatusnetConfig',
663 'format' => '(xml|json)'));
665 // For older methods, we provide "laconica" base action
667 $m->connect('api/laconica/version.:format',
668 array('action' => 'ApiStatusnetVersion',
669 'format' => '(xml|json)'));
671 $m->connect('api/laconica/config.:format',
672 array('action' => 'ApiStatusnetConfig',
673 'format' => '(xml|json)'));
675 // Groups and tags are newer than 0.8.1 so no backward-compatibility
679 //'list' has to be handled differently, as php will not allow a method to be named 'list'
681 $m->connect('api/statusnet/groups/timeline/:id.:format',
682 array('action' => 'ApiTimelineGroup',
683 'id' => Nickname::INPUT_FMT,
684 'format' => '(xml|json|rss|atom)'));
686 $m->connect('api/statusnet/groups/show.:format',
687 array('action' => 'ApiGroupShow',
688 'format' => '(xml|json)'));
690 $m->connect('api/statusnet/groups/show/:id.:format',
691 array('action' => 'ApiGroupShow',
692 'id' => Nickname::INPUT_FMT,
693 'format' => '(xml|json)'));
695 $m->connect('api/statusnet/groups/join.:format',
696 array('action' => 'ApiGroupJoin',
697 'id' => Nickname::INPUT_FMT,
698 'format' => '(xml|json)'));
700 $m->connect('api/statusnet/groups/join/:id.:format',
701 array('action' => 'ApiGroupJoin',
702 'format' => '(xml|json)'));
704 $m->connect('api/statusnet/groups/leave.:format',
705 array('action' => 'ApiGroupLeave',
706 'id' => Nickname::INPUT_FMT,
707 'format' => '(xml|json)'));
709 $m->connect('api/statusnet/groups/leave/:id.:format',
710 array('action' => 'ApiGroupLeave',
711 'format' => '(xml|json)'));
713 $m->connect('api/statusnet/groups/is_member.:format',
714 array('action' => 'ApiGroupIsMember',
715 'format' => '(xml|json)'));
717 $m->connect('api/statusnet/groups/list.:format',
718 array('action' => 'ApiGroupList',
719 'format' => '(xml|json|rss|atom)'));
721 $m->connect('api/statusnet/groups/list/:id.:format',
722 array('action' => 'ApiGroupList',
723 'id' => Nickname::INPUT_FMT,
724 'format' => '(xml|json|rss|atom)'));
726 $m->connect('api/statusnet/groups/list_all.:format',
727 array('action' => 'ApiGroupListAll',
728 'format' => '(xml|json|rss|atom)'));
730 $m->connect('api/statusnet/groups/membership.:format',
731 array('action' => 'ApiGroupMembership',
732 'format' => '(xml|json)'));
734 $m->connect('api/statusnet/groups/membership/:id.:format',
735 array('action' => 'ApiGroupMembership',
736 'id' => Nickname::INPUT_FMT,
737 'format' => '(xml|json)'));
739 $m->connect('api/statusnet/groups/create.:format',
740 array('action' => 'ApiGroupCreate',
741 'format' => '(xml|json)'));
743 $m->connect('api/statusnet/tags/timeline/:tag.:format',
744 array('action' => 'ApiTimelineTag',
745 'format' => '(xml|json|rss|atom)'));
749 'api/statusnet/media/upload',
750 array('action' => 'ApiMediaUpload')
754 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
755 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
756 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
758 $m->connect('api/oauth/request_token',
759 array('action' => 'ApiOauthRequestToken'));
761 $m->connect('api/oauth/access_token',
762 array('action' => 'ApiOauthAccessToken'));
764 $m->connect('api/oauth/authorize',
765 array('action' => 'ApiOauthAuthorize'));
769 $m->connect('admin/site', array('action' => 'siteadminpanel'));
770 $m->connect('admin/design', array('action' => 'designadminpanel'));
771 $m->connect('admin/user', array('action' => 'useradminpanel'));
772 $m->connect('admin/access', array('action' => 'accessadminpanel'));
773 $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
774 $m->connect('admin/sessions', array('action' => 'sessionsadminpanel'));
775 $m->connect('admin/sitenotice', array('action' => 'sitenoticeadminpanel'));
776 $m->connect('admin/snapshot', array('action' => 'snapshotadminpanel'));
777 $m->connect('admin/license', array('action' => 'licenseadminpanel'));
779 $m->connect('getfile/:filename',
780 array('action' => 'getfile'),
781 array('filename' => '[A-Za-z0-9._-]+'));
785 if (common_config('singleuser', 'enabled')) {
787 $nickname = User::singleUserNickname();
789 foreach (array('subscriptions', 'subscribers',
790 'all', 'foaf', 'xrds',
791 'replies', 'microsummary', 'hcard') as $a) {
793 array('action' => $a,
794 'nickname' => $nickname));
797 foreach (array('subscriptions', 'subscribers') as $a) {
798 $m->connect($a.'/:tag',
799 array('action' => $a,
800 'nickname' => $nickname),
801 array('tag' => '[a-zA-Z0-9]+'));
804 foreach (array('rss', 'groups') as $a) {
806 array('action' => 'user'.$a,
807 'nickname' => $nickname));
810 foreach (array('all', 'replies', 'favorites') as $a) {
811 $m->connect($a.'/rss',
812 array('action' => $a.'rss',
813 'nickname' => $nickname));
816 $m->connect('favorites',
817 array('action' => 'showfavorites',
818 'nickname' => $nickname));
820 $m->connect('avatar/:size',
821 array('action' => 'avatarbynickname',
822 'nickname' => $nickname),
823 array('size' => '(original|96|48|24)'));
825 $m->connect('tag/:tag/rss',
826 array('action' => 'userrss',
827 'nickname' => $nickname),
828 array('tag' => '[\pL\pN_\-\.]{1,64}'));
830 $m->connect('tag/:tag',
831 array('action' => 'showstream',
832 'nickname' => $nickname),
833 array('tag' => '[\pL\pN_\-\.]{1,64}'));
835 $m->connect('rsd.xml',
836 array('action' => 'rsd',
837 'nickname' => $nickname));
840 array('action' => 'showstream',
841 'nickname' => $nickname));
843 $m->connect('', array('action' => 'public'));
844 $m->connect('rss', array('action' => 'publicrss'));
845 $m->connect('featuredrss', array('action' => 'featuredrss'));
846 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
847 $m->connect('featured/', array('action' => 'featured'));
848 $m->connect('featured', array('action' => 'featured'));
849 $m->connect('favorited/', array('action' => 'favorited'));
850 $m->connect('favorited', array('action' => 'favorited'));
851 $m->connect('rsd.xml', array('action' => 'rsd'));
853 foreach (array('subscriptions', 'subscribers',
854 'nudge', 'all', 'foaf', 'xrds',
855 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
856 $m->connect(':nickname/'.$a,
857 array('action' => $a),
858 array('nickname' => Nickname::DISPLAY_FMT));
861 foreach (array('subscriptions', 'subscribers') as $a) {
862 $m->connect(':nickname/'.$a.'/:tag',
863 array('action' => $a),
864 array('tag' => '[a-zA-Z0-9]+',
865 'nickname' => Nickname::DISPLAY_FMT));
868 foreach (array('rss', 'groups') as $a) {
869 $m->connect(':nickname/'.$a,
870 array('action' => 'user'.$a),
871 array('nickname' => Nickname::DISPLAY_FMT));
874 foreach (array('all', 'replies', 'favorites') as $a) {
875 $m->connect(':nickname/'.$a.'/rss',
876 array('action' => $a.'rss'),
877 array('nickname' => Nickname::DISPLAY_FMT));
880 $m->connect(':nickname/favorites',
881 array('action' => 'showfavorites'),
882 array('nickname' => Nickname::DISPLAY_FMT));
884 $m->connect(':nickname/avatar/:size',
885 array('action' => 'avatarbynickname'),
886 array('size' => '(original|96|48|24)',
887 'nickname' => Nickname::DISPLAY_FMT));
889 $m->connect(':nickname/tag/:tag/rss',
890 array('action' => 'userrss'),
891 array('nickname' => Nickname::DISPLAY_FMT),
892 array('tag' => '[\pL\pN_\-\.]{1,64}'));
894 $m->connect(':nickname/tag/:tag',
895 array('action' => 'showstream'),
896 array('nickname' => Nickname::DISPLAY_FMT),
897 array('tag' => '[\pL\pN_\-\.]{1,64}'));
899 $m->connect(':nickname/rsd.xml',
900 array('action' => 'rsd'),
901 array('nickname' => Nickname::DISPLAY_FMT));
903 $m->connect(':nickname',
904 array('action' => 'showstream'),
905 array('nickname' => Nickname::DISPLAY_FMT));
910 $m->connect('api/statusnet/app/service/:id.xml',
911 array('action' => 'ApiAtomService'),
912 array('id' => Nickname::DISPLAY_FMT));
914 $m->connect('api/statusnet/app/service.xml',
915 array('action' => 'ApiAtomService'));
917 $m->connect('api/statusnet/app/subscriptions/:subscriber/:subscribed.atom',
918 array('action' => 'AtomPubShowSubscription'),
919 array('subscriber' => '[0-9]+',
920 'subscribed' => '[0-9]+'));
922 $m->connect('api/statusnet/app/subscriptions/:subscriber.atom',
923 array('action' => 'AtomPubSubscriptionFeed'),
924 array('subscriber' => '[0-9]+'));
926 $m->connect('api/statusnet/app/favorites/:profile/:notice.atom',
927 array('action' => 'AtomPubShowFavorite'),
928 array('profile' => '[0-9]+',
929 'notice' => '[0-9]+'));
931 $m->connect('api/statusnet/app/favorites/:profile.atom',
932 array('action' => 'AtomPubFavoriteFeed'),
933 array('profile' => '[0-9]+'));
935 $m->connect('api/statusnet/app/memberships/:profile/:group.atom',
936 array('action' => 'AtomPubShowMembership'),
937 array('profile' => '[0-9]+',
938 'group' => '[0-9]+'));
940 $m->connect('api/statusnet/app/memberships/:profile.atom',
941 array('action' => 'AtomPubMembershipFeed'),
942 array('profile' => '[0-9]+'));
946 Event::handle('RouterInitialized', array($m));
955 $match = $this->m->match($path);
956 } catch (Net_URL_Mapper_InvalidException $e) {
957 common_log(LOG_ERR, "Problem getting route for $path - " .
959 // TRANS: Client error on action trying to visit a non-existing page.
960 $cac = new ClientErrorAction(_('Page not found.'), 404);
967 function build($action, $args=null, $params=null, $fragment=null)
969 $action_arg = array('action' => $action);
972 $args = array_merge($action_arg, $args);
977 $url = $this->m->generate($args, $params, $fragment);
979 // Due to a bug in the Net_URL_Mapper code, the returned URL may
980 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
981 // repair that here rather than modifying the upstream code...
983 $qpos = strpos($url, '?');
984 if ($qpos !== false) {
985 $url = substr($url, 0, $qpos+1) .
986 str_replace('?', '&', substr($url, $qpos+1));
988 // @fixme this is a hacky workaround for http_build_query in the
989 // lower-level code and bad configs that set the default separator
990 // to & instead of &. Encoded &s in parameters will not be
992 $url = substr($url, 0, $qpos+1) .
993 str_replace('&', '&', substr($url, $qpos+1));