/** * 対象レスの対象フィールドから、検索ワードを取得する * * @return string 検索ワード */ function _getReadFilterWord($host, $bbs, $key, $resnum, $field) { $word = null; $aThread = new ThreadRead(); $aThread->setThreadPathInfo($host, $bbs, $key); $aThread->readDat(); $resar = $aThread->explodeDatLine($aThread->datlines[$resnum - 1]); $resar = array_map('trim', $resar); $resar = array_map('strip_tags', $resar); switch ($field) { case 'name': $word = $resar[0]; break; case 'mail': $word = $resar[1]; break; case 'date': $word = preg_replace("/^(.*)ID:([0-9a-zA-Z\\/\\.\\+]+)(.*)\$/", "\\1 \\3", $resar[2]); $word = preg_replace("/^.*(\\d{2,4}\\/\\d{1,2}\\/\\d{1,2}).*\$/", "\\1", $word); break; case 'id': $word = preg_replace("/^.*ID:([0-9a-zA-Z\\/\\.\\+]+).*\$/", "\\1", $resar[2]); break; case 'rres': $_GET['field'] = 'msg'; $_GET['method'] = 'regex'; //$word = '>' . $resnum . '[^\d]'; // [^\d-] //$word = "(>|>|<|<|)|〉|》|≫){1,2}\s*\.?(\d+,)*" . $resnum . "\D"; require_once P2_LIB_DIR . '/ShowThread.php'; $word = ShowThread::getAnchorRegex('%prefix%(.+%delimiter%)?' . $resnum . '(?!\\d|%range_delimiter%)'); } return $word; }
/** * レスフィルタを適用する * * @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) { list($name, $mail, $date_id, $msg) = $aThread->explodeDatLine($ares); foreach ($aShowThread->checkQuoteResNums($n, $name, $msg) 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) { foreach ($aShowThread->checkQuoteResNums($n, $name, $msg) 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; }