Пример #1
0
 /**
  *
  */
 function cutStr($value, $searchFor, $SuggestStringSize, &$startPos, &$valueLength)
 {
     $diffLength = $SuggestStringSize - runner_strlen($searchFor);
     $leftContextLength = floor($diffLength / 2);
     $rigthContextLength = $diffLength - $leftContextLength;
     if ($this->pageObject->pSetEdit->getNCSearch()) {
         // case-insensitive search
         $startPos = stripos($value, $searchFor);
         $startPos = runner_strlen(substr($value, 0, $startPos));
         //UTF-8 support
     } else {
         $startPos = runner_strpos($value, $searchFor);
     }
     $searchStartPos = $startPos;
     $valueLength = runner_strlen($value);
     if ($startPos < $leftContextLength) {
         $rigthContextLength -= $startPos - $leftContextLength;
         $startPos = 0;
     } else {
         $startPos -= $leftContextLength;
     }
     if ($startPos > 0) {
         $found = false;
         for ($i = $startPos - 1; $i >= $startPos - 5 && $i >= 0; $i--) {
             if ($i == 0 || $this->isStopSymbol(runner_substr($value, $i, 1))) {
                 if ($i == 0) {
                     $startPos = 0;
                 } else {
                     $startPos = $i + 1;
                 }
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             for ($i = $startPos; $i <= $startPos + 5 && $i < $searchStartPos; $i++) {
                 if ($this->isStopSymbol(runner_substr($value, $i, 1))) {
                     $startPos = $i + 1;
                     break;
                 }
             }
         }
     }
     if ($startPos + $SuggestStringSize > $valueLength) {
         $SuggestStringSize = $valueLength - $startPos;
     }
     if ($startPos + $SuggestStringSize < $valueLength) {
         $found = false;
         $tempStartPos = $startPos + $SuggestStringSize;
         for ($i = $tempStartPos + 1; $i <= $tempStartPos + 5 && $i < $valueLength; $i++) {
             if ($i == $valueLength - 1 || $this->isStopSymbol(runner_substr($value, $i, 1))) {
                 if ($i == $valueLength - 1) {
                     $SuggestStringSize = $i - $startPos + 1;
                 } else {
                     $SuggestStringSize = $i - $startPos;
                 }
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             for ($i = $tempStartPos; $i >= $tempStartPos - 5; $i--) {
                 if ($this->isStopSymbol(runner_substr($value, $i, 1))) {
                     $SuggestStringSize = $i - $startPos;
                     break;
                 }
             }
         }
     }
     return runner_substr($value, $startPos, $SuggestStringSize);
 }
Пример #2
0
 /**
  * Format the string before the "More ..." link and highlight a search word depending on the search option's value.
  * @param String value				The raw field's content
  * @param String truncatedValue	 	The truncated field's content
  * @param Number cNumberOfChars	
  * @param Number truncLength		The length of the truncated field's content without the final closing tags
  * @return string
  */
 protected function highlightTruncatedBeforeMore($value, $truncatedValue, $cNumberOfChars, $truncLength)
 {
     $highlightData = $this->searchClauseObj->getSearchHighlightingData($this->field, $value, false, array());
     if (!$highlightData) {
         return $truncatedValue;
     }
     $data = $this->getPocessedHTMLValueData($value, strlen($value));
     $processedValue = $data['value'];
     $firstSearchWordData = $this->getFirstSearchWordData($highlightData['searchWords'], $data['notContentPositions'], $processedValue);
     $firstPos = $firstSearchWordData["position"];
     $hasTags = $firstSearchWordData["hasTags"];
     $firstSearchWord = $firstSearchWordData["searchWord"];
     if ($firstPos === FALSE) {
         return $truncatedValue;
     }
     if ($firstPos + strlen($firstSearchWord) <= $truncLength) {
         return $this->getValueHighlighted($truncatedValue, $highlightData);
     }
     if ($firstPos <= $truncLength) {
         $truncatedUnicodeLength = runner_strlen(substr($value, 0, $truncLength));
         $truncatedWithSearchWordUnicodeLength = runner_strlen(substr($value, 0, $firstPos + strlen($firstSearchWord)));
         $data = $this->getPocessedHTMLValueData($value, $cNumberOfChars + $truncatedWithSearchWordUnicodeLength - $truncatedUnicodeLength);
         return $this->getValueHighlighted($data['value'], $highlightData);
     }
     return $this->getValueHighlighted($truncatedValue, $highlightData) . "&nbsp;&lt;...&gt;&nbsp;" . $this->getSearchWordHighlighted($hasTags, $firstSearchWord);
 }
Пример #3
0
/**
 * PHP strrpos wrapper
 */
function runner_strrpos($haystack, $needle, $offset = 0)
{
    global $useUTF8, $mbEnabled;
    if (!$useUTF8) {
        return strrpos($haystack, $needle, $offset);
    }
    if ($mbEnabled) {
        return mb_strrpos($haystack, $needle, $offset, 'UTF-8');
    }
    if ($offset < 0) {
        $offset = runner_strlen($haystack) + $offset;
    }
    if ($offset > 0) {
        $haystack = runner_substr($haystack, $offset, runner_strlen($haystack) - $offset);
    }
    $rpos = strrpos($haystack, $needle);
    if ($rpos === FALSE) {
        return $rpos;
    }
    return $offset + runner_strlen(substr($haystack, 0, $rpos));
}
Пример #4
0
 /**
  * Get the last searchWord occurence in the encoded value string
  * @param String value
  * @param String searchWord
  * @param String searchWordEncoded
  * @return Number
  */
 protected function getLastOccurencePosition($value, $searchWord, $searchWordEncoded)
 {
     $planeLastPos = strrpos($value, $searchWord);
     $planeSubstr = substr($value, 0, $planeLastPos);
     $encodedPlaneSubstr = runner_htmlspecialchars($planeSubstr);
     return runner_strrpos(runner_htmlspecialchars($value), $searchWordEncoded, runner_strlen($encodedPlaneSubstr));
 }