|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* EVO Cli Installer |
|
4
|
|
|
* php cli-install.php --database_server=localhost --database=db --database_user=dbuser --database_password=dbpass --table_prefix=evo_ --cmsadmin=admin [email protected] --cmspassword=123456 --language=ru --mode=new --installData=n --removeInstall=y |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
$self = 'install/cli-install.php'; |
|
8
|
|
|
$path = dirname(__FILE__) . '/'; |
|
9
|
|
|
$base_path = str_replace($self,'',str_replace('\\','/', __FILE__)); |
|
10
|
|
|
define('MODX_API_MODE', true); |
|
11
|
|
|
define('MODX_BASE_PATH', $base_path); |
|
12
|
|
|
define('MODX_SITE_URL', '/'); |
|
13
|
|
|
|
|
14
|
|
|
require_once($path."functions.php"); |
|
15
|
|
|
|
|
16
|
|
|
// set error reporting |
|
17
|
|
|
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED); |
|
18
|
|
|
|
|
19
|
|
|
if (is_file($base_path."assets/cache/siteManager.php")) { |
|
20
|
|
|
include_once($base_path."assets/cache/siteManager.php"); |
|
21
|
|
|
} |
|
22
|
|
|
if(!defined('MGR_DIR') && is_dir($base_path."manager")) { |
|
23
|
|
|
define('MGR_DIR', 'manager'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
require_once($path."lang.php"); |
|
27
|
|
|
require_once($base_path.MGR_DIR.'/includes/version.inc.php'); |
|
28
|
|
|
|
|
29
|
|
|
$moduleName = "EVO"; |
|
30
|
|
|
$moduleVersion = $modx_branch.' '.$modx_version; |
|
31
|
|
|
$moduleRelease = $modx_release_date; |
|
32
|
|
|
$moduleSQLBaseFile = $path."setup.sql"; |
|
33
|
|
|
$moduleSQLDataFile = $path."setup.data.sql"; |
|
34
|
|
|
$moduleSQLResetFile = $path."setup.data.reset.sql"; |
|
35
|
|
|
|
|
36
|
|
|
$moduleChunks = array (); // chunks - array : name, description, type - 0:file or 1:content, file or content |
|
37
|
|
|
$moduleTemplates = array (); // templates - array : name, description, type - 0:file or 1:content, file or content |
|
38
|
|
|
$moduleSnippets = array (); // snippets - array : name, description, type - 0:file or 1:content, file or content,properties |
|
39
|
|
|
$modulePlugins = array (); // plugins - array : name, description, type - 0:file or 1:content, file or content,properties, events,guid |
|
40
|
|
|
$moduleModules = array (); // modules - array : name, description, type - 0:file or 1:content, file or content,properties, guid |
|
41
|
|
|
$moduleTemplates = array (); // templates - array : name, description, type - 0:file or 1:content, file or content,properties |
|
42
|
|
|
$moduleTVs = array (); // template variables - array : name, description, type - 0:file or 1:content, file or content,properties |
|
43
|
|
|
$moduleDependencies = array(); // module depedencies - array : module, table, column, type, name |
|
44
|
|
|
$errors= 0; |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
$installMode= 0; |
|
48
|
|
|
$installData = 0; |
|
49
|
|
|
$tableprefixauto = base_convert(rand(10, 20), 10, 36).substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyz'), rand(0, 33), 3).'_'; |
|
50
|
|
|
|
|
51
|
|
|
$args = array_slice($argv, 1); |
|
52
|
|
|
|
|
53
|
|
|
if ( empty($args) ){ |
|
54
|
|
|
echo 'Install Evolution CMS'.PHP_EOL; |
|
55
|
|
|
//$installYes = readline("Type 'y' to continue: "); |
|
56
|
|
|
//if ($installYes != 'y') return; |
|
57
|
|
|
|
|
58
|
|
|
//set param manual |
|
59
|
|
|
$databasehost = readline($_lang['connection_screen_database_host']. ' [localhost] '); |
|
60
|
|
|
$databaseloginname = readline($_lang['connection_screen_database_login']. ' '); |
|
61
|
|
|
$databaseloginpassword = readline($_lang['connection_screen_database_pass']. ' '); |
|
62
|
|
|
$database_name = readline($_lang['connection_screen_database_name']. ' '); |
|
63
|
|
|
$tableprefix = readline($_lang['connection_screen_table_prefix']. ' ['.$tableprefixauto.'] '); |
|
64
|
|
|
$database_connection_method = readline($_lang['connection_screen_connection_method']. ' [SET CHARACTER SET] '); |
|
65
|
|
|
$database_collation = readline($_lang['connection_screen_collation']. ' [utf8_general_ci] '); |
|
66
|
|
|
$cmsadmin = readline($_lang['connection_screen_default_admin_login']. ' [admin] '); |
|
67
|
|
|
$cmsadminemail = readline($_lang['connection_screen_default_admin_email']. ' '); |
|
68
|
|
|
$cmspassword = readline($_lang['connection_screen_default_admin_password']. ' '); |
|
69
|
|
|
$managerlanguage = readline('Мanager language:' . ' [en] '); |
|
70
|
|
|
$installData = readline('Instal demo-site (y/n):' . ' [n] '); |
|
71
|
|
|
|
|
72
|
|
|
}else{ |
|
73
|
|
|
|
|
74
|
|
|
$cli_variables = []; |
|
75
|
|
|
foreach ($args as $arg) { |
|
76
|
|
|
$tmp = array_map('trim', explode('=', $arg)); |
|
77
|
|
|
if (count($tmp) === 2) { |
|
78
|
|
|
$k = ltrim($tmp[0], '-'); |
|
79
|
|
|
|
|
80
|
|
|
$cli_variables[$k] = $tmp[1]; |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$databasehost = $cli_variables['database_server']; |
|
86
|
|
|
$databaseloginname = $cli_variables['database_user']; |
|
87
|
|
|
$databaseloginpassword = $cli_variables['database_password']; |
|
88
|
|
|
$database_name = $cli_variables['database']; |
|
89
|
|
|
$tableprefix = $cli_variables['table_prefix']; |
|
90
|
|
|
|
|
91
|
|
|
$cmsadmin = $cli_variables['cmsadmin']; |
|
92
|
|
|
$cmsadminemail = $cli_variables['cmsadminemail']; |
|
93
|
|
|
$cmspassword = $cli_variables['cmspassword']; |
|
94
|
|
|
|
|
95
|
|
|
$managerlanguage = $cli_variables['language']; |
|
96
|
|
|
$installData = $cli_variables['installData']; |
|
97
|
|
|
$mode = $cli_variables['mode']; |
|
98
|
|
|
$removeInstall = $cli_variables['removeInstall']; |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
if ($databasehost == '') { $databasehost= 'localhost'; } |
|
104
|
|
|
if ($tableprefix == ''){ $tableprefix = $tableprefixauto; } |
|
105
|
|
|
if ($database_connection_method == '') { $database_connection_method = 'SET CHARACTER SET'; } |
|
106
|
|
|
if ($database_collation == '') { $database_collation = 'utf8_general_ci'; } |
|
107
|
|
|
if ($cmsadmin == ''){ $cmsadmin = 'admin'; } |
|
108
|
|
|
if ($managerlanguage == '') { $managerlanguage = 'en'; } |
|
109
|
|
|
if ($installData == 'y') { $installData = 1;} |
|
110
|
|
|
if ($mode == 'upgrade') { $installMode = 1;} |
|
111
|
|
|
|
|
112
|
|
|
//добавить обработку языка |
|
113
|
|
|
|
|
114
|
|
|
switch ($managerlanguage) { |
|
115
|
|
|
case 'ru': |
|
116
|
|
|
$managerlanguage = 'russian-UTF8'; |
|
117
|
|
|
break; |
|
118
|
|
|
|
|
119
|
|
|
case 'en': |
|
120
|
|
|
default: |
|
121
|
|
|
$managerlanguage = 'english'; |
|
122
|
|
|
break; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
////////////////////////////////////////////////////////////////////////////////////// |
|
126
|
|
View Code Duplication |
if( ! function_exists('f_owc')){ |
|
127
|
|
|
/** |
|
128
|
|
|
* @param $path |
|
129
|
|
|
* @param $data |
|
130
|
|
|
* @param null|int $mode |
|
131
|
|
|
*/ |
|
132
|
|
|
function f_owc($path, $data, $mode = null){ |
|
|
|
|
|
|
133
|
|
|
try { |
|
134
|
|
|
// make an attempt to create the file |
|
135
|
|
|
$hnd = fopen($path, 'w'); |
|
136
|
|
|
fwrite($hnd, $data); |
|
137
|
|
|
fclose($hnd); |
|
138
|
|
|
|
|
139
|
|
|
if(null !== $mode) chmod($path, $mode); |
|
140
|
|
|
}catch(Exception $e){ |
|
141
|
|
|
// Nothing, this is NOT normal |
|
142
|
|
|
unset($e); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
// check PHP version |
|
148
|
|
|
define('PHP_MIN_VERSION', '5.4.0'); |
|
149
|
|
|
$phpMinVersion = PHP_MIN_VERSION; // Maybe not necessary. For backward compatibility |
|
150
|
|
|
echo PHP_EOL . $_lang['checking_php_version']; |
|
151
|
|
|
// -1 if left is less, 0 if equal, +1 if left is higher |
|
152
|
|
|
if (version_compare(phpversion(), PHP_MIN_VERSION) < 0) { |
|
153
|
|
|
$errors++; |
|
154
|
|
|
$tmp = $_lang['you_running_php'] . phpversion() . str_replace('[+min_version+]', PHP_MIN_VERSION, $_lang["modx_requires_php"]); |
|
155
|
|
|
echo $_lang['failed'] . ' ' . $tmp . PHP_EOL; |
|
156
|
|
|
} else { |
|
157
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
// check directories |
|
161
|
|
|
// cache exists? |
|
162
|
|
|
echo strip_tags($_lang['checking_if_cache_exist']); |
|
163
|
|
View Code Duplication |
if (!file_exists($path."../assets/cache") || !file_exists($path."../assets/cache/rss")) { |
|
164
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
165
|
|
|
$errors++; |
|
166
|
|
|
} else { |
|
167
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
|
|
171
|
|
|
// cache writable? |
|
172
|
|
|
echo strip_tags($_lang['checking_if_cache_writable']); |
|
173
|
|
View Code Duplication |
if (!is_writable($path."../assets/cache")) { |
|
174
|
|
|
$errors++; |
|
175
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
176
|
|
|
} else { |
|
177
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
// cache files writable? |
|
182
|
|
|
echo strip_tags($_lang['checking_if_cache_file_writable']); |
|
183
|
|
|
$tmp = $path."../assets/cache/siteCache.idx.php"; |
|
184
|
|
|
if ( ! file_exists($tmp)) { |
|
185
|
|
|
f_owc($tmp, "<?php //EVO site cache file ?>"); |
|
186
|
|
|
} |
|
187
|
|
View Code Duplication |
if ( ! is_writable($tmp)) { |
|
188
|
|
|
$errors++; |
|
189
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
190
|
|
|
} else { |
|
191
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
echo strip_tags($_lang['checking_if_cache_file2_writable']); |
|
196
|
|
View Code Duplication |
if ( ! is_writable($path."../assets/cache/sitePublishing.idx.php")) { |
|
197
|
|
|
$errors++; |
|
198
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
199
|
|
|
} else { |
|
200
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
|
|
204
|
|
|
// File Browser directories exists? |
|
205
|
|
|
echo strip_tags($_lang['checking_if_images_exist']); |
|
206
|
|
View Code Duplication |
switch(true){ |
|
207
|
|
|
case !file_exists($path."../assets/images"): |
|
208
|
|
|
case !file_exists($path."../assets/files"): |
|
209
|
|
|
case !file_exists($path."../assets/backup"): |
|
210
|
|
|
//case !file_exists("../assets/.thumbs"): |
|
211
|
|
|
$errors++; |
|
212
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
213
|
|
|
break; |
|
214
|
|
|
default: |
|
215
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
|
|
219
|
|
|
// File Browser directories writable? |
|
220
|
|
|
echo strip_tags($_lang['checking_if_images_writable']); |
|
221
|
|
View Code Duplication |
switch(true){ |
|
222
|
|
|
case !is_writable($path."../assets/images"): |
|
223
|
|
|
case !is_writable($path."../assets/files"): |
|
224
|
|
|
case !is_writable($path."../assets/backup"): |
|
225
|
|
|
//case !is_writable("../assets/.thumbs"): |
|
226
|
|
|
$errors++; |
|
227
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
228
|
|
|
break; |
|
229
|
|
|
default: |
|
230
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
|
|
234
|
|
|
// export exists? |
|
235
|
|
|
echo strip_tags($_lang['checking_if_export_exists']); |
|
236
|
|
View Code Duplication |
if (!file_exists($path."../assets/export")) { |
|
237
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
238
|
|
|
$errors++; |
|
239
|
|
|
} else { |
|
240
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
|
|
244
|
|
|
// export writable? |
|
245
|
|
|
echo strip_tags($_lang['checking_if_export_writable']); |
|
246
|
|
View Code Duplication |
if (!is_writable($path."../assets/export")) { |
|
247
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
248
|
|
|
$errors++; |
|
249
|
|
|
} else { |
|
250
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
// config.inc.php writable? |
|
255
|
|
|
echo strip_tags($_lang['checking_if_config_exist_and_writable']); |
|
256
|
|
|
$tmp = $path."../".MGR_DIR."/includes/config.inc.php"; |
|
257
|
|
View Code Duplication |
if (!is_file($tmp)) { |
|
258
|
|
|
f_owc($tmp, "<?php //EVO configuration file ?>", 0666); |
|
259
|
|
|
} else { |
|
260
|
|
|
@chmod($tmp, 0666); |
|
261
|
|
|
} |
|
262
|
|
|
$isWriteable = is_writable($tmp); |
|
263
|
|
View Code Duplication |
if (!$isWriteable) { |
|
264
|
|
|
$errors++; |
|
265
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
266
|
|
|
} else { |
|
267
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
|
|
271
|
|
|
// connect to the database |
|
272
|
|
|
if ($installMode == 1) { |
|
273
|
|
|
include $path."../".MGR_DIR."/includes/config.inc.php"; |
|
274
|
|
|
} else { |
|
275
|
|
|
// get db info from post |
|
276
|
|
|
$database_server = $databasehost; |
|
277
|
|
|
$database_user = $databaseloginname; |
|
278
|
|
|
$database_password = $databaseloginpassword; |
|
279
|
|
|
$database_collation = $database_collation; |
|
280
|
|
|
$database_charset = substr($database_collation, 0, strpos($database_collation, '_') - 1); |
|
281
|
|
|
$database_connection_charset = $database_collation; |
|
282
|
|
|
$database_connection_method = $database_connection_method; |
|
283
|
|
|
$dbase = '`' . $database_name . '`'; |
|
284
|
|
|
$table_prefix = $tableprefix; |
|
285
|
|
|
} |
|
286
|
|
|
echo $_lang['creating_database_connection']; |
|
287
|
|
|
if (!$conn = mysqli_connect($database_server, $database_user, $database_password)) { |
|
288
|
|
|
$errors++; |
|
289
|
|
|
echo $_lang['database_connection_failed'].PHP_EOL; |
|
290
|
|
|
} else { |
|
291
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
// make sure we can use the database |
|
296
|
|
|
if ($installMode > 0 && !mysqli_query($conn, "USE {$dbase}")) { |
|
297
|
|
|
$errors++; |
|
298
|
|
|
echo $_lang['database_use_failed'].PHP_EOL; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
// check the database collation if not specified in the configuration |
|
302
|
|
View Code Duplication |
if (!isset ($database_connection_charset) || empty ($database_connection_charset)) { |
|
303
|
|
|
if (!$rs = mysqli_query($conn, "show session variables like 'collation_database'")) { |
|
304
|
|
|
$rs = mysqli_query($conn, "show session variables like 'collation_server'"); |
|
305
|
|
|
} |
|
306
|
|
|
if ($rs && $collation = mysqli_fetch_row($rs)) { |
|
307
|
|
|
$database_collation = $collation[1]; |
|
308
|
|
|
} |
|
309
|
|
|
if (empty ($database_collation)) { |
|
310
|
|
|
$database_collation = 'utf8_unicode_ci'; |
|
311
|
|
|
} |
|
312
|
|
|
$database_charset = substr($database_collation, 0, strpos($database_collation, '_') - 1); |
|
313
|
|
|
$database_connection_charset = $database_charset; |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
// determine the database connection method if not specified in the configuration |
|
317
|
|
|
if (!isset($database_connection_method) || empty($database_connection_method)) { |
|
318
|
|
|
$database_connection_method = 'SET CHARACTER SET'; |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
// check table prefix |
|
322
|
|
|
if ($conn && $installMode == 0) { |
|
323
|
|
|
echo $_lang['checking_table_prefix'] . $table_prefix . '`: '; |
|
324
|
|
View Code Duplication |
if ($rs= mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) { |
|
325
|
|
|
echo $_lang['failed'] . ' ' . $_lang['table_prefix_already_inuse_note'] . PHP_EOL; |
|
326
|
|
|
$errors++; |
|
327
|
|
|
|
|
328
|
|
|
} else { |
|
329
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
330
|
|
|
} |
|
331
|
|
|
} elseif ($conn && $installMode == 2) { |
|
332
|
|
|
echo $_lang['checking_table_prefix'] . $table_prefix . '`: '; |
|
333
|
|
View Code Duplication |
if (!$rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) { |
|
334
|
|
|
echo $_lang['failed'] . ' ' . $_lang['table_prefix_not_exist'] . PHP_EOL; |
|
335
|
|
|
$errors++; |
|
336
|
|
|
|
|
337
|
|
|
} else { |
|
338
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
339
|
|
|
} |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
// check mysql version |
|
343
|
|
|
if ($conn) { |
|
344
|
|
|
echo $_lang['checking_mysql_version']; |
|
345
|
|
|
if ( version_compare(mysqli_get_server_info($conn), '5.0.51', '=') ) { |
|
346
|
|
|
echo $_lang['warning'] . ' ' . $_lang['mysql_5051'] . PHP_EOL; |
|
347
|
|
|
echo $_lang['mysql_5051_warning'] . PHP_EOL; |
|
348
|
|
View Code Duplication |
} else { |
|
349
|
|
|
echo $_lang['ok'] . ' ' . $_lang['mysql_version_is'] . mysqli_get_server_info($conn) . PHP_EOL; |
|
350
|
|
|
} |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
// check for strict mode |
|
354
|
|
|
if ($conn) { |
|
355
|
|
|
echo $_lang['checking_mysql_strict_mode']; |
|
356
|
|
|
$mysqlmode = mysqli_query($conn, "SELECT @@global.sql_mode"); |
|
357
|
|
|
if (mysqli_num_rows($mysqlmode) > 0){ |
|
358
|
|
|
$modes = mysqli_fetch_array($mysqlmode, MYSQLI_NUM); |
|
359
|
|
|
//$modes = array("STRICT_TRANS_TABLES"); // for testing |
|
360
|
|
|
// print_r($modes); |
|
361
|
|
|
foreach ($modes as $mode) { |
|
362
|
|
|
if (stristr($mode, "STRICT_TRANS_TABLES") !== false || stristr($mode, "STRICT_ALL_TABLES") !== false) { |
|
363
|
|
|
echo $_lang['warning'] . ' ' . $_lang['strict_mode'] . PHP_EOL; |
|
364
|
|
|
echo $_lang['strict_mode_error'] . PHP_EOL; |
|
365
|
|
|
} else { |
|
366
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
} else { |
|
370
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
371
|
|
|
} |
|
372
|
|
|
} |
|
373
|
|
|
// Version and strict mode check end |
|
374
|
|
|
|
|
375
|
|
|
// andrazk 20070416 - add install flag and disable manager login |
|
376
|
|
|
// assets/cache writable? |
|
377
|
|
|
if (is_writable($path."../assets/cache")) { |
|
378
|
|
View Code Duplication |
if (file_exists($path.'../assets/cache/installProc.inc.php')) { |
|
379
|
|
|
@chmod($path.'../assets/cache/installProc.inc.php', 0755); |
|
380
|
|
|
unlink($path.'../assets/cache/installProc.inc.php'); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
f_owc($path."../assets/cache/installProc.inc.php", '<?php $installStartTime = '.time().'; ?>'); |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
View Code Duplication |
if($installMode > 0 && $_POST['installdata'] == "1") { |
|
387
|
|
|
echo $_lang['sample_web_site'] . ': ' . $_lang['sample_web_site_note'] . PHP_EOL; |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
if ($errors > 0) { |
|
391
|
|
|
echo $_lang['setup_cannot_continue'] . ' '; |
|
392
|
|
|
|
|
393
|
|
View Code Duplication |
if($errors > 1){ |
|
394
|
|
|
echo $errors . " " . $_lang['errors'] . $_lang['please_correct_errors'] . $_lang['and_try_again_plural']; |
|
395
|
|
|
}else{ |
|
396
|
|
|
echo $_lang['error'] . $_lang['please_correct_error'] . $_lang['and_try_again']. PHP_EOL; |
|
397
|
|
|
} |
|
398
|
|
|
|
|
399
|
|
|
die(); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
|
|
403
|
|
|
|
|
404
|
|
|
////////////////////////////////////////////////////////////////////////////////////// |
|
405
|
|
|
$create = false; |
|
406
|
|
|
|
|
407
|
|
|
// set timout limit |
|
408
|
|
|
@ set_time_limit(120); // used @ to prevent warning when using safe mode? |
|
409
|
|
|
|
|
410
|
|
|
//echo $_lang['setup_database'].PHP_EOL; |
|
411
|
|
|
|
|
412
|
|
|
|
|
413
|
|
|
|
|
414
|
|
|
if ($installMode == 1) { |
|
415
|
|
|
include $path."../".MGR_DIR."/includes/config.inc.php"; |
|
416
|
|
|
} else { |
|
417
|
|
|
// get db info from post |
|
418
|
|
|
$database_server = $databasehost; |
|
419
|
|
|
$database_user = $databaseloginname; |
|
420
|
|
|
$database_password = $databaseloginpassword; |
|
421
|
|
|
$database_collation = $database_collation; |
|
422
|
|
|
$database_charset = substr($database_collation, 0, strpos($database_collation, '_')); |
|
423
|
|
|
$database_connection_charset = $database_charset; |
|
424
|
|
|
$database_connection_method = $database_connection_method; |
|
425
|
|
|
$dbase = "`" .$database_name. "`"; |
|
426
|
|
|
$table_prefix = $tableprefix; |
|
427
|
|
|
$adminname = $cmsadmin; |
|
428
|
|
|
$adminemail = $cmsadminemail; |
|
429
|
|
|
$adminpass = $cmspassword; |
|
430
|
|
|
$managerlanguage = $managerlanguage; |
|
431
|
|
|
$custom_placeholders = array(); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
// set session name variable |
|
435
|
|
|
if (!isset ($site_sessionname)) { |
|
436
|
|
|
$site_sessionname = 'SN' . uniqid(''); |
|
437
|
|
|
} |
|
438
|
|
|
|
|
439
|
|
|
// get base path and url |
|
440
|
|
|
$a = explode("install", str_replace("\\", "/", dirname($_SERVER["PHP_SELF"]))); |
|
441
|
|
|
if (count($a) > 1) |
|
442
|
|
|
array_pop($a); |
|
443
|
|
|
$url = implode("install", $a); |
|
444
|
|
|
reset($a); |
|
445
|
|
|
$a = explode("install", str_replace("\\", "/", realpath(dirname(__FILE__)))); |
|
446
|
|
|
if (count($a) > 1) |
|
447
|
|
|
array_pop($a); |
|
448
|
|
|
$pth = implode("install", $a); |
|
449
|
|
|
unset ($a); |
|
450
|
|
|
$base_url = $url . (substr($url, -1) != "/" ? "/" : ""); |
|
451
|
|
|
$base_path = $pth . (substr($pth, -1) != "/" ? "/" : ""); |
|
452
|
|
|
|
|
453
|
|
|
// connect to the database |
|
454
|
|
|
echo $_lang['setup_database_create_connection'].': '; |
|
455
|
|
|
if (!$conn = mysqli_connect($database_server, $database_user, $database_password)) { |
|
456
|
|
|
echo $_lang["setup_database_create_connection_failed"]." ".$_lang['setup_database_create_connection_failed_note'].PHP_EOL; |
|
457
|
|
|
return; |
|
458
|
|
|
} else { |
|
459
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
// select database |
|
463
|
|
|
echo $_lang['setup_database_selection']. str_replace("`", "", $dbase) . "`: "; |
|
464
|
|
|
if (!mysqli_select_db($conn, str_replace("`", "", $dbase))) { |
|
465
|
|
|
echo $_lang['setup_database_selection_failed']." ".$_lang['setup_database_selection_failed_note'].PHP_EOL; |
|
466
|
|
|
$create = true; |
|
467
|
|
View Code Duplication |
} else { |
|
468
|
|
|
if (function_exists('mysqli_set_charset')) mysqli_set_charset($conn, $database_charset); |
|
469
|
|
|
mysqli_query($conn, "{$database_connection_method} {$database_connection_charset}"); |
|
470
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
471
|
|
|
} |
|
472
|
|
|
|
|
473
|
|
|
// try to create the database |
|
474
|
|
|
if ($create) { |
|
475
|
|
|
echo $_lang['setup_database_creation']. str_replace("`", "", $dbase) . "`: "; |
|
476
|
|
|
// if(!@mysqli_create_db(str_replace("`","",$dbase), $conn)) { |
|
477
|
|
|
if (! mysqli_query($conn, "CREATE DATABASE $dbase DEFAULT CHARACTER SET $database_charset COLLATE $database_collation")) { |
|
478
|
|
|
echo $_lang['setup_database_creation_failed']." ".$_lang['setup_database_creation_failed_note'].PHP_EOL; |
|
479
|
|
|
$errors += 1; |
|
480
|
|
|
|
|
481
|
|
|
echo 'database charset: ' . $database_charset . PHP_EOL; |
|
482
|
|
|
echo 'database collation: ' . $database_collation . PHP_EOL; |
|
483
|
|
|
|
|
484
|
|
|
echo $_lang['setup_database_creation_failed_note2'] . PHP_EOL; |
|
485
|
|
|
|
|
486
|
|
|
die(); |
|
487
|
|
|
|
|
488
|
|
|
} else { |
|
489
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
490
|
|
|
} |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
// check table prefix |
|
494
|
|
|
if ($installMode == 0) { |
|
495
|
|
|
echo $_lang['checking_table_prefix'] . $table_prefix . "`: "; |
|
496
|
|
|
if (@ $rs = mysqli_query($conn, "SELECT COUNT(*) FROM $dbase.`" . $table_prefix . "site_content`")) { |
|
497
|
|
|
echo $_lang['failed'] . " " . $_lang['table_prefix_already_inuse'] . PHP_EOL; |
|
498
|
|
|
$errors += 1; |
|
499
|
|
|
echo $_lang['table_prefix_already_inuse_note'] . PHP_EOL; |
|
500
|
|
|
return; |
|
501
|
|
|
} else { |
|
502
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
503
|
|
|
} |
|
504
|
|
|
} |
|
505
|
|
|
|
|
506
|
|
View Code Duplication |
if(!function_exists('parseProperties')) { |
|
507
|
|
|
/** |
|
508
|
|
|
* parses a resource property string and returns the result as an array |
|
509
|
|
|
* duplicate of method in documentParser class |
|
510
|
|
|
* |
|
511
|
|
|
* @param string $propertyString |
|
512
|
|
|
* @return array |
|
|
|
|
|
|
513
|
|
|
*/ |
|
514
|
|
|
function parseProperties($propertyString) { |
|
515
|
|
|
$parameter= array (); |
|
516
|
|
|
if (!empty ($propertyString)) { |
|
517
|
|
|
$tmpParams= explode("&", $propertyString); |
|
518
|
|
|
$countParams = count($tmpParams); |
|
519
|
|
|
for ($x= 0; $x < $countParams; $x++) { |
|
520
|
|
|
if (strpos($tmpParams[$x], '=', 0)) { |
|
521
|
|
|
$pTmp= explode("=", $tmpParams[$x]); |
|
522
|
|
|
$pvTmp= explode(";", trim($pTmp[1])); |
|
523
|
|
|
if ($pvTmp[1] == 'list' && $pvTmp[3] != "") |
|
524
|
|
|
$parameter[trim($pTmp[0])]= $pvTmp[3]; //list default |
|
525
|
|
|
else |
|
526
|
|
|
if ($pvTmp[1] != 'list' && $pvTmp[2] != "") |
|
527
|
|
|
$parameter[trim($pTmp[0])]= $pvTmp[2]; |
|
528
|
|
|
} |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
return $parameter; |
|
532
|
|
|
} |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
|
|
// check status of Inherit Parent Template plugin |
|
536
|
|
|
$auto_template_logic = 'parent'; |
|
537
|
|
View Code Duplication |
if ($installMode != 0) { |
|
538
|
|
|
$rs = mysqli_query($conn, "SELECT properties, disabled FROM $dbase.`" . $table_prefix . "site_plugins` WHERE name='Inherit Parent Template'"); |
|
539
|
|
|
$row = mysqli_fetch_row($rs); |
|
540
|
|
|
if(!$row) { |
|
541
|
|
|
// not installed |
|
542
|
|
|
$auto_template_logic = 'system'; |
|
543
|
|
|
} else { |
|
544
|
|
|
if($row[1] == 1) { |
|
545
|
|
|
// installed but disabled |
|
546
|
|
|
$auto_template_logic = 'system'; |
|
547
|
|
|
} else { |
|
548
|
|
|
// installed, enabled .. see how it's configured |
|
549
|
|
|
$properties = parseProperties($row[0]); |
|
550
|
|
|
if(isset($properties['inheritTemplate'])) { |
|
551
|
|
|
if($properties['inheritTemplate'] == 'From First Sibling') { |
|
552
|
|
|
$auto_template_logic = 'sibling'; |
|
553
|
|
|
} |
|
554
|
|
|
} |
|
555
|
|
|
} |
|
556
|
|
|
} |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
|
|
560
|
|
|
|
|
561
|
|
|
|
|
562
|
|
|
// open db connection |
|
563
|
|
|
$setupPath = realpath(dirname(__FILE__)); |
|
564
|
|
|
$chunkPath = $path.'assets/chunks'; |
|
565
|
|
|
$snippetPath = $path.'assets/snippets'; |
|
566
|
|
|
$pluginPath = $path.'assets/plugins'; |
|
567
|
|
|
$modulePath = $path.'assets/modules'; |
|
568
|
|
|
$templatePath = $path.'assets/templates'; |
|
569
|
|
|
$tvPath = $path.'assets/tvs'; |
|
570
|
|
|
|
|
571
|
|
|
// setup Template template files - array : name, description, type - 0:file or 1:content, parameters, category |
|
572
|
|
|
$mt = &$moduleTemplates; |
|
573
|
|
View Code Duplication |
if(is_dir($templatePath) && is_readable($templatePath)) { |
|
574
|
|
|
$d = dir($templatePath); |
|
575
|
|
|
while (false !== ($tplfile = $d->read())) |
|
576
|
|
|
{ |
|
577
|
|
|
if(substr($tplfile, -4) != '.tpl') continue; |
|
578
|
|
|
$params = parse_docblock($templatePath, $tplfile); |
|
579
|
|
|
if(is_array($params) && (count($params)>0)) |
|
580
|
|
|
{ |
|
581
|
|
|
$description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
|
582
|
|
|
$mt[] = array |
|
583
|
|
|
( |
|
584
|
|
|
$params['name'], |
|
585
|
|
|
$description, |
|
586
|
|
|
// Don't think this is gonna be used ... but adding it just in case 'type' |
|
587
|
|
|
$params['type'], |
|
588
|
|
|
"$templatePath/{$params['filename']}", |
|
589
|
|
|
$params['modx_category'], |
|
590
|
|
|
$params['lock_template'], |
|
591
|
|
|
array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false, |
|
592
|
|
|
isset($params['save_sql_id_as']) ? $params['save_sql_id_as'] : NULL // Nessecary to fix template-ID for demo-site |
|
593
|
|
|
); |
|
594
|
|
|
} |
|
595
|
|
|
} |
|
596
|
|
|
$d->close(); |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
// setup Template Variable template files |
|
600
|
|
|
$mtv = &$moduleTVs; |
|
601
|
|
View Code Duplication |
if(is_dir($tvPath) && is_readable($tvPath)) { |
|
602
|
|
|
$d = dir($tvPath); |
|
603
|
|
|
while (false !== ($tplfile = $d->read())) { |
|
604
|
|
|
if(substr($tplfile, -4) != '.tpl') continue; |
|
605
|
|
|
$params = parse_docblock($tvPath, $tplfile); |
|
606
|
|
|
if(is_array($params) && (count($params)>0)) { |
|
607
|
|
|
$description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
|
608
|
|
|
$mtv[] = array( |
|
609
|
|
|
$params['name'], |
|
610
|
|
|
$params['caption'], |
|
611
|
|
|
$description, |
|
612
|
|
|
$params['input_type'], |
|
613
|
|
|
$params['input_options'], |
|
614
|
|
|
$params['input_default'], |
|
615
|
|
|
$params['output_widget'], |
|
616
|
|
|
$params['output_widget_params'], |
|
617
|
|
|
"$templatePath/{$params['filename']}", /* not currently used */ |
|
618
|
|
|
$params['template_assignments']!="*"?$params['template_assignments']:implode(",",array_map(create_function('$v','return $v[0];'),$mt)), /* comma-separated list of template names */ |
|
619
|
|
|
$params['modx_category'], |
|
620
|
|
|
$params['lock_tv'], /* value should be 1 or 0 */ |
|
621
|
|
|
array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false |
|
622
|
|
|
); |
|
623
|
|
|
} |
|
624
|
|
|
} |
|
625
|
|
|
$d->close(); |
|
626
|
|
|
} |
|
627
|
|
|
|
|
628
|
|
|
// setup chunks template files - array : name, description, type - 0:file or 1:content, file or content |
|
629
|
|
|
$mc = &$moduleChunks; |
|
630
|
|
View Code Duplication |
if(is_dir($chunkPath) && is_readable($chunkPath)) { |
|
631
|
|
|
$d = dir($chunkPath); |
|
632
|
|
|
while (false !== ($tplfile = $d->read())) { |
|
633
|
|
|
if(substr($tplfile, -4) != '.tpl') { |
|
634
|
|
|
continue; |
|
635
|
|
|
} |
|
636
|
|
|
$params = parse_docblock($chunkPath, $tplfile); |
|
637
|
|
|
if(is_array($params) && count($params) > 0) { |
|
638
|
|
|
$mc[] = array( |
|
639
|
|
|
$params['name'], |
|
640
|
|
|
$params['description'], |
|
641
|
|
|
"$chunkPath/{$params['filename']}", |
|
642
|
|
|
$params['modx_category'], |
|
643
|
|
|
array_key_exists('overwrite', $params) ? $params['overwrite'] : 'true', |
|
644
|
|
|
array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false |
|
645
|
|
|
); |
|
646
|
|
|
} |
|
647
|
|
|
} |
|
648
|
|
|
$d->close(); |
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
// setup snippets template files - array : name, description, type - 0:file or 1:content, file or content,properties |
|
652
|
|
|
$ms = &$moduleSnippets; |
|
653
|
|
View Code Duplication |
if(is_dir($snippetPath) && is_readable($snippetPath)) { |
|
654
|
|
|
$d = dir($snippetPath); |
|
655
|
|
|
while (false !== ($tplfile = $d->read())) { |
|
656
|
|
|
if(substr($tplfile, -4) != '.tpl') { |
|
657
|
|
|
continue; |
|
658
|
|
|
} |
|
659
|
|
|
$params = parse_docblock($snippetPath, $tplfile); |
|
660
|
|
|
if(is_array($params) && count($params) > 0) { |
|
661
|
|
|
$description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
|
662
|
|
|
$ms[] = array( |
|
663
|
|
|
$params['name'], |
|
664
|
|
|
$description, |
|
665
|
|
|
"$snippetPath/{$params['filename']}", |
|
666
|
|
|
$params['properties'], |
|
667
|
|
|
$params['modx_category'], |
|
668
|
|
|
array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false |
|
669
|
|
|
); |
|
670
|
|
|
} |
|
671
|
|
|
} |
|
672
|
|
|
$d->close(); |
|
673
|
|
|
} |
|
674
|
|
|
|
|
675
|
|
|
// setup plugins template files - array : name, description, type - 0:file or 1:content, file or content,properties |
|
676
|
|
|
$mp = &$modulePlugins; |
|
677
|
|
View Code Duplication |
if(is_dir($pluginPath) && is_readable($pluginPath)) { |
|
678
|
|
|
$d = dir($pluginPath); |
|
679
|
|
|
while (false !== ($tplfile = $d->read())) { |
|
680
|
|
|
if(substr($tplfile, -4) != '.tpl') { |
|
681
|
|
|
continue; |
|
682
|
|
|
} |
|
683
|
|
|
$params = parse_docblock($pluginPath, $tplfile); |
|
684
|
|
|
if(is_array($params) && count($params) > 0) { |
|
685
|
|
|
$description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
|
686
|
|
|
$mp[] = array( |
|
687
|
|
|
$params['name'], |
|
688
|
|
|
$description, |
|
689
|
|
|
"$pluginPath/{$params['filename']}", |
|
690
|
|
|
$params['properties'], |
|
691
|
|
|
$params['events'], |
|
692
|
|
|
$params['guid'], |
|
693
|
|
|
$params['modx_category'], |
|
694
|
|
|
$params['legacy_names'], |
|
695
|
|
|
array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false, |
|
696
|
|
|
(int)$params['disabled'] |
|
697
|
|
|
); |
|
698
|
|
|
} |
|
699
|
|
|
} |
|
700
|
|
|
$d->close(); |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
// setup modules - array : name, description, type - 0:file or 1:content, file or content,properties, guid,enable_sharedparams |
|
704
|
|
|
$mm = &$moduleModules; |
|
705
|
|
|
$mdp = &$moduleDependencies; |
|
706
|
|
View Code Duplication |
if(is_dir($modulePath) && is_readable($modulePath)) { |
|
707
|
|
|
$d = dir($modulePath); |
|
708
|
|
|
while (false !== ($tplfile = $d->read())) { |
|
709
|
|
|
if(substr($tplfile, -4) != '.tpl') { |
|
710
|
|
|
continue; |
|
711
|
|
|
} |
|
712
|
|
|
$params = parse_docblock($modulePath, $tplfile); |
|
713
|
|
|
if(is_array($params) && count($params) > 0) { |
|
714
|
|
|
$description = empty($params['version']) ? $params['description'] : "<strong>{$params['version']}</strong> {$params['description']}"; |
|
715
|
|
|
$mm[] = array( |
|
716
|
|
|
$params['name'], |
|
717
|
|
|
$description, |
|
718
|
|
|
"$modulePath/{$params['filename']}", |
|
719
|
|
|
$params['properties'], |
|
720
|
|
|
$params['guid'], |
|
721
|
|
|
(int)$params['shareparams'], |
|
722
|
|
|
$params['modx_category'], |
|
723
|
|
|
array_key_exists('installset', $params) ? preg_split("/\s*,\s*/", $params['installset']) : false |
|
724
|
|
|
); |
|
725
|
|
|
} |
|
726
|
|
|
if ((int)$params['shareparams'] || !empty($params['dependencies'])) { |
|
727
|
|
|
$dependencies = explode(',', $params['dependencies']); |
|
728
|
|
|
foreach ($dependencies as $dependency) { |
|
729
|
|
|
$dependency = explode(':', $dependency); |
|
730
|
|
|
switch (trim($dependency[0])) { |
|
731
|
|
|
case 'template': |
|
732
|
|
|
$mdp[] = array( |
|
733
|
|
|
'module' => $params['name'], |
|
734
|
|
|
'table' => 'templates', |
|
735
|
|
|
'column' => 'templatename', |
|
736
|
|
|
'type' => 50, |
|
737
|
|
|
'name' => trim($dependency[1]) |
|
738
|
|
|
); |
|
739
|
|
|
break; |
|
740
|
|
|
case 'tv': |
|
741
|
|
|
case 'tmplvar': |
|
742
|
|
|
$mdp[] = array( |
|
743
|
|
|
'module' => $params['name'], |
|
744
|
|
|
'table' => 'tmplvars', |
|
745
|
|
|
'column' => 'name', |
|
746
|
|
|
'type' => 60, |
|
747
|
|
|
'name' => trim($dependency[1]) |
|
748
|
|
|
); |
|
749
|
|
|
break; |
|
750
|
|
|
case 'chunk': |
|
751
|
|
|
case 'htmlsnippet': |
|
752
|
|
|
$mdp[] = array( |
|
753
|
|
|
'module' => $params['name'], |
|
754
|
|
|
'table' => 'htmlsnippets', |
|
755
|
|
|
'column' => 'name', |
|
756
|
|
|
'type' => 10, |
|
757
|
|
|
'name' => trim($dependency[1]) |
|
758
|
|
|
); |
|
759
|
|
|
break; |
|
760
|
|
|
case 'snippet': |
|
761
|
|
|
$mdp[] = array( |
|
762
|
|
|
'module' => $params['name'], |
|
763
|
|
|
'table' => 'snippets', |
|
764
|
|
|
'column' => 'name', |
|
765
|
|
|
'type' => 40, |
|
766
|
|
|
'name' => trim($dependency[1]) |
|
767
|
|
|
); |
|
768
|
|
|
break; |
|
769
|
|
|
case 'plugin': |
|
770
|
|
|
$mdp[] = array( |
|
771
|
|
|
'module' => $params['name'], |
|
772
|
|
|
'table' => 'plugins', |
|
773
|
|
|
'column' => 'name', |
|
774
|
|
|
'type' => 30, |
|
775
|
|
|
'name' => trim($dependency[1]) |
|
776
|
|
|
); |
|
777
|
|
|
break; |
|
778
|
|
|
case 'resource': |
|
779
|
|
|
$mdp[] = array( |
|
780
|
|
|
'module' => $params['name'], |
|
781
|
|
|
'table' => 'content', |
|
782
|
|
|
'column' => 'pagetitle', |
|
783
|
|
|
'type' => 20, |
|
784
|
|
|
'name' => trim($dependency[1]) |
|
785
|
|
|
); |
|
786
|
|
|
break; |
|
787
|
|
|
} |
|
788
|
|
|
} |
|
789
|
|
|
} |
|
790
|
|
|
} |
|
791
|
|
|
$d->close(); |
|
792
|
|
|
} |
|
793
|
|
|
|
|
794
|
|
|
// setup callback function |
|
795
|
|
|
$callBackFnc = "clean_up"; |
|
796
|
|
|
|
|
797
|
|
View Code Duplication |
function clean_up($sqlParser) { |
|
|
|
|
|
|
798
|
|
|
$ids = array(); |
|
799
|
|
|
|
|
800
|
|
|
// secure web documents - privateweb |
|
801
|
|
|
mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 0 WHERE privateweb = 1"); |
|
802
|
|
|
$sql = "SELECT DISTINCT sc.id |
|
803
|
|
|
FROM `".$sqlParser->prefix."site_content` sc |
|
804
|
|
|
LEFT JOIN `".$sqlParser->prefix."document_groups` dg ON dg.document = sc.id |
|
805
|
|
|
LEFT JOIN `".$sqlParser->prefix."webgroup_access` wga ON wga.documentgroup = dg.document_group |
|
806
|
|
|
WHERE wga.id>0"; |
|
807
|
|
|
$ds = mysqli_query($sqlParser->conn,$sql); |
|
808
|
|
|
if(!$ds) { |
|
809
|
|
|
echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn); |
|
810
|
|
|
} |
|
811
|
|
|
else { |
|
812
|
|
|
while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"]; |
|
813
|
|
|
if(count($ids)>0) { |
|
814
|
|
|
mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privateweb = 1 WHERE id IN (".implode(", ",$ids).")"); |
|
815
|
|
|
unset($ids); |
|
816
|
|
|
} |
|
817
|
|
|
} |
|
818
|
|
|
|
|
819
|
|
|
// secure manager documents privatemgr |
|
820
|
|
|
mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 0 WHERE privatemgr = 1"); |
|
821
|
|
|
$sql = "SELECT DISTINCT sc.id |
|
822
|
|
|
FROM `".$sqlParser->prefix."site_content` sc |
|
823
|
|
|
LEFT JOIN `".$sqlParser->prefix."document_groups` dg ON dg.document = sc.id |
|
824
|
|
|
LEFT JOIN `".$sqlParser->prefix."membergroup_access` mga ON mga.documentgroup = dg.document_group |
|
825
|
|
|
WHERE mga.id>0"; |
|
826
|
|
|
$ds = mysqli_query($sqlParser->conn,$sql); |
|
827
|
|
|
if(!$ds) { |
|
828
|
|
|
echo "An error occurred while executing a query: ".mysqli_error($sqlParser->conn); |
|
829
|
|
|
} |
|
830
|
|
|
else { |
|
831
|
|
|
while($r = mysqli_fetch_assoc($ds)) $ids[]=$r["id"]; |
|
832
|
|
|
if(count($ids)>0) { |
|
833
|
|
|
mysqli_query($sqlParser->conn,"UPDATE `".$sqlParser->prefix."site_content` SET privatemgr = 1 WHERE id IN (".implode(", ",$ids).")"); |
|
834
|
|
|
unset($ids); |
|
835
|
|
|
} |
|
836
|
|
|
} |
|
837
|
|
|
} |
|
838
|
|
|
|
|
839
|
|
View Code Duplication |
function parse_docblock($element_dir, $filename) { |
|
|
|
|
|
|
840
|
|
|
$params = array(); |
|
841
|
|
|
$fullpath = $element_dir . '/' . $filename; |
|
842
|
|
|
if(is_readable($fullpath)) { |
|
843
|
|
|
$tpl = @fopen($fullpath, "r"); |
|
844
|
|
|
if($tpl) { |
|
845
|
|
|
$params['filename'] = $filename; |
|
846
|
|
|
$docblock_start_found = false; |
|
847
|
|
|
$name_found = false; |
|
848
|
|
|
$description_found = false; |
|
849
|
|
|
|
|
850
|
|
|
while(!feof($tpl)) { |
|
851
|
|
|
$line = fgets($tpl); |
|
852
|
|
|
if(!$docblock_start_found) { |
|
853
|
|
|
// find docblock start |
|
854
|
|
|
if(strpos($line, '/**') !== false) { |
|
855
|
|
|
$docblock_start_found = true; |
|
856
|
|
|
} |
|
857
|
|
|
continue; |
|
858
|
|
|
} elseif(!$name_found) { |
|
859
|
|
|
// find name |
|
860
|
|
|
$ma = null; |
|
861
|
|
|
if(preg_match("/^\s+\*\s+(.+)/", $line, $ma)) { |
|
862
|
|
|
$params['name'] = trim($ma[1]); |
|
863
|
|
|
$name_found = !empty($params['name']); |
|
864
|
|
|
} |
|
865
|
|
|
continue; |
|
866
|
|
|
} elseif(!$description_found) { |
|
867
|
|
|
// find description |
|
868
|
|
|
$ma = null; |
|
869
|
|
|
if(preg_match("/^\s+\*\s+(.+)/", $line, $ma)) { |
|
870
|
|
|
$params['description'] = trim($ma[1]); |
|
871
|
|
|
$description_found = !empty($params['description']); |
|
872
|
|
|
} |
|
873
|
|
|
continue; |
|
874
|
|
|
} else { |
|
875
|
|
|
$ma = null; |
|
876
|
|
|
if(preg_match("/^\s+\*\s+\@([^\s]+)\s+(.+)/", $line, $ma)) { |
|
877
|
|
|
$param = trim($ma[1]); |
|
878
|
|
|
$val = trim($ma[2]); |
|
879
|
|
|
if(!empty($param) && !empty($val)) { |
|
880
|
|
|
if($param == 'internal') { |
|
881
|
|
|
$ma = null; |
|
882
|
|
|
if(preg_match("/\@([^\s]+)\s+(.+)/", $val, $ma)) { |
|
883
|
|
|
$param = trim($ma[1]); |
|
884
|
|
|
$val = trim($ma[2]); |
|
885
|
|
|
} |
|
886
|
|
|
//if($val !== '0' && (empty($param) || empty($val))) { |
|
887
|
|
|
if(empty($param)) { |
|
888
|
|
|
continue; |
|
889
|
|
|
} |
|
890
|
|
|
} |
|
891
|
|
|
$params[$param] = $val; |
|
892
|
|
|
} |
|
893
|
|
|
} elseif(preg_match("/^\s*\*\/\s*$/", $line)) { |
|
894
|
|
|
break; |
|
895
|
|
|
} |
|
896
|
|
|
} |
|
897
|
|
|
} |
|
898
|
|
|
@fclose($tpl); |
|
899
|
|
|
} |
|
900
|
|
|
} |
|
901
|
|
|
return $params; |
|
902
|
|
|
} |
|
903
|
|
|
|
|
904
|
|
|
|
|
905
|
|
|
include $path."sqlParser.class.php"; |
|
906
|
|
|
$sqlParser = new SqlParser($database_server, $database_user, $database_password, str_replace("`", "", $dbase), $table_prefix, $adminname, $adminemail, $adminpass, $database_connection_charset, $managerlanguage, $database_connection_method, $auto_template_logic); |
|
907
|
|
|
$sqlParser->mode = ($installMode < 1) ? "new" : "upd"; |
|
908
|
|
|
/* image and file manager paths now handled via settings screen in Manager |
|
909
|
|
|
$sqlParser->imageUrl = 'http://' . $_SERVER['SERVER_NAME'] . $base_url . "assets/"; |
|
910
|
|
|
$sqlParser->imageUrl = "assets/"; |
|
911
|
|
|
$sqlParser->imagePath = $base_path . "assets/"; |
|
912
|
|
|
$sqlParser->fileManagerPath = $base_path; |
|
913
|
|
|
*/ |
|
914
|
|
|
$sqlParser->ignoreDuplicateErrors = true; |
|
915
|
|
|
$sqlParser->connect(); |
|
916
|
|
|
|
|
917
|
|
|
// install/update database |
|
918
|
|
|
echo $_lang['setup_database_creating_tables']; |
|
919
|
|
|
if ($moduleSQLBaseFile) { |
|
920
|
|
|
$sqlParser->process($moduleSQLBaseFile); |
|
921
|
|
|
// display database results |
|
922
|
|
|
if ($sqlParser->installFailed == true) { |
|
923
|
|
|
$errors += 1; |
|
924
|
|
|
echo $_lang['database_alerts'] . PHP_EOL; |
|
925
|
|
|
echo $_lang['setup_couldnt_install'] . PHP_EOL; |
|
926
|
|
|
echo $_lang['installation_error_occured'] . PHP_EOL; |
|
927
|
|
|
for ($i = 0; $i < count($sqlParser->mysqlErrors); $i++) { |
|
928
|
|
|
echo $sqlParser->mysqlErrors[$i]["error"] . " " . $_lang['during_execution_of_sql'] . " " . strip_tags($sqlParser->mysqlErrors[$i]["sql"]) . PHP_EOL; |
|
929
|
|
|
} |
|
930
|
|
|
echo $_lang['some_tables_not_updated'] . PHP_EOL; |
|
931
|
|
|
die(); |
|
932
|
|
|
} else { |
|
933
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
934
|
|
|
} |
|
935
|
|
|
} |
|
936
|
|
|
|
|
937
|
|
|
// custom or not |
|
938
|
|
|
if (file_exists($path."../assets/cache/siteManager.php")) { |
|
939
|
|
|
$mgrdir = 'include_once(dirname(__FILE__)."/../../assets/cache/siteManager.php");'; |
|
940
|
|
|
}else{ |
|
941
|
|
|
$mgrdir = 'define(\'MGR_DIR\', \'manager\');'; |
|
942
|
|
|
} |
|
943
|
|
|
|
|
944
|
|
|
// write the config.inc.php file if new installation |
|
945
|
|
|
echo $_lang['writing_config_file']; |
|
946
|
|
|
|
|
947
|
|
|
$confph = array(); |
|
948
|
|
|
$confph['database_server'] = $database_server; |
|
949
|
|
|
$confph['user_name'] = mysqli_real_escape_string($conn, $database_user); |
|
950
|
|
|
$confph['password'] = mysqli_real_escape_string($conn, $database_password); |
|
951
|
|
|
$confph['connection_charset'] = $database_connection_charset; |
|
952
|
|
|
$confph['connection_method'] = $database_connection_method; |
|
953
|
|
|
$confph['dbase'] = str_replace('`', '', $dbase); |
|
954
|
|
|
$confph['table_prefix'] = $table_prefix; |
|
955
|
|
|
$confph['lastInstallTime'] = time(); |
|
956
|
|
|
$confph['site_sessionname'] = $site_sessionname; |
|
957
|
|
|
|
|
958
|
|
|
$configString = file_get_contents($path.'config.inc.tpl'); |
|
959
|
|
|
$configString = parse($configString, $confph); |
|
960
|
|
|
|
|
961
|
|
|
$filename = $base_path.MGR_DIR.'/includes/config.inc.php'; |
|
962
|
|
|
$configFileFailed = false; |
|
963
|
|
|
if (@ !$handle = fopen($filename, 'w')) { |
|
964
|
|
|
$configFileFailed = true; |
|
965
|
|
|
} |
|
966
|
|
|
|
|
967
|
|
|
// write $somecontent to our opened file. |
|
968
|
|
|
if (@ fwrite($handle, $configString) === FALSE) { |
|
969
|
|
|
$configFileFailed = true; |
|
970
|
|
|
} |
|
971
|
|
|
@ fclose($handle); |
|
972
|
|
|
|
|
973
|
|
|
// try to chmod the config file go-rwx (for suexeced php) |
|
974
|
|
|
$chmodSuccess = @chmod($filename, 0404); |
|
975
|
|
|
|
|
976
|
|
|
if ($configFileFailed == true) { |
|
|
|
|
|
|
977
|
|
|
echo $_lang['failed'] . PHP_EOL; |
|
978
|
|
|
$errors += 1; |
|
979
|
|
|
|
|
980
|
|
|
echo $_lang['cant_write_config_file'] . ' ' . MGR_DIR .'/includes/config.inc.php' .PHP_EOL; |
|
981
|
|
|
echo ' '.PHP_EOL; |
|
982
|
|
|
echo ' '.PHP_EOL; |
|
983
|
|
|
echo $configString; |
|
984
|
|
|
echo ' '.PHP_EOL; |
|
985
|
|
|
echo ' '.PHP_EOL; |
|
986
|
|
|
echo $_lang['cant_write_config_file_note'] . PHP_EOL; |
|
987
|
|
|
die(); |
|
988
|
|
|
|
|
989
|
|
|
} else { |
|
990
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
991
|
|
|
} |
|
992
|
|
|
|
|
993
|
|
|
// generate new site_id and set manager theme to default |
|
994
|
|
View Code Duplication |
if ($installMode == 0) { |
|
995
|
|
|
$siteid = uniqid(''); |
|
996
|
|
|
mysqli_query($sqlParser->conn, "REPLACE INTO $dbase.`" . $table_prefix . "system_settings` (setting_name,setting_value) VALUES('site_id','$siteid'),('manager_theme','default')"); |
|
997
|
|
|
} else { |
|
998
|
|
|
// update site_id if missing |
|
999
|
|
|
$ds = mysqli_query($sqlParser->conn, "SELECT setting_name,setting_value FROM $dbase.`" . $table_prefix . "system_settings` WHERE setting_name='site_id'"); |
|
1000
|
|
|
if ($ds) { |
|
1001
|
|
|
$r = mysqli_fetch_assoc($ds); |
|
1002
|
|
|
$siteid = $r['setting_value']; |
|
1003
|
|
|
if ($siteid == '' || $siteid = 'MzGeQ2faT4Dw06+U49x3') { |
|
1004
|
|
|
$siteid = uniqid(''); |
|
1005
|
|
|
mysqli_query($sqlParser->conn, "REPLACE INTO $dbase.`" . $table_prefix . "system_settings` (setting_name,setting_value) VALUES('site_id','$siteid')"); |
|
1006
|
|
|
} |
|
1007
|
|
|
} |
|
1008
|
|
|
} |
|
1009
|
|
|
|
|
1010
|
|
|
// Reset database for installation of demo-site |
|
1011
|
|
|
if ($installData && $moduleSQLDataFile && $moduleSQLResetFile) { |
|
1012
|
|
|
echo $_lang['resetting_database']; |
|
1013
|
|
|
$sqlParser->process($moduleSQLResetFile); |
|
1014
|
|
|
// display database results |
|
1015
|
|
|
if ($sqlParser->installFailed == true) { |
|
1016
|
|
|
$errors += 1; |
|
1017
|
|
|
echo $_lang['database_alerts'] . PHP_EOL; |
|
1018
|
|
|
echo $_lang['setup_couldnt_install'] . PHP_EOL; |
|
1019
|
|
|
echo $_lang['installation_error_occured'] . PHP_EOL . PHP_EOL; |
|
1020
|
|
|
/* |
|
1021
|
|
|
for ($i = 0; $i < count($sqlParser->mysqlErrors); $i++) { |
|
1022
|
|
|
echo "<em>" . $sqlParser->mysqlErrors[$i]["error"] . "</em>" . $_lang['during_execution_of_sql'] . "<span class='mono'>" . strip_tags($sqlParser->mysqlErrors[$i]["sql"]) . "</span>.<hr />"; |
|
1023
|
|
|
} |
|
1024
|
|
|
echo "</p>";*/ |
|
1025
|
|
|
echo $_lang['some_tables_not_updated'] . PHP_EOL; |
|
1026
|
|
|
die(); |
|
1027
|
|
|
} else { |
|
1028
|
|
|
echo $_lang['ok'] . PHP_EOL; |
|
1029
|
|
|
} |
|
1030
|
|
|
} |
|
1031
|
|
|
|
|
1032
|
|
|
// Install Templates |
|
1033
|
|
|
$moduleTemplate = $mt; |
|
1034
|
|
|
if (!empty($moduleTemplate) || $installData) { |
|
1035
|
|
|
echo PHP_EOL . $_lang['templates'] . ":" . PHP_EOL; |
|
1036
|
|
|
//$selTemplates = $_POST['template']; |
|
1037
|
|
|
foreach ($moduleTemplates as $k=>$moduleTemplate) { |
|
1038
|
|
|
$installSample = in_array('sample', $moduleTemplate[6]) && $installData == 1; |
|
1039
|
|
|
if($installSample || is_array($moduleTemplate)) { |
|
1040
|
|
|
$name = mysqli_real_escape_string($conn, $moduleTemplate[0]); |
|
1041
|
|
|
$desc = mysqli_real_escape_string($conn, $moduleTemplate[1]); |
|
1042
|
|
|
$category = mysqli_real_escape_string($conn, $moduleTemplate[4]); |
|
1043
|
|
|
$locked = mysqli_real_escape_string($conn, $moduleTemplate[5]); |
|
1044
|
|
|
$filecontent = $moduleTemplate[3]; |
|
1045
|
|
|
$save_sql_id_as = $moduleTemplate[7]; // Nessecary for demo-site |
|
1046
|
|
|
if (!file_exists($filecontent)) { |
|
1047
|
|
|
echo " $name: " . $_lang['unable_install_template'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL; |
|
1048
|
|
|
} else { |
|
1049
|
|
|
// Create the category if it does not already exist |
|
1050
|
|
|
$category_id = getCreateDbCategory($category, $sqlParser); |
|
1051
|
|
|
|
|
1052
|
|
|
// Strip the first comment up top |
|
1053
|
|
|
$template = preg_replace("/^.*?\/\*\*.*?\*\/\s+/s", '', file_get_contents($filecontent), 1); |
|
1054
|
|
|
$template = mysqli_real_escape_string($conn, $template); |
|
1055
|
|
|
|
|
1056
|
|
|
// See if the template already exists |
|
1057
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT * FROM $dbase.`" . $table_prefix . "site_templates` WHERE templatename='$name'"); |
|
1058
|
|
|
|
|
1059
|
|
|
if (mysqli_num_rows($rs)) { |
|
1060
|
|
|
if (!mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_templates` SET content='$template', description='$desc', category=$category_id, locked='$locked' WHERE templatename='$name' LIMIT 1;")) { |
|
1061
|
|
|
$errors += 1; |
|
1062
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1063
|
|
|
return; |
|
1064
|
|
|
} |
|
1065
|
|
View Code Duplication |
if(!is_null($save_sql_id_as)) { |
|
1066
|
|
|
$sql_id = @mysqli_insert_id($sqlParser->conn); |
|
1067
|
|
|
if(!$sql_id) { |
|
1068
|
|
|
$idQuery = mysqli_fetch_assoc(mysqli_query($sqlParser->conn, "SELECT id FROM $dbase.`" . $table_prefix . "site_templates` WHERE templatename='$name' LIMIT 1;")); |
|
1069
|
|
|
$sql_id = $idQuery['id']; |
|
1070
|
|
|
} |
|
1071
|
|
|
$custom_placeholders[$save_sql_id_as] = $sql_id; |
|
1072
|
|
|
} |
|
1073
|
|
|
echo " $name: " . $_lang['upgraded'] . PHP_EOL; |
|
1074
|
|
|
} else { |
|
1075
|
|
|
if (!@ mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_templates` (templatename,description,content,category,locked) VALUES('$name','$desc','$template',$category_id,'$locked');")) { |
|
1076
|
|
|
$errors += 1; |
|
1077
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1078
|
|
|
die(); |
|
1079
|
|
|
} |
|
1080
|
|
|
if(!is_null($save_sql_id_as)) $custom_placeholders[$save_sql_id_as] = @mysqli_insert_id($sqlParser->conn); |
|
1081
|
|
|
echo " $name: " . $_lang['installed'] . PHP_EOL; |
|
1082
|
|
|
} |
|
1083
|
|
|
} |
|
1084
|
|
|
} |
|
1085
|
|
|
} |
|
1086
|
|
|
} |
|
1087
|
|
|
|
|
1088
|
|
|
// Install Template Variables |
|
1089
|
|
|
$moduleTVs = $mtv; |
|
1090
|
|
|
if (is_array($moduleTVs) || $installData) { |
|
1091
|
|
|
echo PHP_EOL . $_lang['tvs'].': '.PHP_EOL; |
|
1092
|
|
|
//$selTVs = $_POST['tv']; |
|
1093
|
|
|
foreach ($moduleTVs as $k=>$moduleTV) { |
|
1094
|
|
|
$installSample = in_array('sample', $moduleTV[12]) && $installData == 1; |
|
1095
|
|
|
if($installSample || is_array($moduleTVs)) { |
|
1096
|
|
|
$name = mysqli_real_escape_string($conn, $moduleTV[0]); |
|
1097
|
|
|
$caption = mysqli_real_escape_string($conn, $moduleTV[1]); |
|
1098
|
|
|
$desc = mysqli_real_escape_string($conn, $moduleTV[2]); |
|
1099
|
|
|
$input_type = mysqli_real_escape_string($conn, $moduleTV[3]); |
|
1100
|
|
|
$input_options = mysqli_real_escape_string($conn, $moduleTV[4]); |
|
1101
|
|
|
$input_default = mysqli_real_escape_string($conn, $moduleTV[5]); |
|
1102
|
|
|
$output_widget = mysqli_real_escape_string($conn, $moduleTV[6]); |
|
1103
|
|
|
$output_widget_params = mysqli_real_escape_string($conn, $moduleTV[7]); |
|
1104
|
|
|
$filecontent = $moduleTV[8]; |
|
1105
|
|
|
$assignments = $moduleTV[9]; |
|
1106
|
|
|
$category = mysqli_real_escape_string($conn, $moduleTV[10]); |
|
1107
|
|
|
$locked = mysqli_real_escape_string($conn, $moduleTV[11]); |
|
1108
|
|
|
|
|
1109
|
|
|
|
|
1110
|
|
|
// Create the category if it does not already exist |
|
1111
|
|
|
$category = getCreateDbCategory($category, $sqlParser); |
|
1112
|
|
|
|
|
1113
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT * FROM $dbase.`" . $table_prefix . "site_tmplvars` WHERE name='$name'"); |
|
1114
|
|
|
if (mysqli_num_rows($rs)) { |
|
1115
|
|
|
$insert = true; |
|
1116
|
|
View Code Duplication |
while($row = mysqli_fetch_assoc($rs)) { |
|
1117
|
|
|
if (!mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_tmplvars` SET type='$input_type', caption='$caption', description='$desc', category=$category, locked=$locked, elements='$input_options', display='$output_widget', display_params='$output_widget_params', default_text='$input_default' WHERE id={$row['id']};")) { |
|
1118
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1119
|
|
|
return; |
|
1120
|
|
|
} |
|
1121
|
|
|
$insert = false; |
|
1122
|
|
|
} |
|
1123
|
|
|
echo " $name: " . $_lang['upgraded'] . PHP_EOL; |
|
1124
|
|
|
} else { |
|
1125
|
|
|
$q = "INSERT INTO $dbase.`" . $table_prefix . "site_tmplvars` (type,name,caption,description,category,locked,elements,display,display_params,default_text) VALUES('$input_type','$name','$caption','$desc',$category,$locked,'$input_options','$output_widget','$output_widget_params','$input_default');"; |
|
1126
|
|
View Code Duplication |
if (!mysqli_query($sqlParser->conn, $q)) { |
|
1127
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1128
|
|
|
return; |
|
1129
|
|
|
} |
|
1130
|
|
|
echo " $name: " . $_lang['installed'] . PHP_EOL; |
|
1131
|
|
|
} |
|
1132
|
|
|
|
|
1133
|
|
|
// add template assignments |
|
1134
|
|
|
$assignments = explode(',', $assignments); |
|
1135
|
|
|
|
|
1136
|
|
View Code Duplication |
if (count($assignments) > 0) { |
|
1137
|
|
|
|
|
1138
|
|
|
// remove existing tv -> template assignments |
|
1139
|
|
|
$ds=mysqli_query($sqlParser->conn, "SELECT id FROM $dbase.`".$table_prefix."site_tmplvars` WHERE name='$name' AND description='$desc';"); |
|
1140
|
|
|
$row = mysqli_fetch_assoc($ds); |
|
1141
|
|
|
$id = $row["id"]; |
|
1142
|
|
|
mysqli_query($sqlParser->conn, 'DELETE FROM ' . $dbase . '.`' . $table_prefix . 'site_tmplvar_templates` WHERE tmplvarid = \'' . $id . '\''); |
|
1143
|
|
|
|
|
1144
|
|
|
// add tv -> template assignments |
|
1145
|
|
|
foreach ($assignments as $assignment) { |
|
1146
|
|
|
$template = mysqli_real_escape_string($conn, $assignment); |
|
1147
|
|
|
$ts = mysqli_query($sqlParser->conn, "SELECT id FROM $dbase.`".$table_prefix."site_templates` WHERE templatename='$template';"); |
|
1148
|
|
|
if ($ds && $ts) { |
|
1149
|
|
|
$tRow = mysqli_fetch_assoc($ts); |
|
1150
|
|
|
$templateId = $tRow['id']; |
|
1151
|
|
|
mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_tmplvar_templates` (tmplvarid, templateid) VALUES($id, $templateId)"); |
|
1152
|
|
|
} |
|
1153
|
|
|
} |
|
1154
|
|
|
} |
|
1155
|
|
|
} |
|
1156
|
|
|
} |
|
1157
|
|
|
} |
|
1158
|
|
|
|
|
1159
|
|
|
|
|
1160
|
|
|
$moduleChunks = $mc; |
|
1161
|
|
|
// Install Chunks |
|
1162
|
|
|
if (is_array ($moduleChunks) || $installData) { |
|
1163
|
|
|
echo PHP_EOL . $_lang['chunks'] . ": " . PHP_EOL; |
|
1164
|
|
|
foreach ($moduleChunks as $k=>$moduleChunk) { |
|
1165
|
|
|
$installSample = in_array('sample', $moduleChunk[5]) && $installData == 1; |
|
1166
|
|
|
$count_new_name = 0; |
|
1167
|
|
|
if($installSample || is_array ($moduleChunks)) { |
|
1168
|
|
|
|
|
1169
|
|
|
$name = mysqli_real_escape_string($conn, $moduleChunk[0]); |
|
1170
|
|
|
$desc = mysqli_real_escape_string($conn, $moduleChunk[1]); |
|
1171
|
|
|
$category = mysqli_real_escape_string($conn, $moduleChunk[3]); |
|
1172
|
|
|
$overwrite = mysqli_real_escape_string($conn, $moduleChunk[4]); |
|
1173
|
|
|
$filecontent = $moduleChunk[2]; |
|
1174
|
|
|
|
|
1175
|
|
|
if (!file_exists($filecontent)) |
|
1176
|
|
|
echo " $name: " . $_lang['unable_install_chunk'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL; |
|
1177
|
|
|
else { |
|
1178
|
|
|
|
|
1179
|
|
|
// Create the category if it does not already exist |
|
1180
|
|
|
$category_id = getCreateDbCategory($category, $sqlParser); |
|
1181
|
|
|
|
|
1182
|
|
|
$chunk = preg_replace("/^.*?\/\*\*.*?\*\/\s+/s", '', file_get_contents($filecontent), 1); |
|
1183
|
|
|
$chunk = mysqli_real_escape_string($conn, $chunk); |
|
1184
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT * FROM $dbase.`" . $table_prefix . "site_htmlsnippets` WHERE name='$name'"); |
|
1185
|
|
|
$count_original_name = mysqli_num_rows($rs); |
|
1186
|
|
View Code Duplication |
if($overwrite == 'false') { |
|
1187
|
|
|
$newname = $name . '-' . str_replace('.', '_', $modx_version); |
|
1188
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT * FROM $dbase.`" . $table_prefix . "site_htmlsnippets` WHERE name='$newname'"); |
|
1189
|
|
|
$count_new_name = mysqli_num_rows($rs); |
|
1190
|
|
|
} |
|
1191
|
|
|
$update = $count_original_name > 0 && $overwrite == 'true'; |
|
1192
|
|
|
if ($update) { |
|
1193
|
|
|
if (!mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_htmlsnippets` SET snippet='$chunk', description='$desc', category=$category_id WHERE name='$name';")) { |
|
1194
|
|
|
$errors += 1; |
|
1195
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1196
|
|
|
return; |
|
1197
|
|
|
} |
|
1198
|
|
|
echo " $name: " . $_lang['upgraded'] . PHP_EOL; |
|
1199
|
|
|
} elseif($count_new_name == 0) { |
|
1200
|
|
|
if($count_original_name > 0 && $overwrite == 'false') { |
|
1201
|
|
|
$name = $newname; |
|
1202
|
|
|
} |
|
1203
|
|
|
if (!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_htmlsnippets` (name,description,snippet,category) VALUES('$name','$desc','$chunk',$category_id);")) { |
|
1204
|
|
|
$errors += 1; |
|
1205
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1206
|
|
|
return; |
|
1207
|
|
|
} |
|
1208
|
|
|
echo " $name: " . $_lang['installed'] . PHP_EOL; |
|
1209
|
|
|
} |
|
1210
|
|
|
} |
|
1211
|
|
|
} |
|
1212
|
|
|
} |
|
1213
|
|
|
} |
|
1214
|
|
|
|
|
1215
|
|
|
// Install Modules |
|
1216
|
|
|
$moduleModules = $mm; |
|
1217
|
|
|
if (is_array($moduleModules) || $installData) { |
|
1218
|
|
|
echo PHP_EOL . $_lang['modules'] . ":" . PHP_EOL; |
|
1219
|
|
|
//$selModules = $_POST['module']; |
|
1220
|
|
|
foreach ($moduleModules as $k=>$moduleModule) { |
|
1221
|
|
|
$installSample = in_array('sample', $moduleModule[7]) && $installData == 1; |
|
1222
|
|
|
if($installSample || is_array($moduleModules)) { |
|
1223
|
|
|
$name = mysqli_real_escape_string($conn, $moduleModule[0]); |
|
1224
|
|
|
$desc = mysqli_real_escape_string($conn, $moduleModule[1]); |
|
1225
|
|
|
$filecontent = $moduleModule[2]; |
|
1226
|
|
|
$properties = $moduleModule[3]; |
|
1227
|
|
|
$guid = mysqli_real_escape_string($conn, $moduleModule[4]); |
|
1228
|
|
|
$shared = mysqli_real_escape_string($conn, $moduleModule[5]); |
|
1229
|
|
|
$category = mysqli_real_escape_string($conn, $moduleModule[6]); |
|
1230
|
|
|
if (!file_exists($filecontent)) |
|
1231
|
|
|
echo " $name: " . $_lang['unable_install_module'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL; |
|
1232
|
|
|
else { |
|
1233
|
|
|
|
|
1234
|
|
|
// Create the category if it does not already exist |
|
1235
|
|
|
$category = getCreateDbCategory($category, $sqlParser); |
|
1236
|
|
|
|
|
1237
|
|
|
$module = end(preg_split("/(\/\/)?\s*\<\?php/", file_get_contents($filecontent), 2)); |
|
|
|
|
|
|
1238
|
|
|
// $module = removeDocblock($module, 'module'); // Modules have no fileBinding, keep docblock for info-tab |
|
1239
|
|
|
$module = mysqli_real_escape_string($conn, $module); |
|
1240
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT * FROM $dbase.`" . $table_prefix . "site_modules` WHERE name='$name'"); |
|
1241
|
|
|
if (mysqli_num_rows($rs)) { |
|
1242
|
|
|
$row = mysqli_fetch_assoc($rs); |
|
1243
|
|
|
$props = mysqli_real_escape_string($conn, propUpdate($properties,$row['properties'])); |
|
1244
|
|
|
if (!mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_modules` SET modulecode='$module', description='$desc', properties='$props', enable_sharedparams='$shared' WHERE name='$name';")) { |
|
1245
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1246
|
|
|
return; |
|
1247
|
|
|
} |
|
1248
|
|
|
echo " $name: " . $_lang['upgraded'] . PHP_EOL; |
|
1249
|
|
|
} else { |
|
1250
|
|
|
if ($properties != NULL ){ |
|
1251
|
|
|
$properties = mysqli_real_escape_string($conn, parseProperties($properties, true)); |
|
|
|
|
|
|
1252
|
|
|
} |
|
1253
|
|
|
if (!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_modules` (name,description,modulecode,properties,guid,enable_sharedparams,category) VALUES('$name','$desc','$module','$properties','$guid','$shared', $category);")) { |
|
1254
|
|
|
echo "<p>" . mysqli_error($sqlParser->conn) . "</p>"; |
|
1255
|
|
|
return; |
|
1256
|
|
|
} |
|
1257
|
|
|
echo " $name: " . $_lang['installed'] . PHP_EOL; |
|
1258
|
|
|
} |
|
1259
|
|
|
} |
|
1260
|
|
|
} |
|
1261
|
|
|
} |
|
1262
|
|
|
} |
|
1263
|
|
|
|
|
1264
|
|
|
// Install Plugins |
|
1265
|
|
|
$modulePlugins = $mp; |
|
1266
|
|
|
if (is_array($modulePlugins) || $installData) { |
|
1267
|
|
|
echo PHP_EOL . $_lang['plugins'] . ":" . PHP_EOL; |
|
1268
|
|
|
$selPlugs = $_POST['plugin']; |
|
1269
|
|
|
foreach ($modulePlugins as $k=>$modulePlugin) { |
|
1270
|
|
|
//$installSample = in_array('sample', $modulePlugin[8]) && $installData == 1; |
|
1271
|
|
|
if($installSample || is_array($modulePlugins)) { |
|
1272
|
|
|
$name = mysqli_real_escape_string($conn, $modulePlugin[0]); |
|
1273
|
|
|
$desc = mysqli_real_escape_string($conn, $modulePlugin[1]); |
|
1274
|
|
|
$filecontent = $modulePlugin[2]; |
|
1275
|
|
|
$properties = $modulePlugin[3]; |
|
1276
|
|
|
$events = explode(",", $modulePlugin[4]); |
|
1277
|
|
|
$guid = mysqli_real_escape_string($conn, $modulePlugin[5]); |
|
1278
|
|
|
$category = mysqli_real_escape_string($conn, $modulePlugin[6]); |
|
1279
|
|
|
$leg_names = ''; |
|
1280
|
|
|
$disabled = $modulePlugin[9]; |
|
1281
|
|
View Code Duplication |
if(array_key_exists(7, $modulePlugin)) { |
|
1282
|
|
|
// parse comma-separated legacy names and prepare them for sql IN clause |
|
1283
|
|
|
$leg_names = "'" . implode("','", preg_split('/\s*,\s*/', mysqli_real_escape_string($conn, $modulePlugin[7]))) . "'"; |
|
1284
|
|
|
} |
|
1285
|
|
|
if (!file_exists($filecontent)) |
|
1286
|
|
|
echo " $name: " . $_lang['unable_install_plugin'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL; |
|
1287
|
|
|
else { |
|
1288
|
|
|
|
|
1289
|
|
|
// disable legacy versions based on legacy_names provided |
|
1290
|
|
View Code Duplication |
if(!empty($leg_names)) { |
|
1291
|
|
|
$update_query = "UPDATE $dbase.`" . $table_prefix . "site_plugins` SET disabled='1' WHERE name IN ($leg_names);"; |
|
1292
|
|
|
$rs = mysqli_query($sqlParser->conn, $update_query); |
|
1293
|
|
|
} |
|
1294
|
|
|
|
|
1295
|
|
|
// Create the category if it does not already exist |
|
1296
|
|
|
$category = getCreateDbCategory($category, $sqlParser); |
|
1297
|
|
|
|
|
1298
|
|
|
$plugin = end(preg_split("/(\/\/)?\s*\<\?php/", file_get_contents($filecontent), 2)); |
|
|
|
|
|
|
1299
|
|
|
$plugin = removeDocblock($plugin, 'plugin'); |
|
1300
|
|
|
$plugin = mysqli_real_escape_string($conn, $plugin); |
|
1301
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT * FROM $dbase.`" . $table_prefix . "site_plugins` WHERE name='$name'"); |
|
1302
|
|
|
if (mysqli_num_rows($rs)) { |
|
1303
|
|
|
$insert = true; |
|
1304
|
|
|
while($row = mysqli_fetch_assoc($rs)) { |
|
1305
|
|
|
$props = mysqli_real_escape_string($conn, propUpdate($properties,$row['properties'])); |
|
1306
|
|
|
if($row['description'] == $desc){ |
|
1307
|
|
|
if (! mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_plugins` SET plugincode='$plugin', description='$desc', properties='$props' WHERE id={$row['id']};")) { |
|
1308
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1309
|
|
|
return; |
|
1310
|
|
|
} |
|
1311
|
|
|
$insert = false; |
|
1312
|
|
View Code Duplication |
} else { |
|
1313
|
|
|
if (!mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_plugins` SET disabled='1' WHERE id={$row['id']};")) { |
|
1314
|
|
|
echo mysqli_error($sqlParser->conn).PHP_EOL; |
|
1315
|
|
|
return; |
|
1316
|
|
|
} |
|
1317
|
|
|
} |
|
1318
|
|
|
} |
|
1319
|
|
View Code Duplication |
if($insert === true) { |
|
1320
|
|
|
$properties = mysqli_real_escape_string($conn, propUpdate($properties,$row['properties'])); |
|
1321
|
|
|
if(!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`".$table_prefix."site_plugins` (name,description,plugincode,properties,moduleguid,disabled,category) VALUES('$name','$desc','$plugin','$properties','$guid','0',$category);")) { |
|
1322
|
|
|
echo mysqli_error($sqlParser->conn).PHP_EOL; |
|
1323
|
|
|
return; |
|
1324
|
|
|
} |
|
1325
|
|
|
} |
|
1326
|
|
|
echo " $name: " . $_lang['upgraded'] . PHP_EOL; |
|
1327
|
|
View Code Duplication |
} else { |
|
1328
|
|
|
if ($properties != NULL ){ |
|
1329
|
|
|
$properties = mysqli_real_escape_string($conn, parseProperties($properties, true)); |
|
|
|
|
|
|
1330
|
|
|
} |
|
1331
|
|
|
if (!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_plugins` (name,description,plugincode,properties,moduleguid,category,disabled) VALUES('$name','$desc','$plugin','$properties','$guid',$category,$disabled);")) { |
|
1332
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1333
|
|
|
return; |
|
1334
|
|
|
} |
|
1335
|
|
|
echo " $name: " . $_lang['installed'] . PHP_EOL; |
|
1336
|
|
|
} |
|
1337
|
|
|
// add system events |
|
1338
|
|
View Code Duplication |
if (count($events) > 0) { |
|
1339
|
|
|
$ds=mysqli_query($sqlParser->conn, "SELECT id FROM $dbase.`".$table_prefix."site_plugins` WHERE name='$name' AND description='$desc';"); |
|
1340
|
|
|
if ($ds) { |
|
1341
|
|
|
$row = mysqli_fetch_assoc($ds); |
|
1342
|
|
|
$id = $row["id"]; |
|
1343
|
|
|
// remove existing events |
|
1344
|
|
|
mysqli_query($sqlParser->conn, 'DELETE FROM ' . $dbase . '.`' . $table_prefix . 'site_plugin_events` WHERE pluginid = \'' . $id . '\''); |
|
1345
|
|
|
// add new events |
|
1346
|
|
|
mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_plugin_events` (pluginid, evtid) SELECT '$id' as 'pluginid',se.id as 'evtid' FROM $dbase.`" . $table_prefix . "system_eventnames` se WHERE name IN ('" . implode("','", $events) . "')"); |
|
1347
|
|
|
} |
|
1348
|
|
|
} |
|
1349
|
|
|
} |
|
1350
|
|
|
} |
|
1351
|
|
|
} |
|
1352
|
|
|
} |
|
1353
|
|
|
|
|
1354
|
|
|
// Install Snippets |
|
1355
|
|
|
$moduleSnippet = $ms; |
|
1356
|
|
|
if (is_array($moduleSnippet) || $installData) { |
|
1357
|
|
|
echo PHP_EOL . $_lang['snippets'] . ":" . PHP_EOL; |
|
1358
|
|
|
//$selSnips = $_POST['snippet']; |
|
1359
|
|
|
foreach ($moduleSnippets as $k=>$moduleSnippet) { |
|
1360
|
|
|
$installSample = in_array('sample', $moduleSnippet[5]) && $installData == 1; |
|
1361
|
|
|
if($installSample || is_array($moduleSnippet)) { |
|
1362
|
|
|
$name = mysqli_real_escape_string($conn, $moduleSnippet[0]); |
|
1363
|
|
|
$desc = mysqli_real_escape_string($conn, $moduleSnippet[1]); |
|
1364
|
|
|
$filecontent = $moduleSnippet[2]; |
|
1365
|
|
|
$properties = $moduleSnippet[3]; |
|
1366
|
|
|
$category = mysqli_real_escape_string($conn, $moduleSnippet[4]); |
|
1367
|
|
|
if (!file_exists($filecontent)) |
|
1368
|
|
|
echo " $name: " . $_lang['unable_install_snippet'] . " '$filecontent' " . $_lang['not_found'] . PHP_EOL; |
|
1369
|
|
|
else { |
|
1370
|
|
|
|
|
1371
|
|
|
// Create the category if it does not already exist |
|
1372
|
|
|
$category = getCreateDbCategory($category, $sqlParser); |
|
1373
|
|
|
|
|
1374
|
|
|
$snippet = end(preg_split("/(\/\/)?\s*\<\?php/", file_get_contents($filecontent))); |
|
|
|
|
|
|
1375
|
|
|
$snippet = removeDocblock($snippet, 'snippet'); |
|
1376
|
|
|
$snippet = mysqli_real_escape_string($conn, $snippet); |
|
1377
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT * FROM $dbase.`" . $table_prefix . "site_snippets` WHERE name='$name'"); |
|
1378
|
|
|
if (mysqli_num_rows($rs)) { |
|
1379
|
|
|
$row = mysqli_fetch_assoc($rs); |
|
1380
|
|
|
$props = mysqli_real_escape_string($conn, propUpdate($properties,$row['properties'])); |
|
1381
|
|
|
if (!mysqli_query($sqlParser->conn, "UPDATE $dbase.`" . $table_prefix . "site_snippets` SET snippet='$snippet', description='$desc', properties='$props' WHERE name='$name';")) { |
|
1382
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1383
|
|
|
return; |
|
1384
|
|
|
} |
|
1385
|
|
|
echo " $name: " . $_lang['upgraded'] . PHP_EOL; |
|
1386
|
|
View Code Duplication |
} else { |
|
1387
|
|
|
if ($properties != NULL ){ |
|
1388
|
|
|
$properties = mysqli_real_escape_string($conn, parseProperties($properties, true)); |
|
|
|
|
|
|
1389
|
|
|
} |
|
1390
|
|
|
if (!mysqli_query($sqlParser->conn, "INSERT INTO $dbase.`" . $table_prefix . "site_snippets` (name,description,snippet,properties,category) VALUES('$name','$desc','$snippet','$properties',$category);")) { |
|
1391
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1392
|
|
|
return; |
|
1393
|
|
|
} |
|
1394
|
|
|
echo " $name: " . $_lang['installed'] . PHP_EOL; |
|
1395
|
|
|
} |
|
1396
|
|
|
} |
|
1397
|
|
|
} |
|
1398
|
|
|
} |
|
1399
|
|
|
} |
|
1400
|
|
|
|
|
1401
|
|
|
// Install demo-site |
|
1402
|
|
|
if ($installData && $moduleSQLDataFile) { |
|
1403
|
|
|
echo PHP_EOL . $_lang['installing_demo_site']; |
|
1404
|
|
|
$sqlParser->process($moduleSQLDataFile); |
|
1405
|
|
|
// display database results |
|
1406
|
|
|
if ($sqlParser->installFailed == true) { |
|
1407
|
|
|
$errors += 1; |
|
1408
|
|
|
echo $_lang['database_alerts'] . PHP_EOL; |
|
1409
|
|
|
echo $_lang['setup_couldnt_install'] . PHP_EOL; |
|
1410
|
|
|
echo $_lang['installation_error_occured'] . PHP_EOL . PHP_EOL; |
|
1411
|
|
|
for ($i = 0; $i < count($sqlParser->mysqlErrors); $i++) { |
|
1412
|
|
|
echo $sqlParser->mysqlErrors[$i]["error"] . " " . $_lang['during_execution_of_sql'] . " " . strip_tags($sqlParser->mysqlErrors[$i]["sql"]) . PHP_EOL; |
|
1413
|
|
|
} |
|
1414
|
|
|
|
|
1415
|
|
|
echo $_lang['some_tables_not_updated'] . PHP_EOL; |
|
1416
|
|
|
return; |
|
1417
|
|
View Code Duplication |
} else { |
|
1418
|
|
|
$sql = sprintf("SELECT id FROM `%ssite_templates` WHERE templatename='EVO startup - Bootstrap'", $sqlParser->prefix); |
|
1419
|
|
|
$rs = mysqli_query($sqlParser->conn, $sql); |
|
1420
|
|
|
if(mysqli_num_rows($rs)) { |
|
1421
|
|
|
$row = mysqli_fetch_assoc($rs); |
|
1422
|
|
|
$sql = sprintf('UPDATE `%ssite_content` SET template=%s WHERE template=4', $sqlParser->prefix, $row['id']); |
|
1423
|
|
|
mysqli_query($sqlParser->conn, $sql); |
|
1424
|
|
|
} |
|
1425
|
|
|
echo $_lang['ok'].PHP_EOL; |
|
1426
|
|
|
} |
|
1427
|
|
|
} |
|
1428
|
|
|
|
|
1429
|
|
|
// Install Dependencies |
|
1430
|
|
|
$moduleDependencies = $mdp; |
|
1431
|
|
|
foreach ($moduleDependencies as $dependency) { |
|
1432
|
|
|
$ds = mysqli_query($sqlParser->conn, 'SELECT id, guid FROM ' . $dbase . '`' . $sqlParser->prefix . 'site_modules` WHERE name="' . $dependency['module'] . '"'); |
|
1433
|
|
View Code Duplication |
if (!$ds) { |
|
1434
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1435
|
|
|
return; |
|
1436
|
|
|
} else { |
|
1437
|
|
|
$row = mysqli_fetch_assoc($ds); |
|
1438
|
|
|
$moduleId = $row["id"]; |
|
1439
|
|
|
$moduleGuid = $row["guid"]; |
|
1440
|
|
|
} |
|
1441
|
|
|
// get extra id |
|
1442
|
|
|
$ds = mysqli_query($sqlParser->conn, 'SELECT id FROM ' . $dbase . '`' . $sqlParser->prefix . 'site_' . $dependency['table'] . '` WHERE ' . $dependency['column'] . '="' . $dependency['name'] . '"'); |
|
1443
|
|
View Code Duplication |
if (!$ds) { |
|
1444
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1445
|
|
|
return; |
|
1446
|
|
|
} else { |
|
1447
|
|
|
$row = mysqli_fetch_assoc($ds); |
|
1448
|
|
|
$extraId = $row["id"]; |
|
1449
|
|
|
} |
|
1450
|
|
|
// setup extra as module dependency |
|
1451
|
|
|
$ds = mysqli_query($sqlParser->conn, 'SELECT module FROM ' . $dbase . '`' . $sqlParser->prefix . 'site_module_depobj` WHERE module=' . $moduleId . ' AND resource=' . $extraId . ' AND type=' . $dependency['type'] . ' LIMIT 1'); |
|
1452
|
|
|
if (!$ds) { |
|
1453
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1454
|
|
|
return; |
|
1455
|
|
|
} else { |
|
1456
|
|
|
if (mysqli_num_rows($ds) === 0) { |
|
1457
|
|
|
mysqli_query($sqlParser->conn, 'INSERT INTO ' . $dbase . '`' . $sqlParser->prefix . 'site_module_depobj` (module, resource, type) VALUES(' . $moduleId . ',' . $extraId . ',' . $dependency['type'] . ')'); |
|
1458
|
|
|
echo $dependency['module'] . ' Module: ' . $_lang['depedency_create'] . PHP_EOL; |
|
1459
|
|
View Code Duplication |
} else { |
|
1460
|
|
|
mysqli_query($sqlParser->conn, 'UPDATE ' . $dbase . '`' . $sqlParser->prefix . 'site_module_depobj` SET module = ' . $moduleId . ', resource = ' . $extraId . ', type = ' . $dependency['type'] . ' WHERE module=' . $moduleId . ' AND resource=' . $extraId . ' AND type=' . $dependency['type']); |
|
1461
|
|
|
echo $dependency['module'] . ' Module: ' . $_lang['depedency_update'] . PHP_EOL; |
|
1462
|
|
|
} |
|
1463
|
|
|
if ($dependency['type'] == 30 || $dependency['type'] == 40) { |
|
1464
|
|
|
// set extra guid for plugins and snippets |
|
1465
|
|
|
$ds = mysqli_query($sqlParser->conn, 'SELECT id FROM ' . $dbase . '`' . $sqlParser->prefix . 'site_' . $dependency['table'] . '` WHERE id=' . $extraId . ' LIMIT 1'); |
|
1466
|
|
|
if (!$ds) { |
|
1467
|
|
|
echo mysqli_error($sqlParser->conn) . PHP_EOL; |
|
1468
|
|
|
return; |
|
1469
|
|
View Code Duplication |
} else { |
|
1470
|
|
|
if (mysqli_num_rows($ds) != 0) { |
|
1471
|
|
|
mysqli_query($sqlParser->conn, 'UPDATE ' . $dbase . '`' . $sqlParser->prefix . 'site_' . $dependency['table'] . '` SET moduleguid = ' . $moduleGuid . ' WHERE id=' . $extraId); |
|
1472
|
|
|
echo $dependency['name'] . ': ' . $_lang['guid_set'] . PHP_EOL; |
|
1473
|
|
|
} |
|
1474
|
|
|
} |
|
1475
|
|
|
} |
|
1476
|
|
|
} |
|
1477
|
|
|
} |
|
1478
|
|
|
|
|
1479
|
|
|
// call back function |
|
1480
|
|
|
if ($callBackFnc != "") |
|
1481
|
|
|
$callBackFnc ($sqlParser); |
|
1482
|
|
|
|
|
1483
|
|
|
// Setup the MODX API -- needed for the cache processor |
|
1484
|
|
|
if (!defined('MODX_MANAGER_PATH')) define('MODX_MANAGER_PATH', $base_path.MGR_DIR.'/'); |
|
1485
|
|
|
$database_type = 'mysqli'; |
|
1486
|
|
|
// initiate a new document parser |
|
1487
|
|
|
include_once($path.'../'.MGR_DIR.'/includes/document.parser.class.inc.php'); |
|
1488
|
|
|
$modx = new DocumentParser; |
|
1489
|
|
|
$modx->db->connect(); |
|
1490
|
|
|
// always empty cache after install |
|
1491
|
|
|
include_once $path."../".MGR_DIR."/processors/cache_sync.class.processor.php"; |
|
1492
|
|
|
$sync = new synccache(); |
|
1493
|
|
|
$sync->setCachepath($path."../assets/cache/"); |
|
1494
|
|
|
$sync->setReport(false); |
|
1495
|
|
|
$sync->emptyCache(); // first empty the cache |
|
1496
|
|
|
|
|
1497
|
|
|
// try to chmod the cache go-rwx (for suexeced php) |
|
1498
|
|
|
$chmodSuccess = @chmod($path.'../assets/cache/siteCache.idx.php', 0600); |
|
1499
|
|
|
$chmodSuccess = @chmod($path.'../assets/cache/sitePublishing.idx.php', 0600); |
|
1500
|
|
|
|
|
1501
|
|
|
// remove any locks on the manager functions so initial manager login is not blocked |
|
1502
|
|
|
mysqli_query($conn, "TRUNCATE TABLE `".$table_prefix."active_users`"); |
|
1503
|
|
|
|
|
1504
|
|
|
// close db connection |
|
1505
|
|
|
$sqlParser->close(); |
|
1506
|
|
|
|
|
1507
|
|
|
// andrazk 20070416 - release manager access |
|
1508
|
|
View Code Duplication |
if (file_exists($path.'../assets/cache/installProc.inc.php')) { |
|
1509
|
|
|
@chmod($path.'../assets/cache/installProc.inc.php', 0755); |
|
1510
|
|
|
unlink($path.'../assets/cache/installProc.inc.php'); |
|
1511
|
|
|
} |
|
1512
|
|
|
|
|
1513
|
|
|
// setup completed! |
|
1514
|
|
|
echo PHP_EOL . $_lang['installation_successful'] . PHP_EOL . PHP_EOL; |
|
1515
|
|
|
//echo "<p>" . $_lang['to_log_into_content_manager'] . "</p>"; |
|
1516
|
|
|
if ($installMode == 0) { |
|
1517
|
|
|
echo strip_tags($_lang['installation_note']) . PHP_EOL; |
|
1518
|
|
|
} else { |
|
1519
|
|
|
echo strip_tags($_lang['upgrade_note']) . PHP_EOL; |
|
1520
|
|
|
} |
|
1521
|
|
|
|
|
1522
|
|
|
|
|
1523
|
|
|
if ( empty($args) ){ |
|
1524
|
|
|
echo PHP_EOL . 'Remove install folder?'.PHP_EOL; |
|
1525
|
|
|
$removeInstall = readline("Type 'y' or 'n' to continue: "); |
|
1526
|
|
|
} |
|
1527
|
|
|
//remove installFolder |
|
1528
|
|
|
if ($removeInstall == 'y') { |
|
1529
|
|
|
removeFolder($path); |
|
1530
|
|
|
removeFolder($base_path.'.tx'); |
|
1531
|
|
|
unlink($base_path.'README.md'); |
|
1532
|
|
|
echo 'Install folder deleted!'. PHP_EOL . PHP_EOL; |
|
1533
|
|
|
} |
|
1534
|
|
|
|
|
1535
|
|
|
/** |
|
1536
|
|
|
* RemoveFolder |
|
1537
|
|
|
* |
|
1538
|
|
|
* @param string $path |
|
1539
|
|
|
* @return string |
|
|
|
|
|
|
1540
|
|
|
*/ |
|
1541
|
|
|
function removeFolder($path) |
|
1542
|
|
|
{ |
|
1543
|
|
|
$dir = realpath($path); |
|
1544
|
|
|
if (!is_dir($dir)) { |
|
1545
|
|
|
return; |
|
1546
|
|
|
} |
|
1547
|
|
|
|
|
1548
|
|
|
$it = new RecursiveDirectoryIterator($dir); |
|
1549
|
|
|
$files = new RecursiveIteratorIterator($it, |
|
1550
|
|
|
RecursiveIteratorIterator::CHILD_FIRST); |
|
1551
|
|
|
foreach ($files as $file) { |
|
1552
|
|
|
if ($file->getFilename() === "." || $file->getFilename() === "..") { |
|
1553
|
|
|
continue; |
|
1554
|
|
|
} |
|
1555
|
|
|
if ($file->isDir()) { |
|
1556
|
|
|
rmdir($file->getRealPath()); |
|
1557
|
|
|
} else { |
|
1558
|
|
|
unlink($file->getRealPath()); |
|
1559
|
|
|
} |
|
1560
|
|
|
} |
|
1561
|
|
|
rmdir($dir); |
|
1562
|
|
|
} |
|
1563
|
|
|
|
|
1564
|
|
|
/** |
|
1565
|
|
|
* Property Update function |
|
1566
|
|
|
* |
|
1567
|
|
|
* @param string $new |
|
1568
|
|
|
* @param string $old |
|
1569
|
|
|
* @return string |
|
|
|
|
|
|
1570
|
|
|
*/ |
|
1571
|
|
View Code Duplication |
function propUpdate($new,$old){ |
|
|
|
|
|
|
1572
|
|
|
$newArr = parseProperties($new); |
|
1573
|
|
|
$oldArr = parseProperties($old); |
|
1574
|
|
|
foreach ($oldArr as $k => $v){ |
|
|
|
|
|
|
1575
|
|
|
if (isset($v['0']['options'])){ |
|
1576
|
|
|
$oldArr[$k]['0']['options'] = $newArr[$k]['0']['options']; |
|
1577
|
|
|
} |
|
1578
|
|
|
} |
|
1579
|
|
|
$return = $oldArr + $newArr; |
|
1580
|
|
|
$return = json_encode($return, JSON_UNESCAPED_UNICODE); |
|
|
|
|
|
|
1581
|
|
|
$return = ($return !== '[]') ? $return : ''; |
|
1582
|
|
|
return $return; |
|
1583
|
|
|
} |
|
1584
|
|
|
|
|
1585
|
|
|
/** |
|
1586
|
|
|
* @param string $propertyString |
|
1587
|
|
|
* @param bool|mixed $json |
|
1588
|
|
|
* @return string |
|
1589
|
|
|
*/ |
|
1590
|
|
View Code Duplication |
function parseProperties($propertyString, $json=false) { |
|
|
|
|
|
|
1591
|
|
|
$propertyString = str_replace('{}', '', $propertyString ); |
|
1592
|
|
|
$propertyString = str_replace('} {', ',', $propertyString ); |
|
1593
|
|
|
|
|
1594
|
|
|
if(empty($propertyString)) return array(); |
|
1595
|
|
|
if($propertyString=='{}' || $propertyString=='[]') return array(); |
|
1596
|
|
|
|
|
1597
|
|
|
$jsonFormat = isJson($propertyString, true); |
|
1598
|
|
|
$property = array(); |
|
1599
|
|
|
// old format |
|
1600
|
|
|
if ( $jsonFormat === false) { |
|
1601
|
|
|
$props= explode('&', $propertyString); |
|
1602
|
|
|
foreach ($props as $prop) { |
|
1603
|
|
|
$prop = trim($prop); |
|
1604
|
|
|
if($prop === '') { |
|
1605
|
|
|
continue; |
|
1606
|
|
|
} |
|
1607
|
|
|
|
|
1608
|
|
|
$arr = explode(';', $prop); |
|
1609
|
|
|
if( ! is_array($arr)) { |
|
1610
|
|
|
$arr = array(); |
|
1611
|
|
|
} |
|
1612
|
|
|
$key = explode('=', isset($arr[0]) ? $arr[0] : ''); |
|
1613
|
|
|
if( ! is_array($key) || empty($key[0])) { |
|
1614
|
|
|
continue; |
|
1615
|
|
|
} |
|
1616
|
|
|
|
|
1617
|
|
|
$property[$key[0]]['0']['label'] = isset($key[1]) ? trim($key[1]) : ''; |
|
1618
|
|
|
$property[$key[0]]['0']['type'] = isset($arr[1]) ? trim($arr[1]) : ''; |
|
1619
|
|
|
switch ($property[$key[0]]['0']['type']) { |
|
1620
|
|
|
case 'list': |
|
1621
|
|
|
case 'list-multi': |
|
1622
|
|
|
case 'checkbox': |
|
1623
|
|
|
case 'radio': |
|
1624
|
|
|
case 'menu': |
|
1625
|
|
|
$property[$key[0]]['0']['value'] = isset($arr[3]) ? trim($arr[3]) : ''; |
|
1626
|
|
|
$property[$key[0]]['0']['options'] = isset($arr[2]) ? trim($arr[2]) : ''; |
|
1627
|
|
|
$property[$key[0]]['0']['default'] = isset($arr[3]) ? trim($arr[3]) : ''; |
|
1628
|
|
|
break; |
|
1629
|
|
|
default: |
|
1630
|
|
|
$property[$key[0]]['0']['value'] = isset($arr[2]) ? trim($arr[2]) : ''; |
|
1631
|
|
|
$property[$key[0]]['0']['default'] = isset($arr[2]) ? trim($arr[2]) : ''; |
|
1632
|
|
|
} |
|
1633
|
|
|
$property[$key[0]]['0']['desc'] = ''; |
|
1634
|
|
|
|
|
1635
|
|
|
} |
|
1636
|
|
|
// new json-format |
|
1637
|
|
|
} else if(!empty($jsonFormat)){ |
|
1638
|
|
|
$property = $jsonFormat; |
|
1639
|
|
|
} |
|
1640
|
|
|
if ($json) { |
|
1641
|
|
|
$property = json_encode($property, JSON_UNESCAPED_UNICODE); |
|
|
|
|
|
|
1642
|
|
|
} |
|
1643
|
|
|
$property = ($property !== '[]') ? $property : ''; |
|
1644
|
|
|
return $property; |
|
1645
|
|
|
} |
|
1646
|
|
|
|
|
1647
|
|
|
/** |
|
1648
|
|
|
* @param string $string |
|
1649
|
|
|
* @param bool $returnData |
|
1650
|
|
|
* @return bool|mixed |
|
1651
|
|
|
*/ |
|
1652
|
|
|
function isJson($string, $returnData=false) { |
|
1653
|
|
|
$data = json_decode($string, true); |
|
1654
|
|
|
return (json_last_error() == JSON_ERROR_NONE) ? ($returnData ? $data : true) : false; |
|
1655
|
|
|
} |
|
1656
|
|
|
|
|
1657
|
|
|
/** |
|
1658
|
|
|
* @param string|int $category |
|
1659
|
|
|
* @param SqlParser $sqlParser |
|
1660
|
|
|
* @return int |
|
1661
|
|
|
*/ |
|
1662
|
|
View Code Duplication |
function getCreateDbCategory($category, $sqlParser) { |
|
|
|
|
|
|
1663
|
|
|
$dbase = $sqlParser->dbname; |
|
1664
|
|
|
$dbase = '`' . trim($dbase,'`') . '`'; |
|
1665
|
|
|
$table_prefix = $sqlParser->prefix; |
|
1666
|
|
|
$category_id = 0; |
|
1667
|
|
|
if(!empty($category)) { |
|
1668
|
|
|
$category = mysqli_real_escape_string($sqlParser->conn, $category); |
|
1669
|
|
|
$rs = mysqli_query($sqlParser->conn, "SELECT id FROM $dbase.`".$table_prefix."categories` WHERE category = '".$category."'"); |
|
1670
|
|
|
if(mysqli_num_rows($rs) && ($row = mysqli_fetch_assoc($rs))) { |
|
1671
|
|
|
$category_id = $row['id']; |
|
1672
|
|
|
} else { |
|
1673
|
|
|
$q = "INSERT INTO $dbase.`".$table_prefix."categories` (`category`) VALUES ('{$category}');"; |
|
1674
|
|
|
$rs = mysqli_query($sqlParser->conn, $q); |
|
1675
|
|
|
if($rs) { |
|
1676
|
|
|
$category_id = mysqli_insert_id($sqlParser->conn); |
|
1677
|
|
|
} |
|
1678
|
|
|
} |
|
1679
|
|
|
} |
|
1680
|
|
|
return $category_id; |
|
1681
|
|
|
} |
|
1682
|
|
|
|
|
1683
|
|
|
/** |
|
1684
|
|
|
* Remove installer Docblock only from components using plugin FileSource / fileBinding |
|
1685
|
|
|
* |
|
1686
|
|
|
* @param string $code |
|
1687
|
|
|
* @param string $type |
|
1688
|
|
|
* @return string |
|
1689
|
|
|
*/ |
|
1690
|
|
View Code Duplication |
function removeDocblock($code, $type) { |
|
|
|
|
|
|
1691
|
|
|
|
|
1692
|
|
|
$cleaned = preg_replace("/^.*?\/\*\*.*?\*\/\s+/s", '', $code, 1); |
|
1693
|
|
|
|
|
1694
|
|
|
// Procedure taken from plugin.filesource.php |
|
1695
|
|
|
switch($type) { |
|
1696
|
|
|
case 'snippet': |
|
1697
|
|
|
$elm_name = 'snippets'; |
|
1698
|
|
|
$include = 'return require'; |
|
1699
|
|
|
$count = 47; |
|
1700
|
|
|
break; |
|
1701
|
|
|
|
|
1702
|
|
|
case 'plugin': |
|
1703
|
|
|
$elm_name = 'plugins'; |
|
1704
|
|
|
$include = 'require'; |
|
1705
|
|
|
$count = 39; |
|
1706
|
|
|
break; |
|
1707
|
|
|
|
|
1708
|
|
|
default: |
|
1709
|
|
|
return $cleaned; |
|
1710
|
|
|
}; |
|
1711
|
|
|
if(substr(trim($cleaned),0,$count) == $include.' MODX_BASE_PATH.\'assets/'.$elm_name.'/') |
|
1712
|
|
|
return $cleaned; |
|
1713
|
|
|
|
|
1714
|
|
|
// fileBinding not found - return code incl docblock |
|
1715
|
|
|
return $code; |
|
1716
|
|
|
} |
|
1717
|
|
|
|
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignoreannotation.See also the PhpDoc documentation for @ignore.