Esempio n. 1
0
 /**
  * Loads data from files in a folder, or single file into the local data array
  */
 public function loadData()
 {
     $args = func_get_args();
     $key = count($args) > 1 ? array_shift($args) : '';
     $path = count($args) > 0 ? Sanitize::toPath(array_shift($args)) : '';
     $data = array();
     if (is_dir($path)) {
         foreach (glob($path . '/*.php', GLOB_NOSORT) as $file) {
             $d = (include $file);
             if (!empty($d)) {
                 $n = basename($file, '.php');
                 $data[$n] = $d;
             }
         }
     } else {
         if (is_file($path) && strpos($path, '.php') !== false) {
             $d = (include $path);
             if (!empty($d)) {
                 $n = basename($path, '.php');
                 $data[$n] = $d;
             }
         }
     }
     if (!empty($key)) {
         $this->set($key, $data);
         return;
     }
     $this->setData($data);
 }
Esempio n. 2
0
 /**
  * Sets the cookie path
  */
 public function setPath($value = '')
 {
     $value = Sanitize::toPath($value);
     if (!empty($value)) {
         $this->_path = $value;
     }
 }
Esempio n. 3
0
 /**
  * Get the item mime/content-type string
  */
 public function getMimeType($default = '')
 {
     $path = $this->getPath();
     $ext = $this->getExtension('none');
     $output = '';
     if (is_dir($path)) {
         $output = 'inode/directory';
     } else {
         if (is_file($path) && !empty($ext)) {
             // try from cache
             if (empty($output) && !empty($this->_cache['mimetype'][$ext])) {
                 $output = $this->_cache['mimetype'][$ext];
             }
             // try using finfo_open
             if (empty($output) && function_exists('finfo_open')) {
                 $finfo = @finfo_open(@FILEINFO_MIME_TYPE);
                 $output = Sanitize::toPath(@finfo_file($finfo, $path));
                 @finfo_close($finfo);
             }
             // try using system file command
             if (empty($output) && function_exists('system')) {
                 @ob_start();
                 @system('file -bi ' . escapeshellarg($path));
                 $output = Sanitize::toPath(preg_replace('/\\;.*$/ui', '', @ob_get_clean()));
             }
             // try using exif_imagetype
             if (empty($output) && function_exists('exif_imagetype') && ($imgtype = @exif_imagetype($path))) {
                 $output = Sanitize::toPath(@image_type_to_mime_type($imgtype));
             }
         }
     }
     if (!empty($output)) {
         $this->_cache['mimetype'][$ext] = $output;
         return $output;
     }
     return $default;
 }
Esempio n. 4
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. 5
0
 /**
  * Set the base path where session files will be saved
  */
 public function setSavePath($path = '')
 {
     $path = Sanitize::toPath($path);
     if (!empty($path)) {
         if (is_dir($path) || mkdir($path, 0775, true)) {
             $this->setOption('save_path', $path);
         }
     }
 }
Esempio n. 6
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. 7
0
 /**
  * Convert a request path string into routing params
  */
 public function parse()
 {
     $this->resetActions();
     $this->resetParams();
     $this->setArea($this->_default_area);
     $this->setController($this->_default_controller);
     $this->addAction('init-action', false);
     $path = Utils::getValue($this->_path_request, '/');
     $path = Sanitize::toPath(@parse_url($path, PHP_URL_PATH));
     $path = str_replace(Server::getBasePath(), '', $path);
     $route = explode('/', trim($path, '/'));
     if (!empty($route[0]) && $this->areaExists($route[0])) {
         $this->setArea(array_shift($route));
     }
     if (!empty($route[0])) {
         $this->setController(array_shift($route));
     }
     if (!empty($route[0])) {
         $this->addAction(array_shift($route));
     }
     if (!empty($route)) {
         $this->_params = array_values($route);
     }
     if (count($this->_actions) === 1) {
         $this->addAction($this->_default_action);
     }
 }
Esempio n. 8
0
 /**
  * Send redirect response
  */
 public function redirect($location = '', $code = 302, $delay = 1)
 {
     $current = Server::getUrl();
     $location = Sanitize::toUrl($location);
     $path1 = Sanitize::toPath(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
     $path2 = Sanitize::toPath(parse_url($location, PHP_URL_PATH));
     $code = is_numeric($code) ? intval($code) : 302;
     if (Validate::isExternal($location) || $path1 !== $path2) {
         $this->flushHeaders();
         $this->flushContents();
         $this->setText($code, '');
         $this->setHeader('Location', $location, true);
         $this->setHeader('Connection', 'close', true);
         $this->send($delay);
     }
     throw new Exception('Redirect aborted, from (' . $current . ') to (' . $location . ').');
 }
Esempio n. 9
0
 /**
  * Adds an entry to the list of breadcrumb links data
  */
 public function addCrumb($name = '', $link = '', $title = '', $params = array())
 {
     $key = Sanitize::toKey($name);
     $name = Sanitize::toName($name);
     $link = Sanitize::toPath($link);
     $title = Sanitize::toTitle($title);
     if (!empty($key) && !empty($link)) {
         $crumbs = $this->get('crumbs', array());
         $crumbs[$key] = array_merge(array('name' => $name, 'link' => $link, 'title' => $title), $params);
         $this->set('crumbs', $crumbs);
     }
 }
Esempio n. 10
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. 11
0
 /**
  * Cleans a path and removes the doc root from it
  */
 private function _relativePath($path = '')
 {
     $path = Sanitize::toPath($path);
     $root = Sanitize::toPath($_SERVER['DOCUMENT_ROOT']);
     foreach (explode('/', $root) as $dir) {
         $path = str_replace($dir . '/', '', $path);
     }
     return '/' . $path;
 }