* @license PHP License * @package WB * @subpackage base */ WBClass::load('WBWxml_Dialog'); /** * Wxml Dialog Module * * * * @version 0.1.0 * @package WB * @subpackage base */ class WBWxml_Dialog_Vfsfile extends WBWxml_Dialog { /** * file * @var WBVFS_File */ protected $file; /** * explorer * @var WBVFS_Explorer */ protected $expl; /** * current working directory * @var array */ protected $cwd = array( 'position' => 'block', 'width' => '100', 'height' => '75' ); /** * Start Dialog * * */ public function start() { if (!$this->startVFS()) { return; } $this->cwd['position'] = $this->getAttribute('position', $this->cwd['position']); $this->cwd['width'] = $this->getAttribute('width', $this->cwd['width']); $this->cwd['height'] = $this->getAttribute('height', $this->cwd['height']); $dir = $this->req->get('dir', '0'); if ($dir === '0' || empty($dir)) { $dir = 0; } $selected = array(); if (!empty($this->value)) { $selected[] = $this->value; $this->file = $this->file->loadByObscureId($this->value); if ($this->file->isOK()) { $dir = $this->file->getDirId(); } } return $this->listFiles($dir, $selected); } /** * Submit falues * * */ public function submit() { if (!$this->startVFS()) { return; } $this->cwd['position'] = $this->req->get('position', 10); $this->cwd['width'] = $this->req->get('width', $this->cwd['width']); $this->cwd['height'] = $this->req->get('height', $this->cwd['height']); $query = $this->req->get('query'); $this->tmpl->addGlobalVar('query', $query); $selected = $this->req->get('file', $this->value); if (!is_array($selected)) { $selected = array($selected); } $dir = $this->req->get('dir', '0'); if ($dir === '0' || empty($dir)) { $dir = 0; } // select first match if ('find' == $this->req->get('action', '')) { $this->file = $this->file->loadByName($query); $selected = array($this->file->getObscureId()); $dir = $this->file->getDirId(); return $this->listFiles($dir, $selected); } if (1 > count($selected)) { return $this->listFiles($dir, $selected); } $files = $this->file->listObscureId($selected); if (empty($files)) { return $this->listFiles($dir, array()); } $this->loadTemplates('insert'); $this->tmpl->addGLobalVars($this->cwd, 'cwd_'); $this->tmpl->addRows('file_list_entry', $files); return true; } /** * User required * * @return bool true if user is logged in, false otherwise */ protected function requireUser() { return false; } /** * List Files and Folder * * * @param string $dir * @param array $selected * @return bool always false */ protected function listFiles($dir, $selected = array()) { WBClass::load('WBException_Datasource'); try{ $this->cwd = array_merge($this->cwd, $this->expl->getDir($dir)); } catch (WBException_Datasource $e) { if ($e->getCode() != 'WBDatasource_Tree:1') { throw $e; } $dir = 0; } $dirs = $this->expl->lsDir($dir); $files = $this->file->listDir($dir); // preselect files foreach ($files as &$f) { if (in_array($f['obscureid'], $selected)) { $f['checked'] = 'checked="checked"'; } } // current working directory $this->cwd['parent'] = $this->expl->getParentDirId($dir); $this->cwd['path'] = $this->expl->getPath($dir, true); $this->cwd['file_count'] = count($files); $this->cwd['dir_count'] = count($dirs); $this->loadTemplates('list'); $this->tmpl->addGLobalVars($this->cwd, 'cwd_'); $this->tmpl->addRows('file_list_entry', $files); $this->tmpl->addRows('dir_list_entry', $dirs); return false; } /** * start virtual file system * * Initialize explorer and file object */ protected function startVFS() { if ($this->file) { return true; } if (!$this->user->isAuthenticated()) { $this->tmpl->readTemplatesFromInput('Wxml/dialog/anon.tmpl'); return false; } $sess = WBClass::create('patSession'); $param = array( 'user' => $this->user->getId() ); if ($sess->has('vfsfile_user')) { $param['user'] = $sess->get('vfsfile_user'); } $this->expl = WBClass::create('WBVFS_Explorer', $param); $this->file = WBClass::create('WBVFS_File', $param); // load default values from config $config = WBClass::create('WBConfig'); if (!$config->load('wxml/converter/wb/vfsfile', true)) { return; } $this->cwd['width'] = $config->get('defaultwidth', $this->cwd['width']); $this->cwd['height'] = $config->get('defaultheight', $this->cwd['height']); return true; } }