Esempio n. 1
0
 /**
  * Set file to save error_log messages to
  */
 public function setLogPath($path)
 {
     $path = Sanitize::toPath($path);
     if (is_dir($path) || mkdir($path, 0775, true)) {
         $this->_logdir = $path;
     }
 }
Esempio n. 2
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);
 }
Esempio n. 3
0
 /**
  * Add a new flash message to the list for $key
  */
 public function setFlash($key = "", $class = "", $message = "")
 {
     if (!empty($key) && is_string($key)) {
         $class = Sanitize::toText($class);
         $message = Sanitize::toText($message);
         $key = $this->fkey . "." . $key;
         $list = $this->session->get($key, array());
         $list[] = array("class" => $class, "message" => $message, "addtime" => time());
         $this->session->set($key, $list);
     }
 }
Esempio n. 4
0
 /**
  * Delete an existing key
  */
 public function deleteKey($key)
 {
     $key = Sanitize::toKey($key);
     if (!empty($key)) {
         $list = explode(".", $key);
         $last = array_pop($list);
         $data =& $this->_data;
         foreach ($list as $step) {
             if (!isset($data[$step])) {
                 return;
             }
             $data =& $data[$step];
         }
         if (isset($data[$last])) {
             $data[$last] = null;
             unset($data[$last]);
         }
     }
 }
Esempio n. 5
0
 /**
  * Set file format to me processed
  */
 public function setFormat($format)
 {
     if (is_string($format)) {
         $this->_format = Sanitize::toKey($format);
     }
 }
Esempio n. 6
0
 /**
  * Builds final query string, returns single array with both query string and query data
  */
 public function build()
 {
     $build = [];
     $tables = implode(", ", $this->_tables);
     $columns = !empty($this->_columns) ? implode(", ", $this->_columns) : "*";
     if (!empty($this->_explain)) {
         $build[] = "EXPLAIN";
     }
     if (!empty($this->_type)) {
         $build[] = $this->_type;
     }
     if ($this->_type === "SELECT") {
         $build[] = $columns . " FROM " . $tables;
     }
     if ($this->_type === "INSERT" || $this->_type === "REPLACE") {
         $build[] = "INTO " . $tables . " (" . implode(", ", $this->_fields) . ") VALUES (" . implode(", ", $this->_keys) . ")";
     }
     if ($this->_type === "UPDATE") {
         $build[] = $tables . " SET " . implode(", ", $this->_pairs);
     }
     if ($this->_type === "DELETE") {
         $build[] = "FROM " . $tables;
     }
     if (!empty($this->_joins)) {
         $build[] = implode(" ", $this->_joins);
     }
     if (!empty($this->_clauses)) {
         $build[] = "WHERE " . preg_replace("/(AND|OR)\$/u", "", implode(" ", $this->_clauses));
     }
     if (!empty($this->_group)) {
         $build[] = "GROUP BY " . implode(", ", $this->_group);
     }
     if (!empty($this->_order)) {
         $build[] = "ORDER BY " . implode(", ", $this->_order);
     }
     if (!empty($this->_limit)) {
         $build[] = "LIMIT " . implode(", ", $this->_limit);
     }
     $query = Sanitize::toSingleSpaces(implode(" ", $build));
     $data = $this->_data;
     $this->init();
     return [$query, $data];
 }
Esempio n. 7
0
 /**
  * Make sure all the globals are set
  */
 private function _cleanGlobals()
 {
     $_GET = Sanitize::toArray(@$_GET);
     $_POST = Sanitize::toArray(@$_POST);
     $_FILES = Sanitize::toArray(@$_FILES);
     $_COOKIE = Sanitize::toArray(@$_COOKIE);
     $_REQUEST = array_merge($_GET, $_POST);
 }
Esempio n. 8
0
 /**
  * Load list of table queries by scanning files from a folder
  */
 public static function loadQueries($path)
 {
     $path = Sanitize::toPath($path);
     $output = [];
     if (!empty($path) && is_dir($path)) {
         foreach (glob($path . "/*.php") as $file) {
             $table = Sanitize::toKey(basename($file, ".php"));
             $queries = [];
             include_once $file;
             $output[$table] = $queries;
         }
     }
     return $output;
 }
Esempio n. 9
0
 /**
  * Try to load a file and return it"s rendered output
  */
 private function _load($file = "", $data = [])
 {
     $file = Sanitize::toPath($file);
     $output = null;
     if (!empty($file) && is_file($file)) {
         ob_start();
         include $file;
         $output = ob_get_contents();
         ob_end_clean();
     }
     return $output;
 }
Esempio n. 10
0
 /**
  * Delete an entry for a dot-notated key string
  */
 public function delete($key = "")
 {
     $key = Sanitize::toKey($key);
     if (!empty($key) && $this->started === true) {
         $path = trim($this->container . "." . $key, ".");
         $list = explode(".", $path);
         $last = array_pop($list);
         $data =& $_SESSION;
         foreach ($list as $step) {
             if (!isset($data[$step])) {
                 return;
                 // gone
             }
             $data =& $data[$step];
         }
         if (isset($data[$last])) {
             // need to reference the last key for unset() to work
             $data[$last] = null;
             unset($data[$last]);
         }
     }
 }
Esempio n. 11
0
 /**
  * Copy existing file to another location
  */
 public function copy($newpath = "")
 {
     $path = $this->getPath();
     $newpath = Sanitize::toPath($newpath);
     $parent = dirname($newpath);
     $output = false;
     if (is_file($path) && !empty($newpath)) {
         if (is_dir($parent) || mkdir($parent, 0777, true)) {
             $strin = fopen($path, "rb");
             $strout = fopen($newpath, "wb");
             $output = stream_copy_to_stream($strin, $strout);
             fclose($strin);
             fclose($strout);
         }
     }
     return $output;
 }
Esempio n. 12
0
 /**
  * Get folder items list (recursive)
  */
 public function getRecursiveList()
 {
     $path = $this->getPath();
     $output = array();
     if (is_dir($path)) {
         $dir = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
         $items = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
         foreach ($items as $item) {
             $output[] = Sanitize::toPath($item->getRealPath());
         }
     }
     return $output;
 }
Esempio n. 13
0
 /**
  * Save final image
  */
 public function save($file = "", $quality = 80)
 {
     $file = Sanitize::toPath($file);
     $folder = dirname($file);
     $saved = false;
     if (!empty($file) && $this->img_source !== null) {
         if (is_dir($folder) || mkdir($folder, 0777, true)) {
             @imagealphablending($this->img_source, false);
             @imagesavealpha($this->img_source, true);
             if ($this->img_type === IMAGETYPE_JPEG) {
                 $saved = @imagejpeg($this->img_source, $file, $quality);
             }
             if ($this->img_type === IMAGETYPE_GIF) {
                 $saved = @imagegif($this->img_source, $file);
             }
             if ($this->img_type === IMAGETYPE_PNG) {
                 $saved = @imagepng($this->img_source, $file);
             }
         }
     }
     @imagedestroy($this->img_source);
     $this->img_source = null;
     return $saved;
 }
Esempio n. 14
0
 /**
  * Get the item mime/content-type string
  */
 public function getInfo()
 {
     $time = $this->getTimestamps();
     $title = Sanitize::toTitle($this->_name);
     $title = Sanitize::toCaps($title);
     return array("path" => $this->_path, "parent" => $this->_parent, "extension" => $this->_extension, "name" => $this->_name, "filename" => $this->getFileName(), "type" => $this->getType(), "perms" => $this->getPermissions(), "owner" => $this->getOwner(), "mimetype" => $this->getMimeType(), "category" => $this->getCategory(), "title" => $title, "created" => $time["created"], "modified" => $time["modified"], "accessed" => $time["accessed"], "writable" => is_writable($this->_path));
 }
Esempio n. 15
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;
 }
Esempio n. 16
0
 /**
  * Resolve the current HTTP request path
  */
 public static function getPath($default = "/")
 {
     $path = Utils::value(@$_SERVER["PATH_INFO"], @$_SERVER["ORIG_PATH_INFO"], "");
     $path = Sanitize::toPath($path);
     return !empty($path) ? $path : $default;
 }
Esempio n. 17
0
 /**
  * Remove table and all rows
  */
 public function dropTable($table)
 {
     $table = Sanitize::toSqlName($table);
     if ($result = $this->query("DROP TABLE " . $table)) {
         return $result;
     }
     return false;
 }
Esempio n. 18
0
 /**
  * Get public web url for a local file if it exists
  */
 public static function getFileUrl($file = "")
 {
     $root = self::getScriptPath();
     $file = Sanitize::toPath(trim($file, ". "));
     $path = str_replace($root, "", $file);
     return self::getBaseUrl($path);
 }
Esempio n. 19
0
 /**
  * Send default response depending on request method and response type
  */
 public function sendDefault($status, $response = null, $data = [])
 {
     if (Connection::isMethod("GET")) {
         if (is_object($response)) {
             $this->sendView($status, $response);
         }
         if (is_array($response)) {
             $this->sendText($status, print_r($response, true));
         }
         if (is_string($response)) {
             if (is_file($response)) {
                 $this->sendTemplate($status, $response, $data);
             }
             $this->sendText($status, $response);
         }
         $this->sendText($status, "Empty response.");
     }
     $this->sendJson($status, array_merge(Sanitize::toArray($response), $data));
 }