function aktt_bitly_shorten_url($url) { $parts = parse_url($url); if (!in_array($parts['host'], array('j.mp', 'bit.ly'))) { $snoop = get_snoopy(); $api_urls = array('bitly' => AKTT_BITLY_API_SHORTEN_URL, 'jmp' => AKTT_BITLY_API_SHORTEN_URL_JMP); $api = $api_urls[aktt_bitly_setting('aktt_bitly_api_url')] . '?version=' . AKTT_BITLY_API_VERSION . '&longUrl=' . urlencode($url); $login = get_option('aktt_bitly_api_login'); $key = get_option('aktt_bitly_api_key'); if (!empty($login) && !empty($key)) { $api .= '&login='******'&apiKey=' . urlencode($key) . '&history=1'; } $snoop->agent = 'Twitter Tools http://alexking.org/projects/wordpress'; $snoop->fetch($api); $result = json_decode($snoop->results); if (!empty($result->results->{$url}->shortUrl)) { $url = $result->results->{$url}->shortUrl; } } return $url; }
function id_http_query($url, $fields, $method = 'GET') { $results = ''; if (function_exists('wp_remote_get')) { // The preferred WP HTTP library is available if ('POST' == $method) { $response = wp_remote_post($url, array('body' => $fields)); if (!is_wp_error($response)) { $results = wp_remote_retrieve_body($response); id_debug_log("Successfully Sent: " . serialize($fields) . " - " . $results); } else { id_debug_log("Failed to Send: " . serialize($fields) . " - " . $response->get_error_message()); } } else { $url .= '?' . http_build_query($fields); $response = wp_remote_get($url); if (!is_wp_error($response)) { $results = wp_remote_retrieve_body($response); id_debug_log("Successfully Sent: " . serialize($fields) . " - " . $results); } else { id_debug_log("Failed to Send: " . serialize($fields) . " - " . $response->get_error_message()); } } } else { // Fall back to Snoopy $snoopy = get_snoopy(); if ('POST' == $method) { if ($snoopy->submit($url, $fields)) { $results = $snoopy->results; id_debug_log("Successfully Sent: " . serialize($fields) . " - " . $results); } else { id_debug_log("Failed to Send: " . serialize($fields) . " - " . $results); } } else { $url .= '?' . http_build_query($fields); if ($snoopy->fetch($url)) { $results = $snoopy->results; id_debug_log("Successfully Sent: " . serialize($fields) . " - " . $results); } else { id_debug_log("Failed to Send: " . serialize($fields) . " - " . $results); } } } return $results; }
function http_post_wp($url, $post_vars) { // turn the query string into an array for snoopy parse_str($post_vars); $post_vars = array(); $post_vars['hub.mode'] = $hub_mode; // PHP converts the periods to underscores $post_vars['hub.url'] = $hub_url; // more universal than curl $snoopy = get_snoopy(); $snoopy->agent = "(PubSubHubbub-Publisher-WP/1.0)"; $snoopy->submit($url, $post_vars); $response = $snoopy->results; // TODO: store the last_response. requires a litle refactoring work. $response_code = $snoopy->response_code; if ($response_code == 204) { return true; } return false; }