static function find_page($url = '') { // clean up path $url = trim($url); if ($url[0] == '/') { $url = substr($url, 1); } if (preg_match('@//|[.][.]|/[.][^/]*@', $url)) { return Page::error_page_file_not_found($url); } // trim trailing slash if (preg_match('@([/]+)$@', $url)) { $url = preg_replace('@([/]+)$@', '', $url); // don't redirect, because apache adds these, and we would loop } // trim extension if (preg_match('@([/]*[.].*|[/]+)$@', $url)) { $url = preg_replace('@([/]*[.].*|[/]+)$@', '', $url); //die($url); Util::redirect($url); } $url = trim($url); if ($url == '') { $url = 'index'; } // options: /* 1. a .php file -> include it 2. a .txt file -> autoformat it 3. a .lhs file -> autoformat it */ if (file_exists("{$url}.txt")) { return new TextFilePage($url, "./{$url}.txt"); } else { if (file_exists("{$url}.lhs")) { return new TextFilePage($url, "./{$url}.lhs"); } else { if (file_exists("{$url}/index.txt")) { return new TextFilePage($url, "./{$url}/index.txt"); } else { if (file_exists("{$url}/index.php")) { include "{$url}/index.php"; return $page; // } else if (file_exists("$url.php")) { // return "x"; } else { return Page::error_page_file_not_found($url); } } } } }
static function die_not_found($url, $msg = '') { $page = Page::error_page_file_not_found($url, $msg); HtmlTemplate::write($page); exit; }