Exemplo n.º 1
0
 /**
  * Downloads and parses HTML's document metadata, formatted with oEmbed standard.
  *
  * @param HtmlDocument $document HTML document.
  */
 public function handle(HtmlDocument $document)
 {
     if (!$this->detectOembedLink($document) || strlen($this->metadataUrl) == 0) {
         return;
     }
     $httpClient = new HttpClient();
     $rawMetadata = $httpClient->get($this->metadataUrl);
     if ($rawMetadata === false) {
         return;
     }
     $parsedMetadata = $this->parseMetadata($rawMetadata);
     if ($parsedMetadata !== false) {
         if (strlen($this->metadataEncoding) > 0 && $document->getEncoding() !== $this->metadataEncoding) {
             $parsedMetadata = Encoding::convertEncodingArray($parsedMetadata, $this->metadataEncoding, $document->getEncoding());
         }
         if ($document->getTitle() == '' && $parsedMetadata['title'] != '') {
             $document->setTitle($parsedMetadata['title']);
         }
         if ($document->getImage() == '' && $parsedMetadata['thumbnail_url'] != '') {
             $document->setImage($parsedMetadata['thumbnail_url']);
         }
         if ($document->getEmdbed() == '' && $parsedMetadata['html'] != '') {
             $document->setEmbed($parsedMetadata['html']);
         }
     }
 }
Exemplo n.º 2
0
function mobileDiskPrepareForJson($string)
{
    if (!Application::getInstance()->isUtfMode()) {
        return Encoding::convertEncodingArray($string, SITE_CHARSET, 'UTF-8');
    }
    return $string;
}
Exemplo n.º 3
0
 public function sendRequest($callName, $data, $devId = "", $apiAppId = "", $certId = "")
 {
     if (strlen($callName) <= 0) {
         throw new ArgumentNullException("callName");
     }
     $this->http->setHeader("X-EBAY-API-CALL-NAME", $callName);
     if (strlen($devId) > 0) {
         $this->http->setHeader("X-EBAY-API-DEV-NAME", $devId);
     }
     if (strlen($apiAppId) > 0) {
         $this->http->setHeader("X-EBAY-API-APP-NAME", $apiAppId);
     }
     if (strlen($certId) > 0) {
         $this->http->setHeader("X-EBAY-API-CERT-NAME", $certId);
     }
     if (strtolower(SITE_CHARSET) != 'utf-8') {
         $data = Encoding::convertEncodingArray($data, SITE_CHARSET, 'UTF-8');
     }
     $result = @$this->http->post($this->apiUrl, $data);
     $errors = $this->http->getError();
     if (!$result && !empty($errors)) {
         $strError = "";
         foreach ($errors as $errorCode => $errMes) {
             $strError .= $errorCode . ": " . $errMes;
         }
         throw new SystemException($strError);
     } else {
         $status = $this->http->getStatus();
         if ($status != 200) {
             throw new SystemException(sprintf('HTTP error code: %d', $status));
         }
     }
     return $result;
 }
Exemplo n.º 4
0
 function __CrmActivityViewPrepareNameForJson($string)
 {
     if (!\Bitrix\Main\Application::getInstance()->isUtfMode()) {
         return \Bitrix\Main\Text\Encoding::convertEncodingArray($string, SITE_CHARSET, 'UTF-8');
     }
     return $string;
 }
Exemplo n.º 5
0
 /**
  * @param array $values
  * @return array
  */
 public function filter(array $values)
 {
     if (Application::getInstance()->isUtfMode()) {
         return null;
     }
     if (empty($values['post']) || !is_array($values['post'])) {
         return null;
     }
     return array('post' => Encoding::convertEncodingArray($values['post'], 'UTF-8', SITE_CHARSET));
 }
Exemplo n.º 6
0
 protected function parseCalcResult($jsonInfo)
 {
     global $APPLICATION;
     $arInfo = json_decode($jsonInfo, true);
     if (is_array($arInfo) && !empty($arInfo)) {
         if (strtolower(SITE_CHARSET) != 'utf-8') {
             $arInfo = \Bitrix\Main\Text\Encoding::convertEncodingArray($arInfo, 'UTF-8', SITE_CHARSET);
         }
         if (isset($arInfo[$this->profileId][2])) {
             $price = 0;
             $price += intval($arInfo[$this->profileId][2]);
             if (isset($arInfo["take"][2]) && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_ENABLED')) {
                 $price += intval($arInfo["take"][2]);
             }
             if (isset($arInfo["deliver"][2]) && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_ENABLED')) {
                 $price += intval($arInfo["deliver"][2]);
             }
             foreach ($arInfo as $key => $value) {
                 if (substr($key, 0, 3) == "ADD") {
                     $price += intval($arInfo[$key][2]);
                 }
             }
             $arResult = array('RESULT' => 'OK', 'VALUE' => $price, 'PACKS_COUNT' => $this->packsCount);
             $period = "";
             if ($this->profileId == "auto" && !empty($arInfo["periods"])) {
                 $period = $arInfo["periods"];
             } elseif ($this->profileId == "avia" && !empty($arInfo["aperiods"])) {
                 $period = $arInfo["aperiods"];
             }
             if (strlen($period) > 0) {
                 $pos = strpos($period, ':');
                 if ($pos !== false) {
                     $CBXSanitizer = new \CBXSanitizer();
                     $CBXSanitizer->DelAllTags();
                     $arResult["TRANSIT"] = " (" . GetMessage("SALE_DH_PECOM_PERIOD_DAYS") . ") " . $CBXSanitizer->SanitizeHtml(substr($period, $pos + 1));
                 }
             }
         } else {
             if (isset($arInfo["error"])) {
                 $error = implode("<br>", $arInfo["error"]);
                 if (strtolower(SITE_CHARSET) != 'utf-8') {
                     $error = $APPLICATION->ConvertCharset($error, 'utf-8', SITE_CHARSET);
                 }
             } else {
                 $error = GetMessage("SALE_DH_PECOM_ERROR");
             }
             $arResult = array('RESULT' => 'ERROR', 'TEXT' => $error);
         }
     } else {
         $arResult = array('RESULT' => 'ERROR', 'TEXT' => GetMessage("SALE_DH_PECOM_ERROR_NO_RESULTS"));
     }
     return $arResult;
 }
Exemplo n.º 7
0
 /**
  * @param string $xmlData XML.
  * @return array Converted.
  */
 public static function convert($xmlData, $convertCharset = true)
 {
     if (strlen($xmlData) <= 0) {
         return array();
     }
     $result = array();
     if ($convertCharset && strtolower(SITE_CHARSET) != 'utf-8') {
         $xmlData = \Bitrix\Main\Text\Encoding::convertEncodingArray($xmlData, SITE_CHARSET, 'UTF-8');
     }
     //	$xmlData = preg_replace('/[[:^print:]]/', '', $xmlData);
     $results = new \SimpleXMLElement($xmlData, LIBXML_NOCDATA);
     if ($results && ($jsonString = json_encode($results))) {
         $result = json_decode($jsonString, TRUE);
     }
     if (strtolower(SITE_CHARSET) != 'utf-8') {
         $result = \Bitrix\Main\Text\Encoding::convertEncodingArray($result, 'UTF-8', SITE_CHARSET);
     }
     return $result;
 }
 public function Send(array $request)
 {
     $method = isset($request['METHOD']) ? strtoupper($request['METHOD']) : '';
     if ($method !== \Bitrix\Main\Web\HttpClient::HTTP_GET && $method !== \Bitrix\Main\Web\HttpClient::HTTP_POST) {
         throw new Bitrix\Main\ArgumentException("Could not find 'METHOD'.", 'request');
     }
     $path = isset($request['PATH']) && is_string($request['PATH']) ? $request['PATH'] : '';
     if ($path === '') {
         throw new Bitrix\Main\ArgumentException("Could not find 'PATH'.", 'request');
     }
     $postData = $method === \Bitrix\Main\Web\HttpClient::HTTP_POST && isset($request['BODY']) ? $request['BODY'] : null;
     if (!$this->client) {
         $this->client = new \Bitrix\Main\Web\HttpClient();
     }
     $this->client->setRedirect(false);
     if ($method === \Bitrix\Main\Web\HttpClient::HTTP_POST && is_array($postData)) {
         //Force UTF encoding
         $this->client->setCharset('UTF-8');
         if ((!isset($request['UTF']) || !$request['UTF']) && !defined('BX_UTF')) {
             $postData = \Bitrix\Main\Text\Encoding::convertEncodingArray($postData, SITE_CHARSET, 'UTF-8');
         }
     }
     $headers = isset($request['HEADERS']) ? $request['HEADERS'] : null;
     if (is_array($headers)) {
         foreach ($headers as $k => $v) {
             $this->client->setHeader($k, $v, true);
         }
     }
     if (!empty($this->cookies)) {
         $this->client->setCookies($this->cookies);
     }
     if ($this->enableProxy) {
         $this->client->setProxy($this->proxyServer, $this->proxyPort, $this->proxyUserName, $this->proxyUserPassword);
     }
     if ($this->userName !== '') {
         $this->client->setAuthorization($this->userName, $this->userPassword);
     }
     $this->client->setHeader('User-Agent', $this->userAgent, true);
     $absolutePath = $this->GetUrl() . $path;
     if (!$this->client->query($method, $absolutePath, $postData)) {
         $this->responseData = null;
         $this->errors = $this->client->getError();
     } else {
         /**@var \Bitrix\Main\Web\HttpHeaders*/
         $responseHeaders = $this->client->getHeaders();
         //STATUS.VERSION & STATUS.PHRASE are delcared for backward compatibility only.
         $this->responseData = array('STATUS' => array('VERSION' => '', 'CODE' => $this->client->getStatus(), 'PHRASE' => ''), 'CONTENT' => array('TYPE' => $this->client->getContentType(), 'ENCODING' => $this->client->getCharset()), 'HEADERS' => $responseHeaders, 'BODY' => $this->client->getResult());
         if ($responseHeaders->get('Set-Cookie', false) !== null) {
             $this->cookies = array_merge($this->cookies, $this->client->getCookies()->toArray());
             CCrmExternalSale::Update($this->externalSaleId, array('COOKIE' => serialize($this->cookies)));
         }
         $this->errors = array();
     }
     return $this->responseData;
 }
Exemplo n.º 9
0
				);
				if (empty($arResult["OFFERS"]))
				{
					$counterData['price'] = (isset($arResult['MIN_PRICE']) ? $arResult['MIN_PRICE']['DISCOUNT_VALUE'] : '');
					$counterData['currency'] = (isset($arResult['MIN_PRICE']) ? $arResult['MIN_PRICE']['CURRENCY'] : '');
				}
				else
				{
					$offer = current($arResult["OFFERS"]);
					$counterData['price'] = (isset($offer['MIN_PRICE']) ? $offer['MIN_PRICE']['DISCOUNT_VALUE'] : '');
					$counterData['currency'] = (isset($offer['MIN_PRICE']) ? $offer['MIN_PRICE']['CURRENCY'] : '');
					unset($offer);
				}

				// make sure it is in utf8
				$counterData = \Bitrix\Main\Text\Encoding::convertEncodingArray($counterData, SITE_CHARSET, 'UTF-8');

				// pack value and protocol version
				$arResult['counterData'] = array(
					'value' => base64_encode(json_encode($counterData)),
					'v' => '1'
				);
				$resultCacheKeys[] = 'counterData';
			}

			$this->SetResultCacheKeys($resultCacheKeys);

			// standard output
			$this->IncludeComponentTemplate();

			if ($bCatalog && $boolNeedCatalogCache)
Exemplo n.º 10
0
$answer = array("success" => false, "message" => Loc::getMessage("main_app_passwords_ajax_error"));
if (!$USER->IsAuthorized()) {
    $answer["message"] = Loc::getMessage("main_app_passwords_ajax_error_auth");
    echo Json::encode($answer);
    die;
}
if (!check_bitrix_sessid()) {
    $answer["message"] = Loc::getMessage("main_app_passwords_ajax_error_sess");
    echo Json::encode($answer);
    die;
}
$context = Bitrix\Main\Context::getCurrent();
$request = $context->getRequest();
if ($request->isPost()) {
    $post = $request->getPostList()->toArray();
    $post = Main\Text\Encoding::convertEncodingArray($post, "UTF-8", $context->getCulture()->getCharset());
    if ($post["action"] == "delete" && ($id = intval($post["ID"])) > 0) {
        //deleting the application password
        if (ApplicationPasswordTable::getRow(array("filter" => array("=ID" => $id, "=USER_ID" => $USER->GetID()))) !== null) {
            $result = ApplicationPasswordTable::delete($id);
            if ($result->isSuccess()) {
                $answer["success"] = true;
                $answer["message"] = Loc::getMessage("main_app_passwords_ajax_deleted");
            } else {
                $answer["message"] = implode("<br>", $result->getErrorMessages());
            }
        }
    } elseif ($post["action"] == "add") {
        //adding a new application password
        $appManager = ApplicationManager::getInstance();
        $applications = $appManager->getApplications();
Exemplo n.º 11
0
 /**
  * Return configuration in JSON format
  *
  * @param $appCode - application code
  * @param bool $platform - platform code
  *
  * @see ConfigTable::getSupportedPlatforms for details on availible platforms
  * @return string
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function getConfigJSON($appCode, $platform = false)
 {
     $map = new \Bitrix\MobileApp\Designer\ConfigMap();
     $res = ConfigTable::getList(array("filter" => array("APP_CODE" => $appCode)));
     $configs = $res->fetchAll();
     $targetConfig = array();
     for ($i = 0; $i < count($configs); $i++) {
         if ($configs[$i]["PLATFORM"] == $platform) {
             $targetConfig = $configs[$i];
             break;
         } elseif ($configs[$i]["PLATFORM"] == "global") {
             $targetConfig = $configs[$i];
         }
     }
     $params = array_key_exists("PARAMS", $targetConfig) ? $targetConfig["PARAMS"] : array();
     $imageParamList = $map->getParamsByType(ParameterType::IMAGE);
     $imageSetParamList = $map->getParamsByType(ParameterType::IMAGE_SET);
     $structuredConfig = array();
     foreach ($params as $key => $value) {
         if (!$map->has($key)) {
             continue;
         }
         if (array_key_exists($key, $imageParamList)) {
             $imagePath = \CFile::GetPath($value);
             if (strlen($imagePath) > 0) {
                 $value = $imagePath;
             } else {
                 continue;
             }
         }
         if (array_key_exists($key, $imageSetParamList)) {
             $tmpValue = array();
             foreach ($value as $imageCode => $imageId) {
                 $imagePath = \CFile::GetPath($imageId);
                 if (strlen($imagePath) > 0) {
                     $tmpValue[$imageCode] = $imagePath;
                 } else {
                     continue;
                 }
             }
             $value = $tmpValue;
         }
         $structuredConfig = array_merge_recursive(self::nameSpaceToArray($key, $value), $structuredConfig);
     }
     $structuredConfig["info"] = array("designer_version" => ConfigMap::VERSION, "platform" => $platform);
     if (toUpper(SITE_CHARSET) != "UTF-8") {
         $structuredConfig = Encoding::convertEncodingArray($structuredConfig, SITE_CHARSET, "UTF-8");
     }
     return json_encode($structuredConfig);
 }
Exemplo n.º 12
0
     break;
 case "removePlatform":
     $code = $_REQUEST["code"];
     $platform = $_REQUEST["platform"];
     $status = Bitrix\MobileApp\Designer\Manager::removeConfig($code, $platform);
     break;
 case "createPlatform":
     $status = \Bitrix\MobileApp\Designer\Manager::addConfig($_REQUEST["code"], $_REQUEST["platform"], array());
     break;
 case "createApp":
     $code = $_REQUEST["code"];
     $createTemplate = $_REQUEST["createNew"] === "Y";
     $bindTemplate = $_REQUEST["bindTemplate"] === "Y";
     $fields = array("FOLDER" => $_REQUEST["folder"], "NAME" => $_REQUEST["name"]);
     if (!\Bitrix\Main\Application::isUtfMode()) {
         $fields = \Bitrix\Main\Text\Encoding::convertEncodingArray($fields, "UTF-8", SITE_CHARSET);
         $code = \Bitrix\Main\Text\Encoding::convertEncoding($code, "UTF-8", SITE_CHARSET);
         $templateName = \Bitrix\Main\Text\Encoding::convertEncoding($templateName, "UTF-8", SITE_CHARSET);
     }
     $result = \Bitrix\MobileApp\Designer\Manager::createApp($code, $fields);
     //creating global config inside
     if ($result == \Bitrix\MobileApp\Designer\Manager::IS_ALREADY_EXISTS) {
         $APPLICATION->RestartBuffer();
         echo CUtil::PhpToJSObject(array("status" => "is_already_exists"));
         die;
     }
     $status = $result == \Bitrix\MobileApp\Designer\Manager::SUCCESS;
     if ($status) {
         \Bitrix\MobileApp\Designer\Manager::copyFromTemplate($fields["FOLDER"], $code);
         if ($bindTemplate) {
             $templateId = $_REQUEST["template_id"];
Exemplo n.º 13
0
 protected function prepareQueryResult(array $result)
 {
     return Text\Encoding::convertEncodingArray($result, 'utf-8', LANG_CHARSET);
 }
Exemplo n.º 14
0
 public static function convertEncodingArray($arData, $charsetFrom, $charsetTo, &$errorMessage = "")
 {
     if (!is_array($arData)) {
         if (is_string($arData)) {
             $arData = Encoding::convertEncoding($arData, $charsetFrom, $charsetTo, $errorMessage);
         }
     } else {
         foreach ($arData as $key => $value) {
             $s = '';
             $newKey = Encoding::convertEncoding($key, $charsetFrom, $charsetTo, $s);
             $arData[$newKey] = Encoding::convertEncodingArray($value, $charsetFrom, $charsetTo, $s);
             if ($newKey != $key) {
                 unset($arData[$key]);
             }
             if ($s !== '') {
                 $errorMessage .= ($errorMessage == "" ? "" : "\n") . $s;
             }
         }
     }
     return $arData;
 }
Exemplo n.º 15
0
 /**
  * @param string $iblockType This variable is the id iblockType.
  * @param string $datum This variable is the encrypted string.
  * @param null $siteId This variable is the id current site.
  * @throws Main\ArgumentNullException
  */
 public static function import($iblockType, $datum, $siteId = null)
 {
     if (empty($datum)) {
         throw new Main\ArgumentNullException("datum");
     }
     if (substr($datum, 0, 10) === "compressed") {
         $datum = gzuncompress(Main\Text\String::getBinarySubstring($datum, 10));
     }
     $len = intval(Main\Text\String::getBinarySubstring($datum, 0, 10));
     $iblockSerialized = Main\Text\String::getBinarySubstring($datum, 10, $len);
     $datum = Main\Text\String::getBinarySubstring($datum, $len + 10);
     $marker = Main\Text\String::getBinarySubstring($datum, 0, 1);
     $picture = null;
     $pictureType = null;
     if ($marker == "P") {
         $len = intval(Main\Text\String::getBinarySubstring($datum, 1, 10));
         $pictureType = Main\Text\String::getBinarySubstring($datum, 11, $len);
         $datum = Main\Text\String::getBinarySubstring($datum, $len + 11);
         $len = intval(Main\Text\String::getBinarySubstring($datum, 0, 10));
         $picture = Main\Text\String::getBinarySubstring($datum, 10, $len);
         $datum = Main\Text\String::getBinarySubstring($datum, $len + 10);
         $marker = Main\Text\String::getBinarySubstring($datum, 0, 1);
     }
     $iblock = CheckSerializedData($iblockSerialized) ? unserialize($iblockSerialized) : array();
     $iblock = Main\Text\Encoding::convertEncodingArray($iblock, "UTF-8", LANG_CHARSET);
     $iblockId = static::createIBlock($iblockType, $iblock, $pictureType, $picture, $siteId);
     if ($iblockId > 0) {
         $documentType = self::getDocumentType($iblockType, $iblockId);
         while (!empty($datum)) {
             if ($marker == "B") {
                 $len = intval(Main\Text\String::getBinarySubstring($datum, 1, 10));
                 $bpDescr = Main\Text\String::getBinarySubstring($datum, 11, $len);
                 $datum = Main\Text\String::getBinarySubstring($datum, $len + 11);
                 $bpDescr = CheckSerializedData($bpDescr) ? unserialize($bpDescr) : array();
                 $bpDescr = Main\Text\Encoding::convertEncodingArray($bpDescr, "UTF-8", LANG_CHARSET);
                 $len = intval(Main\Text\String::getBinarySubstring($datum, 0, 10));
                 $bp = Main\Text\String::getBinarySubstring($datum, 10, $len);
                 $datum = Main\Text\String::getBinarySubstring($datum, $len + 10);
                 static::importTemplate($documentType, $bpDescr, $bp);
             } else {
             }
             if (empty($datum)) {
                 break;
             }
             $marker = Main\Text\String::getBinarySubstring($datum, 0, 1);
         }
     }
 }
Exemplo n.º 16
0
 protected function convertToUtf8($data)
 {
     if (Application::getInstance()->isUtfMode()) {
         return $data;
     }
     return Encoding::convertEncodingArray($data, SITE_CHARSET, 'UTF-8');
 }
Exemplo n.º 17
0
 protected static function unConvertData($data)
 {
     return Encoding::convertEncodingArray($data, 'UTF-8', SITE_CHARSET);
 }
Exemplo n.º 18
0
 protected function sendRequest($operationName, $data)
 {
     $this->http->setHeader("X-EBAY-SOA-CONTENT-TYPE", "text/xml");
     $this->http->setHeader("X-EBAY-SOA-GLOBAL-ID", "EBAY-RU");
     $this->http->setHeader("X-EBAY-SOA-SERVICE-NAME", "SellerProfilesManagementService");
     $this->http->setHeader("X-EBAY-SOA-OPERATION-NAME", $operationName);
     //addSellerProfile getSellerProfiles
     $this->http->setHeader("X-EBAY-SOA-REQUEST-DATA-FORMAT", "XML");
     $this->http->setHeader("X-EBAY-SOA-RESPONSE-DATA-FORMAT", "XML");
     $this->http->setHeader("X-EBAY-SOA-SECURITY-TOKEN", $this->authToken);
     if (strtolower(SITE_CHARSET) != 'utf-8') {
         $data = Encoding::convertEncodingArray($data, SITE_CHARSET, 'UTF-8');
     }
     $result = $this->http->post(self::URL, $data);
     $errors = $this->http->getError();
     if (!$result && !empty($errors)) {
         $strError = "";
         foreach ($errors as $errorCode => $errMes) {
             $strError .= $errorCode . ": " . $errMes;
         }
         Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_POLICY_REQUEST_ERROR", $operationName, $strError, $this->siteId);
     } else {
         $status = $this->http->getStatus();
         if ($status != 200) {
             Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_POLICY_REQUEST_HTTP_ERROR", $operationName, 'HTTP error code: ' . $status, $this->siteId);
         }
         if (strtolower(SITE_CHARSET) != 'utf-8') {
             $result = Encoding::convertEncodingArray($result, 'UTF-8', SITE_CHARSET);
         }
     }
     return $result;
 }
Exemplo n.º 19
0
 public function refreshVariationsTableData(array $ebayCategoriesIds = array())
 {
     $refreshedCount = 0;
     $specXml = $this->getItemSpecifics(array("CategoryID" => empty($ebayCategoriesIds) ? $this->getMappedCategories() : $ebayCategoriesIds));
     $specifics = new \SimpleXMLElement($specXml, LIBXML_NOCDATA);
     foreach ($specifics->Recommendations as $categoryRecommendation) {
         foreach ($categoryRecommendation->NameRecommendation as $nameRecommendation) {
             $fields = array("CATEGORY_ID" => $categoryRecommendation->CategoryID->__toString(), "NAME" => $nameRecommendation->Name->__toString());
             if (isset($nameRecommendation->ValidationRules)) {
                 if ($nameRecommendation->ValidationRules->MinValues) {
                     $fields["MIN_VALUES"] = $nameRecommendation->ValidationRules->MinValues->__toString();
                 } else {
                     $fields["MIN_VALUES"] = 0;
                 }
                 if ($nameRecommendation->ValidationRules->MinValues) {
                     $fields["MAX_VALUES"] = $nameRecommendation->ValidationRules->MaxValues->__toString();
                 } else {
                     $fields["MAX_VALUES"] = 0;
                 }
                 $fields["REQUIRED"] = intval($fields["MIN_VALUES"]) > 0 ? "Y" : "N";
                 $fields["SELECTION_MODE"] = $nameRecommendation->ValidationRules->SelectionMode->__toString();
                 $fields["ALLOWED_AS_VARIATION"] = $nameRecommendation->ValidationRules->VariationSpecifics->__toString() == "Enabled" ? "Y" : "N";
                 $fields["HELP_URL"] = $nameRecommendation->ValidationRules->HelpURL->__toString();
             }
             if (isset($nameRecommendation->ValueRecommendation)) {
                 $values = array();
                 foreach ($nameRecommendation->ValueRecommendation as $valueRecommendation) {
                     $values[] = $valueRecommendation->Value->__toString();
                 }
                 $fields["VALUE"] = $values;
             }
             if (strtolower(SITE_CHARSET) != 'utf-8') {
                 $fields = \Bitrix\Main\Text\Encoding::convertEncodingArray($fields, 'UTF-8', SITE_CHARSET);
             }
             $res = CategoryVariationTable::getList(array("filter" => array("CATEGORY_ID" => $fields["CATEGORY_ID"], "NAME" => $fields["NAME"]), "select" => array("ID")));
             if ($savedVar = $res->fetch()) {
                 $result = CategoryVariationTable::update($savedVar["ID"], $fields);
             } else {
                 $result = CategoryVariationTable::add($fields);
             }
             if ($result > 0) {
                 $refreshedCount++;
             }
         }
     }
     return $refreshedCount;
 }