/** * >>1をプレビューでスレッドデータが見つからなかったときに呼び出される */ public function previewOneNotFound($code = null) { global $_conf; $this->diedat = true; // 2ch, bbspink ならread.cgiで確認 if (P2Util::isHost2chs($this->host)) { $this->getdat_error_msg_ht = $this->get2chDatError($code); if (count($this->datochi_residuums)) { if ($_conf['ktai']) { $aShowThread = new ShowThreadK($this); $aShowThread->am_autong = false; } else { $aShowThread = new ShowThreadPc($this); } $this->onthefly = true; $body = "<div><span class=\"onthefly\">on the fly</span></div>\n"; $body .= "<div class=\"thread\">\n"; $res = $aShowThread->transRes($this->datochi_residuums[1], 1); $body .= is_array($res) ? $res['body'] . $res['q'] : $res; $body .= "</div>\n"; return $body; } } return false; }
/** * >>1のみをプレビューする */ public function previewOne() { global $_conf; if (!($this->host && $this->bbs && $this->key)) { return false; } // ローカルdatから取得 if (is_readable($this->keydat)) { $fd = fopen($this->keydat, "rb"); $first_line = fgets($fd, 32800); fclose($fd); // be.2ch.net ならEUC→SJIS変換 if (P2Util::isHostBe2chNet($this->host)) { $first_line = mb_convert_encoding($first_line, 'CP932', 'CP51932'); } $first_datline = rtrim($first_line); if (strpos($first_datline, '<>') !== false) { $datline_sepa = "<>"; } else { $datline_sepa = ","; $this->dat_type = "2ch_old"; } $d = explode($datline_sepa, $first_datline); $this->setTtitle($d[4]); } // ローカルdatなければオンラインから if (!$first_line) { $method = 'GET'; $url = "http://{$this->host}/{$this->bbs}/dat/{$this->key}.dat"; $purl = parse_url($url); // URL分解 if (isset($purl['query'])) { // クエリー $purl['query'] = '?' . $purl['query']; } else { $purl['query'] = ''; } // プロキシ if ($_conf['proxy_use']) { $send_host = $_conf['proxy_host']; $send_port = $_conf['proxy_port']; $send_path = $url; } else { $send_host = $purl['host']; $send_port = $purl['port']; $send_path = $purl['path'] . $purl['query']; } if (!$send_port) { $send_port = 80; } // デフォルトを80 $request = "{$method} {$send_path} HTTP/1.0\r\n"; $request .= "Host: {$purl['host']}\r\n"; $request .= "User-Agent: Monazilla/1.00 ({$_conf['p2ua']})\r\n"; // $request .= "Range: bytes={$from_bytes}-\r\n"; // Basic認証用のヘッダ if (isset($purl['user']) && isset($purl['pass'])) { $request .= "Authorization: Basic " . base64_encode($purl['user'] . ":" . $purl['pass']) . "\r\n"; } $request .= "Connection: Close\r\n"; $request .= "\r\n"; // WEBサーバへ接続 $fp = @fsockopen($send_host, $send_port, $errno, $errstr, $_conf['http_conn_timeout']); if (!$fp) { self::_pushInfoConnectFailed($url, $errno, $errstr); $this->diedat = true; return false; } stream_set_timeout($fp, $_conf['http_read_timeout'], 0); fputs($fp, $request); $start_here = false; while (!p2_stream_eof($fp, $timed_out)) { if ($start_here) { if ($code == "200") { $first_line = fgets($fp, 32800); break; } else { fclose($fp); return $this->previewOneNotFound(); } } else { $l = fgets($fp, 32800); //echo $l."<br>";// for debug if (preg_match("/^HTTP\\/1\\.\\d (\\d+) (.+)\r\n/", $l, $matches)) { // ex) HTTP/1.1 304 Not Modified $code = $matches[1]; if ($code == "200") { } else { fclose($fp); return $this->previewOneNotFound(); } } elseif (preg_match("/^Content-Length: ([0-9]+)/", $l, $matches)) { $onbytes = $matches[1]; } elseif ($l == "\r\n") { $start_here = true; } } } fclose($fp); // be.2ch.net ならEUC→SJIS変換 if (P2Util::isHostBe2chNet($this->host)) { $first_line = mb_convert_encoding($first_line, 'CP932', 'CP51932'); } $first_datline = rtrim($first_line); if (strpos($first_datline, '<>') !== false) { $datline_sepa = "<>"; } else { $datline_sepa = ","; $this->dat_type = "2ch_old"; } $d = explode($datline_sepa, $first_datline); $this->setTtitle($d[4]); $this->onthefly = true; } else { // 便宜上 if (!$this->readnum) { $this->readnum = 1; } } if ($_conf['ktai']) { $aShowThread = new ShowThreadK($this); $aShowThread->am_autong = false; } else { $aShowThread = new ShowThreadPc($this); } $body = ''; if ($this->onthefly) { $body .= "<div><span class=\"onthefly\">on the fly</span></div>\n"; } $body .= "<div class=\"thread\">\n"; $body .= $aShowThread->transRes($first_line, 1); // 1を表示 $body .= "</div>\n"; return $body; }