public static function create($name, $url) { $db = db_connect(); $query = $db->prepare("INSERT INTO rss_channel(name, url) VALUES(?, ?);"); $query->execute(array($name, $url)); return RSSChannel::get($db->lastInsertId()); }
public function handle_get() { if (!empty($_GET['action']) and $_GET['action'] == "delete" and !empty($_GET['id'])) { $feed = RSSChannel::get($_GET['id']); if ($feed) { $feed->delete(); } $this->redirect(ROOT_URL . "admin/"); } }
$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); }