示例#1
0
文件: iphone.php 项目: 68/rep2iphone
/**
 * ディレクトリに(アクセス拒否のための) .htaccess がなければ、自動で生成する
 *
 * @return  void
 */
function makeDenyHtaccess($dir)
{
    $hta = $dir . '/.htaccess';
    if (!file_exists($hta)) {
        $data = 'Order allow,deny' . "\n" . 'Deny from all' . "\n";
        FileCtl::file_write_contents($hta, $data);
    }
}
示例#2
0
/**
 * ■スレッドあぼーんを複数一括解除する
 */
function settaborn_off($host, $bbs, $taborn_off_keys)
{
    if (!$taborn_off_keys) {
        return;
    }
    // p2_threads_aborn.idx のパス取得
    $taborn_idx = P2Util::idxDirOfHostBbs($host, $bbs) . 'p2_threads_aborn.idx';
    // p2_threads_aborn.idx がなければ
    if (!file_exists($taborn_idx)) {
        p2die('あぼーんリストが見つかりませんでした。');
    }
    // p2_threads_aborn.idx 読み込み
    $taborn_lines = FileCtl::file_read_lines($taborn_idx, FILE_IGNORE_NEW_LINES);
    // 指定keyを削除
    foreach ($taborn_off_keys as $val) {
        $neolines = array();
        if ($taborn_lines) {
            foreach ($taborn_lines as $line) {
                $lar = explode('<>', $line);
                if ($lar[1] == $val) {
                    // key発見
                    // echo "key:{$val} のスレッドをあぼーん解除しました。<br>";
                    $kaijo_attayo = true;
                    continue;
                }
                if (!$lar[1]) {
                    continue;
                }
                // keyのないものは不正データ
                $neolines[] = $line;
            }
        }
        $taborn_lines = $neolines;
    }
    // 書き込む
    if (file_exists($taborn_idx)) {
        copy($taborn_idx, $taborn_idx . '.bak');
        // 念のためバックアップ
    }
    $cont = '';
    if (is_array($taborn_lines)) {
        foreach ($taborn_lines as $l) {
            $cont .= $l . "\n";
        }
    }
    if (FileCtl::file_write_contents($taborn_idx, $cont) === false) {
        p2die('cannot write file.');
    }
    /*
    if (!$kaijo_attayo) {
        // echo "指定されたスレッドは既にあぼーんリストに載っていないようです。";
    } else {
        // echo "あぼーん解除、完了しました。";
    }
    */
}
示例#3
0
 public function save($data)
 {
     global $_conf;
     $path = $_conf['pref_dir'] . '/' . $this->filename;
     $newdata = '';
     foreach ($data as $na_info) {
         $a[0] = strtr(trim($na_info['match'], "\t\r\n"), "\t\r\n", "   ");
         $a[1] = strtr(trim($na_info['replace'], "\t\r\n"), "\t\r\n", "   ");
         if ($na_info['del'] || ($a[0] === '' || $a[1] === '')) {
             continue;
         }
         $newdata .= implode("\t", $a) . "\n";
     }
     return FileCtl::file_write_contents($path, $newdata);
 }
示例#4
0
/**
 * スキンを切り替える
 */
function changeSkin($skin)
{
    global $_conf;
    if (!preg_match('/^\\w+$/', $skin)) {
        return "p2 error: 不正なスキン ({$skin}) が指定されました。";
    }
    if ($skin == 'conf_style') {
        $newskin = './conf/conf_user_style.php';
    } else {
        $newskin = './skin/' . $skin . '.php';
    }
    if (file_exists($newskin)) {
        if (FileCtl::file_write_contents($_conf['expack.skin.setting_path'], $skin) !== FALSE) {
            return $skin;
        } else {
            return "p2 error: {$_conf['expack.skin.setting_path']} にスキン設定を書き込めませんでした。";
        }
    } else {
        return "p2 error: 不正なスキン ({$skin}) が指定されました。";
    }
}
示例#5
0
/**
 * チェックした書き込み記事を削除する
 */
function deleMsg($checked_hists)
{
    global $_conf;
    $lock = new P2Lock($_conf['res_hist_dat'], false);
    // 読み込んで
    $reslines = FileCtl::file_read_lines($_conf['res_hist_dat'], FILE_IGNORE_NEW_LINES);
    if ($reslines === false) {
        p2die("{$_conf['res_hist_dat']} を開けませんでした");
    }
    // ファイルの下に記録されているものが新しいので逆順にする
    $reslines = array_reverse($reslines);
    $neolines = array();
    // チェックして整えて
    if ($reslines) {
        $n = 1;
        foreach ($reslines as $ares) {
            $rar = explode("<>", $ares);
            // 番号と日付が一致するかをチェックする
            if (checkMsgID($checked_hists, $n, $rar[2])) {
                $rmnums[] = $n;
                // 削除する番号を登録
            }
            $n++;
        }
        $neolines = rmLine($rmnums, $reslines);
        P2Util::pushInfoHtml('<p>p2 info: ' . count($rmnums) . '件のレス記事を削除しました</p>');
    }
    if (is_array($neolines)) {
        // 行順を戻す
        $neolines = array_reverse($neolines);
        $cont = "";
        if ($neolines) {
            $cont = implode("\n", $neolines) . "\n";
        }
        // 書き込む
        if (FileCtl::file_write_contents($_conf['res_hist_dat'], $cont) === false) {
            p2die('cannot write file.');
        }
    }
}
示例#6
0
文件: tgrepc.php 项目: unpush/p2-php
        $cache->remove($cache_id_profile, $cache_group_profile);
    } else {
        // 検索履歴を更新
        if ($_conf['expack.tgrep.recent_num'] > 0) {
            FileCtl::make_datafile($_conf['expack.tgrep.recent_file'], $_conf['expack.tgrep.file_perm']);
            $tgrep_recent_list = FileCtl::file_read_lines($_conf['expack.tgrep.recent_file'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
            if (!is_array($tgrep_recent_list)) {
                $tgrep_recent_list = array();
            }
            array_unshift($tgrep_recent_list, preg_replace('/[\\r\\n\\t]/', ' ', trim($_GET['Q'])));
            $tgrep_recent_list = array_unique($tgrep_recent_list);
            while (count($tgrep_recent_list) > $_conf['expack.tgrep.recent_num']) {
                array_pop($tgrep_recent_list);
            }
            $tgrep_recent_data = implode("\n", $tgrep_recent_list) . "\n";
            if (FileCtl::file_write_contents($_conf['expack.tgrep.recent_file'], $tgrep_recent_data) === false) {
                p2die('cannot write file.');
            }
            chmod($_conf['expack.tgrep.recent_file'], $_conf['p2_perm']);
        }
    }
} else {
    $errors = null;
    $threads = null;
    $profile = null;
    $modified = '';
}
// }}}
// {{{ 表示用変数を設定
// 基本変数
$htm = array();
示例#7
0
 /**
  * brdファイルを生成する
  *
  * @return    string    brdファイルのパス
  */
 public function makeBrdFile($cachefile)
 {
     global $_conf, $word;
     $p2brdfile = $cachefile . ".p2.brd";
     FileCtl::make_datafile($p2brdfile);
     $data = FileCtl::file_read_lines($cachefile);
     $cont = '';
     $this->setBrdMatch($cachefile);
     // パターンマッチ形式を登録
     $this->setBrdList($data);
     // カテゴリーと板をセット
     if ($this->categories) {
         foreach ($this->categories as $cate) {
             if ($cate->num > 0) {
                 $cont .= $cate->name . "\t0\n";
                 foreach ($cate->menuitas as $mita) {
                     $cont .= "\t{$mita->host}\t{$mita->bbs}\t{$mita->itaj}\n";
                 }
             }
         }
     }
     if ($cont) {
         if (FileCtl::file_write_contents($p2brdfile, $cont) === false) {
             p2die("{$p2brdfile} を更新できませんでした");
         }
         return $p2brdfile;
     } else {
         if (!$word) {
             P2Util::pushInfoHtml("<p>p2 error: {$cachefile} から板メニューを生成することはできませんでした。</p>");
         }
         return false;
     }
 }
示例#8
0
        $tgrep_list = array();
    }
    if ($purge) {
        $tgrep_tmp_list = $tgrep_list;
        $tgrep_list = array();
        foreach ($tgrep_tmp_list as $tgrep_tmp_query) {
            if ($tgrep_tmp_query != $query) {
                $tgrep_list[] = $tgrep_tmp_query;
            }
        }
    } else {
        array_unshift($tgrep_list, $query);
    }
    $tgrep_list = array_unique($tgrep_list);
    $tgrep_data = implode("\n", $tgrep_list) . "\n";
    if (FileCtl::file_write_contents($list_file, $tgrep_data) === false) {
        p2die('cannot write file.');
    }
} elseif (!empty($_GET['clear']) && file_exists($list_file)) {
    $fp = @fopen($list_file, 'w');
    if (!$fp) {
        p2die('cannot write file.');
    }
    flock($fp, LOCK_EX);
    ftruncate($fp, 0);
    flock($fp, LOCK_UN);
    fclose($fp);
}
// }}}
// {{{ 不要になった変数を解放
unset($_GET['clear'], $_GET['file'], $_GET['purge'], $_GET['query'], $purge, $query, $tgrep_list, $tgrep_data, $tgrep_tmp_list, $tgrep_tmp_query, $fp);
示例#9
0
/**
 * カンマ区切り+@区切りのリストからお気に板をセットする
 *
 * @param   string      $list
 * @param   int|null    $setnum
 * @return  bool
 */
function setFavItaByList($list, $setnum = null)
{
    global $_conf;
    // 記録データ設定
    $rec_lines = array();
    foreach (explode(',', $list) as $aList) {
        list($host, $bbs, $itaj_en) = explode('@', $aList);
        $rec_lines[] = "\t{$host}\t{$bbs}\t" . UrlSafeBase64::decode($itaj_en);
    }
    $script = <<<EOJS
<script type="text/javascript">
//<![CDATA[
if (parent.menu) {
    parent.menu.location.href = '{$_conf['menu_php']}?nr=1';
}
//]]>
</script>

EOJS;
    P2Util::pushInfoHtml($script);
    $cont = '';
    if (!empty($rec_lines)) {
        foreach ($rec_lines as $l) {
            $cont .= $l . "\n";
        }
    }
    // 書き込む
    if (FileCtl::file_write_contents(setFavItaGetBrdPath($setnum), $cont) === false) {
        p2die('cannot write file.');
    }
    return true;
}
示例#10
0
 /**
  * アクセス情報をログに記録する
  */
 public static function recAccessLog($logfile, $maxline = 100, $format = 'dataphp')
 {
     global $_conf, $_login;
     // ログファイルの中身を取得する
     if ($format == 'dataphp') {
         $lines = DataPhp::fileDataPhp($logfile);
     } else {
         $lines = FileCtl::file_read_lines($logfile);
     }
     if ($lines) {
         // 制限行調整
         while (sizeof($lines) > $maxline - 1) {
             array_pop($lines);
         }
     } else {
         $lines = array();
     }
     $lines = array_map('rtrim', $lines);
     // 変数設定
     $date = date('Y/m/d (D) G:i:s');
     // IPアドレスを取得
     if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) {
         $remote_addr = $_SERVER["HTTP_X_REAL_IP"];
     } else {
         $remote_addr = '';
     }
     // HOSTを取得
     if (array_key_exists('HTTP_X_REAL_IP', $_SERVER)) {
         $remote_host = gethostbyaddr($_SERVER['HTTP_X_REAL_IP']);
     } else {
         $remote_host = '';
     }
     if (!$remote_host) {
         $remote_host = gethostbyaddr($_SERVER["HTTP_X_REAL_IP"]);
     }
     if ($remote_host == $_SERVER["HTTP_X_REAL_IP"]) {
         $remote_host = '';
     }
     // UAを取得
     if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) {
         $user_agent = $_SERVER['HTTP_USER_AGENT'];
     } else {
         $user_agent = '';
     }
     // リファラを取得
     if (array_key_exists('HTTP_REFERER', $_SERVER)) {
         $referrer = $_SERVER['HTTP_REFERER'];
     } else {
         $referrer = '';
     }
     $user = isset($_login->user_u) ? $_login->user_u : '';
     // 新しいログ行を設定
     $newdata = implode('<>', array($date, $remote_addr, $remote_host, $user_agent, $referrer, '', $user));
     //$newdata = htmlspecialchars($newdata, ENT_QUOTES);
     // まずタブを全て外して
     $newdata = str_replace("\t", "", $newdata);
     // <>をタブに変換して
     $newdata = str_replace("<>", "\t", $newdata);
     // 新しいデータを一番上に追加
     @array_unshift($lines, $newdata);
     $cont = implode("\n", $lines) . "\n";
     FileCtl::make_datafile($logfile, $_conf['p2_perm']);
     // 書き込み処理
     if ($format == 'dataphp') {
         DataPhp::writeDataPhp($logfile, $cont, $_conf['p2_perm']);
     } else {
         FileCtl::file_write_contents($logfile, $cont);
     }
     return true;
 }
示例#11
0
 /**
  * SETTING.TXT をパースしてキャッシュ保存する
  *
  * 成功すれば、$this->setting_array がセットされる
  *
  * @return boolean 実行成否
  */
 public function cacheParsedSettingTxt()
 {
     global $_conf;
     $this->setting_array = array();
     if (!($lines = FileCtl::file_read_lines($this->_setting_txt))) {
         return false;
     }
     foreach ($lines as $line) {
         if (strpos($line, '=') !== false) {
             list($key, $value) = explode('=', $line, 2);
             $key = trim($key);
             $value = trim($value);
             $this->setting_array[$key] = $value;
         }
     }
     $this->setting_array['p2version'] = $_conf['p2version'];
     // パースキャッシュファイルを保存する
     if (FileCtl::file_write_contents($this->_setting_srd, serialize($this->setting_array)) === false) {
         return false;
     }
     return true;
 }
示例#12
0
/**
 * スレッドあぼーんをオンオフする
 *
 * $set は、0(解除), 1(追加), 2(トグル)
 */
function settaborn($host, $bbs, $key, $set)
{
    global $_conf, $title_msg, $info_msg;
    //==================================================================
    // key.idx 読み込む
    //==================================================================
    // idxfileのパスを求めて
    $idx_host_bbs_dir_s = P2Util::idxDirOfHostBbs($host, $bbs);
    $idxfile = $idx_host_bbs_dir_s . $key . '.idx';
    // データがあるなら読み込む
    if ($lines = FileCtl::file_read_lines($idxfile, FILE_IGNORE_NEW_LINES)) {
        $data = explode('<>', $lines[0]);
    } else {
        $data = array_fill(0, 12, '');
    }
    //==================================================================
    // p2_threads_aborn.idxに書き込む
    //==================================================================
    // p2_threads_aborn.idx のパス取得
    $taborn_idx = $idx_host_bbs_dir_s . 'p2_threads_aborn.idx';
    // p2_threads_aborn.idx がなければ生成
    FileCtl::make_datafile($taborn_idx);
    // p2_threads_aborn.idx 読み込み;
    $taborn_lines = FileCtl::file_read_lines($taborn_idx, FILE_IGNORE_NEW_LINES);
    $neolines = array();
    $aborn_attayo = false;
    if ($taborn_lines) {
        foreach ($taborn_lines as $l) {
            $lar = explode('<>', $l);
            if ($lar[1] == $key) {
                $aborn_attayo = true;
                // 既にあぼーん中である
                if ($set == 0 or $set == 2) {
                    $title_msg_pre = "+ あぼーん 解除しますた";
                    $info_msg_pre = "+ あぼーん 解除しますた";
                }
                continue;
            }
            if (!$lar[1]) {
                continue;
            }
            // keyのないものは不正データ
            $neolines[] = $l;
        }
    }
    // 新規データ追加
    if ($set == 1 or !$aborn_attayo && $set == 2) {
        $newdata = "{$data[0]}<>{$key}<><><><><><><><>";
        $neolines ? array_unshift($neolines, $newdata) : ($neolines = array($newdata));
        $title_msg_pre = "○ あぼーん しますた";
        $info_msg_pre = "○ あぼーん しますた";
    }
    // 書き込む
    $cont = '';
    if (!empty($neolines)) {
        foreach ($neolines as $l) {
            $cont .= $l . "\n";
        }
    }
    if (FileCtl::file_write_contents($taborn_idx, $cont) === false) {
        p2die('cannot write file.');
    }
    $GLOBALS['title_msg'] = $title_msg_pre;
    $GLOBALS['info_msg'] = $info_msg_pre;
    return true;
}
示例#13
0
/**
 * お気に入りセットリストを更新する
 *
 * @return  boolean 更新に成功したらTRUE, 失敗したらFALSE
 */
function updateFavSetList()
{
    global $_conf;
    if (file_exists($_conf['expack.misc.favset_file'])) {
        $setlist_titles = FavSetManager::getFavSetTitles();
    } else {
        FileCtl::make_datafile($_conf['expack.misc.favset_file']);
    }
    if (empty($setlist_titles)) {
        $setlist_titles = array();
    }
    $setlist_names = array('m_favlist_set', 'm_favita_set', 'm_rss_set');
    foreach ($setlist_names as $setlist_name) {
        if (isset($_POST["{$setlist_name}_titles"]) && is_array($_POST["{$setlist_name}_titles"])) {
            $setlist_titles[$setlist_name] = array();
            for ($i = 0; $i <= $_conf['expack.misc.favset_num']; $i++) {
                if (!isset($_POST["{$setlist_name}_titles"][$i])) {
                    $setlist_titles[$setlist_name][$i] = '';
                    continue;
                }
                $newname = trim($_POST["{$setlist_name}_titles"][$i]);
                $newname = preg_replace('/\\r\\n\\t/', ' ', $newname);
                $newname = htmlspecialchars($newname, ENT_QUOTES);
                $setlist_titles[$setlist_name][$i] = $newname;
            }
        }
    }
    $newdata = serialize($setlist_titles);
    if (FileCtl::file_write_contents($_conf['expack.misc.favset_file'], $newdata) === FALSE) {
        P2Util::pushInfoHtml("<p>p2 error: {$_conf['expack.misc.favset_file']} にお気に入りセット設定を書き込めませんでした。");
        return FALSE;
    }
    return TRUE;
}
示例#14
0
/**
 * p2_setting 記録する
 *
 * @return  boolean
 */
function saveSbSetting($p2_setting_txt, $p2_setting, $pre_setting)
{
    global $_conf;
    $pre_setting_itaj = isset($pre_setting['itaj']) ? $pre_setting['itaj'] : null;
    $p2_setting_itaj = isset($p2_setting['itaj']) ? $p2_setting['itaj'] : null;
    if ($pre_setting['viewnum'] != $p2_setting['viewnum'] or $pre_setting['sort'] != $GLOBALS['now_sort'] or $pre_setting_itaj != $p2_setting_itaj) {
        if (!empty($_POST['sort'])) {
            $p2_setting['sort'] = $_POST['sort'];
        } elseif (!empty($_GET['sort'])) {
            $p2_setting['sort'] = $_GET['sort'];
        }
        if (false === FileCtl::make_datafile($p2_setting_txt, $_conf['p2_perm'])) {
            return false;
        }
        if ($p2_setting) {
            $p2_setting_cont = serialize($p2_setting);
            if (FileCtl::file_write_contents($p2_setting_txt, $p2_setting_cont) === false) {
                die("Error: cannot write file.");
            }
        }
    }
    return true;
}
示例#15
0
    /**
     * 新規ユーザを作成する
     */
    public function makeUser($user_u, $pass)
    {
        global $_conf;
        $crypted_login_pass = sha1($pass);
        $auth_user_cont = <<<EOP
<?php
\$rec_login_user_u = '{$user_u}';
\$rec_login_pass_x = '{$crypted_login_pass}';
?>
EOP;
        FileCtl::make_datafile($_conf['auth_user_file'], $_conf['pass_perm']);
        // ファイルがなければ生成
        if (FileCtl::file_write_contents($_conf['auth_user_file'], $auth_user_cont) === false) {
            p2die("{$_conf['auth_user_file']} を保存できませんでした。認証{$p_str['user']}登録失敗。");
        }
        return true;
    }
示例#16
0
    /**
     * 新規ユーザを作成する
     */
    public function makeUser($user_u, $pass)
    {
        global $_conf;
        $login_user = strval($user_u);
        $hashed_login_pass = sha1($pass);
        $login_user_repr = var_export($login_user, true);
        $login_pass_repr = var_export($hashed_login_pass, true);
        $auth_user_cont = <<<EOP
<?php
\$rec_login_user_u = {$login_user_repr};
\$rec_login_pass_x = {$login_pass_repr};

EOP;
        if (FileCtl::file_write_contents($_conf['auth_user_file'], $auth_user_cont) === false) {
            p2die("{$_conf['auth_user_file']} を保存できませんでした。認証{$p_str['user']}登録失敗。");
        }
        return true;
    }
示例#17
0
/**
 * 履歴を記録する
 */
function recRecent($data)
{
    global $_conf;
    $lock = new P2Lock($_conf['recent_idx'], false);
    // $_conf['recent_idx'] ファイルがなければ生成
    FileCtl::make_datafile($_conf['recent_idx'], $_conf['rct_perm']);
    $lines = FileCtl::file_read_lines($_conf['recent_idx'], FILE_IGNORE_NEW_LINES);
    $neolines = array();
    // {{{ 最初に重複要素を削除しておく
    if (is_array($lines)) {
        foreach ($lines as $l) {
            $lar = explode('<>', $l);
            $data_ar = explode('<>', $data);
            if ($lar[1] == $data_ar[1]) {
                continue;
            }
            // keyで重複回避
            if (!$lar[1]) {
                continue;
            }
            // keyのないものは不正データ
            $neolines[] = $l;
        }
    }
    // }}}
    // 新規データ追加
    array_unshift($neolines, $data);
    while (sizeof($neolines) > $_conf['rct_rec_num']) {
        array_pop($neolines);
    }
    // {{{ 書き込む
    if ($neolines) {
        $cont = '';
        foreach ($neolines as $l) {
            $cont .= $l . "\n";
        }
        if (FileCtl::file_write_contents($_conf['recent_idx'], $cont) === false) {
            p2die('cannot write file.');
        }
    }
    // }}}
    return true;
}
示例#18
0
 /**
  * 公式p2で(dat取得権限がない場合はモリタポを消費して)datを取得する
  *
  * @param void
  * @return bool
  */
 protected function _downloadDat2chMoritapo()
 {
     global $_conf;
     // datをダウンロード
     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());
     }
     // データ検証その1
     if (!$body || strpos($body, '<>') === false && strpos($body, ',') === false) {
         return $this->_downloadDat2chMoritapoNotFound();
     }
     // 改行位置を検出
     $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);
     }
     // 1行目の取得とデータ検証その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();
     }
     // データ検証その3 (タイトル = $ar[4])
     $ar = $this->explodeDatLine($firstLine);
     if (count($ar) < 5) {
         return $this->_downloadDat2chMoritapoNotFound();
     }
     // ローカルdatに書き込み
     FileCtl::make_datafile($this->keydat, $_conf['dat_perm']);
     if (FileCtl::file_write_contents($this->keydat, $body) === false) {
         p2die('cannot write file. downloadDat2chMoritapo()');
     }
     return true;
 }
示例#19
0
 /**
  * フィルタリング設定をファイルに保存する
  *
  * @param void
  * @return void
  */
 public function save()
 {
     global $_conf;
     $cachefile = $_conf['pref_dir'] . '/p2_res_filter.txt';
     $res_filter_cont = serialize(array('field' => $this->field, 'method' => $this->method, 'match' => $this->match, 'include' => $this->include));
     FileCtl::file_write_contents($cachefile, $res_filter_cont);
 }
示例#20
0
 /**
  * 定型文を保存する
  *
  * @return bool
  */
 public function save()
 {
     ksort($this->_data);
     return FileCtl::file_write_contents($this->_filename, serialize($this->_data)) !== false;
 }
示例#21
0
/**
 * お気にスレをセットする
 *
 * @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;
}
示例#22
0
 public function save($data)
 {
     global $_conf;
     if ($data) {
         $new_data = true;
         $this->data = $data;
     } elseif (!$this->isLoaded) {
         return;
     } else {
         $new_data = false;
     }
     // HITした時のみ更新する
     if ($this->hits > 0 || $new_data) {
         $cont = '';
         foreach ($this->data as $v) {
             if ($v['del']) {
                 continue;
             }
             // 必要ならここで古いデータはスキップ(削除)する
             if (!empty($v['lasttime']) && $_conf['ngaborn_daylimit']) {
                 if (strtotime($v['lasttime']) < time() - 60 * 60 * 24 * $_conf['ngaborn_daylimit']) {
                     continue;
                 }
             }
             $a['word'] = strtr(trim($v['word'], "\t\r\n"), "\t\r\n", "   ");
             $a['ignorecase'] = $v['ignorecase'];
             $a['regex'] = $v['regex'];
             $a['bbs'] = strtr(trim($v['bbs'], "\t\r\n"), "\t\r\n", "   ");
             $a['lasttime'] = $v['lasttime'];
             $a['hits'] = $v['hits'];
             // lasttimeが設定されていなかったら現在時間を設定(本来なら登録時にするべき)
             if (empty($v['lasttime'])) {
                 $v['lasttime'] = date(self::DATE_FORMAT);
             }
             $cont .= implode("\t", $v) . "\n";
         }
         return FileCtl::file_write_contents($_conf['pref_dir'] . '/' . $this->filename);
     }
 }
示例#23
0
 public function storeCache($key, $data)
 {
     global $_conf;
     if ($this->cacheData[$key]) {
         // overwrite the cache file
         $this->cacheData[$key] = $data;
         $body = '';
         foreach ($this->cacheData as $_k => $_v) {
             $body .= implode("\t", array($_k, serialize(self::sanitizeForCache($_v)))) . "\n";
         }
         return FileCtl::file_write_contents($_conf['pref_dir'] . '/' . $this->cacheFilename, $body);
     } else {
         // append to the cache file
         $this->cacheData[$key] = $data;
         return FileCtl::file_write_contents($_conf['pref_dir'] . '/' . $this->cacheFilename, implode("\t", array($key, serialize(self::sanitizeForCache($data)))) . "\n", FILE_APPEND);
     }
 }
示例#24
0
                        $elements[$newElemName]->setOptions(array($value, $value));
                    }
                }
            }
            if ($value) {
                $updated_fontconfig['custom'][$tname][$pname] = $value;
            }
            $elements[$newElemName]->setValue($value);
        }
    }
}
// 保存
$fontconfig_data = serialize($updated_fontconfig);
$fontconfig_new_hath = md5($fontconfig_data);
if (strcmp($fontconfig_hash, $fontconfig_new_hath) != 0) {
    FileCtl::file_write_contents($_conf['expack.skin.fontconfig_path'], $fontconfig_data);
}
// スタイルシートをリセット
unset($STYLE);
include $skin;
foreach ($STYLE as $K => $V) {
    if (empty($V)) {
        $STYLE[$K] = '';
    } elseif (strpos($K, 'fontfamily') !== false) {
        $STYLE[$K] = p2_correct_css_fontfamily($V);
    } elseif (strpos($K, 'color') !== false) {
        $STYLE[$K] = p2_correct_css_color($V);
    } elseif (strpos($K, 'background') !== false) {
        $STYLE[$K] = 'url("' . addslashes($V) . '")';
    }
}
示例#25
0
    // ルールを適用する
    applyRules();
    // ポストされた値 > 現在の値 > デフォルト値 の順で新しい設定を作成する
    $conf_save = array('.' => $_conf['p2version']);
    foreach ($conf_user_def as $k => $v) {
        if (array_key_exists($k, $_POST['conf_edit'])) {
            $conf_save[$k] = $_POST['conf_edit'][$k];
        } elseif (array_key_exists($k, $_conf)) {
            $conf_save[$k] = $_conf[$k];
        } else {
            $conf_save[$k] = $v;
        }
    }
    // シリアライズして保存
    FileCtl::make_datafile($_conf['conf_user_file']);
    if (FileCtl::file_write_contents($_conf['conf_user_file'], serialize($conf_save)) === false) {
        P2Util::pushInfoHtml('<p>×設定を更新保存できませんでした</p>');
    } else {
        P2Util::pushInfoHtml('<p>○設定を更新保存しました</p>');
        // 変更があれば、内部データも更新しておく
        $_conf = array_merge($_conf, $conf_user_def, $conf_save);
    }
    unset($conf_save);
    // }}}
    // {{{ デフォルトに戻すボタンが押されていたら
} elseif (!empty($_POST['submit_default'])) {
    if (file_exists($_conf['conf_user_file']) and unlink($_conf['conf_user_file'])) {
        P2Util::pushInfoHtml('<p>○設定をデフォルトに戻しました</p>');
        // 変更があれば、内部データも更新しておく
        $_conf = array_merge($_conf, $conf_user_def);
        if (is_array($conf_save)) {
示例#26
0
文件: BbsMap.php 项目: unpush/p2-php
 /**
  * 更新後のデータを書き込む
  *
  * @param   string  $path   書き込むファイルのパス
  * @param   array   $neolines   書き込むデータの配列
  * @return  void
  */
 private static function _writeData($path, $neolines)
 {
     if (is_array($neolines) && count($neolines) > 0) {
         $cont = implode('', $neolines);
         /*} elseif (is_scalar($neolines)) {
           $cont = strval($neolines);*/
     } else {
         $cont = '';
     }
     if (FileCtl::file_write_contents($path, $cont) === false) {
         p2die("cannot write file. ({$path})");
     }
 }
示例#27
0
        if (!empty($na_info['re'])) {
            $a_mode = !empty($na_info['ic']) ? '<regex:i>' : '<regex>';
        } elseif (!empty($na_info['ic'])) {
            $a_mode = '<i>';
        } else {
            $a_mode = '';
        }
        if (strlen($a_bbs) > 0) {
            $a_mode .= '<bbs>' . $a_bbs . '</bbs>';
        }
        if (strlen($a_tt) > 0) {
            $a_mode .= '<title>' . $a_tt . '</title>';
        }
        $newdata .= $a_mode . $a_word . "\t" . $a_time . "\t" . $a_hits . "\n";
    }
    if (FileCtl::file_write_contents($path, $newdata) !== FALSE) {
        P2Util::pushInfoHtml('<p>○設定を更新保存しました</p>');
    } else {
        P2Util::pushInfoHtml('<p>×設定を更新保存できませんでした</p>');
    }
    // }}}
    // {{{ ■デフォルトに戻すボタンが押されていたら
} elseif (!empty($_POST['submit_default'])) {
    if (@unlink($path)) {
        P2Util::pushInfoHtml('<p>○リストを空にしました</p>');
    } else {
        P2Util::pushInfoHtml('<p>×リストを空にできませんでした</p>');
    }
}
// }}}
// {{{ リスト読み込み
示例#28
0
文件: read_i.php 项目: 68/rep2iphone
// フィルタ指定がなければ前回保存を読み込む(フォームのデフォルト値で利用)
if (!isset($GLOBALS['word'])) {
    if (file_exists($cachefile) and $res_filter_cont = file_get_contents($cachefile)) {
        $res_filter = unserialize($res_filter_cont);
    }
    // フィルタ指定があれば
} else {
    // ボタンが押されていたなら、ファイルに設定を保存
    if (isset($_REQUEST['submit_filter'])) {
        // !isset($_REQUEST['idpopup'])
        FileCtl::make_datafile($cachefile, $_conf['p2_perm']);
        if ($res_filter) {
            $res_filter_cont = serialize($res_filter);
        }
        if ($res_filter_cont && empty($GLOBALS['popup_filter'])) {
            if (FileCtl::file_write_contents($cachefile, $res_filter_cont) === false) {
                die("Error: cannot write file.");
            }
        }
    }
}
// }}}
//==================================================================
// メイン
//==================================================================
if (!isset($aThread)) {
    $aThread =& new ThreadRead();
}
// lsのセット
if (!empty($ls)) {
    $aThread->ls = strip_tags(mb_convert_kana($ls, 'a'));
示例#29
0
/**
 * $subject_keys をシリアライズして保存する
 */
function saveSubjectKeys($subject_keys, $sb_keys_txt, $sb_keys_b_txt)
{
    global $_conf;
    //$GLOBALS['debug'] && $GLOBALS['profiler']->enterSection('saveSubjectKeys()');
    //if (file_exists($sb_keys_b_txt)) { unlink($sb_keys_b_txt); }
    if (empty($_REQUEST['norefresh']) && !empty($subject_keys)) {
        if (file_exists($sb_keys_txt)) {
            FileCtl::make_datafile($sb_keys_b_txt);
            copy($sb_keys_txt, $sb_keys_b_txt);
        } else {
            FileCtl::make_datafile($sb_keys_txt);
        }
        if ($sb_keys_cont = serialize($subject_keys)) {
            if (FileCtl::file_write_contents($sb_keys_txt, $sb_keys_cont) === false) {
                p2die('cannot write file.');
            }
        }
    }
    //$GLOBALS['debug'] && $GLOBALS['profiler']->leaveSection('saveSubjectKeys()');
    return true;
}
示例#30
0
 if (file_exists($_conf['expack.skin.setting_path'])) {
     $saved_skin_name = rtrim(file_get_contents($_conf['expack.skin.setting_path']));
     if (!preg_match('/^[0-9A-Za-z_\\-]+$/', $saved_skin_name)) {
         $saved_skin_name = null;
     }
 } else {
     FileCtl::make_datafile($_conf['expack.skin.setting_path'], $_conf['expack.skin.setting_perm']);
 }
 // リクエストで指定されたスキン名
 $new_skin_name = null;
 if (array_key_exists('skin', $_REQUEST) && is_string($_REQUEST['skin'])) {
     $new_skin_name = $_REQUEST['skin'];
     if (!preg_match('/^[0-9A-Za-z_\\-]+$/', $new_skin_name)) {
         $new_skin_name = null;
     } elseif ($new_skin_name != $saved_skin_name) {
         FileCtl::file_write_contents($_conf['expack.skin.setting_path'], $new_skin_name);
     }
 }
 // リクエストで指定された一時スキン名
 $tmp_skin_name = null;
 if (array_key_exists('tmp_skin', $_REQUEST) && is_string($_REQUEST['tmp_skin'])) {
     $tmp_skin_name = $_REQUEST['tmp_skin'];
     if (!preg_match('/^[0-9A-Za-z_\\-]+$/', $tmp_skin_name)) {
         $tmp_skin_name = null;
     }
 }
 // スキン検索
 foreach (array($tmp_skin_name, $new_skin_name, $saved_skin_name, $default_skin_name) as $skin_name) {
     if ($skin_name !== null) {
         if ($skin_name == $default_skin_name) {
             break;