/** * Set new secret * * @param string $secret Secret (binary). * @return $this */ public function setSecret($secret) { $this->secret = $secret; // Backward compatibility. This is the old logic and i can't change it right now:-( if (\CUtil::binStrlen($this->secret) > 25) { $this->digest = 'sha256'; } return $this; }
public static function addLogo($token, $domain, $file, &$error) { $http = new \Bitrix\Main\Web\HttpClient(); $boundary = 'CMY' . md5(rand() . time()); $data = ''; $data .= '--' . $boundary . "\r\n"; $data .= 'Content-Disposition: form-data; name="token"' . "\r\n\r\n"; $data .= $token . "\r\n"; $data .= '--' . $boundary . "\r\n"; $data .= 'Content-Disposition: form-data; name="domain"' . "\r\n\r\n"; $data .= $domain . "\r\n"; $data .= '--' . $boundary . "\r\n"; $data .= 'Content-Disposition: form-data; name="file"; filename="file"' . "\r\n"; $data .= 'Content-Type: application/octet-stream' . "\r\n\r\n"; $data .= file_get_contents($file) . "\r\n"; $data .= '--' . $boundary . "--\r\n"; $http->setHeader('Content-type', 'multipart/form-data; boundary=' . $boundary); $http->setHeader('Content-length', CUtil::binStrlen($data)); $response = $http->post('https://pddimp.yandex.ru/api/add_logo.xml', $data); $result = new CDataXML(); $result->loadString($response); if ($logoUrlNode = $result->selectNodes('/action/domains/domain/logo/url')) { return $logoUrlNode->textContent(); } self::setError2($result, $error); return false; }
public static function setLogo($token, $domain, $file, &$error) { $http = new \Bitrix\Main\Web\HttpClient(); $boundary = 'CMY2' . md5(rand() . time()); $data = ''; $data .= '--' . $boundary . "\r\n"; $data .= 'Content-Disposition: form-data; name="token"' . "\r\n\r\n"; $data .= $token . "\r\n"; $data .= '--' . $boundary . "\r\n"; $data .= 'Content-Disposition: form-data; name="domain"' . "\r\n\r\n"; $data .= $domain . "\r\n"; $data .= '--' . $boundary . "\r\n"; $data .= 'Content-Disposition: form-data; name="file"; filename="logo"' . "\r\n"; $data .= 'Content-Type: application/octet-stream' . "\r\n\r\n"; $data .= file_get_contents($file) . "\r\n"; $data .= '--' . $boundary . "--\r\n"; $http->setHeader('Content-type', 'multipart/form-data; boundary=' . $boundary); $http->setHeader('Content-length', CUtil::binStrlen($data)); $response = $http->post('https://pddimp.yandex.ru/api2/admin/domain/logo/set', $data); $result = json_decode($response, true); if (isset($result['success']) && $result['success'] == 'ok') { return true; } self::setError($result, $error); return false; }
/** * Decode Base32 encoded string * * @param string $base32String Base32 encoded string. * @throws ArgumentTypeException * @throws DecodingException * @return string Original data. */ public static function decode($base32String) { if (!$base32String) { return ''; } if (!is_string($base32String)) { throw new ArgumentTypeException('base32String', 'string'); } $base32String = strtoupper($base32String); $base32Array = str_split($base32String); $string = ''; foreach ($base32Array as $str) { // skip padding if ($str === '=') { continue; } if (!isset(self::$alphabet[$str])) { throw new DecodingException(sprintf('Illegal character: %s', $str)); } $char = self::$alphabet[$str]; $char = decbin($char); $string .= str_pad($char, 5, 0, STR_PAD_LEFT); } while (\CUtil::binStrlen($string) % 8 !== 0) { $string = \CUtil::binSubstr($string, 0, -1); } $binaryArray = self::chunk($string, 8); $realString = ''; foreach ($binaryArray as $bin) { // Pad each value to 8 bits $bin = str_pad($bin, 8, 0, STR_PAD_RIGHT); // Convert binary strings to ASCII $realString .= chr(bindec($bin)); } return $realString; }
/** * @param $string * @return bool */ protected static function adjustPcreBacktrackLimit($string) { if (!is_string($string)) { return false; } $strlen = \CUtil::binStrlen($string) * 2; \CUtil::adjustPcreBacktrackLimit($strlen); return true; }
public static function convertCharset($str, $from, $to) { $from = trim(strtolower($from)); $to = trim(strtolower($to)); if (in_array($from, array('utf-8', 'utf8'))) { $regex = '/ ([\\x00-\\x7F] |[\\xC2-\\xDF][\\x80-\\xBF] |\\xE0[\\xA0-\\xBF][\\x80-\\xBF]|[\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]{2}|\\xED[\\x80-\\x9F][\\x80-\\xBF]) |(\\xE0[\\xA0-\\xBF]|[\\xE1-\\xEC\\xEE\\xEF][\\x80-\\xBF]|\\xED[\\x80-\\x9F] |\\xF0[\\x90-\\xBF][\\x80-\\xBF]{0,2}|[\\xF1-\\xF3][\\x80-\\xBF]{1,3}|\\xF4[\\x80-\\x8F][\\x80-\\xBF]{0,2} |[\\x80-\\xFF]) /x'; $str = preg_replace_callback($regex, function ($matches) { return isset($matches[2]) ? str_repeat('?', CUtil::binStrlen($matches[2])) : $matches[1]; }, $str); } if ($result = Bitrix\Main\Text\Encoding::convertEncoding($str, $from, $to, $error)) { $str = $result; } else { addMessage2Log(sprintf('Failed to convert email part. (%s -> %s : %s)', $from, $to, $error)); } return $str; }