/** * {@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; }
public function filter($content, array $options = array()) { if ($content instanceof HtmlTag) { $content->addClass('su-content-inline su-input-map-inline map')->setAttribute('id', sprintf('content_%s_%s', $this->blockProperty->getBlock()->getId(), str_replace('.', '_', $this->blockProperty->getHierarchicalName()))); } return $content; }
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; }
/** * @param string $content * @param array $options * @return string */ public function filter($content, array $options = array()) { $elements = array(); foreach ($this->blockProperty->getMetadata() as $key => $item) { $elements[$key] = $item->getReferencedElement(); } return $this->parseSupraMarkup($content, $elements); }
/** * {@inheritDoc} */ public function createProperty($name) { $property = new BlockProperty($name); $property->setEditableClass(get_class($this->editable)); // @TODO: value conversion // @TODO: localized values $property->setValue($this->editable->getDefaultValue()); return $property; }
/** * @param mixed $value * @return null|array */ public function transform($value) { if ($value !== null) { // @TODO: not sure if this one is needed. just double checking. throw new \LogicException('Expecting link containing block property value to be null.'); } if ($this->property->getMetadata()->offsetExists('link')) { $metaItem = $this->property->getMetadata()->get('link'); $element = $metaItem->getReferencedElement(); return $element !== null ? $element->toArray() : null; } return null; }
/** * @return BlockPropertyMetadata */ private function getMediaMetadata() { if (!$this->property->getMetadata()->offsetExists('media')) { $this->property->addMetadata(new BlockPropertyMetadata('media', $this->property)); } return $this->property->getMetadata()->get('media'); }
/** * @return string */ public function getHierarchicalName() { if ($this->parent === null) { return $this->name; } return $this->parent->getHierarchicalName() . '.' . $this->name; }
/** * @return BlockPropertyMetadata */ private function getFontsMetadata() { $metaCollection = $this->property->getMetadata(); if ($metaCollection->containsKey('fonts')) { return $metaCollection->get('fonts'); } return new BlockPropertyMetadata('fonts', $this->property); }
/** * @param mixed $value * @return null|array */ public function transform($value) { $metadata = $this->property->getMetadata(); if (!isset($metadata['media'])) { return null; } $element = $metadata['media']->getReferencedElement(); return $element ? $element->toArray() : null; }
/** * {@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; }
/** * @param mixed $value * @return null|array */ public function transform($value) { if ($value !== null) { // @TODO: not sure if this one is needed. just double checking. throw new \LogicException('Expecting image containing block property value to be null.'); } if ($this->property->getMetadata()->offsetExists('image')) { $metaItem = $this->property->getMetadata()->get('image'); $element = $metaItem->getReferencedElement(); if ($element instanceof ImageReferencedElement) { $fileStorage = $this->container['cms.file_storage']; /* @var $fileStorage \Supra\Package\Cms\FileStorage\FileStorage */ $image = $fileStorage->findImage($element->getImageId()); if ($image !== null) { return array_merge($element->toArray(), array('image' => $fileStorage->getFileInfo($image))); } } } return null; }
/** * {@inheritDoc} */ public function filter($content, array $options = array()) { $metadata = $this->property->getMetadata(); if (!isset($metadata['media'])) { return null; } $element = $metadata['media']->getReferencedElement(); if (!$element instanceof MediaReferencedElement) { return null; } $mediaEmbed = $this->container['cms.media_embed']; /* @var $mediaEmbed MediaEmbed */ $mediaObject = $mediaEmbed->parseUrl($element->getUrl()); if ($mediaObject === null) { return null; } $mediaObject->setWidth($element->getWidth()); $mediaObject->setHeight($element->getHeight()); return $mediaObject->getEmbedCode(); }
/** * {@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); }
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) { $tag = new ImageTag($image, $fileStorage); $tag->setAttribute('alt', $element->getAlternateText()); return $tag; } } } return null; }
/** * @return QueryBuilder */ protected function doGetQueryBuilder() { $qb = $this->localizationFinder->getQueryBuilder(); $qb = clone $qb; $qb->from(BlockProperty::CN(), 'bp'); $qb->andWhere('bp.localization = l'); $qb->join('bp.localization', 'l3'); $qb->join('bp.block', 'b'); $qb->join('b.placeHolder', 'ph'); $qb->leftJoin('bp.metadata', 'bpm'); $qb->leftJoin('bpm.referencedElement', 're'); $qb->join('l3.master', 'e3'); $qb->join('l3.path', 'lp3'); $qb->select('bp, b, l3, e3, bpm, ph, lp3, re'); $qb = $this->prepareComponents($qb); return $qb; }
/** * @param MediaReferencedElement $element * @return null|string */ protected function handleMediaElement(MediaReferencedElement $element) { $mediaEmbed = $this->container['cms.media_embed']; /* @var $mediaEmbed MediaEmbed */ $mediaObject = $mediaEmbed->parseUrl($element->getUrl()); if ($mediaObject === null) { return null; } $metadata = $this->property->getMetadata(); if ($metadata->offsetExists('width')) { $width = (int) $metadata->get('width')->getValue(); $mediaObject->setWidth($width); } if ($metadata->offsetExists('height')) { $height = (int) $metadata->get('height')->getValue(); $mediaObject->setHeight($height); } return $mediaObject->getEmbedCode(); }
/** * @param string $content * @param array $options * @return string */ public function filter($content, array $options = array()) { $wrap = '<span id="content_%s_%s" class="su-content-inline su-input-image-inline">%s</span>'; return sprintf($wrap, $this->blockProperty->getBlock()->getId(), str_replace('.', '_', $this->blockProperty->getHierarchicalName()), $content); }
/** * @param string $content * @param array $options * @return string */ public function filter($content, array $options = array()) { $itemTemplate = !empty($options['itemTemplate']) ? $options['itemTemplate'] : null; $wrapperTemplate = !empty($options['wrapperTemplate']) ? $options['wrapperTemplate'] : null; return sprintf('<div id="content_%s_%s" class="su-content-inline su-input-gallery-inline" data-item-template="%s" data-wrapper-template="%s">%s</div>', $this->blockProperty->getBlock()->getId(), str_replace('.', '_', $this->blockProperty->getHierarchicalName()), htmlspecialchars($itemTemplate), htmlspecialchars($wrapperTemplate), $content); }
/** * @param string $content * @param array $options * @return string */ public function filter($content, array $options = array()) { return sprintf('<div id="content_%s_%s" class="su-content-inline su-input-media-inline-content">%s</div>', $this->blockProperty->getBlock()->getId(), str_replace('.', '_', $this->blockProperty->getHierarchicalName()), $content); }
/** * @TODO: this should be moved to editable configuration. * * @param BlockProperty $property * @param Editable\Editable $editable */ protected function configureViewFilters(Editable\Editable $editable, BlockProperty $property) { $propertyId = $property->getId(); if (array_key_exists($propertyId, $this->configuredBlockProperties)) { return; } $filters = array(); // Html content filters if ($editable instanceof Editable\Html) { $filters[] = $this->request instanceof PageRequestEdit ? new Filter\EditableHtmlFilter() : new Filter\HtmlFilter(); // Editable Inline String } elseif ($editable instanceof Editable\InlineString) { if ($this->request instanceof PageRequestEdit) { $filters[] = new Filter\EditableInlineStringFilter(); } // Textarea and Inline Textarea } elseif ($editable instanceof Editable\Textarea || $editable instanceof Editable\InlineTextarea) { $filters[] = new Editable\Filter\TextareaFilter(); if ($this->request instanceof PageRequestEdit && $editable instanceof Editable\InlineTextarea) { $filters[] = new Filter\EditableInlineTextareaFilter(); } } elseif ($editable instanceof Editable\Link) { $filters[] = new Filter\LinkFilter(); } elseif ($editable instanceof Editable\DateTime) { $filters[] = new Editable\Filter\DateTimeFilter(); } elseif ($editable instanceof Editable\Image) { $filters[] = $editable instanceof Editable\InlineImage ? new Filter\InlineImageFilter() : new Filter\ImageFilter(); if ($editable instanceof Editable\InlineImage && $this->request instanceof PageRequestEdit) { $filters[] = new Filter\EditableInlineImageFilter(); } } elseif ($editable instanceof Editable\Gallery) { $filters[] = new Filter\GalleryFilter(); if ($this->request instanceof PageRequestEdit) { $filters[] = new Filter\EditableGalleryFilter(); } } elseif ($editable instanceof Editable\InlineMap) { $filters[] = new Filter\InlineMapFilter(); if ($this->request instanceof PageRequestEdit) { $filters[] = new Filter\EditableInlineMapFilter(); } } elseif ($editable instanceof Editable\Keywords) { $filters[] = new Filter\KeywordsFilter(); } elseif ($editable instanceof Editable\Video) { $filters[] = new Filter\VideoFilter(); } elseif ($editable instanceof Editable\InlineMedia) { $filters[] = new Filter\InlineMediaFilter(); if ($this->request instanceof PageRequestEdit) { $filters[] = new Filter\EditableInlineMediaFilter(); } } foreach ($filters as $filter) { if ($filter instanceof ContainerAware) { $filter->setContainer($this->container); } if ($filter instanceof BlockPropertyAware) { $filter->setBlockProperty($property); } $editable->addViewFilter($filter); } $this->configuredBlockProperties[$propertyId] = true; }
public function isBlockPropertyEditable(BlockProperty $blockProperty) { $page = $blockProperty->getLocalization()->getMaster(); $editable = $page->equals($this); return $editable; }
/** * @return Set\BlockPropertySet */ public function getBlockPropertySet() { if (isset($this->blockPropertySet)) { return $this->blockPropertySet; } $this->blockPropertySet = new Set\BlockPropertySet(); $entityManager = $this->getEntityManager(); $qb = $entityManager->createQueryBuilder(); $expr = $qb->expr(); $or = $expr->orX(); $cnt = 0; $blockSet = $this->getBlockSet(); //$sharedPropertyFinder = new SharedPropertyFinder($entityManager); $localResourceLocalizations = array(); // Loop generates condition for property getter foreach ($blockSet as $block) { /* @var $block Block */ $blockId = $block->getId(); // Skip if the block response is read from the cache already if (in_array($blockId, $this->skipBlockPropertyLoading)) { continue; } $data = null; if ($block->getLocked()) { $data = $block->getPlaceHolder()->getMaster(); } else { $data = $this->getLocalization(); } $dataId = $data->getId(); if (!$this->isLocalResource($data)) { $and = $expr->andX(); $and->add($expr->eq('bp.block', '?' . ++$cnt)); $qb->setParameter($cnt, $blockId); $and->add($expr->eq('bp.localization', '?' . ++$cnt)); $qb->setParameter($cnt, $dataId); $or->add($and); } else { // In reality there can be only one local resource localization $localResourceLocalizations[$dataId] = $data; } //$sharedPropertyFinder->addBlock($block, $data); } $result = array(); // Load only if any condition is added to the query if ($cnt != 0) { $qb->select('bp')->from(BlockProperty::CN(), 'bp')->where($or); $query = $qb->getQuery(); $this->prepareQueryResultCache($query); $result = $query->getResult(); } // Now merge local resource block properties foreach ($localResourceLocalizations as $localization) { /* @var $localization Localization */ $localProperties = $localization->getBlockProperties()->getValues(); $result = array_merge($result, $localProperties); } $this->blockPropertySet->exchangeArray($result); return $this->blockPropertySet; }
/** * {@inheritDoc} */ public function isMatchingProperty(BlockProperty $property) { return $property->getHierarchicalName() == $this->name; }
/** * {@inheritDoc} */ public function count() { return $this->collectionProperty->getProperties()->count(); }
/** * @param string $content * @param array $options * @return string */ public function filter($content, array $options = array()) { $wrap = '<div id="content_%s_%s" class="su-content-inline su-input-string-inline">%s</div>'; return sprintf($wrap, $this->blockProperty->getBlock()->getId(), str_replace('.', '_', $this->blockProperty->getHierarchicalName()), htmlspecialchars($content, ENT_QUOTES, 'UTF-8')); }
protected function prepareData(ClassMetadata $metadata, array $data) { foreach ($data as $name => &$entityData) { switch ($metadata->name) { case Localization::CN(): case PageLocalization::CN(): case TemplateLocalization::CN(): case ApplicationLocalization::CN(): $entityData['publishedRevision'] = null; $args = array($entityData['locale']); break; case PageLocalizationPath::CN(): $args = array(str_ireplace('pageLocalizationPath', '', $name), $entityData['locale']); break; case TemplateLayout::CN(): $args = array($entityData['media']); break; case BlockPropertyMetadata::CN(): $args = array($entityData['name'], $entityData['blockProperty']); break; case BlockProperty::CN(): $args = array($entityData['name']); break; case PagePlaceHolder::CN(): case TemplatePlaceHolder::CN(): $args = array($entityData['name']); break; default: $constructor = new \ReflectionMethod($metadata->name, '__construct'); if ($constructor->getNumberOfRequiredParameters() === 0) { return parent::prepareData($metadata, $data); } throw new \RuntimeException(sprintf('Don\'t know how to build constructor required for [%s].', $metadata->name)); } $entityData = array_merge(array('__construct' => $args), $entityData); } return parent::prepareData($metadata, $data); }