Example #1
0
 public function read() : array
 {
     $url = sprintf(self::ATOM_FORMAT, $this->user);
     $feed = FeedReader::import($url);
     $entries = Collection::create($feed)->filterChain($this->filters)->slice($this->limit)->map(function ($entry) {
         return ['title' => $entry->getTitle(), 'link' => $entry->getLink()];
     });
     return ['last_modified' => $feed->getDateModified(), 'link' => $feed->getLink(), 'links' => $entries->toArray()];
 }
Example #2
0
 /**
  * Append this collection with another.
  *
  * @param Collection $items
  * @return static
  */
 public function append(Collection $items) : self
 {
     return Collection::create(array_merge($this->items, $items->toArray()));
 }
Example #3
0
 private function marshalEntries(array $feedInfo, Console $console) : Collection
 {
     $feedUrl = $feedInfo['url'];
     $logo = $feedInfo['favicon'] ?? 'https://mwop.net/images/favicon/favicon-16x16.png';
     $siteName = $feedInfo['sitename'] ?? '';
     $siteUrl = $feedInfo['siteurl'] ?? '#';
     $filters = $feedInfo['filters'] ?? [];
     $each = $feedInfo['each'] ?? function ($item) {
     };
     $message = sprintf('    Retrieving %s... ', $feedUrl);
     $length = strlen($message);
     $console->write($message, Color::BLUE);
     try {
         $feed = preg_match('#^https?://#', $feedUrl) ? $this->getFeedFromRemoteUrl($feedUrl) : $this->getFeedFromLocalFile($feedUrl);
     } catch (\Throwable $e) {
         $this->reportException($e, $console);
         $this->writeLine('[ FAIL ]', Color::RED);
         return new Collection([]);
     }
     $entries = Collection::create($feed)->filterChain($filters)->slice(5)->each($each)->map(function ($entry) use($logo, $siteName, $siteUrl) {
         return ['title' => $entry->getTitle(), 'link' => $entry->getLink(), 'date-created' => $entry->getDateCreated(), 'favicon' => $logo, 'sitename' => $siteName, 'siteurl' => $siteUrl];
     });
     $this->reportComplete($console, $length);
     return $entries;
 }