示例#1
0
 /**
  * Deletes any existing thumbnail for the specified file.
  *
  * @param MOXMAN_Vfs_IFile $file File to remove thumbnail for.
  */
 public function deleteThumbnail(MOXMAN_Vfs_IFile $file)
 {
     if ($file->isDirectory() || !MOXMAN_Media_ImageAlter::canEdit($file)) {
         return false;
     }
     $config = $file->getConfig();
     if (!$config->get('thumbnail.delete')) {
         return false;
     }
     // Delete thumbnail file
     $thumbnailFolderPath = MOXMAN_Util_PathUtils::combine($file->getParent(), $config->get('thumbnail.folder'));
     $thumbnailFile = MOXMAN::getFile($thumbnailFolderPath, $config->get('thumbnail.prefix') . $file->getName());
     if ($thumbnailFile->exists()) {
         $thumbnailFile->delete();
         $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::DELETE, $thumbnailFile);
         return true;
     }
     return false;
 }
示例#2
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;
 }
 public function putFile(MOXMAN_Vfs_IFile $file)
 {
     $pdo = $this->getPdo();
     if (!$pdo) {
         return null;
     }
     $parentFile = $file->getParentFile();
     if (!$parentFile) {
         $info = array("name" => $file->getFileSystem()->getRootName(), "isDirectory" => true, "canRead" => $file->canRead(), "canWrite" => $file->canWrite(), "size" => 0, "lastModified" => 0);
         return $info;
     }
     $parentPath = $this->getIndexPath($parentFile);
     $attrs = $file->isDirectory() ? "d" : "-";
     $attrs .= $file->canRead() ? "r" : "-";
     $attrs .= $file->canWrite() ? "w" : "-";
     $attrs .= "-";
     $size = $file->getSize();
     $lastModified = $file->getLastModified();
     $numItems = $pdo->i("SELECT COUNT(mc_id) FROM moxman_cache WHERE mc_path = :mc_path AND mc_name = :mc_name", array("mc_path" => $parentPath, "mc_name" => $file->getName()));
     if ($numItems > 0) {
         $pdo->q("UPDATE moxman_cache SET mc_attrs = :mc_attrs, mc_size = :mc_size, " . "mc_last_modified = :mc_last_modified, mc_cached_time = :mc_cached_time WHERE mc_path = :mc_path AND mc_name = :mc_name", array("mc_attrs" => $attrs, "mc_size" => $file->isFile() ? $size : null, "mc_last_modified" => date('Y-m-d H:i:s', $lastModified), "mc_cached_time" => date('Y-m-d H:i:s', time()), "mc_path" => $parentPath, "mc_name" => $file->getName()));
         $this->log("[cache] putFile update");
     } else {
         $pdo->q("INSERT INTO moxman_cache(mc_path, mc_name, mc_extension, mc_attrs, mc_size, mc_last_modified, mc_cached_time) " . "VALUES(:mc_path, :mc_name, :mc_extension, :mc_attrs, :mc_size, :mc_last_modified, :mc_cached_time)", array("mc_path" => $parentPath, "mc_name" => $file->getName(), "mc_extension" => pathinfo($file->getName(), PATHINFO_EXTENSION), "mc_attrs" => $attrs, "mc_size" => $file->isFile() ? $size : null, "mc_last_modified" => date('Y-m-d H:i:s', $lastModified), "mc_cached_time" => date('Y-m-d H:i:s', time())));
         $this->log("[cache] putFile insert");
     }
     $info = array("name" => $file->getName(), "isDirectory" => $attrs[0] == 'd', "canRead" => $attrs[1] == 'r', "canWrite" => $attrs[2] == 'w', "size" => $size, "lastModified" => $lastModified);
     return $info;
 }