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