Пример #1
0
 public function ls($path = null)
 {
     xapp_import('xapp.Directory.Utils');
     xapp_import('xapp.VFS.Local');
     //we listen to VFS messages
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_META_CREATED, $this, "_onItem");
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_ADD, $this, "_addNode");
     //create a single scope for now
     //prepare vfs
     $vfsItems = array();
     //mount one item at root, the system scope.
     $vfsItems[] = array('name' => 'root', 'path' => $path . DIRECTORY_SEPARATOR);
     //vfs ctor
     $this->_vfs = XApp_VFS_Local::factory($vfsItems);
     //vfs dir scanning options
     $directoryOptions = array(XApp_Directory_Utils::OPTION_ONLY_DIRS => false, XApp_Directory_Utils::OPTION_ONLY_FILES => false, XApp_Directory_Utils::OPTION_RECURSIVE => true, XApp_Directory_Utils::OPTION_CLEAR_PATH => true);
     //prepare result
     $this->_currentNodes = array();
     $this->_currentNodes['items'] = array();
     //fire vfs
     $items = $this->_vfs->ls('root/', true, array(XApp_File_Utils::OPTION_DIR_LIST_FIELDS => XAPP_XFILE_SHOW_ISDIR, XApp_File_Utils::OPTION_DIR_LIST => $directoryOptions, XApp_Directory_Utils::OPTION_INCLUDE_LIST => array('*')));
     //complete tree-store data
     $this->_currentNodes['identifier'] = 'path';
     $this->_currentNodes['label'] = 'name';
     return $this->_currentNodes;
 }
Пример #2
0
 public function ls($mount = 'ws', $path = '/', $options = null)
 {
     xapp_import('xapp.Xapp.Hook');
     $recursive = false;
     //sanitize
     $basePath = XApp_Path_Utils::normalizePath($mount, false, false);
     if ($basePath === '' || $basePath === '.') {
         $basePath = 'root';
     }
     $path = XApp_Path_Utils::normalizePath($path, false, false);
     $options = (array) $options;
     $scanPath = $basePath . DIRECTORY_SEPARATOR . $path;
     $scanPath = XApp_Path_Utils::normalizePath($scanPath, false, false);
     $vfs = $this->getFileSystem($scanPath);
     //defaults
     if (!$options) {
         $options = array(XApp_File_Utils::OPTION_DIR_LIST_FIELDS => XAPP_XFILE_SHOW_SIZE | XAPP_XFILE_SHOW_PERMISSIONS | XAPP_XFILE_SHOW_ISREADONLY | XAPP_XFILE_SHOW_ISDIR | XAPP_XFILE_SHOW_OWNER | XAPP_XFILE_SHOW_TIME | XAPP_XFILE_SHOW_MIME);
     }
     //hook into meta data creation for custom completion
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_META_CREATED, $this, "_onItem", '', array('parentPath' => $path, 'mount' => $basePath, 'remote' => $vfs->remote, 'options' => $options));
     //hook into 'node add' for custom node rejection
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_ADD, $this, "_addNode", '', array('mount' => $basePath, 'owner' => $this, 'options' => $options, 'remote' => $vfs->remote));
     $result = null;
     try {
         $vfs->ls(XApp_Path_Utils::normalizePath($scanPath, false), $recursive, $options);
     } catch (Exception $e) {
         return $this->toRPCError(1, $e->getMessage());
     }
     //prepare root object
     $rootObject = new stdClass();
     $fullPath = $vfs->toRealPath($basePath);
     if (!file_exists($fullPath)) {
         xapp_import('xapp.File.Utils');
         $res = XApp_File_Utils::mkDir($fullPath, 0755, true);
         if ($res == false) {
             return $this->toRPCError(1, 'Sorry, couldnt create directory');
         }
     }
     $vfs->add_ls_file_information($vfs->toRealPath($basePath), $rootObject, XAPP_XFILE_SHOW_SIZE | XAPP_XFILE_SHOW_PERMISSIONS | XAPP_XFILE_SHOW_ISREADONLY | XAPP_XFILE_SHOW_TIME | XAPP_XFILE_SHOW_MIME);
     //corrections
     $rootName = '' . $path;
     $rootPath = '' . $path;
     if ($rootName === '' || $rootName === '/') {
         $rootName = '.';
     }
     if ($rootPath === '' || $rootPath === '/') {
         $rootPath = '.';
     } else {
         $rootPath = './' . $path;
     }
     $rootPath = str_replace('//', '/', $rootPath);
     if ($this->isWindows()) {
         //whatever
         $rootPath = str_replace('././', './', $rootName);
     }
     $rootName = basename($rootName);
     $rootName = str_replace('/', '', $rootName);
     //prepare Dojo store root structure
     $result = array('status' => 200, 'total' => 1, 'items' => array());
     $result['items'][] = array('children' => $this->_currentItems, '_EX' => true, 'size' => 0, 'name' => $rootName, 'path' => $rootPath, 'mount' => $basePath, 'directory' => true);
     return $result;
 }
Пример #3
0
 public function onBeforeCall(Xapp_Rpc_Server $server, array $params)
 {
     parent::init();
     Xapp_Hook::connect(XApp_VFS_Base::EVENT_ON_NODE_META_CREATED, $this, "_onItem");
 }