public function SendCDNRequest($settings, $verb, $bucket, $file_name = '', $params = '', $content = false, $additional_headers = array())
 {
     $arToken = $this->_GetToken($settings["HOST"], $settings["USER"], $settings["KEY"]);
     if (!$arToken) {
         return false;
     }
     if (isset($arToken["X-CDN-Management-Url"])) {
         if (preg_match("#^http://(.*?)(|:\\d+)(/.*)\$#", $arToken["X-CDN-Management-Url"], $arCDN)) {
             $Host = $arCDN[1];
             $Port = $arCDN[2] ? substr($arCDN[2], 1) : 80;
             $Urn = $arCDN[3];
             $Proto = "";
         } elseif (preg_match("#^https://(.*?)(|:\\d+)(/.*)\$#", $arToken["X-CDN-Management-Url"], $arCDN)) {
             $Host = $arCDN[1];
             $Port = $arCDN[2] ? substr($arCDN[2], 1) : 443;
             $Urn = $arCDN[3];
             $Proto = "ssl://";
         } else {
             return false;
         }
     } else {
         return false;
     }
     $obRequest = new CHTTP();
     $obRequest->additional_headers["X-Auth-Token"] = $arToken["X-Auth-Token"];
     foreach ($additional_headers as $key => $value) {
         $obRequest->additional_headers[$key] = $value;
     }
     $obRequest->Query($verb, $Host, $Port, $Urn . CCloudUtil::URLEncode("/" . $bucket . $file_name . $params, "UTF-8"), $content, $Proto);
     return $obRequest;
 }
 function SendRequest($access_key, $secret_key, $verb, $bucket, $file_name = '/', $params = '')
 {
     global $APPLICATION;
     $this->status = 0;
     $RequestMethod = $verb;
     $RequestHost = "sts.amazonaws.com";
     $RequestURI = "/";
     $RequestParams = "";
     $params['SignatureVersion'] = 2;
     $params['SignatureMethod'] = 'HmacSHA1';
     $params['AWSAccessKeyId'] = $access_key;
     $params['Timestamp'] = gmdate('Y-m-d') . 'T' . gmdate('H:i:s');
     //.preg_replace("/(\d\d)\$/", ":\\1", date("O"));
     $params['Version'] = '2011-06-15';
     ksort($params);
     foreach ($params as $name => $value) {
         if ($RequestParams != '') {
             $RequestParams .= '&';
         }
         $RequestParams .= urlencode($name) . "=" . urlencode($value);
     }
     $StringToSign = "{$RequestMethod}\n" . "{$RequestHost}\n" . "{$RequestURI}\n" . "{$RequestParams}";
     $Signature = urlencode(base64_encode($this->hmacsha1($StringToSign, $secret_key)));
     $obRequest = new CHTTP();
     $obRequest->Query($RequestMethod, $RequestHost, 443, $RequestURI . "?{$RequestParams}&Signature={$Signature}", false, 'ssl://');
     $this->status = $obRequest->status;
     $this->headers = $obRequest->headers;
     $this->errno = $obRequest->errno;
     $this->errstr = $obRequest->errstr;
     $this->result = $obRequest->result;
     if ($obRequest->status == 200) {
         if ($obRequest->result) {
             $obXML = new CDataXML();
             $text = preg_replace("/<" . "\\?XML.*?\\?" . ">/i", "", $obRequest->result);
             if ($obXML->LoadString($text)) {
                 $arXML = $obXML->GetArray();
                 if (is_array($arXML)) {
                     return $arXML;
                 }
             }
             //XML parse error
             $APPLICATION->ThrowException(GetMessage('CLO_SECSERV_S3_XML_PARSE_ERROR', array('#errno#' => 1)));
             return false;
         } else {
             //Empty success result
             return array();
         }
     } elseif ($obRequest->status > 0) {
         if ($obRequest->result) {
             $APPLICATION->ThrowException(GetMessage('CLO_SECSERV_S3_XML_ERROR', array('#errmsg#' => $obRequest->result)));
             return false;
         }
         $APPLICATION->ThrowException(GetMessage('CLO_SECSERV_S3_XML_PARSE_ERROR', array('#errno#' => 2)));
         return false;
     } else {
         $APPLICATION->ThrowException(GetMessage('CLO_SECSERV_S3_XML_PARSE_ERROR', array('#errno#' => 3)));
         return false;
     }
 }
 function GetBoardFromSite($queryParameters)
 {
     global $APPLICATION;
     $result = array();
     $ob = new CHTTP();
     $ob->http_timeout = 60;
     $ob->Query("GET", "old.vnukovo.ru", 80, "/rus/for-passengers/board1/data.wbp?" . $queryParameters . '&ts=' . mktime(), false, "", "N");
     $result["ERROR"]["CODE"] = $ob->errno;
     $result["ERROR"]["MESSAGE"] = $ob->errstr;
     if (!intval($result["ERROR"]["CODE"])) {
         $res = $APPLICATION->ConvertCharset($ob->result, "UTF-8", SITE_CHARSET);
         //trace($res);
         $xml = new CDataXML();
         if ($xml->LoadString($res) && ($node = $xml->SelectNodes("/responce/rows"))) {
             $rows = $node->elementsByName("row");
             $akNames = array();
             $akCodes = array();
             $departures = array();
             $arrivals = array();
             $terminals = array();
             foreach ($rows as $row) {
                 $cells = $row->elementsByName("cell");
                 // Определяем код авиакомпании и номер рейса
                 preg_match_all("/([A-Za-zА-Яа-я0-9]{2})[\\s]*([0-9]+)/", $cells[0]->content, $flightNumber, PREG_PATTERN_ORDER);
                 $result["FLIGHTS"][] = array("FLIGHT" => array("AK_CODE" => $flightNumber[1][0], "NUMBER" => $flightNumber[2][0]), "AK_NAME" => htmlspecialcharsEx($cells[1]->content), "DEPARTURE" => htmlspecialcharsEx($cells[2]->content), "ARRIVAL" => htmlspecialcharsEx($cells[3]->content), "STATUS" => CAirportBoard::GetStatusInfo($cells[4]->content), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($cells[5]->content), "ESTIMATED" => CAirportBoard::GetDateTimeArray($cells[6]->content), "ACTUAL" => CAirportBoard::GetDateTimeArray($cells[7]->content)), "TERMINAL" => htmlspecialcharsEx($cells[8]->content));
                 // Формируем список уникальных авиакомпаний, терминалов и пунктов вылета и прилета для фильтра
                 if (!in_array(htmlspecialcharsEx($cells[1]->content), $akNames)) {
                     $akNames[] = htmlspecialcharsEx($cells[1]->content);
                 }
                 if (!in_array($flightNumber[1][0], $akCodes)) {
                     $akCodes[] = $flightNumber[1][0];
                 }
                 if (!in_array(htmlspecialcharsEx($cells[2]->content), $departures)) {
                     $departures[] = htmlspecialcharsEx($cells[2]->content);
                 }
                 if (!in_array(htmlspecialcharsEx($cells[3]->content), $arrivals)) {
                     $arrivals[] = htmlspecialcharsEx($cells[3]->content);
                 }
                 if (!in_array(htmlspecialcharsEx($cells[8]->content), $terminals)) {
                     $terminals[] = htmlspecialcharsEx($cells[8]->content);
                 }
             }
             sort($akNames);
             sort($akCodes);
             sort($departures);
             sort($arrivals);
             sort($terminals);
             $result["AK_NAMES"] = $akNames;
             $result["AK_CODES"] = $akCodes;
             $result["DEPARTURES"] = $departures;
             $result["ARRIVALS"] = $arrivals;
             $result["TERMINALS"] = $terminals;
         }
     }
     return $result;
 }
 function GetOneBoardFromSite($queryParameters, $addQueryParameters)
 {
     global $APPLICATION;
     $ob = new CHTTP();
     $ob->http_timeout = 60;
     $ob->Query("GET", "www.pulkovoairport.ru", 80, "/online_serves/online_timetable/" . $queryParameters . '?ts=' . mktime() . (strlen($addQueryParameters) ? '&' . $addQueryParameters : ''), false, "", "N");
     $res = $APPLICATION->ConvertCharset($ob->result, "KOI8-R", SITE_CHARSET);
     $res = str_replace('<table class="tablo tabloBigNew bigTableZebra" border="0">', "++++", $res);
     $res = str_replace('</div> <!-- / gridTbox -->', "++++", $res);
     $explode = explode("++++", $res);
     $res = $explode[1];
     $res = substr($res, 0, strlen($res) - 22);
     return array("ERROR" => array("CODE" => $ob->errno, "MESSAGE" => $ob->errstr), "HTML" => $res);
     unset($explode, $res);
 }
 function GetOneBoardFromSite($queryParameters, $addQueryParameters)
 {
     global $APPLICATION;
     $ob = new CHTTP();
     $ob->http_timeout = 60;
     $ob->Query("GET", "www.domodedovo.ru", 80, "/onlinetablo/?" . $queryParameters . (strlen($addQueryParameters) ? '&' . $addQueryParameters : '') . '&ts=' . mktime(), false, "", "N");
     $res = $APPLICATION->ConvertCharset($ob->result, "UTF-8", SITE_CHARSET);
     $res = str_replace('<table cellspacing="1" cellpadding="3" width="100%" border="0" id="onlinetablo" >', "++++", $res);
     $res = str_replace('</form>', "++++", $res);
     $explode = explode("++++", $res);
     $res = $explode[1];
     $res = str_replace('</table>', "++++", $res);
     $explode = explode("++++", $res);
     $res = $explode[0];
     return array("ERROR" => array("CODE" => $ob->errno, "MESSAGE" => $ob->errstr), "HTML" => $res);
     unset($explode, $res);
 }
Exemple #6
0
 public function createFile(array $fileData)
 {
     $accessToken = $this->getAccessToken();
     $mimeType = $fileData['mimeType'];
     $fileSrc = $fileData['src'];
     $fileName = $fileData['name'];
     CWebDavTools::convertToUtf8($fileName);
     $fileSize = $fileData['size'] ? $fileData['size'] : filesize($fileSrc);
     $content = file_get_contents($fileSrc);
     $http = new CHTTP();
     $http->http_timeout = 10;
     $fileName = urlencode($fileName);
     $arUrl = $http->ParseURL("https://apis.live.net/v5.0/me/skydrive/files/{$fileName}?access_token=" . urlencode($accessToken));
     if (!$http->Query('PUT', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $content, $arUrl['proto'], '')) {
         return false;
     }
     $this->checkHttpResponse($http);
     // error checking
     if ($http->status != '200' && $http->status != '201') {
         return false;
     }
     return json_decode($http->result, true);
 }
Exemple #7
0
function gdGetRss($rss_url, $cache_time = 0)
{
    $cache = new CPHPCache();
    if (!$cache->StartDataCache($cache_time, 'c' . $rss_url, "gdrss")) {
        $v = $cache->GetVars();
        return $v['oRss'];
    }
    $oRssFeeds = new gdRssFeeds();
    $arUrl = parse_url($rss_url);
    if (IntVal($arUrl["port"]) <= 0) {
        $arUrl["port"] = 80;
    }
    $ob = new CHTTP();
    $ob->http_timeout = 10;
    $ob->Query("GET", $arUrl["host"], $arUrl["port"], $arUrl["path"] . ($arUrl["query"] != '' ? "?" . $arUrl["query"] : ''), false, "", "N");
    $errno = $ob->errno;
    $errstr = $ob->errstr;
    $res = $ob->result;
    if (!$res) {
        $cache->EndDataCache(array("oRss" => false));
        return false;
    }
    if (preg_match("/<" . "\\?XML[^>]{1,}encoding=[\"']([^>\"']{1,})[\"'][^>]{0,}\\?" . ">/i", $res, $matches)) {
        $charset = Trim($matches[1]);
    }
    $res = $GLOBALS["APPLICATION"]->ConvertCharset($res, $charset, SITE_CHARSET);
    $xml = new CDataXML();
    $xml->LoadString($res);
    $oNode = $xml->SelectNodes("/rss/channel/title");
    if (!$oNode) {
        $cache->EndDataCache(array("oRss" => false));
        return false;
    }
    $oRssFeeds->title = $oNode->content;
    if (strlen(trim($oRssFeeds->title)) <= 0) {
        if ($oSubNode = $oNode->elementsByName("cdata-section")) {
            $oRssFeeds->title = $oSubNode[0]->content;
        }
    }
    if ($oNode = $xml->SelectNodes("/rss/channel/link")) {
        $oRssFeeds->link = $oNode->content;
    }
    if ($oNode = $xml->SelectNodes("/rss/channel/description")) {
        $oRssFeeds->description = $oNode->content;
    }
    if (strlen(trim($oRssFeeds->description)) <= 0) {
        if ($oNode && ($oSubNode = $oNode->elementsByName("cdata-section"))) {
            $oRssFeeds->description = $oSubNode[0]->content;
        }
    }
    if ($oNode = $xml->SelectNodes("/rss/channel/pubDate")) {
        $oRssFeeds->pubDate = $oNode->content;
    } elseif ($oNode = $xml->SelectNodes("/rss/channel/lastBuildDate")) {
        $oRssFeeds->pubDate = $oNode->content;
    }
    if ($oNode = $xml->SelectNodes("/rss/channel")) {
        $oNodes = $oNode->elementsByName("item");
        foreach ($oNodes as $oNode) {
            $item = array();
            if ($oSubNode = $oNode->elementsByName("title")) {
                $item["TITLE"] = $oSubNode[0]->content;
            }
            if (strlen(trim($item["TITLE"])) <= 0 && !empty($oSubNode)) {
                if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) {
                    $item["TITLE"] = $oSubNode[0]->content;
                }
            }
            if ($oSubNode = $oNode->elementsByName("link")) {
                $item["LINK"] = $oSubNode[0]->content;
            }
            if ($oSubNode = $oNode->elementsByName("pubDate")) {
                $item["PUBDATE"] = $oSubNode[0]->content;
            }
            if ($oSubNode = $oNode->elementsByName("description")) {
                $item["DESCRIPTION"] = $oSubNode[0]->content;
            }
            if (strlen(trim($item["DESCRIPTION"])) <= 0 && !empty($oSubNode)) {
                if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) {
                    $item["DESCRIPTION"] = $oSubNode[0]->content;
                }
            }
            if ($oSubNode = $oNode->elementsByName("author")) {
                $item["AUTHOR"] = $oSubNode[0]->content;
            }
            if (strlen(trim($item["AUTHOR"])) <= 0 && !empty($oSubNode)) {
                if ($oSubNode = $oSubNode[0]->elementsByName("cdata-section")) {
                    $item["AUTHOR"] = $oSubNode[0]->content;
                }
            }
            $oRssFeeds->items[] = $item;
        }
    }
    $cache->EndDataCache(array("oRss" => $oRssFeeds));
    return $oRssFeeds;
}
	private static function SendCommand($channelId, $message, $method = 'POST', $timeout = 5, $dont_wait_answer = true)
	{
		if (!is_array($channelId))
			$channelId = Array($channelId);

		$channelId = implode('/', array_unique($channelId));

		if (strlen($channelId) <=0 || strlen($message) <= 0)
			return false;

		if (!in_array($method, Array('POST', 'GET')))
			return false;

		$nginx_error = COption::GetOptionString("pull", "nginx_error", "N");
		if ($nginx_error != "N")
		{
			$nginx_error = unserialize($nginx_error);
			if (intval($nginx_error['date'])+120 < time())
			{
				COption::SetOptionString("pull", "nginx_error", "N");
				CAdminNotify::DeleteByTag("PULL_ERROR_SEND");
				$nginx_error = "N";
			}
			else if ($nginx_error['count'] >= 10)
			{
				$ar = Array(
					"MESSAGE" => GetMessage('PULL_ERROR_SEND'),
					"TAG" => "PULL_ERROR_SEND",
					"MODULE_ID" => "pull",
				);
				CAdminNotify::Add($ar);
				return false;
			}
		}

		$postdata = CHTTP::PrepareData($message);

		$CHTTP = new CHTTP();
		$CHTTP->http_timeout = intval($timeout);
		$arUrl = $CHTTP->ParseURL(CPullOptions::GetPublishUrl($channelId), false);
		if ($CHTTP->Query($method, $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', $dont_wait_answer))
		{
			$result = $dont_wait_answer? '{}': $CHTTP->result;
		}
		else
		{
			if ($nginx_error == "N")
			{
				$nginx_error = Array(
					'count' => 1,
					'date' => time(),
					'date_increment' => time(),
				);
			}
			else if (intval($nginx_error['date_increment'])+1 < time())
			{
				$nginx_error['count'] = intval($nginx_error['count'])+1;
				$nginx_error['date_increment'] = time();
			}
			COption::SetOptionString("pull", "nginx_error", serialize($nginx_error));
			$result = false;
		}

		return $result;
	}
 function Calculate($profile, $arConfig, $arOrder, $STEP)
 {
     if ($STEP >= 3) {
         return array("RESULT" => "ERROR", "TEXT" => GetMessage('SALE_DH_CPCR_ERROR_CONNECT'));
     }
     $arOrder["WEIGHT"] = CSaleMeasure::Convert($arOrder["WEIGHT"], "G", "KG");
     if ($arOrder["WEIGHT"] <= 0) {
         $arOrder["WEIGHT"] = 1;
     }
     // weight must not be null - let it be 1 kg
     $arLocationFrom = CDeliveryCPCR::__GetLocation($arOrder["LOCATION_FROM"]);
     $arLocationTo = CDeliveryCPCR::__GetLocation($arOrder["LOCATION_TO"]);
     // caching is dependent from category, locations "from" & "to" and from weight interval
     $cache_id = "sale3|9.5.0|cpcr|" . $arConfig["category"]['VALUE'] . "|" . $arLocationFrom["ORIGINAL"]["COUNTRY_ID"] . "|" . $arLocationFrom["ORIGINAL"]["CITY_ID"] . "|" . $arLocationTo["ORIGINAL"]["COUNTRY_ID"] . "|" . $arLocationTo["ORIGINAL"]["CITY_ID"];
     if ($arOrder["WEIGHT"] <= 0.5) {
         $cache_id .= "|0";
     } elseif ($arOrder["WEIGHT"] <= 1) {
         $cache_id .= "|1";
     } else {
         $cache_id .= "|" . ceil($arOrder["WEIGHT"]);
     }
     // other intervals - up to next natural number
     $obCache = new CPHPCache();
     if ($obCache->InitCache(DELIVERY_CPCR_CACHE_LIFETIME, $cache_id, "/")) {
         // cache found
         $vars = $obCache->GetVars();
         $arResult = $vars["RESULT"];
     } else {
         // format HTTP query request data
         $arQuery = array();
         $arQuery[] = DELIVERY_CPCR_SERVER_POST_FROM_COUNTRY . "=" . urlencode($arLocationFrom["COUNTRY"]);
         if (is_set($arLocationFrom["CITY_ID"])) {
             $arQuery[] = DELIVERY_CPCR_SERVER_POST_FROM_CITY . "=" . urlencode($arLocationFrom["CITY_ID"]);
         } else {
             $arQuery[] = DELIVERY_CPCR_SERVER_POST_FROM_CITY_NAME . "=" . urlencode($GLOBALS['APPLICATION']->ConvertCharset($arLocationFrom["CITY"], LANG_CHARSET, 'windows-1251'));
         }
         $arQuery[] = DELIVERY_CPCR_SERVER_POST_WEIGHT . "=" . urlencode($arOrder["WEIGHT"]);
         $arQuery[] = DELIVERY_CPCR_SERVER_POST_CATEGORY . "=" . "1";
         //urlencode($arConfig["category"]["VALUE"]);
         // price coefficient will be added later - to make caching independent from price
         $arQuery[] = DELIVERY_CPCR_SERVER_POST_PRICE . "=0";
         $arQuery[] = DELIVERY_CPCR_SERVER_POST_TO_COUNTRY . "=" . urlencode($arLocationTo["COUNTRY"]);
         /*
         if (is_set($arLocationTo["REGION"]))
         	$arQuery[] = DELIVERY_CPCR_SERVER_POST_TO_REGION."=".urlencode($arLocationTo["REGION"]);
         else
         	$arQuery[] = DELIVERY_CPCR_SERVER_POST_TO_REGION."=".urlencode(DELIVERY_CPCR_CITY_DEFAULT);
         */
         if (is_set($arLocationTo["CITY_ID"])) {
             $arQuery[] = DELIVERY_CPCR_SERVER_POST_TO_CITY . "=" . urlencode($arLocationTo["CITY_ID"]);
         } else {
             $arQuery[] = DELIVERY_CPCR_SERVER_POST_TO_CITY_NAME . "=" . urlencode($GLOBALS['APPLICATION']->ConvertCharset($arLocationTo["CITY"], LANG_CHARSET, 'windows-1251'));
         }
         CDeliveryCPCR::__Write2Log(print_r($arLocationTo, true));
         $arQuery[] = DELIVERY_CPCR_SERVER_POST_ADDITIONAL;
         $query_string = implode("&", $arQuery);
         $query_page = DELIVERY_CPCR_SERVER_PAGE;
         // get data from server
         $ob = new CHTTP();
         $ob->http_timeout = 50;
         $data = $ob->Query(DELIVERY_CPCR_SERVER_METHOD, DELIVERY_CPCR_SERVER, DELIVERY_CPCR_SERVER_PORT, $query_page . (DELIVERY_CPCR_SERVER_METHOD == 'GET' ? (strpos($query_page, '?') === false ? '?' : '&') . $query_string : ''), DELIVERY_CPCR_SERVER_METHOD == 'POST' ? $query_string : false);
         if ($data) {
             $data = $GLOBALS["APPLICATION"]->ConvertCharset($ob->result, 'windows-1251', LANG_CHARSET);
         }
         CDeliveryCPCR::__Write2Log($query_page);
         CDeliveryCPCR::__Write2Log($query_string);
         CDeliveryCPCR::__Write2Log($error_number . ": " . $error_text);
         CDeliveryCPCR::__Write2Log($data);
         if (strpos($data, "<?xml") === false) {
             return array("RESULT" => "ERROR", "TEXT" => GetMessage('SALE_DH_CPCR_ERROR_CONNECT'));
         }
         require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/xml.php";
         $objXML = new CDataXML();
         $objXML->LoadString($data);
         $arResult = $objXML->GetArray();
         $arProfiles = array('SIMPLE' => '"цеоюпд-щйяопеяя"', 'ECONOM' => '"оекхйюм-ярюмдюпр"', 'SIMPLE13' => '"цеоюпд-щйяопеяя 13"', 'SIMPLE18' => '"цеоюпд-щйяопеяя 18"', 'BIZON' => '"ахгнм-йюпцн"', 'COLIBRI' => '"йнкхапх-днйслемр"', 'PELICAN' => '"оекхйюм-нмкюим"', 'FRAXT' => '"тпюур"');
         $arTmpResult = array();
         if (isset($arResult["root"]["#"]["Error"]) and is_array($arResult["root"]["#"]["Error"])) {
             return array("RESULT" => "ERROR", "TEXT" => GetMessage('SALE_DH_CPCR_ERROR_CONNECT') . ' (' . htmlspecialcharsbx(strip_tags($arResult["root"]["#"]["Tariff"][0]["#"]["TariffType"][0]["#"])) . ')');
         } else {
             if (!empty($arResult["root"]["#"]["Tariff"])) {
                 foreach ($arResult["root"]["#"]["Tariff"] as $key => $val) {
                     foreach ($val["#"] as $k => $v) {
                         foreach ($arProfiles as $prof => $title) {
                             if (ToUpper($v[0]["#"]) == ToUpper($title)) {
                                 $arTmpResult[ToLower($prof)] = array('VALUE' => $val["#"]["Total_Dost"][0]["#"], 'TRANSIT' => $val["#"]["DP"][0]["#"]);
                                 unset($arProfiles[$prof]);
                                 break;
                             }
                         }
                     }
                 }
             }
             $arResult = $arTmpResult;
             if (count($arTmpResult) > 0) {
                 $obCache->StartDataCache();
                 $obCache->EndDataCache(array("RESULT" => $arResult));
             } else {
                 return array("RESULT" => "ERROR", "TEXT" => GetMessage('SALE_DH_CPCR_ERROR_CONNECT'));
             }
         }
     }
     if (is_array($arResult[$profile])) {
         $arResult[$profile]['RESULT'] = 'OK';
         // it's starnge but it seems that CPCR new calculator doesnt count insurance tax at all. so, temporarily comment this line.
         // TODO: check this later
         //$arResult[$profile]['VALUE'] += $arOrder["PRICE"] * DELIVERY_CPCR_PRICE_TARIFF
         return $arResult[$profile];
     } else {
         return array("RESULT" => "ERROR", "TEXT" => GetMessage('SALE_DH_CPCR_ERROR_RESPONSE'));
     }
 }
 function GetBoardFromSite()
 {
     $result = array();
     global $APPLICATION;
     $ob = new CHTTP();
     $ob->http_timeout = 60;
     $ob->Query("GET", "svo.aero", 80, "/timetable/today/?ts=" . mktime(), false, "", "N");
     $result["ERROR"] = array("CODE" => $ob->errno, "MESSAGE" => $ob->errstr);
     $res = $APPLICATION->ConvertCharset($ob->result, "UTF-8", SITE_CHARSET);
     $res = str_replace('</thead><tbody>', "++++", $res);
     $res = str_replace('</tr></tbody></table></div>', "</tr>++++", $res);
     $explode = explode("++++", $res);
     $res = '<table>' . $explode[1] . '</table>';
     $resPatterns = array("/<a[^>]*>/Uis", "/<\\/a>/Uis");
     $resReplace = array("", "");
     $res = preg_replace($resPatterns, $resReplace, $res);
     //trace($res);
     if (!intval($result["ERROR"]["CODE"])) {
         $result["INBOUND"]["AK_NAMES"] = array();
         $result["INBOUND"]["AK_CODES"] = array();
         $result["INBOUND"]["DEPARTURES"] = array();
         $result["INBOUND"]["ARRIVALS"] = array();
         $result["INBOUND"]["TERMINALS"] = array();
         $result["OUTBOUND"]["AK_NAMES"] = array();
         $result["OUTBOUND"]["AK_CODES"] = array();
         $result["OUTBOUND"]["DEPARTURES"] = array();
         $result["OUTBOUND"]["ARRIVALS"] = array();
         $result["OUTBOUND"]["TERMINALS"] = array();
         $xml = new CDataXML();
         if ($xml->LoadString($res)) {
             $node = $xml->SelectNodes("/table");
             $rows = $node->elementsByName("tr");
             $i = 0;
             foreach ($rows as $row) {
                 $boardType = strstr($row->getAttribute("class"), "sA") ? "INBOUND" : (strstr($row->getAttribute("class"), "sD") ? "OUTBOUND" : false);
                 if ($boardType) {
                     $cells = $row->elementsByName("td");
                     if (count($cells)) {
                         $img = $cells[4]->elementsByName("img");
                         preg_match_all("/([0-9]{1,2}:[0-9]{1,2})/", $cells[7]->content, $timeFromStatus, PREG_PATTERN_ORDER);
                         preg_match_all("/^([а-я]+)\\s*/i", $cells[7]->content, $status, PREG_PATTERN_ORDER);
                         $result[$boardType]["FLIGHTS"][$i] = array("FLIGHT" => array("AK_CODE" => $cells[2]->content, "NUMBER" => $cells[3]->content), "AK_NAME" => count($img) ? htmlspecialcharsEx($img[0]->getAttribute("alt")) : "", "DEPARTURE" => htmlspecialcharsEx($cells[5]->content), "ARRIVAL" => htmlspecialcharsEx($cells[5]->content), "STATUS" => CAirportBoard::GetStatusInfo($status), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($cells[1]->content, $cells[0]->content), "ESTIMATED" => strpos($cells[7]->content, "задерживается") !== false || strpos($cells[7]->content, "ожидается") !== false ? CAirportBoard::GetDateTimeArray($timeFromStatus[1][0]) : "", "ACTUAL" => strpos($cells[7]->content, "совершил посадку") !== false || strpos($cells[7]->content, "прибыл") !== false || strpos($cells[7]->content, "вылетел") !== false || strpos($cells[7]->content, "отправлен") !== false ? CAirportBoard::GetDateTimeArray($timeFromStatus[1][0]) : ""), "TERMINAL" => $cells[6]->content);
                         // Формируем список уникальных терминалов и пунктов вылета и прилета для фильтра
                         if (!in_array($result[$boardType]["FLIGHTS"][$i]["FLIGHT"]["AK_CODE"], $result[$boardType]["AK_CODES"])) {
                             $result[$boardType]["AK_CODES"][] = $result[$boardType]["FLIGHTS"][$i]["FLIGHT"]["AK_CODE"];
                         }
                         if (!in_array($result[$boardType]["FLIGHTS"][$i]["AK_NAME"], $result[$boardType]["AK_NAMES"]) && strlen($result[$boardType]["FLIGHTS"][$i]["AK_NAME"])) {
                             $result[$boardType]["AK_NAMES"][] = $result[$boardType]["FLIGHTS"][$i]["AK_NAME"];
                         }
                         if (!in_array($result[$boardType]["FLIGHTS"][$i]["DEPARTURE"], $result[$boardType]["DEPARTURES"])) {
                             $result[$boardType]["DEPARTURES"][] = $result[$boardType]["FLIGHTS"][$i]["DEPARTURE"];
                         }
                         if (!in_array($result[$boardType]["FLIGHTS"][$i]["ARRIVAL"], $result[$boardType]["ARRIVALS"])) {
                             $result[$boardType]["ARRIVALS"][] = $result[$boardType]["FLIGHTS"][$i]["ARRIVAL"];
                         }
                         if (!in_array($result[$boardType]["FLIGHTS"][$i]["TERMINAL"], $result[$boardType]["TERMINALS"])) {
                             $result[$boardType]["TERMINALS"][] = $result[$boardType]["FLIGHTS"][$i]["TERMINAL"];
                         }
                         $i++;
                     }
                 }
             }
         }
         sort($result["INBOUND"]["AK_NAMES"]);
         sort($result["INBOUND"]["AK_CODES"]);
         sort($result["INBOUND"]["DEPARTURES"]);
         sort($result["INBOUND"]["ARRIVALS"]);
         sort($result["INBOUND"]["TERMINALS"]);
         sort($result["OUTBOUND"]["AK_NAMES"]);
         sort($result["OUTBOUND"]["AK_CODES"]);
         sort($result["OUTBOUND"]["DEPARTURES"]);
         sort($result["OUTBOUND"]["ARRIVALS"]);
         sort($result["OUTBOUND"]["TERMINALS"]);
         /*
         // Сортируем рейсы по абсолютному времени вылета
         SortFreeStyleArray( $result["FLIGHTS"], Array(
             '["TIME"]["PLANNED"]["DATETIME"]' => 'ASC',
             '["FLIGHT"]'                      => 'ASC'
             )
           );
         */
         //trace($result);
     }
     return $result;
 }
Exemple #11
0
function QueryGetData($SITE, $PORT, $PATH, $QUERY_STR, &$errno, &$errstr, $sMethod="GET", $sProto="", $sContentType = 'N')
{
	$ob = new CHTTP();
	$ob->Query(
			$sMethod,
			$SITE,
			$PORT,
			$PATH . ($sMethod == 'GET' ? ((strpos($PATH, '?') === false ? '?' : '&') . $QUERY_STR) : ''),
			$sMethod == 'POST' ? $QUERY_STR : false,
			$sProto,
			$sContentType
		);

	$errno = $ob->errno;
	$errstr = $ob->errstr;

	return $ob->result;
}
Exemple #12
0
 private function Query($command, $params = array())
 {
     if (strlen($command) <= 0 || !is_array($params)) {
         return false;
     }
     $params['BX_COMMAND'] = $command;
     $params['BX_LICENCE'] = $this->licenceCode;
     $params['BX_DOMAIN'] = $this->domain;
     $params['BX_TYPE'] = $this->type;
     $params['BX_VERSION'] = $this->version;
     $params["BX_HASH"] = $this->RequestSign($this->type, md5(implode("|", $params)));
     $CHTTP = new CHTTP();
     $arUrl = $CHTTP->ParseURL($this->controllerUrl);
     if ($CHTTP->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], CHTTP::PrepareData($params), $arUrl['proto'])) {
         $result = json_decode($CHTTP->result);
         if (!$result) {
             CVoxImplantHistory::WriteToLog($CHTTP->result, 'ERROR QUERY EXECUTE');
         }
     } else {
         $result = json_decode(json_encode(array('error' => array('code' => 'CONNECT_ERROR', 'msg' => 'Parse error or connect error from server'))));
     }
     return $result;
 }
Exemple #13
0
 private static function SendCommand($channelId, $message, $options = array())
 {
     if (!is_array($channelId)) {
         $channelId = array($channelId);
     }
     $channelId = implode('/', array_unique($channelId));
     if (strlen($channelId) <= 0 || strlen($message) <= 0) {
         return false;
     }
     $defaultOptions = array("method" => "POST", "timeout" => 5, "dont_wait_answer" => true);
     $options = array_merge($defaultOptions, $options);
     if (!in_array($options["method"], array('POST', 'GET'))) {
         return false;
     }
     $nginx_error = COption::GetOptionString("pull", "nginx_error", "N");
     if ($nginx_error != "N") {
         $nginx_error = unserialize($nginx_error);
         if (intval($nginx_error['date']) + 120 < time()) {
             COption::SetOptionString("pull", "nginx_error", "N");
             CAdminNotify::DeleteByTag("PULL_ERROR_SEND");
             $nginx_error = "N";
         } else {
             if ($nginx_error['count'] >= 10) {
                 $ar = array("MESSAGE" => GetMessage('PULL_ERROR_SEND'), "TAG" => "PULL_ERROR_SEND", "MODULE_ID" => "pull");
                 CAdminNotify::Add($ar);
                 return false;
             }
         }
     }
     $postdata = CHTTP::PrepareData($message);
     $CHTTP = new CHTTP();
     $CHTTP->http_timeout = intval($options["timeout"]);
     if (isset($options["expiry"])) {
         $CHTTP->SetAdditionalHeaders(array("Message-Expiry" => intval($options["expiry"])));
     }
     $arUrl = $CHTTP->ParseURL(CPullOptions::GetPublishUrl($channelId), false);
     try {
         $sendResult = $CHTTP->Query($options["method"], $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', $options["dont_wait_answer"]);
     } catch (Exception $e) {
         $sendResult = false;
     }
     if ($sendResult) {
         $result = $options["dont_wait_answer"] ? '{}' : $CHTTP->result;
     } else {
         if ($nginx_error == "N") {
             $nginx_error = array('count' => 1, 'date' => time(), 'date_increment' => time());
         } else {
             if (intval($nginx_error['date_increment']) + 1 < time()) {
                 $nginx_error['count'] = intval($nginx_error['count']) + 1;
                 $nginx_error['date_increment'] = time();
             }
         }
         COption::SetOptionString("pull", "nginx_error", serialize($nginx_error));
         $result = false;
     }
     return $result;
 }
	$data=CUtil::JsObjectToPhp($_REQUEST['data']);
	$req=new CHTTP;
	$req->SetAuthBasic($data['login'],$data['pass']);
	$URL=$data['url'];

	if (!$data['phpsessid'])
		$URL.='?mode=checkauth&type=catalog';
	else
	{
		$URL.='?mode=import&type=catalog&filename='.$data['filename'];
		$req->additional_headers['Cookie'] = 'PHPSESSID='.$data['phpsessid'].';';
	}
	$arUrl=$req->ParseURL($URL);

	$req->Query('GET',$arUrl['host'],$arUrl['port'],$arUrl['path_query']);

	$body=explode("\n",$req->result);
	if (count($body)>1)
	{

		$response['status']=$body[0];

		if ($response['status']=='success' && $body[1]=='PHPSESSID')
				$response['phpsessid']=$body[2];
		else
		{
			if (ToUpper($req->headers['Content-Type'])!=ToUpper('text/html; charset=utf-8'))
			$body=$APPLICATION->ConvertCharsetArray($body,'windows-1251','UTF-8');
			$response['text']=$body[1];
		}
 } else {
     $arRATE_DAY_PARSED = ParseDateTime($arParams["RATE_DAY"], "YYYY-MM-DD");
     $arRATE_DAY_PARSED['YYYY'] = intval($arRATE_DAY_PARSED['YYYY']);
     if (1901 > $arRATE_DAY_PARSED["YYYY"] || 2038 < $arRATE_DAY_PARSED["YYYY"]) {
         $arResult["RATE_DAY_TIMESTAMP"] = time();
         $arResult["RATE_DAY_SHOW"] = ConvertTimeStamp($arResult["RATE_DAY_TIMESTAMP"], 'SHORT');
     } else {
         $arResult["RATE_DAY_TIMESTAMP"] = mktime(0, 0, 0, $arRATE_DAY_PARSED["MM"], $arRATE_DAY_PARSED["DD"], $arRATE_DAY_PARSED["YYYY"]);
         $arResult["RATE_DAY_SHOW"] = ConvertTimeStamp($arResult["RATE_DAY_TIMESTAMP"], 'SHORT');
     }
 }
 if (!empty($arParams["arrCURRENCY_FROM"])) {
     if ('Y' == $arParams["SHOW_CB"]) {
         $bWarning = false;
         $obHttp = new CHTTP();
         $obHttp->Query('GET', 'www.cbr.ru', 80, "/scripts/XML_daily.asp?date_req=" . date("d.m.Y", $arResult["RATE_DAY_TIMESTAMP"]), false, '', 'N');
         $strQueryText = $obHttp->result;
         if (empty($strQueryText)) {
             $bWarning = true;
         }
         if (!$bWarning) {
             if (SITE_CHARSET != "windows-1251") {
                 $strQueryText = $APPLICATION->ConvertCharset($strQueryText, "windows-1251", SITE_CHARSET);
             }
             require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/xml.php";
             $strQueryText = preg_replace("#<!DOCTYPE[^>]+?>#i", "", $strQueryText);
             $strQueryText = preg_replace("#<" . "\\?XML[^>]+?\\?" . ">#i", "", $strQueryText);
             $objXML = new CDataXML();
             $objXML->LoadString($strQueryText);
             $arData = $objXML->GetArray();
             $arFields = array();
Exemple #16
0
 public function sendBatch($batch)
 {
     require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/update_client.php";
     $key = CUpdateClient::GetLicenseKey();
     if (strlen($key) > 0 && strlen($batch) > 0) {
         $request = new CHTTP();
         $arPostData = array("Action" => "SendMessage", "MessageBody" => $batch);
         $postdata = CHTTP::PrepareData($arPostData);
         $arUrl = $request->ParseURL(self::$remoteProviderUrl . "?key=" . md5($key), false);
         $request->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postdata, $arUrl['proto'], 'N', true);
         return true;
     }
     return false;
 }
 /**
  * @param array[string]string $arSettings
  * @param string $verb
  * @param string $bucket
  * @param string $file_name
  * @param string $params
  * @param string $content
  * @param array[string]string $additional_headers
  * @return mixed
  */
 public function SendRequest($arSettings, $verb, $bucket, $file_name = '/', $params = '', $content = '', $additional_headers = array())
 {
     global $APPLICATION;
     $this->status = 0;
     if (isset($additional_headers["Content-Type"])) {
         $ContentType = $additional_headers["Content-Type"];
         unset($additional_headers["Content-Type"]);
     } else {
         $ContentType = $content != "" ? 'text/plain' : '';
     }
     foreach ($this->set_headers as $key => $value) {
         $additional_headers[$key] = $value;
     }
     if (array_key_exists("SESSION_TOKEN", $arSettings)) {
         $additional_headers["x-amz-security-token"] = $arSettings["SESSION_TOKEN"];
     }
     ksort($additional_headers);
     $RequestURI = $file_name;
     $obRequest = new CHTTP();
     if (isset($additional_headers["option-file-result"])) {
         $obRequest->fp = $additional_headers["option-file-result"];
     }
     foreach ($this->SignRequest($arSettings, $verb, $bucket, $file_name, $ContentType, $additional_headers) as $key => $value) {
         $obRequest->additional_headers[$key] = $value;
     }
     foreach ($additional_headers as $key => $value) {
         if (preg_match("/^option-/", $key) == 0) {
             $obRequest->additional_headers[$key] = $value;
         }
     }
     if ($this->new_end_point != "" && preg_match('#^(http|https)://' . preg_quote($bucket, '#') . '(.+?)/#', $this->new_end_point, $match) > 0) {
         $host = $bucket . $match[2];
     } elseif ($this->location) {
         $host = $bucket . "." . $this->location . ".amazonaws.com";
     } else {
         $host = $bucket . ".s3.amazonaws.com";
     }
     $was_end_point = $this->new_end_point;
     $this->new_end_point = '';
     $obRequest->Query($verb, $host, 80, $RequestURI . $params, $content, '', $ContentType);
     $this->status = $obRequest->status;
     $this->host = $host;
     $this->verb = $verb;
     $this->url = $RequestURI . $params;
     $this->headers = $obRequest->headers;
     $this->errno = $obRequest->errno;
     $this->errstr = $obRequest->errstr;
     $this->result = $obRequest->result;
     if ($obRequest->status == 200) {
         if (isset($additional_headers["option-raw-result"]) || isset($additional_headers["option--result"])) {
             return $obRequest->result;
         } elseif ($obRequest->result != "") {
             $obXML = new CDataXML();
             $text = preg_replace("/<" . "\\?XML.*?\\?" . ">/i", "", $obRequest->result);
             if ($obXML->LoadString($text)) {
                 $arXML = $obXML->GetArray();
                 if (is_array($arXML)) {
                     return $arXML;
                 }
             }
             //XML parse error
             $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_PARSE_ERROR', array('#errno#' => '1')));
             $APPLICATION->ThrowException($e);
             return false;
         } else {
             //Empty success result
             return array();
         }
     } elseif ($obRequest->status == 307 && isset($obRequest->headers["Location"]) && $was_end_point === "") {
         $this->new_end_point = $obRequest->headers["Location"];
         return $this->SendRequest($arSettings, $verb, $bucket, $file_name, $params, $content, $additional_headers);
     } elseif ($obRequest->status > 0) {
         if ($obRequest->result != "") {
             $obXML = new CDataXML();
             if ($obXML->LoadString($obRequest->result)) {
                 $node = $obXML->SelectNodes("/Error/Message");
                 if (is_object($node)) {
                     $errmsg = trim($node->textContent(), '.');
                     $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_ERROR', array('#errmsg#' => $errmsg)));
                     $APPLICATION->ThrowException($e);
                     return false;
                 }
             }
         }
         $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_PARSE_ERROR', array('#errno#' => '2')));
         $APPLICATION->ThrowException($e);
         return false;
     } else {
         $e = new CApplicationException(GetMessage('CLO_STORAGE_S3_XML_PARSE_ERROR', array('#errno#' => '3')));
         $APPLICATION->ThrowException($e);
         return false;
     }
 }
Exemple #18
0
    die;
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/classes/general/xml.php';
$APPLICATION->SetAdditionalCSS('/bitrix/gadgets/bitrix/probki/styles.css');
if ($arGadgetParams["CITY"] != '') {
    $url = 'yasoft=barff&region=' . substr($arGadgetParams["CITY"], 1) . '&ts=' . mktime();
} else {
    $url = 'ts=' . mktime();
}
$cache = new CPageCache();
if ($arGadgetParams["CACHE_TIME"] > 0 && !$cache->StartDataCache($arGadgetParams["CACHE_TIME"], 'c' . $arGadgetParams["CITY"], "gdprobki")) {
    return;
}
$ob = new CHTTP();
$ob->http_timeout = 10;
$ob->Query("GET", "export.yandex.ru", 80, "/bar/reginfo.xml?" . $url, false, "", "N");
$errno = $ob->errno;
$errstr = $ob->errstr;
$res = $ob->result;
$res = str_replace("−", "-", $res);
$xml = new CDataXML();
$xml->LoadString($APPLICATION->ConvertCharset($res, 'UTF-8', SITE_CHARSET));
$node = $xml->SelectNodes('/info/traffic/title');
?>
<h3><?php 
echo $node->content;
?>
</h3>
<table width="90%"><tr>
<td width="80%" nowrap>
<?php 
	public function SendRequest($settings, $verb, $bucket, $file_name='', $params='', $content=false, $additional_headers=array())
	{
		$arToken = $this->_GetToken($settings["HOST"], $settings["USER"], $settings["KEY"]);
		if(!$arToken)
			return false;

		$this->status = 0;
		$obRequest = new CHTTP;

		$RequestURI = $file_name;

		$ContentType = "N";
		$obRequest->additional_headers["X-Auth-Token"] = $arToken["X-Auth-Token"];
		foreach($additional_headers as $key => $value)
		{
			if($key == "Content-Type")
				$ContentType = $value;
			else
				$obRequest->additional_headers[$key] = $value;
		}

		@$obRequest->Query(
			$this->verb = $verb,
			$arToken["X-Storage-Host"],
			$arToken["X-Storage-Port"],
			$this->url = $arToken["X-Storage-Urn"]."/".$bucket.$RequestURI.$params,
			$content,
			$arToken["X-Storage-Proto"],
			$ContentType
		);
		$this->status = $obRequest->status;
		$this->errno = $obRequest->errno;
		$this->errstr = $obRequest->errstr;
		$this->result = $obRequest->result;

		return $obRequest;
	}
 function SendRequest($access_key, $secret_key, $verb, $bucket, $file_name = '/', $params = '', $content = '', $additional_headers = array())
 {
     global $APPLICATION;
     $this->status = 0;
     if (isset($additional_headers["Content-Type"])) {
         $ContentType = $additional_headers["Content-Type"];
         unset($additional_headers["Content-Type"]);
     } else {
         $ContentType = $content ? 'text/plain' : '';
     }
     if (!array_key_exists("x-goog-api-version", $additional_headers)) {
         $additional_headers["x-goog-api-version"] = "1";
     }
     $RequestMethod = $verb;
     $RequestURI = $file_name;
     $RequestDATE = gmdate('D, d M Y H:i:s', time()) . ' GMT';
     //Prepare Signature
     $CanonicalizedAmzHeaders = "";
     ksort($additional_headers);
     foreach ($additional_headers as $key => $value) {
         if (preg_match("/^x-goog-/", $key)) {
             $CanonicalizedAmzHeaders .= $key . ":" . $value . "\n";
         }
     }
     $CanonicalizedResource = "/" . $bucket . $RequestURI;
     $StringToSign = "{$RequestMethod}\n\n{$ContentType}\n{$RequestDATE}\n{$CanonicalizedAmzHeaders}{$CanonicalizedResource}";
     //$utf = $APPLICATION->ConvertCharset($StringToSign, LANG_CHARSET, "UTF-8");
     $Signature = base64_encode($this->hmacsha1($StringToSign, $secret_key));
     $Authorization = "GOOG1 " . $access_key . ":" . $Signature;
     $obRequest = new CHTTP();
     $obRequest->additional_headers["Date"] = $RequestDATE;
     $obRequest->additional_headers["Authorization"] = $Authorization;
     foreach ($additional_headers as $key => $value) {
         if (!preg_match("/^option-/", $key)) {
             $obRequest->additional_headers[$key] = $value;
         }
     }
     if ($this->new_end_point && preg_match('#^(http|https)://' . preg_quote($bucket, '#') . '(.+)/#', $this->new_end_point, $match)) {
         $host = $match[2];
     } else {
         $host = $bucket . ".commondatastorage.googleapis.com";
     }
     $was_end_point = $this->new_end_point;
     $this->new_end_point = '';
     $obRequest->Query($RequestMethod, $host, 80, $RequestURI . $params, $content, '', $ContentType);
     $this->status = $obRequest->status;
     $this->headers = $obRequest->headers;
     $this->errno = $obRequest->errno;
     $this->errstr = $obRequest->errstr;
     $this->result = $obRequest->result;
     if ($obRequest->status == 200) {
         if (isset($additional_headers["option-raw-result"])) {
             return $obRequest->result;
         } elseif ($obRequest->result) {
             $obXML = new CDataXML();
             $text = preg_replace("/<" . "\\?XML.*?\\?" . ">/i", "", $obRequest->result);
             if ($obXML->LoadString($text)) {
                 $arXML = $obXML->GetArray();
                 if (is_array($arXML)) {
                     return $arXML;
                 }
             }
             //XML parse error
             $APPLICATION->ThrowException(GetMessage('CLO_STORAGE_GOOGLE_XML_PARSE_ERROR', array('#errno#' => 1)));
             return false;
         } else {
             //Empty success result
             return array();
         }
     } elseif ($obRequest->status == 307 && isset($obRequest->headers["Location"]) && !$was_end_point) {
         $this->new_end_point = $obRequest->headers["Location"];
         return $this->SendRequest($access_key, $secret_key, $verb, $bucket, $file_name, $params, $content, $additional_headers);
     } elseif ($obRequest->status > 0) {
         if ($obRequest->result) {
             $obXML = new CDataXML();
             if ($obXML->LoadString($obRequest->result)) {
                 $arXML = $obXML->GetArray();
                 if (is_array($arXML) && is_string($arXML["Error"]["#"]["Message"][0]["#"])) {
                     $APPLICATION->ThrowException(GetMessage('CLO_STORAGE_GOOGLE_XML_ERROR', array('#errmsg#' => trim($arXML["Error"]["#"]["Message"][0]["#"], '.'))));
                     return false;
                 }
             }
         }
         $APPLICATION->ThrowException(GetMessage('CLO_STORAGE_GOOGLE_XML_PARSE_ERROR', array('#errno#' => 2)));
         return false;
     } else {
         $APPLICATION->ThrowException(GetMessage('CLO_STORAGE_GOOGLE_XML_PARSE_ERROR', array('#errno#' => 3)));
         return false;
     }
 }
Exemple #21
0
 }
 if (!$arResult["RESULT"]['ERROR']) {
     $arSoapRequest = new CSOAPRequest($arSoapMethod, $arParams["PR_NAMESPACE"], $arSoapParams);
     $request_body = $arSoapRequest->payload();
     if (!$isUTF) {
         $request_body = $APPLICATION->ConvertCharset($request_body, SITE_CHARSET, "UTF-8");
         $arSoapMethod = $APPLICATION->ConvertCharset($arSoapMethod, SITE_CHARSET, "UTF-8");
     }
     $req = new CHTTP();
     $arUrl = $req->ParseURL($arWebServiceUrl);
     $arUrl["port"] = $arPort;
     $req->SetAuthBasic($arLogin, $arPassword);
     $req->user_agent = "BITRIX SOAP Client";
     $req->http_timeout = $arTimeout;
     $req->additional_headers['SOAPAction'] = $arParams["PR_NAMESPACE"] . $arSoapMethod;
     $result = $req->Query("POST", $arUrl["host"], $arUrl["port"], $arUrl["path"], $request_body, $arUrl["proto"], "text/xml; charset=utf-8");
     if (!$req->errstr) {
         if ($req->status == 401) {
             $arResult["RESULT"]['ERROR'] = GetMessage("AUTH_ERROR");
         } else {
             preg_match("/^<soap:Envelope.*>/i", $req->result, $preg);
             if (empty($preg) || $req->status != "200") {
                 $arResult["RESULT"]['ERROR'] = GetMessage("WRONG_RESPONSE");
             }
         }
     } else {
         $arResult["RESULT"]['ERROR'] = $req->errstr;
     }
     if (!$arResult["RESULT"]['ERROR']) {
         $response = new CSOAPResponse();
         $response->decodeStream($arSoapRequest, "\r\n\r\n" . $req->result);
 function GetBoardFromSite($queryParameters)
 {
     global $APPLICATION;
     $result = array();
     $ob = new CHTTP();
     $ob->http_timeout = 60;
     $ob->Query("GET", "www.rossiya-airlines.com", 80, "/ru/passenger/about_flight/" . $queryParameters . '?ts=' . mktime(), false, "", "N");
     $result["ERROR"]["CODE"] = $ob->errno;
     $result["ERROR"]["MESSAGE"] = $ob->errstr;
     if (intval($result["ERROR"]["CODE"]) == 0) {
         $res = $ob->result;
         $res = str_replace('<table border="0" cellpadding="0" cellspacing="0" class="table" id="tblData">', "++++<table>", $res);
         $res = str_replace('$(document).ready(function()', "++++", $res);
         $explode = explode("++++", $res);
         $res = $explode[1];
         $res = substr($res, 0, strlen($res) - 22);
         $res = str_replace("<br>", " ", $res);
         $res = str_replace("<nobr>", "", $res);
         $res = str_replace("</nobr>", "", $res);
         //trace($res);
         $xml = new CDataXML();
         if ($xml->LoadString($res)) {
             $node = $xml->SelectNodes("/table");
             $rows = $node->elementsByName("tr");
             $akNames = array();
             $akCodes = array();
             $departures = array();
             $arrivals = array();
             $terminals = array();
             foreach ($rows as $row) {
                 if (strstr($row->getAttribute("class"), "finddata")) {
                     $cells = $row->elementsByName("td");
                     $flightNumber = $cells[0]->elementsByName("div");
                     // Определяем код авиакомпании и номер рейса
                     preg_match_all("/([A-Za-zА-Яа-я0-9]{2})([0-9]+)/", $flightNumber[0]->content, $flightNumber, PREG_PATTERN_ORDER);
                     $terminal = $cells[1]->elementsByName("div");
                     $city = $cells[2]->elementsByName("div");
                     $plannedTime = $cells[3]->elementsByName("div");
                     $actualTime = $cells[4]->elementsByName("div");
                     $status = $cells[5]->elementsByName("span");
                     $result["FLIGHTS"][] = array("FLIGHT" => array("AK_CODE" => $flightNumber[1][0], "NUMBER" => $flightNumber[2][0]), "AK_NAME" => "", "DEPARTURE" => htmlspecialcharsEx($city[0]->content), "ARRIVAL" => htmlspecialcharsEx($city[0]->content), "STATUS" => CAirportBoard::GetStatusInfo($status[0]->content), "TIME" => array("PLANNED" => CAirportBoard::GetDateTimeArray($plannedTime[0]->content), "ESTIMATED" => "", "ACTUAL" => CAirportBoard::GetDateTimeArray($actualTime[0]->content)), "TERMINAL" => htmlspecialchars($terminal[0]->content));
                     // Формируем список уникальных терминалов и пунктов вылета и прилета для фильтра
                     if (!in_array($flightNumber[1][0], $akCodes)) {
                         $akCodes[] = $flightNumber[1][0];
                     }
                     if (!in_array(htmlspecialcharsEx($city[0]->content), $departures)) {
                         $departures[] = htmlspecialcharsEx($city[0]->content);
                     }
                     if (!in_array(htmlspecialcharsEx($city[0]->content), $arrivals)) {
                         $arrivals[] = htmlspecialcharsEx($city[0]->content);
                     }
                     if (!in_array(htmlspecialcharsEx($terminal[0]->content), $terminals)) {
                         $terminals[] = htmlspecialcharsEx($terminal[0]->content);
                     }
                 }
             }
             sort($akNames);
             sort($akCodes);
             sort($departures);
             sort($arrivals);
             sort($terminals);
             $result["AK"] = $akNames;
             $result["AK_CODES"] = $akCodes;
             $result["DEPARTURES"] = $departures;
             $result["ARRIVALS"] = $arrivals;
             $result["TERMINALS"] = $terminals;
         }
     }
     //trace($result);
     return $result;
 }
Exemple #23
0
 public function createBlankFile(array $fileData)
 {
     $accessToken = $this->getAccessToken();
     $googleMimeType = $this->getInternalMimeTypeListByExtension(getFileExtension($fileData['name']));
     $fileName = getFileNameWithoutExtension($fileData['name']);
     CWebDavTools::convertToUtf8($fileName);
     if (!$googleMimeType) {
         return false;
     }
     $http = new CHTTP();
     $http->http_timeout = 10;
     $arUrl = $http->ParseURL('https://www.googleapis.com/drive/v2/files');
     $http->SetAdditionalHeaders(array("Authorization" => "Bearer {$accessToken}"));
     $postFields = "{\"title\":\"{$fileName}\",\"mimeType\":\"{$googleMimeType}\"}";
     $postContentType = 'application/json; charset=UTF-8';
     if (!$http->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postFields, $arUrl['proto'], $postContentType)) {
         return false;
     }
     $this->checkHttpResponse($http);
     // access token expired, let's get a new one and try again
     if ($http->status == "401") {
         //todo: invalid credential response
         return false;
     }
     // error checking
     if ($http->status != "200") {
         return false;
     }
     $finalOutput = json_decode($http->result);
     //last signed user must delete file from google drive
     $this->insertPermission(array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id));
     return array('link' => $finalOutput->alternateLink, 'id' => $finalOutput->id);
 }