Example #1
0
File: Feed.php Project: hisaboh/w2t
 /**
  * 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;
 }
Example #2
0
 /**
  * ファイルから生成する
  * @param string $filename
  * @return string
  */
 public function read($filename, $template_name = null)
 {
     $this->filename($filename);
     $this->selected_template = $template_name;
     $cfilename = $this->filename . $this->selected_template;
     if (!self::$CACHE || File::isExpiry($cfilename, self::$CACHE_TIME)) {
         if (strpos($filename, "://") === false) {
             $src = $this->parse(File::read($this->filename));
         } else {
             if (empty($this->url)) {
                 $this->url = $this->filename;
             }
             $src = $this->parse(Http::read($this->filename));
         }
         if (self::$CACHE) {
             File::cwrite($cfilename, $src);
         }
     } else {
         $src = File::cread($cfilename);
     }
     $src = $this->exec($src);
     $this->call_modules("after_read_template", $src);
     return $this->replace_ptag($src);
 }