Ejemplo n.º 1
0
 public static function create()
 {
     // use "Main" as the default
     $page = "Main";
     // check the requested page title for safety and sanity
     $pathinfo = explode('/', WebRequest::pathInfo());
     $pathinfo = array_values(array_filter($pathinfo));
     if (count($pathinfo) >= 1 && $pathinfo[0] != "" && !ereg("[^a-zA-Z0-9]", $pathinfo[0])) {
         $page = $pathinfo[0];
     }
     // okay, the page title should be reasonably safe now, let's try and make the page
     $pagename = "Page" . $page;
     global $cIncludePath;
     $filepath = $cIncludePath . "/Page/" . $pagename . ".php";
     if (file_exists($filepath)) {
         require_once $filepath;
     } else {
         // oops, couldn't find the requested page, let's fail gracefully.
         $pagename = "Page404";
         $filepath = $cIncludePath . "/Page/" . $pagename . ".php";
         require_once $filepath;
     }
     if (class_exists($pagename)) {
         $pageobject = new $pagename();
         if (get_parent_class($pageobject) == "PageBase") {
             Hooks::run("CreatePage", array($pageobject));
             return $pageobject;
         } else {
             // defined, but doesn't inherit properly, so we can't guarentee stuff will work.
             throw new Exception();
         }
     } else {
         // file exists, but the class "within" doesn't, this is a problem as stuff isn't where it should be.
         throw new Exception();
     }
 }