/**
  * Directory Setter/Getter
  * 
  * @param string $dir
  * @throws Exception
  * @return string|FileExplorer
  */
 public function dir($dir = null)
 {
     if ($dir === null) {
         return $this->_dir;
     }
     if (!is_string($dir)) {
         throw new Exception('Invalid Argument');
     }
     //sanitize dir input
     $dir = self::cleanDirname($dir);
     $dir = self::slashTerm($dir);
     if (Folder::isAbsolute($dir)) {
         if (Folder::isWindowsPath($dir)) {
             throw new Exception(__('Cannot use absolute windows path as directory'));
         }
     } else {
         $dir = $this->_dir . $dir;
     }
     $this->_dir = $dir;
     //TODO check if path has changed
     $this->_Folder = $this->getFolder();
     if (!$this->_Folder->pwd()) {
         throw new Exception(__("Folder %s not found", $dir));
     }
     // reset contents
     $this->_contents = null;
     if ($this->autoLoadContents) {
         $this->readContents();
     }
     return $this;
 }
Exemple #2
0
 /**
  * Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.)
  *
  * @param string $path Path to check
  * @return string Set of slashes ("\\" or "/")
  * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::correctSlashFor
  */
 public static function correctSlashFor($path)
 {
     return Folder::isWindowsPath($path) ? '\\' : '/';
 }
Exemple #3
0
 private function __advancedFolderFind($conditions)
 {
     if (empty($this->fileList[0])) {
         $this->return = array();
         return true;
     }
     $i = 0;
     foreach ($this->fileList[0] as $folder) {
         if (in_array($folder, $this->ignore)) {
             continue;
         }
         if ($this->recursive > -2) {
             $Folder = new Folder($this->path . DS . $folder);
             $this->return[$i]['Folder']['path'] = $Folder->path;
             $this->return[$i]['Folder']['name'] = basename($this->return[$i]['Folder']['path']);
             $this->return[$i]['Folder']['parent'] = dirname($this->return[$i]['Folder']['path']);
             $this->return[$i]['Folder']['relative'] = $this->__relativePath($this->return[$i]['Folder']['path']);
             $stat = stat($this->return[$i]['Folder']['path']);
             $this->__fileStatus($i, $stat);
             if ($this->recursive > -1) {
                 $this->return[$i]['Folder']['accessed'] = date('Y-m-d H:i:s', $stat['atime']);
                 $this->return[$i]['Folder']['modified'] = date('Y-m-d H:i:s', $stat['mtime']);
                 $this->return[$i]['Folder']['created'] = date('Y-m-d H:i:s', $stat['ctime']);
                 if ($this->recursive > 0) {
                     $this->return[$i]['Folder']['size'] = $Folder->dirsize();
                     $this->return[$i]['Folder']['absolute'] = $Folder->isAbsolute($this->return[$i]['Folder']['path']);
                     $children = $Folder->tree($this->return[$i]['Folder']['path']);
                     $this->return[$i]['Folder']['sub_folders'] = count($children[0]) - 1;
                     $this->return[$i]['Folder']['sub_files'] = count($children[1]);
                     if ($this->recursive > 1) {
                         $this->return[$i]['Folder']['realpath'] = $Folder->realpath($this->return[$i]['Folder']['path']);
                         $this->return[$i]['Folder']['windows'] = $Folder->isWindowsPath($this->return[$i]['Folder']['path']);
                         $this->return[$i]['Folder']['Children'] = $children;
                         $this->return[$i]['Folder']['Extended'] = $stat;
                         $i++;
                         continue;
                     }
                     $i++;
                 }
                 $i++;
             }
             $i++;
         }
         $i++;
     }
     return true;
 }
Exemple #4
0
 /**
  * testWindowsPath method
  *
  * @return void
  */
 public function testWindowsPath()
 {
     $this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome'));
     $this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome'));
     $this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome'));
     $this->assertTrue(Folder::isWindowsPath('\\\\vmware-host\\Shared Folders\\file'));
 }
Exemple #5
0
	/**
	 * Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.)
	 *
	 * @param string $path Path to check
	 * @return string Set of slashes ("\\" or "/")
	 * @access public
	 * @static
	 */
	function correctSlashFor($path) {
		return (Folder::isWindowsPath($path)) ? '\\' : '/';
	}
Exemple #6
0
 /**
  * Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.)
  *
  * @param string $path Path to check
  * @return string Set of slashes ("\\" or "/")
  * @access public
  * @static
  */
 function correctSlashFor($path)
 {
     if (Folder::isWindowsPath($path)) {
         return '\\';
     }
     return '/';
 }
Exemple #7
0
 /**
  * Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.)
  *
  * @param string $path Path to check
  * @return string Set of slashes ("\\" or "/")
  * @access public
  * @static
  */
 function normalizePath($path)
 {
     if (Folder::isWindowsPath($path)) {
         return '\\';
     }
     return '/';
 }
Exemple #8
0
 /**
  * testWindowsPath method
  *
  * @access public
  * @return void
  */
 function testWindowsPath()
 {
     $this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome'));
     $this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome'));
     $this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome'));
 }
Exemple #9
0
 /**
  * Parses instruction sets and invokes `Medium::make()` for a file
  *
  * @param Model $Model
  * @param string $file Path to a file relative to `baseDirectory`  or an absolute path to a file
  * @return boolean
  */
 function make(&$Model, $file, $overwrite = false)
 {
     extract($this->settings[$Model->alias]);
     list($file, $relativeFile) = $this->_file($Model, $file);
     $relativeDirectory = DS . rtrim(dirname($relativeFile), '.');
     //small patch for windows..
     if (Folder::isWindowsPath($filterDirectory)) {
         $relativeDirectory = str_replace('/', '\\', $relativeDirectory);
     }
     $name = Medium::name($file);
     $filter = Configure::read('Media.filter.' . strtolower($name));
     $hasCallback = method_exists($Model, 'beforeMake');
     foreach ($filter as $version => $instructions) {
         $directory = Folder::slashTerm($filterDirectory . $version . $relativeDirectory);
         $Folder = new Folder($directory, $createDirectory);
         if (!$Folder->pwd()) {
             $message = "MediaBehavior::make - Directory `{$directory}` ";
             $message .= "could not be created or is not writable. ";
             $message .= "Please check the permissions.";
             trigger_error($message, E_USER_WARNING);
             continue;
         }
         if ($hasCallback) {
             $process = compact('overwrite', 'directory', 'name', 'version', 'instructions');
             if ($Model->beforeMake($file, $process)) {
                 continue;
             }
         }
         if (!($Medium = Medium::make($file, $instructions))) {
             $message = "MediaBehavior::make - Failed to make version `{$version}` ";
             $message .= "of file `{$file}`. ";
             trigger_error($message, E_USER_WARNING);
             continue;
         }
         $Medium->store($directory . basename($file), $overwrite);
     }
     return true;
 }