Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        module
5
 * @package         droplet
6
 * @author          Ruud Eisinga (Ruud) John (PCWacht), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8
 * @link			http://www.websitebaker.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: backup_droplets.php 1741 2012-09-07 00:42:30Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/backup_droplets.php $
14
 * @lastmodified    $Date: 2012-09-07 02:42:30 +0200 (Fri, 07 Sep 2012) $
15
 *
16
 */
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
$sOverviewDroplets = $TEXT['LIST_OPTIONS'];
30

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

    
37
?>
38
<div class="droplets" style="margin-top: 6px;">
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
	<span> &raquo; </span>
42
	<a href="<?php echo $module_edit_link;?>" title="<?php echo $sOverviewDroplets ?>" alt="<?php echo $sOverviewDroplets ?>">Droplet Overview</a>
43
</h4>
44
<?php
45

    
46
$OK  = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
47
$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
48
$sBackupName = strftime('%Y%m%d_%H%M%S', time()+ TIMEZONE ).'_droplets.zip';
49
$temp_dir = '/temp/droplets/';
50
$temp_file = $temp_dir.$sBackupName;
51

    
52
if(is_writeable(dirname(WB_PATH.$temp_dir))) {
53
 	rm_full_dir ( WB_PATH.$temp_dir );
54
}
55

    
56
/*
57
// make the temporary working directory
58
if(!make_dir(WB_PATH.$temp_dir, octdec('0777') )){
59
//  $admin->print_error($MESSAGE['MEDIA_DIR_NOT_MADE'], $module_edit_link);
60
}
61
*/
62

    
63
$msg = createFolderProtectFile(rtrim( WB_PATH.$temp_dir,'/') );
64
if(sizeof($msg)) {
65
	print '<h4 class="warning">';
66
	echo implode('<br />',$msg).'<br />'.$MESSAGE['MEDIA_DIR_NOT_MADE'].'<br />';
67
	print '</h4>';
68
}
69

    
70
	$sFilesToZip = '';
71
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets`  ';
72
	$sql .= 'ORDER BY `modified_when` DESC';
73

    
74
	$query_droplets = $database->query($sql);
75
	while($droplet = $query_droplets->fetchRow()) {
76
		echo 'Saving: '.$droplet["name"].'.php';
77
		$sFile = $droplet["name"].'.php';
78
		if($fh = fopen(WB_PATH.$temp_dir.$sFile, 'w'))
79
		{
80
			fwrite($fh, '//:'.$droplet['description']."\n");
81
			fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
82
			fwrite($fh, $droplet['code']);
83
			fclose($fh);
84
			echo " $OK<br />";
85
		} else {
86
			echo " $FAIL<br />";		}
87
	$sFilesToZip .= WB_PATH.$temp_dir.$sFile.',';
88
	}
89

    
90
$sFilesToZip = rtrim($sFilesToZip,',');
91

    
92
echo '<br />Create archive: <strong>'.$sBackupName.'</strong><br />';
93

    
94
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
95
$archive = new PclZip(WB_PATH.$temp_file);
96

    
97
$file_list = $archive->create($sFilesToZip , PCLZIP_OPT_REMOVE_ALL_PATH );
98
if ($file_list == 0){
99
	echo "Packaging error: '.$archive->errorInfo(true).'";
100
	die("Error : ".$archive->errorInfo(true));
101
}
102
elseif(is_readable(WB_PATH.$temp_file)) {
103
	echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
104
}
105
else {
106
	echo '<br /><br />Backup not created - <a href="'.$module_edit_link.'">'.$TEXT['BACK'].'</a>';
107
}
108
echo '</div>';
109
$admin->print_footer();
(4-4/15)