3 * Laconica, the distributed open-source microblogging tool
5 * URL routing utilities
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.
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.
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/>.
24 * @author Evan Prodromou <evan@controlyourself.ca>
25 * @copyright 2009 Control Yourself, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://laconi.ca/
30 if (!defined('LACONICA')) {
34 require_once 'Net/URL/Mapper.php';
39 * Cheap wrapper around Net_URL_Mapper
43 * @author Evan Prodromou <evan@controlyourself.ca>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://laconi.ca/
56 Router::$inst = new Router();
61 function __construct()
64 $this->m = $this->initialize();
68 function initialize() {
70 $m = Net_URL_Mapper::getInstance();
74 $m->connect('', array('action' => 'public'));
75 $m->connect('rss', array('action' => 'publicrss'));
76 $m->connect('xrds', array('action' => 'publicxrds'));
77 $m->connect('featuredrss', array('action' => 'featuredrss'));
78 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
79 $m->connect('opensearch/people', array('action' => 'opensearch',
81 $m->connect('opensearch/notice', array('action' => 'opensearch',
86 $m->connect('doc/:title', array('action' => 'doc'));
90 $m->connect('facebook', array('action' => 'facebookhome'));
91 $m->connect('facebook/index.php', array('action' => 'facebookhome'));
92 $m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
93 $m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
94 $m->connect('facebook/remove', array('action' => 'facebookremove'));
96 // main stuff is repetitive
98 $main = array('login', 'logout', 'register', 'subscribe',
99 'unsubscribe', 'confirmaddress', 'recoverpassword',
100 'invite', 'favor', 'disfavor', 'sup',
103 foreach ($main as $a) {
104 $m->connect('main/'.$a, array('action' => $a));
107 $m->connect('main/tagother/:id', array('action' => 'tagother'));
111 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
112 $m->connect('main/'.$c.'/:code', array('action' => $c));
117 $m->connect('main/openid', array('action' => 'openidlogin'));
118 $m->connect('main/remote', array('action' => 'remotesubscribe'));
122 foreach (array('profile', 'avatar', 'password', 'openid', 'im',
123 'email', 'sms', 'twitter', 'other') as $s) {
124 $m->connect('settings/'.$s, array('action' => $s.'settings'));
129 foreach (array('group', 'people', 'notice') as $s) {
130 $m->connect('search/'.$s, array('action' => $s.'search'));
133 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
137 $m->connect('notice/new', array('action' => 'newnotice'));
138 $m->connect('notice/:notice',
139 array('action' => 'shownotice'),
140 array('notice' => '[0-9]+'));
141 $m->connect('notice/delete', array('action' => 'deletenotice'));
142 $m->connect('notice/delete/:notice',
143 array('action' => 'deletenotice'),
144 array('notice' => '[0-9]+'));
146 $m->connect('message/new', array('action' => 'newmessage'));
147 $m->connect('message/:message',
148 array('action' => 'showmessage'),
149 array('message' => '[0-9]+'));
151 $m->connect('user/:id',
152 array('action' => 'userbyid'),
153 array('id' => '[0-9]+'));
155 $m->connect('tags/', array('action' => 'publictagcloud'));
156 $m->connect('tag/', array('action' => 'publictagcloud'));
157 $m->connect('tags', array('action' => 'publictagcloud'));
158 $m->connect('tag', array('action' => 'publictagcloud'));
159 $m->connect('tag/:tag/rss',
160 array('action' => 'tagrss'),
161 array('tag' => '[a-zA-Z0-9]+'));
162 $m->connect('tag/:tag',
163 array('action' => 'tag'),
164 array('tag' => '[a-zA-Z0-9]+'));
166 $m->connect('peopletag/:tag',
167 array('action' => 'peopletag'),
168 array('tag' => '[a-zA-Z0-9]+'));
170 $m->connect('featured/', array('action' => 'featured'));
171 $m->connect('featured', array('action' => 'featured'));
172 $m->connect('favorited/', array('action' => 'favorited'));
173 $m->connect('favorited', array('action' => 'favorited'));
177 $m->connect('group/new', array('action' => 'newgroup'));
179 foreach (array('edit', 'join', 'leave') as $v) {
180 $m->connect('group/:nickname/'.$v,
181 array('action' => $v.'group'),
182 array('nickname' => '[a-zA-Z0-9]+'));
185 foreach (array('members', 'logo', 'rss') as $n) {
186 $m->connect('group/:nickname/'.$n,
187 array('action' => 'group'.$n),
188 array('nickname' => '[a-zA-Z0-9]+'));
191 $m->connect('group/:id/id',
192 array('action' => 'groupbyid'),
193 array('id' => '[0-9]+'));
195 $m->connect('group/:nickname',
196 array('action' => 'showgroup'),
197 array('nickname' => '[a-zA-Z0-9]+'));
199 $m->connect('group/', array('action' => 'groups'));
200 $m->connect('group', array('action' => 'groups'));
201 $m->connect('groups/', array('action' => 'groups'));
202 $m->connect('groups', array('action' => 'groups'));
204 // Twitter-compatible API
208 $m->connect('api/statuses/:method',
209 array('action' => 'api',
210 'apiaction' => 'statuses'),
211 array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|friends|followers|featured)(\.(atom|rss|xml|json))?'));
213 $m->connect('api/statuses/:method/:argument',
214 array('action' => 'api',
215 'apiaction' => 'statuses'),
216 array('method' => '(user_timeline|show|destroy|friends|followers)'));
220 $m->connect('api/users/show/:argument',
221 array('action' => 'api',
222 'apiaction' => 'users'));
224 $m->connect('api/users/:method',
225 array('action' => 'api',
226 'apiaction' => 'users'),
227 array('method' => 'show(\.(xml|json|atom|rss))?'));
231 $m->connect('api/direct_messages/:method',
232 array('action' => 'api',
233 'apiaction' => 'direct_messages'),
234 array('method' => '(sent|new)(\.(xml|json|atom|rss))?'));
236 $m->connect('api/direct_messages/destroy/:argument',
237 array('action' => 'api',
238 'apiaction' => 'direct_messages'));
240 $m->connect('api/:method',
241 array('action' => 'api',
242 'apiaction' => 'direct_messages'),
243 array('method' => 'direct_messages(\.(xml|json|atom|rss))?'));
247 $m->connect('api/friendships/:method/:argument',
248 array('action' => 'api',
249 'apiaction' => 'friendships'),
250 array('method' => '(create|destroy)'));
252 $m->connect('api/friendships/:method',
253 array('action' => 'api',
254 'apiaction' => 'friendships'),
255 array('method' => 'exists(\.(xml|json|rss|atom))'));
259 $m->connect('api/account/:method',
260 array('action' => 'api',
261 'apiaction' => 'account'));
265 $m->connect('api/favorites/:method/:argument',
266 array('action' => 'api',
267 'apiaction' => 'favorites'));
269 $m->connect('api/favorites/:argument',
270 array('action' => 'api',
271 'apiaction' => 'favorites',
272 'method' => 'favorites'));
274 $m->connect('api/:method',
275 array('action' => 'api',
276 'apiaction' => 'favorites'),
277 array('method' => 'favorites(\.(xml|json|rss|atom))?'));
281 $m->connect('api/notifications/:method/:argument',
282 array('action' => 'api',
283 'apiaction' => 'favorites'));
287 $m->connect('api/blocks/:method/:argument',
288 array('action' => 'api',
289 'apiaction' => 'blocks'));
293 $m->connect('api/help/:method',
294 array('action' => 'api',
295 'apiaction' => 'help'));
299 $m->connect('api/laconica/:method',
300 array('action' => 'api',
301 'apiaction' => 'laconica'));
305 foreach (array('subscriptions', 'subscribers',
306 'nudge', 'xrds', 'all', 'foaf',
307 'replies', 'inbox', 'outbox', 'microsummary') as $a) {
308 $m->connect(':nickname/'.$a,
309 array('action' => $a),
310 array('nickname' => '[a-zA-Z0-9]{1,64}'));
313 foreach (array('subscriptions', 'subscribers') as $a) {
314 $m->connect(':nickname/'.$a.'/:tag',
315 array('action' => $a),
316 array('tag' => '[a-zA-Z0-9]+',
317 'nickname' => '[a-zA-Z0-9]{1,64}'));
320 foreach (array('rss', 'groups') as $a) {
321 $m->connect(':nickname/'.$a,
322 array('action' => 'user'.$a),
323 array('nickname' => '[a-zA-Z0-9]{1,64}'));
326 foreach (array('all', 'replies', 'favorites') as $a) {
327 $m->connect(':nickname/'.$a.'/rss',
328 array('action' => $a.'rss'),
329 array('nickname' => '[a-zA-Z0-9]{1,64}'));
332 $m->connect(':nickname/favorites',
333 array('action' => 'showfavorites'),
334 array('nickname' => '[a-zA-Z0-9]{1,64}'));
336 $m->connect(':nickname/avatar/:size',
337 array('action' => 'avatarbynickname'),
338 array('size' => '(original|96|48|24)',
339 'nickname' => '[a-zA-Z0-9]{1,64}'));
341 $m->connect(':nickname',
342 array('action' => 'showstream'),
343 array('nickname' => '[a-zA-Z0-9]{1,64}'));
350 return $this->m->match($path);
353 function build($action, $args=null, $fragment=null)
355 $action_arg = array('action' => $action);
358 $args = array_merge($action_arg, $args);
363 return $this->m->generate($args, null, $fragment);