forked from symphonycms/export_ensemble
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.driver.php
More file actions
executable file
·223 lines (171 loc) · 6.85 KB
/
extension.driver.php
File metadata and controls
executable file
·223 lines (171 loc) · 6.85 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
Class extension_export_ensemble extends Extension{
public function about(){
return array('name' => 'Export Ensemble',
'version' => '1.11',
'release-date' => '2010-02-12',
'author' => array('name' => 'Alistair Kearney',
'website' => 'http://pointybeard.com',
'email' => 'alistair@pointybeard.com')
);
}
public function getSubscribedDelegates(){
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'appendPreferences'
),
);
}
public function install(){
if(!class_exists('ZipArchive')){
Administration::instance()->Page->pageAlert(__('Export Ensemble cannot be installed, since the "<a href="http://php.net/manual/en/book.zip.php">ZipArchive</a>" class is not available. Ensure that PHP was compiled with the <code>--enable-zip</code> flag.'), AdministrationPage::PAGE_ALERT_ERROR);
return false;
}
return true;
}
private function __addFolderToArchive(&$archive, $path, $parent=NULL){
$iterator = new DirectoryIterator($path);
foreach($iterator as $file){
if($file->isDot() || preg_match('/^\./', $file->getFilename())) continue;
elseif($file->isDir()){
$this->__addFolderToArchive($archive, $file->getPathname(), $parent);
}
else $archive->addFile($file->getPathname(), ltrim(str_replace($parent, NULL, $file->getPathname()), '/'));
}
}
private function __export(){
$sql_schema = $sql_data = NULL;
require_once(dirname(__FILE__) . '/lib/class.mysqldump.php');
$dump = new MySQLDump(Symphony::Database());
$tables = array(
'tbl_authors',
'tbl_cache',
'tbl_entries',
'tbl_extensions',
'tbl_extensions_delegates',
'tbl_fields',
'tbl_fields_%',
'tbl_forgotpass',
'tbl_pages',
'tbl_pages_types',
'tbl_sections',
'tbl_sections_association'
);
## Grab the schema
foreach($tables as $t) $sql_schema .= $dump->export($t, MySQLDump::STRUCTURE_ONLY);
$sql_schema = str_replace('`' . Administration::instance()->Configuration->get('tbl_prefix', 'database'), '`tbl_', $sql_schema);
$sql_schema = preg_replace('/AUTO_INCREMENT=\d+/i', NULL, $sql_schema);
$tables = array(
'tbl_entries',
'tbl_extensions',
'tbl_extensions_delegates',
'tbl_fields',
'tbl_pages',
'tbl_pages_types',
'tbl_sections',
'tbl_sections_association'
);
## Field data and entry data schemas needs to be apart of the workspace sql dump
$sql_data = $dump->export('tbl_fields_%', MySQLDump::ALL);
$sql_data .= $dump->export('tbl_entries_%', MySQLDump::ALL);
## Grab the data
foreach($tables as $t){
$sql_data .= $dump->export($t, MySQLDump::DATA_ONLY);
}
$sql_data = str_replace('`' . Administration::instance()->Configuration->get('tbl_prefix', 'database'), '`tbl_', $sql_data);
$config_string = NULL;
$config = Administration::instance()->Configuration->get();
unset($config['symphony']['build']);
unset($config['symphony']['cookie_prefix']);
unset($config['general']['useragent']);
unset($config['file']['write_mode']);
unset($config['directory']['write_mode']);
unset($config['database']['host']);
unset($config['database']['port']);
unset($config['database']['user']);
unset($config['database']['password']);
unset($config['database']['db']);
unset($config['database']['tbl_prefix']);
unset($config['region']['timezone']);
foreach($config as $group => $set){
foreach($set as $key => $val){
$config_string .= " \$conf['{$group}']['{$key}'] = '{$val}';" . self::CRLF;
}
}
$install_template = str_replace(
array(
'<!-- BUILD -->',
'<!-- VERSION -->',
'<!-- CONFIGURATION -->'
),
array(
Administration::instance()->Configuration->get('build', 'symphony'),
Administration::instance()->Configuration->get('version', 'symphony'),
trim($config_string),
),
file_get_contents(dirname(__FILE__) . '/lib/installer.tpl')
);
$archive = new ZipArchive;
$res = $archive->open(TMP . '/ensemble.tmp.zip', ZipArchive::CREATE);
if ($res === TRUE) {
$this->__addFolderToArchive($archive, EXTENSIONS, DOCROOT);
$this->__addFolderToArchive($archive, SYMPHONY, DOCROOT);
$this->__addFolderToArchive($archive, WORKSPACE, DOCROOT);
$archive->addFromString('install.php', $install_template);
$archive->addFromString('install.sql', $sql_schema);
$archive->addFromString('workspace/install.sql', $sql_data);
$archive->addFile(DOCROOT . '/index.php', 'index.php');
$readme_files = glob(DOCROOT . '/README.*');
if(is_array($readme_files) && !empty($readme_files)){
foreach($readme_files as $filename){
$archive->addFile($filename, basename($filename));
}
}
if(is_file(DOCROOT . '/README')) $archive->addFile(DOCROOT . '/README', 'README');
if(is_file(DOCROOT . '/LICENCE')) $archive->addFile(DOCROOT . '/LICENCE', 'LICENCE');
if(is_file(DOCROOT . '/update.php')) $archive->addFile(DOCROOT . '/update.php', 'update.php');
}
$archive->close();
header('Content-type: application/octet-stream');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header(
sprintf(
'Content-disposition: attachment; filename=%s-ensemble.zip',
Lang::createFilename(
Administration::instance()->Configuration->get('sitename', 'general')
)
)
);
header('Pragma: no-cache');
readfile(TMP . '/ensemble.tmp.zip');
unlink(TMP . '/ensemble.tmp.zip');
exit();
}
public function __SavePreferences($context){
$this->__export();
}
public function appendPreferences($context){
if(isset($_POST['action']['export'])){
$this->__SavePreferences($context);
}
$group = new XMLElement('fieldset');
$group->setAttribute('class', 'settings');
$group->appendChild(new XMLElement('legend', __('Export Ensemble')));
$div = new XMLElement('div', NULL, array('id' => 'file-actions', 'class' => 'label'));
$span = new XMLElement('span');
if(!class_exists('ZipArchive')){
$span->appendChild(
new XMLElement('p', '<strong>' . __('Warning: It appears you do not have the "ZipArchive" class available. Ensure that PHP was compiled with <code>--enable-zip</code>') . '<strong>')
);
}
else{
$span->appendChild(new XMLElement('button', __('Create'), array('name' => 'action[export]', 'type' => 'submit')));
}
$div->appendChild($span);
$div->appendChild(new XMLElement('p', __('Packages entire site as a <code>.zip</code> archive for download.'), array('class' => 'help')));
$group->appendChild($div);
$context['wrapper']->appendChild($group);
}
}