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