public function toHTML() { $content = ""; if ($this->data[self::ARRAY_ATTR][self::PARA_SNIPPET_IMAGE] !== false && file_exists(kirby()->roots->snippets() . '/' . $this->data[self::ARRAY_ATTR][self::PARA_SNIPPET_IMAGE] . '.php')) { $content = (string) snippet($this->data[self::ARRAY_ATTR][self::PARA_SNIPPET_IMAGE], array('data' => $this->data), true); } else { if (array_key_exists(self::ARRAY_SRCSET, $this->data) && is_array($this->data[self::ARRAY_SRCSET]) && count($this->data[self::ARRAY_SRCSET]) > 0) { // Source image exist foreach ($this->data[self::ARRAY_SRCSET] as $srcset) { $attr = array(); if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_MIMETYPE])) { $attr['type'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_MIMETYPE]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_MEDIAQUERY])) { $attr['media'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_MEDIAQUERY]; } $content .= \Html::tag("source", null, $attr); } $attr = array(); if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL])) { $attr['src'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_CLASS])) { $attr['class'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_CLASS]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT])) { $attr['alt'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE])) { $attr['title'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE]; } $content .= \Html::tag("img", null, $attr); $attr = array(); $content = \Html::tag("picture", $content, $attr); } else { // Image $attr = array(); if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL])) { $attr['src'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_OUTPUT_URL]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_CLASS])) { $attr['class'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_CLASS]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT])) { $attr['alt'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_ALT]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE])) { $attr['title'] = $this->data[self::ARRAY_ATTR][self::PARA_IMG_TITLE]; } $content = \Html::tag("img", null, $attr); } // Hyperlink if (!empty($this->data[self::ARRAY_ATTR][self::PARA_LINK_URL])) { $attr = array(); if (!empty($this->data[self::ARRAY_ATTR][self::PARA_LINK_REL])) { $attr['rel'] = $this->data[self::ARRAY_ATTR][self::PARA_LINK_REL]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_LINK_TARGET])) { $attr['target'] = $this->data[self::ARRAY_ATTR][self::PARA_LINK_TARGET]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE])) { $attr['title'] = $this->data[self::ARRAY_ATTR][self::PARA_LINK_TITLE]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_LINK_CLASS])) { $attr['class'] = $this->data[self::ARRAY_ATTR][self::PARA_LINK_CLASS]; } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_GALLERY_LINK_CLASS])) { if (!empty($attr['class'])) { $attr['class'] = $attr['class'] . " " . $this->data[self::ARRAY_ATTR][self::PARA_GALLERY_LINK_CLASS]; } else { $attr['class'] = $this->data[self::ARRAY_ATTR][self::PARA_GALLERY_LINK_CLASS]; } } if (!empty($this->data[self::ARRAY_ATTR][self::PARA_GALLERY_ID])) { $attr[$this->data[self::ARRAY_ATTR][self::PARA_GALLERY_LINK_ATTR]] = $this->data[self::ARRAY_ATTR][self::PARA_GALLERY_PREFIX] . $this->data[self::ARRAY_ATTR][self::PARA_GALLERY_ID]; } $content = \Html::a($this->data[self::ARRAY_ATTR][self::PARA_LINK_URL], $content, $attr); } // Figure if ($this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION] !== false && !empty($this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION])) { if ($this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION] === true && !empty($this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION_FIELD]) && $this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION_FIELD] !== false) { $content = WebHelper::blockFigure($content, $this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION_FIELD], $this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION_TOP], $this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CLASS]); } else { $content = WebHelper::blockFigure($content, $this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION], $this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CAPTION_TOP], $this->data[self::ARRAY_ATTR][self::PARA_FIGURE_CLASS]); } } } return $content; }
* Calculate age */ $offset = 0; $key = 'age'; while (($block = WebHelper::getblock($key, $value, $offset)) !== false) { $offset = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS]; $block_new = WebHelper::calcAge($block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES][$key]); $start = $block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS]; $length = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS] - $block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS]; $value = substr_replace($value, $block_new, $start, $length); } /* * Figure */ $offset = 0; $key = 'figure'; while (($block = WebHelper::getblock($key, $value, $offset)) !== false) { $offset = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS]; $content = $block[WebHelper::BLOCK_ARRAY_VALUE_CONTENT]; $caption = array_key_exists('caption', $block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES]) ? $block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES]['caption'] : false; $caption = empty($caption) ? false : $caption; $caption_top = array_key_exists('caption_top', $block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES]) ? $block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES]['caption_top'] : false; $caption_top = $caption_top === "false" || empty($caption_top) ? false : $caption_top; $caption_class = array_key_exists('class', $block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES]) ? $block[WebHelper::BLOCK_ARRAY_VALUE_ATTRIBUTES]['class'] : false; $block_new = WebHelper::blockFigure($content, $caption, $caption_top, $caption_class); $start = $block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS]; $length = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS] - $block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS]; $value = substr_replace($value, $block_new, $start, $length); } return $value; };