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',
101 'tagother', 'block');
103 foreach ($main as $a) {
104 $m->connect('main/'.$a, array('action' => $a));
109 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
110 $m->connect('main/'.$c.'/:code', array('action' => $c));
115 $m->connect('main/openid', array('action' => 'openidlogin'));
116 $m->connect('main/remote', array('action' => 'remotesubscribe'));
120 foreach (array('profile', 'avatar', 'password', 'openid', 'im',
121 'email', 'sms', 'twitter', 'other') as $s) {
122 $m->connect('settings/'.$s, array('action' => $s.'settings'));
127 foreach (array('group', 'people', 'notice') as $s) {
128 $m->connect('search/'.$s, array('action' => $s.'search'));
131 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
135 $m->connect('notice/new', array('action' => 'newnotice'));
136 $m->connect('notice/:notice',
137 array('action' => 'shownotice'),
138 array('notice' => '[0-9]+'));
139 $m->connect('notice/delete', array('action' => 'deletenotice'));
140 $m->connect('notice/delete/:notice',
141 array('action' => 'deletenotice'),
142 array('notice' => '[0-9]+'));
144 $m->connect('message/new', array('action' => 'newmessage'));
145 $m->connect('message/:message',
146 array('action' => 'showmessage'),
147 array('message' => '[0-9]+'));
149 $m->connect('user/:id',
150 array('action' => 'userbyid'),
151 array('id' => '[0-9]+'));
153 $m->connect('tags/', array('action' => 'publictagcloud'));
154 $m->connect('tag/', array('action' => 'publictagcloud'));
155 $m->connect('tags', array('action' => 'publictagcloud'));
156 $m->connect('tag', array('action' => 'publictagcloud'));
157 $m->connect('tag/:tag/rss',
158 array('action' => 'tagrss'),
159 array('tag' => '[a-zA-Z0-9]+'));
160 $m->connect('tag/:tag',
161 array('action' => 'tag'),
162 array('tag' => '[a-zA-Z0-9]+'));
164 $m->connect('peopletag/:tag',
165 array('action' => 'peopletag'),
166 array('tag' => '[a-zA-Z0-9]+'));
168 $m->connect('featured/', array('action' => 'featured'));
169 $m->connect('featured', array('action' => 'featured'));
170 $m->connect('favorited/', array('action' => 'favorited'));
171 $m->connect('favorited', array('action' => 'favorited'));
175 $m->connect('group/new', array('action' => 'newgroup'));
177 foreach (array('edit', 'join', 'leave') as $v) {
178 $m->connect('group/:nickname/'.$v,
179 array('action' => $v.'group'),
180 array('nickname' => '[a-zA-Z0-9]+'));
183 foreach (array('members', 'logo', 'rss') as $n) {
184 $m->connect('group/:nickname/'.$n,
185 array('action' => 'group'.$n),
186 array('nickname' => '[a-zA-Z0-9]+'));
189 $m->connect('group/:id/id',
190 array('action' => 'groupbyid'),
191 array('id' => '[0-9]+'));
193 $m->connect('group/:nickname',
194 array('action' => 'showgroup'),
195 array('nickname' => '[a-zA-Z0-9]+'));
197 $m->connect('group/', array('action' => 'groups'));
198 $m->connect('group', array('action' => 'groups'));
199 $m->connect('groups/', array('action' => 'groups'));
200 $m->connect('groups', array('action' => 'groups'));
202 // Twitter-compatible API
206 $m->connect('api/statuses/:method',
207 array('action' => 'api',
208 'apiaction' => 'statuses'),
209 array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|friends|followers|featured)(\.(atom|rss|xml|json))?'));
211 $m->connect('api/statuses/:method/:argument',
212 array('action' => 'api',
213 'apiaction' => 'statuses'),
214 array('method' => '(user_timeline|show|destroy|friends|followers)'));
218 $m->connect('api/users/show/:argument',
219 array('action' => 'api',
220 'apiaction' => 'users'));
222 $m->connect('api/users/:method',
223 array('action' => 'api',
224 'apiaction' => 'users'),
225 array('method' => 'show(\.(xml|json|atom|rss))?'));
229 $m->connect('api/direct_messages/:method',
230 array('action' => 'api',
231 'apiaction' => 'direct_messages'),
232 array('method' => '(sent|new)(\.(xml|json|atom|rss))?'));
234 $m->connect('api/direct_messages/destroy/:argument',
235 array('action' => 'api',
236 'apiaction' => 'direct_messages'));
238 $m->connect('api/:method',
239 array('action' => 'api',
240 'apiaction' => 'direct_messages'),
241 array('method' => 'direct_messages(\.(xml|json|atom|rss))?'));
245 $m->connect('api/friendships/:method/:argument',
246 array('action' => 'api',
247 'apiaction' => 'friendships'),
248 array('method' => '(create|destroy)'));
250 $m->connect('api/friendships/:method',
251 array('action' => 'api',
252 'apiaction' => 'friendships'),
253 array('method' => 'exists(\.(xml|json|rss|atom))'));
257 $m->connect('api/account/:method',
258 array('action' => 'api',
259 'apiaction' => 'account'));
263 $m->connect('api/favorites/:method/:argument',
264 array('action' => 'api',
265 'apiaction' => 'favorites'));
267 $m->connect('api/favorites/:argument',
268 array('action' => 'api',
269 'apiaction' => 'favorites',
270 'method' => 'favorites'));
272 $m->connect('api/:method',
273 array('action' => 'api',
274 'apiaction' => 'favorites'),
275 array('method' => 'favorites(\.(xml|json|rss|atom))?'));
279 $m->connect('api/notifications/:method/:argument',
280 array('action' => 'api',
281 'apiaction' => 'favorites'));
285 $m->connect('api/blocks/:method/:argument',
286 array('action' => 'api',
287 'apiaction' => 'blocks'));
291 $m->connect('api/help/:method',
292 array('action' => 'api',
293 'apiaction' => 'help'));
297 $m->connect('api/laconica/:method',
298 array('action' => 'api',
299 'apiaction' => 'laconica'));
303 foreach (array('subscriptions', 'subscribers',
304 'nudge', 'xrds', 'all', 'foaf',
305 'replies', 'inbox', 'outbox', 'microsummary') as $a) {
306 $m->connect(':nickname/'.$a,
307 array('action' => $a),
308 array('nickname' => '[a-zA-Z0-9]{1,64}'));
311 foreach (array('subscriptions', 'subscribers') as $a) {
312 $m->connect(':nickname/'.$a.'/:tag',
313 array('action' => $a),
314 array('tag' => '[a-zA-Z0-9]+',
315 'nickname' => '[a-zA-Z0-9]{1,64}'));
318 foreach (array('rss', 'groups') as $a) {
319 $m->connect(':nickname/'.$a,
320 array('action' => 'user'.$a),
321 array('nickname' => '[a-zA-Z0-9]{1,64}'));
324 foreach (array('all', 'replies', 'favorites') as $a) {
325 $m->connect(':nickname/'.$a.'/rss',
326 array('action' => $a.'rss'),
327 array('nickname' => '[a-zA-Z0-9]{1,64}'));
330 $m->connect(':nickname/favorites',
331 array('action' => 'showfavorites'),
332 array('nickname' => '[a-zA-Z0-9]{1,64}'));
334 $m->connect(':nickname/avatar/:size',
335 array('action' => 'avatarbynickname'),
336 array('size' => '(original|96|48|24)',
337 'nickname' => '[a-zA-Z0-9]{1,64}'));
339 $m->connect(':nickname',
340 array('action' => 'showstream'),
341 array('nickname' => '[a-zA-Z0-9]{1,64}'));
348 return $this->m->match($path);
351 function build($action, $args=null, $fragment=null)
353 $action_arg = array('action' => $action);
356 $args = array_merge($action_arg, $args);
361 return $this->m->generate($args, null, $fragment);