/**
  * @param string $internalUrl
  * @return mixed The URL to access the target file from outside, if available, or FALSE.
  */
 public static function toExternalUrl($internalUrl)
 {
     $currentProc = ProcManager::getInstance()->getCurrentProcess();
     if ($currentProc) {
         $checknum = $currentProc->getChecknum();
     } else {
         $checknum = -1;
     }
     $urlParts = AdvancedPathLib::parse_url($internalUrl);
     if ($urlParts === false) {
         return $internalUrl;
     }
     if ($urlParts['scheme'] === EyeosAbstractVirtualFile::URL_SCHEME_SYSTEM) {
         // EXTERN
         try {
             $externPath = AdvancedPathLib::resolvePath($urlParts['path'], '/extern', AdvancedPathLib::OS_UNIX | AdvancedPathLib::RESOLVEPATH_RETURN_REFDIR_RELATIVE);
             return 'index.php?extern=' . $externPath;
         } catch (Exception $e) {
         }
         // APPS
         try {
             $appPath = AdvancedPathLib::resolvePath($urlParts['path'], '/apps', AdvancedPathLib::OS_UNIX | AdvancedPathLib::RESOLVEPATH_RETURN_REFDIR_RELATIVE);
             $appName = utf8_substr($appPath, 1, utf8_strpos($appPath, '/', 1));
             $appFile = utf8_substr($appPath, utf8_strlen($appName) + 1);
             return 'index.php?checknum=' . $checknum . '&appName=' . $appName . '&appFile=' . $appFile;
         } catch (Exception $e) {
         }
         return $internalUrl;
     }
     //TODO
     return $internalUrl;
 }
 /**
  * @param string $path
  * @return bool
  */
 public function checkPath($path)
 {
     $urlParts = AdvancedPathLib::parse_url($path);
     if (in_array(strtolower($urlParts['scheme']), self::$handledSchemes)) {
         return true;
     }
     return false;
 }
 /**
  * @param string $path
  * @return bool
  */
 public function checkPath($path)
 {
     $urlParts = AdvancedPathLib::parse_url($path);
     if (strtolower($urlParts['scheme']) == 'file') {
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * @param string $path The path to the file (MUST BE A VALID URL)
  * @param mixed $params Additional arguments (could be useful for derivated classes)
  * @throws EyeInvalidArgumentException
  * @throws EyeMissingArgumentException
  * @throws EyeNullPointerException
  */
 public function __construct($path, $params = null)
 {
     try {
         $urlParts = AdvancedPathLib::parse_url($path);
         if ($urlParts['scheme'] != self::URL_SCHEME_SYSTEM) {
             throw new EyeInvalidArgumentException($urlParts['scheme'] . ' is not a valid scheme for system file, expecting ' . self::URL_SCHEME_SYSTEM . '.');
         }
     } catch (EyeException $e) {
         throw new EyeInvalidArgumentException($path . ' is not a valid path value.', 0, $e);
     }
     try {
         parent::__construct($path, $params);
     } catch (EyeException $e) {
         throw new EyeException('Unable to create ' . __CLASS__, 0, $e);
     }
 }
 /**
  * Returns an IVirtualFile object corresponding to the given virtual $path.
  * 
  * @param string $path The path/URL of the file.
  * @param array $params Optionnal addionnal parameters passed to the file class constructor.
  * @return IVirtualFile The file object if the FOF was able to create it or null otherwise.
  * @throws EyeException If an error occured during the creation of the file object.
  */
 public function getFile($path, $params = null)
 {
     $urlParts = AdvancedPathLib::parse_url($path, AdvancedPathLib::OS_UNIX);
     try {
         $xmlConf = FSI::getConfiguration($urlParts['scheme'] . '.scheme');
     } catch (EyeFileNotFoundException $e) {
         throw new EyeMissingConfigurationException('Missing handler configuration file for scheme ' . $urlParts['scheme'] . '://.', 0, $e);
     }
     $handlerClassName = (string) $xmlConf->handlerClassName[0];
     if (!class_exists($handlerClassName)) {
         throw new EyeClassNotFoundException('Unable to find ' . $handlerClassName);
     }
     //autocomplete path if possible (home://myFolder => home://~currentuser/myFolder)
     $path = call_user_func_array(array($handlerClassName, 'autocompletePath'), array($path));
     //check for mounted file first
     $realFile = null;
     if ($xmlConf->mountpointsManager->getName() != '') {
         $realFile = MountedFileLocator::getRealFile($path, null, $params);
         if ($realFile !== null) {
             $params['realFile'] = $realFile;
         }
     }
     //if no mounted path has been found, get the real file object from its locator
     if ($realFile === null) {
         $locatorClassFilename = (string) $xmlConf->locatorClassName[0];
         if ($locatorClassFilename == '') {
             throw new EyeMissingConfigurationException('No VirtualFileLocator class has been specified in the configuration file.');
         }
         if (!is_file(SERVICE_FILESYSTEM_VIRTUALFILEFACTORY_LOCATORS_PATH . '/' . $locatorClassFilename . '.php')) {
             throw new EyeFileNotFoundException('Unable to find specified VirtualFileLocator class file: ' . $locatorClassFilename . '.php.');
         }
         require_once SERVICE_FILESYSTEM_VIRTUALFILEFACTORY_LOCATORS_PATH . '/' . $locatorClassFilename . '.php';
         if (!class_exists($locatorClassFilename)) {
             throw new EyeClassNotFoundException('Unable to find class ' . $locatorClassFilename);
         }
         $params['realFile'] = call_user_func_array(array($locatorClassFilename, 'getRealFile'), array($path, $xmlConf->parameters, $params));
     }
     return new $handlerClassName(AdvancedPathLib::buildUrl($urlParts), $params);
 }
Example #6
0
 /**
  * @param string $path The path to the file
  * @param mixed $params Additional arguments (could be useful for derivated classes)
  */
 public function __construct($path, $params = null)
 {
     $urlParts = AdvancedPathLib::parse_url($path);
     //DSN
     if (!isset($params['PDOFile::dsn'])) {
         throw new EyeInvalidArgumentException('Missing DSN (key "dsn") in $params for database connection.');
     }
     $this->connectionData['dsn'] = $params['dsn'];
     //TABLE NAME
     if (!isset($params['PDOFile::tableName'])) {
         throw new EyeInvalidArgumentException('Missing table name (key "tableName") in $params for database connection.');
     }
     $this->connectionData['tableName'] = $params['tableName'];
     //USER
     if (isset($params['PDOFile::user'])) {
         $this->connectionData['user'] = $params['PDOFile::user'];
     }
     //PASSWORD
     if (isset($params['PDOFile::password'])) {
         $this->connectionData['password'] = $params['PDOFile::password'];
     }
     $this->path = $path;
 }
Example #7
0
 /**
  * Parses a URL and return its components "eyeos style", but keeping a certain compatibility
  * with classical URL analyzer.
  * 
  * Example: home://~john/myDir/myDocument.ext
  * Result:
  * - scheme: "home"
  * - host: "~john"
  * - principalname: "john"
  * - path: "/myDir/myDocument.ext"
  * 
  * @see AdvancedPathLib::parse_url()
  * @return array
  */
 public static function parse_url($path, $flags = AdvancedPathLib::NONE)
 {
     $urlParts = AdvancedPathLib::parse_url($path, $flags);
     if (isset($urlParts['host']) && strpos($urlParts['host'], self::URL_LOCATOR_CHAR) === 0) {
         $urlParts['principalname'] = utf8_substr($urlParts['host'], 1);
     } else {
         if (preg_match('`^/(' . self::URL_LOCATOR_CHAR . '(' . EyeosSQLPrincipalsManager::PRINCIPALNAME_VALIDATION_REGEXP . ').*)`', $urlParts['path'], $matches)) {
             $urlParts['host'] = $matches[1];
             $urlParts['principalname'] = $matches[2];
             //						  This code has NO SENSE
             //                        if(isset($matches[3])) {
             //                            $urlParts['path'] = $matches[3];
             //                        } else {
             //                            $urlParts['path'] = '/';
             //                        }
         }
     }
     // Currently those parts are not supported, so we remove them to avoid any confusion
     unset($urlParts['user']);
     unset($urlParts['pass']);
     return $urlParts;
 }
 /**
  * 
  * @param string $referenceUrl
  * @param string $requestedUrl
  * @param bool $requestedUrlIsDir
  * @return bool
  */
 protected static function impliesUrl($referenceUrl, $requestedUrl)
 {
     $refUrlParts = AdvancedPathLib::parse_url($referenceUrl);
     $requestedUrlParts = AdvancedPathLib::parse_url($requestedUrl);
     // schemes must match
     if ($refUrlParts['scheme'] != $requestedUrlParts['scheme']) {
         return false;
     }
     // hosts must match (except if reference host is "*")
     // TODO: add ability to provide a partial host (e.g. "*.eyeos.org")
     if (isset($refUrlParts['host'])) {
         if ($refUrlParts['host'] != self::WILD_CHAR) {
             if (!isset($requestedUrlParts['host']) || $refUrlParts['host'] != $requestedUrlParts['host']) {
                 return false;
             }
         }
     }
     // initialize reference URL
     $referenceIsDirectory = false;
     $referenceIsRecursive = false;
     $refCanonicalPath = AdvancedPathLib::getCanonicalPath($refUrlParts['path']);
     //var_dump('$refCanonicalPath: ' . $refCanonicalPath);
     // analyze reference URL (directory? recursive?)
     $length = utf8_strlen($refCanonicalPath);
     $lastChar = $length > 0 ? utf8_substr($refCanonicalPath, -1) : 0;
     $lastCharButOneIdx = $length > 0 ? utf8_substr($refCanonicalPath, -2, 1) : 0;
     if ($lastChar == self::RECURSIVE_CHAR && $lastCharButOneIdx == '/') {
         $referenceIsDirectory = true;
         $referenceIsRecursive = true;
         $refCanonicalPath = utf8_substr($refCanonicalPath, 0, -1);
     } elseif ($lastChar == self::WILD_CHAR && $lastCharButOneIdx == '/') {
         $referenceIsDirectory = true;
         $referenceIsRecursive = utf8_substr($refCanonicalPath, 0, -1);
     }
     // initialize requested URL
     $canonicalPath = AdvancedPathLib::getCanonicalPath($requestedUrlParts['path']);
     //var_dump($canonicalPath . ' ### ' . $refCanonicalPath);
     //var_dump('refIsDir: ' . ($referenceIsDirectory ? 'true' : 'false'));
     //var_dump('refIsRecursive: ' . ($referenceIsRecursive ? 'true' : 'false'));
     // check implication
     $implies = false;
     if ($referenceIsDirectory) {
         if ($referenceIsRecursive) {
             $implies = utf8_strlen($canonicalPath) > utf8_strlen($refCanonicalPath) && ($canonicalPath == $refCanonicalPath || utf8_strpos($canonicalPath, $refCanonicalPath) === 0);
         } else {
             $lastSeparatorIdx = utf8_strrpos($canonicalPath, '/');
             if ($lastSeparatorIdx === false) {
                 $implies = false;
             } else {
                 $implies = utf8_strlen($refCanonicalPath) == $lastSeparatorIdx + 1 && utf8_substr($refCanonicalPath, 0, $lastSeparatorIdx + 1) == utf8_substr($canonicalPath, 0, $lastSeparatorIdx + 1);
             }
         }
     } else {
         $implies = $refCanonicalPath == $canonicalPath;
     }
     //var_dump('$implies= ' . ($implies? 'true' : 'false'));
     return $implies;
 }
 public function testParse_url()
 {
     AdvancedPathLib::parse_url_registerFragment2PathProtocol(array('file', 'ftp', 'ftps'));
     $url = '/unix/like/path';
     $this->assertEquals(array('scheme' => 'file', 'path' => '/unix/like/path'), AdvancedPathLib::parse_url($url, AdvancedPathLib::OS_UNIX));
     $url = 'C:/windows/like/path';
     $this->assertEquals(array('scheme' => 'file', 'path' => 'C:/windows/like/path'), AdvancedPathLib::parse_url($url, AdvancedPathLib::OS_WINDOWS));
     $url = 'D:\\another\\windows\\like\\path';
     $this->assertEquals(array('scheme' => 'file', 'path' => 'D:/another/windows/like/path'), AdvancedPathLib::parse_url($url, AdvancedPathLib::OS_WINDOWS));
     $url = 'D:\\another\\windows\\like\\path\\myFile #2.ext';
     $this->assertEquals(array('scheme' => 'file', 'path' => 'D:/another/windows/like/path/myFile #2.ext'), AdvancedPathLib::parse_url($url, AdvancedPathLib::OS_WINDOWS));
     $url = 'ftp://eyeos.org/path/to/myFile.ext';
     $this->assertEquals(array('scheme' => 'ftp', 'host' => 'eyeos.org', 'path' => '/path/to/myFile.ext'), AdvancedPathLib::parse_url($url));
     $url = 'ftp://eyeos.org/path/to/myFile #1.ext';
     $this->assertEquals(array('scheme' => 'ftp', 'host' => 'eyeos.org', 'path' => '/path/to/myFile #1.ext'), AdvancedPathLib::parse_url($url));
     $url = 'home://eyeos.org/unknown/scheme/url';
     $this->assertEquals(array('scheme' => 'home', 'host' => 'eyeos.org', 'path' => '/unknown/scheme/url'), AdvancedPathLib::parse_url($url));
     $url = 'p34f://eyeos.org:34/another/unknown/../scheme/url/../';
     $this->assertEquals(array('scheme' => 'p34f', 'host' => 'eyeos.org', 'port' => 34, 'path' => '/another/scheme'), AdvancedPathLib::parse_url($url));
     $url = '/unix/like/path?with=query';
     $this->assertEquals(array('scheme' => 'file', 'path' => '/unix/like/path', 'query' => 'with=query'), AdvancedPathLib::parse_url($url, AdvancedPathLib::OS_UNIX));
     $url = 'http://eyeos.org/http/like/path?with=query#and-fragment';
     $this->assertEquals(array('scheme' => 'http', 'host' => 'eyeos.org', 'path' => '/http/like/path', 'query' => 'with=query', 'fragment' => 'and-fragment'), AdvancedPathLib::parse_url($url));
     $url = 'file://C:\\path';
     $this->assertEquals(array('scheme' => 'file', 'path' => 'C:/path'), AdvancedPathLib::parse_url($url, AdvancedPathLib::OS_WINDOWS));
 }
Example #10
0
 /**
  * @return bool TRUE if the file has been successfully renamed.
  * @throws EyeIOException
  */
 public function renameTo($newName)
 {
     if (!$this->exists()) {
         throw new EyeFileNotFoundException($this->path . ' does not exist.');
     }
     if (!$newName) {
         return true;
     }
     $urlParts = AdvancedPathLib::parse_url($this->path);
     $urlParts['path'] = AdvancedPathLib::unifyPath(dirname($urlParts['path']) . '/' . $newName);
     $newPath = AdvancedPathLib::buildURL($urlParts);
     if ($this->exists()) {
         $path = AdvancedPathLib::getPhpLocalHackPath($this->path);
         $newPath = AdvancedPathLib::getPhpLocalHackPath($newPath);
         try {
             if (rename($path, $newPath)) {
                 $this->path = $newPath;
                 return true;
             }
             throw new EyeIOException('Unable to rename file ' . $this->path . '.');
         } catch (EyeErrorException $e) {
             throw new EyeIOException('Unable to rename file ' . $this->path . '.', 0, $e);
         }
     } else {
         $this->path = $newPath;
         return true;
     }
 }
 protected static function getMountpointManagerInstance($path)
 {
     $moutpointScheme = AdvancedPathLib::parse_url($path);
     $moutpointScheme = $moutpointScheme['scheme'];
     if (!isset(self::$LoadedManagers[$moutpointScheme])) {
         if (!in_array($moutpointScheme, EyeosAbstractVirtualFile::$VirtualFileSchemes)) {
             throw new EyeInvalidArgumentException($path . ' does not represent an EyeosAbstractVirtualFile.');
         }
         $configFile = $moutpointScheme . '.scheme' . SERVICE_FILESYSTEM_CONFIGURATION_FILE_EXTENSION;
         $conf = FSI::getConfiguration($configFile);
         $managerClassName = (string) $conf->mountpointsManager['class'];
         if (!$managerClassName) {
             throw new EyeMissingConfigurationException('No manager class found in configuration file ' . $configFile);
         }
         if (!is_file(SERVICE_FILESYSTEM_MOUNTPOINTSMANAGERS_MANAGERS_PATH . '/' . $managerClassName . '.php')) {
             throw new EyeFileNotFoundException(SERVICE_FILESYSTEM_MOUNTPOINTSMANAGERS_MANAGERS_PATH . '/' . $managerClassName . '.php');
         }
         require SERVICE_FILESYSTEM_MOUNTPOINTSMANAGERS_MANAGERS_PATH . '/' . $managerClassName . '.php';
         $instance = call_user_func(array($managerClassName, 'getInstance'));
         if (!$instance instanceof IMountpointsManager) {
             throw new EyeUnexpectedValueException($managerClassName . ' does not implement IMountpointsManager.');
         }
         self::$LoadedManagers[$moutpointScheme] = $instance;
     }
     return self::$LoadedManagers[$moutpointScheme];
 }