本文整理汇总了PHP中cf_json_encode函数的典型用法代码示例。如果您正苦于以下问题:PHP cf_json_encode函数的具体用法?PHP cf_json_encode怎么用?PHP cf_json_encode使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cf_json_encode函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dsq_sso
function dsq_sso()
{
if ($key = get_option('disqus_partner_key')) {
// use old style SSO
$new = false;
} elseif (($key = get_option('disqus_secret_key')) && ($public = get_option('disqus_public_key'))) {
// use new style SSO
$new = true;
} else {
// sso is not configured
return array();
}
global $current_user, $dsq_api;
get_currentuserinfo();
if ($current_user->ID) {
$avatar_tag = get_avatar($current_user->ID);
$avatar_data = array();
preg_match('/(src)=((\'|")[^(\'|")]*(\'|"))/i', $avatar_tag, $avatar_data);
$avatar = str_replace(array('"', "'"), '', $avatar_data[2]);
$user_data = array('username' => $current_user->display_name, 'id' => $current_user->ID, 'avatar' => $avatar, 'email' => $current_user->user_email, 'url' => $current_user->user_url);
} else {
$user_data = array();
}
$user_data = base64_encode(cf_json_encode($user_data));
$time = time();
$hmac = dsq_hmacsha1($user_data . ' ' . $time, $key);
$payload = $user_data . ' ' . $hmac . ' ' . $time;
if ($new) {
return array('remote_auth_s3' => $payload, 'api_key' => $public);
} else {
return array('remote_auth_s2' => $payload);
}
}
示例2: cf_json_encode
'excerpt': <?php
echo cf_json_encode(str_replace(array("\r\n", "\n", "\r"), '<br />', get_comment_excerpt()));
?>
,
'type': <?php
echo cf_json_encode($comment_type);
?>
}
<?php
$count++;
}
}
?>
],
'trackback_url': <?php
echo cf_json_encode(get_trackback_url());
?>
};
/* ]]> */
</script>
<script type="text/javascript">
/* <![CDATA[ */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.' + disqus_domain + '/embed.js?pname=wordpress&pver=<?php
echo DISQUS_VERSION;
?>
';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
示例3: dsq_sso
function dsq_sso()
{
if (!($partner_key = get_option('disqus_partner_key'))) {
return;
}
global $current_user, $dsq_api;
get_currentuserinfo();
if ($current_user->ID) {
$avatar_tag = get_avatar($current_user->ID);
$avatar_data = array();
preg_match('/(src)=((\'|")[^(\'|")]*(\'|"))/i', $avatar_tag, $avatar_data);
$avatar = str_replace(array('"', "'"), '', $avatar_data[2]);
$user_data = array('username' => $current_user->display_name, 'id' => $current_user->ID, 'avatar' => $avatar, 'email' => $current_user->user_email);
} else {
$user_data = array();
}
$user_data = base64_encode(cf_json_encode($user_data));
$time = time();
$hmac = dsq_hmacsha1($user_data . ' ' . $time, $partner_key);
$payload = $user_data . ' ' . $hmac . ' ' . $time;
echo '<script type="text/javascript" src="http://' . $dsq_api->short_name . '.disqus.com/remote_auth.js?remote_auth_s2=' . urlencode($payload) . '"></script>';
}
示例4: get_permalink
<script type="text/javascript">
var disqus_url = '<?php
echo get_permalink();
?>
';
var disqus_identifier = '<?php
echo dsq_identifier_for_post($post);
?>
';
var disqus_container_id = 'disqus_thread';
var disqus_shortname = '<?php
echo strtolower(get_option('disqus_forum_url'));
?>
';
var disqus_title = <?php
echo cf_json_encode(dsq_title_for_post($post));
?>
;
var disqus_config_custom = window.disqus_config;
var disqus_config = function () {
/*
All currently supported events:
onReady: fires when everything is ready,
onNewComment: fires when a new comment is posted,
onIdentify: fires when user is authenticated
*/
<?php
$sso = dsq_sso();
if ($sso) {
foreach ($sso as $k => $v) {
示例5: a360_request_handler
function a360_request_handler()
{
if (!empty($_GET['a360_action'])) {
switch ($_GET['a360_action']) {
case 'admin_js':
a360_admin_js();
break;
case 'admin_css_ie':
header('Content-type: text/css');
require 'css/a360-ie.css';
die;
break;
case 'admin_css':
header('Content-type: text/css');
require 'css/datePicker.css';
require 'css/a360.css';
die;
break;
case 'capture_ga_token':
if (!current_user_can('manage_options')) {
wp_die(__('You are not allowed to do that.', 'analytics360'));
}
$args = array();
parse_str($_SERVER['QUERY_STRING'], $args);
$token = NULL;
if (isset($args['token'])) {
$ch = curl_init('https://www.google.com/accounts/AuthSubSessionToken');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $args['token'] . '"'));
$result = curl_exec($ch);
$matches = array();
$found = preg_match('/Token=(.*)/', $result, $matches);
if ($found) {
$token = $matches[1];
$result = update_option('a360_ga_token', $token);
}
}
if (!$token) {
$q = http_build_query(array('a360_error' => 'Authentication with Google did not succeed. Please try again.'));
} else {
delete_option('a360_ga_profile_id');
$q = http_build_query(array('updated' => true));
}
wp_redirect(trailingslashit(get_bloginfo('wpurl')) . 'wp-admin/options-general.php?page=' . basename(__FILE__) . '&' . $q);
break;
case 'get_wp_posts':
add_filter('posts_where', create_function('$where', 'return $where." AND post_date >= \'' . $_GET['start_date'] . '\' AND post_date < \'' . $_GET['end_date'] . '\'";'));
$results = query_posts('post_status=publish&posts_per_page=999');
header('Content-type: text/javascript');
die(cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false)));
break;
case 'get_mc_data':
global $a360_api_key;
if (!class_exists('MCAPI')) {
include_once ABSPATH . PLUGINDIR . '/analytics360/php/MCAPI.class.php';
}
$api = new MCAPI($a360_api_key);
switch ($_GET['data_type']) {
case 'campaigns':
$results = $api->campaigns(array('sendtime_start' => $_GET['start_date'], 'end_start' => $_GET['end_date']));
if ($results) {
die(cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false)));
} else {
die(cf_json_encode(array('success' => false, 'error' => $api->errorMessage)));
}
break;
case 'list_growth':
$results = $api->listGrowthHistory($_GET['list_id']);
if ($results) {
die(cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false)));
} else {
die(cf_json_encode(array('success' => false, 'error' => $api->errorMessage)));
}
break;
}
break;
case 'get_ga_data':
global $a360_ga_token, $a360_ga_profile_id;
$parameters = array('start-date' => $_GET['start_date'], 'end-date' => $_GET['end_date'], 'sort' => 'ga:date', 'ids' => 'ga:' . $a360_ga_profile_id);
// split up top referrals by filtering on each medium in turn
if ($_GET['data_type'] == 'top_referrals') {
$handles = array('referral' => null, 'organic' => null, 'email' => null, 'cpc' => null, '*' => null);
$parameters['dimensions'] = 'ga:medium,ga:source';
$parameters['metrics'] = 'ga:visits,ga:timeOnSite,ga:pageviews';
$parameters['sort'] = '-ga:visits';
foreach ($handles as $filter => $handle) {
$p = $filter == '*' ? array('max-results' => 200) : array('filters' => 'ga:medium==' . $filter, 'max-results' => 200);
$handles[$filter] = $handle = curl_init('https://www.google.com/analytics/feeds/data?' . http_build_query(array_merge($parameters, $p)));
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_TIMEOUT, 10);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, array('Authorization: AuthSub token="' . $a360_ga_token . '"'));
}
$mh = curl_multi_init();
foreach ($handles as $handle) {
curl_multi_add_handle($mh, $handle);
//.........这里部分代码省略.........
示例6: wp_register_script
}
if ( get_option('dsq_external_js') == '1' ) {
wp_register_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
wp_localize_script( 'dsq_embed_script', 'embedVars', $embed_vars );
wp_enqueue_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
}
else {
?>
<script type="text/javascript">
var disqus_url = '<?php echo get_permalink(); ?>';
var disqus_identifier = '<?php echo dsq_identifier_for_post($post); ?>';
var disqus_container_id = 'disqus_thread';
var disqus_shortname = '<?php echo strtolower(get_option('disqus_forum_url')); ?>';
var disqus_title = <?php echo cf_json_encode( dsq_title_for_post($post) ); ?>;
var disqus_config_custom = window.disqus_config;
var disqus_config = function () {
/*
All currently supported events:
onReady: fires when everything is ready,
onNewComment: fires when a new comment is posted,
onIdentify: fires when user is authenticated
*/
<?php
$sso = dsq_sso();
if ($sso) {
foreach ($sso as $k=>$v) {
echo 'this.page.' . esc_js($k) . ' = \'' . esc_js($v) . '\';';
echo "\n";
示例7: a360_request_handler
function a360_request_handler()
{
if (!empty($_GET['a360_action']) && current_user_can('manage_options')) {
switch ($_GET['a360_action']) {
case 'admin_js':
a360_admin_js();
break;
case 'admin_css_ie':
header('Content-type: text/css');
require 'css/a360-ie.css';
die;
break;
case 'admin_css':
header('Content-type: text/css');
require 'css/datePicker.css';
require 'css/a360.css';
die;
break;
case 'capture_ga_token':
$args = array();
parse_str($_SERVER['QUERY_STRING'], $args);
$token = NULL;
if (isset($args['token'])) {
$wp_http = a360_get_wp_http();
$request_args = array('method' => 'GET', 'headers' => a360_get_authsub_headers($args['token']), 'sslverify' => false);
$response = $wp_http->request('https://www.google.com/accounts/AuthSubSessionToken', $request_args);
$error_messages = array();
if (is_wp_error($response)) {
// couldn't connect
$error_messages = $response->get_error_messages();
} else {
if (is_array($response)) {
$matches = array();
$found = preg_match('/Token=(.*)/', $response['body'], $matches);
if ($found) {
$token = $matches[1];
$result = update_option('a360_ga_token', $token);
} else {
// connected, but no token in response.
$error_messages = array($repsonse['body']);
}
}
}
}
if (!$token) {
if (count($error_messages)) {
$capture_errors .= implode("\n", $error_messages);
} else {
$capture_errors = 'unknown error';
}
$q = build_query(array('a360_ga_token_capture_errors' => $capture_errors), '', '&');
} else {
delete_option('a360_ga_profile_id');
$q = build_query(array('updated' => true), '', '&');
}
wp_redirect(site_url('wp-admin/options-general.php?page=' . basename(__FILE__) . '&' . $q));
break;
case 'get_wp_posts':
$start = preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_GET['start_date']) ? $_GET['start_date'] : '0000-00-00';
$end = preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $_GET['end_date']) ? $_GET['end_date'] : '0000-00-00';
add_filter('posts_where', create_function('$where', 'return $where." AND post_date >= \'' . $start . '\' AND post_date < \'' . $end . '\'";'));
$results = query_posts('post_status=publish&posts_per_page=999');
header('Content-type: text/javascript');
die(cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false)));
break;
case 'get_mc_data':
global $a360_api_key;
$api = a360_get_mcapi($a360_api_key);
switch ($_GET['data_type']) {
case 'campaigns':
$results = $api->campaigns(array('sendtime_start' => $_GET['start_date'], 'end_start' => $_GET['end_date']));
if ($results) {
die(cf_json_encode(array('success' => true, 'data' => $results['data'], 'cached' => false)));
} else {
if (empty($api->errorCode)) {
die(cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false)));
} else {
die(cf_json_encode(array('success' => false, 'error' => $api->errorMessage)));
}
}
break;
case 'list_growth':
$results = $api->listGrowthHistory($_GET['list_id']);
if ($results) {
die(cf_json_encode(array('success' => true, 'data' => $results, 'cached' => false)));
} else {
die(cf_json_encode(array('success' => false, 'error' => $api->errorMessage)));
}
break;
}
break;
case 'get_ga_data':
global $a360_ga_token, $a360_ga_profile_id;
$parameters = array('start-date' => $_GET['start_date'], 'end-date' => $_GET['end_date'], 'sort' => 'ga:date', 'ids' => 'ga:' . $a360_ga_profile_id);
// split up top referrals by filtering on each medium in turn
if ($_GET['data_type'] == 'top_referrals') {
$requests = array('referral' => null, 'organic' => null, 'email' => null, 'cpc' => null, '*' => null);
$parameters['dimensions'] = 'ga:medium,ga:source';
$parameters['metrics'] = 'ga:visits,ga:timeOnSite,ga:pageviews';
$parameters['sort'] = '-ga:visits';
//.........这里部分代码省略.........
示例8: mt_dsq_get_sso
function mt_dsq_get_sso($user, $key)
{
if ($user) {
$user_data = array('username' => $user["author_nickname"], 'id' => $user["author_id"], 'email' => $user["author_email"], 'url' => $user["author_url"], 'avatar' => mt_dsq_get_avatar_url($user));
} else {
$user_data = array();
}
$user_data = base64_encode(cf_json_encode($user_data));
$time = time();
$hmac = dsq_hmacsha1($user_data . ' ' . $time, $key);
$payload = "{$user_data} {$hmac} {$time}";
return $payload;
}