require_once dirname(__FILE__) . '/banana.inc.php';
-define('BANANA_FEED_VERSION', '0.1');
+define('BANANA_FEED_VERSION', '0.1.1');
class BananaFeed
{
*/
public $messages = array();
+ /** Last update time
+ */
+ public $lastupdate = 0;
+
+ /** Path where the feed is stored
+ */
+ public $path = null;
+
/** Create an empty feed
*/
private function __construct()
{
$this->version = BANANA_FEED_VERSION;
$this->group = Banana::$group;
- $this->description = Banana::$protocole->getDescription();
+ $this->description = trim(Banana::$protocole->getDescription());
}
/** Update the feed, using current settings of Banana
if (!Banana::$spool || Banana::$spool->group != $this->group) {
return false;
}
- if (!Banana::$spool->ids) {
+ if (empty(Banana::$spool->overview)) {
$spool_indexes = array();
} else {
- $spool_indexes = Banana::$spool->ids;
+ $spool_indexes = array_keys(Banana::$spool->overview);
sort($spool_indexes, SORT_NUMERIC);
$spool_indexes = array_slice($spool_indexes, -Banana::$feed_size, Banana::$feed_size);
- }
+ }
$feed_indexes = array_keys($this->messages);
$old = array_diff($feed_indexes, $spool_indexes);
foreach ($old as $key) {
$new = array_diff($spool_indexes, $feed_indexes);
foreach ($new as $key) {
$message =& Banana::$protocole->getMessage($key);
+ if (is_null($message)) {
+ return;
+ }
$array = array();
$array['author'] = $message->getAuthorName();
$array['date'] = $message->getHeaderValue('Date');
$array['title'] = $message->getHeaderValue('Subject');
- $array['body'] = $message->toHtml();
+ $array['body'] = $message->getFormattedBody();
$array['link'] = Banana::$page->makeUrl(array('group' => $this->group, 'artid' => $key));
if (Banana::$protocole->canSend()) {
$array['reply'] = Banana::$page->makeUrl(array('group' => $this->group, 'artid' => $key, 'action' => 'new'));
$this->messages[$key] = $array;
}
uasort($this->messages, Array('BananaFeed', 'compare'));
- $this->writeToFile();
+ $this->lastupdate = time();
+ $this->saveToFile();
}
/** Get the spool corresponding with the current settings of Banana
*/
static private function filename()
{
- $file = Banana::$spool_root . '/' . Banana::$protocole->name() . '/';
- if (!is_dir($file)) {
- mkdir($file);
- }
- return $file . Banana::$protocole->filename() . '_feed';
+ return BananaSpool::getPath('feed');
}
/** Read a feed from a cache file
/** Write a feed to a cache file
*/
- private function writeToFile()
+ private function saveToFile()
{
$file = BananaFeed::filename();
file_put_contents($file, serialize($this));
/** Merge to feeds into a new one
*/
- static public function &merge(&$feed1, &$feed2, $name, $description = null)
+ static public function &merge($feed1, $feed2, $name, $description = null)
{
if (!$feed1) {
$feed = null;
}
uasort($messages, array('BananaFeed', 'compare'));
$master->messages =& $messages;
+ $master->lastupdate = time();
return $master;
}
}
}
-// vim:set et sw=4 sts=4 ts=4 enc=utf-8:
+// vim:set et sw=4 sts=4 ts=4 fenc=utf-8:
?>