protected function flushData() { $fileXml = ""; $feedDataRes = QueueTable::getList(array("filter" => array("FEED_TYPE" => $this->feedType))); $filePrepared = false; while ($feedData = $feedDataRes->fetch()) { if (!$filePrepared) { $fileXml = $this->path . "/xml/" . $this->feedType . "_" . $this->fileNameSalt . ".xml"; $this->prepareFile($fileXml); $filePrepared = true; } Ebay::log(Logger::LOG_LEVEL_DEBUG, "EBAY_DATA_PROCESSOR_SFTPQUEUE_FLUSHING", $this->feedType, print_r($feedData["DATA"], true), $this->siteId); if (strtolower(SITE_CHARSET) != 'utf-8') { $feedData["DATA"] = \Bitrix\Main\Text\Encoding::convertEncoding($feedData["DATA"], SITE_CHARSET, 'UTF-8'); } $res = file_put_contents($fileXml, $feedData["DATA"], FILE_APPEND); if ($res !== false) { QueueTable::delete($feedData["ID"]); } else { throw new SystemException("Can't flush data feed \"" . $this->feedType . "\" to file " . $fileXml); } } if ($this->coverTag !== null && $filePrepared) { file_put_contents($fileXml, "</" . $this->coverTag . ">\n", FILE_APPEND); } return $fileXml; }
/** * @param $trackingNumber * @return \Bitrix\Sale\Delivery\Tracking\StatusResult. */ public function getStatus($trackingNumber) { $result = new StatusResult(); if (!$this->checkTracknumberFormat($trackingNumber)) { $result->addError(new Error(Loc::getMessage('SALE_DELIVERY_TRACKING_RUS_POST_ERROR_TRNUM_FORMAT'))); } if (empty($this->params['LOGIN'])) { $result->addError(new Error(Loc::getMessage("SALE_DELIVERY_TRACKING_RUS_POST_LOGIN_ERROR"))); } if (empty($this->params['PASSWORD'])) { $result->addError(new Error(Loc::getMessage("SALE_DELIVERY_TRACKING_RUS_POST_PASSWORD_ERROR"))); } if ($result->isSuccess()) { try { $t = new RusPostSingle($this->params['LOGIN'], $this->params['PASSWORD']); $result = $t->getOperationHistory($trackingNumber); } catch (\SoapFault $e) { $result->addError(new Error(Encoding::convertEncoding($e->getMessage(), 'UTF-8', SITE_CHARSET))); if (strlen($e->detail->OperationHistoryFaultReason) > 0) { $result->addError(new Error(Encoding::convertEncoding($e->detail->OperationHistoryFaultReason, 'UTF-8', SITE_CHARSET))); } } } return $result; }
/** * @param array $arCity * @return array */ public function getIpByCities($arCity) { $arCityIp = array(); $dataDir = dirname(__DIR__); $CIDRFile = $dataDir . '/data/cidr_optim.txt'; $CitiesFile = $dataDir . '/data/cities.txt'; $this->fhandleCIDR = fopen($CIDRFile, 'r') or die("Cannot open {$CIDRFile}"); $this->fhandleCities = fopen($CitiesFile, 'r') or die("Cannot open {$CitiesFile}"); $city_ids = array(); rewind($this->fhandleCities); while (!feof($this->fhandleCities)) { $str = fgets($this->fhandleCities); $arRecord = explode("\t", trim($str)); $city_name = Encoding::convertEncoding($arRecord[1], 'windows-1251', SITE_CHARSET); if (intval($arCity[$city_name]) > 0) { $city_ids[$arRecord[0]] = $city_name; } } $city_ids[1753] = "Магас"; if (count($city_ids) > 0) { rewind($this->fhandleCIDR); while (!feof($this->fhandleCIDR)) { $str = fgets($this->fhandleCIDR); $arRecord = explode("\t", trim($str)); if (!empty($city_ids[$arRecord[4]])) { $city_name = $city_ids[$arRecord[4]]; $city_site_id = $arCity[$city_name]; $arCityIp[$city_site_id] = $arRecord[2]; } } } unset($arCity); unset($city_ids); return $arCityIp; }
protected function requestData() { $data = '<?xml version="1.0" encoding="utf-8"?> <GeteBayDetailsRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <RequesterCredentials> <eBayAuthToken>' . $this->authToken . '</eBayAuthToken> </RequesterCredentials> </GeteBayDetailsRequest>'; $dataXml = $this->apiCaller->sendRequest("GeteBayDetails", $data); if (strtolower(SITE_CHARSET) != 'utf-8') { $dataXml = Encoding::convertEncoding($dataXml, 'UTF-8', SITE_CHARSET); } $result = Xml2Array::convert($dataXml); return $result; }
/** * @param string $ip * @return mixed */ public function getRecord($ip = null) { if ($ip === null) { $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'; } if (!isset(self::$cacheIp[$ip])) { $result = parent::getRecord($ip); if (is_array($result)) { foreach ($result as $key => $value) { $result[$key] = Encoding::convertEncoding($value, 'windows-1251', SITE_CHARSET); } } self::$cacheIp[$ip] = $result; } return self::$cacheIp[$ip]; }
protected function getItems(array $params = array()) { $data = '<?xml version="1.0" encoding="utf-8"?> <GetCategoriesRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <RequesterCredentials> <eBayAuthToken>' . $this->authToken . '</eBayAuthToken> </RequesterCredentials> <CategorySiteID>' . $this->ebaySiteId . '</CategorySiteID> <WarningLevel>' . $this->warningLevel . '</WarningLevel>' . "\n"; $data .= $this->array2Tags($params); $data .= '</GetCategoriesRequest>?'; $categoriesXml = $this->apiCaller->sendRequest("GetCategories", $data); if (strtolower(SITE_CHARSET) != 'utf-8') { $categoriesXml = Encoding::convertEncoding($categoriesXml, 'UTF-8', SITE_CHARSET); } $result = Xml2Array::convert($categoriesXml); return $result; }
public static function convertPhysicalToUri($path) { if (self::$physicalEncoding == "") { self::$physicalEncoding = self::getPhysicalEncoding(); } if (self::$directoryIndex == null) { self::$directoryIndex = self::getDirectoryIndexArray(); } if (isset(self::$directoryIndex[self::getName($path)])) { $path = self::getDirectory($path) . "/"; } if ('utf-8' !== self::$physicalEncoding) { $path = Text\Encoding::convertEncoding($path, self::$physicalEncoding, 'utf-8'); } return implode('/', array_map("rawurlencode", explode('/', $path))); }
$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"]; \Bitrix\MobileApp\Designer\Manager::bindTemplate($templateId, $fields["FOLDER"], $createTemplate); }
/** * Returns a filename from the Content-disposition header. * * @return string|null Filename if it was found in the Content-disposition header or null otherwise. */ public function getFilename() { $contentDisposition = $this->get('Content-disposition'); if ($contentDisposition !== null) { $filename = null; $encoding = null; $contentElements = explode(';', $contentDisposition); foreach ($contentElements as $contentElement) { $contentElement = trim($contentElement); if (preg_match('/^filename\\*=(.+)\'(.+)?\'(.+)$/', $contentElement, $matches)) { $filename = $matches[3]; $encoding = $matches[1]; break; } elseif (preg_match('/^filename="(.+)"$/', $contentElement, $matches)) { $filename = $matches[3]; } } if ($filename != '') { $filename = urldecode($filename); if ($encoding != '') { $charset = \Bitrix\Main\Context::getCurrent()->getCulture()->getCharset(); $filename = \Bitrix\Main\Text\Encoding::convertEncoding($filename, $encoding, $charset); } } return $filename; } return null; }
/** * Converts string from utf-8 in site charset and returns it * * @param string $s * * @return string */ public static function ConvertFromUtf($s = '') { return defined("BX_UTF") ? $s : Encoding::convertEncoding($s, 'UTF-8', SITE_CHARSET); }
protected function queryOld($scope, $method = "GET", $data = null, $skipRefreshAuth = false) { if ($this->engineSettings['AUTH']) { $http = new \CHTTP(); $http->setAdditionalHeaders(array('Authorization' => 'OAuth ' . $this->engineSettings['AUTH']['access_token'])); $http->setFollowRedirect(false); switch ($method) { case 'GET': $result = $http->get($scope); break; case 'POST': $result = $http->post($scope, $data); break; case 'PUT': $result = $http->httpQuery($method, $scope, $http->prepareData($data)); break; case 'DELETE': break; } if ($http->status == 401 && !$skipRefreshAuth) { if ($this->checkAuthExpired(false)) { $this->queryOld($scope, $method, $data, true); } } $http->result = Text\Encoding::convertEncoding($http->result, 'utf-8', LANG_CHARSET); return $http; } }
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; }
/** * Returns HttpClient object with query result * * @param string $method Method * @param array $param array of query data * @param bool $skipRefreshAuth Skip authorization refresh. Doesn't work with Yandex. * * @returns \Bitrix\Main\Web\HttpClient * @throws SystemException */ protected function query($method, $param = array(), $skipRefreshAuth = false) { if ($this->engineSettings['AUTH']) { $http = new HttpClient(); $http->setRedirect(false); $http->setHeader("Content-Type", "application/json; charset=utf-8"); $postData = array("method" => $method, "locale" => $this->locale, "token" => $this->engineSettings['AUTH']['access_token']); if (!empty($param)) { $postData["param"] = $param; } $postData = YandexJson::encode($postData, JSON_UNESCAPED_UNICODE); $ts = microtime(true); $http->post(static::API_URL, $postData); LogTable::add(array('ENGINE_ID' => $this->getId(), 'REQUEST_URI' => static::API_URL, 'REQUEST_DATA' => Text\Encoding::convertEncoding($postData, 'UTF-8', SITE_CHARSET), 'RESPONSE_TIME' => microtime(true) - $ts, 'RESPONSE_STATUS' => $http->getStatus(), 'RESPONSE_DATA' => Text\Encoding::convertEncoding($http->getResult(), 'UTF-8', SITE_CHARSET))); if ($http->getStatus() == 401 && !$skipRefreshAuth) { if ($this->checkAuthExpired(false)) { $this->query($method, $param, true); } } return $http; } else { throw new SystemException("No Yandex auth data"); } }
/** * Sanitizes string and converts it to the site's charset. * * @param string $str Input string. * @return string */ protected function filterString($str) { $sanitizer = new \CBXSanitizer(); $sanitizer->SetLevel(\CBXSanitizer::SECURE_LEVEL_HIGH); $sanitizer->ApplyHtmlSpecChars(false); $str = html_entity_decode($str, ENT_QUOTES, $this->getEncoding()); $str = Encoding::convertEncoding($str, $this->getEncoding(), Context::getCurrent()->getCulture()->getCharset()); $str = trim($str); $str = $sanitizer->SanitizeHtml($str); return $str; }
protected static function convertCharset($path, $direction = 1) { static $physicalEncoding = ""; if ($physicalEncoding == "") { $physicalEncoding = self::getPhysicalEncoding(); } static $logicalEncoding = ""; if ($logicalEncoding == "") { $logicalEncoding = self::getLogicalEncoding(); } if ($physicalEncoding == $logicalEncoding) { return $path; } if ($direction == self::LOGICAL_TO_PHYSICAL) { $result = Text\Encoding::convertEncoding($path, $logicalEncoding, $physicalEncoding); } else { $result = Text\Encoding::convertEncoding($path, $physicalEncoding, $logicalEncoding); } return $result; }