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('GNUSOCIAL')) { exit(1); }
35 * Cheap wrapper around Net_URL_Mapper
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
48 const REGEX_TAG = '[^\/]+'; // [\pL\pN_\-\.]{1,64} better if we can do unicode regexes
53 Router::$inst = new Router();
59 * Clear the global singleton instance for this class.
60 * Needed to ensure reset when switching site configurations.
62 static function clear()
67 function __construct()
69 if (empty($this->m)) {
70 $this->m = $this->initialize();
75 * Create a unique hashkey for the router.
77 * The router's url map can change based on the version of the software
78 * you're running and the plugins that are enabled. To avoid having bad routes
79 * get stuck in the cache, the key includes a list of plugins and the software
82 * There can still be problems with a) differences in versions of the plugins and
83 * b) people running code between official versions, but these tend to be more
84 * sophisticated users who can grok what's going on and clear their caches.
86 * @return string cache key string that should uniquely identify a router
89 static function cacheKey()
91 $parts = array('router');
93 // Many router paths depend on this setting.
94 if (common_config('singleuser', 'enabled')) {
100 return Cache::codeKey(implode(':', $parts));
103 function initialize()
105 $m = new URLMapper();
107 if (Event::handle('StartInitializeRouter', array(&$m))) {
109 // top of the menu hierarchy, sometimes "Home"
110 $m->connect('', array('action' => 'top'));
114 $m->connect('robots.txt', array('action' => 'robotstxt'));
116 $m->connect('opensearch/people', array('action' => 'opensearch',
117 'type' => 'people'));
118 $m->connect('opensearch/notice', array('action' => 'opensearch',
119 'type' => 'notice'));
123 $m->connect('doc/:title', array('action' => 'doc'));
125 $m->connect('main/otp/:user_id/:token',
126 array('action' => 'otp'),
127 array('user_id' => '[0-9]+',
130 // these take a code; before the main part
132 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
133 $m->connect('main/'.$c.'/:code', array('action' => $c));
136 // Also need a block variant accepting ID on URL for mail links
137 $m->connect('main/block/:profileid',
138 array('action' => 'block'),
139 array('profileid' => '[0-9]+'));
141 $m->connect('main/sup/:seconds', array('action' => 'sup'),
142 array('seconds' => '[0-9]+'));
144 // main stuff is repetitive
146 $main = array('login', 'logout', 'register', 'subscribe',
147 'unsubscribe', 'cancelsubscription', 'approvesub',
148 'confirmaddress', 'recoverpassword',
150 'block', 'unblock', 'subedit',
151 'groupblock', 'groupunblock',
152 'sandbox', 'unsandbox',
153 'silence', 'unsilence',
154 'grantrole', 'revokerole',
165 foreach ($main as $a) {
166 $m->connect('main/'.$a, array('action' => $a));
169 $m->connect('main/all', array('action' => 'networkpublic'));
171 $m->connect('main/tagprofile/:id', array('action' => 'tagprofile'),
172 array('id' => '[0-9]+'));
174 $m->connect('main/tagprofile', array('action' => 'tagprofile'));
176 $m->connect('main/xrds',
177 array('action' => 'publicxrds'));
181 foreach (array('profile', 'avatar', 'password', 'im', 'oauthconnections',
182 'oauthapps', 'email', 'sms', 'url') as $s) {
183 $m->connect('settings/'.$s, array('action' => $s.'settings'));
186 if (common_config('oldschool', 'enabled')) {
187 $m->connect('settings/oldschool', array('action' => 'oldschoolsettings'));
190 $m->connect('settings/oauthapps/show/:id',
191 array('action' => 'showapplication'),
192 array('id' => '[0-9]+')
194 $m->connect('settings/oauthapps/new',
195 array('action' => 'newapplication')
197 $m->connect('settings/oauthapps/edit/:id',
198 array('action' => 'editapplication'),
199 array('id' => '[0-9]+')
201 $m->connect('settings/oauthapps/delete/:id',
202 array('action' => 'deleteapplication'),
203 array('id' => '[0-9]+')
208 foreach (array('group', 'people', 'notice') as $s) {
209 $m->connect('search/'.$s.'?q=:q',
210 array('action' => $s.'search'),
212 $m->connect('search/'.$s, array('action' => $s.'search'));
215 // The second of these is needed to make the link work correctly
216 // when inserted into the page. The first is needed to match the
217 // route on the way in. Seems to be another Net_URL_Mapper bug to me.
218 $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
220 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
222 $m->connect('attachment/:attachment',
223 array('action' => 'attachment'),
224 array('attachment' => '[0-9]+'));
226 $m->connect('attachment/:attachment/download',
227 array('action' => 'attachment_download'),
228 array('attachment' => '[0-9]+'));
230 $m->connect('attachment/:attachment/thumbnail',
231 array('action' => 'attachment_thumbnail'),
232 array('attachment' => '[0-9]+'));
234 $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
235 array('action' => 'newnotice'),
236 array('replyto' => Nickname::DISPLAY_FMT),
237 array('inreplyto' => '[0-9]+'));
239 $m->connect('notice/new?replyto=:replyto',
240 array('action' => 'newnotice'),
241 array('replyto' => Nickname::DISPLAY_FMT));
243 $m->connect('notice/new', array('action' => 'newnotice'));
245 $m->connect('notice/:notice',
246 array('action' => 'shownotice'),
247 array('notice' => '[0-9]+'));
249 $m->connect('notice/:notice/delete',
250 array('action' => 'deletenotice'),
251 array('notice' => '[0-9]+'));
255 $m->connect('conversation/:id',
256 array('action' => 'conversation'),
257 array('id' => '[0-9]+'));
259 $m->connect('user/:id',
260 array('action' => 'userbyid'),
261 array('id' => '[0-9]+'));
263 if (!common_config('performance', 'high')) {
264 $m->connect('tags/', array('action' => 'publictagcloud'));
265 $m->connect('tag/', array('action' => 'publictagcloud'));
266 $m->connect('tags', array('action' => 'publictagcloud'));
267 $m->connect('tag', array('action' => 'publictagcloud'));
269 $m->connect('tag/:tag/rss',
270 array('action' => 'tagrss'),
271 array('tag' => self::REGEX_TAG));
272 $m->connect('tag/:tag',
273 array('action' => 'tag'),
274 array('tag' => self::REGEX_TAG));
278 $m->connect('group/new', array('action' => 'newgroup'));
280 foreach (array('edit', 'join', 'leave', 'delete', 'cancel', 'approve') as $v) {
281 $m->connect('group/:nickname/'.$v,
282 array('action' => $v.'group'),
283 array('nickname' => Nickname::DISPLAY_FMT));
284 $m->connect('group/:id/id/'.$v,
285 array('action' => $v.'group'),
286 array('id' => '[0-9]+'));
289 foreach (array('members', 'logo', 'rss') as $n) {
290 $m->connect('group/:nickname/'.$n,
291 array('action' => 'group'.$n),
292 array('nickname' => Nickname::DISPLAY_FMT));
295 $m->connect('group/:nickname/foaf',
296 array('action' => 'foafgroup'),
297 array('nickname' => Nickname::DISPLAY_FMT));
299 $m->connect('group/:nickname/blocked',
300 array('action' => 'blockedfromgroup'),
301 array('nickname' => Nickname::DISPLAY_FMT));
303 $m->connect('group/:nickname/makeadmin',
304 array('action' => 'makeadmin'),
305 array('nickname' => Nickname::DISPLAY_FMT));
307 $m->connect('group/:nickname/members/pending',
308 array('action' => 'groupqueue'),
309 array('nickname' => Nickname::DISPLAY_FMT));
311 $m->connect('group/:id/id',
312 array('action' => 'groupbyid'),
313 array('id' => '[0-9]+'));
315 $m->connect('group/:nickname',
316 array('action' => 'showgroup'),
317 array('nickname' => Nickname::DISPLAY_FMT));
319 $m->connect('group/:nickname/',
320 array('action' => 'showgroup'),
321 array('nickname' => Nickname::DISPLAY_FMT));
323 $m->connect('group/', array('action' => 'groups'));
324 $m->connect('group', array('action' => 'groups'));
325 $m->connect('groups/', array('action' => 'groups'));
326 $m->connect('groups', array('action' => 'groups'));
328 // Twitter-compatible API
333 array('action' => 'Redirect',
334 'nextAction' => 'doc',
335 'args' => array('title' => 'api')));
337 $m->connect('api/statuses/public_timeline.:format',
338 array('action' => 'ApiTimelinePublic',
339 'format' => '(xml|json|rss|atom|as)'));
341 // this is not part of the Twitter API. Also may require authentication depending on server config!
342 $m->connect('api/statuses/networkpublic_timeline.:format',
343 array('action' => 'ApiTimelineNetworkPublic',
344 'format' => '(xml|json|rss|atom|as)'));
346 $m->connect('api/statuses/friends_timeline/:id.:format',
347 array('action' => 'ApiTimelineFriends',
348 'id' => Nickname::INPUT_FMT,
349 'format' => '(xml|json|rss|atom|as)'));
351 $m->connect('api/statuses/friends_timeline.:format',
352 array('action' => 'ApiTimelineFriends',
353 'format' => '(xml|json|rss|atom|as)'));
355 $m->connect('api/statuses/home_timeline/:id.:format',
356 array('action' => 'ApiTimelineHome',
357 'id' => Nickname::INPUT_FMT,
358 'format' => '(xml|json|rss|atom|as)'));
360 $m->connect('api/statuses/home_timeline.:format',
361 array('action' => 'ApiTimelineHome',
362 'format' => '(xml|json|rss|atom|as)'));
364 $m->connect('api/statuses/user_timeline/:id.:format',
365 array('action' => 'ApiTimelineUser',
366 'id' => Nickname::INPUT_FMT,
367 'format' => '(xml|json|rss|atom|as)'));
369 $m->connect('api/statuses/user_timeline.:format',
370 array('action' => 'ApiTimelineUser',
371 'format' => '(xml|json|rss|atom|as)'));
373 $m->connect('api/statuses/mentions/:id.:format',
374 array('action' => 'ApiTimelineMentions',
375 'id' => Nickname::INPUT_FMT,
376 'format' => '(xml|json|rss|atom|as)'));
378 $m->connect('api/statuses/mentions.:format',
379 array('action' => 'ApiTimelineMentions',
380 'format' => '(xml|json|rss|atom|as)'));
382 $m->connect('api/statuses/replies/:id.:format',
383 array('action' => 'ApiTimelineMentions',
384 'id' => Nickname::INPUT_FMT,
385 'format' => '(xml|json|rss|atom|as)'));
387 $m->connect('api/statuses/replies.:format',
388 array('action' => 'ApiTimelineMentions',
389 'format' => '(xml|json|rss|atom|as)'));
391 $m->connect('api/statuses/mentions_timeline/:id.:format',
392 array('action' => 'ApiTimelineMentions',
393 'id' => Nickname::INPUT_FMT,
394 'format' => '(xml|json|rss|atom|as)'));
396 $m->connect('api/statuses/mentions_timeline.:format',
397 array('action' => 'ApiTimelineMentions',
398 'format' => '(xml|json|rss|atom|as)'));
400 $m->connect('api/statuses/friends/:id.:format',
401 array('action' => 'ApiUserFriends',
402 'id' => Nickname::INPUT_FMT,
403 'format' => '(xml|json)'));
405 $m->connect('api/statuses/friends.:format',
406 array('action' => 'ApiUserFriends',
407 'format' => '(xml|json)'));
409 $m->connect('api/statuses/followers/:id.:format',
410 array('action' => 'ApiUserFollowers',
411 'id' => Nickname::INPUT_FMT,
412 'format' => '(xml|json)'));
414 $m->connect('api/statuses/followers.:format',
415 array('action' => 'ApiUserFollowers',
416 'format' => '(xml|json)'));
418 $m->connect('api/statuses/show/:id.:format',
419 array('action' => 'ApiStatusesShow',
421 'format' => '(xml|json|atom)'));
423 $m->connect('api/statuses/show.:format',
424 array('action' => 'ApiStatusesShow',
425 'format' => '(xml|json|atom)'));
427 $m->connect('api/statuses/update.:format',
428 array('action' => 'ApiStatusesUpdate',
429 'format' => '(xml|json)'));
431 $m->connect('api/statuses/destroy/:id.:format',
432 array('action' => 'ApiStatusesDestroy',
434 'format' => '(xml|json)'));
436 $m->connect('api/statuses/destroy.:format',
437 array('action' => 'ApiStatusesDestroy',
438 'format' => '(xml|json)'));
440 // START qvitter API additions
442 $m->connect('api/attachment/:id.:format',
443 array('action' => 'ApiAttachment',
445 'format' => '(xml|json)'));
447 $m->connect('api/checkhub.:format',
448 array('action' => 'ApiCheckHub',
449 'format' => '(xml|json)'));
451 $m->connect('api/externalprofile/show.:format',
452 array('action' => 'ApiExternalProfileShow',
453 'format' => '(xml|json)'));
455 $m->connect('api/statusnet/groups/admins/:id.:format',
456 array('action' => 'ApiGroupAdmins',
457 'id' => Nickname::INPUT_FMT,
458 'format' => '(xml|json)'));
460 $m->connect('api/account/update_link_color.:format',
461 array('action' => 'ApiAccountUpdateLinkColor',
462 'format' => '(xml|json)'));
464 $m->connect('api/account/update_background_color.:format',
465 array('action' => 'ApiAccountUpdateBackgroundColor',
466 'format' => '(xml|json)'));
468 $m->connect('api/account/register.:format',
469 array('action' => 'ApiAccountRegister',
470 'format' => '(xml|json)'));
472 $m->connect('api/check_nickname.:format',
473 array('action' => 'ApiCheckNickname',
474 'format' => '(xml|json)'));
476 // END qvitter API additions
480 $m->connect('api/users/show/:id.:format',
481 array('action' => 'ApiUserShow',
482 'id' => Nickname::INPUT_FMT,
483 'format' => '(xml|json)'));
485 $m->connect('api/users/show.:format',
486 array('action' => 'ApiUserShow',
487 'format' => '(xml|json)'));
489 $m->connect('api/users/profile_image/:screen_name.:format',
490 array('action' => 'ApiUserProfileImage',
491 'screen_name' => Nickname::DISPLAY_FMT,
492 'format' => '(xml|json)'));
496 $m->connect('api/friendships/show.:format',
497 array('action' => 'ApiFriendshipsShow',
498 'format' => '(xml|json)'));
500 $m->connect('api/friendships/exists.:format',
501 array('action' => 'ApiFriendshipsExists',
502 'format' => '(xml|json)'));
504 $m->connect('api/friendships/create/:id.:format',
505 array('action' => 'ApiFriendshipsCreate',
506 'id' => Nickname::INPUT_FMT,
507 'format' => '(xml|json)'));
509 $m->connect('api/friendships/create.:format',
510 array('action' => 'ApiFriendshipsCreate',
511 'format' => '(xml|json)'));
513 $m->connect('api/friendships/destroy/:id.:format',
514 array('action' => 'ApiFriendshipsDestroy',
515 'id' => Nickname::INPUT_FMT,
516 'format' => '(xml|json)'));
518 $m->connect('api/friendships/destroy.:format',
519 array('action' => 'ApiFriendshipsDestroy',
520 'format' => '(xml|json)'));
524 $m->connect('api/friends/ids/:id.:format',
525 array('action' => 'ApiUserFriends',
526 'ids_only' => true));
528 $m->connect('api/followers/ids/:id.:format',
529 array('action' => 'ApiUserFollowers',
530 'ids_only' => true));
532 $m->connect('api/friends/ids.:format',
533 array('action' => 'ApiUserFriends',
534 'ids_only' => true));
536 $m->connect('api/followers/ids.:format',
537 array('action' => 'ApiUserFollowers',
538 'ids_only' => true));
542 $m->connect('api/account/verify_credentials.:format',
543 array('action' => 'ApiAccountVerifyCredentials'));
545 $m->connect('api/account/update_profile.:format',
546 array('action' => 'ApiAccountUpdateProfile'));
548 $m->connect('api/account/update_profile_image.:format',
549 array('action' => 'ApiAccountUpdateProfileImage'));
551 $m->connect('api/account/update_delivery_device.:format',
552 array('action' => 'ApiAccountUpdateDeliveryDevice'));
554 // special case where verify_credentials is called w/out a format
556 $m->connect('api/account/verify_credentials',
557 array('action' => 'ApiAccountVerifyCredentials'));
559 $m->connect('api/account/rate_limit_status.:format',
560 array('action' => 'ApiAccountRateLimitStatus'));
564 $m->connect('api/blocks/create/:id.:format',
565 array('action' => 'ApiBlockCreate',
566 'id' => Nickname::INPUT_FMT,
567 'format' => '(xml|json)'));
569 $m->connect('api/blocks/create.:format',
570 array('action' => 'ApiBlockCreate',
571 'format' => '(xml|json)'));
573 $m->connect('api/blocks/destroy/:id.:format',
574 array('action' => 'ApiBlockDestroy',
575 'id' => Nickname::INPUT_FMT,
576 'format' => '(xml|json)'));
578 $m->connect('api/blocks/destroy.:format',
579 array('action' => 'ApiBlockDestroy',
580 'format' => '(xml|json)'));
584 $m->connect('api/help/test.:format',
585 array('action' => 'ApiHelpTest',
586 'format' => '(xml|json)'));
590 $m->connect('api/statusnet/version.:format',
591 array('action' => 'ApiGNUsocialVersion',
592 'format' => '(xml|json)'));
594 $m->connect('api/statusnet/config.:format',
595 array('action' => 'ApiGNUsocialConfig',
596 'format' => '(xml|json)'));
598 // For our current software name, we provide "gnusocial" base action
600 $m->connect('api/gnusocial/version.:format',
601 array('action' => 'ApiGNUsocialVersion',
602 'format' => '(xml|json)'));
604 $m->connect('api/gnusocial/config.:format',
605 array('action' => 'ApiGNUsocialConfig',
606 'format' => '(xml|json)'));
608 // Groups and tags are newer than 0.8.1 so no backward-compatibility
612 //'list' has to be handled differently, as php will not allow a method to be named 'list'
614 $m->connect('api/statusnet/groups/timeline/:id.:format',
615 array('action' => 'ApiTimelineGroup',
616 'id' => Nickname::INPUT_FMT,
617 'format' => '(xml|json|rss|atom|as)'));
619 $m->connect('api/statusnet/groups/show/:id.:format',
620 array('action' => 'ApiGroupShow',
621 'id' => Nickname::INPUT_FMT,
622 'format' => '(xml|json)'));
624 $m->connect('api/statusnet/groups/show.:format',
625 array('action' => 'ApiGroupShow',
626 'format' => '(xml|json)'));
628 $m->connect('api/statusnet/groups/join/:id.:format',
629 array('action' => 'ApiGroupJoin',
630 'id' => Nickname::INPUT_FMT,
631 'format' => '(xml|json)'));
633 $m->connect('api/statusnet/groups/join.:format',
634 array('action' => 'ApiGroupJoin',
635 'format' => '(xml|json)'));
637 $m->connect('api/statusnet/groups/leave/:id.:format',
638 array('action' => 'ApiGroupLeave',
639 'format' => '(xml|json)'));
641 $m->connect('api/statusnet/groups/leave.:format',
642 array('action' => 'ApiGroupLeave',
643 'id' => Nickname::INPUT_FMT,
644 'format' => '(xml|json)'));
646 $m->connect('api/statusnet/groups/is_member.:format',
647 array('action' => 'ApiGroupIsMember',
648 'format' => '(xml|json)'));
650 $m->connect('api/statusnet/groups/list/:id.:format',
651 array('action' => 'ApiGroupList',
652 'id' => Nickname::INPUT_FMT,
653 'format' => '(xml|json|rss|atom)'));
655 $m->connect('api/statusnet/groups/list.:format',
656 array('action' => 'ApiGroupList',
657 'format' => '(xml|json|rss|atom)'));
659 $m->connect('api/statusnet/groups/list_all.:format',
660 array('action' => 'ApiGroupListAll',
661 'format' => '(xml|json|rss|atom)'));
663 $m->connect('api/statusnet/groups/membership/:id.:format',
664 array('action' => 'ApiGroupMembership',
665 'id' => Nickname::INPUT_FMT,
666 'format' => '(xml|json)'));
668 $m->connect('api/statusnet/groups/membership.:format',
669 array('action' => 'ApiGroupMembership',
670 'format' => '(xml|json)'));
672 $m->connect('api/statusnet/groups/create.:format',
673 array('action' => 'ApiGroupCreate',
674 'format' => '(xml|json)'));
676 $m->connect('api/statusnet/groups/update/:id.:format',
677 array('action' => 'ApiGroupProfileUpdate',
678 'id' => '[a-zA-Z0-9]+',
679 'format' => '(xml|json)'));
681 $m->connect('api/statusnet/conversation/:id.:format',
682 array('action' => 'apiconversation',
684 'format' => '(xml|json|rss|atom|as)'));
686 // Lists (people tags)
687 $m->connect('api/lists/list.:format',
688 array('action' => 'ApiListSubscriptions',
689 'format' => '(xml|json)'));
691 $m->connect('api/lists/memberships.:format',
692 array('action' => 'ApiListMemberships',
693 'format' => '(xml|json)'));
695 $m->connect('api/:user/lists/memberships.:format',
696 array('action' => 'ApiListMemberships',
697 'user' => '[a-zA-Z0-9]+',
698 'format' => '(xml|json)'));
700 $m->connect('api/lists/subscriptions.:format',
701 array('action' => 'ApiListSubscriptions',
702 'format' => '(xml|json)'));
704 $m->connect('api/:user/lists/subscriptions.:format',
705 array('action' => 'ApiListSubscriptions',
706 'user' => '[a-zA-Z0-9]+',
707 'format' => '(xml|json)'));
709 $m->connect('api/lists.:format',
710 array('action' => 'ApiLists',
711 'format' => '(xml|json)'));
713 $m->connect('api/:user/lists/:id.:format',
714 array('action' => 'ApiList',
715 'user' => '[a-zA-Z0-9]+',
716 'id' => '[a-zA-Z0-9]+',
717 'format' => '(xml|json)'));
719 $m->connect('api/:user/lists.:format',
720 array('action' => 'ApiLists',
721 'user' => '[a-zA-Z0-9]+',
722 'format' => '(xml|json)'));
724 $m->connect('api/:user/lists/:id/statuses.:format',
725 array('action' => 'ApiTimelineList',
726 'user' => '[a-zA-Z0-9]+',
727 'id' => '[a-zA-Z0-9]+',
728 'format' => '(xml|json|rss|atom)'));
730 $m->connect('api/:user/:list_id/members/:id.:format',
731 array('action' => 'ApiListMember',
732 'user' => '[a-zA-Z0-9]+',
733 'list_id' => '[a-zA-Z0-9]+',
734 'id' => '[a-zA-Z0-9]+',
735 'format' => '(xml|json)'));
737 $m->connect('api/:user/:list_id/members.:format',
738 array('action' => 'ApiListMembers',
739 'user' => '[a-zA-Z0-9]+',
740 'list_id' => '[a-zA-Z0-9]+',
741 'format' => '(xml|json)'));
743 $m->connect('api/:user/:list_id/subscribers/:id.:format',
744 array('action' => 'ApiListSubscriber',
745 'user' => '[a-zA-Z0-9]+',
746 'list_id' => '[a-zA-Z0-9]+',
747 'id' => '[a-zA-Z0-9]+',
748 'format' => '(xml|json)'));
750 $m->connect('api/:user/:list_id/subscribers.:format',
751 array('action' => 'ApiListSubscribers',
752 'user' => '[a-zA-Z0-9]+',
753 'list_id' => '[a-zA-Z0-9]+',
754 'format' => '(xml|json)'));
757 $m->connect('api/statusnet/tags/timeline/:tag.:format',
758 array('action' => 'ApiTimelineTag',
759 'tag' => self::REGEX_TAG,
760 'format' => '(xml|json|rss|atom|as)'));
764 'api/statusnet/media/upload',
765 array('action' => 'ApiMediaUpload')
768 'api/statuses/update_with_media.json',
769 array('action' => 'ApiMediaUpload')
771 // Twitter Media upload API v1.1
773 'api/media/upload.:format',
774 array('action' => 'ApiMediaUpload',
775 'format' => '(xml|json)',
780 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
781 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
782 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
784 $m->connect('api/oauth/request_token',
785 array('action' => 'ApiOAuthRequestToken'));
787 $m->connect('api/oauth/access_token',
788 array('action' => 'ApiOAuthAccessToken'));
790 $m->connect('api/oauth/authorize',
791 array('action' => 'ApiOAuthAuthorize'));
795 $m->connect('panel/site', array('action' => 'siteadminpanel'));
796 $m->connect('panel/user', array('action' => 'useradminpanel'));
797 $m->connect('panel/access', array('action' => 'accessadminpanel'));
798 $m->connect('panel/paths', array('action' => 'pathsadminpanel'));
799 $m->connect('panel/sessions', array('action' => 'sessionsadminpanel'));
800 $m->connect('panel/sitenotice', array('action' => 'sitenoticeadminpanel'));
801 $m->connect('panel/license', array('action' => 'licenseadminpanel'));
803 $m->connect('panel/plugins', array('action' => 'pluginsadminpanel'));
804 $m->connect('panel/plugins/enable/:plugin',
805 array('action' => 'pluginenable'),
806 array('plugin' => '[A-Za-z0-9_]+'));
807 $m->connect('panel/plugins/disable/:plugin',
808 array('action' => 'plugindisable'),
809 array('plugin' => '[A-Za-z0-9_]+'));
811 $m->connect('getfile/:filename',
812 array('action' => 'getfile'),
813 array('filename' => '[A-Za-z0-9._-]+'));
815 // Common people-tag stuff
817 $m->connect('peopletag/:tag', array('action' => 'peopletag',
818 'tag' => self::REGEX_TAG));
820 $m->connect('selftag/:tag', array('action' => 'selftag',
821 'tag' => self::REGEX_TAG));
823 $m->connect('main/addpeopletag', array('action' => 'addpeopletag'));
825 $m->connect('main/removepeopletag', array('action' => 'removepeopletag'));
827 $m->connect('main/profilecompletion', array('action' => 'profilecompletion'));
829 $m->connect('main/peopletagautocomplete', array('action' => 'peopletagautocomplete'));
833 if (common_config('singleuser', 'enabled')) {
835 $nickname = User::singleUserNickname();
837 foreach (array('subscriptions', 'subscribers',
838 'all', 'foaf', 'replies',
841 array('action' => $a,
842 'nickname' => $nickname));
845 foreach (array('subscriptions', 'subscribers') as $a) {
846 $m->connect($a.'/:tag',
847 array('action' => $a,
848 'nickname' => $nickname),
849 array('tag' => self::REGEX_TAG));
852 $m->connect('subscribers/pending',
853 array('action' => 'subqueue',
854 'nickname' => $nickname));
856 foreach (array('rss', 'groups') as $a) {
858 array('action' => 'user'.$a,
859 'nickname' => $nickname));
862 foreach (array('all', 'replies') as $a) {
863 $m->connect($a.'/rss',
864 array('action' => $a.'rss',
865 'nickname' => $nickname));
868 $m->connect('avatar',
869 array('action' => 'avatarbynickname',
870 'nickname' => $nickname));
871 $m->connect('avatar/:size',
872 array('action' => 'avatarbynickname',
873 'nickname' => $nickname),
874 array('size' => '(|original|\d+)'));
876 $m->connect('tag/:tag/rss',
877 array('action' => 'userrss',
878 'nickname' => $nickname),
879 array('tag' => self::REGEX_TAG));
881 $m->connect('tag/:tag',
882 array('action' => 'showstream',
883 'nickname' => $nickname),
884 array('tag' => self::REGEX_TAG));
886 $m->connect('rsd.xml',
887 array('action' => 'rsd',
888 'nickname' => $nickname));
892 $m->connect('peopletags',
893 array('action' => 'peopletagsbyuser'));
895 $m->connect('peopletags/private',
896 array('action' => 'peopletagsbyuser',
899 $m->connect('peopletags/public',
900 array('action' => 'peopletagsbyuser',
903 $m->connect('othertags',
904 array('action' => 'peopletagsforuser'));
906 $m->connect('peopletagsubscriptions',
907 array('action' => 'peopletagsubscriptions'));
909 $m->connect('all/:tag/subscribers',
910 array('action' => 'peopletagsubscribers',
911 'tag' => self::REGEX_TAG));
913 $m->connect('all/:tag/tagged',
914 array('action' => 'peopletagged',
915 'tag' => self::REGEX_TAG));
917 $m->connect('all/:tag/edit',
918 array('action' => 'editpeopletag',
919 'tag' => self::REGEX_TAG));
921 foreach(array('subscribe', 'unsubscribe') as $v) {
922 $m->connect('peopletag/:id/'.$v,
923 array('action' => $v.'peopletag',
924 'id' => '[0-9]{1,64}'));
926 $m->connect('user/:tagger_id/profiletag/:id/id',
927 array('action' => 'profiletagbyid',
928 'tagger_id' => '[0-9]+',
931 $m->connect('all/:tag',
932 array('action' => 'showprofiletag',
933 'nickname' => $nickname,
934 'tag' => self::REGEX_TAG));
936 foreach (array('subscriptions', 'subscribers') as $a) {
937 $m->connect($a.'/:tag',
938 array('action' => $a),
939 array('tag' => self::REGEX_TAG));
943 $m->connect('rss', array('action' => 'publicrss'));
944 $m->connect('featuredrss', array('action' => 'featuredrss'));
945 $m->connect('featured/', array('action' => 'featured'));
946 $m->connect('featured', array('action' => 'featured'));
947 $m->connect('rsd.xml', array('action' => 'rsd'));
949 foreach (array('subscriptions', 'subscribers',
950 'nudge', 'all', 'foaf', 'replies',
951 'inbox', 'outbox') as $a) {
952 $m->connect(':nickname/'.$a,
953 array('action' => $a),
954 array('nickname' => Nickname::DISPLAY_FMT));
956 $m->connect(':nickname/subscribers/pending',
957 array('action' => 'subqueue'),
958 array('nickname' => Nickname::DISPLAY_FMT));
960 // some targeted RSS 1.0 actions (extends TargetedRss10Action)
961 foreach (array('all', 'replies') as $a) {
962 $m->connect(':nickname/'.$a.'/rss',
963 array('action' => $a.'rss'),
964 array('nickname' => Nickname::DISPLAY_FMT));
969 $m->connect(':nickname/peopletags',
970 array('action' => 'peopletagsbyuser',
971 'nickname' => Nickname::DISPLAY_FMT));
973 $m->connect(':nickname/peopletags/private',
974 array('action' => 'peopletagsbyuser',
975 'nickname' => Nickname::DISPLAY_FMT,
978 $m->connect(':nickname/peopletags/public',
979 array('action' => 'peopletagsbyuser',
980 'nickname' => Nickname::DISPLAY_FMT,
983 $m->connect(':nickname/othertags',
984 array('action' => 'peopletagsforuser',
985 'nickname' => Nickname::DISPLAY_FMT));
987 $m->connect(':nickname/peopletagsubscriptions',
988 array('action' => 'peopletagsubscriptions',
989 'nickname' => Nickname::DISPLAY_FMT));
991 $m->connect(':tagger/all/:tag/subscribers',
992 array('action' => 'peopletagsubscribers',
993 'tagger' => Nickname::DISPLAY_FMT,
994 'tag' => self::REGEX_TAG));
996 $m->connect(':tagger/all/:tag/tagged',
997 array('action' => 'peopletagged',
998 'tagger' => Nickname::DISPLAY_FMT,
999 'tag' => self::REGEX_TAG));
1001 $m->connect(':tagger/all/:tag/edit',
1002 array('action' => 'editpeopletag',
1003 'tagger' => Nickname::DISPLAY_FMT,
1004 'tag' => self::REGEX_TAG));
1006 foreach(array('subscribe', 'unsubscribe') as $v) {
1007 $m->connect('peopletag/:id/'.$v,
1008 array('action' => $v.'peopletag',
1009 'id' => '[0-9]{1,64}'));
1011 $m->connect('user/:tagger_id/profiletag/:id/id',
1012 array('action' => 'profiletagbyid',
1013 'tagger_id' => '[0-9]+',
1016 $m->connect(':nickname/all/:tag',
1017 array('action' => 'showprofiletag'),
1018 array('nickname' => Nickname::DISPLAY_FMT,
1019 'tag' => self::REGEX_TAG));
1021 foreach (array('subscriptions', 'subscribers') as $a) {
1022 $m->connect(':nickname/'.$a.'/:tag',
1023 array('action' => $a),
1024 array('tag' => self::REGEX_TAG,
1025 'nickname' => Nickname::DISPLAY_FMT));
1028 foreach (array('rss', 'groups') as $a) {
1029 $m->connect(':nickname/'.$a,
1030 array('action' => 'user'.$a),
1031 array('nickname' => Nickname::DISPLAY_FMT));
1034 $m->connect(':nickname/avatar',
1035 array('action' => 'avatarbynickname'),
1036 array('nickname' => Nickname::DISPLAY_FMT));
1037 $m->connect(':nickname/avatar/:size',
1038 array('action' => 'avatarbynickname'),
1039 array('size' => '(|original|\d+)',
1040 'nickname' => Nickname::DISPLAY_FMT));
1042 $m->connect(':nickname/tag/:tag/rss',
1043 array('action' => 'userrss'),
1044 array('nickname' => Nickname::DISPLAY_FMT),
1045 array('tag' => self::REGEX_TAG));
1047 $m->connect(':nickname/tag/:tag',
1048 array('action' => 'showstream'),
1049 array('nickname' => Nickname::DISPLAY_FMT),
1050 array('tag' => self::REGEX_TAG));
1052 $m->connect(':nickname/rsd.xml',
1053 array('action' => 'rsd'),
1054 array('nickname' => Nickname::DISPLAY_FMT));
1056 $m->connect(':nickname',
1057 array('action' => 'showstream'),
1058 array('nickname' => Nickname::DISPLAY_FMT));
1060 $m->connect(':nickname/',
1061 array('action' => 'showstream'),
1062 array('nickname' => Nickname::DISPLAY_FMT));
1066 $m->connect('api/statusnet/app/service/:id.xml',
1067 array('action' => 'ApiAtomService'),
1068 array('id' => Nickname::DISPLAY_FMT));
1070 $m->connect('api/statusnet/app/service.xml',
1071 array('action' => 'ApiAtomService'));
1073 $m->connect('api/statusnet/app/subscriptions/:subscriber/:subscribed.atom',
1074 array('action' => 'AtomPubShowSubscription'),
1075 array('subscriber' => '[0-9]+',
1076 'subscribed' => '[0-9]+'));
1078 $m->connect('api/statusnet/app/subscriptions/:subscriber.atom',
1079 array('action' => 'AtomPubSubscriptionFeed'),
1080 array('subscriber' => '[0-9]+'));
1082 $m->connect('api/statusnet/app/memberships/:profile/:group.atom',
1083 array('action' => 'AtomPubShowMembership'),
1084 array('profile' => '[0-9]+',
1085 'group' => '[0-9]+'));
1087 $m->connect('api/statusnet/app/memberships/:profile.atom',
1088 array('action' => 'AtomPubMembershipFeed'),
1089 array('profile' => '[0-9]+'));
1093 $m->connect('url/:id',
1094 array('action' => 'redirecturl',
1099 Event::handle('RouterInitialized', array($m));
1108 return $this->m->match($path);
1109 } catch (NoRouteMapException $e) {
1110 common_debug($e->getMessage());
1111 // TRANS: Client error on action trying to visit a non-existing page.
1112 throw new ClientException(_('Page not found.'), 404);
1116 function build($action, $args=null, $params=null, $fragment=null)
1118 $action_arg = array('action' => $action);
1121 $args = array_merge($action_arg, $args);
1123 $args = $action_arg;
1126 $url = $this->m->generate($args, $params, $fragment);
1127 // Due to a bug in the Net_URL_Mapper code, the returned URL may
1128 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
1129 // repair that here rather than modifying the upstream code...
1131 $qpos = strpos($url, '?');
1132 if ($qpos !== false) {
1133 $url = substr($url, 0, $qpos+1) .
1134 str_replace('?', '&', substr($url, $qpos+1));
1136 // @fixme this is a hacky workaround for http_build_query in the
1137 // lower-level code and bad configs that set the default separator
1138 // to & instead of &. Encoded &s in parameters will not be
1140 $url = substr($url, 0, $qpos+1) .
1141 str_replace('&', '&', substr($url, $qpos+1));