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