1
|
<?php
|
2
|
/**
|
3
|
*
|
4
|
* @category module
|
5
|
* @package droplet
|
6
|
* @author Ruud Eisinga (Ruud) John (PCWacht)
|
7
|
* @author WebsiteBaker Project
|
8
|
* @copyright 2004-2009, Ryan Djurovich
|
9
|
* @copyright 2009-2011, Website Baker Org. e.V.
|
10
|
* @link http://www.websitebaker2.org/
|
11
|
* @license http://www.gnu.org/licenses/gpl.html
|
12
|
* @platform WebsiteBaker 2.8.x
|
13
|
* @requirements PHP 5.2.2 and higher
|
14
|
* @version $Id: backup_droplets.php 1473 2011-07-09 00:40:50Z Luisehahne $
|
15
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/tags/2.8.2/wb/modules/droplets/backup_droplets.php $
|
16
|
* @lastmodified $Date: 2011-07-09 02:40:50 +0200 (Sat, 09 Jul 2011) $
|
17
|
*
|
18
|
*/
|
19
|
|
20
|
// tool_edit.php
|
21
|
require_once('../../config.php');
|
22
|
require_once(WB_PATH.'/framework/class.admin.php');
|
23
|
|
24
|
require_once(WB_PATH.'/framework/functions.php');
|
25
|
// create admin object depending on platform (admin tools were moved out of settings with WB 2.7)
|
26
|
$admin = new admin('admintools', 'admintools');
|
27
|
$admintool_link = ADMIN_URL .'/admintools/index.php';
|
28
|
$module_edit_link = ADMIN_URL .'/admintools/tool.php?tool=droplets';
|
29
|
$template_edit_link = ADMIN_URL .'/admintools/tool.php?tool=templateedit';
|
30
|
|
31
|
// protect from CSRF
|
32
|
$id = $admin->checkIDKEY('id', false, 'GET');
|
33
|
if (!$id or $id != 999) {
|
34
|
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $module_edit_link);
|
35
|
exit();
|
36
|
}
|
37
|
|
38
|
?>
|
39
|
<h4 style="margin: 0; border-bottom: 1px solid #DDD; padding-bottom: 5px;">
|
40
|
<a href="<?php echo $admintool_link;?>"><?php echo $HEADING['ADMINISTRATION_TOOLS']; ?></a>
|
41
|
->
|
42
|
<a href="<?php echo $module_edit_link;?>">Droplets</a>
|
43
|
</h4>
|
44
|
<?php
|
45
|
|
46
|
$temp_dir = WB_PATH.'/temp/droplets/';
|
47
|
$temp_file = '/modules/droplets/backup-droplets.zip';
|
48
|
// make the temporary working directory
|
49
|
mkdir($temp_dir);
|
50
|
$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets ORDER BY modified_when DESC");
|
51
|
while($droplet = $query_droplets->fetchRow()) {
|
52
|
echo 'Saving: '.$droplet["name"].'.php<br />';
|
53
|
$sFile = $temp_dir.$droplet["name"].'.php';
|
54
|
$fh = fopen($sFile, 'w') ;
|
55
|
fwrite($fh, '//:'.$droplet['description']."\n");
|
56
|
fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
|
57
|
fwrite($fh, $droplet['code']);
|
58
|
fclose($fh);
|
59
|
}
|
60
|
echo '<br />Create archive: backup-droplets.zip<br />';
|
61
|
|
62
|
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
63
|
$archive = new PclZip(WB_PATH.$temp_file);
|
64
|
$file_list = $archive->create($temp_dir, PCLZIP_OPT_REMOVE_ALL_PATH);
|
65
|
if ($file_list == 0){
|
66
|
echo "Packaging error: '.$archive->errorInfo(true).'";
|
67
|
die("Error : ".$archive->errorInfo(true));
|
68
|
}
|
69
|
else {
|
70
|
echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
|
71
|
}
|
72
|
delete_directory ( $temp_dir );
|
73
|
$admin->print_footer();
|
74
|
|
75
|
function delete_directory($dirname) {
|
76
|
if (is_dir($dirname))
|
77
|
$dir_handle = opendir($dirname);
|
78
|
if (!$dir_handle)
|
79
|
return false;
|
80
|
while($file = readdir($dir_handle)) {
|
81
|
if ($file != "." && $file != "..") {
|
82
|
if (!is_dir($dirname."/".$file))
|
83
|
unlink($dirname."/".$file);
|
84
|
else
|
85
|
delete_directory($dirname.'/'.$file);
|
86
|
}
|
87
|
}
|
88
|
closedir($dir_handle);
|
89
|
rmdir($dirname);
|
90
|
return true;
|
91
|
}
|