Exemple #1
0
 /**
  * URLからフィードを取得
  *
  * @param string $url
  * @return Atom
  */
 public function do_read($url)
 {
     $urls = func_get_args();
     $feed = null;
     if (!self::$CACHE || File::isExpiry($urls, self::$CACHE_TIME)) {
         foreach ($urls as $url) {
             if (is_string($url) && ($url = trim($url)) && !empty($url)) {
                 if (!self::$CACHE || File::isExpiry($url, self::$CACHE_TIME)) {
                     $src = Tag::xhtmlnize($this->do_get($url)->body(), "link");
                     if (Tag::setof($tag, $src, "head")) {
                         foreach ($tag->in("link") as $link) {
                             if ("alternate" == strtolower($link->inParam("rel")) && strpos(strtolower($link->inParam("type")), "application") === 0 && $url != ($link = File::absolute($url, $link->inParam("href")))) {
                                 $src = $this->do_get($link)->body();
                                 break;
                             }
                         }
                     }
                     $tmp = self::parse($src);
                     if (self::$CACHE) {
                         File::cwrite($url, $tmp);
                     }
                 } else {
                     $tmp = File::cread($url);
                 }
                 if ($feed === null) {
                     if ($this->title !== null) {
                         $tmp->title($this->title());
                     }
                     if ($this->subtitle !== null) {
                         $tmp->subtitle($this->subtitle());
                     }
                     if ($this->id !== null) {
                         $tmp->id($this->id());
                     }
                     if ($this->generator !== null) {
                         $tmp->generator($this->generator());
                     }
                     if ($this->updated !== null) {
                         $tmp->updated($this->updated());
                     }
                     $feed = $tmp;
                 } else {
                     $feed->add($tmp);
                 }
             }
         }
         if (!$feed instanceof Atom) {
             $feed = new Atom();
         }
         $feed->sort();
         if (self::$CACHE) {
             File::cwrite($urls, $feed);
         }
     } else {
         $feed = File::cread($urls);
     }
     return $feed;
 }