コード例 #1
0
ファイル: App.php プロジェクト: ricobl/frix
	private function get_models () {
		
		if (!isset($this->models)) {
			// Each model must have its own php-file named by its Model-extended class
			$this->models = Fs::dir($this->models_path, '(.+)\.php$', '\1');
		}
		
		return $this->models;
		
	}
コード例 #2
0
ファイル: views.php プロジェクト: ricobl/frix
	function files_list ($root, $path = '') {
		
		$fb_root = url(self::$root, $root);
		
		self::$context['filebrowser'] = true;
		
		$this->context_breadcrumbs('Filebrowser', $fb_root);
		
		$files = array();
		
		// Fix empty path
		$path = preg_replace('#(^/)|(/$)#', '', $path);
		
		$real_path = join_path(Frix::config('MEDIA_ROOT'), $this->file_manager_path, $path);
		
		if ($path) {
			
			$current_path = $fb_root;
			$parts = explode('/', $path);
			
			foreach ($parts as $part) {
				$current_path = url($current_path, $part);
				$this->context_breadcrumbs($part, $current_path);
			}
			
			// Remove current dir
			array_pop($parts);
			
			$files[] = array(
				'name' => '.. (' . end($parts) . ')',
				'class' => 'up',
				'size' => ' ',
				'is_dir' => true,
				'is_empty' => false,
				'link' => url($fb_root, dirname($path)),
			);
		}
		
		if (!is_dir($real_path)) {
			throw new Http404Exception;
		}
		
		if ($_POST['new_dir']) {
			return $this->files_new_dir($real_path);
		}
		elseif ($_POST['new_file']) {
			return $this->files_new($real_path);
		}
		elseif ($_GET['del']) {
			return $this->files_delete($real_path);
		}
		
		if ($_GET['err']) {
			
			self::$context['msg_type'] = 'err';
			
			if ($_GET['err'] == 'bad_upload') {
				load('Upload');
				self::$context['msg'] = Upload::$errors[$_GET['code']];
			}
			else {
				$msg = array(
					'err_upload' => 'Couldn\'t save file, check your permissions.',
					'bad_dir' => 'Invalid or forbidden folder name!',
					'file_exists' => 'File or folder already exists, try a different name.',
					'del_dir' => 'Couldn\'t remove folder, check if it is empty.',
					'del_file' => 'Couldn\'t remove folder, check your permissions.',
					'not_found' => 'Object not found!',
				);
				
				self::$context['msg'] = $msg[$_GET['err']];
			}
			
			
		}
		elseif ($_GET['msg']) {
			$msg = array(
				'new_dir' => 'Folder created sucessfully!',
				'del_dir' => 'Folder removed sucessfully!',
				'del_file' => 'File removed sucessfully!',
				'new_file' => 'File uploaded sucessfully!',
			);
			
			self::$context['msg'] = $msg[$_GET['msg']];
			self::$context['msg_type'] = 'ok';
		}
		
		// Load a list of files not starting with a dot
		$file_list = Fs::dir($real_path, '^[^.].*');
		
		$base_link = url(Frix::config('MEDIA_URL'), $this->file_manager_path, $path);
		
		foreach ($file_list as $file) {
			
			$full_path = join_path($real_path, $file);
			
			$file_obj = array(
				'name' => $file,
			);
			
			if (is_dir($full_path)) {
				$file_obj['size'] = ' ';
				$file_obj['link'] = url($fb_root, $path, $file);
				$file_obj['is_dir'] = true;
				$file_obj['is_empty'] = Fs::is_empty_dir($full_path);
				$file_obj['class'] = 'dir';
			}
			else {
				$file_obj['size'] = Fs::format_size(Fs::file_size($full_path), 1);
				$file_obj['link'] = url($base_link, $file);
				$file_obj['target'] = '_blank';
				$file_obj['class'] = Fs::extension($file);
			}
			
			$files[] = $file_obj;
			
		}
		
		self::$context['files'] = $files;
		
		$t = new Template('frix/admin/filebrowser/list');
		echo $t->render(self::$context);
		
	}
コード例 #3
0
ファイル: Node.php プロジェクト: jasny/Q
 /**
  * Copy or rename/move this file.
  * 
  * @param callback $fn     copy or rename
  * @param Fs_Dir   $dir
  * @param string   $name
  * @param int      $flags  Fs::% options as binary set
  * @return Fs_Node
  */
 protected function doCopyRename($fn, $dir, $name, $flags = 0)
 {
     if (empty($name) || $name == '.' || $name == '..' || strpos('/', $name) !== false) {
         throw new SecurityException("Unable to {$fn} '{$this->_path}' to '{$dir}/{$name}': Invalid filename '{$name}'");
     }
     if (!$dir instanceof Fs_Dir) {
         $dir = Fs::dir($dir, dirname($this->_path));
     }
     if (!$dir->exists()) {
         if (~$flags & Fs::MKDIR) {
             throw new Fs_Exception("Unable to " . ($fn == 'rename' ? 'move' : $fn) . " '{$this->_path}' to '{$dir}/': Directory does not exist");
         }
         $dir->create();
     } elseif ($dir->has($name)) {
         $dest = $dir->{$name};
         if ($dest instanceof Fs_Dir && !$dest instanceof Fs_Symlink && count($dest) != 0) {
             throw new Fs_Exception("Unable to {$fn} '{$this->_path}' to '{$dest->_path}': Target is a non-empty directory");
         }
         if ($flags & Fs::UPDATE == Fs::UPDATE && $dest['ctime'] >= $this['ctime']) {
             return false;
         }
         if (~$flags & Fs::OVERWRITE) {
             throw new Fs_Exception("Unable to {$fn} '{$this->_path}' to '{$dest->_path}': Target already exists");
         }
         if ($dest instanceof Fs_Dir) {
             if (!@rmdir($dest->_path)) {
                 throw new Fs_Exception("Failed to {$fn} '{$this->_path}' to '{$dir}/{$name}'", error_get_last());
             }
         } elseif ($this instanceof Fs_Dir) {
             if (!unlink($dest->_path)) {
                 throw new Fs_Exception("Failed to {$fn} '{$this->_path}' to '{$dir}/{$name}'", error_get_last());
             }
         }
     }
     if ($fn == 'copy' && $flags & Fs::NO_DEREFERENCE) {
         return Fs::symlink($this->target(), "{$dir}/{$name}");
     }
     if (!@$fn($this->_path, "{$dir}/{$name}")) {
         throw new Fs_Exception("Failed to {$fn} '{$this->_path}' to '{$dir}/{$name}'", error_get_last());
     }
     return Fs::get("{$dir}/{$name}");
 }
コード例 #4
0
ファイル: Dir.php プロジェクト: jasny/Q
 /**
  * ArrayAccess; Returns the value at specified offset, loading the section if needed.
  * 
  * @param string $key
  * @return Config_File
  */
 public function offsetGet($key)
 {
     if (parent::offsetExists($key)) {
         return parent::offsetGet($key);
     }
     $dirname = "{$this->_path}/{$key}";
     $filename = "{$dirname}.{$this->_ext}";
     $options = array();
     if ($this->_transformer) {
         $options['transformer'] = $this->_transformer;
     }
     if (is_dir($dirname)) {
         parent::offsetSet($key, new Config_Dir(Fs::dir($dirname), $options));
     } elseif (file_exists($filename)) {
         parent::offsetSet($key, new Config_File(Fs::file($filename), $options));
     } else {
         trigger_error("Configuration section '{$key}' doesn't exist for '{$this->_path}'", E_WARNING);
         return null;
     }
     return parent::offsetGet($key);
 }