Ejemplo n.º 1
0
/**
 * RSSをダウンロードし、パース結果を返す
 */
function p2GetRSS($remotefile, $atom = 0)
{
    global $_conf;
    $refresh = !empty($_GET['refresh']) || !empty($_POST['refresh']);
    $localpath = rss_get_save_path($remotefile);
    if (PEAR::isError($localpath)) {
        P2Util::pushInfoHtml('<p>' . $localpath->getMessage() . '</p>');
        return $localpath;
    }
    // 保存用ディレクトリがなければつくる
    if (!is_dir(dirname($localpath))) {
        FileCtl::mkdirFor($localpath);
    }
    // If-Modified-Sinceつきでダウンロード(ファイルが無いか、古いか、強制リロードのとき)
    if (!file_exists($localpath) || $refresh || filemtime($localpath) < time() - $_conf['expack.rss.check_interval'] * 60) {
        $dl = P2Util::fileDownload($remotefile, $localpath, true, 301);
        if ($dl->isSuccess()) {
            chmod($localpath, $_conf['expack.rss.setting_perm']);
        }
    }
    // キャッシュが更新されなかったか、ダウンロード成功ならRSSをパース
    if (file_exists($localpath) && (!isset($dl) || $dl->isSuccess())) {
        if ($atom) {
            $atom = isset($dl) && $dl->code == 200 ? 2 : 1;
        }
        $rss = p2ParseRSS($localpath, $atom);
        return $rss;
    } else {
        return $dl;
    }
}
Ejemplo n.º 2
0
/**
 * チャットちゃんねる cha2.net の dat を読んで保存する関数
 * (差分取得には未対応)
 * ※2ch互換として読み込んでいるので現在この関数は利用はしていない。@see TreadRead->downloadDat()
 *
 * @access  public
 * @return  boolean
 */
function downloadDatCha2(&$ThreadRead)
{
    // {{{ 既得datの取得レス数が適性かどうかを念のためチェック
    if (file_exists($ThreadRead->keydat)) {
        $dls = file($ThreadRead->keydat);
        if (sizeof($dls) != $ThreadRead->gotnum) {
            // echo 'bad size!<br>';
            unlink($ThreadRead->keydat);
            $ThreadRead->gotnum = 0;
        }
    } else {
        $ThreadRead->gotnum = 0;
    }
    // }}}
    if ($ThreadRead->gotnum == 0) {
        $file_append = false;
        $START = 1;
    } else {
        $file_append = true;
        $START = $ThreadRead->gotnum + 1;
    }
    // チャットちゃんねる
    $cha2url = "http://{$ThreadRead->host}/cgi-bin/{$ThreadRead->bbs}/dat/{$ThreadRead->key}.dat";
    $datfile = $ThreadRead->keydat;
    FileCtl::mkdirFor($datfile);
    $cha2url_res = P2Util::fileDownload($cha2url, $datfile);
    if (!$cha2url_res or !$cha2url_res->is_success()) {
        $ThreadRead->diedat = true;
        return false;
    }
    $ThreadRead->isonline = true;
    return true;
}
Ejemplo n.º 3
0
 /**
  * Wiki:Last-Modifiedをチェックしてキャッシュする
  * time:チェックしない期間(unixtime)
  */
 function cacheDownload($url, $path, $time = 0)
 {
     global $_conf;
     $filetime = @filemtime($path);
     // キャッシュ有効期間ならチェックしない
     if ($filetime > 0 && $filetime > time() - $time) {
         return;
     }
     if (!class_exists('HTTP_Request', false)) {
         require 'HTTP/Request.php';
     }
     $req =& new HTTP_Request($url, array('timeout' => $_conf['fsockopen_time_limit']));
     $req->setMethod('HEAD');
     $now = time();
     $req->sendRequest();
     $unixtime = strtotime($req->getResponseHeader('Last-Modified'));
     // 新しければ取得
     if ($unixtime > $filetime) {
         P2Util::fileDownload($url, $path);
         // 最終更新日時を設定
         // touch($path, $unixtime);
     } else {
         // touch($path, $now);
     }
     touch($path, $now);
 }
Ejemplo n.º 4
0
 /**
  * Wiki:Last-Modifiedをチェックしてキャッシュする
  * time:チェックしない期間(unixtime)
  */
 public static function cacheDownload($url, $path, $time = 0)
 {
     $filetime = @filemtime($path);
     // キャッシュ有効期間ならダウンロードしない
     if ($filetime !== false && $filetime > time() - $time) {
         return;
     }
     // 新しければ取得
     P2Util::fileDownload($url, $path);
 }
Ejemplo n.º 5
0
/**
 * オンライン上のrep2-expack最新版をチェックする
 *
 * @return string HTML
 */
function checkUpdatan()
{
    global $_conf, $p2web_url_r, $expack_url_r, $expack_dl_url_r, $expack_hist_url_r;
    $no_p2status_dl_flag = false;
    $ver_txt_url = $_conf['expack.web_url'] . 'version.txt';
    $cachefile = P2Util::cacheFileForDL($ver_txt_url);
    FileCtl::mkdirFor($cachefile);
    if (file_exists($cachefile)) {
        // キャッシュの更新が指定時間以内なら
        if (filemtime($cachefile) > time() - $_conf['p2status_dl_interval'] * 86400) {
            $no_p2status_dl_flag = true;
        }
    }
    if (empty($no_p2status_dl_flag)) {
        P2Util::fileDownload($ver_txt_url, $cachefile);
    }
    $ver_txt = FileCtl::file_read_lines($cachefile, FILE_IGNORE_NEW_LINES);
    $update_ver = $ver_txt[0];
    $kita = 'キタ━━━━(゚∀゚)━━━━!!!!!!';
    //$kita = 'キタ*・゚゚・*:.。..。.:*・゚(゚∀゚)゚・*:.。. .。.:*・゚゚・*!!!!!';
    $newversion_found_html = '';
    if ($update_ver && version_compare($update_ver, $_conf['p2version'], '>')) {
        $newversion_found_html = <<<EOP
<div class="kakomi">
    {$kita}<br>
    オンライン上に 拡張パック の最新バージョンを見つけますた。<br>
    rep2-expack rev.{$update_ver} → <a href="{$expack_dl_url_r}"{$_conf['ext_win_target_at']}>ダウンロード</a> / <a href="{$expack_hist_url_r}"{$_conf['ext_win_target_at']}>更新記録</a>
</div>
<hr class="invisible">
EOP;
    }
    return $newversion_found_html;
}
Ejemplo n.º 6
0
 /**
  * スレッドのdatをダウンロードし、保存する
  *
  * @param ThreadRead $thread
  * @return bool
  */
 public static function invoke(ThreadRead $thread)
 {
     global $_conf;
     // {{{ 既得datの取得レス数が適正かどうかを念のためチェック
     if (file_exists($thread->keydat)) {
         $dls = FileCtl::file_read_lines($thread->keydat);
         if (!$dls || count($dls) != $thread->gotnum) {
             // echo 'bad size!<br>';
             unlink($thread->keydat);
             $thread->gotnum = 0;
         }
     } else {
         $thread->gotnum = 0;
     }
     // }}}
     // {{{ offlaw.cgiからdatをダウンロード
     $host = $thread->host;
     $bbs = $thread->bbs;
     $key = $thread->key;
     if ($thread->gotnum == 0) {
         $option = '';
         $append = false;
     } else {
         $option = sprintf('%d-', $thread->gotnum + 1);
         $append = true;
     }
     // http://[SERVER]/bbs/offlaw.cgi/[BBS]/[KEY]/[OPTION];
     $url = "http://{$host}/bbs/offlaw.cgi/{$bbs}/{$key}/{$option}";
     $tempfile = $thread->keydat . '.tmp';
     FileCtl::mkdirFor($tempfile);
     if ($append) {
         touch($tempfile, filemtime($thread->keydat));
     } elseif (file_exists($tempfile)) {
         unlink($tempfile);
     }
     $response = P2Util::fileDownload($url, $tempfile);
     if ($response->isError()) {
         if (304 != $response->code) {
             $thread->diedat = true;
         }
         return false;
     }
     // }}}
     // {{{ ダウンロードした各行をチェックしつつローカルdatに書き込み
     $lines = file($tempfile);
     unlink($tempfile);
     if ($append) {
         $fp = fopen($thread->keydat, 'ab');
     } else {
         $fp = fopen($thread->keydat, 'wb');
     }
     if (!$fp) {
         p2die("cannot write file. ({$thread->keydat})");
     }
     flock($fp, LOCK_EX);
     foreach ($lines as $i => $line) {
         // 取得済みレス数をインクリメント
         $thread->gotnum++;
         // 行を分解、要素数チェック (厳密には === 6)
         $lar = explode('<>', rtrim($line));
         if (count($lar) >= 5) {
             // レス番号は保存しないので取り出す
             $resnum = (int) array_shift($lar);
             // レス番号と取得済みレス数が異なっていたらあぼーん扱い
             while ($thread->gotnum < $resnum) {
                 $abn = "あぼーん<>あぼーん<>あぼーん<>あぼーん<>";
                 if ($thread->gotnum == 1) {
                     $abn .= $lar[4];
                     // スレタイトル
                 }
                 $abn .= "\n";
                 fwrite($fp, $abn);
                 $thread->gotnum++;
             }
             // 行を書き込む
             fwrite($fp, implode('<>', $lar) . "\n");
         } else {
             $thread->gotnum--;
             $lineno = $i + 1;
             P2Util::pushInfoHtml("<p>rep2 info: dat書式エラー: line {$lineno} of {$url}.</p>");
             break;
         }
     }
     flock($fp, LOCK_UN);
     fclose($fp);
     // }}}
     $thread->isonline = true;
     return true;
 }
Ejemplo n.º 7
0
/**
 * まちBBSの read.cgi を読んで datに保存する関数
 *
 * @access  public
 * @return  boolean
 */
function downloadDatMachiBbs(&$ThreadRead)
{
    // {{{ 既得datの取得レス数が適性かどうかを念のためチェック
    if (file_exists($ThreadRead->keydat)) {
        $dls = file($ThreadRead->keydat);
        if (sizeof($dls) != $ThreadRead->gotnum) {
            // echo 'bad size!<br>';
            unlink($ThreadRead->keydat);
            $ThreadRead->gotnum = 0;
        }
    } else {
        $ThreadRead->gotnum = 0;
    }
    // }}}
    if ($ThreadRead->gotnum == 0) {
        $file_append = false;
        $START = 1;
    } else {
        $file_append = true;
        $START = $ThreadRead->gotnum + 1;
    }
    // まちBBS
    $machiurl = "http://{$ThreadRead->host}/bbs/read.cgi?BBS={$ThreadRead->bbs}&KEY={$ThreadRead->key}&START={$START}";
    $tempfile = $ThreadRead->keydat . '.html.temp';
    FileCtl::mkdirFor($tempfile);
    $machiurl_res = P2Util::fileDownload($machiurl, $tempfile);
    if (!$machiurl_res or !$machiurl_res->is_success()) {
        $ThreadRead->diedat = true;
        return false;
    }
    $mlines = file($tempfile);
    // 一時ファイルを削除する
    unlink($tempfile);
    // (まちBBS)<html>error</html>
    if (trim($mlines[0]) == '<html>error</html>') {
        $ThreadRead->pushDownloadDatErrorMsgHtml('error' . '<br>');
        $ThreadRead->diedat = true;
        return false;
    }
    // {{{ DATを書き込む
    $latest_num = 0;
    if ($mdatlines = _machiHtmltoDatLines($mlines, $latest_num)) {
        $cont = '';
        for ($i = $START; $i <= $latest_num; $i++) {
            if (isset($mdatlines[$i])) {
                $cont .= $mdatlines[$i];
            } else {
                $cont .= "あぼーん<>あぼーん<>あぼーん<>あぼーん<>\n";
            }
        }
        $done = false;
        if ($fp = fopen($ThreadRead->keydat, 'ab+')) {
            flock($fp, LOCK_EX);
            if (false !== fwrite($fp, $cont)) {
                $done = true;
            }
            flock($fp, LOCK_UN);
            fclose($fp);
        }
        if (!$done) {
            trigger_error('cannot write file (' . $ThreadRead->keydat . ')', E_USER_WARNING);
            die('Error: cannot write file.');
        }
    }
    // }}}
    $ThreadRead->isonline = true;
    return true;
}
Ejemplo n.º 8
0
 /**
  * オンライン板リストを読込む
  */
 public static function read_brd_online()
 {
     global $_conf;
     $brd_menus = array();
     $isNewDL = false;
     if ($_conf['brdfile_online']) {
         $cachefile = P2Util::cacheFileForDL($_conf['brdfile_online']);
         $noDL = false;
         $read_html_flag = false;
         // キャッシュがある場合
         if (file_exists($cachefile . '.p2.brd')) {
             // norefreshならDLしない
             if (!empty($_GET['nr'])) {
                 $noDL = true;
                 // キャッシュの更新が指定時間以内ならDLしない
             } elseif (@filemtime($cachefile . '.p2.brd') > time() - 60 * 60 * $_conf['menu_dl_interval']) {
                 $noDL = true;
             }
         }
         // DLしない
         if ($noDL) {
             // DLする
         } else {
             //echo "DL!<br>";//
             $brdfile_online_res = P2Util::fileDownload($_conf['brdfile_online'], $cachefile);
             if ($brdfile_online_res->isSuccess() && $brdfile_online_res->code != 304) {
                 $isNewDL = true;
             }
         }
         // html形式なら
         if (preg_match('/html?$/', $_conf['brdfile_online'])) {
             // 更新されていたら新規キャッシュ作成
             if ($isNewDL) {
                 // 検索結果がキャッシュされるのを回避
                 if (isset($GLOBALS['word']) && strlen($GLOBALS['word']) > 0) {
                     $_tmp = array($GLOBALS['word'], $GLOBALS['word_fm'], $GLOBALS['words_fm']);
                     $GLOBALS['word'] = null;
                     $GLOBALS['word_fm'] = null;
                     $GLOBALS['words_fm'] = null;
                 } else {
                     $_tmp = null;
                 }
                 //echo "NEW!<br>"; //
                 $aBrdMenu = new BrdMenu();
                 // クラス BrdMenu のオブジェクトを生成
                 $aBrdMenu->makeBrdFile($cachefile);
                 // .p2.brdファイルを生成
                 $brd_menus[] = $aBrdMenu;
                 unset($aBrdMenu);
                 if ($_tmp) {
                     list($GLOBALS['word'], $GLOBALS['word_fm'], $GLOBALS['words_fm']) = $_tmp;
                     $brd_menus = array();
                 } else {
                     $read_html_flag = true;
                 }
             }
             if (file_exists($cachefile . '.p2.brd')) {
                 $cache_brd = $cachefile . '.p2.brd';
             } else {
                 $cache_brd = $cachefile;
             }
         } else {
             $cache_brd = $cachefile;
         }
         if (!$read_html_flag) {
             if ($data = FileCtl::file_read_lines($cache_brd)) {
                 $aBrdMenu = new BrdMenu();
                 // クラス BrdMenu のオブジェクトを生成
                 $aBrdMenu->setBrdMatch($cache_brd);
                 // パターンマッチ形式を登録
                 $aBrdMenu->setBrdList($data);
                 // カテゴリーと板をセット
                 if ($aBrdMenu->num) {
                     $brd_menus[] = $aBrdMenu;
                 } else {
                     P2Util::pushInfoHtml("<p>p2 error: {$cache_brd} から板メニューを生成することはできませんでした。</p>");
                 }
                 unset($data, $aBrdMenu);
             } else {
                 P2Util::pushInfoHtml("<p>p2 error: {$cachefile} は読み込めませんでした。</p>");
             }
         }
     }
     return $brd_menus;
 }
Ejemplo n.º 9
0
Archivo: title.php Proyecto: poppen/p2
/**
 * オンライン上のrep2最新版をチェックする
 *
 * @return  string  HTML
 */
function _checkUpdatan()
{
    global $_conf, $p2web_url_r;
    $no_p2status_dl_flag = false;
    $ver_txt_url = $_conf['p2web_url'] . 'p2status.txt';
    $cachefile = P2Util::cacheFileForDL($ver_txt_url);
    FileCtl::mkdirFor($cachefile);
    if (file_exists($cachefile)) {
        // キャッシュの更新が指定時間以内なら
        if (filemtime($cachefile) > time() - $_conf['p2status_dl_interval'] * 60) {
            $no_p2status_dl_flag = true;
        }
    }
    if (empty($no_p2status_dl_flag)) {
        P2Util::fileDownload($ver_txt_url, $cachefile);
    }
    $ver_txt = file($cachefile);
    $update_ver = $ver_txt[0];
    $kita = 'キタ━━━━(゚∀゚)━━━━!!!!!!';
    //$kita = 'キタ*・゚゚・*:.。..。.:*・゚(゚∀゚)゚・*:.。. .。.:*・゚゚・*!!!!!';
    $newversion_found_html = '';
    if ($update_ver && version_compare($update_ver, $_conf['p2version'], '>')) {
        $update_ver_hs = hs($update_ver);
        $p2web_url_r_hs = hs($p2web_url_r);
        $newversion_found_html = <<<EOP
<div class="kakomi">
    {$kita}<br>
    オンライン上に rep2 の最新バージョンを見つけますた。<br>
    rep2<!-- version {$update_ver_hs}--> → <a href="{$p2web_url_r_hs}cgi/dl/dl.php?dl=p2">ダウンロード</a> / <a href="{$p2web_url_r_hs}p2/doc/ChangeLog.txt"{$_conf['ext_win_target_at']}>更新記録</a>
</div>
<hr class="invisible">
EOP;
    }
    return $newversion_found_html;
}
Ejemplo n.º 10
0
Archivo: P2Util.php Proyecto: poppen/p2
 /**
  * @access  private
  * @return  integer|false
  */
 function getSamba24Time($host, $bbs)
 {
     // http://pc11.2ch.net/software/
     $url = sprintf('http://%s/%s/index.html', $host, $bbs);
     $cachefile = P2Util::cacheFileForDL($url);
     $r = P2Util::fileDownload($url, $cachefile, array('disp_error' => true, 'use_tmp_file' => true));
     if (!$r->is_success()) {
         return false;
     }
     // <br><a href="http://www.2ch.net/">2ちゃんねる</a> BBS.CGI - 2007/11/14 (SpeedyCGI) +<a href="http://bbq.uso800.net/">BBQ</a> +BBM +Rock54/54M +Samba24=30 +ByeSaru=ON<br> ページのおしまいだよ。。と</body></html>
     //$lines = preg_split("/\n/", trim($html));
     if (!($lines = file($cachefile))) {
         return false;
     }
     $count = count($lines);
     $lasti = $count - 1;
     if (preg_match('/ \\+Samba24=(\\d+) /', $lines[$lasti], $m)) {
         return (int) $m[1];
     }
     return 0;
 }
Ejemplo n.º 11
0
Archivo: BrdCtl.php Proyecto: poppen/p2
 /**
  * オンライン板リストを読み込む
  *
  * @static
  * @access  private
  * @return  array
  */
 function readBrdOnline()
 {
     global $_conf;
     if (!$_conf['brdfile_online']) {
         return array();
     }
     $brd_menus = array();
     $cachefile = P2Util::cacheFileForDL($_conf['brdfile_online']);
     $noDL = false;
     $isNewDL = false;
     $read_html_flag = false;
     $p2brdfile = BrdCtl::getP2BrdFile($cachefile);
     // キャッシュがある場合
     if (file_exists($p2brdfile)) {
         // norefreshならDLしない
         if (!empty($_GET['nr'])) {
             $noDL = true;
             // キャッシュの更新が指定時間以内ならDLしない
         } elseif (filemtime($p2brdfile) > time() - 60 * 60 * $_conf['menu_dl_interval']) {
             $noDL = true;
         }
     }
     // DLしない
     if ($noDL) {
         // DLする
     } else {
         //echo "DL!<br>";//
         $brdfile_online_res = P2Util::fileDownload($_conf['brdfile_online'], $cachefile, array('disp_error' => true, 'use_tmp_file' => true));
         if ($brdfile_online_res and $brdfile_online_res->is_success() && $brdfile_online_res->code != '304') {
             $isNewDL = true;
         }
     }
     // html形式なら
     if (preg_match('/html?$/', $_conf['brdfile_online'])) {
         // 更新されていたら新規キャッシュ作成
         if ($isNewDL) {
             //echo "NEW!<br>"; //
             $aBrdMenu = new BrdMenu();
             $aBrdMenu->makeBrdFile($cachefile);
             // .p2.brdファイルを生成
             $brd_menus[] = $aBrdMenu;
             $read_html_flag = true;
         }
         if (file_exists($p2brdfile)) {
             $cache_brd = $p2brdfile;
         } else {
             $cache_brd = $cachefile;
         }
     } else {
         $cache_brd = $cachefile;
     }
     if (!$read_html_flag) {
         if ($data = file($cache_brd)) {
             $aBrdMenu = new BrdMenu();
             $aBrdMenu->setBrdMatch($cache_brd);
             // パターンマッチ形式を登録
             $aBrdMenu->setBrdList($data);
             // カテゴリーと板をセット
             if ($aBrdMenu->num) {
                 $brd_menus[] = $aBrdMenu;
             } else {
                 P2Util::pushInfoHtml(sprintf("<p>p2 error: %s から板メニューを生成することはできませんでした。</p>\n", hs($cache_brd)));
             }
         } else {
             P2Util::pushInfoHtml(sprintf("<p>p2 error: %s は読み込めませんでした。</p>\n", hs($cachefile)));
         }
     }
     return $brd_menus;
 }
Ejemplo n.º 12
0
/**
 * したらばJBBSの rawmode.cgi を読んで、datに保存する(2ch風に整形)
 */
function shitarabaDownload(ThreadRead $aThread)
{
    $GLOBALS['machi_latest_num'] = '';
    // {{{ 既得datの取得レス数が適性かどうかを念のためチェック
    if (file_exists($aThread->keydat)) {
        $dls = FileCtl::file_read_lines($aThread->keydat);
        if (!$dls || sizeof($dls) != $aThread->gotnum) {
            // echo 'bad size!<br>';
            unlink($aThread->keydat);
            $aThread->gotnum = 0;
        }
    } else {
        $aThread->gotnum = 0;
    }
    // }}}
    if ($aThread->gotnum == 0) {
        $file_append = false;
        $START = 1;
    } else {
        $file_append = true;
        $START = $aThread->gotnum + 1;
    }
    // JBBS@したらば
    if (P2Util::isHostJbbsShitaraba($aThread->host)) {
        // したらばのlivedoor移転に対応。読込先をlivedoorとする。
        $host = P2Util::adjustHostJbbs($aThread->host);
        list($host, $category, ) = explode('/', $host);
        $machiurl = "http://{$host}/bbs/rawmode.cgi/{$category}/{$aThread->bbs}/{$aThread->key}/{$START}-";
    }
    $tempfile = $aThread->keydat . '.dat.temp';
    FileCtl::mkdirFor($tempfile);
    $machiurl_res = P2Util::fileDownload($machiurl, $tempfile);
    if ($machiurl_res->isError()) {
        $aThread->diedat = true;
        return false;
    }
    // {{{ したらばならEUCをSJISに変換
    if (P2Util::isHostJbbsShitaraba($aThread->host)) {
        $temp_data = FileCtl::file_read_contents($tempfile);
        $temp_data = mb_convert_encoding($temp_data, 'CP932', 'CP51932');
        if (FileCtl::file_write_contents($tempfile, $temp_data) === false) {
            p2die('cannot write file.');
        }
    }
    // }}}
    $mlines = FileCtl::file_read_lines($tempfile);
    // 一時ファイルを削除する
    unlink($tempfile);
    // ↓rawmode.cgiではこれは出ないだろう
    /*
    // (JBBS)ERROR!: スレッドがありません。過去ログ倉庫にもありません。
    if (stripos($mlines[0], 'ERROR') === 0) {
        $aThread->getdat_error_msg_ht .= $mlines[0];
        $aThread->diedat = true;
        return false;
    }
    */
    // {{{ DATを書き込む
    if ($mdatlines = shitarabaDatTo2chDatLines($mlines)) {
        $file_append = $file_append ? FILE_APPEND : 0;
        $cont = '';
        for ($i = $START; $i <= $GLOBALS['machi_latest_num']; $i++) {
            if ($mdatlines[$i]) {
                $cont .= $mdatlines[$i];
            } else {
                $cont .= "あぼーん<>あぼーん<>あぼーん<>あぼーん<>\n";
            }
        }
        if (FileCtl::file_write_contents($aThread->keydat, $cont, $file_append) === false) {
            p2die('cannot write file.');
        }
    }
    // }}}
    $aThread->isonline = true;
    return true;
}