3 * A File upgrader class for WordPress.
5 * This set of classes are designed to be used to upgrade/install a local set of files on the filesystem via the Filesystem Abstraction classes.
7 * @link http://trac.wordpress.org/ticket/7875 consolidate plugin/theme/core upgrade/install functions
10 * @subpackage Upgrader
15 * WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file.
17 * @TODO More Detailed docs, for methods as well.
20 * @subpackage Upgrader
24 var $strings = array();
26 var $result = array();
28 function WP_Upgrader($skin = null) {
29 return $this->__construct($skin);
31 function __construct($skin = null) {
33 $this->skin = new WP_Upgrader_Skin();
39 $this->skin->set_upgrader($this);
40 $this->generic_strings();
43 function generic_strings() {
44 $this->strings['bad_request'] = __('Invalid Data provided.');
45 $this->strings['fs_unavailable'] = __('Could not access filesystem.');
46 $this->strings['fs_error'] = __('Filesystem error.');
47 $this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.');
48 $this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).');
49 $this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.');
50 $this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.');
51 /* translators: %s: directory name */
52 $this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).');
54 $this->strings['download_failed'] = __('Download failed.');
55 $this->strings['installing_package'] = __('Installing the latest version…');
56 $this->strings['folder_exists'] = __('Destination folder already exists.');
57 $this->strings['mkdir_failed'] = __('Could not create directory.');
58 $this->strings['bad_package'] = __('Incompatible Archive.');
60 $this->strings['maintenance_start'] = __('Enabling Maintenance mode…');
61 $this->strings['maintenance_end'] = __('Disabling Maintenance mode…');
64 function fs_connect( $directories = array() ) {
65 global $wp_filesystem;
67 if ( false === ($credentials = $this->skin->request_filesystem_credentials()) )
70 if ( ! WP_Filesystem($credentials) ) {
72 if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() )
73 $error = $wp_filesystem->errors;
74 $this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again
78 if ( ! is_object($wp_filesystem) )
79 return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] );
81 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
82 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors);
84 foreach ( (array)$directories as $dir ) {
87 if ( ! $wp_filesystem->abspath() )
88 return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']);
91 if ( ! $wp_filesystem->wp_content_dir() )
92 return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']);
95 if ( ! $wp_filesystem->wp_plugins_dir() )
96 return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']);
98 case WP_CONTENT_DIR . '/themes':
99 if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') )
100 return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']);
103 if ( ! $wp_filesystem->find_folder($dir) )
104 return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir));
109 } //end fs_connect();
111 function download_package($package) {
113 if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote?
114 return $package; //must be a local file..
116 if ( empty($package) )
117 return new WP_Error('no_package', $this->strings['no_package']);
119 $this->skin->feedback('downloading_package', $package);
121 $download_file = download_url($package);
123 if ( is_wp_error($download_file) )
124 return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message());
126 return $download_file;
129 function unpack_package($package, $delete_package = true) {
130 global $wp_filesystem;
132 $this->skin->feedback('unpack_package');
134 $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
136 //Clean up contents of upgrade directory beforehand.
137 $upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
138 if ( !empty($upgrade_files) ) {
139 foreach ( $upgrade_files as $file )
140 $wp_filesystem->delete($upgrade_folder . $file['name'], true);
143 //We need a working directory
144 $working_dir = $upgrade_folder . basename($package, '.zip');
146 // Clean up working directory
147 if ( $wp_filesystem->is_dir($working_dir) )
148 $wp_filesystem->delete($working_dir, true);
150 // Unzip package to working directory
151 $result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice?
153 // Once extracted, delete the package if required.
154 if ( $delete_package )
157 if ( is_wp_error($result) ) {
158 $wp_filesystem->delete($working_dir, true);
165 function install_package($args = array()) {
166 global $wp_filesystem;
167 $defaults = array( 'source' => '', 'destination' => '', //Please always pass these
168 'clear_destination' => false, 'clear_working' => false,
169 'hook_extra' => array());
171 $args = wp_parse_args($args, $defaults);
174 @set_time_limit( 300 );
176 if ( empty($source) || empty($destination) )
177 return new WP_Error('bad_request', $this->strings['bad_request']);
179 $this->skin->feedback('installing_package');
181 $res = apply_filters('upgrader_pre_install', true, $hook_extra);
182 if ( is_wp_error($res) )
185 //Retain the Original source and destinations
186 $remote_source = $source;
187 $local_destination = $destination;
189 $source_files = array_keys( $wp_filesystem->dirlist($remote_source) );
190 $remote_destination = $wp_filesystem->find_folder($local_destination);
192 //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
193 if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
194 $source = trailingslashit($source) . trailingslashit($source_files[0]);
195 elseif ( count($source_files) == 0 )
196 return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files?
197 //else //Its only a single file, The upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
199 //Hook ability to change the source file location..
200 $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
201 if ( is_wp_error($source) )
204 //Has the source location changed? If so, we need a new source_files list.
205 if ( $source !== $remote_source )
206 $source_files = array_keys( $wp_filesystem->dirlist($source) );
208 //Protection against deleting files in any important base directories.
209 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) {
210 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
211 $destination = trailingslashit($destination) . trailingslashit(basename($source));
214 if ( $wp_filesystem->exists($remote_destination) ) {
215 if ( $clear_destination ) {
216 //We're going to clear the destination if theres something there
217 $this->skin->feedback('remove_old');
218 $removed = $wp_filesystem->delete($remote_destination, true);
219 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
221 if ( is_wp_error($removed) )
223 else if ( ! $removed )
224 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
226 //If we're not clearing the destination folder and something exists there allready, Bail.
227 //But first check to see if there are actually any files in the folder.
228 $_files = $wp_filesystem->dirlist($remote_destination);
229 if ( ! empty($_files) ) {
230 $wp_filesystem->delete($remote_source, true); //Clear out the source files.
231 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination );
236 //Create destination if needed
237 if ( !$wp_filesystem->exists($remote_destination) )
238 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) )
239 return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
241 // Copy new version of item into place.
242 $result = copy_dir($source, $remote_destination);
243 if ( is_wp_error($result) ) {
244 if ( $clear_working )
245 $wp_filesystem->delete($remote_source, true);
249 //Clear the Working folder?
250 if ( $clear_working )
251 $wp_filesystem->delete($remote_source, true);
253 $destination_name = basename( str_replace($local_destination, '', $destination) );
254 if ( '.' == $destination_name )
255 $destination_name = '';
257 $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
259 $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result);
260 if ( is_wp_error($res) ) {
261 $this->result = $res;
265 //Bombard the calling function will all the info which we've just used.
266 return $this->result;
269 function run($options) {
271 $defaults = array( 'package' => '', //Please always pass this.
272 'destination' => '', //And this
273 'clear_destination' => false,
274 'clear_working' => true,
276 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters.
279 $options = wp_parse_args($options, $defaults);
282 //Connect to the Filesystem first.
283 $res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) );
284 if ( ! $res ) //Mainly for non-connected filesystem.
287 if ( is_wp_error($res) ) {
288 $this->skin->error($res);
292 if ( !$is_multi ) // call $this->header separately if running multiple times
293 $this->skin->header();
295 $this->skin->before();
297 //Download the package (Note, This just returns the filename of the file if the package is a local file)
298 $download = $this->download_package( $package );
299 if ( is_wp_error($download) ) {
300 $this->skin->error($download);
301 $this->skin->after();
305 //Unzip's the file into a temporary directory
306 $working_dir = $this->unpack_package( $download );
307 if ( is_wp_error($working_dir) ) {
308 $this->skin->error($working_dir);
309 $this->skin->after();
313 //With the given options, this installs it to the destination directory.
314 $result = $this->install_package( array(
315 'source' => $working_dir,
316 'destination' => $destination,
317 'clear_destination' => $clear_destination,
318 'clear_working' => $clear_working,
319 'hook_extra' => $hook_extra
321 $this->skin->set_result($result);
322 if ( is_wp_error($result) ) {
323 $this->skin->error($result);
324 $this->skin->feedback('process_failed');
327 $this->skin->feedback('process_success');
329 $this->skin->after();
332 $this->skin->footer();
337 function maintenance_mode($enable = false) {
338 global $wp_filesystem;
339 $file = $wp_filesystem->abspath() . '.maintenance';
341 $this->skin->feedback('maintenance_start');
342 // Create maintenance file to signal that we are upgrading
343 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
344 $wp_filesystem->delete($file);
345 $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
346 } else if ( !$enable && $wp_filesystem->exists($file) ) {
347 $this->skin->feedback('maintenance_end');
348 $wp_filesystem->delete($file);
355 * Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file.
357 * @TODO More Detailed docs, for methods as well.
360 * @subpackage Upgrader
363 class Plugin_Upgrader extends WP_Upgrader {
367 var $show_before = '';
369 function upgrade_strings() {
370 $this->strings['up_to_date'] = __('The plugin is at the latest version.');
371 $this->strings['no_package'] = __('Upgrade package not available.');
372 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
373 $this->strings['unpack_package'] = __('Unpacking the update…');
374 $this->strings['deactivate_plugin'] = __('Deactivating the plugin…');
375 $this->strings['remove_old'] = __('Removing the old version of the plugin…');
376 $this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
377 $this->strings['process_failed'] = __('Plugin upgrade failed.');
378 $this->strings['process_success'] = __('Plugin upgraded successfully.');
381 function install_strings() {
382 $this->strings['no_package'] = __('Install package not available.');
383 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
384 $this->strings['unpack_package'] = __('Unpacking the package…');
385 $this->strings['installing_package'] = __('Installing the plugin…');
386 $this->strings['process_failed'] = __('Plugin install failed.');
387 $this->strings['process_success'] = __('Plugin installed successfully.');
390 function install($package) {
393 $this->install_strings();
396 'package' => $package,
397 'destination' => WP_PLUGIN_DIR,
398 'clear_destination' => false, //Do not overwrite files.
399 'clear_working' => true,
400 'hook_extra' => array()
403 // Force refresh of plugin update information
404 delete_site_transient('update_plugins');
408 function upgrade($plugin) {
411 $this->upgrade_strings();
413 $current = get_site_transient( 'update_plugins' );
414 if ( !isset( $current->response[ $plugin ] ) ) {
415 $this->skin->before();
416 $this->skin->set_result(false);
417 $this->skin->error('up_to_date');
418 $this->skin->after();
422 // Get the URL to the zip file
423 $r = $current->response[ $plugin ];
425 add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
426 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
427 //'source_selection' => array(&$this, 'source_selection'), //theres a track ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
430 'package' => $r->package,
431 'destination' => WP_PLUGIN_DIR,
432 'clear_destination' => true,
433 'clear_working' => true,
434 'hook_extra' => array(
439 // Cleanup our hooks, incase something else does a upgrade on this connection.
440 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
441 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
443 if ( ! $this->result || is_wp_error($this->result) )
444 return $this->result;
446 // Force refresh of plugin update information
447 delete_site_transient('update_plugins');
450 function bulk_upgrade($plugins) {
454 $this->upgrade_strings();
456 $current = get_site_transient( 'update_plugins' );
458 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
460 $this->skin->header();
462 // Connect to the Filesystem first.
463 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
465 $this->skin->footer();
469 $this->skin->bulk_header();
471 $this->maintenance_mode(true);
475 $this->update_count = count($plugins);
476 $this->update_current = 0;
477 foreach ( $plugins as $plugin ) {
478 $this->update_current++;
479 $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
481 if ( !isset( $current->response[ $plugin ] ) ) {
482 $this->skin->set_result(false);
483 $this->skin->before();
484 $this->skin->error('up_to_date');
485 $this->skin->after();
486 $results[$plugin] = false;
490 // Get the URL to the zip file
491 $r = $current->response[ $plugin ];
493 $this->skin->plugin_active = is_plugin_active($plugin);
495 $result = $this->run(array(
496 'package' => $r->package,
497 'destination' => WP_PLUGIN_DIR,
498 'clear_destination' => true,
499 'clear_working' => true,
501 'hook_extra' => array(
506 $results[$plugin] = $this->result;
508 // Prevent credentials auth screen from displaying multiple times
509 if ( false === $result )
511 } //end foreach $plugins
513 $this->maintenance_mode(false);
515 $this->skin->bulk_footer();
517 $this->skin->footer();
519 // Cleanup our hooks, incase something else does a upgrade on this connection.
520 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
522 // Force refresh of plugin update information
523 delete_site_transient('update_plugins');
528 //return plugin info.
529 function plugin_info() {
530 if ( ! is_array($this->result) )
532 if ( empty($this->result['destination_name']) )
535 $plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
536 if ( empty($plugin) )
539 $pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
541 return $this->result['destination_name'] . '/' . $pluginfiles[0];
544 //Hooked to pre_install
545 function deactivate_plugin_before_upgrade($return, $plugin) {
547 if ( is_wp_error($return) ) //Bypass.
550 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
551 if ( empty($plugin) )
552 return new WP_Error('bad_request', $this->strings['bad_request']);
554 if ( is_plugin_active($plugin) ) {
555 $this->skin->feedback('deactivate_plugin');
556 //Deactivate the plugin silently, Prevent deactivation hooks from running.
557 deactivate_plugins($plugin, true);
561 //Hooked to upgrade_clear_destination
562 function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
563 global $wp_filesystem;
565 if ( is_wp_error($removed) )
566 return $removed; //Pass errors through.
568 $plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
569 if ( empty($plugin) )
570 return new WP_Error('bad_request', $this->strings['bad_request']);
572 $plugins_dir = $wp_filesystem->wp_plugins_dir();
573 $this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
575 if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished.
578 // If plugin is in its own directory, recursively delete the directory.
579 if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory seperator AND that its not the root plugin folder
580 $deleted = $wp_filesystem->delete($this_plugin_dir, true);
582 $deleted = $wp_filesystem->delete($plugins_dir . $plugin);
585 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
592 * Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file.
594 * @TODO More Detailed docs, for methods as well.
597 * @subpackage Upgrader
600 class Theme_Upgrader extends WP_Upgrader {
604 function upgrade_strings() {
605 $this->strings['up_to_date'] = __('The theme is at the latest version.');
606 $this->strings['no_package'] = __('Upgrade package not available.');
607 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
608 $this->strings['unpack_package'] = __('Unpacking the update…');
609 $this->strings['remove_old'] = __('Removing the old version of the theme…');
610 $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
611 $this->strings['process_failed'] = __('Theme upgrade failed.');
612 $this->strings['process_success'] = __('Theme upgraded successfully.');
615 function install_strings() {
616 $this->strings['no_package'] = __('Install package not available.');
617 $this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…');
618 $this->strings['unpack_package'] = __('Unpacking the package…');
619 $this->strings['installing_package'] = __('Installing the theme…');
620 $this->strings['process_failed'] = __('Theme install failed.');
621 $this->strings['process_success'] = __('Theme installed successfully.');
624 function install($package) {
627 $this->install_strings();
630 'package' => $package,
631 'destination' => WP_CONTENT_DIR . '/themes',
632 'clear_destination' => false, //Do not overwrite files.
633 'clear_working' => true
636 $this->run($options);
638 if ( ! $this->result || is_wp_error($this->result) )
639 return $this->result;
641 // Force refresh of theme update information
642 delete_site_transient('update_themes');
644 if ( empty($result['destination_name']) )
647 return $result['destination_name'];
650 function upgrade($theme) {
653 $this->upgrade_strings();
655 // Is an update available?
656 $current = get_site_transient( 'update_themes' );
657 if ( !isset( $current->response[ $theme ] ) ) {
658 $this->skin->before();
659 $this->skin->set_result(false);
660 $this->skin->error('up_to_date');
661 $this->skin->after();
665 $r = $current->response[ $theme ];
667 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
668 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
669 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
672 'package' => $r['package'],
673 'destination' => WP_CONTENT_DIR . '/themes',
674 'clear_destination' => true,
675 'clear_working' => true,
676 'hook_extra' => array(
681 $this->run($options);
683 if ( ! $this->result || is_wp_error($this->result) )
684 return $this->result;
686 // Force refresh of theme update information
687 delete_site_transient('update_themes');
692 function bulk_upgrade($themes) {
696 $this->upgrade_strings();
698 $current = get_site_transient( 'update_themes' );
700 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
701 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
702 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
704 $this->skin->header();
706 // Connect to the Filesystem first.
707 $res = $this->fs_connect( array(WP_CONTENT_DIR) );
709 $this->skin->footer();
713 $this->skin->bulk_header();
715 $this->maintenance_mode(true);
719 $this->update_count = count($themes);
720 $this->update_current = 0;
721 foreach ( $themes as $theme ) {
722 $this->update_current++;
724 if ( !isset( $current->response[ $theme ] ) ) {
725 $this->skin->set_result(false);
726 $this->skin->before();
727 $this->skin->error('up_to_date');
728 $this->skin->after();
729 $results[$theme] = false;
733 $this->skin->theme_info = $this->theme_info($theme);
735 // Get the URL to the zip file
736 $r = $current->response[ $theme ];
739 'package' => $r['package'],
740 'destination' => WP_CONTENT_DIR . '/themes',
741 'clear_destination' => true,
742 'clear_working' => true,
743 'hook_extra' => array(
748 $result = $this->run($options);
750 $results[$theme] = $this->result;
752 // Prevent credentials auth screen from displaying multiple times
753 if ( false === $result )
755 } //end foreach $plugins
757 $this->maintenance_mode(false);
759 $this->skin->bulk_footer();
761 $this->skin->footer();
763 // Cleanup our hooks, incase something else does a upgrade on this connection.
764 remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
765 remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
766 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
768 // Force refresh of theme update information
769 delete_site_transient('update_themes');
774 function current_before($return, $theme) {
776 if ( is_wp_error($return) )
779 $theme = isset($theme['theme']) ? $theme['theme'] : '';
781 if ( $theme != get_stylesheet() ) //If not current
783 //Change to maintainence mode now.
785 $this->maintenance_mode(true);
789 function current_after($return, $theme) {
790 if ( is_wp_error($return) )
793 $theme = isset($theme['theme']) ? $theme['theme'] : '';
795 if ( $theme != get_stylesheet() ) //If not current
798 //Ensure stylesheet name hasnt changed after the upgrade:
799 if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
800 $theme_info = $this->theme_info();
801 $stylesheet = $this->result['destination_name'];
802 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
803 switch_theme($template, $stylesheet, true);
806 //Time to remove maintainence mode
808 $this->maintenance_mode(false);
812 function delete_old_theme($removed, $local_destination, $remote_destination, $theme) {
813 global $wp_filesystem;
815 $theme = isset($theme['theme']) ? $theme['theme'] : '';
817 if ( is_wp_error($removed) || empty($theme) )
818 return $removed; //Pass errors through.
820 $themes_dir = $wp_filesystem->wp_themes_dir();
821 if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) )
822 if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) )
827 function theme_info($theme = null) {
829 if ( empty($theme) ) {
830 if ( !empty($this->result['destination_name']) )
831 $theme = $this->result['destination_name'];
835 return get_theme_data(WP_CONTENT_DIR . '/themes/' . $theme . '/style.css');
841 * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file
843 * @TODO More Detailed docs, for methods as well.
846 * @subpackage Upgrader
849 class Core_Upgrader extends WP_Upgrader {
851 function upgrade_strings() {
852 $this->strings['up_to_date'] = __('WordPress is at the latest version.');
853 $this->strings['no_package'] = __('Upgrade package not available.');
854 $this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…');
855 $this->strings['unpack_package'] = __('Unpacking the update…');
856 $this->strings['copy_failed'] = __('Could not copy files.');
859 function upgrade($current) {
860 global $wp_filesystem;
863 $this->upgrade_strings();
865 if ( !empty($feedback) )
866 add_filter('update_feedback', $feedback);
868 // Is an update available?
869 if ( !isset( $current->response ) || $current->response == 'latest' )
870 return new WP_Error('up_to_date', $this->strings['up_to_date']);
872 $res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) );
873 if ( is_wp_error($res) )
876 $wp_dir = trailingslashit($wp_filesystem->abspath());
878 $download = $this->download_package( $current->package );
879 if ( is_wp_error($download) )
882 $working_dir = $this->unpack_package( $download );
883 if ( is_wp_error($working_dir) )
886 // Copy update-core.php from the new version into place.
887 if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {
888 $wp_filesystem->delete($working_dir, true);
889 return new WP_Error('copy_failed', $this->strings['copy_failed']);
891 $wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE);
893 require(ABSPATH . 'wp-admin/includes/update-core.php');
895 return update_core($working_dir, $wp_dir);
901 * Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes.
903 * @TODO More Detailed docs, for methods as well.
906 * @subpackage Upgrader
909 class WP_Upgrader_Skin {
912 var $done_header = false;
915 function WP_Upgrader_Skin($args = array()) {
916 return $this->__construct($args);
918 function __construct($args = array()) {
919 $defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
920 $this->options = wp_parse_args($args, $defaults);
923 function set_upgrader(&$upgrader) {
924 if ( is_object($upgrader) )
925 $this->upgrader =& $upgrader;
926 $this->add_strings();
929 function add_strings() {
932 function set_result($result) {
933 $this->result = $result;
936 function request_filesystem_credentials($error = false) {
937 $url = $this->options['url'];
938 $context = $this->options['context'];
939 if ( !empty($this->options['nonce']) )
940 $url = wp_nonce_url($url, $this->options['nonce']);
941 return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now.
945 if ( $this->done_header )
947 $this->done_header = true;
948 echo '<div class="wrap">';
950 echo '<h2>' . $this->options['title'] . '</h2>';
956 function error($errors) {
957 if ( ! $this->done_header )
959 if ( is_string($errors) ) {
960 $this->feedback($errors);
961 } elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
962 foreach ( $errors->get_error_messages() as $message ) {
963 if ( $errors->get_error_data() )
964 $this->feedback($message . ' ' . $errors->get_error_data() );
966 $this->feedback($message);
971 function feedback($string) {
972 if ( isset( $this->upgrader->strings[$string] ) )
973 $string = $this->upgrader->strings[$string];
975 if ( strpos($string, '%') !== false ) {
976 $args = func_get_args();
977 $args = array_splice($args, 1);
979 $string = vsprintf($string, $args);
981 if ( empty($string) )
983 show_message($string);
991 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
993 * @TODO More Detailed docs, for methods as well.
996 * @subpackage Upgrader
999 class Plugin_Upgrader_Skin extends WP_Upgrader_Skin {
1001 var $plugin_active = false;
1002 var $plugin_network_active = false;
1004 function Plugin_Upgrader_Skin($args = array()) {
1005 return $this->__construct($args);
1008 function __construct($args = array()) {
1009 $defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Upgrade Plugin') );
1010 $args = wp_parse_args($args, $defaults);
1012 $this->plugin = $args['plugin'];
1014 $this->plugin_active = is_plugin_active( $this->plugin );
1015 $this->plugin_network_active = is_plugin_active_for_network( $this->plugin );
1017 parent::__construct($args);
1021 $this->plugin = $this->upgrader->plugin_info();
1022 if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){
1023 show_message(__('Reactivating the plugin…'));
1024 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>';
1027 $update_actions = array(
1028 'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>',
1029 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'
1031 if ( $this->plugin_active )
1032 unset( $update_actions['activate_plugin'] );
1033 if ( ! $this->result || is_wp_error($this->result) )
1034 unset( $update_actions['activate_plugin'] );
1036 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin);
1037 if ( ! empty($update_actions) )
1038 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
1042 if ( $this->upgrader->show_before ) {
1043 echo $this->upgrader->show_before;
1044 $this->upgrader->show_before = '';
1050 * Plugin Upgrader Skin for WordPress Plugin Upgrades.
1052 * @package WordPress
1053 * @subpackage Upgrader
1056 class Bulk_Upgrader_Skin extends WP_Upgrader_Skin {
1057 var $in_loop = false;
1060 function Bulk_Upgrader_Skin($args = array()) {
1061 return $this->__construct($args);
1064 function __construct($args = array()) {
1065 $defaults = array( 'url' => '', 'nonce' => '' );
1066 $args = wp_parse_args($args, $defaults);
1068 parent::__construct($args);
1071 function add_strings() {
1072 $this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take awhile on some hosts, so please be patient.');
1073 $this->upgrader->strings['skin_update_failed_error'] = __('An error occured while updating %1$s: <strong>%2$s</strong>.');
1074 $this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.');
1075 $this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>'.__('Show Details').'</span><span class="hidden">'.__('Hide Details').'</span>.</a>';
1076 $this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.');
1079 function feedback($string) {
1080 if ( isset( $this->upgrader->strings[$string] ) )
1081 $string = $this->upgrader->strings[$string];
1083 if ( strpos($string, '%') !== false ) {
1084 $args = func_get_args();
1085 $args = array_splice($args, 1);
1086 if ( !empty($args) )
1087 $string = vsprintf($string, $args);
1089 if ( empty($string) )
1091 if ( $this->in_loop )
1092 echo "$string<br />\n";
1094 echo "<p>$string</p>\n";
1098 // Nothing, This will be displayed within a iframe.
1102 // Nothing, This will be displayed within a iframe.
1104 function error($error) {
1105 if ( is_string($error) && isset( $this->upgrader->strings[$error] ) )
1106 $this->error = $this->upgrader->strings[$error];
1108 if ( is_wp_error($error) ) {
1109 foreach ( $error->get_error_messages() as $emessage ) {
1110 if ( $error->get_error_data() )
1111 $messages[] = $emessage . ' ' . $error->get_error_data();
1113 $messages[] = $emessage;
1115 $this->error = implode(', ', $messages);
1117 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1120 function bulk_header() {
1121 $this->feedback('skin_upgrade_start');
1124 function bulk_footer() {
1125 $this->feedback('skin_upgrade_end');
1128 function before($title = '') {
1129 $this->in_loop = true;
1130 printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <img alt="" src="' . admin_url( 'images/wpspin_light.gif' ) . '" class="hidden waiting-' . $this->upgrader->update_current . '" style="vertical-align:middle;" /></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count);
1131 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1132 echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>';
1133 $this->flush_output();
1136 function after($title = '') {
1138 if ( $this->error || ! $this->result ) {
1140 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>';
1142 echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>';
1144 echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>';
1146 if ( !empty($this->result) && !is_wp_error($this->result) ) {
1147 echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>';
1148 echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>';
1152 $this->flush_output();
1156 $this->in_loop = false;
1157 $this->error = false;
1160 function flush_output() {
1161 wp_ob_end_flush_all();
1166 class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin {
1167 var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in.
1168 function Plugin_Upgrader_Skin($args = array()) {
1169 parent::__construct($args);
1172 function add_strings() {
1173 parent::add_strings();
1174 $this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)');
1178 parent::before($this->plugin_info['Title']);
1182 parent::after($this->plugin_info['Title']);
1184 function bulk_footer() {
1185 parent::bulk_footer();
1186 $update_actions = array(
1187 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>',
1188 'updates_page' => '<a href="' . admin_url('update-core.php') . '" title="' . esc_attr__('Goto WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
1191 $update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info);
1192 if ( ! empty($update_actions) )
1193 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
1197 class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin {
1198 var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in.
1199 function Theme_Upgrader_Skin($args = array()) {
1200 parent::__construct($args);
1203 function add_strings() {
1204 parent::add_strings();
1205 $this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)');
1209 parent::before($this->theme_info['Name']);
1213 parent::after($this->theme_info['Name']);
1215 function bulk_footer() {
1216 parent::bulk_footer();
1217 $update_actions = array(
1218 'themes_page' => '<a href="' . admin_url('themes.php') . '" title="' . esc_attr__('Goto themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>',
1219 'updates_page' => '<a href="' . admin_url('update-core.php') . '" title="' . esc_attr__('Goto WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>'
1222 $update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info);
1223 if ( ! empty($update_actions) )
1224 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
1229 * Plugin Installer Skin for WordPress Plugin Installer.
1231 * @TODO More Detailed docs, for methods as well.
1233 * @package WordPress
1234 * @subpackage Upgrader
1237 class Plugin_Installer_Skin extends WP_Upgrader_Skin {
1241 function Plugin_Installer_Skin($args = array()) {
1242 return $this->__construct($args);
1245 function __construct($args = array()) {
1246 $defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' );
1247 $args = wp_parse_args($args, $defaults);
1249 $this->type = $args['type'];
1250 $this->api = isset($args['api']) ? $args['api'] : array();
1252 parent::__construct($args);
1256 if ( !empty($this->api) )
1257 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version);
1262 $plugin_file = $this->upgrader->plugin_info();
1264 $install_actions = array();
1266 $from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins';
1268 if ( 'import' == $from )
1269 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&from=import&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin & Run Importer') . '</a>';
1271 $install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
1273 if ( is_multisite() && current_user_can( 'manage_network_plugins' ) )
1274 $install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . __('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>';
1276 if ( 'import' == $from )
1277 $install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>';
1278 else if ( $this->type == 'web' )
1279 $install_actions['plugins_page'] = '<a href="' . admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>';
1281 $install_actions['plugins_page'] = '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>';
1284 if ( ! $this->result || is_wp_error($this->result) ) {
1285 unset( $install_actions['activate_plugin'] );
1286 unset( $install_actions['network_activate'] );
1288 $install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file);
1289 if ( ! empty($install_actions) )
1290 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
1295 * Theme Installer Skin for the WordPress Theme Installer.
1297 * @TODO More Detailed docs, for methods as well.
1299 * @package WordPress
1300 * @subpackage Upgrader
1303 class Theme_Installer_Skin extends WP_Upgrader_Skin {
1307 function Theme_Installer_Skin($args = array()) {
1308 return $this->__construct($args);
1311 function __construct($args = array()) {
1312 $defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' );
1313 $args = wp_parse_args($args, $defaults);
1315 $this->type = $args['type'];
1316 $this->api = isset($args['api']) ? $args['api'] : array();
1318 parent::__construct($args);
1322 if ( !empty($this->api) ) {
1323 /* translators: 1: theme name, 2: version */
1324 $this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the theme <strong>%1$s %2$s</strong>.'), $this->api->name, $this->api->version);
1329 if ( empty($this->upgrader->result['destination_name']) )
1332 $theme_info = $this->upgrader->theme_info();
1333 if ( empty($theme_info) )
1335 $name = $theme_info['Name'];
1336 $stylesheet = $this->upgrader->result['destination_name'];
1337 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1339 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1340 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1342 $install_actions = array(
1343 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>',
1344 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'
1347 if ( $this->type == 'web' )
1348 $install_actions['themes_page'] = '<a href="' . admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>';
1350 $install_actions['themes_page'] = '<a href="' . admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
1352 if ( ! $this->result || is_wp_error($this->result) )
1353 unset( $install_actions['activate'], $install_actions['preview'] );
1355 $install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info);
1356 if ( ! empty($install_actions) )
1357 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$install_actions));
1362 * Theme Upgrader Skin for WordPress Theme Upgrades.
1364 * @TODO More Detailed docs, for methods as well.
1366 * @package WordPress
1367 * @subpackage Upgrader
1370 class Theme_Upgrader_Skin extends WP_Upgrader_Skin {
1373 function Theme_Upgrader_Skin($args = array()) {
1374 return $this->__construct($args);
1377 function __construct($args = array()) {
1378 $defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Upgrade Theme') );
1379 $args = wp_parse_args($args, $defaults);
1381 $this->theme = $args['theme'];
1383 parent::__construct($args);
1388 $update_actions = array();
1389 if ( !empty($this->upgrader->result['destination_name']) &&
1390 ($theme_info = $this->upgrader->theme_info()) &&
1391 !empty($theme_info) ) {
1393 $name = $theme_info['Name'];
1394 $stylesheet = $this->upgrader->result['destination_name'];
1395 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet;
1397 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) );
1398 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template);
1400 $update_actions['preview'] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>';
1401 $update_actions['activate'] = '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>';
1403 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() )
1404 unset($update_actions['preview'], $update_actions['activate']);
1407 $update_actions['themes_page'] = '<a href="' . admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>';
1409 $update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme);
1410 if ( ! empty($update_actions) )
1411 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions));
1416 * Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if its a local file to the Upgrade/Installer functions.
1418 * @TODO More Detailed docs, for methods as well.
1420 * @package WordPress
1421 * @subpackage Upgrader
1424 class File_Upload_Upgrader {
1428 function File_Upload_Upgrader($form, $urlholder) {
1429 return $this->__construct($form, $urlholder);
1431 function __construct($form, $urlholder) {
1432 if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
1433 wp_die($uploads['error']);
1435 if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
1436 wp_die(__('Please select a file'));
1438 if ( !empty($_FILES) )
1439 $this->filename = $_FILES[$form]['name'];
1440 else if ( isset($_GET[$urlholder]) )
1441 $this->filename = $_GET[$urlholder];
1443 //Handle a newly uploaded file, Else assume its already been uploaded
1444 if ( !empty($_FILES) ) {
1445 $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename );
1446 $this->package = $uploads['basedir'] . '/' . $this->filename;
1448 // Move the file to the uploads dir
1449 if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
1450 wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
1452 $this->package = $uploads['basedir'] . '/' . $this->filename;