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 1684 2012-05-05 07:17:09Z Luisehahne $
|
13
|
* @filesource $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/droplets/backup_droplets.php $
|
14
|
* @lastmodified $Date: 2012-05-05 09:17:09 +0200 (Sat, 05 May 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
|
<h4 style="margin: 0; border-bottom: 1px solid #DDD; padding-bottom: 5px;">
|
39
|
<a href="<?php echo $admintool_link;?>" title="<?php echo $HEADING['ADMINISTRATION_TOOLS']; ?>"><?php echo $HEADING['ADMINISTRATION_TOOLS']; ?></a>
|
40
|
->
|
41
|
<a href="<?php echo $module_edit_link;?>" title="<?php echo $sOverviewDroplets ?>" alt="<?php echo $sOverviewDroplets ?>">Droplet Edit</a>
|
42
|
</h4>
|
43
|
<?php
|
44
|
|
45
|
$OK = ' <span style="color:#006400; font-weight:bold;">OK</span> ';
|
46
|
$FAIL = ' <span style="color:#ff0000; font-weight:bold;">FAILED</span> ';
|
47
|
$sBackupName = strftime('%Y%m%d_%H%M%S', time()+ TIMEZONE ).'_droplets.zip';
|
48
|
$temp_dir = '/temp/droplets/';
|
49
|
$temp_file = $temp_dir.$sBackupName;
|
50
|
|
51
|
if(is_writeable(dirname(WB_PATH.$temp_dir))) {
|
52
|
rm_full_dir ( WB_PATH.$temp_dir );
|
53
|
}
|
54
|
|
55
|
/*
|
56
|
// make the temporary working directory
|
57
|
if(!make_dir(WB_PATH.$temp_dir, octdec('0777') )){
|
58
|
// $admin->print_error($MESSAGE['MEDIA_DIR_NOT_MADE'], $module_edit_link);
|
59
|
}
|
60
|
*/
|
61
|
|
62
|
$msg = createFolderProtectFile(rtrim( WB_PATH.$temp_dir,'/') );
|
63
|
if(sizeof($msg)) {
|
64
|
print '<h4 class="warning">';
|
65
|
echo implode('<br />',$msg).'<br />'.$MESSAGE['MEDIA_DIR_NOT_MADE'].'<br />';
|
66
|
print '</h4>';
|
67
|
}
|
68
|
|
69
|
$sFilesToZip = '';
|
70
|
$sql = 'SELECT * FROM `'.TABLE_PREFIX.'mod_droplets` ';
|
71
|
$sql .= 'ORDER BY `modified_when` DESC';
|
72
|
|
73
|
$query_droplets = $database->query($sql);
|
74
|
while($droplet = $query_droplets->fetchRow()) {
|
75
|
echo 'Saving: /temp/droplets/'.$droplet["name"].'.php';
|
76
|
$sFile = $droplet["name"].'.php';
|
77
|
if($fh = fopen(WB_PATH.$temp_dir.$sFile, 'w'))
|
78
|
{
|
79
|
fwrite($fh, '//:'.$droplet['description']."\n");
|
80
|
fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
|
81
|
fwrite($fh, $droplet['code']);
|
82
|
fclose($fh);
|
83
|
echo " $OK<br />";
|
84
|
} else {
|
85
|
echo " $FAIL<br />"; }
|
86
|
$sFilesToZip .= WB_PATH.$temp_dir.$sFile.',';
|
87
|
}
|
88
|
|
89
|
$sFilesToZip = rtrim($sFilesToZip,',');
|
90
|
|
91
|
echo '<br />Create archive: <strong>'.$sBackupName.'</strong><br />';
|
92
|
|
93
|
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
94
|
$archive = new PclZip(WB_PATH.$temp_file);
|
95
|
|
96
|
$file_list = $archive->create($sFilesToZip , PCLZIP_OPT_ADD_PATH, WB_PATH.$temp_dir );
|
97
|
if ($file_list == 0){
|
98
|
echo "Packaging error: '.$archive->errorInfo(true).'";
|
99
|
die("Error : ".$archive->errorInfo(true));
|
100
|
}
|
101
|
elseif(is_readable(WB_PATH.$temp_file)) {
|
102
|
echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
|
103
|
}
|
104
|
else {
|
105
|
echo '<br /><br />Backup not created - <a href="'.$module_edit_link.'">'.$TEXT['BACK'].'</a>';
|
106
|
}
|
107
|
|
108
|
$admin->print_footer();
|