diff --git a/plugins/story-blocks/shortcodes/PullQuoteShortcode.php b/plugins/story-blocks/shortcodes/PullQuoteShortcode.php new file mode 100644 index 0000000..4401f7d --- /dev/null +++ b/plugins/story-blocks/shortcodes/PullQuoteShortcode.php @@ -0,0 +1,43 @@ +shortcode->getHandlers()->add('pull-quote', function (ShortcodeInterface $sc) { + $plugin = $this->grav['plugins']->getPlugin('story-blocks'); + $page = $plugin ? $plugin->getCurrentPage() : null; + + $imageName = $sc->getParameter('image', ''); + $alt = htmlspecialchars($sc->getParameter('alt', ''), ENT_QUOTES); + $content = trim($sc->getContent()); + $imageUrl = ($page && $imageName) ? $page->url() . '/' . $imageName : ''; + + $bgHtml = ''; + if ($imageUrl) { + $bgHtml = << + {$alt} +
+ +HTML; + } + + $innerClass = $imageUrl ? 'pull-quote__inner' : 'pull-quote__inner pull-quote__inner--no-image'; + + return << +{$bgHtml} +
+ +

{$content}

+ +
+ +HTML; + }); + } +} diff --git a/plugins/story-blocks/shortcodes/SnapGalleryShortcode.php b/plugins/story-blocks/shortcodes/SnapGalleryShortcode.php new file mode 100644 index 0000000..7e83bf1 --- /dev/null +++ b/plugins/story-blocks/shortcodes/SnapGalleryShortcode.php @@ -0,0 +1,54 @@ +shortcode->getHandlers()->add('snap-gallery', function (ShortcodeInterface $sc) { + $plugin = $this->grav['plugins']->getPlugin('story-blocks'); + $page = $plugin ? $plugin->getCurrentPage() : null; + $baseUrl = $page ? $page->url() . '/' : ''; + + $images = array_map('trim', explode(',', $sc->getParameter('images', ''))); + $captions = array_map('trim', explode(',', $sc->getParameter('captions', ''))); + $alts = array_map('trim', explode(',', $sc->getParameter('alts', ''))); + + $slidesHtml = ''; + $dotsHtml = ''; + + foreach ($images as $i => $filename) { + if (!$filename) continue; + $url = $baseUrl . $filename; + $caption = htmlspecialchars($captions[$i] ?? '', ENT_QUOTES); + $alt = htmlspecialchars($alts[$i] ?? '', ENT_QUOTES); + $eager = $i === 0 ? 'eager' : 'lazy'; + $active = $i === 0 ? ' is-active' : ''; + + $captionTag = $caption + ? '
' . $caption . '
' + : ''; + + $slidesHtml .= << + + {$alt} + {$captionTag} + +HTML; + $dotsHtml .= ''; + } + + return << +
+ {$slidesHtml} + +
+ +HTML; + }); + } +}