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 foreach (['' => 'attachment',
223 '/view' => 'attachment_view',
224 '/download' => 'attachment_download',
225 '/thumbnail' => 'attachment_thumbnail'] as $postfix => $action) {
226 foreach (['attachment' => '[0-9]+',
227 'filehash' => '[A-Za-z0-9._-]+'] as $type => $match) {
228 $m->connect("attachment/:{$type}{$postfix}",
229 ['action' => $action],
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 $m->connect('tag/:tag/rss',
264 array('action' => 'tagrss'),
265 array('tag' => self::REGEX_TAG));
266 $m->connect('tag/:tag',
267 array('action' => 'tag'),
268 array('tag' => self::REGEX_TAG));
272 $m->connect('group/new', array('action' => 'newgroup'));
274 foreach (array('edit', 'join', 'leave', 'delete', 'cancel', 'approve') as $v) {
275 $m->connect('group/:nickname/'.$v,
276 array('action' => $v.'group'),
277 array('nickname' => Nickname::DISPLAY_FMT));
278 $m->connect('group/:id/id/'.$v,
279 array('action' => $v.'group'),
280 array('id' => '[0-9]+'));
283 foreach (array('members', 'logo', 'rss') as $n) {
284 $m->connect('group/:nickname/'.$n,
285 array('action' => 'group'.$n),
286 array('nickname' => Nickname::DISPLAY_FMT));
289 $m->connect('group/:nickname/foaf',
290 array('action' => 'foafgroup'),
291 array('nickname' => Nickname::DISPLAY_FMT));
293 $m->connect('group/:nickname/blocked',
294 array('action' => 'blockedfromgroup'),
295 array('nickname' => Nickname::DISPLAY_FMT));
297 $m->connect('group/:nickname/makeadmin',
298 array('action' => 'makeadmin'),
299 array('nickname' => Nickname::DISPLAY_FMT));
301 $m->connect('group/:nickname/members/pending',
302 array('action' => 'groupqueue'),
303 array('nickname' => Nickname::DISPLAY_FMT));
305 $m->connect('group/:id/id',
306 array('action' => 'groupbyid'),
307 array('id' => '[0-9]+'));
309 $m->connect('group/:nickname',
310 array('action' => 'showgroup'),
311 array('nickname' => Nickname::DISPLAY_FMT));
313 $m->connect('group/:nickname/',
314 array('action' => 'showgroup'),
315 array('nickname' => Nickname::DISPLAY_FMT));
317 $m->connect('group/', array('action' => 'groups'));
318 $m->connect('group', array('action' => 'groups'));
319 $m->connect('groups/', array('action' => 'groups'));
320 $m->connect('groups', array('action' => 'groups'));
322 // Twitter-compatible API
327 array('action' => 'Redirect',
328 'nextAction' => 'doc',
329 'args' => array('title' => 'api')));
331 $m->connect('api/statuses/public_timeline.:format',
332 array('action' => 'ApiTimelinePublic',
333 'format' => '(xml|json|rss|atom|as)'));
335 // this is not part of the Twitter API. Also may require authentication depending on server config!
336 $m->connect('api/statuses/networkpublic_timeline.:format',
337 array('action' => 'ApiTimelineNetworkPublic',
338 'format' => '(xml|json|rss|atom|as)'));
340 $m->connect('api/statuses/friends_timeline/:id.:format',
341 array('action' => 'ApiTimelineFriends',
342 'id' => Nickname::INPUT_FMT,
343 'format' => '(xml|json|rss|atom|as)'));
345 $m->connect('api/statuses/friends_timeline.:format',
346 array('action' => 'ApiTimelineFriends',
347 'format' => '(xml|json|rss|atom|as)'));
349 $m->connect('api/statuses/home_timeline/:id.:format',
350 array('action' => 'ApiTimelineHome',
351 'id' => Nickname::INPUT_FMT,
352 'format' => '(xml|json|rss|atom|as)'));
354 $m->connect('api/statuses/home_timeline.:format',
355 array('action' => 'ApiTimelineHome',
356 'format' => '(xml|json|rss|atom|as)'));
358 $m->connect('api/statuses/user_timeline/:id.:format',
359 array('action' => 'ApiTimelineUser',
360 'id' => Nickname::INPUT_FMT,
361 'format' => '(xml|json|rss|atom|as)'));
363 $m->connect('api/statuses/user_timeline.:format',
364 array('action' => 'ApiTimelineUser',
365 'format' => '(xml|json|rss|atom|as)'));
367 $m->connect('api/statuses/mentions/:id.:format',
368 array('action' => 'ApiTimelineMentions',
369 'id' => Nickname::INPUT_FMT,
370 'format' => '(xml|json|rss|atom|as)'));
372 $m->connect('api/statuses/mentions.:format',
373 array('action' => 'ApiTimelineMentions',
374 'format' => '(xml|json|rss|atom|as)'));
376 $m->connect('api/statuses/replies/:id.:format',
377 array('action' => 'ApiTimelineMentions',
378 'id' => Nickname::INPUT_FMT,
379 'format' => '(xml|json|rss|atom|as)'));
381 $m->connect('api/statuses/replies.:format',
382 array('action' => 'ApiTimelineMentions',
383 'format' => '(xml|json|rss|atom|as)'));
385 $m->connect('api/statuses/mentions_timeline/:id.:format',
386 array('action' => 'ApiTimelineMentions',
387 'id' => Nickname::INPUT_FMT,
388 'format' => '(xml|json|rss|atom|as)'));
390 $m->connect('api/statuses/mentions_timeline.:format',
391 array('action' => 'ApiTimelineMentions',
392 'format' => '(xml|json|rss|atom|as)'));
394 $m->connect('api/statuses/friends/:id.:format',
395 array('action' => 'ApiUserFriends',
396 'id' => Nickname::INPUT_FMT,
397 'format' => '(xml|json)'));
399 $m->connect('api/statuses/friends.:format',
400 array('action' => 'ApiUserFriends',
401 'format' => '(xml|json)'));
403 $m->connect('api/statuses/followers/:id.:format',
404 array('action' => 'ApiUserFollowers',
405 'id' => Nickname::INPUT_FMT,
406 'format' => '(xml|json)'));
408 $m->connect('api/statuses/followers.:format',
409 array('action' => 'ApiUserFollowers',
410 'format' => '(xml|json)'));
412 $m->connect('api/statuses/show/:id.:format',
413 array('action' => 'ApiStatusesShow',
415 'format' => '(xml|json|atom)'));
417 $m->connect('api/statuses/show.:format',
418 array('action' => 'ApiStatusesShow',
419 'format' => '(xml|json|atom)'));
421 $m->connect('api/statuses/update.:format',
422 array('action' => 'ApiStatusesUpdate',
423 'format' => '(xml|json|atom)'));
425 $m->connect('api/statuses/destroy/:id.:format',
426 array('action' => 'ApiStatusesDestroy',
428 'format' => '(xml|json)'));
430 $m->connect('api/statuses/destroy.:format',
431 array('action' => 'ApiStatusesDestroy',
432 'format' => '(xml|json)'));
434 // START qvitter API additions
436 $m->connect('api/attachment/:id.:format',
437 array('action' => 'ApiAttachment',
439 'format' => '(xml|json)'));
441 $m->connect('api/checkhub.:format',
442 array('action' => 'ApiCheckHub',
443 'format' => '(xml|json)'));
445 $m->connect('api/externalprofile/show.:format',
446 array('action' => 'ApiExternalProfileShow',
447 'format' => '(xml|json)'));
449 $m->connect('api/statusnet/groups/admins/:id.:format',
450 array('action' => 'ApiGroupAdmins',
451 'id' => Nickname::INPUT_FMT,
452 'format' => '(xml|json)'));
454 $m->connect('api/account/update_link_color.:format',
455 array('action' => 'ApiAccountUpdateLinkColor',
456 'format' => '(xml|json)'));
458 $m->connect('api/account/update_background_color.:format',
459 array('action' => 'ApiAccountUpdateBackgroundColor',
460 'format' => '(xml|json)'));
462 $m->connect('api/account/register.:format',
463 array('action' => 'ApiAccountRegister',
464 'format' => '(xml|json)'));
466 $m->connect('api/check_nickname.:format',
467 array('action' => 'ApiCheckNickname',
468 'format' => '(xml|json)'));
470 // END qvitter API additions
474 $m->connect('api/users/show/:id.:format',
475 array('action' => 'ApiUserShow',
476 'id' => Nickname::INPUT_FMT,
477 'format' => '(xml|json)'));
479 $m->connect('api/users/show.:format',
480 array('action' => 'ApiUserShow',
481 'format' => '(xml|json)'));
483 $m->connect('api/users/profile_image/:screen_name.:format',
484 array('action' => 'ApiUserProfileImage',
485 'screen_name' => Nickname::DISPLAY_FMT,
486 'format' => '(xml|json)'));
490 $m->connect('api/friendships/show.:format',
491 array('action' => 'ApiFriendshipsShow',
492 'format' => '(xml|json)'));
494 $m->connect('api/friendships/exists.:format',
495 array('action' => 'ApiFriendshipsExists',
496 'format' => '(xml|json)'));
498 $m->connect('api/friendships/create/:id.:format',
499 array('action' => 'ApiFriendshipsCreate',
500 'id' => Nickname::INPUT_FMT,
501 'format' => '(xml|json)'));
503 $m->connect('api/friendships/create.:format',
504 array('action' => 'ApiFriendshipsCreate',
505 'format' => '(xml|json)'));
507 $m->connect('api/friendships/destroy/:id.:format',
508 array('action' => 'ApiFriendshipsDestroy',
509 'id' => Nickname::INPUT_FMT,
510 'format' => '(xml|json)'));
512 $m->connect('api/friendships/destroy.:format',
513 array('action' => 'ApiFriendshipsDestroy',
514 'format' => '(xml|json)'));
518 $m->connect('api/friends/ids/:id.:format',
519 array('action' => 'ApiUserFriends',
520 'ids_only' => true));
522 $m->connect('api/followers/ids/:id.:format',
523 array('action' => 'ApiUserFollowers',
524 'ids_only' => true));
526 $m->connect('api/friends/ids.:format',
527 array('action' => 'ApiUserFriends',
528 'ids_only' => true));
530 $m->connect('api/followers/ids.:format',
531 array('action' => 'ApiUserFollowers',
532 'ids_only' => true));
536 $m->connect('api/account/verify_credentials.:format',
537 array('action' => 'ApiAccountVerifyCredentials'));
539 $m->connect('api/account/update_profile.:format',
540 array('action' => 'ApiAccountUpdateProfile'));
542 $m->connect('api/account/update_profile_image.:format',
543 array('action' => 'ApiAccountUpdateProfileImage'));
545 $m->connect('api/account/update_delivery_device.:format',
546 array('action' => 'ApiAccountUpdateDeliveryDevice'));
548 // special case where verify_credentials is called w/out a format
550 $m->connect('api/account/verify_credentials',
551 array('action' => 'ApiAccountVerifyCredentials'));
553 $m->connect('api/account/rate_limit_status.:format',
554 array('action' => 'ApiAccountRateLimitStatus'));
558 $m->connect('api/blocks/create/:id.:format',
559 array('action' => 'ApiBlockCreate',
560 'id' => Nickname::INPUT_FMT,
561 'format' => '(xml|json)'));
563 $m->connect('api/blocks/create.:format',
564 array('action' => 'ApiBlockCreate',
565 'format' => '(xml|json)'));
567 $m->connect('api/blocks/destroy/:id.:format',
568 array('action' => 'ApiBlockDestroy',
569 'id' => Nickname::INPUT_FMT,
570 'format' => '(xml|json)'));
572 $m->connect('api/blocks/destroy.:format',
573 array('action' => 'ApiBlockDestroy',
574 'format' => '(xml|json)'));
578 $m->connect('api/help/test.:format',
579 array('action' => 'ApiHelpTest',
580 'format' => '(xml|json)'));
584 $m->connect('api/statusnet/version.:format',
585 array('action' => 'ApiGNUsocialVersion',
586 'format' => '(xml|json)'));
588 $m->connect('api/statusnet/config.:format',
589 array('action' => 'ApiGNUsocialConfig',
590 'format' => '(xml|json)'));
592 // For our current software name, we provide "gnusocial" base action
594 $m->connect('api/gnusocial/version.:format',
595 array('action' => 'ApiGNUsocialVersion',
596 'format' => '(xml|json)'));
598 $m->connect('api/gnusocial/config.:format',
599 array('action' => 'ApiGNUsocialConfig',
600 'format' => '(xml|json)'));
602 // Groups and tags are newer than 0.8.1 so no backward-compatibility
606 //'list' has to be handled differently, as php will not allow a method to be named 'list'
608 $m->connect('api/statusnet/groups/timeline/:id.:format',
609 array('action' => 'ApiTimelineGroup',
610 'id' => Nickname::INPUT_FMT,
611 'format' => '(xml|json|rss|atom|as)'));
613 $m->connect('api/statusnet/groups/show/:id.:format',
614 array('action' => 'ApiGroupShow',
615 'id' => Nickname::INPUT_FMT,
616 'format' => '(xml|json)'));
618 $m->connect('api/statusnet/groups/show.:format',
619 array('action' => 'ApiGroupShow',
620 'format' => '(xml|json)'));
622 $m->connect('api/statusnet/groups/join/:id.:format',
623 array('action' => 'ApiGroupJoin',
624 'id' => Nickname::INPUT_FMT,
625 'format' => '(xml|json)'));
627 $m->connect('api/statusnet/groups/join.:format',
628 array('action' => 'ApiGroupJoin',
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/leave.:format',
636 array('action' => 'ApiGroupLeave',
637 'id' => Nickname::INPUT_FMT,
638 'format' => '(xml|json)'));
640 $m->connect('api/statusnet/groups/is_member.:format',
641 array('action' => 'ApiGroupIsMember',
642 'format' => '(xml|json)'));
644 $m->connect('api/statusnet/groups/list/:id.:format',
645 array('action' => 'ApiGroupList',
646 'id' => Nickname::INPUT_FMT,
647 'format' => '(xml|json|rss|atom)'));
649 $m->connect('api/statusnet/groups/list.:format',
650 array('action' => 'ApiGroupList',
651 'format' => '(xml|json|rss|atom)'));
653 $m->connect('api/statusnet/groups/list_all.:format',
654 array('action' => 'ApiGroupListAll',
655 'format' => '(xml|json|rss|atom)'));
657 $m->connect('api/statusnet/groups/membership/:id.:format',
658 array('action' => 'ApiGroupMembership',
659 'id' => Nickname::INPUT_FMT,
660 'format' => '(xml|json)'));
662 $m->connect('api/statusnet/groups/membership.:format',
663 array('action' => 'ApiGroupMembership',
664 'format' => '(xml|json)'));
666 $m->connect('api/statusnet/groups/create.:format',
667 array('action' => 'ApiGroupCreate',
668 'format' => '(xml|json)'));
670 $m->connect('api/statusnet/groups/update/:id.:format',
671 array('action' => 'ApiGroupProfileUpdate',
672 'id' => '[a-zA-Z0-9]+',
673 'format' => '(xml|json)'));
675 $m->connect('api/statusnet/conversation/:id.:format',
676 array('action' => 'apiconversation',
678 'format' => '(xml|json|rss|atom|as)'));
680 // Lists (people tags)
681 $m->connect('api/lists/list.:format',
682 array('action' => 'ApiListSubscriptions',
683 'format' => '(xml|json)'));
685 $m->connect('api/lists/memberships.:format',
686 array('action' => 'ApiListMemberships',
687 'format' => '(xml|json)'));
689 $m->connect('api/:user/lists/memberships.:format',
690 array('action' => 'ApiListMemberships',
691 'user' => '[a-zA-Z0-9]+',
692 'format' => '(xml|json)'));
694 $m->connect('api/lists/subscriptions.:format',
695 array('action' => 'ApiListSubscriptions',
696 'format' => '(xml|json)'));
698 $m->connect('api/:user/lists/subscriptions.:format',
699 array('action' => 'ApiListSubscriptions',
700 'user' => '[a-zA-Z0-9]+',
701 'format' => '(xml|json)'));
703 $m->connect('api/lists.:format',
704 array('action' => 'ApiLists',
705 'format' => '(xml|json)'));
707 $m->connect('api/:user/lists/:id.:format',
708 array('action' => 'ApiList',
709 'user' => '[a-zA-Z0-9]+',
710 'id' => '[a-zA-Z0-9]+',
711 'format' => '(xml|json)'));
713 $m->connect('api/:user/lists.:format',
714 array('action' => 'ApiLists',
715 'user' => '[a-zA-Z0-9]+',
716 'format' => '(xml|json)'));
718 $m->connect('api/:user/lists/:id/statuses.:format',
719 array('action' => 'ApiTimelineList',
720 'user' => '[a-zA-Z0-9]+',
721 'id' => '[a-zA-Z0-9]+',
722 'format' => '(xml|json|rss|atom)'));
724 $m->connect('api/:user/:list_id/members/:id.:format',
725 array('action' => 'ApiListMember',
726 'user' => '[a-zA-Z0-9]+',
727 'list_id' => '[a-zA-Z0-9]+',
728 'id' => '[a-zA-Z0-9]+',
729 'format' => '(xml|json)'));
731 $m->connect('api/:user/:list_id/members.:format',
732 array('action' => 'ApiListMembers',
733 'user' => '[a-zA-Z0-9]+',
734 'list_id' => '[a-zA-Z0-9]+',
735 'format' => '(xml|json)'));
737 $m->connect('api/:user/:list_id/subscribers/:id.:format',
738 array('action' => 'ApiListSubscriber',
739 'user' => '[a-zA-Z0-9]+',
740 'list_id' => '[a-zA-Z0-9]+',
741 'id' => '[a-zA-Z0-9]+',
742 'format' => '(xml|json)'));
744 $m->connect('api/:user/:list_id/subscribers.:format',
745 array('action' => 'ApiListSubscribers',
746 'user' => '[a-zA-Z0-9]+',
747 'list_id' => '[a-zA-Z0-9]+',
748 'format' => '(xml|json)'));
751 $m->connect('api/statusnet/tags/timeline/:tag.:format',
752 array('action' => 'ApiTimelineTag',
753 'tag' => self::REGEX_TAG,
754 'format' => '(xml|json|rss|atom|as)'));
758 'api/statusnet/media/upload',
759 array('action' => 'ApiMediaUpload')
762 'api/statuses/update_with_media.json',
763 array('action' => 'ApiMediaUpload')
765 // Twitter Media upload API v1.1
767 'api/media/upload.:format',
768 array('action' => 'ApiMediaUpload',
769 'format' => '(xml|json)',
774 $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
775 $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
776 $m->connect('api/trends.json', array('action' => 'ApiTrends'));
778 $m->connect('api/oauth/request_token',
779 array('action' => 'ApiOAuthRequestToken'));
781 $m->connect('api/oauth/access_token',
782 array('action' => 'ApiOAuthAccessToken'));
784 $m->connect('api/oauth/authorize',
785 array('action' => 'ApiOAuthAuthorize'));
789 $m->connect('panel/site', array('action' => 'siteadminpanel'));
790 $m->connect('panel/user', array('action' => 'useradminpanel'));
791 $m->connect('panel/access', array('action' => 'accessadminpanel'));
792 $m->connect('panel/paths', array('action' => 'pathsadminpanel'));
793 $m->connect('panel/sessions', array('action' => 'sessionsadminpanel'));
794 $m->connect('panel/sitenotice', array('action' => 'sitenoticeadminpanel'));
795 $m->connect('panel/license', array('action' => 'licenseadminpanel'));
797 $m->connect('panel/plugins', array('action' => 'pluginsadminpanel'));
798 $m->connect('panel/plugins/enable/:plugin',
799 array('action' => 'pluginenable'),
800 array('plugin' => '[A-Za-z0-9_]+'));
801 $m->connect('panel/plugins/disable/:plugin',
802 array('action' => 'plugindisable'),
803 array('plugin' => '[A-Za-z0-9_]+'));
805 // Common people-tag stuff
807 $m->connect('peopletag/:tag', array('action' => 'peopletag',
808 'tag' => self::REGEX_TAG));
810 $m->connect('selftag/:tag', array('action' => 'selftag',
811 'tag' => self::REGEX_TAG));
813 $m->connect('main/addpeopletag', array('action' => 'addpeopletag'));
815 $m->connect('main/removepeopletag', array('action' => 'removepeopletag'));
817 $m->connect('main/profilecompletion', array('action' => 'profilecompletion'));
819 $m->connect('main/peopletagautocomplete', array('action' => 'peopletagautocomplete'));
823 if (common_config('singleuser', 'enabled')) {
825 $nickname = User::singleUserNickname();
827 foreach (array('subscriptions', 'subscribers',
828 'all', 'foaf', 'replies',
831 array('action' => $a,
832 'nickname' => $nickname));
835 foreach (array('subscriptions', 'subscribers') as $a) {
836 $m->connect($a.'/:tag',
837 array('action' => $a,
838 'nickname' => $nickname),
839 array('tag' => self::REGEX_TAG));
842 $m->connect('subscribers/pending',
843 array('action' => 'subqueue',
844 'nickname' => $nickname));
846 foreach (array('rss', 'groups') as $a) {
848 array('action' => 'user'.$a,
849 'nickname' => $nickname));
852 foreach (array('all', 'replies') as $a) {
853 $m->connect($a.'/rss',
854 array('action' => $a.'rss',
855 'nickname' => $nickname));
858 $m->connect('avatar',
859 array('action' => 'avatarbynickname',
860 'nickname' => $nickname));
861 $m->connect('avatar/:size',
862 array('action' => 'avatarbynickname',
863 'nickname' => $nickname),
864 array('size' => '(|original|\d+)'));
866 $m->connect('tag/:tag/rss',
867 array('action' => 'userrss',
868 'nickname' => $nickname),
869 array('tag' => self::REGEX_TAG));
871 $m->connect('tag/:tag',
872 array('action' => 'showstream',
873 'nickname' => $nickname),
874 array('tag' => self::REGEX_TAG));
876 $m->connect('rsd.xml',
877 array('action' => 'rsd',
878 'nickname' => $nickname));
882 $m->connect('peopletags',
883 array('action' => 'peopletagsbyuser'));
885 $m->connect('peopletags/private',
886 array('action' => 'peopletagsbyuser',
889 $m->connect('peopletags/public',
890 array('action' => 'peopletagsbyuser',
893 $m->connect('othertags',
894 array('action' => 'peopletagsforuser'));
896 $m->connect('peopletagsubscriptions',
897 array('action' => 'peopletagsubscriptions'));
899 $m->connect('all/:tag/subscribers',
900 array('action' => 'peopletagsubscribers',
901 'tag' => self::REGEX_TAG));
903 $m->connect('all/:tag/tagged',
904 array('action' => 'peopletagged',
905 'tag' => self::REGEX_TAG));
907 $m->connect('all/:tag/edit',
908 array('action' => 'editpeopletag',
909 'tag' => self::REGEX_TAG));
911 foreach(array('subscribe', 'unsubscribe') as $v) {
912 $m->connect('peopletag/:id/'.$v,
913 array('action' => $v.'peopletag',
914 'id' => '[0-9]{1,64}'));
916 $m->connect('user/:tagger_id/profiletag/:id/id',
917 array('action' => 'profiletagbyid',
918 'tagger_id' => '[0-9]+',
921 $m->connect('all/:tag',
922 array('action' => 'showprofiletag',
923 'tagger' => $nickname,
924 'tag' => self::REGEX_TAG));
926 foreach (array('subscriptions', 'subscribers') as $a) {
927 $m->connect($a.'/:tag',
928 array('action' => $a),
929 array('tag' => self::REGEX_TAG));
933 $m->connect('rss', array('action' => 'publicrss'));
934 $m->connect('featuredrss', array('action' => 'featuredrss'));
935 $m->connect('featured/', array('action' => 'featured'));
936 $m->connect('featured', array('action' => 'featured'));
937 $m->connect('rsd.xml', array('action' => 'rsd'));
939 foreach (array('subscriptions', 'subscribers',
940 'nudge', 'all', 'foaf', 'replies',
941 'inbox', 'outbox') as $a) {
942 $m->connect(':nickname/'.$a,
943 array('action' => $a),
944 array('nickname' => Nickname::DISPLAY_FMT));
946 $m->connect(':nickname/subscribers/pending',
947 array('action' => 'subqueue'),
948 array('nickname' => Nickname::DISPLAY_FMT));
950 // some targeted RSS 1.0 actions (extends TargetedRss10Action)
951 foreach (array('all', 'replies') as $a) {
952 $m->connect(':nickname/'.$a.'/rss',
953 array('action' => $a.'rss'),
954 array('nickname' => Nickname::DISPLAY_FMT));
959 $m->connect(':nickname/peopletags',
960 array('action' => 'peopletagsbyuser',
961 'nickname' => Nickname::DISPLAY_FMT));
963 $m->connect(':nickname/peopletags/private',
964 array('action' => 'peopletagsbyuser',
965 'nickname' => Nickname::DISPLAY_FMT,
968 $m->connect(':nickname/peopletags/public',
969 array('action' => 'peopletagsbyuser',
970 'nickname' => Nickname::DISPLAY_FMT,
973 $m->connect(':nickname/othertags',
974 array('action' => 'peopletagsforuser',
975 'nickname' => Nickname::DISPLAY_FMT));
977 $m->connect(':nickname/peopletagsubscriptions',
978 array('action' => 'peopletagsubscriptions',
979 'nickname' => Nickname::DISPLAY_FMT));
981 $m->connect(':tagger/all/:tag/subscribers',
982 array('action' => 'peopletagsubscribers',
983 'tagger' => Nickname::DISPLAY_FMT,
984 'tag' => self::REGEX_TAG));
986 $m->connect(':tagger/all/:tag/tagged',
987 array('action' => 'peopletagged',
988 'tagger' => Nickname::DISPLAY_FMT,
989 'tag' => self::REGEX_TAG));
991 $m->connect(':tagger/all/:tag/edit',
992 array('action' => 'editpeopletag',
993 'tagger' => Nickname::DISPLAY_FMT,
994 'tag' => self::REGEX_TAG));
996 foreach(array('subscribe', 'unsubscribe') as $v) {
997 $m->connect('peopletag/:id/'.$v,
998 array('action' => $v.'peopletag',
999 'id' => '[0-9]{1,64}'));
1001 $m->connect('user/:tagger_id/profiletag/:id/id',
1002 array('action' => 'profiletagbyid',
1003 'tagger_id' => '[0-9]+',
1006 $m->connect(':nickname/all/:tag',
1007 array('action' => 'showprofiletag'),
1008 array('nickname' => Nickname::DISPLAY_FMT,
1009 'tag' => self::REGEX_TAG));
1011 foreach (array('subscriptions', 'subscribers') as $a) {
1012 $m->connect(':nickname/'.$a.'/:tag',
1013 array('action' => $a),
1014 array('tag' => self::REGEX_TAG,
1015 'nickname' => Nickname::DISPLAY_FMT));
1018 foreach (array('rss', 'groups') as $a) {
1019 $m->connect(':nickname/'.$a,
1020 array('action' => 'user'.$a),
1021 array('nickname' => Nickname::DISPLAY_FMT));
1024 $m->connect(':nickname/avatar',
1025 array('action' => 'avatarbynickname'),
1026 array('nickname' => Nickname::DISPLAY_FMT));
1027 $m->connect(':nickname/avatar/:size',
1028 array('action' => 'avatarbynickname'),
1029 array('size' => '(|original|\d+)',
1030 'nickname' => Nickname::DISPLAY_FMT));
1032 $m->connect(':nickname/tag/:tag/rss',
1033 array('action' => 'userrss'),
1034 array('nickname' => Nickname::DISPLAY_FMT),
1035 array('tag' => self::REGEX_TAG));
1037 $m->connect(':nickname/tag/:tag',
1038 array('action' => 'showstream'),
1039 array('nickname' => Nickname::DISPLAY_FMT),
1040 array('tag' => self::REGEX_TAG));
1042 $m->connect(':nickname/rsd.xml',
1043 array('action' => 'rsd'),
1044 array('nickname' => Nickname::DISPLAY_FMT));
1046 $m->connect(':nickname',
1047 array('action' => 'showstream'),
1048 array('nickname' => Nickname::DISPLAY_FMT));
1050 $m->connect(':nickname/',
1051 array('action' => 'showstream'),
1052 array('nickname' => Nickname::DISPLAY_FMT));
1056 $m->connect('api/statusnet/app/service/:id.xml',
1057 array('action' => 'ApiAtomService'),
1058 array('id' => Nickname::DISPLAY_FMT));
1060 $m->connect('api/statusnet/app/service.xml',
1061 array('action' => 'ApiAtomService'));
1063 $m->connect('api/statusnet/app/subscriptions/:subscriber/:subscribed.atom',
1064 array('action' => 'AtomPubShowSubscription'),
1065 array('subscriber' => '[0-9]+',
1066 'subscribed' => '[0-9]+'));
1068 $m->connect('api/statusnet/app/subscriptions/:subscriber.atom',
1069 array('action' => 'AtomPubSubscriptionFeed'),
1070 array('subscriber' => '[0-9]+'));
1072 $m->connect('api/statusnet/app/memberships/:profile/:group.atom',
1073 array('action' => 'AtomPubShowMembership'),
1074 array('profile' => '[0-9]+',
1075 'group' => '[0-9]+'));
1077 $m->connect('api/statusnet/app/memberships/:profile.atom',
1078 array('action' => 'AtomPubMembershipFeed'),
1079 array('profile' => '[0-9]+'));
1083 $m->connect('url/:id',
1084 array('action' => 'redirecturl',
1089 Event::handle('RouterInitialized', array($m));
1098 return $this->m->match($path);
1099 } catch (NoRouteMapException $e) {
1100 common_debug($e->getMessage());
1101 // TRANS: Client error on action trying to visit a non-existing page.
1102 throw new ClientException(_('Page not found.'), 404);
1106 function build($action, $args=null, $params=null, $fragment=null)
1108 $action_arg = array('action' => $action);
1111 $args = array_merge($action_arg, $args);
1113 $args = $action_arg;
1116 $url = $this->m->generate($args, $params, $fragment);
1117 // Due to a bug in the Net_URL_Mapper code, the returned URL may
1118 // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
1119 // repair that here rather than modifying the upstream code...
1121 $qpos = strpos($url, '?');
1122 if ($qpos !== false) {
1123 $url = substr($url, 0, $qpos+1) .
1124 str_replace('?', '&', substr($url, $qpos+1));
1126 // @fixme this is a hacky workaround for http_build_query in the
1127 // lower-level code and bad configs that set the default separator
1128 // to & instead of &. Encoded &s in parameters will not be
1130 $url = substr($url, 0, $qpos+1) .
1131 str_replace('&', '&', substr($url, $qpos+1));