getMedias() public method

public getMedias ( ) : array
return array
Beispiel #1
0
 /**
  * @see Document\Tag\TagInterface::frontend
  * @return string
  */
 public function frontend()
 {
     if (!is_array($this->options)) {
         $this->options = array();
     }
     $image = $this->getImage();
     if ($image instanceof Asset) {
         if (isset($this->options["thumbnail"]) && $this->options["thumbnail"] || $this->cropPercent) {
             // create a thumbnail first
             $autoName = false;
             $thumbConfig = $image->getThumbnailConfig($this->options["thumbnail"]);
             if (!$thumbConfig && $this->cropPercent) {
                 $thumbConfig = new Asset\Image\Thumbnail\Config();
             }
             if ($this->cropPercent) {
                 $cropConfig = array("width" => $this->cropWidth, "height" => $this->cropHeight, "y" => $this->cropTop, "x" => $this->cropLeft);
                 $thumbConfig->addItemAt(0, "cropPercent", $cropConfig);
                 // also crop media query specific configs
                 if ($thumbConfig->hasMedias()) {
                     foreach ($thumbConfig->getMedias() as $mediaName => $mediaItems) {
                         $thumbConfig->addItemAt(0, "cropPercent", $cropConfig, $mediaName);
                     }
                 }
                 $autoName = true;
             }
             if ($this->options["highResolution"] && $this->options["highResolution"] > 1) {
                 $thumbConfig->setHighResolution($this->options["highResolution"]);
             }
             // autogenerate a name for the thumbnail because it's different from the original
             if ($autoName) {
                 $hash = md5(Serialize::serialize($thumbConfig->getItems()));
                 $thumbConfig->setName($thumbConfig->getName() . "_auto_" . $hash);
             }
             $imagePath = $image->getThumbnail($thumbConfig);
         } else {
             $imagePath = $image->getFullPath();
         }
         $altText = $this->alt;
         $titleText = $this->alt;
         if (empty($titleText)) {
             if ($this->getImage()->getMetadata("title")) {
                 $titleText = $this->getImage()->getMetadata("title");
             }
         }
         if (empty($altText)) {
             if ($this->getImage()->getMetadata("alt")) {
                 $altText = $this->getImage()->getMetadata("alt");
             } else {
                 $altText = $titleText;
             }
         }
         // get copyright from asset
         if ($this->getImage()->getMetadata("copyright")) {
             if (!empty($altText)) {
                 $altText .= " | ";
             }
             if (!empty($titleText)) {
                 $titleText .= " | ";
             }
             $altText .= "© " . $this->getImage()->getMetadata("copyright");
             $titleText .= "© " . $this->getImage()->getMetadata("copyright");
         }
         $defaultAttributes = array("alt" => $altText);
         if (!empty($titleText)) {
             $defaultAttributes["title"] = $titleText;
         }
         // add attributes to image
         $allowedAttributes = array("alt", "align", "border", "height", "hspace", "ismap", "longdesc", "usemap", "vspace", "width", "class", "dir", "id", "lang", "style", "title", "xml:lang", "onmouseover", "onabort", "onclick", "ondblclick", "onmousedown", "onmousemove", "onmouseout", "onmouseup", "onkeydown", "onkeypress", "onkeyup", "itemprop", "itemscope", "itemtype", "disableWidthHeightAttributes");
         $htmlEscapeAttributes = array("alt", "align", "border", "height", "hspace", "longdesc", "usemap", "vspace", "width", "class", "dir", "id", "lang", "title");
         $customAttributes = array();
         if (array_key_exists("attributes", $this->options) && is_array($this->options["attributes"])) {
             $customAttributes = $this->options["attributes"];
         }
         $availableAttribs = array_merge($this->options, $defaultAttributes, $customAttributes);
         $attribs = [];
         $attribsRaw = [];
         foreach ($availableAttribs as $key => $value) {
             if ((is_string($value) || is_numeric($value) || is_bool($value)) && (in_array($key, $allowedAttributes) || array_key_exists($key, $customAttributes))) {
                 $attribsRaw[$key] = $value;
                 if (in_array($key, $htmlEscapeAttributes)) {
                     $value = htmlspecialchars($value);
                 }
                 $attribs[] = $key . '="' . $value . '"';
             }
         }
         if ($imagePath instanceof Asset\Image\Thumbnail) {
             // thumbnail's HTML is always generated by the thumbnail itself
             return $imagePath->getHTML($attribsRaw);
         } else {
             return '<img src="' . $imagePath . '" ' . implode(" ", $attribs) . ' />';
         }
     }
 }