['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); } }