/** * 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; }
/** * Prints step 2 for Network installation process. * * @since 3.0.0 */ function network_step2($errors = false) { global $base, $nxtdb; $hostname = get_clean_basedomain(); if (!isset($base)) { $base = trailingslashit(stripslashes(dirname(dirname($_SERVER['SCRIPT_NAME'])))); } // Wildcard DNS message. if (is_nxt_error($errors)) { echo '<div class="error">' . $errors->get_error_message() . '</div>'; } if ($_POST) { if (allow_subdomain_install()) { $subdomain_install = allow_subdirectory_install() ? !empty($_POST['subdomain_install']) : true; } else { $subdomain_install = false; } } else { if (is_multisite()) { $subdomain_install = is_subdomain_install(); ?> <p><?php _e('The original configuration steps are shown here for reference.'); ?> </p> <?php } else { $subdomain_install = (bool) $nxtdb->get_var("SELECT meta_value FROM {$nxtdb->sitemeta} WHERE site_id = 1 AND meta_key = 'subdomain_install'"); ?> <div class="error"><p><strong><?php _e('Warning:'); ?> </strong> <?php _e('An existing NXTClass network was detected.'); ?> </p></div> <p><?php _e('Please complete the configuration steps. To create a new network, you will need to empty or remove the network database tables.'); ?> </p> <?php } } if ($_POST || !is_multisite()) { ?> <h3><?php esc_html_e('Enabling the Network'); ?> </h3> <p><?php _e('Complete the following steps to enable the features for creating a network of sites.'); ?> </p> <div class="updated inline"><p><?php if (file_exists(ABSPATH . '.htaccess')) { printf(__('<strong>Caution:</strong> We recommend you back up your existing <code>nxt-config.php</code> and <code>%s</code> files.'), '.htaccess'); } elseif (file_exists(ABSPATH . 'web.config')) { printf(__('<strong>Caution:</strong> We recommend you back up your existing <code>nxt-config.php</code> and <code>%s</code> files.'), 'web.config'); } else { _e('<strong>Caution:</strong> We recommend you back up your existing <code>nxt-config.php</code> file.'); } ?> </p></div> <?php } ?> <ol> <li><p><?php printf(__('Create a <code>blogs.dir</code> directory at <code>%s/blogs.dir</code>. This directory is used to store uploaded media for your additional sites and must be writeable by the web server.'), nxt_CONTENT_DIR); if (nxt_CONTENT_DIR != ABSPATH . 'nxt-content') { echo ' <strong>' . __('Warning:') . ' ' . __('Networks may not be fully compatible with custom nxt-content directories.') . '</strong>'; } ?> </p></li> <li><p><?php printf(__('Add the following to your <code>nxt-config.php</code> file in <code>%s</code> <strong>above</strong> the line reading <code>/* That’s all, stop editing! Happy blogging. */</code>:'), ABSPATH); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="7"> define( 'MULTISITE', true ); define( 'SUBDOMAIN_INSTALL', <?php echo $subdomain_install ? 'true' : 'false'; ?> ); $base = '<?php echo $base; ?> '; define( 'DOMAIN_CURRENT_SITE', '<?php echo $hostname; ?> ' ); define( 'PATH_CURRENT_SITE', '<?php echo $base; ?> ' ); define( 'SITE_ID_CURRENT_SITE', 1 ); define( 'BLOG_ID_CURRENT_SITE', 1 );</textarea> <?php $keys_salts = array('AUTH_KEY' => '', 'SECURE_AUTH_KEY' => '', 'LOGGED_IN_KEY' => '', 'NONCE_KEY' => '', 'AUTH_SALT' => '', 'SECURE_AUTH_SALT' => '', 'LOGGED_IN_SALT' => '', 'NONCE_SALT' => ''); foreach ($keys_salts as $c => $v) { if (defined($c)) { unset($keys_salts[$c]); } } if (!empty($keys_salts)) { $keys_salts_str = ''; $from_api = nxt_remote_get('https://api.nxtclass.org/secret-key/1.1/salt/'); if (is_nxt_error($from_api)) { foreach ($keys_salts as $c => $v) { $keys_salts_str .= "\ndefine( '{$c}', '" . nxt_generate_password(64, true, true) . "' );"; } } else { $from_api = explode("\n", nxt_remote_retrieve_body($from_api)); foreach ($keys_salts as $c => $v) { $keys_salts_str .= "\ndefine( '{$c}', '" . substr(array_shift($from_api), 28, 64) . "' );"; } } $num_keys_salts = count($keys_salts); ?> <p><?php echo _n('This unique authentication key is also missing from your <code>nxt-config.php</code> file.', 'These unique authentication keys are also missing from your <code>nxt-config.php</code> file.', $num_keys_salts); ?> <?php _e('To make your installation more secure, you should also add:'); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $num_keys_salts; ?> "><?php echo esc_textarea($keys_salts_str); ?> </textarea> <?php } ?> </li> <?php if (iis7_supports_permalinks()) { if ($subdomain_install) { $web_config_file = '<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="NXTClass Rule 1" stopProcessing="true"> <match url="^index\\.php$" ignoreCase="false" /> <action type="None" /> </rule> <rule name="NXTClass Rule 2" stopProcessing="true"> <match url="^files/(.+)" ignoreCase="false" /> <action type="Rewrite" url="nxt-includes/ms-files.php?file={R:1}" appendQueryString="false" /> </rule> <rule name="NXTClass Rule 3" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions logicalGrouping="MatchAny"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> </conditions> <action type="None" /> </rule> <rule name="NXTClass Rule 4" stopProcessing="true"> <match url="." ignoreCase="false" /> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>'; } else { $web_config_file = '<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="NXTClass Rule 1" stopProcessing="true"> <match url="^index\\.php$" ignoreCase="false" /> <action type="None" /> </rule> <rule name="NXTClass Rule 2" stopProcessing="true"> <match url="^([_0-9a-zA-Z-]+/)?files/(.+)" ignoreCase="false" /> <action type="Rewrite" url="nxt-includes/ms-files.php?file={R:2}" appendQueryString="false" /> </rule> <rule name="NXTClass Rule 3" stopProcessing="true"> <match url="^([_0-9a-zA-Z-]+/)?nxt-admin$" ignoreCase="false" /> <action type="Redirect" url="{R:1}nxt-admin/" redirectType="Permanent" /> </rule> <rule name="NXTClass Rule 4" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions logicalGrouping="MatchAny"> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" /> </conditions> <action type="None" /> </rule> <rule name="NXTClass Rule 5" stopProcessing="true"> <match url="^[_0-9a-zA-Z-]+/(nxt-(content|admin|includes).*)" ignoreCase="false" /> <action type="Rewrite" url="{R:1}" /> </rule> <rule name="NXTClass Rule 6" stopProcessing="true"> <match url="^([_0-9a-zA-Z-]+/)?(.*\\.php)$" ignoreCase="false" /> <action type="Rewrite" url="{R:2}" /> </rule> <rule name="NXTClass Rule 7" stopProcessing="true"> <match url="." ignoreCase="false" /> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration>'; } ?> <li><p><?php printf(__('Add the following to your <code>web.config</code> file in <code>%s</code>, replacing other NXTClass rules:'), ABSPATH); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="20"> <?php echo esc_textarea($web_config_file); ?> </textarea></li> </ol> <?php } else { // end iis7_supports_permalinks(). construct an htaccess file instead: $htaccess_file = 'RewriteEngine On RewriteBase ' . $base . ' RewriteRule ^index\\.php$ - [L] # uploaded files RewriteRule ^' . ($subdomain_install ? '' : '([_0-9a-zA-Z-]+/)?') . 'files/(.+) nxt-includes/ms-files.php?file=$' . ($subdomain_install ? 1 : 2) . ' [L]' . "\n"; if (!$subdomain_install) { $htaccess_file .= "\n# add a trailing slash to /nxt-admin\n" . 'RewriteRule ^([_0-9a-zA-Z-]+/)?nxt-admin$ $1nxt-admin/ [R=301,L]' . "\n"; } $htaccess_file .= "\n" . 'RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L]'; // @todo custom content dir. if (!$subdomain_install) { $htaccess_file .= "\nRewriteRule ^[_0-9a-zA-Z-]+/(nxt-(content|admin|includes).*) \$1 [L]\nRewriteRule ^[_0-9a-zA-Z-]+/(.*\\.php)\$ \$1 [L]"; } $htaccess_file .= "\nRewriteRule . index.php [L]"; ?> <li><p><?php printf(__('Add the following to your <code>.htaccess</code> file in <code>%s</code>, replacing other NXTClass rules:'), ABSPATH); ?> </p> <textarea class="code" readonly="readonly" cols="100" rows="<?php echo $subdomain_install ? 11 : 16; ?> "> <?php echo esc_textarea($htaccess_file); ?> </textarea></li> </ol> <?php } // end IIS/Apache code branches. if (!is_multisite()) { ?> <p><?php printf(__('Once you complete these steps, your network is enabled and configured. You will have to log in again.')); ?> <a href="<?php echo esc_url(site_url('nxt-login.php')); ?> "><?php _e('Log In'); ?> </a></p> <?php } }
/** * Opens a remote file using the NXTClass API or Snoopy * @since 3.0 * @param $url The URL to open * @param $method get or post * @param $postData An array with key=>value paris * @param $timeout Timeout for the request, by default 10 * @return mixed False on error, the body of the response on success */ function RemoteOpen($url, $method = 'get', $postData = null, $timeout = 10) { global $nxt_version; //Before nxt 2.7, nxt_remote_fopen was quite crappy so Snoopy was favoured. if (floatval($nxt_version) < 2.7) { if (!file_exists(ABSPATH . 'nxt-includes/class-snoopy.php')) { trigger_error('Snoopy Web Request failed: Snoopy not found.', E_USER_NOTICE); return false; //Hoah? } require_once ABSPATH . 'nxt-includes/class-snoopy.php'; $s = new Snoopy(); $s->read_timeout = $timeout; if ($method == 'get') { $s->fetch($url); } else { $s->submit($url, $postData); } if ($s->status != "200") { trigger_error('Snoopy Web Request failed: Status: ' . $s->status . "; Content: " . htmlspecialchars($s->results), E_USER_NOTICE); } return $s->results; } else { $options = array(); $options['timeout'] = $timeout; if ($method == 'get') { $response = nxt_remote_get($url, $options); } else { $response = nxt_remote_post($url, array_merge($options, array('body' => $postData))); } if (is_nxt_error($response)) { $errs = $response->get_error_messages(); $errs = htmlspecialchars(implode('; ', $errs)); trigger_error('nxt HTTP API Web Request failed: ' . $errs, E_USER_NOTICE); return false; } return $response['body']; } return false; }
/** * Check NXTClass version against the newest version. * * The NXTClass version, PHP version, and Locale is sent. Checks against the * NXTClass server at api.nxtclass.org server. Will only check if NXTClass * isn't installing. * * @package NXTClass * @since 2.3.0 * @uses $nxt_version Used to check against the newest NXTClass version. * * @return mixed Returns null if update is unsupported. Returns false if check is too soon. */ function nxt_version_check() { if (defined('nxt_INSTALLING')) { return; } global $nxtdb, $nxt_local_package; include ABSPATH . nxtINC . '/version.php'; // include an unmodified $nxt_version $php_version = phpversion(); $current = get_site_transient('update_core'); if (!is_object($current)) { $current = new stdClass(); $current->updates = array(); $current->version_checked = $nxt_version; } $locale = apply_filters('core_version_check_locale', get_locale()); // Update last_checked for current to prevent multiple blocking requests if request hangs $current->last_checked = time(); set_site_transient('update_core', $current); if (method_exists($nxtdb, 'db_version')) { $mysql_version = preg_replace('/[^0-9.].*/', '', $nxtdb->db_version()); } else { $mysql_version = 'N/A'; } if (is_multisite()) { $user_count = get_user_count(); $num_blogs = get_blog_count(); $nxt_install = network_site_url(); $multisite_enabled = 1; } else { $user_count = count_users(); $multisite_enabled = 0; $num_blogs = 1; $nxt_install = home_url('/'); } $query = array('version' => $nxt_version, 'php' => $php_version, 'locale' => $locale, 'mysql' => $mysql_version, 'local_package' => isset($nxt_local_package) ? $nxt_local_package : '', 'blogs' => $num_blogs, 'users' => $user_count['total_users'], 'multisite_enabled' => $multisite_enabled); $url = 'http://api.nxtclass.org/core/version-check/1.6/?' . http_build_query($query, null, '&'); $options = array('timeout' => defined('DOING_CRON') && DOING_CRON ? 30 : 3, 'user-agent' => 'NXTClass/' . $nxt_version . '; ' . home_url('/'), 'headers' => array('nxt_install' => $nxt_install, 'nxt_blog' => home_url('/'))); $response = nxt_remote_get($url, $options); if (is_nxt_error($response) || 200 != nxt_remote_retrieve_response_code($response)) { return false; } $body = trim(nxt_remote_retrieve_body($response)); if (!($body = maybe_unserialize($body))) { return false; } if (!isset($body['offers'])) { return false; } $offers = $body['offers']; foreach ($offers as &$offer) { foreach ($offer as $offer_key => $value) { if ('packages' == $offer_key) { $offer['packages'] = (object) array_intersect_key(array_map('esc_url', $offer['packages']), array_fill_keys(array('full', 'no_content', 'new_bundled', 'partial'), '')); } elseif ('download' == $offer_key) { $offer['download'] = esc_url($value); } else { $offer[$offer_key] = esc_html($value); } } $offer = (object) array_intersect_key($offer, array_fill_keys(array('response', 'download', 'locale', 'packages', 'current', 'php_version', 'mysql_version', 'new_bundled', 'partial_version'), '')); } $updates = new stdClass(); $updates->updates = $offers; $updates->last_checked = time(); $updates->version_checked = $nxt_version; set_site_transient('update_core', $updates); }
/** * 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; }
do_action('after_db_upgrade'); } elseif (get_option('db_version') != $nxt_db_version && empty($_POST)) { if (!is_multisite()) { nxt_redirect(admin_url('upgrade.php?_nxt_http_referer=' . urlencode(stripslashes($_SERVER['REQUEST_URI'])))); exit; } elseif (apply_filters('do_mu_upgrade', true)) { /** * On really small MU installs run the upgrader every time, * else run it less often to reduce load. * * @since 2.8.4b */ $c = get_blog_count(); if ($c <= 50 || $c > 50 && mt_rand(0, (int) ($c / 50)) == 1) { require_once ABSPATH . nxtINC . '/http.php'; $response = nxt_remote_get(admin_url('upgrade.php?step=1'), array('timeout' => 120, 'httpversion' => '1.1')); do_action('after_mu_upgrade', $response); unset($response); } unset($c); } } require_once ABSPATH . 'nxt-admin/includes/admin.php'; auth_redirect(); nocache_headers(); // Schedule trash collection if (!nxt_next_scheduled('nxt_scheduled_delete') && !defined('nxt_INSTALLING')) { nxt_schedule_event(time(), 'daily', 'nxt_scheduled_delete'); } set_screen_options(); $date_format = get_option('date_format');
/** * 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; }
require_once ABSPATH . nxtINC . '/plugin.php'; require_once ABSPATH . nxtINC . '/l10n.php'; require_once ABSPATH . nxtINC . '/pomo/translations.php'; if (!$no_api) { require_once ABSPATH . nxtINC . '/class-http.php'; require_once ABSPATH . nxtINC . '/http.php'; nxt_fix_server_vars(); /**#@+ * @ignore */ function get_bloginfo() { return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . str_replace($_SERVER['PHP_SELF'], '/nxt-admin/setup-config.php', ''); } /**#@-*/ $secret_keys = nxt_remote_get('https://api.nxtclass.org/secret-key/1.1/salt/'); } if ($no_api || is_nxt_error($secret_keys)) { $secret_keys = array(); require_once ABSPATH . nxtINC . '/pluggable.php'; for ($i = 0; $i < 8; $i++) { $secret_keys[] = nxt_generate_password(64, true, true); } } else { $secret_keys = explode("\n", nxt_remote_retrieve_body($secret_keys)); foreach ($secret_keys as $k => $v) { $secret_keys[$k] = substr($v, 28, 64); } } $key = 0; foreach ($configFile as $line_num => $line) {
/** * Connects using the NXTClass HTTP API to get data * * @param url - url to request * @param post - post data to pass through NXTClass * @return the raw http response **/ function http($url, $post = false) { # Return false if the token has not been set if (trim($this->token) == '') { return ''; } # Set the arguments to pass to NXTClass $args = array('sslverify' => false); # Add the optional post values if ($post) { $post .= '&service=analytics&source=google-analyticator-' . GOOGLE_ANALYTICATOR_VERSION; $args['body'] = $post; } # Set the content to form data $args['headers'] = array('Content-Type' => 'application/x-www-form-urlencoded'); # Add the token information if ($this->token) { $args['headers']['Authorization'] = 'AuthSub token="' . $this->token . '"'; } # Disable the fopen transport since it doesn't work with the Google API add_filter('use_fopen_transport', create_function('$a', 'return false;')); # Check compatibility mode settings if (get_option('ga_compatibility') == 'level1') { add_filter('use_curl_transport', create_function('$a', 'return false;')); } elseif (get_option('ga_compatibility') == 'level2') { add_filter('use_curl_transport', create_function('$a', 'return false;')); add_filter('use_streams_transport', create_function('$a', 'return false;')); } # Make the connection if ($post) { $response = nxt_remote_post($url, $args); } else { $response = nxt_remote_get($url, $args); } # Check for NXTClass error if (is_nxt_error($response)) { $this->responseHash['error'] = __('NXTClass HTTP error.', 'google-analyticator'); return ''; } # Set the message response $this->responseCode = $response['response']['code']; # Build an array of messages foreach (explode("\n", $response['body']) as $line) { if (trim($line) != '') { $pos = strpos($line, '='); if ($pos !== false) { $this->responseHash[strtolower(substr($line, 0, $pos))] = substr($line, $pos + 1); } } } # Return the body of the response return $response['body']; }
/** * HTTP request for URI to retrieve content. * * @since 1.5.1 * @uses nxt_remote_get() * * @param string $uri URI/URL of web page to retrieve. * @return bool|string HTTP content. False on failure. */ function nxt_remote_fopen($uri) { $parsed_url = @parse_url($uri); if (!$parsed_url || !is_array($parsed_url)) { return false; } $options = array(); $options['timeout'] = 10; $response = nxt_remote_get($uri, $options); if (is_nxt_error($response)) { return false; } return nxt_remote_retrieve_body($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 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); } } }
case "upgrade": $n = isset($_GET['n']) ? intval($_GET['n']) : 0; if ($n < 5) { global $nxt_db_version; update_site_option('nxtmu_upgrade_site', $nxt_db_version); } $blogs = $nxtdb->get_results("SELECT * FROM {$nxtdb->blogs} WHERE site_id = '{$nxtdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A); if (empty($blogs)) { echo '<p>' . __('All done!') . '</p>'; break; } echo "<ul>"; foreach ((array) $blogs as $details) { $siteurl = get_blog_option($details['blog_id'], 'siteurl'); echo "<li>{$siteurl}</li>"; $response = nxt_remote_get(trailingslashit($siteurl) . "nxt-admin/upgrade.php?step=upgrade_db", array('timeout' => 120, 'httpversion' => '1.1')); if (is_nxt_error($response)) { nxt_die(sprintf(__('Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>'), $siteurl, $response->get_error_message())); } do_action('after_mu_upgrade', $response); do_action('nxtmu_upgrade_site', $details['blog_id']); } echo "</ul>"; ?> <p><?php _e('If your browser doesn’t start loading the next page automatically, click this link:'); ?> <a class="button" href="upgrade.php?action=upgrade&n=<?php echo $n + 5; ?> "><?php
/** * Finds a pingback server URI based on the given URL. * * Checks the HTML for the rel="pingback" link and x-pingback headers. It does * a check for the x-pingback headers first and returns that, if available. The * check for the rel="pingback" has more overhead than just the header. * * @since 1.5.0 * * @param string $url URL to ping. * @param int $deprecated Not Used. * @return bool|string False on failure, string containing URI on success. */ function discover_pingback_server_uri($url, $deprecated = '') { if (!empty($deprecated)) { _deprecated_argument(__FUNCTION__, '2.7'); } $pingback_str_dquote = 'rel="pingback"'; $pingback_str_squote = 'rel=\'pingback\''; /** @todo Should use Filter Extension or custom preg_match instead. */ $parsed_url = parse_url($url); if (!isset($parsed_url['host'])) { // Not an URL. This should never happen. return false; } //Do not search for a pingback server on our own uploads $uploads_dir = nxt_upload_dir(); if (0 === strpos($url, $uploads_dir['baseurl'])) { return false; } $response = nxt_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0')); if (is_nxt_error($response)) { return false; } if (nxt_remote_retrieve_header($response, 'x-pingback')) { return nxt_remote_retrieve_header($response, 'x-pingback'); } // Not an (x)html, sgml, or xml page, no use going further. if (preg_match('#(image|audio|video|model)/#is', nxt_remote_retrieve_header($response, 'content-type'))) { return false; } // Now do a GET since we're going to look in the html headers (and we're sure its not a binary file) $response = nxt_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0')); if (is_nxt_error($response)) { return false; } $contents = nxt_remote_retrieve_body($response); $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote); $pingback_link_offset_squote = strpos($contents, $pingback_str_squote); if ($pingback_link_offset_dquote || $pingback_link_offset_squote) { $quote = $pingback_link_offset_dquote ? '"' : '\''; $pingback_link_offset = $quote == '"' ? $pingback_link_offset_dquote : $pingback_link_offset_squote; $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset); $pingback_href_start = $pingback_href_pos + 6; $pingback_href_end = @strpos($contents, $quote, $pingback_href_start); $pingback_server_url_len = $pingback_href_end - $pingback_href_start; $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len); // We may find rel="pingback" but an incomplete pingback URL if ($pingback_server_url_len > 0) { // We got it! return $pingback_server_url; } } return false; }
/** * 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); }