本文整理汇总了PHP中OAuthRequest::generate_raw_timestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP OAuthRequest::generate_raw_timestamp方法的具体用法?PHP OAuthRequest::generate_raw_timestamp怎么用?PHP OAuthRequest::generate_raw_timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OAuthRequest
的用法示例。
在下文中一共展示了OAuthRequest::generate_raw_timestamp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle_twitter_login
/**
* Login or create a new user using whatever data we get from Twitter.
*/
function handle_twitter_login()
{
header("Content-type: application/json");
$resp = array("status" => 0);
$secret = @$_POST['secret'];
$data_str = @$_POST['data'];
$data_str = '?' == substr($data_str, 0, 1) ? substr($data_str, 1) : $data_str;
$data = array();
parse_str($data_str, $data);
if (!$data) {
die(json_encode($resp));
}
$twitter = $this->_get_twitter_object($data['oauth_token'], $secret);
/* --- Start delta time correction --- */
if (method_exists('OAuthRequest', 'generate_raw_timestamp')) {
$test_time = OAuthRequest::generate_raw_timestamp();
$test_url = "https://api.twitter.com/1/help/test.json";
$request = wp_remote_get($test_url, array('sslverify' => false));
$headers = wp_remote_retrieve_headers($request);
if (!empty($headers['date'])) {
$twitter_time = strtotime($headers['date']);
$delta = $twitter_time - $test_time;
if (abs($delta) > EAB_OAUTH_TIMESTAMP_DELTA_THRESHOLD) {
add_action('eab-oauth-twitter-generate_timestamp', create_function('$time', 'return $time + ' . $delta . ';'));
}
}
}
/* --- End delta time correction --- */
$access = $twitter->getAccessToken($data['oauth_verifier']);
$twitter = $this->_get_twitter_object($access['oauth_token'], $access['oauth_token_secret']);
$tw_user = $twitter->get('account/verify_credentials');
// Have user, now register him/her
$domain = preg_replace('/www\\./', '', parse_url(site_url(), PHP_URL_HOST));
$username = preg_replace('/[^_0-9a-z]/i', '_', strtolower($tw_user->name));
$email = $username . '@twitter.' . $domain;
//STUB email
$wordp_user = get_user_by('email', $email);
if (!$wordp_user) {
// Not an existing user, let's create a new one
$password = wp_generate_password(12, false);
$count = 0;
while (username_exists($username)) {
$username .= rand(0, 9);
if (++$count > 10) {
break;
}
}
$wordp_user = wp_create_user($username, $password, $email);
if (is_wp_error($wordp_user)) {
die(json_encode($resp));
} else {
list($first_name, $last_name) = explode(' ', @$tw_user->name, 2);
update_user_meta($wordp_user, 'first_name', $first_name);
update_user_meta($wordp_user, 'last_name', $last_name);
}
} else {
$wordp_user = $wordp_user->ID;
}
update_user_meta($wordp_user, '_eab_tw', array('id' => $tw_user->id, 'avatar' => $tw_user->profile_image_url, 'token' => $access));
do_action('eab-user_logged_in-twitter', $wordp_user, $tw_user->id, $tw_user->profile_image_url, $access);
$user = get_userdata($wordp_user);
wp_set_current_user($user->ID, $user->user_login);
wp_set_auth_cookie($user->ID);
// Logged in with Twitter, yay
do_action('wp_login', $user->user_login);
die(json_encode(array("status" => 1)));
}