コード例 #1
0
ファイル: LinkFilter.php プロジェクト: sitesupra/sitesupra
 /**
  * {@inheritDoc}
  */
 public function filter($content, array $options = array())
 {
     if ($this->blockProperty->getMetadata()->offsetExists('link')) {
         $element = $this->blockProperty->getMetadata()->get('link')->getReferencedElement();
         if ($element !== null) {
             /* @var $element LinkReferencedElement */
             if (!$element instanceof LinkReferencedElement) {
                 // @TODO: any exception should be thrown probably
                 return null;
             }
             // @TODO: the same code is inside HtmlFilter, should combine somehow.
             $title = ReferencedElementUtils::getLinkReferencedElementTitle($element, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale());
             // @TODO: what if we failed to obtain the URL?
             $url = ReferencedElementUtils::getLinkReferencedElementUrl($element, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale());
             $tag = new HtmlTag('a', $title ? $title : $url);
             $tag->setAttribute('title', $title)->setAttribute('href', $url)->setAttribute('class', $element->getClassName());
             $target = $element->getTarget();
             if (!empty($target)) {
                 $tag->setAttribute('target', $target);
             }
             switch ($element->getResource()) {
                 case LinkReferencedElement::RESOURCE_FILE:
                     $tag->setAttribute('target', '_blank');
                     break;
             }
             return $tag;
         }
     }
     return null;
 }
コード例 #2
0
 public function filter($content, array $options = array())
 {
     if ($this->blockProperty->getMetadata()->offsetExists('image')) {
         $element = $this->blockProperty->getMetadata()->get('image')->getReferencedElement();
         if ($element !== null) {
             /* @var $element ImageReferencedElement */
             if (!$element instanceof ImageReferencedElement) {
                 // @TODO: any exception should be thrown probably
                 return null;
             }
             $imageId = $element->getImageId();
             $fileStorage = $this->container['cms.file_storage'];
             /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */
             $image = $fileStorage->findImage($imageId);
             if ($image === null) {
                 return null;
             }
             $imageSize = $image->findImageSize($element->getSizeName());
             if ($imageSize === null) {
                 return null;
             }
             $tag = new HtmlTag('img');
             $width = $imageSize->isCropped() ? $imageSize->getCropWidth() : $imageSize->getWidth();
             $tag->setAttribute('width', $width);
             $height = $imageSize->isCropped() ? $imageSize->getCropHeight() : $imageSize->getCropHeight();
             $tag->setAttribute('height', $height);
             $tag->setAttribute('alt', trim($element->getAlternateText()));
             $tag->setAttribute('src', $fileStorage->getWebPath($image, $imageSize));
             return $tag;
         }
     }
     return null;
 }
コード例 #3
0
 public function filter($content, array $options = array())
 {
     $mapData = array('latitude' => 56.946744, 'longitude' => 24.09856, 'zoom' => 12, 'height' => 200);
     if (!empty($content)) {
         $content = unserialize($content);
         if (is_array($content)) {
             $mapData = array_merge($mapData, array('latitude' => $content['latitude'], 'longitude' => $content['longitude'], 'zoom' => $content['zoom'], 'height' => $content['height']));
         }
     }
     $tag = new HtmlTag('div');
     $tag->forceTwoPartTag(true);
     $tag->setAttributes(array('data-latitude' => $mapData['latitude'], 'data-longitude' => $mapData['longitude'], 'data-zoom' => $mapData['zoom']));
     if (!empty($mapData['height'])) {
         $tag->setAttribute('style', 'height: ' . (int) $mapData['height'] . 'px');
     }
     // @TODO: if height is supported natively, marker text input also could be part of map editable.
     if (!empty($options['markerText'])) {
         $tag->setAttribute('data-marker-text', $options['markerText']);
     }
     return $tag;
 }
コード例 #4
0
 /**
  * @param ImageReferencedElement $element
  * @return null|string
  */
 protected function handleImageElement(ImageReferencedElement $element)
 {
     $imageId = $element->getImageId();
     $fileStorage = $this->container['cms.file_storage'];
     /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */
     $image = $fileStorage->findImage($imageId);
     if ($image === null) {
         return null;
     }
     $imageSize = $image->findImageSize($element->getSizeName());
     if ($imageSize === null) {
         return null;
     }
     $tag = new HtmlTag('img');
     $width = $imageSize->isCropped() ? $imageSize->getCropWidth() : $imageSize->getWidth();
     $tag->setAttribute('width', $width);
     $height = $imageSize->isCropped() ? $imageSize->getCropHeight() : $imageSize->getCropHeight();
     $tag->setAttribute('height', $height);
     $tag->setAttribute('alt', trim($element->getAlternateText()));
     $tag->setAttribute('src', $fileStorage->getWebPath($image, $imageSize));
     return $tag;
 }
コード例 #5
0
ファイル: HtmlFilter.php プロジェクト: sitesupra/sitesupra
 /**
  * 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;
 }
コード例 #6
0
ファイル: PageExtension.php プロジェクト: sitesupra/sitesupra
 /**
  * @param HtmlTag $tag
  * @param array $attributes
  *
  * @return null|HtmlTag
  */
 public function decorateHtmlTag($tag, array $attributes)
 {
     if (!$tag instanceof HtmlTag) {
         return null;
     }
     foreach ($attributes as $name => $value) {
         $tag->setAttribute($name, $value);
     }
     return $tag;
 }
コード例 #7
0
ファイル: ImageTag.php プロジェクト: sitesupra/sitesupra
 /**
  * {@inheritDoc}
  */
 public function toHtml()
 {
     try {
         $this->setAttribute('src', $this->getResizedImagePath($this->width, $this->height));
     } catch (\Exception $e) {
         // @TODO: it's not nice to silently exit here.
         // should log raised exception at least.
         return '';
     }
     return parent::toHtml();
 }
コード例 #8
0
 /**
  * @param string $key
  * @param string $url
  * @return ResponseContext
  */
 public function addCssLinkToLayoutSnippet($key, $url)
 {
     $linkTag = new HtmlTag('link');
     $linkTag->setAttribute('rel', 'stylesheet');
     $linkTag->setAttribute('type', 'text/css');
     $linkTag->setAttribute('href', $url);
     $this->addToLayoutSnippet($key, $linkTag->toHtml());
     return $this;
 }