예제 #1
0
파일: Opml.php 프로젝트: slowmotion/Readr
 /**
  * @param Feeds $feeds
  * @return string
  */
 public function create(Feeds $feeds)
 {
     $items = $feeds->fetchAll();
     $tags = array();
     $unclassified = array();
     foreach ($items as $item) {
         $t = array_filter(explode(',', $item['tags']), 'strlen');
         if (!empty($t)) {
             foreach ($t as $tag) {
                 if (!isset($tags[$tag])) {
                     $tags[$tag] = array();
                 }
                 $tags[$tag][] = $item;
             }
         } else {
             $unclassified[] = $item;
         }
     }
     ksort($tags);
     $xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
     $xml .= '<opml version="1.0">' . PHP_EOL;
     $xml .= '<head><title>Readr subscriptions</title></head>' . PHP_EOL;
     $xml .= '<body>' . PHP_EOL;
     foreach ($tags as $tag => $items) {
         $tag = htmlspecialchars($tag);
         $xml .= sprintf('<outline text="%s">', $tag, $tag) . PHP_EOL;
         foreach ($items as $item) {
             $title = htmlspecialchars($item['title']);
             $xml .= sprintf('    <outline text="%s" title="%s" type="rss" xmlUrl="%s" htmlUrl="%s"/>', $title, $title, $item['url'], $item['link']) . PHP_EOL;
         }
         $xml .= '</outline>' . PHP_EOL;
     }
     foreach ($unclassified as $item) {
         $title = htmlspecialchars($item['title']);
         $xml .= sprintf('<outline text="%s" title="%s" type="rss" xmlUrl="%s" htmlUrl="%s"/>', $title, $title, $item['url'], $item['link']) . PHP_EOL;
     }
     $xml .= '</body>' . PHP_EOL;
     $xml .= '</opml>';
     return $xml;
 }
예제 #2
0
 /**
  * @param int $limit (default: 1000)
  * @return void
  */
 public function update($limit = 1000)
 {
     @set_time_limit(600);
     @error_reporting(E_ERROR);
     $feeds = $this->feedsModel->fetchAll($limit, 0, 'last_update ASC');
     $simplePie = new SimplePie();
     $simplePie->enable_cache(false);
     foreach ($feeds as $feed) {
         $simplePie->set_feed_url($feed['url']);
         $result = $simplePie->init();
         if ($result) {
             $items = $simplePie->get_items();
             foreach ($items as $item) {
                 if (!$item) {
                     continue;
                 }
                 $author = $item->get_author();
                 $this->entriesModel->insert($feed['id'], $item->get_title(), $item->get_content(), $author ? $author->get_name() : null, $item->get_permalink(), $item->get_date('U'));
             }
         }
         $this->feedsModel->setUpdateData($feed['id'], time(), $result ? null : $simplePie->error());
     }
 }