Esempio n. 1
0
 /**
  * レスフィルタを適用する
  *
  * @param ShowThread $aShowThread
  * @return array
  */
 public function apply(ShowThread $aShowThread)
 {
     $aThread = $aShowThread->thread;
     $failure = $this->match == self::MATCH_ON ? false : true;
     $count = count($aThread->datlines);
     $datlines = array_fill(0, $count, null);
     $hit_nums = array();
     //        $res_nums = array();
     $check_refs = $this->include & self::INCLUDE_REFERENCES ? true : false;
     $check_refed = $this->include & self::INCLUDE_REFERENCED ? true : false;
     // {{{ 1パス目 (マッチングと参照レス検出)
     if ($this->field == self::FIELD_NUMBER && $this->method == self::METHOD_JUST && $this->match == self::MATCH_ON) {
         // レス番号完全一致は特別扱い
         $n = (int) $this->word;
         if ($n > 0 && $n <= $count) {
             $i = $n - 1;
             $ares = $aThread->datlines[$i];
             $datlines[$i] = $ares;
             $hit_nums[] = $i;
             if ($check_refs || $check_refed) {
                 list($name, $mail, $date_id, $msg) = $aThread->explodeDatLine($ares);
                 foreach ($aShowThread->checkQuoteResNums($n, $name, $msg, $check_refs, $check_refed, false) as $rn) {
                     $ri = $rn - 1;
                     if ($datlines[$ri] === null) {
                         $datlines[$ri] = $aThread->datlines[$ri];
                         $hit_nums[] = $ri;
                     }
                 }
             }
             /*
                             if ($check_refed) {
                                 $res_nums[] = $n;
                             }
             */
         }
     } else {
         // 通常のマッチング
         foreach ($aThread->datlines as $i => $ares) {
             $n = $i + 1;
             list($name, $mail, $date_id, $msg) = $aThread->explodeDatLine($ares);
             if (($id = $aThread->ids[$n]) !== null) {
                 $date_id = str_replace($aThread->idp[$n] . $id, "ID:{$id}", $date_id);
             }
             $target = $this->getTarget($ares, $n, $name, $mail, $date_id, $msg);
             if (!$target) {
                 continue;
             }
             if ($this->_match($target, $n, $failure)) {
                 if ($datlines[$i] === null) {
                     $datlines[$i] = $ares;
                     $hit_nums[] = $i;
                 }
                 if ($check_refs || $check_refed) {
                     foreach ($aShowThread->checkQuoteResNums($n, $name, $msg, $check_refs, $check_refed, false) as $rn) {
                         $ri = $rn - 1;
                         if ($datlines[$ri] === null) {
                             $datlines[$ri] = $aThread->datlines[$ri];
                             $hit_nums[] = $ri;
                         }
                     }
                 }
                 /*
                                     if ($check_refed) {
                                         $res_nums[] = $n;
                                     }
                 */
             }
         }
     }
     // }}}
     // {{{ 2パス目 (マッチしたレスへの参照)
     /*
             if (count($res_nums)) {
                 $pattern = ShowThread::getAnchorRegex(
                     '%prefix%(.+%delimiter%)?(?:' . implode('|', $res_nums) . ')(?!\\d|%range_delimiter%)'
                 );
                 foreach ($aThread->datlines as $i => $ares) {
                     if ($datlines[$i] === null) {
                         list(, , , $msg) = $aThread->explodeDatLine($ares);
                         if (StrCtl::filterMatch($pattern, $msg, false)) {
                             $datlines[$i] = $aThread->datlines[$i];
                             $hit_nums[] = $i;
                         }
                     }
                 }
             }
     */
     // }}}
     $hits = count($hit_nums);
     if ($hits) {
         $this->hits += $hits;
         $this->last_hit_resnum = max($hit_nums);
     }
     return $datlines;
 }