示例#1
0
 public function sGetImageLink($hash, $imageSize = null)
 {
     if (empty($hash)) {
         return "";
     }
     $mediaService = Shopware()->Container()->get('shopware_media.media_service');
     // get the image directory
     $imageDir = 'media/image/';
     // if no imageSize was set, return the full image
     if (null === $imageSize) {
         return $mediaService->getUrl($imageDir . $hash);
     }
     // get filename and extension in order to insert thumbnail size later
     $extension = pathinfo($hash, PATHINFO_EXTENSION);
     $fileName = pathinfo($hash, PATHINFO_FILENAME);
     $thumbDir = $imageDir . 'thumbnail/';
     // get thumbnail sizes
     $sizes = $this->articleMediaAlbum->getSettings()->getThumbnailSize();
     foreach ($sizes as $key => &$size) {
         if (strpos($size, 'x') === 0) {
             $size = $size . 'x' . $size;
         }
     }
     if (isset($sizes[$imageSize])) {
         return $mediaService->getUrl($thumbDir . $fileName . '_' . $sizes[(int) $imageSize] . '.' . $extension);
     }
     return "";
 }
示例#2
0
 public function sGetImageLink($hash, $imageSize = null)
 {
     if (!empty($hash)) {
         $sql = "SELECT articleID FROM s_articles_img WHERE img =?";
         $articleId = Shopware()->Db()->fetchOne($sql, array($hash));
         $imageSize = intval($imageSize);
         $image = $this->getArticleRepository()->getArticleCoverImageQuery($articleId)->getOneOrNullResult(\Doctrine\ORM\AbstractQuery::HYDRATE_ARRAY);
         if (empty($image)) {
             return "";
         }
         //first we get all thumbnail sizes of the article album
         $sizes = $this->articleMediaAlbum->getSettings()->getThumbnailSize();
         //now we get the configured image and thumbnail dir.
         $imageDir = 'http://' . $this->shop->getHost() . $this->request->getBasePath() . '/media/image/';
         $thumbDir = $imageDir . 'thumbnail/';
         foreach ($sizes as $key => $size) {
             if (strpos($size, 'x') === 0) {
                 $size = $size . 'x' . $size;
             }
             $imageData[$key] = $thumbDir . $image['path'] . '_' . $size . '.' . $image['extension'];
         }
         if (!empty($imageData)) {
             return $imageData[$imageSize];
         }
     }
     return "";
 }
示例#3
0
 public function sGetImageLink($hash, $imageSize = null)
 {
     if (empty($hash)) {
         return "";
     }
     // get the image directory
     $imageDir = 'http://' . $this->shop->getHost() . $this->shop->getBasePath() . '/media/image/';
     // if no imageSize was set, return the full image
     if (null === $imageSize) {
         return $imageDir . $hash;
     }
     // get filename and extension in order to insert thumbnail size later
     $extension = pathinfo($hash, PATHINFO_EXTENSION);
     $fileName = pathinfo($hash, PATHINFO_FILENAME);
     $thumbDir = $imageDir . 'thumbnail/';
     // get thumbnail sizes
     $sizes = $this->articleMediaAlbum->getSettings()->getThumbnailSize();
     foreach ($sizes as $key => &$size) {
         if (strpos($size, 'x') === 0) {
             $size = $size . 'x' . $size;
         }
     }
     if (isset($sizes[$imageSize])) {
         return $thumbDir . $fileName . '_' . $sizes[(int) $imageSize] . '.' . $extension;
     }
     return "";
 }
 /**
  * @param Album $album
  * @return bool
  */
 private function hasNoThumbnails($album)
 {
     $sizes = $album->getSettings()->getThumbnailSize();
     return empty($sizes) || empty($sizes[0]) || $album->getMedia()->count() === 0;
 }
示例#5
0
文件: Media.php 项目: nhp/shopware-4
    /**
     * Loads the thumbnails paths via the configured thumbnail sizes.
     * If the thumbnail file of a configured thumbnail size don't exists, it will be created.
     * @return array
     */
    public function loadThumbnails()
    {
        if ($this->type !== self::TYPE_IMAGE) {
            return array();
        }
        $sizes = array();

        //concat default sizes
        foreach ($this->defaultThumbnails as $size) {
            if (count($size) === 1) {
                $sizes[] = $size . 'x' . $size;
            } else {
                $sizes[] = $size[0] . 'x' . $size[1];
            }
        }

        //Check if the album has loaded correctly.
        if ($this->album !== null && $this->album->getSettings() !== null && $this->album->getSettings()->getCreateThumbnails() === 1) {
            $sizes = array_merge($this->album->getSettings()->getThumbnailSize(), $sizes);
            $sizes = array_unique($sizes);
        }
        $thumbnails = array();

        //iterate thumbnail sizes
        foreach ($sizes as $size) {
            if (strpos($size, 'x') === false) {
                $size = $size . 'x' . $size;
            }
			$path = $this->getThumbnailDir() . str_replace('.' . $this->extension, '_' . $size . '.' . $this->extension, $this->getFileName());
            //create the thumbnail if not exist.
            if (!file_exists($path)) {
                $data = explode('x', $size);
                $this->createThumbnail((int) $data[0], (int) $data[1]);
            }
            $path = str_replace(Shopware()->OldPath(), '', $path);
            if (DIRECTORY_SEPARATOR !== '/') {
                $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
            }
            $thumbnails[$size] = $path;
        }

        return $thumbnails;
    }
示例#6
0
文件: Media.php 项目: nhp/shopware-4
    /**
     * Creates the thumbnail files in the different sizes which configured in the album settings.
     *
     * @param \Shopware\Models\Media\Album $album
     * @return void
     */
    public function createAlbumThumbnails(Album $album)
    {
        //is image media?
        if ($this->type !== self::TYPE_IMAGE) {
            return;
        }

        //Check if the album has loaded correctly and should be created for the album thumbnails?
        if ($album === null || $album->getSettings() === null || !$album->getSettings()->getCreateThumbnails()) {
            return;
        }

        //load the configured album thumbnail sizes
        $sizes = $album->getSettings()->getThumbnailSize();       

        //iterate the sizes and create the thumbnails
        foreach ($sizes as $size) {
            //split the width and height (example: $size = 70x70)
            $data = explode('x', $size);

            //check if the album thumbnail is already configured over the default thumbnails, so we don't have to create the same thumbnail again.
            if (in_array($data, $this->defaultThumbnails)) {
                continue;
            }

            // To avoid any confusing, we're mapping the index based to an association based array and remove the index based elements.
            $data['width'] = $data[0];
            $data['height'] = $data[1];
            unset($data[0]);
            unset($data[1]);

            //continue if configured size is not numeric
            if (!is_numeric($data['width'])) {
                continue;
            }
            //if no height configured, set 0
            $data['height'] = (isset($data['height'])) ? $data['height'] : 0;

            //create thumbnail with the configured size
            $this->createThumbnail((int) $data['width'], (int) $data['height']);
        }
    }
 /**
  * {@inheritDoc}
  */
 public function getSettings()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getSettings', array());
     return parent::getSettings();
 }
示例#8
0
 /**
  * This method resolves the given request data and returns
  * an array with album data
  *
  * @param $data
  * @param Album $album
  * @throws Exception
  * @return array|bool
  */
 protected function resolveAlbumData($data, $album)
 {
     $settings = $album->getSettings();
     if (!$settings) {
         $settings = new Settings();
         $settings->setAlbum($album);
     }
     // validate album name
     if (empty($data['text'])) {
         throw new Exception('No valid album name passed!');
     }
     $data['name'] = $data['text'];
     $data['parent'] = null;
     if (!empty($data['parentId']) && $data['parentId'] != 'root') {
         $parent = $this->getManager()->find('Shopware\\Models\\Media\\Album', $data['parentId']);
         if (!$parent) {
             throw new Exception('No valid parent album passed!');
         }
         $data['parent'] = $parent;
     }
     $thumbnailSizes = '';
     $createThumbnails = 0;
     $icon = 'sprite-blue-folder';
     if (isset($data['createThumbnails'])) {
         $createThumbnails = (int) $data['createThumbnails'];
     }
     if (isset($data['thumbnailSize'])) {
         $thumbnailSizes = array();
         foreach ($data['thumbnailSize'] as $size) {
             if (!empty($size['value']) && $size['value'] !== '') {
                 $thumbnailSizes[] = $size['value'];
             }
         }
     }
     if (isset($data['iconCls']) && !empty($data['iconCls'])) {
         $icon = $data['iconCls'];
     }
     $albumId = $album->getId();
     if (empty($albumId) && $data['parent'] !== null) {
         /** @var Settings $parentSettings */
         $parentSettings = $data['parent']->getSettings();
         $thumbnailSizes = $parentSettings->getThumbnailSize();
         $createThumbnails = $parentSettings->getCreateThumbnails();
     }
     $settings->setCreateThumbnails($createThumbnails);
     $settings->setThumbnailSize(empty($thumbnailSizes) ? '' : $thumbnailSizes);
     $settings->setIcon($icon);
     $data['settings'] = $settings;
     return $data;
 }
示例#9
0
 /**
  * Returns an array of all thumbnail paths the media object can have
  *
  * @param bool $highDpi - If true, returns the file path for the high dpi thumbnails instead
  * @return array
  */
 public function getThumbnailFilePaths($highDpi = false)
 {
     if ($this->type !== self::TYPE_IMAGE) {
         return array();
     }
     $sizes = array();
     //concat default sizes
     foreach ($this->defaultThumbnails as $size) {
         if (count($size) === 1) {
             $sizes[] = $size . 'x' . $size;
         } else {
             $sizes[] = $size[0] . 'x' . $size[1];
         }
     }
     //Check if the album has loaded correctly.
     if ($this->album !== null && $this->album->getSettings() !== null && $this->album->getSettings()->getCreateThumbnails() === 1) {
         $sizes = array_merge($this->album->getSettings()->getThumbnailSize(), $sizes);
         $sizes = array_unique($sizes);
     }
     $thumbnails = array();
     $suffix = $highDpi ? '@2x' : '';
     //iterate thumbnail sizes
     foreach ($sizes as $size) {
         if (strpos($size, 'x') === false) {
             $size = $size . 'x' . $size;
         }
         $fileName = str_replace('.' . $this->extension, '_' . $size . $suffix . '.' . $this->extension, $this->getFileName());
         $path = $this->getThumbnailDir() . $fileName;
         $path = str_replace(Shopware()->OldPath(), '', $path);
         if (DIRECTORY_SEPARATOR !== '/') {
             $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
         }
         $thumbnails[$size] = $path;
     }
     return $thumbnails;
 }