Ejemplo n.º 1
0
 private function addVideoMeta(MOXMAN_Vfs_IFile $file, $metaData)
 {
     $fileName = $file->getName();
     $ext = strtolower(MOXMAN_Util_PathUtils::getExtension($fileName));
     if (preg_match('/^(mp4|ogv|webm)$/', $ext)) {
         $metaData->url_type = MOXMAN_Util_Mime::get($fileName);
         $name = substr($fileName, 0, strlen($fileName) - strlen($ext));
         // Alternative video formats
         $altExt = array("mp4", "ogv", "webm");
         foreach ($altExt as $altExt) {
             if ($ext != $altExt) {
                 $altFile = MOXMAN::getFile($file->getParent(), $name . $altExt);
                 if ($altFile->exists()) {
                     $metaData->alt_url = $altFile->getUrl();
                     break;
                 }
             }
         }
         // Alternative image format
         $altFile = MOXMAN::getFile($file->getParent(), $name . "jpg");
         if ($altFile->exists()) {
             $metaData->alt_img = $altFile->getUrl();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns a config based on the specified file.
  *
  * @param MOXMAN_Vfs_IFile $file File to get the config for.
  * @return MOXMAN_Util_Config Config for the specified file.
  */
 public function getConfig(MOXMAN_Vfs_IFile $file)
 {
     $config = clone $this->config;
     $path = $file->isFile() ? $file->getParent() : $file->getPath();
     $root = $this->fileSystem->getRootPath();
     $mcAccessFile = $this->config->get("filesystem.local.access_file_name", "mc_access");
     $user = MOXMAN::getUser();
     $configFiles = array();
     $targetConfigPath = $path . '/' . $mcAccessFile;
     // Collect config files
     while ($path && strlen($path) >= strlen($root)) {
         if (file_exists($path . '/' . $mcAccessFile)) {
             $configFiles[] = $path . '/' . $mcAccessFile;
         }
         $path = MOXMAN_Util_PathUtils::getParent($path);
     }
     // Extend current config with the config files
     for ($i = count($configFiles) - 1; $i >= 0; $i--) {
         // Parse mc_access file
         $iniParser = new MOXMAN_Util_IniParser();
         $iniParser->load($configFiles[$i]);
         // Loop and extend it
         $items = $iniParser->getItems();
         foreach ($items as $key => $value) {
             // Group specific config
             if (is_array($value)) {
                 $targetGroups = explode(',', $key);
                 foreach ($targetGroups as $targetGroup) {
                     if ($user->isMemberOf($targetGroup)) {
                         foreach ($value as $key2 => $value2) {
                             if (strpos($key2, '_') === 0) {
                                 if ($targetConfigPath == $configFiles[$i]) {
                                     $key2 = substr($key2, 1);
                                 } else {
                                     continue;
                                 }
                             }
                             $config->put($key2, $value2);
                         }
                     }
                 }
             } else {
                 if (strpos($key, '_') === 0) {
                     if ($targetConfigPath == $configFiles[$i]) {
                         $key = substr($key, 1);
                     } else {
                         continue;
                     }
                 }
                 $config->put($key, $value);
             }
         }
     }
     return $config;
 }
Ejemplo n.º 3
0
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     $this->fileSystem->getCache()->remove($dest->getPath());
     $fromStream = $this->open("rb");
     $toStream = $dest->open("wb");
     while (($buff = $fromStream->read(8192)) !== "") {
         $toStream->write($buff);
     }
     $fromStream->close();
     $toStream->close();
 }
Ejemplo n.º 4
0
 /**
  * Get an unique file
  *
  * @param MOXMAN_Vfs_IFile $file File object to check against
  * @return MOXMAN_Vfs_IFile Unique file object.
  */
 public static function uniqueFile(MOXMAN_Vfs_IFile $file)
 {
     $fileName = $file->getName();
     $ext = MOXMAN_Util_PathUtils::getExtension($fileName);
     for ($i = 2; $file->exists(); $i++) {
         if ($file->isFile() && $ext) {
             $file = MOXMAN::getFile($file->getParent(), basename($fileName, '.' . $ext) . '_' . $i . '.' . $ext);
         } else {
             $file = MOXMAN::getFile($file->getParent(), $fileName . '_' . $i);
         }
     }
     return $file;
 }
Ejemplo n.º 5
0
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if ($this->isDirectory()) {
         $dest->mkdir();
     } else {
         $fromStream = $this->open("rb");
         $toStream = $dest->open("wb");
         while (($buff = $fromStream->read(8192)) !== "") {
             $toStream->write($buff);
         }
         $fromStream->close();
         $toStream->close();
     }
 }
Ejemplo n.º 6
0
 /** @ignore */
 private static function getPngInfo(MOXMAN_Vfs_IFile $file)
 {
     $stream = null;
     $info = array();
     try {
         $stream = $file->open(MOXMAN_Vfs_IFileStream::READ);
         $magic = $stream->read(8);
         if ($magic === "‰PNG\r\n\n") {
             // Is PNG
             // Read chunks
             do {
                 $buff = $stream->read(4);
                 if (strlen($buff) != 4) {
                     break;
                 }
                 $chunk = unpack('Nlen', $buff);
                 $chunk['type'] = $stream->read(4);
                 if (strlen($chunk['type']) != 4) {
                     break;
                 }
                 // Found header then read it
                 if ($chunk['type'] == 'IHDR') {
                     $header = unpack('Nwidth/Nheight/Cbits/Ctype/Ccompression/Cfilter/Cinterlace', $stream->read(13));
                     break;
                 }
                 // Jump to next chunk and skip CRC
                 $stream->skip($chunk['len'] + 4);
             } while ($buff !== null);
             $info = array("width" => $header["width"], "height" => $header["height"], "depth" => $header['type'] == 3 ? 8 : 32);
         }
         $stream->close();
         return $info;
     } catch (Exception $e) {
         if ($stream) {
             $stream->close();
         }
         throw $e;
     }
 }
Ejemplo n.º 7
0
 /**
  * Returns an URL for the specified file object.
  *
  * @param MOXMAN_Vfs_IFile $file File to get the absolute URL for.
  * @return String Absolute URL for the specified file.
  */
 public function getUrl(MOXMAN_Vfs_IFile $file)
 {
     $config = $file->getConfig();
     // Get config items
     $wwwroot = $config->get("filesystem.local.wwwroot");
     $prefix = $config->get("filesystem.local.urlprefix");
     $suffix = $config->get("filesystem.local.urlsuffix");
     $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);
     // Insert path into URL
     $url = substr($file->getPath(), strlen($wwwroot));
     $url = MOXMAN_Util_PathUtils::combine($prefix, $url);
     // Add suffix to URL
     if ($suffix) {
         $url .= $suffix;
     }
     return $url;
 }
Ejemplo n.º 8
0
 /**
  * Fixes filenames
  *
  * @param MOXMAN_Vfs_IFile $file File to fix name on.
  */
 public function renameFile(MOXMAN_Vfs_IFile $file)
 {
     $config = $file->getConfig();
     $autorename = $config->get("autorename.enabled", "");
     $spacechar = $config->get("autorename.space", "_");
     $custom = $config->get("autorename.pattern", "/[^0-9a-z\\-_]/i");
     $overwrite = $config->get("upload.overwrite", false);
     $lowercase = $config->get("autorename.lowercase", false);
     $prefix = $lowercase = $config->get("autorename.prefix", '');
     // @codeCoverageIgnoreStart
     if (!$autorename) {
         return $file;
     }
     // @codeCoverageIgnoreEnd
     $path = $file->getPath();
     $name = $file->getName();
     $orgname = $name;
     $ext = MOXMAN_Util_PathUtils::getExtension($path);
     $name = preg_replace("/\\." . $ext . "\$/i", "", $name);
     $name = str_replace(array('\'', '"'), '', $name);
     $name = htmlentities($name, ENT_QUOTES, 'UTF-8');
     $name = preg_replace('~&([a-z]{1,2})(acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml);~i', '$1', $name);
     $name = preg_replace($custom, $spacechar, $name);
     $name = str_replace(" ", $spacechar, $name);
     $name = trim($name);
     if ($lowercase) {
         $ext = strtolower($ext);
         $name = strtolower($name);
     }
     if ($ext) {
         $name = $name . "." . $ext;
     }
     //add prefix
     if ($prefix != '') {
         $aa = explode("-", $name);
         if (count($aa) == 1) {
             $name = $prefix . $name;
         }
     }
     // If no change to name after all this, return original file.
     if ($name === $orgname) {
         return $file;
     }
     // Return new file
     $toFile = MOXMAN::getFile($file->getParent() . "/" . $name);
     return $toFile;
 }
 /**
  * Returns the meta data file instance used to store meta information.
  *
  * @param MOXMAN_Vfs_IFile $file File instance to get the meta data file for.
  * @return MOXMAN_Vfs_IFile Meta data file.
  */
 protected function getMetaFile(MOXMAN_Vfs_IFile $file)
 {
     $metaFile = null;
     if ($file->exists()) {
         $parent = $file->getParentFile();
         // Check if file isn't a root file
         if ($parent !== null) {
             $metaFile = $parent->getFileSystem()->getFile(MOXMAN_Util_PathUtils::combine($parent->getPath(), "meta.dat"));
         }
     }
     return $metaFile;
 }
Ejemplo n.º 10
0
 /**
  * Copies this file to the specified file instance.
  *
  * @param MCE_File $dest File to copy to.
  */
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if ($this->exists() && $this->isDirectory()) {
         if (!$this->isFileOrEmptyDir()) {
             throw new MOXMAN_Exception("Copy non empty folders not supported by Azure.");
         } else {
             $dest->mkdir();
             return;
         }
     }
     if ($dest instanceof MOXMAN_Azure_File) {
         $containerUrl = MOXMAN_Util_PathUtils::combine($this->fileSystem->getContainerOption("account"), $this->fileSystem->getContainerOption("name"));
         $fromUrl = "/" . MOXMAN_Util_PathUtils::combine($containerUrl, $this->getInternalPath());
         $request = $this->getFileSystem()->createRequest(array("method" => "PUT", "path" => $dest->getInternalPath(), "headers" => array("x-ms-copy-source" => $fromUrl, "Content-Length" => 0)));
         $this->getFileSystem()->sendRequest($request);
     } else {
         $fromStream = $this->open("rb");
         $toStream = $dest->open("wb");
         while (($buff = $fromStream->read(8192)) !== "") {
             $toStream->write($buff);
         }
         $fromStream->close();
         $toStream->close();
     }
 }
Ejemplo n.º 11
0
 /**
  * Copies this file to the specified file instance.
  *
  * @param MCE_File $dest File to copy to.
  */
 public function copyTo(MOXMAN_Vfs_IFile $dest)
 {
     if ($this->exists() && $this->isDirectory()) {
         if (!$this->isFileOrEmptyDir()) {
             throw new MOXMAN_Exception("Copy non empty folders not supported by S3.");
         } else {
             $dest->mkdir();
             return;
         }
     }
     if ($dest instanceof MOXMAN_AmazonS3_File) {
         $fromPath = $this->getInternalPath();
         $toPath = $dest->getInternalPath();
         if ($this->isDirectory()) {
             $fromPath .= "/";
             $toPath .= "/";
         }
         $this->getFileSystem()->getClient()->copy($fromPath, $toPath);
         $dest->removeStatCache();
     } else {
         $fromStream = $this->open("rb");
         $toStream = $dest->open("wb");
         while (($buff = $fromStream->read(8192)) !== "") {
             $toStream->write($buff);
         }
         $fromStream->close();
         $toStream->close();
     }
 }
Ejemplo n.º 12
0
 /**
  * Removes formats from an image.
  *
  * @param MOXMAN_Vfs_IFile $file File to generate images for.
  */
 public function removeFormat(MOXMAN_Vfs_IFile $file)
 {
     if (!$file->exists()) {
         return;
     }
     $config = $file->getConfig();
     $format = $config->get("autoformat.rules", "");
     if ($config->get("autoformat.delete_format_images", true) === false) {
         return;
     }
     // @codeCoverageIgnoreStart
     if (!$format) {
         return;
     }
     // @codeCoverageIgnoreEnd
     $chunks = preg_split('/,/', $format, 0, PREG_SPLIT_NO_EMPTY);
     $imageInfo = MOXMAN_Media_MediaInfo::getInfo($file);
     $width = $imageInfo["width"];
     $height = $imageInfo["height"];
     foreach ($chunks as $chunk) {
         $parts = explode('=', $chunk);
         $fileName = preg_replace('/\\..+$/', '', $file->getName());
         $extension = preg_replace('/^.+\\./', '', $file->getName());
         $targetWidth = $newWidth = $width;
         $targetHeight = $newHeight = $height;
         $items = explode('|', $parts[0]);
         foreach ($items as $item) {
             switch ($item) {
                 case "gif":
                 case "jpg":
                 case "jpeg":
                 case "png":
                     $extension = $item;
                     break;
                 default:
                     $matches = array();
                     if (preg_match('/\\s?([0-9|\\*]+)\\s?x([0-9|\\*]+)\\s?/', $item, $matches)) {
                         $targetWidth = $matches[1];
                         $targetHeight = $matches[2];
                         if ($targetWidth == '*') {
                             // Width is omitted
                             $targetWidth = floor($width / ($height / $targetHeight));
                         }
                         if ($targetHeight == '*') {
                             // Height is omitted
                             $targetHeight = floor($height / ($width / $targetWidth));
                         }
                     }
             }
         }
         // Scale it
         if ($targetWidth != $width || $targetHeight != $height) {
             $scale = min($targetWidth / $width, $targetHeight / $height);
             $newWidth = $scale > 1 ? $width : floor($width * $scale);
             $newHeight = $scale > 1 ? $height : floor($height * $scale);
         }
         // Build output path
         $outPath = $parts[1];
         $outPath = str_replace("%f", $fileName, $outPath);
         $outPath = str_replace("%e", $extension, $outPath);
         $outPath = str_replace("%ow", "" . $width, $outPath);
         $outPath = str_replace("%oh", "" . $height, $outPath);
         $outPath = str_replace("%tw", "" . $targetWidth, $outPath);
         $outPath = str_replace("%th", "" . $targetHeight, $outPath);
         $outPath = str_replace("%w", "" . $newWidth, $outPath);
         $outPath = str_replace("%h", "" . $newHeight, $outPath);
         $outFile = MOXMAN::getFileSystemManager()->getFile($file->getParent(), $outPath);
         if ($outFile->exists()) {
             $outFile->delete();
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * Renames/Moves this file to the specified file instance.
  *
  * @param MOXMAN_Vfs_IFile $dest File to rename/move to.
  */
 public function moveTo(MOXMAN_Vfs_IFile $dest)
 {
     $entries = $this->fileSystem->getEntries($this->path);
     foreach ($entries as $entry) {
         $toPath = MOXMAN_Util_PathUtils::combine($dest->getPath(), substr($entry->path, strlen($this->getPath())));
         $this->fileSystem->addEntry($toPath, array("isFile" => $entry->isFile, "lastModified" => $entry->lastModified, "data" => $entry->data, "canRead" => $entry->canRead, "canWrite" => $entry->canWrite));
     }
     $this->fileSystem->deleteEntry($this->path);
 }
Ejemplo n.º 14
0
 /**
  * Sends the specified file to the client by streaming it.
  *
  * @param MOXMAN_Vfs_IFile $file File to stream to client.
  * @param Boolean $download State if the file should be downloaded or not by the client.
  */
 public function sendFile(MOXMAN_Vfs_IFile $file, $download = false)
 {
     // Check if the file is a local file is so use the faster method
     if ($file instanceof MOXMAN_Vfs_Local_File) {
         $this->sendLocalFile($file->getInternalPath(), $download);
         return;
     }
     // Check if the remote file system has a local temp path
     $localTempPath = MOXMAN::getFileSystemManager()->getLocalTempPath($file);
     if (file_exists($localTempPath)) {
         $this->sendLocalFile($localTempPath, $download);
         return;
     }
     if ($download) {
         $this->disableCache();
         $this->setHeader("Content-type", "application/octet-stream");
         $this->setHeader("Content-Disposition", "attachment; filename=\"" . $file->getName() . "\"");
     } else {
         $this->setHeader("Content-type", MOXMAN_Util_Mime::get($file->getName()));
     }
     // Non local file system then read and stream
     $stream = $file->open(MOXMAN_Vfs_IFileStream::READ);
     if ($stream) {
         // Read chunk by chunk and stream it
         while (($buff = $stream->read()) !== "") {
             $this->sendContent($buff);
         }
         $stream->close();
     }
 }
Ejemplo n.º 15
0
 /**
  * Removes the local temp file for a specific file instance.
  *
  * @param MOXMAN_Vfs_IFile File instance used to create a local temp file.
  */
 public function removeLocalTempFile(MOXMAN_Vfs_IFile $file)
 {
     if ($file->exists()) {
         $tempDir = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir($this->config), "moxman_blob_cache");
         $tempFile = MOXMAN_Util_PathUtils::combine($tempDir, md5($file->getPath() . $file->getLastModified()) . "." . MOXMAN_Util_PathUtils::getExtension($file->getName()));
         if (file_exists($tempFile)) {
             unlink($tempFile);
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * Returns public config options to the client.
  *
  * @param MOXMAN_Vfs_IFile $file File to get public config options for.
  * @return stdClass JSON serializable object of config options.
  */
 protected function getPublicConfig($file = null)
 {
     $exposed = array("general.hidden_tools", "general.disabled_tools", "filesystem.extensions", "filesystem.force_directory_template", "upload.maxsize", "upload.chunk_size", "upload.extensions", "createdoc.templates", "createdoc.fields", "createdir.templates");
     $result = array();
     $config = $file ? $file->getConfig() : MOXMAN::getConfig();
     foreach ($exposed as $name) {
         $result[$name] = $config->get($name);
     }
     return (object) $result;
 }
Ejemplo n.º 17
0
 /**
  * Returns true/false if the specified file can be altered or not.
  *
  * @param MOXMAN_Vfs_IFile $file File to check if can be altered.
  * @return Boolean True/false if the image can be edited or not.
  */
 public static function canEdit(MOXMAN_Vfs_IFile $file)
 {
     $ext = MOXMAN_Util_PathUtils::getExtension($file->getName());
     return preg_match('/gif|jpe?g|png|bmp/', $ext) === 1;
 }
Ejemplo n.º 18
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);
     }
 }
Ejemplo n.º 19
0
 /**
  * Returns an URL for the specified file object.
  *
  * @param MOXMAN_Vfs_IFile $file File to get the absolute URL for.
  * @return String Absolute URL for the specified file.
  */
 public function getUrl(MOXMAN_Vfs_IFile $file)
 {
     $config = $file->getConfig();
     // Get config items
     $wwwroot = $config->get("filesystem.local.wwwroot");
     $prefix = $config->get("filesystem.local.urlprefix");
     $suffix = $config->get("filesystem.local.urlsuffix");
     // Map to wwwroot array
     if (is_array($wwwroot)) {
         foreach ($wwwroot as $rootPath => $rootConfig) {
             $rootPath = MOXMAN_Util_PathUtils::toAbsolute(MOXMAN_ROOT, $rootPath);
             if (strpos($file->getPath(), $rootPath) === 0) {
                 $wwwroot = $rootPath;
                 if (isset($rootConfig["wwwroot"])) {
                     $wwwroot = $rootConfig["wwwroot"];
                 }
                 if (isset($rootConfig["urlprefix"])) {
                     $prefix = $rootConfig["urlprefix"];
                 }
                 if (isset($rootConfig["urlsuffix"])) {
                     $suffix = $rootConfig["urlsuffix"];
                 }
                 break;
             }
         }
         if (is_array($wwwroot)) {
             $wwwroot = "";
         }
     }
     $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);
     // Insert path into URL
     if (stripos($file->getPath(), $wwwroot) === 0) {
         $url = substr($file->getPath(), strlen($wwwroot));
         $url = MOXMAN_Util_PathUtils::combine($prefix, MOXMAN_Http_Uri::escapeUriString($url));
         // Add suffix to URL
         if ($suffix) {
             $url .= $suffix;
         }
         return $url;
     }
     return "";
 }
Ejemplo n.º 20
0
 /**
  * Returns true or false if the file is accepted or not.
  *
  * @param MOXMAN_Vfs_IFile $file File to grant or deny.
  * @param Boolean $isFile Default state if the filter is on an non existing file.
  * @return Boolean True/false if the file is accepted or not.
  */
 public function accept(MOXMAN_Vfs_IFile $file, $isFile = true)
 {
     if ($this->isEmpty()) {
         return true;
     }
     $name = $file->getName();
     $isFile = $file->exists() ? $file->isFile() : $isFile;
     // Handle file patterns
     if ($isFile) {
         if ($this->dirsOnly) {
             return false;
         }
         // Handle exclude files
         if ($this->excludeFiles) {
             foreach ($this->excludeFiles as $fileName) {
                 if ($name == $fileName) {
                     return false;
                 }
             }
         }
         // Handle exclude pattern
         if ($this->excludeFilePattern && preg_match($this->excludeFilePattern, $name)) {
             return false;
         }
         // Handle include pattern
         if ($this->includeFilePattern && !preg_match($this->includeFilePattern, $name)) {
             return false;
         }
         // Handle file extension pattern
         if ($this->extensions) {
             $ext = MOXMAN_Util_PathUtils::getExtension($name);
             $valid = false;
             foreach ($this->extensions as $extension) {
                 if ($extension == $ext) {
                     $valid = true;
                     break;
                 }
             }
             if (!$valid) {
                 return false;
             }
         }
     } else {
         if ($this->filesOnly) {
             return false;
         }
         // Handle exclude pattern
         if ($this->excludeDirectoryPattern && preg_match($this->excludeDirectoryPattern, $name)) {
             return false;
         }
         // Handle include pattern
         if ($this->includeDirectoryPattern && !preg_match($this->includeDirectoryPattern, $name)) {
             return false;
         }
     }
     // Handle include wildcard pattern
     if ($this->includeWildcardPatternRegExp && !preg_match($this->includeWildcardPatternRegExp, $name)) {
         return false;
     }
     // Handle exclude wildcard pattern
     if ($this->excludeWildcardPatternRegExp && preg_match($this->excludeWildcardPatternRegExp, $name)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 21
0
 /**
  * Returns true or false if the file is accepted or not.
  *
  * @param MOXMAN_Vfs_IFile $file File to grant or deny.
  * @param Boolean $isFile Default state if the filter is on an non existing file.
  * @return int Accepted or the reson why it failed.
  */
 public function accept(MOXMAN_Vfs_IFile $file, $isFile = true)
 {
     $name = $file->getName();
     $absPath = $file->getPath();
     $isFile = $file->exists() ? $file->isFile() : $isFile;
     // Handle file patterns
     if ($isFile) {
         if ($this->dirsOnly) {
             if ($this->logFunction) {
                 $this->log("File denied \"" . $absPath . "\" by \"dirsOnly\".");
             }
             return self::INVALID_TYPE;
         }
         // Handle exclude files
         if (is_array($this->excludeFiles) && $isFile) {
             foreach ($this->excludeFiles as $fileName) {
                 if ($name == $fileName) {
                     if ($this->logFunction) {
                         $this->log("File \"" . $absPath . "\" denied by \"excludeFiles\".");
                     }
                     return self::INVALID_NAME;
                 }
             }
         }
         // Handle include files
         if (is_array($this->includeFiles) && $isFile) {
             $state = false;
             foreach ($this->includeFiles as $fileName) {
                 if ($name == $fileName) {
                     $state = true;
                     break;
                 }
             }
             if (!$state) {
                 if ($this->logFunction) {
                     $this->log("File \"" . $absPath . "\" denied by \"includeFiles\".");
                 }
                 return self::INVALID_NAME;
             }
         }
         // Handle exclude pattern
         if ($this->excludeFilePattern && preg_match($this->excludeFilePattern, $name)) {
             if ($this->logFunction) {
                 $this->log("File \"" . $absPath . "\" denied by \"excludeFilePattern\".");
             }
             return self::INVALID_NAME;
         }
         // Handle include pattern
         if ($this->includeFilePattern && !preg_match($this->includeFilePattern, $name)) {
             if ($this->logFunction) {
                 $this->log("File \"" . $absPath . "\" denied by \"includeFilePattern\".");
             }
             return self::INVALID_NAME;
         }
         // Handle file extension pattern
         if (is_array($this->extensions)) {
             $ext = MOXMAN_Util_PathUtils::getExtension($absPath);
             $valid = false;
             foreach ($this->extensions as $extension) {
                 if ($extension == $ext) {
                     $valid = true;
                     break;
                 }
             }
             if (!$valid) {
                 if ($this->logFunction) {
                     $this->log("File \"" . $absPath . "\" denied by \"extensions\".");
                 }
                 return self::INVALID_EXTENSION;
             }
         }
     } else {
         if ($this->filesOnly) {
             if ($this->logFunction) {
                 $this->log("Dir denied \"" . $absPath . "\" by \"filesOnly\".");
             }
             return self::INVALID_TYPE;
         }
         // Handle exclude folders
         if (is_array($this->excludeFolders)) {
             foreach ($this->excludeFolders as $folder) {
                 if (strpos($absPath, $folder) !== false) {
                     if ($this->logFunction) {
                         $this->log('File denied "' . $absPath . '" by "excludeFolders".');
                     }
                     return self::INVALID_NAME;
                 }
             }
         }
         // Handle include folders
         if (is_array($this->includeFolders)) {
             $state = false;
             foreach ($this->includeFolders as $folder) {
                 if (strpos($absPath, $folder) !== false) {
                     $state = true;
                     break;
                 }
             }
             if (!$state) {
                 if ($this->logFunction) {
                     $this->log("File \"" . $absPath . "\" denied by \"includeFolders\".");
                 }
                 return self::INVALID_NAME;
             }
         }
         // Handle exclude pattern
         if ($this->excludeDirectoryPattern && preg_match($this->excludeDirectoryPattern, $name)) {
             if ($this->logFunction) {
                 $this->log("File \"" . $absPath . "\" denied by \"excludeDirectoryPattern\".");
             }
             return self::INVALID_NAME;
         }
         // Handle include pattern
         if ($this->includeDirectoryPattern && !preg_match($this->includeDirectoryPattern, $name)) {
             if ($this->logFunction) {
                 $this->log("File \"" . $absPath . "\" denied by \"includeDirectoryPattern\".");
             }
             return self::INVALID_NAME;
         }
     }
     // Handle include wildcard pattern
     if ($this->includeWildcardPattern && !$this->matchWildCard($this->includeWildcardPattern, $name)) {
         if ($this->logFunction) {
             $this->log("File \"" . $absPath . "\" denied by \"includeWildcardPattern\".");
         }
         return self::INVALID_NAME;
     }
     // Handle exclude wildcard pattern
     if ($this->excludeWildcardPattern && $this->matchWildCard($this->excludeWildcardPattern, $name)) {
         if ($this->logFunction) {
             $this->log("File \"" . $absPath . "\" denied by \"excludeWildcardPattern\".");
         }
         return self::INVALID_NAME;
     }
     return self::ACCEPTED;
 }
Ejemplo n.º 22
0
 /**
  * Converts a file instance to a JSON serializable object.
  *
  * @param MOXMAN_Vfs_IFile $file File to convert into JSON format.
  * @param Boolean $meta State if the meta data should be returned or not.
  * @return stdClass JSON serializable object.
  */
 public static function fileToJson($file, $meta = false)
 {
     $config = $file->getConfig();
     $renameFilter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "rename");
     $editFilter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "edit");
     $viewFilter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "view");
     $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'));
     $result = (object) array("path" => $file->getPublicPath(), "size" => $file->getSize(), "lastModified" => $file->getLastModified(), "isFile" => $file->isFile(), "canRead" => $file->canRead(), "canWrite" => $file->canWrite(), "canEdit" => $file->isFile() && $editFilter->accept($file), "canRename" => $renameFilter->accept($file), "canView" => $file->isFile() && $viewFilter->accept($file), "canPreview" => $file->isFile() && MOXMAN_Media_ImageAlter::canEdit($file), "visible" => $configuredFilter->accept($file), "exists" => $file->exists());
     if ($meta) {
         $args = new MOXMAN_Vfs_CustomInfoEventArgs(MOXMAN_Vfs_CustomInfoEventArgs::INSERT_TYPE, $file);
         MOXMAN::getPluginManager()->get("core")->fire("CustomInfo", $args);
         $metaData = (object) array_merge($file->getMetaData()->getAll(), $args->getInfo());
         if (MOXMAN_Media_ImageAlter::canEdit($file)) {
             $thumbnailFolderPath = MOXMAN_Util_PathUtils::combine($file->getParent(), $config->get('thumbnail.folder'));
             $thumbnailFile = MOXMAN::getFile($thumbnailFolderPath, $config->get('thumbnail.prefix') . $file->getName());
             // TODO: Implement stat info cache layer here
             if ($file instanceof MOXMAN_Vfs_Local_File) {
                 $info = MOXMAN_Media_MediaInfo::getInfo($file->getPath());
                 $metaData->width = $info["width"];
                 $metaData->height = $info["height"];
             }
             if ($thumbnailFile->exists()) {
                 $metaData->thumb_url = $thumbnailFile->getUrl();
                 // Get image size server side only on local filesystem
                 if ($file instanceof MOXMAN_Vfs_Local_File) {
                     $info = MOXMAN_Media_MediaInfo::getInfo($thumbnailFile->getPath());
                     $metaData->thumb_width = $info["width"];
                     $metaData->thumb_height = $info["height"];
                 }
             }
         }
         $metaData->url = $file->getUrl();
         $result->meta = $metaData;
     }
     return $result;
 }
Ejemplo n.º 23
0
 private function getIndexPath(MOXMAN_Vfs_IFile $file)
 {
     $path = $file->getPath();
     $rootName = $file->getFileSystem()->getRootName();
     $publicPath = MOXMAN_Util_PathUtils::combine($rootName !== "/" ? "/" . $rootName : $rootName, substr($path, strlen($file->getFileSystem()->getRootPath())));
     return $publicPath;
 }
Ejemplo n.º 24
0
 /**
  * Converts a file instance to a JSON serializable object.
  *
  * @param MOXMAN_Vfs_IFile $file File to convert into JSON format.
  * @param Boolean $meta State if the meta data should be returned or not.
  * @return stdClass JSON serializable object.
  */
 public static function fileToJson($file, $meta = false)
 {
     $config = $file->getConfig();
     $renameFilter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "rename");
     $editFilter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "edit");
     $viewFilter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "view");
     $result = (object) array("path" => $file->getPublicPath(), "size" => $file->getSize(), "lastModified" => $file->getLastModified(), "isFile" => $file->isFile(), "canRead" => $file->canRead(), "canWrite" => $file->canWrite(), "canEdit" => $file->isFile() && $editFilter->accept($file) === MOXMAN_Vfs_IFileFilter::ACCEPTED, "canRename" => $renameFilter->accept($file) === MOXMAN_Vfs_IFileFilter::ACCEPTED, "canView" => $file->isFile() && $viewFilter->accept($file) === MOXMAN_Vfs_IFileFilter::ACCEPTED, "canPreview" => $file->isFile() && MOXMAN_Media_ImageAlter::canEdit($file), "exists" => $file->exists());
     if ($meta) {
         $metaData = $file->getMetaData();
         //$args = $this->fireCustomInfo(MOXMAN_Core_CustomInfoEventArgs::INSERT_TYPE, $file);
         $metaData = (object) $metaData->getAll();
         if ($file instanceof MOXMAN_Vfs_Local_File && MOXMAN_Media_ImageAlter::canEdit($file)) {
             $thumbnailFolderPath = MOXMAN_Util_PathUtils::combine($file->getParent(), $config->get('thumbnail.folder'));
             $thumbnailFile = MOXMAN::getFile($thumbnailFolderPath, $config->get('thumbnail.prefix') . $file->getName());
             // TODO: Implement stat info cache layer here
             $info = MOXMAN_Media_MediaInfo::getInfo($file);
             $metaData->width = $info["width"];
             $metaData->height = $info["height"];
             if ($thumbnailFile->exists()) {
                 $metaData->thumb_url = $thumbnailFile->getUrl();
                 $info = MOXMAN_Media_MediaInfo::getInfo($thumbnailFile);
                 $metaData->thumb_width = $info["width"];
                 $metaData->thumb_height = $info["height"];
             }
         }
         $metaData->url = $file->getUrl();
         $result->meta = $metaData;
     }
     return $result;
 }
Ejemplo n.º 25
0
 /**
  * Returns a new config object based on the specified files path.
  * This will match the file path with the path.overrides in the config.
  *
  * @param MOXMAN_Vfs_IFile $file File to match agains path.overrides.
  * @return MOXMAN_Util_Config New path specific config instance.
  */
 public function getFileConfig(MOXMAN_Vfs_IFile $file)
 {
     $config = new MOXMAN_Util_Config($this->items);
     $pathOverrides = $this->get("filesystem.directories");
     if (is_array($pathOverrides) && !empty($pathOverrides)) {
         if ($file->isFile()) {
             $file = $file->getParentFile();
             // @codeCoverageIgnoreStart
             if (!$file) {
                 return $config;
             }
             // @codeCoverageIgnoreEnd
         }
         $path = $file->getPublicPath();
         foreach (array_keys($pathOverrides) as $pattern) {
             $overrides = $this->getOverrides($pattern);
             if (strpos($pattern, 'regexp:') === 0) {
                 // regexp:/pattern/
                 if (preg_match(substr($pattern, 7), $path)) {
                     $config->extend($overrides);
                 }
             } else {
                 foreach (explode(',', $pattern) as $pattern) {
                     if (strpos($pattern, '/') === false) {
                         // Directory name
                         $pattern = "/\\/" . preg_quote($pattern) . "(\\/|\$)/";
                         if (preg_match($pattern, $path)) {
                             $config->extend($overrides);
                         }
                     } else {
                         if (strrchr($pattern, '/') === '/') {
                             $pattern = substr($pattern, 0, strlen($pattern) - 1);
                         }
                         if (preg_match("/\\/\\.\$/", $pattern)) {
                             // Directory path with /. at the end
                             if ($path === substr($pattern, 0, strlen($pattern) - 2)) {
                                 $config->extend($overrides);
                             }
                         } else {
                             if ($path === $pattern || strpos($path, $pattern . '/') === 0) {
                                 // Directory path
                                 $config->extend($overrides);
                             }
                         }
                     }
                 }
             }
         }
     }
     return $config;
 }