Ejemplo n.º 1
0
Archivo: P2Util.php Proyecto: poppen/p2
 /**
  * @access  public
  * @return  array
  */
 function getThreadAbornKeys($host, $bbs)
 {
     $taborn_file = P2Util::getThreadAbornFile($host, $bbs);
     //$ta_num = 0;
     $ta_keys = array();
     if ($tabornlines = @file($taborn_file)) {
         //$ta_num = sizeof($tabornlines);
         foreach ($tabornlines as $l) {
             $data = explode('<>', rtrim($l));
             if ($data[1]) {
                 $ta_keys[$data[1]] = true;
             }
         }
     }
     return $ta_keys;
 }
Ejemplo n.º 2
0
/**
 * スレッドあぼーんをオンオフする関数
 *
 * $set は、0(解除), 1(追加), 2(トグル)
 *
 * @access  public
 * @return  boolean  実行成否
 */
function settaborn($host, $bbs, $key, $set)
{
    global $_conf, $title_msg, $info_msg;
    // {{{ key.idx 読み込む
    $idxfile = P2Util::getKeyIdxFilePath($host, $bbs, $key);
    $data[0] = null;
    // データがあるなら読み込む
    if (file_exists($idxfile)) {
        $lines = file($idxfile);
        $l = rtrim($lines[0]);
        $data = explode('<>', $l);
    }
    // }}}
    // p2_threads_aborn.idx のパス取得
    $taborn_idx = P2Util::getThreadAbornFile($host, $bbs);
    if (false === FileCtl::make_datafile($taborn_idx, $_conf['p2_perm'])) {
        return false;
    }
    if (false === ($taborn_lines = file($taborn_idx))) {
        return false;
    }
    $newlines = array();
    $aborn_attayo = false;
    $title_msg_pre = '';
    $info_msg_pre = '';
    if ($taborn_lines) {
        foreach ($taborn_lines as $line) {
            $line = rtrim($line);
            $lar = explode('<>', $line);
            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のないものは不正データ
            $newlines[] = $line;
        }
    }
    // 新規データ追加
    if ($set == 1 or !$aborn_attayo && $set == 2) {
        $newdata = "{$data['0']}<>{$key}<><><><><><><><>";
        $newlines ? array_unshift($newlines, $newdata) : ($newlines = array($newdata));
        $title_msg_pre = "○ あぼーん しますた";
        $info_msg_pre = "○ あぼーん しますた";
    }
    // 書き込む
    $cont = '';
    if ($newlines) {
        foreach ($newlines as $l) {
            $cont .= $l . "\n";
        }
    }
    if (false === file_put_contents($taborn_idx, $cont, LOCK_EX)) {
        p2die('cannot write file.');
        return false;
    }
    $GLOBALS['title_msg'] = $title_msg_pre;
    $GLOBALS['info_msg'] = $info_msg_pre;
    return true;
}
Ejemplo n.º 3
0
/**
 * スレッドあぼーんを複数一括解除する関数
 *
 * @access  public
 * @return  boolean  実行成否
 */
function settaborn_off($host, $bbs, $taborn_off_keys)
{
    if (!$taborn_off_keys) {
        return;
    }
    // p2_threads_aborn.idx のパス取得
    $taborn_idx = P2Util::getThreadAbornFile($host, $bbs);
    // p2_threads_aborn.idx がなければ
    if (!file_exists($taborn_idx)) {
        p2die("あぼーんリストが見つかりませんでした。");
        return false;
    }
    // p2_threads_aborn.idx 読み込み
    if (false === ($taborn_lines = file($taborn_idx))) {
        return false;
    }
    // 指定keyを削除
    foreach ($taborn_off_keys as $val) {
        $neolines = array();
        if ($taborn_lines) {
            foreach ($taborn_lines as $line) {
                $line = rtrim($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 (false === file_put_contents($taborn_idx, $cont, LOCK_EX)) {
        p2die('Error: cannot write file.');
        return false;
    }
    /*
    if (!$kaijo_attayo) {
        // echo "指定されたスレッドは既にあぼーんリストに載っていないようです。";
    } else {
        // echo "あぼーん解除、完了しました。";
    }
    */
    return true;
}
Ejemplo n.º 4
0
 /**
  * readList
  *
  * @access  public
  * @return  array
  */
 function readList()
 {
     global $_conf;
     $GLOBALS['debug'] && $GLOBALS['profiler']->enterSection('readList()');
     $lines = array();
     // spmodeの場合
     if ($this->spmode) {
         // ローカルの履歴ファイル 読み込み
         if ($this->spmode == "recent") {
             file_exists($_conf['recent_file']) and $lines = file($_conf['recent_file']);
             // ローカルの書き込み履歴ファイル 読み込み
         } elseif ($this->spmode == "res_hist") {
             file_exists($_conf['res_hist_idx']) and $lines = file($_conf['res_hist_idx']);
             // ローカルのお気にファイル 読み込み
         } elseif ($this->spmode == "fav") {
             file_exists($_conf['favlist_file']) and $lines = file($_conf['favlist_file']);
             // ニュース系サブジェクト読み込み
         } elseif ($this->spmode == "news") {
             unset($news);
             $news[] = array(host => "news2.2ch.net", bbs => "newsplus");
             // ニュース速報+
             $news[] = array(host => "news2.2ch.net", bbs => "liveplus");
             // ニュース実況
             $news[] = array(host => "book.2ch.net", bbs => "bizplus");
             // ビジネスニュース速報+
             $news[] = array(host => "live2.2ch.net", bbs => "news");
             // ニュース速報
             $news[] = array(host => "news3.2ch.net", bbs => "news2");
             // ニュース議論
             foreach ($news as $n) {
                 require_once P2_LIB_DIR . '/SubjectTxt.php';
                 $aSubjectTxt = new SubjectTxt($n['host'], $n['bbs']);
                 if (is_array($aSubjectTxt->subject_lines)) {
                     foreach ($aSubjectTxt->subject_lines as $l) {
                         if (preg_match("/^([0-9]+)\\.(dat|cgi)(,|<>)(.+) ?(\\(|()([0-9]+)(\\)|))/", $l, $matches)) {
                             //$this->isonline = true;
                             unset($al);
                             $al['key'] = $matches[1];
                             $al['ttitle'] = rtrim($matches[4]);
                             $al['rescount'] = $matches[6];
                             $al['host'] = $n['host'];
                             $al['bbs'] = $n['bbs'];
                             $lines[] = $al;
                         }
                     }
                 }
             }
             // p2_threads_aborn.idx 読み込み
         } elseif ($this->spmode == 'taborn') {
             $file = P2Util::getThreadAbornFile($this->host, $this->bbs);
             if (file_exists($file)) {
                 $lines = file($file);
             }
             // {{{ spmodeがdat倉庫の場合 @todo ページング用に数を制限できるようにしたい
         } elseif ($this->spmode == 'soko') {
             $dat_bbs_dir = P2Util::datDirOfHostBbs($this->host, $this->bbs, false);
             $idx_bbs_dir = P2Util::idxDirOfHostBbs($this->host, $this->bbs, false);
             $dat_pattern = '/([0-9]+)\\.dat$/';
             $idx_pattern = '/([0-9]+)\\.idx$/';
             // {{{ datログディレクトリを走査して孤立datにidx付加する
             $GLOBALS['debug'] && $GLOBALS['profiler']->enterSection('dat');
             if ($cdir = dir($dat_bbs_dir)) {
                 // or die ("ログディレクトリがないよ!");
                 while ($entry = $cdir->read()) {
                     if (preg_match($dat_pattern, $entry, $matches)) {
                         $theidx = $idx_bbs_dir . DIRECTORY_SEPARATOR . $matches[1] . '.idx';
                         if (!file_exists($theidx)) {
                             if ($datlines = file($dat_bbs_dir . DIRECTORY_SEPARATOR . $entry)) {
                                 $firstdatline = rtrim($datlines[0]);
                                 if (strstr($firstdatline, '<>')) {
                                     $datline_sepa = '<>';
                                 } else {
                                     $datline_sepa = ',';
                                 }
                                 $d = explode($datline_sepa, $firstdatline);
                                 $atitle = $d[4];
                                 $gotnum = sizeof($datlines);
                                 $readnum = $gotnum;
                                 $anewline = $readnum + 1;
                                 $data = array($atitle, $matches[1], '', $gotnum, '', $readnum, '', '', '', $anewline, '', '', '');
                                 P2Util::recKeyIdx($theidx, $data);
                             }
                         }
                         // array_push($lines, $idl[0]);
                     }
                 }
                 $cdir->close();
             }
             $GLOBALS['debug'] && $GLOBALS['profiler']->leaveSection('dat');
             // }}}
             // {{{ idxログディレクトリを走査してidx情報を抽出してリスト化
             // オンラインも倉庫もまとめて抽出している。オンラインを外すのは subject.php で行っている。
             $GLOBALS['debug'] && $GLOBALS['profiler']->enterSection('idx');
             if ($cdir = dir($idx_bbs_dir)) {
                 // or die ("ログディレクトリがないよ!");
                 $limit = 1000;
                 // ひとまず簡易制限
                 $i = 0;
                 while ($entry = $cdir->read()) {
                     if (preg_match($idx_pattern, $entry)) {
                         if ($idl = file($idx_bbs_dir . DIRECTORY_SEPARATOR . $entry)) {
                             array_push($lines, $idl[0]);
                             $i++;
                             if ($i >= $limit) {
                                 P2Util::pushInfoHtml("<p>p2 info: idxログ数が、表\示処理可能\数である{$limit}件をオーバーしています。</p>");
                                 break;
                             }
                         }
                     }
                 }
                 $cdir->close();
             }
             $GLOBALS['debug'] && $GLOBALS['profiler']->leaveSection('idx');
             // }}}
             // }}}
             // スレの殿堂の場合  // p2_palace.idx 読み込み
         } elseif ($this->spmode == "palace") {
             $palace_idx = $_conf['pref_dir'] . '/p2_palace.idx';
             file_exists($palace_idx) and $lines = file($palace_idx);
         }
         // オンライン上の subject.txt を読み込む(spmodeでない場合)
     } else {
         require_once P2_LIB_DIR . '/SubjectTxt.php';
         $aSubjectTxt = new SubjectTxt($this->host, $this->bbs);
         $lines = $aSubjectTxt->subject_lines;
     }
     $GLOBALS['debug'] && $GLOBALS['profiler']->leaveSection('readList()');
     return $lines;
 }