Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 /**
  * Get the first searchWord occurence in the encoded value string
  * @param String value
  * @param String searchWord
  * @param String searchWordEncoded
  * @return Number
  */
 protected function getFistOccurencePosition($value, $searchWord, $searchWordEncoded)
 {
     $planeFirstPos = strpos($value, $searchWord);
     $planeSubstr = substr($value, 0, $planeFirstPos);
     $encodedPlaneSubstr = runner_htmlspecialchars($planeSubstr);
     return runner_strpos(runner_htmlspecialchars($value), $searchWordEncoded, runner_strlen($encodedPlaneSubstr));
 }