From 02f155c33073680334227d1568344bcc98604eb9 Mon Sep 17 00:00:00 2001 From: stfnhmplr Date: Fri, 26 Aug 2016 22:17:37 +0200 Subject: [PATCH] added slideshow for blog/site with shortcode --- CHANGELOG.md | 3 +++ composer.json | 2 +- index.php | 6 +++-- src/Content/MiniGalleryPlugin.php | 43 +++++++++++++++++++++++++------ src/Model/Gallery.php | 6 ++++- views/galleries.php | 2 +- views/slideshow.php | 29 +++++++++++++++++---- webpack.config.js | 1 + 8 files changed, 74 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 865eafa..2a177e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.1.1 (August XX, 2016) +- add a mini slideshow with shortcode to your post or site + ## 0.1.0 (August 21, 2016) - bugfix gallery link @frontend - added back button (enable via settings) to gallery-view diff --git a/composer.json b/composer.json index 36226d9..b15d237 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "shw/gallery", "type": "pagekit-extension", - "version": "0.0.4-beta", + "version": "0.1.0-beta", "title": "Gallery", "description": "A extension to manage your pictures", "license": "MIT", diff --git a/index.php b/index.php index 8c4f066..8147c1a 100644 --- a/index.php +++ b/index.php @@ -2,6 +2,7 @@ use Pagekit\Application; use Shw\Gallery\Events\RouteListener; +use Shw\Gallery\Content\MiniGalleryPlugin; /* * This array is the module definition. @@ -159,7 +160,8 @@ 'boot' => function ($event, $app) { $app->subscribe( - new RouteListener + new RouteListener, + new MiniGalleryPlugin ); }, @@ -168,7 +170,7 @@ $scripts->register('gallery-dashboard', 'gallery:app/bundle/gallery-dashboard.js', '~dashboard'); $scripts->register('gallery-meta', 'gallery:app/bundle/gallery-meta.js', '~gallery-edit'); $scripts->register('gallery-images', 'gallery:app/bundle/gallery-images.js', '~gallery-edit'); - + //$scripts->register('minigallery', 'gallery:app/bundle/minigallery.js', ['~editor']); } ] diff --git a/src/Content/MiniGalleryPlugin.php b/src/Content/MiniGalleryPlugin.php index 515b417..0e10bc1 100644 --- a/src/Content/MiniGalleryPlugin.php +++ b/src/Content/MiniGalleryPlugin.php @@ -1,11 +1,14 @@ getContent()); + $content = $event->getContent(); + $pattern = '/\[gallery(.*?)](.*?)\[\/gallery]/'; + $pattern2 = '/(\w+?)=\"(.+?)\"/'; - if ($event['readmore'] && count($content) > 1) { - $event['post']->readmore = true; - $event->setContent($content[0]); - } else { - $event->setContent(implode('', $content)); + if(preg_match_all($pattern, $content, $matches, PREG_PATTERN_ORDER)) { + + foreach($matches[1] as $key => $match) { + + preg_match_all($pattern2, $match, $attributes, PREG_PATTERN_ORDER); + + $attributes = array_merge(array_fill_keys(['id', 'title', 'width', 'height', 'limit'], ''), + array_combine($attributes[1], $attributes[2])); + $attributes['description'] = (key_exists(0, $matches[2])) ? $matches[2][0] : null; + + $gallery_id = intval($attributes['id']); + $gallery = Gallery::find($gallery_id); + + $query = Image::query()->where(compact('gallery_id')); + + if(key_exists('limit', $attributes)) { + $query = $query->limit(intval($attributes['limit'])); + } + + if($images = $query->get()) { + $content = str_replace($matches[0][$key], App::view('gallery:views/slideshow.php', compact('images', 'attributes')), $content); + } else { + $content = str_replace($matches[0][$key], 'Images not found', $content); + } + } + + $event->setContent($content); } } diff --git a/src/Model/Gallery.php b/src/Model/Gallery.php index 77a43fe..aca7afb 100644 --- a/src/Model/Gallery.php +++ b/src/Model/Gallery.php @@ -26,6 +26,9 @@ class Gallery implements \JsonSerializable /* Gallery unpublished. */ const STATUS_UNPUBLISHED = 3; + /* Minigallery only */ + const STATUS_MINIGALLERY = 4; + /** @Column(type="integer") @Id */ public $id; @@ -76,7 +79,8 @@ public static function getStatuses() self::STATUS_PUBLISHED => __('Published'), self::STATUS_UNPUBLISHED => __('Unpublished'), self::STATUS_DRAFT => __('Draft'), - self::STATUS_PENDING_REVIEW => __('Pending Review') + self::STATUS_PENDING_REVIEW => __('Pending Review'), + self::STATUS_MINIGALLERY => __('Minigallery only') ]; } diff --git a/views/galleries.php b/views/galleries.php index 4732c32..b63e352 100644 --- a/views/galleries.php +++ b/views/galleries.php @@ -10,7 +10,7 @@

title ?>

- +
diff --git a/views/slideshow.php b/views/slideshow.php index 6a045d0..1d21276 100644 --- a/views/slideshow.php +++ b/views/slideshow.php @@ -1,5 +1,24 @@ - \ No newline at end of file +script('minigallery', '', ['uikit', 'uikit-slideshow']) ?> + +
+ +

+ + + 1): ?> + + + + +

+ +
+ diff --git a/webpack.config.js b/webpack.config.js index cc60110..fa8f625 100755 --- a/webpack.config.js +++ b/webpack.config.js @@ -9,6 +9,7 @@ module.exports = [ "link-gallery": "./app/components/link-gallery.vue", "gallery-meta": "./app/components/gallery-meta.vue", "gallery-images": "./app/components/gallery-images.vue" + }, output: { filename: "./app/bundle/[name].js"