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