From 68f5ac77ee0ca7788c7c48681ad2067de2af427b Mon Sep 17 00:00:00 2001 From: emkael Date: Mon, 16 Jan 2017 17:32:19 +0100 Subject: * new structure, for multiple providers --- providers/Provider.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 providers/Provider.php (limited to 'providers/Provider.php') diff --git a/providers/Provider.php b/providers/Provider.php new file mode 100644 index 0000000..0c3f344 --- /dev/null +++ b/providers/Provider.php @@ -0,0 +1,54 @@ +_feed = $feed; + $this->_options = $options; + } + + abstract protected function _getCachePath(); + + protected function _getCache($path) { + return file_get_contents($path); + } + + abstract protected function _fetchItems(); + + abstract protected function _spamFilter($items); + + protected function _getItems() { + $cacheFile = sprintf($this->_getCachePath(), $this->_feed); + $this->_cacheTime = file_exists($cacheFile) ? filemtime($cacheFile) : 0; + if ($this->_cacheTime > strtotime('-' . $this->_cacheTimeout)) { + return json_decode($this->_getCache($cacheFile)); + } else { + $content = $this->_fetchItems(); + file_put_contents($cacheFile, json_encode($content)); + $this->_cacheTime = time(); + return $content; + } + } + + public function get() { + $items = $this->_getItems(); + if (isset($this->_options['spamfilter'])) { + $items = $this->_spamFilter($items); + } + return $items; + } + + public function cacheTime() { + return $this->_cacheTime; + } + +} + +?> -- cgit v1.2.3