summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--providers/Item.php16
-rw-r--r--providers/Provider.php8
-rw-r--r--providers/Twitter.php22
-rw-r--r--templates/atom.tpl14
-rw-r--r--templates/rss.tpl10
5 files changed, 53 insertions, 17 deletions
diff --git a/providers/Item.php b/providers/Item.php
new file mode 100644
index 0000000..cecbd26
--- /dev/null
+++ b/providers/Item.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Providers;
+
+class Item {
+
+ public $ID;
+ public $Title;
+ public $Link;
+ public $Time;
+ public $Text;
+ public $Author;
+
+}
+
+?>
diff --git a/providers/Provider.php b/providers/Provider.php
index 02031ad..2e14d2b 100644
--- a/providers/Provider.php
+++ b/providers/Provider.php
@@ -24,16 +24,18 @@ abstract class Provider {
abstract protected function _spamFilter($items);
+ abstract protected function _mapItems($content);
+
abstract protected function _sortContent($content);
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));
+ return unserialize($this->_getCache($cacheFile));
} else {
$content = $this->_fetchItems();
- file_put_contents($cacheFile, json_encode($content));
+ file_put_contents($cacheFile, serialize($content));
$this->_cacheTime = time();
return $content;
}
@@ -44,7 +46,7 @@ abstract class Provider {
if (isset($this->_options['spamfilter'])) {
$items = $this->_spamFilter($items);
}
- return $this->_sortContent($items);
+ return $this->_sortContent($this->_mapItems($items));
}
public function cacheTime() {
diff --git a/providers/Twitter.php b/providers/Twitter.php
index e9b98e1..704420e 100644
--- a/providers/Twitter.php
+++ b/providers/Twitter.php
@@ -3,6 +3,7 @@
namespace Providers;
require_once('Provider.php');
+require_once('Item.php');
require_once('../lib/codebird-php/src/codebird.php');
@@ -19,7 +20,7 @@ class Twitter extends \Providers\Provider {
}
protected function _getCachePath() {
- return '../cache/twitter.%s.json';
+ return '../cache/twitter.%s';
}
protected function _fetchItems() {
@@ -111,8 +112,25 @@ class Twitter extends \Providers\Provider {
return $content;
}
+ protected function _mapItems($content) {
+ $items = [];
+ foreach ($content as $i) {
+ $item = new Item();
+ $item->ID = $i->id_str;
+ $item->Title = $i->text;
+ $item->Link = sprintf('https://twitter.com/%s/status%s', $this->_feed, $i->id_str);
+ $item->Time = $i->created_at;
+ $item->Text = $i->text;
+ if (isset($i->user)) {
+ $item->Author = $i->user->screen_name;
+ }
+ $items[] = $item;
+ }
+ return $items;
+ }
+
protected function _sortContent($content) {
- usort($content, function($c1, $c2) { return strcmp($c2->id_str, $c1->id_str); });
+ usort($content, function($c1, $c2) { return strcmp($c2->ID, $c1->ID); });
return $content;
}
diff --git a/templates/atom.tpl b/templates/atom.tpl
index df4a762..ea8f357 100644
--- a/templates/atom.tpl
+++ b/templates/atom.tpl
@@ -6,14 +6,14 @@
<updated>{$cacheTime|date_format:"c"}</updated>
{foreach from=$content item=item}
<entry>
- <title>{$item->text|escape}</title>
- <link href="https://twitter.com/{$user}/status/{$item->id_str}" />
- <id>http://emkael.info/tulz/twitterRSS/{$item->user->id_str}/{$item->id_str}</id>
- <updated>{$item->created_at|date_format:"c"}</updated>
- <summary><![CDATA[ {$item->text|escape} ]]></summary>
- {if isset($item->user)}
+ <title>{$item->Title|escape}</title>
+ <link href="{$item->Link}" />
+ <id>{$feedID}/{$item->ID}</id>
+ <updated>{$item->Time|date_format:"c"}</updated>
+ <summary><![CDATA[ {$item->Text|escape} ]]></summary>
+ {if isset($item->Author)}
<author>
- <name>{$item->user->screen_name}</name>
+ <name>{$item->Author}</name>
</author>
{/if}
</entry>
diff --git a/templates/rss.tpl b/templates/rss.tpl
index 03ea30b..a0be07e 100644
--- a/templates/rss.tpl
+++ b/templates/rss.tpl
@@ -6,11 +6,11 @@
<lastBuildDate>{$cacheTime|date_format:"D, d M Y H:i:s O"}</lastBuildDate>
{foreach from=$content item=item}
<item>
- <title>{$item->text|escape}</title>
- <link>https://twitter.com/{$user}/status/{$item->id_str}</link>
- <guid>{$feedID}/{$item->id_str}</guid>
- <description><![CDATA[ {$item->text|escape} ]]></description>
- <pubDate>{$item->created_at|date_format:"D, d M Y H:i:s O"}</pubDate>
+ <title>{$item->Title|escape}</title>
+ <link>{$item->Link}</link>
+ <guid>{$feedID}/{$item->ID}</guid>
+ <description><![CDATA[ {$item->Text|escape} ]]></description>
+ <pubDate>{$item->Time|date_format:"D, d M Y H:i:s O"}</pubDate>
</item>
{/foreach}
</channel>