1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116:
<?php
$plugin_is_filter = 2 | ADMIN_PLUGIN | THEME_PLUGIN;
$plugin_description = gettext("Periodically backup the Zenphoto database content.");
$plugin_author = "Stephen Billard (sbillard)";
$plugin_category = gettext('Admin');
$option_interface = 'auto_backup';
if ((getOption('last_backup_run') + getOption('backup_interval') * 86400) < time()) {
require_once(dirname(dirname(__FILE__)) . '/admin-functions.php');
zp_register_filter('admin_head', 'auto_backup::timer_handler');
zp_register_filter('theme_head', 'auto_backup::timer_handler');
}
class auto_backup {
function __construct() {
setOptionDefault('backup_interval', 7);
setOptionDefault('backups_to_keep', 5);
}
function getOptionsSupported() {
$options = array(
gettext('Run interval') => array(
'key' => 'backup_interval',
'type' => OPTION_TYPE_TEXTBOX,
'order' => 1,
'desc' => gettext('The run interval (in days) for auto backup.')),
gettext('Backups to keep') => array(
'key' => 'backups_to_keep',
'type' => OPTION_TYPE_TEXTBOX,
'order' => 0,
'desc' => gettext('Auto backup will keep only this many backup sets. Older sets will be removed.'))
);
if ($d = getOption('last_backup_run')) {
$options[
gettext('Last backup')] = array(
'key' => 'last_backup_run',
'type' => OPTION_TYPE_NOTE,
'order' => 2,
'desc' => '<p class="notebox">' . sprintf(gettext('Auto Backup last ran %s.'), date('Y-m-d H:i:s', $d)) . '</p>');
}
return $options;
}
function handleOption($option, $currentValue) {
}
static function timer_handler($discard) {
$curdir = getcwd();
$folder = SERVERPATH . "/" . BACKUPFOLDER;
if (!is_dir($folder)) {
mkdir($folder, FOLDER_MOD);
}
chdir($folder);
$filelist = safe_glob('*' . '.zdb');
$list = array();
foreach ($filelist as $file) {
$list[$file] = filemtime($file);
}
chdir($curdir);
asort($list);
$list = array_flip($list);
$keep = getOption('backups_to_keep');
while (count($list) >= $keep) {
$file = array_shift($list);
@chmod(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file, 0777);
unlink(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file);
}
cron_starter(SERVERPATH . '/' . ZENFOLDER . '/' . UTILITIES_FOLDER . '/backup_restore.php', array('backup' => 1, 'autobackup' => 1, 'compress' => sprintf('%u', getOption('backup_compression')), 'XSRFTag' => 'backup'), 3
);
return $discard;
}
}
?>