コード例 #1
0
ファイル: Control.php プロジェクト: kcallow/MatchMe
 /**
  *
  */
 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
/**
 * 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));
}
コード例 #3
0
/**
 * @intellisense
 */
function GetShorteningForLargeText($strValue, $cNumberOfChars)
{
    $ret = runner_substr($strValue, 0, $cNumberOfChars);
    return runner_htmlspecialchars($ret);
}
コード例 #4
0
ファイル: audit.php プロジェクト: sdev1/CloudStockEnquiry
 function CreateLogFile()
 {
     $p = strrpos($this->logfile, ".");
     $logfileName = runner_substr($this->logfile, 0, $p);
     $logfileExt = runner_substr($this->logfile, $p + 1, strlen($this->logfile) - 1);
     $tn = $logfileName . "_" . format_datetime_custom(db2time(now()), "yyyyMMdd") . "." . $logfileExt;
     $fulname = getabspath($tn);
     $fsize = 0;
     if (file_exists($fulname)) {
         $fsize = filesize($fulname);
     }
     $fp = @fopen($fulname, "a");
     if ($fp) {
         if (!filesize($fulname)) {
             $str = $this->columnDate . chr(9) . $this->columnTime . chr(9) . $this->columnIP . chr(9) . $this->columnUser . chr(9) . $this->columnTable . chr(9) . $this->columnAction . chr(9) . $this->columnKey . chr(9) . $this->columnField . chr(9) . $this->columnOldValue . chr(9) . $this->columnNewValue . "\r\n";
             if ($fp) {
                 fputs($fp, $str);
             }
         }
     }
     return $fp;
 }
コード例 #5
0
ファイル: ViewControl.php プロジェクト: kcallow/MatchMe
 /**
  * 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, htmlspecialchars encoded field's content
  * @param Number cNumberOfChars	
  * @prarm Number contenLength		The length of the truncated value	 
  * @return string
  */
 protected function highlightTruncatedBeforeMore($value, $truncatedValue, $cNumberOfChars, $contenLength)
 {
     $lookupParams = $this->getLookupParams();
     $highlightData = $this->searchClauseObj->getSearchHighlightingData($this->field, $value, false, $lookupParams);
     if (!$highlightData) {
         return $truncatedValue;
     }
     $searchWord = $this->getFirstSearchWordInLargeText($highlightData['searchWords'], $value);
     $searchWordEncoded = runner_htmlspecialchars($searchWord);
     $highlighting = $this->addHighlightingSpan($searchWordEncoded);
     $searchOpt = $highlightData['searchOpt'];
     switch ($searchOpt) {
         case 'Equals':
             return $this->addHighlightingSpan($truncatedValue);
         case 'Starts with':
             if (strlen($searchWordEncoded) > strlen($truncatedValue)) {
                 return $this->addHighlightingSpan($truncatedValue);
             }
             return preg_replace('/^' . preg_quote($searchWordEncoded, "/") . '/i', $highlighting, $truncatedValue);
         case 'Contains':
             $regExpModifier = $this->useUTF8 ? 'u' : '';
             $firstPos = $this->getFistOccurencePosition($value, $searchWord, $searchWordEncoded);
             $lastPos = $this->getLastOccurencePosition($value, $searchWord, $searchWordEncoded);
             $searchWordEncodedLen = runner_strlen($searchWordEncoded);
             $truncLen = runner_strlen($truncatedValue);
             $pattern = '/(' . $this->getSearchWordPattern($highlightData['searchWords'], true) . ')/i';
             if ($lastPos + $searchWordEncodedLen <= $truncLen || $firstPos + $searchWordEncodedLen <= $truncLen) {
                 if (!$this->haveTheSameSpChReference($pattern, $truncatedValue)) {
                     return preg_replace($pattern . $regExpModifier, $this->addHighlightingSpan('$1'), $truncatedValue);
                 }
                 return $this->highlightValueWithSpecialChars($truncatedValue, $pattern . $regExpModifier);
             }
             if ($firstPos > $truncLen) {
                 $newNumberOfChars = ceil($cNumberOfChars / 2);
                 $qNumberOfChars = ceil($cNumberOfChars / 4);
                 $firstPosDecoded = runner_strpos($value, $searchWord);
                 $truncSubsr = runner_substr($value, 0, $cNumberOfChars);
                 $valueSubstr = runner_substr($value, $firstPosDecoded - $qNumberOfChars, $qNumberOfChars + runner_strlen($searchWord));
                 $truncSubsr = runner_substr($truncSubsr, 0, $newNumberOfChars);
                 $valueSubstr = runner_htmlspecialchars($valueSubstr);
                 $pattern = '/(' . preg_quote($searchWordEncoded, "/") . ')/i';
                 if (!$this->haveTheSameSpChReference($pattern, $valueSubstr)) {
                     $valueSubstr = preg_replace($pattern . $regExpModifier, $highlighting, $valueSubstr);
                 } else {
                     $valueSubstr = $this->highlightValueWithSpecialChars($valueSubstr, $pattern . $regExpModifier);
                 }
                 return runner_htmlspecialchars($truncSubsr) . "&nbsp;&lt;...&gt;&nbsp;" . $valueSubstr;
             }
             return runner_substr($truncatedValue, 0, $firstPos) . $highlighting;
         default:
             return $truncatedValue;
     }
 }