Example #1
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;
 }
 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;
     }
 }
 /**
  * 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";
 }
 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("*", "  ", $tmp);
             $this->possible_parents[$section->id] = $tmp . $section->title;
         }
     }
     parent::edit();
 }
Example #5
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);
 }
Example #6
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, "", "&");
 }
Example #7
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");
 }
 /**
  * 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);
     }
 }
Example #9
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;
 }
Example #10
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");
     }
 }
Example #11
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 "";
     }
 }
Example #12
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();
 }
 /**
  * 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");
 }