Esempio n. 1
0
 /**
  * Directory listing
  * @link http://localhost/xide/code/php/xide-php/server/xide/service.php?service=XApp_Directory_Service.ls&callback=asdF&path=/ws/&recursive=true
  * @param string $path
  * @param bool $recursive
  * @param null $options
  * @return array
  */
 public function ls($mount = 'ws', $path = '/', $options = null)
 {
     $recursive = false;
     $vfs = $this->getFileSystem($mount);
     /**
      * variable normalization
      */
     $basePath = XApp_Path_Utils::normalizePath($mount, false, false);
     if ($basePath === '' || $basePath === '.') {
         $basePath = 'ws';
     }
     $path = XApp_Path_Utils::normalizePath($path, false, false);
     $scanPath = $basePath . DIRECTORY_SEPARATOR . $path;
     $scanPath = XApp_Path_Utils::normalizePath($scanPath, false, false);
     if (!$options) {
         /*
         			$options= xapp_has_option(self::DEFAULT_NODE_FIELDS) ? xapp_get_option(self::DEFAULT_NODE_FIELDS,$this) :  Array(
         				XApp_File_Utils::OPTION_DIR_LIST_FIELDS=>
         					XAPP_XFILE_SHOW_MIME|
         					XAPP_XFILE_SHOW_SIZE|
         					XAPP_XFILE_SHOW_PERMISSIONS|
         					XAPP_XFILE_SHOW_ISREADONLY|
         					XAPP_XFILE_SHOW_ISDIR);
         */
         $options = array(XApp_File_Utils::OPTION_DIR_LIST_FIELDS => XAPP_XFILE_SHOW_MIME | XAPP_XFILE_SHOW_SIZE | XAPP_XFILE_SHOW_PERMISSIONS | XAPP_XFILE_SHOW_ISREADONLY | XAPP_XFILE_SHOW_ISDIR);
     }
     $items = $vfs->ls(XApp_Path_Utils::normalizePath($scanPath, false), $recursive, $options);
     return $items;
 }
Esempio n. 2
0
 public static function getParents($workspace, $path)
 {
     $parentPath = $workspace . DIRECTORY_SEPARATOR . $path . '..';
     $result = array();
     /*echo('$parentPath : ' . $parentPath . '<br/>') ;*/
     $originalPath = XApp_Path_Utils::normalizePath($path);
     $completePath = realpath($workspace . DIRECTORY_SEPARATOR . $path);
     if (is_file($completePath)) {
         /*echo('is file : complete path ' . $path . '<br/>') ;*/
         /***
          * maqetta wants the root item for the file
          */
         $firstItem = array();
         $parts = explode('/', $path);
         $firstItem['name'] = '';
         $firstItemPath = realpath($workspace . DIRECTORY_SEPARATOR . dirname($path));
         /*echo('<br/>first item path '.$workspace . DIRECTORY_SEPARATOR . dirname($path).'<br/>');*/
         $firstItem['isDir'] = is_dir($firstItemPath);
         $firstItem['readOnly'] = is_writable($firstItemPath) ? true : false;
         $firstItem['members'] = self::getMembers($workspace, realpath($workspace . DIRECTORY_SEPARATOR));
         $firstItem['isDirty'] = false;
         $result[] = $firstItem;
         /***
          * as next we need the full list for the first item;
          */
         $firstItemList = array();
         $firstItemList['name'] = $parts[0];
         $firstItemList['members'] = self::getMembers($workspace, realpath($workspace . DIRECTORY_SEPARATOR . $parts[0]), $parts[0]);
         $result[] = $firstItemList;
     } elseif (is_dir($completePath)) {
         $parentPath = realpath($workspace . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . '..');
         $result = array();
         $item = array();
         $item['name'] = str_replace($parentPath, '', $workspace);
         $item['members'] = self::getMembers($workspace, $parentPath);
         $result[] = $item;
         return $result;
     }
     /*echo('workspace : ' . $workspace);*/
     //echo('$parentPath : ' . $parentPath . '<br/>');
     /*xapp_dump($dirList);*/
     /*
     $result =array();
     $item =array();
     $item['name'] = str_replace($parentPath,'',$workspace);
     $item['members'] = self::getMembers($workspace,$parentPath);
     $result[]=$item;
     */
     return $result;
 }
Esempio n. 3
0
 public function compress($mount, $selection, $type = 'zip', &$errors)
 {
     $to = '';
     $firstItem = XApp_Path_Utils::normalizePath($selection[0], false, false);
     require_once realpath(dirname(__FILE__)) . "/Archive/archive.php";
     $this->safeIniSet('memory_limit', '128M');
     @set_time_limit(0);
     $archive = new xFileArchive();
     $zipSelection = array();
     $root = $this->toRealPath($mount);
     foreach ($selection as $selectedFile) {
         $selectedFile = XApp_Path_Utils::normalizePath($selectedFile, false, false);
         $selectedFile = str_replace($mount, '', $selectedFile);
         $selectedFileFull = $root . DIRECTORY_SEPARATOR . $selectedFile;
         if (is_dir($selectedFileFull)) {
             $includeFileMask = XApp_File_Utils::defaultInclusionPatterns();
             $excludeFileMask = XApp_File_Utils::defaultExclusionPatterns();
             $options = array(XApp_File_Utils::OPTION_RECURSIVE => true);
             $scanlist = XApp_Directory_Utils::getFilteredDirList($selectedFileFull, $includeFileMask, $excludeFileMask, $options);
             if ($scanlist != null && count($scanlist)) {
                 $zipSelection = array_merge($zipSelection, $scanlist);
             }
         } elseif (is_file($selectedFileFull)) {
             $zipSelection[] = $selectedFileFull;
         }
     }
     if ($to == null || $to == '') {
         $firstItem = str_replace($mount, '', $firstItem);
         $to = $root . DIRECTORY_SEPARATOR . $firstItem . '.zip';
         /*TODO
         			if(file_exists($to)){
         				$base = basename($to);
         				$ext = '';
         				$dotPos = strrpos($base, ".");
         				if ($dotPos > -1) {
         					$radic = substr($base, 0, $dotPos);
         					$ext = substr($base, $dotPos);
         				}
         
         				$i = 1;
         				$newName = $base;
         				while (file_exists($dstDirectory . "/" . $newName)) {
         					$suffix = "-$i";
         					if (isSet($radic)) {
         						$newName = $radic . $suffix . $ext;
         					} else {
         						$newName = $base . $suffix;
         					}
         					$i++;
         				}
         				$destFile = $dstDirectory . "/" . $newName;
         			}
         			*/
     }
     $archive->create($to, $zipSelection, 'zip', '', $root, true);
     return $to;
 }
Esempio n. 4
0
 public function resolvePath($scopeName, $path, $rootVariable = '__ROOT__', $secure = true, $merge = true)
 {
     xapp_import('xapp.Path.Utils');
     $scope = $this->getScope($scopeName);
     $rootVariable = $rootVariable ?: '__ROOT__';
     $path = XApp_Path_Utils::securePath($path);
     if ($scope) {
         $root = $scope->resolveAbsolute($rootVariable) . DIRECTORY_SEPARATOR;
         if ($secure === true) {
             if ($merge == true) {
                 return XApp_Path_Utils::securePath(XApp_Path_Utils::merge($root, XApp_Path_Utils::normalizePath($path)));
             } else {
                 return XApp_Path_Utils::securePath($root . XApp_Path_Utils::normalizePath($path, false, false));
             }
         } else {
             return XApp_Path_Utils::merge($root, XApp_Path_Utils::normalizePath($path, false, false));
         }
     } else {
         throw new ErrorException("scope:" . $scopeName . "does not exist", 1390101);
     }
 }
Esempio n. 5
0
 /**
  * @param $mount
  * @param $selection
  * @param string $type
  * @return mixed
  */
 public function downloadTo($url, $mount, $to)
 {
     xapp_import('xapp.Path.Utils');
     xapp_import('xapp.File.Utils');
     xapp_import('xapp.Commons.ErrorHandler');
     xapp_import('xapp.Utils.Download');
     xapp_import('xapp.Utils.SystemTextEncoding');
     $success = array();
     $error = array();
     $mount = XApp_Path_Utils::getMount($mount);
     $vfs = $this->getFileSystem($mount);
     $realSrcFile = '' . $url;
     XApp_ErrorHandler::start();
     if ($this->isLocal($mount, $this->getFSResources())) {
         $srcFile = '' . XApp_Path_Utils::decodeSecureMagic($to);
         $destFile = $vfs->toRealPath($mount . DIRECTORY_SEPARATOR . $srcFile);
         if (is_dir($destFile) && (!file_exists($destFile) || !is_file($destFile))) {
             $destDirectory = '' . $destFile;
             //default file name
             $fileName = 'remoteFile.download';
             //try to get a file name from the url through parse_url(pathinfo())
             $urlParts = parse_url($url);
             if ($urlParts['path']) {
                 $pathInfo = pathinfo($urlParts['path']);
                 if ($pathInfo['basename']) {
                     $fileName = $pathInfo['basename'];
                 }
             }
             $destFile = XApp_File_Utils::unique_filename($destFile, $fileName);
             $destFile = $destDirectory . DIRECTORY_SEPARATOR . $destFile;
             touch($destFile);
         }
         try {
             $srcPath = XApp_Download::download($realSrcFile);
             if (!file_exists($srcPath)) {
                 return self::toRPCError(1, 'Error downloading ' . $srcPath . ' Error : ' . $srcPath);
             }
             $src = fopen($srcPath, "r");
             $dest = fopen($destFile, "w");
             if ($dest !== false) {
                 while (!feof($src)) {
                     stream_copy_to_stream($src, $dest, 4096);
                 }
                 fclose($dest);
             }
             fclose($src);
             @unlink($srcPath);
         } catch (Exception $e) {
             return self::toRPCError(1, $e->getMessage());
         }
     } else {
         $mountManager = $vfs->getMountManager();
         $to = XApp_Path_Utils::normalizePath($to, false, false);
         $to = $mount . '://' . $to;
         $to = $vfs->cleanSlashesRemote($to);
         try {
             $src = fopen($realSrcFile, "r");
             while (!feof($src)) {
                 $mountManager->updateStream($to, $src);
             }
             fclose($src);
         } catch (Exception $e) {
             return self::toRPCError(1, $e->getMessage());
         }
     }
     /*
     $errors = XApp_ErrorHandler::stop();
     if($errors){
     	xapp_clog($errors);
     	$this->logger->log(json_encode($errors));
     }
     */
     /*xapp_clog($errors);*/
     return true;
 }
Esempio n. 6
0
 /**
  * @param $path
  * @return string
  */
 public function toFlyPath($path)
 {
     $path = XApp_Path_Utils::normalizePath($path);
     $mount = XApp_Path_Utils::getMount($path);
     $relativePath = XApp_Path_Utils::getRelativePart($path);
     return $mount . '://' . $relativePath;
 }
Esempio n. 7
0
 public function deleteFile($path)
 {
     $vfs = $this->_getFileSystem();
     $success = array();
     $error = array();
     $vfs->deleteFile(XApp_Path_Utils::securePath(XApp_Path_Utils::normalizePath($path, true, false)), null, $error, $success);
 }