本文整理汇总了PHP中Safe::json_encode方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::json_encode方法的具体用法?PHP Safe::json_encode怎么用?PHP Safe::json_encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Safe
的用法示例。
在下文中一共展示了Safe::json_encode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export_response
/**
* build a response on server side
*
* [php]
* $result = $codec->export_response($values, $service);
* if(!$result[0])
* echo $result[1]; // print error code
* else
* ... // send data from $result[1] to the web client
* [/php]
*
* @param mixed transmitted values, if any
* @param string name of the remote service, if any
* @return an array of which the first value indicates call success or failure
*/
function export_response($values = NULL, $service = NULL)
{
// a structured response
$response = array();
$response['result'] = $values;
$response['error'] = NULL;
if (empty($values['id'])) {
$response['id'] = NULL;
} else {
$response['id'] = $values['id'];
unset($response['result']['id']);
}
// encode it and deliver the outcome
if ($encoded = Safe::json_encode($response)) {
return array(TRUE, $encoded);
}
return array(FALSE, 'No way to encode the request');
}
示例2: register_shutdown_function
register_shutdown_function('on_shutdown');
}
// else wait for some update --on time out, browser will recall us anyway
$response =& Comments::pull($anchor->get_reference(), isset($_REQUEST['timestamp']) ? gmstrftime('%Y-%m-%d %H:%M:%S', $_REQUEST['timestamp']) : 0);
// shutdown is not an error anymore
$pending = FALSE;
// ensure that the conversation is on-going
$status = 'started';
if ($anchor->get_value('locked') == 'Y') {
$status = 'stopped';
} else {
$fields = array();
$fields['id'] = $anchor->get_value('id');
$fields['overlay'] = $anchor->get_value('overlay');
if ($overlay = Overlay::load($fields, $anchor->get_reference())) {
$status = $overlay->get_value('status', 'started');
}
}
// provide page status
$response['status'] = $status;
// encode result in JSON
$output = Safe::json_encode($response);
// allow for data compression
render_raw('application/json; charset=' . $context['charset']);
// actual transmission except on a HEAD request
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
echo $output;
}
// the post-processing hook, then exit
finalize_page(TRUE);
}
示例3: get_start_url
/**
* the URL to start and to join the meeting
*
* @see overlays/events/start.php
*
* @return string the URL to redirect the user to the meeting, or NULL on error
*/
function get_start_url()
{
global $context;
// almost random passwords
$this->initialize_passwords();
// link to authenticate
$url = 'https://my.dimdim.com/api/auth/login';
// parameters to authenticate
$parameters = array();
$parameters['account'] = $this->attributes['account'];
$parameters['password'] = $this->attributes['password'];
$parameters['group'] = 'all';
// encode in json
$data = array('request' => Safe::json_encode($parameters));
// do authenticate
if ($response = http::proceed($url, '', $data)) {
// successful authentication
$output = Safe::json_decode($response);
if (isset($output['result']) && $output['result']) {
// remember the authentication token
$fields = array('token' => $output['response']['authToken']);
$this->set_values($fields);
// link to create a meeting
$url = 'https://my.dimdim.com/api/conf/start_meeting';
// provide authentication token
$headers = 'X-Dimdim-Auth-Token: ' . $this->attributes['token'] . CRLF;
// parameters to create a meeting
$parameters = array();
$parameters['authToken'] = $this->attributes['token'];
$parameters['account'] = $this->attributes['account'];
$parameters['clientId'] = Surfer::get_id();
$parameters['displayName'] = Surfer::get_name();
$parameters['meetingName'] = $this->anchor->get_title();
$parameters['roomName'] = $this->anchor->get_title();
$parameters['meetingLengthMinutes'] = $this->attributes['duration'];
$parameters['attendeeKey'] = $this->attendee_password;
$parameters['assistantEnabled'] = 'false';
// disable some features
$parameters['displayDialInfo'] = 'false';
// message displayed within the BigBlueButton session
$welcome = '';
// meeting title
if (is_object($this->anchor)) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Title'), $this->anchor->get_title()) . "\n";
}
// meeting date
if (isset($this->attributes['date_stamp'])) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Date'), Skin::build_date($this->attributes['date_stamp'], 'standalone')) . "\n";
}
// meeting duration
if (isset($this->attributes['duration'])) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Duration'), $this->attributes['duration'] . ' ' . i18n::s('minutes')) . "\n";
}
// build a link to the owner page, if any
if (is_object($this->anchor) && ($user = Users::get($this->anchor->get_value('owner_id')))) {
$welcome .= sprintf(i18n::s('%s: %s'), i18n::s('Chairman'), $user['full_name']) . "\n";
}
// welcome message
$parameters['agenda'] = $welcome;
// return URL
if (is_callable(array($this->anchor, 'get_url'))) {
$parameters['returnurl'] = $context['url_to_home'] . $context['url_to_root'] . $this->anchor->get_url();
}
// encode in json
$data = array('request' => Safe::json_encode($parameters));
// do the transaction
if ($response = http::proceed($url, $headers, $data)) {
// successful transaction
$output = Safe::json_decode($response);
if (isset($output['result']) && $output['result']) {
// redirect to the target page
return 'https://my.dimdim.com/redirect?clientId=' . urlencode(Surfer::get_id()) . '&account=' . urlencode($this->attributes['account']);
}
}
}
}
// don't know where to go
return NULL;
}
示例4: unset
$response['id'] = NULL;
} else {
$response['id'] = $parameters['id'];
}
// do not reply if the sender has sent a notification, and if there is no error
if ($response['id'] == NULL && $response['error'] == NULL) {
$response = '';
} else {
// JSON-RPC 2.0 requires either some result, or an error, but not both
if (isset($response['jsonrpc'])) {
if ($response['error'] == NULL) {
unset($response['error']);
} else {
unset($response['result']);
}
}
// encode the response
$response = Safe::json_encode($response);
// save the response if debug mode
if (isset($context['debug_rpc']) && $context['debug_rpc'] == 'Y') {
Logger::remember('services/json_rpc.php: json_rpc response', $response, 'debug');
}
}
// handle the output correctly
render_raw('application/json; charset=' . $context['charset']);
// actual transmission except on a HEAD request
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
echo $response;
}
// the post-processing hook
finalize_page();
示例5: substr
break;
}
}
// to be returned to caller
$response['session_id'] = substr($data, $head, $tail - $head);
// prepare the authentication token
$credentials = 'session_id=' . $response['session_id'] . '&create_time=' . time() . '&role=publisher' . '&nonce=' . microtime(true) . mt_rand();
// hash credentials using secret
$hash = hash_hmac('sha1', $credentials, $context['opentok_api_secret']);
// finalize the authentication token expected by OpenTok
$response['token'] = 'T1==' . base64_encode('partner_id=' . $context['opentok_api_key'] . '&sig=' . $hash . ':' . $credentials);
// handle the output correctly
render_raw('application/json; charset=' . $context['charset']);
// actual transmission except on a HEAD request
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
echo Safe::json_encode($response);
}
// the post-processing hook
finalize_page();
return;
}
// some error has occured
Safe::header('Status: 400 Bad Request', TRUE, 400);
die(Logger::error_pop());
// manage the OpenTok session
} else {
// leverage URL rewriting if possible
switch ($context['with_friendly_urls']) {
case 'Y':
$link = $context['url_to_home'] . $context['url_to_root'] . 'faceme.php/';
break;
示例6: get_login_url
/**
* package credentials to be passed in a link
*
* @param string action (e.g., 'visit', see users/login.php)
* @param string reference to target (e.g., 'section:123')
* @param string name or e-mail address
* @param string salt to be used for the hash
* @return string the link to be authenticated
*/
public static function get_login_url($command, $reference, $name, $salt)
{
global $context;
// build a signed
$credentials = array();
$credentials[0] = $command;
$credentials[1] = $reference;
$credentials[2] = $name;
$credentials[3] = sprintf('%u', crc32($command . ':' . $reference . ':' . $name . ':' . $salt));
// we prefer JSON over PHP serialization
if (!($serialized = Safe::json_encode($credentials))) {
$serialized = serialize($credentials);
}
// finalize the snippet
$id = base64_encode($serialized);
// be cool with search engines
if ($context['with_friendly_urls'] == 'Y') {
return 'users/login.php/' . rawurlencode($id);
} elseif ($context['with_friendly_urls'] == 'R') {
return 'users/login.php/' . rawurlencode($id);
} else {
return 'users/login.php?credentials=' . urlencode($id);
}
}