public function __construct($request) { if (!empty($_SESSION['username'])) { parent::__construct($request, "admin.php"); $this->handle_get(); $this->handle_post(); $this->context['rss_list'] = RSSChannel::list_all(); } else { header("HTTP/1.0 403 Forbidden"); exit(0); } }
$channel->save(); } function parse_rss($data) { $dom = new DomDocument(); $dom->loadXML($data); $feeds = array(); $xpath = new DOMXpath($dom); foreach ($xpath->query("/rss/channel/item") as $item) { $pub_date = $xpath->query("pubDate/text()", $item)->item(0)->wholeText; $pub_date = DateTime::createFromFormat(DateTime::RSS, $pub_date); array_push($feeds, array("title" => $xpath->query("title/text()", $item)->item(0)->wholeText, "description" => $xpath->query("description/text()", $item)->item(0)->wholeText, "link" => $xpath->query("link/text()", $item)->item(0)->wholeText, "pub_date" => $pub_date)); } return $feeds; } function fetch_items($channel) { $opts = array(); if (ENABLE_PROXY) { $opts = array("http" => array("proxy" => "tcp://" . PROXY_SERVER . ":" . PROXY_PORT, "request_fulluri" => true)); } $context = stream_context_create($opts); $data = file_get_contents($channel->get_url(), false, $context); $items = parse_rss($data); return $items; } foreach (RSSChannel::list_all() as $channel) { print "Fecthing feeds for " . $channel->get_name() . "\n"; $items = fetch_items($channel); save_items($channel, $items); }