From a7ec07fc32e64a191365aef86a64429cd130613e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Thu, 6 Sep 2018 12:28:04 +0200 Subject: [PATCH] Initial commit --- LICENSE | 9 ++ blueprints.yaml | 61 +++++++++++++ llinstagram.css | 14 +++ llinstagram.php | 105 +++++++++++++++++++++++ llinstagram.yaml | 2 + templates/partials/llinstagram.html.twig | 9 ++ 6 files changed, 200 insertions(+) create mode 100644 LICENSE create mode 100644 blueprints.yaml create mode 100644 llinstagram.css create mode 100644 llinstagram.php create mode 100644 llinstagram.yaml create mode 100644 templates/partials/llinstagram.html.twig diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..13633e2 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/blueprints.yaml b/blueprints.yaml new file mode 100644 index 0000000..63fb156 --- /dev/null +++ b/blueprints.yaml @@ -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 diff --git a/llinstagram.css b/llinstagram.css new file mode 100644 index 0000000..75b1895 --- /dev/null +++ b/llinstagram.css @@ -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; +} diff --git a/llinstagram.php b/llinstagram.php new file mode 100644 index 0000000..6402e7b --- /dev/null +++ b/llinstagram.php @@ -0,0 +1,105 @@ + ['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); + } +} diff --git a/llinstagram.yaml b/llinstagram.yaml new file mode 100644 index 0000000..313edcd --- /dev/null +++ b/llinstagram.yaml @@ -0,0 +1,2 @@ +enabled: true +route: / diff --git a/templates/partials/llinstagram.html.twig b/templates/partials/llinstagram.html.twig new file mode 100644 index 0000000..ec55af0 --- /dev/null +++ b/templates/partials/llinstagram.html.twig @@ -0,0 +1,9 @@ +