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