public static function onBeforeHTMLEditorScriptRuns() { $asset = Asset::getInstance(); $asset->addJs('/bitrix/js/newkaliningrad.typografru/typograf.js'); $messages = Loc::loadLanguageFile(Path::normalize(__FILE__)); $asset->addString(sprintf('<script>BX.message(%s)</script>', Json::encode($messages, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE))); }
private function Process($service, $id = false, $jsdecode = true) { $token = $this->GetToken(); $s = curl_init(); if ($id !== false) { $service = str_replace("#ID#", $id, $service); } curl_setopt($s, CURLOPT_URL, "https://api.ozon.ru/{$service}"); //?applicationid={$this->appID}&token=$token curl_setopt($s, CURLOPT_HTTPHEADER, array("x-ApiVersion: 0.1", "accept:application/json", "x-applicationid:{$this->appID}", "x-token:{$token}")); curl_setopt($s, CURLOPT_RETURNTRANSFER, true); $reply = curl_exec($s); curl_close($s); if ($jsdecode) { if (strtoupper(SITE_CHARSET) == "UTF-8") { $reply = mb_convert_encoding($reply, "utf8", "cp1251"); } try { $reply = \Bitrix\Main\Web\Json::decode($reply); } catch (Exception $e) { $reply = array(); } } return $reply; }
function renderMenu($id, $items) { ?> <script> BX('<?php echo $id; ?> ').onclick = function() { this.blur(); BX.adminShowMenu(this, <?php $json = array(); foreach ($items as $name => $params) { $json[] = array('TEXT' => $name, 'ONCLICK' => "window.location.href = '?" . http_build_query($params) . "'"); } echo Json::encode($json); ?> , {active_class: 'adm-btn-save-active'}); return false; }; </script> <?php }
protected function doPostAction($isEdit, $action) { /** @global CMain $APPLICATION */ global $APPLICATION; if ($isEdit) { $APPLICATION->RestartBuffer(); header('Content-Type: application/json', true); echo Json::encode($this->arResult); die; } else { switch ($action) { case 'download': $APPLICATION->restartBuffer(); header('Content-Type: text/plain', true); header('Content-Disposition: attachment; filename="recovery_codes.txt"'); header('Content-Transfer-Encoding: binary'); header(sprintf('Content-Length: %d', CUtil::BinStrlen($this->arResult['PLAIN_RESPONSE']))); echo $this->arResult['PLAIN_RESPONSE']; exit; break; case 'print': $APPLICATION->restartBuffer(); $this->includeComponentTemplate(static::PRINT_PAGE); exit; break; case 'view': default: $this->includeComponentTemplate(static::VIEW_PAGE); break; } } }
public function GetAccessToken() { if (($tokens = $this->getStorageTokens()) && is_array($tokens)) { $this->access_token = $tokens["OATOKEN"]; if ($this->checkAccessToken()) { return true; } } if ($this->code === false) { return false; } $h = new \Bitrix\Main\Web\HttpClient(array("socketTimeout" => $this->httpTimeout)); $h->setAuthorization($this->appID, $this->appSecret); $result = $h->post(self::TOKEN_URL, array("grant_type" => "authorization_code", "code" => $this->code, "client_id" => $this->appID)); $this->arResult = \Bitrix\Main\Web\Json::decode($result); if (isset($this->arResult["access_token"]) && $this->arResult["access_token"] != '') { // yandex doesn't send refresh tokens but I leave it here in case they will if (isset($this->arResult["refresh_token"]) && $this->arResult["refresh_token"] != '') { $this->refresh_token = $this->arResult["refresh_token"]; } $this->access_token = $this->arResult["access_token"]; $this->accessTokenExpires = $this->arResult["expires_in"] + time(); $_SESSION["OAUTH_DATA"] = array("OATOKEN" => $this->access_token); return true; } return false; }
protected function sendJsonResponse($response) { global $APPLICATION; $APPLICATION->restartBuffer(); header('Content-Type:application/json; charset=UTF-8'); echo Json::encode($response); $this->end(); }
protected function sendJsonResponse($response) { $this->getApplication()->restartBuffer(); while (ob_end_clean()) { } header('Content-Type:application/json; charset=UTF-8'); echo Json::encode($response); $this->end(); }
public static function encode($data) { // php 5.4.0+ if (defined('JSON_UNESCAPED_UNICODE')) { return parent::encode($data, JSON_UNESCAPED_UNICODE); } else { return static::_encode(static::convertData($data)); } }
/** * Response constructor. * @param $response */ public function __construct($response) { $this->response = $response; $this->fields = Json::decode($this->response); if ($this->fields['error_code']) { $this->setError($this->fields); } $this->state = 'ok'; if ($this->getErrors()) { $this->state = 'error'; } }
protected function sendJsonResponse($response) { if (!defined('PUBLIC_AJAX_MODE')) { define('PUBLIC_AJAX_MODE', true); } global $APPLICATION; $APPLICATION->restartBuffer(); while (ob_end_clean()) { } header('Content-Type:application/json; charset=UTF-8'); echo Json::encode($response); $this->end(); }
protected function sendJsonResponse($response, $params = null) { if (!defined('PUBLIC_AJAX_MODE')) { // define('PUBLIC_AJAX_MODE', true); } global $APPLICATION; $APPLICATION->restartBuffer(); if (!empty($params['http_status']) && $params['http_status'] == 403) { header('HTTP/1.0 403 Forbidden', true, 403); } if (!empty($params['http_status']) && $params['http_status'] == 500) { header('HTTP/1.0 500 Internal Server Error', true, 500); } header('Content-Type:application/json; charset=UTF-8'); echo Json::encode($response); $this->end(); }
public function executeComponent() { /** @global CMain $APPLICATION */ global $APPLICATION; if ($this->request->isPost() && $this->request['action']) { // try to connect $result = $this->toEdit(); $result = Json::encode($result); $APPLICATION->RestartBuffer(); header('Content-Type: application/json', true); echo $result; die; } else { $APPLICATION->SetTitle(Loc::getMessage("SECURITY_OTP_TITLE")); // get data for new OTP connection $this->arResult = $this->toView(); $this->IncludeComponentTemplate(); } }
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; }
protected function showJsonAnswer($result) { if (!defined("PUBLIC_AJAX_MODE")) { define("PUBLIC_AJAX_MODE", true); } if (!defined("NO_KEEP_STATISTIC")) { define("NO_KEEP_STATISTIC", "Y"); } if (!defined("NO_AGENT_STATISTIC")) { define("NO_AGENT_STATISTIC", "Y"); } if (!defined("NO_AGENT_CHECK")) { define("NO_AGENT_CHECK", true); } if (!defined("DisableEventsCheck")) { define("DisableEventsCheck", true); } require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; $GLOBALS["APPLICATION"]->RestartBuffer(); while (ob_end_clean()) { } $version = IsIE(); if (!(0 < $version && $version < 10)) { header('Content-Type:application/json; charset=UTF-8'); } echo Json::encode($result); \CMain::finalActions(); die; }
?> "> <?php echo htmlspecialcharsbx($value); ?> <a href="javascript:void(0);" data-role="delete-access" data-code="<?php echo htmlspecialcharsbx($code); ?> " class="access-delete"></a> </div> <?php } ?> </div> <a href="javascript:void(0)" class="bx-action-href" id="add_access" data-role="add-access"><?php echo GetMessage("SEC_OTP_MANDATORY_RIGHTS_SELECT"); ?> </a> </td> </tr> <?php $tabControl->Buttons(array("disabled" => !$canWrite, "back_url" => $_GET["return_url"] ? $_GET["return_url"] : "security_otp.php?lang=" . LANG)); $tabControl->End(); ?> </form> <script id="settings" type="application/json"><?php echo \Bitrix\Main\Web\Json::encode(array('rights' => array_flip($targetRights))); ?> </script> <?php require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php";
<script type="text/javascript"> BX(function () { BX['LiveFeedClass_<?php echo $arResult['RAND_STRING']; ?> '] = new BX.LiveFeedClass({ socnetGroupId: '<?php echo $arResult['SOCNET_GROUP_ID']; ?> ', randomString: '<?php echo $arResult['RAND_STRING']; ?> ', listData: <?php echo \Bitrix\Main\Web\Json::encode($arResult['LIST_DATA']); ?> }); BX.bind(BX('bx-lists-settings-btn'), 'click', function(e) { BX['LiveFeedClass_<?php echo $arResult['RAND_STRING']; ?> '].createSettingsDropdown(e); }); }); </script> <?php $frame->end(); ?> <script type="text/javascript">
public function unsign($signedValue, $salt = null) { $encodedValue = parent::unsign($signedValue, $salt); return Json::decode(base64_decode($encodedValue)); }
public function GetAppInfo() { if ($this->access_token === false) { return false; } $h = new \Bitrix\Main\Web\HttpClient(); $h->setTimeout($this->httpTimeout); $result = $h->post(static::TOKENINFO_URL . '?access_token=' . urlencode($this->access_token)); $result = \Bitrix\Main\Web\Json::decode($result); if (is_array($result) && $result["audience"]) { $result["id"] = $result["audience"]; } return $result; }
case 'original_texts': $res = $engine->getOriginalTexts($arDomain['DOMAIN'], $arDomain['SITE_DIR']); break; case 'crawling': $res = array('excluded' => $engine->getExcluded($arDomain['DOMAIN'], $arDomain['SITE_DIR']), 'indexed' => $engine->getIndexed($arDomain['DOMAIN'], $arDomain['SITE_DIR'])); break; default: $res = array('error' => 'unknown action'); break; } } catch (Engine\YandexException $e) { $res = array('error' => array('message' => $e->getMessage(), 'status' => $e->getStatus(), 'code' => $e->getCode())); } } Header('Content-type: application/json; charset=' . LANG_CHARSET); echo \Bitrix\Main\Web\Json::encode($res); } elseif (isset($_REQUEST['get'])) { switch ($_REQUEST['get']) { case 'original_text_form': $arSettings = $engine->getSettings(); $arDomains = \CSeoUtils::getDomainsList(); foreach ($arDomains as $key => $domain) { if (!isset($arSettings['SITES'][$domain['DOMAIN']])) { unset($arDomains[$key]); } } if (count($arDomains) <= 0) { $msg = new CAdminMessage(array('MESSAGE' => Loc::getMessage('SEO_YANDEX_ERROR'), 'HTML' => 'Y')); echo $msg->Show(); } else { ?>
$availableTypesDescription = \Bitrix\Security\Mfa\Otp::getTypesDescription(); $currentPage = $APPLICATION->GetCurPageParam(sprintf('%s_active_tab=%s', $tabControl->name, $tabControl->tabs[$tabControl->tabIndex]['DIV']), array(sprintf('%s_active_tab', $tabControl->name))); $deactivateDays = array(); $deactivateDays[] = GetMessage("SEC_OTP_NO_DAYS"); for ($i = 1; $i <= 10; $i++) { $deactivateDays[$i] = FormatDate("ddiff", time() - 60 * 60 * 24 * $i); } $jsMessages = array('SEC_OTP_ERROR_TITLE' => GetMessage('SEC_OTP_ERROR_TITLE'), 'SEC_OTP_UNKNOWN_ERROR' => GetMessage('SEC_OTP_UNKNOWN_ERROR')); $jsSettings = array('userId' => (int) $ID, 'successfulUrl' => $currentPage, 'deactivateDays' => $deactivateDays, 'availableTypes' => $availableTypesDescription); ?> <script id="otp-user-edit-messages" type="application/json"><?php echo \Bitrix\Main\Web\Json::encode($jsMessages); ?> </script> <script id="otp-user-edit-settings" type="application/json"><?php echo \Bitrix\Main\Web\Json::encode($jsSettings); ?> </script> <!--Popup starts--> <tr style="display: none;"> <td colspan="2"> <div id="otp-mobile-popup" class="otp-popup otp-mobile" data-title="<?php echo GetMessage('SEC_OTP_CONNECT_MOBILE_TITLE'); ?> "> <div class="otp-description"> <ol> <li><?php echo GetMessage('SEC_OTP_CONNECT_MOBILE_STEP_1'); ?> </li>
public static function register() { $httpClient = new HttpClient(); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/update_client.php"; $queryParams = array("action" => "register", "key" => md5(\CUpdateClient::GetLicenseKey()), "redirect_uri" => static::getRedirectUri()); $result = $httpClient->post(static::SERVICE_URL . static::REGISTER, $queryParams); $result = Json::decode($result); if ($result["error"]) { throw new SystemException($result["error"]); } else { static::setAccessSettings($result); } }
/** * Lists folder contents * @param $path * @param $folderId * @return mixed */ public function listFolder($path, $folderId) { if ($path === '/') { $folderId = '0'; } $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1)); $http->setHeader('Content-Type', 'application/json; charset=UTF-8'); $http->setHeader('Authorization', "Bearer {$this->getAccessToken()}"); if ($http->get(self::API_URL_V2 . "/folders/{$folderId}/items?fields=name,size,modified_at") === false) { $errorString = implode('; ', array_keys($http->getError())); $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_LIST_FOLDER))); return null; } if (!$this->checkHttpResponse($http)) { return null; } $items = Json::decode($http->getResult()); if ($items === null) { $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON))); return null; } if (!isset($items['entries'])) { $this->errorCollection->add(array(new Error('Could not find items in response', self::ERROR_HTTP_LIST_FOLDER))); return null; } $reformatItems = array(); foreach ($items['entries'] as $item) { $isFolder = $item['type'] === 'folder'; $dateTime = new \DateTime($item['modified_at']); $reformatItems[$item['id']] = array('id' => $item['id'], 'name' => $item['name'], 'type' => $isFolder ? 'folder' : 'file', 'size' => $isFolder ? '' : \CFile::formatSize($item['size']), 'sizeInt' => $isFolder ? '' : $item['size'], 'modifyBy' => '', 'modifyDate' => $dateTime->format('d.m.Y'), 'modifyDateInt' => $dateTime->getTimestamp(), 'provider' => static::getCode()); if (!$isFolder) { $reformatItems[$item['id']]['storage'] = ''; $reformatItems[$item['id']]['ext'] = getFileExtension($item['name']); } } unset($item); return $reformatItems; }
/** * Gets a file's metadata by ID * @param FileData $fileData * @return array|null */ private function getFileMetadataInternal(FileData $fileData) { if (!$this->checkRequiredInputParams($fileData->toArray(), array('id'))) { return null; } $accessToken = $this->getAccessToken(); $http = new HttpClient(array('socketTimeout' => 10, 'streamTimeout' => 30, 'version' => HttpClient::HTTP_1_1)); $http->setHeader('Content-Type', 'application/json; charset=UTF-8'); $http->setHeader('Authorization', "Bearer {$accessToken}"); if ($http->get(self::API_URL_V2 . '/files/' . $fileData->getId()) === false) { $errorString = implode('; ', array_keys($http->getError())); $this->errorCollection->add(array(new Error($errorString, self::ERROR_HTTP_GET_METADATA))); return null; } if (!$this->checkHttpResponse($http)) { return null; } $file = Json::decode($http->getResult()); if ($file === null) { $this->errorCollection->add(array(new Error('Could not decode response as json', self::ERROR_BAD_JSON))); return null; } return $file; }
if ($code != '') { $orm = ApplicationPasswordTable::getList(array('select' => array('ID'), 'filter' => array('USER_ID' => $USER->GetID(), 'CODE' => $code))); if ($row = $orm->fetch()) { ApplicationPasswordTable::delete($row['ID']); } } $password = ApplicationPasswordTable::generatePassword(); $res = ApplicationPasswordTable::add(array('USER_ID' => $USER->GetID(), 'APPLICATION_ID' => 'desktop', 'PASSWORD' => $password, 'DATE_CREATE' => new Main\Type\DateTime(), 'CODE' => $code, 'COMMENT' => GetMessage('DESKTOP_APP_GENERATOR'), 'SYSCOMMENT' => GetMessage('DESKTOP_APP_TITE'))); if ($res->isSuccess()) { $answer["appPassword"] = $password; } } } if (isset($_REQUEST['json']) && $_REQUEST['json'] == 'y') { header('Content-Type: application/json'); echo Main\Web\Json::encode($answer); } else { echo toJsObject($answer); } function toJsObject(array $answer) { $answerParts = array(); foreach ($answer as $attr => $value) { switch (gettype($value)) { case 'string': $value = "'" . CUtil::JSEscape($value) . "'"; break; case 'boolean': $value = $value === true ? 'true' : 'false'; break; case 'array':
protected function prepareAnswer($result) { return \Bitrix\Main\Web\Json::decode($result); }
} $arParams = array("MOBILE" => "Y", "PATH_TO_USER" => $_REQUEST["p_user"], "PATH_TO_GROUP" => $_REQUEST["p_group"], "PATH_TO_CONPANY_DEPARTMENT" => $_REQUEST["p_dep"], "PATH_TO_CRMLEAD" => $_REQUEST["p_crmlead"], "PATH_TO_CRMDEAL" => $_REQUEST["p_crmdeal"], "PATH_TO_CRMCONTACT" => $_REQUEST["p_crmcontact"], "PATH_TO_CRMCOMPANY" => $_REQUEST["p_crmcompany"], "NAME_TEMPLATE" => $_REQUEST["nt"], "SHOW_LOGIN" => $_REQUEST["sl"], "DESTINATION_LIMIT" => 100, "CHECK_PERMISSIONS_DEST" => "N", "CREATED_BY" => $author_id); $arDestinations = CSocNetLogTools::FormatDestinationFromRights($arRights, $arParams, $iMoreCount); if (is_array($arDestinations)) { $iDestinationsHidden = 0; $arGroupID = CSocNetLogTools::GetAvailableGroups(); foreach ($arDestinations as $key => $arDestination) { if (array_key_exists("TYPE", $arDestination) && array_key_exists("ID", $arDestination) && $arDestination["TYPE"] == "SG" && !in_array(intval($arDestination["ID"]), $arGroupID)) { unset($arDestinations[$key]); $iDestinationsHidden++; } } $arResult["arDestinations"] = array_slice($arDestinations, $iDestinationLimit); $arResult["iDestinationsHidden"] = $iDestinationsHidden; } } } elseif ($action == "send_comment_writing" && CModule::IncludeModule("pull")) { $arParams = array("ENTITY_XML_ID" => $_REQUEST["ENTITY_XML_ID"], "NAME_TEMPLATE" => $_REQUEST["nt"], "SHOW_LOGIN" => $_REQUEST["sl"], "AVATAR_SIZE_COMMENT" => intval($as)); $rsUser = CUser::GetList($by = "last_name", $order = "asc", array("ID" => intval($GLOBALS["USER"]->GetId())), array("FIELDS" => array("ID", "NAME", "LAST_NAME", "SECOND_NAME", "LOGIN", "PERSONAL_GENDER", "PERSONAL_PHOTO"))); if ($arUser = $rsUser->Fetch()) { $arFileTmp = CFile::ResizeImageGet($arUser["PERSONAL_PHOTO"], array("width" => $arParams["AVATAR_SIZE_COMMENT"], "height" => $arParams["AVATAR_SIZE_COMMENT"]), BX_RESIZE_IMAGE_EXACT, false); CPullWatch::AddToStack('UNICOMMENTS' . $_REQUEST["ENTITY_XML_ID"], array('module_id' => 'unicomments', 'command' => 'answer', 'expiry' => 60, 'params' => array("USER_ID" => $arUser["ID"], "ENTITY_XML_ID" => $_REQUEST["ENTITY_XML_ID"], "TS" => time(), "NAME" => CUser::FormatName($arParams["NAME_TEMPLATE"], $arUser, $arParams["SHOW_LOGIN"] != "N" ? true : false), "AVATAR" => $arFileTmp && isset($arFileTmp['src']) ? $arFileTmp['src'] : false))); $arResult["SUCCESS"] = 'Y'; } } header('Content-Type: application/x-javascript; charset=' . LANG_CHARSET); echo \Bitrix\Main\Web\Json::encode($arResult); } define('PUBLIC_AJAX_MODE', true); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php"; die;
public static function registerSite($domain) { $query = new \Bitrix\Main\Web\HttpClient(); $result = $query->get(B24NETWORK_URL . '/client.php?action=register&redirect_uri=' . urlencode($domain . '/bitrix/tools/oauth/bitrix24net.php') . '&key=' . urlencode(LICENSE_KEY)); $arResult = \Bitrix\Main\Web\Json::decode($result); if (is_array($arResult)) { return $arResult; } else { return array("error" => "Unknown response", "error_details" => $result); } }
/** * Returns current Yandex user data * * @return array * * @throws SystemException * @throws YandexException */ public function getCurrentUser() { if (!array_key_exists('AUTH_USER', $this->engineSettings) || !is_array($this->engineSettings['AUTH_USER'])) { $queryResult = self::query(self::QUERY_USER); if ($queryResult->getStatus() == self::HTTP_STATUS_OK && strlen($queryResult->getResult()) > 0) { $res = Web\Json::decode($queryResult->getResult()); if (is_array($res)) { $this->engineSettings['AUTH_USER'] = $res; $this->saveSettings(); return $this->engineSettings['AUTH_USER']; } } throw new Engine\YandexException($queryResult); } else { return $this->engineSettings['AUTH_USER']; } }
); } }, "trendLines": [], "legend": { //"switchable": false }, "graphs": yandexGraphs[currentGraph], "guides": [], "valueAxes": [ yandexAxis[currentGraph] ], "allLabels": [], "balloon": {}, "titles": [], "dataProvider": <?=Main\Web\Json::encode($graphData)?> }); <? if($bLoadStats): ?> loadGraphData(); <? endif; ?> window.showStats = BX.DoNothing; }; <? if($tabControl->selectedTab == "edit_stats"): ?>
$newNumber = substr($_POST["BLACKLIST_NEW_NUMBER"], 0, 20); $newNumber = CVoxImplantPhone::Normalize($newNumber); if ($newNumber) { $dbBlacklist = Bitrix\Voximplant\BlacklistTable::getList(array("filter" => array("PHONE_NUMBER" => $newNumber))); if (!$dbBlacklist->Fetch()) { Bitrix\Voximplant\BlacklistTable::add(array("PHONE_NUMBER" => $newNumber)); } LocalRedirect(POST_FORM_ACTION_URI); } else { $arResult["ERROR"] = GetMessage("VI_BLACKLIST_NUMBER_ERROR"); } } if (isset($_POST["action"]) && $_POST["action"] == "delete_number") { $dbBlacklist = Bitrix\Voximplant\BlacklistTable::getList(array("filter" => array("PHONE_NUMBER" => $_POST["number"]))); if ($arBlacklist = $dbBlacklist->Fetch()) { Bitrix\Voximplant\BlacklistTable::delete($arBlacklist["ID"]); } $APPLICATION->RestartBuffer(); echo \Bitrix\Main\Web\Json::encode(array("success" => "Y")); die; } } $arResult["ITEMS"] = array(); $dbBlacklist = Bitrix\Voximplant\BlacklistTable::getList(); while ($arBlacklist = $dbBlacklist->Fetch()) { $arResult["ITEMS"][] = $arBlacklist; } $arResult["BLACKLIST_AUTO"] = Bitrix\Main\Config\Option::get("voximplant", "blacklist_auto", "N"); $arResult["BLACKLIST_TIME"] = intval(Bitrix\Main\Config\Option::get("voximplant", "blacklist_time", 5)); $arResult["BLACKLIST_COUNT"] = intval(Bitrix\Main\Config\Option::get("voximplant", "blacklist_count", 5)); $this->IncludeComponentTemplate();