/**
  * @return array
  */
 public function getFeed($params = [])
 {
     /** @var Page $page */
     $page = $this->grav['page'];
     /** @var Twig $twig */
     $twig = $this->grav['twig'];
     /** @var Data $config */
     $config = $this->mergeConfig($page, TRUE);
     // Autoload composer components
     require __DIR__ . '/vendor/autoload.php';
     // Set up cache settings
     $cache_config = array("storage" => "files", "default_chmod" => 0777, "fallback" => "files", "securityKey" => "auto", "htaccess" => true, "path" => __DIR__ . "/cache");
     // Init the cache engine
     $this->cache = phpFastCache("files", $cache_config);
     // Generate API url
     $url = 'https://api.instagram.com/v1/users/' . $config->get('feed_parameters.user_id') . '/media/recent/?access_token=' . $config->get('feed_parameters.access_token');
     // Get the cached results if available
     $results = $this->cache->get($url);
     // Get the results from the live API, cached version not found
     if ($results === null) {
         $results = Response::get($url);
         // Cache the results
         $this->cache->set($url, $results, InstagramPlugin::HOUR_IN_SECONDS * $config->get('feed_parameters.cache_time'));
         // Convert hours to seconds
     }
     $this->parseResponse($results);
     $this->template_vars = ['user_id' => $config->get('feed_parameters.user_id'), 'client_id' => $config->get('feed_parameters.client_id'), 'feed' => $this->feeds, 'count' => $config->get('feed_parameters.count')];
     $output = $this->grav['twig']->twig()->render($this->template_html, $this->template_vars);
     return $output;
 }
 public function fetch($refresh = false, $callback = null)
 {
     if (!$this->raw || $refresh) {
         $response = Response::get($this->repository, [], $callback);
         $this->raw = $response;
         $this->cache->save(md5($this->repository), $this->raw, $this->lifetime);
     }
     return $this->raw;
 }
Exemplo n.º 3
0
 private static function _downloadSelfupgrade($package, $tmp)
 {
     $output = Response::get($package['download'], []);
     Folder::mkdir($tmp);
     file_put_contents($tmp . DS . $package['name'], $output);
     return $tmp . DS . $package['name'];
 }
Exemplo n.º 4
0
 /**
  * @param $package
  *
  * @return string
  */
 private function download($package)
 {
     $this->tmp = CACHE_DIR . DS . 'tmp/Grav-' . uniqid();
     $output = Response::get($package['download'], [], [$this, 'progress']);
     Folder::mkdir($this->tmp);
     $this->output->write("\r");
     $this->output->write("  |- Downloading upgrade [" . $this->formatBytes($package['size']) . "]...   100%");
     $this->output->writeln('');
     file_put_contents($this->tmp . DS . $package['name'], $output);
     return $this->tmp . DS . $package['name'];
 }
 /**
  * @param $package
  *
  * @return string
  */
 private function downloadPackage($package)
 {
     $this->tmp = CACHE_DIR . DS . 'tmp/Grav-' . uniqid();
     $filename = $package->slug . basename($package->zipball_url);
     $output = Response::get($package->zipball_url, [], [$this, 'progress']);
     Folder::mkdir($this->tmp);
     $this->output->write("\r");
     $this->output->write("  |- Downloading package...   100%");
     $this->output->writeln('');
     file_put_contents($this->tmp . DS . $filename, $output);
     return $this->tmp . DS . $filename;
 }
Exemplo n.º 6
0
 private static function download($package)
 {
     $contents = Response::get($package->zipball_url, []);
     $cache_dir = self::getGrav()['locator']->findResource('cache://', true);
     $cache_dir = $cache_dir . DS . 'tmp/Grav-' . uniqid();
     Folder::mkdir($cache_dir);
     $filename = $package->slug . basename($package->zipball_url);
     file_put_contents($cache_dir . DS . $filename, $contents);
     return $cache_dir . DS . $filename;
 }
Exemplo n.º 7
0
 /**
  * Get https://getgrav.org news feed
  *
  * @return mixed
  */
 public function getFeed()
 {
     $feed_url = 'https://getgrav.org/blog.atom';
     $body = Response::get($feed_url);
     $reader = new Reader();
     $parser = $reader->getParser($feed_url, $body, 'utf-8');
     $feed = $parser->execute();
     return $feed;
 }
Exemplo n.º 8
0
 /**
  * @param Package $package
  *
  * @param string    $license
  *
  * @return string
  */
 private function downloadPackage($package, $license = null)
 {
     $tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
     $this->tmp = $tmp_dir . '/Grav-' . uniqid();
     $filename = $package->slug . basename($package->zipball_url);
     $query = '';
     if ($package->premium) {
         $query = \json_encode(array_merge($package->premium, ['slug' => $package->slug, 'filename' => $package->premium['filename'], 'license_key' => $license]));
         $query = '?d=' . base64_encode($query);
     }
     try {
         $output = Response::get($package->zipball_url . $query, [], [$this, 'progress']);
     } catch (\Exception $e) {
         $error = str_replace("\n", "\n  |  '- ", $e->getMessage());
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- Downloading package...    <red>error</red>                             ");
         $this->output->writeln("  |  '- " . $error);
         return false;
     }
     Folder::mkdir($this->tmp);
     $this->output->write("\r");
     $this->output->write("  |- Downloading package...   100%");
     $this->output->writeln('');
     file_put_contents($this->tmp . DS . $filename, $output);
     return $this->tmp . DS . $filename;
 }
Exemplo n.º 9
0
 /**
  * @param $package
  *
  * @return string
  */
 private function download($package)
 {
     $cache_dir = Grav::instance()['locator']->findResource('cache://', true);
     $this->tmp = $cache_dir . DS . 'tmp/Grav-' . uniqid();
     $output = Response::get($package['download'], [], [$this, 'progress']);
     Folder::mkdir($this->tmp);
     $this->output->write("\r");
     $this->output->write("  |- Downloading upgrade [" . $this->formatBytes($package['size']) . "]...   100%");
     $this->output->writeln('');
     file_put_contents($this->tmp . DS . $package['name'], $output);
     return $this->tmp . DS . $package['name'];
 }
 /**
  * Download the zip package via the URL
  *
  * @param $package_file
  * @param $tmp
  * @return null|string
  */
 private function downloadPackage($package_file, $tmp)
 {
     $this->output->write("  |- Downloading package...     0%");
     $package = parse_url($package_file);
     $filename = basename($package['path']);
     $output = Response::get($package_file, [], [$this, 'progress']);
     if ($output) {
         Folder::mkdir($tmp);
         $this->output->write("\r");
         $this->output->write("  |- Downloading package...   100%");
         $this->output->writeln('');
         file_put_contents($tmp . DS . $filename, $output);
         return $tmp . DS . $filename;
     }
     return null;
 }
Exemplo n.º 11
0
 /**
  * @param Package $package
  *
  * @return string
  */
 private function downloadPackage($package)
 {
     $cache_dir = Grav::instance()['locator']->findResource('cache://', true);
     $this->tmp = $cache_dir . DS . 'tmp/Grav-' . uniqid();
     $filename = $package->slug . basename($package->zipball_url);
     $output = Response::get($package->zipball_url, [], [$this, 'progress']);
     Folder::mkdir($this->tmp);
     $this->output->write("\r");
     $this->output->write("  |- Downloading package...   100%");
     $this->output->writeln('');
     file_put_contents($this->tmp . DS . $filename, $output);
     return $this->tmp . DS . $filename;
 }