Esempio n. 1
0
 /**
  * @static
  * @param Asset_Image|Asset_Video|string
  * @param Asset_Image_Thumbnail_Config $config
  * @param string $path
  * @return string
  */
 public static function process($asset, Asset_Image_Thumbnail_Config $config, $fileSystemPath = null)
 {
     $format = strtolower($config->getFormat());
     if (!$fileSystemPath) {
         $fileSystemPath = $asset->getFileSystemPath();
     }
     // simple detection for source type if SOURCE is selected
     if ($format == "source") {
         $typeMapping = array("gif" => "gif", "jpeg" => "jpeg", "jpg" => "jpeg", "png" => "png");
         $fileExt = Pimcore_File::getFileExtension($asset->getFilename());
         if ($typeMapping[$fileExt]) {
             $format = $typeMapping[$fileExt];
         } else {
             // use PNG if source doesn't have a valid mapping
             $format = "png";
         }
     }
     $filename = "thumb_" . $asset->getId() . "__" . $config->getName() . "." . $format;
     $fsPath = PIMCORE_TEMPORARY_DIRECTORY . "/" . $filename;
     $path = str_replace(PIMCORE_DOCUMENT_ROOT, "", $fsPath);
     // check for existing and still valid thumbnail
     if (is_file($fsPath) and filemtime($fsPath) > $asset->getModificationDate()) {
         return $path;
     }
     // transform image
     $image = Asset_Image::getImageTransformInstance();
     if (!$image->load($fileSystemPath)) {
         return "/pimcore/static/img/image-not-supported.png";
     }
     $transformations = $config->getItems();
     if (is_array($transformations) && count($transformations) > 0) {
         foreach ($transformations as $transformation) {
             if (!empty($transformation)) {
                 $arguments = array();
                 $mapping = self::$argumentMapping[$transformation["method"]];
                 if (is_array($transformation["arguments"])) {
                     foreach ($transformation["arguments"] as $key => $value) {
                         $position = array_search($key, $mapping);
                         if ($position !== false) {
                             $arguments[$position] = $value;
                         }
                     }
                 }
                 ksort($arguments);
                 if (count($mapping) == count($arguments)) {
                     call_user_func_array(array($image, $transformation["method"]), $arguments);
                 } else {
                     $message = "Image Transform failed: cannot call method `" . $transformation["method"] . "´ with arguments `" . implode(",", $arguments) . "´ because there are too few arguments";
                     Logger::error($message);
                 }
             }
         }
     }
     $image->save($fsPath, $format, $config->getQuality());
     return $path;
 }
 public function getImageThumbnailAction()
 {
     $image = Asset_Image::getById(intval($this->_getParam("id")));
     $thumbnail = null;
     if ($this->_getParam("thumbnail")) {
         $thumbnail = $image->getThumbnailConfig($this->_getParam("thumbnail"));
     }
     if (!$thumbnail) {
         if ($this->_getParam("config")) {
             $thumbnail = $image->getThumbnailConfig(Zend_Json::decode($this->_getParam("config")));
         } else {
             $thumbnail = $image->getThumbnailConfig($this->_getAllParams());
         }
     }
     $format = strtolower($thumbnail->getFormat());
     if ($format == "source") {
         $thumbnail->setFormat("PNG");
         $format = "png";
     }
     if ($this->_getParam("cropPercent")) {
         $thumbnail->addItemAt(0, "cropPercent", array("width" => $this->_getParam("cropWidth"), "height" => $this->_getParam("cropHeight"), "y" => $this->_getParam("cropTop"), "x" => $this->_getParam("cropLeft")));
         $hash = md5(Pimcore_Tool_Serialize::serialize($this->_getAllParams()));
         $thumbnail->setName("auto_" . $hash);
     }
     $this->getResponse()->setHeader("Content-Type", "image/" . $format, true);
     if ($this->_getParam("download")) {
         $this->getResponse()->setHeader("Content-Disposition", 'attachment; filename="' . $image->getFilename() . '"');
     }
     $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $image->getThumbnail($thumbnail);
     $imageContent = file_get_contents($thumbnailFile);
     $fileExtension = Pimcore_File::getFileExtension($thumbnailFile);
     if (in_array($fileExtension, array("gif", "jpeg", "jpeg", "png"))) {
         header("Content-Type: image/" . $fileExtension);
     } else {
         header("Content-Type: " . $image->getMimetype());
     }
     header("Content-Length: " . filesize($thumbnailFile));
     echo $imageContent;
     exit;
 }
Esempio n. 3
0
 /**
  * detects the pimcore internal asset type based on the mime-type and file extension
  *
  * @return void
  */
 public function setTypeFromMapping()
 {
     $found = false;
     $mappings = array("image" => array("/image/", "/\\.eps\$/", "/\\.ai\$/", "/\\.svgz\$/", "/\\.pcx\$/", "/\\.iff\$/", "/\\.pct\$/", "/\\.wmf\$/"), "text" => array("/text/"), "audio" => array("/audio/"), "video" => array("/video/"), "document" => array("/msword/", "/pdf/", "/powerpoint/", "/office/", "/excel/", "/opendocument/"), "archive" => array("/zip/", "/tar/"));
     foreach ($mappings as $type => $patterns) {
         foreach ($patterns as $pattern) {
             if (preg_match($pattern, $this->getMimetype() . " ." . Pimcore_File::getFileExtension($this->getFilename()))) {
                 $this->setType($type);
                 $found = true;
                 break;
             }
         }
         // break at first match
         if ($found) {
             break;
         }
     }
     // default is unknown
     if (!$found) {
         $this->setType("unknown");
     }
 }
Esempio n. 4
0
 /**
  * Returns a uniqe key for the element in the $target-Path (recursive)
  * @static
  * @return Element_Interface|string
  * @param string $type
  * @param string $sourceKey
  * @param Element_Interface $target
  */
 public static function getSaveCopyName($type, $sourceKey, $target)
 {
     $equalElement = self::getElementByPath($type, $target->getFullPath() . "/" . $sourceKey);
     if ($equalElement) {
         // only for assets: add the prefix _copy before the file extension (if exist) not after to that source.jpg will be source_copy.jpg and not source.jpg_copy
         if ($type == "asset" && ($fileExtension = Pimcore_File::getFileExtension($sourceKey))) {
             $sourceKey = str_replace("." . $fileExtension, "_copy." . $fileExtension, $sourceKey);
         } else {
             $sourceKey .= "_copy";
         }
         return self::getSaveCopyName($type, $sourceKey, $target);
     }
     return $sourceKey;
 }
Esempio n. 5
0
 /**
  * @param  User $user
  * @param  Asset $asset
  * @param  Asset $parent
  * @param boolean $expanded
  * @return
  */
 protected function getTreeNodePermissionConfig($user, $child, $parent, $expanded)
 {
     $userGroup = $user->getParent();
     if ($userGroup instanceof User) {
         $child->getPermissionsForUser($userGroup);
         $lock_list = $child->isAllowed("list");
         $lock_view = $child->isAllowed("view");
         $lock_publish = $child->isAllowed("publish");
         $lock_delete = $child->isAllowed("delete");
         $lock_rename = $child->isAllowed("rename");
         $lock_create = $child->isAllowed("create");
         $lock_permissions = $child->isAllowed("permissions");
         $lock_settings = $child->isAllowed("settings");
         $lock_versions = $child->isAllowed("versions");
         $lock_properties = $child->isAllowed("properties");
     }
     if ($parent instanceof Asset) {
         $parent->getPermissionsForUser($user);
     }
     $assetPermission = $child->getPermissionsForUser($user);
     $generallyAllowed = $user->isAllowed("assets");
     $parentId = (int) $child->getParentId();
     $parentAllowedList = true;
     if ($parent instanceof Asset) {
         $parentAllowedList = $parent->isAllowed("list") and $generallyAllowed;
     }
     $tmpAsset = array("_parent" => $parentId > 0 ? $parentId : null, "_id" => (int) $child->getId(), "text" => $child->getFilename(), "type" => $child->getType(), "path" => $child->getFullPath(), "basePath" => $child->getPath(), "elementType" => "asset", "permissionSet" => $assetPermission->getId() > 0 and $assetPermission->getCid() === $child->getId(), "list" => $child->isAllowed("list"), "list_editable" => $parentAllowedList and $generallyAllowed and !$lock_list and !$user->isAdmin(), "view" => $child->isAllowed("view"), "view_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_view and !$user->isAdmin(), "publish" => $child->isAllowed("publish"), "publish_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_publish and !$user->isAdmin(), "delete" => $child->isAllowed("delete"), "delete_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_delete and !$user->isAdmin(), "rename" => $child->isAllowed("rename"), "rename_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_rename and !$user->isAdmin(), "create" => $child->isAllowed("create"), "create_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_create and !$user->isAdmin(), "permissions" => $child->isAllowed("permissions"), "permissions_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_permissions and !$user->isAdmin(), "settings" => $child->isAllowed("settings"), "settings_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_settings and !$user->isAdmin(), "versions" => $child->isAllowed("versions"), "versions_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_versions and !$user->isAdmin(), "properties" => $child->isAllowed("properties"), "properties_editable" => $child->isAllowed("list") and $generallyAllowed and !$lock_properties and !$user->isAdmin());
     $tmpAsset["expanded"] = $expanded;
     $tmpAsset["_is_leaf"] = $child->hasNoChilds();
     // set type specific settings
     if ($child->getType() == "folder") {
         $tmpAsset["iconCls"] = "pimcore_icon_folder";
     } else {
         $tmpAsset["iconCls"] = "pimcore_icon_" . Pimcore_File::getFileExtension($child->getFilename());
     }
     return $tmpAsset;
 }