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       2009-2012, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: backup_droplets.php 1676 2012-04-24 09:16:23Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/backup_droplets.php $
15
 * @lastmodified    $Date: 2012-04-24 11:16:23 +0200 (Tue, 24 Apr 2012) $
16
 *
17
 */
18

    
19
// tool_edit.php
20
require_once('../../config.php');
21
require_once(WB_PATH.'/framework/class.admin.php');
22

    
23
require_once(WB_PATH.'/framework/functions.php');
24
// create admin object depending on platform (admin tools were moved out of settings with WB 2.7)
25
$admin = new admin('admintools', 'admintools');
26
$admintool_link = ADMIN_URL .'/admintools/index.php';
27
$module_edit_link = ADMIN_URL .'/admintools/tool.php?tool=droplets';
28
$sOverviewDroplets = $TEXT['LIST_OPTIONS'];
29

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

    
36
?>
37
<h4 style="margin: 0; border-bottom: 1px solid #DDD; padding-bottom: 5px;">
38
	<a href="<?php echo $admintool_link;?>" title="<?php echo $HEADING['ADMINISTRATION_TOOLS']; ?>"><?php echo $HEADING['ADMINISTRATION_TOOLS']; ?></a>
39
	->
40
	<a href="<?php echo $module_edit_link;?>" title="<?php echo $sOverviewDroplets ?>" alt="<?php echo $sOverviewDroplets ?>">Droplet Edit</a>
41
</h4>
42
<?php
43

    
44
$OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
45
$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
46

    
47
$temp_dir = '/temp/droplets/';
48
$temp_file = $temp_dir.'backup-droplets.zip';
49

    
50
if(is_writeable(dirname(WB_PATH.$temp_dir))) {
51
 	rm_full_dir ( WB_PATH.$temp_dir );
52
}
53

    
54
$msg = createFolderProtectFile(rtrim( WB_PATH.$temp_dir,'/') );
55
if(sizeof($msg)) {
56
	print '<h4 class="warning">';
57
	echo implode('<br />',$msg).'<br />'.$MESSAGE['MEDIA_DIR_NOT_MADE'].'<br />';
58
	print '</h4>';
59
}
60

    
61
	$sFilesToZip = '';
62
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets`  ';
63
	$sql .= 'ORDER BY `modified_when` DESC';
64

    
65
	$query_droplets = $database->query($sql);
66
	while($droplet = $query_droplets->fetchRow()) {
67
		echo 'Saving: /temp/droplets/'.$droplet["name"].'.php';
68
		$sFile = $droplet["name"].'.php';
69
		if($fh = fopen(WB_PATH.$temp_dir.$sFile, 'w'))
70
		{
71
			fwrite($fh, '//:'.$droplet['description']."\n");
72
			fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
73
			fwrite($fh, $droplet['code']);
74
			fclose($fh);
75
			echo " $OK<br />";
76
		} else {
77
			echo " $FAIL<br />";		}
78
	$sFilesToZip .= WB_PATH.$temp_dir.$sFile.',';
79
	}
80

    
81
$sFilesToZip = rtrim($sFilesToZip,',');
82

    
83
echo '<br />Create archive: backup-droplets.zip<br />';
84

    
85
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
86
$archive = new PclZip(WB_PATH.$temp_file);
87

    
88
$file_list = $archive->create($sFilesToZip , PCLZIP_OPT_ADD_PATH, WB_PATH.$temp_dir );
89
if ($file_list == 0){
90
	echo "Packaging error: '.$archive->errorInfo(true).'";
91
	die("Error : ".$archive->errorInfo(true));
92
}
93
elseif(is_readable(WB_PATH.$temp_file)) {
94
	echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
95
}
96
else {
97
	echo '<br /><br />Backup not created - <a href="'.$module_edit_link.'">'.$TEXT['BACK'].'</a>';
98
}
99

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