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