Ejemplo n.º 1
0
 function copy_dir($thisfolder, $folder)
 {
     $thisdir = get_dir_file_info($thisfolder);
     foreach ($thisdir as $f) {
         if (is_dir($f['server_path'])) {
             $main_app = str_replace('\\plugins\\' . $folder . '\\files', '', $f['server_path']);
             if (is_dir($main_app)) {
                 $subfolder = get_dir_file_info($f['server_path']);
                 copy_dir($f['server_path'], $folder);
             } else {
                 mkdir($main_app);
                 echo "<span style='color:#66ae61'>mkdir: " . $main_app . "</span><br/>";
                 $subfolder = get_dir_file_info($f['server_path']);
                 copy_dir($f['server_path'], $folder);
             }
         } else {
             $new_loc = str_replace('\\plugins\\' . $folder . '\\files', '', $f['server_path']);
             if (copy($f['server_path'], $new_loc)) {
                 echo "<span style='color:#66ae61'>copied: " . $new_loc . "</span><br/>";
             } else {
                 echo "<span style='color:#f00'>failed: " . $new_loc . "</span><br/>";
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Generate a child theme.
  *
  * @since 1.1.0
  */
 public function generate()
 {
     global $wp_filesystem;
     WP_Filesystem();
     $parent = wp_get_theme($this->template);
     if (!$parent->exists()) {
         return new WP_Error('invalid_template', esc_html__('Invalid parent theme slug.', 'audiotheme-agent'));
     }
     $parts = explode('/', $parent->get_template());
     $slug = sprintf('%s-child', reset($parts));
     $directory = path_join($parent->get_theme_root(), $slug);
     if ($wp_filesystem->exists($directory)) {
         return new WP_Error('directory_exists', esc_html__('Child theme directory already exists.', 'audiotheme-agent'));
     }
     if (false === $wp_filesystem->mkdir($directory)) {
         return new WP_Error('fs_error', esc_html__('Could not create child theme directory.', 'audiotheme-agent'));
     }
     $source = audiotheme_agent()->get_path('data/child-theme/');
     copy_dir($source, $directory);
     if ($parent->get_screenshot()) {
         $wp_filesystem->copy(path_join($parent->get_template_directory(), $parent->get_screenshot('relative')), path_join($directory, $parent->get_screenshot('relative')));
     }
     $data = array('{{author}}' => wp_get_current_user()->display_name, '{{author_url}}' => wp_get_current_user()->user_url, '{{name}}' => $parent->get('Name'), '{{slug}}' => $parent->get_template(), '{{url}}' => esc_url(home_url()));
     $files = array('functions.php', 'style.css');
     foreach ($files as $file) {
         $filename = path_join($directory, $file);
         $contents = $wp_filesystem->get_contents($filename);
         $contents = str_replace(array_keys($data), array_values($data), $contents);
         $wp_filesystem->put_contents($filename, $contents);
     }
     return true;
 }
Ejemplo n.º 3
0
/**
 * 拷贝目录及下面所有文件
 *
 * @param string $from 原路径
 * @param string $to   目标路径
 *
 * @return bool true拷贝成功,否则false
 */
function copy_dir($from, $to)
{
    $from = dir_path($from);
    $to = dir_path($to);
    if (!is_dir($from)) {
        return false;
    }
    if ($from == $to) {
        return true;
    }
    !is_dir($to) && create_dir($to);
    $list = glob($from . '*');
    if (!empty($list)) {
        foreach ($list as $v) {
            $path = $to . basename($v);
            if (is_dir($v)) {
                copy_dir($v, $path);
            } else {
                copy($v, $path);
                chmod($path, 0755);
            }
        }
    }
    return true;
}
Ejemplo n.º 4
0
/**
 * 
 * @param type $study_name the name of the study directory
 * @return the job id
 */
function create_execution_env($study_name, $script_name)
{
    include 'config.inc.php';
    $jobid = create_job_id($study_name, $script_name);
    $job_dir = get_job_exec_dir($jobid);
    while (is_dir($job_dir)) {
        // the sandbox directory is already existing, sleep 1 second and generate another ID
        sleep(1);
        $jobid = create_job_id($study_name, $script_name);
        $job_dir = get_job_exec_dir($jobid);
    }
    mkdir($job_dir, 0777, true);
    // [job_root_dir]/[job_id]/data --> ../../data/[fs_root]/[study_name]/data
    $datadir = $NC_CONFIG["symlink_prefix"] . "/" . $study_name . "/data";
    $pipelinedir = get_absolute_path($study_name . "/pipeline");
    $resultsdir = $NC_CONFIG["symlink_prefix"] . "/" . $study_name . "/results/" . $jobid;
    OC_Filesystem::mkdir("{$study_name}/results/{$jobid}");
    # le dir /data e /results sono link simbolici alle vere directory del caso di studio
    mkdir($job_dir . "/pipeline");
    symlink($datadir, $job_dir . "/data");
    symlink($resultsdir, $job_dir . "/results");
    # creo il file in cui verrà rediretto lo standard output
    $date = date("Y-m-d H:i:s");
    OC_Filesystem::file_put_contents(get_job_output_file($study_name, $jobid), "Standard output for job {$jobid}, run at {$date}\n");
    $jobinfo = array("jobid" => $jobid, "study" => $study_name);
    save_job_info($study_name, $jobid, $jobinfo);
    # copia gli script del caso di studio nella pipeline
    copy_dir($pipelinedir, $job_dir . "/pipeline");
    return $jobid;
}
Ejemplo n.º 5
0
/**
 * Upgrade the XPressME .
 *
 * @param string $from New release unzipped path.
 * @param string $to Path to old WordPress installation.
 * @return WP_Error|null WP_Error on failure, null on success.
 */
function update_xpress($from, $to) {
	global $wp_filesystem, $_old_xpress_files, $wpdb;
	show_message( __('Disable overwrite of wp-config.php...', 'xpressme') );
	// remove wp-config.php from the new version into place.
	$wp_config = $from . 'wp-config.php';
	if ( !$wp_filesystem->delete($wp_config, true)){
		return new WP_Error('delete_failed', $this->strings['delete_failed']);
	}

	// Copy new versions of XPressME Integration Kit files into place.
	show_message( __('Copy new versions of XPressME Integration Kit files into place...', 'xpressme') );
	$result = copy_dir($from . $distro, $to);
	if ( is_wp_error($result) ) {
		$wp_filesystem->delete($maintenance_file);
		$wp_filesystem->delete($from, true);
		return $result;
	}

	// Remove old files
	show_message( __('Remove an unnecessary, old file...', 'xpressme') );
	foreach ( $_old_xpress_files as $old_file ) {
		$old_file = $to . $old_file;
		if ( !$wp_filesystem->exists($old_file) )
			continue;
		$wp_filesystem->delete($old_file, true);
	}
	show_message( __('Set templates directory chmod 777', 'xpressme') );
	$wp_filesystem->chmod($to . 'templates/', 0777);

	// Remove working directory
	$working_dir = dirname(dirname($from));
	show_message( sprintf(__('Remove working directory(%s)...', 'xpressme'),$working_dir) );
	$wp_filesystem->delete($working_dir, true);

}
Ejemplo n.º 6
0
function add_lang()
{
    global $smarty, $lang;
    $chinese_name = post('chinese_name');
    $foreign_name = post('foreign_name');
    $pack_name = post('pack_name');
    $short_name = post('short_name');
    $index_entrance = post('index_entrance');
    $admin_entrance = post('admin_entrance');
    if ($chinese_name != '' && $foreign_name != '' && $pack_name != '' && $index_entrance != '' && $admin_entrance != '' && $index_entrance != 'index.php' && $admin_entrance != 'admin.php') {
        $var_value = $pack_name . '{v}' . $index_entrance . '{v}' . $admin_entrance . '{v}' . $chinese_name . '{v}' . $foreign_name;
        $obj = new varia();
        $obj->add_var_value('languages', $var_value);
        $site = get_site_info();
        $obj->add_var_value('site_title', $site['title'], $pack_name);
        $obj->add_var_value('site_name', $site['name'], $pack_name);
        $obj->add_var_value('site_record', $site['record'], $pack_name);
        $obj->add_var_value('site_tech', $site['tech'], $pack_name);
        $obj->add_var_value('site_keywords', $site['keywords'], $pack_name);
        $obj->add_var_value('site_description', $site['description'], $pack_name);
        $obj->add_var_value('notice', '', $pack_name, true);
        $obj->add_var_value('service_code', '', $pack_name, true);
        $obj->add_var_value('user_agreement', '', $pack_name, true);
        $obj = new channel();
        $obj->set_where('cha_original = 0');
        $list = $obj->get_list();
        for ($i = 0; $i < count($list); $i++) {
            $obj->clear_value();
            $obj->set_value('cha_lang', $pack_name);
            $obj->set_value('cha_code', $list[$i]['cha_code']);
            $obj->set_value('cha_name', $list[$i]['cha_name']);
            $obj->set_value('cha_original', $list[$i]['cha_original']);
            $obj->add();
        }
        if (!file_exists('languages/' . $pack_name)) {
            copy_dir('languages/' . S_LANG, 'languages/' . $pack_name);
        }
        if (S_MULTILINGUAL) {
            $file = file_get_contents('admin/index.txt');
            $file = str_replace('{$pack_name}', $pack_name, $file);
            $file = str_replace('{$index_entrance}', $index_entrance, $file);
            $file = str_replace('{$admin_entrance}', $admin_entrance, $file);
            file_put_contents($index_entrance, $file);
            $file = file_get_contents('admin/admin.txt');
            $file = str_replace('{$pack_name}', $pack_name, $file);
            $file = str_replace('{$index_entrance}', $index_entrance, $file);
            $file = str_replace('{$admin_entrance}', $admin_entrance, $file);
            file_put_contents($admin_entrance, $file);
        }
        $info_text = '添加语言成功';
    } else {
        $info_text = '的输入不合法,添加语言失败';
    }
    $smarty->assign('info_text', $info_text);
    $smarty->assign('link_text', $lang['return_list']);
    $smarty->assign('link_href', url(array('channel' => 'file', 'mod' => 'lang_lists')));
}
Ejemplo n.º 7
0
 function copy_dir($abs_item, $abs_new_item)
 {
     if (nx_isFTPMode()) {
         $tmp_dir = nx_ftp_make_local_copy($abs_item);
         $res = $GLOBALS['FTPCONNECTION']->putRecursive($tmp_dir, $abs_new_item);
         remove($tmp_dir);
         return $res;
     } else {
         return copy_dir($abs_item, $abs_new_item);
     }
 }
Ejemplo n.º 8
0
function copy_dir($src, $dst)
{
    $dir = opendir($src);
    if (!is_dir($dst)) {
        mkdir($dst);
    }
    while (false !== ($file = readdir($dir))) {
        if ($file != '.' && $file != '..') {
            if (is_dir($src . '/' . $file)) {
                copy_dir($src . '/' . $file, $dst . '/' . $file);
            } else {
                copy($src . '/' . $file, $dst . '/' . $file);
            }
        }
    }
    closedir($dir);
}
Ejemplo n.º 9
0
/**
 * Upgrade the core of WordPress.
 *
 * This will create a .maintenance file at the base of the WordPress directory
 * to ensure that people can not access the web site, when the files are being
 * copied to their locations.
 *
 * The files in the {@link $_old_files} list will be removed and the new files
 * copied from the zip file after the database is upgraded.
 *
 * The steps for the upgrader for after the new release is downloaded and
 * unzipped is:
 *   1. Test unzipped location for select files to ensure that unzipped worked.
 *   2. Create the .maintenance file in current WordPress base.
 *   3. Copy new WordPress directory over old WordPress files.
 *   4. Upgrade WordPress to new version.
 *   5. Delete new WordPress directory path.
 *   6. Delete .maintenance file.
 *   7. Remove old files.
 *   8. Delete 'update_core' option.
 *
 * There are several areas of failure. For instance if PHP times out before step
 * 6, then you will not be able to access any portion of your site. Also, since
 * the upgrade will not continue where it left off, you will not be able to
 * automatically remove old files and remove the 'update_core' option. This
 * isn't that bad.
 *
 * If the copy of the new WordPress over the old fails, then the worse is that
 * the new WordPress directory will remain.
 *
 * If it is assumed that every file will be copied over, including plugins and
 * themes, then if you edit the default theme, you should rename it, so that
 * your changes remain.
 *
 * @since 2.7.0
 *
 * @param string $from New release unzipped path.
 * @param string $to Path to old WordPress installation.
 * @return WP_Error|null WP_Error on failure, null on success.
 */
function update_core($from, $to)
{
    global $wp_filesystem, $_old_files;
    @set_time_limit(300);
    // Sanity check the unzipped distribution
    apply_filters('update_feedback', __('Verifying the unpacked files'));
    if (!$wp_filesystem->exists($from . '/wordpress/wp-settings.php') || !$wp_filesystem->exists($from . '/wordpress/wp-admin/admin.php') || !$wp_filesystem->exists($from . '/wordpress/wp-includes/functions.php')) {
        $wp_filesystem->delete($from, true);
        return new WP_Error('insane_distro', __('The update could not be unpacked'));
    }
    apply_filters('update_feedback', __('Installing the latest version'));
    // Create maintenance file to signal that we are upgrading
    $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    $maintenance_file = $to . '.maintenance';
    $wp_filesystem->delete($maintenance_file);
    $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
    // Copy new versions of WP files into place.
    $result = copy_dir($from . '/wordpress', $to);
    if (is_wp_error($result)) {
        $wp_filesystem->delete($maintenance_file);
        $wp_filesystem->delete($from, true);
        return $result;
    }
    // Remove old files
    foreach ($_old_files as $old_file) {
        $old_file = $to . $old_file;
        if (!$wp_filesystem->exists($old_file)) {
            continue;
        }
        $wp_filesystem->delete($old_file, true);
    }
    // Upgrade DB with separate request
    apply_filters('update_feedback', __('Upgrading database'));
    $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
    wp_remote_post($db_upgrade_url, array('timeout' => 60));
    // Remove working directory
    $wp_filesystem->delete($from, true);
    // Force refresh of update information
    if (function_exists('delete_transient')) {
        delete_transient('update_core');
    } else {
        delete_option('update_core');
    }
    // Remove maintenance file, we're done.
    $wp_filesystem->delete($maintenance_file);
}
Ejemplo n.º 10
0
function copy_dir($dir2copy, $dir_paste)
{
    if (is_dir($dir2copy)) {
        if ($dh = opendir($dir2copy)) {
            while (($file = readdir($dh)) !== false) {
                if (!is_dir($dir_paste)) {
                    mkdir($dir_paste, 0755);
                }
                if (is_dir($dir2copy . $file) && $file != '..' && $file != '.') {
                    copy_dir($dir2copy . $file . '/', $dir_paste . $file . '/');
                } elseif ($file != '..' && $file != '.') {
                    copy($dir2copy . $file, $dir_paste . $file);
                }
            }
            closedir($dh);
        }
    }
}
Ejemplo n.º 11
0
function copy_dir($from, $to)
{
    @mkdir($to);
    $d = dir($from);
    while (($f = $d->read()) !== false) {
        if ($f[0] != '.') {
            $from_path = "{$from}/{$f}";
            $to_path = "{$to}/{$f}";
            if (is_dir($from_path)) {
                copy_dir($from_path, $to_path);
            } else {
                if (!copy($from_path, $to_path)) {
                    die('<p>Copy failed');
                }
            }
        }
    }
}
/**
 *
 * This is a very simple plugin that should be deleted as soon as the update is finished.
 * Upon acceptance from the WordPress repo we need to rename the plugin folder from rapidology to rapidology-by-leadpages
 * to recieve updates from the repo
 *
 */
function rapidology_updater()
{
    add_option('update_refresh', 0);
    $old_file = WP_PLUGIN_DIR . '/rapidology';
    $new_file = WP_PLUGIN_DIR . '/rapidology-by-leadpages';
    $update_folder = WP_PLUGIN_DIR . '/rapidology-by-leadpages.zip';
    //deactivate old rapidology
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    if (!file_exists($new_file)) {
        mkdir($new_file, 0777);
        $result = copy_dir($old_file, $new_file, array('.DS_Store', '.git', '.gitignore', '.idea'));
        deactivate_plugins('rapidology/rapidology.php');
        delTree($old_file);
        update_option('update_refresh', true);
    }
}
Ejemplo n.º 13
0
 public function edit($data)
 {
     $dir = __ROOTDIR__ . '/lang/' . in($data['lang']);
     $info = $this->info($data['id']);
     if (!is_dir($dir)) {
         if (!@mkdir($dir, 0777)) {
             return false;
         }
         @copy_dir(__ROOTDIR__ . '/lang/zh', $dir);
     } else {
         if (!@copy_dir(__ROOTDIR__ . '/lang/' . $info['lang'], $dir)) {
             return false;
         }
     }
     if (is_dir($dir)) {
         @del_dir(__ROOTDIR__ . '/lang/' . $info['lang']);
     }
     $condition['id'] = intval($data['id']);
     return $this->model->table('lang')->data($data)->where($condition)->update();
 }
Ejemplo n.º 14
0
 public function upgrade()
 {
     $dir = __ROOTDIR__ . '/data/update/';
     if (!file_exists($dir . '/ver.xml')) {
         $this->msg('升级信息文件不存在!', 0);
         return;
     }
     $xml = file_get_contents($dir . '/ver.xml');
     $info = Xml::decode($xml);
     $time = $info['ver']['vertime'];
     if ($time != $this->config['ver_date']) {
         $this->msg('该更新包不适合当前版本!', 0);
         return;
     }
     if (!copy_dir($dir . '/update', __ROOTDIR__, true)) {
         $this->msg('移动文件失败!', 0);
         return;
     }
     if ($info['ver']['sql'] == '1') {
         model('update')->index();
     }
     del_dir($dir);
     $this->msg('升级成功!清空手动清空所有缓存!');
 }
Ejemplo n.º 15
0
function copy_dir($dir2copy, $dir_paste)
{
    // On vérifie si $dir2copy est un dossier
    if (is_dir($dir2copy)) {
        // Si oui, on l'ouvre
        if ($dh = opendir($dir2copy)) {
            // On liste les dossiers et fichiers de $dir2copy
            while (($file = readdir($dh)) !== false) {
                // Si le dossier dans lequel on veut coller n'ex iste pas, on le créé
                if (!is_dir($dir_paste)) {
                    mkdir($dir_paste, 0777);
                }
                // S'il s'agit d'un dossier, on relance la fonction récursive
                if (is_dir($dir2copy . $file) && $file != '..' && $file != '.') {
                    copy_dir($dir2copy . $file . '/', $dir_paste . $file . '/');
                } elseif ($file != '..' && $file != '.') {
                    copy($dir2copy . $file, $dir_paste . $file);
                }
            }
            // On ferme $dir2copy
            closedir($dh);
        }
    }
}
Ejemplo n.º 16
0
function copy_dir($source, $dest)
{
    if (is_file($source)) {
        $c = copy($source, $dest);
        chmod($dest, 0777);
        return $c;
    }
    if (!is_dir($dest)) {
        $oldumask = umask(0);
        mkdir($dest, 0777);
        umask($oldumask);
    }
    $dir = dir($source);
    while (false !== ($entry = $dir->read())) {
        if ($entry == '.' || $entry == '..') {
            continue;
        }
        if ($dest !== "{$source}/{$entry}") {
            copy_dir("{$source}/{$entry}", "{$dest}/{$entry}");
        }
    }
    $dir->close();
    return true;
}
Ejemplo n.º 17
0
 function copy_dir($dir2copy, $dir_paste)
 {
     // Verify directory
     if (is_dir($dir2copy)) {
         // Open Directory
         if ($dh = opendir($dir2copy)) {
             // list directory
             while (($file = readdir($dh)) !== false) {
                 // if pastdir don't exist create
                 if (!is_dir($dir_paste)) {
                     mkdir($dir_paste, 0777);
                 }
                 // if it's directory recursive
                 if (is_dir($dir2copy . $file) && $file != '..' && $file != '.') {
                     copy_dir($dir2copy . $file . '/', $dir_paste . $file . '/');
                 } elseif ($file != '..' && $file != '.') {
                     copy($dir2copy . $file, $dir_paste . $file);
                 }
             }
             // close directory
             closedir($dh);
         }
     }
 }
Ejemplo n.º 18
0
/**
 * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
 * Assumes that WP_Filesystem() has already been called and setup.
 *
 * @since 2.5.0
 *
 * @param string $from source directory
 * @param string $to destination directory
 * @return mixed WP_Error on failure, True on success.
 */
function copy_dir($from, $to)
{
    global $wp_filesystem;
    $dirlist = $wp_filesystem->dirlist($from);
    $from = trailingslashit($from);
    $to = trailingslashit($to);
    foreach ((array) $dirlist as $filename => $fileinfo) {
        if ('f' == $fileinfo['type']) {
            if (!$wp_filesystem->copy($from . $filename, $to . $filename, true)) {
                // If copy failed, chmod file to 0644 and try again.
                $wp_filesystem->chmod($to . $filename, 0644);
                if (!$wp_filesystem->copy($from . $filename, $to . $filename, true)) {
                    return new WP_Error('copy_failed', __('Could not copy file'), $to . $filename);
                }
            }
            $wp_filesystem->chmod($to . $filename, FS_CHMOD_FILE);
        } elseif ('d' == $fileinfo['type']) {
            if (!$wp_filesystem->is_dir($to . $filename)) {
                if (!$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR)) {
                    return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $filename);
                }
            }
            $result = copy_dir($from . $filename, $to . $filename);
            if (is_wp_error($result)) {
                return $result;
            }
        }
    }
    return true;
}
Ejemplo n.º 19
0
/**
 * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
 * Assumes that WP_Filesystem() has already been called and setup.
 *
 * @since 2.5.0
 *
 * @global WP_Filesystem_Base $wp_filesystem Subclass
 *
 * @param string $from source directory
 * @param string $to destination directory
 * @param array $skip_list a list of files/folders to skip copying
 * @return mixed WP_Error on failure, True on success.
 */
function copy_dir($from, $to, $skip_list = array() ) {
	global $wp_filesystem;

	$dirlist = $wp_filesystem->dirlist($from);

	$from = trailingslashit($from);
	$to = trailingslashit($to);

	foreach ( (array) $dirlist as $filename => $fileinfo ) {
		if ( in_array( $filename, $skip_list ) )
			continue;

		if ( 'f' == $fileinfo['type'] ) {
			if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
				// If copy failed, chmod file to 0644 and try again.
				$wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
				if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
					return new WP_Error( 'copy_failed_copy_dir', __( 'Could not copy file.' ), $to . $filename );
			}
		} elseif ( 'd' == $fileinfo['type'] ) {
			if ( !$wp_filesystem->is_dir($to . $filename) ) {
				if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
					return new WP_Error( 'mkdir_failed_copy_dir', __( 'Could not create directory.' ), $to . $filename );
			}

			// generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list
			$sub_skip_list = array();
			foreach ( $skip_list as $skip_item ) {
				if ( 0 === strpos( $skip_item, $filename . '/' ) )
					$sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
			}

			$result = copy_dir($from . $filename, $to . $filename, $sub_skip_list);
			if ( is_wp_error($result) )
				return $result;
		}
	}
	return true;
}
Ejemplo n.º 20
0
function synved_option_wp_upgrader_post_install($perform, $extra, $result = null)
{
    $upgrade_transfer = get_option('synved_option_wp_upgrade_addon_transfer');
    if ($upgrade_transfer != null) {
        $list = $upgrade_transfer['list'];
        foreach ($list as $upgrade_item) {
            $original = $upgrade_item['original'];
            $temporary = $upgrade_item['temporary'];
            wp_mkdir_p($original);
            copy_dir($temporary, $original);
        }
        global $wp_filesystem;
        if ($wp_filesystem != null) {
            $directory = $upgrade_transfer['directory'];
            $wp_filesystem->delete($directory, true);
        }
        update_option('synved_option_wp_upgrade_addon_transfer', '');
    }
    return $perform;
}
Ejemplo n.º 21
0
 /**
  * Install a package.
  *
  * Copies the contents of a package form a source directory, and installs them in
  * a destination directory. Optionally removes the source. It can also optionally
  * clear out the destination folder if it already exists.
  *
  * @since 2.8.0
  *
  * @param array|string $args {
  *     Optional. Array or string of arguments for installing a package. Default empty array.
  *
  *     @type string $source                      Required path to the package source. Default empty.
  *     @type string $destination                 Required path to a folder to install the package in.
  *                                               Default empty.
  *     @type bool   $clear_destination           Whether to delete any files already in the destination
  *                                               folder. Default false.
  *     @type bool   $clear_working               Whether to delete the files form the working directory
  *                                               after copying to the destination. Default false.
  *     @type bool   $abort_if_destination_exists Whether to abort the installation if
  *                                               the destination folder already exists. Default true.
  *     @type array  $hook_extra                  Extra arguments to pass to the filter hooks called by
  *                                               {@see WP_Upgrader::install_package()}. Default empty array.
  * }
  *
  * @return array|WP_Error The result (also stored in `WP_Upgrader:$result`), or a {@see WP_Error} on failure.
  */
 public function install_package($args = array())
 {
     global $wp_filesystem, $wp_theme_directories;
     $defaults = array('source' => '', 'destination' => '', 'clear_destination' => false, 'clear_working' => false, 'abort_if_destination_exists' => true, 'hook_extra' => array());
     $args = wp_parse_args($args, $defaults);
     // These were previously extract()'d.
     $source = $args['source'];
     $destination = $args['destination'];
     $clear_destination = $args['clear_destination'];
     // @set_time_limit( 300 ); // for SAE, modified by Gimhoy (blog.gimhoy.com)
     if (empty($source) || empty($destination)) {
         return new WP_Error('bad_request', $this->strings['bad_request']);
     }
     $this->skin->feedback('installing_package');
     /**
      * Filter the install response before the installation has started.
      *
      * Returning a truthy value, or one that could be evaluated as a WP_Error
      * will effectively short-circuit the installation, returning that value
      * instead.
      *
      * @since 2.8.0
      *
      * @param bool|WP_Error $response   Response.
      * @param array         $hook_extra Extra arguments passed to hooked filters.
      */
     $res = apply_filters('upgrader_pre_install', true, $args['hook_extra']);
     if (is_wp_error($res)) {
         return $res;
     }
     //Retain the Original source and destinations
     $remote_source = $args['source'];
     $local_destination = $destination;
     $source_files = array_keys($wp_filesystem->dirlist($remote_source));
     $remote_destination = $wp_filesystem->find_folder($local_destination);
     //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
     if (1 == count($source_files) && $wp_filesystem->is_dir(trailingslashit($args['source']) . $source_files[0] . '/')) {
         //Only one folder? Then we want its contents.
         $source = trailingslashit($args['source']) . trailingslashit($source_files[0]);
     } elseif (count($source_files) == 0) {
         return new WP_Error('incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files']);
         // There are no files?
     } else {
         //It's only a single file, the upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename.
         $source = trailingslashit($args['source']);
     }
     /**
      * Filter the source file location for the upgrade package.
      *
      * @since 2.8.0
      *
      * @param string      $source        File source location.
      * @param string      $remote_source Remove file source location.
      * @param WP_Upgrader $this          WP_Upgrader instance.
      */
     $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
     if (is_wp_error($source)) {
         return $source;
     }
     // Has the source location changed? If so, we need a new source_files list.
     if ($source !== $remote_source) {
         $source_files = array_keys($wp_filesystem->dirlist($source));
     }
     /*
      * Protection against deleting files in any important base directories.
      * Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
      * destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
      * to copy the directory into the directory, whilst they pass the source
      * as the actual files to copy.
      */
     $protected_directories = array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes');
     if (is_array($wp_theme_directories)) {
         $protected_directories = array_merge($protected_directories, $wp_theme_directories);
     }
     if (in_array($destination, $protected_directories)) {
         $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
         $destination = trailingslashit($destination) . trailingslashit(basename($source));
     }
     if ($clear_destination) {
         //We're going to clear the destination if there's something there
         $this->skin->feedback('remove_old');
         $removed = true;
         if ($wp_filesystem->exists($remote_destination)) {
             $removed = $wp_filesystem->delete($remote_destination, true);
         }
         /**
          * Filter whether the upgrader cleared the destination.
          *
          * @since 2.8.0
          *
          * @param bool   $removed            Whether the destination was cleared.
          * @param string $local_destination  The local package destination.
          * @param string $remote_destination The remote package destination.
          * @param array  $hook_extra         Extra arguments passed to hooked filters.
          */
         $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra']);
         if (is_wp_error($removed)) {
             return $removed;
         } else {
             if (!$removed) {
                 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
             }
         }
     } elseif ($args['abort_if_destination_exists'] && $wp_filesystem->exists($remote_destination)) {
         //If we're not clearing the destination folder and something exists there already, Bail.
         //But first check to see if there are actually any files in the folder.
         $_files = $wp_filesystem->dirlist($remote_destination);
         if (!empty($_files)) {
             $wp_filesystem->delete($remote_source, true);
             //Clear out the source files.
             return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination);
         }
     }
     //Create destination if needed
     if (!$wp_filesystem->exists($remote_destination)) {
         if (!$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR)) {
             return new WP_Error('mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination);
         }
     }
     // Copy new version of item into place.
     $result = copy_dir($source, $remote_destination);
     if (is_wp_error($result)) {
         if ($args['clear_working']) {
             $wp_filesystem->delete($remote_source, true);
         }
         return $result;
     }
     //Clear the Working folder?
     if ($args['clear_working']) {
         $wp_filesystem->delete($remote_source, true);
     }
     $destination_name = basename(str_replace($local_destination, '', $destination));
     if ('.' == $destination_name) {
         $destination_name = '';
     }
     $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
     /**
      * Filter the install response after the installation has finished.
      *
      * @since 2.8.0
      *
      * @param bool  $response   Install response.
      * @param array $hook_extra Extra arguments passed to hooked filters.
      * @param array $result     Installation result data.
      */
     $res = apply_filters('upgrader_post_install', true, $args['hook_extra'], $this->result);
     if (is_wp_error($res)) {
         $this->result = $res;
         return $res;
     }
     //Bombard the calling function will all the info which we've just used.
     return $this->result;
 }
 public function pathPast()
 {
     if (!isset($_SESSION['path_copy'])) {
         show_json($this->L['clipboard_null'], false, array());
     }
     session_start();
     //re start
     $error = '';
     $data = array();
     $clipboard = json_decode($_SESSION['path_copy'], true);
     $copy_type = $_SESSION['path_copy_type'];
     $path_past = $this->path;
     if (!is_writable($path_past)) {
         show_json($this->L['no_permission_write'], false, $data);
     }
     $list_num = count($clipboard);
     if ($list_num == 0) {
         show_json($this->L['clipboard_null'], false, $data);
     }
     for ($i = 0; $i < $list_num; $i++) {
         $path_copy = _DIR($clipboard[$i]['path']);
         $filename = get_path_this($path_copy);
         $filename_out = iconv_app($filename);
         if (!file_exists($path_copy) && !is_dir($path_copy)) {
             $error .= $path_copy . "<li>{$filename_out}'.{$this->L}['copy_not_exists'].'</li>";
             continue;
         }
         if ($clipboard[$i]['type'] == 'folder') {
             if ($path_copy == substr($path_past, 0, strlen($path_copy))) {
                 $error .= "<em style='color:#fff;'>{$filename_out}" . $this->L['current_has_parent'] . "</em>";
                 continue;
             }
         }
         $auto_path = get_filename_auto($path_past . $filename);
         $filename = get_path_this($auto_path);
         if ($copy_type == 'copy') {
             if ($clipboard[$i]['type'] == 'folder') {
                 copy_dir($path_copy, $auto_path);
             } else {
                 copy($path_copy, $auto_path);
             }
         } else {
             rename($path_copy, $auto_path);
         }
         $data[] = iconv_app($filename);
     }
     if ($copy_type == 'copy') {
         $msg = $this->L['past_success'] . $error;
     } else {
         $_SESSION['path_copy'] = json_encode(array());
         $_SESSION['path_copy_type'] = '';
         $msg = $this->L['cute_past_success'] . $error;
     }
     $state = $error == '' ? true : false;
     show_json($msg, $state, $data);
 }
 /**
  * @param string $source_dir path
  * @param string $destination_dir path
  * @param bool $fs Use WP_Filesystem or not
  * @param array $skip_dirs {'path': mixed}
  *
  * @return WP_Error|true
  */
 private function copy_dir($source_dir, $destination_dir, $fs, $skip_dirs)
 {
     $included_hidden_names = fw_ext('backups')->get_config('included_hidden_names');
     if ($fs) {
         global $wp_filesystem;
         /** @var WP_Filesystem_Base $wp_filesystem */
         $fs_source_dir = fw_fix_path(FW_WP_Filesystem::real_path_to_filesystem_path($source_dir));
         if (empty($fs_source_dir)) {
             return new WP_Error('dir_to_fs_failed', sprintf(__('Cannot convert Filesystem path: %s', 'fw'), $source_dir));
         } elseif (false === ($list = $wp_filesystem->dirlist($fs_source_dir, true))) {
             return new WP_Error('dir_list_failed', sprintf(__('Failed to list dir: %s', 'fw'), $source_dir));
         }
         foreach ($list as $file) {
             if ($file['name'][0] === '.' && !isset($included_hidden_names[$file['name']])) {
                 continue;
             }
             $file_path = $source_dir . '/' . $file['name'];
             $fs_file_path = $fs_source_dir . '/' . $file['name'];
             $destination_file_path = $destination_dir . '/' . $file['name'];
             $fs_destination_file_path = fw_fix_path(FW_WP_Filesystem::real_path_to_filesystem_path($destination_file_path));
             if (empty($fs_destination_file_path)) {
                 return new WP_Error('path_to_fs_failed', sprintf(__('Cannot convert Filesystem path: %s', 'fw'), $destination_file_path));
             }
             if ($file['type'] === 'd') {
                 if (isset($skip_dirs[$destination_file_path])) {
                     continue;
                 } else {
                     foreach ($skip_dirs as $skip_dir => $skip_dir_data) {
                         if (strlen(preg_replace('/^' . preg_quote($destination_file_path, '/') . '/', '', $skip_dir)) != strlen($skip_dir)) {
                             continue 2;
                             // skip dir if it's inside current dir
                         }
                     }
                 }
                 if (!$wp_filesystem->mkdir($fs_destination_file_path)) {
                     return new WP_Error('fs_mkdir_fail', sprintf(__('Failed to create dir: %s', 'fw'), $destination_file_path));
                 }
                 if (is_wp_error($result = copy_dir($fs_file_path, $fs_destination_file_path))) {
                     return $result;
                 }
             } else {
                 if (!$wp_filesystem->copy($fs_file_path, $fs_destination_file_path)) {
                     return new WP_Error('file_copy_fail', sprintf(__('Failed to copy file: %s', 'fw'), $file_path));
                 }
             }
         }
         return true;
     } else {
         $names = array_diff(($names = scandir($source_dir)) ? $names : array(), array('.', '..'));
         foreach ($names as $file_name) {
             $file_path = $source_dir . '/' . $file_name;
             $destination_file_path = $destination_dir . '/' . $file_name;
             if ($file_name[0] === '.' && !isset($included_hidden_names[$file_name])) {
                 continue;
             }
             if (is_dir($file_path)) {
                 if (isset($skip_dirs[$destination_file_path])) {
                     continue;
                 } else {
                     foreach ($skip_dirs as $skip_dir => $skip_dir_data) {
                         if (strlen(preg_replace('/^' . preg_quote($destination_file_path, '/') . '/', '', $skip_dir)) != strlen($skip_dir)) {
                             continue 2;
                             // skip dir it's inside current dir
                         }
                     }
                 }
                 if (is_dir($destination_file_path)) {
                     /**
                      * Some times empty directories are not deleted ( @see fw_ext_backups_rmdir_recursive() )
                      * even if rmdir() returns true, the directory remains (I don't know why),
                      * so a workaround is to check if it exists and do not try to created it
                      * (because create will return false)
                      */
                 } elseif (!mkdir($destination_file_path)) {
                     return new WP_Error('dir_mk_fail', sprintf(__('Failed to create dir: %s', 'fw'), $destination_file_path));
                 }
                 if (is_wp_error($result = $this->copy_dir($file_path, $destination_file_path, $fs, array()))) {
                     return $result;
                 }
             } else {
                 if (!copy($file_path, $destination_file_path)) {
                     return new WP_Error('file_copy_fail', sprintf(__('Failed to copy file: %s', 'fw'), $file_path));
                 }
             }
         }
         return true;
     }
 }
Ejemplo n.º 24
0
/**
 * Upgrade the core of WordPress.
 *
 * This will create a .maintenance file at the base of the WordPress directory
 * to ensure that people can not access the web site, when the files are being
 * copied to their locations.
 *
 * The files in the {@link $_old_files} list will be removed and the new files
 * copied from the zip file after the database is upgraded.
 *
 * The steps for the upgrader for after the new release is downloaded and
 * unzipped is:
 *   1. Test unzipped location for select files to ensure that unzipped worked.
 *   2. Create the .maintenance file in current WordPress base.
 *   3. Copy new WordPress directory over old WordPress files.
 *   4. Upgrade WordPress to new version.
 *   5. Delete new WordPress directory path.
 *   6. Delete .maintenance file.
 *   7. Remove old files.
 *   8. Delete 'update_core' option.
 *
 * There are several areas of failure. For instance if PHP times out before step
 * 6, then you will not be able to access any portion of your site. Also, since
 * the upgrade will not continue where it left off, you will not be able to
 * automatically remove old files and remove the 'update_core' option. This
 * isn't that bad.
 *
 * If the copy of the new WordPress over the old fails, then the worse is that
 * the new WordPress directory will remain.
 *
 * If it is assumed that every file will be copied over, including plugins and
 * themes, then if you edit the default theme, you should rename it, so that
 * your changes remain.
 *
 * @since 2.7.0
 *
 * @param string $from New release unzipped path.
 * @param string $to Path to old WordPress installation.
 * @return WP_Error|null WP_Error on failure, null on success.
 */
function update_core($from, $to)
{
    global $wp_filesystem, $_old_files, $wpdb;
    @set_time_limit(300);
    $php_version = phpversion();
    $mysql_version = $wpdb->db_version();
    $required_php_version = '4.3';
    $required_mysql_version = '4.1.2';
    $wp_version = '3.0.4';
    $php_compat = version_compare($php_version, $required_php_version, '>=');
    $mysql_compat = version_compare($mysql_version, $required_mysql_version, '>=') || file_exists(WP_CONTENT_DIR . '/db.php');
    if (!$mysql_compat || !$php_compat) {
        $wp_filesystem->delete($from, true);
    }
    if (!$mysql_compat && !$php_compat) {
        return new WP_Error('php_mysql_not_compatible', sprintf(__('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version));
    } elseif (!$php_compat) {
        return new WP_Error('php_not_compatible', sprintf(__('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version));
    } elseif (!$mysql_compat) {
        return new WP_Error('mysql_not_compatible', sprintf(__('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version));
    }
    // Sanity check the unzipped distribution
    apply_filters('update_feedback', __('Verifying the unpacked files&#8230;'));
    $distro = '';
    $roots = array('/wordpress', '/wordpress-mu');
    foreach ($roots as $root) {
        if ($wp_filesystem->exists($from . $root . '/wp-settings.php') && $wp_filesystem->exists($from . $root . '/wp-admin/admin.php') && $wp_filesystem->exists($from . $root . '/wp-includes/functions.php')) {
            $distro = $root;
            break;
        }
    }
    if (!$distro) {
        $wp_filesystem->delete($from, true);
        return new WP_Error('insane_distro', __('The update could not be unpacked'));
    }
    apply_filters('update_feedback', __('Installing the latest version&#8230;'));
    // Create maintenance file to signal that we are upgrading
    $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    $maintenance_file = $to . '.maintenance';
    $wp_filesystem->delete($maintenance_file);
    $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
    // Copy new versions of WP files into place.
    $result = copy_dir($from . $distro, $to);
    if (is_wp_error($result)) {
        $wp_filesystem->delete($maintenance_file);
        $wp_filesystem->delete($from, true);
        return $result;
    }
    // Remove old files
    foreach ($_old_files as $old_file) {
        $old_file = $to . $old_file;
        if (!$wp_filesystem->exists($old_file)) {
            continue;
        }
        $wp_filesystem->delete($old_file, true);
    }
    // Upgrade DB with separate request
    apply_filters('update_feedback', __('Upgrading database&#8230;'));
    $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
    wp_remote_post($db_upgrade_url, array('timeout' => 60));
    // Remove working directory
    $wp_filesystem->delete($from, true);
    // Force refresh of update information
    if (function_exists('delete_site_transient')) {
        delete_site_transient('update_core');
    } else {
        delete_option('update_core');
    }
    // Remove maintenance file, we're done.
    $wp_filesystem->delete($maintenance_file);
}
Ejemplo n.º 25
0
/**
 * Copies a directory from one location to another via the WordPress Filesystem Abstraction.
 * Assumes that WP_Filesystem() has already been called and setup.
 *
 * @since 2.5.0
 *
 * @param string $from source directory
 * @param string $to destination directory
 * @param array $skip_list a list of files/folders to skip copying
 * @return mixed WP_Error on failure, True on success.
 */
function copy_dir($from, $to, $skip_list = array())
{
    global $wp_filesystem;
    $dirlist = $wp_filesystem->dirlist($from);
    $from = trailingslashit($from);
    $to = trailingslashit($to);
    $skip_regex = '';
    foreach ((array) $skip_list as $key => $skip_file) {
        $skip_regex .= preg_quote($skip_file, '!') . '|';
    }
    if (!empty($skip_regex)) {
        $skip_regex = '!(' . rtrim($skip_regex, '|') . ')$!i';
    }
    foreach ((array) $dirlist as $filename => $fileinfo) {
        if (!empty($skip_regex)) {
            if (preg_match($skip_regex, $from . $filename)) {
                continue;
            }
        }
        if ('f' == $fileinfo['type']) {
            if (!$wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE)) {
                // If copy failed, chmod file to 0644 and try again.
                $wp_filesystem->chmod($to . $filename, 0644);
                if (!$wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE)) {
                    return new WP_Error('copy_failed', __('Could not copy file.'), $to . $filename);
                }
            }
        } elseif ('d' == $fileinfo['type']) {
            if (!$wp_filesystem->is_dir($to . $filename)) {
                if (!$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR)) {
                    return new WP_Error('mkdir_failed', __('Could not create directory.'), $to . $filename);
                }
            }
            $result = copy_dir($from . $filename, $to . $filename, $skip_list);
            if (is_wp_error($result)) {
                return $result;
            }
        }
    }
    return true;
}
Ejemplo n.º 26
0
/**
 * Upgrade the core of WordPress.
 *
 * This will create a .maintenance file at the base of the WordPress directory
 * to ensure that people can not access the web site, when the files are being
 * copied to their locations.
 *
 * The files in the {@link $_old_files} list will be removed and the new files
 * copied from the zip file after the database is upgraded.
 *
 * The files in the {@link $_new_bundled_files} list will be added to the installation
 * if the version is greater than or equal to the old version being upgraded.
 *
 * The steps for the upgrader for after the new release is downloaded and
 * unzipped is:
 *   1. Test unzipped location for select files to ensure that unzipped worked.
 *   2. Create the .maintenance file in current WordPress base.
 *   3. Copy new WordPress directory over old WordPress files.
 *   4. Upgrade WordPress to new version.
 *     4.1. Copy all files/folders other than wp-content
 *     4.2. Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR
 *     4.3. Copy any new bundled themes/plugins to their respective locations
 *   5. Delete new WordPress directory path.
 *   6. Delete .maintenance file.
 *   7. Remove old files.
 *   8. Delete 'update_core' option.
 *
 * There are several areas of failure. For instance if PHP times out before step
 * 6, then you will not be able to access any portion of your site. Also, since
 * the upgrade will not continue where it left off, you will not be able to
 * automatically remove old files and remove the 'update_core' option. This
 * isn't that bad.
 *
 * If the copy of the new WordPress over the old fails, then the worse is that
 * the new WordPress directory will remain.
 *
 * If it is assumed that every file will be copied over, including plugins and
 * themes, then if you edit the default theme, you should rename it, so that
 * your changes remain.
 *
 * @since 2.7.0
 *
 * @global WP_Filesystem_Base $wp_filesystem
 * @global array              $_old_files
 * @global array              $_new_bundled_files
 * @global wpdb               $wpdb
 * @global string             $wp_version
 * @global string             $required_php_version
 * @global string             $required_mysql_version
 *
 * @param string $from New release unzipped path.
 * @param string $to   Path to old WordPress installation.
 * @return WP_Error|null WP_Error on failure, null on success.
 */
function update_core($from, $to)
{
    global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
    @set_time_limit(300);
    /**
     * Filter feedback messages displayed during the core update process.
     *
     * The filter is first evaluated after the zip file for the latest version
     * has been downloaded and unzipped. It is evaluated five more times during
     * the process:
     *
     * 1. Before WordPress begins the core upgrade process.
     * 2. Before Maintenance Mode is enabled.
     * 3. Before WordPress begins copying over the necessary files.
     * 4. Before Maintenance Mode is disabled.
     * 5. Before the database is upgraded.
     *
     * @since 2.5.0
     *
     * @param string $feedback The core update feedback messages.
     */
    apply_filters('update_feedback', __('Verifying the unpacked files&#8230;'));
    // Sanity check the unzipped distribution.
    $distro = '';
    $roots = array('/wordpress/', '/wordpress-mu/');
    foreach ($roots as $root) {
        if ($wp_filesystem->exists($from . $root . 'readme.html') && $wp_filesystem->exists($from . $root . 'wp-includes/version.php')) {
            $distro = $root;
            break;
        }
    }
    if (!$distro) {
        $wp_filesystem->delete($from, true);
        return new WP_Error('insane_distro', __('The update could not be unpacked'));
    }
    /**
     * Import $wp_version, $required_php_version, and $required_mysql_version from the new version
     * $wp_filesystem->wp_content_dir() returned unslashed pre-2.8
     *
     * @global string $wp_version
     * @global string $required_php_version
     * @global string $required_mysql_version
     */
    global $wp_version, $required_php_version, $required_mysql_version;
    $versions_file = trailingslashit($wp_filesystem->wp_content_dir()) . 'upgrade/version-current.php';
    if (!$wp_filesystem->copy($from . $distro . 'wp-includes/version.php', $versions_file)) {
        $wp_filesystem->delete($from, true);
        return new WP_Error('copy_failed_for_version_file', __('The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.'), 'wp-includes/version.php');
    }
    $wp_filesystem->chmod($versions_file, FS_CHMOD_FILE);
    require WP_CONTENT_DIR . '/upgrade/version-current.php';
    $wp_filesystem->delete($versions_file);
    $php_version = phpversion();
    $mysql_version = $wpdb->db_version();
    $old_wp_version = $wp_version;
    // The version of WordPress we're updating from
    $development_build = false !== strpos($old_wp_version . $wp_version, '-');
    // a dash in the version indicates a Development release
    $php_compat = version_compare($php_version, $required_php_version, '>=');
    if (file_exists(WP_CONTENT_DIR . '/db.php') && empty($wpdb->is_mysql)) {
        $mysql_compat = true;
    } else {
        $mysql_compat = version_compare($mysql_version, $required_mysql_version, '>=');
    }
    if (!$mysql_compat || !$php_compat) {
        $wp_filesystem->delete($from, true);
    }
    if (!$mysql_compat && !$php_compat) {
        return new WP_Error('php_mysql_not_compatible', sprintf(__('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher and MySQL version %3$s or higher. You are running PHP version %4$s and MySQL version %5$s.'), $wp_version, $required_php_version, $required_mysql_version, $php_version, $mysql_version));
    } elseif (!$php_compat) {
        return new WP_Error('php_not_compatible', sprintf(__('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version));
    } elseif (!$mysql_compat) {
        return new WP_Error('mysql_not_compatible', sprintf(__('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version));
    }
    /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters('update_feedback', __('Preparing to install the latest version&#8230;'));
    // Don't copy wp-content, we'll deal with that below
    // We also copy version.php last so failed updates report their old version
    $skip = array('wp-content', 'wp-includes/version.php');
    $check_is_writable = array();
    // Check to see which files don't really need updating - only available for 3.7 and higher
    if (function_exists('get_core_checksums')) {
        // Find the local version of the working directory
        $working_dir_local = WP_CONTENT_DIR . '/upgrade/' . basename($from) . $distro;
        $checksums = get_core_checksums($wp_version, isset($wp_local_package) ? $wp_local_package : 'en_US');
        if (is_array($checksums) && isset($checksums[$wp_version])) {
            $checksums = $checksums[$wp_version];
        }
        // Compat code for 3.7-beta2
        if (is_array($checksums)) {
            foreach ($checksums as $file => $checksum) {
                if ('wp-content' == substr($file, 0, 10)) {
                    continue;
                }
                if (!file_exists(ABSPATH . $file)) {
                    continue;
                }
                if (!file_exists($working_dir_local . $file)) {
                    continue;
                }
                if (md5_file(ABSPATH . $file) === $checksum) {
                    $skip[] = $file;
                } else {
                    $check_is_writable[$file] = ABSPATH . $file;
                }
            }
        }
    }
    // If we're using the direct method, we can predict write failures that are due to permissions.
    if ($check_is_writable && 'direct' === $wp_filesystem->method) {
        $files_writable = array_filter($check_is_writable, array($wp_filesystem, 'is_writable'));
        if ($files_writable !== $check_is_writable) {
            $files_not_writable = array_diff_key($check_is_writable, $files_writable);
            foreach ($files_not_writable as $relative_file_not_writable => $file_not_writable) {
                // If the writable check failed, chmod file to 0644 and try again, same as copy_dir().
                $wp_filesystem->chmod($file_not_writable, FS_CHMOD_FILE);
                if ($wp_filesystem->is_writable($file_not_writable)) {
                    unset($files_not_writable[$relative_file_not_writable]);
                }
            }
            // Store package-relative paths (the key) of non-writable files in the WP_Error object.
            $error_data = version_compare($old_wp_version, '3.7-beta2', '>') ? array_keys($files_not_writable) : '';
            if ($files_not_writable) {
                return new WP_Error('files_not_writable', __('The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.'), implode(', ', $error_data));
            }
        }
    }
    /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters('update_feedback', __('Enabling Maintenance mode&#8230;'));
    // Create maintenance file to signal that we are upgrading
    $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    $maintenance_file = $to . '.maintenance';
    $wp_filesystem->delete($maintenance_file);
    $wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
    /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters('update_feedback', __('Copying the required files&#8230;'));
    // Copy new versions of WP files into place.
    $result = _copy_dir($from . $distro, $to, $skip);
    if (is_wp_error($result)) {
        $result = new WP_Error($result->get_error_code(), $result->get_error_message(), substr($result->get_error_data(), strlen($to)));
    }
    // Since we know the core files have copied over, we can now copy the version file
    if (!is_wp_error($result)) {
        if (!$wp_filesystem->copy($from . $distro . 'wp-includes/version.php', $to . 'wp-includes/version.php', true)) {
            $wp_filesystem->delete($from, true);
            $result = new WP_Error('copy_failed_for_version_file', __('The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.'), 'wp-includes/version.php');
        }
        $wp_filesystem->chmod($to . 'wp-includes/version.php', FS_CHMOD_FILE);
    }
    // Check to make sure everything copied correctly, ignoring the contents of wp-content
    $skip = array('wp-content');
    $failed = array();
    if (isset($checksums) && is_array($checksums)) {
        foreach ($checksums as $file => $checksum) {
            if ('wp-content' == substr($file, 0, 10)) {
                continue;
            }
            if (!file_exists($working_dir_local . $file)) {
                continue;
            }
            if (file_exists(ABSPATH . $file) && md5_file(ABSPATH . $file) == $checksum) {
                $skip[] = $file;
            } else {
                $failed[] = $file;
            }
        }
    }
    // Some files didn't copy properly
    if (!empty($failed)) {
        $total_size = 0;
        foreach ($failed as $file) {
            if (file_exists($working_dir_local . $file)) {
                $total_size += filesize($working_dir_local . $file);
            }
        }
        // If we don't have enough free space, it isn't worth trying again.
        // Unlikely to be hit due to the check in unzip_file().
        $available_space = @disk_free_space(ABSPATH);
        if ($available_space && $total_size >= $available_space) {
            $result = new WP_Error('disk_full', __('There is not enough free disk space to complete the update.'));
        } else {
            $result = _copy_dir($from . $distro, $to, $skip);
            if (is_wp_error($result)) {
                $result = new WP_Error($result->get_error_code() . '_retry', $result->get_error_message(), substr($result->get_error_data(), strlen($to)));
            }
        }
    }
    // Custom Content Directory needs updating now.
    // Copy Languages
    if (!is_wp_error($result) && $wp_filesystem->is_dir($from . $distro . 'wp-content/languages')) {
        if (WP_LANG_DIR != ABSPATH . WPINC . '/languages' || @is_dir(WP_LANG_DIR)) {
            $lang_dir = WP_LANG_DIR;
        } else {
            $lang_dir = WP_CONTENT_DIR . '/languages';
        }
        if (!@is_dir($lang_dir) && 0 === strpos($lang_dir, ABSPATH)) {
            // Check the language directory exists first
            $wp_filesystem->mkdir($to . str_replace(ABSPATH, '', $lang_dir), FS_CHMOD_DIR);
            // If it's within the ABSPATH we can handle it here, otherwise they're out of luck.
            clearstatcache();
            // for FTP, Need to clear the stat cache
        }
        if (@is_dir($lang_dir)) {
            $wp_lang_dir = $wp_filesystem->find_folder($lang_dir);
            if ($wp_lang_dir) {
                $result = copy_dir($from . $distro . 'wp-content/languages/', $wp_lang_dir);
                if (is_wp_error($result)) {
                    $result = new WP_Error($result->get_error_code() . '_languages', $result->get_error_message(), substr($result->get_error_data(), strlen($wp_lang_dir)));
                }
            }
        }
    }
    /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters('update_feedback', __('Disabling Maintenance mode&#8230;'));
    // Remove maintenance file, we're done with potential site-breaking changes
    $wp_filesystem->delete($maintenance_file);
    // 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users, preventing installation of Twenty Twelve.
    if ('3.5' == $old_wp_version) {
        if (is_dir(WP_CONTENT_DIR . '/themes/twentytwelve') && !file_exists(WP_CONTENT_DIR . '/themes/twentytwelve/style.css')) {
            $wp_filesystem->delete($wp_filesystem->wp_themes_dir() . 'twentytwelve/');
        }
    }
    // Copy New bundled plugins & themes
    // This gives us the ability to install new plugins & themes bundled with future versions of WordPress whilst avoiding the re-install upon upgrade issue.
    // $development_build controls us overwriting bundled themes and plugins when a non-stable release is being updated
    if (!is_wp_error($result) && (!defined('CORE_UPGRADE_SKIP_NEW_BUNDLED') || !CORE_UPGRADE_SKIP_NEW_BUNDLED)) {
        foreach ((array) $_new_bundled_files as $file => $introduced_version) {
            // If a $development_build or if $introduced version is greater than what the site was previously running
            if ($development_build || version_compare($introduced_version, $old_wp_version, '>')) {
                $directory = '/' == $file[strlen($file) - 1];
                list($type, $filename) = explode('/', $file, 2);
                // Check to see if the bundled items exist before attempting to copy them
                if (!$wp_filesystem->exists($from . $distro . 'wp-content/' . $file)) {
                    continue;
                }
                if ('plugins' == $type) {
                    $dest = $wp_filesystem->wp_plugins_dir();
                } elseif ('themes' == $type) {
                    $dest = trailingslashit($wp_filesystem->wp_themes_dir());
                } else {
                    continue;
                }
                if (!$directory) {
                    if (!$development_build && $wp_filesystem->exists($dest . $filename)) {
                        continue;
                    }
                    if (!$wp_filesystem->copy($from . $distro . 'wp-content/' . $file, $dest . $filename, FS_CHMOD_FILE)) {
                        $result = new WP_Error("copy_failed_for_new_bundled_{$type}", __('Could not copy file.'), $dest . $filename);
                    }
                } else {
                    if (!$development_build && $wp_filesystem->is_dir($dest . $filename)) {
                        continue;
                    }
                    $wp_filesystem->mkdir($dest . $filename, FS_CHMOD_DIR);
                    $_result = copy_dir($from . $distro . 'wp-content/' . $file, $dest . $filename);
                    // If a error occurs partway through this final step, keep the error flowing through, but keep process going.
                    if (is_wp_error($_result)) {
                        if (!is_wp_error($result)) {
                            $result = new WP_Error();
                        }
                        $result->add($_result->get_error_code() . "_{$type}", $_result->get_error_message(), substr($_result->get_error_data(), strlen($dest)));
                    }
                }
            }
        }
        //end foreach
    }
    // Handle $result error from the above blocks
    if (is_wp_error($result)) {
        $wp_filesystem->delete($from, true);
        return $result;
    }
    // Remove old files
    foreach ($_old_files as $old_file) {
        $old_file = $to . $old_file;
        if (!$wp_filesystem->exists($old_file)) {
            continue;
        }
        $wp_filesystem->delete($old_file, true);
    }
    // Remove any Genericons example.html's from the filesystem
    _upgrade_422_remove_genericons();
    // Upgrade DB with separate request
    /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters('update_feedback', __('Upgrading database&#8230;'));
    $db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
    wp_remote_post($db_upgrade_url, array('timeout' => 60));
    // Clear the cache to prevent an update_option() from saving a stale db_version to the cache
    wp_cache_flush();
    // (Not all cache backends listen to 'flush')
    wp_cache_delete('alloptions', 'options');
    // Remove working directory
    $wp_filesystem->delete($from, true);
    // Force refresh of update information
    if (function_exists('delete_site_transient')) {
        delete_site_transient('update_core');
    } else {
        delete_option('update_core');
    }
    /**
     * Fires after WordPress core has been successfully updated.
     *
     * @since 3.3.0
     *
     * @param string $wp_version The current WordPress version.
     */
    do_action('_core_updated_successfully', $wp_version);
    // Clear the option that blocks auto updates after failures, now that we've been successful.
    if (function_exists('delete_site_option')) {
        delete_site_option('auto_core_update_failed');
    }
    return $wp_version;
}
 public function copy_templates()
 {
     $templates_dir = trailingslashit(trailingslashit(HW_YARPP_DIR) . 'hw-yarpp-templates');
     require_once ABSPATH . 'wp-admin/includes/file.php';
     WP_Filesystem(false, get_stylesheet_directory());
     global $wp_filesystem;
     if ($wp_filesystem->method !== 'direct') {
         return false;
     }
     return copy_dir($templates_dir, get_stylesheet_directory(), array('.svn'));
 }
 /**
  * This basically is set to fix the directories for our plugins.
  *
  * Take incoming remote_source file and rename it to match what it should be.
  *
  * @param  string $source        This is usually the same as $remote_source but *may* be something else if this has already been filtered
  * @param  string $remote_source What WP has set as the source (ee plugins coming from beta.eventespresso.com will be beta.tmp)
  * @param  WPPluginUpgrader $wppu
  * @return string renamed file and path
  */
 function fixDirName($source, $remote_source, $wppu)
 {
     global $wp_filesystem;
     //get out early if this doesn't have a plugin updgrader object.
     if (!$wppu instanceof Plugin_Upgrader) {
         return $source;
     }
     //if this is a bulk update then we need an alternate method to verify this is an update we need to modify.
     if ($wppu->bulk) {
         $url_to_check = $wppu->skin->options['url'];
         $is_good = strpos($url_to_check, urlencode($this->pluginFile)) === FALSE ? FALSE : TRUE;
     } else {
         $is_good = isset($wppu->skin->plugin) && $wppu->skin->plugin == $this->pluginFile ? TRUE : FALSE;
     }
     if ($is_good) {
         $new_dir = $wp_filesystem->wp_content_dir() . 'upgrade/' . $this->slug . '/';
         //make new directory if needed.
         if ($wp_filesystem->exists($new_dir)) {
             //delete the existing dir first because we want to make sure clean install
             $wp_filesystem->delete($new_dir, FALSE, 'd');
         }
         //now make sure that we DON'T have the directory and we'll create a new one for this.
         if (!$wp_filesystem->exists($new_dir)) {
             if (!$wp_filesystem->mkdir($new_dir, FS_CHMOD_DIR)) {
                 return new WP_Error('mkdir_failed_destination', $wppu->strings['mkdir_failed'], $new_dir);
             }
         }
         //copy original $source into new source
         $result = copy_dir($source, $new_dir);
         if (is_wp_error($result)) {
             //something went wrong let's just return the original $source as a fallback.
             return $source;
         }
         //everything went okay... new source = new dir
         $source = $new_dir;
     }
     return $source;
 }
Ejemplo n.º 29
0
 function install_package($args = array())
 {
     global $wp_filesystem;
     $defaults = array('source' => '', 'destination' => '', 'clear_destination' => false, 'clear_working' => false, 'hook_extra' => array());
     $args = wp_parse_args($args, $defaults);
     extract($args);
     @set_time_limit(300);
     if (empty($source) || empty($destination)) {
         return new WP_Error('bad_request', $this->strings['bad_request']);
     }
     $this->skin->feedback('installing_package');
     $res = apply_filters('upgrader_pre_install', true, $hook_extra);
     if (is_wp_error($res)) {
         return $res;
     }
     //Retain the Original source and destinations
     $remote_source = $source;
     $local_destination = $destination;
     $source_files = array_keys($wp_filesystem->dirlist($remote_source));
     $remote_destination = $wp_filesystem->find_folder($local_destination);
     //Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
     if (1 == count($source_files) && $wp_filesystem->is_dir(trailingslashit($source) . $source_files[0] . '/')) {
         //Only one folder? Then we want its contents.
         $source = trailingslashit($source) . trailingslashit($source_files[0]);
     } elseif (count($source_files) == 0) {
         return new WP_Error('bad_package', $this->strings['bad_package']);
     }
     //There are no files?
     //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.
     //Hook ability to change the source file location..
     $source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
     if (is_wp_error($source)) {
         return $source;
     }
     //Has the source location changed? If so, we need a new source_files list.
     if ($source !== $remote_source) {
         $source_files = array_keys($wp_filesystem->dirlist($source));
     }
     //Protection against deleting files in any important base directories.
     if (in_array($destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes'))) {
         $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source));
         $destination = trailingslashit($destination) . trailingslashit(basename($source));
     }
     if ($wp_filesystem->exists($remote_destination)) {
         if ($clear_destination) {
             //We're going to clear the destination if theres something there
             $this->skin->feedback('remove_old');
             $removed = $wp_filesystem->delete($remote_destination, true);
             $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra);
             if (is_wp_error($removed)) {
                 return $removed;
             } else {
                 if (!$removed) {
                     return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
                 }
             }
         } else {
             //If we're not clearing the destination folder and something exists there allready, Bail.
             //But first check to see if there are actually any files in the folder.
             $_files = $wp_filesystem->dirlist($remote_destination);
         }
     }
     //Create destination if needed
     if (!$wp_filesystem->exists($remote_destination)) {
         if (!$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR)) {
             return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination);
         }
     }
     // Copy new version of item into place.
     $result = copy_dir($source, $remote_destination);
     if (is_wp_error($result)) {
         if ($clear_working) {
             $wp_filesystem->delete($remote_source, true);
         }
         return $result;
     }
     //Clear the Working folder?
     if ($clear_working) {
         $wp_filesystem->delete($remote_source, true);
     }
     $destination_name = basename(str_replace($local_destination, '', $destination));
     if ('.' == $destination_name) {
         $destination_name = '';
     }
     $this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir');
     $res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result);
     if (is_wp_error($res)) {
         $this->result = $res;
         return $res;
     }
     //Bombard the calling function will all the info which we've just used.
     return $this->result;
 }
Ejemplo n.º 30
0
function copy_dir($src, $trg, $copy_subdirs = true, $overwrite = false, $die_on_failure = true, $source_relative_path = true)
{
    global $convert, $phpbb_root_path, $config, $user, $db;
    $dirlist = $filelist = $bad_dirs = array();
    $src = path($src, $source_relative_path);
    $trg = path($trg);
    $src_path = relative_base($src, $source_relative_path, __LINE__, __FILE__);
    $trg_path = $phpbb_root_path . $trg;
    if (!is_dir($trg_path)) {
        @mkdir($trg_path, 0777);
        @chmod($trg_path, 0777);
    }
    if (!phpbb_is_writable($trg_path)) {
        $bad_dirs[] = path($config['script_path']) . $trg;
    }
    if ($handle = @opendir($src_path)) {
        while ($entry = readdir($handle)) {
            if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm') {
                continue;
            }
            if (is_dir($src_path . $entry)) {
                $dirlist[] = $entry;
            } else {
                $filelist[] = $entry;
            }
        }
        closedir($handle);
    } else {
        if ($dir = @dir($src_path)) {
            while ($entry = $dir->read()) {
                if ($entry[0] == '.' || $entry == 'CVS' || $entry == 'index.htm') {
                    continue;
                }
                if (is_dir($src_path . $entry)) {
                    $dirlist[] = $entry;
                } else {
                    $filelist[] = $entry;
                }
            }
            $dir->close();
        } else {
            $convert->p_master->error(sprintf($user->lang['CONV_ERROR_COULD_NOT_READ'], relative_base($src, $source_relative_path)), __LINE__, __FILE__);
        }
    }
    if ($copy_subdirs) {
        for ($i = 0; $i < sizeof($dirlist); ++$i) {
            $dir = $dirlist[$i];
            if ($dir == 'CVS') {
                continue;
            }
            if (!is_dir($trg_path . $dir)) {
                @mkdir($trg_path . $dir, 0777);
                @chmod($trg_path . $dir, 0777);
            }
            if (!phpbb_is_writable($trg_path . $dir)) {
                $bad_dirs[] = $trg . $dir;
                $bad_dirs[] = $trg_path . $dir;
            }
            if (!sizeof($bad_dirs)) {
                copy_dir($src . $dir, $trg . $dir, true, $overwrite, $die_on_failure, $source_relative_path);
            }
        }
    }
    if (sizeof($bad_dirs)) {
        $str = sizeof($bad_dirs) == 1 ? $user->lang['MAKE_FOLDER_WRITABLE'] : $user->lang['MAKE_FOLDERS_WRITABLE'];
        sort($bad_dirs);
        $convert->p_master->error(sprintf($str, implode('<br />', $bad_dirs)), __LINE__, __FILE__);
    }
    for ($i = 0; $i < sizeof($filelist); ++$i) {
        copy_file($src . $filelist[$i], $trg . $filelist[$i], $overwrite, $die_on_failure, $source_relative_path);
    }
}