/** * DATをダウンロードする */ public function downloadDat() { global $_conf; // まちBBS if (P2Util::isHostMachiBbs($this->host)) { DownloadDatMachiBbs::invoke($this); // JBBS@したらば } elseif (P2Util::isHostJbbsShitaraba($this->host)) { if (!function_exists('shitarabaDownload')) { include P2_LIB_DIR . '/read_shitaraba.inc.php'; } shitarabaDownload($this); // 2ch系 } else { $this->getDatBytesFromLocalDat(); // $aThread->length をset // 2ch bbspink●読み if (P2Util::isHost2chs($this->host) && !empty($_GET['maru'])) { // ログインしてなければ or ログイン後、24時間以上経過していたら自動再ログイン if (!file_exists($_conf['sid2ch_php']) || !empty($_REQUEST['relogin2ch']) || filemtime($_conf['sid2ch_php']) < time() - 60 * 60 * 24) { if (!function_exists('login2ch')) { include P2_LIB_DIR . '/login2ch.inc.php'; } if (!login2ch()) { $this->getdat_error_msg_ht .= $this->get2chDatError(); $this->diedat = true; return false; } } 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']) { if (!array_key_exists('csrfid', $_GET) || $this->_getCsrfIdForMoritapoDat() != $_GET['csrfid']) { p2die('不正なリクエストです'); } $this->_downloadDat2chMoritapo(); // 2chの過去ログ倉庫読み } elseif (!empty($_GET['kakolog']) && !empty($_GET['kakoget'])) { if ($_GET['kakoget'] == 1) { $ext = '.dat.gz'; } elseif ($_GET['kakoget'] == 2) { $ext = '.dat'; } $this->_downloadDat2chKako($_GET['kakolog'], $ext); // 2ch or 2ch互換 } else { // DATを差分DLする $this->_downloadDat2ch($this->length); } } }
/** * DATをダウンロード保存する * * @access public * @return boolean */ function downloadDat() { global $_conf; // まちBBS if (P2Util::isHostMachiBbs($this->host)) { require_once P2_LIB_DIR . '/downloadDatMachiBbs.func.php'; downloadDatMachiBbs($this); // JBBS@したらば } elseif (P2Util::isHostJbbsShitaraba($this->host)) { require_once P2_LIB_DIR . '/downloadDatShitaraba.func.php'; downloadDatShitaraba($this); /* // cha2.net(→2ch互換として扱ってみる) } elseif (P2Util::isHostCha2($this->host)) { require_once P2_LIB_DIR . '/downloadDatCha2.func.php'; downloadDatCha2($this); */ // 2ch系 } else { $this->getDatBytesFromLocalDat(); // $aThread->length をset // 2ch bbspink●読み if (P2Util::isHost2chs($this->host) && !empty($_GET['maru'])) { // ログインしてなければ or ログイン後、24時間以上経過していたら自動再ログイン if (!file_exists($_conf['sid2ch_php']) || !empty($_REQUEST['relogin2ch']) or filemtime($_conf['sid2ch_php']) < time() - 60 * 60 * 24) { require_once P2_LIB_DIR . '/login2ch.func.php'; if (!login2ch()) { $this->pushDownloadDatErrorMsgHtml($this->get2chDatError()); $this->diedat = true; return false; } } $this->downloadDat2chMaru(); // 2chの過去ログ倉庫読み } elseif (!empty($_GET['kakolog']) && !empty($_GET['kakoget'])) { if ($_GET['kakoget'] == 1) { $ext = '.dat.gz'; } elseif ($_GET['kakoget'] == 2) { $ext = '.dat'; } $this->downloadDat2chKako($_GET['kakolog'], $ext); // 2ch or 2ch互換 } else { // DATを差分DLする $this->downloadDat2ch($this->length); } } return true; }
/** * リンク対象文字列の種類を判定して対応した関数/メソッドに渡して処理する * * @access private * @return string HTML */ function link_callback($s) { global $_conf; // preg_replace_callback()では名前付きでキャプチャできない? if (!isset($s['link'])) { // $s[1] => "<a...>...</a>", $s[2] => "<a..>", $s[3] => "...", $s[4] => "</a>" $s['link'] = $s[1]; $s['quote'] = $s[5]; $s['url'] = isset($s[8]) ? $s[8] : null; $s['id'] = isset($s[11]) ? $s[11] : null; } // マッチしたサブパターンに応じて分岐 // リンク if ($s['link']) { if (preg_match('{ href=(["\'])?(.+?)(?(1)\\1)(?=[ >])}i', $s[2], $m)) { $url = $m[2]; $html = $s[3]; } else { return $s[3]; } // 引用 } elseif ($s['quote']) { return $this->quote_msg_callback(array($s['quote'])); // http or ftp のURL } elseif ($s['url']) { if ($s[9] == 'ftp') { return $s[0]; } $url = preg_replace('/^t?(tps?)$/', 'ht$1', $s[9]) . '://' . $s[10]; $html = $s['url']; // ID } elseif ($s['id'] && $_conf['flex_idpopup']) { // && $_conf['flex_idlink_k'] return $this->idfilter_callback(array($s['id'], $s[12])); // その他(予備) } else { return strip_tags($s[0]); } // 以下、urlケースの処理 $url = P2Util::htmlEntityDecodeLite($url); // ime.nuを外す // (http以外のケースもあったっけ?) if (P2Util::isHostMachiBbs($this->thread->host)) { $url_tmp = preg_replace('|^([a-z]+://)machi\\.to/bbs/link\\.cgi\\?URL=|', '', $url); if ($url != $url_tmp) { $url = $url_tmp; $html = preg_replace('|^([a-z]+://)machi\\.to/bbs/link\\.cgi\\?URL=|', '', $html); } } else { $url = preg_replace('|^([a-z]+://)ime\\.nu/|', '$1', $url); } // URLをパース $purl = @parse_url($url); if (!$purl || !isset($purl['host']) || !strstr($purl['host'], '.') || $purl['host'] == '127.0.0.1') { return $html; } // URLを処理 foreach ($this->url_handlers as $handler) { if (isset($handler['this'])) { if (FALSE !== ($linkHtml = call_user_func(array($this, $handler['this']), $url, $purl, $html))) { return $linkHtml; } } elseif (isset($handler['class']) && isset($handler['method'])) { if (FALSE !== ($linkHtml = call_user_func(array($handler['class'], $handler['method']), $url, $purl, $html))) { return $linkHtml; } } elseif (isset($handler['function'])) { if (FALSE !== ($linkHtml = call_user_func($handler['function'], $url, $purl, $html))) { return $linkHtml; } } } return $html; }
/** * コンストラクタ */ protected function __construct(ThreadRead $aThread, $matome = false) { global $_conf; // スレッドオブジェクトを登録 $this->thread = $aThread; $this->str_to_link_regex = $this->_buildStrToLinkRegex(); // まとめ読みモードか否か if ($matome) { $this->_matome = ++self::$_matome_count; } else { $this->_matome = false; } $this->_url_handlers = array(); $this->_user_url_handlers = array(); $this->_ngaborn_frequent = 0; if ($_conf['ngaborn_frequent']) { if ($_conf['ngaborn_frequent_dayres'] == 0) { $this->_ngaborn_frequent = $_conf['ngaborn_frequent']; } elseif ($this->thread->setDayRes() && $this->thread->dayres < $_conf['ngaborn_frequent_dayres']) { $this->_ngaborn_frequent = $_conf['ngaborn_frequent']; } } $this->_has_ngaborns = false; $this->_aborn_nums = array(); $this->_ng_nums = array(); if (P2Util::isHostBbsPink($this->thread->host)) { $this->_redirector = self::REDIRECTOR_PINKTOWER; } elseif (P2Util::isHost2chs($this->thread->host)) { $this->_redirector = self::REDIRECTOR_IMENU; } elseif (P2Util::isHostMachiBbs($this->thread->host)) { $this->_redirector = self::REDIRECTOR_MACHIBBS; } else { $this->_redirector = self::REDIRECTOR_NONE; } $this->_quote_res_nums = array(); $this->_quote_res_nums_checked = array(); $this->_quote_res_nums_done = array(); }
/** * みみずん検索に対応しているか調べる */ public function isEnabled() { // hostがセットされてないかもしれないので // (セットされていなければ2chとみなす) if ($this->host) { // まちBBSならfalse if (P2Util::isHostMachiBbs($this->host)) { return false; } // 2chでなければfalse if (!P2Util::isHost2chs($this->host)) { return false; } } $this->enabled = true; return $this->enabled; }
P2Util::header_nocache(); header('Content-Type: text/plain; charset=UTF-8'); // }}} // {{{ 初期化 $post_param_keys = array('bbs', 'key', 'time', 'FROM', 'mail', 'MESSAGE', 'subject', 'submit'); $post_internal_keys = array('host', 'sub', 'popup', 'rescount', 'ttitle_en'); foreach ($post_param_keys as $pk) { ${$pk} = isset($_POST[$pk]) ? mb_convert_encoding($_POST[$pk], 'CP932', 'UTF-8') : ''; } foreach ($post_internal_keys as $pk) { ${$pk} = isset($_POST[$pk]) ? $_POST[$pk] : ''; } // したらばのlivedoor移転に対応。post先をlivedoorとする。 $host = P2Util::adjustHostJbbs($host); // machibbs、JBBS@したらば なら if (P2Util::isHostMachiBbs($host) or P2Util::isHostJbbsShitaraba($host)) { /* compact() と array_combine() でPOSTする値の配列を作るので、 $post_param_keys と $post_send_keys の値の順序は揃える! */ //$post_param_keys = array('bbs', 'key', 'time', 'FROM', 'mail', 'MESSAGE', 'subject', 'submit'); $post_send_keys = array('BBS', 'KEY', 'TIME', 'NAME', 'MAIL', 'MESSAGE', 'SUBJECT', 'submit'); // 2ch } else { $post_send_keys = $post_param_keys; } $post = array_combine($post_send_keys, compact($post_param_keys)); unset($post['submit']); // }}} // {{{ execute $post_backup_key = PostDataStore::getKeyForBackup($host, $bbs, $key, !empty($_REQUEST['newthread'])); PostDataStore::set($post_backup_key, $post); echo '1';
/** * 元スレURLを返す * * @access public * @param boolean $original 携帯でも2chのスレURLを返す * @return string URL */ function getMotoThread($original = false) { global $_conf; // 携帯カスタマイズ指定 if ($_conf['ktai'] && !$original && $_conf['k_motothre_external']) { $motothre_url = $this->compileMobile2chUri(); // まちBBS } elseif (P2Util::isHostMachiBbs($this->host)) { // PC if (!$_conf['ktai'] || $original) { /* $motothre_url = sprintf( 'http://%s/bbs/read.cgi?BBS=%s&KEY=%s', $this->host, rawurlencode($this->bbs), rawurlencode($this->key) ); */ $motothre_url = "http://{$this->host}/bbs/read.cgi/{$this->bbs}/{$this->key}/{$this->ls}"; // 携帯 } else { $motothre_url = sprintf('http://%s/bbs/read.cgi?IMODE=TRUE&BBS=%s&KEY=%s', $this->host, rawurlencode($this->bbs), rawurlencode($this->key)); } // まちびねっと } elseif (P2Util::isHostMachiBbsNet($this->host)) { $motothre_url = sprintf('http://%s/test/read.cgi?bbs=%s&key=%s', $this->host, rawurlencode($this->bbs), rawurlencode($this->key)); // JBBSしたらば } elseif (P2Util::isHostJbbsShitaraba($this->host)) { $preg = '{(jbbs\\.shitaraba\\.com|jbbs\\.livedoor\\.com|jbbs\\.livedoor\\.jp)}'; $host_bbs_cgi = preg_replace($preg, '$1/bbs/read.cgi', $this->host); $motothre_url = "http://{$host_bbs_cgi}/{$this->bbs}/{$this->key}/{$this->ls}"; // $motothre_url = "http://{$this->host}/bbs/read.cgi?BBS={$this->bbs}&KEY={$this->key}"; // 2ch系 } elseif (P2Util::isHost2chs($this->host)) { // PC if (!UA::isK() || UA::isIPhoneGroup() || $original) { $motothre_url = "http://{$this->host}/test/read.cgi/{$this->bbs}/{$this->key}/{$this->ls}"; // 携帯 } else { // BBS PINK if (P2Util::isHostBbsPink($this->host)) { // r.iはもう使われていない //$motothre_url = "http://{$this->host}/test/r.i/{$this->bbs}/{$this->key}/{$this->ls}"; $motothre_url = "http://speedo.ula.cc/test/r.so/{$this->host}/{$this->bbs}/{$this->key}/{$this->ls}?guid=ON"; // 2ch(c.2ch) } else { $motothre_url = $this->compileMobile2chUri(); } } // その他 } else { $motothre_url = "http://{$this->host}/test/read.cgi/{$this->bbs}/{$this->key}/{$this->ls}"; } return $motothre_url; }
if ($have_sb_footer_links) { echo "<p>"; echo $dat_soko_ht; echo $taborn_link_ht; echo $taborn_now_ht; echo $buildnewthread_ht; echo $import_dat_ht; echo "</p>"; } // スペシャルモードでなければフォーム入力補完======================== $ini_url_text = ''; if (!$aThreadList->spmode) { if (P2Util::isHostJbbsShitaraba($aThreadList->host)) { // したらば $ini_url_text = "http://{$aThreadList->host}/bbs/read.cgi?BBS={$aThreadList->bbs}&KEY="; } elseif (P2Util::isHostMachiBbs($aThreadList->host)) { // まちBBS $ini_url_text = "http://{$aThreadList->host}/bbs/read.pl?BBS={$aThreadList->bbs}&KEY="; } elseif (P2Util::isHostMachiBbsNet($aThreadList->host)) { // まちビねっと $ini_url_text = "http://{$aThreadList->host}/test/read.cgi?bbs={$aThreadList->bbs}&key="; } else { $ini_url_text = "http://{$aThreadList->host}/test/read.cgi/{$aThreadList->bbs}/"; } } //if(!$aThreadList->spmode || $aThreadList->spmode=="fav" || $aThreadList->spmode=="recent" || $aThreadList->spmode=="res_hist"){ $onclick_ht = <<<EOP var url_v=document.forms["urlform"].elements["url_text"].value; if (url_v=="" || url_v=="{$ini_url_text}") { alert("見たいスレッドのURLを入力して下さい。 例:http://pc.2ch.net/test/read.cgi/mac/1034199997/"); return false;
<th class="ti">レス</th> <th class="ti">No.</th> <th class="tl">タイトル</th> <th class="t">板</th> <th class="t">Birthday</th> <th class="ti">勢い</th> </tr> </thead> <tbody> <?php $R = true; foreach ($threads as $o => $t) { $new = ''; $turl = sprintf('%s?host=%s&bbs=%s&key=%d', $_conf['read_php'], $t->host, $t->bbs, $t->tkey); $burl = sprintf('%s?host=%s&bbs=%s&itaj_en=%s&word=%s', $_conf['subject_php'], $t->host, $t->bbs, UrlSafeBase64::encode($t->ita), $htm['query_en']); if (P2Util::isHostMachiBbs($t->host)) { $ourl = sprintf('http://%s/bbs/read.cgi/%s/%s/', $t->host, $t->bbs, $t->tkey); } else { $ourl = sprintf('http://%s/test/read.cgi/%s/%s/', $t->host, $t->bbs, $t->tkey); } $iurl = P2Util::throughIme($ourl); $aThread = new Thread(); $aThread->setThreadPathInfo($t->host, $t->bbs, $t->tkey); if ($aThread->getThreadInfoFromIdx() && $aThread->isKitoku()) { $rnum = max($t->resnum, $aThread->readnum); $nnum = max(0, $rnum - $aThread->readnum); } else { $rnum = $t->resnum; $nnum = ''; } ?>
/** * 元スレURLを返す * * @param bool $force_pc trueなら携帯モードでもPC用の元スレURLを返す * @param string $ls レス表示番号or範囲。nullならlsプロパティを使う * 掲示板によっては無視される場合もある * @return string 元スレURL */ public function getMotoThread($force_pc = false, $ls = null) { global $_conf; if ($force_pc) { $mobile = false; } elseif ($_conf['iphone']) { $mobile = false; } elseif ($_conf['ktai']) { $mobile = true; } else { $mobile = false; } if ($ls === null) { $ls = $this->ls; } // 2ch系 if (P2Util::isHost2chs($this->host)) { // PC if (!$mobile) { $motothre_url = "http://{$this->host}/test/read.cgi/{$this->bbs}/{$this->key}/{$ls}"; // 携帯 } else { if (P2Util::isHostBbsPink($this->host)) { //$motothre_url = "http://{$this->host}/test/r.i/{$this->bbs}/{$this->key}/{$ls}"; $motothre_url = "http://speedo.ula.cc/test/r.so/{$this->host}/{$this->bbs}/{$this->key}/{$ls}"; } else { $mail = rawurlencode($_conf['my_mail']); // c.2chはl指定に非対応なので、代わりにn $ls = substr($ls, 0, 1) == 'l' ? 'n' : $ls; $motothre_url = "http://c.2ch.net/test/--3!mail={$mail}/{$this->bbs}/{$this->key}/{$ls}"; } } // まちBBS } elseif (P2Util::isHostMachiBbs($this->host)) { if ($mobile) { $motothre_url = "http://{$this->host}/bbs/read.pl?IMODE=TRUE&BBS={$this->bbs}&KEY={$this->key}"; } else { $motothre_url = "http://{$this->host}/bbs/read.cgi/{$this->bbs}/{$this->key}/{$ls}"; } // まちびねっと } elseif (P2Util::isHostMachiBbsNet($this->host)) { $motothre_url = "http://{$this->host}/test/read.cgi?bbs={$this->bbs}&key={$this->key}"; if ($mobile) { $motothre_url .= '&imode=true'; } // JBBSしたらば } elseif (P2Util::isHostJbbsShitaraba($this->host)) { list($host, $category) = explode('/', P2Util::adjustHostJbbs($this->host), 2); $bbs_cgi = $mobile ? 'i.cgi' : 'read.cgi'; $motothre_url = "http://{$host}/bbs/{$bbs_cgi}/{$category}/{$this->bbs}/{$this->key}/{$ls}"; // その他 } else { $motothre_url = "http://{$this->host}/test/read.cgi/{$this->bbs}/{$this->key}/{$ls}"; } return $motothre_url; }
/** * SETTING.TXT をダウンロードして、パースして、キャッシュする * * @return boolean 実行成否 */ public function downloadSettingTxt() { global $_conf; // まちBBS・したらば は SETTING.TXT が存在しないものとする if (P2Util::isHostMachiBbs($this->_host) || P2Util::isHostJbbsShitaraba($this->_host)) { return false; } FileCtl::mkdirFor($this->_setting_txt); // 板ディレクトリが無ければ作る if (file_exists($this->_setting_srd) && file_exists($this->_setting_txt)) { // 更新しない場合は、その場で抜けてしまう if (!empty($_GET['norefresh']) || isset($_REQUEST['word'])) { return true; // キャッシュが新しい場合も抜ける } elseif ($this->isCacheFresh()) { return true; } $modified = http_date(filemtime($this->_setting_txt)); } else { $modified = false; } // DL $params = array(); $params['timeout'] = $_conf['http_conn_timeout']; $params['readTimeout'] = array($_conf['http_read_timeout'], 0); if ($_conf['proxy_use']) { $params['proxy_host'] = $_conf['proxy_host']; $params['proxy_port'] = $_conf['proxy_port']; } $req = new HTTP_Request($this->_url, $params); $modified && $req->addHeader('If-Modified-Since', $modified); $req->addHeader('User-Agent', "Monazilla/1.00 ({$_conf['p2ua']})"); $response = $req->sendRequest(); if (PEAR::isError($response)) { $error_msg = $response->getMessage(); } else { $code = $req->getResponseCode(); if ($code == 302) { // ホストの移転を追跡 $new_host = BbsMap::getCurrentHost($this->_host, $this->_bbs); if ($new_host != $this->_host) { $aNewSettingTxt = new SettingTxt($new_host, $this->_bbs); $body = $aNewSettingTxt->downloadSettingTxt(); return true; } } if (!($code == 200 || $code == 206 || $code == 304)) { //var_dump($req->getResponseHeader()); $error_msg = $code; } } // DLエラー if (isset($error_msg) && strlen($error_msg) > 0) { $url_t = P2Util::throughIme($this->_url); $info_msg_ht = "<p class=\"info-msg\">Error: {$error_msg}<br>"; $info_msg_ht .= "rep2 info: <a href=\"{$url_t}\"{$_conf['ext_win_target_at']}>{$this->_url}</a> に接続できませんでした。</p>"; P2Util::pushInfoHtml($info_msg_ht); touch($this->_setting_txt); // DL失敗した場合も touch return false; } $body = $req->getResponseBody(); // DL成功して かつ 更新されていたら保存 if ($body && $code != '304') { // したらば or be.2ch.net ならEUCをSJISに変換 if (P2Util::isHostJbbsShitaraba($this->_host) || P2Util::isHostBe2chNet($this->_host)) { $body = mb_convert_encoding($body, 'CP932', 'CP51932'); } if (FileCtl::file_write_contents($this->_setting_txt, $body) === false) { p2die('cannot write file'); } // パースしてキャッシュを保存する if (!$this->cacheParsedSettingTxt()) { return false; } } else { // touchすることで更新インターバルが効くので、しばらく再チェックされなくなる touch($this->_setting_txt); // 同時にキャッシュもtouchしないと、_setting_txtと_setting_srdで更新時間がずれ、 // 毎回ここまで処理が来る(サーバへのヘッダリクエストが飛ぶ)場合がある。 touch($this->_setting_srd); } return true; }
/** * ホストの種類を判定する * * @param string $host ホスト名 * @return string ホストの種類 */ private static function _detectHostType($host) { if (P2Util::isHostBbsPink($host)) { $type = 'bbspink'; } elseif (P2Util::isHost2chs($host)) { $type = '2channel'; } elseif (P2Util::isHostMachiBbs($host)) { $type = 'machibbs'; } elseif (P2Util::isHostJbbsShitaraba($host)) { $type = 'jbbs'; } else { $type = $host; } return $type; }
EOP; } else { $on_check_sage = ''; } // }}} // {{{ ●/Be/公式p2 書き込み チェックボックス // 2ch●書き込み if (P2Util::isHost2chs($host) and file_exists($_conf['sid2ch_php'])) { $htm['maru_post'] = '<span title="2ch●IDの使用"><input type="checkbox" id="maru" name="maru" value="1">' . '<label for="maru">●</label></span>'; } // Be if (P2Util::isHost2chs($host) and $_conf['be_2ch_code'] && $_conf['be_2ch_mail']) { $htm['beres'] = '<input type="checkbox" id="beres" name="beres" value="1"' . $hd['beres_checked'] . '>' . '<label for="beres">Beで書き込む</label>'; } // 公式p2 if ((P2Util::isHost2chs($host) || P2Util::isHostMachiBbs($host)) && $_conf['p2_2ch_mail'] && $_conf['p2_2ch_pass']) { $htm['p2res'] = '<input type="checkbox" id="p2res" name="p2res" value="1"' . $hd['p2res_checked'] . '>' . '<label for="p2res">公式p2で書き込む</label>'; } // }}} // {{{ 書き込みブロック用チェックボックス if (!$_conf['ktai']) { $htm['block_submit'] = <<<EOP <input type="checkbox" id="block_submit" onclick="switchBlockSubmit(this.checked)"><label for="block_submit">block</label> EOP; } // }}} // {{{ ソースコード補正用チェックボックス if (!$_conf['ktai']) { if ($_conf['editor_srcfix'] == 1 || $_conf['editor_srcfix'] == 2 && preg_match('/pc\\d+\\.2ch\\.net/', $host)) { $htm['src_fix'] = <<<EOP <input type="checkbox" id="fix_source" name="fix_source" value="1"><label for="fix_source">src</label>
/** * host が 信頼できる掲示板サイトなら true を返す * * @access public * @return boolean */ function isTrustedHost($host) { return P2Util::isHost2chs($host) || P2Util::isHostBbsPink($host) || P2Util::isHostMachiBbs($host) || P2Util::isHostJbbsShitaraba($host); }