public function GetValue() { $result = $this->value; if (ord($result[0]) == 0x0) { $result = CUtil::BinSubstr($result, 1); } return $result; }
function CRCCryptData($data, $pwdString, $type) { $type = strtoupper($type); if ($type != "D") { $type = "E"; } $res_data = ""; if ($type == 'D') { $data = urldecode($data); } $key[] = ""; $box[] = ""; $temp_swap = ""; $pwdLength = CUtil::BinStrlen($pwdString); for ($i = 0; $i <= 255; $i++) { $key[$i] = ord(CUtil::BinSubstr($pwdString, $i % $pwdLength, 1)); $box[$i] = $i; } $x = 0; for ($i = 0; $i <= 255; $i++) { $x = ($x + $box[$i] + $key[$i]) % 256; $temp_swap = $box[$i]; $box[$i] = $box[$x]; $box[$x] = $temp_swap; } $temp = ""; $k = ""; $cipherby = ""; $cipher = ""; $a = 0; $j = 0; for ($i = 0, $n = CUtil::BinStrlen($data); $i < $n; $i++) { $a = ($a + 1) % 256; $j = ($j + $box[$a]) % 256; $temp = $box[$a]; $box[$a] = $box[$j]; $box[$j] = $temp; $k = $box[($box[$a] + $box[$j]) % 256]; $cipherby = ord(CUtil::BinSubstr($data, $i, 1)) ^ $k; $cipher .= chr($cipherby); } if ($type == 'D') { $res_data = urldecode(urlencode($cipher)); } else { $res_data = urlencode($cipher); } return $res_data; }
public function getPayload() { $sJSONPayload = str_replace('"' . self::APPLE_RESERVED_NAMESPACE . '":[]', '"' . self::APPLE_RESERVED_NAMESPACE . '":{}', CPushManager::_MakeJson($this->_getPayload(), "", false)); $nJSONPayloadLen = CUtil::BinStrlen($sJSONPayload); if ($nJSONPayloadLen > $this->payloadMaxSize) { if ($this->_bAutoAdjustLongPayload) { $nMaxTextLen = $nTextLen = CUtil::BinStrlen($this->text) - ($nJSONPayloadLen - $this->payloadMaxSize); if ($nMaxTextLen > 0) { while (CUtil::BinStrlen($this->text = CUtil::BinSubstr($this->text, 0, --$nTextLen)) > $nMaxTextLen) { } return $this->getPayload(); } else { return false; } } else { return false; } } return $sJSONPayload; }
public function getPayload() { $sJSONPayload = str_replace('"' . self::APPLE_RESERVED_NAMESPACE . '":[]', '"' . self::APPLE_RESERVED_NAMESPACE . '":{}', CPushManager::_MakeJson($this->_getPayload(), "", false)); $nJSONPayloadLen = CUtil::BinStrlen($sJSONPayload); if ($nJSONPayloadLen > self::PAYLOAD_MAXIMUM_SIZE) { if ($this->_bAutoAdjustLongPayload) { $nMaxTextLen = $nTextLen = CUtil::BinStrlen($this->text) - ($nJSONPayloadLen - self::PAYLOAD_MAXIMUM_SIZE); if ($nMaxTextLen > 0) { while (CUtil::BinStrlen($this->text = CUtil::BinSubstr($this->text, 0, --$nTextLen)) > $nMaxTextLen) { } return $this->getPayload(); } else { throw new Exception("JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " . self::PAYLOAD_MAXIMUM_SIZE . " bytes. The message text can not be auto-adjusted."); } } else { throw new Exception("JSON Payload is too long: {$nJSONPayloadLen} bytes. Maximum size is " . self::PAYLOAD_MAXIMUM_SIZE . " bytes"); } } return $sJSONPayload; }
function PrintHTTP($strRequest, $strHeaders, $strRes) { echo "== Request ==\n". (($l = CUtil::BinStrlen($strRequest)) > 1000 ? CUtil::BinSubstr($strRequest, 0, 1000).' ... ('.$l.' bytes)' : $strRequest)."\n". "== Response ==\n". $strHeaders."\n". "== Body ==\n". (($l = CUtil::BinStrlen($strRes)) > 1000 ? CUtil::BinSubstr($strRes, 0, 1000).' ... ('.$l.' bytes)' : $strRes)."\n". "==========\n"; }
public static function Crypt($str, $key=false) { $res = ''; if($key===false) $key = COption::GetOptionString("main", "pwdhashadd", ""); $key1 = CMailUtil::BinMD5($key); while($str) { $m = CUtil::BinSubstr($str, 0, 16); $str = CUtil::BinSubstr($str, 16); $res .= CMailUtil::ByteXOR($m, $key1, 16); $key1 = CMailUtil::BinMD5($key.$key1.$m); } return(base64_encode($res)); }
function PrepareSearchResult($str) { //$words - contains what we will highlight $words = array(); foreach ($this->Query->m_words as $v) { $v = ToUpper($v); $words[$v] = "KAV"; if(strpos($v, "\"")!==false) $words[str_replace("\"", """, $v)] = "KAV"; } foreach ($this->Query->m_stemmed_words as $v) $words[ToUpper($v)]="STEM"; //Prepare upper case version of the string if ($this->Query->bStemming) { //And add missing stemming words $arStemInfo = stemming_init($this->Query->m_lang); $a = stemming($this->Query->m_query, $this->Query->m_lang, true); foreach ($a as $stem => $cnt) { if (!preg_match("/cut[56]/i", $stem)) $words[$stem] = "STEM"; } $pcreLettersClass = "[".$arStemInfo["pcre_letters"]."]"; $strUpp = stemming_upper($str, $this->Query->m_lang); } else { $strUpp = ToUpper($str); $pcreLettersClass = ""; } $wordsCount = count($words); //We'll use regexp to find positions of the words in the text $pregMask = ""; foreach ($words as $search => $type) { if ($type == "STEM") $pregMask = "(?<!".$pcreLettersClass.")".preg_quote($search, "/").$pcreLettersClass."*|".$pregMask; else $pregMask = $pregMask."|".preg_quote($search, "/"); } $pregMask = trim($pregMask, "|"); $arPos = array(); //This will contain positions of the first occurrence $arPosW = array(); //This is "running" words array $arPosP = array(); //and their positions $arPosLast = false; //Best found combination of the positions $matches = array(); if (preg_match_all("/(".$pregMask.")/i".BX_UTF_PCRE_MODIFIER, $strUpp, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE)) { foreach ($matches as $oneCase) { $search = null; if (isset($words[$oneCase[0][0]])) { $search = $oneCase[0][0]; } else { $a = stemming($oneCase[0][0], $this->Query->m_lang, true); foreach ($a as $stem => $cnt) { if (isset($words[$stem])) { $search = $stem; break; } } } if (isset($search)) { $p = $oneCase[0][1]; if (!isset($arPos[$search])) $arPos[$search] = $p; //Add to the tail of the running window $arPosP[] = $p; $arPosW[] = $search; $cc = count($arPosW); if ($cc >= $wordsCount) { //This cuts the tail of the running window while ($cc > $wordsCount) { array_shift($arPosW); array_shift($arPosP); $cc--; } //Check if all the words present in the current window if (count(array_unique($arPosW)) == $wordsCount) { //And check if positions is the best if ( !$arPosLast || ( (max($arPosP) - min($arPosP)) < (max($arPosLast) - min($arPosLast)) )) $arPosLast = $arPosP; } } } } } if ($arPosLast) $arPos = $arPosLast; //Nothing found just cut some text if (empty($arPos)) { $str_len = strlen($str); $pos_end = 500; while (($pos_end < $str_len) && (strpos(" ,.\n\r", substr($str, $pos_end, 1)) === false)) $pos_end++; return substr($str, 0, $pos_end).($pos_end < $str_len? "...": ""); } sort($arPos); $str_len = CUtil::BinStrlen($str); $delta = 250/count($arPos); $arOtr = array(); //Have to do it two times because Positions eat each other for ($i = 0; $i < 2; $i++) { $arOtr = array(); $last_pos = -1; foreach ($arPos as $pos_mid) { //Find where sentence begins $pos_beg = $pos_mid - $delta; if($pos_beg <= 0) $pos_beg = 0; while(($pos_beg > 0) && (strpos(" ,.!?\n\r", CUtil::BinSubstr($str, $pos_beg, 1)) === false)) $pos_beg--; //Find where sentence ends $pos_end = $pos_mid + $delta; if($pos_end > $str_len) $pos_end = $str_len; while(($pos_end < $str_len) && (strpos(" ,.!?\n\r", CUtil::BinSubstr($str, $pos_end, 1)) === false)) $pos_end++; if($pos_beg <= $last_pos) $arOtr[count($arOtr)-1][1] = $pos_end; else $arOtr[] = array($pos_beg, $pos_end); $last_pos = $pos_end; } //Adjust length of the text $delta = 250/count($arOtr); } $str_result = ""; foreach ($arOtr as $borders) { $str_result .= ($borders[0]<=0? "": " ...") .CUtil::BinSubstr($str, $borders[0], $borders[1] - $borders[0] + 1) .($borders[1] >= $str_len? "": "... ") ; } foreach ($words as $search => $type) $str_result = $this->repl($search, $type, $str_result); $str_result = str_replace("%/^%", "</b>", str_replace("%^%","<b>", $str_result)); return $str_result; }
function EncodeHeaderFrom($text, $charset) { $i = CUtil::BinStrlen($text); while ($i > 0) { if (ord(CUtil::BinSubstr($text, $i - 1, 1)) >> 7) { break; } $i--; } if ($i == 0) { return $text; } else { return "=?" . $charset . "?B?" . base64_encode(CUtil::BinSubstr($text, 0, $i)) . "?=" . CUtil::BinSubstr($text, $i); } }
/** * @param string $content * @return array|bool */ private static function getFrameIndexes($content) { $openTag = "<!--'start_frame_cache_"; $closingTag = "<!--'end_frame_cache_"; $ending = "'-->"; $areas = array(); $offset = 0; while (($openTagStart = \CUtil::BinStrpos($content, $openTag, $offset)) !== false) { $endingPos = \CUtil::BinStrpos($content, $ending, $openTagStart); if ($endingPos === false) { break; } $idStart = $openTagStart + strlen($openTag); $idLength = $endingPos - $idStart; $areaId = \CUtil::BinSubstr($content, $idStart, $idLength); $openTagEnd = $endingPos + strlen($ending); $realClosingTag = $closingTag . $areaId . $ending; $closingTagStart = \CUtil::BinStrpos($content, $realClosingTag, $openTagEnd); if ($closingTagStart === false) { $offset = $openTagEnd; continue; } $closingTagEnd = $closingTagStart + strlen($realClosingTag); $area = new \stdClass(); $area->id = $areaId; $area->openTagStart = $openTagStart; $area->openTagEnd = $openTagEnd; $area->closingTagStart = $closingTagStart; $area->closingTagEnd = $closingTagEnd; $areas[] = $area; $offset = $closingTagEnd; } return count($areas) > 0 ? $areas : false; }
/** * Unpack values from string (something like rsplit). * Simple example for separator ".": * <code> * // Unpack all values: * unpack('test.all.values', 0) -> ['test', 'all', 'values'] * * // Unpack 2 values (by default). First element containing the rest of string. * unpack('test.all.values') -> ['test.all', 'values'] * * // Exception if separator is missing * unpack('test.all values', 3) -> throws BadSignatureException * </code> * * @param string $value String for unpacking. * @param int $limit If $limit === 0 - unpack all values, default - 2. * @return array * @throws BadSignatureException */ protected function unpack($value, $limit = 2) { // Some kind of optimization if ($limit === 0) { if (strpos($value, $this->separator) === false) { throw new BadSignatureException('Separator not found in value'); } return explode($this->separator, $value); } $result = array(); while (--$limit > 0) { $pos = bxstrrpos($value, $this->separator); if ($pos === false) { throw new BadSignatureException('Separator not found in value'); } $result[] = \CUtil::BinSubstr($value, $pos + 1); $value = \CUtil::BinSubstr($value, 0, $pos); } $result[] = $value; return array_reverse($result); }