16 * @subpackage PathManager |
16 * @subpackage PathManager |
17 * @see http://enanocms.org/Help:API_Documentation |
17 * @see http://enanocms.org/Help:API_Documentation |
18 */ |
18 */ |
19 |
19 |
20 class pathManager { |
20 class pathManager { |
21 var $pages, $custom_page, $cpage, $page, $fullpage, $page_exists, $namespace, $nslist, $admin_tree, $wiki_mode, $page_protected, $template_cache; |
21 var $pages, $custom_page, $cpage, $page, $fullpage, $page_exists, $namespace, $nslist, $admin_tree, $wiki_mode, $page_protected, $template_cache, $anonymous_page; |
22 function __construct() |
22 function __construct() |
23 { |
23 { |
24 global $db, $session, $paths, $template, $plugins; // Common objects |
24 global $db, $session, $paths, $template, $plugins; // Common objects |
25 |
25 |
26 $GLOBALS['paths'] =& $this; |
26 $GLOBALS['paths'] =& $this; |
27 $this->pages = Array(); |
27 $this->pages = Array(); |
28 |
|
29 dc_here('paths: setting up namespaces, admin nodes'); |
|
30 |
28 |
31 // DEFINE NAMESPACES HERE |
29 // DEFINE NAMESPACES HERE |
32 // The key names should NOT EVER be changed, or Enano will be very broken |
30 // The key names should NOT EVER be changed, or Enano will be very broken |
33 $this->nslist = Array( |
31 $this->nslist = Array( |
34 'Article' =>'', |
32 'Article' =>'', |
150 $this->pages[$r['urlname']] = $r; |
146 $this->pages[$r['urlname']] = $r; |
151 $this->pages[] =& $this->pages[$r['urlname']]; |
147 $this->pages[] =& $this->pages[$r['urlname']]; |
152 |
148 |
153 } |
149 } |
154 $db->free_result(); |
150 $db->free_result(); |
155 dc_here('paths: determining page ID'); |
151 if ( defined('ENANO_INTERFACE_INDEX') || defined('ENANO_INTERFACE_AJAX') ) |
156 if( isset($_GET['title']) ) |
152 { |
157 { |
153 if( isset($_GET['title']) ) |
158 if ( $_GET['title'] == '' && getConfig('main_page') != '' ) |
154 { |
159 { |
155 if ( $_GET['title'] == '' && getConfig('main_page') != '' ) |
160 $this->main_page(); |
156 { |
161 } |
157 $this->main_page(); |
162 if(strstr($_GET['title'], ' ')) |
158 } |
163 { |
159 if(strstr($_GET['title'], ' ')) |
164 $loc = urldecode(rawurldecode($_SERVER['REQUEST_URI'])); |
160 { |
165 $loc = str_replace(' ', '_', $loc); |
161 $loc = urldecode(rawurldecode($_SERVER['REQUEST_URI'])); |
166 $loc = str_replace('+', '_', $loc); |
162 $loc = str_replace(' ', '_', $loc); |
167 $loc = str_replace('%20', '_', $loc); |
163 $loc = str_replace('+', '_', $loc); |
168 redirect($loc, 'Redirecting...', 'Space detected in the URL, please wait whilst you are redirected', 0); |
164 $loc = str_replace('%20', '_', $loc); |
169 exit; |
165 redirect($loc, 'Redirecting...', 'Space detected in the URL, please wait whilst you are redirected', 0); |
170 } |
166 exit; |
171 $url_namespace_special = substr($_GET['title'], 0, strlen($this->nslist['Special']) ); |
167 } |
172 $url_namespace_template = substr($_GET['title'], 0, strlen($this->nslist['Template']) ); |
168 $url_namespace_special = substr($_GET['title'], 0, strlen($this->nslist['Special']) ); |
173 if($url_namespace_special == $this->nslist['Special'] || $url_namespace_template == $this->nslist['Template'] ) |
169 $url_namespace_template = substr($_GET['title'], 0, strlen($this->nslist['Template']) ); |
174 { |
170 if($url_namespace_special == $this->nslist['Special'] || $url_namespace_template == $this->nslist['Template'] ) |
175 $ex = explode('/', $_GET['title']); |
171 { |
176 $this->page = $ex[0]; |
172 $ex = explode('/', $_GET['title']); |
|
173 $this->page = $ex[0]; |
|
174 } |
|
175 else |
|
176 { |
|
177 $this->page = $_GET['title']; |
|
178 } |
|
179 $this->fullpage = $_GET['title']; |
|
180 } |
|
181 elseif( isset($_SERVER['PATH_INFO']) ) |
|
182 { |
|
183 $pi = explode('/', $_SERVER['PATH_INFO']); |
|
184 |
|
185 if( !isset($pi[1]) || (isset($pi[1]) && $pi[1] == '' && getConfig('main_page') != '') ) |
|
186 { |
|
187 $this->main_page(); |
|
188 } |
|
189 if( strstr($pi[1], ' ') ) |
|
190 { |
|
191 $loc = str_replace(' ', '_', urldecode(rawurldecode($_SERVER['REQUEST_URI']))); |
|
192 $loc = str_replace('+', '_', $loc); |
|
193 $loc = str_replace('%20', '_', $loc); |
|
194 redirect($loc, 'Redirecting...', 'Please wait whilst you are redirected', 3); |
|
195 exit; |
|
196 } |
|
197 unset($pi[0]); |
|
198 if( substr($pi[1], 0, strlen($this->nslist['Special'])) == $this->nslist['Special'] || substr($pi[1], 0, strlen($this->nslist['Template'])) == $this->nslist['Template'] ) |
|
199 { |
|
200 $pi2 = $pi[1]; |
|
201 } |
|
202 else |
|
203 { |
|
204 $pi2 = implode('/', $pi); |
|
205 } |
|
206 $this->page = $pi2; |
|
207 $this->fullpage = implode('/', $pi); |
177 } |
208 } |
178 else |
209 else |
179 { |
210 { |
180 $this->page = $_GET['title']; |
211 $k = array_keys($_GET); |
181 } |
212 foreach($k as $c) |
182 $this->fullpage = $_GET['title']; |
213 { |
183 } |
214 if(substr($c, 0, 1) == '/') |
184 elseif( isset($_SERVER['PATH_INFO']) ) |
215 { |
185 { |
216 $this->page = substr($c, 1, strlen($c)); |
186 $pi = explode('/', $_SERVER['PATH_INFO']); |
217 |
187 |
218 // Bugfix for apache somehow passing dots as underscores |
188 if( !isset($pi[1]) || (isset($pi[1]) && $pi[1] == '' && getConfig('main_page') != '') ) |
219 global $mime_types; |
189 { |
220 |
190 $this->main_page(); |
221 $exts = array_keys($mime_types); |
191 } |
222 $exts = '(' . implode('|', $exts) . ')'; |
192 if( strstr($pi[1], ' ') ) |
223 |
193 { |
224 if ( preg_match( '#_'.$exts.'#i', $this->page ) ) |
194 $loc = str_replace(' ', '_', urldecode(rawurldecode($_SERVER['REQUEST_URI']))); |
225 { |
195 $loc = str_replace('+', '_', $loc); |
226 $this->page = preg_replace( '#_'.$exts.'#i', '.\\1', $this->page ); |
196 $loc = str_replace('%20', '_', $loc); |
227 } |
197 redirect($loc, 'Redirecting...', 'Please wait whilst you are redirected', 3); |
228 |
198 exit; |
229 $this->fullpage = $this->page; |
199 } |
230 |
200 unset($pi[0]); |
231 if(substr($this->page, 0, strlen($this->nslist['Special']))==$this->nslist['Special'] || substr($this->page, 0, strlen($this->nslist['Template']))==$this->nslist['Template']) |
201 if( substr($pi[1], 0, strlen($this->nslist['Special'])) == $this->nslist['Special'] || substr($pi[1], 0, strlen($this->nslist['Template'])) == $this->nslist['Template'] ) |
232 { |
202 { |
233 $ex = explode('/', $this->page); |
203 $pi2 = $pi[1]; |
234 $this->page = $ex[0]; |
|
235 } |
|
236 if(strstr($this->page, ' ')) |
|
237 { |
|
238 $loc = str_replace(' ', '_', urldecode(rawurldecode($_SERVER['REQUEST_URI']))); |
|
239 $loc = str_replace('+', '_', $loc); |
|
240 $loc = str_replace('%20', '_', $loc); |
|
241 redirect($loc, 'Redirecting...', 'Space in the URL detected, please wait whilst you are redirected', 0); |
|
242 exit; |
|
243 } |
|
244 break; |
|
245 } |
|
246 } |
|
247 if(!$this->page && !($this->page == '' && getConfig('main_page') == '')) |
|
248 { |
|
249 $this->main_page(); |
|
250 } |
|
251 } |
|
252 } |
|
253 else |
|
254 { |
|
255 // Starting up Enano with the API from a page that wants to do its own thing. Generate |
|
256 // metadata for an anonymous page and avoid redirection at all costs. |
|
257 if ( isset($GLOBALS['title']) ) |
|
258 { |
|
259 $title =& $GLOBALS['title']; |
|
260 } |
|
261 else if ( isset($_SERVER['REQUEST_URI']) ) |
|
262 { |
|
263 $title = basename($_SERVER['REQUEST_URI']); |
204 } |
264 } |
205 else |
265 else |
206 { |
266 { |
207 $pi2 = implode('/', $pi); |
267 $title = 'Untitled page'; |
208 } |
268 } |
209 $this->page = $pi2; |
269 $this->page = $this->nslist['Special'] . 'AnonymousPage'; |
210 $this->fullpage = implode('/', $pi); |
270 $this->fullpage = $this->nslist['Special'] . 'AnonymousPage'; |
211 } |
271 $this->cpage = array( |
212 else |
272 'name' => $title, |
213 { |
273 'urlname' => 'AnonymousPage', |
214 $k = array_keys($_GET); |
274 'namespace' => 'Special', |
215 foreach($k as $c) |
275 'special' => 0, |
216 { |
276 'visible' => 1, |
217 if(substr($c, 0, 1) == '/') |
277 'comments_on' => 0, |
218 { |
278 'protected' => 1, |
219 $this->page = substr($c, 1, strlen($c)); |
279 'delvotes' => 0, |
220 |
280 'delvote_ips' => '' |
221 // Bugfix for apache somehow passing dots as underscores |
281 ); |
222 global $mime_types; |
282 $this->anonymous_page = true; |
223 |
|
224 $exts = array_keys($mime_types); |
|
225 $exts = '(' . implode('|', $exts) . ')'; |
|
226 |
|
227 if ( preg_match( '#_'.$exts.'#i', $this->page ) ) |
|
228 { |
|
229 $this->page = preg_replace( '#_'.$exts.'#i', '.\\1', $this->page ); |
|
230 } |
|
231 |
|
232 $this->fullpage = $this->page; |
|
233 |
|
234 if(substr($this->page, 0, strlen($this->nslist['Special']))==$this->nslist['Special'] || substr($this->page, 0, strlen($this->nslist['Template']))==$this->nslist['Template']) |
|
235 { |
|
236 $ex = explode('/', $this->page); |
|
237 $this->page = $ex[0]; |
|
238 } |
|
239 if(strstr($this->page, ' ')) |
|
240 { |
|
241 $loc = str_replace(' ', '_', urldecode(rawurldecode($_SERVER['REQUEST_URI']))); |
|
242 $loc = str_replace('+', '_', $loc); |
|
243 $loc = str_replace('%20', '_', $loc); |
|
244 redirect($loc, 'Redirecting...', 'Space in the URL detected, please wait whilst you are redirected', 0); |
|
245 exit; |
|
246 } |
|
247 break; |
|
248 } |
|
249 } |
|
250 if(!$this->page && !($this->page == '' && getConfig('main_page') == '')) |
|
251 { |
|
252 $this->main_page(); |
|
253 } |
|
254 } |
283 } |
255 |
284 |
256 $this->page = sanitize_page_id($this->page); |
285 $this->page = sanitize_page_id($this->page); |
257 $this->fullpage = sanitize_page_id($this->fullpage); |
286 $this->fullpage = sanitize_page_id($this->fullpage); |
258 |
287 |
259 dc_here('paths: setting $paths->cpage'); |
|
260 |
|
261 if(isset($this->pages[$this->page])) |
288 if(isset($this->pages[$this->page])) |
262 { |
289 { |
263 dc_here('paths: page existence verified, our page ID is: '.$this->page); |
|
264 $this->page_exists = true; |
290 $this->page_exists = true; |
265 $this->cpage = $this->pages[$this->page]; |
291 $this->cpage = $this->pages[$this->page]; |
266 $this->namespace = $this->cpage['namespace']; |
292 $this->namespace = $this->cpage['namespace']; |
267 if(!isset($this->cpage['wiki_mode'])) $this->cpage['wiki_mode'] = 2; |
293 if(!isset($this->cpage['wiki_mode'])) $this->cpage['wiki_mode'] = 2; |
268 |
294 |
302 $this->page_protected = $this->cpage['protected']; |
328 $this->page_protected = $this->cpage['protected']; |
303 } |
329 } |
304 } |
330 } |
305 else |
331 else |
306 { |
332 { |
307 dc_here('paths: page doesn\'t exist, creating new page in memory<br />our page ID is: '.$this->page); |
|
308 $this->page_exists = false; |
333 $this->page_exists = false; |
309 $page_name = dirtify_page_id($this->page); |
334 $page_name = dirtify_page_id($this->page); |
310 $page_name = str_replace('_', ' ', $page_name); |
335 $page_name = str_replace('_', ' ', $page_name); |
311 |
336 |
312 $pid_cleaned = sanitize_page_id($this->page); |
337 $pid_cleaned = sanitize_page_id($this->page); |
313 if ( $pid_cleaned != $this->page ) |
338 if ( $pid_cleaned != $this->page ) |
314 { |
339 { |
315 redirect($pid_cleaned, 'Sanitizer message', 'page id sanitized', 0); |
340 redirect($pid_cleaned, 'Sanitizer message', 'page id sanitized', 0); |
316 } |
341 } |
317 |
342 |
318 $this->cpage = Array( |
343 if ( !is_array($this->cpage) ) |
319 'name'=>$page_name, |
344 { |
320 'urlname'=>$this->page, |
345 $this->cpage = Array( |
321 'namespace'=>'Article', |
346 'name'=>$page_name, |
322 'special'=>0, |
347 'urlname'=>$this->page, |
323 'visible'=>0, |
348 'namespace'=>'Article', |
324 'comments_on'=>1, |
349 'special'=>0, |
325 'protected'=>0, |
350 'visible'=>0, |
326 'delvotes'=>0, |
351 'comments_on'=>1, |
327 'delvote_ips'=>'', |
352 'protected'=>0, |
328 'wiki_mode'=>2, |
353 'delvotes'=>0, |
329 ); |
354 'delvote_ips'=>'', |
|
355 'wiki_mode'=>2, |
|
356 ); |
|
357 } |
330 // Look for a namespace prefix in the urlname, and assign a different namespace, if necessary |
358 // Look for a namespace prefix in the urlname, and assign a different namespace, if necessary |
331 $k = array_keys($this->nslist); |
359 $k = array_keys($this->nslist); |
332 for($i=0;$i<sizeof($this->nslist);$i++) |
360 for($i=0;$i<sizeof($this->nslist);$i++) |
333 { |
361 { |
334 $ln = strlen($this->nslist[$k[$i]]); |
362 $ln = strlen($this->nslist[$k[$i]]); |