コード例 #1
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);
		
	}