Ejemplo n.º 1
0
 public function __construct($path, $data = array(), $format = "html")
 {
     $this->path = $path;
     $this->data = $data;
     $this->format = $format;
     $this->routed_controller = WaxUrl::route_controller($this->path);
 }
Ejemplo n.º 2
0
 /**
  *  Loops through the defined lookup patterns until one matches
  *  Any url variables that are explicitly set are ignored, this only works on the url portion
  *
  * @return void
  **/
 public static function perform_mappings()
 {
     if (!self::$params) {
         self::$params = $_GET;
     }
     self::detect_maintenance();
     //before mappings get the format
     if (!self::$params["format"] && preg_match("/(.*)\\.(.*)/", self::$params["route"], $matches)) {
         self::$params["format"] = $matches[2];
         self::$params["route"] = $matches[1];
     }
     //before mappings build a route array
     if (!self::$params["route_array"]) {
         self::$params["route_array"] = explode("/", self::$params["route"]);
     }
     foreach (self::$mappings as $map) {
         $left = $map[0];
         $right = self::$params["route"];
         if (substr($right, -1) == "/") {
             $right = substr($right, 0, -1);
         }
         //take off the first slash if it's there
         $left = preg_replace("/:([A-Za-z0-9\\-_]*\\*)/", "([A-Za-z0-9.\\-/_]*)", $left);
         $left = preg_replace("/:([A-Za-z0-9\\-_]*)/", "([A-Za-z0-9.\\-_]*)", $left);
         $left = str_replace("/", "\\/", $left);
         if ($left === $right && !strpos($left, ":")) {
             $mapped_route = $map[1];
         } elseif (preg_match("/" . $left . "/", $right, $matches)) {
             if (!self::$params["controller"] && !$map[1]["controller"]) {
                 self::route_controller();
                 break;
             }
             $mappings = split("/", $map[0]);
             array_shift($matches);
             while (count($mappings)) {
                 if ($mappings[0] == $matches[0]) {
                     // exact text mappings
                     array_shift($matches);
                 } elseif (substr($mappings[0], 0, 1) == ":" && substr($mappings[0], -1) == "*") {
                     // *-based variable mappings to allow any number of variables
                     $mapped_route[substr($mappings[0], 1, -1)] = explode("/", $matches[0]);
                 } elseif (substr($mappings[0], 0, 1) == ":") {
                     // variable-based mappings
                     $mapped_route[substr($mappings[0], 1)] = $matches[0];
                     array_shift($matches);
                 }
                 array_shift($mappings);
             }
             $mapped_route = array_merge($mapped_route, (array) $map[1]);
         }
         // Map against named parameters in options array
         if ($mapped_route) {
             foreach ($mapped_route as $k => $val) {
                 self::$params[$k] = $val;
             }
             break;
         }
     }
     self::force_defaults();
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 function __construct()
 {
     /**
      * authentication
      **/
     $auth = new WaxAuthDb(array("encrypt" => false, "db_table" => $this->auth_database_table, "session_key" => "wildfire_user_cookie"));
     $this->current_user = $auth->get_user();
     if ($this->current_user->usergroup == 30) {
         $this->is_admin = true;
     }
     /**
      * module setup
      **/
     $this->before_filter("all", "check_authorised", array("login"));
     $this->configure_modules();
     $this->all_modules = CMSApplication::get_modules(true);
     if (!array_key_exists($this->module_name, CMSApplication::get_modules())) {
         Session::add_message('This component is not registered with the application.');
         $this->redirect_to('/admin/home/index');
     }
     /**
      * model instanciation
      **/
     $this->cm_conf = CmsConfiguration::get("general");
     if ($this->model_class) {
         $this->model = new $this->model_class($this->cm_conf['campaign_monitor_ClientID']);
         $this->model_name = WXInflections::underscore($this->model_class);
     }
     $this->sub_links["create"] = "Create New " . $this->display_name;
     $this->sub_links["view_subscriber"] = "View Subscribers";
     $this->sub_links["view_segments"] = "View Segments";
     if (!($this->this_page = WaxUrl::get("page"))) {
         $this->this_page = 1;
     }
 }
Ejemplo n.º 5
0
 public function setUp()
 {
     $_POST = array();
     $_GET = array();
     WaxUrl::$params = false;
     Request::$params = false;
 }
Ejemplo n.º 6
0
 public function init()
 {
     if (!self::$init) {
         self::$get = WaxUrl::get_params();
         self::$post = $_POST;
         self::$params = array_merge(self::$get, self::$post);
         self::$init = true;
     }
 }
Ejemplo n.º 7
0
 /**
  * Ajax function - removes an association between a section and a user
  * makes a view with new data
  **/
 public function remove_section()
 {
     $this->use_layout = false;
     $this->model = new $this->model_class(WaxUrl::get("id"));
     $section = new CmsSection(Request::get("sect"));
     $this->model->allowed_sections->unlink($section);
     $sect = new CmsSection();
     $this->all_sections = $sect->all();
     $this->use_view = "_list_sections";
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }
Ejemplo n.º 9
0
 public function edit()
 {
     $model = new $this->model_class(WaxUrl::get("id"));
     $this->possible_parents = array("None");
     $remove_ids = array();
     foreach ($model->tree() as $section) {
         $remove_ids[] = $section->id;
     }
     //only the subtree of the current node
     foreach ($this->model->tree() as $section) {
         //all sections
         if (!in_array($section->id, $remove_ids)) {
             $tmp = str_pad("", $section->get_level(), "*", STR_PAD_LEFT);
             $tmp = str_replace("*", "&nbsp;&nbsp;", $tmp);
             $this->possible_parents[$section->id] = $tmp . $section->title;
         }
     }
     parent::edit();
 }
Ejemplo n.º 10
0
 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);
 }
Ejemplo n.º 11
0
 /**
  * Using the route array this function:
  *  - creates a stacking order, 
  *  - traverses the stack,
  *  - checks for extension names (ie if you add .xml it will look for a view with .xml),
  *  - checks that the part your looking for is a number (to discount get vars) & looks up the section
  *  - adds the url to the stack
  * If the initial stack has something left in it (ie a content url) look for that or look for all content in the section
  */
 protected function find_contents_by_path()
 {
     //use the full url params to create the stack to look though
     if (!($stack = WaxUrl::get("route_array"))) {
         $stack = $this->route_array;
     }
     //use the WaxUrl route array, revert to old controller->route_array otherwise
     unset($stack['route']);
     unset($stack['controller']);
     //remove the controller as this is set by the app, so dont want to look for this as a section
     foreach ($stack as $key => $url) {
         //check the formatting - if found then it removes the extension
         if ($key === "format") {
             $this->set_formatting($url);
             unset($stack[$key]);
         } elseif ($this->find_section($url, $this->cms_section->id)) {
             //only check numeric keys, ie not page or search terms && check its a section
             $this->section_stack[] = $url;
             unset($stack[$key]);
         }
     }
     //if theres something left in the stack, find the page
     if (count($stack)) {
         $this->find_content(end($stack));
     } else {
         $this->find_content(false);
     }
 }
Ejemplo n.º 12
0
 /**
  *  Generate URL based on current URL and optional arguments
  *
  *  @param mixed[]
  *  <ul>
  *    <li><b>string:</b><br />
  *      The string value is returned immediately with no
  *      substitutions.</li>
  *    <li><b>array:</b>
  *     <ul>
  *       <li><samp>':controller'=></samp><i>controller value</i></li>
  *       <li><samp>':action'=></samp><i>action value</i></li>
  *       <li><samp>':id'=></samp><i>id value</i></li>
  *     </ul>
  *  </ul>
  *  @return string
  */
 public function url_for($options = array(), $url_base = "/")
 {
     $url = array();
     $extra_params = array();
     if (is_array($options) && array_key_exists("controller", $options)) {
         $url[] = $options["controller"];
         unset($options["controller"]);
     } else {
         $url[] = WaxUrl::get("controller");
     }
     //  If controller found, get action from $options
     if (is_array($options) && array_key_exists("action", $options)) {
         $url[] = $options["action"];
         unset($options["action"]);
     } else {
         $url[] = WaxUrl::get("action");
     }
     if (is_array($options) && array_key_exists("id", $options)) {
         $url[] = $options["id"];
         unset($options["id"]);
     } else {
         $url[] = WaxUrl::get("id");
     }
     if (is_array($options) && count($options)) {
         foreach ($options as $key => $value) {
             $extra_params[$key] = $value;
         }
     }
     if (!count($extra_params)) {
         if (array_pop(array_values($url)) == "index") {
             array_pop($url);
         }
         return str_replace("//", "/", $url_base . implode("/", $url) . "/");
     }
     return $url_base . str_replace("//", "/", implode("/", $url) . "/") . "?" . http_build_query($extra_params, "", "&");
 }
Ejemplo n.º 13
0
 public function test_hyphenated_actions()
 {
     $_GET["route"] = "gallery-create/anyid";
     $this->assertEqual(WaxUrl::get("controller"), "page");
     $this->assertEqual(WaxUrl::get("action"), "gallery-create");
     $this->assertEqual(WaxUrl::get("id"), "anyid");
 }
Ejemplo n.º 14
0
 /**
  *	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();
 }
Ejemplo n.º 15
0
 public function member()
 {
     $this->member = $this->fetch_member_data(WaxUrl::get("id"));
     $this->model_viewer_width = 703;
     $this->model_viewer_height = 500;
     foreach ($this->member['items'] as $item) {
         if (in_array($item['slot'], $this->counted_item_slots) && $item['ilevel']) {
             $total_ilevel += $item['ilevel'];
             $total_counted_items += 1;
         }
     }
     if ($total_counted_items > 0) {
         $this->member['avg_ilevel'] = $total_ilevel / $total_counted_items;
     }
     //print_r($this->member); exit;
 }
Ejemplo n.º 16
0
 /**
  * delete model record
  */
 public function delete()
 {
     $id = WaxUrl::get("id");
     if (!$id) {
         $id = $this->route_array[0];
     }
     if ($id) {
         /*updated to new methods*/
         $field = $this->model->primary_key;
         $model = $this->model->clear()->filter($field . '=' . $id)->first()->limit(false)->delete();
         Session::add_message("Item successfully deleted");
         $this->redirect_to("/" . WaxUrl::get("controller") . "/index");
     }
 }
Ejemplo n.º 17
0
 /**
  *	This method is what it's all about, it simply steps through the filters and
  *	runs the action.
  *
  *	It then picks up the view content along the way and hey presto, you have a page.
  *  If you've messed up and not provided an action, it throws an exception.
  *
  *	@access protected
  */
 public function execute_request()
 {
     $this->controller = WaxUrl::get("controller");
     $this->action = WaxUrl::get("action");
     $this->route_array = explode("/", $_GET["route"]);
     $this->use_format = WaxUrl::get("format");
     WaxLog::log("info", "Loading controller {$this->controller} with action {$this->action} from route '{$_GET['route']}'");
     $this->controller_global();
     $this->run_filters("before");
     if (!$this->is_public_method($this, $this->action)) {
         if ($this->is_public_method($this, Inflections::underscore($this->action))) {
             $underscore_action = Inflections::underscore($this->action);
             $this->{$underscore_action}();
         } elseif (method_exists($this, 'method_missing')) {
             $this->method_missing();
         } else {
             $class = get_class($this);
             throw new WXRoutingException("No Public Action Defined for - " . $this->action . " in controller {$class}.", "Missing Action");
         }
     } else {
         $this->{$this->action}();
     }
     $this->run_filters("after");
     $this->content_for_layout = $this->render_view();
     if ($content = $this->render_layout()) {
         echo $content;
     } elseif ($this->content_for_layout) {
         echo $this->content_for_layout;
     } else {
         echo "";
     }
 }
Ejemplo n.º 18
0
 public function url($options)
 {
     return WaxUrl::build_url($options);
 }
Ejemplo n.º 19
0
 /**
  * Ajax function - removes an association between a category and a content record
  * makes a view with new data
  **/
 public function remove_category()
 {
     $this->use_layout = false;
     $this->model = new $this->model_class(WaxUrl::get("id"));
     $category = new CmsCategory(Request::get("cat"));
     $this->model->categories->unlink($category);
     if (!($this->attached_categories = $this->model->categories)) {
         $this->attached_categories = array();
     }
     $cat = new CmsCategory();
     if (!($this->all_categories = $cat->all())) {
         $this->all_categories = array();
     }
     $this->cat_partial = $this->render_partial("list_categories");
 }