Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
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.º 3
0
function mobileDiskPrepareForJson($string)
{
    if (!Application::getInstance()->isUtfMode()) {
        return Encoding::convertEncodingArray($string, SITE_CHARSET, 'UTF-8');
    }
    return $string;
}
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 /**
  * @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;
 }
Exemplo n.º 6
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.º 7
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.º 8
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.º 9
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.º 10
0
    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;
    }
Exemplo n.º 11
0
 /**
  * @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];
 }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
0
     $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);
         }
Exemplo n.º 14
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.º 15
0
 protected static function decode($url)
 {
     return Text\Encoding::convertEncodingToCurrent(urldecode($url));
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 17
0
 /**
  * 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);
 }
Exemplo n.º 18
0
 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;
     }
 }
Exemplo n.º 19
0
 protected function convertToUtf8($data)
 {
     if (Application::getInstance()->isUtfMode()) {
         return $data;
     }
     return Encoding::convertEncodingArray($data, SITE_CHARSET, 'UTF-8');
 }
Exemplo n.º 20
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.º 21
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;
 }
Exemplo n.º 22
0
 /**
  * Returns url-decoded and converted to the current encoding URI of the request.
  *
  * @return string
  */
 public function getDecodedUri()
 {
     $page = $this->getRequestUri();
     $page = urldecode($page);
     $page = Text\Encoding::convertEncodingToCurrent($page);
     return $page;
 }
Exemplo n.º 23
0
 protected function prepareQueryResult(array $result)
 {
     return Text\Encoding::convertEncodingArray($result, 'utf-8', LANG_CHARSET);
 }
Exemplo n.º 24
0
 public function getRequestedPage()
 {
     if ($this->requestedFile != null) {
         return $this->requestedFile;
     }
     $page = $this->getRequestUri();
     if (empty($page)) {
         $this->requestedFile = parent::getRequestedPage();
         return $this->requestedFile;
     }
     $page = urldecode($page);
     $page = Text\Encoding::convertEncodingToCurrent($page);
     $this->requestedFile = $this->convertToPath($page);
     return $this->requestedFile;
 }
Exemplo n.º 25
0
 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)));
 }
Exemplo n.º 26
0
 public function getRequestedPage()
 {
     if ($this->requestedFile != null) {
         return $this->requestedFile;
     }
     $page = $this->getRequestUri();
     if ($page == "") {
         return $this->requestedFile = parent::getRequestedPage();
     }
     $page = urldecode($page);
     $page = Text\Encoding::convertEncodingToCurrent($page);
     $uri = new Web\Uri($page, Web\UriType::RELATIVE);
     return $this->requestedFile = $uri->convertToPath();
 }
Exemplo n.º 27
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.º 28
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.º 29
0
 /**
  * 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");
     }
 }
Exemplo n.º 30
0
 private function fixUpRequestUriAndQueryString()
 {
     /** @var $context HttpContext */
     $context = $this->context;
     $queryString = $context->getServer()->get("QUERY_STRING");
     $requestUri = $context->getServer()->get("REQUEST_URI");
     $redirectStatus = $context->getServer()->get("REDIRECT_STATUS");
     //try to fix REQUEST_URI under IIS
     $arProtocols = array('http', 'https');
     foreach ($arProtocols as $protocol) {
         $marker = "404;" . $protocol . "://";
         if (($p = strpos($queryString, $marker)) !== false) {
             $uri = $queryString;
             if (($p = strpos($uri, "/", $p + strlen($marker))) !== false) {
                 if ($requestUri == '' || $requestUri == '/404.php' || strpos($requestUri, $marker) !== false) {
                     $requestUri = substr($uri, $p);
                 }
                 $redirectStatus = '404';
                 $queryString = '';
                 break;
             }
         }
     }
     $requestUri = urldecode($requestUri);
     $requestUri = \Bitrix\Main\Text\Encoding::convertEncodingToCurrent($requestUri);
     $sefApplicationCurPageUrl = $context->getRequest()->get("SEF_APPLICATION_CUR_PAGE_URL");
     if ($redirectStatus == '404' || $sefApplicationCurPageUrl != null) {
         if ($redirectStatus != '404') {
             $requestUri = $sefApplicationCurPageUrl;
         }
         if (($pos = strpos($requestUri, "?")) !== false) {
             $queryString = substr($requestUri, $pos + 1);
         }
     }
     if ($queryString != $context->getServer()->get("QUERY_STRING") || $requestUri != $context->getServer()->get("REQUEST_URI") || $redirectStatus != $context->getServer()->get("REDIRECT_STATUS")) {
         $context->rewriteUri($requestUri, $queryString, $redirectStatus);
     }
 }