home
api
develop
badge
wallpaper
rhaco.org
PHP library & setup framework
lingr
bugs
jaja
arbo
rhaco_1_x
arbo rev. 25
trunk/network/SvnLogger.php
sfとgooglecodeのデザイン変更に対応
68: sf.netの変更に対応
67: sf.netの変更に対応
66: google codeに2タイプ存在するので追加
55: googleのレイアウト変更に対応
32: doctestを無効にしとく
31: diffの実装
29: catの実装、load,saveの削除
27: google codeのレイアウトパターン2種類に対応
26: 全てのレイアウトが同じではない?
25: sfとgooglecodeのデザイン変更に対応
21:
15:
14:
13: Copyrightの表記修正
type = $type; $this->url = $urlOrAccount; $this->cmd = $cmd; $this->revision = ObjectUtil::anonym(' var $id = 0; var $author = null; var $date = null; var $comment = ""; var $added = array(); var $modified = array(); var $deleted = array(); function set($id,$author,$comment,$date){ $this->id = intval($id); $this->author = StringUtil::encode(trim($author)); $this->comment = StringUtil::encode(trim($comment)); $this->date = DateUtil::format($date); } function setPath($action,$file){ switch (strtolower($action)){ case "A": case "added": $this->added[] = str_replace("\n","",StringUtil::toULD($file)); break; case "M": case "modified": $this->modified[] = str_replace("\n","",StringUtil::toULD($file)); break; case "D": case "deleted": $this->deleted[] = str_replace("\n","",StringUtil::toULD($file)); } } '); } function TYPE_SHELL(){ /*** #pass */ return 0; } function TYPE_SOURCEFORGE(){ return 1; } function TYPE_GOOGLE(){ return 2; } /** * 指定のリビジョンを取得する * * @param integer $from * @param integer $to * @return array * */ function revision($from,$to=null,$order=true){ if(empty($to)) $to = $from; switch($this->type){ case SvnLogger::TYPE_SHELL(): $revisions = $this->_revisionShell($from,$to); break; case SvnLogger::TYPE_SOURCEFORGE(): $revisions = $this->_revisionSourceforge($from,$to); break; case SvnLogger::TYPE_GOOGLE(): $revisions = $this->_revisionGoogle($from,$to); break; } if(!$order) rsort($revisions); $this->revisions = $revisions; return $revisions; } /** * 取得したリビジョンをRSS出力する * * @param string $title * @param string $description * @param string $url * @param string $linkformat */ function toRss($title,$description,$url,$linkformat=""){ $feed = new Rss20(); $feed->setChannel($title,$description,$url); if(empty($linkformat)) $linkformat = $this->linkformat; foreach($this->revisions as $rev){ $item = new RssItem20(); $item->setPubDate($rev->date); $item->setAuthor($rev->author); $item->setDescription($rev->comment); $item->setTitle($rev->id); $item->setLink(sprintf($linkformat,$rev->id)); $feed->setItem($item); } $feed->output(); } /** * 最後のリビジョン番号を取得する * * @return integer */ function last(){ switch($this->type){ case SvnLogger::TYPE_SHELL(): return $this->_lastShell(); case SvnLogger::TYPE_SOURCEFORGE(): return $this->_lastSourceforge(); case SvnLogger::TYPE_GOOGLE(): return $this->_lastGoogle(); } } /** * キャッシュから取得する * * @param unknown_type $from * @param unknown_type $to * @param unknown_type $order * @return unknown */ function load($from,$to=null,$order=true){ $revisions = array(); for($i=$from;$i<=$to;$i++){ if(!Cache::isExists($this->url.$i)){ $this->revision($i); $this->save(); } $revisions[] = Cache::get($this->url.$i); } if(!$order) rsort($revisions); $this->revisions = $revisions; return $revisions; } /** * キャッシュに保存する * */ function save(){ foreach($this->revisions as $rev){ Cache::set($this->url.$rev->id, $rev); } } function _revisionSourceforge($from,$to){ $browser = new Browser(); $result = array(); $urlformat = sprintf("http://%s.svn.sourceforge.net/viewvc/%s/?view=rev&revision=%%d",$this->url,$this->url); $this->linkformat = $urlformat; for($i=$from;$i<=$to;$i++){ if(SimpleTag::setof($tag,$browser->get(sprintf($urlformat,$i)),"body")){ $result[$i] = $this->_revision($i, $tag->f("table[1].table[0].tr[1].td.value()"), $tag->f("table[1].table[0].tr[3].td.pre.value()"), preg_replace("/^(.+?)<.+$/","\\1",$tag->f("table[1].table[0].tr[2].td.value()"))); foreach(ArrayUtil::arrays($tag->f("table[1].table[1].in(tr)")) as $tr){ $result[$i]->setPath($tr->f("td[1].a.value()"), preg_replace("/^.+>/","",$tr->f("td[0].a.value()"))); } } } return $result; } function _lastSourceforge(){ $browser = new Browser(); if(SimpleTag::setof($tag,$browser->get(sprintf("http://%s.svn.sourceforge.net/viewvc/%s/?view=rev",$this->url,$this->url)),"body")){ return (int)(preg_replace("/[^\d]/","",$tag->f("table[1].h1.value()"))); } return 0; } function _revisionGoogle($from,$to){ $browser = new Browser(); $result = array(); $urlformat = sprintf("http://code.google.com/p/%s/source/detail?r=%%d",$this->url); $this->linkformat = $urlformat; for($i=$from;$i<=$to;$i++){ if(SimpleTag::setof($tag,$browser->get(sprintf($urlformat,$i)),"body")){ $div = $tag->f("div[15].table[1].tr[0]"); $result[$i] = $this->_revision($i, trim(strip_tags($div->f("td[0].table[0].tr[0].td[0].value()"))), $div->f("td[1].pre.value()"), trim(strip_tags($div->f("td[0].table[0].tr[1].td[0].span[0].param('title')"))) ); foreach($div->f("td[1].table[0].in('tr')") as $tr){ $result[$i]->setPath($tr->f("td[1].value()"),$tr->f("td[2].a.value()")); } } } return $result; } function _lastGoogle(){ $browser = new Browser(); if(SimpleTag::setof($tag,$browser->get(sprintf("http://code.google.com/p/%s/source/list",$this->url)),"body")){ return (int)(preg_replace("/[^\d]/","",$tag->f("table[4].tr[1].td[0].a.value()"))); } return 0; } function _revisionShell($from,$to){ $src = $this->_cmd(sprintf("%s log %s --xml --verbose %s",$this->cmd,sprintf("-r %d:%d ",$from,$to),$this->url)); $result = array(); $this->linkformat = $this->url; if(SimpleTag::setof($tag,$src,"log")){ foreach($tag->getIn("logentry") as $log){ $revision = $log->param("revision"); $result[$revision] = $this->_revision($revision, $log->getInValue("author"), $log->getInValue("msg"), $log->getInValue("date")); foreach($log->getIn("paths") as $paths){ foreach($paths->getIn("path") as $path){ $result[$revision]->setPath($path->param("action"),$path->getValue()); } } } } return $result; } function _lastShell(){ $src = $this->_cmd(sprintf("%s info %s",$this->cmd,$this->url)); if(preg_match("/Last Changed Rev: ([\d]+)/i",$src,$match)){ return (int)$match[1]; } return 0; } function _revision($id,$author,$comment,$date){ $obj = Variable::copy($this->revision); $obj->set($id,$author,$comment,$date); return $obj; } function _cmd($cmd){ Logger::debug($cmd); ob_start(); system($cmd); return ob_get_clean(); } } ?>