Ejemplo n.º 1
0
/**
 * スレッド情報を取得する
 *
 * @param   string  $host
 * @param   string  $bbs
 * @param   string  $key
 * @return  object  スレッド情報
 */
function get_thread_info($host, $bbs, $key)
{
    global $_conf;
    $group = P2Util::getHostGroupName($host);
    $info = new stdClass();
    $info->type = 'thread';
    $info->group = $group;
    $info->host = $host;
    $info->bbs = $bbs;
    $info->key = $key;
    $aThread = new Thread();
    // hostを分解してidxファイルのパスを求める
    $aThread->setThreadPathInfo($host, $bbs, $key);
    $key_line = $aThread->getThreadInfoFromIdx();
    // $aThread->length をset
    $aThread->getDatBytesFromLocalDat();
    // 板名を取得
    $aThread->itaj = P2Util::getItaName($host, $bbs);
    if (!$aThread->itaj) {
        if (isset($_GET['itaj_en'])) {
            $aThread->itaj = UrlSafeBase64::decode($_GET['itaj_en']);
        } else {
            $aThread->itaj = $bbs;
        }
    }
    $info->itaj = $aThread->itaj;
    // スレタイトルを取得
    if (!$aThread->ttitle) {
        if (isset($_GET['ttitle_en'])) {
            $aThread->setTtitle(UrlSafeBase64::decode($_GET['ttitle_en']));
        } else {
            $aThread->setTitleFromLocal();
        }
    }
    $info->ttitle = $aThread->ttitle;
    // お気にスレ登録状況を取得
    $favs = array();
    if ($_conf['expack.misc.multi_favs']) {
        $favlist_titles = FavSetManager::getFavSetTitles('m_favlist_set');
        for ($i = 0; $i <= $_conf['expack.misc.favset_num']; $i++) {
            if (!isset($favlist_titles[$i]) || $favlist_titles[$i] == '') {
                if ($i == 0) {
                    $favtitle = 'お気にスレ';
                } else {
                    $favtitle = "お気にスレ{$i}";
                }
            } else {
                $favtitle = $favlist_titles[$i];
            }
            $favs[$i] = array('title' => $favtitle, 'set' => !empty($aThread->favs[$i]));
        }
    } else {
        $favs[0] = array('title' => 'お気にスレ', 'set' => !empty($aThread->fav));
    }
    $info->favs = $favs;
    // 殿堂チェック
    $info->palace = false;
    if ($pallines = FileCtl::file_read_lines($_conf['palace_idx'], FILE_IGNORE_NEW_LINES)) {
        foreach ($pallines as $l) {
            $palarray = explode('<>', $l);
            if ($aThread->key == $palarray[1] && $aThread->bbs == $palarray[11]) {
                if (P2Util::getHostGroupName($palarray[10]) == $group) {
                    $info->palace = true;
                    break;
                }
            }
        }
    }
    // スレッドあぼーんチェック
    $info->taborn = false;
    $taborn_idx = P2Util::idxDirOfHostBbs($host, $bbs) . 'p2_threads_aborn.idx';
    if ($tabornlines = FileCtl::file_read_lines($taborn_idx, FILE_IGNORE_NEW_LINES)) {
        foreach ($tabornlines as $l) {
            $tabornarray = explode('<>', $l);
            if ($key == $tabornarray[1]) {
                $info->taborn = true;
                break;
            }
        }
    }
    // ログ関連
    $hasLog = false;
    if (file_exists($aThread->keydat)) {
        $info->keydat = $aThread->keydat;
        $info->length = $aThread->length;
        $hasLog = true;
    } else {
        $info->keydat = null;
        $info->length = -1;
    }
    if (file_exists($aThread->keyidx)) {
        $info->keyidx = $aThread->keyidx;
        $hasLog = true;
    } else {
        $info->keyidx = null;
    }
    if ($aThread->gotnum) {
        $info->gotnum = $aThread->gotnum;
    } elseif ($hasLog) {
        $info->gotnum = 0;
    } else {
        $info->gotnum = -1;
    }
    return $info;
}
Ejemplo n.º 2
0
 /**
  * すべてのお気にスレ・お気に板を読み込む
  *
  * @param bool $force
  * @return void
  */
 public static function loadAllFavSet($force = false)
 {
     global $_conf;
     static $done = false;
     if ($done && !$force) {
         return;
     }
     // キャッシュの有無をチェック
     $cache_file = $_conf['cache_dir'] . DIRECTORY_SEPARATOR . 'favset_cache.txt';
     if ($force || !file_exists($cache_file)) {
         $use_cache = false;
     } else {
         $cache_mtime = filemtime($cache_file);
         if (filemtime(__FILE__) > $cache_mtime) {
             $use_cache = false;
         } else {
             $use_cache = true;
         }
     }
     // キャッシュが有効かどうかをチェック
     if ($use_cache && file_exists($_conf['orig_favlist_idx']) && filemtime($_conf['orig_favlist_idx']) > $cache_mtime) {
         $use_cache = false;
     }
     if ($use_cache && file_exists($_conf['orig_favita_brd']) && filemtime($_conf['orig_favita_brd']) > $cache_mtime) {
         $use_cache = false;
     }
     // 読み込み対象ファイルのリストを作成すると同時にキャッシュが有効かどうかをチェック
     $favlist_idxes = array($_conf['orig_favlist_idx']);
     $favita_brds = array($_conf['orig_favita_brd']);
     for ($i = 1; $i <= $_conf['expack.misc.favset_num']; $i++) {
         $favlist_idx = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . sprintf('p2_favlist%d.idx', $i);
         if ($use_cache && file_exists($favlist_idx) && filemtime($favlist_idx) > $cache_mtime) {
             $use_cache = false;
         }
         $favlist_idxes[$i] = $favlist_idx;
         $favita_brd = $_conf['pref_dir'] . DIRECTORY_SEPARATOR . sprintf('p2_favita%d.brd', $i);
         if ($use_cache && file_exists($favita_brd) && filemtime($favita_brd) > $cache_mtime) {
             $use_cache = false;
         }
         $favita_brds[$i] = $favita_brd;
     }
     // キャッシュが有効なら、それを使う
     if ($use_cache) {
         $cache = unserialize(file_get_contents($cache_file));
         if (is_array($cache)) {
             list($_conf['favlists'], $_conf['favitas']) = $cache;
             $done = true;
             return;
         }
     }
     // すべてのお気にスレを読み込む
     $_conf['favlists'] = array();
     foreach ($favlist_idxes as $i => $favlist_idx) {
         $_conf['favlists'][$i] = array();
         if ($favlines = FileCtl::file_read_lines($favlist_idx, FILE_IGNORE_NEW_LINES)) {
             foreach ($favlines as $l) {
                 $lar = explode('<>', $l);
                 // bbsのないものは不正データなのでスキップ
                 if (!isset($lar[11])) {
                     continue;
                 }
                 $key = $lar[1];
                 $host = $lar[10];
                 $bbs = $lar[11];
                 $group = P2Util::getHostGroupName($host);
                 $_conf['favlists'][$i][] = array('group' => $group, 'host' => $host, 'bbs' => $bbs, 'key' => $key);
             }
         }
     }
     // すべてのお気に板を読み込む
     $_conf['favitas'] = array();
     foreach ($favita_brds as $i => $favita_brd) {
         $_conf['favitas'][$i] = array();
         if ($favlines = FileCtl::file_read_lines($favita_brd, FILE_IGNORE_NEW_LINES)) {
             foreach ($favlines as $l) {
                 $lar = explode("\t", $l);
                 $host = $lar[1];
                 $bbs = $lar[2];
                 $itaj = $lar[3];
                 $group = P2Util::getHostGroupName($host);
                 $_conf['favitas'][$i][] = array('group' => $group, 'host' => $host, 'bbs' => $bbs, 'itaj' => $itaj);
             }
         }
     }
     //キャッシュに保存する
     if (!is_dir($_conf['pref_dir'])) {
         FileCtl::mkdirFor($cache_file);
     }
     file_put_contents($cache_file, serialize(array($_conf['favlists'], $_conf['favitas'])));
     $done = true;
 }
Ejemplo n.º 3
0
 /**
  * お気に入り登録状態を取得する
  */
 public function getFavStatus()
 {
     global $_conf;
     if (!is_array($this->_favs)) {
         if (!$_conf['expack.misc.multi_favs'] || $_conf['expack.misc.favset_num'] < 0) {
             $this->_favs = array($this->fav);
         } else {
             $this->_favs = array_fill(0, $_conf['expack.misc.favset_num'] + 1, false);
             $group = P2Util::getHostGroupName($this->host);
             foreach ($_conf['favlists'] as $num => $favlist) {
                 foreach ($favlist as $fav) {
                     if ($this->key == $fav['key'] && $this->bbs == $fav['bbs'] && $group == $fav['group']) {
                         $this->_favs[$num] = true;
                         break;
                     }
                 }
             }
         }
     }
     return $this->_favs;
 }