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); if (!empty($this->headers)) { $args['headers'] = $this->headers; } if (SIMPLEPIE_USERAGENT != $this->useragent) { //Use default nxt user agent unless custom has been specified $args['user-agent'] = $this->useragent; } $res = nxt_remote_request($url, $args); if (is_nxt_error($res)) { $this->error = 'nxt HTTP Error: ' . $res->get_error_message(); $this->success = false; } else { $this->headers = nxt_remote_retrieve_headers($res); $this->body = nxt_remote_retrieve_body($res); $this->status_code = nxt_remote_retrieve_response_code($res); } } else { if (!($this->body = file_get_contents($url))) { $this->error = 'file_get_contents could not read the file'; $this->success = false; } } }
function query() { $args = func_get_args(); $method = array_shift($args); $request = new IXR_Request($method, $args); $xml = $request->getXml(); $port = $this->port ? ":{$this->port}" : ''; $url = $this->scheme . '://' . $this->server . $port . $this->path; $args = array('headers' => array('Content-Type' => 'text/xml'), 'user-agent' => $this->useragent, 'body' => $xml); // Merge Custom headers ala #8145 foreach ($this->headers as $header => $value) { $args['headers'][$header] = $value; } if ($this->timeout !== false) { $args['timeout'] = $this->timeout; } // Now send the request if ($this->debug) { echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n"; } $response = nxt_remote_post($url, $args); if (is_nxt_error($response)) { $errno = $response->get_error_code(); $errorstr = $response->get_error_message(); $this->error = new IXR_Error(-32300, "transport error: {$errno} {$errorstr}"); return false; } if (200 != nxt_remote_retrieve_response_code($response)) { $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . nxt_remote_retrieve_response_code($response) . ')'); return false; } if ($this->debug) { echo '<pre class="ixr_response">' . htmlspecialchars(nxt_remote_retrieve_body($response)) . "\n</pre>\n\n"; } // Now parse what we've got back $this->message = new IXR_Message(nxt_remote_retrieve_body($response)); if (!$this->message->parse()) { // XML error $this->error = new IXR_Error(-32700, 'parse error. not well formed'); return false; } // Is the message a fault? if ($this->message->messageType == 'fault') { $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); return false; } // Message must be OK return true; }
/** * Gets the Pingback endpoint URI provided by a web page specified by URL * * @return string|boolean Returns the Pingback endpoint URI if found or false */ function get_endpoint_uri($url) { // First check for an X-pingback header if (!($response = nxt_remote_head($url))) { return false; } if (!($content_type = nxt_remote_retrieve_header($response, 'content-type'))) { return false; } if (preg_match('#(image|audio|video|model)/#is', $content_type)) { return false; } if ($x_pingback = nxt_remote_retrieve_header($response, 'x-pingback')) { return trim($x_pingback); } // Fall back to extracting it from the HTML link if (!($response = nxt_remote_get($url))) { return false; } if (200 !== nxt_remote_retrieve_response_code($response)) { return false; } if ('' === ($response_body = nxt_remote_retrieve_body($response))) { return false; } if (!preg_match_all('@<link([^>]+)>@im', $response_body, $response_links)) { return false; } foreach ($response_links[1] as $response_link_attributes) { $_link = array('rel' => false, 'href' => false); $response_link_attributes = preg_split('@\\s+@im', $response_link_attributes, -1, PREG_SPLIT_NO_EMPTY); foreach ($response_link_attributes as $response_link_attribute) { if ($_link['rel'] == 'pingback' && $_link['href']) { return $_link['href']; } if (strpos($response_link_attribute, '=', 1) !== false) { list($_key, $_value) = explode('=', $response_link_attribute, 2); $_link[strtolower($_key)] = trim($_value, "'\""); } } } // Fail return false; }
function nxt_credits() { global $nxt_version; $locale = get_locale(); $results = get_site_transient('nxtclass_credits_' . $locale); if (!is_array($results)) { $response = nxt_remote_get("http://api.nxtclass.org/core/credits/1.0/?version={$nxt_version}&locale={$locale}"); if (is_nxt_error($response) || 200 != nxt_remote_retrieve_response_code($response)) { return false; } $results = maybe_unserialize(nxt_remote_retrieve_body($response)); if (!is_array($results)) { return false; } set_site_transient('nxtclass_credits_' . $locale, $results, 86400); // One day } return $results; }
/** * Check theme versions against the latest versions hosted on NXTClass.org. * * A list of all themes installed in sent to nxt. Checks against the * NXTClass server at api.nxtclass.org. Will only check if NXTClass isn't * installing. * * @package NXTClass * @since 2.7.0 * @uses $nxt_version Used to notify the NXTClass version. * * @return mixed Returns null if update is unsupported. Returns false if check is too soon. */ function nxt_update_themes() { include ABSPATH . nxtINC . '/version.php'; // include an unmodified $nxt_version if (defined('nxt_INSTALLING')) { return false; } if (!function_exists('get_themes')) { require_once ABSPATH . 'nxt-includes/theme.php'; } $installed_themes = get_themes(); $last_update = get_site_transient('update_themes'); if (!is_object($last_update)) { $last_update = new stdClass(); } // Check for updated every 60 minutes if hitting update pages; else, check every 12 hours. $timeout = in_array(current_filter(), array('load-themes.php', 'load-update.php', 'load-update-core.php')) ? 3600 : 43200; $time_not_changed = isset($last_update->last_checked) && $timeout > time() - $last_update->last_checked; $themes = array(); $checked = array(); $exclude_fields = array('Template Files', 'Stylesheet Files', 'Status', 'Theme Root', 'Theme Root URI', 'Template Dir', 'Stylesheet Dir', 'Description', 'Tags', 'Screenshot'); // Put slug of current theme into request. $themes['current_theme'] = get_option('stylesheet'); foreach ((array) $installed_themes as $theme_title => $theme) { $themes[$theme['Stylesheet']] = array(); $checked[$theme['Stylesheet']] = $theme['Version']; $themes[$theme['Stylesheet']]['Name'] = $theme['Name']; $themes[$theme['Stylesheet']]['Version'] = $theme['Version']; foreach ((array) $theme as $key => $value) { if (!in_array($key, $exclude_fields)) { $themes[$theme['Stylesheet']][$key] = $value; } } } $theme_changed = false; foreach ($checked as $slug => $v) { $update_request->checked[$slug] = $v; if (!isset($last_update->checked[$slug]) || strval($last_update->checked[$slug]) !== strval($v)) { $theme_changed = true; } } if (isset($last_update->response) && is_array($last_update->response)) { foreach ($last_update->response as $slug => $update_details) { if (!isset($checked[$slug])) { $theme_changed = true; break; } } } if ($time_not_changed && !$theme_changed) { return false; } // Update last_checked for current to prevent multiple blocking requests if request hangs $last_update->last_checked = time(); set_site_transient('update_themes', $last_update); $options = array('timeout' => defined('DOING_CRON') && DOING_CRON ? 30 : 3, 'body' => array('themes' => serialize($themes)), 'user-agent' => 'NXTClass/' . $nxt_version . '; ' . get_bloginfo('url')); $raw_response = nxt_remote_post('http://api.nxtclass.org/themes/update-check/1.0/', $options); if (is_nxt_error($raw_response) || 200 != nxt_remote_retrieve_response_code($raw_response)) { return false; } $new_update = new stdClass(); $new_update->last_checked = time(); $new_update->checked = $checked; $response = unserialize(nxt_remote_retrieve_body($raw_response)); if (false !== $response) { $new_update->response = $response; } set_site_transient('update_themes', $new_update); }
/** * populate network settings * * @since 3.0.0 * * @param int $network_id id of network to populate * @return bool|nxt_Error True on success, or nxt_Error on warning (with the install otherwise successful, * so the error code must be checked) or failure. */ function populate_network($network_id = 1, $domain = '', $email = '', $site_name = '', $path = '/', $subdomain_install = false) { global $nxtdb, $current_site, $nxt_db_version, $nxt_rewrite; $errors = new nxt_Error(); if ('' == $domain) { $errors->add('empty_domain', __('You must provide a domain name.')); } if ('' == $site_name) { $errors->add('empty_sitename', __('You must provide a name for your network of sites.')); } // check for network collision if ($network_id == $nxtdb->get_var($nxtdb->prepare("SELECT id FROM {$nxtdb->site} WHERE id = %d", $network_id))) { $errors->add('siteid_exists', __('The network already exists.')); } $site_user = get_user_by('email', $email); if (!is_email($email)) { $errors->add('invalid_email', __('You must provide a valid e-mail address.')); } if ($errors->get_error_code()) { return $errors; } // set up site tables $template = get_option('template'); $stylesheet = get_option('stylesheet'); $allowed_themes = array($stylesheet => true); if ($template != $stylesheet) { $allowed_themes[$template] = true; } if (nxt_DEFAULT_THEME != $stylesheet && nxt_DEFAULT_THEME != $template) { $allowed_themes[nxt_DEFAULT_THEME] = true; } if (1 == $network_id) { $nxtdb->insert($nxtdb->site, array('domain' => $domain, 'path' => $path)); $network_id = $nxtdb->insert_id; } else { $nxtdb->insert($nxtdb->site, array('domain' => $domain, 'path' => $path, 'id' => $network_id)); } if (!is_multisite()) { $site_admins = array($site_user->user_login); $users = get_users(array('fields' => array('ID', 'user_login'))); if ($users) { foreach ($users as $user) { if (is_super_admin($user->ID) && !in_array($user->user_login, $site_admins)) { $site_admins[] = $user->user_login; } } } } else { $site_admins = get_site_option('site_admins'); } $welcome_email = __('Dear User, Your new SITE_NAME site has been successfully set up at: BLOG_URL You can log in to the administrator account with the following information: Username: USERNAME Password: PASSWORD Log in here: BLOG_URLnxt-login.php We hope you enjoy your new site. Thanks! --The SITE_NAME Team'); $sitemeta = array('site_name' => $site_name, 'admin_email' => $site_user->user_email, 'admin_user_id' => $site_user->ID, 'registration' => 'none', 'upload_filetypes' => 'jpg jpeg png gif mp3 mov avi wmv midi mid pdf', 'blog_upload_space' => 10, 'fileupload_maxk' => 1500, 'site_admins' => $site_admins, 'allowedthemes' => $allowed_themes, 'illegal_names' => array('www', 'web', 'root', 'admin', 'main', 'invite', 'administrator', 'files'), 'nxtmu_upgrade_site' => $nxt_db_version, 'welcome_email' => $welcome_email, 'first_post' => __('Welcome to <a href="SITE_URL">SITE_NAME</a>. This is your first post. Edit or delete it, then start blogging!'), 'siteurl' => get_option('siteurl') . '/', 'add_new_users' => '0', 'upload_space_check_disabled' => '0', 'subdomain_install' => intval($subdomain_install), 'global_terms_enabled' => global_terms_enabled() ? '1' : '0', 'initial_db_version' => get_option('initial_db_version'), 'active_sitewide_plugins' => array()); if (!$subdomain_install) { $sitemeta['illegal_names'][] = 'blog'; } $insert = ''; foreach ($sitemeta as $meta_key => $meta_value) { $meta_key = $nxtdb->escape($meta_key); if (is_array($meta_value)) { $meta_value = serialize($meta_value); } $meta_value = $nxtdb->escape($meta_value); if (!empty($insert)) { $insert .= ', '; } $insert .= "( {$network_id}, '{$meta_key}', '{$meta_value}')"; } $nxtdb->query("INSERT INTO {$nxtdb->sitemeta} ( site_id, meta_key, meta_value ) VALUES " . $insert); $current_site->domain = $domain; $current_site->path = $path; $current_site->site_name = ucfirst($domain); if (!is_multisite()) { $nxtdb->insert($nxtdb->blogs, array('site_id' => $network_id, 'domain' => $domain, 'path' => $path, 'registered' => current_time('mysql'))); $blog_id = $nxtdb->insert_id; update_user_meta($site_user->ID, 'source_domain', $domain); update_user_meta($site_user->ID, 'primary_blog', $blog_id); if (!($upload_path = get_option('upload_path'))) { $upload_path = substr(nxt_CONTENT_DIR, strlen(ABSPATH)) . '/uploads'; update_option('upload_path', $upload_path); } update_option('fileupload_url', get_option('siteurl') . '/' . $upload_path); } if ($subdomain_install) { update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/'); } else { update_option('permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/'); } $nxt_rewrite->flush_rules(); if ($subdomain_install) { $vhost_ok = false; $errstr = ''; $hostname = substr(md5(time()), 0, 6) . '.' . $domain; // Very random hostname! $page = nxt_remote_get('http://' . $hostname, array('timeout' => 5, 'httpversion' => '1.1')); if (is_nxt_error($page)) { $errstr = $page->get_error_message(); } elseif (200 == nxt_remote_retrieve_response_code($page)) { $vhost_ok = true; } if (!$vhost_ok) { $msg = '<p><strong>' . __('Warning! Wildcard DNS may not be configured correctly!') . '</strong></p>'; $msg .= '<p>' . sprintf(__('The installer attempted to contact a random hostname (<code>%1$s</code>) on your domain.'), $hostname); if (!empty($errstr)) { $msg .= ' ' . sprintf(__('This resulted in an error message: %s'), '<code>' . $errstr . '</code>'); } $msg .= '</p>'; $msg .= '<p>' . __('To use a subdomain configuration, you must have a wildcard entry in your DNS. This usually means adding a <code>*</code> hostname record pointing at your web server in your DNS configuration tool.') . '</p>'; $msg .= '<p>' . __('You can still use your site but any subdomain you create may not be accessible. If you know your DNS is correct, ignore this message.') . '</p>'; return new nxt_Error('no_wildcard_dns', $msg); } } return true; }
/** * Downloads a url to a local temporary file using the NXTClass HTTP Class. * Please note, That the calling function must unlink() the file. * * @since 2.5.0 * * @param string $url the URL of the file to download * @param int $timeout The timeout for the request to download the file default 300 seconds * @return mixed nxt_Error on failure, string Filename on success. */ function download_url($url, $timeout = 300) { //WARNING: The file is not automatically deleted, The script must unlink() the file. if (!$url) { return new nxt_Error('http_no_url', __('Invalid URL Provided.')); } $tmpfname = nxt_tempnam($url); if (!$tmpfname) { return new nxt_Error('http_no_file', __('Could not create Temporary file.')); } $response = nxt_remote_get($url, array('timeout' => $timeout, 'stream' => true, 'filename' => $tmpfname)); if (is_nxt_error($response)) { unlink($tmpfname); return $response; } if (200 != nxt_remote_retrieve_response_code($response)) { unlink($tmpfname); return new nxt_Error('http_404', trim(nxt_remote_retrieve_response_message($response))); } return $tmpfname; }
/** * Perform a HTTP HEAD or GET request. * * If $file_path is a writable filename, this will do a GET request and write * the file to that path. * * @since 2.5.0 * * @param string $url URL to fetch. * @param string|bool $file_path Optional. File path to write request to. * @param int $red (private) The number of Redirects followed, Upon 5 being hit, returns false. * @return bool|string False on failure and string of headers if HEAD request. */ function nxt_get_http($url, $file_path = false, $red = 1) { @set_time_limit(60); if ($red > 5) { return false; } $options = array(); $options['redirection'] = 5; if (false == $file_path) { $options['method'] = 'HEAD'; } else { $options['method'] = 'GET'; } $response = nxt_remote_request($url, $options); if (is_nxt_error($response)) { return false; } $headers = nxt_remote_retrieve_headers($response); $headers['response'] = nxt_remote_retrieve_response_code($response); // nxt_HTTP no longer follows redirects for HEAD requests. if ('HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset($headers['location'])) { return nxt_get_http($headers['location'], $file_path, ++$red); } if (false == $file_path) { return $headers; } // GET request - write it to the supplied filename $out_fp = fopen($file_path, 'w'); if (!$out_fp) { return $headers; } fwrite($out_fp, nxt_remote_retrieve_body($response)); fclose($out_fp); clearstatcache(); return $headers; }
/** * Check if the user needs a browser update * * @since 3.2.0 * * @return array|bool False on failure, array of browser data on success. */ function nxt_check_browser_version() { if (empty($_SERVER['HTTP_USER_AGENT'])) { return false; } $key = md5($_SERVER['HTTP_USER_AGENT']); if (false === ($response = get_site_transient('browser_' . $key))) { global $nxt_version; $options = array('body' => array('useragent' => $_SERVER['HTTP_USER_AGENT']), 'user-agent' => 'NXTClass/' . $nxt_version . '; ' . get_bloginfo('url')); $response = nxt_remote_post('http://api.nxtclass.org/core/browse-happy/1.0/', $options); if (is_nxt_error($response) || 200 != nxt_remote_retrieve_response_code($response)) { return false; } /** * Response should be an array with: * 'name' - string - A user friendly browser name * 'version' - string - The most recent version of the browser * 'current_version' - string - The version of the browser the user is using * 'upgrade' - boolean - Whether the browser needs an upgrade * 'insecure' - boolean - Whether the browser is deemed insecure * 'upgrade_url' - string - The url to visit to upgrade * 'img_src' - string - An image representing the browser * 'img_src_ssl' - string - An image (over SSL) representing the browser */ $response = unserialize(nxt_remote_retrieve_body($response)); if (!$response) { return false; } set_site_transient('browser_' . $key, $response, 604800); // cache for 1 week } return $response; }
function woo_presstrends() { if (!defined('WOO_PRESSTRENDS_THEMEKEY')) { return; } // Add your PressTrends API Keys $api_key = 'ypvilflyjb7yyht8as1u2k0no3rxbgl2p4a9'; $auth = WOO_PRESSTRENDS_THEMEKEY; // Check if we have cached data. $data = get_transient('woo_presstrends_data'); if (!$data || $data == '') { // Don't edit below $api_base = 'http://api.presstrends.io/index.php/api/sites/add/auth/'; // Run setup $url = $api_base . $auth . '/api/' . $api_key . '/'; $data = array(); $count_posts = nxt_count_posts(); $comments_count = nxt_count_comments(); $theme_data = get_theme_data(get_template_directory() . '/style.css'); $plugin_count = count(get_option('active_plugins')); $data['url'] = stripslashes(str_replace(array('http://', '/', ':'), '', site_url())); $data['posts'] = $count_posts->publish; $data['comments'] = $comments_count->total_comments; $data['theme_version'] = $theme_data['Version']; $data['theme_name'] = str_replace(' ', '', get_bloginfo('name')); $data['plugins'] = $plugin_count; foreach ($data as $k => $v) { $url .= $k . '/' . $v . '/'; } // Perform the remote request. $response = nxt_remote_get($url); if (is_nxt_error($response) || nxt_remote_retrieve_response_code($response) != 200) { // Silence is golden. } else { set_transient('woo_presstrends_data', $data, 60 * 60 * 24); } } }
function et_check_themes_updates($update_transient) { global $nxt_version; if (!isset($update_transient->checked)) { return $update_transient; } else { $themes = $update_transient->checked; } $send_to_api = array('action' => 'check_theme_updates', 'installed_themes' => $themes); $options = array('timeout' => defined('DOING_CRON') && DOING_CRON ? 30 : 3, 'body' => $send_to_api, 'user-agent' => 'NXTClass/' . $nxt_version . '; ' . home_url()); $theme_request = nxt_remote_post('http://www.elegantthemes.com/api/api.php', $options); if (!is_nxt_error($theme_request) && nxt_remote_retrieve_response_code($theme_request) == 200) { $theme_response = unserialize(nxt_remote_retrieve_body($theme_request)); if (!empty($theme_response)) { $update_transient->response = array_merge(!empty($update_transient->response) ? $update_transient->response : array(), $theme_response); $last_update->checked = $themes; $last_update->response = $theme_response; } } $last_update->last_checked = time(); set_site_transient('et_update_themes', $last_update); return $update_transient; }
function woo_presstrends() { if (!defined('WOO_PRESSTRENDS_THEMEKEY')) { return; } // Add your PressTrends API Keys $api_key = 'ypvilflyjb7yyht8as1u2k0no3rxbgl2p4a9'; $auth = WOO_PRESSTRENDS_THEMEKEY; // Check if we have cached data. $data = get_transient('woo_presstrends_data'); if (!$data || $data == '') { global $nxtdb; // Don't edit below $api_base = 'http://api.presstrends.io/index.php/api/sites/add/auth/'; // Run setup $url = $api_base . $auth . '/api/' . $api_key . '/'; $data = array(); $count_posts = nxt_count_posts(); $count_pages = nxt_count_posts('page'); $comments_count = nxt_count_comments(); $theme_data = get_theme_data(get_template_directory() . '/style.css'); $plugin_count = count(get_option('active_plugins')); $data['url'] = stripslashes(str_replace(array('http://', '/', ':'), '', site_url())); $data['posts'] = $count_posts->publish; $data['comments'] = $comments_count->total_comments; $data['theme_version'] = $theme_data['Version']; $data['theme_name'] = $theme_data['Name']; $data['site_name'] = str_replace(' ', '', get_bloginfo('name')); $data['plugins'] = $plugin_count; $all_plugins = get_plugins(); $plugin_name = ''; foreach ($all_plugins as $plugin_file => $plugin_data) { $plugin_name .= $plugin_data['Name']; $plugin_name .= '&'; } $posts_with_comments = $nxtdb->get_var("SELECT COUNT(*) FROM {$nxtdb->prefix}posts WHERE post_type='post' AND comment_count > 0"); $comments_to_posts = number_format($posts_with_comments / $count_posts->publish * 100, 0, '.', ''); $pingback_result = $nxtdb->get_var('SELECT COUNT(comment_ID) FROM ' . $nxtdb->comments . ' WHERE comment_type = "pingback"'); $data['posts'] = $count_posts->publish; $data['pages'] = $count_pages->publish; $data['comments'] = $comments_count->total_comments; $data['approved'] = $comments_count->approved; $data['spam'] = $comments_count->spam; $data['pingbacks'] = $pingback_result; $data['post_conversion'] = $comments_to_posts; $data['plugin'] = urlencode($plugin_name); $data['nxtversion'] = get_bloginfo('version'); foreach ($data as $k => $v) { $url .= $k . '/' . $v . '/'; } // Perform the remote request. $response = nxt_remote_get($url); if (is_nxt_error($response) || nxt_remote_retrieve_response_code($response) != 200) { // Silence is golden. } else { set_transient('woo_presstrends_data', $data, 60 * 60 * 24); } } }
/** * Fetches result from an oEmbed provider for a specific format and complete provider URL * * @since 3.0.0 * @access private * @param string $provider_url_with_args URL to the provider with full arguments list (url, maxheight, etc.) * @param string $format Format to use * @return bool|object False on failure, otherwise the result in the form of an object. */ function _fetch_with_format($provider_url_with_args, $format) { $provider_url_with_args = add_query_arg('format', $format, $provider_url_with_args); $response = nxt_remote_get($provider_url_with_args); if (501 == nxt_remote_retrieve_response_code($response)) { return new nxt_Error('not-implemented'); } if (!($body = nxt_remote_retrieve_body($response))) { return false; } $parse_method = "_parse_{$format}"; return $this->{$parse_method}($body); }