Ejemplo n.º 1
0
/**
 * 携帯TOPメニューの順番を変更する関数
 *
 * @access  public
 * @param   string  $code
 * @param   string  $set  top, up, down, bottom
 * @return  boolean
 */
function _setOrderIndexMenuK($code, $set)
{
    global $_conf;
    if (!preg_match('/^[\\w]+$/', $code) || !preg_match('/^[\\w]+$/', $set)) {
        P2Util::pushInfoHtml('<p>p2 error: 引数が変です</p>');
        return false;
    }
    /*
    $_conf['index_menu_k'] = array(
        'recent_shinchaku', // 0.最近読んだスレの新着
        'recent',           // 1.最近読んだスレの全て
        'fav_shinchaku',    // 2.お気にスレの新着
        'fav',              // 3.お気にスレの全て
        'favita',           // 4.お気に板
        'cate',             // 5.板リスト
        'res_hist',         // 6.書込履歴 #.ログ
        'palace',           // 7.スレの殿堂
        'setting',          // 8.ログイン管理
        'editpref'          // 9.設定管理
    );
    */
    /*
    // 無効なコード
    if (!in_array($code, $_conf['index_menu_k'])) {
        return false;
    }
    */
    $menu = $_conf['index_menu_k'];
    if (false === ($menu = _getMenuKMovedIndex($menu, $code, $set))) {
        return false;
    }
    if (false === P2Util::setConfUser('index_menu_k', $menu)) {
        return false;
    }
    return true;
}
Ejemplo n.º 2
0
Archivo: post.php Proyecto: poppen/p2
/**
 * レスを書き込む or 新規スレッドを立てる
 * スレ立ての場合は、$key は空 '' でよい
 *
 * @return  boolean|string  書き込み成功なら true、失敗なら false または失敗理由文字列
 */
function _postIt($host, $bbs, $key, $post, $bbs_cgi)
{
    global $_conf, $popup, $rescount, $ttitle_en, $STYLE, $post_cache;
    list($request, $send_host, $send_port) = _buildRequestForPost($host, $bbs, $key, $post, $bbs_cgi);
    $maru_kakiko = empty($_POST['maru_kakiko']) ? 0 : 1;
    P2Util::setConfUser('maru_kakiko', $maru_kakiko);
    // 書き込みを一時的に保存
    $failed_post_file = P2Util::getFailedPostFilePath($host, $bbs, $key);
    $cont = serialize($post_cache);
    if (!DataPhp::writeDataPhp($failed_post_file, $cont, $_conf['res_write_perm'])) {
        p2die('ファイルの書き込みエラー');
    }
    // p2 sambaのチェック
    if ($p2SambaErrorMsgHtml = _getP2SambaErrorMsgHtml($host, $bbs)) {
        _showPostMsg(false, $p2SambaErrorMsgHtml, false);
        return false;
    }
    // WEBサーバへ接続
    $fp = fsockopen($send_host, $send_port, $errno, $errstr, $_conf['fsockopen_time_limit']);
    if (!$fp) {
        _showPostMsg(false, "サーバ接続エラー: {$errstr} ({$errno})<br>p2 Error: 板サーバへの接続に失敗しました", false);
        return false;
    }
    // HTTPリクエスト送信
    fwrite($fp, $request, strlen($request));
    $post_seikou = false;
    $p2cookies = _readCookieFile(_cachePathForCookieByHost($host));
    // header
    while (!feof($fp)) {
        $l = fgets($fp, 8192);
        // クッキーキタ
        if (preg_match("/Set-Cookie: (.+?)\r\n/", $l, $matches)) {
            $cgroups = explode(";", $matches[1]);
            if ($cgroups) {
                foreach ($cgroups as $v) {
                    if (preg_match("/(.+)=(.*)/", $v, $m)) {
                        $k = ltrim($m[1]);
                        if ($k != 'path') {
                            $p2cookies[$k] = $m[2];
                        }
                    }
                }
            }
            // 転送は書き込み成功と判断
        } elseif (preg_match("/^Location: /", $l, $matches)) {
            $post_seikou = true;
        }
        if ($l == "\r\n") {
            break;
        }
    }
    // クッキーをファイルに保存する
    _saveCookieFile($p2cookies, _cachePathForCookieByHost($host));
    // body
    $response = '';
    while (!feof($fp)) {
        $response .= fread($fp, 164000);
    }
    fclose($fp);
    // be.2ch.net or JBBSしたらば 文字コード変換 EUC→SJIS
    if (P2Util::isHostBe2chNet($host) || P2Util::isHostJbbsShitaraba($host)) {
        $response = mb_convert_encoding($response, 'SJIS-win', 'eucJP-win');
        //<META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
        $response = preg_replace("{(<head>.*<META http-equiv=\"Content-Type\" content=\"text/html; charset=)EUC-JP(\">.*</head>)}is", "\$1Shift_JIS\$2", $response);
    }
    $kakikonda_match = "/<title>.*(書きこみました|■ 書き込みました ■|書き込み終了 - SubAll BBS).*<\\/title>/is";
    $cookie_kakunin_match = "/<!-- 2ch_X:cookie -->|<title>■ 書き込み確認 ■<\\/title>|>書き込み確認。</";
    if (eregi("(<.+>)", $response, $matches)) {
        $response = $matches[1];
    }
    // カキコミ成功
    if (preg_match($kakikonda_match, $response, $matches) or $post_seikou) {
        // クッキーの書き込み自動保存を消去する
        if (isset($_COOKIE['post_msg'])) {
            P2Util::unsetCookie('post_msg');
            // ドメイン指定なしも入れておこ
            setcookie('post_msg', '', time() - 3600);
        }
        $reload = empty($_POST['from_read_new']);
        _showPostMsg(true, '書きこみが終わりました。', $reload);
        // 投稿失敗記録があれば削除する
        if (file_exists($failed_post_file)) {
            unlink($failed_post_file);
        }
        return true;
        //$response_ht = htmlspecialchars($response, ENT_QUOTES);
        //echo "<pre>{$response_ht}</pre>";
        // ■cookie確認表示(post再チャレンジしてね)
    } elseif (preg_match($cookie_kakunin_match, $response, $matches)) {
        $htm['more_hidden_post'] = '';
        // p2用の追加キー
        $more_hidden_keys = array('newthread', 'submit_beres', 'from_read_new', 'maru_kakiko', 'csrfid', 'k', UA::getQueryKey());
        foreach ($more_hidden_keys as $hk) {
            if (isset($_POST[$hk])) {
                $htm['more_hidden_post'] .= sprintf('<input type="hidden" name="%s" value="%s">', hs($hk), hs($_POST[$hk])) . "\n";
            }
        }
        $form_pattern = '/<form method="?POST"? action="?\\.\\.\\/test\\/(sub)?bbs\\.cgi(?:\\?guid=ON)?"?>/i';
        $myname = basename($_SERVER['SCRIPT_NAME']);
        $host_hs = hs($host);
        $popup_hs = hs($popup);
        $rescount_hs = hs($rescount);
        $ttitle_en_hs = hs($ttitle_en);
        $form_replace = <<<EOFORM
<form method="POST" action="{$myname}?guid=ON" accept-charset="{$_conf['accept_charset']}">
    <input type="hidden" name="detect_hint" value="◎◇">
    <input type="hidden" name="host" value="{$host_hs}">
    <input type="hidden" name="popup" value="{$popup_hs}">
    <input type="hidden" name="rescount" value="{$rescount_hs}">
    <input type="hidden" name="ttitle_en" value="{$ttitle_en_hs}">
    <input type="hidden" name="sub" value="\$1">
    {$htm['more_hidden_post']}
EOFORM;
        $response = preg_replace($form_pattern, $form_replace, $response);
        $h_b = explode("</head>", $response);
        // HTMLプリント
        echo $h_b[0];
        if (!$_conf['ktai']) {
            P2View::printIncludeCssHtml('style');
            P2View::printIncludeCssHtml('post');
        }
        if ($popup) {
            $mado_okisa = explode(',', $STYLE['post_pop_size']);
            $mado_okisa_x = $mado_okisa[0];
            $mado_okisa_y = $mado_okisa[1] + 200;
            echo <<<EOSCRIPT
            <script language="JavaScript">
            <!--
                resizeTo({$mado_okisa_x},{$mado_okisa_y});
            // -->
            </script>
EOSCRIPT;
        }
        echo "</head>";
        echo $h_b[1];
        //return false;
        return 'COOKIE';
        // その他はレスポンスをそのまま表示(結果はエラーとしてfalseを返す)
    } else {
        $response = ereg_replace('こちらでリロードしてください。<a href="\\.\\./[a-z]+/index\\.html"> GO! </a><br>', "", $response);
        echo $response;
        return false;
    }
}