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;
40 private function __construct()
44 public static function getInstance($id = '__default__')
46 if (empty(self::$_singleton)) {
47 self::$_singleton = new StatusNet_URL_Mapper();
49 return self::$_singleton;
52 public function connect($path, $defaults = array(), $rules = array())
55 if (Event::handle('StartConnectPath', array(&$path, &$defaults, &$rules, &$result))) {
56 $result = parent::connect($path, $defaults, $rules);
57 Event::handle('EndConnectPath', array($path, $defaults, $rules, $result));
66 * Cheap wrapper around Net_URL_Mapper
70 * @author Evan Prodromou <evan@status.net>
71 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
72 * @link http://status.net/
79 static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
80 'postnotice', 'updateprofile', 'finishremotesubscribe');
85 Router::$inst = new Router();
90 function __construct()
93 $this->m = $this->initialize();
99 $m = StatusNet_URL_Mapper::getInstance();
101 if (Event::handle('StartInitializeRouter', array(&$m))) {
103 $m->connect('robots.txt', array('action' => 'robotstxt'));
105 $m->connect('opensearch/people', array('action' => 'opensearch',
106 'type' => 'people'));
107 $m->connect('opensearch/notice', array('action' => 'opensearch',
108 'type' => 'notice'));
112 $m->connect('doc/:title', array('action' => 'doc'));
114 $m->connect('main/otp/:user_id/:token',
115 array('action' => 'otp'),
116 array('user_id' => '[0-9]+',
119 // main stuff is repetitive
121 $main = array('login', 'logout', 'register', 'subscribe',
122 'unsubscribe', 'confirmaddress', 'recoverpassword',
123 'invite', 'favor', 'disfavor', 'sup',
124 'block', 'unblock', 'subedit',
125 'groupblock', 'groupunblock',
126 'sandbox', 'unsandbox',
127 'silence', 'unsilence',
128 'grantrole', 'revokerole',
135 foreach ($main as $a) {
136 $m->connect('main/'.$a, array('action' => $a));
139 // Also need a block variant accepting ID on URL for mail links
140 $m->connect('main/block/:profileid',
141 array('action' => 'block'),
142 array('profileid' => '[0-9]+'));
144 $m->connect('main/sup/:seconds', array('action' => 'sup'),
145 array('seconds' => '[0-9]+'));
147 $m->connect('main/tagother/:id', array('action' => 'tagother'));
149 $m->connect('main/oembed',
150 array('action' => 'oembed'));
152 $m->connect('main/xrds',
153 array('action' => 'publicxrds'));
157 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
158 $m->connect('main/'.$c.'/:code', array('action' => $c));
163 $m->connect('main/remote', array('action' => 'remotesubscribe'));
164 $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
166 foreach (Router::$bare as $action) {
167 $m->connect('index.php?action=' . $action, array('action' => $action));
172 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
173 'oauthapps', 'email', 'sms', 'userdesign', 'other') as $s) {
174 $m->connect('settings/'.$s, array('action' => $s.'settings'));
177 $m->connect('settings/oauthapps/show/:id',
178 array('action' => 'showapplication'),
179 array('id' => '[0-9]+')
181 $m->connect('settings/oauthapps/new',
182 array('action' => 'newapplication')
184 $m->connect('settings/oauthapps/edit/:id',
185 array('action' => 'editapplication'),
186 array('id' => '[0-9]+')
188 $m->connect('settings/oauthapps/delete/:id',
189 array('action' => 'deleteapplication'),
190 array('id' => '[0-9]+')
195 foreach (array('group', 'people', 'notice') as $s) {
196 $m->connect('search/'.$s, array('action' => $s.'search'));
197 $m->connect('search/'.$s.'?q=:q',
198 array('action' => $s.'search'),
202 // The second of these is needed to make the link work correctly
203 // when inserted into the page. The first is needed to match the
204 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
205 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
206 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
209 $m->connect('attachment/:attachment',
210 array('action' => 'attachment'),
211 array('attachment' => '[0-9]+'));
213 $m->connect('attachment/:attachment/ajax',
214 array('action' => 'attachment_ajax'),
215 array('attachment' => '[0-9]+'));
217 $m->connect('attachment/:attachment/thumbnail',
218 array('action' => 'attachment_thumbnail'),
219 array('attachment' => '[0-9]+'));
221 $m->connect('notice/new', array('action' => 'newnotice'));
222 $m->connect('notice/new?replyto=:replyto',
223 array('action' => 'newnotice'),
224 array('replyto' => '[A-Za-z0-9_-]+'));
225 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
226 array('action' => 'newnotice'),
227 array('replyto' => '[A-Za-z0-9_-]+'),
228 array('inreplyto' => '[0-9]+'));
230 $m->connect('notice/:notice/file',
231 array('action' => 'file'),
232 array('notice' => '[0-9]+'));
234 $m->connect('notice/:notice',
235 array('action' => 'shownotice'),
236 array('notice' => '[0-9]+'));
237 $m->connect('notice/delete', array('action' => 'deletenotice'));
238 $m->connect('notice/delete/:notice',
239 array('action' => 'deletenotice'),
240 array('notice' => '[0-9]+'));
242 $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
246 $m->connect('conversation/:id',
247 array('action' => 'conversation'),
248 array('id' => '[0-9]+'));
250 $m->connect('message/new', array('action' => 'newmessage'));
251 $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
252 $m->connect('message/:message',
253 array('action' => 'showmessage'),
254 array('message' => '[0-9]+'));
256 $m->connect('user/:id',
257 array('action' => 'userbyid'),
258 array('id' => '[0-9]+'));
260 $m->connect('tags/', array('action' => 'publictagcloud'));
261 $m->connect('tag/', array('action' => 'publictagcloud'));
262 $m->connect('tags', array('action' => 'publictagcloud'));
263 $m->connect('tag', array('action' => 'publictagcloud'));
264 $m->connect('tag/:tag/rss',
265 array('action' => 'tagrss'),
266 array('tag' => '[\pL\pN_\-\.]{1,64}'));
267 $m->connect('tag/:tag',
268 array('action' => 'tag'),
269 array('tag' => '[\pL\pN_\-\.]{1,64}'));
271 $m->connect('peopletag/:tag',
272 array('action' => 'peopletag'),
273 array('tag' => '[a-zA-Z0-9]+'));
277 $m->connect('group/new', array('action' => 'newgroup'));
279 foreach (array('edit', 'join', 'leave') as $v) {
280 $m->connect('group/:nickname/'.$v,
281 array('action' => $v.'group'),
282 array('nickname' => '[a-zA-Z0-9]+'));
283 $m->connect('group/:id/id/'.$v,
284 array('action' => $v.'group'),
285 array('id' => '[0-9]+'));
288 foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
289 $m->connect('group/:nickname/'.$n,
290 array('action' => 'group'.$n),
291 array('nickname' => '[a-zA-Z0-9]+'));
294 $m->connect('group/:nickname/foaf',
295 array('action' => 'foafgroup'),
296 array('nickname' => '[a-zA-Z0-9]+'));
298 $m->connect('group/:nickname/blocked',
299 array('action' => 'blockedfromgroup'),
300 array('nickname' => '[a-zA-Z0-9]+'));
302 $m->connect('group/:nickname/makeadmin',
303 array('action' => 'makeadmin'),
304 array('nickname' => '[a-zA-Z0-9]+'));
306 $m->connect('group/:id/id',
307 array('action' => 'groupbyid'),
308 array('id' => '[0-9]+'));
310 $m->connect('group/:nickname',
311 array('action' => 'showgroup'),
312 array('nickname' => '[a-zA-Z0-9]+'));
314 $m->connect('group/', array('action' => 'groups'));
315 $m->connect('group', array('action' => 'groups'));
316 $m->connect('groups/', array('action' => 'groups'));
317 $m->connect('groups', array('action' => 'groups'));
319 // Twitter-compatible API
323 $m->connect('api/statuses/public_timeline.:format',
324 array('action' => 'ApiTimelinePublic',
325 'format' => '(xml|json|rss|atom)'));
327 $m->connect('api/statuses/friends_timeline.:format',
328 array('action' => 'ApiTimelineFriends',
329 'format' => '(xml|json|rss|atom)'));
331 $m->connect('api/statuses/friends_timeline/:id.:format',
332 array('action' => 'ApiTimelineFriends',
333 'id' => '[a-zA-Z0-9]+',
334 'format' => '(xml|json|rss|atom)'));
336 $m->connect('api/statuses/home_timeline.:format',
337 array('action' => 'ApiTimelineHome',
338 'format' => '(xml|json|rss|atom)'));
340 $m->connect('api/statuses/home_timeline/:id.:format',
341 array('action' => 'ApiTimelineHome',
342 'id' => '[a-zA-Z0-9]+',
343 'format' => '(xml|json|rss|atom)'));
345 $m->connect('api/statuses/user_timeline.:format',
346 array('action' => 'ApiTimelineUser',
347 'format' => '(xml|json|rss|atom)'));
349 $m->connect('api/statuses/user_timeline/:id.:format',
350 array('action' => 'ApiTimelineUser',
351 'id' => '[a-zA-Z0-9]+',
352 'format' => '(xml|json|rss|atom)'));
354 $m->connect('api/statuses/mentions.:format',
355 array('action' => 'ApiTimelineMentions',
356 'format' => '(xml|json|rss|atom)'));
358 $m->connect('api/statuses/mentions/:id.:format',
359 array('action' => 'ApiTimelineMentions',
360 'id' => '[a-zA-Z0-9]+',
361 'format' => '(xml|json|rss|atom)'));
363 $m->connect('api/statuses/replies.:format',
364 array('action' => 'ApiTimelineMentions',
365 'format' => '(xml|json|rss|atom)'));
367 $m->connect('api/statuses/replies/:id.:format',
368 array('action' => 'ApiTimelineMentions',
369 'id' => '[a-zA-Z0-9]+',
370 'format' => '(xml|json|rss|atom)'));
372 $m->connect('api/statuses/retweeted_by_me.:format',
373 array('action' => 'ApiTimelineRetweetedByMe',
374 'format' => '(xml|json|atom)'));
376 $m->connect('api/statuses/retweeted_to_me.:format',
377 array('action' => 'ApiTimelineRetweetedToMe',
378 'format' => '(xml|json|atom)'));
380 $m->connect('api/statuses/retweets_of_me.:format',
381 array('action' => 'ApiTimelineRetweetsOfMe',
382 'format' => '(xml|json|atom)'));
384 $m->connect('api/statuses/friends.:format',
385 array('action' => 'ApiUserFriends',
386 'format' => '(xml|json)'));
388 $m->connect('api/statuses/friends/:id.:format',
389 array('action' => 'ApiUserFriends',
390 'id' => '[a-zA-Z0-9]+',
391 'format' => '(xml|json)'));
393 $m->connect('api/statuses/followers.:format',
394 array('action' => 'ApiUserFollowers',
395 'format' => '(xml|json)'));
397 $m->connect('api/statuses/followers/:id.:format',
398 array('action' => 'ApiUserFollowers',
399 'id' => '[a-zA-Z0-9]+',
400 'format' => '(xml|json)'));
402 $m->connect('api/statuses/show.:format',
403 array('action' => 'ApiStatusesShow',
404 'format' => '(xml|json)'));
406 $m->connect('api/statuses/show/:id.:format',
407 array('action' => 'ApiStatusesShow',
409 'format' => '(xml|json)'));
411 $m->connect('api/statuses/update.:format',
412 array('action' => 'ApiStatusesUpdate',
413 'format' => '(xml|json)'));
415 $m->connect('api/statuses/destroy.:format',
416 array('action' => 'ApiStatusesDestroy',
417 'format' => '(xml|json)'));
419 $m->connect('api/statuses/destroy/:id.:format',
420 array('action' => 'ApiStatusesDestroy',
422 'format' => '(xml|json)'));
424 $m->connect('api/statuses/retweet/:id.:format',
425 array('action' => 'ApiStatusesRetweet',
427 'format' => '(xml|json)'));
429 $m->connect('api/statuses/retweets/:id.:format',
430 array('action' => 'ApiStatusesRetweets',
432 'format' => '(xml|json)'));
436 $m->connect('api/users/show.:format',
437 array('action' => 'ApiUserShow',
438 'format' => '(xml|json)'));
440 $m->connect('api/users/show/:id.:format',
441 array('action' => 'ApiUserShow',
442 'id' => '[a-zA-Z0-9]+',
443 'format' => '(xml|json)'));
447 $m->connect('api/direct_messages.:format',
448 array('action' => 'ApiDirectMessage',
449 'format' => '(xml|json|rss|atom)'));
451 $m->connect('api/direct_messages/sent.:format',
452 array('action' => 'ApiDirectMessage',
453 'format' => '(xml|json|rss|atom)',
456 $m->connect('api/direct_messages/new.:format',
457 array('action' => 'ApiDirectMessageNew',
458 'format' => '(xml|json)'));
462 $m->connect('api/friendships/show.:format',
463 array('action' => 'ApiFriendshipsShow',
464 'format' => '(xml|json)'));
466 $m->connect('api/friendships/exists.:format',
467 array('action' => 'ApiFriendshipsExists',
468 'format' => '(xml|json)'));
470 $m->connect('api/friendships/create.:format',
471 array('action' => 'ApiFriendshipsCreate',
472 'format' => '(xml|json)'));
474 $m->connect('api/friendships/destroy.:format',
475 array('action' => 'ApiFriendshipsDestroy',
476 'format' => '(xml|json)'));
478 $m->connect('api/friendships/create/:id.:format',
479 array('action' => 'ApiFriendshipsCreate',
480 'id' => '[a-zA-Z0-9]+',
481 'format' => '(xml|json)'));
483 $m->connect('api/friendships/destroy/:id.:format',
484 array('action' => 'ApiFriendshipsDestroy',
485 'id' => '[a-zA-Z0-9]+',
486 'format' => '(xml|json)'));
490 $m->connect('api/friends/ids/:id.:format',
491 array('action' => 'apiuserfriends',
492 'ids_only' => true));
494 $m->connect('api/followers/ids/:id.:format',
495 array('action' => 'apiuserfollowers',
496 'ids_only' => true));
498 $m->connect('api/friends/ids.:format',
499 array('action' => 'apiuserfriends',
500 'ids_only' => true));
502 $m->connect('api/followers/ids.:format',
503 array('action' => 'apiuserfollowers',
504 'ids_only' => true));
508 $m->connect('api/account/verify_credentials.:format',
509 array('action' => 'ApiAccountVerifyCredentials'));
511 $m->connect('api/account/update_profile.:format',
512 array('action' => 'ApiAccountUpdateProfile'));
514 $m->connect('api/account/update_profile_image.:format',
515 array('action' => 'ApiAccountUpdateProfileImage'));
517 $m->connect('api/account/update_profile_background_image.:format',
518 array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
520 $m->connect('api/account/update_profile_colors.:format',
521 array('action' => 'ApiAccountUpdateProfileColors'));
523 $m->connect('api/account/update_delivery_device.:format',
524 array('action' => 'ApiAccountUpdateDeliveryDevice'));
526 // special case where verify_credentials is called w/out a format
528 $m->connect('api/account/verify_credentials',
529 array('action' => 'ApiAccountVerifyCredentials'));
531 $m->connect('api/account/rate_limit_status.:format',
532 array('action' => 'ApiAccountRateLimitStatus'));
536 $m->connect('api/favorites.:format',
537 array('action' => 'ApiTimelineFavorites',
538 'format' => '(xml|json|rss|atom)'));
540 $m->connect('api/favorites/:id.:format',
541 array('action' => 'ApiTimelineFavorites',
542 'id' => '[a-zA-Z0-9]+',
543 'format' => '(xml|json|rss|atom)'));
545 $m->connect('api/favorites/create/:id.:format',
546 array('action' => 'ApiFavoriteCreate',
547 'id' => '[a-zA-Z0-9]+',
548 'format' => '(xml|json)'));
550 $m->connect('api/favorites/destroy/:id.:format',
551 array('action' => 'ApiFavoriteDestroy',
552 'id' => '[a-zA-Z0-9]+',
553 'format' => '(xml|json)'));
556 $m->connect('api/blocks/create/:id.:format',
557 array('action' => 'ApiBlockCreate',
558 'id' => '[a-zA-Z0-9]+',
559 'format' => '(xml|json)'));
561 $m->connect('api/blocks/destroy/:id.:format',
562 array('action' => 'ApiBlockDestroy',
563 'id' => '[a-zA-Z0-9]+',
564 'format' => '(xml|json)'));
567 $m->connect('api/help/test.:format',
568 array('action' => 'ApiHelpTest',
569 'format' => '(xml|json)'));
573 $m->connect('api/statusnet/version.:format',
574 array('action' => 'ApiStatusnetVersion',
575 'format' => '(xml|json)'));
577 $m->connect('api/statusnet/config.:format',
578 array('action' => 'ApiStatusnetConfig',
579 'format' => '(xml|json)'));
581 // For older methods, we provide "laconica" base action
583 $m->connect('api/laconica/version.:format',
584 array('action' => 'ApiStatusnetVersion',
585 'format' => '(xml|json)'));
587 $m->connect('api/laconica/config.:format',
588 array('action' => 'ApiStatusnetConfig',
589 'format' => '(xml|json)'));
591 // Groups and tags are newer than 0.8.1 so no backward-compatibility
595 //'list' has to be handled differently, as php will not allow a method to be named 'list'
597 $m->connect('api/statusnet/groups/timeline/:id.:format',
598 array('action' => 'ApiTimelineGroup',
599 'id' => '[a-zA-Z0-9]+',
600 'format' => '(xml|json|rss|atom)'));
602 $m->connect('api/statusnet/groups/show.:format',
603 array('action' => 'ApiGroupShow',
604 'format' => '(xml|json)'));
606 $m->connect('api/statusnet/groups/show/:id.:format',
607 array('action' => 'ApiGroupShow',
608 'id' => '[a-zA-Z0-9]+',
609 'format' => '(xml|json)'));
611 $m->connect('api/statusnet/groups/join.:format',
612 array('action' => 'ApiGroupJoin',
613 'id' => '[a-zA-Z0-9]+',
614 'format' => '(xml|json)'));
616 $m->connect('api/statusnet/groups/join/:id.:format',
617 array('action' => 'ApiGroupJoin',
618 'format' => '(xml|json)'));
620 $m->connect('api/statusnet/groups/leave.:format',
621 array('action' => 'ApiGroupLeave',
622 'id' => '[a-zA-Z0-9]+',
623 'format' => '(xml|json)'));
625 $m->connect('api/statusnet/groups/leave/:id.:format',
626 array('action' => 'ApiGroupLeave',
627 'format' => '(xml|json)'));
629 $m->connect('api/statusnet/groups/is_member.:format',
630 array('action' => 'ApiGroupIsMember',
631 'format' => '(xml|json)'));
633 $m->connect('api/statusnet/groups/list.:format',
634 array('action' => 'ApiGroupList',
635 'format' => '(xml|json|rss|atom)'));
637 $m->connect('api/statusnet/groups/list/:id.:format',
638 array('action' => 'ApiGroupList',
639 'id' => '[a-zA-Z0-9]+',
640 'format' => '(xml|json|rss|atom)'));
642 $m->connect('api/statusnet/groups/list_all.:format',
643 array('action' => 'ApiGroupListAll',
644 'format' => '(xml|json|rss|atom)'));
646 $m->connect('api/statusnet/groups/membership.:format',
647 array('action' => 'ApiGroupMembership',
648 'format' => '(xml|json)'));
650 $m->connect('api/statusnet/groups/membership/:id.:format',
651 array('action' => 'ApiGroupMembership',
652 'id' => '[a-zA-Z0-9]+',
653 'format' => '(xml|json)'));
655 $m->connect('api/statusnet/groups/create.:format',
656 array('action' => 'ApiGroupCreate',
657 'format' => '(xml|json)'));
659 $m->connect('api/statusnet/tags/timeline/:tag.:format',
660 array('action' => 'ApiTimelineTag',
661 'format' => '(xml|json|rss|atom)'));
665 'api/statusnet/media/upload',
666 array('action' => 'ApiMediaUpload')
670 $m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
671 $m->connect('api/search.json', array('action' => 'twitapisearchjson'));
672 $m->connect('api/trends.json', array('action' => 'twitapitrends'));
674 $m->connect('api/oauth/request_token',
675 array('action' => 'apioauthrequesttoken'));
677 $m->connect('api/oauth/access_token',
678 array('action' => 'apioauthaccesstoken'));
680 $m->connect('api/oauth/authorize',
681 array('action' => 'apioauthauthorize'));
685 $m->connect('admin/site', array('action' => 'siteadminpanel'));
686 $m->connect('admin/design', array('action' => 'designadminpanel'));
687 $m->connect('admin/user', array('action' => 'useradminpanel'));
688 $m->connect('admin/access', array('action' => 'accessadminpanel'));
689 $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
690 $m->connect('admin/sessions', array('action' => 'sessionsadminpanel'));
691 $m->connect('admin/sitenotice', array('action' => 'sitenoticeadminpanel'));
692 $m->connect('admin/snapshot', array('action' => 'snapshotadminpanel'));
694 $m->connect('getfile/:filename',
695 array('action' => 'getfile'),
696 array('filename' => '[A-Za-z0-9._-]+'));
700 if (common_config('singleuser', 'enabled')) {
702 $user = User::siteOwner();
705 $nickname = $user->nickname;
707 $nickname = common_config('singleuser', 'nickname');
708 if (empty($nickname)) {
709 throw new ServerException(_("No single user defined for single-user mode."));
713 foreach (array('subscriptions', 'subscribers',
714 'all', 'foaf', 'xrds',
715 'replies', 'microsummary', 'hcard') as $a) {
717 array('action' => $a,
718 'nickname' => $nickname));
721 foreach (array('subscriptions', 'subscribers') as $a) {
722 $m->connect($a.'/:tag',
723 array('action' => $a,
724 'nickname' => $nickname),
725 array('tag' => '[a-zA-Z0-9]+'));
728 foreach (array('rss', 'groups') as $a) {
730 array('action' => 'user'.$a,
731 'nickname' => $nickname));
734 foreach (array('all', 'replies', 'favorites') as $a) {
735 $m->connect($a.'/rss',
736 array('action' => $a.'rss',
737 'nickname' => $nickname));
740 $m->connect('favorites',
741 array('action' => 'showfavorites',
742 'nickname' => $nickname));
744 $m->connect('avatar/:size',
745 array('action' => 'avatarbynickname',
746 'nickname' => $nickname),
747 array('size' => '(original|96|48|24)'));
749 $m->connect('tag/:tag/rss',
750 array('action' => 'userrss',
751 'nickname' => $nickname),
752 array('tag' => '[\pL\pN_\-\.]{1,64}'));
754 $m->connect('tag/:tag',
755 array('action' => 'showstream',
756 'nickname' => $nickname),
757 array('tag' => '[\pL\pN_\-\.]{1,64}'));
759 $m->connect('rsd.xml',
760 array('action' => 'rsd',
761 'nickname' => $nickname));
764 array('action' => 'showstream',
765 'nickname' => $nickname));
769 $m->connect('', array('action' => 'public'));
770 $m->connect('rss', array('action' => 'publicrss'));
771 $m->connect('featuredrss', array('action' => 'featuredrss'));
772 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
773 $m->connect('featured/', array('action' => 'featured'));
774 $m->connect('featured', array('action' => 'featured'));
775 $m->connect('favorited/', array('action' => 'favorited'));
776 $m->connect('favorited', array('action' => 'favorited'));
777 $m->connect('rsd.xml', array('action' => 'rsd'));
779 foreach (array('subscriptions', 'subscribers',
780 'nudge', 'all', 'foaf', 'xrds',
781 'replies', 'inbox', 'outbox', 'microsummary', 'hcard') as $a) {
782 $m->connect(':nickname/'.$a,
783 array('action' => $a),
784 array('nickname' => '[a-zA-Z0-9]{1,64}'));
787 foreach (array('subscriptions', 'subscribers') as $a) {
788 $m->connect(':nickname/'.$a.'/:tag',
789 array('action' => $a),
790 array('tag' => '[a-zA-Z0-9]+',
791 'nickname' => '[a-zA-Z0-9]{1,64}'));
794 foreach (array('rss', 'groups') as $a) {
795 $m->connect(':nickname/'.$a,
796 array('action' => 'user'.$a),
797 array('nickname' => '[a-zA-Z0-9]{1,64}'));
800 foreach (array('all', 'replies', 'favorites') as $a) {
801 $m->connect(':nickname/'.$a.'/rss',
802 array('action' => $a.'rss'),
803 array('nickname' => '[a-zA-Z0-9]{1,64}'));
806 $m->connect(':nickname/favorites',
807 array('action' => 'showfavorites'),
808 array('nickname' => '[a-zA-Z0-9]{1,64}'));
810 $m->connect(':nickname/avatar/:size',
811 array('action' => 'avatarbynickname'),
812 array('size' => '(original|96|48|24)',
813 'nickname' => '[a-zA-Z0-9]{1,64}'));
815 $m->connect(':nickname/tag/:tag/rss',
816 array('action' => 'userrss'),
817 array('nickname' => '[a-zA-Z0-9]{1,64}'),
818 array('tag' => '[\pL\pN_\-\.]{1,64}'));
820 $m->connect(':nickname/tag/:tag',
821 array('action' => 'showstream'),
822 array('nickname' => '[a-zA-Z0-9]{1,64}'),
823 array('tag' => '[\pL\pN_\-\.]{1,64}'));
825 $m->connect(':nickname/rsd.xml',
826 array('action' => 'rsd'),
827 array('nickname' => '[a-zA-Z0-9]{1,64}'));
829 $m->connect(':nickname',
830 array('action' => 'showstream'),
831 array('nickname' => '[a-zA-Z0-9]{1,64}'));
836 Event::handle('RouterInitialized', array($m));
845 $match = $this->m->match($path);
846 } catch (Net_URL_Mapper_InvalidException $e) {
847 common_log(LOG_ERR, "Problem getting route for $path - " .
849 $cac = new ClientErrorAction("Page not found.", 404);
856 function build($action, $args=null, $params=null, $fragment=null)
858 $action_arg = array('action' => $action);
861 $args = array_merge($action_arg, $args);
866 $url = $this->m->generate($args, $params, $fragment);
868 // Due to a bug in the Net_URL_Mapper code, the returned URL may
869 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
870 // repair that here rather than modifying the upstream code...
872 $qpos = strpos($url, '?');
873 if ($qpos !== false) {
874 $url = substr($url, 0, $qpos+1) .
875 str_replace('?', '&', substr($url, $qpos+1));