Initial commit

master
Nikola Forró 6 years ago
commit a7ec07fc32

@ -0,0 +1,9 @@
MIT License
Copyright (c) 2018 Nikola Forró
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,61 @@
name: LLInstagram
version: 0.1
description: Lady Lilia's Instagram feed
icon: instagram
form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin status
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
instagram:
type: section
text: Settings
underline: true
fields:
instagram.type:
type: select
size: small
label: Media type
default: images
options:
images: Images
videos: Videos
both: Both
instagram.filter:
type: text
size: small
label: Filter
placeholder: filter
instagram.count:
type: text
size: small
label: Amount of media to show
placeholder: defaults to 10
default: 10
validate:
type: number
min: 1
instagram.sort_order:
type: select
size: small
label: Sort order
default: likes
options:
likes: Likes
random: Random
newest: Newest
oldest: Oldest

@ -0,0 +1,14 @@
.instagram {
margin: 0;
display: flex;
justify-content: space-between;
flex-direction: row;
flex-wrap: wrap;
flex-flow: row wrap;
align-content: flex-end;
}
.instagram li {
display: inline;
width: 180px;
}

@ -0,0 +1,105 @@
<?php
namespace Grav\Plugin;
use Grav\Common\Config\Config;
use Grav\Common\GPM\Response;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Page\Collection;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
class LLInstagramPlugin extends Plugin
{
const API_URL = '/instagram/api/media';
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
public function onPluginsInitialized()
{
$this->enable([
'onTwigInitialized' => ['onTwigInitialized', 0],
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0],
]);
}
public function onTwigInitialized()
{
$this->grav['assets']->add('plugin://llinstagram/llinstagram.css');
$this->grav['twig']->twig->addFunction(new \Twig_SimpleFunction('instagram_feed', [$this, 'feed']));
}
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
public function feed($templateFile = 'partials/llinstagram.html.twig')
{
$feed = $this->getImages();
return $this->grav['twig']->twig()->render($templateFile, compact('feed'));
}
private function getImages()
{
$config = $this->mergeConfig($this->grav['page'], TRUE);
$type = $config->get('llinstagram.type');
$filter = $config->get('llinstagram.filter');
$count = $config->get('llinstagram.count');
$sort_order = $config->get('llinstagram.sort_order');
$params = array(
'filter' => $filter,
'page_size' => $count,
'page_number' => 0,
);
switch ($type) {
case 'images':
$params['type'] = 'GraphImage';
break;
case 'videos':
$params['type'] = 'GraphVideo';
break;
}
switch ($sort_order) {
case 'likes':
$params['sort_by'] = 'likes';
$params['sort_order'] = 'desc';
break;
case 'random':
$params['sort_order'] = 'random';
break;
case 'newest':
$params['sort_by'] = 'taken_at';
$params['sort_order'] = 'desc';
break;
case 'oldest':
$params['sort_by'] = 'taken_at';
$params['sort_order'] = 'asc';
break;
}
$baseurl = Uri::getCurrentUri()->withScheme('https')->getBaseUrl();
$url = sprintf('%s%s?%s', $baseurl, $this::API_URL, http_build_query($params));
$data = Response::get($url);
return json_decode($data);
}
}

@ -0,0 +1,2 @@
enabled: true
route: /

@ -0,0 +1,9 @@
<ul class="instagram">
{% for item in feed %}
<li>
<a href="https://www.instagram.com/p/{{ item.shortcode }}" target="_blank">
<img src="{{ item.display_url }}" alt="{{ item.caption }}">
</a>
</li>
{% endfor %}
</ul>
Loading…
Cancel
Save