Project

General

Profile

1 989 aldus
<?php
2 991 Ruebenwurz
3
// $Id$
4
5 989 aldus
/*
6
*	@version	1.0
7
*	@author		Ruud Eisinga (Ruud) John (PCWacht)
8
*	@date		June 2009
9
*
10
*/
11
12
// tool_edit.php
13
require_once('../../config.php');
14
require_once(WB_PATH.'/framework/class.admin.php');
15
require_once(WB_PATH.'/framework/functions.php');
16
// create admin object depending on platform (admin tools were moved out of settings with WB 2.7)
17
$admin = new admin('admintools', 'admintools');
18
$admintool_link = ADMIN_URL .'/admintools/index.php';
19
$module_edit_link = ADMIN_URL .'/admintools/tool.php?tool=droplets';
20
$template_edit_link = ADMIN_URL .'/admintools/tool.php?tool=templateedit';
21
22
23
?>
24
<h4 style="margin: 0; border-bottom: 1px solid #DDD; padding-bottom: 5px;">
25
	<a href="<?php echo $admintool_link;?>"><?php echo $HEADING['ADMINISTRATION_TOOLS']; ?></a>
26
	->
27
	<a href="<?php echo $module_edit_link;?>">Droplets</a>
28
</h4>
29
<?php
30
31
$temp_dir = WB_PATH.'/temp/droplets/';
32
$temp_file = '/modules/droplets/backup-droplets.zip';
33
// make the temporary working directory
34
mkdir($temp_dir);
35
$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets ORDER BY modified_when DESC");
36
while($droplet = $query_droplets->fetchRow()) {
37
	echo 'Saving: '.$droplet["name"].'.php<br />';
38
	$sFile = $temp_dir.$droplet["name"].'.php';
39
	$fh = fopen($sFile, 'w') ;
40
	fwrite($fh, '//:'.$droplet['description']."\n");
41
	fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
42
	fwrite($fh, $droplet['code']);
43
	fclose($fh);
44
}
45
echo '<br />Create archive: backup-droplets.zip<br />';
46
47
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
48
$archive = new PclZip(WB_PATH.$temp_file);
49
$file_list = $archive->create($temp_dir, PCLZIP_OPT_REMOVE_ALL_PATH);
50
if ($file_list == 0){
51
	echo "Packaging error: '.$archive->errorInfo(true).'";
52
	die("Error : ".$archive->errorInfo(true));
53
}
54
else {
55
	echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
56
}
57
delete_directory ( $temp_dir );
58
$admin->print_footer();
59
60
61
function delete_directory($dirname) {
62
    if (is_dir($dirname))
63
        $dir_handle = opendir($dirname);
64
    if (!$dir_handle)
65
        return false;
66
    while($file = readdir($dir_handle)) {
67
        if ($file != "." && $file != "..") {
68
            if (!is_dir($dirname."/".$file))
69
                unlink($dirname."/".$file);
70
            else
71
                delete_directory($dirname.'/'.$file);
72
        }
73
    }
74
    closedir($dir_handle);
75
    rmdir($dirname);
76
    return true;
77
}
78
?>