Ejemplo n.º 1
4
/**
 * Pings http://api.genesistheme.com/ asking if a new version of this theme is
 * available.
 *
 * If not, it returns false.
 *
 * If so, the external server passes serialized data back to this function,
 * which gets unserialized and returned for use.
 *
 * @since 1.1.0
 *
 * @uses genesis_get_option()
 * @uses PARENT_THEME_VERSION Genesis version string
 *
 * @global string $wp_version WordPress version string
 * @return mixed Unserialized data, or false on failure
 */
function genesis_update_check()
{
    global $wp_version;
    /**	If updates are disabled */
    if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) {
        return false;
    }
    /** Get time of last update check */
    $genesis_update = get_transient('genesis-update');
    /** If it has expired, do an update check */
    if (!$genesis_update) {
        $url = 'http://api.genesistheme.com/update-themes/';
        $options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'wp_version' => $wp_version, 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};")));
        $response = wp_remote_post($url, $options);
        $genesis_update = wp_remote_retrieve_body($response);
        /** If an error occurred, return FALSE, store for 1 hour */
        if ('error' == $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) {
            set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60);
            return false;
        }
        /** Else, unserialize */
        $genesis_update = maybe_unserialize($genesis_update);
        /** And store in transient for 24 hours */
        set_transient('genesis-update', $genesis_update, 60 * 60 * 24);
    }
    /** If we're already using the latest version, return false */
    if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) {
        return false;
    }
    return $genesis_update;
}
Ejemplo n.º 2
1
 public static function gdrive_auth_token()
 {
     if (isset($_GET['code'])) {
         $post_vars = array('code' => $_GET['code'], 'client_id' => UpdraftPlus_Options::get_updraft_option('updraft_googledrive_clientid'), 'client_secret' => UpdraftPlus_Options::get_updraft_option('updraft_googledrive_secret'), 'redirect_uri' => admin_url('options-general.php?page=updraftplus&action=updraftmethod-googledrive-auth'), 'grant_type' => 'authorization_code');
         $result = wp_remote_post('https://accounts.google.com/o/oauth2/token', array('timeout' => 30, 'method' => 'POST', 'body' => $post_vars));
         if (is_wp_error($result)) {
             $add_to_url = "Bad response when contacting Google: ";
             foreach ($result->get_error_messages() as $message) {
                 global $updraftplus;
                 $updraftplus->log("Google Drive authentication error: " . $message);
                 $add_to_url .= "{$message}. ";
             }
             header('Location: ' . admin_url('options-general.php?page=updraftplus&error=' . urlencode($add_to_url)));
         } else {
             $json_values = json_decode($result['body'], true);
             if (isset($json_values['refresh_token'])) {
                 // Save token
                 UpdraftPlus_Options::update_updraft_option('updraft_googledrive_token', $json_values['refresh_token']);
                 if (isset($json_values['access_token'])) {
                     set_transient('updraftplus_tmp_googledrive_access_token', $json_values['access_token'], 3600);
                     // We do this to clear the GET parameters, otherwise WordPress sticks them in the _wp_referer in the form and brings them back, leading to confusion + errors
                     header('Location: ' . admin_url('options-general.php?page=updraftplus&action=updraftmethod-googledrive-auth&state=success'));
                 }
             } else {
                 $msg = __('No refresh token was received from Google. This often means that you entered your client secret wrongly, or that you have not yet re-authenticated (below) since correcting it. Re-check it, then follow the link to authenticate again. Finally, if that does not work, then use expert mode to wipe all your settings, create a new Google client ID/secret, and start again.', 'updraftplus');
                 if (isset($json_values['error'])) {
                     $msg .= ' ' . sprintf(__('Error: %s', 'updraftplus'), $json_values['error']);
                 }
                 header('Location: ' . admin_url('options-general.php?page=updraftplus&error=' . $msg));
             }
         }
     } else {
         header('Location: ' . admin_url('options-general.php?page=updraftplus&error=' . __('Authorization failed', 'updraftplus')));
     }
 }
Ejemplo n.º 3
1
 function check_for_update($transient)
 {
     global $wp_filesystem, $smof_data;
     if (empty($transient->checked)) {
         return $transient;
     }
     $request_args = array('id' => $this->id, 'slug' => $this->slug, 'version' => $transient->checked[$this->id]);
     $request_args['item_code'] = '2833226';
     $request_args['envato_username'] = $smof_data['t4p_username'];
     $request_args['api_key'] = $smof_data['t4p_api'];
     $filename = trailingslashit(get_template_directory()) . 'log.txt';
     $request_string = $this->prepare_request('plugin_update', $request_args);
     $raw_response = wp_remote_post($this->api_url, $request_string);
     $response = null;
     if (!is_wp_error($raw_response) && $raw_response['response']['code'] == 200) {
         $response = json_decode($raw_response['body'], true);
     }
     if (!empty($response)) {
         // Feed the update data into WP updater
         $transient->response[$this->id] = (object) $response;
     }
     /*$handle = fopen($filename, 'a');
       fwrite($handle, json_encode($request_string));
       fwrite($handle, json_encode($raw_response));*/
     return $transient;
 }
Ejemplo n.º 4
0
function layerslider_verify_purchase_code()
{
    global $wp_version;
    // Get data
    $pcode = get_option('layerslider-purchase-code', '');
    $validated = get_option('layerslider-validated', '0');
    $channel = $_POST['channel'] === 'beta' ? 'beta' : 'stable';
    // Save sent data
    update_option('layerslider-release-channel', $channel);
    update_option('layerslider-purchase-code', $_POST['purchase_code']);
    // Release channel
    if ($validated == 1) {
        if ($pcode == $_POST['purchase_code']) {
            die(json_encode(array('success' => true, 'message' => __('Your settings were successfully saved.', 'LayerSlider'))));
        }
    }
    // Verify license
    $response = wp_remote_post('http://activate.kreaturamedia.com/', array('user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'), 'body' => array('plugin' => urlencode('LayerSlider WP'), 'license' => urlencode($_POST['purchase_code']))));
    // Valid
    if ($response['body'] == 'valid') {
        update_option('layerslider-validated', '1');
        die(json_encode(array('success' => true, 'message' => __('Thank you for purchasing LayerSlider WP. You successfully validated your purchase code for auto-updates.', 'LayerSlider'))));
        // Invalid
    } else {
        update_option('layerslider-validated', '0');
        die(json_encode(array('success' => false, 'message' => __("Your purchase code doesn't appear to be valid. Please make sure that you entered your purchase code correctly.", "LayerSlider"))));
    }
}
Ejemplo n.º 5
0
function mm_ux_log($args = array())
{
    $url = "https://ssl.google-analytics.com/collect";
    global $title;
    if (empty($_SERVER['REQUEST_URI'])) {
        return;
    }
    $path = explode('wp-admin', $_SERVER['REQUEST_URI']);
    if (empty($path) || empty($path[1])) {
        $path = array("", " ");
    }
    $defaults = array('v' => '1', 'tid' => 'UA-39246514-3', 't' => 'pageview', 'cid' => md5(get_option('siteurl')), 'uid' => md5(get_option('siteurl') . get_current_user_id()), 'cn' => 'mojo_wp_plugin', 'cs' => 'mojo_wp_plugin', 'cm' => 'plugin_admin', 'ul' => get_locale(), 'dp' => $path[1], 'sc' => '', 'ua' => @$_SERVER['HTTP_USER_AGENT'], 'dl' => $path[1], 'dh' => get_option('siteurl'), 'dt' => $title, 'ec' => '', 'ea' => '', 'el' => '', 'ev' => '');
    if (isset($_SERVER['REMOTE_ADDR'])) {
        $defaults['uip'] = $_SERVER['REMOTE_ADDR'];
    }
    $params = wp_parse_args($args, $defaults);
    $test = get_transient('mm_test', '');
    if (isset($test['key']) && isset($test['name'])) {
        $params['cm'] = $params['cm'] . "_" . $test['name'] . "_" . $test['key'];
    }
    //use test account for testing
    if (defined('WP_DEBUG') && WP_DEBUG) {
        $params['tid'] = 'UA-19617272-27';
    }
    $z = wp_rand(0, 1000000000);
    $query = http_build_query(array_filter($params));
    $args = array('body' => $query, 'method' => 'POST', 'blocking' => false);
    $url = add_query_arg(array('z' => $z), $url);
    wp_remote_post($url, $args);
}
function pmxi_wp_ajax_save_import_functions()
{
    if (!check_ajax_referer('wp_all_import_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin'))));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_import_plugin'))));
    }
    $uploads = wp_upload_dir();
    $functions = $uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_IMPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php';
    $input = new PMXI_Input();
    $post = $input->post('data', '');
    $response = wp_remote_post('http://phpcodechecker.com/api', array('body' => array('code' => $post)));
    if (is_wp_error($response)) {
        $error_message = $response->get_error_message();
        exit(json_encode(array('result' => false, 'msg' => $error_message)));
        die;
    } else {
        $body = json_decode(wp_remote_retrieve_body($response), true);
        if ($body['errors'] === 'TRUE') {
            exit(json_encode(array('result' => false, 'msg' => $body['syntax']['message'])));
            die;
        } elseif ($body['errors'] === 'FALSE') {
            if (strpos($post, "<?php") === false || strpos($post, "?>") === false) {
                exit(json_encode(array('result' => false, 'msg' => __('PHP code must be wrapped in "&lt;?php" and "?&gt;"', 'wp_all_import_plugin'))));
                die;
            } else {
                file_put_contents($functions, $post);
            }
        }
    }
    exit(json_encode(array('result' => true, 'msg' => __('File has been successfully updated.', 'wp_all_import_plugin'))));
    die;
}
Ejemplo n.º 7
0
 /**
  * Execute an API call
  * @param string $method The HTTP method
  * @param string $url The API endpoint
  * @param string $call The API method to call
  * @param array $additional Additional parameters
  * @return array
  */
 public function fetch($method, $url, $call, array $additional = array())
 {
     // Get the signed request URL
     $request = $this->getSignedRequest($method, $url, $call, $additional);
     if ($method == 'GET') {
         $args = array();
         $response = wp_remote_get($request['url'], $args);
         $this->outFile = null;
     } elseif ($method == 'POST') {
         $args = array('body' => $request['postfields']);
         $response = wp_remote_post($request['url'], $args);
     } elseif ($method == 'PUT' && $this->inFile) {
         return new WP_Error('unsupported', "WordPress does not have a native HTTP PUT function");
     }
     // If the response body is not a JSON encoded string
     // we'll return the entire response body
     // Important to do this first, as the next section relies on the decoding having taken place
     if (!($body = json_decode($response['body']))) {
         $body = $response['body'];
     }
     // Check if an error occurred and throw an Exception. This is part of the authentication process - don't modify.
     if (!empty($body->error)) {
         $message = $body->error . ' (Status Code: ' . $response['code'] . ')';
         throw new Dropbox_Exception($message);
     }
     if (is_wp_error($response)) {
         $message = $response->get_error_message();
         throw new Dropbox_Exception($message);
     }
     $results = array('body' => $body, 'code' => $response['response']['code'], 'headers' => $response['headers']);
     return $results;
 }
 /**
  * parse_gateway_notification method, receives data from the payment gateway
  * @access private
  */
 function parse_gateway_notification()
 {
     /// PayPal first expects the IPN variables to be returned to it within 30 seconds, so we do this first.
     if ('sandbox' == get_option('paypal_certified_server_type')) {
         $paypal_url = "https://www.sandbox.paypal.com/webscr";
     } else {
         $API_Endpoint = "https://api-3t.paypal.com/nvp";
         $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
     }
     $received_values = array();
     $received_values['cmd'] = '_notify-validate';
     $received_values += stripslashes_deep($_POST);
     $options = array('timeout' => 20, 'body' => $received_values, 'httpversion' => '1.1', 'user-agent' => 'WP e-Commerce/' . WPSC_PRESENTABLE_VERSION);
     $response = wp_remote_post($paypal_url, $options);
     do_action('wpsc_paypal_express_ipn', $received_values, $this);
     if ('VERIFIED' == $response['body']) {
         $this->paypal_ipn_values = $received_values;
         $this->session_id = $received_values['invoice'];
         if (strtolower($received_values['payment_status']) == 'completed') {
             $this->set_purchase_processed_by_sessionid(3);
             transaction_results($this->session_id, false);
         } elseif (strtolower($received_values['payment_status']) == 'denied') {
             $this->set_purchase_processed_by_sessionid(6);
         }
     } else {
         exit("IPN Request Failure");
     }
 }
Ejemplo n.º 9
0
/**
 * Retrieve plugin installer pages from WordPress Plugins API.
 *
 * It is possible for a plugin to override the Plugin API result with three
 * filters. Assume this is for plugins, which can extend on the Plugin Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overridding the filters.
 *
 * The first filter, 'plugins_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'plugins_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'plugins_api', is the result that would be returned.
 *
 * @since 2.7.0
 *
 * @param string $action
 * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
 * @return mixed
 */
function plugins_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    $args = apply_filters('plugins_api_args', $args, $action);
    //NOTE: Ensure that an object is returned via this filter.
    $res = apply_filters('plugins_api', false, $action, $args);
    //NOTE: Allows a plugin to completely override the builtin WordPress.org API.
    if (!$res) {
        $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array('body' => array('action' => $action, 'request' => serialize($args))));
        if (is_wp_error($request)) {
            $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $request->get_error_message());
        } else {
            $res = unserialize($request['body']);
            if (!$res) {
                $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $request['body']);
            }
        }
    }
    return apply_filters('plugins_api_result', $res, $action, $args);
}
Ejemplo n.º 10
0
 /**
  * Calls the API and, if successfull, returns the object delivered by the API.
  *
  * @uses         get_bloginfo()
  * @uses         wp_remote_post()
  * @uses         is_wp_error()
  *
  * @return false||object
  */
 protected function call_remote_api()
 {
     // only check if a transient is not set (or if it's expired)
     if (get_transient($this->product->get_slug() . '-update-check-error') !== false) {
         return;
     }
     // setup api parameters
     $api_params = array('edd_action' => 'get_version', 'license' => $this->license_key, 'name' => $this->product->get_item_name(), 'slug' => $this->product->get_slug(), 'author' => $this->product->get_author());
     // setup request parameters
     $request_params = array('timeout' => 15, 'sslverify' => false, 'body' => $api_params);
     // call remote api
     $response = wp_remote_post($this->product->get_api_url(), $request_params);
     // wp / http error?
     if (is_wp_error($response)) {
         $this->wp_error = $response;
         // show error to user
         add_action('admin_notices', array($this, 'show_update_error'));
         // set a transient to prevent checking for updates on every page load
         set_transient($this->product->get_slug() . '-update-check-error', true, 60 * 30);
         // 30 mins
         return false;
     }
     // decode response
     $response = json_decode(wp_remote_retrieve_body($response));
     $response->sections = maybe_unserialize($response->sections);
     return $response;
 }
Ejemplo n.º 11
0
 public function doRequests($URLs, $Blocking, $ID)
 {
     $requestParameters = array('plugin_version' => PLUGIN_VERSION, 'key' => $this->_apiKey, 'lossy' => $this->_compressionType, 'cmyk2rgb' => $this->_CMYKtoRGBconversion, 'resize' => $this->_resizeImages, 'resize_width' => $this->_resizeWidth, 'resize_height' => $this->_resizeHeight, 'urllist' => $URLs);
     $arguments = array('method' => 'POST', 'timeout' => 45, 'redirection' => 3, 'sslverify' => false, 'httpversion' => '1.0', 'blocking' => $Blocking, 'headers' => array(), 'body' => json_encode($requestParameters), 'cookies' => array());
     $response = wp_remote_post($this->_apiEndPoint, $arguments);
     //only if $Blocking is true analyze the response
     if ($Blocking) {
         //there was an error, save this error inside file's SP optimization field
         if (is_object($response) && get_class($response) == 'WP_Error') {
             $errorMessage = $response->errors['http_request_failed'][0];
             $errorCode = 503;
         } elseif (isset($response['response']['code']) && $response['response']['code'] != 200) {
             $errorMessage = $response['response']['code'] . " - " . $response['response']['message'];
             $errorCode = $response['response']['code'];
         }
         if (isset($errorMessage)) {
             //set details inside file so user can know what happened
             $meta = wp_get_attachment_metadata($ID);
             $meta['ShortPixelImprovement'] = 'Error: <i>' . $errorMessage . '</i>';
             unset($meta['ShortPixel']['WaitingProcessing']);
             wp_update_attachment_metadata($ID, $meta);
             return array("response" => array("code" => $errorCode, "message" => $errorMessage));
         }
         return $response;
         //this can be an error or a good response
     }
     return $response;
 }
 function check_for_update($transient)
 {
     global $wp_filesystem;
     $avada_options = get_option('Avada_Key');
     if (empty($transient->checked)) {
         return $transient;
     }
     $request_args = array('id' => $this->theme_id, 'slug' => $this->theme_slug, 'version' => $transient->checked[$this->theme_slug]);
     if ($this->api_url == 'http://updates.theme-fusion.com/avada-theme.php') {
         $request_args['item_code'] = '2833226';
         $request_args['envato_username'] = $avada_options['tf_username'];
         $request_args['api_key'] = $avada_options['tf_api'];
     }
     $filename = trailingslashit(get_template_directory()) . 'log.txt';
     $request_string = $this->prepare_request('theme_update', $request_args);
     $raw_response = wp_remote_post($this->api_url, $request_string);
     $response = null;
     if (!is_wp_error($raw_response) && $raw_response['response']['code'] == 200) {
         $response = json_decode($raw_response['body'], true);
     }
     if (!empty($response)) {
         // Feed the update data into WP updater
         $transient->response[$this->theme_slug] = $response;
     }
     /*$handle = fopen($filename, 'a');
     		fwrite($handle, json_encode($request_string));
     		fwrite($handle, json_encode($raw_response));*/
     return $transient;
 }
Ejemplo n.º 13
0
/**
 * Returns array with headers in $response[0] and body in $response[1]
 * Based on a function from Akismet
 */
function AtD_http_post($request, $host, $path, $port = 80)
{
    $http_args = array('body' => $request, 'headers' => array('Content-Type' => 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'), 'Host' => $host, 'User-Agent' => 'AtD/0.1'), 'httpversion' => '1.0', 'timeout' => apply_filters('atd_http_post_timeout', 15));
    // Handle non-standard ports being passed in.
    if (80 !== $port && is_numeric($port) && intval($port) > 0) {
        $host .= ':' . intval($port);
    }
    // Strip any / off the begining so we can add it back and protect against SSRF
    $path = ltrim($path, '/');
    $AtD_url = set_url_scheme("http://{$host}/{$path}");
    $response = wp_remote_post($AtD_url, $http_args);
    $code = (int) wp_remote_retrieve_response_code($response);
    if (is_wp_error($response)) {
        /**
         * Fires when there is a post error to AtD.
         *
         * @since 1.2.3
         *
         * @param int|string http-error The error that AtD runs into.
         */
        do_action('atd_http_post_error', 'http-error');
        return array();
    } elseif (200 != $code) {
        /** This action is documented in modules/after-the-deadline/proxy.php */
        do_action('atd_http_post_error', $code);
    }
    return array(wp_remote_retrieve_headers($response), wp_remote_retrieve_body($response));
}
Ejemplo n.º 14
0
 public function call($operation, $params = array())
 {
     $url = self::URL . '/' . $operation;
     $params['blog'] = $this->blog;
     if ($this->ready()) {
         $params['token'] = $this->token;
     }
     $response = wp_remote_post($url, array('body' => $params, 'timeout' => 0));
     if (is_wp_error($response)) {
         die($response->get_error_message());
     }
     $response = json_decode($response['body']);
     if (property_exists($response, 'error')) {
         if (is_object($response->error)) {
             die($response->error->message);
         } elseif ($response->code == 'invalid-session') {
             throw new ClientInvalidSession();
         } else {
             die($response->error);
         }
     }
     if (property_exists($response, 'token')) {
         update_option(self::TOKEN, $response->token);
     }
     return $response;
 }
 protected function validate_themes()
 {
     if (empty($this->themes) || !is_array($this->themes)) {
         return new WP_Error('missing_themes', __('No themes found.', 'jetpack'));
     }
     foreach ($this->themes as $index => $theme) {
         if (self::is_installed_theme($theme)) {
             return new WP_Error('theme_already_installed', __('The theme is already installed', 'jetpack'));
         }
         if (wp_endswith($theme, '-wpcom')) {
             $file = self::download_wpcom_theme_to_file($theme);
             if (is_wp_error($file)) {
                 return $file;
             }
             $this->download_links[$theme] = $file;
             continue;
         }
         $params = (object) array('slug' => $theme);
         $url = 'https://api.wordpress.org/themes/info/1.0/';
         $args = array('body' => array('action' => 'theme_information', 'request' => serialize($params)));
         $response = wp_remote_post($url, $args);
         $theme_data = unserialize($response['body']);
         if (is_wp_error($theme_data)) {
             return $theme_data;
         }
         if (!is_object($theme_data) && !isset($theme_data->download_link)) {
             return new WP_Error('theme_not_found', __('This theme does not exist', 'jetpack'), 404);
         }
         $this->download_links[$theme] = $theme_data->download_link;
     }
     return true;
 }
Ejemplo n.º 16
0
/**
 * Check to see if a new version of Catayst is available.
 *
 * @since 1.0
 * @return either response or transient.
 */
function dynamik_update_check()
{
    global $wp_version;
    // Debug Auto-Update.
    //delete_transient( 'dynamik-gen-update' );
    $dynamik_transient = get_transient('dynamik-gen-update');
    if ($dynamik_transient == false) {
        $api_url = 'http://api.cobaltapps.com/dynamik-update/';
        // Start checking for an update
        $send_for_check = array('body' => array('action' => 'theme_update', 'request' => array('slug' => 'dynamik-gen', 'version' => CHILD_THEME_VERSION)), 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url());
        $raw_response = wp_remote_post($api_url, $send_for_check);
        if (!is_wp_error($raw_response) && $raw_response['response']['code'] == 200 && is_serialized($raw_response['body'])) {
            $response = unserialize($raw_response['body']);
        } else {
            set_transient('dynamik-gen-update', array('new_version' => CHILD_THEME_VERSION), 60 * 60 * 24);
            // store for 24 hours
        }
        if (!empty($response)) {
            set_transient('dynamik-gen-update', $response, 60 * 60 * 24);
            // store for 24 hours
            return $response;
        }
    } else {
        return $dynamik_transient;
    }
}
Ejemplo n.º 17
0
 private static function apiRequest($act, $post_data = null, $use_ssl = true)
 {
     global $wp_version;
     $site = rawurlencode(base64_encode(get_option('siteurl')));
     $url = "http" . ($use_ssl ? "s://ssl-account.com" : ":/") . "/interface.fabi.me/wpfilebase-pro/{$act}.php";
     $get_args = array('version' => WPFB_VERSION, 'pl_slug' => 'wp-filebase', 'pl_ver' => WPFB_VERSION, 'wp_ver' => $wp_version, 'site' => $site);
     // try to get from cache
     $cache_key = 'wpfb_apireq_' . md5($act . '||' . serialize($get_args) . '||' . serialize($post_data) . '||' . __FILE__);
     if (isset($_REQUEST['no_api_cache'])) {
         delete_transient($cache_key);
     }
     $res = get_transient($cache_key);
     if ($res !== false) {
         return $res;
     }
     //trigger_error ( "WP-Filebase apiRequest (ssl=$use_ssl): $act ".json_encode($post_data), E_USER_NOTICE );
     if (empty($post_data)) {
         $res = wp_remote_get($url, $get_args);
     } else {
         $res = wp_remote_post(add_query_arg($get_args, $url), array('body' => $post_data));
     }
     if (is_wp_error($res)) {
         if ($use_ssl) {
             // retry without ssl
             return self::apiRequest($act, $post_data, false);
         }
         echo "<b>WP-Filebase API request error:</b>";
         print_r($res);
         return false;
     }
     $res = empty($res['body']) ? false : json_decode($res['body']);
     set_transient($cache_key, $res, 0 + 6 * HOUR_IN_SECONDS);
     return $res;
 }
 protected function process_access_token_request()
 {
     if (array_key_exists('code', $_REQUEST) && array_key_exists('post_id', $_REQUEST)) {
         global $pms_post_protected;
         global $pms_session;
         $post_id = intval($_REQUEST['post_id']);
         $settings = $this->get_settings();
         $url = Postmatic_Social_Gplus_Authenticator::$ACCESS_URL;
         $client_id = $settings[Postmatic_Social_Gplus_Authenticator::$CLIENT_ID];
         $client_secret = $settings[Postmatic_Social_Gplus_Authenticator::$CLIENT_SECRET];
         $query_string = $this->to_query_string(array('code' => $_REQUEST['code'], 'client_id' => $client_id, 'client_secret' => $client_secret, 'redirect_uri' => $this->get_oauth_callback(), 'grant_type' => 'authorization_code'));
         $response = wp_remote_post(esc_url_raw($url), array('body' => $query_string, 'sslverify' => false));
         if (is_wp_error($response)) {
             $error_string = $response->get_error_message();
             throw new Exception($error_string);
         } else {
             $response_body = json_decode($response['body'], true);
             if ($response_body && is_array($response_body) && array_key_exists('access_token', $response_body)) {
                 $access_token = $response_body['access_token'];
                 $user_details = $this->get_user_details($access_token);
                 $pms_session['user'] = $user_details;
                 $pms_post_protected = true;
                 $user_details['disconnect_content'] = $GLOBALS['postmatic-social']->disconnect_content($user_details, $post_id);
                 wp_send_json($user_details);
                 die;
             } else {
                 throw new Exception(__('Missing the access_token parameter', 'postmatic-social'));
             }
         }
     } else {
         die;
     }
 }
 /**
  * Check the server for theme updates.
  *
  * @param  object $data `update_themes` transient
  * @return object       Transformed `update_themes` transient
  */
 public static function check_for_update($data)
 {
     // Setup
     self::set_theme_data();
     $request = array('slug' => self::$theme_slug, 'version' => self::$theme_version);
     if (defined('DOING_CRON') && DOING_CRON) {
         $timeout = 30;
     } else {
         $timeout = 3;
     }
     $options = array('timeout' => $timeout, 'body' => array('request' => wp_json_encode($request)));
     $raw_response = wp_remote_post(self::$api_url, $options);
     if (is_wp_error($raw_response)) {
         return $raw_response;
     } else {
         if (wp_remote_retrieve_response_code($raw_response) !== 200) {
             return new WP_Error('broke', __('Theme update failed:'), $raw_response);
         }
     }
     $response = json_decode(wp_remote_retrieve_body($raw_response), true);
     if (gettype($response) === 'array' && isset($response['new_version']) && isset($response['url']) && isset($response['package'])) {
         $data->response[self::$theme_slug] = array('theme' => self::$theme_slug, 'new_version' => $response['new_version'], 'url' => $response['url'], 'package' => $response['package']);
     }
     return $data;
 }
Ejemplo n.º 20
0
	/**
	 * Submit customer report to ServMask.com
	 *
	 * @param  string  $email   User E-mail
	 * @param  string  $message User Message
	 * @param  integer $terms   User Accept Terms
	 *
	 * @return array
	 */
	public function add( $email, $message, $terms ) {
		$errors = array();

		// Submit report to ServMask
		if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
			$errors[] = __( 'Your email is not valid.', AI1WM_PLUGIN_NAME );
		} else if ( empty( $message ) ) {
			$errors[] = __( 'Please enter comments in the text area.', AI1WM_PLUGIN_NAME );
		} else if ( empty( $terms ) ) {
			$errors[] = __( 'Please accept report term conditions.', AI1WM_PLUGIN_NAME );
		} else {
			$response = wp_remote_post(
				AI1WM_REPORT_URL,
				array(
					'body' => array(
						'email'   => $email,
						'message' => $message,
					),
				)
			);

			if ( is_wp_error( $response ) ) {
				$errors[] = sprintf( __( 'Something went wrong: %s', AI1WM_PLUGIN_NAME ), $response->get_error_message() );
			}
		}

		return array( 'errors' => $errors );
	}
 function display()
 {
     $browser = new SendPress_Browser();
     if (get_bloginfo('version') < '3.4') {
         $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css');
         $theme = $theme_data['Name'] . ' ' . $theme_data['Version'];
     } else {
         $theme_data = wp_get_theme();
         $theme = $theme_data->Name . ' ' . $theme_data->Version;
     }
     // Try to identify the hosting provider
     $host = false;
     if (defined('WPE_APIKEY')) {
         $host = 'WP Engine';
     } elseif (defined('PAGELYBIN')) {
         $host = 'Pagely';
     }
     $request['cmd'] = '_notify-validate';
     $params = array('sslverify' => false, 'timeout' => 60, 'body' => $request);
     $response = wp_remote_post('https://www.paypal.com/cgi-bin/webscr', $params);
     if (!is_wp_error($response) && $response['response']['code'] >= 200 && $response['response']['code'] < 300) {
         $WP_REMOTE_POST = 'wp_remote_post() works' . "\n";
     } else {
         $WP_REMOTE_POST = 'wp_remote_post() does not work' . "\n";
     }
     return $this->display_output($browser, $theme, $host, $WP_REMOTE_POST);
 }
 /**
  * Overload method to transparently intercept calls.
  * Perform an HTTP request using the Wordpress HTTP API
  *
  * @param string $url
  * @param array $data
  * @param string $method
  * @return string
  */
 function httpRequestCurl($url, array $data, $method = 'POST')
 {
     if ('GET' == $method) {
         $url_with_params = $url;
         if (count($data) > 0) {
             $url_with_params .= '?' . http_build_query($data);
         }
         $url = $url_with_params;
     } else {
         // build a WP approved array
         $data = array('method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => $data, 'cookies' => array());
     }
     if ('GET' == $method) {
         $reply = wp_remote_get($url, $data);
     } else {
         $reply = wp_remote_post($url, $data);
     }
     if (isset($reply)) {
         if (is_wp_error($reply)) {
             throw new Sailthru_Client_Exception("Bad response received from {$url}: " . $reply->get_error_message());
         } else {
             if (wp_remote_retrieve_response_code($reply) == 200) {
                 return $reply['body'];
             }
         }
     } else {
         throw new Sailthru_Client_Exception('A reply was never generated.');
     }
 }
/**
 * Retrieve plugin installer pages from WordPress Plugins API.
 *
 * It is possible for a plugin to override the Plugin API result with three
 * filters. Assume this is for plugins, which can extend on the Plugin Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overriding the filters.
 *
 * The first filter, 'plugins_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'plugins_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'plugins_api', is the result that would be returned.
 *
 * @since 2.7.0
 *
 * @param string $action
 * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
 * @return object plugins_api response object on success, WP_Error on failure.
 */
function plugins_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    // Allows a plugin to override the WordPress.org API entirely.
    // Use the filter 'plugins_api_result' to merely add results.
    // Please ensure that a object is returned from the following filters.
    $args = apply_filters('plugins_api_args', $args, $action);
    $res = apply_filters('plugins_api', false, $action, $args);
    if (false === $res) {
        $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))));
        if (is_wp_error($request)) {
            $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message());
        } else {
            $res = unserialize(wp_remote_retrieve_body($request));
            if (false === $res) {
                $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body($request));
            }
        }
    } elseif (!is_wp_error($res)) {
        $res->external = true;
    }
    return apply_filters('plugins_api_result', $res, $action, $args);
}
Ejemplo n.º 24
0
/**
 * Ping http://api.genesistheme.com/ asking if a new version of this theme is available.
 *
 * If not, it returns false.
 *
 * If so, the external server passes serialized data back to this function, which gets unserialized and returned for use.
 *
 * Applies `genesis_update_remote_post_options` filter.
 *
 * Ping occurs at a maximum of once every 24 hours.
 *
 * @since 1.1.0
 *
 * @uses genesis_get_option() Get theme setting value.
 * @uses genesis_html5()      Check for HTML5 support.
 * @uses PARENT_THEME_VERSION Genesis version string.
 *
 * @global string $wp_version WordPress version string.
 *
 * @return array Unserialized data, or empty on failure.
 */
function genesis_update_check()
{
    //* Use cache
    static $genesis_update = null;
    global $wp_version;
    //* If updates are disabled
    if (!genesis_get_option('update') || !current_theme_supports('genesis-auto-updates')) {
        return array();
    }
    //* If cache is empty, pull transient
    if (!$genesis_update) {
        $genesis_update = get_transient('genesis-update');
    }
    //* If transient has expired, do a fresh update check
    if (!$genesis_update) {
        $url = 'http://api.genesistheme.com/update-themes/';
        $options = apply_filters('genesis_update_remote_post_options', array('body' => array('genesis_version' => PARENT_THEME_VERSION, 'html5' => genesis_html5(), 'php_version' => phpversion(), 'uri' => home_url(), 'user-agent' => "WordPress/{$wp_version};", 'wp_version' => $wp_version)));
        $response = wp_remote_post($url, $options);
        $genesis_update = wp_remote_retrieve_body($response);
        //* If an error occurred, return FALSE, store for 1 hour
        if ('error' === $genesis_update || is_wp_error($genesis_update) || !is_serialized($genesis_update)) {
            set_transient('genesis-update', array('new_version' => PARENT_THEME_VERSION), 60 * 60);
            return array();
        }
        //* Else, unserialize
        $genesis_update = maybe_unserialize($genesis_update);
        //* And store in transient for 24 hours
        set_transient('genesis-update', $genesis_update, 60 * 60 * 24);
    }
    //* If we're already using the latest version, return empty array.
    if (version_compare(PARENT_THEME_VERSION, $genesis_update['new_version'], '>=')) {
        return array();
    }
    return $genesis_update;
}
Ejemplo n.º 25
0
 protected function getURL($url, $postParams = array())
 {
     wordfence::status(4, 'info', "Calling Wordfence API v" . WORDFENCE_API_VERSION . ":" . $url);
     if (!function_exists('wp_remote_post')) {
         require_once ABSPATH . WPINC . 'http.php';
     }
     $ssl_verify = (bool) wfConfig::get('ssl_verify');
     $args = array('timeout' => 900, 'user-agent' => "Wordfence.com UA " . (defined('WORDFENCE_VERSION') ? WORDFENCE_VERSION : '[Unknown version]'), 'body' => $postParams, 'sslverify' => $ssl_verify);
     if (!$ssl_verify) {
         // Some versions of cURL will complain that SSL verification is disabled but the CA bundle was supplied.
         $args['sslcertificates'] = false;
     }
     $response = wp_remote_post($url, $args);
     $this->lastHTTPStatus = (int) wp_remote_retrieve_response_code($response);
     if (is_wp_error($response)) {
         $error_message = $response->get_error_message();
         throw new Exception("There was an " . ($error_message ? '' : 'unknown ') . "error connecting to the the Wordfence scanning servers" . ($error_message ? ": {$error_message}" : '.'));
     }
     if (!empty($response['response']['code'])) {
         $this->lastHTTPStatus = (int) $response['response']['code'];
     }
     if (200 != $this->lastHTTPStatus) {
         throw new Exception("We received an error response when trying to contact the Wordfence scanning servers. The HTTP status code was [{$this->lastHTTPStatus}]");
     }
     $this->curlContent = wp_remote_retrieve_body($response);
     return $this->curlContent;
 }
Ejemplo n.º 26
0
 function check_for_update()
 {
     $theme = wp_get_theme($this->theme_slug);
     $update_data = get_transient($this->response_key);
     if (false === $update_data) {
         $failed = false;
         $api_params = array('edd_action' => 'get_version', 'license' => $this->license, 'name' => $this->item_name, 'slug' => $this->theme_slug, 'author' => $this->author);
         $response = wp_remote_post($this->remote_api_url, array('timeout' => 15, 'body' => $api_params));
         // make sure the response was successful
         if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
             $failed = true;
         }
         $update_data = json_decode(wp_remote_retrieve_body($response));
         if (!is_object($update_data)) {
             $failed = true;
         }
         // if the response failed, try again in 30 minutes
         if ($failed) {
             $data = new stdClass();
             $data->new_version = $theme->get('Version');
             set_transient($this->response_key, $data, strtotime('+30 minutes'));
             return false;
         }
         // if the status is 'ok', return the update arguments
         if (!$failed) {
             $update_data->sections = maybe_unserialize($update_data->sections);
             set_transient($this->response_key, $update_data, strtotime('+12 hours'));
         }
     }
     if (version_compare($theme->get('Version'), $update_data->new_version, '>=')) {
         return false;
     }
     return (array) $update_data;
 }
Ejemplo n.º 27
0
/**
 * This function calibrefx_update_check is to ...
 */
function calibrefx_update_check()
{
    global $wp_version;
    /** Get time of last update check */
    $calibrefx_update = get_transient('calibrefx-update');
    /** If it has expired, do an update check */
    if (!$calibrefx_update) {
        $url = 'http://api.calibrefx.com/themes-update/';
        $options = apply_filters('calibrefx_update_remote_post_options', array('body' => array('theme_name' => 'calibrefx', 'theme_version' => FRAMEWORK_VERSION, 'url' => home_url(), 'wp_version' => $wp_version, 'php_version' => phpversion(), 'user-agent' => "WordPress/{$wp_version};")));
        $response = wp_remote_post($url, $options);
        $calibrefx_update = wp_remote_retrieve_body($response);
        /** If an error occurred, return FALSE, store for 48 hour */
        if ('error' == $calibrefx_update || is_wp_error($calibrefx_update) || !is_serialized($calibrefx_update)) {
            set_transient('calibrefx-update', array('new_version' => FRAMEWORK_VERSION), 60 * 60 * 48);
            return false;
        }
        /** Else, unserialize */
        $calibrefx_update = maybe_unserialize($calibrefx_update);
        /** And store in transient for 48 hours */
        set_transient('calibrefx-update', $calibrefx_update, 60 * 60 * 48);
    }
    /** If we're already using the latest version, return false */
    if (version_compare(FRAMEWORK_VERSION, $calibrefx_update['new_version'], '>=')) {
        return false;
    }
    return $calibrefx_update;
}
 /**
  * Uses the Brightcove oAuth API to retrieve and store an access key for use with requests. The token is stored as a transient
  * with an expiration time matching that which is returned from Brightcove. The call to the API is only performed if that transient
  * is invalid or expired. Return a WP_Error object for use in WordPress in the case of failure.
  *
  * @since  1.0.0
  *
  * @see    get_transient()
  * @see    set_transient()
  * @see    delete_transient()
  * @see    wp_remote_post()
  *
  * @param bool $force_new_token whether or not to obtain a new OAuth token
  * @param bool $retry           true to retry on failure or false
  *
  * @return string|WP_Error
  */
 public function _request_access_token($force_new_token = false, $retry = true)
 {
     $transient_name = $this->transient_name;
     $token = $force_new_token ? false : get_transient($transient_name);
     if (!$token) {
         $endpoint = esc_url_raw(self::ENDPOINT_BASE . '/access_token?grant_type=client_credentials');
         $request = wp_remote_post($endpoint, $this->_http_headers);
         if ('400' == wp_remote_retrieve_response_code($request)) {
             // Just in case
             delete_transient($transient_name);
             $oauth_error = new WP_Error('oauth_access_token_failure', sprintf(__('There is a problem with your Brightcove %1$s or %2$s', 'brightcove'), '<code>client_id</code>', '<code>client_secret</code>'));
             BC_Logging::log(sprintf('BC OAUTH ERROR: %s', $oauth_error->get_error_message()));
             return $oauth_error;
         }
         $body = wp_remote_retrieve_body($request);
         $data = json_decode($body);
         if (isset($data->access_token)) {
             $token = $data->access_token;
             set_transient($transient_name, $token, $data->expires_in);
         } else {
             if (!$retry) {
                 return new WP_Error('oauth_access_token_response_failure', sprintf(esc_html__('oAuth API did not return us an access token', 'brightcove')));
             }
             return $this->_request_access_token($force_new_token, false);
         }
     }
     return $token;
 }
/**
 * Retrieve plugin installer pages from WordPress Plugins API.
 *
 * It is possible for a plugin to override the Plugin API result with three
 * filters. Assume this is for plugins, which can extend on the Plugin Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overriding the filters.
 *
 * The first filter, 'plugins_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'plugins_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'plugins_api', is the result that would be returned.
 *
 * @since 2.7.0
 *
 * @param string $action
 * @param array|object $args Optional. Arguments to serialize for the Plugin Info API.
 * @return object plugins_api response object on success, WP_Error on failure.
 */
function plugins_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    // Allows a plugin to override the WordPress.org API entirely.
    // Use the filter 'plugins_api_result' to merely add results.
    // Please ensure that a object is returned from the following filters.
    $args = apply_filters('plugins_api_args', $args, $action);
    $res = apply_filters('plugins_api', false, $action, $args);
    if (false === $res) {
        $request = wp_remote_post('http://api.wordpress.org/plugins/info/1.0/', array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))));
        if (is_wp_error($request)) {
            $res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), $request->get_error_message());
        } else {
            $res = maybe_unserialize(wp_remote_retrieve_body($request));
            if (!is_object($res) && !is_array($res)) {
                $res = new WP_Error('plugins_api_failed', __('An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.'), wp_remote_retrieve_body($request));
            }
        }
    } elseif (!is_wp_error($res)) {
        $res->external = true;
    }
    return apply_filters('plugins_api_result', $res, $action, $args);
}
Ejemplo n.º 30
0
function smart_manager_validate_license_key()
{
    global $sm_base_name, $sm_check_update_timeout, $sm_plugin_data, $sm_sku, $sm_license_key, $sm_download_url, $sm_installed_version, $sm_live_version;
    $sm_license_key = isset($_REQUEST['license_key']) && !empty($_REQUEST['license_key']) ? $_REQUEST['license_key'] : '';
    $storeapps_validation_url = 'http://www.storeapps.org/wp-admin/admin-ajax.php?action=woocommerce_validate_serial_key&serial=' . urlencode($sm_license_key) . '&is_download=true&sku=' . $sm_sku;
    $resp_type = array('headers' => array('content-type' => 'application/text'));
    $response_info = wp_remote_post($storeapps_validation_url, $resp_type);
    //return WP_Error on response failure
    if (is_array($response_info)) {
        $response_code = wp_remote_retrieve_response_code($response_info);
        $response_msg = wp_remote_retrieve_response_message($response_info);
        // if ($response_code == 200 && $response_msg == 'OK') {
        if ($response_code == 200) {
            $storeapps_response = wp_remote_retrieve_body($response_info);
            $decoded_response = json_decode($storeapps_response);
            if ($decoded_response->is_valid == 1) {
                update_site_option('smart_manager_license_key', $sm_license_key);
                update_site_option('smart_manager_download_url', $decoded_response->download_url);
            } else {
                remove_license_download_url();
            }
            echo $storeapps_response;
            exit;
        }
        remove_license_download_url();
        echo json_encode(array('is_valid' => 0));
        exit;
    }
    remove_license_download_url();
    echo json_encode(array('is_valid' => 0));
    exit;
}