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'));
226 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
227 $m->connect('main/'.$c.'/:code', array('action' => $c));
232 $m->connect('main/remote', array('action' => 'remotesubscribe'));
233 $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
235 foreach (Router::$bare as $action) {
236 $m->connect('index.php?action=' . $action, array('action' => $action));
241 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
242 'oauthapps', 'email', 'sms', 'userdesign', 'other') as $s) {
243 $m->connect('settings/'.$s, array('action' => $s.'settings'));
246 $m->connect('settings/oauthapps/show/:id',
247 array('action' => 'showapplication'),
248 array('id' => '[0-9]+')
250 $m->connect('settings/oauthapps/new',
251 array('action' => 'newapplication')
253 $m->connect('settings/oauthapps/edit/:id',
254 array('action' => 'editapplication'),
255 array('id' => '[0-9]+')
257 $m->connect('settings/oauthapps/delete/:id',
258 array('action' => 'deleteapplication'),
259 array('id' => '[0-9]+')
264 foreach (array('group', 'people', 'notice') as $s) {
265 $m->connect('search/'.$s, array('action' => $s.'search'));
266 $m->connect('search/'.$s.'?q=:q',
267 array('action' => $s.'search'),
271 // The second of these is needed to make the link work correctly
272 // when inserted into the page. The first is needed to match the
273 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
274 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
275 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
278 $m->connect('attachment/:attachment',
279 array('action' => 'attachment'),
280 array('attachment' => '[0-9]+'));
282 $m->connect('attachment/:attachment/ajax',
283 array('action' => 'attachment_ajax'),
284 array('attachment' => '[0-9]+'));
286 $m->connect('attachment/:attachment/thumbnail',
287 array('action' => 'attachment_thumbnail'),
288 array('attachment' => '[0-9]+'));
290 $m->connect('notice/new', array('action' => 'newnotice'));
291 $m->connect('notice/new?replyto=:replyto',
292 array('action' => 'newnotice'),
293 array('replyto' => '[A-Za-z0-9_-]+'));
294 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
295 array('action' => 'newnotice'),
296 array('replyto' => '[A-Za-z0-9_-]+'),
297 array('inreplyto' => '[0-9]+'));
299 $m->connect('notice/:notice/file',
300 array('action' => 'file'),
301 array('notice' => '[0-9]+'));
303 $m->connect('notice/:notice',
304 array('action' => 'shownotice'),
305 array('notice' => '[0-9]+'));
306 $m->connect('notice/delete', array('action' => 'deletenotice'));
307 $m->connect('notice/delete/:notice',
308 array('action' => 'deletenotice'),
309 array('notice' => '[0-9]+'));
311 $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
315 $m->connect('conversation/:id',
316 array('action' => 'conversation'),
317 array('id' => '[0-9]+'));
319 $m->connect('message/new', array('action' => 'newmessage'));
320 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
321 $m->connect('message/:message',
322 array('action' => 'showmessage'),
323 array('message' => '[0-9]+'));
325 $m->connect('user/:id',
326 array('action' => 'userbyid'),
327 array('id' => '[0-9]+'));
329 $m->connect('tags/', array('action' => 'publictagcloud'));
330 $m->connect('tag/', array('action' => 'publictagcloud'));
331 $m->connect('tags', array('action' => 'publictagcloud'));
332 $m->connect('tag', array('action' => 'publictagcloud'));
333 $m->connect('tag/:tag/rss',
334 array('action' => 'tagrss'),
335 array('tag' => '[\pL\pN_\-\.]{1,64}'));
336 $m->connect('tag/:tag',
337 array('action' => 'tag'),
338 array('tag' => '[\pL\pN_\-\.]{1,64}'));
340 $m->connect('peopletag/:tag',
341 array('action' => 'peopletag'),
342 array('tag' => '[a-zA-Z0-9]+'));
346 $m->connect('group/new', array('action' => 'newgroup'));
348 foreach (array('edit', 'join', 'leave', 'delete') as $v) {
349 $m->connect('group/:nickname/'.$v,
350 array('action' => $v.'group'),
351 array('nickname' => '[a-zA-Z0-9]+'));
352 $m->connect('group/:id/id/'.$v,
353 array('action' => $v.'group'),
354 array('id' => '[0-9]+'));
357 foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
358 $m->connect('group/:nickname/'.$n,
359 array('action' => 'group'.$n),
360 array('nickname' => '[a-zA-Z0-9]+'));
363 $m->connect('group/:nickname/foaf',
364 array('action' => 'foafgroup'),
365 array('nickname' => '[a-zA-Z0-9]+'));
367 $m->connect('group/:nickname/blocked',
368 array('action' => 'blockedfromgroup'),
369 array('nickname' => '[a-zA-Z0-9]+'));
371 $m->connect('group/:nickname/makeadmin',
372 array('action' => 'makeadmin'),
373 array('nickname' => '[a-zA-Z0-9]+'));
375 $m->connect('group/:id/id',
376 array('action' => 'groupbyid'),
377 array('id' => '[0-9]+'));
379 $m->connect('group/:nickname',
380 array('action' => 'showgroup'),
381 array('nickname' => '[a-zA-Z0-9]+'));
383 $m->connect('group/', array('action' => 'groups'));
384 $m->connect('group', array('action' => 'groups'));
385 $m->connect('groups/', array('action' => 'groups'));
386 $m->connect('groups', array('action' => 'groups'));
388 // Twitter-compatible API
392 $m->connect('api/statuses/public_timeline.:format',
393 array('action' => 'ApiTimelinePublic',
394 'format' => '(xml|json|rss|atom)'));
396 $m->connect('api/statuses/friends_timeline.:format',
397 array('action' => 'ApiTimelineFriends',
398 'format' => '(xml|json|rss|atom)'));
400 $m->connect('api/statuses/friends_timeline/:id.:format',
401 array('action' => 'ApiTimelineFriends',
402 'id' => '[a-zA-Z0-9]+',
403 'format' => '(xml|json|rss|atom)'));
405 $m->connect('api/statuses/home_timeline.:format',
406 array('action' => 'ApiTimelineHome',
407 'format' => '(xml|json|rss|atom)'));
409 $m->connect('api/statuses/home_timeline/:id.:format',
410 array('action' => 'ApiTimelineHome',
411 'id' => '[a-zA-Z0-9]+',
412 'format' => '(xml|json|rss|atom)'));
414 $m->connect('api/statuses/user_timeline.:format',
415 array('action' => 'ApiTimelineUser',
416 'format' => '(xml|json|rss|atom)'));
418 $m->connect('api/statuses/user_timeline/:id.:format',
419 array('action' => 'ApiTimelineUser',
420 'id' => '[a-zA-Z0-9]+',
421 'format' => '(xml|json|rss|atom)'));
423 $m->connect('api/statuses/mentions.:format',
424 array('action' => 'ApiTimelineMentions',
425 'format' => '(xml|json|rss|atom)'));
427 $m->connect('api/statuses/mentions/:id.:format',
428 array('action' => 'ApiTimelineMentions',
429 'id' => '[a-zA-Z0-9]+',
430 'format' => '(xml|json|rss|atom)'));
432 $m->connect('api/statuses/replies.:format',
433 array('action' => 'ApiTimelineMentions',
434 'format' => '(xml|json|rss|atom)'));
436 $m->connect('api/statuses/replies/:id.:format',
437 array('action' => 'ApiTimelineMentions',
438 'id' => '[a-zA-Z0-9]+',
439 'format' => '(xml|json|rss|atom)'));
441 $m->connect('api/statuses/retweeted_by_me.:format',
442 array('action' => 'ApiTimelineRetweetedByMe',
443 'format' => '(xml|json|atom)'));
445 $m->connect('api/statuses/retweeted_to_me.:format',
446 array('action' => 'ApiTimelineRetweetedToMe',
447 'format' => '(xml|json|atom)'));
449 $m->connect('api/statuses/retweets_of_me.:format',
450 array('action' => 'ApiTimelineRetweetsOfMe',
451 'format' => '(xml|json|atom)'));
453 $m->connect('api/statuses/friends.:format',
454 array('action' => 'ApiUserFriends',
455 'format' => '(xml|json)'));
457 $m->connect('api/statuses/friends/:id.:format',
458 array('action' => 'ApiUserFriends',
459 'id' => '[a-zA-Z0-9]+',
460 'format' => '(xml|json)'));
462 $m->connect('api/statuses/followers.:format',
463 array('action' => 'ApiUserFollowers',
464 'format' => '(xml|json)'));
466 $m->connect('api/statuses/followers/:id.:format',
467 array('action' => 'ApiUserFollowers',
468 'id' => '[a-zA-Z0-9]+',
469 'format' => '(xml|json)'));
471 $m->connect('api/statuses/show.:format',
472 array('action' => 'ApiStatusesShow',
473 'format' => '(xml|json)'));
475 $m->connect('api/statuses/show/:id.:format',
476 array('action' => 'ApiStatusesShow',
478 'format' => '(xml|json)'));
480 $m->connect('api/statuses/update.:format',
481 array('action' => 'ApiStatusesUpdate',
482 'format' => '(xml|json)'));
484 $m->connect('api/statuses/destroy.:format',
485 array('action' => 'ApiStatusesDestroy',
486 'format' => '(xml|json)'));
488 $m->connect('api/statuses/destroy/:id.:format',
489 array('action' => 'ApiStatusesDestroy',
491 'format' => '(xml|json)'));
493 $m->connect('api/statuses/retweet/:id.:format',
494 array('action' => 'ApiStatusesRetweet',
496 'format' => '(xml|json)'));
498 $m->connect('api/statuses/retweets/:id.:format',
499 array('action' => 'ApiStatusesRetweets',
501 'format' => '(xml|json)'));
505 $m->connect('api/users/show.:format',
506 array('action' => 'ApiUserShow',
507 'format' => '(xml|json)'));
509 $m->connect('api/users/show/:id.:format',
510 array('action' => 'ApiUserShow',
511 'id' => '[a-zA-Z0-9]+',
512 'format' => '(xml|json)'));
516 $m->connect('api/direct_messages.:format',
517 array('action' => 'ApiDirectMessage',
518 'format' => '(xml|json|rss|atom)'));
520 $m->connect('api/direct_messages/sent.:format',
521 array('action' => 'ApiDirectMessage',
522 'format' => '(xml|json|rss|atom)',
525 $m->connect('api/direct_messages/new.:format',
526 array('action' => 'ApiDirectMessageNew',
527 'format' => '(xml|json)'));
531 $m->connect('api/friendships/show.:format',
532 array('action' => 'ApiFriendshipsShow',
533 'format' => '(xml|json)'));
535 $m->connect('api/friendships/exists.:format',
536 array('action' => 'ApiFriendshipsExists',
537 'format' => '(xml|json)'));
539 $m->connect('api/friendships/create.:format',
540 array('action' => 'ApiFriendshipsCreate',
541 'format' => '(xml|json)'));
543 $m->connect('api/friendships/destroy.:format',
544 array('action' => 'ApiFriendshipsDestroy',
545 'format' => '(xml|json)'));
547 $m->connect('api/friendships/create/:id.:format',
548 array('action' => 'ApiFriendshipsCreate',
549 'id' => '[a-zA-Z0-9]+',
550 'format' => '(xml|json)'));
552 $m->connect('api/friendships/destroy/:id.:format',
553 array('action' => 'ApiFriendshipsDestroy',
554 'id' => '[a-zA-Z0-9]+',
555 'format' => '(xml|json)'));
559 $m->connect('api/friends/ids/:id.:format',
560 array('action' => 'ApiUserFriends',
561 'ids_only' => true));
563 $m->connect('api/followers/ids/:id.:format',
564 array('action' => 'ApiUserFollowers',
565 'ids_only' => true));
567 $m->connect('api/friends/ids.:format',
568 array('action' => 'ApiUserFriends',
569 'ids_only' => true));
571 $m->connect('api/followers/ids.:format',
572 array('action' => 'ApiUserFollowers',
573 'ids_only' => true));
577 $m->connect('api/account/verify_credentials.:format',
578 array('action' => 'ApiAccountVerifyCredentials'));
580 $m->connect('api/account/update_profile.:format',
581 array('action' => 'ApiAccountUpdateProfile'));
583 $m->connect('api/account/update_profile_image.:format',
584 array('action' => 'ApiAccountUpdateProfileImage'));
586 $m->connect('api/account/update_profile_background_image.:format',
587 array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
589 $m->connect('api/account/update_profile_colors.:format',
590 array('action' => 'ApiAccountUpdateProfileColors'));
592 $m->connect('api/account/update_delivery_device.:format',
593 array('action' => 'ApiAccountUpdateDeliveryDevice'));
595 // special case where verify_credentials is called w/out a format
597 $m->connect('api/account/verify_credentials',
598 array('action' => 'ApiAccountVerifyCredentials'));
600 $m->connect('api/account/rate_limit_status.:format',
601 array('action' => 'ApiAccountRateLimitStatus'));
605 $m->connect('api/favorites.:format',
606 array('action' => 'ApiTimelineFavorites',
607 'format' => '(xml|json|rss|atom)'));
609 $m->connect('api/favorites/:id.:format',
610 array('action' => 'ApiTimelineFavorites',
611 'id' => '[a-zA-Z0-9]+',
612 'format' => '(xml|json|rss|atom)'));
614 $m->connect('api/favorites/create/:id.:format',
615 array('action' => 'ApiFavoriteCreate',
616 'id' => '[a-zA-Z0-9]+',
617 'format' => '(xml|json)'));
619 $m->connect('api/favorites/destroy/:id.:format',
620 array('action' => 'ApiFavoriteDestroy',
621 'id' => '[a-zA-Z0-9]+',
622 'format' => '(xml|json)'));
625 $m->connect('api/blocks/create.:format',
626 array('action' => 'ApiBlockCreate',
627 'format' => '(xml|json)'));
629 $m->connect('api/blocks/create/:id.:format',
630 array('action' => 'ApiBlockCreate',
631 'id' => '[a-zA-Z0-9]+',
632 'format' => '(xml|json)'));
634 $m->connect('api/blocks/destroy.:format',
635 array('action' => 'ApiBlockDestroy',
636 'format' => '(xml|json)'));
638 $m->connect('api/blocks/destroy/:id.:format',
639 array('action' => 'ApiBlockDestroy',
640 'id' => '[a-zA-Z0-9]+',
641 'format' => '(xml|json)'));
644 $m->connect('api/help/test.:format',
645 array('action' => 'ApiHelpTest',
646 'format' => '(xml|json)'));
650 $m->connect('api/statusnet/version.:format',
651 array('action' => 'ApiStatusnetVersion',
652 'format' => '(xml|json)'));
654 $m->connect('api/statusnet/config.:format',
655 array('action' => 'ApiStatusnetConfig',
656 'format' => '(xml|json)'));
658 // For older methods, we provide "laconica" base action
660 $m->connect('api/laconica/version.:format',
661 array('action' => 'ApiStatusnetVersion',
662 'format' => '(xml|json)'));
664 $m->connect('api/laconica/config.:format',
665 array('action' => 'ApiStatusnetConfig',
666 'format' => '(xml|json)'));
668 // Groups and tags are newer than 0.8.1 so no backward-compatibility
672 //'list' has to be handled differently, as php will not allow a method to be named 'list'
674 $m->connect('api/statusnet/groups/timeline/:id.:format',
675 array('action' => 'ApiTimelineGroup',
676 'id' => '[a-zA-Z0-9]+',
677 'format' => '(xml|json|rss|atom)'));
679 $m->connect('api/statusnet/groups/show.:format',
680 array('action' => 'ApiGroupShow',
681 'format' => '(xml|json)'));
683 $m->connect('api/statusnet/groups/show/:id.:format',
684 array('action' => 'ApiGroupShow',
685 'id' => '[a-zA-Z0-9]+',
686 'format' => '(xml|json)'));
688 $m->connect('api/statusnet/groups/join.:format',
689 array('action' => 'ApiGroupJoin',
690 'id' => '[a-zA-Z0-9]+',
691 'format' => '(xml|json)'));
693 $m->connect('api/statusnet/groups/join/:id.:format',
694 array('action' => 'ApiGroupJoin',
695 'format' => '(xml|json)'));
697 $m->connect('api/statusnet/groups/leave.:format',
698 array('action' => 'ApiGroupLeave',
699 'id' => '[a-zA-Z0-9]+',
700 'format' => '(xml|json)'));
702 $m->connect('api/statusnet/groups/leave/:id.:format',
703 array('action' => 'ApiGroupLeave',
704 'format' => '(xml|json)'));
706 $m->connect('api/statusnet/groups/is_member.:format',
707 array('action' => 'ApiGroupIsMember',
708 'format' => '(xml|json)'));
710 $m->connect('api/statusnet/groups/list.:format',
711 array('action' => 'ApiGroupList',
712 'format' => '(xml|json|rss|atom)'));
714 $m->connect('api/statusnet/groups/list/:id.:format',
715 array('action' => 'ApiGroupList',
716 'id' => '[a-zA-Z0-9]+',
717 'format' => '(xml|json|rss|atom)'));
719 $m->connect('api/statusnet/groups/list_all.:format',
720 array('action' => 'ApiGroupListAll',
721 'format' => '(xml|json|rss|atom)'));
723 $m->connect('api/statusnet/groups/membership.:format',
724 array('action' => 'ApiGroupMembership',
725 'format' => '(xml|json)'));
727 $m->connect('api/statusnet/groups/membership/:id.:format',
728 array('action' => 'ApiGroupMembership',
729 'id' => '[a-zA-Z0-9]+',
730 'format' => '(xml|json)'));
732 $m->connect('api/statusnet/groups/create.:format',
733 array('action' => 'ApiGroupCreate',
734 'format' => '(xml|json)'));
736 $m->connect('api/statusnet/tags/timeline/:tag.:format',
737 array('action' => 'ApiTimelineTag',
738 'format' => '(xml|json|rss|atom)'));
742 'api/statusnet/media/upload',
743 array('action' => 'ApiMediaUpload')
747 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
748 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
749 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
751 $m->connect('api/oauth/request_token',
752 array('action' => 'ApiOauthRequestToken'));
754 $m->connect('api/oauth/access_token',
755 array('action' => 'ApiOauthAccessToken'));
757 $m->connect('api/oauth/authorize',
758 array('action' => 'ApiOauthAuthorize'));
762 $m->connect('admin/site', array('action' => 'siteadminpanel'));
763 $m->connect('admin/design', array('action' => 'designadminpanel'));
764 $m->connect('admin/user', array('action' => 'useradminpanel'));
765 $m->connect('admin/access', array('action' => 'accessadminpanel'));
766 $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
767 $m->connect('admin/sessions', array('action' => 'sessionsadminpanel'));
768 $m->connect('admin/sitenotice', array('action' => 'sitenoticeadminpanel'));
769 $m->connect('admin/snapshot', array('action' => 'snapshotadminpanel'));
770 $m->connect('admin/license', array('action' => 'licenseadminpanel'));
772 $m->connect('getfile/:filename',
773 array('action' => 'getfile'),
774 array('filename' => '[A-Za-z0-9._-]+'));
778 if (common_config('singleuser', 'enabled')) {
780 $nickname = User::singleUserNickname();
782 foreach (array('subscriptions', 'subscribers',
783 'all', 'foaf', 'xrds',
784 'replies', 'microsummary', 'hcard') as $a) {
786 array('action' => $a,
787 'nickname' => $nickname));
790 foreach (array('subscriptions', 'subscribers') as $a) {
791 $m->connect($a.'/:tag',
792 array('action' => $a,
793 'nickname' => $nickname),
794 array('tag' => '[a-zA-Z0-9]+'));
797 foreach (array('rss', 'groups') as $a) {
799 array('action' => 'user'.$a,
800 'nickname' => $nickname));
803 foreach (array('all', 'replies', 'favorites') as $a) {
804 $m->connect($a.'/rss',
805 array('action' => $a.'rss',
806 'nickname' => $nickname));
809 $m->connect('favorites',
810 array('action' => 'showfavorites',
811 'nickname' => $nickname));
813 $m->connect('avatar/:size',
814 array('action' => 'avatarbynickname',
815 'nickname' => $nickname),
816 array('size' => '(original|96|48|24)'));
818 $m->connect('tag/:tag/rss',
819 array('action' => 'userrss',
820 'nickname' => $nickname),
821 array('tag' => '[\pL\pN_\-\.]{1,64}'));
823 $m->connect('tag/:tag',
824 array('action' => 'showstream',
825 'nickname' => $nickname),
826 array('tag' => '[\pL\pN_\-\.]{1,64}'));
828 $m->connect('rsd.xml',
829 array('action' => 'rsd',
830 'nickname' => $nickname));
833 array('action' => 'showstream',
834 'nickname' => $nickname));
836 $m->connect('', array('action' => 'public'));
837 $m->connect('rss', array('action' => 'publicrss'));
838 $m->connect('featuredrss', array('action' => 'featuredrss'));
839 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
840 $m->connect('featured/', array('action' => 'featured'));
841 $m->connect('featured', array('action' => 'featured'));
842 $m->connect('favorited/', array('action' => 'favorited'));
843 $m->connect('favorited', array('action' => 'favorited'));
844 $m->connect('rsd.xml', array('action' => 'rsd'));
846 foreach (array('subscriptions', 'subscribers',
847 'nudge', 'all', 'foaf', 'xrds',
848 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
849 $m->connect(':nickname/'.$a,
850 array('action' => $a),
851 array('nickname' => '[a-zA-Z0-9]{1,64}'));
854 foreach (array('subscriptions', 'subscribers') as $a) {
855 $m->connect(':nickname/'.$a.'/:tag',
856 array('action' => $a),
857 array('tag' => '[a-zA-Z0-9]+',
858 'nickname' => '[a-zA-Z0-9]{1,64}'));
861 foreach (array('rss', 'groups') as $a) {
862 $m->connect(':nickname/'.$a,
863 array('action' => 'user'.$a),
864 array('nickname' => '[a-zA-Z0-9]{1,64}'));
867 foreach (array('all', 'replies', 'favorites') as $a) {
868 $m->connect(':nickname/'.$a.'/rss',
869 array('action' => $a.'rss'),
870 array('nickname' => '[a-zA-Z0-9]{1,64}'));
873 $m->connect(':nickname/favorites',
874 array('action' => 'showfavorites'),
875 array('nickname' => '[a-zA-Z0-9]{1,64}'));
877 $m->connect(':nickname/avatar/:size',
878 array('action' => 'avatarbynickname'),
879 array('size' => '(original|96|48|24)',
880 'nickname' => '[a-zA-Z0-9]{1,64}'));
882 $m->connect(':nickname/tag/:tag/rss',
883 array('action' => 'userrss'),
884 array('nickname' => '[a-zA-Z0-9]{1,64}'),
885 array('tag' => '[\pL\pN_\-\.]{1,64}'));
887 $m->connect(':nickname/tag/:tag',
888 array('action' => 'showstream'),
889 array('nickname' => '[a-zA-Z0-9]{1,64}'),
890 array('tag' => '[\pL\pN_\-\.]{1,64}'));
892 $m->connect(':nickname/rsd.xml',
893 array('action' => 'rsd'),
894 array('nickname' => '[a-zA-Z0-9]{1,64}'));
896 $m->connect(':nickname',
897 array('action' => 'showstream'),
898 array('nickname' => '[a-zA-Z0-9]{1,64}'));
903 Event::handle('RouterInitialized', array($m));
912 $match = $this->m->match($path);
913 } catch (Net_URL_Mapper_InvalidException $e) {
914 common_log(LOG_ERR, "Problem getting route for $path - " .
916 // TRANS: Client error on action trying to visit a non-existing page.
917 $cac = new ClientErrorAction(_('Page not found.'), 404);
924 function build($action, $args=null, $params=null, $fragment=null)
926 $action_arg = array('action' => $action);
929 $args = array_merge($action_arg, $args);
934 $url = $this->m->generate($args, $params, $fragment);
936 // Due to a bug in the Net_URL_Mapper code, the returned URL may
937 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
938 // repair that here rather than modifying the upstream code...
940 $qpos = strpos($url, '?');
941 if ($qpos !== false) {
942 $url = substr($url, 0, $qpos+1) .
943 str_replace('?', '&', substr($url, $qpos+1));
945 // @fixme this is a hacky workaround for http_build_query in the
946 // lower-level code and bad configs that set the default separator
947 // to & instead of &. Encoded &s in parameters will not be
949 $url = substr($url, 0, $qpos+1) .
950 str_replace('&', '&', substr($url, $qpos+1));