コード例 #1
0
ファイル: setFav.func.php プロジェクト: poppen/p2
/**
 * お気にスレをセットする関数
 *
 * $setfav は、'0'(解除), '1'(追加), 'top', 'up', 'down', 'bottom'
 *
 * @access  public
 * @return  boolean
 */
function setFav($host, $bbs, $key, $setfav)
{
    global $_conf;
    if (P2Validate::host($host) || P2Validate::bbs($bbs) || P2Validate::key($key)) {
        return false;
    }
    // スレッド.idx 記録
    $data = _setFavToKeyIdx($host, $bbs, $key, $setfav);
    $newlines = array();
    $before_line_num = 0;
    if (false === FileCtl::make_datafile($_conf['favlist_file'], $_conf['favlist_perm'])) {
        return false;
    }
    if (false === ($favlines = file($_conf['favlist_file']))) {
        return false;
    }
    // 最初に重複要素を削除しておく
    if (!empty($favlines)) {
        $i = -1;
        foreach ($favlines as $line) {
            $i++;
            $line = rtrim($line);
            $lar = explode('<>', $line);
            // 重複回避
            if ($lar[1] == $key && $lar[11] == $bbs) {
                $before_line_num = $i;
                // 移動前の行番号をセット
                continue;
                // keyのないものは不正データなのでスキップ
            } elseif (!$lar[1]) {
                continue;
            } elseif (P2Validate::host($lar[10]) || P2Validate::bbs($lar[11]) || P2Validate::key($lar[1])) {
                continue;
            } else {
                $newlines[] = $line;
            }
        }
    }
    if (!empty($GLOBALS['brazil'])) {
        //$newlines = _removeLargeFavlistData($newlines);
    }
    // 記録データ設定
    if ($setfav) {
        $newdata = implode('<>', array(geti($data[0]), $key, geti($data[2]), geti($data[3]), geti($data[4]), geti($data[5]), 1, geti($data[7]), geti($data[8]), geti($data[9]), $host, $bbs));
        require_once P2_LIB_DIR . '/getSetPosLines.func.php';
        $rec_lines = getSetPosLines($newlines, $newdata, $before_line_num, $setfav);
    } else {
        $rec_lines = $newlines;
    }
    if (false === file_put_contents($_conf['favlist_file'], $rec_lines ? implode("\n", $rec_lines) . "\n" : '', LOCK_EX)) {
        trigger_error(sprintf('file_put_contents(%s)', $_conf['favlist_file']), E_USER_WARNING);
        return false;
    }
    // お気にスレ共有
    _setFavRank($host, $bbs, $key, $setfav, geti($data[0]));
    return true;
}
コード例 #2
0
ファイル: setPalace.func.php プロジェクト: poppen/p2
/**
 * スレを殿堂入りにセットする関数
 *
 * $set は、0(解除), 1(追加), top, up, down, bottom
 *
 * @access  public
 * @return  boolean
 */
function setPalace($host, $bbs, $key, $set)
{
    global $_conf;
    $idxfile = P2Util::getKeyIdxFilePath($host, $bbs, $key);
    // 既に key.idx データがあるなら読み込む
    if (file_exists($idxfile) and $lines = file($idxfile)) {
        $l = rtrim($lines[0]);
        $data = explode('<>', $l);
    }
    if (false === FileCtl::make_datafile($_conf['palace_file'], $_conf['palace_perm'])) {
        return false;
    }
    if (false === ($pallines = file($_conf['palace_file']))) {
        return false;
    }
    $newlines = array();
    $before_line_num = 0;
    // {{{ 最初に重複要素を削除しておく
    if (!empty($pallines)) {
        $i = -1;
        foreach ($pallines as $l) {
            $i++;
            $l = rtrim($l);
            $lar = explode('<>', $l);
            // 重複回避
            if ($lar[1] == $key && $lar[11] == $bbs) {
                $before_line_num = $i;
                // 移動前の行番号をセット
                continue;
                // keyのないものは不正データなのでスキップ
            } elseif (!$lar[1]) {
                continue;
            } else {
                $newlines[] = $l;
            }
        }
    }
    // }}}
    if (!empty($GLOBALS['brazil'])) {
        //$newlines = _removeLargePallistData($newlines);
    }
    // 新規データ設定
    if ($set) {
        $newdata = implode('<>', array(geti($data[0]), $key, geti($data[2]), geti($data[3]), geti($data[4]), geti($data[5]), geti($data[6]), geti($data[7]), geti($data[8]), geti($data[9]), $host, $bbs));
        require_once P2_LIB_DIR . '/getSetPosLines.func.php';
        $rec_lines = getSetPosLines($newlines, $newdata, $before_line_num, $set);
    } else {
        $rec_lines = $newlines;
    }
    if (false === FileCtl::filePutRename($_conf['palace_file'], $rec_lines ? implode("\n", $rec_lines) . "\n" : '')) {
        trigger_error(sprintf('p2 error: %s(), FileCtl::filePutRename() failed.', __FUNCTION__), E_USER_WARNING);
        return false;
    }
    return true;
}
コード例 #3
0
ファイル: setfav.inc.php プロジェクト: xingskycn/p2-php
/**
 * お気にスレをセットする
 *
 * @param   string      $host
 * @param   string      $bbs
 * @param   string      $key
 * @param   int|string  $setfavita  0(解除), 1(追加), 2(トグル), top, up, down, bottom
 * @param   string      $ttitle
 * @param   int|null    $setnum
 * @return  bool
 */
function setFav($host, $bbs, $key, $setfav, $ttitle = null, $setnum = null)
{
    global $_conf;
    //==================================================================
    // key.idx
    //==================================================================
    // idxfileのパスを求めて
    $idxfile = P2Util::idxDirOfHostBbs($host, $bbs) . $key . '.idx';
    // 板ディレクトリが無ければ作る
    // FileCtl::mkdirFor($idxfile);
    // 既にidxデータがあるなら読み込む
    if ($lines = FileCtl::file_read_lines($idxfile, FILE_IGNORE_NEW_LINES)) {
        $data = explode('<>', $lines[0]);
    } else {
        $data = array_fill(0, 12, '');
        if (is_string($ttitle) && strlen($ttitle)) {
            $data[0] = p2h($ttitle, false);
        }
    }
    // {{{ スレッド.idx 記録
    if (($setfav == '0' || $setfav == '1') && $_conf['favlist_idx'] == $_conf['orig_favlist_idx']) {
        // お気にスレから外した結果、idxの意味がなくなれば削除する
        if ($setfav == '0' and !$data[3] && !$data[4] && $data[9] <= 1) {
            @unlink($idxfile);
        } else {
            $sar = array($data[0], $key, $data[2], $data[3], $data[4], $data[5], $setfav, $data[7], $data[8], $data[9], $data[10], $data[11], $data[12]);
            P2Util::recKeyIdx($idxfile, $sar);
        }
    }
    // }}}
    //==================================================================
    // favlist.idx
    //==================================================================
    if (!is_null($setnum) && $_conf['expack.misc.multi_favs']) {
        if (0 < $setnum && $setnum <= $_conf['expack.misc.favset_num']) {
            $favlist_idx = $_conf['pref_dir'] . sprintf('/p2_favlist%d.idx', $setnum);
        } else {
            $favlist_idx = $_conf['orig_favlist_idx'];
        }
    } else {
        $favlist_idx = $_conf['favlist_idx'];
    }
    // favlistファイルがなければ生成
    FileCtl::make_datafile($favlist_idx);
    // favlist読み込み
    $favlines = FileCtl::file_read_lines($favlist_idx, FILE_IGNORE_NEW_LINES);
    //================================================
    // 処理
    //================================================
    $neolines = array();
    $before_line_num = 0;
    $was_set = false;
    // 最初に重複要素を削除しておく
    if (!empty($favlines)) {
        $i = -1;
        foreach ($favlines as $l) {
            $i++;
            $lar = explode('<>', $l);
            // 重複回避
            if ($lar[1] == $key && $lar[11] == $bbs) {
                $before_line_num = $i;
                // 移動前の行番号をセット
                $was_set = true;
                continue;
                // keyのないものは不正データなのでスキップ
            } elseif (!$lar[1]) {
                continue;
            } else {
                $neolines[] = $l;
            }
        }
    }
    if ($setfav == 2) {
        $setfav = $was_set ? 0 : 1;
    }
    // 記録データ設定
    if ($setfav) {
        if (!function_exists('getSetPosLines')) {
            include P2_LIB_DIR . '/getsetposlines.inc.php';
        }
        $newdata = "{$data[0]}<>{$key}<>{$data[2]}<>{$data[3]}<>{$data[4]}<>{$data[5]}<>1<>{$data[7]}<>{$data[8]}<>{$data[9]}<>{$host}<>{$bbs}";
        $rec_lines = getSetPosLines($neolines, $newdata, $before_line_num, $setfav);
    } else {
        $rec_lines = $neolines;
    }
    $cont = '';
    if (!empty($rec_lines)) {
        foreach ($rec_lines as $l) {
            $cont .= $l . "\n";
        }
    }
    // 書き込む
    if (FileCtl::file_write_contents($favlist_idx, $cont) === false) {
        p2die('cannot write file.');
    }
    //================================================
    // お気にスレ共有
    //================================================
    if ($_conf['join_favrank'] && $_conf['favlist_idx'] == $_conf['orig_favlist_idx']) {
        if ($setfav == "0") {
            $act = "out";
        } elseif ($setfav == "1") {
            $act = "add";
        } else {
            return;
        }
        $itaj = P2Util::getItaName($host, $bbs);
        $post = array("host" => $host, "bbs" => $bbs, "key" => $key, "ttitle" => $data[0], "ita" => $itaj, "act" => $act);
        postFavRank($post);
    }
    return true;
}
コード例 #4
0
ファイル: setfavita.inc.php プロジェクト: unpush/p2-php
/**
 * host,bbsからお気に板をセットする
 *
 * @param   string      $host
 * @param   string      $bbs
 * @param   int|string  $setfavita  0(解除), 1(追加), 2(トグル), top, up, down, bottom
 * @param   string      $itaj
 * @param   int|null    $setnum
 * @return  bool
 */
function setFavItaByHostBbs($host, $bbs, $setfavita, $itaj = null, $setnum = null)
{
    global $_conf;
    // p2_favita.brd 読み込み
    $favita_brd = setFavItaGetBrdPath($setnum);
    $lines = FileCtl::file_read_lines($favita_brd, FILE_IGNORE_NEW_LINES);
    //================================================
    // 処理
    //================================================
    $neolines = array();
    $before_line_num = 0;
    $was_set = false;
    // 最初に重複要素を消去
    if (!empty($lines)) {
        $i = -1;
        foreach ($lines as $l) {
            $i++;
            // {{{ 旧データ(ver0.6.0以下)移行措置
            if ($l[0] != "\t") {
                $l = "\t" . $l;
            }
            // }}}
            $lar = explode("\t", $l);
            if ($lar[1] == $host and $lar[2] == $bbs) {
                // 重複回避
                $before_line_num = $i;
                $was_set = true;
                continue;
            } elseif (!$lar[1] || !$lar[2]) {
                // 不正データ(host, bbsなし)もアウト
                continue;
            } else {
                $neolines[] = $l;
            }
        }
    }
    if ($setfavita == 2) {
        $setfavita = $was_set ? 0 : 1;
    }
    // 記録データ設定
    if ($setfavita && $host && $bbs) {
        if (!is_string($itaj) || strlen($itaj) == 0) {
            $itaj = $bbs;
        }
        $newdata = "\t{$host}\t{$bbs}\t{$itaj}";
        require_once P2_LIB_DIR . '/getsetposlines.inc.php';
        $rec_lines = getSetPosLines($neolines, $newdata, $before_line_num, $setfavita);
        // 解除
    } else {
        $rec_lines = $neolines;
    }
    $cont = '';
    if (!empty($rec_lines)) {
        foreach ($rec_lines as $l) {
            $cont .= $l . "\n";
        }
    }
    // 書き込む
    if (FileCtl::file_write_contents($favita_brd, $cont) === false) {
        p2die('cannot write file.');
    }
    return true;
}
コード例 #5
0
ファイル: setFavIta.func.php プロジェクト: poppen/p2
/**
 * お気に板をセットする関数
 *
 * $setfavita は、0(解除), 1(追加), top, up, down, bottom
 *
 * @access  public
 * @return  boolean
 */
function setFavIta()
{
    global $_conf;
    // {{{ パラメータの設定
    if (isset($_GET['setfavita'])) {
        $setfavita = $_GET['setfavita'];
    } elseif (isset($_POST['setfavita'])) {
        $setfavita = $_POST['setfavita'];
    }
    $host = isset($_GET['host']) ? $_GET['host'] : NULL;
    $bbs = isset($_GET['bbs']) ? $_GET['bbs'] : NULL;
    if (isset($setfavita) && !preg_match('/^[a-zA-Z0-9]+$/', $setfavita)) {
        P2Util::pushInfoHtml('<p>p2 info: 不正な引数です(setfavita)');
        return false;
    }
    if (isset($host) && P2Validate::host($host) || isset($bbs) && P2Validate::bbs($bbs)) {
        P2Util::pushInfoHtml("<p>p2 info: 板の指定が変です</p>");
        return false;
    }
    if (!empty($_POST['url'])) {
        if (preg_match("/http:\\/\\/(.+)\\/([^\\/]+)\\/([^\\/]+\\.html?)?/", $_POST['url'], $matches)) {
            $host = preg_replace('{/test/read\\.cgi$}', '', $matches[1]);
            $bbs = $matches[2];
        } else {
            P2Util::pushInfoHtml(sprintf("<p>p2 info: 「%s」は板のURLとして無効です。</p>", hs($_POST['url'])));
        }
    }
    $list = isset($_POST['list']) ? $_POST['list'] : '';
    // リストで並び替え
    if (!empty($_POST['submit_listfavita'])) {
        if (!$list) {
            P2Util::pushInfoHtml("<p>p2 info: リストの指定が変です</p>");
            return false;
        }
    } else {
        // 新規追加 or 一つずつ並び替え
        if (!$host || !$bbs) {
            P2Util::pushInfoHtml("<p>p2 info: 板の指定が変です</p>");
            return false;
        }
    }
    $itaj = isset($_POST['itaj']) ? $_POST['itaj'] : '';
    if (!$itaj && isset($_GET['itaj_en'])) {
        $itaj = base64_decode($_GET['itaj_en']);
    }
    !$itaj and $itaj = $bbs;
    // }}}
    //================================================
    // 処理
    //================================================
    if (false === FileCtl::make_datafile($_conf['favita_path'], $_conf['favita_perm'])) {
        return false;
    }
    if (false === ($lines = file($_conf['favita_path']))) {
        return false;
    }
    $neolines = array();
    $before_line_num = 0;
    // 最初に重複要素を消去しておく
    if ($lines) {
        $i = -1;
        $avoided = false;
        foreach ($lines as $l) {
            $i++;
            $l = rtrim($l);
            // {{{ 旧データ(ver0.6.0以下)移行措置
            if (!preg_match("/^\t/", $l)) {
                $l = "\t" . $l;
            }
            // }}}
            $lar = explode("\t", $l);
            if (!$avoided and $lar[1] == $host && $lar[2] == $bbs) {
                // 重複回避
                $avoided = true;
                $before_line_num = $i;
                continue;
            } elseif (!$lar[1] || !$lar[2]) {
                // 不正データ(host, bbsなし)もアウト
                continue;
            } elseif (P2Validate::host($lar[1]) || P2Validate::bbs($lar[2])) {
                continue;
            } else {
                $neolines[] = $l;
            }
        }
    }
    // 記録データ設定
    // リスト丸ごとポストして指定
    if (!empty($_POST['submit_listfavita']) && $list) {
        $rec_lines = array();
        foreach (explode(',', $list) as $aList) {
            list($host, $bbs, $itaj_en) = array_map('rawurldecode', explode('@', $aList, 3));
            $itaj = base64_decode($itaj_en);
            $rec_lines[] = "\t{$host}\t{$bbs}\t" . $itaj;
        }
        P2Util::pushInfoHtml("<script language=\"javascript\">if (parent.menu) { parent.menu.location.href='{$_conf['menu_php']}?nr=1'; }</script>");
        // 一つのデータを指定して操作
    } elseif ($setfavita and $host && $bbs && $itaj) {
        $newdata = "\t{$host}\t{$bbs}\t{$itaj}";
        require_once P2_LIB_DIR . '/getSetPosLines.func.php';
        $rec_lines = getSetPosLines($neolines, $newdata, $before_line_num, $setfavita);
        // 解除
    } else {
        $rec_lines = $neolines;
    }
    $cont = '';
    if (!empty($rec_lines)) {
        foreach ($rec_lines as $l) {
            $cont .= $l . "\n";
        }
    }
    // 書き込む
    if (false === file_put_contents($_conf['favita_path'], $cont, LOCK_EX)) {
        trigger_error("file_put_contents(" . $_conf['favita_path'] . ")", E_USER_WARNING);
        die('Error: cannot write file.');
        return false;
    }
    return true;
}
コード例 #6
0
ファイル: setpalace.inc.php プロジェクト: xingskycn/p2-php
/**
 * スレを殿堂入りにセットする
 *
 * @param   string      $host
 * @param   string      $bbs
 * @param   string      $key
 * @param   int|string  $setpal  0(解除), 1(追加), 2(トグル) top, up, down, bottom
 * @param   string      $ttitle
 * @return  bool
 */
function setPal($host, $bbs, $key, $setpal, $ttitle = null)
{
    global $_conf;
    // key.idx のパスを求めて
    $idxfile = P2Util::idxDirOfHostBbs($host, $bbs) . $key . '.idx';
    // 既に key.idx データがあるなら読み込む
    if ($lines = FileCtl::file_read_lines($idxfile, FILE_IGNORE_NEW_LINES)) {
        $data = explode('<>', $lines[0]);
    } else {
        $data = array_fill(0, 12, '');
        if (is_string($ttitle) && strlen($ttitle)) {
            $data[0] = p2h($ttitle, false);
        }
    }
    //==================================================================
    // p2_palace.idxに書き込む
    //==================================================================
    $lock = new P2Lock($_conf['palace_idx'], false);
    // palace_idx ファイルがなければ生成
    FileCtl::make_datafile($_conf['palace_idx']);
    // palace_idx 読み込み
    $pallines = FileCtl::file_read_lines($_conf['palace_idx'], FILE_IGNORE_NEW_LINES);
    $neolines = array();
    $pal_attayo = false;
    $before_line_num = 0;
    // {{{ 最初に重複要素を削除しておく
    if (!empty($pallines)) {
        $i = -1;
        foreach ($pallines as $l) {
            $i++;
            $lar = explode('<>', $l);
            // 重複回避
            if ($lar[1] == $key && $lar[11] == $bbs) {
                $pal_attayo = true;
                $before_line_num = $i;
                // 移動前の行番号をセット
                continue;
                // keyのないものは不正データなのでスキップ
            } elseif (!$lar[1]) {
                continue;
            } else {
                $neolines[] = $l;
            }
        }
    }
    // }}}
    if ($setpal == 2) {
        $setpal = $pal_attayo ? 0 : 1;
    }
    // 新規データ設定
    if ($setpal) {
        $newdata = "{$data[0]}<>{$key}<>{$data[2]}<>{$data[3]}<>{$data[4]}<>{$data[5]}<>{$data[6]}<>{$data[7]}<>{$data[8]}<>{$data[9]}<>{$host}<>{$bbs}";
        require_once P2_LIB_DIR . '/getsetposlines.inc.php';
        $rec_lines = getSetPosLines($neolines, $newdata, $before_line_num, $setpal);
    } else {
        $rec_lines = $neolines;
    }
    $cont = '';
    if (!empty($rec_lines)) {
        foreach ($rec_lines as $l) {
            $cont .= $l . "\n";
        }
    }
    // 書き込む
    if (FileCtl::file_write_contents($_conf['palace_idx'], $cont) === false) {
        p2die('cannot write file.');
    }
    return true;
}