-
Notifications
You must be signed in to change notification settings - Fork 0
/
_download_sites.php
134 lines (113 loc) · 4.31 KB
/
_download_sites.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
$file = 'http://sandbox.fusbfg.de/sites.zip';
if (file_put_contents("sites.zip", file_get_contents($file)) ) {
echo 'File "'.$file.'" geladen.<br/>';
unzip("sites.zip");
if ( createsites() ) {
if (file_exists("drupal/sites/default/settings.php")) {
echo '<br/><br/>Deleting "sites/default/settings.php"<br/>';
unlink("drupal/sites/default/settings.php");
}
if (file_exists("drupal/sites/default/default.settings.php")) {
$file = 'drupal/sites/default/default.settings.php';
$newfile = 'drupal/sites/default/settings.php';
if (!copy($file, $newfile)) {
echo '<br/>Failed to copy <em>'.$file.'</em>';
} else {
print 'Copied <em>'.$file.'</em><br/>';
}
}
removetxt();
}
unlink("sites.zip");
print '<br/>Next Step: <b><a href="_helper.php#installdrupal">_helper.php</a></b>';
} else {
echo 'Herunterladen von "'.$file.'" fehlgeschlagen.<br/>';
}
function unzip($file){
$zip = zip_open($file);
if ($zip) {echo "Open zip file\n"; } else{
echo "Unable to open zip file\n";
}
if(is_resource($zip)){
echo "<br>ZIP is_resource<br>\n";
$tree = "";
while(($zip_entry = zip_read($zip)) !== false){
if(strpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR) !== false){
$last = strrpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR);
$dir = substr(zip_entry_name($zip_entry), 0, $last);
$file = substr(zip_entry_name($zip_entry), strrpos(zip_entry_name($zip_entry), DIRECTORY_SEPARATOR)+1);
if(!is_dir($dir)){
@mkdir($dir, 0755, true) or die("Unable to create $dir\n");
}
if(strlen(trim($file)) > 0){
$return = @file_put_contents($dir."/".$file, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)));
if($return === false){
die("Unable to write file $dir/$file\n");
}
}
}else{
if (file_put_contents($file, zip_entry_read($zip_entry, zip_entry_filesize($zip_entry))) ) {
echo "Sites entpacken\n";
} else {
echo "Entpacken fehlgeschlagen\n";
}
}
}
}
}
function createsites() {
if (!is_dir('sites')) {
echo '<br><br>Folder <i>sites</i> does not exist.<br>';
if (mkdir('sites', 0777, true) ) {
echo 'Create folder <i>sites</i><br>';
if ( rename("all",'sites/all') && rename("default",'sites/default') ) {
echo 'Folders <i>all</i> and <i>default</i> moved into folder <i>sites</i>';
movesites();
}
} else {
echo 'Could not create folder <i>sites</i><br>';
return FALSE;
}
} else {
echo 'Folder <i>sites</i> already exists.<br>';
return FALSE;
}
return TRUE;
}
function movesites() {
print '<br/>Trying to move folder <em>sites</em> into folder <em>drupal</em> ... <br/>';
$dir = 'drupal' . DIRECTORY_SEPARATOR . 'sites';
if (is_dir($dir)) {
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->isDir()){
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
if (!rmdir($dir)) {
echo '<br/>Could not unlink "drupal/sites"<br/>';
} else {
echo '<br/>Remove old "drupal/sites"<br/>';
if ( rename("sites",'drupal/sites') ) {
echo 'Folders <i>all</i> and <i>default</i> moved into folder <i>sites</i>';
} else {
echo 'Could not move';
}
}
} else {
print 'Did not succeed. Please rename folder <em>drupal-xxx</em> to <em>drupal</em> and move folder <em>sites</em> in it.<br/>';
}
}
function removetxt() {
foreach (glob("drupal/*.txt") as $filename) {
if ($filename != 'drupal/robots.txt') {
echo 'Remove <em>'.$filename . '</em><br/>';
unlink($filename);
}
}
}