/** * Print to ajax the status of the last OAuth request. * * @static */ public static function check_oauth_authorization_status() { self::die_if_not_allowed(); check_ajax_referer('lp_check_oauth_nonce'); $options = get_option(self::$options_name); $livepress_com = new LivePress_Communication($options['api_key']); $status = $livepress_com->is_authorized_oauth(); if ($status->status == 'authorized') { $options['post_to_twitter'] = true; $options['oauth_authorized_user'] = $status->username; update_option(self::$options_name, $options); } else { if ($status->status == 'unauthorized') { $options['post_to_twitter'] = false; $options['oauth_authorized_user'] = ''; update_option(self::$options_name, $options); } } header('Content-Type: application/json'); echo json_encode($status); die; }
/** * Check if the request is from Facebook's Open Graph protocol. If * so then just return the basic HTML for embedding. The link to * share on Facebook should be: * http://host/permalink?lpup=[livepress_update_id] */ function opengraph_request() { if (isset($_GET['lpup'])) { $id = absint($_GET['lpup']); $update = $this->lp_get_single_update($id); $data = $this->opengraph_data($update); $post_parent_url = get_permalink($update->post_parent); if (0 === preg_match('/\\/\\?/', $post_parent_url)) { $post_parent_url .= "?"; } else { $post_parent_url .= "&"; } $canonical_url = $post_parent_url . 'lpup=' . $id . '#livepress-update-' . $id; echo "<!DOCTYPE HTML>\n"; echo "<html>\n"; echo "<head prefix=\"og: http://ogp.me/ns#\">\n"; echo "<link rel=\"canonical\" href=\"" . esc_url($canonical_url) . "\">\n"; echo "<title>" . esc_html($this->lp_strip_shortcodes($data->title)) . "</title>\n"; // Twitter card: // TODO: Make this customizable echo "<meta name=\"twitter:card\" content=\"summary_large_image\" />\n"; echo '<meta name="twitter:title" content="' . esc_attr($this->lp_strip_shortcodes(urldecode($data->title))) . "\" />\n"; echo '<meta name="twitter:description" content="' . esc_html($this->lp_strip_shortcodes(urldecode($data->description))) . "\" />\n"; echo '<meta name="twitter:image" content="' . esc_attr($data->img) . "\" />\n"; echo '<meta name="twitter:url" content="' . esc_url($canonical_url) . "\" />\n"; // Check if the update should be attributed to a Twitter user: $lp_twitter_user = get_user_meta($update->post_author, 'lp_twitter', true); if (!empty($lp_twitter_user)) { echo '<meta name="twitter:site:id" content="' . esc_attr($lp_twitter_user) . "\" />\n"; } // Check if we're posting updates to a Twitter account and use // it for twitter site handle: $this->options = get_option(LivePress_Administration::$options_name); $lp_com = new LivePress_Communication($this->options['api_key']); $lp_twitter_blog = $lp_com->is_authorized_oauth(); if (!empty($lp_twitter_blog) && $lp_twitter_blog->username !== NULL) { echo '<meta name="twitter:site" content=' . esc_attr($lp_twitter_blog->username) . "\" />\n"; } // Facebook Open Graph: echo '<meta property="og:title" content="' . esc_attr($this->lp_strip_shortcodes(urldecode($data->title))) . "\" />\n"; echo "<meta property=\"og:type\" content=\"" . esc_attr($data->type) . "\" />\n"; echo '<meta property="og:url" content="' . esc_url($canonical_url) . "\" />\n"; echo '<meta property="og:image" content="' . esc_attr($data->img) . "\" />\n"; echo '<meta property="og:image:url" content="' . esc_attr($data->img) . "\" />\n"; echo '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . "\" />\n"; echo '<meta property="og:description" content="' . esc_html($this->lp_strip_shortcodes(urldecode($data->description))) . "\" />\n"; $post_url = $post_parent_url . '#livepress-update-' . $id; echo "<meta http-equiv=\"refresh\" content=\"2;URL=" . $post_url . "\">\n"; echo "<script type=\"text/javascript\">window.location.replace('" . $post_url . "');</script>\n"; echo "</head>\n"; echo "<body>\n"; echo '<p>' . esc_html($data->description) . "</p>\n"; echo "</body>\n</html>\n"; exit(0); } }