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 {
37 private static $_singleton = null;
39 private function __construct()
43 public static function getInstance($id = '__default__')
45 if (empty(self::$_singleton)) {
46 self::$_singleton = new StatusNet_URL_Mapper();
48 return self::$_singleton;
51 public function connect($path, $defaults = array(), $rules = array())
54 if (Event::handle('StartConnectPath', array(&$path, &$defaults, &$rules, &$result))) {
55 $result = parent::connect($path, $defaults, $rules);
56 Event::handle('EndConnectPath', array($path, $defaults, $rules, $result));
65 * Cheap wrapper around Net_URL_Mapper
69 * @author Evan Prodromou <evan@status.net>
70 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
71 * @link http://status.net/
77 static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
78 'postnotice', 'updateprofile', 'finishremotesubscribe');
83 Router::$inst = new Router();
88 function __construct()
91 $this->m = $this->initialize();
97 $m = StatusNet_URL_Mapper::getInstance();
99 if (Event::handle('StartInitializeRouter', array(&$m))) {
101 $m->connect('robots.txt', array('action' => 'robotstxt'));
103 $m->connect('opensearch/people', array('action' => 'opensearch',
104 'type' => 'people'));
105 $m->connect('opensearch/notice', array('action' => 'opensearch',
106 'type' => 'notice'));
110 $m->connect('doc/:title', array('action' => 'doc'));
112 $m->connect('main/otp/:user_id/:token',
113 array('action' => 'otp'),
114 array('user_id' => '[0-9]+',
117 // main stuff is repetitive
119 $main = array('login', 'logout', 'register', 'subscribe',
120 'unsubscribe', 'confirmaddress', 'recoverpassword',
121 'invite', 'favor', 'disfavor', 'sup',
122 'block', 'unblock', 'subedit',
123 'groupblock', 'groupunblock',
124 'sandbox', 'unsandbox',
125 'silence', 'unsilence',
126 'grantrole', 'revokerole',
133 foreach ($main as $a) {
134 $m->connect('main/'.$a, array('action' => $a));
137 // Also need a block variant accepting ID on URL for mail links
138 $m->connect('main/block/:profileid',
139 array('action' => 'block'),
140 array('profileid' => '[0-9]+'));
142 $m->connect('main/sup/:seconds', array('action' => 'sup'),
143 array('seconds' => '[0-9]+'));
145 $m->connect('main/tagother/:id', array('action' => 'tagother'));
147 $m->connect('main/oembed',
148 array('action' => 'oembed'));
150 $m->connect('main/xrds',
151 array('action' => 'publicxrds'));
155 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
156 $m->connect('main/'.$c.'/:code', array('action' => $c));
161 $m->connect('main/remote', array('action' => 'remotesubscribe'));
162 $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
164 foreach (Router::$bare as $action) {
165 $m->connect('index.php?action=' . $action, array('action' => $action));
170 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
171 'oauthapps', 'email', 'sms', 'userdesign', 'other') as $s) {
172 $m->connect('settings/'.$s, array('action' => $s.'settings'));
175 $m->connect('settings/oauthapps/show/:id',
176 array('action' => 'showapplication'),
177 array('id' => '[0-9]+')
179 $m->connect('settings/oauthapps/new',
180 array('action' => 'newapplication')
182 $m->connect('settings/oauthapps/edit/:id',
183 array('action' => 'editapplication'),
184 array('id' => '[0-9]+')
186 $m->connect('settings/oauthapps/delete/:id',
187 array('action' => 'deleteapplication'),
188 array('id' => '[0-9]+')
193 foreach (array('group', 'people', 'notice') as $s) {
194 $m->connect('search/'.$s, array('action' => $s.'search'));
195 $m->connect('search/'.$s.'?q=:q',
196 array('action' => $s.'search'),
200 // The second of these is needed to make the link work correctly
201 // when inserted into the page. The first is needed to match the
202 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
203 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
204 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
207 $m->connect('attachment/:attachment',
208 array('action' => 'attachment'),
209 array('attachment' => '[0-9]+'));
211 $m->connect('attachment/:attachment/ajax',
212 array('action' => 'attachment_ajax'),
213 array('attachment' => '[0-9]+'));
215 $m->connect('attachment/:attachment/thumbnail',
216 array('action' => 'attachment_thumbnail'),
217 array('attachment' => '[0-9]+'));
219 $m->connect('notice/new', array('action' => 'newnotice'));
220 $m->connect('notice/new?replyto=:replyto',
221 array('action' => 'newnotice'),
222 array('replyto' => '[A-Za-z0-9_-]+'));
223 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
224 array('action' => 'newnotice'),
225 array('replyto' => '[A-Za-z0-9_-]+'),
226 array('inreplyto' => '[0-9]+'));
228 $m->connect('notice/:notice/file',
229 array('action' => 'file'),
230 array('notice' => '[0-9]+'));
232 $m->connect('notice/:notice',
233 array('action' => 'shownotice'),
234 array('notice' => '[0-9]+'));
235 $m->connect('notice/delete', array('action' => 'deletenotice'));
236 $m->connect('notice/delete/:notice',
237 array('action' => 'deletenotice'),
238 array('notice' => '[0-9]+'));
240 $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
244 $m->connect('conversation/:id',
245 array('action' => 'conversation'),
246 array('id' => '[0-9]+'));
248 $m->connect('message/new', array('action' => 'newmessage'));
249 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
250 $m->connect('message/:message',
251 array('action' => 'showmessage'),
252 array('message' => '[0-9]+'));
254 $m->connect('user/:id',
255 array('action' => 'userbyid'),
256 array('id' => '[0-9]+'));
258 $m->connect('tags/', array('action' => 'publictagcloud'));
259 $m->connect('tag/', array('action' => 'publictagcloud'));
260 $m->connect('tags', array('action' => 'publictagcloud'));
261 $m->connect('tag', array('action' => 'publictagcloud'));
262 $m->connect('tag/:tag/rss',
263 array('action' => 'tagrss'),
264 array('tag' => '[\pL\pN_\-\.]{1,64}'));
265 $m->connect('tag/:tag',
266 array('action' => 'tag'),
267 array('tag' => '[\pL\pN_\-\.]{1,64}'));
269 $m->connect('peopletag/:tag',
270 array('action' => 'peopletag'),
271 array('tag' => '[a-zA-Z0-9]+'));
275 $m->connect('group/new', array('action' => 'newgroup'));
277 foreach (array('edit', 'join', 'leave', 'delete') as $v) {
278 $m->connect('group/:nickname/'.$v,
279 array('action' => $v.'group'),
280 array('nickname' => '[a-zA-Z0-9]+'));
281 $m->connect('group/:id/id/'.$v,
282 array('action' => $v.'group'),
283 array('id' => '[0-9]+'));
286 foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
287 $m->connect('group/:nickname/'.$n,
288 array('action' => 'group'.$n),
289 array('nickname' => '[a-zA-Z0-9]+'));
292 $m->connect('group/:nickname/foaf',
293 array('action' => 'foafgroup'),
294 array('nickname' => '[a-zA-Z0-9]+'));
296 $m->connect('group/:nickname/blocked',
297 array('action' => 'blockedfromgroup'),
298 array('nickname' => '[a-zA-Z0-9]+'));
300 $m->connect('group/:nickname/makeadmin',
301 array('action' => 'makeadmin'),
302 array('nickname' => '[a-zA-Z0-9]+'));
304 $m->connect('group/:id/id',
305 array('action' => 'groupbyid'),
306 array('id' => '[0-9]+'));
308 $m->connect('group/:nickname',
309 array('action' => 'showgroup'),
310 array('nickname' => '[a-zA-Z0-9]+'));
312 $m->connect('group/', array('action' => 'groups'));
313 $m->connect('group', array('action' => 'groups'));
314 $m->connect('groups/', array('action' => 'groups'));
315 $m->connect('groups', array('action' => 'groups'));
317 // Twitter-compatible API
321 $m->connect('api/statuses/public_timeline.:format',
322 array('action' => 'ApiTimelinePublic',
323 'format' => '(xml|json|rss|atom)'));
325 $m->connect('api/statuses/friends_timeline.:format',
326 array('action' => 'ApiTimelineFriends',
327 'format' => '(xml|json|rss|atom)'));
329 $m->connect('api/statuses/friends_timeline/:id.:format',
330 array('action' => 'ApiTimelineFriends',
331 'id' => '[a-zA-Z0-9]+',
332 'format' => '(xml|json|rss|atom)'));
334 $m->connect('api/statuses/home_timeline.:format',
335 array('action' => 'ApiTimelineHome',
336 'format' => '(xml|json|rss|atom)'));
338 $m->connect('api/statuses/home_timeline/:id.:format',
339 array('action' => 'ApiTimelineHome',
340 'id' => '[a-zA-Z0-9]+',
341 'format' => '(xml|json|rss|atom)'));
343 $m->connect('api/statuses/user_timeline.:format',
344 array('action' => 'ApiTimelineUser',
345 'format' => '(xml|json|rss|atom)'));
347 $m->connect('api/statuses/user_timeline/:id.:format',
348 array('action' => 'ApiTimelineUser',
349 'id' => '[a-zA-Z0-9]+',
350 'format' => '(xml|json|rss|atom)'));
352 $m->connect('api/statuses/mentions.:format',
353 array('action' => 'ApiTimelineMentions',
354 'format' => '(xml|json|rss|atom)'));
356 $m->connect('api/statuses/mentions/:id.:format',
357 array('action' => 'ApiTimelineMentions',
358 'id' => '[a-zA-Z0-9]+',
359 'format' => '(xml|json|rss|atom)'));
361 $m->connect('api/statuses/replies.:format',
362 array('action' => 'ApiTimelineMentions',
363 'format' => '(xml|json|rss|atom)'));
365 $m->connect('api/statuses/replies/:id.:format',
366 array('action' => 'ApiTimelineMentions',
367 'id' => '[a-zA-Z0-9]+',
368 'format' => '(xml|json|rss|atom)'));
370 $m->connect('api/statuses/retweeted_by_me.:format',
371 array('action' => 'ApiTimelineRetweetedByMe',
372 'format' => '(xml|json|atom)'));
374 $m->connect('api/statuses/retweeted_to_me.:format',
375 array('action' => 'ApiTimelineRetweetedToMe',
376 'format' => '(xml|json|atom)'));
378 $m->connect('api/statuses/retweets_of_me.:format',
379 array('action' => 'ApiTimelineRetweetsOfMe',
380 'format' => '(xml|json|atom)'));
382 $m->connect('api/statuses/friends.:format',
383 array('action' => 'ApiUserFriends',
384 'format' => '(xml|json)'));
386 $m->connect('api/statuses/friends/:id.:format',
387 array('action' => 'ApiUserFriends',
388 'id' => '[a-zA-Z0-9]+',
389 'format' => '(xml|json)'));
391 $m->connect('api/statuses/followers.:format',
392 array('action' => 'ApiUserFollowers',
393 'format' => '(xml|json)'));
395 $m->connect('api/statuses/followers/:id.:format',
396 array('action' => 'ApiUserFollowers',
397 'id' => '[a-zA-Z0-9]+',
398 'format' => '(xml|json)'));
400 $m->connect('api/statuses/show.:format',
401 array('action' => 'ApiStatusesShow',
402 'format' => '(xml|json)'));
404 $m->connect('api/statuses/show/:id.:format',
405 array('action' => 'ApiStatusesShow',
407 'format' => '(xml|json)'));
409 $m->connect('api/statuses/update.:format',
410 array('action' => 'ApiStatusesUpdate',
411 'format' => '(xml|json)'));
413 $m->connect('api/statuses/destroy.:format',
414 array('action' => 'ApiStatusesDestroy',
415 'format' => '(xml|json)'));
417 $m->connect('api/statuses/destroy/:id.:format',
418 array('action' => 'ApiStatusesDestroy',
420 'format' => '(xml|json)'));
422 $m->connect('api/statuses/retweet/:id.:format',
423 array('action' => 'ApiStatusesRetweet',
425 'format' => '(xml|json)'));
427 $m->connect('api/statuses/retweets/:id.:format',
428 array('action' => 'ApiStatusesRetweets',
430 'format' => '(xml|json)'));
434 $m->connect('api/users/show.:format',
435 array('action' => 'ApiUserShow',
436 'format' => '(xml|json)'));
438 $m->connect('api/users/show/:id.:format',
439 array('action' => 'ApiUserShow',
440 'id' => '[a-zA-Z0-9]+',
441 'format' => '(xml|json)'));
445 $m->connect('api/direct_messages.:format',
446 array('action' => 'ApiDirectMessage',
447 'format' => '(xml|json|rss|atom)'));
449 $m->connect('api/direct_messages/sent.:format',
450 array('action' => 'ApiDirectMessage',
451 'format' => '(xml|json|rss|atom)',
454 $m->connect('api/direct_messages/new.:format',
455 array('action' => 'ApiDirectMessageNew',
456 'format' => '(xml|json)'));
460 $m->connect('api/friendships/show.:format',
461 array('action' => 'ApiFriendshipsShow',
462 'format' => '(xml|json)'));
464 $m->connect('api/friendships/exists.:format',
465 array('action' => 'ApiFriendshipsExists',
466 'format' => '(xml|json)'));
468 $m->connect('api/friendships/create.:format',
469 array('action' => 'ApiFriendshipsCreate',
470 'format' => '(xml|json)'));
472 $m->connect('api/friendships/destroy.:format',
473 array('action' => 'ApiFriendshipsDestroy',
474 'format' => '(xml|json)'));
476 $m->connect('api/friendships/create/:id.:format',
477 array('action' => 'ApiFriendshipsCreate',
478 'id' => '[a-zA-Z0-9]+',
479 'format' => '(xml|json)'));
481 $m->connect('api/friendships/destroy/:id.:format',
482 array('action' => 'ApiFriendshipsDestroy',
483 'id' => '[a-zA-Z0-9]+',
484 'format' => '(xml|json)'));
488 $m->connect('api/friends/ids/:id.:format',
489 array('action' => 'ApiUserFriends',
490 'ids_only' => true));
492 $m->connect('api/followers/ids/:id.:format',
493 array('action' => 'ApiUserFollowers',
494 'ids_only' => true));
496 $m->connect('api/friends/ids.:format',
497 array('action' => 'ApiUserFriends',
498 'ids_only' => true));
500 $m->connect('api/followers/ids.:format',
501 array('action' => 'ApiUserFollowers',
502 'ids_only' => true));
506 $m->connect('api/account/verify_credentials.:format',
507 array('action' => 'ApiAccountVerifyCredentials'));
509 $m->connect('api/account/update_profile.:format',
510 array('action' => 'ApiAccountUpdateProfile'));
512 $m->connect('api/account/update_profile_image.:format',
513 array('action' => 'ApiAccountUpdateProfileImage'));
515 $m->connect('api/account/update_profile_background_image.:format',
516 array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
518 $m->connect('api/account/update_profile_colors.:format',
519 array('action' => 'ApiAccountUpdateProfileColors'));
521 $m->connect('api/account/update_delivery_device.:format',
522 array('action' => 'ApiAccountUpdateDeliveryDevice'));
524 // special case where verify_credentials is called w/out a format
526 $m->connect('api/account/verify_credentials',
527 array('action' => 'ApiAccountVerifyCredentials'));
529 $m->connect('api/account/rate_limit_status.:format',
530 array('action' => 'ApiAccountRateLimitStatus'));
534 $m->connect('api/favorites.:format',
535 array('action' => 'ApiTimelineFavorites',
536 'format' => '(xml|json|rss|atom)'));
538 $m->connect('api/favorites/:id.:format',
539 array('action' => 'ApiTimelineFavorites',
540 'id' => '[a-zA-Z0-9]+',
541 'format' => '(xml|json|rss|atom)'));
543 $m->connect('api/favorites/create/:id.:format',
544 array('action' => 'ApiFavoriteCreate',
545 'id' => '[a-zA-Z0-9]+',
546 'format' => '(xml|json)'));
548 $m->connect('api/favorites/destroy/:id.:format',
549 array('action' => 'ApiFavoriteDestroy',
550 'id' => '[a-zA-Z0-9]+',
551 'format' => '(xml|json)'));
554 $m->connect('api/blocks/create.:format',
555 array('action' => 'ApiBlockCreate',
556 'format' => '(xml|json)'));
558 $m->connect('api/blocks/create/:id.:format',
559 array('action' => 'ApiBlockCreate',
560 'id' => '[a-zA-Z0-9]+',
561 'format' => '(xml|json)'));
563 $m->connect('api/blocks/destroy.:format',
564 array('action' => 'ApiBlockDestroy',
565 'format' => '(xml|json)'));
567 $m->connect('api/blocks/destroy/:id.:format',
568 array('action' => 'ApiBlockDestroy',
569 'id' => '[a-zA-Z0-9]+',
570 'format' => '(xml|json)'));
573 $m->connect('api/help/test.:format',
574 array('action' => 'ApiHelpTest',
575 'format' => '(xml|json)'));
579 $m->connect('api/statusnet/version.:format',
580 array('action' => 'ApiStatusnetVersion',
581 'format' => '(xml|json)'));
583 $m->connect('api/statusnet/config.:format',
584 array('action' => 'ApiStatusnetConfig',
585 'format' => '(xml|json)'));
587 // For older methods, we provide "laconica" base action
589 $m->connect('api/laconica/version.:format',
590 array('action' => 'ApiStatusnetVersion',
591 'format' => '(xml|json)'));
593 $m->connect('api/laconica/config.:format',
594 array('action' => 'ApiStatusnetConfig',
595 'format' => '(xml|json)'));
597 // Groups and tags are newer than 0.8.1 so no backward-compatibility
601 //'list' has to be handled differently, as php will not allow a method to be named 'list'
603 $m->connect('api/statusnet/groups/timeline/:id.:format',
604 array('action' => 'ApiTimelineGroup',
605 'id' => '[a-zA-Z0-9]+',
606 'format' => '(xml|json|rss|atom)'));
608 $m->connect('api/statusnet/groups/show.:format',
609 array('action' => 'ApiGroupShow',
610 'format' => '(xml|json)'));
612 $m->connect('api/statusnet/groups/show/:id.:format',
613 array('action' => 'ApiGroupShow',
614 'id' => '[a-zA-Z0-9]+',
615 'format' => '(xml|json)'));
617 $m->connect('api/statusnet/groups/join.:format',
618 array('action' => 'ApiGroupJoin',
619 'id' => '[a-zA-Z0-9]+',
620 'format' => '(xml|json)'));
622 $m->connect('api/statusnet/groups/join/:id.:format',
623 array('action' => 'ApiGroupJoin',
624 'format' => '(xml|json)'));
626 $m->connect('api/statusnet/groups/leave.:format',
627 array('action' => 'ApiGroupLeave',
628 'id' => '[a-zA-Z0-9]+',
629 'format' => '(xml|json)'));
631 $m->connect('api/statusnet/groups/leave/:id.:format',
632 array('action' => 'ApiGroupLeave',
633 'format' => '(xml|json)'));
635 $m->connect('api/statusnet/groups/is_member.:format',
636 array('action' => 'ApiGroupIsMember',
637 'format' => '(xml|json)'));
639 $m->connect('api/statusnet/groups/list.:format',
640 array('action' => 'ApiGroupList',
641 'format' => '(xml|json|rss|atom)'));
643 $m->connect('api/statusnet/groups/list/:id.:format',
644 array('action' => 'ApiGroupList',
645 'id' => '[a-zA-Z0-9]+',
646 'format' => '(xml|json|rss|atom)'));
648 $m->connect('api/statusnet/groups/list_all.:format',
649 array('action' => 'ApiGroupListAll',
650 'format' => '(xml|json|rss|atom)'));
652 $m->connect('api/statusnet/groups/membership.:format',
653 array('action' => 'ApiGroupMembership',
654 'format' => '(xml|json)'));
656 $m->connect('api/statusnet/groups/membership/:id.:format',
657 array('action' => 'ApiGroupMembership',
658 'id' => '[a-zA-Z0-9]+',
659 'format' => '(xml|json)'));
661 $m->connect('api/statusnet/groups/create.:format',
662 array('action' => 'ApiGroupCreate',
663 'format' => '(xml|json)'));
665 $m->connect('api/statusnet/tags/timeline/:tag.:format',
666 array('action' => 'ApiTimelineTag',
667 'format' => '(xml|json|rss|atom)'));
671 'api/statusnet/media/upload',
672 array('action' => 'ApiMediaUpload')
676 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
677 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
678 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
680 $m->connect('api/oauth/request_token',
681 array('action' => 'ApiOauthRequestToken'));
683 $m->connect('api/oauth/access_token',
684 array('action' => 'ApiOauthAccessToken'));
686 $m->connect('api/oauth/authorize',
687 array('action' => 'ApiOauthAuthorize'));
691 $m->connect('admin/site', array('action' => 'siteadminpanel'));
692 $m->connect('admin/design', array('action' => 'designadminpanel'));
693 $m->connect('admin/user', array('action' => 'useradminpanel'));
694 $m->connect('admin/access', array('action' => 'accessadminpanel'));
695 $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
696 $m->connect('admin/sessions', array('action' => 'sessionsadminpanel'));
697 $m->connect('admin/sitenotice', array('action' => 'sitenoticeadminpanel'));
698 $m->connect('admin/snapshot', array('action' => 'snapshotadminpanel'));
699 $m->connect('admin/license', array('action' => 'licenseadminpanel'));
701 $m->connect('getfile/:filename',
702 array('action' => 'getfile'),
703 array('filename' => '[A-Za-z0-9._-]+'));
707 if (common_config('singleuser', 'enabled')) {
709 $user = User::singleUser();
710 $nickname = $user->nickname;
712 foreach (array('subscriptions', 'subscribers',
713 'all', 'foaf', 'xrds',
714 'replies', 'microsummary', 'hcard') as $a) {
716 array('action' => $a,
717 'nickname' => $nickname));
720 foreach (array('subscriptions', 'subscribers') as $a) {
721 $m->connect($a.'/:tag',
722 array('action' => $a,
723 'nickname' => $nickname),
724 array('tag' => '[a-zA-Z0-9]+'));
727 foreach (array('rss', 'groups') as $a) {
729 array('action' => 'user'.$a,
730 'nickname' => $nickname));
733 foreach (array('all', 'replies', 'favorites') as $a) {
734 $m->connect($a.'/rss',
735 array('action' => $a.'rss',
736 'nickname' => $nickname));
739 $m->connect('favorites',
740 array('action' => 'showfavorites',
741 'nickname' => $nickname));
743 $m->connect('avatar/:size',
744 array('action' => 'avatarbynickname',
745 'nickname' => $nickname),
746 array('size' => '(original|96|48|24)'));
748 $m->connect('tag/:tag/rss',
749 array('action' => 'userrss',
750 'nickname' => $nickname),
751 array('tag' => '[\pL\pN_\-\.]{1,64}'));
753 $m->connect('tag/:tag',
754 array('action' => 'showstream',
755 'nickname' => $nickname),
756 array('tag' => '[\pL\pN_\-\.]{1,64}'));
758 $m->connect('rsd.xml',
759 array('action' => 'rsd',
760 'nickname' => $nickname));
763 array('action' => 'showstream',
764 'nickname' => $nickname));
766 $m->connect('', array('action' => 'public'));
767 $m->connect('rss', array('action' => 'publicrss'));
768 $m->connect('featuredrss', array('action' => 'featuredrss'));
769 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
770 $m->connect('featured/', array('action' => 'featured'));
771 $m->connect('featured', array('action' => 'featured'));
772 $m->connect('favorited/', array('action' => 'favorited'));
773 $m->connect('favorited', array('action' => 'favorited'));
774 $m->connect('rsd.xml', array('action' => 'rsd'));
776 foreach (array('subscriptions', 'subscribers',
777 'nudge', 'all', 'foaf', 'xrds',
778 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
779 $m->connect(':nickname/'.$a,
780 array('action' => $a),
781 array('nickname' => '[a-zA-Z0-9]{1,64}'));
784 foreach (array('subscriptions', 'subscribers') as $a) {
785 $m->connect(':nickname/'.$a.'/:tag',
786 array('action' => $a),
787 array('tag' => '[a-zA-Z0-9]+',
788 'nickname' => '[a-zA-Z0-9]{1,64}'));
791 foreach (array('rss', 'groups') as $a) {
792 $m->connect(':nickname/'.$a,
793 array('action' => 'user'.$a),
794 array('nickname' => '[a-zA-Z0-9]{1,64}'));
797 foreach (array('all', 'replies', 'favorites') as $a) {
798 $m->connect(':nickname/'.$a.'/rss',
799 array('action' => $a.'rss'),
800 array('nickname' => '[a-zA-Z0-9]{1,64}'));
803 $m->connect(':nickname/favorites',
804 array('action' => 'showfavorites'),
805 array('nickname' => '[a-zA-Z0-9]{1,64}'));
807 $m->connect(':nickname/avatar/:size',
808 array('action' => 'avatarbynickname'),
809 array('size' => '(original|96|48|24)',
810 'nickname' => '[a-zA-Z0-9]{1,64}'));
812 $m->connect(':nickname/tag/:tag/rss',
813 array('action' => 'userrss'),
814 array('nickname' => '[a-zA-Z0-9]{1,64}'),
815 array('tag' => '[\pL\pN_\-\.]{1,64}'));
817 $m->connect(':nickname/tag/:tag',
818 array('action' => 'showstream'),
819 array('nickname' => '[a-zA-Z0-9]{1,64}'),
820 array('tag' => '[\pL\pN_\-\.]{1,64}'));
822 $m->connect(':nickname/rsd.xml',
823 array('action' => 'rsd'),
824 array('nickname' => '[a-zA-Z0-9]{1,64}'));
826 $m->connect(':nickname',
827 array('action' => 'showstream'),
828 array('nickname' => '[a-zA-Z0-9]{1,64}'));
833 Event::handle('RouterInitialized', array($m));
842 $match = $this->m->match($path);
843 } catch (Net_URL_Mapper_InvalidException $e) {
844 common_log(LOG_ERR, "Problem getting route for $path - " .
846 // TRANS: Client error on action trying to visit a non-existing page.
847 $cac = new ClientErrorAction(_('Page not found.'), 404);
854 function build($action, $args=null, $params=null, $fragment=null)
856 $action_arg = array('action' => $action);
859 $args = array_merge($action_arg, $args);
864 $url = $this->m->generate($args, $params, $fragment);
866 // Due to a bug in the Net_URL_Mapper code, the returned URL may
867 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
868 // repair that here rather than modifying the upstream code...
870 $qpos = strpos($url, '?');
871 if ($qpos !== false) {
872 $url = substr($url, 0, $qpos+1) .
873 str_replace('?', '&', substr($url, $qpos+1));
875 // @fixme this is a hacky workaround for http_build_query in the
876 // lower-level code and bad configs that set the default separator
877 // to & instead of &. Encoded &s in parameters will not be
879 $url = substr($url, 0, $qpos+1) .
880 str_replace('&', '&', substr($url, $qpos+1));