Beispiel #1
0
/**
 * スレタイ(と本文)でマッチしたらtrueを返す
 */
function matchSbFilter(Thread $aThread)
{
    // 全文検索でdatがあれば、内容を読み込む
    if (!empty($_REQUEST['find_cont'])) {
        if (file_exists($aThread->keydat)) {
            $subject = file_get_contents($aThread->keydat);
            // be.2ch.net はEUC
            if (P2Util::isHostBe2chNet($aThread->host)) {
                $subject = mb_convert_encoding($subject, 'CP932', 'CP51932');
            }
        } else {
            return false;
        }
    } else {
        $subject = $aThread->ttitle;
    }
    if ($GLOBALS['sb_filter']['method'] == 'and') {
        foreach ($GLOBALS['words_fm'] as $word) {
            if (!StrCtl::filterMatch($word, $subject)) {
                return false;
            }
        }
    } else {
        if (!StrCtl::filterMatch($GLOBALS['word_fm'], $subject)) {
            return false;
        }
    }
    return true;
}
Beispiel #2
0
 /**
  * データを読み込んで、カテゴリと板を登録する
  *
  * @access  public
  * @return  void
  */
 function setBrdList($data)
 {
     global $_conf;
     if (empty($data)) {
         return;
     }
     // 除外URLリスト
     $not_bbs_list = array('http://members.tripod.co.jp/Backy/del_2ch/');
     foreach ($data as $v) {
         $v = rtrim($v);
         // カテゴリを探す
         if (preg_match($this->cate_match, $v, $matches)) {
             $aBrdMenuCate = new BrdMenuCate($matches[1]);
             if ($this->format == 'brd') {
                 $aBrdMenuCate->is_open = (bool) $matches[2];
             }
             $this->addBrdMenuCate($aBrdMenuCate);
             // 板を探す
         } elseif (preg_match($this->ita_match, $v, $matches)) {
             // html形式なら除外URLを外す
             if ($this->format == 'html') {
                 foreach ($not_bbs_list as $not_a_bbs) {
                     if ($not_a_bbs == $matches[1]) {
                         continue 2;
                     }
                 }
             }
             $aBrdMenuIta = new BrdMenuIta();
             // html形式
             if ($this->format == 'html') {
                 $aBrdMenuIta->host = $matches[2];
                 $aBrdMenuIta->bbs = $matches[3];
                 $itaj_match = $matches[6];
                 // brd形式
             } else {
                 $aBrdMenuIta->host = $matches[1];
                 $aBrdMenuIta->bbs = $matches[2];
                 $itaj_match = $matches[3];
             }
             $aBrdMenuIta->setItaj(rtrim($itaj_match));
             // {{{ 板検索マッチ
             // and検索
             if ($GLOBALS['words_fm']) {
                 $no_match = false;
                 foreach ($GLOBALS['words_fm'] as $word_fm_ao) {
                     $target = $aBrdMenuIta->itaj . "\t" . $aBrdMenuIta->bbs;
                     if (false === StrCtl::filterMatch($word_fm_ao, $target)) {
                         $no_match = true;
                     }
                 }
                 if (!$no_match) {
                     $this->categories[$this->num - 1]->ita_match_num++;
                     if (isset($GLOBALS['ita_mikke']['num'])) {
                         $GLOBALS['ita_mikke']['num']++;
                     } else {
                         $GLOBALS['ita_mikke']['num'] = 1;
                     }
                     $GLOBALS['ita_mikke']['host'] = $aBrdMenuIta->host;
                     $GLOBALS['ita_mikke']['bbs'] = $aBrdMenuIta->bbs;
                     $GLOBALS['ita_mikke']['itaj_en'] = $aBrdMenuIta->itaj_en;
                     // マーキング
                     if ($_conf['ktai'] && is_string($_conf['k_filter_marker'])) {
                         $aBrdMenuIta->itaj_ht = StrCtl::filterMarking($GLOBALS['word_fm'], $aBrdMenuIta->itaj, $_conf['k_filter_marker']);
                     } else {
                         $aBrdMenuIta->itaj_ht = StrCtl::filterMarking($GLOBALS['word_fm'], $aBrdMenuIta->itaj);
                     }
                     // マッチマーキングなければ(bbsでマッチしたとき)、全部マーキング
                     if ($aBrdMenuIta->itaj_ht == $aBrdMenuIta->itaj) {
                         $aBrdMenuIta->itaj_ht = '<b class="filtering">' . $aBrdMenuIta->itaj_ht . '</b>';
                     }
                     // 検索が見つからなくて、さらに携帯の時
                 } else {
                     if ($_conf['ktai']) {
                         continue;
                     }
                 }
             }
             // }}}
             if ($this->num) {
                 $this->categories[$this->num - 1]->addBrdMenuIta($aBrdMenuIta);
             }
         }
     }
     // foreach
 }
Beispiel #3
0
/**
 * スレタイ(と本文)でマッチしたらtrueを返す
 *
 * @return  boolean
 */
function matchSbFilter(&$aThread)
{
    // 全文検索でdatがあれば、内容を読み込む
    if (!empty($_REQUEST['find_cont']) && file_exists($aThread->keydat)) {
        $dat_cont = file_get_contents($aThread->keydat);
    }
    if ($GLOBALS['sb_filter']['method'] == "and") {
        reset($GLOBALS['words_fm']);
        foreach ($GLOBALS['words_fm'] as $word_fm_ao) {
            // 全文検索でdatがあれば、内容を検索
            if (!empty($_REQUEST['find_cont']) && file_exists($aThread->keydat)) {
                // be.2ch.net はEUC
                if (P2Util::isHostBe2chNet($aThread->host)) {
                    $target_cont = mb_convert_encoding($word_fm_ao, 'eucJP-win', 'SJIS-win');
                }
                if (!StrCtl::filterMatch($target_cont, $dat_cont)) {
                    return false;
                }
                // スレタイを検索
            } elseif (!StrCtl::filterMatch($word_fm_ao, $aThread->ttitle)) {
                return false;
            }
        }
    } else {
        // 全文検索でdatがあれば、内容を検索
        if (!empty($_REQUEST['find_cont']) && file_exists($aThread->keydat)) {
            $target_cont = $GLOBALS['word_fm'];
            // be.2ch.net はEUC
            if (P2Util::isHostBe2chNet($aThread->host)) {
                $target_cont = mb_convert_encoding($target_cont, 'eucJP-win', 'SJIS-win');
            }
            if (!StrCtl::filterMatch($target_cont, $dat_cont)) {
                return false;
            }
            // スレタイだけ検索
        } elseif (!StrCtl::filterMatch($GLOBALS['word_fm'], $aThread->ttitle)) {
            return false;
        }
    }
    return true;
}
Beispiel #4
0
 /**
  * マッチ判定
  *
  * @param string $target
  * @param int $resnum
  * @param boolean $failure
  * @return boolean
  */
 private function _match($target, $resnum, $failure)
 {
     if ($this->method == self::METHOD_AND) {
         $hits = 0;
         foreach ($this->_words_fm as $pattern) {
             if (StrCtl::filterMatch($pattern, $target) == $failure) {
                 if ($failure === false) {
                     return false;
                 } else {
                     $hits++;
                 }
             }
         }
         if ($hits == $this->_words_num) {
             return false;
         }
     } else {
         if (StrCtl::filterMatch($this->_word_fm, $target) == $failure) {
             return false;
         }
     }
     return true;
 }
Beispiel #5
0
    /**
     * レスフィルタリングのマッチ判定
     *
     * @access  private
     * @return  string|false    マッチしたらマッチ文字列(「含まない」条件の時はtrue)を、マッチしなかったらfalseを返す
     *                          (単純にbooleanを返すようにしてもいいかもしれない)
     */
    function filterMatch($target, $resnum)
    {
        global $_conf;
        global $_filter_hits, $_filter_range;
        $failed = $GLOBALS['res_filter']['match'] == 'off' ? true : false;
        if ($GLOBALS['res_filter']['method'] == 'and') {
            $words_fm_hit = 0;
            foreach ($GLOBALS['words_fm'] as $word_fm_ao) {
                $match = StrCtl::filterMatch($word_fm_ao, $target);
                if ((bool) strlen($match) == $failed) {
                    if ($GLOBALS['res_filter']['match'] != 'off') {
                        return false;
                    } else {
                        $words_fm_hit++;
                    }
                }
            }
            if ($words_fm_hit == count($GLOBALS['words_fm'])) {
                return false;
            }
        } else {
            $match = StrCtl::filterMatch($GLOBALS['word_fm'], $target);
            if ((bool) strlen($match) == $failed) {
                return false;
            }
        }
        $GLOBALS['_filter_hits']++;
        // 表示範囲外なら偽判定とする
        if (isset($GLOBALS['word']) && !empty($_filter_range) && ($_filter_hits < $_filter_range['start'] || $_filter_hits > $_filter_range['to'])) {
            return false;
        }
        $GLOBALS['last_hit_resnum'] = $resnum;
        // 逐次更新用
        if (!$_conf['ktai']) {
            echo <<<EOP
<script type="text/javascript">
<!--
filterCount({$GLOBALS['_filter_hits']});
-->
</script>

EOP;
        }
        return $failed ? !(bool) $match : $match;
    }