[P2-php-svn] [812] expack:

Back to archive index

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ƒ“ƒ[ƒh—pƒCƒ“ƒ^[ƒtƒFƒCƒX
+ */
+
+// {{{ DownloadDatInterface
+
+interface DownloadDatInterface
+{
+    // {{{ invoke()
+
+    /**
+     * ƒXƒŒƒbƒh‚Ì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 - ‚Ü‚¿BBS—pdatƒ_ƒEƒ“ƒ[ƒhƒNƒ‰ƒX
+ */
+
+// {{{ DownloadDatMachiBbs
+
+/**
+ * ‚Ü‚¿BBS‚Ìoffraw.cgi‚©‚琶dat‚ðŽæ“¾‚·‚é
+ *
+ * @link http://www.machi.to/offlaw.txt
+ */
+class DownloadDatMachiBbs implements DownloadDatInterface
+{
+    // {{{ invoke()
+
+    /**
+     * ƒXƒŒƒbƒh‚Ìdat‚ðƒ_ƒEƒ“ƒ[ƒh‚µA•Û‘¶‚·‚é
+     *
+     * @param ThreadRead $thread
+     * @return bool
+     */
+    static public function invoke(ThreadRead $thread)
+    {
+        global $_conf;
+
+        // {{{ Šù“¾dat‚̎擾ƒŒƒX”‚ª“K³‚©‚Ç‚¤‚©‚ð”O‚Ì‚½‚߃`ƒFƒbƒN
+
+        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‚µ‚½Šes‚ðƒ`ƒFƒbƒN‚µ‚‚ƒ[ƒJƒ‹dat‚ɏ‘‚«ž‚Ý
+
+        $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:



P2-php-svn メーリングリストの案内
Back to archive index