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();
         }
     }
 }
 /**
  * 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;
 }
示例#3
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;
 }
示例#4
0
 public function moveThumbnail(MOXMAN_Vfs_IFile $fromFile, MOXMAN_Vfs_IFile $toFile)
 {
     if ($fromFile->isDirectory() || !MOXMAN_Media_ImageAlter::canEdit($fromFile)) {
         return false;
     }
     $config = $fromFile->getConfig();
     // From thumbnail
     $fromThumbnailFolderPath = MOXMAN_Util_PathUtils::combine($fromFile->getParent(), $config->get('thumbnail.folder'));
     $fromThumbnailFile = MOXMAN::getFile($fromThumbnailFolderPath, $config->get('thumbnail.prefix') . $fromFile->getName());
     // To thumbnail
     $toThumbnailFolderPath = MOXMAN_Util_PathUtils::combine($toFile->getParent(), $config->get('thumbnail.folder'));
     $toThumbnailFile = MOXMAN::getFile($toThumbnailFolderPath, $config->get('thumbnail.prefix') . $toFile->getName());
     $thumbnailFolderFile = $toThumbnailFile->getParentFile();
     if (!$thumbnailFolderFile->exists()) {
         $thumbnailFolderFile->mkdir();
         $this->fireThumbnailFileAction(MOXMAN_Vfs_FileActionEventArgs::ADD, $thumbnailFolderFile);
     }
     if ($fromThumbnailFile->exists()) {
         $fromThumbnailFile->moveTo($toThumbnailFile);
         $this->fireThumbnailTargetFileAction(MOXMAN_Vfs_FileActionEventArgs::MOVE, $fromThumbnailFile, $toThumbnailFile);
         return true;
     }
     return false;
 }
示例#5
0
 public function getThumbnail(MOXMAN_Vfs_IFile $file)
 {
     $config = $file->getConfig();
     if ($config->get('thumbnail.enabled') !== true) {
         return $file;
     }
     $thumbnailFolderPath = MOXMAN_Util_PathUtils::combine($file->getParent(), $config->get('thumbnail.folder'));
     $thumbnailFile = MOXMAN::getFile($thumbnailFolderPath, $config->get('thumbnail.prefix') . $file->getName());
     return $thumbnailFile;
 }