]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/router.php
Updated styles for versions page
[quix0rs-gnu-social.git] / lib / router.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * URL routing utilities
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  URL
23  * @package   StatusNet
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/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once 'Net/URL/Mapper.php';
35
36 /**
37  * URL Router
38  *
39  * Cheap wrapper around Net_URL_Mapper
40  *
41  * @category URL
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47
48 class Router
49 {
50     var $m = null;
51     static $inst = null;
52     static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
53                          'postnotice', 'updateprofile', 'finishremotesubscribe');
54
55     static function get()
56     {
57         if (!Router::$inst) {
58             Router::$inst = new Router();
59         }
60         return Router::$inst;
61     }
62
63     function __construct()
64     {
65         if (!$this->m) {
66             $this->m = $this->initialize();
67         }
68     }
69
70     function initialize()
71     {
72         $m = Net_URL_Mapper::getInstance();
73
74         if (Event::handle('StartInitializeRouter', array(&$m))) {
75
76             // In the "root"
77
78             $m->connect('', array('action' => 'public'));
79             $m->connect('rss', array('action' => 'publicrss'));
80             $m->connect('featuredrss', array('action' => 'featuredrss'));
81             $m->connect('favoritedrss', array('action' => 'favoritedrss'));
82             $m->connect('opensearch/people', array('action' => 'opensearch',
83                                                    'type' => 'people'));
84             $m->connect('opensearch/notice', array('action' => 'opensearch',
85                                                    'type' => 'notice'));
86
87             // docs
88
89             $m->connect('doc/:title', array('action' => 'doc'));
90
91             $m->connect('main/login?user_id=:user_id&token=:token', array('action'=>'login'), array('user_id'=> '[0-9]+', 'token'=>'.+'));
92
93             // main stuff is repetitive
94
95             $main = array('login', 'logout', 'register', 'subscribe',
96                           'unsubscribe', 'confirmaddress', 'recoverpassword',
97                           'invite', 'favor', 'disfavor', 'sup',
98                           'block', 'unblock', 'subedit',
99                           'groupblock', 'groupunblock',
100                           'sandbox', 'unsandbox',
101                           'silence', 'unsilence',
102                           'repeat',
103                           'deleteuser',
104                           'geocode',
105                           'version',
106                           );
107
108             foreach ($main as $a) {
109                 $m->connect('main/'.$a, array('action' => $a));
110             }
111
112             $m->connect('main/sup/:seconds', array('action' => 'sup'),
113                         array('seconds' => '[0-9]+'));
114
115             $m->connect('main/tagother/:id', array('action' => 'tagother'));
116
117             $m->connect('main/oembed',
118                         array('action' => 'oembed'));
119
120             $m->connect('main/xrds',
121                         array('action' => 'publicxrds'));
122
123             // these take a code
124
125             foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
126                 $m->connect('main/'.$c.'/:code', array('action' => $c));
127             }
128
129             // exceptional
130
131             $m->connect('main/remote', array('action' => 'remotesubscribe'));
132             $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
133
134             foreach (Router::$bare as $action) {
135                 $m->connect('index.php?action=' . $action, array('action' => $action));
136             }
137
138             // settings
139
140             foreach (array('profile', 'avatar', 'password', 'im',
141                            'email', 'sms', 'userdesign', 'other') as $s) {
142                 $m->connect('settings/'.$s, array('action' => $s.'settings'));
143             }
144
145             // search
146
147             foreach (array('group', 'people', 'notice') as $s) {
148                 $m->connect('search/'.$s, array('action' => $s.'search'));
149                 $m->connect('search/'.$s.'?q=:q',
150                             array('action' => $s.'search'),
151                             array('q' => '.+'));
152             }
153
154             // The second of these is needed to make the link work correctly
155             // when inserted into the page. The first is needed to match the
156             // route on the way in. Seems to be another Net_URL_Mapper bug to me.
157             $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
158             $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
159                         array('q' => '.+'));
160
161             $m->connect('attachment/:attachment',
162                         array('action' => 'attachment'),
163                         array('attachment' => '[0-9]+'));
164
165             $m->connect('attachment/:attachment/ajax',
166                         array('action' => 'attachment_ajax'),
167                         array('attachment' => '[0-9]+'));
168
169             $m->connect('attachment/:attachment/thumbnail',
170                         array('action' => 'attachment_thumbnail'),
171                         array('attachment' => '[0-9]+'));
172
173             $m->connect('notice/new', array('action' => 'newnotice'));
174             $m->connect('notice/new?replyto=:replyto',
175                         array('action' => 'newnotice'),
176                         array('replyto' => '[A-Za-z0-9_-]+'));
177             $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
178                         array('action' => 'newnotice'),
179                         array('replyto' => '[A-Za-z0-9_-]+'),
180                         array('inreplyto' => '[0-9]+'));
181
182             $m->connect('notice/:notice/file',
183                         array('action' => 'file'),
184                         array('notice' => '[0-9]+'));
185
186             $m->connect('notice/:notice',
187                         array('action' => 'shownotice'),
188                         array('notice' => '[0-9]+'));
189             $m->connect('notice/delete', array('action' => 'deletenotice'));
190             $m->connect('notice/delete/:notice',
191                         array('action' => 'deletenotice'),
192                         array('notice' => '[0-9]+'));
193
194             $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
195
196             // conversation
197
198             $m->connect('conversation/:id',
199                         array('action' => 'conversation'),
200                         array('id' => '[0-9]+'));
201
202             $m->connect('message/new', array('action' => 'newmessage'));
203             $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
204             $m->connect('message/:message',
205                         array('action' => 'showmessage'),
206                         array('message' => '[0-9]+'));
207
208             $m->connect('user/:id',
209                         array('action' => 'userbyid'),
210                         array('id' => '[0-9]+'));
211
212             $m->connect('tags/', array('action' => 'publictagcloud'));
213             $m->connect('tag/', array('action' => 'publictagcloud'));
214             $m->connect('tags', array('action' => 'publictagcloud'));
215             $m->connect('tag', array('action' => 'publictagcloud'));
216             $m->connect('tag/:tag/rss',
217                         array('action' => 'tagrss'),
218                         array('tag' => '[a-zA-Z0-9]+'));
219             $m->connect('tag/:tag',
220                         array('action' => 'tag'),
221                         array('tag' => '[\pL\pN_\-\.]{1,64}'));
222
223             $m->connect('peopletag/:tag',
224                         array('action' => 'peopletag'),
225                         array('tag' => '[a-zA-Z0-9]+'));
226
227             $m->connect('featured/', array('action' => 'featured'));
228             $m->connect('featured', array('action' => 'featured'));
229             $m->connect('favorited/', array('action' => 'favorited'));
230             $m->connect('favorited', array('action' => 'favorited'));
231
232             // groups
233
234             $m->connect('group/new', array('action' => 'newgroup'));
235
236             foreach (array('edit', 'join', 'leave') as $v) {
237                 $m->connect('group/:nickname/'.$v,
238                             array('action' => $v.'group'),
239                             array('nickname' => '[a-zA-Z0-9]+'));
240             }
241
242             foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
243                 $m->connect('group/:nickname/'.$n,
244                             array('action' => 'group'.$n),
245                             array('nickname' => '[a-zA-Z0-9]+'));
246             }
247
248             $m->connect('group/:nickname/foaf',
249                         array('action' => 'foafgroup'),
250                         array('nickname' => '[a-zA-Z0-9]+'));
251
252             $m->connect('group/:nickname/blocked',
253                         array('action' => 'blockedfromgroup'),
254                         array('nickname' => '[a-zA-Z0-9]+'));
255
256             $m->connect('group/:nickname/makeadmin',
257                         array('action' => 'makeadmin'),
258                         array('nickname' => '[a-zA-Z0-9]+'));
259
260             $m->connect('group/:id/id',
261                         array('action' => 'groupbyid'),
262                         array('id' => '[0-9]+'));
263
264             $m->connect('group/:nickname',
265                         array('action' => 'showgroup'),
266                         array('nickname' => '[a-zA-Z0-9]+'));
267
268             $m->connect('group/', array('action' => 'groups'));
269             $m->connect('group', array('action' => 'groups'));
270             $m->connect('groups/', array('action' => 'groups'));
271             $m->connect('groups', array('action' => 'groups'));
272
273             // Twitter-compatible API
274
275             // statuses API
276
277             $m->connect('api/statuses/public_timeline.:format',
278                         array('action' => 'ApiTimelinePublic',
279                               'format' => '(xml|json|rss|atom)'));
280
281             $m->connect('api/statuses/friends_timeline.:format',
282                         array('action' => 'ApiTimelineFriends',
283                               'format' => '(xml|json|rss|atom)'));
284
285             $m->connect('api/statuses/friends_timeline/:id.:format',
286                         array('action' => 'ApiTimelineFriends',
287                               'id' => '[a-zA-Z0-9]+',
288                               'format' => '(xml|json|rss|atom)'));
289
290             $m->connect('api/statuses/home_timeline.:format',
291                         array('action' => 'ApiTimelineHome',
292                               'format' => '(xml|json|rss|atom)'));
293
294             $m->connect('api/statuses/home_timeline/:id.:format',
295                         array('action' => 'ApiTimelineHome',
296                               'id' => '[a-zA-Z0-9]+',
297                               'format' => '(xml|json|rss|atom)'));
298
299             $m->connect('api/statuses/user_timeline.:format',
300                         array('action' => 'ApiTimelineUser',
301                               'format' => '(xml|json|rss|atom)'));
302
303             $m->connect('api/statuses/user_timeline/:id.:format',
304                         array('action' => 'ApiTimelineUser',
305                               'id' => '[a-zA-Z0-9]+',
306                               'format' => '(xml|json|rss|atom)'));
307
308             $m->connect('api/statuses/mentions.:format',
309                         array('action' => 'ApiTimelineMentions',
310                               'format' => '(xml|json|rss|atom)'));
311
312             $m->connect('api/statuses/mentions/:id.:format',
313                         array('action' => 'ApiTimelineMentions',
314                               'id' => '[a-zA-Z0-9]+',
315                               'format' => '(xml|json|rss|atom)'));
316
317             $m->connect('api/statuses/replies.:format',
318                         array('action' => 'ApiTimelineMentions',
319                               'format' => '(xml|json|rss|atom)'));
320
321             $m->connect('api/statuses/replies/:id.:format',
322                         array('action' => 'ApiTimelineMentions',
323                               'id' => '[a-zA-Z0-9]+',
324                               'format' => '(xml|json|rss|atom)'));
325
326             $m->connect('api/statuses/retweeted_by_me.:format',
327                         array('action' => 'ApiTimelineRetweetedByMe',
328                               'format' => '(xml|json|atom)'));
329
330             $m->connect('api/statuses/retweeted_to_me.:format',
331                         array('action' => 'ApiTimelineRetweetedToMe',
332                               'format' => '(xml|json|atom)'));
333
334             $m->connect('api/statuses/retweets_of_me.:format',
335                         array('action' => 'ApiTimelineRetweetsOfMe',
336                               'format' => '(xml|json|atom)'));
337
338             $m->connect('api/statuses/friends.:format',
339                         array('action' => 'ApiUserFriends',
340                               'format' => '(xml|json)'));
341
342             $m->connect('api/statuses/friends/:id.:format',
343                         array('action' => 'ApiUserFriends',
344                               'id' => '[a-zA-Z0-9]+',
345                               'format' => '(xml|json)'));
346
347             $m->connect('api/statuses/followers.:format',
348                         array('action' => 'ApiUserFollowers',
349                               'format' => '(xml|json)'));
350
351             $m->connect('api/statuses/followers/:id.:format',
352                         array('action' => 'ApiUserFollowers',
353                               'id' => '[a-zA-Z0-9]+',
354                               'format' => '(xml|json)'));
355
356             $m->connect('api/statuses/show.:format',
357                         array('action' => 'ApiStatusesShow',
358                               'format' => '(xml|json)'));
359
360             $m->connect('api/statuses/show/:id.:format',
361                         array('action' => 'ApiStatusesShow',
362                               'id' => '[0-9]+',
363                               'format' => '(xml|json)'));
364
365             $m->connect('api/statuses/update.:format',
366                         array('action' => 'ApiStatusesUpdate',
367                               'format' => '(xml|json)'));
368
369             $m->connect('api/statuses/destroy.:format',
370                         array('action' => 'ApiStatusesDestroy',
371                               'format' => '(xml|json)'));
372
373             $m->connect('api/statuses/destroy/:id.:format',
374                         array('action' => 'ApiStatusesDestroy',
375                               'id' => '[0-9]+',
376                               'format' => '(xml|json)'));
377
378             $m->connect('api/statuses/retweet/:id.:format',
379                         array('action' => 'ApiStatusesRetweet',
380                               'id' => '[0-9]+',
381                               'format' => '(xml|json)'));
382
383             $m->connect('api/statuses/retweets/:id.:format',
384                         array('action' => 'ApiStatusesRetweets',
385                               'id' => '[0-9]+',
386                               'format' => '(xml|json)'));
387
388             // users
389
390             $m->connect('api/users/show.:format',
391                         array('action' => 'ApiUserShow',
392                               'format' => '(xml|json)'));
393
394             $m->connect('api/users/show/:id.:format',
395                         array('action' => 'ApiUserShow',
396                               'id' => '[a-zA-Z0-9]+',
397                               'format' => '(xml|json)'));
398
399             // direct messages
400
401             $m->connect('api/direct_messages.:format',
402                         array('action' => 'ApiDirectMessage',
403                               'format' => '(xml|json|rss|atom)'));
404
405             $m->connect('api/direct_messages/sent.:format',
406                         array('action' => 'ApiDirectMessage',
407                               'format' => '(xml|json|rss|atom)',
408                               'sent' => true));
409
410             $m->connect('api/direct_messages/new.:format',
411                         array('action' => 'ApiDirectMessageNew',
412                               'format' => '(xml|json)'));
413
414             // friendships
415
416             $m->connect('api/friendships/show.:format',
417                         array('action' => 'ApiFriendshipsShow',
418                               'format' => '(xml|json)'));
419
420             $m->connect('api/friendships/exists.:format',
421                         array('action' => 'ApiFriendshipsExists',
422                               'format' => '(xml|json)'));
423
424             $m->connect('api/friendships/create.:format',
425                         array('action' => 'ApiFriendshipsCreate',
426                               'format' => '(xml|json)'));
427
428             $m->connect('api/friendships/destroy.:format',
429                         array('action' => 'ApiFriendshipsDestroy',
430                               'format' => '(xml|json)'));
431
432             $m->connect('api/friendships/create/:id.:format',
433                         array('action' => 'ApiFriendshipsCreate',
434                               'id' => '[a-zA-Z0-9]+',
435                               'format' => '(xml|json)'));
436
437             $m->connect('api/friendships/destroy/:id.:format',
438                         array('action' => 'ApiFriendshipsDestroy',
439                               'id' => '[a-zA-Z0-9]+',
440                               'format' => '(xml|json)'));
441
442             // Social graph
443
444             $m->connect('api/friends/ids/:id.:format',
445                         array('action' => 'apiFriends',
446                               'ids_only' => true));
447
448             $m->connect('api/followers/ids/:id.:format',
449                         array('action' => 'apiFollowers',
450                               'ids_only' => true));
451
452             $m->connect('api/friends/ids.:format',
453                         array('action' => 'apiFriends',
454                               'ids_only' => true));
455
456             $m->connect('api/followers/ids.:format',
457                         array('action' => 'apiFollowers',
458                               'ids_only' => true));
459
460             // account
461
462             $m->connect('api/account/verify_credentials.:format',
463                         array('action' => 'ApiAccountVerifyCredentials'));
464
465             $m->connect('api/account/update_profile.:format',
466                         array('action' => 'ApiAccountUpdateProfile'));
467
468             $m->connect('api/account/update_profile_image.:format',
469                         array('action' => 'ApiAccountUpdateProfileImage'));
470
471             $m->connect('api/account/update_profile_background_image.:format',
472                         array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
473
474             $m->connect('api/account/update_profile_colors.:format',
475                         array('action' => 'ApiAccountUpdateProfileColors'));
476
477             $m->connect('api/account/update_delivery_device.:format',
478                         array('action' => 'ApiAccountUpdateDeliveryDevice'));
479
480             // special case where verify_credentials is called w/out a format
481
482             $m->connect('api/account/verify_credentials',
483                         array('action' => 'ApiAccountVerifyCredentials'));
484
485             $m->connect('api/account/rate_limit_status.:format',
486                         array('action' => 'ApiAccountRateLimitStatus'));
487
488             // favorites
489
490             $m->connect('api/favorites.:format',
491                         array('action' => 'ApiTimelineFavorites',
492                               'format' => '(xml|json|rss|atom)'));
493
494             $m->connect('api/favorites/:id.:format',
495                         array('action' => 'ApiTimelineFavorites',
496                               'id' => '[a-zA-Z0-9]+',
497                               'format' => '(xmljson|rss|atom)'));
498
499             $m->connect('api/favorites/create/:id.:format',
500                         array('action' => 'ApiFavoriteCreate',
501                               'id' => '[a-zA-Z0-9]+',
502                               'format' => '(xml|json)'));
503
504             $m->connect('api/favorites/destroy/:id.:format',
505                         array('action' => 'ApiFavoriteDestroy',
506                               'id' => '[a-zA-Z0-9]+',
507                               'format' => '(xml|json)'));
508             // blocks
509
510             $m->connect('api/blocks/create/:id.:format',
511                         array('action' => 'ApiBlockCreate',
512                               'id' => '[a-zA-Z0-9]+',
513                               'format' => '(xml|json)'));
514
515             $m->connect('api/blocks/destroy/:id.:format',
516                         array('action' => 'ApiBlockDestroy',
517                               'id' => '[a-zA-Z0-9]+',
518                               'format' => '(xml|json)'));
519             // help
520
521             $m->connect('api/help/test.:format',
522                         array('action' => 'ApiHelpTest',
523                               'format' => '(xml|json)'));
524
525             // statusnet
526
527             $m->connect('api/statusnet/version.:format',
528                         array('action' => 'ApiStatusnetVersion',
529                               'format' => '(xml|json)'));
530
531             $m->connect('api/statusnet/config.:format',
532                         array('action' => 'ApiStatusnetConfig',
533                               'format' => '(xml|json)'));
534
535             // For older methods, we provide "laconica" base action
536
537             $m->connect('api/laconica/version.:format',
538                         array('action' => 'ApiStatusnetVersion',
539                               'format' => '(xml|json)'));
540
541             $m->connect('api/laconica/config.:format',
542                         array('action' => 'ApiStatusnetConfig',
543                               'format' => '(xml|json)'));
544
545             // Groups and tags are newer than 0.8.1 so no backward-compatibility
546             // necessary
547
548             // Groups
549             //'list' has to be handled differently, as php will not allow a method to be named 'list'
550
551             $m->connect('api/statusnet/groups/timeline/:id.:format',
552                         array('action' => 'ApiTimelineGroup',
553                               'id' => '[a-zA-Z0-9]+',
554                               'format' => '(xmljson|rss|atom)'));
555
556             $m->connect('api/statusnet/groups/show.:format',
557                         array('action' => 'ApiGroupShow',
558                               'format' => '(xml|json)'));
559
560             $m->connect('api/statusnet/groups/show/:id.:format',
561                         array('action' => 'ApiGroupShow',
562                               'id' => '[a-zA-Z0-9]+',
563                               'format' => '(xml|json)'));
564
565             $m->connect('api/statusnet/groups/join.:format',
566                         array('action' => 'ApiGroupJoin',
567                               'id' => '[a-zA-Z0-9]+',
568                               'format' => '(xml|json)'));
569
570             $m->connect('api/statusnet/groups/join/:id.:format',
571                         array('action' => 'ApiGroupJoin',
572                               'format' => '(xml|json)'));
573
574             $m->connect('api/statusnet/groups/leave.:format',
575                         array('action' => 'ApiGroupLeave',
576                               'id' => '[a-zA-Z0-9]+',
577                               'format' => '(xml|json)'));
578
579             $m->connect('api/statusnet/groups/leave/:id.:format',
580                         array('action' => 'ApiGroupLeave',
581                               'format' => '(xml|json)'));
582
583             $m->connect('api/statusnet/groups/is_member.:format',
584                         array('action' => 'ApiGroupIsMember',
585                               'format' => '(xml|json)'));
586
587             $m->connect('api/statusnet/groups/list.:format',
588                         array('action' => 'ApiGroupList',
589                               'format' => '(xml|json|rss|atom)'));
590
591             $m->connect('api/statusnet/groups/list/:id.:format',
592                         array('action' => 'ApiGroupList',
593                               'id' => '[a-zA-Z0-9]+',
594                               'format' => '(xml|json|rss|atom)'));
595
596             $m->connect('api/statusnet/groups/list_all.:format',
597                         array('action' => 'ApiGroupListAll',
598                               'format' => '(xml|json|rss|atom)'));
599
600             $m->connect('api/statusnet/groups/membership.:format',
601                         array('action' => 'ApiGroupMembership',
602                               'format' => '(xml|json)'));
603
604             $m->connect('api/statusnet/groups/membership/:id.:format',
605                         array('action' => 'ApiGroupMembership',
606                               'id' => '[a-zA-Z0-9]+',
607                               'format' => '(xml|json)'));
608
609             $m->connect('api/statusnet/groups/create.:format',
610                         array('action' => 'ApiGroupCreate',
611                               'format' => '(xml|json)'));
612             // Tags
613             $m->connect('api/statusnet/tags/timeline/:tag.:format',
614                         array('action' => 'ApiTimelineTag',
615                               'format' => '(xmljson|rss|atom)'));
616
617             // search
618             $m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
619             $m->connect('api/search.json', array('action' => 'twitapisearchjson'));
620             $m->connect('api/trends.json', array('action' => 'twitapitrends'));
621
622             $m->connect('admin/site', array('action' => 'siteadminpanel'));
623             $m->connect('admin/design', array('action' => 'designadminpanel'));
624             $m->connect('admin/user', array('action' => 'useradminpanel'));
625             $m->connect('admin/paths', array('action' => 'pathsadminpanel'));
626
627             $m->connect('getfile/:filename',
628                         array('action' => 'getfile'),
629                         array('filename' => '[A-Za-z0-9._-]+'));
630
631             // user stuff
632
633             foreach (array('subscriptions', 'subscribers',
634                            'nudge', 'all', 'foaf', 'xrds',
635                            'replies', 'inbox', 'outbox', 'microsummary') as $a) {
636                 $m->connect(':nickname/'.$a,
637                             array('action' => $a),
638                             array('nickname' => '[a-zA-Z0-9]{1,64}'));
639             }
640
641             foreach (array('subscriptions', 'subscribers') as $a) {
642                 $m->connect(':nickname/'.$a.'/:tag',
643                             array('action' => $a),
644                             array('tag' => '[a-zA-Z0-9]+',
645                                   'nickname' => '[a-zA-Z0-9]{1,64}'));
646             }
647
648             foreach (array('rss', 'groups') as $a) {
649                 $m->connect(':nickname/'.$a,
650                             array('action' => 'user'.$a),
651                             array('nickname' => '[a-zA-Z0-9]{1,64}'));
652             }
653
654             foreach (array('all', 'replies', 'favorites') as $a) {
655                 $m->connect(':nickname/'.$a.'/rss',
656                             array('action' => $a.'rss'),
657                             array('nickname' => '[a-zA-Z0-9]{1,64}'));
658             }
659
660             $m->connect(':nickname/favorites',
661                         array('action' => 'showfavorites'),
662                         array('nickname' => '[a-zA-Z0-9]{1,64}'));
663
664             $m->connect(':nickname/avatar/:size',
665                         array('action' => 'avatarbynickname'),
666                         array('size' => '(original|96|48|24)',
667                               'nickname' => '[a-zA-Z0-9]{1,64}'));
668
669             $m->connect(':nickname/tag/:tag/rss',
670                         array('action' => 'userrss'),
671                         array('nickname' => '[a-zA-Z0-9]{1,64}'),
672                         array('tag' => '[a-zA-Z0-9]+'));
673
674             $m->connect(':nickname/tag/:tag',
675                         array('action' => 'showstream'),
676                         array('nickname' => '[a-zA-Z0-9]{1,64}'),
677                         array('tag' => '[a-zA-Z0-9]+'));
678
679             $m->connect(':nickname',
680                         array('action' => 'showstream'),
681                         array('nickname' => '[a-zA-Z0-9]{1,64}'));
682
683             Event::handle('RouterInitialized', array($m));
684         }
685
686         return $m;
687     }
688
689     function map($path)
690     {
691         try {
692             $match = $this->m->match($path);
693         } catch (Net_URL_Mapper_InvalidException $e) {
694             common_log(LOG_ERR, "Problem getting route for $path - " .
695                        $e->getMessage());
696             $cac = new ClientErrorAction("Page not found.", 404);
697             $cac->showPage();
698         }
699
700         return $match;
701     }
702
703     function build($action, $args=null, $params=null, $fragment=null)
704     {
705         $action_arg = array('action' => $action);
706
707         if ($args) {
708             $args = array_merge($action_arg, $args);
709         } else {
710             $args = $action_arg;
711         }
712
713         $url = $this->m->generate($args, $params, $fragment);
714
715         // Due to a bug in the Net_URL_Mapper code, the returned URL may
716         // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
717         // repair that here rather than modifying the upstream code...
718
719         $qpos = strpos($url, '?');
720         if ($qpos !== false) {
721             $url = substr($url, 0, $qpos+1) .
722               str_replace('?', '&', substr($url, $qpos+1));
723         }
724         return $url;
725     }
726 }