示例#1
0
 /**
  * Add single check test to local checklist
  */
 public function addCheck($info, $test, $pass = "", $fail = "")
 {
     $info = Sanitize::toString($info);
     $test = Sanitize::toBool($test);
     $pass = Utils::value($pass, "Ready");
     $fail = Utils::value($fail, "Missing");
     $this->_checklist[] = array("info" => $info, "test" => $test, "pass" => $pass, "fail" => $fail);
 }
示例#2
0
 /**
  * Get the server script handling the request
  */
 public static function getScriptFile()
 {
     $value = Utils::value(@$_SERVER["SCRIPT_FILENAME"], "");
     $value = Sanitize::toPath($value);
     return $value;
 }
示例#3
0
 /**
  * Extends the session cookie lifetime period
  */
 public function extendCookie($expire = null)
 {
     $time = time();
     $default = $time + $this->getOption("cookie_lifetime", 0);
     $expire = Utils::value(Sanitize::toTimestamp($expire), $default);
     if ($expire > $time) {
         return setcookie(session_name(), session_id(), $expire, $this->getOption("cookie_path"), $this->getOption("cookie_domain"), $this->getOption("cookie_secure"), $this->getOption("cookie_httponly"));
     }
     return false;
 }
示例#4
0
 /**
  * Returns the HTTP authentication password (if any)
  */
 public static function getPassword($default = "")
 {
     return Utils::value(@$_SERVER["PHP_AUTH_PW"], $default);
 }
示例#5
0
 /**
  * Get array of item timestamps
  */
 public function getTimestamps()
 {
     $path = $this->getPath();
     $now = time();
     $created = Utils::value(@filectime($path), $now);
     $modified = Utils::value(@filemtime($path), $now);
     $accessed = Utils::value(@fileatime($path), $now);
     return array("created" => min($created, $modified, $accessed), "modified" => max($created, $modified), "accessed" => max($modified, $accessed));
 }
示例#6
0
 /**
  * Parse file data as PHP var_dump() data dump
  */
 private function _parseDump($data = "")
 {
     $output = [];
     $data = preg_replace("/(array|object|string)\\(\\w*\\)(\\#\\d*\\s*)?(\\(\\d*\\))?\\s*{?/ui", "", $data);
     $data = preg_replace("/(int|bool)\\((\\w+)\\)/ui", "\$2", $data);
     $data = preg_replace("/\\s*=>[\r\n]+/ui", " => ", $data);
     $data = preg_replace("/[ ]{2,}/ui", " ", $data);
     $data = str_replace(['"', "{", "}"], "", $data);
     foreach ($this->_keymap as $key => $search) {
         @preg_match("/(\\[" . $search . "\\])([\\s\\=\\>]+)(.*)/u", $data, $matches);
         $output[$key] = trim(Utils::value(@$matches[3], ""));
     }
     return $output;
 }
示例#7
0
 /**
  * Parse request body as multipart FormData
  */
 private function _parseForm()
 {
     $boundary = trim(strtok($this->_body, "\n"));
     $chunks = preg_split("/" . $boundary . "(\\-\\-)?/", $this->_body, -1, PREG_SPLIT_NO_EMPTY);
     $params = [];
     $files = [];
     $counter = [];
     if (is_array($chunks)) {
         foreach ($chunks as $index => $chunk) {
             // skip empty chunks
             $chunk = ltrim($chunk, "-\r\n\t\\s ");
             if (empty($chunk)) {
                 continue;
             }
             // split chunk into headers and value
             @(list($head, $value) = explode("\r\n\r\n", $chunk, 2));
             $headers = $this->_parseBodyHeaders($head);
             $name = Utils::value(@$headers["name"], "undefined_" . ($index + 1));
             $type = Utils::value(@$headers["content-type"], "application/octet-stream");
             $key = Sanitize::toKey($name);
             $value = trim($value);
             // counter to increment array-like param names
             if (isset($counter[$key]) !== true) {
                 $counter[$key] = 0;
             }
             // process uploaded file
             if (isset($headers["filename"])) {
                 $file = $headers["filename"];
                 $name = str_replace("[]", "", $name);
                 $path = "";
                 $copy = false;
                 if (!empty($headers["filename"]) && !empty($value)) {
                     $path = Sanitize::toPath(tempnam($this->_tmpdir, "upload"));
                     $copy = file_put_contents($path, $value);
                 }
                 if (preg_match("/\\[\\d+\\]\$/", $name) !== 1) {
                     $name .= "[" . $counter[$key] . "]";
                 }
                 $files[$name . "[name]"] = $file;
                 $files[$name . "[type]"] = $type;
                 $files[$name . "[tmp_name]"] = $path;
                 $files[$name . "[error]"] = !empty($copy) ? 0 : UPLOAD_ERR_NO_FILE;
                 $files[$name . "[size]"] = !empty($copy) ? filesize($path) : 0;
             } else {
                 if (preg_match("/\\[\\]\$/", $name) === 1) {
                     $name = str_replace("[]", "[" . $counter[$key] . "]", $name);
                 }
                 $params[$name] = $value;
             }
             $counter[$key] += 1;
         }
         // finalize arrays
         parse_str(urldecode(http_build_query($params, "", "&")), $_POST);
         parse_str(urldecode(http_build_query($files, "", "&")), $_FILES);
     }
 }
示例#8
0
 /**
  * Set and error and return false
  */
 public function setError($error = "")
 {
     $this->_error = Utils::value($error, "There has been an unspecified database error.");
     return false;
 }
示例#9
0
 /**
  * Load and filter list of menu items data from a file
  */
 private function _loadMenuData($file)
 {
     $file = Sanitize::toPath($file);
     $menu = is_file($file) ? include_once $file : [];
     $output = [];
     $count = 1;
     if (is_array($menu)) {
         foreach ($menu as $idx => $item) {
             $active = "";
             $url = Utils::value(@$item["url"], Server::getBaseUrl());
             if (empty($item["url"])) {
                 if (!empty($item["route"])) {
                     if (preg_match("/^(\\/" . $this->_area . ")?(\\/" . $this->_controller . ")/", $item["route"]) === 1) {
                         $active = "active";
                         // route matched current location
                     }
                     $url = Server::getBaseUrl($item["route"]);
                 } else {
                     if (!empty($item["controller"])) {
                         if ($this->_controller === $item["controller"]) {
                             $active = "active";
                             // controller matched current controller
                         }
                         $area = $this->_area !== "site" ? $this->_area : "";
                         $route = Utils::buildPath($area, $item["controller"], @$item["action"]);
                         $url = Server::getBaseUrl($route);
                     }
                 }
             }
             $item["active"] = $active;
             $item["url"] = $url;
             $output[] = $item;
             $count++;
         }
     }
     return $output;
 }
示例#10
0
 /**
  * Get the formatted error text
  */
 public function getErrorText($text = "")
 {
     $text = Utils::value($text, "Too many failed attempts.");
     $count = $this->session->get($this->key . ".info.fail_count", 0);
     $total = $this->session->get($this->key . ".info.fail_total", 0);
     $last = $this->session->get($this->key . ".info.last_attempt", 0);
     $keymap = array("attempts" => $total, "countdown" => Numeric::toCountdown($last, $this->cd_time), "count" => "(" . $count . "/" . $this->cd_trigger . ")", "total" => "(" . $total . "/" . $this->max_attempts . ")");
     return Utils::render($text, $keymap);
 }
示例#11
0
 /**
  * Set the response charset
  */
 public function setCharset($charset)
 {
     $charset = Sanitize::toText($charset);
     $this->_charset = Utils::value($charset, $this->_charset, "UTF-8");
     return $this;
 }