]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/router.php
Added 'login' command that gives you a link that can be used to login to the website
[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             // special case where verify_credentials is called w/out a format
432
433             $m->connect('api/account/verify_credentials',
434                         array('action' => 'ApiAccountVerifyCredentials'));
435
436             $m->connect('api/account/rate_limit_status.:format',
437                         array('action' => 'ApiAccountRateLimitStatus'));
438
439             // favorites
440
441             $m->connect('api/favorites.:format',
442                         array('action' => 'ApiTimelineFavorites',
443                               'format' => '(xml|json|rss|atom)'));
444
445             $m->connect('api/favorites/:id.:format',
446                         array('action' => 'ApiTimelineFavorites',
447                               'id' => '[a-zA-Z0-9]+',
448                               'format' => '(xmljson|rss|atom)'));
449
450             $m->connect('api/favorites/create/:id.:format',
451                         array('action' => 'ApiFavoriteCreate',
452                               'id' => '[a-zA-Z0-9]+',
453                               'format' => '(xml|json)'));
454
455             $m->connect('api/favorites/destroy/:id.:format',
456                         array('action' => 'ApiFavoriteDestroy',
457                               'id' => '[a-zA-Z0-9]+',
458                               'format' => '(xml|json)'));
459             // blocks
460
461             $m->connect('api/blocks/create/:id.:format',
462                         array('action' => 'ApiBlockCreate',
463                               'id' => '[a-zA-Z0-9]+',
464                               'format' => '(xml|json)'));
465
466             $m->connect('api/blocks/destroy/:id.:format',
467                         array('action' => 'ApiBlockDestroy',
468                               'id' => '[a-zA-Z0-9]+',
469                               'format' => '(xml|json)'));
470             // help
471
472             $m->connect('api/help/test.:format',
473                         array('action' => 'ApiHelpTest',
474                               'format' => '(xml|json)'));
475
476             // statusnet
477
478             $m->connect('api/statusnet/version.:format',
479                         array('action' => 'ApiStatusnetVersion',
480                               'format' => '(xml|json)'));
481
482             $m->connect('api/statusnet/config.:format',
483                         array('action' => 'ApiStatusnetConfig',
484                               'format' => '(xml|json)'));
485
486             // For older methods, we provide "laconica" base action
487
488             $m->connect('api/laconica/version.:format',
489                         array('action' => 'ApiStatusnetVersion',
490                               'format' => '(xml|json)'));
491
492             $m->connect('api/laconica/config.:format',
493                         array('action' => 'ApiStatusnetConfig',
494                               'format' => '(xml|json)'));
495
496             // Groups and tags are newer than 0.8.1 so no backward-compatibility
497             // necessary
498
499             // Groups
500             //'list' has to be handled differently, as php will not allow a method to be named 'list'
501
502             $m->connect('api/statusnet/groups/timeline/:id.:format',
503                         array('action' => 'ApiTimelineGroup',
504                               'id' => '[a-zA-Z0-9]+',
505                               'format' => '(xmljson|rss|atom)'));
506
507             $m->connect('api/statusnet/groups/show.:format',
508                         array('action' => 'ApiGroupShow',
509                               'format' => '(xml|json)'));
510
511             $m->connect('api/statusnet/groups/show/:id.:format',
512                         array('action' => 'ApiGroupShow',
513                               'id' => '[a-zA-Z0-9]+',
514                               'format' => '(xml|json)'));
515
516             $m->connect('api/statusnet/groups/join.:format',
517                         array('action' => 'ApiGroupJoin',
518                               'id' => '[a-zA-Z0-9]+',
519                               'format' => '(xml|json)'));
520
521             $m->connect('api/statusnet/groups/join/:id.:format',
522                         array('action' => 'ApiGroupJoin',
523                               'format' => '(xml|json)'));
524
525             $m->connect('api/statusnet/groups/leave.:format',
526                         array('action' => 'ApiGroupLeave',
527                               'id' => '[a-zA-Z0-9]+',
528                               'format' => '(xml|json)'));
529
530             $m->connect('api/statusnet/groups/leave/:id.:format',
531                         array('action' => 'ApiGroupLeave',
532                               'format' => '(xml|json)'));
533
534             $m->connect('api/statusnet/groups/is_member.:format',
535                         array('action' => 'ApiGroupIsMember',
536                               'format' => '(xml|json)'));
537
538             $m->connect('api/statusnet/groups/list.:format',
539                         array('action' => 'ApiGroupList',
540                               'format' => '(xml|json|rss|atom)'));
541
542             $m->connect('api/statusnet/groups/list/:id.:format',
543                         array('action' => 'ApiGroupList',
544                               'id' => '[a-zA-Z0-9]+',
545                               'format' => '(xml|json|rss|atom)'));
546
547             $m->connect('api/statusnet/groups/list_all.:format',
548                         array('action' => 'ApiGroupListAll',
549                               'format' => '(xml|json|rss|atom)'));
550
551             $m->connect('api/statusnet/groups/membership.:format',
552                         array('action' => 'ApiGroupMembership',
553                               'format' => '(xml|json)'));
554
555             $m->connect('api/statusnet/groups/membership/:id.:format',
556                         array('action' => 'ApiGroupMembership',
557                               'id' => '[a-zA-Z0-9]+',
558                               'format' => '(xml|json)'));
559
560             $m->connect('api/statusnet/groups/create.:format',
561                         array('action' => 'ApiGroupCreate',
562                               'format' => '(xml|json)'));
563             // Tags
564             $m->connect('api/statusnet/tags/timeline/:tag.:format',
565                         array('action' => 'ApiTimelineTag',
566                               'format' => '(xmljson|rss|atom)'));
567
568             // search
569             $m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
570             $m->connect('api/search.json', array('action' => 'twitapisearchjson'));
571             $m->connect('api/trends.json', array('action' => 'twitapitrends'));
572
573             $m->connect('getfile/:filename',
574                         array('action' => 'getfile'),
575                         array('filename' => '[A-Za-z0-9._-]+'));
576
577             // user stuff
578
579             foreach (array('subscriptions', 'subscribers',
580                            'nudge', 'all', 'foaf', 'xrds',
581                            'replies', 'inbox', 'outbox', 'microsummary') as $a) {
582                 $m->connect(':nickname/'.$a,
583                             array('action' => $a),
584                             array('nickname' => '[a-zA-Z0-9]{1,64}'));
585             }
586
587             foreach (array('subscriptions', 'subscribers') as $a) {
588                 $m->connect(':nickname/'.$a.'/:tag',
589                             array('action' => $a),
590                             array('tag' => '[a-zA-Z0-9]+',
591                                   'nickname' => '[a-zA-Z0-9]{1,64}'));
592             }
593
594             foreach (array('rss', 'groups') as $a) {
595                 $m->connect(':nickname/'.$a,
596                             array('action' => 'user'.$a),
597                             array('nickname' => '[a-zA-Z0-9]{1,64}'));
598             }
599
600             foreach (array('all', 'replies', 'favorites') as $a) {
601                 $m->connect(':nickname/'.$a.'/rss',
602                             array('action' => $a.'rss'),
603                             array('nickname' => '[a-zA-Z0-9]{1,64}'));
604             }
605
606             $m->connect(':nickname/favorites',
607                         array('action' => 'showfavorites'),
608                         array('nickname' => '[a-zA-Z0-9]{1,64}'));
609
610             $m->connect(':nickname/avatar/:size',
611                         array('action' => 'avatarbynickname'),
612                         array('size' => '(original|96|48|24)',
613                               'nickname' => '[a-zA-Z0-9]{1,64}'));
614
615             $m->connect(':nickname/tag/:tag/rss',
616                         array('action' => 'userrss'),
617                         array('nickname' => '[a-zA-Z0-9]{1,64}'),
618                         array('tag' => '[a-zA-Z0-9]+'));
619
620             $m->connect(':nickname/tag/:tag',
621                         array('action' => 'showstream'),
622                         array('nickname' => '[a-zA-Z0-9]{1,64}'),
623                         array('tag' => '[a-zA-Z0-9]+'));
624
625             $m->connect(':nickname',
626                         array('action' => 'showstream'),
627                         array('nickname' => '[a-zA-Z0-9]{1,64}'));
628
629             Event::handle('RouterInitialized', array($m));
630         }
631
632         return $m;
633     }
634
635     function map($path)
636     {
637         try {
638             $match = $this->m->match($path);
639         } catch (Net_URL_Mapper_InvalidException $e) {
640             common_log(LOG_ERR, "Problem getting route for $path - " .
641                        $e->getMessage());
642             $cac = new ClientErrorAction("Page not found.", 404);
643             $cac->showPage();
644         }
645
646         return $match;
647     }
648
649     function build($action, $args=null, $params=null, $fragment=null)
650     {
651         $action_arg = array('action' => $action);
652
653         if ($args) {
654             $args = array_merge($action_arg, $args);
655         } else {
656             $args = $action_arg;
657         }
658
659         $url = $this->m->generate($args, $params, $fragment);
660
661         // Due to a bug in the Net_URL_Mapper code, the returned URL may
662         // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
663         // repair that here rather than modifying the upstream code...
664
665         $qpos = strpos($url, '?');
666         if ($qpos !== false) {
667             $url = substr($url, 0, $qpos+1) .
668               str_replace('?', '&', substr($url, $qpos+1));
669         }
670         return $url;
671     }
672 }