/** * Make a HTTP GET request to the provided URL * @param string $url URL to make the request to * @param array $data optional Data to send with the request * @param boolean $cache Try and make a cache request first * @return wp_response Results of the GET request */ static function get($url, $data = array(), $cache = false) { // esc_url_raw eats []'s , so I'm forced to skip it for urls containing // those characters - at this time only the account list request if (!strpos($url, '[0]')) { $url = esc_url_raw($url); } if ($cache && defined('WPCOM_IS_VIP_ENV')) { return wpcom_vip_file_get_contents($url); } else { $response = wp_remote_get($url, $data); $newUrl = ThePlatform_API_HTTP::check_for_auth_error($response, $url); if ($newUrl === false) { return $response; } else { return ThePlatform_API_HTTP::get($newUrl, $data, $cache); } } }
private function get_video_data($video_url) { $data = array(); $args = array('url' => $video_url, 'format' => 'json'); $url = add_query_arg($args, self::ENDPOINT); if (function_exists('wpcom_vip_file_get_contents')) { $_data = wpcom_vip_file_get_contents(esc_url_raw($url)); if (!empty($_data)) { $_data = json_decode($_data); } } else { $request = wp_remote_get(esc_url_raw($url)); if (is_array($request) && !empty($request['response']['code']) && $request['response']['code'] === 200 && !empty($request['body'])) { $_data = json_decode($request['body']); } } if (isset($_data) && !is_null($_data)) { $data = $_data; } return $data; }
/** * Returns profile information for a WordPress/Gravatar user * * @param string|int $email_or_id Email, ID, or username for user to lookup * @return false|array Profile info formatted as noted here: http://en.gravatar.com/site/implement/profiles/php/. If user not found, returns false. */ function wpcom_vip_get_user_profile($email_or_id) { if (is_numeric($email_or_id)) { $user = get_user_by('id', $email_or_id); if (!$user) { return false; } $email = $user->user_email; } elseif (is_email($email_or_id)) { $email = $email_or_id; } else { $user_login = sanitize_user($email_or_id, true); $user = get_user_by('login', $user_login); if (!$user) { return; } $email = $user->user_email; } $hashed_email = md5(strtolower(trim($email))); $profile_url = esc_url_raw(sprintf('%s.gravatar.com/%s.php', is_ssl() ? 'https://secure' : 'http://www', $hashed_email), array('http', 'https')); $profile = wpcom_vip_file_get_contents($profile_url, 1, 900); if ($profile) { $profile = unserialize($profile); if (is_array($profile) && !empty($profile['entry']) && is_array($profile['entry'])) { $profile = $profile['entry'][0]; } else { $profile = false; } } return $profile; }
/** * Get cache bust number from assets * Returns: Number from text file */ public function get_cache_bust() { $location = $this->assets . '/plugin/cache_bust.txt'; $response = ''; $result = null; // Check if VIP functions exist, which will cache response // for fifteen minutes, with a timeout of three seconds if (true == function_exists('wpcom_vip_file_get_contents')) { $response = wpcom_vip_file_get_contents($location); } else { $http = new WP_Http(); $response = $http->request($location); } // Validate response if (true == is_string($response)) { $result = $response; } else { if (true == is_array($response) && true == isset($response['body'])) { $result = $response['body']; } else { $result = '0'; } } return $result; }
function smittenkitchen_svg_shortcode($atts, $content = null) { $a = shortcode_atts(array('file' => ''), $atts); $file = get_template_directory_uri() . '/assets/svg/' . $atts['file'] . '.svg'; if (function_exists('wpcom_is_vip')) { return wpcom_vip_file_get_contents(esc_url($file)); } else { return file_get_contents(esc_url($file)); } }
/** * This is the old deprecated version of wpcom_vip_file_get_contents(). Please don't use this function in any new code. * * @deprecated * @link http://lobby.vip.wordpress.com/best-practices/fetching-remote-data/ Fetching Remote Data * @param string $url URL to fetch * @param bool $echo_content Optional. If true (the default), echo the remote file's contents. If false, return it. * @param int $timeout Optional. The timeout limit in seconds; valid values are 1-10. Defaults to 3. * @return string|null If $echo_content is true, there will be no return value. * @see wpcom_vip_file_get_contents */ function vip_wp_file_get_content($url, $echo_content = true, $timeout = 3) { _deprecated_function(__FUNCTION__, '2.0.0', 'wpcom_vip_file_get_contents'); $output = wpcom_vip_file_get_contents($url, $timeout); if ($echo_content) { echo $output; } else { return $output; } }
/** * Sync Discourse comments with WordPress * * @param int $postid */ function sync_comments($postid) { $discourse_options = self::get_plugin_options(); // every 10 minutes do a json call to sync comment count and top comments $last_sync = (int) get_post_meta($postid, 'discourse_last_sync', true); $time = date_create()->format('U'); $debug = isset($discourse_options['debug-mode']) && intval($discourse_options['debug-mode']) == 1; if ($debug || $last_sync + 60 * 10 < $time) { $got_lock = get_transient('discourse_sync_lock'); if (!$got_lock) { set_transient('discourse_sync_lock', true); if (get_post_status($postid) == 'publish') { // workaround unpublished posts, publish if needed // if you have a scheduled post we never seem to be called if (!(get_post_meta($postid, 'discourse_post_id', true) > 0)) { $post = get_post($postid); self::publish_post_to_discourse('publish', 'publish', $post); } $comment_count = intval($discourse_options['max-comments']); $min_trust_level = intval($discourse_options['min-trust-level']); $min_score = intval($discourse_options['min-score']); $min_replies = intval($discourse_options['min-replies']); $bypass_trust_level_score = intval($discourse_options['bypass-trust-level-score']); $options = 'best=' . $comment_count . '&min_trust_level=' . $min_trust_level . '&min_score=' . $min_score; $options .= '&min_replies=' . $min_replies . '&bypass_trust_level_score=' . $bypass_trust_level_score; if (isset($discourse_options['only-show-moderator-liked']) && intval($discourse_options['only-show-moderator-liked']) == 1) { $options .= '&only_moderator_liked=true'; } $permalink = (string) get_post_meta($postid, 'discourse_permalink', true) . '/wordpress.json?' . $options; $result = wpcom_vip_file_get_contents($permalink); $json = json_decode($result); if (isset($json->posts_count)) { $posts_count = $json->posts_count - 1; if ($posts_count < 0) { $posts_count = 0; } delete_post_meta($postid, 'discourse_comments_count'); add_post_meta($postid, 'discourse_comments_count', $posts_count, true); delete_post_meta($postid, 'discourse_comments_raw'); add_post_meta($postid, 'discourse_comments_raw', esc_sql($result), true); delete_post_meta($postid, 'discourse_last_sync'); add_post_meta($postid, 'discourse_last_sync', $time, true); } } delete_transient('discourse_sync_lock'); } } }
function mf_send_hipchat_notification($message = 'Default Message', $from = 'MakeBot') { $base = 'https://api.hipchat.com/v1/rooms/message'; $auth_token = '9f4f9113e8eeb3754da520d295ca59'; $room = 198932; $notify = 1; $opts = array('auth_token' => $auth_token, 'room_id' => $room, 'from' => $from, 'notify' => $notify, 'message' => urlencode($message), 'color' => 'green'); $url = add_query_arg($opts, $base); $json = wpcom_vip_file_get_contents($url); }
</a> <header id="masthead" class="site-header" role="banner"> <div id="masthead-wrapper"> <div class="site-branding"> <?php if (function_exists('jetpack_the_site_logo') && jetpack_the_site_logo()) { jetpack_the_site_logo(); } else { ?> <a href="<?php echo esc_url(home_url('/')); ?> " rel="home"><?php echo wpcom_vip_file_get_contents(esc_url(get_template_directory_uri()) . '/assets/svg/smittenkitchen.svg'); ?> </a> <?php } if (is_front_page() && is_home()) { ?> <h1 class="site-title"><a href="<?php echo esc_url(home_url('/')); ?> " rel="home"><?php bloginfo('name'); ?> </a></h1> <?php } else {