コード例 #1
0
ファイル: BrdMenu.php プロジェクト: poppen/p2
 /**
  * brdファイルを生成する
  *
  * @access  public
  * @return  string|false  成功したら生成したbrdファイルのパスを返す
  */
 function makeBrdFile($cachefile)
 {
     global $_conf;
     $cont = '';
     $data = file($cachefile);
     $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) {
         // 2008/07/14 なぜここでこんな条件が必要だったのか不明。コメントアウトしてみる。
         //if (strlen($GLOBALS['word']) > 0) {
         P2Util::pushInfoHtml(sprintf("<p>p2 error: %s から板メニューを生成することはできませんでした。</p>\n", hs($cachefile)));
         //}
         unlink($cachefile);
         return false;
     }
     $p2brdfile = BrdCtl::getP2BrdFile($cachefile);
     if (false === FileCtl::make_datafile($p2brdfile, $_conf['p2_perm'])) {
         return false;
     }
     if (false === FileCtl::filePutRename($p2brdfile, $cont)) {
         die(sprintf('p2 error: %s を更新できませんでした', hs($p2brdfile)));
         return false;
     }
     return $p2brdfile;
 }
コード例 #2
0
ファイル: BrdCtl.php プロジェクト: 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;
 }