예제 #1
0
 /**
  * Returns a file object out of the specified URL.
  *
  * @param string Absolute URL for the specified file.
  * @return MOXMAN_Vfs_IFile File that got resolved or null if it wasn't found.
  */
 public function getFile($url)
 {
     $prefix = "http://memory";
     $file = null;
     if (strpos($url, $prefix) === 0) {
         $filePath = substr($url, strlen($prefix));
         if (MOXMAN_Util_PathUtils::isChildOf($filePath, $this->fileSystem->getRootPath())) {
             return $this->fileSystem->getFile($filePath);
         }
     }
     return $file;
 }
예제 #2
0
 /**
  * Returns a MOXMAN_Vfs_IFile instance based on the specified path.
  *
  * @param string $path Path of the file to retrive.
  * @return MOXMAN_Vfs_IFile File instance for the specified path.
  */
 public function getFile($path)
 {
     // Never give access to the mc_access file
     if ($this->getConfig()->get("filesystem.local.access_file_name") === basename($path)) {
         throw new MOXMAN_Exception("Can't access the access_file_name.");
     }
     $this->verifyPath($path);
     // Force the path to an absolute path
     $path = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $path);
     // If the path is out side the root then return null
     if (!MOXMAN_Util_PathUtils::isChildOf($path, $this->rootPath)) {
         $null = null;
         return $null;
     }
     return new MOXMAN_Vfs_Local_File($this, $path);
 }
예제 #3
0
 /**
  * Returns a file object out of the specified URL.
  *
  * @param string Absolute URL for the specified file.
  * @return MOXMAN_Vfs_IFile File that got resolved or null if it wasn't found.
  */
 public function getFile($url)
 {
     $file = null;
     $prefix = $this->fileSystem->getBucketOption("urlprefix");
     $prefix = preg_replace('/^https?:\\/\\//', '//', $prefix);
     $url = preg_replace('/^https?:\\/\\//', '//', $url);
     if (strpos($url, $prefix) === 0) {
         $bucketKey = $this->fileSystem->getBucketOption("key");
         $path = urldecode(substr($url, strlen($prefix)));
         $filePath = MOXMAN_Util_PathUtils::combine("s3://" . $bucketKey, $path);
         if (MOXMAN_Util_PathUtils::isChildOf($filePath, $this->fileSystem->getRootPath())) {
             return $this->fileSystem->getFile($filePath);
         }
     }
     return $file;
 }
예제 #4
0
 /**
  * Returns a file object out of the specified URL.
  *
  * @param string Absolute URL for the specified file.
  * @return MOXMAN_Vfs_IFile File that got resolved or null if it wasn't found.
  */
 public function getFile($url)
 {
     $file = null;
     $prefix = $this->fileSystem->getContainerOption("urlprefix");
     $containerName = $this->fileSystem->getContainerOption("name");
     $containerKey = $this->fileSystem->getContainerOption("key");
     $match = MOXMAN_Util_PathUtils::combine($prefix, $containerName);
     if (strpos($url, $match) === 0) {
         $bucketpath = MOXMAN_Util_PathUtils::combine($prefix, $containerName);
         $filePath = MOXMAN_Util_PathUtils::combine("azure://" . $containerKey, substr($url, strlen($bucketpath)));
         if (MOXMAN_Util_PathUtils::isChildOf($filePath, $this->fileSystem->getRootPath())) {
             return $this->fileSystem->getFile($filePath);
         }
     }
     return $file;
 }
예제 #5
0
 /**
  * Returns a file object out of the specified URL.
  *
  * @param string Absolute URL for the specified file.
  * @return MOXMAN_Vfs_IFile File that got resolved or null if it wasn't found.
  */
 public function getFile($url)
 {
     $config = $this->fileSystem->getConfig();
     $file = null;
     // Get config items
     $wwwroot = $config->get("filesystem.local.wwwroot");
     $prefix = $config->get("filesystem.local.urlprefix");
     $paths = MOXMAN_Util_PathUtils::getSitePaths();
     // No wwwroot specified try to figure out a wwwroot
     if (!$wwwroot) {
         $wwwroot = $paths["wwwroot"];
     } else {
         // Force the www root to an absolute file system path
         $wwwroot = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $wwwroot);
     }
     // Add prefix to URL
     if ($prefix == "") {
         $prefix = MOXMAN_Util_PathUtils::combine("{proto}://{host}", $paths["prefix"]);
     }
     // Replace protocol
     if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
         $prefix = str_replace("{proto}", "https", $prefix);
     } else {
         $prefix = str_replace("{proto}", "http", $prefix);
     }
     // Replace host/port
     $prefix = str_replace("{host}", $_SERVER['HTTP_HOST'], $prefix);
     $prefix = str_replace("{port}", $_SERVER['SERVER_PORT'], $prefix);
     // Remove prefix from url
     if ($prefix && strpos($url, $prefix) === 0) {
         $url = substr($url, strlen($prefix));
     }
     // Parse url and check if path part of the URL is within the root of the file system
     $url = parse_url($url);
     if (isset($url["path"])) {
         $path = MOXMAN_Util_PathUtils::combine($wwwroot, $url["path"]);
         if (MOXMAN_Util_PathUtils::isChildOf($path, $this->fileSystem->getRootPath())) {
             // Crop away root path part and glue it back on again since the case might be different
             // For example: c:/inetpub/wwwroot and C:/InetPub/WWWRoot this will force it into the
             // valid fileSystem root path prefix
             $path = substr($path, strlen($this->fileSystem->getRootPath()));
             $path = MOXMAN_Util_PathUtils::combine($this->fileSystem->getRootPath(), $path);
             $file = $this->fileSystem->getFile($path);
         }
     }
     return $file;
 }
예제 #6
0
 /**
  * Returns a MOXMAN_Vfs_IFile instance based on the specified path.
  *
  * @param string $path Path of the file to retrive.
  * @return MOXMAN_Vfs_IFile File instance for the specified path.
  */
 public function getFile($path)
 {
     // Get file from cache
     if ($this->cache->has($path)) {
         return $this->cache->get($path);
     }
     // Never give access to the mc_access file
     if ($this->getConfig()->get("filesystem.local.access_file_name") === basename($path)) {
         throw new MOXMAN_Exception("Can't access the access_file_name.");
     }
     MOXMAN_Util_PathUtils::verifyPath($path, true);
     // Force the path to an absolute path
     $path = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $path);
     // If the path is out side the root then return null
     if (!MOXMAN_Util_PathUtils::isChildOf($path, $this->rootPath)) {
         $null = null;
         return $null;
     }
     // Create the file and put it in the cache
     $file = new MOXMAN_Vfs_Local_File($this, $path);
     $this->cache->put($path, $file);
     return $file;
 }
예제 #7
0
파일: File.php 프로젝트: GHarutyunyan/cms
 public function getUrl()
 {
     $url = "";
     $fileSystem = $this->getFileSystem();
     $wwwroot = $fileSystem->getAccountItem("wwwroot");
     $path = $this->getInternalPath();
     // Resolve ftp path to url
     if ($wwwroot) {
         if (MOXMAN_Util_PathUtils::isChildOf($path, $wwwroot)) {
             // Get config items
             $prefix = $fileSystem->getAccountItem("prefix", "{proto}://{host}");
             $suffix = $fileSystem->getAccountItem("urlsuffix");
             // Replace protocol
             if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
                 $prefix = str_replace("{proto}", "https", $prefix);
             } else {
                 $prefix = str_replace("{proto}", "http", $prefix);
             }
             // Replace host/port
             $prefix = str_replace("{host}", $fileSystem->getAccountItem("host"), $prefix);
             $prefix = str_replace("{port}", $_SERVER['SERVER_PORT'], $prefix);
             // Insert path into URL
             $url = substr($path, strlen($wwwroot));
             // Add prefix to URL
             if ($prefix) {
                 $url = MOXMAN_Util_PathUtils::combine($prefix, $url);
             }
             // Add suffix to URL
             if ($suffix) {
                 $url .= $suffix;
             }
         } else {
             throw new MOXMAN_Exception("Ftp path is not within wwwroot path.");
         }
     }
     return $url;
 }
 /**
  * Returns the parent files absolute path or an empty string if there is no parent.
  *
  * @return String parent files absolute path.
  */
 public function getParent()
 {
     $path = MOXMAN_Util_PathUtils::getParent($this->getPath());
     // If path is out side the file systems root path
     if (!MOXMAN_Util_PathUtils::isChildOf($path, $this->fileSystem->getRootPath())) {
         return "";
     }
     return $path;
 }
예제 #9
0
 /**
  * Copies this file to the specified file instance.
  *
  * @param MOXMAN_Vfs_IFile $dest File to copy to.
  */
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if (!$this->exists()) {
         throw new Exception("Source file doesn't exist: " . $dest->getPublicPath());
     }
     if (MOXMAN_Util_PathUtils::isChildOf($dest->getPath(), $this->getPath())) {
         throw new Exception("You can't copy the file into it self.");
     }
     // File copy or dir copy
     if ($this->isFile()) {
         if ($dest instanceof MOXMAN_Vfs_Local_File) {
             copy($this->internalPath, $this->fromUtf($dest->getPath()));
         } else {
             // Copy between file systems
             $in = $this->open(MOXMAN_Vfs_IFileStream::READ);
             $out = $dest->open(MOXMAN_Vfs_IFileStream::WRITE);
             // Stream in file to out file
             while (($data = $in->read()) !== "") {
                 $out->write($data);
             }
             $in->close();
             $out->close();
         }
     } else {
         // Copy dir to dir
         $this->copyDir($this, $dest);
     }
 }
예제 #10
0
 /**
  * Executes the command logic with the specified RPC parameters.
  *
  * @param Object $params Command parameters sent from client.
  * @return Object Result object to be passed back to client.
  */
 public function execute($params)
 {
     $url = isset($params->url) ? $params->url : "";
     $path = isset($params->path) ? $params->path : "{default}";
     $rootPath = isset($params->rootpath) ? $params->rootpath : "";
     $lastPath = isset($params->lastPath) ? $params->lastPath : "";
     $offset = isset($params->offset) ? $params->offset : 0;
     $length = isset($params->length) ? $params->length : null;
     $orderBy = isset($params->orderBy) ? $params->orderBy : "name";
     $desc = isset($params->desc) ? $params->desc : false;
     // Result URL to closest file
     $file = null;
     if ($url) {
         try {
             $file = MOXMAN::getFile($url);
             if ($file && !MOXMAN_Util_PathUtils::isChildOf($file->getPublicPath(), $rootPath)) {
                 $file = null;
             }
         } catch (MOXMAN_Exception $e) {
             // Might throw exception ignore it
             $file = null;
         }
         if ($file) {
             if ($file->exists()) {
                 $urlFile = $file;
             }
             while (!$file->exists() || !$file->isDirectory()) {
                 $file = $file->getParentFile();
             }
         }
     }
     if ($rootPath) {
         if (!MOXMAN_Util_PathUtils::isChildOf($path, $rootPath)) {
             $path = $rootPath;
         }
         if (!MOXMAN_Util_PathUtils::isChildOf($lastPath, $rootPath)) {
             $lastPath = null;
         }
     }
     // Resolve lastPath input
     if ($lastPath && !$file) {
         try {
             $file = MOXMAN::getFile($lastPath);
         } catch (MOXMAN_Exception $e) {
             // Might throw exception ignore it
             $file = null;
         }
         if ($file) {
             while (!$file->exists() || !$file->isDirectory()) {
                 $file = $file->getParentFile();
             }
         }
     }
     $file = $file ? $file : MOXMAN::getFile($path);
     // Force update on cached file info
     if (isset($params->force) && $params->force) {
         MOXMAN_Vfs_Cache_FileInfoStorage::getInstance()->updateFileList($file);
     }
     if (!$file->isDirectory()) {
         throw new MOXMAN_Exception("Path isn't a directory: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_TYPE);
     }
     $config = $file->getConfig();
     // Setup input file filter
     $paramsFileFilter = new MOXMAN_Vfs_BasicFileFilter();
     if (isset($params->include_directory_pattern) && $params->include_directory_pattern) {
         $paramsFileFilter->setIncludeDirectoryPattern($params->include_directory_pattern);
     }
     if (isset($params->exclude_directory_pattern) && $params->exclude_directory_pattern) {
         $paramsFileFilter->setExcludeDirectoryPattern($params->exclude_directory_pattern);
     }
     if (isset($params->include_file_pattern) && $params->include_file_pattern) {
         $paramsFileFilter->setIncludeFilePattern($params->include_file_pattern);
     }
     if (isset($params->exclude_file_pattern) && $params->exclude_file_pattern) {
         $paramsFileFilter->setExcludeFilePattern($params->exclude_file_pattern);
     }
     if (isset($params->extensions) && $params->extensions) {
         $paramsFileFilter->setIncludeExtensions($params->extensions);
     }
     if (isset($params->filter) && $params->filter != null) {
         $paramsFileFilter->setIncludeWildcardPattern($params->filter);
     }
     if (isset($params->only_dirs) && $params->only_dirs === true) {
         $paramsFileFilter->setOnlyDirs(true);
     }
     if (isset($params->only_files) && $params->only_files === true) {
         $paramsFileFilter->setOnlyFiles(true);
     }
     // Setup file filter
     $configuredFilter = new MOXMAN_Vfs_BasicFileFilter();
     $configuredFilter->setIncludeDirectoryPattern($config->get('filesystem.include_directory_pattern'));
     $configuredFilter->setExcludeDirectoryPattern($config->get('filesystem.exclude_directory_pattern'));
     $configuredFilter->setIncludeFilePattern($config->get('filesystem.include_file_pattern'));
     $configuredFilter->setExcludeFilePattern($config->get('filesystem.exclude_file_pattern'));
     $configuredFilter->setIncludeExtensions($config->get('filesystem.extensions'));
     // Setup combined filter
     $combinedFilter = new MOXMAN_Vfs_CombinedFileFilter();
     $combinedFilter->addFilter($paramsFileFilter);
     $combinedFilter->addFilter($configuredFilter);
     $files = $file->listFilesFiltered($combinedFilter)->limit($offset, $length)->orderBy($orderBy, $desc);
     $args = $this->fireFilesAction(MOXMAN_Vfs_FileActionEventArgs::LIST_FILES, $file, $files);
     $files = $args->getFileList();
     $renameFilter = MOXMAN_Vfs_BasicFileFilter::createFromConfig($file->getConfig(), "rename");
     $editFilter = MOXMAN_Vfs_BasicFileFilter::createFromConfig($file->getConfig(), "edit");
     $viewFilter = MOXMAN_Vfs_BasicFileFilter::createFromConfig($file->getConfig(), "view");
     // List thumbnails and make lookup table
     $thumbnails = array();
     $thumbnailFolder = $config->get("thumbnail.folder");
     $thumbnailPrefix = $config->get("thumbnail.prefix");
     if ($config->get('thumbnail.enabled')) {
         $thumbFolderFile = MOXMAN::getFile($file->getPath(), $thumbnailFolder);
         // Force update on cached file info
         if (isset($params->force) && $params->force) {
             MOXMAN_Vfs_Cache_FileInfoStorage::getInstance()->updateFileList($thumbFolderFile);
         }
         if ($file instanceof MOXMAN_Vfs_Local_File === false) {
             $hasThumbnails = false;
             foreach ($files as $subFile) {
                 if (MOXMAN_Media_ImageAlter::canEdit($subFile)) {
                     $hasThumbnails = true;
                     break;
                 }
             }
             if ($hasThumbnails) {
                 $thumbFiles = $thumbFolderFile->listFilesFiltered($combinedFilter)->limit($offset, $length)->orderBy($orderBy, $desc);
                 foreach ($thumbFiles as $thumbFile) {
                     $thumbnails[$thumbFile->getName()] = true;
                 }
             }
         } else {
             // Stat individual files on local fs faster than listing 1000 files
             $fileSystem = $thumbFolderFile->getFileSystem();
             foreach ($files as $subFile) {
                 if (MOXMAN_Media_ImageAlter::canEdit($subFile)) {
                     $thumbFile = $fileSystem->getFile(MOXMAN_Util_PathUtils::combine($thumbFolderFile->getPath(), $thumbnailPrefix . $subFile->getName()));
                     if ($thumbFile->exists()) {
                         $thumbnails[$thumbFile->getName()] = true;
                     }
                 }
             }
         }
     }
     $result = (object) array("columns" => array("name", "size", "modified", "attrs", "info"), "config" => $this->getPublicConfig($file), "file" => $this->fileToJson($file, true), "urlFile" => isset($urlFile) ? $this->fileToJson($urlFile, true) : null, "data" => array(), "url" => $file->getUrl(), "thumbnailFolder" => $thumbnailFolder, "thumbnailPrefix" => $thumbnailPrefix, "offset" => $files->getOffset(), "last" => $files->isLast());
     foreach ($files as $subFile) {
         $attrs = $subFile->isDirectory() ? "d" : "-";
         $attrs .= $subFile->canRead() ? "r" : "-";
         $attrs .= $subFile->canWrite() ? "w" : "-";
         $attrs .= $renameFilter->accept($subFile) ? "r" : "-";
         $attrs .= $subFile->isFile() && $editFilter->accept($subFile) ? "e" : "-";
         $attrs .= $subFile->isFile() && $viewFilter->accept($subFile) ? "v" : "-";
         $attrs .= $subFile->isFile() && MOXMAN_Media_ImageAlter::canEdit($subFile) ? "p" : "-";
         $attrs .= isset($thumbnails[$thumbnailPrefix . $subFile->getName()]) ? "t" : "-";
         $args = $this->fireCustomInfo(MOXMAN_Vfs_CustomInfoEventArgs::LIST_TYPE, $subFile);
         $custom = (object) $args->getInfo();
         if ($subFile->getPublicLinkPath()) {
             $custom->link = $subFile->getPublicLinkPath();
         }
         $result->data[] = array($subFile->getName(), $subFile->isDirectory() ? 0 : $subFile->getSize(), $subFile->getLastModified(), $attrs, $custom);
     }
     return $result;
 }