/** * If a requested theme/plugin is from wordpress.org -OR- from us, let it through * @param array $options */ public function run($options) { $_options = get_option('gd_quicksetup_options'); if (preg_match('/(?:(\\.)?wordpress\\.org|' . preg_quote(parse_url($_options['api_url'], PHP_URL_HOST)) . ')$/', parse_url($options['package'], PHP_URL_HOST))) { // Some older servers don't have our SSL certs in their bundle add_filter('https_ssl_verify', '__return_false'); parent::run($options); remove_filter('https_local_ssl_verify', '__return_false'); } }
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; } } }