/**
  * Log plugin installations
  *
  * @action transition_post_status
  *
  * @param \WP_Upgrader $upgrader
  * @param array $extra
  *
  * @return bool
  */
 public function callback_upgrader_process_complete($upgrader, $extra)
 {
     $logs = array();
     $success = !is_wp_error($upgrader->skin->result);
     $error = null;
     if (!$success) {
         $errors = $upgrader->skin->result->errors;
         list($error) = reset($errors);
     }
     // This would have failed down the road anyway
     if (!isset($extra['type'])) {
         return false;
     }
     $type = $extra['type'];
     $action = $extra['action'];
     if (!in_array($type, array('plugin', 'theme'))) {
         return false;
     }
     if ('install' === $action) {
         if ('plugin' === $type) {
             $path = $upgrader->plugin_info();
             if (!$path) {
                 return false;
             }
             $data = get_plugin_data($upgrader->skin->result['local_destination'] . '/' . $path);
             $slug = $upgrader->result['destination_name'];
             $name = $data['Name'];
             $version = $data['Version'];
         } else {
             // theme
             $slug = $upgrader->theme_info();
             if (!$slug) {
                 return false;
             }
             wp_clean_themes_cache();
             $theme = wp_get_theme($slug);
             $name = $theme->name;
             $version = $theme->version;
         }
         $action = 'installed';
         $message = _x('Installed %1$s: %2$s %3$s', 'Plugin/theme installation. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', 'stream');
         $logs[] = compact('slug', 'name', 'version', 'message', 'action');
     } elseif ('update' === $action) {
         $action = 'updated';
         $message = _x('Updated %1$s: %2$s %3$s', 'Plugin/theme update. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', 'stream');
         if ('plugin' === $type) {
             if (isset($extra['bulk']) && true === $extra['bulk']) {
                 $slugs = $extra['plugins'];
             } else {
                 $slugs = array($upgrader->skin->plugin);
             }
             $_plugins = $this->get_plugins();
             foreach ($slugs as $slug) {
                 $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $slug);
                 $name = $plugin_data['Name'];
                 $version = $plugin_data['Version'];
                 $old_version = $_plugins[$slug]['Version'];
                 $logs[] = compact('slug', 'name', 'old_version', 'version', 'message', 'action');
             }
         } else {
             // theme
             if (isset($extra['bulk']) && true === $extra['bulk']) {
                 $slugs = $extra['themes'];
             } else {
                 $slugs = array($upgrader->skin->theme);
             }
             foreach ($slugs as $slug) {
                 $theme = wp_get_theme($slug);
                 $stylesheet = $theme['Stylesheet Dir'] . '/style.css';
                 $theme_data = get_file_data($stylesheet, array('Version' => 'Version'));
                 $name = $theme['Name'];
                 $old_version = $theme['Version'];
                 $version = $theme_data['Version'];
                 $logs[] = compact('slug', 'name', 'old_version', 'version', 'message', 'action');
             }
         }
     } else {
         return false;
     }
     $context = $type . 's';
     foreach ($logs as $log) {
         $name = isset($log['name']) ? $log['name'] : null;
         $version = isset($log['version']) ? $log['version'] : null;
         $slug = isset($log['slug']) ? $log['slug'] : null;
         $old_version = isset($log['old_version']) ? $log['old_version'] : null;
         $message = isset($log['message']) ? $log['message'] : null;
         $action = isset($log['action']) ? $log['action'] : null;
         $this->log($message, compact('type', 'name', 'version', 'slug', 'success', 'error', 'old_version'), null, $context, $action);
     }
     return true;
 }
Ejemplo n.º 2
0
 public function __construct($skin = null, $info = null, $shortinit = false)
 {
     global $wpdb;
     // Line up a wpdb-like object to use
     $this->use_wpdb = !function_exists('mysql_query') && !function_exists('mysqli_query') || !$wpdb->is_mysql || !$wpdb->ready ? true : false;
     $this->our_siteurl = untrailingslashit(site_url());
     if (false == $this->use_wpdb) {
         // We have our own extension which drops lots of the overhead on the query
         $wpdb_obj = new UpdraftPlus_WPDB(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
         // Was that successful?
         if (!$wpdb_obj->is_mysql || !$wpdb_obj->ready) {
             $this->use_wpdb = true;
         } else {
             $this->wpdb_obj = $wpdb_obj;
             $this->mysql_dbh = $wpdb_obj->updraftplus_getdbh();
             $this->use_mysqli = $wpdb_obj->updraftplus_use_mysqli();
         }
     }
     if ($shortinit) {
         return;
     }
     $this->ud_backup_info = $info;
     $this->ud_foreign = empty($info['meta_foreign']) ? false : $info['meta_foreign'];
     parent::__construct($skin);
     $this->init();
     $this->backup_strings();
     $this->is_multisite = is_multisite();
 }
 /**
  * A mimic of the `WP_Upgrader::download_package` method that adds a step to store the temp file with a shorter
  * file name.
  *
  * @see WP_Upgrader::download_package()
  *
  * @param string $package The URI of the package. If this is the full path to an
  *                        existing local file, it will be returned untouched.
  *
  * @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
  */
 protected function download($package)
 {
     if (empty($this->filesystem)) {
         // try to connect
         $this->upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
         global $wp_filesystem;
         // still empty?
         if (empty($wp_filesystem)) {
             // bail
             return false;
         }
         $this->filesystem = $wp_filesystem;
     }
     $this->upgrader->skin->feedback('downloading_package', $package);
     $download_file = download_url($package);
     if (is_wp_error($download_file)) {
         return new WP_Error('download_failed', $this->upgrader->strings['download_failed'], $download_file->get_error_message());
     }
     $file = $this->get_short_filename($download_file);
     $moved = $this->filesystem->move($download_file, $file);
     if (empty($moved)) {
         // we tried, we failed, we bail and let WP do its job
         return false;
     }
     return $file;
 }
Ejemplo n.º 4
0
 public function __construct($skin = null, $info = null, $shortinit = false, $restore_options = array())
 {
     global $wpdb;
     // Line up a wpdb-like object
     $this->use_wpdb = !function_exists('mysql_query') && !function_exists('mysqli_query') || !$wpdb->is_mysql || !$wpdb->ready ? true : false;
     $this->our_siteurl = untrailingslashit(site_url());
     if (false == $this->use_wpdb) {
         // We have our own extension which drops lots of the overhead on the query
         $wpdb_obj = new UpdraftPlus_WPDB(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
         // Was that successful?
         if (!$wpdb_obj->is_mysql || !$wpdb_obj->ready) {
             $this->use_wpdb = true;
         } else {
             $this->wpdb_obj = $wpdb_obj;
             $this->mysql_dbh = $wpdb_obj->updraftplus_getdbh();
             $this->use_mysqli = $wpdb_obj->updraftplus_use_mysqli();
         }
     }
     if ($shortinit) {
         return;
     }
     $this->ud_backup_info = $info;
     do_action('updraftplus_restorer_restore_options', $restore_options);
     $this->ud_multisite_selective_restore = is_array($restore_options) && !empty($restore_options['updraft_restore_ms_whichsites']) && $restore_options['updraft_restore_ms_whichsites'] > 0 ? $restore_options['updraft_restore_ms_whichsites'] : false;
     $this->ud_restore_options = $restore_options;
     $this->ud_foreign = empty($info['meta_foreign']) ? false : $info['meta_foreign'];
     if (isset($info['is_multisite'])) {
         $this->ud_backup_is_multisite = $info['is_multisite'];
     }
     if (isset($info['created_by_version'])) {
         $this->created_by_version = $info['created_by_version'];
     }
     add_filter('updraftplus_logline', array($this, 'updraftplus_logline'), 10, 5);
     parent::__construct($skin);
     $this->init();
     $this->backup_strings();
     $this->is_multisite = is_multisite();
 }
Ejemplo n.º 5
0
 /**
  * Creates a lock using WordPress options.
  *
  * @since 4.5.0
  * @access public
  * @static
  *
  * @param string $lock_name       The name of this unique lock.
  * @param int    $release_timeout Optional. The duration in seconds to respect an existing lock.
  *                                Default: 1 hour.
  * @return bool False if a lock couldn't be created or if the lock is no longer valid. True otherwise.
  */
 public static function create_lock($lock_name, $release_timeout = null)
 {
     global $wpdb;
     if (!$release_timeout) {
         $release_timeout = HOUR_IN_SECONDS;
     }
     $lock_option = $lock_name . '.lock';
     // Try to lock.
     $lock_result = $wpdb->query($wpdb->prepare("INSERT IGNORE INTO `{$wpdb->options}` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_option, time()));
     if (!$lock_result) {
         $lock_result = get_option($lock_option);
         // If a lock couldn't be created, and there isn't a lock, bail.
         if (!$lock_result) {
             return false;
         }
         // Check to see if the lock is still valid. If not, bail.
         if ($lock_result > time() - $release_timeout) {
             return false;
         }
         // There must exist an expired lock, clear it and re-gain it.
         WP_Upgrader::release_lock($lock_name);
         return WP_Upgrader::create_lock($lock_name, $release_timeout);
     }
     // Update the lock, as by this point we've definitely got a lock, just need to fire the actions.
     update_option($lock_option, time());
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Expects $_POST['type'] == plugin/theme
  * $_POST['list'] == 'theme1,theme2' or 'plugin1,plugin2'
  */
 function upgradePluginTheme()
 {
     //Prevent disable/re-enable at upgrade
     define('DOING_CRON', true);
     MainWP_Helper::getWPFilesystem();
     include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
     //        if (file_exists(ABSPATH . '/wp-admin/includes/deprecated.php')) include_once(ABSPATH . '/wp-admin/includes/deprecated.php');
     if (file_exists(ABSPATH . '/wp-admin/includes/screen.php')) {
         include_once ABSPATH . '/wp-admin/includes/screen.php';
     }
     if (file_exists(ABSPATH . '/wp-admin/includes/template.php')) {
         include_once ABSPATH . '/wp-admin/includes/template.php';
     }
     if (file_exists(ABSPATH . '/wp-admin/includes/misc.php')) {
         include_once ABSPATH . '/wp-admin/includes/misc.php';
     }
     include_once ABSPATH . '/wp-admin/includes/file.php';
     include_once ABSPATH . '/wp-admin/includes/plugin.php';
     $information = array();
     $information['upgrades'] = array();
     $mwp_premium_updates_todo = array();
     $mwp_premium_updates_todo_slugs = array();
     if (isset($_POST['type']) && 'plugin' === $_POST['type']) {
         include_once ABSPATH . '/wp-admin/includes/update.php';
         if (null !== $this->filterFunction) {
             add_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
         }
         $plugins = explode(',', urldecode($_POST['list']));
         // To fix: backupbuddy update
         if (in_array('backupbuddy/backupbuddy.php', $plugins)) {
             if (isset($GLOBALS['ithemes_updater_path'])) {
                 if (!class_exists('Ithemes_Updater_Settings')) {
                     require $GLOBALS['ithemes_updater_path'] . '/settings.php';
                 }
                 if (class_exists('Ithemes_Updater_Settings')) {
                     $ithemes_updater = new Ithemes_Updater_Settings();
                     $ithemes_updater->update();
                 }
             }
         }
         ////
         global $wp_current_filter;
         $wp_current_filter[] = 'load-plugins.php';
         @wp_update_plugins();
         $information['plugin_updates'] = get_plugin_updates();
         $plugins = explode(',', urldecode($_POST['list']));
         $premiumPlugins = array();
         $premiumUpdates = get_option('mainwp_premium_updates');
         if (is_array($premiumUpdates)) {
             $newPlugins = array();
             foreach ($plugins as $plugin) {
                 if (in_array($plugin, $premiumUpdates)) {
                     $premiumPlugins[] = $plugin;
                 } else {
                     $newPlugins[] = $plugin;
                 }
             }
             $plugins = $newPlugins;
         }
         if (count($plugins) > 0) {
             //@see wp-admin/update.php
             $upgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
             $result = $upgrader->bulk_upgrade($plugins);
             if (!empty($result)) {
                 foreach ($result as $plugin => $info) {
                     if (empty($info)) {
                         $information['upgrades'][$plugin] = false;
                     } else {
                         $information['upgrades'][$plugin] = true;
                     }
                 }
             } else {
                 MainWP_Helper::error(__('Bad request', 'mainwp-child'));
             }
         }
         if (count($premiumPlugins) > 0) {
             $mwp_premium_updates = apply_filters('mwp_premium_perform_update', array());
             if (is_array($mwp_premium_updates) && is_array($premiumPlugins)) {
                 foreach ($premiumPlugins as $premiumPlugin) {
                     foreach ($mwp_premium_updates as $key => $update) {
                         $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                         if (0 === strcmp($slug, $premiumPlugin)) {
                             $mwp_premium_updates_todo[$key] = $update;
                             $mwp_premium_updates_todo_slugs[] = $premiumPlugin;
                         }
                     }
                 }
             }
             unset($mwp_premium_updates);
             $premiumUpgrader = new Plugin_Upgrader(new Bulk_Plugin_Upgrader_Skin(compact('nonce', 'url')));
         }
         if (count($plugins) <= 0 && count($premiumPlugins) <= 0) {
             MainWP_Helper::error(__('Bad request', 'mainwp-child'));
         }
         if (null !== $this->filterFunction) {
             remove_filter('pre_site_transient_update_plugins', $this->filterFunction, 99);
         }
     } else {
         if (isset($_POST['type']) && 'theme' === $_POST['type']) {
             include_once ABSPATH . '/wp-admin/includes/update.php';
             if (null !== $this->filterFunction) {
                 add_filter('pre_site_transient_update_themes', $this->filterFunction, 99);
             }
             @wp_update_themes();
             include_once ABSPATH . '/wp-admin/includes/theme.php';
             $information['theme_updates'] = $this->upgrade_get_theme_updates();
             $themes = explode(',', $_POST['list']);
             $premiumThemes = array();
             $premiumUpdates = get_option('mainwp_premium_updates');
             if (is_array($premiumUpdates)) {
                 $newThemes = array();
                 foreach ($themes as $theme) {
                     if (in_array($theme, $premiumUpdates)) {
                         $premiumThemes[] = $theme;
                     } else {
                         $newThemes[] = $theme;
                     }
                 }
                 $themes = $newThemes;
             }
             if (count($themes) > 0) {
                 // To fix: optimizePressTheme update
                 $addFilterToFixUpdate_optimizePressTheme = false;
                 if (in_array('optimizePressTheme', $themes)) {
                     $addFilterToFixUpdate_optimizePressTheme = true;
                     add_filter('site_transient_update_themes', array($this, 'hookFixOptimizePressThemeUpdate'), 99);
                 }
                 //@see wp-admin/update.php
                 $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('nonce', 'url')));
                 $result = $upgrader->bulk_upgrade($themes);
                 if ($addFilterToFixUpdate_optimizePressTheme) {
                     remove_filter('site_transient_update_themes', array($this, 'hookFixOptimizePressThemeUpdate'), 99);
                 }
                 if (!empty($result)) {
                     foreach ($result as $theme => $info) {
                         if (empty($info)) {
                             $information['upgrades'][$theme] = false;
                         } else {
                             $information['upgrades'][$theme] = true;
                         }
                     }
                 } else {
                     MainWP_Helper::error(__('Bad request', 'mainwp-child'));
                 }
             }
             if (count($premiumThemes) > 0) {
                 $mwp_premium_updates = apply_filters('mwp_premium_perform_update', array());
                 $mwp_premium_updates_todo = array();
                 $mwp_premium_updates_todo_slugs = array();
                 if (is_array($premiumThemes) && is_array($mwp_premium_updates)) {
                     foreach ($premiumThemes as $premiumTheme) {
                         foreach ($mwp_premium_updates as $key => $update) {
                             $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                             if (0 === strcmp($slug, $premiumTheme)) {
                                 $mwp_premium_updates_todo[$key] = $update;
                                 $mwp_premium_updates_todo_slugs[] = $slug;
                             }
                         }
                     }
                 }
                 unset($mwp_premium_updates);
                 $premiumUpgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('nonce', 'url')));
             }
             if (count($themes) <= 0 && count($premiumThemes) <= 0) {
                 MainWP_Helper::error(__('Bad request', 'mainwp-child'));
             }
             if (null !== $this->filterFunction) {
                 remove_filter('pre_site_transient_update_themes', $this->filterFunction, 99);
             }
         } else {
             MainWP_Helper::error(__('Bad request', 'mainwp-child'));
         }
     }
     if (count($mwp_premium_updates_todo) > 0) {
         //Upgrade via WP
         //@see wp-admin/update.php
         $result = $premiumUpgrader->bulk_upgrade($mwp_premium_updates_todo_slugs);
         if (!empty($result)) {
             foreach ($result as $plugin => $info) {
                 if (!empty($info)) {
                     $information['upgrades'][$plugin] = true;
                     foreach ($mwp_premium_updates_todo as $key => $update) {
                         $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                         if (0 === strcmp($slug, $plugin)) {
                             //unset($mwp_premium_updates_todo[$key]);
                         }
                     }
                 }
             }
         }
         //Upgrade via callback
         foreach ($mwp_premium_updates_todo as $update) {
             $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
             if (isset($update['url'])) {
                 $installer = new WP_Upgrader();
                 //@see wp-admin/includes/class-wp-upgrader.php
                 $result = $installer->run(array('package' => $update['url'], 'destination' => 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes', 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array()));
                 $information['upgrades'][$slug] = !is_wp_error($result) && !empty($result);
             } else {
                 if (isset($update['callback'])) {
                     if (is_array($update['callback']) && isset($update['callback'][0]) && isset($update['callback'][1])) {
                         $update_result = @call_user_func(array($update['callback'][0], $update['callback'][1]));
                         $information['upgrades'][$slug] = $update_result && true;
                     } else {
                         if (is_string($update['callback'])) {
                             $update_result = @call_user_func($update['callback']);
                             $information['upgrades'][$slug] = $update_result && true;
                         } else {
                             $information['upgrades'][$slug] = false;
                         }
                     }
                 } else {
                     $information['upgrades'][$slug] = false;
                 }
             }
         }
     }
     $information['sync'] = $this->getSiteStats(array(), false);
     MainWP_Helper::write($information);
 }
Ejemplo n.º 7
0
 /**
  * Upgrade WordPress core.
  *
  * @since 2.8.0
  * @access public
  *
  * @global WP_Filesystem_Base $wp_filesystem Subclass
  * @global callable           $_wp_filesystem_direct_method
  *
  * @param object $current Response object for whether WordPress is current.
  * @param array  $args {
  *        Optional. Arguments for upgrading WordPress core. Default empty array.
  *
  *        @type bool $pre_check_md5    Whether to check the file checksums before
  *                                     attempting the upgrade. Default true.
  *        @type bool $attempt_rollback Whether to attempt to rollback the chances if
  *                                     there is a problem. Default false.
  *        @type bool $do_rollback      Whether to perform this "upgrade" as a rollback.
  *                                     Default false.
  * }
  * @return null|false|WP_Error False or WP_Error on failure, null on success.
  */
 public function upgrade($current, $args = array())
 {
     global $wp_filesystem;
     include ABSPATH . WPINC . '/version.php';
     // $wp_version;
     $start_time = time();
     $defaults = array('pre_check_md5' => true, 'attempt_rollback' => false, 'do_rollback' => false, 'allow_relaxed_file_ownership' => false);
     $parsed_args = wp_parse_args($args, $defaults);
     $this->init();
     $this->upgrade_strings();
     // Is an update available?
     if (!isset($current->response) || $current->response == 'latest') {
         return new WP_Error('up_to_date', $this->strings['up_to_date']);
     }
     $res = $this->fs_connect(array(ABSPATH, WP_CONTENT_DIR), $parsed_args['allow_relaxed_file_ownership']);
     if (!$res || is_wp_error($res)) {
         return $res;
     }
     $wp_dir = trailingslashit($wp_filesystem->abspath());
     $partial = true;
     if ($parsed_args['do_rollback']) {
         $partial = false;
     } elseif ($parsed_args['pre_check_md5'] && !$this->check_files()) {
         $partial = false;
     }
     /*
      * If partial update is returned from the API, use that, unless we're doing
      * a reinstall. If we cross the new_bundled version number, then use
      * the new_bundled zip. Don't though if the constant is set to skip bundled items.
      * If the API returns a no_content zip, go with it. Finally, default to the full zip.
      */
     if ($parsed_args['do_rollback'] && $current->packages->rollback) {
         $to_download = 'rollback';
     } elseif ($current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version && $partial) {
         $to_download = 'partial';
     } elseif ($current->packages->new_bundled && version_compare($wp_version, $current->new_bundled, '<') && (!defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || !CORE_UPGRADE_SKIP_NEW_BUNDLED)) {
         $to_download = 'new_bundled';
     } elseif ($current->packages->no_content) {
         $to_download = 'no_content';
     } else {
         $to_download = 'full';
     }
     // Lock to prevent multiple Core Updates occuring
     $lock = WP_Upgrader::create_lock('core_updater', 15 * MINUTE_IN_SECONDS);
     if (!$lock) {
         return new WP_Error('locked', $this->strings['locked']);
     }
     $download = $this->download_package($current->packages->{$to_download});
     if (is_wp_error($download)) {
         WP_Upgrader::release_lock('core_updater');
         return $download;
     }
     $working_dir = $this->unpack_package($download);
     if (is_wp_error($working_dir)) {
         WP_Upgrader::release_lock('core_updater');
         return $working_dir;
     }
     // Copy update-core.php from the new version into place.
     if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
         $wp_filesystem->delete($working_dir, true);
         WP_Upgrader::release_lock('core_updater');
         return new WP_Error('copy_failed_for_update_core_file', __('The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.'), 'wp-admin/includes/update-core.php');
     }
     $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
     require_once ABSPATH . 'wp-admin/includes/update-core.php';
     if (!function_exists('update_core')) {
         WP_Upgrader::release_lock('core_updater');
         return new WP_Error('copy_failed_space', $this->strings['copy_failed_space']);
     }
     $result = update_core($working_dir, $wp_dir);
     // In the event of an issue, we may be able to roll back.
     if ($parsed_args['attempt_rollback'] && $current->packages->rollback && !$parsed_args['do_rollback']) {
         $try_rollback = false;
         if (is_wp_error($result)) {
             $error_code = $result->get_error_code();
             /*
              * Not all errors are equal. These codes are critical: copy_failed__copy_dir,
              * mkdir_failed__copy_dir, copy_failed__copy_dir_retry, and disk_full.
              * do_rollback allows for update_core() to trigger a rollback if needed.
              */
             if (false !== strpos($error_code, 'do_rollback')) {
                 $try_rollback = true;
             } elseif (false !== strpos($error_code, '__copy_dir')) {
                 $try_rollback = true;
             } elseif ('disk_full' === $error_code) {
                 $try_rollback = true;
             }
         }
         if ($try_rollback) {
             /** This filter is documented in wp-admin/includes/update-core.php */
             apply_filters('update_feedback', $result);
             /** This filter is documented in wp-admin/includes/update-core.php */
             apply_filters('update_feedback', $this->strings['start_rollback']);
             $rollback_result = $this->upgrade($current, array_merge($parsed_args, array('do_rollback' => true)));
             $original_result = $result;
             $result = new WP_Error('rollback_was_required', $this->strings['rollback_was_required'], (object) array('update' => $original_result, 'rollback' => $rollback_result));
         }
     }
     /** This action is documented in wp-admin/includes/class-wp-upgrader.php */
     do_action('upgrader_process_complete', $this, array('action' => 'update', 'type' => 'core'));
     // Clear the current updates
     delete_site_transient('update_core');
     if (!$parsed_args['do_rollback']) {
         $stats = array('update_type' => $current->response, 'success' => true, 'fs_method' => $wp_filesystem->method, 'fs_method_forced' => defined('FS_METHOD') || has_filter('filesystem_method'), 'fs_method_direct' => !empty($GLOBALS['_wp_filesystem_direct_method']) ? $GLOBALS['_wp_filesystem_direct_method'] : '', 'time_taken' => time() - $start_time, 'reported' => $wp_version, 'attempted' => $current->version);
         if (is_wp_error($result)) {
             $stats['success'] = false;
             // Did a rollback occur?
             if (!empty($try_rollback)) {
                 $stats['error_code'] = $original_result->get_error_code();
                 $stats['error_data'] = $original_result->get_error_data();
                 // Was the rollback successful? If not, collect its error too.
                 $stats['rollback'] = !is_wp_error($rollback_result);
                 if (is_wp_error($rollback_result)) {
                     $stats['rollback_code'] = $rollback_result->get_error_code();
                     $stats['rollback_data'] = $rollback_result->get_error_data();
                 }
             } else {
                 $stats['error_code'] = $result->get_error_code();
                 $stats['error_data'] = $result->get_error_data();
             }
         }
         wp_version_check($stats);
     }
     WP_Upgrader::release_lock('core_updater');
     return $result;
 }
Ejemplo n.º 8
0
 public function upgrade_premium($premium = false)
 {
     if (!class_exists('WP_Upgrader')) {
         include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     if (!$premium || empty($premium)) {
         return array('error' => 'No premium files for upgrade.');
     }
     $upgrader = false;
     $pr_update = array();
     $themes = array();
     $plugins = array();
     $result = array();
     $premium_update = array();
     $premium_update = apply_filters('mwp_premium_perform_update', $premium_update);
     if (!empty($premium_update)) {
         foreach ($premium as $pr) {
             foreach ($premium_update as $key => $update) {
                 $update = array_change_key_case($update, CASE_LOWER);
                 if ($update['name'] == $pr['name']) {
                     // prepare bulk updates for premiums that use WordPress upgrader
                     if (isset($update['type'])) {
                         if ($update['type'] == 'plugin') {
                             if (isset($update['slug']) && !empty($update['slug'])) {
                                 $plugins[$update['slug']] = $update;
                             }
                         }
                         if ($update['type'] == 'theme') {
                             if (isset($update['template']) && !empty($update['template'])) {
                                 $themes[$update['template']] = $update;
                             }
                         }
                     }
                 } else {
                     unset($premium_update[$key]);
                 }
             }
         }
         // try default wordpress upgrader
         if (!empty($plugins)) {
             $updateplugins = $this->upgrade_plugins(array_values($plugins));
             if (!empty($updateplugins) && isset($updateplugins['upgraded'])) {
                 foreach ($premium_update as $key => $update) {
                     $update = array_change_key_case($update, CASE_LOWER);
                     foreach ($updateplugins['upgraded'] as $slug => $upgrade) {
                         if (isset($update['slug']) && $update['slug'] == $slug) {
                             if ($upgrade == 1) {
                                 unset($premium_update[$key]);
                             }
                             $pr_update['plugins']['upgraded'][md5($update['name'])] = $upgrade;
                         }
                     }
                 }
             }
         }
         //try direct install with overwrite
         if (!empty($premium_update)) {
             foreach ($premium_update as $update) {
                 $update = array_change_key_case($update, CASE_LOWER);
                 $update_result = false;
                 if (isset($update['url'])) {
                     if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance')) {
                         $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = 'Site under maintanace.';
                     }
                     /** @handled class */
                     $upgrader_skin = new WP_Upgrader_Skin();
                     $upgrader_skin->done_header = true;
                     /** @handled class */
                     $upgrader = new WP_Upgrader();
                     @($update_result = $upgrader->run(array('package' => $update['url'], 'destination' => isset($update['type']) && $update['type'] == 'theme' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array())));
                     $update_result = !$update_result || is_wp_error($update_result) ? $this->mmb_get_error($update_result) : 1;
                 } else {
                     if (isset($update['callback'])) {
                         if (is_array($update['callback'])) {
                             $update_result = call_user_func(array($update['callback'][0], $update['callback'][1]));
                         } else {
                             if (is_string($update['callback'])) {
                                 $update_result = call_user_func($update['callback']);
                             } else {
                                 $update_result = 'Upgrade function "' . $update['callback'] . '" does not exists.';
                             }
                         }
                         $update_result = $update_result !== true ? $this->mmb_get_error($update_result) : 1;
                     } else {
                         $update_result = 'Bad update params.';
                     }
                 }
                 $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = $update_result;
             }
         }
         return $pr_update;
     } else {
         foreach ($premium as $pr) {
             $result[$pr['type'] . 's']['upgraded'][md5($pr['name'])] = 'This premium update is not registered.';
         }
         return $result;
     }
 }
Ejemplo n.º 9
0
 function install_bsf_product($install_id)
 {
     global $bsf_product_validate_url, $bsf_support_url;
     if (!current_user_can('install_plugins')) {
         wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'bsf'));
     }
     $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array();
     $install_product_data = array();
     if (!empty($brainstrom_bundled_products)) {
         foreach ($brainstrom_bundled_products as $keys => $products) {
             if (strlen($keys) > 1) {
                 foreach ($products as $key => $product) {
                     if ($product->id === $install_id) {
                         $install_product_data = $product;
                         break;
                     }
                 }
             } else {
                 if ($products->id === $install_id) {
                     $install_product_data = $products;
                     break;
                 }
             }
         }
     }
     if (empty($install_product_data)) {
         return false;
     }
     if ($install_product_data->type !== 'plugin') {
         return false;
     }
     /* temp */
     /*$install_product_data->in_house = 'wp';
     		$install_product_data->download_url = 'https://downloads.wordpress.org/plugin/redux-framework.3.5.9.zip';*/
     $is_wp = isset($install_product_data->in_house) && $install_product_data->in_house === 'wp' ? true : false;
     if ($is_wp) {
         $download_path = $install_product_data->download_url;
     } else {
         $path = $bsf_product_validate_url;
         $timezone = date_default_timezone_get();
         $call = 'file=' . $install_product_data->download_url . '&hashtime=' . strtotime(date('d-m-Y h:i:s a')) . '&timezone=' . $timezone;
         $hash = $call;
         //$parse = parse_url($path);
         //$download = $parse['scheme'].'://'.$parse['host'];
         $get_path = 'http://downloads.brainstormforce.com/';
         $download_path = rtrim($get_path, '/') . '/download.php?' . $hash . '&base=ignore';
     }
     require_once ABSPATH . '/wp-admin/includes/file.php';
     WP_Filesystem();
     global $wp_filesystem;
     require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     $WP_Upgrader = new WP_Upgrader();
     $res = $WP_Upgrader->fs_connect(array(WP_CONTENT_DIR));
     if (!$res) {
         wp_die(new WP_Error('Server error', __("Error! Can't connect to filesystem", 'bsf')));
     }
     $Plugin_Upgrader = new Plugin_Upgrader();
     $defaults = array('clear_update_cache' => true);
     $args = array();
     $parsed_args = wp_parse_args($args, $defaults);
     $Plugin_Upgrader->init();
     $Plugin_Upgrader->install_strings();
     $Plugin_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');
     $Plugin_Upgrader->strings['remove_old'] = __('Removing old plugin, if exists', 'bsf');
     add_filter('upgrader_source_selection', array($Plugin_Upgrader, 'check_package'));
     $Plugin_Upgrader->run(array('package' => $download_path, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install')));
     remove_filter('upgrader_source_selection', array($Plugin_Upgrader, 'check_package'));
     if (!$Plugin_Upgrader->result || is_wp_error($Plugin_Upgrader->result)) {
         return $Plugin_Upgrader->result;
     }
     // Force refresh of plugin update information
     wp_clean_plugins_cache($parsed_args['clear_update_cache']);
     //return true;
     $response = array('status' => true, 'type' => 'plugin', 'name' => $install_product_data->name, 'init' => $install_product_data->init);
     $plugin_abs_path = WP_PLUGIN_DIR . '/' . $install_product_data->init;
     if (is_file($plugin_abs_path)) {
         if (!isset($_GET['action']) && !isset($_GET['id'])) {
             echo '|bsf-plugin-installed|';
         }
         $is_plugin_installed = true;
         if (!is_plugin_active($install_product_data->init)) {
             activate_plugin($install_product_data->init);
             if (is_plugin_active($install_product_data->init)) {
                 if (!isset($_GET['action']) && !isset($_GET['id'])) {
                     echo '|bsf-plugin-activated|';
                 }
             }
         } else {
             if (!isset($_GET['action']) && !isset($_GET['id'])) {
                 echo '|bsf-plugin-activated|';
             }
         }
     }
     return $response;
 }
Ejemplo n.º 10
0
 function __construct($skin = null)
 {
     parent::__construct($skin);
     $this->init();
     $this->backup_strings();
 }
Ejemplo n.º 11
0
    public static function settings_panel()
    {
        if (isset($_GET['wpak_action']) && $_GET['wpak_action'] == 'upload-theme') {
            if (!current_user_can('upload_plugins') && !current_user_can('wpak_edit_apps')) {
                wp_die(__('You do not have sufficient permissions to install WP AppKit themes on this site.', WpAppKit::i18n_domain));
            }
            check_admin_referer('wpak-theme-upload');
            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
            $file_upload = new File_Upload_Upgrader('themezip', 'package');
            $file_type = wp_check_filetype($file_upload->filename);
            if ($file_type['ext'] == 'zip' && $file_type['type'] == 'application/zip') {
                $title = sprintf(__('Installing WP AppKit from uploaded file: %s', WpAppKit::i18n_domain), esc_html(basename($file_upload->filename)));
                $nonce = 'wpak-theme-upload';
                $url = add_query_arg(array('package' => $file_upload->id));
                // A nonce is passed to WP_Upgrader_Skin class, so wp_nonce_url() is called and url is escaped there...
                $upgrader = new WP_Upgrader(new WP_Upgrader_Skin(compact('title', 'nonce', 'url')));
                $destination_folder_name = basename(sanitize_file_name($file_upload->filename), ".zip");
                $result = $upgrader->run(array('package' => $file_upload->package, 'destination' => WpakThemes::get_themes_directory() . '/' . $destination_folder_name, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array()));
                if ($result || is_wp_error($result)) {
                    $file_upload->cleanup();
                }
                if (!is_wp_error($result)) {
                    echo sprintf(__("WP AppKit theme '%s' installed successfully!", WpAppKit::i18n_domain), $destination_folder_name);
                } else {
                    _e('An error occured', WpAppKit::i18n_domain);
                    echo ' : ' . $result->get_error_message();
                }
                echo '<br/><br/><a href="' . esc_url(remove_query_arg('wpak_action')) . '">' . __('Back to theme upload form', WpAppKit::i18n_domain) . '</a>';
                echo '<br/><br/><a href="' . admin_url() . '/edit.php?post_type=wpak_apps">' . __('Go to my WP AppKit app list', WpAppKit::i18n_domain) . '</a>';
            } else {
                _e("Uploaded file must be a valid zip file", WpAppKit::i18n_domain);
            }
        } else {
            ?>
			<div class="wrap" id="wpak-settings">
				<h2><?php 
            _e('WP AppKit Themes upload', WpAppKit::i18n_domain);
            ?>
</h2>

				<?php 
            if (!empty($result['message'])) {
                ?>
					<div class="<?php 
                echo $result['type'];
                ?>
" ><p><?php 
                echo $result['message'];
                ?>
</p></div>
				<?php 
            }
            ?>

				<div class="upload-plugin">
					<p class="install-help"><?php 
            _e('If you have a WP AppKit theme in a .zip format, you may install it by uploading it here.');
            ?>
</p>
					<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php 
            echo esc_url(add_query_arg(array('wpak_action' => 'upload-theme')));
            ?>
">
						<?php 
            wp_nonce_field('wpak-theme-upload');
            ?>
						<label class="screen-reader-text" for="themezip"><?php 
            _e('WP AppKit Theme zip file', WpAppKit::i18n_domain);
            ?>
</label>
						<input type="file" id="themezip" name="themezip" />
						<?php 
            submit_button(__('Install Now'), 'button', 'install-theme-submit', false);
            ?>
					</form>
				</div>

			</div>
			<?php 
        }
    }
Ejemplo n.º 12
0
 /**
  * Kicks off the background update process, looping through all pending updates.
  *
  * @since 3.7.0
  * @access public
  *
  * @global wpdb   $wpdb
  * @global string $wp_version
  */
 public function run()
 {
     global $wpdb, $wp_version;
     if ($this->is_disabled()) {
         return;
     }
     if (!is_main_network() || !is_main_site()) {
         return;
     }
     if (!WP_Upgrader::create_lock('auto_updater')) {
         return;
     }
     // Don't automatically run these thins, as we'll handle it ourselves
     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
     remove_action('upgrader_process_complete', 'wp_version_check');
     remove_action('upgrader_process_complete', 'wp_update_plugins');
     remove_action('upgrader_process_complete', 'wp_update_themes');
     // Next, Plugins
     wp_update_plugins();
     // Check for Plugin updates
     $plugin_updates = get_site_transient('update_plugins');
     if ($plugin_updates && !empty($plugin_updates->response)) {
         foreach ($plugin_updates->response as $plugin) {
             $this->update('plugin', $plugin);
         }
         // Force refresh of plugin update information
         wp_clean_plugins_cache();
     }
     // Next, those themes we all love
     wp_update_themes();
     // Check for Theme updates
     $theme_updates = get_site_transient('update_themes');
     if ($theme_updates && !empty($theme_updates->response)) {
         foreach ($theme_updates->response as $theme) {
             $this->update('theme', (object) $theme);
         }
         // Force refresh of theme update information
         wp_clean_themes_cache();
     }
     // Next, Process any core update
     wp_version_check();
     // Check for Core updates
     $core_update = find_core_auto_update();
     if ($core_update) {
         $this->update('core', $core_update);
     }
     // Clean up, and check for any pending translations
     // (Core_Upgrader checks for core updates)
     $theme_stats = array();
     if (isset($this->update_results['theme'])) {
         foreach ($this->update_results['theme'] as $upgrade) {
             $theme_stats[$upgrade->item->theme] = true === $upgrade->result;
         }
     }
     wp_update_themes($theme_stats);
     // Check for Theme updates
     $plugin_stats = array();
     if (isset($this->update_results['plugin'])) {
         foreach ($this->update_results['plugin'] as $upgrade) {
             $plugin_stats[$upgrade->item->plugin] = true === $upgrade->result;
         }
     }
     wp_update_plugins($plugin_stats);
     // Check for Plugin updates
     // Finally, Process any new translations
     $language_updates = wp_get_translation_updates();
     if ($language_updates) {
         foreach ($language_updates as $update) {
             $this->update('translation', $update);
         }
         // Clear existing caches
         wp_clean_update_cache();
         wp_version_check();
         // check for Core updates
         wp_update_themes();
         // Check for Theme updates
         wp_update_plugins();
         // Check for Plugin updates
     }
     // Send debugging email to all development installs.
     if (!empty($this->update_results)) {
         $development_version = false !== strpos($wp_version, '-');
         /**
          * Filter whether to send a debugging email for each automatic background update.
          *
          * @since 3.7.0
          *
          * @param bool $development_version By default, emails are sent if the
          *                                  install is a development version.
          *                                  Return false to avoid the email.
          */
         if (apply_filters('automatic_updates_send_debug_email', $development_version)) {
             $this->send_debug_email();
         }
         if (!empty($this->update_results['core'])) {
             $this->after_core_update($this->update_results['core'][0]);
         }
         /**
          * Fires after all automatic updates have run.
          *
          * @since 3.8.0
          *
          * @param array $update_results The results of all attempted updates.
          */
         do_action('automatic_updates_complete', $this->update_results);
     }
     WP_Upgrader::release_lock('auto_updater');
 }
Ejemplo n.º 13
0
 public function __construct()
 {
     parent::__construct();
 }
 /**
  * Downloads the MarketPress Dashboard
  *
  * @since	0.1
  * @uses	WP_Upgrader, wp_safe_redirect, admin_url
  * @return	void
  */
 public function install_marketpress_dashboard()
 {
     // Download
     $package = 'http://marketpress.com/mpdash.zip';
     $upgrader = new WP_Upgrader(new AU_Install_Skin());
     // File System Connect
     $res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
     // Download Package
     $download = $upgrader->download_package($package);
     // Don't delete local files
     $delete_package = $download != $package;
     // Unpack the package
     $working_dir = $upgrader->unpack_package($download, $delete_package);
     // Install the package
     $result = $upgrader->install_package(array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => FALSE, 'clear_working' => TRUE, 'hook_extra' => array()));
     // Redirect
     wp_safe_redirect(network_admin_url('plugins.php?message=marketpress_installed'));
 }
Ejemplo n.º 15
0
 public static function installPlugin($url, $activatePlugin = false)
 {
     $hasWPFileSystem = MainWP_Utility::getWPFilesystem();
     /** @global WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     if (file_exists(ABSPATH . '/wp-admin/includes/screen.php')) {
         include_once ABSPATH . '/wp-admin/includes/screen.php';
     }
     include_once ABSPATH . '/wp-admin/includes/template.php';
     include_once ABSPATH . '/wp-admin/includes/misc.php';
     include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . '/wp-admin/includes/plugin.php';
     $installer = new WP_Upgrader();
     $ssl_verifyhost = get_option('mainwp_sslVerifyCertificate');
     $ssl_api_verifyhost = get_option('mainwp_api_sslVerifyCertificate') === false || get_option('mainwp_api_sslVerifyCertificate') == 1 ? 1 : 0;
     if ($ssl_verifyhost === '0' || $ssl_api_verifyhost == 0) {
         add_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'noSSLFilterFunction'), 99, 2);
     }
     add_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'http_request_reject_unsafe_urls'), 99, 2);
     $result = $installer->run(array('package' => $url, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array()));
     remove_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'http_request_reject_unsafe_urls'), 99, 2);
     if ($ssl_verifyhost === '0') {
         remove_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'noSSLFilterFunction'), 99);
     }
     $error = $output = $plugin_slug = null;
     if (is_wp_error($result)) {
         $error = $result->get_error_codes();
         if (is_array($error)) {
             if ($error[0] == 'folder_exists') {
                 $error = __('Destination folder already exists.', 'mainwp');
             } else {
                 $error = implode(', ', $error);
             }
         }
     } else {
         $path = $result['destination'];
         foreach ($result['source_files'] as $srcFile) {
             // to fix bug
             if ($srcFile == 'readme.txt') {
                 continue;
             }
             $thePlugin = get_plugin_data($path . $srcFile);
             if ($thePlugin != null && $thePlugin != '' && $thePlugin['Name'] != '') {
                 $output .= __('Successfully installed the plugin', 'mainwp') . ' ' . $thePlugin['Name'] . ' ' . $thePlugin['Version'];
                 $plugin_slug = $result['destination_name'] . '/' . $srcFile;
                 if ($activatePlugin) {
                     activate_plugin($path . $srcFile, '', false, true);
                     do_action('mainwp_api_extension_activated', $path . $srcFile);
                 }
                 break;
             }
         }
     }
     if (!empty($error)) {
         $return['error'] = $error;
     } else {
         MainWP_Extensions::enableExtension($plugin_slug);
         $return['result'] = 'SUCCESS';
         $return['output'] = $output;
         $return['slug'] = $plugin_slug;
     }
     return $return;
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->init();
 }
 function upgrade_bsf_product($request_product_id, $bundled_id)
 {
     global $bsf_product_validate_url, $bsf_support_url;
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update plugins for this site.', 'bsf'));
     }
     $brainstrom_users = get_option('brainstrom_users') ? get_option('brainstrom_users') : array();
     $brainstrom_products = get_option('brainstrom_products') ? get_option('brainstrom_products') : array();
     $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array();
     $plugins = $themes = $mix = array();
     if (!empty($brainstrom_products)) {
         $plugins = isset($brainstrom_products['plugins']) ? $brainstrom_products['plugins'] : array();
         $themes = isset($brainstrom_products['themes']) ? $brainstrom_products['themes'] : array();
     }
     $mix = array_merge($plugins, $themes);
     $bsf_username = $purchase_key = $type = $template = $name = '';
     if (!empty($brainstrom_users)) {
         foreach ($brainstrom_users as $bsf_user) {
             $bsf_username = $bsf_user['email'];
         }
     }
     $found_in_bsf_products = false;
     if ($bundled_id !== false) {
         $product_details_id = $bundled_id;
     } else {
         $product_details_id = $request_product_id;
     }
     foreach ($mix as $key => $product) {
         $pid = $product['id'];
         if ($pid === $product_details_id) {
             $purchase_key = $product['purchase_key'];
             $type = $product['type'];
             $template = $product['template'];
             $name = $product['product_name'];
             $found_in_bsf_products = true;
             break;
         }
     }
     if ($bundled_id !== false) {
         if (!empty($brainstrom_bundled_products)) {
             foreach ($brainstrom_bundled_products as $bp) {
                 if ($bp->id === $request_product_id) {
                     $type = $bp->type;
                     $template = $bp->init;
                     $name = $bp->name;
                 }
             }
         }
     }
     if ($bsf_username === '' || $purchase_key === '' || $request_product_id === '') {
         wp_die('Not valid to update product');
     }
     $path = base64_decode($bsf_product_validate_url);
     $data = array('action' => 'bsf_product_update_request', 'id' => $request_product_id, 'username' => $bsf_username, 'purchase_key' => $purchase_key, 'site_url' => get_site_url(), 'bundled' => $bundled_id);
     $request = @wp_remote_post($path, array('body' => $data, 'timeout' => '60', 'sslverify' => false));
     if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
         $result = json_decode($request['body']);
         if (isset($result->error) && !$result->error) {
             $download_path = $result->update_data->download_url;
             $timezone = date_default_timezone_get();
             $call = 'file=' . $download_path . '&hashtime=' . strtotime(date('d-m-Y h:i:s a')) . '&timezone=' . $timezone;
             $hash = base64_encode($call);
             $parse = parse_url($path);
             $download = $parse['scheme'] . '://' . $parse['host'];
             $get_path = 'http://downloads.brainstormforce.com/';
             $download_path = rtrim($get_path, '/') . '/download.php?hash=' . $hash;
             //echo $download_path;
             //die();
             require_once ABSPATH . '/wp-admin/includes/file.php';
             WP_Filesystem();
             global $wp_filesystem;
             require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
             $WP_Upgrader = new WP_Upgrader();
             $res = $WP_Upgrader->fs_connect(array(WP_CONTENT_DIR));
             if (!$res) {
                 wp_die(new WP_Error('Server error', __("Error! Can't connect to filesystem", 'bsf')));
             } else {
                 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package';
                 $package_filename = basename($download_path);
                 $plugin_folder = dirname($template);
                 if ($type === 'theme' && $bundled_id === false) {
                     $defaults = array('clear_update_cache' => true);
                     $args = array();
                     $parsed_args = wp_parse_args($args, $defaults);
                     $Theme_Upgrader = new Theme_Upgrader();
                     $Theme_Upgrader->init();
                     $Theme_Upgrader->upgrade_strings();
                     $Theme_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');
                     add_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before'), 10, 2);
                     add_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after'), 10, 2);
                     add_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme'), 10, 4);
                     $Theme_Upgrader->run(array('package' => $download_path, 'destination' => get_theme_root($template), 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'hook_extra' => array('theme' => $template, 'type' => 'theme', 'action' => 'update')));
                     remove_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before'));
                     remove_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after'));
                     remove_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme'));
                     if (!$Theme_Upgrader->result || is_wp_error($Theme_Upgrader->result)) {
                         return $Theme_Upgrader->result;
                     }
                     wp_clean_themes_cache($parsed_args['clear_update_cache']);
                     $response = array('status' => true, 'type' => 'theme', 'name' => $name);
                     return $response;
                 } elseif ($type === 'plugin') {
                     $Plugin_Upgrader = new Plugin_Upgrader();
                     $Plugin_Upgrader->init();
                     $Plugin_Upgrader->upgrade_strings();
                     $Plugin_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf');
                     add_filter('upgrader_pre_install', array(&$Plugin_Upgrader, 'deactivate_plugin_before_upgrade'), 10, 2);
                     add_filter('upgrader_clear_destination', array(&$Plugin_Upgrader, 'delete_old_plugin'), 10, 4);
                     $Plugin_Upgrader->run(array('package' => $download_path, 'destination' => WP_PLUGIN_DIR, 'abort_if_destination_exists' => false, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin_folder)));
                     // Cleanup our hooks, in case something else does a upgrade on this connection.
                     remove_filter('upgrader_pre_install', array(&$Plugin_Upgrader, 'deactivate_plugin_before_upgrade'));
                     remove_filter('upgrader_clear_destination', array(&$Plugin_Upgrader, 'delete_old_plugin'));
                     if (!$Plugin_Upgrader->result || is_wp_error($Plugin_Upgrader->result)) {
                         return $Plugin_Upgrader->result;
                     }
                     if (is_dir($wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package')) {
                         $wp_filesystem->delete($wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package', true);
                     }
                     // Force refresh of plugin update information
                     delete_site_transient('update_plugins');
                     wp_cache_delete('plugins', 'plugins');
                     $response = array('status' => true, 'type' => 'plugin', 'name' => $name);
                     return $response;
                 }
             }
         } else {
             echo $result->message;
         }
     }
 }
Ejemplo n.º 18
0
/**
 * Install a plugin
 *
 * @param string $plugin_name
 * @return array
 */
function learn_press_install_add_on($plugin_name)
{
    require_once LPR_PLUGIN_PATH . '/inc/admin/class-lpr-upgrader.php';
    $upgrader = new LPR_Upgrader();
    global $wp_filesystem;
    $response = array();
    $package = 'http://thimpress.com/lprepo/' . $plugin_name . '.zip';
    $package = $upgrader->download_package($package);
    if (is_wp_error($package)) {
        $response['error'] = $package;
    } else {
        $working_dir = $upgrader->unpack_package($package, true, $plugin_name);
        if (is_wp_error($working_dir)) {
            $response['error'] = $working_dir;
        } else {
            $wp_upgrader = new WP_Upgrader();
            $options = array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install'));
            //$response = array();
            $result = $wp_upgrader->install_package($options);
            if (is_wp_error($result)) {
                $response['error'] = $result;
            } else {
                $response = $result;
                $response['text'] = __('Installed');
            }
        }
    }
    return $response;
}
Ejemplo n.º 19
0
 /**
  * Install a plugin from .org in the background via a cron job (used by
  * installer - opt in).
  * @param string $plugin_to_install_id
  * @param array $plugin_to_install
  * @since 2.6.0
  */
 public static function background_installer($plugin_to_install_id, $plugin_to_install)
 {
     if (!empty($plugin_to_install['repo-slug'])) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
         require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
         WP_Filesystem();
         $skin = new Automatic_Upgrader_Skin();
         $upgrader = new WP_Upgrader($skin);
         $installed_plugins = array_map(array(__CLASS__, 'format_plugin_slug'), array_keys(get_plugins()));
         $plugin_slug = $plugin_to_install['repo-slug'];
         $plugin = $plugin_slug . '/' . $plugin_slug . '.php';
         $installed = false;
         $activate = false;
         // See if the plugin is installed already
         if (in_array($plugin_to_install['repo-slug'], $installed_plugins)) {
             $installed = true;
             $activate = !is_plugin_active($plugin);
         }
         // Install this thing!
         if (!$installed) {
             // Suppress feedback
             ob_start();
             try {
                 $plugin_information = plugins_api('plugin_information', array('slug' => $plugin_to_install['repo-slug'], 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'homepage' => false, 'donate_link' => false, 'author_profile' => false, 'author' => false)));
                 if (is_wp_error($plugin_information)) {
                     throw new Exception($plugin_information->get_error_message());
                 }
                 $package = $plugin_information->download_link;
                 $download = $upgrader->download_package($package);
                 if (is_wp_error($download)) {
                     throw new Exception($download->get_error_message());
                 }
                 $working_dir = $upgrader->unpack_package($download, true);
                 if (is_wp_error($working_dir)) {
                     throw new Exception($working_dir->get_error_message());
                 }
                 $result = $upgrader->install_package(array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install')));
                 if (is_wp_error($result)) {
                     throw new Exception($result->get_error_message());
                 }
                 $activate = true;
             } catch (Exception $e) {
                 WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], $e->getMessage(), esc_url(admin_url('index.php?wc-install-plugin-redirect=' . $plugin_to_install['repo-slug']))));
             }
             // Discard feedback
             ob_end_clean();
         }
         wp_clean_plugins_cache();
         // Activate this thing
         if ($activate) {
             try {
                 $result = activate_plugin($plugin);
                 if (is_wp_error($result)) {
                     throw new Exception($result->get_error_message());
                 }
             } catch (Exception $e) {
                 WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], admin_url('plugins.php')));
             }
         }
     }
 }
Ejemplo n.º 20
0
 function __construct()
 {
     $skin = new WPtouchIconSetSkin();
     parent::__construct($skin);
 }
 /**
  * References parent constructor and sets defaults for class.
  *
  * @since 2.2.0
  */
 public function __construct($skin = null)
 {
     // Get TGMPA class instance
     $this->tgmpa = call_user_func(array(get_class($GLOBALS['tgmpa']), 'get_instance'));
     parent::__construct($skin);
 }
Ejemplo n.º 22
0
 function unpack_package($package, $delete_package = true)
 {
     global $wp_filesystem, $updraftplus;
     $updraft_dir = $updraftplus->backups_dir_location();
     // If not database, then it is a zip - unpack in the usual way
     if (!preg_match('/db\\.gz(\\.crypt)?$/i', $package)) {
         return parent::unpack_package($updraft_dir . '/' . $package, $delete_package);
     }
     $backup_dir = $wp_filesystem->find_folder($updraft_dir);
     // Unpack a database. The general shape of the following is copied from class-wp-upgrader.php
     @set_time_limit(1800);
     $this->skin->feedback('unpack_package');
     $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
     @$wp_filesystem->mkdir($upgrade_folder, 0775);
     //Clean up contents of upgrade directory beforehand.
     $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
     if (!empty($upgrade_files)) {
         foreach ($upgrade_files as $file) {
             $wp_filesystem->delete($upgrade_folder . $file['name'], true);
         }
     }
     //We need a working directory
     $working_dir = $upgrade_folder . basename($package, '.crypt');
     # $working_dir_filesystem = WP_CONTENT_DIR.'/upgrade/'. basename($package, '.crypt');
     // Clean up working directory
     if ($wp_filesystem->is_dir($working_dir)) {
         $wp_filesystem->delete($working_dir, true);
     }
     if (!$wp_filesystem->mkdir($working_dir, 0775)) {
         return new WP_Error('mkdir_failed', __('Failed to create a temporary directory', 'updraftplus') . ' (' . $working_dir . ')');
     }
     // Unpack package to working directory
     if ($updraftplus->is_db_encrypted($package)) {
         $this->skin->feedback('decrypt_database');
         $encryption = UpdraftPlus_Options::get_updraft_option('updraft_encryptionphrase');
         if (!$encryption) {
             return new WP_Error('no_encryption_key', __('Decryption failed. The database file is encrypted, but you have no encryption key entered.', 'updraftplus'));
         }
         // Encrypted - decrypt it
         require_once UPDRAFTPLUS_DIR . '/includes/phpseclib/Crypt/Rijndael.php';
         $rijndael = new Crypt_Rijndael();
         // Get decryption key
         $rijndael->setKey($encryption);
         $ciphertext = $rijndael->decrypt($wp_filesystem->get_contents($backup_dir . $package));
         if ($ciphertext) {
             $this->skin->feedback('decrypted_database');
             if (!$wp_filesystem->put_contents($working_dir . '/backup.db.gz', $ciphertext)) {
                 return new WP_Error('write_failed', __('Failed to write out the decrypted database to the filesystem', 'updraftplus'));
             }
         } else {
             return new WP_Error('decryption_failed', __('Decryption failed. The most likely cause is that you used the wrong key.', 'updraftplus'));
         }
     } else {
         if (!$wp_filesystem->copy($backup_dir . $package, $working_dir . '/backup.db.gz')) {
             if ($wp_filesystem->errors->get_error_code()) {
                 foreach ($wp_filesystem->errors->get_error_messages() as $message) {
                     show_message($message);
                 }
             }
             return new WP_Error('copy_failed', $this->strings['copy_failed']);
         }
     }
     // Once extracted, delete the package if required (non-recursive, is a file)
     if ($delete_package) {
         $wp_filesystem->delete($backup_dir . $package, false, true);
     }
     return $working_dir;
 }