<?php namespace Providers; require_once('JsonFeed.php'); require_once('Item.php'); class Substack extends \Providers\JsonFeed { protected function _getFeedUrl($feed) { return sprintf('https://%s.substack.com/api/v1/posts', $feed); } protected function _getCachePath() { return '../cache/substack.%s'; } protected function _parseFeedContent($feed) { return $feed; } protected function _mapItems($content) { $items = []; foreach ($content as $item) { $itemObject = new Item(); $itemObject->ID = sprintf($this->feedUrl . $item->id); $itemObject->Title = $item->title; if ($item->subtitle) { $itemObject->Title .= ' | ' . $item->subtitle; } $itemObject->Time = $item->post_date; $itemObject->Text = $item->truncated_body_text; $itemObject->Link = $item->canonical_url; $itemObject->Author = $item->publishedBylines[0]->name; $items[] = $itemObject; } return $items; } public function title() { $cacheFile = sprintf($this->_getCachePath() . '.title', $this->_feed); if (!file_exists($cacheFile)) { $this->_fetchItems(); } if ($this->_feedJson) { $title = $this->_feedJson[0]->publishedBylines[0]->publicationUsers[0]->publication->name; file_put_contents($cacheFile, $title); return $title; } else { return file_get_contents($cacheFile); } } } ?>