'); } private function _removehtml($s) { return strip_tags($s); } private function _splitbychars($s, $start = 0, $length = null) { return Str::substr($s, $start, $length); } private function _splitbywords($s, $start, $length) { $len = intval(Str::strlen($s)); if ($len > $start) { $posStart = max(0, $start == 0 ? 0 : Str::strpos($s, ' ', $start)); $posEnd = max(0, $length > $len ? $len : Str::strpos($s, ' ', $length)); if ($posEnd == 0 && $length <= $len) $posEnd = $len; return Str::substr($s, $posStart, $posEnd); } else { return ''; } } private function _findimage($s, $index) { $index = isset($index) ? intval($index) - 1 : 0; preg_match_all('/(]*>)|(background(-image)??\s*?:.*?url\((["|\']?)?(.+?)(["|\']?)?\))/i', $s, $r); if (isset($r[2]) && !empty($r[2][$index])) { $s = $r[2][$index]; } else if (isset($r[6]) && !empty($r[6][$index])) { $s = trim($r[6][$index], "'\" \t\n\r\0\x0B"); } else { $s = ''; } return $s; } private function _findlink($s, $index) { $index = isset($index) ? intval($index) - 1 : 0; preg_match_all('/href=["\']?([^"\'>]+)["\']?/i', $s, $r); if (isset($r[1]) && !empty($r[1][$index])) { $s = $r[1][$index]; } else { $s = ''; } return $s; } private function _removevarlink($s) { return preg_replace('/(.*?)<\/a>/', '', $s); } private function _removelinebreaks($s) { return preg_replace('/\r?\n|\r/', '', $s); } public function getTitle($isAdmin = false) { return $this->fill($this->title); } public function getDescription() { return $this->fill($this->description); } public function getRawTitle() { return $this->title; } public function getRawDescription() { return $this->description; } public function getBackgroundImage() { return $this->fill($this->parameters->get('backgroundImage')); } public function getThumbnail() { return ResourceTranslator::toUrl($this->getThumbnailRaw()); } public function getThumbnailRaw() { $image = $this->thumbnail; if (empty($image)) { return $this->getBackgroundImage(); } return $this->fill($image); } public function getThumbnailDynamic() { $image = $this->thumbnail; if (empty($image)) { $image = $this->parameters->get('backgroundImage'); } return $this->fill($image); } public function getThumbnailAltDynamic() { $alt = $this->fill($this->parameters->get('thumbnailAlt')); if (empty($alt)) { $alt = $this->getTitle(); } return $alt; } public function getLightboxImage() { $image = $this->fill($this->parameters->get('ligthboxImage')); if (empty($image)) { $image = $this->getBackgroundImage(); } return ResourceTranslator::toUrl($image); } public function getRow() { $this->fillParameters(); return array( 'title' => $this->getTitle(), 'slide' => $this->getFilledLayers(), 'description' => $this->getDescription(), 'thumbnail' => ResourceTranslator::urlToResource($this->getThumbnail()), 'published' => $this->published, 'publish_up' => $this->publish_up, 'publish_down' => $this->publish_down, 'first' => $this->first, 'params' => $this->parameters->toJSON(), 'slider' => $this->slider, 'ordering' => $this->ordering, 'generator_id' => 0 ); } public function fillParameters() { $this->parameters->set('backgroundImage', $this->fill($this->parameters->get('backgroundImage'))); $this->parameters->set('backgroundAlt', $this->fill($this->parameters->get('backgroundAlt'))); $this->parameters->set('backgroundTitle', $this->fill($this->parameters->get('backgroundTitle'))); $this->parameters->set('backgroundVideoMp4', $this->fill($this->parameters->get('backgroundVideoMp4'))); $this->parameters->set('backgroundColor', $this->fill($this->parameters->get('backgroundColor'))); $this->parameters->set('href', $this->fill($this->parameters->get('href'))); } private function getFilledLayers() { $layers = $this->slide['layers']; if (!$this->underEdit) { $layers = AbstractComponent::translateUniqueIdentifier($layers); } $this->fillLayers($layers); return json_encode($layers); } public function setNextCacheRefresh($time) { $this->nextCacheRefresh = min($this->nextCacheRefresh, $time); } public function setVisibility($visibility) { $this->visible = $visibility; } public function isVisible() { if (!$this->visible) { return false; } if ($this->publish_down != '1970-01-01 00:00:00') { $publish_down = strtotime($this->publish_down); if ($publish_down) { if ($publish_down > Platform::getTimestamp()) { $this->setNextCacheRefresh($publish_down); } else { return false; } } } if ($this->publish_up != '1970-01-01 00:00:00') { $publish_up = strtotime($this->publish_up); if ($publish_up) { if ($publish_up > Platform::getTimestamp()) { $this->setNextCacheRefresh($publish_up); return false; } } } return true; } public function getSlideStat() { if ($this->hasGenerator()) { return $this->generator->getSlideStat(); } return '1/1'; } public function getGeneratorLabel() { $source = $this->generator->getSource(); if (!$source) { return n2_('Not found'); } return $source->getLabel(); } public function getElementID() { return $this->getSlider()->elementId; } public function addScript($script, $name = false) { $this->sliderObject->addScript($script, $name); } public function isScriptAdded($name) { return $this->sliderObject->isScriptAdded($name); } public function addLess($file, $context) { $this->sliderObject->addLess($file, $context); } public function addCSS($css) { $this->sliderObject->addCSS($css); } public function addDeviceCSS($device, $css) { $this->sliderObject->addDeviceCSS($device, $css); } public function addFont($font, $mode, $pre = null) { return $this->sliderObject->addFont($font, $mode, $pre); } public function addStyle($style, $mode, $pre = null) { return $this->sliderObject->addStyle($style, $mode, $pre); } public function addImage($imageUrl) { $this->sliderObject->addImage($imageUrl); } public function isAdmin() { return $this->sliderObject->isAdmin; } public function isLazyLoadingEnabled() { return $this->sliderObject->features->lazyLoad->isEnabled; } public function optimizeImageWebP($src) { return array(); } public function renderImage($item, $src, $attributes = array(), $pictureAttributes = array()) { /** * @see https://bugs.chromium.org/p/chromium/issues/detail?id=1181291 */ if (!$this->frontendFirst) { $attributes['loading'] = 'lazy'; } $imageUrl = ResourceTranslator::toUrl($src); FastImageSize::initAttributes($src, $attributes); $attributes = Html::addExcludeLazyLoadAttributes($attributes); $attributes['src'] = $imageUrl; $this->addImage($imageUrl); return Html::tag('img', $attributes, false); } public function getThumbnailType() { return $this->parameters->get('thumbnailType', 'default'); } public function renderThumbnailImage($width, $height, $attributes = array()) { $src = $this->getThumbnailRaw(); if (empty($src)) { return ''; } $attributes['src'] = ResourceTranslator::toUrl($src); $originalThumbnailSize = FastImageSize::getSize($src); if ($originalThumbnailSize) { $attributes['width'] = $originalThumbnailSize['width']; $attributes['height'] = $originalThumbnailSize['height']; } $attributes['loading'] = 'lazy'; $attributes = Html::addExcludeLazyLoadAttributes($attributes); $sources = array(); $imagePath = ResourceTranslator::toPath($src); if (isset($imagePath[0])) { $optimizeThumbnail = $this->sliderObject->params->get('optimize-thumbnail-scale', 0); if ($optimizeThumbnail) { $optimizedThumbnailUrl = $this->sliderObject->features->optimize->optimizeThumbnail($attributes['src']); $attributes['src'] = $optimizedThumbnailUrl; $optimizedThumbnailSize = FastImageSize::getSize(ResourceTranslator::urlToResource($optimizedThumbnailUrl)); if ($optimizedThumbnailSize) { $attributes['width'] = $optimizedThumbnailSize['width']; $attributes['height'] = $optimizedThumbnailSize['height']; } } } $sources[] = Html::tag('img', $attributes, false); return HTML::tag('picture', Html::addExcludeLazyLoadAttributes(), implode('', $sources)); } }