Beispiel #1
0
 /**
  * Planet クロールする
  **/
 public static function __setup_crawl__()
 {
     $http_feed = new Feed();
     foreach (C(PlanetSubscription)->find_all() as $subscription) {
         Exceptions::clear();
         Log::debug(sprintf('[crawl] feed: %d (%s)', $subscription->id(), $subscription->title()));
         try {
             $feed = $http_feed->do_read($subscription->rss_url());
             $subscription->title($feed->title());
             if ($feed->is_link()) {
                 $subscription->link(self::_get_link_href($feed->link()));
             }
             $subscription->rss_url($http_feed->url());
             $subscription->save(true);
             foreach ($feed->entry() as $entry) {
                 Exceptions::clear();
                 try {
                     $planet_entry = new PlanetEntry();
                     $planet_entry->subscription_id($subscription->id());
                     $planet_entry->title(Tag::cdata($entry->title()));
                     $planet_entry->description(Text::htmldecode(Tag::cdata($entry->fm_content())));
                     $planet_entry->link($entry->first_href());
                     $planet_entry->updated($entry->published());
                     $planet_entry->save();
                 } catch (Exception $e) {
                     Log::warn($e->getMessage());
                 }
             }
         } catch (Exception $e) {
             Log::error($e);
         }
     }
 }
Beispiel #2
0
 public function diff($path, $revA, $revB)
 {
     $url = sprintf("http://%s.svn.sourceforge.net/viewvc/%s/%s?r1=%d&r2=%d&diff_format=u", $this->project, $this->project, $path, $revA, $revB);
     if (Tag::setof($tag, $this->do_get($url)->body(), "body")) {
         $result = Text::htmldecode(preg_replace("/^\\+{3} .+\n/", "", preg_replace("/^-{3} .+\n/", "", trim($tag->f("pre.value()")))));
         if ($result !== "400 Bad Request") {
             return $result;
         }
     }
     throw new Exception("undef");
 }
Beispiel #3
0
 public static function parse_search_list($response)
 {
     $results = array();
     if (Tag::setof($atom, $response, "feed")) {
         foreach ($atom->in("entry") as $entry) {
             $self = new self();
             $self->id(preg_replace("/^.+\\:([\\d]+)\$/", "\\1", $entry->f("id.value()")));
             $self->text($entry->f("title.value()"));
             $self->source(Text::htmldecode($entry->f("twitter:source.value()")));
             $self->created_at($atom->f("published.value()"));
             $user = new TwitterUser();
             $user->name(str_replace("http://twitter.com/", "", Text::htmldecode($entry->f("author.uri.value()"))));
             $user->screen_name(Text::htmldecode($entry->f("author.name.value()")));
             $user->profile_image_url(Text::htmldecode($entry->f("link[1].param(href)")));
             $self->user($user);
             $results[] = $self;
         }
     }
     return $results;
 }
Beispiel #4
0
 public function diff($path, $revA, $revB)
 {
     $url = sprintf("http://code.google.com/p/%s/source/diff?old=%d&r=%d&format=unidiff&path=%s", $this->project, $revA, $revB, $path);
     $src = $this->do_get($url)->body();
     if (Tag::setof($tag, $src, "body")) {
         $lines = "";
         $block = "";
         $fs = $ts = $fl = $tl = 0;
         $blocks = $tag->f("table[5].in(tr)");
         foreach ($blocks as $tr) {
             $from = $tr->f("th[0].value()");
             if ($from == "...") {
                 if (!empty($block)) {
                     $lines .= sprintf("@@ -%d,%d +%d,%d @@\n%s", $fs, $fl, $ts, $tl, $block);
                 }
                 $block = "";
                 $fs = $ts = $fl = $tl = 0;
             } else {
                 $to = $tr->f("th[1].value()");
                 if ($fs == 0 && !empty($from)) {
                     $fs = $from;
                 }
                 if ($ts == 0 && !empty($to)) {
                     $ts = $to;
                 }
                 if (!empty($from)) {
                     $fl++;
                 }
                 if (!empty($to)) {
                     $tl++;
                 }
                 $block .= Text::htmldecode(strip_tags($tr->f("th[2].value()") . $tr->f("td.value()")) . "\n");
             }
         }
         return $lines;
     }
     throw new Exception("undef");
 }
Beispiel #5
0
 /**
  * パラメータを取得
  *
  * @param string $name
  * @param mixed $default
  * @return string
  */
 protected final function __in_param__($name, $default = null)
 {
     $name = strtolower($name);
     $result = isset($this->param[$name]) ? $this->param[$name] : null;
     $result = $result === null ? $default : $result[1];
     return $this->cdata_value ? Text::htmldecode($result) : $result;
     /***
     			$tag = new Tag("hoge","abc");
     			$tag->add("aaa","123")->add("bbb","456");
     			eq("123",$tag->in_param("aaa","hoge"));
     			eq("123",$tag->in_param("aAa","hoge"));
     			eq("hoge",$tag->in_param("ccc","hoge"));
     		 */
 }
Beispiel #6
0
 /**
  * htmlデコードをする
  * @param string $value 対象の文字列
  * @return string
  */
 public function htmldecode($value)
 {
     return Text::htmldecode(self::cdata($value));
     /***
     			$t = new self();
     			eq("ほげほげ",$t->htmldecode("ほげほげ"));
     			eq("><ほげ& ほげ",$t->htmldecode("><ほげ& ほげ"));
     			eq("<abc />",$t->htmldecode("<![CDATA[<abc />]]>"));
     		 */
 }
Beispiel #7
0
 /**
  * htmlデコードをする
  * @param string $value
  * @return string
  */
 public static final function htmldecode($value)
 {
     return Text::htmldecode(Tag::cdata($value));
 }
Beispiel #8
0
 private function parse_form()
 {
     $tag = Tag::anyhow($this->body);
     foreach ($tag->in("form") as $key => $formtag) {
         $form = new stdClass();
         $form->name = $formtag->in_param("name", $formtag->in_param("id", $key));
         $form->action = File::absolute($this->url, $formtag->in_param("action", $this->url));
         $form->method = strtolower($formtag->in_param("method", "get"));
         $form->multiple = false;
         $form->element = array();
         foreach ($formtag->in("input") as $count => $input) {
             $obj = new stdClass();
             $obj->name = $input->in_param("name", $input->in_param("id", "input_" . $count));
             $obj->type = strtolower($input->in_param("type", "text"));
             $obj->value = Text::htmldecode($input->in_param("value"));
             $obj->selected = "selected" === strtolower($input->in_param("checked", $input->in_attr("checked")));
             $obj->multiple = false;
             $form->element[] = $obj;
         }
         foreach ($formtag->in("textarea") as $count => $input) {
             $obj = new stdClass();
             $obj->name = $input->in_param("name", $input->in_param("id", "textarea_" . $count));
             $obj->type = "textarea";
             $obj->value = Text::htmldecode($input->value());
             $obj->selected = true;
             $obj->multiple = false;
             $form->element[] = $obj;
         }
         foreach ($formtag->in("select") as $count => $input) {
             $obj = new stdClass();
             $obj->name = $input->in_param("name", $input->in_param("id", "select_" . $count));
             $obj->type = "select";
             $obj->value = array();
             $obj->selected = true;
             $obj->multiple = "multiple" == strtolower($input->param("multiple", $input->attr("multiple")));
             foreach ($input->in("option") as $count => $option) {
                 $op = new stdClass();
                 $op->value = Text::htmldecode($option->in_param("value", $option->value()));
                 $op->selected = "selected" == strtolower($option->in_param("selected", $option->in_attr("selected")));
                 $obj->value[] = $op;
             }
             $form->element[] = $obj;
         }
         $this->form[] = $form;
     }
 }
Beispiel #9
0
 protected function setText($value)
 {
     $this->text = Text::htmldecode($value);
 }