Skip to content

Commit

Permalink
added slideshow for blog/site with shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnhmplr committed Aug 26, 2016
1 parent 56b370f commit 02f155c
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 4 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Pagekit\Application;
use Shw\Gallery\Events\RouteListener;
use Shw\Gallery\Content\MiniGalleryPlugin;

/*
* This array is the module definition.
Expand Down Expand Up @@ -159,7 +160,8 @@

'boot' => function ($event, $app) {
$app->subscribe(
new RouteListener
new RouteListener,
new MiniGalleryPlugin
);
},

Expand All @@ -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']);
}

]
Expand Down
43 changes: 35 additions & 8 deletions src/Content/MiniGalleryPlugin.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

namespace Pagekit\Blog\Content;
namespace Shw\Gallery\Content;

use Pagekit\Application as App;
use Pagekit\Content\Event\ContentEvent;
use Pagekit\Event\EventSubscriberInterface;
use Shw\Gallery\Model\Image;
use Shw\Gallery\Model\Gallery;

class ReadmorePlugin implements EventSubscriberInterface
class MiniGalleryPlugin implements EventSubscriberInterface
{
/**
* Content plugins callback.
Expand All @@ -14,13 +17,37 @@ class ReadmorePlugin implements EventSubscriberInterface
*/
public function onContentPlugins(ContentEvent $event)
{
$content = preg_split('/\[readmore\]/i', $event->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);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/Model/Gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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')
];
}

Expand Down
2 changes: 1 addition & 1 deletion views/galleries.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div class="uk-text-center">
<h2 class="uk-h3"><?= $gallery->title ?></h2>
<a class="uk-thumbnail uk-overlay-toggle" href="<?= $view->url('@gallery/id', ['id' => $gallery->id]) ?>">
<img class="uk-thumbnail" src="/storage/shw-gallery/thumbnails/tn_<?= $gallery->image->filename?>">
<img class="uk-thumbnail" src="/storage/shw-gallery/thumbnails/tn_<?= $gallery->image->filename ?>">
</a>
</div>
<?php endforeach; ?>
Expand Down
29 changes: 24 additions & 5 deletions views/slideshow.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<ul class="uk-slideshow" data-uk-slideshow>
{% for image in images %}
<li><img src="storage/shw-gallery/{{ image.filename }}" alt="{{ image.alt }}"></li>
{% endfor %}
</ul>
<?php $view->script('minigallery', '', ['uikit', 'uikit-slideshow']) ?>

<div class="uk-slidenav-position uk-width-large-3-4 uk-container-center"
style="width:<?= $attributes['width'] ?>; height:<?= $attributes['height'] ?>;"
data-uk-slideshow="">
<?php if ($attributes['title']) : ?>
<h3 class="uk-margin-remove"><?= $attributes['title'] ?></h3>
<?php endif ?>
<ul class="uk-slideshow">
<?php foreach ($images as $image): ?>
<li>
<img src="storage/shw-gallery/<?=$image->filename?>" alt="<?=$image->title?>">
</li>
<?php endforeach ?>
</ul>
<?php if(count($images) > 1): ?>
<a href="" class="uk-slidenav uk-slidenav-contrast uk-slidenav-previous" data-uk-slideshow-item="previous"></a>
<a href="" class="uk-slidenav uk-slidenav-contrast uk-slidenav-next" data-uk-slideshow-item="next"></a>
<?php endif ?>
<?php if ($attributes['description']) : ?>
<p class="uk-margin-remove"><?= $attributes['description'] ?></p>
<?php endif ?>
</div>

1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 02f155c

Please sign in to comment.