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/
52 function __construct()
54 $m = Net_URL_Mapper::getInstance();
58 $m->connect('', array('action' => 'public'));
59 $m->connect('rss', array('action' => 'publicrss'));
60 $m->connect('xrds', array('action' => 'publicxrds'));
61 $m->connect('featuredrss', array('action' => 'featuredrss'));
62 $m->connect('favoritedrss', array('action' => 'favoritedrss'));
63 $m->connect('opensearch/people', array('action' => 'opensearch',
65 $m->connect('opensearch/notice', array('action' => 'opensearch',
70 $m->connect('doc/:title', array('action' => 'doc'));
74 $m->connect('facebook', array('action' => 'facebookhome'));
75 $m->connect('facebook/index.php', array('action' => 'facebookhome'));
76 $m->connect('facebook/settings.php', array('action' => 'facebooksettings'));
77 $m->connect('facebook/invite.php', array('action' => 'facebookinvite'));
78 $m->connect('facebook/remove', array('action' => 'facebookremove'));
80 // main stuff is repetitive
82 $main = array('login', 'logout', 'register', 'subscribe',
83 'unsubscribe', 'confirmaddress', 'recoverpassword',
84 'invite', 'favor', 'disfavor', 'sup',
87 foreach ($main as $a) {
88 $m->connect('main/'.$a, array('action' => $a));
93 foreach (array('register', 'confirmaddress', 'recoverpassword') as $c) {
94 $m->connect('main/'.$c.'/:code', array('action' => $c));
99 $m->connect('main/openid', array('action' => 'openidlogin'));
100 $m->connect('main/remote', array('action' => 'remotesubscribe'));
104 foreach (array('profile', 'avatar', 'password', 'openid', 'im',
105 'email', 'sms', 'twitter', 'other') as $s) {
106 $m->connect('settings/'.$s, array('action' => $s.'settings'));
111 foreach (array('group', 'people', 'notice') as $s) {
112 $m->connect('search/'.$s, array('action' => $s.'search'));
115 $m->connect('search/notice/rss', array('action' => 'noticesearchrss'));
119 $m->connect('notice/new', array('action' => 'newnotice'));
120 $m->connect('notice/:notice',
121 array('action' => 'shownotice'),
122 array('notice' => '[0-9]+'));
123 $m->connect('notice/delete', array('action' => 'deletenotice'));
124 $m->connect('notice/delete/:notice',
125 array('action' => 'deletenotice'),
126 array('notice' => '[0-9]+'));
128 $m->connect('message/new', array('action' => 'newmessage'));
129 $m->connect('message/:message',
130 array('action' => 'showmessage'),
131 array('message' => '[0-9]+'));
133 $m->connect('user/:id',
134 array('action' => 'userbyid'),
135 array('id' => '[0-9]+'));
137 $m->connect('tags/?', array('action' => 'publictagcloud'));
138 $m->connect('tag/?', array('action' => 'publictagcloud'));
139 $m->connect('tag/:tag/rss',
140 array('action' => 'tagrss'),
141 array('tag' => '[a-zA-Z0-9]+'));
142 $m->connect('tag/:tag',
143 array('action' => 'tag'),
144 array('tag' => '[a-zA-Z0-9]+'));
146 $m->connect('peopletag/:tag',
147 array('action' => 'peopletag'),
148 array('tag' => '[a-zA-Z0-9]+'));
150 $m->connect('featured/?', array('action' => 'featured'));
151 $m->connect('favorited/?', array('action' => 'favorited'));
155 $m->connect('group/new', array('action' => 'newgroup'));
157 foreach (array('edit', 'join', 'leave') as $v) {
158 $m->connect('group/:nickname/'.$v,
159 array('action' => $v.'group'),
160 array('nickname' => '[a-zA-Z0-9]+'));
163 foreach (array('members', 'logo', 'rss') as $n) {
164 $m->connect('group/:nickname/'.$n,
165 array('action' => 'group'.$n),
166 array('nickname' => '[a-zA-Z0-9]+'));
169 $m->connect('group/:id/id',
170 array('action' => 'groupbyid'),
171 array('id' => '[0-9]+'));
173 $m->connect('group/:nickname',
174 array('action' => 'showgroup'),
175 array('nickname' => '[a-zA-Z0-9]+'));
177 $m->connect('group/?', array('action' => 'groups'));
179 // Twitter-compatible API
183 $m->connect('api/statuses/:method',
184 array('action' => 'api',
185 'apiaction' => 'statuses'),
186 array('method' => '(public_timeline|friends_timeline|user_timeline|update|replies|friends|followers|featured)(\.(atom|rss|xml|json))?'));
188 $m->connect('api/statuses/:method/:argument',
189 array('action' => 'api',
190 'apiaction' => 'statuses'),
191 array('method' => '(user_timeline|show|destroy|friends|followers)'));
195 $m->connect('api/users/show/:argument',
196 array('action' => 'api',
197 'apiaction' => 'users'));
199 $m->connect('api/users/:method',
200 array('action' => 'api',
201 'apiaction' => 'users'),
202 array('method' => 'show(\.(xml|json|atom|rss))?'));
206 $m->connect('api/direct_messages/:method',
207 array('action' => 'api',
208 'apiaction' => 'direct_messages'),
209 array('method' => '(sent|new)(\.(xml|json|atom|rss))?'));
211 $m->connect('api/direct_messages/destroy/:argument',
212 array('action' => 'api',
213 'apiaction' => 'direct_messages'));
215 $m->connect('api/:method',
216 array('action' => 'api',
217 'apiaction' => 'direct_messages'),
218 array('method' => 'direct_messages(\.(xml|json|atom|rss))?'));
222 $m->connect('api/friendships/:method/:argument',
223 array('action' => 'api',
224 'apiaction' => 'friendships'),
225 array('method' => '(create|destroy)'));
227 $m->connect('api/friendships/:method',
228 array('action' => 'api',
229 'apiaction' => 'friendships'),
230 array('method' => 'exists(\.(xml|json|rss|atom))'));
234 $m->connect('api/account/:method',
235 array('action' => 'api',
236 'apiaction' => 'account'));
240 $m->connect('api/favorites/:method/:argument',
241 array('action' => 'api',
242 'apiaction' => 'favorites'));
244 $m->connect('api/favorites/:argument',
245 array('action' => 'api',
246 'apiaction' => 'favorites',
247 'method' => 'favorites'));
249 $m->connect('api/:method',
250 array('action' => 'api',
251 'apiaction' => 'favorites'),
252 array('method' => 'favorites(\.(xml|json|rss|atom))?'));
256 $m->connect('api/notifications/:method/:argument',
257 array('action' => 'api',
258 'apiaction' => 'favorites'));
262 $m->connect('api/blocks/:method/:argument',
263 array('action' => 'api',
264 'apiaction' => 'blocks'));
268 $m->connect('api/help/:method',
269 array('action' => 'api',
270 'apiaction' => 'help'));
274 $m->connect('api/laconica/:method',
275 array('action' => 'api',
276 'apiaction' => 'laconica'));
280 foreach (array('subscriptions', 'subscribers',
281 'nudge', 'xrds', 'all', 'foaf',
282 'replies', 'inbox', 'outbox', 'microsummary') as $a) {
283 $m->connect(':nickname/'.$a,
284 array('action' => $a),
285 array('nickname' => '[a-zA-Z0-9]{1,64}'));
288 foreach (array('subscriptions', 'subscribers') as $a) {
289 $m->connect(':nickname/'.$a.'/:tag',
290 array('action' => $a),
291 array('tag' => '[a-zA-Z0-9]+',
292 'nickname' => '[a-zA-Z0-9]{1,64}'));
295 foreach (array('rss', 'groups') as $a) {
296 $m->connect(':nickname/'.$a,
297 array('action' => 'user'.$a),
298 array('nickname' => '[a-zA-Z0-9]{1,64}'));
301 foreach (array('all', 'replies', 'favorites') as $a) {
302 $m->connect(':nickname/'.$a.'/rss',
303 array('action' => $a.'rss'),
304 array('nickname' => '[a-zA-Z0-9]{1,64}'));
307 $m->connect(':nickname/favorites',
308 array('action' => 'showfavorites'),
309 array('nickname' => '[a-zA-Z0-9]{1,64}'));
311 $m->connect(':nickname/avatar/:size',
312 array('action' => 'avatarbynickname'),
313 array('size' => '(original|96|48|24)',
314 'nickname' => '[a-zA-Z0-9]{1,64}'));
316 $m->connect(':nickname',
317 array('action' => 'showstream'),
318 array('nickname' => '[a-zA-Z0-9]{1,64}'));
325 return $this->m->match($path);
328 function build($action, $args=null, $fragment=null)
330 $action_arg = array('action' => $action);
333 $args = array_merge($args, $action_arg);
338 return $this->m->generate($args, null, $fragment);