get_option() public static méthode

Returns the requested option. Looks in jetpack_options or jetpack_$name as appropriate.
public static get_option ( string $name, mixed $default = false )
$name string Option name
$default mixed (optional)
 /**
  * Gets locally stored token
  *
  * @return object|false
  */
 public static function get_access_token($user_id = false)
 {
     if ($user_id) {
         if (!($tokens = Jetpack::get_option('user_tokens'))) {
             return false;
         }
         if ($user_id === JETPACK_MASTER_USER) {
             if (!($user_id = Jetpack::get_option('master_user'))) {
                 return false;
             }
         }
         if (!isset($tokens[$user_id]) || !($token = $tokens[$user_id])) {
             return false;
         }
         $token_chunks = explode('.', $token);
         if (empty($token_chunks[1]) || empty($token_chunks[2])) {
             return false;
         }
         if ($user_id != $token_chunks[2]) {
             return false;
         }
         $token = "{$token_chunks[0]}.{$token_chunks[1]}";
     } else {
         $token = Jetpack::get_option('blog_token');
         if (empty($token)) {
             return false;
         }
     }
     return (object) array('secret' => $token, 'external_user_id' => (int) $user_id);
 }
 /**
  * @return WP_Error|string secret_2 on success, WP_Error( error_code => error_code, error_message => error description, error_data => status code ) on failure
  *
  * Possible error_codes:
  *
  * verify_secret_1_missing
  * verify_secret_1_malformed
  * verify_secrets_missing: No longer have verification secrets stored
  * verify_secrets_mismatch: stored secret_1 does not match secret_1 sent by Jetpack.WordPress.com
  */
 function verify_action($params)
 {
     $action = $params[0];
     $verify_secret = $params[1];
     if (empty($verify_secret)) {
         return $this->error(new Jetpack_Error('verify_secret_1_missing', sprintf('The required "%s" parameter is missing.', 'secret_1'), 400));
     } else {
         if (!is_string($verify_secret)) {
             return $this->error(new Jetpack_Error('verify_secret_1_malformed', sprintf('The required "%s" parameter is malformed.', 'secret_1'), 400));
         }
     }
     $secrets = Jetpack::get_option($action);
     if (!$secrets || is_wp_error($secrets)) {
         Jetpack::delete_option($action);
         return $this->error(new Jetpack_Error('verify_secrets_missing', 'Verification took too long', 400));
     }
     @(list($secret_1, $secret_2, $secret_eol) = explode(':', $secrets));
     if (empty($secret_1) || empty($secret_2) || empty($secret_eol) || $secret_eol < time()) {
         Jetpack::delete_option($action);
         return $this->error(new Jetpack_Error('verify_secrets_missing', 'Verification took too long', 400));
     }
     if ($verify_secret !== $secret_1) {
         Jetpack::delete_option($action);
         return $this->error(new Jetpack_Error('verify_secrets_mismatch', 'Secret mismatch', 400));
     }
     Jetpack::delete_option($action);
     return $secret_2;
 }
/**
 * Executes an elasticsearch query via our REST API.
 *
 * Requires setup on our end and a paid addon to your hosting account.
 * You probably shouldn't be using this function. Questions? Ask us.
 *
 * Valid arguments:
 *
 * * size: Number of query results to return.
 *
 * * from: Offset, the starting result to return.
 *
 * * multi_match: Will do a match search against the default fields (this is almost certainly what you want).
 *                e.g. array( 'query' => 'this is a test', 'fields' => array( 'content' ) )
 *                See: http://www.elasticsearch.org/guide/reference/query-dsl/multi-match-query.html
 *
 * * query_string: Will do a query_string search, interprets the string as Lucene query syntax.
 *                 e.g. array( 'default_field' => 'content', 'query' => 'tag:(world OR nation) howdy' )
 *                 This can fail if the user doesn't close parenthesis, or specifies a field that is not valid.
 *                 See: http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html
 *
 * * more_like_this: Will do a more_like_this search, which is best for related content.
 *                   e.g. array( 'fields' => array( 'title', 'content' ), 'like_text' => 'this is a test', 'min_term_freq' => 1, 'max_query_terms' => 12 )
 *                   See: http://www.elasticsearch.org/guide/reference/query-dsl/mlt-query.html
 *
 * * facets: Structured set of facets. DO NOT do a terms facet on the content of posts/comments. It will load ALL terms into memory,
 *           probably taking minutes to complete and slowing down the entire cluster. With great power... etc.
 *           See: http://www.elasticsearch.org/guide/reference/api/search/facets/index.html
 *
 * * filter: Structured set of filters (often FASTER, since cached from one query to the next).
 *            See: http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query.html
 *
 * * highlight: Structure defining how to highlight the results.
 *              See: http://www.elasticsearch.org/guide/reference/api/search/highlighting.html
 *
 * * fields: Structure defining what fields to return with the results.
 *           See: http://www.elasticsearch.org/guide/reference/api/search/fields.html
 *
 * * sort: Structure defining how to sort the results.
 *         See: http://www.elasticsearch.org/guide/reference/api/search/sort.html
 *
 * @param array $args
 * @return bool|string False if WP_Error, otherwise JSON string
 */
function es_api_search_index($args)
{
    if (class_exists('Jetpack')) {
        $jetpack_blog_id = Jetpack::get_option('id');
        if (!$jetpack_blog_id) {
            return array('error' => 'Failed to get Jetpack blog_id');
        }
        $args['blog_id'] = $jetpack_blog_id;
    }
    $defaults = array('blog_id' => get_current_blog_id());
    $args = wp_parse_args($args, $defaults);
    $args['blog_id'] = absint($args['blog_id']);
    $service_url = 'http://public-api.wordpress.com/rest/v1/sites/' . $args['blog_id'] . '/search';
    unset($args['blog_id']);
    $request = wp_remote_post($service_url, array('headers' => array('Content-Type' => 'application/json'), 'body' => json_encode($args)));
    if (is_wp_error($request)) {
        return false;
    }
    $response = json_decode(wp_remote_retrieve_body($request), true);
    // Rewrite blog id from remote to local id
    if (isset($response['results']) && isset($response['results']['hits'])) {
        $local_blog_id = get_current_blog_id();
        foreach ($response['results']['hits'] as $key => $hit) {
            if (isset($hit['fields']['blog_id']) && $hit['fields']['blog_id'] == $jetpack_blog_id) {
                $response['results']['hits'][$key]['fields']['blog_id'] = $local_blog_id;
            }
        }
    }
    return $response;
}
function jetpack_enhanced_distribution_before_activate_default_modules()
{
    $old_version = Jetpack::get_option('old_version');
    list($old_version) = explode(':', $old_version);
    if (version_compare($old_version, '1.9-something', '>=')) {
        return;
    }
    Jetpack::check_privacy(__FILE__);
}
function wpme_get_shortlink($id = 0, $context = 'post', $allow_slugs = true)
{
    global $wp_query;
    $blog_id = Jetpack::get_option('id');
    if ('query' == $context) {
        if (is_singular()) {
            $id = $wp_query->get_queried_object_id();
            $context = 'post';
        } elseif (is_front_page()) {
            $context = 'blog';
        } else {
            return '';
        }
    }
    if ('blog' == $context) {
        if (empty($id)) {
            $id = $blog_id;
        }
        return 'http://wp.me/' . wpme_dec2sixtwo($id);
    }
    $post = get_post($id);
    if (empty($post)) {
        return '';
    }
    $post_id = $post->ID;
    $type = '';
    if ($allow_slugs && 'publish' == $post->post_status && 'post' == $post->post_type && strlen($post->post_name) <= 8 && false === strpos($post->post_name, '%') && false === strpos($post->post_name, '-')) {
        $id = $post->post_name;
        $type = 's';
    } else {
        $id = wpme_dec2sixtwo($post_id);
        if ('page' == $post->post_type) {
            $type = 'P';
        } elseif ('post' == $post->post_type) {
            $type = 'p';
        } elseif ('attachment' == $post->post_type) {
            $type = 'a';
        }
    }
    if (empty($type)) {
        return '';
    }
    return 'http://wp.me/' . $type . wpme_dec2sixtwo($blog_id) . '-' . $id;
}
 /**
  * @return object|WP_Error
  */
 function get_token($data)
 {
     $jetpack = Jetpack::init();
     $role = $jetpack->translate_current_user_to_role();
     if (!$role) {
         return new Jetpack_Error('role', __('An administrator for this blog must set up the Jetpack connection.', 'jetpack'));
     }
     $client_secret = Jetpack_Data::get_access_token(0);
     if (!$client_secret) {
         return new Jetpack_Error('client_secret', __('You need to register your Jetpack before connecting it.', 'jetpack'));
     }
     $body = array('client_id' => Jetpack::get_option('id'), 'client_secret' => $client_secret->secret, 'grant_type' => 'authorization_code', 'code' => $data['code'], 'redirect_uri' => add_query_arg(array('action' => 'authorize', '_wpnonce' => wp_create_nonce("jetpack-authorize_{$role}")), menu_page_url('jetpack', false)));
     $args = array('method' => 'POST', 'body' => $body, 'headers' => array('Accept' => 'application/json'));
     $response = Jetpack_Client::_wp_remote_request(Jetpack::fix_url_for_bad_hosts(Jetpack::api_url('token'), $args), $args);
     if (is_wp_error($response)) {
         return new Jetpack_Error('token_http_request_failed', $response->get_error_message());
     }
     $code = wp_remote_retrieve_response_code($response);
     $entity = wp_remote_retrieve_body($response);
     if ($entity) {
         $json = json_decode($entity);
     } else {
         $json = false;
     }
     if (200 != $code || !empty($json->error)) {
         if (empty($json->error)) {
             return new Jetpack_Error('unknown', '', $code);
         }
         $error_description = isset($json->error_description) ? sprintf(__('Error Details: %s', 'jetpack'), (string) $json->error_description) : '';
         return new Jetpack_Error((string) $json->error, $error_description, $code);
     }
     if (empty($json->access_token) || !is_scalar($json->access_token)) {
         return new Jetpack_Error('access_token', '', $code);
     }
     if (empty($json->token_type) || 'X_JETPACK' != strtoupper($json->token_type)) {
         return new Jetpack_Error('token_type', '', $code);
     }
     if (empty($json->scope)) {
         return new Jetpack_Error('scope', 'No Scope', $code);
     }
     @(list($role, $hmac) = explode(':', $json->scope));
     if (empty($role) || empty($hmac)) {
         return new Jetpack_Error('scope', 'Malformed Scope', $code);
     }
     if ($jetpack->sign_role($role) !== $json->scope) {
         return new Jetpack_Error('scope', 'Invalid Scope', $code);
     }
     if (!($cap = $jetpack->translate_role_to_cap($role))) {
         return new Jetpack_Error('scope', 'No Cap', $code);
     }
     if (!current_user_can($cap)) {
         return new Jetpack_Error('scope', 'current_user_cannot', $code);
     }
     return (string) $json->access_token;
 }
 public static function set_time_diff(&$response, $force_set = false)
 {
     $code = wp_remote_retrieve_response_code($response);
     // Only trust the Date header on some responses
     if (200 != $code && 304 != $code && 400 != $code && 401 != $code) {
         return;
     }
     if (!($date = wp_remote_retrieve_header($response, 'date'))) {
         return;
     }
     if (0 >= ($time = (int) strtotime($date))) {
         return;
     }
     $time_diff = $time - time();
     if ($force_set) {
         // during register
         Jetpack::update_option('time_diff', $time_diff);
     } else {
         // otherwise
         $old_diff = Jetpack::get_option('time_diff');
         if (false === $old_diff || abs($time_diff - (int) $old_diff) > 10) {
             Jetpack::update_option('time_diff', $time_diff);
         }
     }
 }
    function options_page_tumblr()
    {
        // Nonce check
        check_admin_referer('options_page_tumblr_' . $_REQUEST['connection']);
        $connected_services = Jetpack::get_option('publicize_connections');
        $connection = $connected_services['tumblr'][$_POST['connection']];
        $options_to_show = $connection['connection_data']['meta']['options_responses'];
        $request = $options_to_show[0];
        $blogs = $request['response']['user']['blogs'];
        $blog_selected = false;
        if (!empty($connection['connection_data']['meta']['tumblr_base_hostname'])) {
            foreach ($blogs as $blog) {
                if ($connection['connection_data']['meta']['tumblr_base_hostname'] == $this->get_basehostname($blog['url'])) {
                    $blog_selected = $connection['connection_data']['meta']['tumblr_base_hostname'];
                    break;
                }
            }
        }
        // Use their Primary blog if they haven't selected one yet
        if (!$blog_selected) {
            foreach ($blogs as $blog) {
                if ($blog['primary']) {
                    $blog_selected = $this->get_basehostname($blog['url']);
                }
            }
        }
        ?>

		<div id="thickbox-content">

			<?php 
        ob_start();
        Publicize_UI::connected_notice('Tumblr');
        $update_notice = ob_get_clean();
        if (!empty($update_notice)) {
            echo $update_notice;
        }
        ?>

			<p><?php 
        printf(esc_html__('Publicize to my %s:', 'jetpack'), '<strong>' . esc_html__('Tumblr blog', 'jetpack') . '</strong>');
        ?>
</p>

			<ul id="option-tumblr-blog">

			<?php 
        foreach ($blogs as $blog) {
            $url = $this->get_basehostname($blog['url']);
            ?>
				<li>
					<input type="radio" name="option" data-type="blog" id="<?php 
            echo esc_attr($url);
            ?>
" value="<?php 
            echo esc_attr($url);
            ?>
" <?php 
            checked($blog_selected == $url, true);
            ?>
 />
					<label for="<?php 
            echo esc_attr($url);
            ?>
"><span class="name"><?php 
            echo esc_html($blog['title']);
            ?>
</span></label>
				</li>
			<?php 
        }
        ?>

			</ul>

			<?php 
        Publicize_UI::global_checkbox('tumblr', $_REQUEST['connection']);
        ?>

			<p style="text-align: center;">
				<input type="submit" value="<?php 
        esc_attr_e('OK', 'jetpack');
        ?>
" class="button tumblr-options save-options" name="save" data-connection="<?php 
        echo esc_attr($_REQUEST['connection']);
        ?>
" rel="<?php 
        echo wp_create_nonce('save_tumblr_blog_' . $_REQUEST['connection']);
        ?>
" />
			</p> <br />
		</div>

		<?php 
    }
Exemple #9
0
 /**
  * Modify Infinite Scroll configuration information
  *
  * @uses Jetpack::get_active_modules, is_user_logged_in, stats_get_options, Jetpack::get_option, get_option, JETPACK__API_VERSION, JETPACK__VERSION
  * @filter infinite_scroll_js_settings
  * @return array
  */
 public function filter_infinite_scroll_js_settings($settings)
 {
     // Provide WP Stats info for tracking Infinite Scroll loads
     // Abort if Stats module isn't active
     if (in_array('stats', Jetpack::get_active_modules())) {
         // Abort if user is logged in but logged-in users shouldn't be tracked.
         if (is_user_logged_in()) {
             $stats_options = stats_get_options();
             $track_loggedin_users = isset($stats_options['reg_users']) ? (bool) $stats_options['reg_users'] : false;
             if (!$track_loggedin_users) {
                 return $settings;
             }
         }
         // We made it this far, so gather the data needed to track IS views
         $settings['stats'] = 'blog=' . Jetpack::get_option('id') . '&host=' . parse_url(get_option('home'), PHP_URL_HOST) . '&v=ext&j=' . JETPACK__API_VERSION . ':' . JETPACK__VERSION;
     }
     // Check if Google Analytics tracking is requested
     $settings['google_analytics'] = (bool) get_option($this->option_name_google_analytics);
     return $settings;
 }
Exemple #10
0
function jetpack_debug_menu_display_handler()
{
    if (!current_user_can('manage_options')) {
        wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'jetpack'));
    }
    global $current_user;
    get_currentuserinfo();
    $is_jetpack_support_open = is_jetpack_support_open();
    $self_xml_rpc_url = site_url('xmlrpc.php');
    $tests = array();
    $tests['HTTP'] = wp_remote_get('http://jetpack.wordpress.com/jetpack.test/1/');
    $tests['HTTPS'] = wp_remote_get('https://jetpack.wordpress.com/jetpack.test/1/');
    if (preg_match('/^https:/', $self_xml_rpc_url)) {
        $tests['SELF'] = wp_remote_get(preg_replace('/^https:/', 'http:', $self_xml_rpc_url));
        $tests['SELF-SEC'] = wp_remote_get($self_xml_rpc_url, array('sslverify' => true));
    } else {
        $tests['SELF'] = wp_remote_get($self_xml_rpc_url);
    }
    $user_id = get_current_user_id();
    $user_tokens = Jetpack::get_option('user_tokens');
    if (is_array($user_tokens) && array_key_exists($user_id, $user_tokens)) {
        $user_token = $user_tokens[$user_id];
    } else {
        $user_token = '[this user has no token]';
    }
    unset($user_tokens);
    $debug_info = "\r\n";
    foreach (array('CLIENT_ID' => 'id', 'BLOG_TOKEN' => 'blog_token', 'MASTER_USER' => 'master_user', 'CERT' => 'fallback_no_verify_ssl_certs', 'TIME_DIFF' => 'time_diff', 'VERSION' => 'version', 'OLD_VERSION' => 'old_version', 'PUBLIC' => 'public') as $label => $option_name) {
        $debug_info .= "\r\n" . esc_html($label . ": " . Jetpack::get_option($option_name));
    }
    $debug_info .= "\r\n" . esc_html("USER_ID: " . $user_id);
    $debug_info .= "\r\n" . esc_html("USER_TOKEN: " . $user_token);
    $debug_info .= "\r\n" . esc_html("PHP_VERSION: " . PHP_VERSION);
    $debug_info .= "\r\n" . esc_html("WORDPRESS_VERSION: " . $GLOBALS['wp_version']);
    $debug_info .= "\r\n" . esc_html("JETPACK__VERSION: " . JETPACK__VERSION);
    $debug_info .= "\r\n" . esc_html("JETPACK__PLUGIN_DIR: " . JETPACK__PLUGIN_DIR);
    $debug_info .= "\r\n" . esc_html("SITE_URL: " . site_url());
    $debug_info .= "\r\n" . esc_html("HOME_URL: " . home_url());
    $debug_info .= "\r\n\r\nTEST RESULTS:\r\n\r\n";
    $debug_raw_info = '';
    ?>

	<div class="wrap">
		<h2><?php 
    esc_html_e('Jetpack Debugging Center', 'jetpack');
    ?>
</h2>
		<h3><?php 
    _e("Tests your site's compatibily with Jetpack.", 'jetpack');
    ?>
</h3>
		<h3><?php 
    _e('Tests:', 'jetpack');
    ?>
</h3>
		<div class="jetpack-debug-test-container">
		<?php 
    foreach ($tests as $test_name => $test_result) {
        $result = '';
        if (is_wp_error($test_result)) {
            $test_class = 'jetpack-test-error';
            $offer_ticket_submission = true;
            $status = __('System Failure!', 'jetpack');
            $result = esc_html($test_result->get_error_message());
        } else {
            $response_code = wp_remote_retrieve_response_code($test_result);
            if (empty($response_code)) {
                $test_class = 'jetpack-test-error';
                $offer_ticket_submission = true;
                $status = __('Failed!', 'jetpack');
            } elseif ('200' == $response_code) {
                $test_class = 'jetpack-test-success';
                $status = __('Passed!', 'jetpack');
            } else {
                $test_class = 'jetpack-test-error';
                $offer_ticket_submission = true;
                $status = __('Failed!', 'jetpack');
            }
        }
        $debug_info .= $test_name . ': ' . $status . "\r\n";
        $debug_raw_info .= "\r\n\r\n" . $test_name . "\r\n" . esc_html(print_r($test_result, 1));
        ?>
			<div class="jetpack-test-results <?php 
        esc_html_e($test_class, 'jetpack');
        ?>
">
				<p>
					<a class="jetpack-test-heading" href="#"><?php 
        esc_html_e($test_name, 'jetpack');
        ?>
: <?php 
        esc_html_e($status, 'jetpack');
        ?>
					<span class="noticon noticon-collapse"></span>
					</a>
				</p>
				<pre class="jetpack-test-details"><?php 
        esc_html_e($result, 'jetpack');
        ?>
</pre>
			</div>
		<?php 
    }
    $debug_info .= "\r\n\r\nRAW TEST RESULTS:" . $debug_raw_info . "\r\n";
    ?>
		</div>
		<div class="entry-content">
			<h3><?php 
    esc_html_e('Trouble with Jetpack?', 'jetpack');
    ?>
</h3>
			<h4><?php 
    esc_html_e('It may be caused by one of these issues, which you can diagnose yourself:', 'jetpack');
    ?>
</h4>
			<ol>
				<li><b><em><?php 
    esc_html_e('A known issue.', 'jetpack');
    ?>
</em></b>  <?php 
    echo sprintf(__('Some themes and plugins have <a href="%1$s" target="_blank">known conflicts</a> with Jetpack – check the <a href="%2$s" target="_blank">list</a>. (You can also browse the <a href="%3$s">Jetpack support pages</a> or <a href="%4$s">Jetpack support forum</a> to see if others have experienced and solved the problem.)', 'jetpack'), 'http://jetpack.me/known-issues/', 'http://jetpack.me/known-issues/', 'http://jetpack.me/support/', 'http://wordpress.org/support/plugin/jetpack');
    ?>
</li>
				<li><b><em><?php 
    esc_html_e('An incompatible plugin.', 'jetpack');
    ?>
</em></b>  <?php 
    esc_html_e("Find out by disabling all plugins except Jetpack. If the problem persists, it's not a plugin issue. If the problem is solved, turn your plugins on one by one until the problem pops up again – there's the culprit! Let us know, and we'll try to help.", 'jetpack');
    ?>
</li>
				<li><b><em><?php 
    esc_html_e('A theme conflict.', 'jetpack');
    ?>
</em></b>  <?php 
    esc_html_e("If your problem isn't known or caused by a plugin, try activating Twenty Twelve (the default WordPress theme). If this solves the problem, something in your theme is probably broken – let the theme's author know.", 'jetpack');
    ?>
</li>
				<li><b><em><?php 
    esc_html_e('A problem with your XMLRPC file.', 'jetpack');
    ?>
</em></b>  <?php 
    echo sprintf(__('Load your <a href="%s">XMLRPC file</a>. It should say “XML-RPC server accepts POST requests only.” on a line by itself.', 'jetpack'), site_url('xmlrpc.php'));
    ?>
					<ul>
						<li>- <?php 
    esc_html_e("If it's not by itself, a theme or plugin is displaying extra characters. Try steps 2 and 3.", 'jetpack');
    ?>
</li>
						<li>- <?php 
    esc_html_e("If you get a 404 message, contact your web host. Their security may block XMLRPC.", 'jetpack');
    ?>
</li>
					</ul>
				</li>
			</ol>
			<p class="jetpack-show-contact-form"><?php 
    _e('If none of these help you find a solution, <a href="#">click here to contact Jetpack support</a>. Tell us as much as you can about the issue and what steps you\'ve tried to resolve it, and one of our Happiness Engineers will be in touch to help.', 'jetpack');
    ?>
 
			</p>
		</div>
		<div id="contact-message" style="display:none">
		<?php 
    if ($is_jetpack_support_open) {
        ?>
			<form id="contactme" method="post" action="http://jetpack.me/contact-support/">
				<input type="hidden" name="action" value="submit">
				<input type="hidden" name="jetpack" value="needs-service">
				
				<input type="hidden" name="contact_form" id="contact_form" value="1">
				<input type="hidden" name="blog_url" id="blog_url" value="<?php 
        echo esc_attr(site_url());
        ?>
">
				<input type="hidden" name="subject" id="subject" value="from: <?php 
        echo esc_attr(site_url());
        ?>
 Jetpack contact form">
				<div class="formbox">
					<label for="message" class="h"><?php 
        esc_html_e('Please describe the problem you are having.', 'jetpack');
        ?>
</label>
					<textarea name="message" cols="40" rows="7" id="did"></textarea>
				</div>
		
				<div id="name_div" class="formbox">
					<label class="h" for="your_name"><?php 
        esc_html_e('Name', 'jetpack');
        ?>
</label>
		  			<span class="errormsg"><?php 
        esc_html_e('Let us know your name.', 'jetpack');
        ?>
</span>
					<input name="your_name" type="text" id="your_name" value="<?php 
        esc_html_e($current_user->display_name, 'jetpack');
        ?>
" size="40">
				</div>
		
				<div id="email_div" class="formbox">
					<label class="h" for="your_email"><?php 
        esc_html_e('E-mail', 'jetpack');
        ?>
</label>
		  			<span class="errormsg"><?php 
        esc_html_e('Use a valid email address.', 'jetpack');
        ?>
</span>
					<input name="your_email" type="text" id="your_email" value="<?php 
        esc_html_e($current_user->user_email, 'jetpack');
        ?>
" size="40">
				</div>

				<div id="toggle_debug_info" class="formbox">
					<p><?php 
        _e('The test results and some other useful debug information will be sent to the support team. Please feel free to <a href="#">review/modify</a> this information.', 'jetpack');
        ?>
</p>
				</div>
				
				<div id="debug_info_div" class="formbox" style="display:none">
					<label class="h" for="debug_info"><?php 
        esc_html_e('Debug Info', 'jetpack');
        ?>
</label>
		  			<textarea name="debug_info" cols="40" rows="7" id="debug_info"><?php 
        echo esc_attr($debug_info);
        ?>
</textarea>
				</div>

				<div style="clear: both;"></div>
		
				<div id="blog_div" class="formbox">
					<div id="submit_div" class="contact-support">
					<input type="submit" name="submit" value="Contact Support">
					</div>
				</div>
				<div style="clear: both;"></div>
			</form>
		<?php 
    }
    ?>
		</div>
	</div>
<?php 
}
Exemple #11
0
 /**
  * Just a shortcut to the serialized Jetpack options.
  *
  * @param string $service The name of the service that we're looking for.
  * @param string $default The data to return if we've not got anything on file.
  * @returns string $link The social link that we've got, or the default if not.
  */
 private function get_link($service, $default = '')
 {
     $links = Jetpack::get_option('social_links', array());
     if (!empty($links[$service])) {
         return $links[$service];
     }
     return $default;
 }
Exemple #12
0
 public static function jumpstart_has_updated_module_option($option_name = '')
 {
     // Bail if Jump Start has already been dismissed
     if ('new_connection' !== Jetpack::get_option('jumpstart')) {
         return false;
     }
     $jetpack = Jetpack::init();
     // Manual build of module options
     $option_names = self::get_jetapck_options_for_reset();
     if (in_array($option_name, $option_names['wp_options'])) {
         Jetpack_Options::update_option('jumpstart', 'jetpack_action_taken');
         //Jump start is being dismissed send data to MC Stats
         $jetpack->stat('jumpstart', 'manual,' . $option_name);
         $jetpack->do_stats('server_side');
     }
 }
Exemple #13
0
function stats_get_csv($table, $args = null)
{
    $defaults = array('end' => false, 'days' => false, 'limit' => 3, 'post_id' => false, 'summarize' => '');
    $args = wp_parse_args($args, $defaults);
    $args['table'] = $table;
    $args['blog_id'] = Jetpack::get_option('id');
    $stats_csv_url = add_query_arg($args, 'http://stats.wordpress.com/csv.php');
    $key = md5($stats_csv_url);
    // Get cache
    $stats_cache = get_option('stats_cache');
    if (!$stats_cache || !is_array($stats_cache)) {
        $stats_cache = array();
    }
    // Return or expire this key
    if (isset($stats_cache[$key])) {
        $time = key($stats_cache[$key]);
        if (time() - $time < 300) {
            return $stats_cache[$key][$time];
        }
        unset($stats_cache[$key]);
    }
    $stats_rows = array();
    do {
        if (!($stats = stats_get_remote_csv($stats_csv_url))) {
            break;
        }
        $labels = array_shift($stats);
        if (0 === stripos($labels[0], 'error')) {
            break;
        }
        $stats_rows = array();
        for ($s = 0; isset($stats[$s]); $s++) {
            $row = array();
            foreach ($labels as $col => $label) {
                $row[$label] = $stats[$s][$col];
            }
            $stats_rows[] = $row;
        }
    } while (0);
    // Expire old keys
    foreach ($stats_cache as $k => $cache) {
        if (!is_array($cache) || 300 < time() - key($cache)) {
            unset($stats_cache[$k]);
        }
    }
    // Set cache
    $stats_cache[$key] = array(time() => $stats_rows);
    update_option('stats_cache', $stats_cache);
    return $stats_rows;
}
Exemple #14
0
 /**
  * Verify the hash included in remote comments.
  *
  * @since JetpackComments (1.4)
  * @param type $comment Not used
  */
 public function pre_comment_on_post($comment)
 {
     $post_array = stripslashes_deep($_POST);
     // Bail if missing the Jetpack token
     if (!isset($post_array['sig'])) {
         unset($_POST['hc_post_as']);
         return;
     }
     if (FALSE !== strpos($post_array['hc_avatar'], '.gravatar.com')) {
         $post_array['hc_avatar'] = htmlentities($post_array['hc_avatar']);
     }
     $check = Jetpack_Comments::sign_remote_comment_parameters($post_array, Jetpack::get_option('blog_token'));
     if (is_wp_error($check)) {
         wp_die($check);
     }
     // Bail if token is expired or not valid
     if ($check !== $post_array['sig']) {
         wp_die(__('Invalid security token.', 'jetpack'));
     }
 }
Exemple #15
0
 function initialize()
 {
     $this->token_details['blog_id'] = Jetpack::get_option('id');
 }
 public static function jetpack_site_icon_available_in_core()
 {
     global $wp_version;
     $core_icon_available = function_exists('has_site_icon') && version_compare($wp_version, '4.3-beta') >= 0;
     if (!$core_icon_available) {
         return false;
     }
     // No need for Jetpack's site icon anymore if core's is already set
     if (has_site_icon()) {
         if (Jetpack::is_module_active('site-icon')) {
             Jetpack::log('deactivate', 'site-icon');
             Jetpack::deactivate_module('site-icon');
         }
         return true;
     }
     // Transfer Jetpack's site icon to use core.
     $site_icon_id = Jetpack::get_option('site_icon_id');
     if ($site_icon_id) {
         // Update core's site icon
         update_option('site_icon', $site_icon_id);
         // Delete Jetpack's icon option. We still want the blavatar and attached data though.
         delete_option('site_icon_id');
     }
     // No need for Jetpack's site icon anymore
     if (Jetpack::is_module_active('site-icon')) {
         Jetpack::log('deactivate', 'site-icon');
         Jetpack::deactivate_module('site-icon');
     }
     return true;
 }
Exemple #17
0
 /**
  * Get jetpack blog id, or the jetpack blog id of the main blog in the main network
  *
  * @return int
  */
 public function get_main_blog_jetpack_id()
 {
     if (!is_main_site()) {
         switch_to_blog($this->get_main_blog_id());
         $id = Jetpack::get_option('id', false);
         restore_current_blog();
     } else {
         $id = Jetpack::get_option('id');
     }
     return $id;
 }
 public static function jumpstart_has_updated_module_option($option_name = '')
 {
     // Bail if Jump Start has already been dismissed
     if ('new_connection' !== Jetpack::get_option('jumpstart')) {
         return false;
     }
     $jetpack = Jetpack::init();
     // Manual build of module options
     $option_names = array('sharing-options', 'disabled_likes', 'disabled_reblogs', 'jetpack_comments_likes_enabled', 'wp_mobile_excerpt', 'wp_mobile_featured_images', 'wp_mobile_app_promos', 'stats_options', 'stats_dashboard_widget', 'safecss_preview_rev', 'safecss_rev', 'safecss_revision_migrated', 'nova_menu_order', 'jetpack_portfolio', 'jetpack_portfolio_posts_per_page', 'jetpack_testimonial', 'jetpack_testimonial_posts_per_page', 'wp_mobile_custom_css', 'sharedaddy_disable_resources', 'sharing-options', 'sharing-services', 'site_icon_temp_data', 'featured-content', 'site_logo');
     if (in_array($option_name, $option_names)) {
         Jetpack_Options::update_option('jumpstart', 'jetpack_action_taken');
         //Jump start is being dismissed send data to MC Stats
         $jetpack->stat('jumpstart', 'manual,' . $option_name);
         $jetpack->do_stats('server_side');
     }
 }
 /**
  * Get a post and associated data in the standard JP format.
  * Cannot be called statically
  *
  * @param int $id Post ID
  * @return Array containing full post details
  */
 function get_post($id)
 {
     $post_obj = get_post($id);
     if (!$post_obj) {
         return false;
     }
     if (is_callable($post_obj, 'to_array')) {
         // WP >= 3.5
         $post = $post_obj->to_array();
     } else {
         // WP < 3.5
         $post = get_object_vars($post_obj);
     }
     if (0 < strlen($post['post_password'])) {
         $post['post_password'] = '******' . wp_generate_password(10, false);
         // We don't want the real password.  Just pass something random.
     }
     // local optimizations
     unset($post['filter'], $post['ancestors'], $post['post_content_filtered'], $post['to_ping'], $post['pinged']);
     if ($this->is_post_public($post)) {
         $post['post_is_public'] = Jetpack::get_option('public');
     } else {
         //obscure content
         $post['post_content'] = '';
         $post['post_excerpt'] = '';
         $post['post_is_public'] = false;
     }
     $post_type_obj = get_post_type_object($post['post_type']);
     $post['post_is_excluded_from_search'] = $post_type_obj->exclude_from_search;
     $post['tax'] = array();
     $taxonomies = get_object_taxonomies($post_obj);
     foreach ($taxonomies as $taxonomy) {
         $terms = get_object_term_cache($post_obj->ID, $taxonomy);
         if (empty($terms)) {
             $terms = wp_get_object_terms($post_obj->ID, $taxonomy);
         }
         $term_names = array();
         foreach ($terms as $term) {
             $term_names[] = $term->name;
         }
         $post['tax'][$taxonomy] = $term_names;
     }
     $meta = get_post_meta($post_obj->ID, false);
     $post['meta'] = array();
     foreach ($meta as $key => $value) {
         $post['meta'][$key] = array_map('maybe_unserialize', $value);
     }
     $post['extra'] = array('author' => get_the_author_meta('display_name', $post_obj->post_author), 'author_email' => get_the_author_meta('email', $post_obj->post_author));
     if ($fid = get_post_thumbnail_id($id)) {
         $feature = wp_get_attachment_image_src($fid, 'large');
         if (!empty($feature[0])) {
             $post['extra']['featured_image'] = $feature[0];
         }
     }
     $post['permalink'] = get_permalink($post_obj->ID);
     $post['shortlink'] = wp_get_shortlink($post_obj->ID);
     return $post;
 }
Exemple #20
0
 function verify_json_api_authorization_request()
 {
     require_once dirname(__FILE__) . '/class.jetpack-signature.php';
     $token = Jetpack_Data::get_access_token(JETPACK_MASTER_USER);
     if (!$token || empty($token->secret)) {
         wp_die(__('You must connect your Jetpack plugin to WordPress.com to use this feature.', 'jetpack'));
     }
     $die_error = __('Someone may be trying to trick you into giving them access to your site.  Or it could be you just encountered a bug :).  Either way, please close this window.', 'jetpack');
     $jetpack_signature = new Jetpack_Signature($token->secret, (int) Jetpack::get_option('time_diff'));
     $signature = $jetpack_signature->sign_current_request(array('body' => null, 'method' => 'GET'));
     if (!$signature) {
         wp_die($die_error);
     } else {
         if (is_wp_error($signature)) {
             wp_die($die_error);
         } else {
             if ($signature !== $_GET['signature']) {
                 if (is_ssl()) {
                     // If we signed an HTTP request on the Jetpack Servers, but got redirected to HTTPS by the local blog, check the HTTP signature as well
                     $signature = $jetpack_signature->sign_current_request(array('scheme' => 'http', 'body' => null, 'method' => 'GET'));
                     if (!$signature || is_wp_error($signature) || $signature !== $_GET['signature']) {
                         wp_die($die_error);
                     }
                 } else {
                     wp_die($die_error);
                 }
             }
         }
     }
     $timestamp = (int) $_GET['timestamp'];
     $nonce = stripslashes((string) $_GET['nonce']);
     if (!$this->add_nonce($timestamp, $nonce)) {
         // De-nonce the nonce, at least for 5 minutes.
         // We have to reuse this nonce at least once (used the first time when the initial request is made, used a second time when the login form is POSTed)
         $old_nonce_time = get_option("jetpack_nonce_{$timestamp}_{$nonce}");
         if ($old_nonce_time < time() - 300) {
             wp_die(__('The authorization process expired.  Please go back and try again.', 'jetpack'));
         }
     }
     $data = json_decode(base64_decode(stripslashes($_GET['data'])));
     $data_filters = array('state' => 'opaque', 'client_id' => 'int', 'client_title' => 'string', 'client_image' => 'url');
     foreach ($data_filters as $key => $sanitation) {
         if (!isset($data->{$key})) {
             wp_die($die_error);
         }
         switch ($sanitation) {
             case 'int':
                 $this->json_api_authorization_request[$key] = (int) $data->{$key};
                 break;
             case 'opaque':
                 $this->json_api_authorization_request[$key] = (string) $data->{$key};
                 break;
             case 'string':
                 $this->json_api_authorization_request[$key] = wp_kses((string) $data->{$key}, array());
                 break;
             case 'url':
                 $this->json_api_authorization_request[$key] = esc_url_raw((string) $data->{$key});
                 break;
         }
     }
     if (empty($this->json_api_authorization_request['client_id'])) {
         wp_die($die_error);
     }
 }