/**
  * Internal method to create the size
  * @param ImageReferencedElement $entity
  * @param EntityManager $em
  */
 protected function createImageSize(ImageReferencedElement $entity, EntityManager $em)
 {
     $imageId = $entity->getImageId();
     $fileStorage = $this->container['cms.file_storage'];
     /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */
     $image = $fileStorage->findImage($imageId);
     if ($image === null) {
         $this->container->getLogger()->warn("Image [{$imageId}] was not found inside the file storage." . " Maybe another file storage must be configured for the image size creator listener?");
         return false;
     }
     $width = $entity->getWidth();
     $height = $entity->getHeight();
     // No dimensions
     if ($width > 0 && $height > 0 || $entity->isCropped()) {
         if ($entity->isCropped()) {
             $sizeName = $fileStorage->createImageVariant($image, $width, $height, $entity->getCropLeft(), $entity->getCropTop(), $entity->getCropWidth(), $entity->getCropHeight());
         } else {
             $sizeName = $fileStorage->createResizedImage($image, $width, $height);
         }
         $entity->setSizeName($sizeName);
         // Maybe could update to real width/height inside image metadata?
         //		$size = $image->getImageSize($sizeName);
         //		$entity->setWidth($size->getWidth());
         //		$entity->setHeight($size->getHeight());
         // Recalculate the changeset because of changed size name field
         $class = $em->getClassMetadata(ImageReferencedElement::CN());
         $unitOfWork = $em->getUnitOfWork();
         $unitOfWork->recomputeSingleEntityChangeSet($class, $entity);
     }
 }
 protected function logEvent($name, $event)
 {
     //log this into monolog
     $context = array();
     if ($event instanceof RequestResponseEvent) {
         $context['url'] = $event->getRequest()->getPathInfo();
     }
     $this->container->getLogger()->addDebug(sprintf('Processing event "%s"', $name), $context);
 }
Exemplo n.º 3
0
 /**
  * {@inheritDoc}
  * @return string
  */
 public function filter($content, array $options = array())
 {
     $itemTemplate = !empty($options['itemTemplate']) ? (string) $options['itemTemplate'] : '';
     $wrapperTemplate = !empty($options['wrapperTemplate']) ? (string) $options['wrapperTemplate'] : '';
     $output = '';
     $fileStorage = $this->container['cms.file_storage'];
     /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */
     foreach ($this->blockProperty->getMetadata() as $metadata) {
         /* @var $metadata \Supra\Package\Cms\Entity\BlockPropertyMetadata */
         $element = $metadata->getReferencedElement();
         if (!$element instanceof ImageReferencedElement || $element->getSizeName() === null) {
             continue;
         }
         $image = $fileStorage->findImage($element->getImageId());
         if ($image === null) {
             continue;
         }
         $previewSize = $image->getImageSize($element->getSizeName());
         if ($previewSize === null) {
             continue;
         }
         $previewUrl = $fileStorage->getWebPath($image, $previewSize);
         $crop = isset($options['fullSizeCrop']) ? (bool) $options['fullSizeCrop'] : true;
         $fullSizeWidth = !empty($options['fullSizeMaxWidth']) ? (int) $options['fullSizeMaxWidth'] : null;
         $fullSizeHeight = !empty($options['fullSizeMaxHeight']) ? (int) $options['fullSizeMaxWidth'] : null;
         try {
             list($width, $height) = $this->getFullSizeDimensions($image, $fullSizeWidth, $fullSizeHeight, $crop);
             $fullSizeName = $fileStorage->createResizedImage($image, $width, $height, $crop);
         } catch (FileStorageException $e) {
             $this->container->getLogger()->warn($e->getMessage());
             continue;
         }
         $fullSize = $image->getImageSize($fullSizeName);
         $fullSizeUrl = $fileStorage->getWebPath($image, $fullSize);
         $itemData = array('image' => '<img src="' . $previewUrl . '" alt="' . $element->getAlternateText() . '" />', 'imageUrl' => $previewUrl, 'title' => $element->getTitle(), 'description' => $element->getDescription(), 'fullSizeUrl' => $fullSizeUrl, 'fullSizeWidth' => $fullSize->getWidth(), 'fullSizeHeight' => $fullSize->getHeight());
         $output .= preg_replace_callback('/{{\\s*(image|title|description|fullSizeUrl|fullSizeWidth|fullSizeHeight)\\s*}}/', function ($matches) use($itemData) {
             return $itemData[$matches[1]];
         }, $itemTemplate);
     }
     return preg_replace('/{{\\s*items\\s*}}/', $output, $wrapperTemplate);
 }
Exemplo n.º 4
0
 /**
  * Is current image format supported by image processor
  * @param string $filename Path to file
  */
 public function isSupportedImageFormat($filename)
 {
     $info = new ImageInfo($filename);
     if ($info->hasError()) {
         $this->container->getLogger()->error($info->getError());
         return false;
     }
     if (!$this->isMimeTypeImage($info->getMime())) {
         return false;
     }
     return ImageProcessor\ImageProcessor::isSupportedImageType($info->getType());
 }
Exemplo n.º 5
0
 /**
  * Parse supra.image
  * 
  * @param ImageReferencedElement $imageData
  * @return null|HtmlTag
  */
 protected function parseSupraImage(ImageReferencedElement $imageData)
 {
     $imageId = $imageData->getImageId();
     $fileStorage = $this->container['cms.file_storage'];
     /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */
     $image = $fileStorage->findImage($imageId);
     if ($image === null) {
         return null;
     }
     $sizeName = $imageData->getSizeName();
     $size = $image->findImageSize($sizeName);
     if ($size === null) {
         $this->container->getLogger()->warn("Image [{$imageId}] size [{$sizeName}] not found.");
         return null;
     }
     $tag = new HtmlTag('img');
     if ($size->isCropped()) {
         $width = $size->getCropWidth();
         $height = $size->getCropHeight();
     } else {
         $width = $size->getWidth();
         $height = $size->getHeight();
     }
     $src = $fileStorage->getWebPath($image, $size);
     $tag->setAttribute('src', $src);
     $align = $imageData->getAlign();
     if (!empty($align)) {
         if ($align === 'left') {
             $tag->addClass('pull-left');
         } else {
             if ($align === 'right') {
                 $tag->addClass('pull-right');
             } else {
                 if ($align === 'center') {
                     $tag->addClass('center-block');
                     $tag->setAttribute('style', "width: {$width}px;");
                 }
             }
         }
     }
     if (!empty($width)) {
         $tag->setAttribute('width', $width);
     }
     if (!empty($height)) {
         $tag->setAttribute('height', $height);
     }
     $title = trim($imageData->getTitle());
     if (!empty($title)) {
         $tag->setAttribute('title', $title);
     }
     $tag->setAttribute('alt', trim($imageData->getAlternateText()));
     return $tag;
 }
 /**
  * {@inheritDoc}
  */
 public function transform($value)
 {
     $imageDataArray = array();
     $fileStorage = $this->getFileStorage();
     foreach ($this->property->getMetadata() as $metadata) {
         /* @var $metadata BlockPropertyMetadata */
         $element = $metadata->getReferencedElement();
         if (!$element instanceof ImageReferencedElement) {
             throw new TransformationFailedException(sprintf('Expecting only image referenced elements, [%s] received.', $element ? get_class($element) : 'NULL'));
         }
         $image = $fileStorage->findImage($element->getImageId());
         if ($image === null) {
             $this->container->getLogger()->warn("Image [{$element->getImageId()}] not found.");
             continue;
         }
         $imageDataArray[] = array('title' => $element->getTitle(), 'description' => $element->getDescription(), 'image' => array_merge($element->toArray(), array('image' => $fileStorage->getFileInfo($image))));
     }
     return $imageDataArray;
 }
Exemplo n.º 7
0
 public function inject(ContainerInterface $container)
 {
     if (!$container->getParameter('debug')) {
         return;
     }
     $container[$this->name . '.session_collector'] = function () {
         return new SessionCollector();
     };
     $container[$this->name . '.timeline_collector'] = function () {
         return new TimelineCollector();
     };
     $container[$this->name . '.event_collector'] = function () {
         return new EventCollector();
     };
     $container[$this->name . '.monolog_collector'] = function (ContainerInterface $container) {
         return new MonologCollector($container->getLogger());
     };
     $container[$this->name . '.doctrine_collector'] = function (ContainerInterface $container) {
         $debugStack = new DebugStack();
         $container['doctrine.logger']->addLogger($debugStack);
         return new DoctrineCollector($debugStack);
     };
     $container[$this->name . '.debug_bar'] = function ($container) {
         $debugBar = new StandardDebugBar();
         $debugBar->addCollector($container[$this->name . '.session_collector']);
         $debugBar->addCollector($container[$this->name . '.doctrine_collector']);
         $debugBar->addCollector($container[$this->name . '.event_collector']);
         $debugBar->addCollector($container[$this->name . '.monolog_collector']);
         return $debugBar;
     };
     $container[$this->name . '.response_listener'] = new DebugBarResponseListener();
     $container[$this->name . '.assets_listener'] = new AssetsPublishEventListener();
     $container->getEventDispatcher()->addListener(KernelEvent::RESPONSE, array($container[$this->name . '.response_listener'], 'listen'));
     $container->getEventDispatcher()->addListener(FrameworkConsoleEvent::ASSETS_PUBLISH, array($container[$this->name . '.assets_listener'], 'listen'));
     //timeline collector binds to many events at once
     $container->getEventDispatcher()->addSubscriber($container[$this->name . '.timeline_collector']);
 }
Exemplo n.º 8
0
 /**
  * Logs a SQL statement somewhere.
  *
  * @param string $sql The SQL to be executed.
  * @param array $params The SQL parameters.
  * @param array $types The SQL parameter types.
  * @return void
  */
 public function startQuery($sql, array $params = null, array $types = null)
 {
     $this->container->getLogger()->addDebug(sprintf('DOCTRINE: %s', $sql), $params ? $params : array());
 }