示例#1
0
/**
 * Retrieve plugin installer pages from NXTClass 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, nxt_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 NXTClass.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 = nxt_remote_post('http://api.nxtclass.org/plugins/info/1.0/', array('timeout' => 15, 'body' => array('action' => $action, 'request' => serialize($args))));
        if (is_nxt_error($request)) {
            $res = new nxt_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message());
        } else {
            $res = unserialize(nxt_remote_retrieve_body($request));
            if (false === $res) {
                $res = new nxt_Error('plugins_api_failed', __('An unknown error occurred.'), nxt_remote_retrieve_body($request));
            }
        }
    } elseif (!is_nxt_error($res)) {
        $res->external = true;
    }
    return apply_filters('plugins_api_result', $res, $action, $args);
}
示例#2
0
 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;
 }
示例#4
0
 /**
  * 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;
 }
示例#5
0
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;
}
示例#6
0
/**
 * 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&#8217;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 
    }
}
示例#7
0
/**
 * 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);
}
示例#8
0
/**
 * Retrieve theme installer pages from NXTClass Themes API.
 *
 * It is possible for a theme to override the Themes API result with three
 * filters. Assume this is for themes, which can extend on the Theme Info to
 * offer more choices. This is very powerful and must be used with care, when
 * overridding the filters.
 *
 * The first filter, 'themes_api_args', is for the args and gives the action as
 * the second parameter. The hook for 'themes_api_args' must ensure that an
 * object is returned.
 *
 * The second filter, 'themes_api', is the result that would be returned.
 *
 * @since 2.8.0
 *
 * @param string $action
 * @param array|object $args Optional. Arguments to serialize for the Theme Info API.
 * @return mixed
 */
function themes_api($action, $args = null)
{
    if (is_array($args)) {
        $args = (object) $args;
    }
    if (!isset($args->per_page)) {
        $args->per_page = 24;
    }
    $args = apply_filters('themes_api_args', $args, $action);
    //NOTE: Ensure that an object is returned via this filter.
    $res = apply_filters('themes_api', false, $action, $args);
    //NOTE: Allows a theme to completely override the builtin NXTClass.org API.
    if (!$res) {
        $request = nxt_remote_post('http://api.nxtclass.org/themes/info/1.0/', array('body' => array('action' => $action, 'request' => serialize($args))));
        if (is_nxt_error($request)) {
            $res = new nxt_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message());
        } else {
            $res = unserialize(nxt_remote_retrieve_body($request));
            if (!$res) {
                $res = new nxt_Error('themes_api_failed', __('An unknown error occurred.'), nxt_remote_retrieve_body($request));
            }
        }
    }
    //var_dump(array($args, $res));
    return apply_filters('themes_api_result', $res, $action, $args);
}
示例#9
0
      */
     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) {
     switch (substr($line, 0, 16)) {
         case "define('DB_NAME'":
             $configFile[$line_num] = str_replace("database_name_here", $dbname, $line);
             break;
         case "define('DB_USER'":
             $configFile[$line_num] = str_replace("'username_here'", "'{$uname}'", $line);
             break;
         case "define('DB_PASSW":
             $configFile[$line_num] = str_replace("'password_here'", "'{$passwrd}'", $line);
示例#10
0
/**
 * 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);
}
示例#11
0
/**
 * 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 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;
}
示例#13
0
/**
 * 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;
}
示例#14
0
 /**
  * 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);
 }