示例#1
0
/**
 * Display a html list of files
 *
 * @param HMBKP_Scheduled_Backup $schedule
 * @param mixed                  $excludes    (default: null)
 * @param string                 $file_method (default: 'get_included_files')
 * @return void
 */
function hmbkp_file_list(HMBKP_Scheduled_Backup $schedule, $excludes = null, $file_method = 'get_included_files')
{
    if (!is_null($excludes)) {
        $schedule->set_excludes($excludes);
    }
    $exclude_string = $schedule->exclude_string('regex');
    ?>

	<ul class="hmbkp_file_list code">

		<?php 
    foreach ($schedule->get_files() as $file) {
        if (!is_null($excludes) && strpos($file, str_ireplace($schedule->get_root(), '', $schedule->get_path())) !== false) {
            continue;
        }
        // Skip dot files, they should only exist on versions of PHP between 5.2.11 -> 5.3
        if (method_exists($file, 'isDot') && $file->isDot()) {
            continue;
        }
        // Show only unreadable files
        if ($file_method === 'get_unreadable_files' && @realpath($file->getPathname()) && $file->isReadable()) {
            continue;
        } elseif ($file_method !== 'get_unreadable_files' && (!@realpath($file->getPathname()) || !$file->isReadable())) {
            continue;
        }
        // Show only included files
        if ($file_method === 'get_included_files') {
            if ($exclude_string && preg_match('(' . $exclude_string . ')', str_ireplace(trailingslashit($schedule->get_root()), '', HM_Backup::conform_dir($file->getPathname())))) {
                continue;
            }
        }
        // Show only excluded files
        if ($file_method === 'get_excluded_files') {
            if (!$exclude_string || !preg_match('(' . $exclude_string . ')', str_ireplace(trailingslashit($schedule->get_root()), '', HM_Backup::conform_dir($file->getPathname())))) {
                continue;
            }
        }
        if (@realpath($file->getPathname()) && !$file->isReadable() && $file->isDir()) {
            ?>

				<li title="<?php 
            echo esc_attr(HM_Backup::conform_dir(trailingslashit($file->getPathName())));
            ?>
"><?php 
            echo esc_html(ltrim(trailingslashit(str_ireplace(HM_Backup::conform_dir(trailingslashit($schedule->get_root())), '', HM_Backup::conform_dir($file->getPathName()))), '/'));
            ?>
</li>

			<?php 
        } else {
            ?>

				<li title="<?php 
            echo esc_attr(HM_Backup::conform_dir($file->getPathName()));
            ?>
"><?php 
            echo esc_html(ltrim(str_ireplace(HM_Backup::conform_dir(trailingslashit($schedule->get_root())), '', HM_Backup::conform_dir($file->getPathName())), '/'));
            ?>
</li>

			<?php 
        }
    }
    ?>

	</ul>

<?php 
}
示例#2
0
/**
 * Handles anything that needs to be
 * done when the plugin is updated
 */
function hmbkp_update()
{
    // Update from backUpWordPress 0.4.5
    if (get_option('bkpwp_max_backups')) {
        // Carry over the custom path
        if ($legacy_path = get_option('bkpwppath')) {
            update_option('hmbkp_path', $legacy_path);
        }
        // Options to remove
        $legacy_options = array('bkpwp_archive_types', 'bkpwp_automail_from', 'bkpwp_domain', 'bkpwp_domain_path', 'bkpwp_easy_mode', 'bkpwp_excludelists', 'bkpwp_install_user', 'bkpwp_listmax_backups', 'bkpwp_max_backups', 'bkpwp_presets', 'bkpwp_reccurrences', 'bkpwp_schedules', 'bkpwp_calculation', 'bkpwppath', 'bkpwp_status_config', 'bkpwp_status');
        foreach ($legacy_options as $option) {
            delete_option($option);
        }
        global $wp_roles;
        $wp_roles->remove_cap('administrator', 'manage_backups');
        $wp_roles->remove_cap('administrator', 'download_backups');
        wp_clear_scheduled_hook('bkpwp_schedule_bkpwp_hook');
    }
    // Version 1 to 2
    if (get_option('hmbkp_plugin_version') && version_compare('2.0', get_option('hmbkp_plugin_version'), '>')) {
        /**
         * Setup a backwards compatible schedule
         */
        $legacy_schedule = new HMBKP_Scheduled_Backup('backup');
        // Backup type
        if (defined('HMBKP_FILES_ONLY') && HMBKP_FILES_ONLY || get_option('hmbkp_files_only')) {
            $legacy_schedule->set_type('file');
        } elseif (defined('HMBKP_DATABASE_ONLY') && HMBKP_DATABASE_ONLY || get_option('hmbkp_database_only')) {
            $legacy_schedule->set_type('database');
        } else {
            $legacy_schedule->set_type('complete');
        }
        // Daily schedule time
        if (defined('HMBKP_DAILY_SCHEDULE_TIME') && HMBKP_DAILY_SCHEDULE_TIME) {
            $legacy_schedule->set_schedule_start_time(strtotime(HMBKP_DAILY_SCHEDULE_TIME));
        }
        // Backup schedule
        $legacy_schedule->set_reoccurrence(get_option('hmbkp_schedule_frequency', 'hmbkp_daily'));
        // Automatic backups disabled?
        if (defined('HMBKP_DISABLE_AUTOMATIC_BACKUP') && HMBKP_DISABLE_AUTOMATIC_BACKUP || get_option('hmbkp_disable_automatic_backup')) {
            $legacy_schedule->set_reoccurrence('manually');
        }
        // Max backups
        if (defined('HMBKP_MAX_BACKUPS') && is_numeric(HMBKP_MAX_BACKUPS)) {
            $legacy_schedule->set_max_backups((int) HMBKP_MAX_BACKUPS);
        } else {
            $legacy_schedule->set_max_backups((int) get_option('hmbkp_max_backups', 10));
        }
        // Excludes
        if (get_option('hmbkp_excludes')) {
            $legacy_schedule->set_excludes(get_option('hmbkp_excludes'));
        }
        // Backup email
        if (defined('HMBKP_EMAIL') && is_email(HMBKP_EMAIL)) {
            $legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => HMBKP_EMAIL));
        } elseif (is_email(get_option('hmbkp_email_address'))) {
            $legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => get_option('hmbkp_email_address')));
        }
        // Set the archive filename to what it used to be
        $legacy_schedule->set_archive_filename(implode('-', array(get_bloginfo('name'), 'backup', date('Y-m-d-H-i-s', current_time('timestamp')))) . '.zip');
        $legacy_schedule->save();
        // Remove the legacy options
        foreach (array('hmbkp_database_only', 'hmbkp_files_only', 'hmbkp_max_backups', 'hmbkp_email_address', 'hmbkp_email', 'hmbkp_schedule_frequency', 'hmbkp_disable_automatic_backup') as $option_name) {
            delete_option($option_name);
        }
    }
    // Update from 2.2.4
    if (get_option('hmbkp_plugin_version') && version_compare('2.2.5', get_option('hmbkp_plugin_version'), '>')) {
        $schedules = HMBKP_Schedules::get_instance();
        // Loop through all schedules and re-set the reccurrence to include hmbkp_
        foreach ($schedules->get_schedules() as $schedule) {
            $reoccurrence = $schedule->get_reoccurrence();
            if ($reoccurrence !== 'manually' && strpos($reoccurrence, 'hmbkp_') === false) {
                $schedule->set_reoccurrence('hmbkp_' . $schedule->get_reoccurrence());
            }
            $schedule->save();
        }
    }
    // Every update
    if (get_option('hmbkp_plugin_version') && version_compare(HMBKP_VERSION, get_option('hmbkp_plugin_version'), '>')) {
        hmbkp_deactivate();
        // re-calcuate the backups directory and move to it.
        if (!defined('HMBKP_PATH')) {
            $old_path = hmbkp_path();
            delete_option('hmbkp_path');
            delete_option('hmbkp_default_path');
            hmbkp_path_move($old_path, hmbkp_path());
        }
        // Force .htaccess to be re-written
        if (file_exists(hmbkp_path() . '/.htaccess')) {
            unlink(hmbkp_path() . '/.htaccess');
        }
        // Force index.html to be re-written
        if (file_exists(hmbkp_path() . '/index.html')) {
            unlink(hmbkp_path() . '/index.html');
        }
    }
    // Update the stored version
    if (get_option('hmbkp_plugin_version') !== HMBKP_VERSION) {
        update_option('hmbkp_plugin_version', HMBKP_VERSION);
    }
}
示例#3
0
/**
 * Delete an exclude rule
 *
 * @access public
 * @return void
 */
function hmbkp_delete_exclude_rule()
{
    if (empty($_GET['hmbkp_schedule_id'])) {
        die;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id']));
    $excludes = $schedule->get_excludes();
    $schedule->set_excludes(array_diff($excludes, (array) stripslashes(sanitize_text_field($_GET['hmbkp_exclude_rule']))));
    $schedule->save();
    require HMBKP_PLUGIN_PATH . '/admin/schedule-form-excludes.php';
    die;
}
示例#4
0
/**
 * Delete an exclude rule
 *
 * @access public
 * @return void
 */
function hmbkp_remove_exclude_rule()
{
    check_admin_referer('hmbkp_remove_exclude_rule', 'hmbkp-remove_exclude_rule_nonce');
    if (!isset($_GET['hmbkp_remove_exclude'])) {
        die;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id']));
    $excludes = $schedule->get_excludes();
    $schedule->set_excludes(array_diff($excludes, (array) stripslashes(sanitize_text_field($_GET['hmbkp_remove_exclude']))));
    $schedule->save();
    wp_safe_redirect(wp_get_referer(), '303');
    die;
}
示例#5
0
/**
 * Delete an exclude rule
 *
 * @access public
 * @return void
 */
function hmbkp_remove_exclude_rule()
{
    check_admin_referer('hmbkp_remove_exclude_rule', 'hmbkp-remove_exclude_rule_nonce');
    if (!isset($_GET['hmbkp_remove_exclude'])) {
        die;
    }
    $schedule = new HMBKP_Scheduled_Backup(sanitize_text_field($_GET['hmbkp_schedule_id']));
    $excludes = $schedule->get_excludes();
    $schedule->set_excludes(array_diff($excludes, (array) stripslashes(sanitize_text_field($_GET['hmbkp_remove_exclude']))));
    $schedule->save();
    $url = add_query_arg(array('action' => 'hmbkp_edit_schedule', 'hmbkp_panel' => 'hmbkp_edit_schedule_excludes'), hmbkp_get_settings_url());
    if (isset($_GET['hmbkp_directory_browse'])) {
        $url = add_query_arg('hmbkp_directory_browse', sanitize_text_field($_GET['hmbkp_directory_browse']), $url);
    }
    wp_safe_redirect($url, '303');
    die;
}