public function standalone_partial() { if (!$this->routed_controller && WaxUrl::$params["controller"]) { $controller = WaxUrl::$params["controller"]; } else { if (!$this->routed_controller) { $controller = WaxUrl::$default_controller; } else { $controller = $this->routed_controller; } } $delegate = Inflections::slashcamelize($controller, true) . "Controller"; $p_controller = new $delegate(); $p_controller->controller = $controller; $p_controller->use_layout = false; $p_controller->use_format = $this->format; if (strpos($this->path, "/")) { $partial = substr($this->path, strrpos($this->path, "/") + 1); $path = substr($this->path, 0, strrpos($this->path, "/") + 1); $path = $path . $partial; } else { $partial = $this->path; } if (is_array($this->data)) { foreach ($this->data as $var => $val) { $p_controller->{$var} = $val; } } $p_controller->use_view = $partial; if ($p_controller->is_public_method($p_controller, $partial)) { $p_controller->{$partial}(); } $this->output = $p_controller->render_view(); }
public function handle_error() { if ($email = self::$email_on_error) { mail($email, self::$email_subject_on_error, $this->cli_error_message); } if ($location = self::$redirect_on_error) { error_log($this->cli_error_message); if (!self::$double_redirect) { self::$double_redirect = true; header("HTTP/1.1 500 Application Error", 1, 500); if (is_readable(PUBLIC_DIR . ltrim($location, "/"))) { $content = file_get_contents(PUBLIC_DIR . ltrim($location, "/")); ob_end_clean(); foreach (self::$replacements as $value => $replace) { $content = str_ireplace($replace, $this->{$value}, $content); } echo $content; exit; } $_GET["route"] = $location; $delegate = Inflections::slashcamelize(WaxUrl::get("controller"), true) . "Controller"; $delegate_controller = new $delegate(); $delegate_controller->execute_request(); exit; } } header("Status: 500 Application Error"); echo $this->error_message; exit; }
/** * Partial Helper Function * Renders a partial from path $path into the current view * To inherit an existing view use this method: eg..... * * <?=partial("mypartial", $this);?> * * Alternate syntax allows standalone execution that runs the partialname() method * <?=partial("mypartial")?> * * @param string $path * @param array $extra_vals * @param string $format */ public function partial($path, $extra_vals = array(), $format = "html") { $controller = WaxUrl::route_controller($path); $cache = new WaxCache($_SERVER['HTTP_HOST'] . md5($path . $_SERVER['REQUEST_URI'] . serialize($_GET)) . '.partial'); if (count($_POST)) { $cache->expire(); } if (Config::get('partial_cache') && !substr_count($path, "admin") && !substr_count(strtolower($controller), "admin") && $cache->valid()) { $partial = $cache->get(); } else { if ($extra_vals instanceof WaxTemplate) { $old_template_paths = $extra_vals->template_paths; foreach ($extra_vals as $var => $val) { $this->{$var} = $val; } $view = new WXTemplate(); if (count($extra_vals->plugins) > 0) { foreach ($old_template_paths as $template) { $view->add_path(str_replace($extra_vals->use_view, $path, $template)); } } $view->add_path(VIEW_DIR . $path); foreach ($this as $var => $val) { if (!$view->{$var}) { $view->{$var} = $val; } } $view->add_path(VIEW_DIR . $view->controller . "/" . $path); $partial = $view->parse($format, "partial"); } else { if (!$controller) { $controller = WaxUrl::$default_controller; } $delegate = Inflections::slashcamelize($controller, true); $delegate .= "Controller"; $delegate_controller = new $delegate(); $delegate_controller->controller = $controller; $partial = $delegate_controller->execute_partial($path, $format); } } if (Config::get('partial_cache') && !substr_count($controller, "admin")) { $cache->set($partial); } return $partial; }
function __construct($message, $code = "Page cannot be found", $status = "404") { if ($location = self::$redirect_on_error) { $this->error_heading = $code; $this->error_message = $this->format_trace($this); $this->error_site = str_ireplace("www.", '', $_SERVER['HTTP_HOST']); $this->error_site = substr($this->error_site, 0, strpos($this->error_site, '.')); $this->error_site_name = ucwords(Inflections::humanize($this->error_site)); $this->simple_routing_error_log(); if (!self::$double_redirect) { self::$double_redirect = true; header("HTTP/1.1 404 Not Found", 1, 404); if (is_readable(PUBLIC_DIR . ltrim($location, "/"))) { $content = file_get_contents(PUBLIC_DIR . ltrim($location, "/")); foreach (self::$replacements as $value => $replace) { $content = str_ireplace($replace, $this->{$value}, $content); } ob_end_clean(); echo $content; exit; } $_GET["route"] = $location; WaxUrl::$params = false; WaxUrl::perform_mappings(); $delegate = Inflections::slashcamelize(WaxUrl::get("controller"), true) . "Controller"; $delegate_controller = new $delegate(); $delegate_controller->execute_request(); exit; } else { WaxLog::log("error", "[Routing] Double redirect error"); $code = "Application Error"; $message = "A Page not found error was triggered and you have not set up a page to handle it"; } } parent::__construct($message, $code); }
protected function is_controller($test) { $path = ""; if (strpos($test, "/")) { $path = substr($test, 0, strpos($test, "/") + 1); } if (is_file(CONTROLLER_DIR . $path . Inflections::slashcamelize($test, true) . "Controller.php")) { return true; } if (is_file(FRAMEWORK_DIR . "/dispatch/" . Inflections::slashcamelize($test, true) . "Controller.php")) { return true; } return false; }
public function file() { return $this->cache_dir . Inflections::underscore(Inflections::slashcamelize($this->label)) . ".cache"; }
/** * Instantiates a config object and constructs the route. * @access private * @return void */ private function delegate_request() { Session::start(); $delegate = Inflections::slashcamelize(WaxUrl::get("controller"), true) . "Controller"; $delegate_controller = new $delegate(); $delegate_controller->execute_request(); }