public function update() { $feed = new SimplePie(); $feed->set_feed_url('http://api.twitter.com/1/statuses/user_timeline.atom?screen_name=' . $this->user); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $title = substr($item->get_title(), strlen($this->user) + 2); $title = sprintf('<blockquote>%s</blockquote>', $title); $data = array( 'id' => $item->get_id(), 'title' => Twitter_Autolink::create($title) ->setTarget(false) ->setExternal(false) ->addLinks(), 'content' => '', 'source' => 'twitter', 'timestamp' => $item->get_date('U') ); Murray_Entry::create($data); } }
public function update() { $feed = new SimplePie(); $feed->set_feed_url('https://github.com/' . $this->user . '.atom'); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $id = $item->get_id(); $title = substr($item->get_title(), strlen($this->user) + 1); $title = sprintf('<a href="%s">%s</a>', $item->get_permalink(), $title); $data = array( 'id' => $id, 'title' => $title, 'content' => $item->get_content(), 'source' => 'github', 'timestamp' => $item->get_date('U') ); /*$type = substr($id, 20, strpos($id, '/')); switch ($type) { case 'PushEvent': case 'IssueCommentEvent': case 'PullRequestEvent': case 'IssuesEvent': default: // no-op, standard stuff will work fine break; }*/ Murray_Entry::create($data); } }
/** * Create a new entry * * @param array $data * @return Murray_Entry */ public static function create($data) { $stmt = Murray::$db->prepare('REPLACE INTO entries (id, title, content, source, timestamp) VALUES(:id, :title, :content, :source, :timestamp)'); $stmt->bindValue(':id', $data['id']); $stmt->bindValue(':title', $data['title']); $stmt->bindValue(':content', $data['content']); $stmt->bindValue(':source', $data['source']); $stmt->bindValue(':timestamp', $data['timestamp']); $stmt->execute(); //var_dump($stmt->errorInfo()); return Murray_Entry::get((int) Murray::$db->lastInsertId()); }
protected function update_from_feed($url, $title_format, $title_start = 0) { $feed = new SimplePie(); $feed->set_feed_url($url); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $title = substr($item->get_title(), $title_start); $title = sprintf($title_format, $item->get_permalink(), $title); $data = array( 'id' => $item->get_id(), 'title' => $title, 'content' => '', 'source' => 'reddit', 'timestamp' => $item->get_date('U') ); Murray_Entry::create($data); } }
public function update() { $feed = new SimplePie(); $feed->set_feed_url('http://ws.audioscrobbler.com/1.0/user/' . $this->user . '/recenttracks.rss'); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $title = sprintf('listened to <a href="%s">%s</a>', $item->get_permalink(), $item->get_title()); $data = array( 'id' => $item->get_id(), 'title' => $title, 'content' => '', 'source' => 'lastfm', 'timestamp' => $item->get_date('U') ); Murray_Entry::create($data); } }
<?php include(__DIR__ . '/library/Murray.php'); if (isset($_GET['update'])) { set_time_limit(0); Murray_Sources::update(); die(); } $entries = Murray_Entry::get_all(); include(Murray::$path . '/views/index.php');