Example #1
0
 /**
  * Callback function for the designer fix preg_replace_callback
  * Automatically adjusts paths if they have .. in them
  * 
  * @access private
  * @final
  * @param array $match An array of the found items from the regular expression
  * @return string
  */
 private final function _designerFixCallback($match)
 {
     // if this isn't empty then it is a link
     $link = !empty($match[2]);
     // get the tag
     $tag = $match[1];
     // set the default to return the full string that was matched
     $return = $match[0];
     $custom = false;
     // do the replacement
     switch ($tag) {
         case "[current]":
             $return = Reg::get("Path.current");
             break;
         case "[site]":
             $return = Reg::get("Path.site");
             break;
         case "[skin]":
             $return = Reg::get("Path.skin");
             break;
         case "[root]":
             $return = Reg::get("Path.root");
             break;
         case "[branch.site]":
             $return = Reg::get("Path.branch");
             break;
         case "[branch.skin]":
             $return = Reg::get("Path.branchSkin");
             break;
         case "[branch.root]":
             $return = Reg::get("Path.branchRoot");
             break;
         default:
             // see if it is a php variable. Quick way to echo variables from $this
             if (strpos($tag, '$') === 1) {
                 $custom = true;
                 $var = str_replace(array('[', ']', '$', 'this->'), '', $tag);
                 // if it is in an object then we need to go down the objects pulling out the variables
                 // not pretty
                 if (strpos($var, '->') !== false) {
                     $parts = explode('->', $var);
                     $failed = false;
                     $var = $this->{array_shift($parts)};
                     foreach ($parts as $part) {
                         if (!isset($var->{$part})) {
                             // variable isn't set so it failed
                             $failed = true;
                             break;
                         }
                         $var = $var->{$part};
                     }
                     if ($failed === false) {
                         $return = $var;
                     }
                 } else {
                     // it is a variable that isn't an object
                     if (isset($this->{$var})) {
                         $return = $this->{$var};
                     }
                 }
                 // the variable didn't exist so send nothing back to the page
                 // don't want variable names to sneak in
                 if ($return == $tag) {
                     $return = '';
                 }
             } else {
                 if (Reg::has(str_replace(array('[', ']'), '', $tag))) {
                     $custom = true;
                     // get the variable from the registry
                     $return = Reg::get(str_replace(array('[', ']'), '', $tag));
                 } else {
                     // look for the tag within the working URI
                     $working_uri = Reg::get("URI.working");
                     if (Reg::hasVal("Branch.name")) {
                         $working_uri = array_merge(array("branch" => Reg::get("Branch.name")), $working_uri);
                     }
                     foreach ($working_uri as $key => $item) {
                         $tmp_key = "[" . $key . "]";
                         if ($tag == $tmp_key && Reg::has('Path.' . $key)) {
                             $return = Reg::get('Path.' . $key);
                             break 1;
                         }
                     }
                 }
             }
             break;
     }
     // if it is a link then we need to do some more processing
     if ($link === true && $custom === false) {
         // remove any ../ from the url so that they are clean
         $link_arr = explode("/", $match[2]);
         $up_link_count = count(array_keys(array_slice($link_arr, 1), ".."));
         $return = explode('/', $return);
         $return = implode("/", $up_link_count ? array_slice($return, 0, -1 * $up_link_count) : $return) . implode("/", array_pad(array_slice($link_arr, $up_link_count + 1), -(count(array_slice($link_arr, $up_link_count + 1)) + 1), ""));
         // if mod_rewrite isn't being used then need to make sure the URL is valid by turning any extra ? into &
         if (Reg::get("URI.useModRewrite") != true && !empty($return)) {
             if (substr_count($return, "?", 0) > 1) {
                 $return = strrev(preg_replace("/\\?/i", "&", strrev($return), substr_count($return, "?", 0) - 1));
             }
         }
     } else {
         if (!empty($match[2])) {
             $return .= $match[2];
         }
     }
     // call hook
     Hook::call('Controller.designerFixCallback', array(&$match, &$return));
     return $return;
 }
 /**
  * Loads the url for the error. If the url points to a page inside the framework the function attempts to load it and handles any errors
  * or issues associated such as loading in a default error. If the url points to a page outside the framework then header location is set
  * and execution is stopped.
  * 
  * @access public
  * @static
  * @final
  * @param string|array $url The url that should be loaded can be the url or an array in the URI.map format
  */
 public function loadURL($url)
 {
     // call hook
     Hook::call('Exception.loadURL.before', array(&$url));
     if (!empty($url)) {
         if (!is_array($url) && preg_match("/^(http:|https:|ftp:|ftps:)/im", $url)) {
             // call hook
             Hook::call('Exception.loadURL.redirect', array(&$url));
             header('Location: ' . $url);
             header('Connection: close');
             exit;
         }
         if (is_array($url)) {
             $url = '/' . implode('/', array_merge(Reg::get("URI.map"), $url));
         }
         $url = str_replace(Reg::get('Path.root'), "", $url);
         $_SERVER['REQUEST_URI'] = $url;
         Reg::set("URI.working", $url);
         Reg::del("Branch.name");
         Config::processURI();
         $load['name'] = Config::uriToClass(Reg::get("URI.working.controller"));
         if (Reg::hasVal("Branch.name")) {
             $load['branch'] = Config::uriToClass(Reg::get("Branch.name"));
         }
         $load['type'] = 'Controller';
         $load = implode('_', $load);
         $controller = new $load();
         if (!is_object($controller)) {
             if (!file_exists(Reg::get("System.defaultError404"))) {
                 include Reg::get("System.defaultError404");
             } else {
                 echo Reg::get("System.defaultError404");
             }
         } else {
             try {
                 // call hook
                 Hook::call('Exception.loadURL.controller', array(&$controller));
                 $controller->_showView();
             } catch (EvergreenException $e) {
                 var_dump($e);
                 exit;
                 if (Reg::get("System.mode") == "development") {
                     if (isset(self::$params['code'])) {
                         $code = self::$params['code'];
                     }
                     // call hook
                     Hook::call('Exception.loadURL.default', array(&$url, &$code));
                     switch ($code) {
                         case 'GEN':
                             if (file_exists(Reg::get("System.defaultErrorGEN"))) {
                                 include Reg::get("System.defaultErrorGEN");
                             } else {
                                 echo Reg::get("System.defaultErrorGEN");
                             }
                             break;
                         case 'DB':
                             if (file_exists(Reg::get("System.defaultErrorDB"))) {
                                 include Reg::get("System.defaultErrorDB");
                             } else {
                                 echo Reg::get("System.defaultErrorDB");
                             }
                             break;
                         default:
                             if (file_exists(Reg::get("System.defaultErrorGEN"))) {
                                 include Reg::get("System.defaultErrorGEN");
                             } else {
                                 echo Reg::get("System.defaultErrorGEN");
                             }
                             break;
                     }
                 }
             }
         }
     } else {
         if (file_exists(Reg::get("System.defaultErrorGEN"))) {
             include Reg::get("System.defaultErrorGEN");
         } else {
             echo Reg::get("System.defaultErrorGEN");
         }
     }
 }
Example #3
0
 /**
  * Returns if an error has been triggered or not.
  * 
  * @access public
  * @static
  * @final
  * @return boolean true if an error has been triggered and boolean false if not
  */
 public static final function triggered()
 {
     $triggered = self::$triggered;
     // call hook
     Hook::call('Error.triggered', array(&$triggered));
     return $triggered;
 }
Example #4
0
 /**
  * Returns the page load info.
  * 
  * @access public
  * @param integer $starttime The float microtime that the script started
  */
 public function showPageLoadInfo($starttime)
 {
     // call hook
     Hook::call('showPageLoadInfo.before', array(&$starttime));
     $totaltime = microtime(true) - $starttime;
     echo sprintf('Time : %.3fs seconds', $totaltime);
     if (class_exists('DB', false)) {
         echo ' | Queries Executed : ' . DB::getQueryCount();
     }
     if (function_exists('memory_get_usage')) {
         // php has to be compiled with --enable-memory-limit for this to exist
         // prior to version 5.2.1
         echo ' | Memory Used : ' . $this->convertBytes(memory_get_usage(true));
     }
     if (function_exists('memory_get_peak_usage')) {
         // php 5.2+
         echo ' | Peak Memory Used: ' . $this->convertBytes(memory_get_peak_usage(true));
     }
     // call hook
     Hook::call('showPageLoadInfo.after');
 }
Example #5
0
 /**
  * Deletes a variable by the key and returns true if deleted otherwise returns false.
  * 
  * @access public
  * @static
  * @param string $key The registration variable that is being accessed
  * @return boolean true if the variable was deleted and boolean false if it wasn't or doesn't exist
  */
 public static function del($key)
 {
     // call hook
     if (method_exists('Hook', 'call')) {
         Hook::call('Reg.del.' . $key, array(&$key));
     }
     $path = explode('.', $key);
     $variablesHolder =& self::$variables;
     // loop through the exploded variable key to get to the correct level in the variable array
     foreach ($path as $i => $path_key) {
         if ($i == count($path) - 1) {
             if (isset($variablesHolder[$path_key])) {
                 // unset the variable key
                 unset($variablesHolder[$path_key]);
                 return true;
             } else {
                 return false;
             }
         } else {
             // set the current level of the array to the holder and continue to loop
             $variablesHolder =& $variablesHolder[$path_key];
         }
     }
     return false;
 }