/** * {@inheritdoc} */ public function parse(FeedInterface $feed, FetcherResultInterface $fetcher_result, StateInterface $state) { // Set time zone to GMT for parsing dates with strtotime(). $tz = date_default_timezone_get(); date_default_timezone_set('GMT'); // Reset item counter. $this->items_count = 0; // Get raw data. $raw = trim($fetcher_result->getRaw()); if (!strlen($raw)) { throw new EmptyFeedException(); } $data = Json::decode($raw); $result = new ParserResult(); if ($data && count($data['items']) > 0) { $this->processItems($data['items'], $result); } if ($data['pageInfo']['totalResults'] && $data['pageInfo']['resultsPerPage'] && $data['pageInfo']['totalResults'] > $data['pageInfo']['resultsPerPage']) { $number_of_pages = $data['pageInfo']['totalResults'] / $data['pageInfo']['resultsPerPage']; if ($number_of_pages > 1) { $feed_type = $feed->getType(); $fetcher_configuration = $feed_type->getFetcher()->getConfiguration(); $yt_state = ['channel_id' => $feed->getSource(), 'api_key' => $fetcher_configuration['api_key'], 'import_limit' => $fetcher_configuration['import_limit'], 'page_limit' => $fetcher_configuration['page_limit'], 'pageToken' => '']; for ($i = 0; $i <= $number_of_pages; $i++) { if (!$data) { throw new EmptyFeedException(); } if ($data['nextPageToken']) { $yt_state['pageToken'] = $data['nextPageToken']; $data = Json::decode($this->fetchInternal($feed, $yt_state)); $this->processItems($data['items'], $result); } } } } date_default_timezone_set($tz); return $result; }
/** * {@inheritdoc} */ public function buildFeedForm(array $form, FormStateInterface $form_state, FeedInterface $feed) { $form['source'] = ['#title' => $this->t('Feed URL'), '#type' => 'url', '#default_value' => $feed->getSource()]; return $form; }
/** * {@inheritdoc} */ public function buildFeedForm(array $form, FormStateInterface $form_state, FeedInterface $feed) { $form['channel_id'] = ['#title' => $this->t('Channel ID'), '#type' => 'textfield', '#default_value' => $feed->getSource()]; return $form; }
/** * {@inheritdoc} */ public function buildFeedForm(array $form, FormStateInterface $form_state, FeedInterface $feed) { $form['source'] = ['#title' => $this->t('Server file or directory path'), '#type' => 'feeds_uri', '#default_value' => $feed->getSource(), '#allowed_schemes' => $this->configuration['allowed_schemes'], '#description' => $this->t('The allowed schemes are: %schemes', ['%schemes' => implode(', ', $this->configuration['allowed_schemes'])])]; return $form; }
/** * {@inheritdoc} */ public function fetch(FeedInterface $feed, StateInterface $state) { if (is_file($feed->getSource())) { return new FetcherResult($feed->getSource()); } // File does not exist. throw new \RuntimeException(SafeMarkup::format('Resource is not a file: %source', ['%source' => $feed->getSource()])); }