]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/router.php
2fd255fe6ff6161ad0f486f09f58410cd180adaa
[quix0rs-gnu-social.git] / lib / router.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * URL routing utilities
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  URL
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once 'Net/URL/Mapper.php';
35
36 /**
37  * URL Router
38  *
39  * Cheap wrapper around Net_URL_Mapper
40  *
41  * @category URL
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47
48 class Router
49 {
50     var $m = null;
51     static $inst = null;
52     static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
53                          'postnotice', 'updateprofile', 'finishremotesubscribe');
54
55     static function get()
56     {
57         if (!Router::$inst) {
58             Router::$inst = new Router();
59         }
60         return Router::$inst;
61     }
62
63     function __construct()
64     {
65         if (!$this->m) {
66             $this->m = $this->initialize();
67         }
68     }
69
70     function initialize()
71     {
72         $m = Net_URL_Mapper::getInstance();
73
74         if (Event::handle('StartInitializeRouter', array(&$m))) {
75
76             // In the "root"
77
78             $m->connect('', array('action' => 'public'));
79             $m->connect('rss', array('action' => 'publicrss'));
80             $m->connect('featuredrss', array('action' => 'featuredrss'));
81             $m->connect('favoritedrss', array('action' => 'favoritedrss'));
82             $m->connect('opensearch/people', array('action' => 'opensearch',
83                                                    'type' => 'people'));
84             $m->connect('opensearch/notice', array('action' => 'opensearch',
85                                                    'type' => 'notice'));
86
87             // docs
88
89             $m->connect('doc/:title', array('action' => 'doc'));
90
91             // main stuff is repetitive
92
93             $main = array('login', 'logout', 'register', 'subscribe',
94                           'unsubscribe', 'confirmaddress', 'recoverpassword',
95                           'invite', 'favor', 'disfavor', 'sup',
96                           'block', 'unblock', 'subedit',
97                           'groupblock', 'groupunblock');
98
99             foreach ($main as $a) {
100                 $m->connect('main/'.$a, array('action' => $a));
101             }
102
103             $m->connect('main/sup/:seconds', array('action' => 'sup'),
104                         array('seconds' => '[0-9]+'));
105
106             $m->connect('main/tagother/:id', array('action' => 'tagother'));
107
108             $m->connect('main/oembed',
109                         array('action' => 'oembed'));
110
111             // these take a code
112
113             foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
114                 $m->connect('main/'.$c.'/:code', array('action' => $c));
115             }
116
117             // exceptional
118
119             $m->connect('main/remote', array('action' => 'remotesubscribe'));
120             $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
121
122             foreach (Router::$bare as $action) {
123                 $m->connect('index.php?action=' . $action, array('action' => $action));
124             }
125
126             // settings
127
128             foreach (array('profile', 'avatar', 'password', 'im',
129                            'email', 'sms', 'userdesign', 'other') as $s) {
130                 $m->connect('settings/'.$s, array('action' => $s.'settings'));
131             }
132
133             // search
134
135             foreach (array('group', 'people', 'notice') as $s) {
136                 $m->connect('search/'.$s, array('action' => $s.'search'));
137                 $m->connect('search/'.$s.'?q=:q',
138                             array('action' => $s.'search'),
139                             array('q' => '.+'));
140             }
141
142             // The second of these is needed to make the link work correctly
143             // when inserted into the page. The first is needed to match the
144             // route on the way in. Seems to be another Net_URL_Mapper bug to me.
145             $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
146             $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
147                         array('q' => '.+'));
148
149             $m->connect('attachment/:attachment',
150                         array('action' => 'attachment'),
151                         array('attachment' => '[0-9]+'));
152
153             $m->connect('attachment/:attachment/ajax',
154                         array('action' => 'attachment_ajax'),
155                         array('attachment' => '[0-9]+'));
156
157             $m->connect('attachment/:attachment/thumbnail',
158                         array('action' => 'attachment_thumbnail'),
159                         array('attachment' => '[0-9]+'));
160
161             $m->connect('notice/new', array('action' => 'newnotice'));
162             $m->connect('notice/new?replyto=:replyto',
163                         array('action' => 'newnotice'),
164                         array('replyto' => '[A-Za-z0-9_-]+'));
165             $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
166                         array('action' => 'newnotice'),
167                         array('replyto' => '[A-Za-z0-9_-]+'),
168                         array('inreplyto' => '[0-9]+'));
169
170             $m->connect('notice/:notice/file',
171                         array('action' => 'file'),
172                         array('notice' => '[0-9]+'));
173
174             $m->connect('notice/:notice',
175                         array('action' => 'shownotice'),
176                         array('notice' => '[0-9]+'));
177             $m->connect('notice/delete', array('action' => 'deletenotice'));
178             $m->connect('notice/delete/:notice',
179                         array('action' => 'deletenotice'),
180                         array('notice' => '[0-9]+'));
181
182             $m->connect('bookmarklet/new', array('action' => 'bookmarklet'));
183
184             // conversation
185
186             $m->connect('conversation/:id',
187                         array('action' => 'conversation'),
188                         array('id' => '[0-9]+'));
189
190             $m->connect('message/new', array('action' => 'newmessage'));
191             $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
192             $m->connect('message/:message',
193                         array('action' => 'showmessage'),
194                         array('message' => '[0-9]+'));
195
196             $m->connect('user/:id',
197                         array('action' => 'userbyid'),
198                         array('id' => '[0-9]+'));
199
200             $m->connect('tags/', array('action' => 'publictagcloud'));
201             $m->connect('tag/', array('action' => 'publictagcloud'));
202             $m->connect('tags', array('action' => 'publictagcloud'));
203             $m->connect('tag', array('action' => 'publictagcloud'));
204             $m->connect('tag/:tag/rss',
205                         array('action' => 'tagrss'),
206                         array('tag' => '[a-zA-Z0-9]+'));
207             $m->connect('tag/:tag',
208                         array('action' => 'tag'),
209                         array('tag' => '[\pL\pN_\-\.]{1,64}'));
210
211             $m->connect('peopletag/:tag',
212                         array('action' => 'peopletag'),
213                         array('tag' => '[a-zA-Z0-9]+'));
214
215             $m->connect('featured/', array('action' => 'featured'));
216             $m->connect('featured', array('action' => 'featured'));
217             $m->connect('favorited/', array('action' => 'favorited'));
218             $m->connect('favorited', array('action' => 'favorited'));
219
220             // groups
221
222             $m->connect('group/new', array('action' => 'newgroup'));
223
224             foreach (array('edit', 'join', 'leave') as $v) {
225                 $m->connect('group/:nickname/'.$v,
226                             array('action' => $v.'group'),
227                             array('nickname' => '[a-zA-Z0-9]+'));
228             }
229
230             foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
231                 $m->connect('group/:nickname/'.$n,
232                             array('action' => 'group'.$n),
233                             array('nickname' => '[a-zA-Z0-9]+'));
234             }
235
236             $m->connect('group/:nickname/foaf',
237                         array('action' => 'foafgroup'),
238                         array('nickname' => '[a-zA-Z0-9]+'));
239
240             $m->connect('group/:nickname/blocked',
241                         array('action' => 'blockedfromgroup'),
242                         array('nickname' => '[a-zA-Z0-9]+'));
243
244             $m->connect('group/:nickname/makeadmin',
245                         array('action' => 'makeadmin'),
246                         array('nickname' => '[a-zA-Z0-9]+'));
247
248             $m->connect('group/:id/id',
249                         array('action' => 'groupbyid'),
250                         array('id' => '[0-9]+'));
251
252             $m->connect('group/:nickname',
253                         array('action' => 'showgroup'),
254                         array('nickname' => '[a-zA-Z0-9]+'));
255
256             $m->connect('group/', array('action' => 'groups'));
257             $m->connect('group', array('action' => 'groups'));
258             $m->connect('groups/', array('action' => 'groups'));
259             $m->connect('groups', array('action' => 'groups'));
260
261             // Twitter-compatible API
262
263             // statuses API
264
265             $m->connect('api/statuses/public_timeline.:format',
266                         array('action' => 'ApiTimelinePublic',
267                               'format' => '(xml|json|rss|atom)'));
268
269             $m->connect('api/statuses/friends_timeline.:format',
270                         array('action' => 'ApiTimelineFriends',
271                               'format' => '(xml|json|rss|atom)'));
272
273             $m->connect('api/statuses/friends_timeline/:id.:format',
274                         array('action' => 'ApiTimelineFriends',
275                               'id' => '[a-zA-Z0-9]+',
276                               'format' => '(xml|json|rss|atom)'));
277             $m->connect('api/statuses/home_timeline.:format',
278                         array('action' => 'ApiTimelineFriends',
279                               'format' => '(xml|json|rss|atom)'));
280
281             $m->connect('api/statuses/home_timeline/:id.:format',
282                         array('action' => 'ApiTimelineFriends',
283                               'id' => '[a-zA-Z0-9]+',
284                               'format' => '(xml|json|rss|atom)'));
285
286             $m->connect('api/statuses/user_timeline.:format',
287                         array('action' => 'ApiTimelineUser',
288                               'format' => '(xml|json|rss|atom)'));
289
290             $m->connect('api/statuses/user_timeline/:id.:format',
291                         array('action' => 'ApiTimelineUser',
292                               'id' => '[a-zA-Z0-9]+',
293                               'format' => '(xml|json|rss|atom)'));
294
295             $m->connect('api/statuses/mentions.:format',
296                         array('action' => 'ApiTimelineMentions',
297                               'format' => '(xml|json|rss|atom)'));
298
299             $m->connect('api/statuses/mentions/:id.:format',
300                         array('action' => 'ApiTimelineMentions',
301                               'id' => '[a-zA-Z0-9]+',
302                               'format' => '(xml|json|rss|atom)'));
303
304             $m->connect('api/statuses/replies.:format',
305                         array('action' => 'ApiTimelineMentions',
306                               'format' => '(xml|json|rss|atom)'));
307
308             $m->connect('api/statuses/replies/:id.:format',
309                         array('action' => 'ApiTimelineMentions',
310                               'id' => '[a-zA-Z0-9]+',
311                               'format' => '(xml|json|rss|atom)'));
312
313             $m->connect('api/statuses/friends.:format',
314                         array('action' => 'ApiUserFriends',
315                               'format' => '(xml|json)'));
316
317             $m->connect('api/statuses/friends/:id.:format',
318                         array('action' => 'ApiUserFriends',
319                               'id' => '[a-zA-Z0-9]+',
320                               'format' => '(xml|json)'));
321
322             $m->connect('api/statuses/followers.:format',
323                         array('action' => 'ApiUserFollowers',
324                               'format' => '(xml|json)'));
325
326             $m->connect('api/statuses/followers/:id.:format',
327                         array('action' => 'ApiUserFollowers',
328                               'id' => '[a-zA-Z0-9]+',
329                               'format' => '(xml|json)'));
330
331             $m->connect('api/statuses/show.:format',
332                         array('action' => 'ApiStatusesShow',
333                               'format' => '(xml|json)'));
334
335             $m->connect('api/statuses/show/:id.:format',
336                         array('action' => 'ApiStatusesShow',
337                               'id' => '[0-9]+',
338                               'format' => '(xml|json)'));
339
340             $m->connect('api/statuses/update.:format',
341                         array('action' => 'ApiStatusesUpdate',
342                               'format' => '(xml|json)'));
343
344             $m->connect('api/statuses/destroy.:format',
345                         array('action' => 'ApiStatusesDestroy',
346                               'format' => '(xml|json)'));
347
348             $m->connect('api/statuses/destroy/:id.:format',
349                         array('action' => 'ApiStatusesDestroy',
350                               'id' => '[0-9]+',
351                               'format' => '(xml|json)'));
352
353             // users
354
355             $m->connect('api/users/show/:id.:format',
356                         array('action' => 'ApiUserShow',
357                               'id' => '[a-zA-Z0-9]+',
358                               'format' => '(xml|json)'));
359
360             $m->connect('api/users/:method',
361                         array('action' => 'api',
362                               'apiaction' => 'users'),
363                         array('method' => 'show(\.(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
460             // notifications
461
462             $m->connect('api/notifications/:method/:argument',
463                         array('action' => 'api',
464                               'apiaction' => 'favorites'));
465
466             // blocks
467
468             $m->connect('api/blocks/create/:id.:format',
469                         array('action' => 'ApiBlockCreate',
470                               'id' => '[a-zA-Z0-9]+',
471                               'format' => '(xml|json)'));
472
473             $m->connect('api/blocks/destroy/:id.:format',
474                         array('action' => 'ApiBlockDestroy',
475                               'id' => '[a-zA-Z0-9]+',
476                               'format' => '(xml|json)'));
477             // help
478
479             $m->connect('api/help/test.:format',
480                         array('action' => 'ApiHelpTest',
481                               'format' => '(xml|json)'));
482
483             // statusnet
484
485             $m->connect('api/statusnet/version.:format',
486                         array('action' => 'ApiStatusnetVersion',
487                               'format' => '(xml|json)'));
488
489             $m->connect('api/statusnet/config.:format',
490                         array('action' => 'ApiStatusnetConfig',
491                               'format' => '(xml|json)'));
492
493             // For older methods, we provide "laconica" base action
494
495             $m->connect('api/laconica/version.:format',
496                         array('action' => 'ApiStatusnetVersion',
497                               'format' => '(xml|json)'));
498
499             $m->connect('api/laconica/config.:format',
500                         array('action' => 'ApiStatusnetConfig',
501                               'format' => '(xml|json)'));
502
503             // Groups and tags are newer than 0.8.1 so no backward-compatibility
504             // necessary
505
506             // Groups
507             //'list' has to be handled differently, as php will not allow a method to be named 'list'
508
509             $m->connect('api/statusnet/groups/timeline/:id.:format',
510                         array('action' => 'ApiTimelineGroup',
511                               'id' => '[a-zA-Z0-9]+',
512                               'format' => '(xmljson|rss|atom)'));
513
514             $m->connect('api/statusnet/groups/show.:format',
515                         array('action' => 'ApiGroupShow',
516                               'format' => '(xml|json)'));
517
518             $m->connect('api/statusnet/groups/show/:id.:format',
519                         array('action' => 'ApiGroupShow',
520                               'id' => '[a-zA-Z0-9]+',
521                               'format' => '(xml|json)'));
522
523             $m->connect('api/statusnet/groups/join.:format',
524                         array('action' => 'ApiGroupJoin',
525                               'id' => '[a-zA-Z0-9]+',
526                               'format' => '(xml|json)'));
527
528             $m->connect('api/statusnet/groups/join/:id.:format',
529                         array('action' => 'ApiGroupJoin',
530                               'format' => '(xml|json)'));
531
532             $m->connect('api/statusnet/groups/leave.:format',
533                         array('action' => 'ApiGroupLeave',
534                               'id' => '[a-zA-Z0-9]+',
535                               'format' => '(xml|json)'));
536
537             $m->connect('api/statusnet/groups/leave/:id.:format',
538                         array('action' => 'ApiGroupLeave',
539                               'format' => '(xml|json)'));
540
541             $m->connect('api/statusnet/groups/is_member.:format',
542                         array('action' => 'ApiGroupIsMember',
543                               'format' => '(xml|json)'));
544
545             $m->connect('api/statusnet/groups/list.:format',
546                         array('action' => 'ApiGroupList',
547                               'format' => '(xml|json|rss|atom)'));
548
549             $m->connect('api/statusnet/groups/list/:id.:format',
550                         array('action' => 'ApiGroupList',
551                               'id' => '[a-zA-Z0-9]+',
552                               'format' => '(xml|json|rss|atom)'));
553
554             $m->connect('api/statusnet/groups/list_all.:format',
555                         array('action' => 'ApiGroupListAll',
556                               'format' => '(xml|json|rss|atom)'));
557
558             $m->connect('api/statusnet/groups/membership.:format',
559                         array('action' => 'ApiGroupMembership',
560                               'format' => '(xml|json)'));
561
562             $m->connect('api/statusnet/groups/membership/:id.:format',
563                         array('action' => 'ApiGroupMembership',
564                               'id' => '[a-zA-Z0-9]+',
565                               'format' => '(xml|json)'));
566
567             $m->connect('api/statusnet/groups/create.:format',
568                         array('action' => 'ApiGroupCreate',
569                               'format' => '(xml|json)'));
570             // Tags
571             $m->connect('api/statusnet/tags/timeline/:tag.:format',
572                         array('action' => 'ApiTimelineTag',
573                               'format' => '(xmljson|rss|atom)'));
574
575             // search
576             $m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
577             $m->connect('api/search.json', array('action' => 'twitapisearchjson'));
578             $m->connect('api/trends.json', array('action' => 'twitapitrends'));
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 }