svnno****@sourc*****
svnno****@sourc*****
2010年 1月 1日 (金) 03:52:35 JST
Revision: 755 http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=755 Author: rsk Date: 2010-01-01 03:52:34 +0900 (Fri, 01 Jan 2010) Log Message: ----------- expack: - A Happy New Year! - rev.100101.0345. - ãã¹ãã®ç§»è»¢éæ¤åºãã§ããããã«ãªã£ãã (datãèµ°æ»ãã¦ãªãªã¸ãã«ã¨æããããã¹ããæ½åºãã) - å ¬å¼p2ããdatããã¦ã³ãã¼ãã§ããããã«ãªã£ãã -- datåå¾æ¨©éã®ãªãã¹ã¬ããã§ã¯èªåçã«ã¢ãªã¿ããæ¶è²»ã㦠権éãè³¼å ¥ããã®ã§æ³¨æãã¦ãã ããã ãã¦ã³ãã¼ãã«å¤±æããããæå³ãã大éã®ã¢ãªã¿ãã 使ã£ã¦ãã¾ã£ã¦ãèªå·±è²¬ä»»ã§ãã -- æå¹ã«ããæ¹æ³ã¯å ¬å¼p2ã使ã£ã¦ã®æ¸ãè¾¼ã¿ã¨åãã Modified Paths: -------------- p2ex/trunk/conf/conf.inc.php p2ex/trunk/lib/P2Client.php p2ex/trunk/lib/P2Util.php p2ex/trunk/lib/ThreadRead.php p2ex/trunk/lib/read_header.inc.php p2ex/trunk/lib/read_header_k.inc.php p2ex/trunk/post.php -------------- next part -------------- Modified: p2ex/trunk/conf/conf.inc.php =================================================================== --- p2ex/trunk/conf/conf.inc.php 2009-12-31 15:42:37 UTC (rev 754) +++ p2ex/trunk/conf/conf.inc.php 2009-12-31 18:52:34 UTC (rev 755) @@ -7,7 +7,7 @@ // o[Wîñ $_conf = array( 'p2version' => '1.7.29+1.8.x', // rep2Ìo[W - 'p2expack' => '091231.1900', // g£pbNÌo[W + 'p2expack' => '100101.0345', // g£pbNÌo[W 'p2name' => 'expack', // rep2̼O ); Modified: p2ex/trunk/lib/P2Client.php =================================================================== --- p2ex/trunk/lib/P2Client.php 2009-12-31 15:42:37 UTC (rev 754) +++ p2ex/trunk/lib/P2Client.php 2009-12-31 18:52:34 UTC (rev 755) @@ -260,6 +260,7 @@ // u^|Åp2ÉæèÞvNÌL³ð²×éB // ³¢êÍdatæ¾ Àª éàÌÆ·éB + // datæ¾ ÀªÈ¢êâ^|Ê Ìcª«èÈ¢êÌÍ[ÜéB $dom = new P2DOM($html); $expression = './/a[contains(@href, "' . self::SCRIPT_NAME_READ . '")' . ' and contains(@href, "&moritapodat=")]'; @@ -272,7 +273,6 @@ } // datðæ¾·éB - // datæ¾ ÀªÈ¢êâ^|Ê Ìcª«èÈ¢êÌÍ[ÜéB $getData = array( self::REQUEST_PARAMETER_HOST => (string)$host, self::REQUEST_PARAMETER_BBS => (string)$bbs, Modified: p2ex/trunk/lib/P2Util.php =================================================================== --- p2ex/trunk/lib/P2Util.php 2009-12-31 15:42:37 UTC (rev 754) +++ p2ex/trunk/lib/P2Util.php 2009-12-31 18:52:34 UTC (rev 755) @@ -1782,6 +1782,30 @@ } // }}} + // {{{ getP2Client() + + /** + * P2ClientNXÌCX^X𶬷é + * + * @param void + * @return P2Client + */ + static public function getP2Client() + { + global $_conf; + + if (!class_exists('P2Client', false)) { + require P2_LIB_DIR . '/P2Client.php'; + } + + try { + return new P2Client($_conf['p2_2ch_mail'], $_conf['p2_2ch_pass'], $_conf['cookie_dir']); + } catch (P2Exception $e) { + p2die($e->getMessage()); + } + } + + // }}} // {{{ debug() /* static public function debug() Modified: p2ex/trunk/lib/ThreadRead.php =================================================================== --- p2ex/trunk/lib/ThreadRead.php 2009-12-31 15:42:37 UTC (rev 754) +++ p2ex/trunk/lib/ThreadRead.php 2009-12-31 18:52:34 UTC (rev 755) @@ -84,6 +84,12 @@ include $_conf['sid2ch_php']; $this->_downloadDat2chMaru($uaMona, $SID2ch); + // 2ch bbspink ^|ÇÝ + } elseif (P2Util::isHost2chs($this->host) && !empty($_GET['moritapodat']) && + $_conf['p2_2ch_mail'] && $_conf['p2_2ch_pass']) + { + $this->_downloadDat2chMoritapo(); + // 2chÌßOqÉÇÝ } elseif (!empty($_GET['kakolog']) && !empty($_GET['kakoget'])) { if ($_GET['kakoget'] == 1) { @@ -110,7 +116,7 @@ * * @return mix æ¾Å«½©AXVªÈ©Á½êÍtrueðÔ· */ - private function _downloadDat2ch($from_bytes) + protected function _downloadDat2ch($from_bytes) { global $_conf, $_info_msg_ht; global $debug; @@ -245,8 +251,7 @@ // XbhªÈ¢Æ»f } else { fclose($fp); - $this->_downloadDat2chNotFound(); - return false; + return $this->_downloadDat2chNotFound(); } } else { @@ -270,8 +275,7 @@ return $this->_downloadDat2ch($from_bytes); } else { fclose($fp); - $this->_downloadDat2chNotFound(); - return false; + return $this->_downloadDat2chNotFound(); } } elseif ($code == "304") { // Not Modified @@ -288,8 +292,7 @@ } else { fclose($fp); - $this->_downloadDat2chNotFound(); - return false; + return $this->_downloadDat2chNotFound(); } } @@ -325,7 +328,7 @@ /** * 2ch DATð_E[hÅ«È©Á½Æ«ÉÄÑo³êé */ - private function _downloadDat2chNotFound() + protected function _downloadDat2chNotFound() { // 2ch, bbspink Èçread.cgiÅmF if (P2Util::isHost2chs($this->host)) { @@ -346,7 +349,7 @@ * @return bool * @see lib/login2ch.inc.php */ - private function _downloadDat2chMaru($uaMona, $SID2ch) + protected function _downloadDat2chMaru($uaMona, $SID2ch) { global $_conf; @@ -558,7 +561,7 @@ /** * IDÅÌ澪ūȩÁ½Æ«ÉÄÑo³êé */ - private function _downloadDat2chMaruNotFound() + protected function _downloadDat2chMaruNotFound() { global $_conf; @@ -567,8 +570,9 @@ $_REQUEST['relogin2ch'] = true; return $this->downloadDat(); } else { - $remarutori_ht = "<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true&relogin2ch=true\">Äæ¾ðÝé</a>"; - $this->getdat_error_msg_ht .= "<p>p2 info - IDÅÌXbhæ¾É¸sµÜµ½B[{$remarutori_ht}]</p>"; + $remarutori_ht = " [<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true&relogin2ch=true\">Äæ¾ðÝé</a>]"; + $moritori_ht = $this->_generateMoritapoDatLink(); + $this->getdat_error_msg_ht .= "<p>p2 info - IDÅÌXbhæ¾É¸sµÜµ½B{$remarutori_ht}{$moritori_ht}</p>"; $this->diedat = true; return false; } @@ -580,7 +584,7 @@ /** * 2chÌßOqÉ©çdat.gzð_E[hð·é */ - private function _downloadDat2chKako($uri, $ext) + protected function _downloadDat2chKako($uri, $ext) { global $_conf, $_info_msg_ht; @@ -735,10 +739,8 @@ /** * ßOðæ¾Å«È©Á½Æ«ÉÄÑo³êé - * - * @private */ - private function _downloadDat2chKakoNotFound($uri, $ext) + protected function _downloadDat2chKakoNotFound($uri, $ext) { global $_conf; @@ -823,11 +825,12 @@ if (preg_match($kakosoko_match, $read_response_html, $matches)) { $dat_response_status = "±ÌXbhÍßOqÉÉi[³êĢܷB"; //if (file_exists($_conf['idpw2ch_php']) || file_exists($_conf['sid2ch_php'])) { - $marutori_ht = "<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true\">IDÅp2ÉæèÞ</a>"; + $marutori_ht = " [<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true\">IDÅp2ÉæèÞ</a>]"; //} else { - // $marutori_ht = "<a href=\"login2ch.php\" target=\"subject\">IDOC</a>"; + // $marutori_ht = " [<a href=\"login2ch.php\" target=\"subject\">IDOC</a>]"; //} - $dat_response_msg = "<p>2ch info - ±ÌXbhÍßOqÉÉi[³êĢܷB [{$marutori_ht}]</p>"; + $moritori_ht = $this->_generateMoritapoDatLink(); + $dat_response_msg = "<p>2ch info - ±ÌXbhÍßOqÉÉi[³êĢܷB{$marutori_ht}{$moritori_ht}</p>"; // // <title>ª»ñÈÂorXbhȢŷBor error 3939 @@ -843,8 +846,9 @@ } elseif (preg_match($waithtml_match, $read_response_html, $matches)) { $dat_response_status = "à·! XbhÍhtml»³êéÌðÒÁÄ¢éæ¤Å·B"; - $marutori_ht = "<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true\">IDÅp2ÉæèÞ</a>"; - $dat_response_msg = "<p>2ch info - à·! XbhÍhtml»³êéÌðÒÁÄ¢éæ¤Å·B [{$marutori_ht}]</p>"; + $marutori_ht = " [<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true\">IDÅp2ÉæèÞ</a>]"; + $moritori_ht = $this->_generateMoritapoDatLink(); + $dat_response_msg = "<p>2ch info - à·! XbhÍhtml»³êéÌðÒÁÄ¢éæ¤Å·B{$marutori_ht}{$moritori_ht}</p>"; } else { if ($_GET['kakolog']) { @@ -1229,7 +1233,7 @@ /** * êÂÌXàÅÌIDo»ðZbg·é */ - private function _setIdCount() + protected function _setIdCount() { if (!$this->datlines) { return; @@ -1276,6 +1280,192 @@ } // }}} + // {{{ scanOriginalHosts() + + /** + * datð¸µÄX§ÄÌzXgóâðo·é + * + * @param void + * @return array + */ + public function scanOriginalHosts() + { + if (file_exists($this->keydat) && $dat = file_get_contents($this->keydat)) { + $bbs_re = preg_quote($this->bbs, '@'); + if (preg_match_all("@/(\\w+\\.(?:2ch\\.net|bbspink\\.com))(?:/test/read\\.cgi)?/{$bbs_re}\\b@", $dat, $matches, PREG_PATTERN_ORDER)) { + $hosts = array_unique($matches[1]); + $arKey = array_search($this->host, $hosts); + if ($arKey !== false && array_key_exists($arKey, $hosts)) { + unset($hosts[$arKey]); + } + + return $hosts; + } + } + + return array(); + } + + // }}} + // {{{ getDefaultGetDatErrorMessageHTML() + + /** + * ftHgÌdat澸sG[bZ[WHTMLðæ¾·é + * + * @param void + * @return string + */ + public function getDefaultGetDatErrorMessageHTML() + { + global $_conf; + + $diedat_msg = '<p><b>p2 info - ÂT[o©çÅVÌXbhîñðæ¾Å«Ü¹ñŵ½B</b>'; + if ($hosts = $this->scanOriginalHosts()) { + $common_q = '&bbs=' . rawurldecode($this->bbs) + . '&key=' . rawurldecode($this->key) + . '&ls=' . rawurldecode($this->ls); + $diedat_msg .= '<br>dat©ç¼ÌzXgóâðoµÜµ½B'; + foreach ($hosts as $host) { + $diedat_msg .= " [<a href=\"{$_conf['read_php']}?host={$host}{$common_q}\">{$host}</a>]"; + } + } + $diedat_msg .= '</p>'; + + return $diedat_msg; + } + + // }}} + // {{{ _generateMoritapoDatLink() + + /** + * ö®p2Å(datæ¾ ÀªÈ¢êÍ^|ðÁïµÄ)datðæ¾·é½ßÌN𶬷éB + * + * @param void + * @return string + */ + protected function _generateMoritapoDatLink() + { + global $_conf; + + if ($_conf['p2_2ch_mail'] && $_conf['p2_2ch_pass']) { + return " [<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&moritapodat=true\">^|Åp2ÉæèÞ</a>]"; + } else { + return ''; + } + } + + // }}} + // {{{ _downloadDat2chMoritapo() + + /** + * ö®p2Å(datæ¾ ÀªÈ¢êÍ^|ðÁïµÄ)datðæ¾·é + * + * @param void + * @return bool + */ + protected function _downloadDat2chMoritapo() + { + global $_conf; + + // datð_E[h + try { + $client = P2Util::getP2Client(); + $body = $client->downloadDat($this->host, $this->bbs, $this->key, $response); + // DEBUG + /* + $GLOBALS['_downloadDat2chMoritapo_response_dump'] = '<pre>' . htmlspecialchars(print_r($response, true)) . '</pre>'; + register_shutdown_function(create_function('', 'echo $GLOBALS[\'_downloadDat2chMoritapo_response_dump\'];')); + */ + } catch (P2Exception $e) { + p2die($e->getMessage()); + } + + // f[^Ø»Ì1 + if (!$body || (strpos($body, '<>') === false && strpos($body, ',') === false)) { + return $this->_downloadDat2chMoritapoNotFound(); + } + + // üsÊuðo + $posCR = strpos($body, "\r"); + $posLF = strpos($body, "\n"); + if ($posCR === false && $posLF === false) { + $pos = strlen($body); + } elseif ($posCR === false) { + $pos = $posLF; + } elseif ($posLF === false) { + $pos = $posCR; + } else { + $pos = min($posLF, $posCR); + } + + // 1sÚÌæ¾Æf[^Ø»Ì2 + $firstLine = rtrim(substr($body, 0, $pos)); + if (strpos($firstLine, '<>') !== false) { + $this->dat_type = '2ch'; + } elseif (strpos($firstLine, ',') !== false) { + $this->dat_type = '2ch_old'; + } else { + return $this->_downloadDat2chMoritapoNotFound(); + } + + // f[^Ø»Ì3 (^Cg = $ar[4]) + $ar = $this->explodeDatLine($firstLine); + if (count($ar) < 5) { + return $this->_downloadDat2chMoritapoNotFound(); + } + + // [JdatÉ«Ý + FileCtl::make_datafile($this->keydat, $_conf['dat_perm']); + if (FileCtl::file_write_contents($this->keydat, $body) === false) { + p2die('cannot write file. downloadDat2chMoritapo()'); + } + + return true; + } + + // }}} + // {{{ _downloadDat2chMoritapoNotFound() + + /** + * ^|ÅÌ澪ūȩÁ½Æ«ÉÄÑo³êé + * + * @param void + * @return bool + */ + protected function _downloadDat2chMoritapoNotFound() + { + global $_conf; + + $marutori_ht = " [<a href=\"{$_conf['read_php']}?host={$this->host}&bbs={$this->bbs}&key={$this->key}&ls={$this->ls}&maru=true\">IDÅp2ÉæèÞ</a>]"; + + if ($hosts = $this->scanOriginalHosts()) { + $hosts_ht = '<br>dat©ç¼ÌzXgóâðoµÜµ½B'; + foreach ($hosts as $host) { + $hosts_ht .= " [<a href=\"#\" onclick=\"this.parentNode.elements['host'].value='{$host}';return false;\">{$host}</a>]"; + } + } else { + $hosts_ht = ''; + } + + $this->getdat_error_msg_ht .= <<<EOF +<p>p2 info - ^|ÅÌXbhæ¾É¸sµÜµ½B{$marutori_ht}</p> +<form action="{$_conf['read_php']}" method="get"> + zXgð + <input type="text" name="host" value="{$this->host}" size="12"> + <input type="hidden" name="bbs" value="{$this->bbs}"> + <input type="hidden" name="key" value="{$this->key}"> + <input type="hidden" name="ls" value="{$this->ls}"> + ÉÏ¦Ä + <input type="submit" name="moritapodat" value="^|Åp2ÉæèñÅÝé"> + {$hosts_ht} +</form>\n +EOF; + $this->diedat = true; + + return false; + } + + // }}} } // }}} Modified: p2ex/trunk/lib/read_header.inc.php =================================================================== --- p2ex/trunk/lib/read_header.inc.php 2009-12-31 15:42:37 UTC (rev 754) +++ p2ex/trunk/lib/read_header.inc.php 2009-12-31 18:52:34 UTC (rev 755) @@ -283,7 +283,7 @@ if ($aThread->getdat_error_msg_ht) { $diedat_msg = $aThread->getdat_error_msg_ht; } else { - $diedat_msg = "<p><b>p2 info - ÂT[o©çÅVÌXbhîñðæ¾Å«Ü¹ñŵ½B</b></p>"; + $diedat_msg = $aThread->getDefaultGetDatErrorMessageHTML(); } $motothre_popup = " onmouseover=\"showHtmlPopUp('{$motothre_url}',event,{$_conf['iframe_popup_delay']})\" onmouseout=\"offHtmlPopUp()\""; Modified: p2ex/trunk/lib/read_header_k.inc.php =================================================================== --- p2ex/trunk/lib/read_header_k.inc.php 2009-12-31 15:42:37 UTC (rev 754) +++ p2ex/trunk/lib/read_header_k.inc.php 2009-12-31 18:52:34 UTC (rev 755) @@ -225,7 +225,7 @@ if ($aThread->getdat_error_msg_ht) { $diedat_msg = $aThread->getdat_error_msg_ht; } else { - $diedat_msg = "<p><b>p2 info - ÂT[o©çÅVÌXbhîñðæ¾Å«Ü¹ñŵ½B</b></p>"; + $diedat_msg = $aThread->getDefaultGetDatErrorMessageHTML(); } $motothre_ht = "<a href=\"{$motothre_url}\" target=\"_blank\">{$motothre_url}</a>"; Modified: p2ex/trunk/post.php =================================================================== --- p2ex/trunk/post.php 2009-12-31 15:42:37 UTC (rev 754) +++ p2ex/trunk/post.php 2009-12-31 18:52:34 UTC (rev 755) @@ -538,9 +538,6 @@ { global $_conf; - if (!class_exists('P2Client', false)) { - include P2_LIB_DIR . '/P2Client.php'; - } if (!is_dir($_conf['cookie_dir'])) { FileCtl::mkdir_r($_conf['cookie_dir']); } @@ -552,8 +549,9 @@ } try { - $client = new P2Client($_conf['p2_2ch_mail'], $_conf['p2_2ch_pass'], $_conf['cookie_dir']); - $posted = $client->post($host, $bbs, $key, $FROM, $mail, $MESSAGE, $beRes, $response); + $posted = P2Util::getP2Client()->post($host, $bbs, $key, + $FROM, $mail, $MESSAGE, + $beRes, $response); } catch (P2Exception $e) { p2die('ö®p2|Xg¸s', $e->getMessage()); }