svnno****@sourc*****
svnno****@sourc*****
2010年 1月 26日 (火) 21:06:59 JST
Revision: 812 http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=812 Author: rsk Date: 2010-01-26 21:06:59 +0900 (Tue, 26 Jan 2010) Log Message: ----------- expack: - ç»é²ãå¿ãã¦ãããã¡ã¤ã«ã追å ã Added Paths: ----------- p2ex/trunk/lib/DownloadDatInterface.php p2ex/trunk/lib/DownloadDatMachiBbs.php -------------- next part -------------- Added: p2ex/trunk/lib/DownloadDatInterface.php =================================================================== --- p2ex/trunk/lib/DownloadDatInterface.php (rev 0) +++ p2ex/trunk/lib/DownloadDatInterface.php 2010-01-26 12:06:59 UTC (rev 812) @@ -0,0 +1,34 @@ +<?php +/** + * rep2expack - dat_E[hpC^[tFCX + */ + +// {{{ DownloadDatInterface + +interface DownloadDatInterface +{ + // {{{ invoke() + + /** + * XbhÌdatð_E[hµAÛ¶·é + * + * @param ThreadRead $aThread + * @return bool + */ + static public function invoke(ThreadRead $aThread); + + // }}} +} + +// }}} + +/* + * Local Variables: + * mode: php + * coding: cp932 + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ +// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker: Added: p2ex/trunk/lib/DownloadDatMachiBbs.php =================================================================== --- p2ex/trunk/lib/DownloadDatMachiBbs.php (rev 0) +++ p2ex/trunk/lib/DownloadDatMachiBbs.php 2010-01-26 12:06:59 UTC (rev 812) @@ -0,0 +1,126 @@ +<?php +/** + * rep2expack - Ü¿BBSpdat_E[hNX + */ + +// {{{ DownloadDatMachiBbs + +/** + * Ü¿BBSÌoffraw.cgi©ç¶datðæ¾·é + * + * @link http://www.machi.to/offlaw.txt + */ +class DownloadDatMachiBbs implements DownloadDatInterface +{ + // {{{ invoke() + + /** + * XbhÌdatð_E[hµAÛ¶·é + * + * @param ThreadRead $thread + * @return bool + */ + static public function invoke(ThreadRead $thread) + { + global $_conf; + + // {{{ ù¾datÌæ¾XªK³©Ç¤©ðO̽ß`FbN + + if (file_exists($thread->keydat)) { + $dls = FileCtl::file_read_lines($thread->keydat); + if (!$dls || count($dls) != $thread->gotnum) { + // echo 'bad size!<br>'; + unlink($thread->keydat); + $thread->gotnum = 0; + } + } else { + $thread->gotnum = 0; + } + + // }}} + // {{{ offraw.cgi©çdatð_E[h + + $host = $thread->host; + $bbs = $thread->bbs; + $key = $thread->key; + + if ($thread->gotnum == 0) { + $option = ''; + $append = false; + } else { + $option = sprintf('%d-', $thread->gotnum + 1); + $append = true; + } + + // http://[SERVER]/bbs/offlaw.cgi/[BBS]/[KEY]/[OPTION]; + $url = "http://{$host}/bbs/offlaw.cgi/{$bbs}/{$key}/{$option}"; + + $tempfile = $thread->keydat . '.tmp'; + FileCtl::mkdirFor($tempfile); + if ($append) { + touch($tempfile, filemtime($thread->keydat)); + } elseif (file_exists($tempfile)) { + unlink($tempfile); + } + $response = P2Util::fileDownload($url, $tempfile); + + if ($response->isError()) { + if (304 != $response->code) { + $thread->diedat = true; + } + return false; + } + + // }}} + // {{{ _E[hµ½esð`FbNµÂÂ[JdatÉ«Ý + + $lines = file($tempfile); + unlink($tempfile); + + if ($append) { + $fp = fopen($thread->keydat, 'ab'); + } else { + $fp = fopen($thread->keydat, 'wb'); + } + if (!$fp) { + p2die("cannot write file. ({$thread->keydat})"); + } + flock($fp, LOCK_EX); + + foreach ($lines as $i => $line) { + if (substr_count($line, '<>') >= 4) { // µ§ÉÍ "=== 5" + // sªÌ "XÔ<>" ÍÛ¶µÈ¢ + fwrite($fp, substr($line, strpos($line, '<>' + 2))); + $thread->gotnum++; + } else { + $lineno = $i + 1; + P2Util::pushInfoHtml("<p>rep2 info: dat®G[: line {$lineno} of {$url}.</p>"); + break; + } + } + + flock($fp, LOCK_UN); + fclose($fp); + + // }}} + + $thread->isonline = true; + + return true; + } + + // }}} +} + +// }}} + +/* + * Local Variables: + * mode: php + * coding: cp932 + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ +// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker: