Project

General

Profile

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 1503 2011-08-18 02:18:59Z Luisehahne $
15
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/backup_droplets.php $
16
 * @lastmodified    $Date: 2011-08-18 04:18:59 +0200 (Thu, 18 Aug 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
$sOverviewDroplets = $TEXT['LIST_OPTIONS'];
31

    
32
// protect from CSRF
33
$id = intval($admin->checkIDKEY('id', false, 'GET'));
34
if (!$id or $id != 999) {
35
 $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $module_edit_link);
36
}
37

    
38
?>
39
<h4 style="margin: 0; border-bottom: 1px solid #DDD; padding-bottom: 5px;">
40
	<a href="<?php echo $admintool_link;?>" title="<?php echo $HEADING['ADMINISTRATION_TOOLS']; ?>"><?php echo $HEADING['ADMINISTRATION_TOOLS']; ?></a>
41
	->
42
	<a href="<?php echo $module_edit_link;?>" title="<?php echo $sOverviewDroplets ?>" alt="<?php echo $sOverviewDroplets ?>">Droplet Edit</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
$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets`  ';
51
$sql .= 'ORDER BY `modified_when` DESC';
52
$query_droplets = $database->query($sql);
53
while($droplet = $query_droplets->fetchRow()) {
54
	echo 'Saving: '.$droplet["name"].'.php<br />';
55
	$sFile = $temp_dir.$droplet["name"].'.php';
56
	$fh = fopen($sFile, 'w') ;
57
	fwrite($fh, '//:'.$droplet['description']."\n");
58
	fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
59
	fwrite($fh, $droplet['code']);
60
	fclose($fh);
61
}
62
echo '<br />Create archive: backup-droplets.zip<br />';
63

    
64
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
65
$archive = new PclZip(WB_PATH.$temp_file);
66
$file_list = $archive->create($temp_dir, PCLZIP_OPT_REMOVE_ALL_PATH);
67
if ($file_list == 0){
68
	echo "Packaging error: '.$archive->errorInfo(true).'";
69
	die("Error : ".$archive->errorInfo(true));
70
}
71
else {
72
	echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
73
}
74

    
75
delete_directory ( $temp_dir );
76

    
77
function delete_directory($dirname) {
78
    if (is_dir($dirname))
79
        $dir_handle = opendir($dirname);
80
    if (!$dir_handle)
81
        return false;
82
    while($file = readdir($dir_handle)) {
83
        if ($file != "." && $file != "..") {
84
            if (!is_dir($dirname."/".$file))
85
                unlink($dirname."/".$file);
86
            else
87
                delete_directory($dirname.'/'.$file);          
88
        }
89
    }
90
    closedir($dir_handle);
91
    rmdir($dirname);
92
    return true;
93
}
94

    
95
$admin->print_footer();
(4-4/14)