Ejemplo n.º 1
0
/**
 * 指定したキーのスレッドログ(idx (,dat))を削除する
 *
 * 通常は、この関数を直接呼び出すことはない。deleteLogs() から呼び出される。
 *
 * @see deleteLogs()
 * @return  integer|false  削除できたら1, 削除対象がなければ2を返す。失敗があればfalse。
 */
function deleteThisKey($host, $bbs, $key)
{
    global $_conf;
    $anidx = P2Util::idxDirOfHostBbs($host, $bbs) . $key . '.idx';
    $adat = P2Util::datDirOfHostBbs($host, $bbs) . $key . '.dat';
    // Fileの削除処理
    // idx(個人用設定)
    if (file_exists($anidx)) {
        if (unlink($anidx)) {
            $deleted_flag = true;
        } else {
            $failed_flag = true;
        }
    }
    // datの削除処理
    if (file_exists($adat)) {
        if (unlink($adat)) {
            $deleted_flag = true;
        } else {
            $failed_flag = true;
        }
    }
    // 失敗があれば
    if (!empty($failed_flag)) {
        return false;
        // 削除できたら
    } elseif (!empty($deleted_flag)) {
        return 1;
        // 削除対象がなければ
    } else {
        return 2;
    }
}
Ejemplo n.º 2
0
 /**
  * コンストラクタ
  */
 public function __construct($host, $bbs)
 {
     $this->host = $host;
     $this->bbs = $bbs;
     $this->storage = 'file';
     $this->subject_file = P2Util::datDirOfHostBbs($host, $bbs) . 'subject.txt';
     $this->subject_url = 'http://' . $host . '/' . $bbs . '/subject.txt';
     // したらばのlivedoor移転に対応。読込先をlivedoorとする。
     $this->subject_url = P2Util::adjustHostJbbs($this->subject_url);
     // subject.txtをダウンロード&セットする
     $this->dlAndSetSubject();
 }
Ejemplo n.º 3
0
 /**
  * @constructor
  */
 function SettingTxt($host, $bbs)
 {
     $this->cache_interval = 60 * 60 * 12;
     // キャッシュは12時間有効
     $this->host = $host;
     $this->bbs = $bbs;
     $dat_bbs_dir_s = P2Util::datDirOfHostBbs($this->host, $this->bbs);
     $this->setting_txt = $dat_bbs_dir_s . 'SETTING.TXT';
     $this->setting_srd = $dat_bbs_dir_s . 'p2_kb_setting.srd';
     $this->url = 'http://' . $this->host . '/' . $this->bbs . '/SETTING.TXT';
     // したらばのlivedoor移転に対応。読込先をlivedoorとする。
     //$this->url = P2Util::adjustHostJbbsShitaraba($this->url);
     // SETTING.TXT をダウンロード&セットする
     $this->dlAndSetData();
 }
Ejemplo n.º 4
0
 /**
  * コンストラクタ
  */
 public function __construct($host, $bbs)
 {
     $this->_cache_interval = 60 * 60 * 12;
     // キャッシュは12時間有効
     $this->_host = $host;
     $this->_bbs = $bbs;
     $dat_host_bbs_dir_s = P2Util::datDirOfHostBbs($host, $bbs);
     $this->_setting_txt = $dat_host_bbs_dir_s . 'SETTING.TXT';
     $this->_setting_srd = $dat_host_bbs_dir_s . 'p2_kb_setting.srd';
     $this->_url = 'http://' . $host . '/' . $bbs . '/SETTING.TXT';
     //$this->_url = P2Util::adjustHostJbbs($this->_url); // したらばのlivedoor移転に対応。読込先をlivedoorとする。
     $this->setting_array = array();
     // SETTING.TXT をダウンロード&セットする
     $this->dlAndSetData();
 }
Ejemplo n.º 5
0
Archivo: Thread.php Proyecto: poppen/p2
 /**
  * Set Path info
  *
  * @access  public
  * @return  void
  */
 function setThreadPathInfo($host, $bbs, $key)
 {
     $GLOBALS['debug'] && $GLOBALS['profiler']->enterSection('setThreadPathInfo()');
     if (preg_match('/[<>]/', $host) || preg_match('/[<>]/', $bbs) || preg_match('/[<>]/', $key)) {
         trigger_error(__FUNCTION__, E_USER_WARNING);
         die('Error: ' . __FUNCTION__);
     }
     $this->host = $host;
     $this->bbs = $bbs;
     $this->key = $key;
     $this->keydat = P2Util::datDirOfHostBbs($this->host, $this->bbs) . $this->key . '.dat';
     $this->keyidx = P2Util::getKeyIdxFilePath($this->host, $this->bbs, $this->key);
     $GLOBALS['debug'] && $GLOBALS['profiler']->leaveSection('setThreadPathInfo()');
 }
Ejemplo n.º 6
0
 /**
  * subject.txtを一括ダウンロード&保存する
  *
  * @param array|string $subjects
  * @param bool $force
  * @return void
  */
 public static function fetchSubjectTxt($subjects, $force = false)
 {
     global $_conf;
     // {{{ ダウンロード対象を設定
     // お気に板等の.idx形式のファイルをパース
     if (is_string($subjects)) {
         $lines = FileCtl::file_read_lines($subjects, FILE_IGNORE_NEW_LINES);
         if (!$lines) {
             return;
         }
         $subjects = array();
         foreach ($lines as $l) {
             $la = explode('<>', $l);
             if (count($la) < 12) {
                 continue;
             }
             $host = $la[10];
             $bbs = $la[11];
             if ($host === '' || $bbs === '') {
                 continue;
             }
             $id = $host . '<>' . $bbs;
             if (isset($subjects[$id])) {
                 continue;
             }
             $subjects[$id] = array($host, $bbs);
         }
         // [host, bbs] の連想配列を検証
     } elseif (is_array($subjects)) {
         $originals = $subjects;
         $subjects = array();
         foreach ($originals as $s) {
             if (!is_array($s) || !isset($s['host']) || !isset($s['bbs'])) {
                 continue;
             }
             $id = $s['host'] . '<>' . $s['bbs'];
             if (isset($subjects[$id])) {
                 continue;
             }
             $subjects[$id] = array($s['host'], $s['bbs']);
         }
         // 上記以外
     } else {
         return;
     }
     if (!count($subjects)) {
         return;
     }
     // }}}
     // {{{ キューをセットアップ
     // キューおよびその他の変数を初期化
     $queue = new P2HttpRequestQueue();
     $hosts = array();
     $time = time() - $_conf['sb_dl_interval'];
     $eucjp2sjis = null;
     // 各subject.txtへのリクエストをキューに追加
     foreach ($subjects as $subject) {
         list($host, $bbs) = $subject;
         $file = P2Util::datDirOfHostBbs($host, $bbs) . 'subject.txt';
         if (!$force && file_exists($file) && filemtime($file) > $time) {
             continue;
         }
         $url = 'http://' . $host . '/' . $bbs . '/subject.txt';
         if (P2Util::isHostJbbsShitaraba($host) || P2Util::isHostBe2chNet($host)) {
             if ($eucjp2sjis === null) {
                 $eucjp2sjis = new P2HttpCallback_SaveEucjpAsSjis();
             }
             $req = new P2HttpGet($url, $file, null, $eucjp2sjis);
         } else {
             $req = new P2HttpGet($url, $file);
         }
         // 同一ホストに対しての同時接続は MAX_REQUESTS_PER_HOST まで
         if (!isset($hosts[$host])) {
             $hosts[$host] = new P2HttpRequestQueue();
             $queue->push($req);
         } elseif (count($hosts[$host]) < self::MAX_REQUESTS_PER_HOST) {
             $queue->push($req);
         } else {
             $hosts[$host]->pop()->setNext($req);
         }
         $hosts[$host]->push($req);
     }
     // }}}
     // リクエストを送信
     if (count($queue)) {
         self::send(new HttpRequestPool(), $queue);
         clearstatcache();
     }
 }
Ejemplo n.º 7
0
     }
     $host = $_POST['host'];
     $bbs = $_POST['bbs'];
     //if ($_POST['key'] == 'auto') {
     $key = preg_replace('/\\.(dat|html?)$/', '', $_FILES['dat_file']['name']);
     /*} elseif (preg_match('/^[1-9][0-9]+$/', $_POST['key'])) {
           $key = $_POST['key'];
           if ($key != preg_replace('/\.(dat|html?)$/', '', $_FILES['dat_file']['name'])) {
               $is_error = TRUE;
               P2Util::pushInfoHtml('<p>Error: アップロードされたdatのファイル名とスレッドキーがマッチしません。</p>');
           }
       } else {
           $is_error = TRUE;
           P2Util::pushInfoHtml('<p>Error: スレッドキーの指定が変です。</p>');
       }*/
     $dat_path = P2Util::datDirOfHostBbs($host, $bbs) . $key . '.dat';
     // アップロード失敗のとき
 } else {
     $is_error = TRUE;
     // エラーメッセージは http://jp.php.net/manual/ja/features.file-upload.errors.php からコピペ
     switch ($_FILES['dat_file']['error']) {
         case UPLOAD_ERR_INI_SIZE:
             P2Util::pushInfoHtml('<p>Error: アップロードされたファイルは、php.ini の upload_max_filesize ディレクティブの値を超えています。</p>');
             break;
         case UPLOAD_ERR_FORM_SIZE:
             P2Util::pushInfoHtml('<p>Error: アップロードされたファイルは、HTMLフォームで指定された MAX_FILE_SIZE を超えています。</p>');
             break;
         case UPLOAD_ERR_PARTIAL:
             P2Util::pushInfoHtml('<p>Error: アップロードされたファイルは一部のみしかアップロードされていません。</p>');
             break;
         case UPLOAD_ERR_NO_FILE:
Ejemplo n.º 8
0
 /**
  * datの保存ディレクトリを返す
  *
  * @param bool $dir_sep
  * @return string
  * @see P2Util::datDirOfHost(), ThreadList::getDatDir()
  */
 public function getDatDir($dir_sep = true)
 {
     return P2Util::datDirOfHostBbs($this->host, $this->bbs, $dir_sep);
 }
Ejemplo n.º 9
0
Archivo: P2Util.php Proyecto: poppen/p2
 /**
  * @access  private
  * @return  string
  */
 function getSamba24CacheFile($host, $bbs)
 {
     return P2Util::datDirOfHostBbs($host, $bbs) . 'samba24.txt';
 }
Ejemplo n.º 10
0
 /**
  * @access  private
  * @return  void
  */
 function setSubjectFile($host, $bbs)
 {
     $this->subject_file = P2Util::datDirOfHostBbs($host, $bbs) . 'subject.txt';
 }
Ejemplo n.º 11
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;
 }