/** * Returns the title of the search result row * * @param array $row Result row * @return string Title from row */ public function makeTitle($row) { $add = ''; if ($this->multiplePagesType($row['item_type'])) { $dat = unserialize($row['cHashParams']); $pp = explode('-', $dat['key']); if ($pp[0] != $pp[1]) { $add = ', ' . $this->pi_getLL('word_pages') . ' ' . $dat['key']; } else { $add = ', ' . $this->pi_getLL('word_page') . ' ' . $pp[0]; } } $outputString = $this->charsetConverter->crop('utf-8', $row['item_title'], $this->conf['results.']['titleCropAfter'], $this->conf['results.']['titleCropSignifier']); return $outputString . $add; }
/** * Marks up the search words from $this->searchWords in the $str with a color. * * @param string $str Text in which to find and mark up search words. This text is assumed to be UTF-8 like the search words internally is. * @return string Processed content */ protected function markupSWpartsOfString($str) { $htmlParser = GeneralUtility::makeInstance(HtmlParser::class); // Init: $str = str_replace(' ', ' ', $htmlParser->bidir_htmlspecialchars($str, -1)); $str = preg_replace('/\\s\\s+/', ' ', $str); $swForReg = array(); // Prepare search words for regex: foreach ($this->searchWords as $d) { $swForReg[] = preg_quote($d['sword'], '/'); } $regExString = '(' . implode('|', $swForReg) . ')'; // Split and combine: $parts = preg_split('/' . $regExString . '/i', ' ' . $str . ' ', 20000, PREG_SPLIT_DELIM_CAPTURE); // Constants: $summaryMax = $this->settings['results.']['markupSW_summaryMax']; $postPreLgd = $this->settings['results.']['markupSW_postPreLgd']; $postPreLgd_offset = $this->settings['results.']['markupSW_postPreLgd_offset']; $divider = $this->settings['results.']['markupSW_divider']; $occurencies = (count($parts) - 1) / 2; if ($occurencies) { $postPreLgd = MathUtility::forceIntegerInRange($summaryMax / $occurencies, $postPreLgd, $summaryMax / 2); } // Variable: $summaryLgd = 0; $output = array(); // Shorten in-between strings: foreach ($parts as $k => $strP) { if ($k % 2 == 0) { // Find length of the summary part: $strLen = $this->charsetConverter->strlen('utf-8', $parts[$k]); $output[$k] = $parts[$k]; // Possibly shorten string: if (!$k) { // First entry at all (only cropped on the frontside) if ($strLen > $postPreLgd) { $output[$k] = $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset))); } } elseif ($summaryLgd > $summaryMax || !isset($parts[$k + 1])) { // In case summary length is exceed OR if there are no more entries at all: if ($strLen > $postPreLgd) { $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], $postPreLgd - $postPreLgd_offset)) . $divider; } } else { if ($strLen > $postPreLgd * 2) { $output[$k] = preg_replace('/[[:space:]][^[:space:]]+$/', '', $this->charsetConverter->crop('utf-8', $parts[$k], $postPreLgd - $postPreLgd_offset)) . $divider . preg_replace('/^[^[:space:]]+[[:space:]]/', '', $this->charsetConverter->crop('utf-8', $parts[$k], -($postPreLgd - $postPreLgd_offset))); } } $summaryLgd += $this->charsetConverter->strlen('utf-8', $output[$k]); // Protect output: $output[$k] = htmlspecialchars($output[$k]); // If summary lgd is exceed, break the process: if ($summaryLgd > $summaryMax) { break; } } else { $summaryLgd += $this->charsetConverter->strlen('utf-8', $strP); $output[$k] = '<strong class="tx-indexedsearch-redMarkup">' . htmlspecialchars($parts[$k]) . '</strong>'; } } // Return result: return implode('', $output); }