示例#1
0
function premise_get_social_share_twitter_share_url($postId = null)
{
    $base = 'https://twitter.com/share/';
    $args = array('url' => urlencode(get_permalink($postId)), 'text' => urlencode(premise_get_social_share_twitter_text()));
    return apply_filters('premise_get_social_share_twitter_share_url', add_query_arg($args, $base), $postId);
}
示例#2
0
 function authorize_facebook($postId)
 {
     global $premise_base;
     $data = stripslashes_deep($_REQUEST);
     $code = isset($data['code']) ? $data['code'] : false;
     $permalink = get_permalink($postId);
     if (!$code) {
         self::redirect($permalink);
     }
     $settings = $premise_base->get_settings();
     $key = $secret = '';
     if (isset($settings['sharing']['facebook-app-id']) && isset($settings['sharing']['facebook-app-secret'])) {
         $key = $settings['sharing']['facebook-app-id'];
         $secret = $settings['sharing']['facebook-app-secret'];
     }
     $callbackUrl = add_query_arg(array('social-share-ID' => $postId, 'facebook-oauth-callback' => 1), $permalink);
     $accessUrl = 'https://graph.facebook.com/oauth/access_token';
     $accessUrl = add_query_arg(array('client_id' => $key, 'redirect_uri' => urlencode($callbackUrl), 'client_secret' => $secret, 'code' => $code), $accessUrl);
     $response = wp_remote_get($accessUrl, array('sslverify' => false));
     if (is_wp_error($response)) {
         self::redirect($permalink);
     }
     $body = wp_remote_retrieve_body($response);
     $httpCode = wp_remote_retrieve_response_code($response);
     if ($httpCode == 400) {
         self::redirect($permalink);
     }
     $params = null;
     parse_str($body, $params);
     $accessToken = $params['access_token'];
     $postArguments = array('access_token' => $accessToken, 'name' => get_the_title($postId), 'message' => premise_get_social_share_twitter_text($postId), 'link' => $permalink, 'privacy' => json_encode(array('value' => 'EVERYONE')));
     $postResponse = wp_remote_post('https://graph.facebook.com/me/feed', array('body' => $postArguments, 'sslverify' => false));
     if (is_wp_error($postResponse)) {
         self::redirect($permalink);
     }
     $body = wp_remote_retrieve_body($postResponse);
     $postHttpCode = wp_remote_retrieve_response_code($postResponse);
     if (200 != $postHttpCode) {
         self::redirect($permalink);
     }
     $object = json_decode($body);
     if (isset($object->id)) {
         self::set_cookie($postId);
     }
     self::redirect($permalink);
 }