protected function parseSubImages($tag, $value, array $attr_template = null) { $offset = 0; while (($block = WebHelper::getblock($tag, $value, $offset)) !== false) { $offset = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS]; $this->data[ImageExtObject::ARRAY_IMAGES][] = $this->getImageArray($tag, $block, $attr_template); } }
<?php use at\fanninger\kirby\extension\webhelper\WebHelper; ?> <div class="<?php WebHelper::snippetAttribute($data, 'class'); ?> "> <?php WebHelper::snippetAttribute($data, 'images'); ?> </div>
protected function parseAndConvertTag($tag, $value, array $attr_template = null) { $offset = 0; while (($block = WebHelper::getblock($tag, $value, $offset)) !== false) { $content = ""; $offset = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS]; $start = $block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS]; $length = $block[WebHelper::BLOCK_ARRAY_VALUE_ENDPOS] - $block[WebHelper::BLOCK_ARRAY_VALUE_STARTPOS]; switch ($tag) { case ImageExtObject::TAG_IMAGEEXT_GALLERY: case ImageExtObject::TAG_IMAGE_GALLERY: $gallery = new ImageExtGallery($this); $gallery->parse($tag, $block, $attr_template); $gallery->optimizeOutput(); if ($this->isDebug()) { $content = $gallery->getDebug(); } else { $content = $gallery->toHTML(); } break; case ImageExtObject::TAG_IMAGEEXT: case ImageExtObject::TAG_IMAGE: $image = new ImageExtImage($this); $image->parse($tag, $block, $attr_template); $image->parseFileAttributes(); $image->optimizeOutput(); if ($this->isDebug()) { $content = $image->getDebug(); } else { $image->generate(); $content = $image->toHTML(); } break; } // Replace placholder with final content $value = substr_replace($value, $content, $start, $length); $offset = $start + strlen($content); } return $value; }
} if (strlen($data[ImageExtImage::ARRAY_ATTR][ImageExtImage::PARA_IMG_ALT]) > 0) { echo ' alt="' . $data[ImageExtImage::ARRAY_ATTR][ImageExtImage::PARA_IMG_ALT] . '"'; } if (strlen($data[ImageExtImage::ARRAY_ATTR][ImageExtImage::PARA_IMG_TITLE]) > 0) { echo ' title="' . $data[ImageExtImage::ARRAY_ATTR][ImageExtImage::PARA_IMG_TITLE] . '"'; } ?> /> <?php if (strlen($data[ImageExtImage::ARRAY_ATTR][ImageExtImage::PARA_LINK_URL]) > 0) { ?> </a> <?php } ?> <?php if (strlen(WebHelper::snippetAttribute($data, 'figure_caption')) > 0) { ?> <figcaption> <?php WebHelper::snippetAttribute($data, 'figure_caption'); ?> </figcaption> <?php } if (strlen(WebHelper::snippetAttribute($data, 'figure_caption')) > 0) { ?> </figure> <?php }
public function getDebug() { $content = print_r($this->data, true); $content = WebHelper::convert($content); $content = \Html::tag("code", $content); return \Html::tag("pre", $content); }
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; };