function Request($server, $page, $port, $params, $uri = false) { if ($uri && strlen($uri) > 0) { $strURI = $uri; } else { $strURI = "http://" . $server . (strlen($port) > 0 && intval($port) > 0 ? ":" . intval($port) : "") . (strlen($page) ? $page : "/") . (strlen($params) > 0 ? "?" . $params : ""); } $http = new \Bitrix\Main\Web\HttpClient(array("version" => "1.0", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5)); $strData = $http->get($strURI); $errors = $http->getError(); $arRSSResult = array(); if (!$strData && !empty($errors)) { $strError = ""; foreach ($errors as $errorCode => $errMes) { $strError .= $errorCode . ": " . $errMes; } \CEventLog::Add(array("SEVERITY" => "ERROR", "AUDIT_TYPE_ID" => "XDIMPORT_HTTP", "MODULE_ID" => "xdimport", "ITEM_ID" => "RSS_REQUEST", "DESCRIPTION" => $strError)); } if ($strData) { $rss_charset = "windows-1251"; if (preg_match("/<" . "\\?XML[^>]{1,}encoding=[\"']([^>\"']{1,})[\"'][^>]{0,}\\?" . ">/i", $strData, $matches)) { $rss_charset = Trim($matches[1]); } $strData = preg_replace("/<" . "\\?XML.*?\\?" . ">/i", "", $strData); $strData = $GLOBALS["APPLICATION"]->ConvertCharset($strData, $rss_charset, SITE_CHARSET); } if (strlen($strData) > 0) { require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/xml.php"; $objXML = new CDataXML(); $res = $objXML->LoadString($strData); if ($res !== false) { $ar = $objXML->GetArray(); if (is_array($ar) && isset($ar["rss"]) && is_array($ar["rss"]) && isset($ar["rss"]["#"]) && is_array($ar["rss"]["#"]) && isset($ar["rss"]["#"]["channel"]) && is_array($ar["rss"]["#"]["channel"]) && isset($ar["rss"]["#"]["channel"][0]) && is_array($ar["rss"]["#"]["channel"][0]) && isset($ar["rss"]["#"]["channel"][0]["#"])) { $arRSSResult = $ar["rss"]["#"]["channel"][0]["#"]; } else { $arRSSResult = array(); } $arRSSResult["rss_charset"] = strtolower(SITE_CHARSET); } } if (is_array($arRSSResult) && !empty($arRSSResult)) { $arRSSResult = CXDILFSchemeRSS::FormatArray($arRSSResult); if (!empty($arRSSResult) && array_key_exists("item", $arRSSResult) && is_array($arRSSResult["item"]) && !empty($arRSSResult["item"])) { $arRSSResult["item"] = array_reverse($arRSSResult["item"]); } } return $arRSSResult; }
public static function getAllPecomCities($cleanCache = false) { global $APPLICATION; $ttl = 2592000; $data = array(); $cacheId = "SaleDeliveryPecomCities"; $cacheManager = \Bitrix\Main\Application::getInstance()->getManagedCache(); if ($cleanCache) { $cacheManager->clean($cacheId); } if ($cacheManager->read($ttl, $cacheId)) { $data = $cacheManager->get($cacheId); } if (empty($data)) { $http = new \Bitrix\Main\Web\HttpClient(array("version" => "1.1", "socketTimeout" => 30, "streamTimeout" => 30, "redirect" => true, "redirectMax" => 5)); $jsnData = $http->get("http://www.pecom.ru/ru/calc/towns.php"); $errors = $http->getError(); if (!$jsnData && !empty($errors)) { $strError = ""; foreach ($errors as $errorCode => $errMes) { $strError .= $errorCode . ": " . $errMes; } \CEventLog::Add(array("SEVERITY" => "ERROR", "AUDIT_TYPE_ID" => "SALE_DELIVERY", "MODULE_ID" => "sale", "ITEM_ID" => "PECOM_GET_TOWNS", "DESCRIPTION" => $strError)); } $data = json_decode($jsnData, true); if (strtolower(SITE_CHARSET) != 'utf-8') { $data = $APPLICATION->ConvertCharsetArray($data, 'utf-8', SITE_CHARSET); if (is_array($data)) { foreach ($data as $key => $value) { $newKey = $APPLICATION->ConvertCharset($key, 'utf-8', SITE_CHARSET); $data[$newKey] = $value; unset($data[$key]); } } } if (!is_array($data)) { $data = array(); } $cacheManager->set($cacheId, $data); } return $data; }
public function getNewAccessToken($refreshToken = false, $userId = 0, $save = false, $scope = array()) { if ($this->appID == false || $this->appSecret == false) { return false; } if ($refreshToken == false) { $refreshToken = $this->refresh_token; } if ($scope != null) { $this->addScope($scope); } $http = new \Bitrix\Main\Web\HttpClient(array('socketTimeout' => $this->httpTimeout)); $result = $http->get(self::NET_URL . self::TOKEN_URL . '?' . http_build_query(array('client_id' => $this->appID, 'client_secret' => $this->appSecret, 'refresh_token' => $refreshToken, 'scope' => implode(',', $this->getScope()), 'grant_type' => 'refresh_token'))); $arResult = CUtil::JsObjectToPhp($result); if (isset($arResult["access_token"]) && $arResult["access_token"] != '') { $this->access_token = $arResult["access_token"]; $this->accessTokenExpires = time() + $arResult["expires_in"]; $this->refresh_token = $arResult["refresh_token"]; if ($save && intval($userId) > 0) { $dbSocservUser = CSocServAuthDB::GetList(array(), array("USER_ID" => intval($userId), "EXTERNAL_AUTH_ID" => CSocServBitrix24Net::ID), false, false, array("ID")); $arOauth = $dbSocservUser->Fetch(); if ($arOauth) { CSocServAuthDB::Update($arOauth["ID"], array("OATOKEN" => $this->access_token, "OATOKEN_EXPIRES" => $this->accessTokenExpires, "REFRESH_TOKEN" => $this->refresh_token)); } } return true; } return false; }
public function getNewAccessToken($refreshToken, $userId = 0, $save = false, $scope = array()) { if ($this->appID == false || $this->appSecret == false) { return false; } if ($scope != null) { $this->addScope($scope); } $httpClient = new \Bitrix\Main\Web\HttpClient(array("socketTimeout" => $this->httpTimeout)); $result = $httpClient->get($this->portalURI . "/oauth/token/" . "?client_id=" . urlencode($this->appID) . "&grant_type=refresh_token" . "&client_secret=" . $this->appSecret . "&refresh_token=" . $refreshToken . '&scope=' . $this->getScopeEncode()); $arResult = \Bitrix\Main\Web\Json::decode($result); if (isset($arResult["access_token"]) && $arResult["access_token"] != '') { $this->access_token = $arResult["access_token"]; $this->accessTokenExpires = $arResult["expires_in"]; $this->member_id = $arResult["member_id"]; if (isset($arResult["refresh_token"]) && $arResult["refresh_token"] != '') { $this->refresh_token = $arResult["refresh_token"]; } if ($save && intval($userId) > 0) { CUserOptions::SetOption('socialservices', 'bitrix24_task_planer_gadget_token', $this->access_token, false, $userId); CUserOptions::SetOption('socialservices', 'bitrix24_task_planer_gadget_token_expire', $this->accessTokenExpires + time(), false, $userId); CUserOptions::SetOption('socialservices', 'bitrix24_task_planer_gadget_refresh_token', $this->refresh_token, false, $userId); } return true; } return false; }
public static function GetVideoOembed($url = '') { // Get oembed url $oembed = self::GetOembedUrlInfo($url); $output = array('result' => false, 'error' => ""); $http = new \Bitrix\Main\Web\HttpClient(); $resp = $http->get($oembed['url']); if ($resp === false) { $error = $http->getError(); foreach($error as $errorCode => $errorMessage) { $output['error'] .= '['.$errorCode.'] '.$errorMessage.";\n"; } } else { $resParams = json_decode($resp, true); if ($resParams && is_array($resParams)) { if (!defined('BX_UTF') || BX_UTF !== true) { $resParams['title'] = CharsetConverter::ConvertCharset($resParams['title'], 'UTF-8', SITE_CHARSET); $resParams['html'] = CharsetConverter::ConvertCharset($resParams['html'], 'UTF-8', SITE_CHARSET); $resParams['provider_name'] = CharsetConverter::ConvertCharset($resParams['provider_name'], 'UTF-8', SITE_CHARSET); } $resParams['html'] = preg_replace("/https?:\/\//is", '//', $resParams['html']); $output['result'] = true; $output['data'] = array( 'html' => $resParams['html'], 'title' => $resParams['title'], 'width' => intval($resParams['width']), 'height' => intval($resParams['height']), 'provider' => $resParams['provider_name'] ); } else { $output['error'] .= '[FVID404] '.GetMessage('HTMLED_VIDEO_NOT_FOUND').";\n"; } } return $output; }
public function GetCurrentUser() { if ($this->access_token === false) { return false; } $h = new \Bitrix\Main\Web\HttpClient(); $result = $h->get(self::USERINFO_URL . '?format=json&oauth_token=' . urlencode($this->access_token)); $result = \Bitrix\Main\Web\Json::decode($result); if (is_array($result)) { $result["access_token"] = $this->access_token; $result["refresh_token"] = $this->refresh_token; $result["expires_in"] = $this->accessTokenExpires; } return $result; }
} elseif ($USER->CanDoOperation('manage_short_uri')) { $aMenu[] = array("parent_menu" => "global_menu_settings", "sort" => 1700, "text" => GetMessage("MAIN_MENU_SHORT_URLS"), "url" => "short_uri_admin.php?lang=" . LANGUAGE_ID, "more_url" => array("short_uri_edit.php"), "title" => GetMessage("MAIN_MENU_SHORT_URLS_ALT"), "icon" => "sys_menu_icon"); } if ($USER->CanDoOperation('install_updates')) { $arMarket = array(); if (method_exists($adminMenu, "IsSectionActive")) { if ($adminMenu->IsSectionActive("menu_marketplace")) { $CACHE = 60 * 60 * 24; $obCache = new CPHPCache(); $cache_id = "main_menu_marketplace_" . LANGUAGE_ID; if ($obCache->InitCache($CACHE, $cache_id, "/")) { $vars = $obCache->GetVars(); $arMarket = $vars["arMarket"]; } else { $ht = new Bitrix\Main\Web\HttpClient(array("socketTimeout" => 30)); if ($res = $ht->get("http://marketplace.1c-bitrix.ru/data_export.php")) { if ($ht->getStatus() == "200") { $res = $APPLICATION->ConvertCharset($res, "windows-1251", SITE_CHARSET); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/xml.php"; $objXML = new CDataXML(); $objXML->LoadString($res); $arResult = $objXML->GetArray(); if (!empty($arResult) && is_array($arResult)) { if (!empty($arResult["categories"]["#"]["category"])) { foreach ($arResult["categories"]["#"]["category"] as $category) { $arCategory = array(); $arUrls = array(); if (!empty($category["#"]["items"][0]["#"]["item"])) { foreach ($category["#"]["items"][0]["#"]["item"] as $catIn) { $url = "update_system_market.php?category=" . $catIn["#"]["id"][0]["#"]; $arCategory[] = array("text" => $catIn["#"]["name"][0]["#"] . " (" . $catIn["#"]["count"][0]["#"] . ")", "title" => GetMessage("MAIN_MENU_MP_CATEGORY") . " " . $catIn["#"]["name"][0]["#"], "url" => $url . "&lang=" . LANGUAGE_ID);
private static function get($url, $data) { $http = new \Bitrix\Main\Web\HttpClient(); $response = $http->get($url . '?' . http_build_query($data)); $result = json_decode($response, true); return $result; }
public static function GetVideoOembed($url = '') { // Get oembed url $oembed = self::GetOembedUrlInfo($url); $output = array('result' => false, 'error' => ""); $http = new \Bitrix\Main\Web\HttpClient(); $resp = $http->get($oembed['url']); if ($resp === false) { $io = CBXVirtualIo::GetInstance(); $path = $url; $serverPath = self::GetServerPath(); if (strpos($path, $serverPath) !== false) { $path = str_replace($serverPath, '', $path); } if ($io->FileExists($io->RelativeToAbsolutePath($path))) { $output['data'] = array('local' => true, 'path' => $path); $output['result'] = true; } else { $path = $url; $http = new \Bitrix\Main\Web\HttpClient(); $resp1 = $http->get($path); if ($resp1 !== false) { $output['data'] = array('local' => true, 'path' => $url); } $output['result'] = true; } if (!$output['result']) { $error = $http->getError(); foreach ($error as $errorCode => $errorMessage) { $output['error'] .= '[' . $errorCode . '] ' . $errorMessage . ";\n"; } } } else { $resParams = json_decode($resp, true); if ($resParams && is_array($resParams)) { if (!defined('BX_UTF') || BX_UTF !== true) { $resParams['title'] = CharsetConverter::ConvertCharset($resParams['title'], 'UTF-8', SITE_CHARSET); $resParams['html'] = CharsetConverter::ConvertCharset($resParams['html'], 'UTF-8', SITE_CHARSET); $resParams['provider_name'] = CharsetConverter::ConvertCharset($resParams['provider_name'], 'UTF-8', SITE_CHARSET); } $resParams['html'] = preg_replace("/https?:\\/\\//is", '//', $resParams['html']); $output['result'] = true; $output['data'] = array('html' => $resParams['html'], 'title' => $resParams['title'], 'width' => intval($resParams['width']), 'height' => intval($resParams['height']), 'provider' => $resParams['provider_name']); } else { $output['error'] .= '[FVID404] ' . GetMessage('HTMLED_VIDEO_NOT_FOUND') . ";\n"; } } return $output; }
public function GetAppInfo() { if ($this->access_token === false) { return false; } $h = new \Bitrix\Main\Web\HttpClient(); $h->setTimeout($this->httpTimeout); $result = $h->get(self::APP_URL . '?fields=id&access_token=' . urlencode($this->access_token)); $result = \Bitrix\Main\Web\Json::decode($result); return $result['response']; }
function CheckKernel($arParams) { $time_start = time(); global $DB; $arCompare = array("install/components/bitrix/" => "/bitrix/components/bitrix/", "install/js/" => "/bitrix/js/", "install/activities/" => "/bitrix/activities/", "install/admin/" => "/bitrix/admin/", "install/wizards/" => "/bitrix/wizards/"); if (!$_SESSION["BX_CHECKLIST"][$arParams["TEST_ID"]]) { $_SESSION["BX_CHECKLIST"][$arParams["TEST_ID"]] = array(); } $NS =& $_SESSION["BX_CHECKLIST"][$arParams["TEST_ID"]]; if ($arParams["STEP"] == false) { $NS = array(); $rsInstalledModules = CModule::GetList(); while ($ar = $rsInstalledModules->Fetch()) { if (!strpos($ar["ID"], ".")) { $NS["MLIST"][] = $ar["ID"]; } } $NS["MNUM"] = 0; $NS["FILE_LIST"] = array(); $NS["FILES_COUNT"] = 0; $NS["MODFILES_COUNT"] = 0; } $arError = false; $module_id = $NS["MLIST"][$NS["MNUM"]]; $module_folder = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/" . $module_id . "/"; $dbtype = strtolower($DB->type); if ($module_id == "main") { $ver = SM_VERSION; } else { $arModuleVersion = array(); @(include $module_folder . "install/version.php"); $ver = $arModuleVersion["VERSION"]; } $arFilesCount = 0; $arModifiedFilesCount = 0; $state = array(); $Skip = false; if (!$ver) { $state = array("STATUS" => false, "MESSAGE" => GetMessage("CL_MODULE_VERSION_ERROR", array("#module_id#" => $module_id)) . "\n"); $arError = true; } else { if (count($NS["FILE_LIST"]) == 0) { $sHost = COption::GetOptionString("main", "update_site", "www.bitrixsoft.com"); $proxyAddr = COption::GetOptionString("main", "update_site_proxy_addr", ""); $proxyPort = COption::GetOptionString("main", "update_site_proxy_port", ""); $proxyUserName = COption::GetOptionString("main", "update_site_proxy_user", ""); $proxyPassword = COption::GetOptionString("main", "update_site_proxy_pass", ""); $http = new \Bitrix\Main\Web\HttpClient(); $http->setProxy($proxyAddr, $proxyPort, $proxyUserName, $proxyPassword); $data = $http->get("http://" . $sHost . "/bitrix/updates/checksum.php?check_sum=Y&module_id=" . $module_id . "&ver=" . $ver . "&dbtype=" . $dbtype . "&mode=2"); $NS["FILE_LIST"] = $result = unserialize(gzinflate($data)); $NS["MODULE_FILES_COUNT"] = count($NS["FILE_LIST"]); } else { $result = $NS["FILE_LIST"]; } $arMessage = ""; $timeout = COption::GetOptionString("main", "update_load_timeout", "30"); if (is_array($result) && !$result["error"]) { foreach ($result as $file => $checksum) { $arFile = $module_folder . $file; unset($NS["FILE_LIST"][$file]); if (!file_exists($arFile)) { continue; } $arFilesCount++; if (md5_file($arFile) != $checksum) { $arMessage .= str_replace(array("//", "\\\\"), array("/", "\\"), $arFile) . "\n"; $arModifiedFilesCount++; } $arTmpCompare = $arCompare; foreach ($arTmpCompare as $key => $value) { if (strpos($file, $key) === 0) { $arFile = str_replace($key, $_SERVER["DOCUMENT_ROOT"] . $value, $file); if (!file_exists($arFile) || md5_file($arFile) != $checksum) { $arModifiedFilesCount++; $arMessage .= str_replace(array("//", "\\\\"), array("/", "\\"), $arFile) . "\n"; } $arFilesCount++; } } if (time() - $time_start >= $timeout) { break; } } if (strlen($arMessage) > 0) { $state = array("MESSAGE" => $arMessage, "STATUS" => false); } } else { if ($result["error"] != "unknow module id") { $state["MESSAGE"] = GetMessage("CL_CANT_CHECK", array("#module_id#" => $module_id)) . "\n"; $arError = true; } else { $Skip = true; } } } if ($state["MESSAGE"]) { $NS["MESSAGE"][$module_id] .= $state["MESSAGE"]; } if (!$arError && !$Skip) { if (count($NS["FILE_LIST"]) == 0) { if (strlen($NS["MESSAGE"][$module_id]) == 0) { $NS["MESSAGE"][$module_id] = GetMessage("CL_NOT_MODIFIED", array("#module_id#" => $module_id)) . "\n"; } else { $NS["MESSAGE"][$module_id] = GetMessage("CL_MODIFIED_FILES", array("#module_id#" => $module_id)) . "\n" . $NS["MESSAGE"][$module_id]; } } $NS["FILES_COUNT"] += $arFilesCount; $NS["MODFILES_COUNT"] += $arModifiedFilesCount; } if ($state["STATUS"] === false || $arError == true || $Skip) { if ($state["STATUS"] === false || $arError == true) { $NS["STATUS"] = false; } $NS["FILE_LIST"] = array(); $NS["MODULE_FILES_COUNT"] = 0; } if ($NS["MNUM"] + 1 >= count($NS["MLIST"]) && !$NS["LAST_FILE"]) { $arDetailReport = ""; foreach ($NS["MESSAGE"] as $module_message) { $arDetailReport .= "<div class=\"checklist-dot-line\"></div>" . $module_message; } $arResult = array("MESSAGE" => array("PREVIEW" => GetMessage("CL_KERNEL_CHECK_FILES") . $NS["FILES_COUNT"] . "\n" . GetMessage("CL_KERNEL_CHECK_MODULE") . count($NS["MLIST"]) . "\n" . GetMessage("CL_KERNEL_CHECK_MODIFIED") . $NS["MODFILES_COUNT"], "DETAIL" => $arDetailReport), "STATUS" => $NS["STATUS"] === false ? false : true); } else { $percent = round($NS["MNUM"] / (count($NS["MLIST"]) * 0.01), 0); $module_percent = 0; if ($NS["MODULE_FILES_COUNT"] > 0) { $module_percent = 1 / (count($NS["MLIST"]) * 0.01) * (($NS["MODULE_FILES_COUNT"] - count($NS["FILE_LIST"])) / ($NS["MODULE_FILES_COUNT"] * 0.01) * 0.01); } $percent += $module_percent; $arResult = array("IN_PROGRESS" => "Y", "PERCENT" => number_format($percent, 2)); if (count($NS["FILE_LIST"]) == 0) { $NS["MNUM"]++; $NS["MODULE_FILES_COUNT"] = 0; } } return $arResult; }
public function GetCurrentUser() { if ($this->access_token === false) { return false; } $h = new \Bitrix\Main\Web\HttpClient(); $h->setHeader("Authorization", "Bearer " . $this->access_token); $result = $h->get(static::ACCOUNT_URL); $result = \Bitrix\Main\Web\Json::decode($result); if (is_array($result)) { $result["access_token"] = $this->access_token; } return $result; }
public function getMessages($uid) { if ($this->access_token === false) { return false; } $url = self::GRAPH_URL . '/' . $uid . '/apprequests?access_token=' . $this->access_token; $ob = new \Bitrix\Main\Web\HttpClient(); return $ob->get($url); }
public function GetCurrentUser() { if ($this->access_token === false) { return false; } $httpClient = new \Bitrix\Main\Web\HttpClient(); $httpClient->setHeader("Authorization", "Bearer " . $this->access_token); $result = $httpClient->get($this->resource . static::VERSION . static::CONTACTS_URL); $result = \Bitrix\Main\Web\Json::decode($result); if (is_array($result)) { $result["access_token"] = $this->access_token; $result["refresh_token"] = $this->refresh_token; $result["expires_in"] = $this->accessTokenExpires; } return $result; }