]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/router.php
cf5c06b26fbde7d6c86421f386ce688df7efa666
[quix0rs-gnu-social.git] / lib / router.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * URL routing utilities
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  URL
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once 'Net/URL/Mapper.php';
35
36 /**
37  * URL Router
38  *
39  * Cheap wrapper around Net_URL_Mapper
40  *
41  * @category URL
42  * @package  StatusNet
43  * @author   Evan Prodromou <evan@status.net>
44  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45  * @link     http://status.net/
46  */
47
48 class Router
49 {
50     var $m = null;
51     static $inst = null;
52     static $bare = array('requesttoken', 'accesstoken', 'userauthorization',
53                          'postnotice', 'updateprofile', 'finishremotesubscribe');
54
55     static function get()
56     {
57         if (!Router::$inst) {
58             Router::$inst = new Router();
59         }
60         return Router::$inst;
61     }
62
63     function __construct()
64     {
65         if (!$this->m) {
66             $this->m = $this->initialize();
67         }
68     }
69
70     function initialize()
71     {
72         $m = Net_URL_Mapper::getInstance();
73
74         // In the "root"
75
76         $m->connect('', array('action' => 'public'));
77         $m->connect('rss', array('action' => 'publicrss'));
78         $m->connect('featuredrss', array('action' => 'featuredrss'));
79         $m->connect('favoritedrss', array('action' => 'favoritedrss'));
80         $m->connect('opensearch/people', array('action' => 'opensearch',
81                                                'type' => 'people'));
82         $m->connect('opensearch/notice', array('action' => 'opensearch',
83                                                'type' => 'notice'));
84
85         // docs
86
87         $m->connect('doc/:title', array('action' => 'doc'));
88
89         // Twitter
90
91         $m->connect('twitter/authorization', array('action' => 'twitterauthorization'));
92
93         // facebook
94
95         $m->connect('facebook', array('action' => 'facebookhome'));
96         $m->connect('facebook/index.php', array('action' => 'facebookhome'));
97         $m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
98         $m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
99         $m->connect('facebook/remove', array('action' => 'facebookremove'));
100
101         // main stuff is repetitive
102
103         $main = array('login', 'logout', 'register', 'subscribe',
104                       'unsubscribe', 'confirmaddress', 'recoverpassword',
105                       'invite', 'favor', 'disfavor', 'sup',
106                       'block', 'unblock', 'subedit',
107                       'groupblock', 'groupunblock');
108
109         foreach ($main as $a) {
110             $m->connect('main/'.$a, array('action' => $a));
111         }
112
113         $m->connect('main/sup/:seconds', array('action' => 'sup'),
114                     array('seconds' => '[0-9]+'));
115
116         $m->connect('main/tagother/:id', array('action' => 'tagother'));
117
118         $m->connect('main/oembed',
119                     array('action' => 'oembed'));
120
121         // these take a code
122
123         foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
124             $m->connect('main/'.$c.'/:code', array('action' => $c));
125         }
126
127         // exceptional
128
129         $m->connect('main/remote', array('action' => 'remotesubscribe'));
130         $m->connect('main/remote?nickname=:nickname', array('action' => 'remotesubscribe'), array('nickname' => '[A-Za-z0-9_-]+'));
131
132         foreach (Router::$bare as $action) {
133             $m->connect('index.php?action=' . $action, array('action' => $action));
134         }
135
136         // settings
137
138         foreach (array('profile', 'avatar', 'password', 'im',
139                        'email', 'sms', 'twitter', 'userdesign', 'other') as $s) {
140             $m->connect('settings/'.$s, array('action' => $s.'settings'));
141         }
142
143         // search
144
145         foreach (array('group', 'people', 'notice') as $s) {
146             $m->connect('search/'.$s, array('action' => $s.'search'));
147             $m->connect('search/'.$s.'?q=:q',
148                         array('action' => $s.'search'),
149                         array('q' => '.+'));
150         }
151
152         // The second of these is needed to make the link work correctly
153         // when inserted into the page. The first is needed to match the
154         // route on the way in. Seems to be another Net_URL_Mapper bug to me.
155         $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
156         $m->connect('search/notice/rss?q=:q', array('action' => 'noticesearchrss'),
157                     array('q' => '.+'));
158
159         $m->connect('attachment/:attachment',
160                     array('action' => 'attachment'),
161                     array('attachment' => '[0-9]+'));
162
163         $m->connect('attachment/:attachment/ajax',
164                     array('action' => 'attachment_ajax'),
165                     array('attachment' => '[0-9]+'));
166
167         $m->connect('attachment/:attachment/thumbnail',
168                     array('action' => 'attachment_thumbnail'),
169                     array('attachment' => '[0-9]+'));
170
171         $m->connect('notice/new', array('action' => 'newnotice'));
172         $m->connect('notice/new?replyto=:replyto',
173                     array('action' => 'newnotice'),
174                     array('replyto' => '[A-Za-z0-9_-]+'));
175         $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto',
176                     array('action' => 'newnotice'),
177                     array('replyto' => '[A-Za-z0-9_-]+'),
178                     array('inreplyto' => '[0-9]+'));
179
180         $m->connect('notice/:notice/file',
181             array('action' => 'file'),
182             array('notice' => '[0-9]+'));
183
184         $m->connect('notice/:notice',
185                     array('action' => 'shownotice'),
186                     array('notice' => '[0-9]+'));
187         $m->connect('notice/delete', array('action' => 'deletenotice'));
188         $m->connect('notice/delete/:notice',
189                     array('action' => 'deletenotice'),
190                     array('notice' => '[0-9]+'));
191
192         // conversation
193
194         $m->connect('conversation/:id',
195                     array('action' => 'conversation'),
196                     array('id' => '[0-9]+'));
197
198         $m->connect('message/new', array('action' => 'newmessage'));
199         $m->connect('message/new?to=:to', array('action' => 'newmessage'), array('to' => '[A-Za-z0-9_-]+'));
200         $m->connect('message/:message',
201                     array('action' => 'showmessage'),
202                     array('message' => '[0-9]+'));
203
204         $m->connect('user/:id',
205                     array('action' => 'userbyid'),
206                     array('id' => '[0-9]+'));
207
208         $m->connect('tags/', array('action' => 'publictagcloud'));
209         $m->connect('tag/', array('action' => 'publictagcloud'));
210         $m->connect('tags', array('action' => 'publictagcloud'));
211         $m->connect('tag', array('action' => 'publictagcloud'));
212         $m->connect('tag/:tag/rss',
213                     array('action' => 'tagrss'),
214                     array('tag' => '[a-zA-Z0-9]+'));
215         $m->connect('tag/:tag',
216                     array('action' => 'tag'),
217                     array('tag' => '[\pL\pN_\-\.]{1,64}'));
218
219         $m->connect('peopletag/:tag',
220                     array('action' => 'peopletag'),
221                     array('tag' => '[a-zA-Z0-9]+'));
222
223         $m->connect('featured/', array('action' => 'featured'));
224         $m->connect('featured', array('action' => 'featured'));
225         $m->connect('favorited/', array('action' => 'favorited'));
226         $m->connect('favorited', array('action' => 'favorited'));
227
228         // groups
229
230         $m->connect('group/new', array('action' => 'newgroup'));
231
232         foreach (array('edit', 'join', 'leave') as $v) {
233             $m->connect('group/:nickname/'.$v,
234                         array('action' => $v.'group'),
235                         array('nickname' => '[a-zA-Z0-9]+'));
236         }
237
238         foreach (array('members', 'logo', 'rss', 'designsettings') as $n) {
239             $m->connect('group/:nickname/'.$n,
240                         array('action' => 'group'.$n),
241                         array('nickname' => '[a-zA-Z0-9]+'));
242         }
243
244         $m->connect('group/:nickname/foaf',
245                     array('action' => 'foafgroup'),
246                     array('nickname' => '[a-zA-Z0-9]+'));
247
248         $m->connect('group/:nickname/blocked',
249                     array('action' => 'blockedfromgroup'),
250                     array('nickname' => '[a-zA-Z0-9]+'));
251
252         $m->connect('group/:nickname/makeadmin',
253                     array('action' => 'makeadmin'),
254                     array('nickname' => '[a-zA-Z0-9]+'));
255
256         $m->connect('group/:id/id',
257                     array('action' => 'groupbyid'),
258                     array('id' => '[0-9]+'));
259
260         $m->connect('group/:nickname',
261                     array('action' => 'showgroup'),
262                     array('nickname' => '[a-zA-Z0-9]+'));
263
264         $m->connect('group/', array('action' => 'groups'));
265         $m->connect('group', array('action' => 'groups'));
266         $m->connect('groups/', array('action' => 'groups'));
267         $m->connect('groups', array('action' => 'groups'));
268
269         // Twitter-compatible API
270
271         // statuses API
272
273         $m->connect('api/statuses/public_timeline.:format',
274                     array('action' => 'ApiTimelinePublic',
275                     'format' => '(xml|json|rss|atom)'));
276
277         $m->connect('api/statuses/friends_timeline.:format',
278                     array('action' => 'ApiTimelineFriends',
279                           'format' => '(xml|json|rss|atom)'));
280
281         $m->connect('api/statuses/friends_timeline/:id.:format',
282                     array('action' => 'ApiTimelineFriends',
283                           'id' => '[a-zA-Z0-9]+',
284                           'format' => '(xml|json|rss|atom)'));
285         $m->connect('api/statuses/home_timeline.:format',
286                     array('action' => 'ApiTimelineFriends',
287                           'format' => '(xml|json|rss|atom)'));
288
289         $m->connect('api/statuses/home_timeline/:id.:format',
290                     array('action' => 'ApiTimelineFriends',
291                           'id' => '[a-zA-Z0-9]+',
292                           'format' => '(xml|json|rss|atom)'));
293
294         $m->connect('api/statuses/user_timeline.:format',
295                     array('action' => 'ApiTimelineUser',
296                     'format' => '(xml|json|rss|atom)'));
297
298         $m->connect('api/statuses/user_timeline/:id.:format',
299                     array('action' => 'ApiTimelineUser',
300                     'id' => '[a-zA-Z0-9]+',
301                     'format' => '(xml|json|rss|atom)'));
302
303         $m->connect('api/statuses/mentions.:format',
304                     array('action' => 'ApiTimelineMentions',
305                     'format' => '(xml|json|rss|atom)'));
306
307         $m->connect('api/statuses/mentions/:id.:format',
308                     array('action' => 'ApiTimelineMentions',
309                     'id' => '[a-zA-Z0-9]+',
310                     'format' => '(xml|json|rss|atom)'));
311
312         $m->connect('api/statuses/replies.:format',
313                     array('action' => 'ApiTimelineMentions',
314                     'format' => '(xml|json|rss|atom)'));
315
316         $m->connect('api/statuses/replies/:id.:format',
317                     array('action' => 'ApiTimelineMentions',
318                     'id' => '[a-zA-Z0-9]+',
319                     'format' => '(xml|json|rss|atom)'));
320
321         $m->connect('api/statuses/friends.:format',
322                      array('action' => 'ApiUserFriends',
323                            'format' => '(xml|json)'));
324
325         $m->connect('api/statuses/friends/:id.:format',
326                     array('action' => 'ApiUserFriends',
327                     'id' => '[a-zA-Z0-9]+',
328                     'format' => '(xml|json)'));
329
330         $m->connect('api/statuses/followers.:format',
331                      array('action' => 'ApiUserFollowers',
332                            'format' => '(xml|json)'));
333
334         $m->connect('api/statuses/followers/:id.:format',
335                     array('action' => 'ApiUserFollowers',
336                     'id' => '[a-zA-Z0-9]+',
337                     'format' => '(xml|json)'));
338
339         $m->connect('api/statuses/show.:format',
340                     array('action' => 'ApiStatusesShow',
341                           'format' => '(xml|json)'));
342
343         $m->connect('api/statuses/show/:id.:format',
344                     array('action' => 'ApiStatusesShow',
345                           'id' => '[0-9]+',
346                           'format' => '(xml|json)'));
347
348         $m->connect('api/statuses/update.:format',
349                     array('action' => 'ApiStatusesUpdate',
350                           'format' => '(xml|json)'));
351
352         $m->connect('api/statuses/destroy.:format',
353                   array('action' => 'ApiStatusesDestroy',
354                         'format' => '(xml|json)'));
355
356         $m->connect('api/statuses/destroy/:id.:format',
357                   array('action' => 'ApiStatusesDestroy',
358                         'id' => '[0-9]+',
359                         'format' => '(xml|json)'));
360
361         // users
362
363         $m->connect('api/users/show/:id.:format',
364                     array('action' => 'ApiUserShow',
365                           'id' => '[a-zA-Z0-9]+',
366                           'format' => '(xml|json)'));
367
368         $m->connect('api/users/:method',
369                     array('action' => 'api',
370                           'apiaction' => 'users'),
371                     array('method' => 'show(\.(xml|json))?'));
372
373         // direct messages
374
375
376         $m->connect('api/direct_messages.:format',
377                     array('action' => 'ApiDirectMessage',
378                           'format' => '(xml|json|rss|atom)'));
379
380         $m->connect('api/direct_messages/sent.:format',
381                     array('action' => 'ApiDirectMessage',
382                           'format' => '(xml|json|rss|atom)',
383                           'sent' => true));
384
385         $m->connect('api/direct_messages/new.:format',
386                      array('action' => 'ApiDirectMessageNew',
387                            'format' => '(xml|json)'));
388
389         // friendships
390
391         $m->connect('api/friendships/show.:format',
392                     array('action' => 'ApiFriendshipsShow',
393                           'format' => '(xml|json)'));
394
395         $m->connect('api/friendships/exists.:format',
396                     array('action' => 'ApiFriendshipsExists',
397                           'format' => '(xml|json)'));
398
399         $m->connect('api/friendships/create.:format',
400                     array('action' => 'ApiFriendshipsCreate',
401                           'format' => '(xml|json)'));
402
403         $m->connect('api/friendships/destroy.:format',
404                      array('action' => 'ApiFriendshipsDestroy',
405                           'format' => '(xml|json)'));
406
407         $m->connect('api/friendships/create/:id.:format',
408                     array('action' => 'ApiFriendshipsCreate',
409                           'id' => '[a-zA-Z0-9]+',
410                           'format' => '(xml|json)'));
411
412         $m->connect('api/friendships/destroy/:id.:format',
413                     array('action' => 'ApiFriendshipsDestroy',
414                     'id' => '[a-zA-Z0-9]+',
415                     'format' => '(xml|json)'));
416
417         // Social graph
418
419         $m->connect('api/friends/ids/:id.:format',
420                     array('action' => 'apiFriends',
421                           'ids_only' => true));
422
423         $m->connect('api/followers/ids/:id.:format',
424                     array('action' => 'apiFollowers',
425                           'ids_only' => true));
426
427         $m->connect('api/friends/ids.:format',
428                     array('action' => 'apiFriends',
429                           'ids_only' => true));
430
431         $m->connect('api/followers/ids.:format',
432                      array('action' => 'apiFollowers',
433                           'ids_only' => true));
434
435         // account
436
437         $m->connect('api/account/verify_credentials.:format',
438                     array('action' => 'ApiAccountVerifyCredentials'));
439
440         // special case where verify_credentials is called w/out a format
441
442         $m->connect('api/account/verify_credentials',
443                     array('action' => 'ApiAccountVerifyCredentials'));
444
445         $m->connect('api/account/rate_limit_status.:format',
446                     array('action' => 'ApiAccountRateLimitStatus'));
447
448         // favorites
449
450         $m->connect('api/favorites.:format',
451                     array('action' => 'ApiTimelineFavorites',
452                     'format' => '(xml|json|rss|atom)'));
453
454         $m->connect('api/favorites/:id.:format',
455                     array('action' => 'ApiTimelineFavorites',
456                           'id' => '[a-zA-Z0-9]+',
457                           'format' => '(xmljson|rss|atom)'));
458
459         $m->connect('api/favorites/create/:id.:format',
460                     array('action' => 'ApiFavoriteCreate',
461                           'id' => '[a-zA-Z0-9]+',
462                           'format' => '(xml|json)'));
463
464         $m->connect('api/favorites/destroy/:id.:format',
465                     array('action' => 'ApiFavoriteDestroy',
466                           'id' => '[a-zA-Z0-9]+',
467                           'format' => '(xml|json)'));
468
469         // notifications
470
471         $m->connect('api/notifications/:method/:argument',
472                     array('action' => 'api',
473                           'apiaction' => 'favorites'));
474
475         // blocks
476
477         $m->connect('api/blocks/:method/:argument',
478                     array('action' => 'api',
479                           'apiaction' => 'blocks'));
480
481         // help
482
483         $m->connect('api/help/test.:format',
484                     array('action' => 'ApiHelpTest',
485                           'format' => '(xml|json)'));
486
487         // statusnet
488
489         $m->connect('api/statusnet/version.:format',
490                     array('action' => 'ApiStatusnetVersion',
491                           'format' => '(xml|json)'));
492
493         $m->connect('api/statusnet/config.:format',
494                     array('action' => 'ApiStatusnetConfig',
495                    'format' => '(xml|json)'));
496
497         // For older methods, we provide "laconica" base action
498
499         $m->connect('api/laconica/version.:format',
500                     array('action' => 'ApiStatusnetVersion',
501                           'format' => '(xml|json)'));
502
503         $m->connect('api/laconica/config.:format',
504                     array('action' => 'ApiStatusnetConfig',
505                     'format' => '(xml|json)'));
506
507         // Groups and tags are newer than 0.8.1 so no backward-compatibility
508         // necessary
509
510         // Groups
511         //'list' has to be handled differently, as php will not allow a method to be named 'list'
512
513         $m->connect('api/statusnet/groups/timeline/:id.:format',
514                     array('action' => 'ApiTimelineGroup',
515                           'id' => '[a-zA-Z0-9]+',
516                           'format' => '(xmljson|rss|atom)'));
517
518         $m->connect('api/statusnet/groups/show.:format',
519                     array('action' => 'ApiGroupShow',
520                     'format' => '(xml|json)'));
521
522         $m->connect('api/statusnet/groups/show/:id.:format',
523                     array('action' => 'ApiGroupShow',
524                           'id' => '[a-zA-Z0-9]+',
525                           'format' => '(xml|json)'));
526
527         $m->connect('api/statusnet/groups/join.:format',
528                     array('action' => 'ApiGroupJoin',
529                           'id' => '[a-zA-Z0-9]+',
530                           'format' => '(xml|json)'));
531
532         $m->connect('api/statusnet/groups/join/:id.:format',
533                     array('action' => 'ApiGroupJoin',
534                     'format' => '(xml|json)'));
535
536         $m->connect('api/statusnet/groups/leave.:format',
537                     array('action' => 'ApiGroupLeave',
538                           'id' => '[a-zA-Z0-9]+',
539                           'format' => '(xml|json)'));
540
541         $m->connect('api/statusnet/groups/leave/:id.:format',
542                     array('action' => 'ApiGroupLeave',
543                           'format' => '(xml|json)'));
544
545         $m->connect('api/statusnet/groups/is_member.:format',
546                     array('action' => 'ApiGroupIsMember',
547                           'format' => '(xml|json)'));
548
549         $m->connect('api/statusnet/groups/list.:format',
550                     array('action' => 'ApiGroupList',
551                           'format' => '(xml|json|rss|atom)'));
552
553         $m->connect('api/statusnet/groups/list/:id.:format',
554                     array('action' => 'ApiGroupList',
555                           'id' => '[a-zA-Z0-9]+',
556                           'format' => '(xml|json|rss|atom)'));
557
558         $m->connect('api/statusnet/groups/list_all.:format',
559                     array('action' => 'ApiGroupListAll',
560                           'format' => '(xml|json|rss|atom)'));
561
562         $m->connect('api/statusnet/groups/membership.:format',
563                     array('action' => 'ApiGroupMembership',
564                          'format' => '(xml|json)'));
565
566         $m->connect('api/statusnet/groups/membership/:id.:format',
567                      array('action' => 'ApiGroupMembership',
568                            'id' => '[a-zA-Z0-9]+',
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         return $m;
635     }
636
637     function map($path)
638     {
639         try {
640             $match = $this->m->match($path);
641         } catch (Net_URL_Mapper_InvalidException $e) {
642             common_log(LOG_ERR, "Problem getting route for $path - " .
643                        $e->getMessage());
644             $cac = new ClientErrorAction("Page not found.", 404);
645             $cac->showPage();
646         }
647
648         return $match;
649     }
650
651     function build($action, $args=null, $params=null, $fragment=null)
652     {
653         $action_arg = array('action' => $action);
654
655         if ($args) {
656             $args = array_merge($action_arg, $args);
657         } else {
658             $args = $action_arg;
659         }
660
661         $url = $this->m->generate($args, $params, $fragment);
662
663         // Due to a bug in the Net_URL_Mapper code, the returned URL may
664         // contain a malformed query of the form ?p1=v1?p2=v2?p3=v3. We
665         // repair that here rather than modifying the upstream code...
666
667         $qpos = strpos($url, '?');
668         if ($qpos !== false) {
669             $url = substr($url, 0, $qpos+1) .
670               str_replace('?', '&', substr($url, $qpos+1));
671         }
672         return $url;
673     }
674 }