]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/router.php
Merge branch '0.9.x' into pluginize-twitter-bridge
[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         // In the "root"
75
76         $m->connect('', array('action' => 'public'));
77         $m->connect('rss', array('action' => 'publicrss'));
78         $m->connect('featuredrss', array('action' => 'featuredrss'));
79         $m->connect('favoritedrss', array('action' => 'favoritedrss'));
80         $m->connect('opensearch/people', array('action' => 'opensearch',
81                                                'type' => 'people'));
82         $m->connect('opensearch/notice', array('action' => 'opensearch',
83                                                'type' => 'notice'));
84
85         // docs
86
87         $m->connect('doc/:title', array('action' => 'doc'));
88
89         // facebook
90
91         $m->connect('facebook', array('action' => 'facebookhome'));
92         $m->connect('facebook/index.php', array('action' => 'facebookhome'));
93         $m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
94         $m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
95         $m->connect('facebook/remove', array('action' => 'facebookremove'));
96
97         // main stuff is repetitive
98
99         $main = array('login', 'logout', 'register', 'subscribe',
100                       'unsubscribe', 'confirmaddress', 'recoverpassword',
101                       'invite', 'favor', 'disfavor', 'sup',
102                       'block', 'unblock', 'subedit',
103                       'groupblock', 'groupunblock');
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         // 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         // conversation
189
190         $m->connect('conversation/:id',
191                     array('action' => 'conversation'),
192                     array('id' => '[0-9]+'));
193
194         $m->connect('message/new', array('action' => 'newmessage'));
195         $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
196         $m->connect('message/:message',
197                     array('action' => 'showmessage'),
198                     array('message' => '[0-9]+'));
199
200         $m->connect('user/:id',
201                     array('action' => 'userbyid'),
202                     array('id' => '[0-9]+'));
203
204         $m->connect('tags/', array('action' => 'publictagcloud'));
205         $m->connect('tag/', array('action' => 'publictagcloud'));
206         $m->connect('tags', array('action' => 'publictagcloud'));
207         $m->connect('tag', array('action' => 'publictagcloud'));
208         $m->connect('tag/:tag/rss',
209                     array('action' => 'tagrss'),
210                     array('tag' => '[a-zA-Z0-9]+'));
211         $m->connect('tag/:tag',
212                     array('action' => 'tag'),
213                     array('tag' => '[\pL\pN_\-\.]{1,64}'));
214
215         $m->connect('peopletag/:tag',
216                     array('action' => 'peopletag'),
217                     array('tag' => '[a-zA-Z0-9]+'));
218
219         $m->connect('featured/', array('action' => 'featured'));
220         $m->connect('featured', array('action' => 'featured'));
221         $m->connect('favorited/', array('action' => 'favorited'));
222         $m->connect('favorited', array('action' => 'favorited'));
223
224         // groups
225
226         $m->connect('group/new', array('action' => 'newgroup'));
227
228         foreach (array('edit', 'join', 'leave') as $v) {
229             $m->connect('group/:nickname/'.$v,
230                         array('action' => $v.'group'),
231                         array('nickname' => '[a-zA-Z0-9]+'));
232         }
233
234         foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
235             $m->connect('group/:nickname/'.$n,
236                         array('action' => 'group'.$n),
237                         array('nickname' => '[a-zA-Z0-9]+'));
238         }
239
240         $m->connect('group/:nickname/foaf',
241                     array('action' => 'foafgroup'),
242                     array('nickname' => '[a-zA-Z0-9]+'));
243
244         $m->connect('group/:nickname/blocked',
245                     array('action' => 'blockedfromgroup'),
246                     array('nickname' => '[a-zA-Z0-9]+'));
247
248         $m->connect('group/:nickname/makeadmin',
249                     array('action' => 'makeadmin'),
250                     array('nickname' => '[a-zA-Z0-9]+'));
251
252         $m->connect('group/:id/id',
253                     array('action' => 'groupbyid'),
254                     array('id' => '[0-9]+'));
255
256         $m->connect('group/:nickname',
257                     array('action' => 'showgroup'),
258                     array('nickname' => '[a-zA-Z0-9]+'));
259
260         $m->connect('group/', array('action' => 'groups'));
261         $m->connect('group', array('action' => 'groups'));
262         $m->connect('groups/', array('action' => 'groups'));
263         $m->connect('groups', array('action' => 'groups'));
264
265         // Twitter-compatible API
266
267         // statuses API
268
269         $m->connect('api/statuses/public_timeline.:format',
270                     array('action' => 'ApiTimelinePublic',
271                     'format' => '(xml|json|rss|atom)'));
272
273         $m->connect('api/statuses/friends_timeline.:format',
274                     array('action' => 'ApiTimelineFriends',
275                           'format' => '(xml|json|rss|atom)'));
276
277         $m->connect('api/statuses/friends_timeline/:id.:format',
278                     array('action' => 'ApiTimelineFriends',
279                           'id' => '[a-zA-Z0-9]+',
280                           'format' => '(xml|json|rss|atom)'));
281         $m->connect('api/statuses/home_timeline.:format',
282                     array('action' => 'ApiTimelineFriends',
283                           'format' => '(xml|json|rss|atom)'));
284
285         $m->connect('api/statuses/home_timeline/:id.:format',
286                     array('action' => 'ApiTimelineFriends',
287                           'id' => '[a-zA-Z0-9]+',
288                           'format' => '(xml|json|rss|atom)'));
289
290         $m->connect('api/statuses/user_timeline.:format',
291                     array('action' => 'ApiTimelineUser',
292                     'format' => '(xml|json|rss|atom)'));
293
294         $m->connect('api/statuses/user_timeline/:id.:format',
295                     array('action' => 'ApiTimelineUser',
296                     'id' => '[a-zA-Z0-9]+',
297                     'format' => '(xml|json|rss|atom)'));
298
299         $m->connect('api/statuses/mentions.:format',
300                     array('action' => 'ApiTimelineMentions',
301                     'format' => '(xml|json|rss|atom)'));
302
303         $m->connect('api/statuses/mentions/:id.:format',
304                     array('action' => 'ApiTimelineMentions',
305                     'id' => '[a-zA-Z0-9]+',
306                     'format' => '(xml|json|rss|atom)'));
307
308         $m->connect('api/statuses/replies.:format',
309                     array('action' => 'ApiTimelineMentions',
310                     'format' => '(xml|json|rss|atom)'));
311
312         $m->connect('api/statuses/replies/:id.:format',
313                     array('action' => 'ApiTimelineMentions',
314                     'id' => '[a-zA-Z0-9]+',
315                     'format' => '(xml|json|rss|atom)'));
316
317         $m->connect('api/statuses/friends.:format',
318                      array('action' => 'ApiUserFriends',
319                            'format' => '(xml|json)'));
320
321         $m->connect('api/statuses/friends/:id.:format',
322                     array('action' => 'ApiUserFriends',
323                     'id' => '[a-zA-Z0-9]+',
324                     'format' => '(xml|json)'));
325
326         $m->connect('api/statuses/followers.:format',
327                      array('action' => 'ApiUserFollowers',
328                            'format' => '(xml|json)'));
329
330         $m->connect('api/statuses/followers/:id.:format',
331                     array('action' => 'ApiUserFollowers',
332                     'id' => '[a-zA-Z0-9]+',
333                     'format' => '(xml|json)'));
334
335         $m->connect('api/statuses/show.:format',
336                     array('action' => 'ApiStatusesShow',
337                           'format' => '(xml|json)'));
338
339         $m->connect('api/statuses/show/:id.:format',
340                     array('action' => 'ApiStatusesShow',
341                           'id' => '[0-9]+',
342                           'format' => '(xml|json)'));
343
344         $m->connect('api/statuses/update.:format',
345                     array('action' => 'ApiStatusesUpdate',
346                           'format' => '(xml|json)'));
347
348         $m->connect('api/statuses/destroy.:format',
349                   array('action' => 'ApiStatusesDestroy',
350                         'format' => '(xml|json)'));
351
352         $m->connect('api/statuses/destroy/:id.:format',
353                   array('action' => 'ApiStatusesDestroy',
354                         'id' => '[0-9]+',
355                         'format' => '(xml|json)'));
356
357         // users
358
359         $m->connect('api/users/show/:id.:format',
360                     array('action' => 'ApiUserShow',
361                           'id' => '[a-zA-Z0-9]+',
362                           'format' => '(xml|json)'));
363
364         $m->connect('api/users/:method',
365                     array('action' => 'api',
366                           'apiaction' => 'users'),
367                     array('method' => 'show(\.(xml|json))?'));
368
369         // direct messages
370
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         // special case where verify_credentials is called w/out a format
437
438         $m->connect('api/account/verify_credentials',
439                     array('action' => 'ApiAccountVerifyCredentials'));
440
441         $m->connect('api/account/rate_limit_status.:format',
442                     array('action' => 'ApiAccountRateLimitStatus'));
443
444         // favorites
445
446         $m->connect('api/favorites.:format',
447                     array('action' => 'ApiTimelineFavorites',
448                     'format' => '(xml|json|rss|atom)'));
449
450         $m->connect('api/favorites/:id.:format',
451                     array('action' => 'ApiTimelineFavorites',
452                           'id' => '[a-zA-Z0-9]+',
453                           'format' => '(xmljson|rss|atom)'));
454
455         $m->connect('api/favorites/create/:id.:format',
456                     array('action' => 'ApiFavoriteCreate',
457                           'id' => '[a-zA-Z0-9]+',
458                           'format' => '(xml|json)'));
459
460         $m->connect('api/favorites/destroy/:id.:format',
461                     array('action' => 'ApiFavoriteDestroy',
462                           'id' => '[a-zA-Z0-9]+',
463                           'format' => '(xml|json)'));
464
465         // notifications
466
467         $m->connect('api/notifications/:method/:argument',
468                     array('action' => 'api',
469                           'apiaction' => 'favorites'));
470
471         // blocks
472
473         $m->connect('api/blocks/create/:id.:format',
474                     array('action' => 'ApiBlockCreate',
475                           'id' => '[a-zA-Z0-9]+',
476                           'format' => '(xml|json)'));
477
478         $m->connect('api/blocks/destroy/:id.:format',
479                     array('action' => 'ApiBlockDestroy',
480                           'id' => '[a-zA-Z0-9]+',
481                           'format' => '(xml|json)'));
482         // help
483
484         $m->connect('api/help/test.:format',
485                     array('action' => 'ApiHelpTest',
486                           'format' => '(xml|json)'));
487
488         // statusnet
489
490         $m->connect('api/statusnet/version.:format',
491                     array('action' => 'ApiStatusnetVersion',
492                           'format' => '(xml|json)'));
493
494         $m->connect('api/statusnet/config.:format',
495                     array('action' => 'ApiStatusnetConfig',
496                    'format' => '(xml|json)'));
497
498         // For older methods, we provide "laconica" base action
499
500         $m->connect('api/laconica/version.:format',
501                     array('action' => 'ApiStatusnetVersion',
502                           'format' => '(xml|json)'));
503
504         $m->connect('api/laconica/config.:format',
505                     array('action' => 'ApiStatusnetConfig',
506                     'format' => '(xml|json)'));
507
508         // Groups and tags are newer than 0.8.1 so no backward-compatibility
509         // necessary
510
511         // Groups
512         //'list' has to be handled differently, as php will not allow a method to be named 'list'
513
514         $m->connect('api/statusnet/groups/timeline/:id.:format',
515                     array('action' => 'ApiTimelineGroup',
516                           'id' => '[a-zA-Z0-9]+',
517                           'format' => '(xmljson|rss|atom)'));
518
519         $m->connect('api/statusnet/groups/show.:format',
520                     array('action' => 'ApiGroupShow',
521                     'format' => '(xml|json)'));
522
523         $m->connect('api/statusnet/groups/show/:id.:format',
524                     array('action' => 'ApiGroupShow',
525                           'id' => '[a-zA-Z0-9]+',
526                           'format' => '(xml|json)'));
527
528         $m->connect('api/statusnet/groups/join.:format',
529                     array('action' => 'ApiGroupJoin',
530                           'id' => '[a-zA-Z0-9]+',
531                           'format' => '(xml|json)'));
532
533         $m->connect('api/statusnet/groups/join/:id.:format',
534                     array('action' => 'ApiGroupJoin',
535                     'format' => '(xml|json)'));
536
537         $m->connect('api/statusnet/groups/leave.:format',
538                     array('action' => 'ApiGroupLeave',
539                           'id' => '[a-zA-Z0-9]+',
540                           'format' => '(xml|json)'));
541
542         $m->connect('api/statusnet/groups/leave/:id.:format',
543                     array('action' => 'ApiGroupLeave',
544                           'format' => '(xml|json)'));
545
546         $m->connect('api/statusnet/groups/is_member.:format',
547                     array('action' => 'ApiGroupIsMember',
548                           'format' => '(xml|json)'));
549
550         $m->connect('api/statusnet/groups/list.:format',
551                     array('action' => 'ApiGroupList',
552                           'format' => '(xml|json|rss|atom)'));
553
554         $m->connect('api/statusnet/groups/list/:id.:format',
555                     array('action' => 'ApiGroupList',
556                           'id' => '[a-zA-Z0-9]+',
557                           'format' => '(xml|json|rss|atom)'));
558
559         $m->connect('api/statusnet/groups/list_all.:format',
560                     array('action' => 'ApiGroupListAll',
561                           'format' => '(xml|json|rss|atom)'));
562
563         $m->connect('api/statusnet/groups/membership.:format',
564                     array('action' => 'ApiGroupMembership',
565                          'format' => '(xml|json)'));
566
567         $m->connect('api/statusnet/groups/membership/:id.:format',
568                     array('action' => 'ApiGroupMembership',
569                            'id' => '[a-zA-Z0-9]+',
570                            'format' => '(xml|json)'));
571                            
572         $m->connect('api/statusnet/groups/create.:format',
573                     array('action' => 'ApiGroupCreate',
574                           'format' => '(xml|json)'));
575         // Tags
576         $m->connect('api/statusnet/tags/timeline/:tag.:format',
577                     array('action' => 'ApiTimelineTag',
578                           'format' => '(xmljson|rss|atom)'));
579
580         // search
581         $m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
582         $m->connect('api/search.json', array('action' => 'twitapisearchjson'));
583         $m->connect('api/trends.json', array('action' => 'twitapitrends'));
584
585         // user stuff
586
587         foreach (array('subscriptions', 'subscribers',
588                        'nudge', 'all', 'foaf', 'xrds',
589                        'replies', 'inbox', 'outbox', 'microsummary') as $a) {
590             $m->connect(':nickname/'.$a,
591                         array('action' => $a),
592                         array('nickname' => '[a-zA-Z0-9]{1,64}'));
593         }
594
595         foreach (array('subscriptions', 'subscribers') as $a) {
596             $m->connect(':nickname/'.$a.'/:tag',
597                         array('action' => $a),
598                         array('tag' => '[a-zA-Z0-9]+',
599                               'nickname' => '[a-zA-Z0-9]{1,64}'));
600         }
601
602         foreach (array('rss', 'groups') as $a) {
603             $m->connect(':nickname/'.$a,
604                         array('action' => 'user'.$a),
605                         array('nickname' => '[a-zA-Z0-9]{1,64}'));
606         }
607
608         foreach (array('all', 'replies', 'favorites') as $a) {
609             $m->connect(':nickname/'.$a.'/rss',
610                         array('action' => $a.'rss'),
611                         array('nickname' => '[a-zA-Z0-9]{1,64}'));
612         }
613
614         $m->connect(':nickname/favorites',
615                     array('action' => 'showfavorites'),
616                     array('nickname' => '[a-zA-Z0-9]{1,64}'));
617
618         $m->connect(':nickname/avatar/:size',
619                     array('action' => 'avatarbynickname'),
620                     array('size' => '(original|96|48|24)',
621                           'nickname' => '[a-zA-Z0-9]{1,64}'));
622
623         $m->connect(':nickname/tag/:tag/rss',
624             array('action' => 'userrss'),
625             array('nickname' => '[a-zA-Z0-9]{1,64}'),
626             array('tag' => '[a-zA-Z0-9]+'));
627
628         $m->connect(':nickname/tag/:tag',
629                     array('action' => 'showstream'),
630                     array('nickname' => '[a-zA-Z0-9]{1,64}'),
631                     array('tag' => '[a-zA-Z0-9]+'));
632
633         $m->connect(':nickname',
634                     array('action' => 'showstream'),
635                     array('nickname' => '[a-zA-Z0-9]{1,64}'));
636
637         Event::handle('RouterInitialized', array($m));
638
639         return $m;
640     }
641
642     function map($path)
643     {
644         try {
645             $match = $this->m->match($path);
646         } catch (Net_URL_Mapper_InvalidException $e) {
647             common_log(LOG_ERR, "Problem getting route for $path - " .
648                        $e->getMessage());
649             $cac = new ClientErrorAction("Page not found.", 404);
650             $cac->showPage();
651         }
652
653         return $match;
654     }
655
656     function build($action, $args=null, $params=null, $fragment=null)
657     {
658         $action_arg = array('action' => $action);
659
660         if ($args) {
661             $args = array_merge($action_arg, $args);
662         } else {
663             $args = $action_arg;
664         }
665
666         $url = $this->m->generate($args, $params, $fragment);
667
668         // Due to a bug in the Net_URL_Mapper code, the returned URL may
669         // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
670         // repair that here rather than modifying the upstream code...
671
672         $qpos = strpos($url, '?');
673         if ($qpos !== false) {
674             $url = substr($url, 0, $qpos+1) .
675               str_replace('?', '&', substr($url, $qpos+1));
676         }
677         return $url;
678     }
679 }