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