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