template = $tpl; foreach ($data as $key => $value) { $this->$key = $value; } } } /** An abstract feed. A feed is nothing more than a set of article. */ abstract class PlFeed implements PlIterator { public $title; public $link; public $description; public $img_link; private $article_tpl; private $iterator; public function __construct($title, $link, $desc, $img_link, $article_tpl) { $this->title = $title; $this->link = $link; $this->description = $desc; $this->img_link = $img_link; $this->article_tpl = $article_tpl; } /** Fetch the feed for the given user. */ abstract protected function fetch(PlUser &$user); public function next() { $data = $this->iterator->next(); if (!empty($data)) { return new PlFeedArticle($this->article_tpl, $data); } return null; } public function total() { return $this->iterator->total(); } public function first() { return $this->iterator->first(); } public function last() { return $this->iterator->last(); } public function run(PlPage& $page, $login, $token, $require_auth = true, $type = 'rss2') { $user = Platal::session()->tokenAuth($login, $token); if (empty($user)) { if ($require_auth) { return PL_FORBIDDEN; } else { $user = null; } } $page->assign('rss_hash', $token); pl_content_headers("application/rss+xml"); $this->iterator = $this->fetch($user); $page->coreTpl('feed.' . $type . '.tpl', NO_SKIN); $page->assign_by_ref('feed', $this); $page->run(); } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>