Esempio n. 1
0
 /**
  * Execute the route
  */
 public function Execute()
 {
     $path = $this->GetQueryString();
     if (!isset($this->routes["/"])) {
         return false;
     }
     if (defined("__BUTTERPHP_FILTER__") || defined("__BUTTERPHP_ALL__")) {
         $_GET = \BTRAutoFilter::Filter($_GET);
         $_POST = \BTRAutoFilter::Filter($_POST);
     }
     $p = !is_null($path) ? $path : '/';
     $php = \BTRAutoMap::Query();
     $php->router = $this;
     $php->HTTPCode = !isset($this->routes[$p]) || !isset($this->routes[$p . "/"]) ? 404 : 200;
     foreach ($this->routes as $key => $value) {
         $pattern = $key;
         if (!empty($this->parameterMap[$key])) {
             foreach ($this->parameterMap[$key] as $param) {
                 $pattern .= "((?<" . $param . ">[^/]+)/)?";
             }
             $result = "/" . addcslashes($pattern, "/") . "/";
             $matches = array();
             $matched = preg_match($result, $path, $matches);
             if ($matched === 1) {
                 if (empty($php->get)) {
                     $php->get = new \stdClass();
                 }
                 foreach ($matches as $matchKey => $matchValue) {
                     if (!is_numeric($matchKey)) {
                         $php->get->{$matchKey} = $matchValue;
                     }
                 }
                 return $this->routes[$key]($php);
             }
         }
     }
     if (isset($this->routes[$p])) {
         return $this->routes[$p]($php);
     } else {
         //return the base route if no correction is possible
         return $this->routes["/"]($php);
     }
 }
Esempio n. 2
0
 /**
  * Filters the malicous content (script blogs) from the given data
  * @param mixed $data
  * @return mixed
  */
 public static function Filter($data)
 {
     $cleaned = array();
     if (empty($data)) {
         return $data;
     }
     if (!is_array($data)) {
         return \BTRAutoFilter::Clean($data);
     }
     foreach ($data as $key => $value) {
         $sub = null;
         $cleanedKey = \BTRAutoFilter::Clean($key);
         if (!is_array($value)) {
             $sub = \BTRAutoFilter::Clean($value);
         } else {
             $sub = \BTRAutoFilter::Filter($value);
         }
         $cleaned[$cleanedKey] = $sub;
     }
     return $cleaned;
 }
 public function testFilterNoArrayNothingMalicousFloat()
 {
     $got = \BTRAutoFilter::Filter(1.556);
     $this->assertTrue(floatval($got) === 1.556);
 }