本文整理汇总了PHP中Services_JSON::encodeUnsafe方法的典型用法代码示例。如果您正苦于以下问题:PHP Services_JSON::encodeUnsafe方法的具体用法?PHP Services_JSON::encodeUnsafe怎么用?PHP Services_JSON::encodeUnsafe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Services_JSON
的用法示例。
在下文中一共展示了Services_JSON::encodeUnsafe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* Send the HTTP request via cURL
*
* @return SiftResponse
*/
public function send()
{
$json = new Services_JSON();
$propertiesString = http_build_query($this->properties);
$curlUrl = $this->url;
if ($this->method == self::GET) {
$curlUrl .= '?' . $propertiesString;
}
// Mock the request if self::$mock exists
if (self::$mock) {
if (self::$mock['url'] == $curlUrl && self::$mock['method'] == $this->method) {
return self::$mock['response'];
}
return null;
}
// Open and configure curl connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $curlUrl);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
if ($this->method == self::POST) {
$jsonString = $json->encodeUnsafe($this->properties);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($jsonString), 'User-Agent: SiftScience/v' . SiftClient::API_VERSION . ' sift-php/' . SiftClient::VERSION));
}
// Send the request using curl and parse result
$result = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the curl connection
curl_close($ch);
return new SiftResponse($result, $httpStatusCode, $this);
}
示例2:
function test_json_encode_decode()
{
require_once ABSPATH . WPINC . '/class-json.php';
$json = new Services_JSON();
// Super basic test to verify Services_JSON is intact and working.
$this->assertEquals('["foo"]', $json->encodeUnsafe(array('foo')));
$this->assertEquals(array('foo'), $json->decode('["foo"]'));
}
示例3: languageSelect
public static function languageSelect($attributes = array(), $lang = null)
{
$json = new Services_JSON();
$configs = Gio_Core_Config_Xml::getConfig();
$defaultLang = $configs->localization->languages->default;
$selectedId = isset($attributes['selected']) ? $attributes['selected'] : $defaultLang;
$disableId = isset($attributes['disabled']) ? $attributes['disabled'] : null;
$elementDisabled = isset($attributes['disabled']) && $attributes['disabled'] === true ? ' disabled="disabled"' : '';
$name = isset($attributes['name']) ? $attributes['name'] : null;
$id = isset($attributes['id']) ? $attributes['id'] : null;
$output = sprintf("<select name='%s' id='%s' viewHelperClass='%s' viewHelperAttributes='%s'%s>", $name, $id, 'Modules_Core_Services_Language::languageSelect', $json->encodeUnsafe($attributes), $elementDisabled) . self::EOL . '<option value="">---</option>' . self::EOL;
if (isset($configs->localization->languages->list)) {
foreach (explode(',', $configs->localization->languages->list) as $l) {
$languages[$l] = explode('|', $configs->localization->languages->details->{$l});
}
}
foreach ($languages as $index => $language) {
$selected = $selectedId == null || $selectedId != $language[0] ? '' : ' selected="selected"';
$disable = $disableId == null || $disableId != $language[0] ? '' : ' disabled';
$output .= sprintf('<option value="%s"%s%s>%s (%s)</option>', $index, $selected, $disable, $language[1], $language[2]) . self::EOL;
}
$output .= '</select>' . self::EOL;
$viewHelperUrl = Gio_Core_View::getInstance()->url('core_locale_viewhelper');
$scripts = <<<END
\t\t<script type="text/javascript">
\t\t\$('#{$id}').bind('change', function() {
\t\tvar lang = \$(this).val();
\t\tvar total = \$('.g_a_translatable').length;
\t\tvar moduleId = \$('#module_id').val();
\t\tif (lang != '') {
\t\t\t\$('.g_a_translatable').each(function(index) {
\t\t\t\tvar self = this;
\t\t\t\tvar element = \$(this).children()[0];
\t\t\t\t\$(self).addClass('g_a_ajax_loading');
\t\t\t\tvar data = {
\t\t\t\t\tid: \$(element).attr('id'),
\t\t\t\t\tname: \$(element).attr('name'),
\t\t\t\t\tlanguage: lang,
\t\t\t\t\tmoduleId: moduleId,
\t\t\t\t\tviewHelperClass: \$(element).attr('viewHelperClass'),
\t\t\t\t\tviewHelperAttributes: \$(element).attr('viewHelperAttributes')
\t\t\t\t};
\t\t\t
\t\t\t\t\$.ajaxq('core_locale', {
\t\t\t\t\ttype: 'post',
\t\t\t\t\turl: '{$viewHelperUrl}',
\t\t\t\t\tdata: data,
\t\t\t\t\tsuccess: function(response) {
\t\t\t\t\t\t\$(self).html(response).removeClass('g_a_ajax_loading');
\t\t\t\t\t}
\t\t\t\t});
\t\t\t});
\t\t}
\t});
\t\t</script>
END;
return $output . $scripts;
}
示例4:
function json_encode($string)
{
global $json;
if (!is_a($json, 'Services_JSON')) {
require_once W3TC_LIB_DIR . '/JSON.php';
$json = new Services_JSON();
}
return $json->encodeUnsafe($string);
}
示例5:
function json_encode($string)
{
global $nxt_json;
if (!is_a($nxt_json, 'Services_JSON')) {
require_once ABSPATH . nxtINC . '/class-json.php';
$nxt_json = new Services_JSON();
}
return $nxt_json->encodeUnsafe($string);
}
示例6:
function json_encode($string)
{
global $wp_json;
if (!$wp_json instanceof Services_JSON) {
require_once ABSPATH . WPINC . '/class-json.php';
$wp_json = new Services_JSON();
}
return $wp_json->encodeUnsafe($string);
}
示例7:
function json_encode($string)
{
global $json_obj;
if (!is_a($json_obj, 'Services_JSON')) {
require_once 'class-json.php';
$json_obj = new Services_JSON();
}
return $json_obj->encodeUnsafe($string);
}
示例8: send
/**
* Send the HTTP request via cURL
*
* @return SiftResponse
*/
public function send()
{
$curlUrl = $this->url;
// Mock the request if self::$mock exists
if (self::$mock) {
if (self::$mock['url'] == $curlUrl && self::$mock['method'] == $this->method) {
return self::$mock['response'];
}
return null;
}
// Open and configure curl connection
$ch = curl_init();
$headers = array('Authorization: Basic ' . $this->apiKey, 'User-Agent: SiftScience/v' . SiftClient::API_VERSION . ' sift-partner-php/' . Sift::VERSION);
//GET Specific setup. The check for null is in the case that we don't add any parameters.
if ($this->method == self::GET) {
if ($this->properties !== null) {
$propertiesString = http_build_query($this->properties);
$curlUrl .= '?' . $propertiesString;
}
} else {
// POST specific setup
if ($this->method == self::POST) {
curl_setopt($ch, CURLOPT_POST, 1);
} else {
if ($this->method == self::PUT) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
}
}
// shared by POST and PUT setup
if (function_exists('json_encode')) {
$jsonString = json_encode($this->properties);
} else {
require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php';
$json = new Services_JSON();
$jsonString = $json->encodeUnsafe($this->properties);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
/**
* add 'Content-Type: application/json',
* 'Content-Length: ' . strlen($jsonString),
*/
array_push($headers, 'Content-Type: application/json');
array_push($headers, 'Content-Length: ' . strlen($jsonString));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $curlUrl);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
// Set the header
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Send the request using curl and parse result
$result = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the curl connection
curl_close($ch);
return new SiftResponse($result, $httpStatusCode, $this);
}
示例9: set
public static function set($name, $value = null, $sessionId = null)
{
$session = self::getSessionById($sessionId);
if ($session != null) {
$json = new Services_JSON();
$data = $json->encodeUnsafe($value);
self::update($data, $sessionId);
}
return null;
}
示例10: send
/**
* Send the HTTP request via cURL
*
* @return SiftResponse
*/
public function send()
{
$curlUrl = $this->url;
if ($this->params) {
$queryString = http_build_query($this->params);
$separator = parse_url($curlUrl, PHP_URL_QUERY) ? '&' : '?';
$curlUrl .= $separator . $queryString;
}
// Mock the request if self::$mock exists
if (self::$mock) {
if (self::$mock['url'] == $curlUrl && self::$mock['method'] == $this->method) {
return self::$mock['response'];
}
return null;
}
// Open and configure curl connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $curlUrl);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
$headers = array('User-Agent: SiftScience/v' . $this->version . ' sift-php/' . Sift::VERSION);
if ($this->auth) {
curl_setopt($ch, CURLOPT_USERPWD, $this->auth);
}
// HTTP-method-specific configuration.
if ($this->method == self::POST) {
if (function_exists('json_encode')) {
$jsonString = json_encode($this->body);
} else {
require_once dirname(__FILE__) . '/Services_JSON-1.0.3/JSON.php';
$json = new Services_JSON();
$jsonString = $json->encodeUnsafe($this->body);
}
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
$headers += array('Content-Type: application/json', 'Content-Length: ' . strlen($jsonString));
} else {
if ($this->method == self::DELETE) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
}
}
// Send the request using curl and parse result
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close the curl connection
curl_close($ch);
return new SiftResponse($result, $httpStatusCode, $this);
}
示例11: addAction
public function addAction()
{
$request = $this->getRequest();
if ($request->isPost()) {
$type = strtolower($request->getPost('type'));
switch ($type) {
case 'ajax':
$this->disableLayout();
$this->setNoRender();
$tagText = trim($request->getPost('tag_text'));
$tagText = $this->view->STRING->escape($tagText);
//$tagText = Gio_Core_String::stripTags($tagText, array('.'));
$response = array('status' => 'RESULT_NOT_OK', 'tag_text' => null, 'tag_id' => null);
$json = new Services_JSON();
if ($tagText) {
if (Modules_Tag_Services_Tag::checkExist($tagText)) {
$response['status'] = 'RESULT_EXIST';
} else {
$tag = array('tag_text' => $tagText, 'slug' => Gio_Core_String::removeSign($tagText, '-', true), 'created_date' => date('Y-m-d H:i:s'));
$tagId = Modules_Tag_Services_Tag::add($tag);
$response['status'] = 'RESULT_OK';
$response['tag_text'] = $tagText;
$response['tag_id'] = $tagId;
}
}
$this->getResponse()->setBody($json->encodeUnsafe($response));
return;
break;
default:
$tagData = $request->getPost('tag');
$tagData = Modules_Tag_Services_Tag::validate($tagData);
if (isset($tagData['messages_error']) && $tagData['messages_error']) {
$this->view->errorMessages = $tagData['messages'];
$this->view->tagData = $tagData;
return;
}
if (Modules_Tag_Services_Tag::checkExist($tagData['tag_text'])) {
$this->view->tagData = $tagData;
$this->view->existMessage = true;
return;
}
$tag = array('tag_text' => $this->view->STRING->escape($tagData['tag_text']), 'slug' => $tagData['slug'], 'created_date' => date('Y-m-d H:i:s'));
$tagId = Modules_Tag_Services_Tag::add($tag);
Gio_Core_Messenger::getInstance()->addMessage($this->view->TRANSLATOR->translator('tag_actions_add_success'));
$this->redirect($this->view->url('tag_tag_add'));
break;
}
}
}
示例12: moduleSelect
public static function moduleSelect($attributes = array())
{
$json = new Services_JSON();
$view = Gio_Core_View::getInstance();
$selectedId = isset($attributes['selected']) ? $attributes['selected'] : null;
$disableId = isset($attributes['disable']) ? $attributes['disable'] : null;
$elementDisabled = isset($attributes['disabled']) && $attributes['disabled'] === true ? ' disabled="disabled"' : '';
$output = sprintf("<select name='%s' id='%s' viewHelperClass='%s' viewHelperAttributes='%s'%s>", $attributes['name'], $attributes['id'], 'Modules_Core_Services_Module', $json->encodeUnsafe($attributes), $elementDisabled) . self::EOL . '<option value="">---</option>' . self::EOL;
$modules = self::getModulesInstalled();
foreach ($modules as $module) {
$selected = $selectedId == null || $selectedId != $module['module_id'] ? '' : ' selected="selected"';
$disable = $disableId == null || $disableId != $module['module_id'] ? '' : ' disabled';
$output .= sprintf('<option value="%s"%s%s>%s</option>', $module['module_id'], $selected, $disable, $view->TRANSLATOR->translator('about_' . $module['description'] . '_title', $module['module_id'])) . self::EOL;
}
$output .= '</select>' . self::EOL;
return $output;
}
示例13: showAction
public function showAction()
{
$perPage = $this->getParam('limit', 10);
$this->view->limit = $perPage;
$pageIndex = $this->getParam('pageIndex', 1);
$offset = ($pageIndex - 1) * $perPage;
$request = Gio_Core_Request::getInstance();
$json = new Services_JSON();
$params = $request->getParams();
$paramString = base64_encode($json->encodeUnsafe($params));
$this->view->paramString = $paramString;
/**
* Get comments by paramString
*/
$numComments = Modules_Comment_Services_Comment::countThreadComments($paramString, 'active');
$comments = Modules_Comment_Services_Comment::getThreadComments($offset, $perPage, $paramString, 'active');
$this->view->comments = $comments;
$this->view->numComments = $numComments;
// Pager
require_once LIB_DIR . DS . 'PEAR' . DS . 'Pager' . DS . 'Sliding.php';
$pagerOptions = array('mode' => 'Sliding', 'append' => false, 'perPage' => $perPage, 'delta' => 3, 'urlVar' => 'page', 'path' => '', 'fileName' => 'javascript: Comment.Widgets.Comment.loadComments(%d)', 'separator' => '', 'nextImg' => '<small class="icon arrow_right"></small>', 'prevImg' => '<small class="icon arrow_left"></small>', 'altNext' => '', 'altPrev' => '', 'altPage' => '', 'totalItems' => $numComments, 'currentPage' => $pageIndex, 'urlSeparator' => '/', 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 0, 'curPageSpanPre' => '<a href="javascript: void();" class="current">', 'curPageSpanPost' => '</a>');
$pager = new Pager_Sliding($pagerOptions);
$this->view->pager = $pager;
}
示例14:
function json_encode($string)
{
global $wp_json;
if (!is_a($wp_json, 'Services_JSON')) {
require_once 'class-json.php';
$wp_json = new Services_JSON();
}
return $wp_json->encodeUnsafe($string);
}
示例15:
function json_encode($content)
{
require_once 'JSON.php';
$json = new Services_JSON();
return $json->encodeUnsafe($content);
}