/** * Decodes JSON sting. * * @static * * @param string $data * @param bool $asArray get result as array instead of object * * @return mixed */ public static function decodeJson($data, $asArray = true) { if (self::$json === null) { self::$json = new CJson(); } return self::$json->decode($data, $asArray); }
/** * Output ajax response. If any error was added, 'result' is false, otherwise true. * * @return void */ public function send() { $json = new CJson(); if ($this->_result) { echo $json->encode(['result' => true, 'data' => $this->_data]); } else { echo $json->encode(['result' => false, 'errors' => $this->_errors]); } }
/** * Creates an HTTP cookie to be sent along with an HTTP response. * * Internally, the value of a cookie is always stored as a string. If the cookie's value was provided as an array * or map, it's encoded into JSON and is stored as a JSON string. Boolean values are stored as "1" for `true` and * as "0" for `false`. * * @param string $cookieName The cookie's name. * @param mixed $value The cookie's value. This can be a string, a `bool`, an `int`, a `float`, an array, or a * map. */ public function __construct($cookieName, $value) { assert('is_cstring($cookieName) && (is_cstring($value) || is_bool($value) || is_int($value) || ' . 'is_float($value) || is_collection($value))', vs(isset($this), get_defined_vars())); $this->m_name = $cookieName; if (is_cstring($value)) { $this->m_value = $value; } else { if (is_bool($value)) { $this->m_value = CString::fromBool10($value); } else { if (is_int($value)) { $this->m_value = CString::fromInt($value); } else { if (is_float($value)) { $this->m_value = CString::fromFloat($value); } else { $json = new CJson($value); $this->m_value = $json->encode(); } } } } }
public function send($pUrl, $pMethod = self::RM_GET, $pData = array()) { $optArr = array('http' => array('method' => $pMethod, 'header' => 'Content-Type: text/plain;charset=utf-8')); $stream = \stream_context_create($optArr); switch ($pMethod) { case self::RM_PUT: case self::RM_POST: $optArr['http']['content'] = CJson::encode($pData); $stream = \stream_context_create($optArr); $res = \file_get_contents(sprintf('%s:%s/%s', self::$HOST, self::$PORT, $pUrl), null, $stream); break; case self::RM_DELETE: case self::RM_GET: if (count($pData) > 0) { $res = \file_get_contents(sprintf('%s:%s/%s?%s', self::$HOST, self::$PORT, $pUrl, \http_build_query($pData)), null, $stream); } else { $res = \file_get_contents(sprintf('%s:%s/%s', self::$HOST, self::$PORT, $pUrl), null, $stream); } break; } return $res; }
$mapInfo = getSelementsInfo($map, array('severity_min' => getRequest('severity_min'))); processAreasCoordinates($map, $areas, $mapInfo); $allLinks = false; } /* * Draw map */ drawMapConnectors($im, $map, $mapInfo, $allLinks); if (!isset($_REQUEST['noselements'])) { drawMapHighligts($im, $map, $mapInfo); drawMapSelements($im, $map, $mapInfo); } $expandMacros = getRequest('expand_macros', true); drawMapLabels($im, $map, $mapInfo, $expandMacros); drawMapLinkLabels($im, $map, $mapInfo, $expandMacros); if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) { drawMapSelementsMarks($im, $map, $mapInfo); } show_messages(); if (getRequest('base64image')) { ob_start(); imagepng($im); $imageSource = ob_get_contents(); ob_end_clean(); $json = new CJson(); echo $json->encode(array('result' => base64_encode($imageSource))); imagedestroy($im); } else { imageOut($im); } require_once dirname(__FILE__) . '/include/page_footer.php';
require_once dirname(__FILE__) . '/include/maps.inc.php'; require_once dirname(__FILE__) . '/include/forms.inc.php'; $page['title'] = _('Configuration of network maps'); $page['file'] = 'sysmap.php'; $page['hist_arg'] = array('sysmapid'); $page['scripts'] = array('class.cmap.js', 'class.cviewswitcher.js', 'multiselect.js'); $page['type'] = detect_page_type(); require_once dirname(__FILE__) . '/include/page_header.php'; // VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION $fields = array('sysmapid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), 'selementid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, null), 'sysmap' => array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({action})'), 'selements' => array(T_ZBX_STR, O_OPT, P_SYS, DB_ID, null), 'links' => array(T_ZBX_STR, O_OPT, P_SYS, DB_ID, null), 'action' => array(T_ZBX_STR, O_OPT, P_ACT, IN('"update"'), null), 'delete' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, null, null), 'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, null, null), 'form_refresh' => array(T_ZBX_INT, O_OPT, null, null, null), 'favobj' => array(T_ZBX_STR, O_OPT, P_ACT, null, null), 'favid' => array(T_ZBX_STR, O_OPT, P_ACT, null, null)); check_fields($fields); /* * Ajax */ if (isset($_REQUEST['favobj'])) { $json = new CJson(); // if ($_REQUEST['favobj'] == 'sysmap' && getRequest('action') == 'update') { if (getRequest('favobj') == 'sysmap' && hasRequest('action') && getRequest('action') == 'update') { $sysmapid = getRequest('sysmapid', 0); @ob_start(); try { DBstart(); $sysmap = API::Map()->get(array('sysmapids' => $sysmapid, 'editable' => true, 'output' => array('sysmapid'))); $sysmap = reset($sysmap); if ($sysmap === false) { throw new Exception(_('Access denied!') . "\n\r"); } $sysmapUpdate = $json->decode($_REQUEST['sysmap'], true); $sysmapUpdate['sysmapid'] = $sysmapid; $result = API::Map()->update($sysmapUpdate); if ($result !== false) {
public function testSubscribeContactsForReportType() { $type = 'report'; $report = SavedReportTestHelper::makeSimpleContactRowsAndColumnsReport(); $marketingList = MarketingListTestHelper::createMarketingListByName('MarketingList5', 'MarketingList Description5'); $marketingListId = $marketingList->id; $contactCount = Contact::getCount(); $this->assertNotNull($report); $this->setGetArray(array('marketingListId' => $marketingListId, 'id' => $report->id, 'type' => $type)); $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts'); $contentArray = CJson::decode($content); $this->assertNotEmpty($contentArray); $this->assertArrayHasKey('type', $contentArray); $this->assertArrayHasKey('message', $contentArray); $this->assertEquals($contactCount . ' subscribed.', $contentArray['message']); $this->assertEquals('message', $contentArray['type']); $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts'); $contentArray = CJson::decode($content); $this->assertNotEmpty($contentArray); $this->assertArrayHasKey('type', $contentArray); $this->assertArrayHasKey('message', $contentArray); $this->assertEquals('0 subscribed. ' . $contactCount . ' skipped, already in the list.', $contentArray['message']); $this->assertEquals('message', $contentArray['type']); Yii::app()->pagination->setForCurrentUserByType('reportResultsListPageSize', 1); $this->setGetArray(array('marketingListId' => $marketingListId, 'id' => $report->id, 'type' => $type, 'page' => 2)); $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts'); $contentArray = CJson::decode($content); $percent = round(2 / $contactCount * 100, 0); // Not Coding Standard $this->assertNotEmpty($contentArray); $this->assertArrayHasKey('type', $contentArray); $this->assertArrayHasKey('message', $contentArray); $this->assertEquals("Processing: {$percent} % complete", $contentArray['message']); $this->assertEquals('message', $contentArray['type']); $this->assertEquals(3, $contentArray['nextPage']); $this->assertEquals(0, $contentArray['subscribedCount']); $this->assertEquals(1, $contentArray['skippedCount']); $this->setGetArray(array('marketingListId' => $marketingListId, 'id' => $report->id, 'type' => $type, 'page' => $contactCount, 'skippedCount' => $contactCount - 1, 'subscribedCount' => 0)); $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/defaultPortlet/subscribeContacts'); $contentArray = CJson::decode($content); $this->assertNotEmpty($contentArray); $this->assertArrayHasKey('type', $contentArray); $this->assertArrayHasKey('message', $contentArray); $this->assertEquals("0 subscribed. {$contactCount} skipped, already in the list.", $contentArray['message']); $this->assertEquals('message', $contentArray['type']); }
function imageOut(&$image, $format = null) { global $page, $IMAGE_FORMAT_DEFAULT; if (is_null($format)) { $format = $IMAGE_FORMAT_DEFAULT; } ob_start(); if (IMAGE_FORMAT_JPEG == $format) { imagejpeg($image); } else { imagepng($image); } $imageSource = ob_get_contents(); ob_end_clean(); if ($page['type'] != PAGE_TYPE_IMAGE) { $imageId = md5(strlen($imageSource)); CSession::setValue('image_id', [$imageId => $imageSource]); } switch ($page['type']) { case PAGE_TYPE_IMAGE: echo $imageSource; break; case PAGE_TYPE_JSON: $json = new CJson(); echo $json->encode(['result' => $imageId]); break; case PAGE_TYPE_TEXT: default: echo $imageId; } }
/** * * Encodes the mixed $valueToEncode into JSON format. * * @param mixed $valueToEncode Value to be encoded into JSON format * * @param array $deQuote Array of keys whose values should **not** be * quoted in encoded string. * * @param bool $forceObject force all arrays to objects * * @return string JSON encoded value * */ public function encode($valueToEncode, $deQuote = array(), $forceObject = false) { if (!$this->_config['bypass_ext'] && function_exists('json_encode') && defined('JSON_FORCE_OBJECT')) { if ($this->_config['noerror']) { $old_errlevel = error_reporting(E_ERROR ^ E_WARNING); } $encoded = json_encode($valueToEncode, $forceObject ? JSON_FORCE_OBJECT : null); if ($this->_config['noerror']) { error_reporting($old_errlevel); } } else { // fall back to php-only method self::$forceObject = $forceObject ? true : null; $encoded = $this->_json_encode($valueToEncode); } // sometimes you just don't want some values quoted if (!empty($deQuote)) { $encoded = $this->_deQuote($encoded, $deQuote); } return $encoded; }
/** * Filters a string or a collection of strings according to the expected output type(s) and returns the output * value(s). * * @param mixed $inputStringOrDecodedCollection The string to be filtered or the array or map containing the * strings to be filtered. If the parameter's value is a JSON-encoded string, the output value is going to be * either an array or map. * @param reference $success **OUTPUT.** After the method is called, the value of this parameter tells whether * the filtering was successful. * * @return mixed The output value or a collection of values of the expected type(s) after having been put through * the filter. */ public function filter($inputStringOrDecodedCollection, &$success) { assert('is_cstring($inputStringOrDecodedCollection) || is_collection($inputStringOrDecodedCollection)', vs(isset($this), get_defined_vars())); $success = true; if ($this->m_expectedType != self::CARRAY && $this->m_expectedType != self::CMAP) { // The expected output type is not a collection; the input value must be of string type. if (!is_cstring($inputStringOrDecodedCollection)) { $success = false; return oop_x($this->m_defaultValue); } $inputString = $inputStringOrDecodedCollection; if ($this->m_expectedType == self::BOOL || $this->m_expectedType == self::INT || $this->m_expectedType == self::FLOAT || $this->m_expectedType == self::EMAIL || $this->m_expectedType == self::URL || $this->m_expectedType == self::IP) { // Trim the input string on both sides from whitespace, including Unicode whitespace and control // characters. $trimmingSubjectRe = CUString::TRIMMING_AND_SPACING_NORM_SUBJECT_RE; $inputString = CRegex::remove($inputString, "/^({$trimmingSubjectRe})+|({$trimmingSubjectRe})+\\z/u"); } // Pre-process the string for integer and floating-point types. $looksLikeHex; if ($this->m_expectedType == self::INT || $this->m_expectedType == self::FLOAT) { if (CString::startsWith($inputString, "+")) { // Remove the plus sign. $inputString = CString::substr($inputString, 1); } $looksLikeHex = CRegex::find($inputString, "/^-?0x/i"); if ($this->m_allowLeadingZeros && !($this->m_expectedType == self::INT && $this->m_allowHex && $looksLikeHex)) { // Remove any leading zeros (except for special cases). $inputString = CRegex::replace($inputString, "/^(\\D*)0*(?!\\b)/", "\$1"); } if ($this->m_allowComma) { $inputString = CRegex::remove($inputString, "/,(?=\\d{3}\\b)/"); } } // Validate and sanitize the value according to its expected type. if ($this->m_expectedType == self::BOOL) { if (!CRegex::find($inputString, "/^(1|true|yes|on|0|false|no|off)\\z/i")) { $success = false; return $this->m_defaultValue; } return CString::equals($inputString, "1") || CString::equalsCi($inputString, "true") || CString::equalsCi($inputString, "yes") || CString::equalsCi($inputString, "on"); } if ($this->m_expectedType == self::INT) { $value; if (!($this->m_allowHex && $looksLikeHex)) { // Regular. if (!CRegex::find($inputString, "/^-?(?!0(?!\\b))\\d+\\z/")) { $success = false; return $this->m_defaultValue; } $value = CString::toInt($inputString); } else { // Hex. if (!CRegex::find($inputString, "/^-?0x[0-9A-F]+\\z/i")) { $success = false; return $this->m_defaultValue; } $value = CString::toIntFromHex($inputString); } if (isset($this->m_intValidMin) && $value < $this->m_intValidMin || isset($this->m_intValidMax) && $value > $this->m_intValidMax) { $success = false; return $this->m_defaultValue; } if (isset($this->m_intClampingMin) && $value < $this->m_intClampingMin) { $value = $this->m_intClampingMin; } if (isset($this->m_intClampingMax) && $value > $this->m_intClampingMax) { $value = $this->m_intClampingMax; } return $value; } if ($this->m_expectedType == self::FLOAT) { if (!CRegex::find($inputString, "/^-?(?!0(?!\\b))\\d*\\.?\\d+(e[\\-+]?\\d+)?\\z/i")) { $success = false; return $this->m_defaultValue; } $value = CString::toFloat($inputString); if (isset($this->m_floatValidMin) && $value < $this->m_floatValidMin || isset($this->m_floatValidMax) && $value > $this->m_floatValidMax) { $success = false; return $this->m_defaultValue; } if (isset($this->m_floatClampingMin) && $value < $this->m_floatClampingMin) { $value = $this->m_floatClampingMin; } if (isset($this->m_floatClampingMax) && $value > $this->m_floatClampingMax) { $value = $this->m_floatClampingMax; } return $value; } if ($this->m_expectedType == self::CSTRING) { $value = $inputString; if (!CString::isValid($value)) { $success = false; return $this->m_defaultValue; } if (!$this->m_keepAbnormalNewlines) { $value = CString::normNewlines($value); } if (!$this->m_keepNonPrintable) { if (!$this->m_keepTabsAndNewlines) { $value = CRegex::remove($value, "/[\\x00-\\x1F\\x7F-\\xFF]/"); } else { $value = CRegex::remove($value, "/[\\x00-\\x1F\\x7F-\\xFF](?<![\\x09\\x0A\\x0D])/"); } } else { if (!$this->m_keepTabsAndNewlines) { $value = CRegex::remove($value, "/[\\x09\\x0A\\x0D]/"); } } if (!$this->m_keepSideSpacing) { $value = CString::trim($value); } if (!$this->m_keepExtraSpacing) { $value = CString::normSpacing($value); } return $value; } if ($this->m_expectedType == self::CUSTRING) { $value = $inputString; if (!CUString::isValid($value)) { $success = false; return $this->m_defaultValue; } if (!$this->m_keepAbnormalNewlines) { $value = CUString::normNewlines($value); } if (!$this->m_keepNonPrintable) { if (!$this->m_keepTabsAndNewlines) { $value = CRegex::remove($value, "/\\p{C}|\\p{Zl}|\\p{Zp}/u"); } else { $value = CRegex::remove($value, "/\\p{C}(?<!\\x{0009}|\\x{000A}|\\x{000D})/u"); } } else { if (!$this->m_keepTabsAndNewlines) { $value = CRegex::remove($value, "/\\x{0009}|\\x{000A}|\\x{000D}|\\p{Zl}|\\p{Zp}/u"); } } if (!$this->m_keepSideSpacing) { $value = CUString::trim($value); } if (!$this->m_keepExtraSpacing) { $value = CUString::normSpacing($value); } return $value; } if ($this->m_expectedType == self::EMAIL) { $value = filter_var($inputString, FILTER_VALIDATE_EMAIL); if (!is_cstring($value)) { $success = false; return $this->m_defaultValue; } return $value; } if ($this->m_expectedType == self::URL) { $value = $inputString; if (!CUrl::isValid($value, $this->m_ignoreProtocolAbsence)) { $success = false; return $this->m_defaultValue; } if ($this->m_ignoreProtocolAbsence) { $value = CUrl::ensureProtocol($value); } return $value; } if ($this->m_expectedType == self::IP) { $value = $inputString; $options = CBitField::ALL_UNSET; if (!$this->m_allowPrivateRange) { $options |= CIp::DISALLOW_PRIVATE_RANGE; } if (!$this->m_allowReservedRange) { $options |= CIp::DISALLOW_RESERVED_RANGE; } $isValid; if (!$this->m_ipV6 && !$this->m_ipV4OrV6) { $isValid = CIp::isValidV4($value, $options); } else { if (!$this->m_ipV4OrV6) { $isValid = CIp::isValidV6($value, $options); } else { $isValid = CIp::isValidV4($value, $options) || CIp::isValidV6($value, $options); } } if (!$isValid) { $success = false; return $this->m_defaultValue; } return $value; } } else { if ($this->m_expectedType == self::CARRAY) { if (!is_cstring($inputStringOrDecodedCollection) && !is_carray($inputStringOrDecodedCollection)) { $success = false; return oop_x($this->m_defaultValue); } $value; if (is_cstring($inputStringOrDecodedCollection)) { // Assume JSON format for the input string. $json = new CJson($inputStringOrDecodedCollection, $this->m_jsonStrictness); $value = $json->decode($success); if (!$success) { return oop_x($this->m_defaultValue); } if (!is_carray($value)) { $success = false; return oop_x($this->m_defaultValue); } } else { $value = $inputStringOrDecodedCollection; } $value = self::recurseCollectionFiltering($value, $this->m_collectionInputFilters, $success, 0); if (!$success) { return oop_x($this->m_defaultValue); } return $value; } else { if (!is_cstring($inputStringOrDecodedCollection) && !is_cmap($inputStringOrDecodedCollection)) { $success = false; return oop_x($this->m_defaultValue); } $value; if (is_cstring($inputStringOrDecodedCollection)) { // Assume JSON format for the input string. $json = new CJson($inputStringOrDecodedCollection, $this->m_jsonStrictness); $value = $json->decode($success); if (!$success) { return oop_x($this->m_defaultValue); } if (!is_cmap($value)) { $success = false; return oop_x($this->m_defaultValue); } } else { $value = $inputStringOrDecodedCollection; } $value = self::recurseCollectionFiltering($value, $this->m_collectionInputFilters, $success, 0); if (!$success) { return oop_x($this->m_defaultValue); } return $value; } } }
function imageOut(&$image, $format = null) { global $page, $IMAGE_FORMAT_DEFAULT; if (is_null($format)) { $format = $IMAGE_FORMAT_DEFAULT; } ob_start(); if (IMAGE_FORMAT_JPEG == $format) { imagejpeg($image); } else { imagepng($image); } $imageSource = ob_get_contents(); ob_end_clean(); if ($page['type'] != PAGE_TYPE_IMAGE) { session_start(); $imageId = md5(strlen($imageSource)); $_SESSION['image_id'] = array(); $_SESSION['image_id'][$imageId] = $imageSource; session_write_close(); } switch ($page['type']) { case PAGE_TYPE_IMAGE: echo $imageSource; break; case PAGE_TYPE_JSON: $json = new CJson(); echo $json->encode(array('result' => $imageId)); break; case PAGE_TYPE_TEXT: default: echo $imageId; } }
public function actionSavePayments() { // Changes in payment block in order managment // Не лишняя ли это функция? $this->_prepairJson(); $orderId = $this->_request->getParam('order_id'); $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $orderId)); if (!$payment) { $payment = new ProjectPayments(); $payment->order_id = $orderId; $payment->received = 0; $payment->to_receive = 0; $payment->to_pay = 0; } $to_receive = $this->_request->getParam('to_receive', 0); if ($this->_request->getParam('project_price')) { $payment->project_price = $this->_request->getParam('project_price'); } if ($this->_request->getParam('to_receive')) { $payment->to_receive += (int) $this->_request->getParam('to_receive'); } if (!($this->_request->getParam('work_price') === null)) { $payment->work_price = $this->_request->getParam('work_price'); } if ($this->_request->getParam('to_pay')) { $paying = (int) $this->_request->getParam('to_pay'); } if ($paying > 0 && $to_receive == 0 && $payment->work_price > 0 && $paying + $payment->to_pay > $payment->work_price + $payment->payed && (int) $payment->to_pay > 0) { echo CJson::encode(['Оплата превышает лимит']); Yii::app()->end(); } $payment->to_pay += $paying; if ($payment->save()) { //(To User) $order = Zakaz::model()->findByPk($orderId); if ($payment->project_price > 0 && $order && $order->status == 1) { $order->status = 2; $order->save(false); } //(To Author) //$order = Zakaz::model()->findByPk($orderId); if ($paying > 0) { $user = User::model()->with('profile')->findByPk($order->executor); $manag = User::model()->findByPk(Yii::app()->user->id); $buh = new Payment(); $buh->approve = 0; $buh->order_id = $orderId; $buh->receive_date = date('Y-m-d H:i:s'); $buh->theme = $order->title; $buh->user = $user->email; $buh->summ = $paying; $buh->payment_type = Payment::OUTCOMING_EXECUTOR; $buh->manager = $manag->email; /*$buh->details_ya = $user->profile->yandex; $buh->details_wm = $user->profile->wmr; $buh->details_bank = $user->profile->bank_account;*/ $buh->save(); } $this->_response->setData(array('project_price' => $payment->project_price, 'to_receive' => $payment->to_receive, 'work_price' => $payment->work_price, 'to_pay' => $payment->to_pay)); } else { $this->_response->setData(array('result' => 'false')); } $this->_response->send(); }
$mapInfo = getSelementsInfo($map, ['severity_min' => getRequest('severity_min')]); processAreasCoordinates($map, $areas, $mapInfo); $allLinks = false; } /* * Draw map */ drawMapConnectors($im, $map, $mapInfo, $allLinks); if (!isset($_REQUEST['noselements'])) { drawMapHighligts($im, $map, $mapInfo); drawMapSelements($im, $map, $mapInfo); } $expandMacros = getRequest('expand_macros', true); drawMapLabels($im, $map, $mapInfo, $expandMacros, $graphtheme); drawMapLinkLabels($im, $map, $mapInfo, $expandMacros, $graphtheme); if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) { drawMapSelementsMarks($im, $map, $mapInfo); } show_messages(); if (getRequest('base64image')) { ob_start(); imagepng($im); $imageSource = ob_get_contents(); ob_end_clean(); $json = new CJson(); echo $json->encode(['result' => base64_encode($imageSource)]); imagedestroy($im); } else { imageOut($im); } require_once dirname(__FILE__) . '/include/page_footer.php';
protected static function readAndAddConfig($configFp, $configName, $configs) { if (CMap::hasKey(self::$ms_configAliases, $configName)) { $configName = self::$ms_configAliases[$configName]; } $configName = CString::toLowerCase($configName); $configJson = CFile::read($configFp); $configJson = CRegex::remove($configJson, "/^\\h*\\/\\/.*/m"); // remove comments $configJson = "{\"{$configName}\": {$configJson}}"; $json = new CJson($configJson); $success; $config = $json->decode($success); assert('$success', vs(isset($this), get_defined_vars())); CArray::push($configs, $config); }
/** * execute when object is unserialized * @return mixed */ public function __wakeup() { return CJson::decode($this); }
public function testEncode() { $value = m(["prop0" => "value", "prop1" => a("value0", "value1"), "prop2" => m(["subProp0" => "value0", "subProp1" => "value1"]), "prop3" => a(true, 1234, 56.78)]); $json = new CJson($value); $encJson = $json->encode(); $json = new CJson($encJson); $success; $decMap = $json->decode($success); $this->assertTrue($success && $decMap->equals($value)); }
/** * convert string with data in JSON format to php array. * * @param string $string * * @return array */ public function read($string) { $json = new CJson(); return $json->decode($string, true); }
if ($triggers) { CArrayHelper::sort($triggers, array(array('field' => 'description', 'order' => ZBX_SORT_UP))); if (isset($data['limit'])) { $triggers = array_slice($triggers, 0, $data['limit']); } foreach ($triggers as $trigger) { $hostName = ''; if ($trigger['hosts']) { $trigger['hosts'] = reset($trigger['hosts']); $hostName = $trigger['hosts']['name'] . NAME_DELIMITER; } $result[] = array('id' => $trigger['triggerid'], 'name' => $trigger['description'], 'prefix' => $hostName); } } break; } break; default: fatal_error('Wrong RPC call to JS RPC!'); } if ($requestType == PAGE_TYPE_JSON) { if (isset($data['id'])) { echo $json->encode(array('jsonrpc' => '2.0', 'result' => $result, 'id' => $data['id'])); } } elseif ($requestType == PAGE_TYPE_TEXT_RETURN_JSON) { $json = new CJson(); echo $json->encode(array('jsonrpc' => '2.0', 'result' => $result)); } elseif ($requestType == PAGE_TYPE_TEXT || $requestType == PAGE_TYPE_JS) { echo $result; } require_once dirname(__FILE__) . '/include/page_footer.php';
/** * Convert array with export data to JSON format. * * @param array $array * * @return string */ public function write(array $array) { $json = new CJson(); return $json->encode($array); }
} } break; case 'users': $users = API::User()->get(['editable' => array_key_exists('editable', $data) ? $data['editable'] : null, 'output' => ['userid', 'alias', 'name', 'surname'], 'search' => array_key_exists('search', $data) ? ['alias' => $data['search'], 'name' => $data['search'], 'surname' => $data['search']] : null, 'searchByAny' => true, 'limit' => $config['search_limit']]); if ($users) { CArrayHelper::sort($users, [['field' => 'alias', 'order' => ZBX_SORT_UP]]); if (array_key_exists('limit', $data)) { $users = array_slice($users, 0, $data['limit']); } foreach ($users as $user) { $result[] = ['id' => $user['userid'], 'name' => getUserFullname($user)]; } } break; } break; default: fatal_error('Wrong RPC call to JS RPC!'); } if ($requestType == PAGE_TYPE_JSON) { if (isset($data['id'])) { echo $json->encode(['jsonrpc' => '2.0', 'result' => $result, 'id' => $data['id']]); } } elseif ($requestType == PAGE_TYPE_TEXT_RETURN_JSON) { $json = new CJson(); echo $json->encode(['jsonrpc' => '2.0', 'result' => $result]); } elseif ($requestType == PAGE_TYPE_TEXT || $requestType == PAGE_TYPE_JS) { echo $result; } require_once dirname(__FILE__) . '/include/page_footer.php';