Exemple #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);
}
 function query()
 {
     $args = func_get_args();
     $method = array_shift($args);
     $request = new IXR_Request($method, $args);
     $xml = $request->getXml();
     $url = $this->scheme . '://' . $this->server . ':' . $this->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} {$errstr}");
         return false;
     }
     $code = $response['response']['code'];
     if ($code != 200) {
         $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$code})");
         return false;
     }
     if ($this->debug) {
         echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n";
     }
     // Now parse what we've got back
     $this->message = new IXR_Message($response['body']);
     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;
 }
 /**
  * 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;
 }
Exemple #4
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);
}
Exemple #5
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);
}
Exemple #6
0
/**
 * Send request to run cron through HTTP request that doesn't halt page loading.
 *
 * @since 2.1.0
 *
 * @return null Cron could not be spawned, because it is not needed to run.
 */
function spawn_cron($local_time = 0)
{
    if (!$local_time) {
        $local_time = time();
    }
    if (defined('DOING_CRON') || isset($_GET['doing_nxt_cron'])) {
        return;
    }
    /*
     * multiple processes on multiple web servers can run this code concurrently
     * try to make this as atomic as possible by setting doing_cron switch
     */
    $lock = get_transient('doing_cron');
    if ($lock > $local_time + 10 * 60) {
        $lock = 0;
    }
    // don't run if another process is currently running it or more than once every 60 sec.
    if ($lock + nxt_CRON_LOCK_TIMEOUT > $local_time) {
        return;
    }
    //sanity check
    $crons = _get_cron_array();
    if (!is_array($crons)) {
        return;
    }
    $keys = array_keys($crons);
    if (isset($keys[0]) && $keys[0] > $local_time) {
        return;
    }
    if (defined('ALTERNATE_nxt_CRON') && ALTERNATE_nxt_CRON) {
        if (!empty($_POST) || defined('DOING_AJAX')) {
            return;
        }
        $doing_nxt_cron = $local_time;
        set_transient('doing_cron', $doing_nxt_cron);
        ob_start();
        nxt_redirect(add_query_arg('doing_nxt_cron', $doing_nxt_cron, stripslashes($_SERVER['REQUEST_URI'])));
        echo ' ';
        // flush any buffers and send the headers
        while (@ob_end_flush()) {
        }
        flush();
        nxt_DEBUG ? include_once ABSPATH . 'nxt-cron.php' : @(include_once ABSPATH . 'nxt-cron.php');
        return;
    }
    $doing_nxt_cron = $local_time;
    set_transient('doing_cron', $doing_nxt_cron);
    $cron_url = get_option('siteurl') . '/nxt-cron.php?doing_nxt_cron=' . $doing_nxt_cron;
    nxt_remote_post($cron_url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true)));
}
/**
 * Send request to run cron through HTTP request that doesn't halt page loading.
 *
 * @since 2.1.0
 *
 * @return null Cron could not be spawned, because it is not needed to run.
 */
function spawn_cron($local_time = 0)
{
    if (!$local_time) {
        $local_time = time();
    }
    if (defined('DOING_CRON') || isset($_GET['doing_nxt_cron'])) {
        return;
    }
    /*
     * do not even start the cron if local server timer has drifted
     * such as due to power failure, or misconfiguration
     */
    $timer_accurate = check_server_timer($local_time);
    if (!$timer_accurate) {
        return;
    }
    /*
     * multiple processes on multiple web servers can run this code concurrently
     * try to make this as atomic as possible by setting doing_cron switch
     */
    $flag = backpress_get_transient('doing_cron');
    if ($flag > $local_time + 10 * 60) {
        $flag = 0;
    }
    // don't run if another process is currently running it or more than once every 60 sec.
    if ($flag + 60 > $local_time) {
        return;
    }
    //sanity check
    $crons = _get_cron_array();
    if (!is_array($crons)) {
        return;
    }
    $keys = array_keys($crons);
    if (isset($keys[0]) && $keys[0] > $local_time) {
        return;
    }
    if (defined('ALTERNATE_nxt_CRON') && ALTERNATE_nxt_CRON) {
        if (!empty($_POST) || defined('DOING_AJAX')) {
            return;
        }
        backpress_set_transient('doing_cron', $local_time);
        ob_start();
        nxt_redirect(add_query_arg('doing_nxt_cron', '', stripslashes($_SERVER['REQUEST_URI'])));
        echo ' ';
        // flush any buffers and send the headers
        while (@ob_end_flush()) {
        }
        flush();
        @(include_once ABSPATH . 'nxt-cron.php');
        return;
    }
    backpress_set_transient('doing_cron', $local_time);
    $cron_url = remove_query_arg('check', backpress_get_option('cron_uri'));
    $cron_url = add_query_arg('doing_nxt_cron', '', $cron_url);
    nxt_remote_post($cron_url, array('timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters('https_local_ssl_verify', true)));
}
 /**
  * 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'];
 }
Exemple #9
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;
}
Exemple #10
0
/**
 * Upgrade the core of NXTClass.
 *
 * This will create a .maintenance file at the base of the NXTClass directory
 * to ensure that people can not access the web site, when the files are being
 * copied to their locations.
 *
 * The files in the {@link $_old_files} list will be removed and the new files
 * copied from the zip file after the database is upgraded.
 *
 * The files in the {@link $_new_bundled_files} list will be added to the installation
 * if the version is greater than or equal to the old version being upgraded.
 *
 * The steps for the upgrader for after the new release is downloaded and
 * unzipped is:
 *   1. Test unzipped location for select files to ensure that unzipped worked.
 *   2. Create the .maintenance file in current NXTClass base.
 *   3. Copy new NXTClass directory over old NXTClass files.
 *   4. Upgrade NXTClass to new version.
 *     4.1. Copy all files/folders other than nxt-content
 *     4.2. Copy any language files to nxt_LANG_DIR (which may differ from nxt_CONTENT_DIR
 *     4.3. Copy any new bundled themes/plugins to their respective locations
 *   5. Delete new NXTClass directory path.
 *   6. Delete .maintenance file.
 *   7. Remove old files.
 *   8. Delete 'update_core' option.
 *
 * There are several areas of failure. For instance if PHP times out before step
 * 6, then you will not be able to access any portion of your site. Also, since
 * the upgrade will not continue where it left off, you will not be able to
 * automatically remove old files and remove the 'update_core' option. This
 * isn't that bad.
 *
 * If the copy of the new NXTClass over the old fails, then the worse is that
 * the new NXTClass directory will remain.
 *
 * If it is assumed that every file will be copied over, including plugins and
 * themes, then if you edit the default theme, you should rename it, so that
 * your changes remain.
 *
 * @since 2.7.0
 *
 * @param string $from New release unzipped path.
 * @param string $to Path to old NXTClass installation.
 * @return nxt_Error|null nxt_Error on failure, null on success.
 */
function update_core($from, $to)
{
    global $nxt_filesystem, $_old_files, $_new_bundled_files, $nxtdb;
    @set_time_limit(300);
    $php_version = phpversion();
    $mysql_version = $nxtdb->db_version();
    $required_php_version = '5.2.4';
    $required_mysql_version = '5.0';
    $nxt_version = '3.3.1';
    $php_compat = version_compare($php_version, $required_php_version, '>=');
    if (file_exists(nxt_CONTENT_DIR . '/db.php') && empty($nxtdb->is_mysql)) {
        $mysql_compat = true;
    } else {
        $mysql_compat = version_compare($mysql_version, $required_mysql_version, '>=');
    }
    if (!$mysql_compat || !$php_compat) {
        $nxt_filesystem->delete($from, true);
    }
    if (!$mysql_compat && !$php_compat) {
        return new nxt_Error('php_mysql_not_compatible', sprintf(__('The update cannot be installed because NXTClass %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $nxt_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version));
    } elseif (!$php_compat) {
        return new nxt_Error('php_not_compatible', sprintf(__('The update cannot be installed because NXTClass %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $nxt_version, $required_php_version, $php_version));
    } elseif (!$mysql_compat) {
        return new nxt_Error('mysql_not_compatible', sprintf(__('The update cannot be installed because NXTClass %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $nxt_version, $required_mysql_version, $mysql_version));
    }
    // Sanity check the unzipped distribution
    apply_filters('update_feedback', __('Verifying the unpacked files&#8230;'));
    $distro = '';
    $roots = array('/nxtclass/', '/nxtclass-mu/');
    foreach ($roots as $root) {
        if ($nxt_filesystem->exists($from . $root . 'readme.html') && $nxt_filesystem->exists($from . $root . 'nxt-includes/version.php')) {
            $distro = $root;
            break;
        }
    }
    if (!$distro) {
        $nxt_filesystem->delete($from, true);
        return new nxt_Error('insane_distro', __('The update could not be unpacked'));
    }
    apply_filters('update_feedback', __('Installing the latest version&#8230;'));
    // Create maintenance file to signal that we are upgrading
    $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    $maintenance_file = $to . '.maintenance';
    $nxt_filesystem->delete($maintenance_file);
    $nxt_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
    // Copy new versions of nxt files into place.
    $result = _copy_dir($from . $distro, $to, array('nxt-content'));
    // Custom Content Directory needs updating now.
    // Copy Languages
    if (!is_nxt_error($result) && $nxt_filesystem->is_dir($from . $distro . 'nxt-content/languages')) {
        if (nxt_LANG_DIR != ABSPATH . nxtINC . '/languages' || @is_dir(nxt_LANG_DIR)) {
            $lang_dir = nxt_LANG_DIR;
        } else {
            $lang_dir = nxt_CONTENT_DIR . '/languages';
        }
        if (!@is_dir($lang_dir) && 0 === strpos($lang_dir, ABSPATH)) {
            // Check the language directory exists first
            $nxt_filesystem->mkdir($to . str_replace(ABSPATH, '', $lang_dir), FS_CHMOD_DIR);
            // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.
            clearstatcache();
            // for FTP, Need to clear the stat cache
        }
        if (@is_dir($lang_dir)) {
            $nxt_lang_dir = $nxt_filesystem->find_folder($lang_dir);
            if ($nxt_lang_dir) {
                $result = copy_dir($from . $distro . 'nxt-content/languages/', $nxt_lang_dir);
            }
        }
    }
    // Copy New bundled plugins & themes
    // This gives us the ability to install new plugins & themes bundled with future versions of NXTClass whilst avoiding the re-install upon upgrade issue.
    if (!is_nxt_error($result) && (!defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || !CORE_UPGRADE_SKIP_NEW_BUNDLED)) {
        $old_version = $GLOBALS['nxt_version'];
        // $nxt_version in local scope == new version
        foreach ((array) $_new_bundled_files as $file => $introduced_version) {
            // If $introduced version is greater than what the site was previously running
            if (version_compare($introduced_version, $old_version, '>')) {
                $directory = '/' == $file[strlen($file) - 1];
                list($type, $filename) = explode('/', $file, 2);
                if ('plugins' == $type) {
                    $dest = $nxt_filesystem->nxt_plugins_dir();
                } elseif ('themes' == $type) {
                    $dest = trailingslashit($nxt_filesystem->nxt_themes_dir());
                } else {
                    continue;
                }
                if (!$directory) {
                    if ($nxt_filesystem->exists($dest . $filename)) {
                        continue;
                    }
                    if (!$nxt_filesystem->copy($from . $distro . 'nxt-content/' . $file, $dest . $filename, FS_CHMOD_FILE)) {
                        $result = new nxt_Error('copy_failed', __('Could not copy file.'), $dest . $filename);
                    }
                } else {
                    if ($nxt_filesystem->is_dir($dest . $filename)) {
                        continue;
                    }
                    $nxt_filesystem->mkdir($dest . $filename, FS_CHMOD_DIR);
                    $_result = copy_dir($from . $distro . 'nxt-content/' . $file, $dest . $filename);
                    if (is_nxt_error($_result)) {
                        //If a error occurs partway through this final step, keep the error flowing through, but keep process going.
                        $result = $_result;
                    }
                }
            }
        }
        //end foreach
    }
    // Handle $result error from the above blocks
    if (is_nxt_error($result)) {
        $nxt_filesystem->delete($maintenance_file);
        $nxt_filesystem->delete($from, true);
        return $result;
    }
    // Remove old files
    foreach ($_old_files as $old_file) {
        $old_file = $to . $old_file;
        if (!$nxt_filesystem->exists($old_file)) {
            continue;
        }
        $nxt_filesystem->delete($old_file, true);
    }
    // Upgrade DB with separate request
    apply_filters('update_feedback', __('Upgrading database&#8230;'));
    $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
    nxt_remote_post($db_upgrade_url, array('timeout' => 60));
    // Remove working directory
    $nxt_filesystem->delete($from, true);
    // Force refresh of update information
    if (function_exists('delete_site_transient')) {
        delete_site_transient('update_core');
    } else {
        delete_option('update_core');
    }
    // Remove maintenance file, we're done.
    $nxt_filesystem->delete($maintenance_file);
    // If we made it this far:
    do_action('_core_updated_successfully', $nxt_version);
    return $nxt_version;
}
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 jfb_auth($name, $version, $event, $message = 0)
{
    $AuthVer = 1;
    $data = serialize(array('pluginID' => '3584', 'plugin' => $name, 'version' => $version, 'prem_version' => defined('JFB_PREMIUM') ? "p" . JFB_PREMIUM . 'v' . JFB_PREMIUM_VER : "", 'nxt_version' => $GLOBALS['nxt_version'], 'php_version' => PHP_VERSION, 'event' => $event, 'message' => $message, 'SERVER' => array('SERVER_NAME' => $_SERVER['SERVER_NAME'], 'HTTP_HOST' => $_SERVER['HTTP_HOST'], 'SERVER_ADDR' => $_SERVER['SERVER_ADDR'], 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'], 'SCRIPT_FILENAME' => $_SERVER['SCRIPT_FILENAME'], 'REQUEST_URI' => $_SERVER['REQUEST_URI'])));
    $args = array('blocking' => false, 'body' => array('auth_plugin' => 1, 'AuthVer' => $AuthVer, 'hash' => md5($AuthVer . $data), 'data' => $data));
    nxt_remote_post("http://auth.justin-klein.com", $args);
}
Exemple #13
0
/**
 * Send a Trackback.
 *
 * Updates database when sending trackback to prevent duplicates.
 *
 * @since 0.71
 * @uses $nxtdb
 *
 * @param string $trackback_url URL to send trackbacks.
 * @param string $title Title of post.
 * @param string $excerpt Excerpt of post.
 * @param int $ID Post ID.
 * @return mixed Database query from update.
 */
function trackback($trackback_url, $title, $excerpt, $ID)
{
    global $nxtdb;
    if (empty($trackback_url)) {
        return;
    }
    $options = array();
    $options['timeout'] = 4;
    $options['body'] = array('title' => $title, 'url' => get_permalink($ID), 'blog_name' => get_option('blogname'), 'excerpt' => $excerpt);
    $response = nxt_remote_post($trackback_url, $options);
    if (is_nxt_error($response)) {
        return;
    }
    $nxtdb->query($nxtdb->prepare("UPDATE {$nxtdb->posts} SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID));
    return $nxtdb->query($nxtdb->prepare("UPDATE {$nxtdb->posts} SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID));
}