Revision 1457
Added by Dietmar almost 13 years ago
backup_droplets.php | ||
---|---|---|
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$
|
|
15 |
* @filesource $HeadURL$
|
|
16 |
* @lastmodified $Date$
|
|
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 |
|
|
31 |
// protect from CSRF
|
|
32 |
$id = $admin->checkIDKEY('id', false, 'GET');
|
|
33 |
if (!$id or $id != 999) {
|
|
34 |
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL);
|
|
35 |
exit();
|
|
36 |
}
|
|
37 |
|
|
38 |
?>
|
|
39 |
<h4 style="margin: 0; border-bottom: 1px solid #DDD; padding-bottom: 5px;">
|
|
40 |
<a href="<?php echo $admintool_link;?>"><?php echo $HEADING['ADMINISTRATION_TOOLS']; ?></a>
|
|
41 |
->
|
|
42 |
<a href="<?php echo $module_edit_link;?>">Droplets</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 |
$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets ORDER BY modified_when DESC");
|
|
51 |
while($droplet = $query_droplets->fetchRow()) {
|
|
52 |
echo 'Saving: '.$droplet["name"].'.php<br />';
|
|
53 |
$sFile = $temp_dir.$droplet["name"].'.php';
|
|
54 |
$fh = fopen($sFile, 'w') ;
|
|
55 |
fwrite($fh, '//:'.$droplet['description']."\n");
|
|
56 |
fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n");
|
|
57 |
fwrite($fh, $droplet['code']);
|
|
58 |
fclose($fh);
|
|
59 |
}
|
|
60 |
echo '<br />Create archive: backup-droplets.zip<br />';
|
|
61 |
|
|
62 |
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');
|
|
63 |
$archive = new PclZip(WB_PATH.$temp_file);
|
|
64 |
$file_list = $archive->create($temp_dir, PCLZIP_OPT_REMOVE_ALL_PATH);
|
|
65 |
if ($file_list == 0){
|
|
66 |
echo "Packaging error: '.$archive->errorInfo(true).'";
|
|
67 |
die("Error : ".$archive->errorInfo(true));
|
|
68 |
}
|
|
69 |
else {
|
|
70 |
echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>';
|
|
71 |
}
|
|
72 |
delete_directory ( $temp_dir );
|
|
73 |
$admin->print_footer();
|
|
74 |
|
|
75 |
|
|
76 |
function delete_directory($dirname) {
|
|
77 |
if (is_dir($dirname))
|
|
78 |
$dir_handle = opendir($dirname);
|
|
79 |
if (!$dir_handle)
|
|
80 |
return false;
|
|
81 |
while($file = readdir($dir_handle)) {
|
|
82 |
if ($file != "." && $file != "..") {
|
|
83 |
if (!is_dir($dirname."/".$file))
|
|
84 |
unlink($dirname."/".$file);
|
|
85 |
else
|
|
86 |
delete_directory($dirname.'/'.$file);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
closedir($dir_handle);
|
|
90 |
rmdir($dirname);
|
|
91 |
return true;
|
|
92 |
}
|
|
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$ |
|
15 |
* @filesource $HeadURL$ |
|
16 |
* @lastmodified $Date$ |
|
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 |
|
|
31 |
// protect from CSRF |
|
32 |
$id = $admin->checkIDKEY('id', false, 'GET'); |
|
33 |
if (!$id or $id != 999) { |
|
34 |
$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL); |
|
35 |
exit(); |
|
36 |
} |
|
37 |
|
|
38 |
?> |
|
39 |
<h4 style="margin: 0; border-bottom: 1px solid #DDD; padding-bottom: 5px;"> |
|
40 |
<a href="<?php echo $admintool_link;?>"><?php echo $HEADING['ADMINISTRATION_TOOLS']; ?></a> |
|
41 |
-> |
|
42 |
<a href="<?php echo $module_edit_link;?>">Droplets</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 |
$query_droplets = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_droplets ORDER BY modified_when DESC"); |
|
51 |
while($droplet = $query_droplets->fetchRow()) { |
|
52 |
echo 'Saving: '.$droplet["name"].'.php<br />'; |
|
53 |
$sFile = $temp_dir.$droplet["name"].'.php'; |
|
54 |
$fh = fopen($sFile, 'w') ; |
|
55 |
fwrite($fh, '//:'.$droplet['description']."\n"); |
|
56 |
fwrite($fh, '//:'.str_replace("\n"," ",$droplet['comments'])."\n"); |
|
57 |
fwrite($fh, $droplet['code']); |
|
58 |
fclose($fh); |
|
59 |
} |
|
60 |
echo '<br />Create archive: backup-droplets.zip<br />'; |
|
61 |
|
|
62 |
require_once(WB_PATH.'/include/pclzip/pclzip.lib.php'); |
|
63 |
$archive = new PclZip(WB_PATH.$temp_file); |
|
64 |
$file_list = $archive->create($temp_dir, PCLZIP_OPT_REMOVE_ALL_PATH); |
|
65 |
if ($file_list == 0){ |
|
66 |
echo "Packaging error: '.$archive->errorInfo(true).'"; |
|
67 |
die("Error : ".$archive->errorInfo(true)); |
|
68 |
} |
|
69 |
else { |
|
70 |
echo '<br /><br />Backup created - <a href="'.WB_URL.$temp_file.'">Download</a>'; |
|
71 |
} |
|
72 |
delete_directory ( $temp_dir ); |
|
73 |
$admin->print_footer(); |
|
74 |
|
|
75 |
|
|
76 |
function delete_directory($dirname) { |
|
77 |
if (is_dir($dirname)) |
|
78 |
$dir_handle = opendir($dirname); |
|
79 |
if (!$dir_handle) |
|
80 |
return false; |
|
81 |
while($file = readdir($dir_handle)) { |
|
82 |
if ($file != "." && $file != "..") { |
|
83 |
if (!is_dir($dirname."/".$file)) |
|
84 |
unlink($dirname."/".$file); |
|
85 |
else |
|
86 |
delete_directory($dirname.'/'.$file); |
|
87 |
} |
|
88 |
} |
|
89 |
closedir($dir_handle); |
|
90 |
rmdir($dirname); |
|
91 |
return true; |
|
92 |
} |
|
93 | 93 |
?> |
94 | 94 |
Also available in: Unified diff
Preparing 2.8.2 stable, last tests