1
|
<?php
|
2
|
|
3
|
// $Id: upgrade-script.php 719 2008-02-20 19:47:52Z doc $
|
4
|
|
5
|
/*
|
6
|
|
7
|
Website Baker Project <http://www.websitebaker.org/>
|
8
|
Copyright (C) 2004-2008, Ryan Djurovich
|
9
|
|
10
|
Website Baker is free software; you can redistribute it and/or modify
|
11
|
it under the terms of the GNU General Public License as published by
|
12
|
the Free Software Foundation; either version 2 of the License, or
|
13
|
(at your option) any later version.
|
14
|
|
15
|
Website Baker is distributed in the hope that it will be useful,
|
16
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
GNU General Public License for more details.
|
19
|
|
20
|
You should have received a copy of the GNU General Public License
|
21
|
along with Website Baker; if not, write to the Free Software
|
22
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
|
24
|
*/
|
25
|
|
26
|
/**
|
27
|
PHP ROUTINES FOR THE UPGRADE SCRIPT
|
28
|
**/
|
29
|
// this function checks the basic configurations of an existing WB intallation
|
30
|
function status_msg($message, $class='check', $element='span') {
|
31
|
// returns a status message
|
32
|
echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
|
33
|
}
|
34
|
|
35
|
function check_baseline_configuration() {
|
36
|
// check if config.php file exists and contains values
|
37
|
status_msg('config.php: ');
|
38
|
@include_once('config.php');
|
39
|
if(defined('WB_PATH')) {
|
40
|
status_msg('OK', 'ok');
|
41
|
} else {
|
42
|
// output error message and return error status
|
43
|
status_msg('FAILED', 'error');
|
44
|
status_msg('<strong>Error:</strong><br />No valid config.php found in: "<em>'
|
45
|
.dirname(__FILE__).'</em>"<br />Please check if this script is placed in the WB root directory '
|
46
|
.'and check/correct the config.php file before proceeding.<br /><br />You can not proceed before this error is fixed!!!'
|
47
|
, 'warning', 'div');
|
48
|
return -1;
|
49
|
}
|
50
|
|
51
|
// check if the WB 2.7 installation files were already uploaded via FTP
|
52
|
status_msg(', WB 2.7 core files uploaded: ');
|
53
|
@include_once(WB_PATH .'/framework/functions.php');
|
54
|
@include_once(WB_PATH .'/admin/interface/version.php');
|
55
|
if(defined('VERSION') && VERSION == '2.7'
|
56
|
&& function_exists('get_variable_content')
|
57
|
&& file_exists(WB_PATH .'/modules/menu_link/languages/DE.php')
|
58
|
&& file_exists(WB_PATH .'/modules/output_filter/filter-routines.php')
|
59
|
&& file_exists(WB_PATH .'/modules/captcha_control/languages/DE.php')
|
60
|
&& file_exists(WB_PATH .'/modules/jsadmin/jsadmin_backend_include.php')
|
61
|
&& file_exists(WB_PATH .'/admin/admintools/tool.php')
|
62
|
&& file_exists(WB_PATH .'/admin/interface/er_levels.php')) {
|
63
|
status_msg('OK','ok');
|
64
|
} else {
|
65
|
// output a warning and return error status
|
66
|
status_msg('FAILED','error');
|
67
|
status_msg('<strong>Error:</strong><br />Some of the Website Baker 2.7 core files were not found.'
|
68
|
.'<br />Please upload all core files (except config.php and folder /install) contained in the WB 2.7 installation package first.'
|
69
|
.'<br /><br />You can not proceed before this error is fixed!!!'
|
70
|
, 'warning', 'div');
|
71
|
return -1;
|
72
|
}
|
73
|
|
74
|
// check database connection (try to extract a single value which should always exist)
|
75
|
$group_id = '';
|
76
|
status_msg(', Database connection: ');
|
77
|
if(class_exists('database')) {
|
78
|
$db = new database;
|
79
|
$table = TABLE_PREFIX .'groups';
|
80
|
$group_id = @$db->get_one("SELECT group_id FROM $table WHERE group_id = '1' LIMIT 1");
|
81
|
}
|
82
|
if($group_id == '1') {
|
83
|
status_msg('OK', 'ok');
|
84
|
} else {
|
85
|
// output error message and return error status
|
86
|
status_msg('FAILED', 'error');
|
87
|
status_msg('<strong>Error:</strong><br />Unable to connect to your existing Website Baker database.'
|
88
|
.'<br />Make sure that the database class is available and the connection data in the config.php file is correct '
|
89
|
.'and your database is not corrupt.<br />To check if your database is corrupt, you can use a tool like '
|
90
|
.'<a href="http://www.phpmyadmin.net/" target="_blank">phpMyAdmin</a>.'
|
91
|
.'<br /><br />You can not proceed before this error is fixed!!!'
|
92
|
, 'warning', 'div');
|
93
|
return -1;
|
94
|
}
|
95
|
return 0;
|
96
|
}
|
97
|
|
98
|
?>
|
99
|
|
100
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
101
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
102
|
<head>
|
103
|
<title>Upgrade script from Website Baker v2.6.7 to Website Baker v2.7</title>
|
104
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
105
|
<style type="text/css">
|
106
|
body {
|
107
|
margin:0;
|
108
|
padding:0;
|
109
|
border:0;
|
110
|
background: #EBF7FC;
|
111
|
color:#000;
|
112
|
font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
|
113
|
font-size: small;
|
114
|
height:101%;
|
115
|
}
|
116
|
|
117
|
#container {
|
118
|
width:85%;
|
119
|
background: #9ACBF1 url(admin/interface/background.png) repeat-x;
|
120
|
border:1px solid #000;
|
121
|
color:#000;
|
122
|
margin:2em auto;
|
123
|
padding:0 15px;
|
124
|
min-height: 500px;
|
125
|
text-align:left;
|
126
|
}
|
127
|
|
128
|
p { line-height:1.5em; }
|
129
|
|
130
|
h1,h2,h3,h4,h5,h6 {
|
131
|
font-family: Verdana, Arial, Helvetica, sans-serif;
|
132
|
color: #369;
|
133
|
margin-top: 1.0em;
|
134
|
margin-bottom: 0.1em;
|
135
|
}
|
136
|
|
137
|
h1 { font-size:150%; }
|
138
|
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
|
139
|
h3 { font-size: 120%; }
|
140
|
|
141
|
.ok, .error { font-weight:bold; }
|
142
|
.ok { color:green; }
|
143
|
.error { color:red; }
|
144
|
.check { color:#555; }
|
145
|
|
146
|
.red { background-color:#FF0000 }
|
147
|
.green { background-color:#00FF00 }
|
148
|
|
149
|
.warning {
|
150
|
width: 98%;
|
151
|
background:#FFDBDB;
|
152
|
padding:0.2em;
|
153
|
margin-top:0.5em;
|
154
|
border: 1px solid black;
|
155
|
}
|
156
|
</style>
|
157
|
</head>
|
158
|
<body>
|
159
|
<div id="container">
|
160
|
<img src="admin/interface/logo.png" alt="Website Baker Logo" />
|
161
|
|
162
|
<h1>Website Baker Upgrade</h1>
|
163
|
<p>This script is for <strong>upgrading an existing v2.6.7</strong> installation to the latest Website Baker <strong>version 2.7</strong>. The upgrade script checks the configuration of your installed Website Baker system and alters the existing WB database to reflect the changes introduced with WB 2.7.</p>
|
164
|
|
165
|
<?php
|
166
|
if(!isset($_POST['backup_confirmed'])) {
|
167
|
?>
|
168
|
<h2>Step 1: Check existing installation</h2>
|
169
|
<p>Checking the configuration of your existing Website Baker installation:<br />
|
170
|
<?php
|
171
|
// check the basic Website Baker installation before proceeding
|
172
|
if(check_baseline_configuration() != 0) die;
|
173
|
status_msg('<p>Congratulations: You have passed all the required pre-checks.', 'ok');
|
174
|
?>
|
175
|
|
176
|
<h2>Step 2: Create a backup of your existing data</h2>
|
177
|
<p>It is highly recommended to <strong>create a manual backup</strong> of the entire <strong>/pages folder</strong> and the <strong>MySQL database</strong> before proceeding. The upgrade script is not sufficiently tested at the moment and should therefore only be used for testing purposes!!! Please confirm the disclaimer before starting this script.</p>
|
178
|
|
179
|
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
|
180
|
<textarea cols="80" rows="5">DISCLAIMER: The Website Baker upgrade script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. One needs to confirm that a manual backup of the /pages folder (including all files and subfolders contained in it) and backup of the entire Website Baker MySQL database was created before you can proceed.</textarea>
|
181
|
<br /><br /><input name="backup_confirmed" type="checkbox" value="confirmed" /> I confirm that a manual backup of the /pages folder and the MySQL database was created.
|
182
|
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
|
183
|
</form>
|
184
|
<br />
|
185
|
|
186
|
<?php
|
187
|
if(isset($_POST['send'])) {
|
188
|
status_msg('<strong>Notice:</strong><br />You need to confirm that you have created a manual backup of the /pages directory and the MySQL database before you can proceed.', 'warning', 'div');
|
189
|
}
|
190
|
?>
|
191
|
<br /><br />
|
192
|
<?php
|
193
|
} else {
|
194
|
/**
|
195
|
THE WEBSITE BAKER UPGRADE SCRIPT STARTS HERE
|
196
|
**/
|
197
|
require_once('config.php');
|
198
|
require_once(WB_PATH.'/framework/functions.php');
|
199
|
?>
|
200
|
<h2>Step 3: Upgrading the existing Website Baker installation to WB 2.7</h2>
|
201
|
<p>will upgrade Website Baker 2.6.5 / 2.6.7 to version 2.7</p>
|
202
|
<?php
|
203
|
|
204
|
$OK = '<span class="green">OK</span>';
|
205
|
$FAIL = '<span class="red">failed</span>';
|
206
|
|
207
|
|
208
|
/**********************************************************
|
209
|
* - modules-based search
|
210
|
*/
|
211
|
function db_add_search_key_value($key, $value) {
|
212
|
global $database; global $OK; global $FAIL;
|
213
|
$table = TABLE_PREFIX.'search';
|
214
|
$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
|
215
|
if($query->numRows() > 0) {
|
216
|
echo "$key: allready there. $OK.<br />";
|
217
|
return true;
|
218
|
} else {
|
219
|
$database->query("INSERT INTO $table (name,value,extra) VALUES ('$key', '$value', '')");
|
220
|
echo (mysql_error()?mysql_error().'<br />':'');
|
221
|
$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
|
222
|
if($query->numRows() > 0) {
|
223
|
echo "$key: $OK.<br />";
|
224
|
return true;
|
225
|
} else {
|
226
|
echo "$key: $FAIL!<br />";
|
227
|
return false;
|
228
|
}
|
229
|
}
|
230
|
}
|
231
|
function db_add_field($field, $table, $desc) {
|
232
|
global $database; global $OK; global $FAIL;
|
233
|
echo "<u>Adding field '$field' to table '$table'</u><br />";
|
234
|
$table = TABLE_PREFIX.$table;
|
235
|
$query = $database->query("DESCRIBE $table '$field'");
|
236
|
if($query->numRows() == 0) { // add field
|
237
|
$query = $database->query("ALTER TABLE $table ADD $field $desc");
|
238
|
echo (mysql_error()?mysql_error().'<br />':'');
|
239
|
$query = $database->query("DESCRIBE $table '$field'");
|
240
|
echo (mysql_error()?mysql_error().'<br />':'');
|
241
|
if($query->numRows() > 0) {
|
242
|
echo "'$field' added. $OK.<br />";
|
243
|
} else {
|
244
|
echo "adding '$field' $FAIL!<br />";
|
245
|
}
|
246
|
} else {
|
247
|
echo "'$field' allready there. $OK.<br />";
|
248
|
}
|
249
|
}
|
250
|
|
251
|
echo "<br /><u>Adding module_order and max_excerpt to search-table</u><br />";
|
252
|
// module_order - in which order to show the search-results
|
253
|
// max_excerpt - how many lines of excerpt to print per matching page
|
254
|
|
255
|
$cfg = array(
|
256
|
'module_order' => 'faqbaker,manual,wysiwyg',
|
257
|
'max_excerpt' => '15'
|
258
|
);
|
259
|
foreach($cfg as $key=>$value) {
|
260
|
db_add_search_key_value($key, $value);
|
261
|
}
|
262
|
|
263
|
echo "<br /><u>Adding some internal config-elements to search-table</u><br />";
|
264
|
// These are global config-elements which don't appear in settings-page. Change them in the database if needed.
|
265
|
// cfg_show_description - whether to show page-description on the results page (true/false), def: true
|
266
|
// cfg_search_description - whether to search in page-description (true/false), def: true [only used while searching title/link/description/keywords]
|
267
|
// cfg_search_keywords - whether to search in page-keywords (true/false), def: true [only used while searching title/link/description/keywords]
|
268
|
// cfg_enable_old_search - use old search-method, too (true/false), def: true [use old method as fallback]
|
269
|
$cfg = array(
|
270
|
'cfg_show_description' => 'true',
|
271
|
'cfg_search_description' => 'true',
|
272
|
'cfg_search_keywords' => 'true',
|
273
|
'cfg_enable_old_search' => 'true'
|
274
|
);
|
275
|
foreach($cfg as $key=>$value) {
|
276
|
db_add_search_key_value($key, $value);
|
277
|
}
|
278
|
|
279
|
echo "<br /><u>Changing results_loop in search-table</u><br />";
|
280
|
// adding [EXCERPT]
|
281
|
|
282
|
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
|
283
|
if($query->numRows() > 0) {
|
284
|
$fetch_results_loop = $query->fetchRow();
|
285
|
$string = $fetch_results_loop['value'];
|
286
|
if(preg_match("/\[EXCERPT\]/", $string)) {
|
287
|
echo "[EXCERPT] is allready there. $OK.<br />";
|
288
|
} else {
|
289
|
$string = preg_replace("/10px;\">\[DESCRIPTION\]/", "5px;\">[DESCRIPTION]", $string);
|
290
|
$string .= "<tr><td colspan=\"2\" style=\"text-align: justify; padding-bottom: 10px;\">[EXCERPT]</td></tr>";
|
291
|
$string = addslashes($string);
|
292
|
$database->query("UPDATE ".TABLE_PREFIX."search SET name='results_loop',value='".$string."',extra='' WHERE name = 'results_loop' LIMIT 1");
|
293
|
echo (mysql_error()?mysql_error().'<br />':'');
|
294
|
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
|
295
|
if($query->numRows() > 0) {
|
296
|
$fetch_results_loop = $query->fetchRow();
|
297
|
$string = $fetch_results_loop['value'];
|
298
|
if(preg_match("/\[EXCERPT\]/", $string)) {
|
299
|
echo "[EXCERPT] added. $OK.<br />";
|
300
|
} else {
|
301
|
echo "adding [EXCERPT] $FAIL!<br />";
|
302
|
}
|
303
|
}
|
304
|
}
|
305
|
}
|
306
|
|
307
|
echo "<br /><u>Changing \"Header:\" in search-table</u><br />";
|
308
|
// adding [SEARCH_PATH]
|
309
|
|
310
|
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
|
311
|
if($query->numRows() > 0) {
|
312
|
$fetch_header = $query->fetchRow();
|
313
|
$string = $fetch_header['value'];
|
314
|
if(preg_match("/\[SEARCH_PATH\]/", $string)) {
|
315
|
echo "[SEARCH_PATH] is allready there. $OK.<br />";
|
316
|
} else {
|
317
|
$string = preg_replace("/<input type=\"text\" name=\"string\" value=\"\[SEARCH_STRING\]\" style=\"width: 100%;\" \/>/", "<input type=\"hidden\" name=\"search_path\" value=\"[SEARCH_PATH]\" /><input type=\"text\" name=\"string\" value=\"[SEARCH_STRING]\" style=\"width: 100%;\" />", $string);
|
318
|
$string = addslashes($string);
|
319
|
$database->query("UPDATE ".TABLE_PREFIX."search SET name='header',value='".$string."',extra='' WHERE name = 'header' LIMIT 1");
|
320
|
echo (mysql_error()?mysql_error().'<br />':'');
|
321
|
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
|
322
|
if($query->numRows() > 0) {
|
323
|
$fetch_header = $query->fetchRow();
|
324
|
$string = $fetch_header['value'];
|
325
|
if(preg_match("/\[SEARCH_PATH\]/", $string)) {
|
326
|
echo "[SEARCH_PATH] added. $OK.<br />";
|
327
|
} else {
|
328
|
echo "adding [SEARCH_PATH] $FAIL!<br />";
|
329
|
}
|
330
|
}
|
331
|
}
|
332
|
}
|
333
|
|
334
|
|
335
|
/**********************************************************
|
336
|
* - publish-by-date
|
337
|
*/
|
338
|
// Add fields "publ_start" and "publ_end" to table "sections"
|
339
|
// check if fields are present
|
340
|
db_add_field('publ_start', 'sections', "INT NOT NULL DEFAULT '0'");
|
341
|
db_add_field('publ_end', 'sections', "INT NOT NULL DEFAULT '0'");
|
342
|
|
343
|
|
344
|
/**********************************************************
|
345
|
* - core-module menu_link
|
346
|
*/
|
347
|
// create table
|
348
|
$table = TABLE_PREFIX ."mod_menu_link";
|
349
|
$database->query("DROP TABLE IF EXISTS `$table`");
|
350
|
$database->query("
|
351
|
CREATE TABLE `$table` (
|
352
|
`section_id` INT(11) NOT NULL DEFAULT '0',
|
353
|
`page_id` INT(11) NOT NULL DEFAULT '0',
|
354
|
`target_page_id` INT(11) NOT NULL DEFAULT '0',
|
355
|
`anchor` VARCHAR(255) NOT NULL DEFAULT '0' ,
|
356
|
`extern` VARCHAR(255) NOT NULL DEFAULT '' ,
|
357
|
PRIMARY KEY (`section_id`)
|
358
|
)
|
359
|
");
|
360
|
// fetch all menu_link-pages in $pages
|
361
|
$pages = array();
|
362
|
$table_p = TABLE_PREFIX.'pages';
|
363
|
$table_s = TABLE_PREFIX.'sections';
|
364
|
$table_mm = TABLE_PREFIX ."mod_menu_link";
|
365
|
|
366
|
$query_page = $database->query("SELECT p.*, s.section_id FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module = 'menu_link'");
|
367
|
if($query_page->numRows() > 0) {
|
368
|
while($page = $query_page->fetchRow()) {
|
369
|
$pages[$page['page_id']]['page_details'] = $page;
|
370
|
}
|
371
|
}
|
372
|
if($pages!=array())
|
373
|
echo "<br /><u>Convert menu_links</u><br />";
|
374
|
|
375
|
// get all related files with content from pages/ in $pages, too
|
376
|
function list_files_dirs($dir, $depth=true, $files=array(), $dirs=array()) {
|
377
|
$dh=opendir($dir);
|
378
|
while(($file = readdir($dh)) !== false) {
|
379
|
if($file == '.' || $file == '..') {
|
380
|
continue;
|
381
|
}
|
382
|
if(is_dir($dir.'/'.$file)) {
|
383
|
if($depth) {
|
384
|
$dirs[] = $dir.'/'.$file;
|
385
|
list($files, $dirs) = list_files_dirs($dir.'/'.$file, $depth, $files, $dirs);
|
386
|
}
|
387
|
} else {
|
388
|
$files[] = $dir.'/'.$file;
|
389
|
}
|
390
|
}
|
391
|
closedir($dh);
|
392
|
natcasesort($files);
|
393
|
natcasesort($dirs);
|
394
|
return(array($files, $dirs));
|
395
|
}
|
396
|
list($files, $dirs) = list_files_dirs(WB_PATH.PAGES_DIRECTORY);
|
397
|
foreach($files as $file) {
|
398
|
if(($content = implode('', file($file))) !== FALSE) {
|
399
|
if(preg_match('/\$page_id = (\d+)/', $content, $matches)) {
|
400
|
if(array_key_exists($matches[1], $pages)) {
|
401
|
$pages[$matches[1]]['file_content'] = $content;
|
402
|
$pages[$matches[1]]['filename'] = $file;
|
403
|
}
|
404
|
}
|
405
|
}
|
406
|
}
|
407
|
unset($files); unset($dirs);
|
408
|
// try to convert old menu_links to new ones
|
409
|
foreach($pages as $p) {
|
410
|
$page = $p['page_details'];
|
411
|
$file_content = $p['file_content'];
|
412
|
$filename = $p['filename'];
|
413
|
$link = $p['page_details']['link'];
|
414
|
$parent_pid = $p['page_details']['parent'];
|
415
|
$page_id = $p['page_details']['page_id'];
|
416
|
$section_id = $p['page_details']['section_id'];
|
417
|
$menu_title = $p['page_details']['menu_title'];
|
418
|
|
419
|
// calculate link from wb_pages.parent and menu_title
|
420
|
$cur_link = '';
|
421
|
if($parent_pid != '0' && $query_link = $database->query("SELECT link FROM $table_p WHERE page_id = '$parent_pid'")) {
|
422
|
$res = $query_link->fetchRow();
|
423
|
$cur_link .= $res['link'];
|
424
|
}
|
425
|
$cur_link .= '/'.page_filename($menu_title);
|
426
|
echo "found: $cur_link<br />";
|
427
|
$database->query("UPDATE $table_p SET link = '$cur_link' WHERE page_id = '$page_id'");
|
428
|
echo (mysql_error()?'mySQL: '.mysql_error().'<br />':'');
|
429
|
|
430
|
$new_filenames[$page_id]['file'] = WB_PATH.PAGES_DIRECTORY.$cur_link.PAGE_EXTENSION;
|
431
|
$new_filenames[$page_id]['link'] = $cur_link;
|
432
|
$new_filenames[$page_id]['menu'] = $menu_title;
|
433
|
|
434
|
// delete old access files in pages
|
435
|
if(file_exists($filename)) {
|
436
|
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
|
437
|
echo "Cannot delete access file in pages/ - permission denied ($FAIL)<br />";
|
438
|
} else {
|
439
|
unlink($filename);
|
440
|
}
|
441
|
}
|
442
|
|
443
|
// make entry in wb_mod_menu_link
|
444
|
if($query_pid = $database->query("SELECT page_id FROM $table_p WHERE page_id != '$page_id' AND link = '$link'")) {
|
445
|
$res = $query_pid->fetchRow();
|
446
|
$target_page_id = $res['page_id'];
|
447
|
$extern = '';
|
448
|
if(strpos($link, '://') !== FALSE || strpos($link, 'mailto:') !== FALSE) {
|
449
|
$target_page_id=-1;
|
450
|
$extern=addslashes($link);
|
451
|
}
|
452
|
$database->query("INSERT INTO $table_mm (page_id, section_id, target_page_id, anchor, extern) VALUES ('$page_id', '$section_id', '$target_page_id', '0', '$extern')");
|
453
|
echo (mysql_error()?'mySQL: '.mysql_error().'<br />':'');
|
454
|
}
|
455
|
}
|
456
|
// create new access files in pages/; make directories as needed
|
457
|
foreach($pages as $p) {
|
458
|
$page_id = $p['page_details']['page_id'];
|
459
|
$filename = $new_filenames[$page_id]['file'];
|
460
|
$menu_title = $new_filenames[$page_id]['menu'];
|
461
|
$link = $new_filenames[$page_id]['link'];
|
462
|
$content = $p['file_content'];
|
463
|
$level = $p['page_details']['level'];
|
464
|
$depth = '';
|
465
|
for($i=0; $i<=$level; $i++)
|
466
|
$depth .= '../';
|
467
|
$content = preg_replace('#((../)+)config\.php#', "{$depth}config.php", $content);
|
468
|
while(file_exists($filename)) {
|
469
|
echo "Cannot create '$filename' - file exist. Renamed to: ";
|
470
|
$menu_title .= '_';
|
471
|
$link .= '_';
|
472
|
$filename = WB_PATH.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
|
473
|
echo "$filename<br />";
|
474
|
$database->query("UPDATE $table_p SET link='$link', menu_title='$menu_title' WHERE page_id = '$page_id'");
|
475
|
echo mysql_error()?'mySQL: '.mysql_error().'<br />':'';
|
476
|
}
|
477
|
// check if we need to create a subdir somewhere
|
478
|
$dirs = array();
|
479
|
while(dirname($link) != '/') {
|
480
|
$link = dirname($link);
|
481
|
$dirs[] = WB_PATH.PAGES_DIRECTORY.$link;
|
482
|
}
|
483
|
foreach(array_reverse($dirs) as $dir) {
|
484
|
if(!file_exists($dir)) {
|
485
|
mkdir($dir, OCTAL_DIR_MODE);
|
486
|
}
|
487
|
}
|
488
|
// create new file in pages/
|
489
|
if($handle=fopen($filename, "wb")) {
|
490
|
if(!fwrite($handle, $content)) {
|
491
|
echo "Cannot write to $filename - ($FAIL)<br />";
|
492
|
}
|
493
|
fclose($handle);
|
494
|
} else {
|
495
|
echo "Cannot create $filename - ($FAIL)<br />";
|
496
|
}
|
497
|
|
498
|
}
|
499
|
|
500
|
// some code missing to regenerate page_title from link/filename
|
501
|
// for_all_pages: if filename($page_title) != basename($link) {
|
502
|
// rename $page_title to basename($link)
|
503
|
// }
|
504
|
// This must be done after menu_link-upgrade
|
505
|
//
|
506
|
// Should we really do this? - must be checked
|
507
|
|
508
|
|
509
|
/**********************************************************
|
510
|
* - asp - Advanced Spam Protection
|
511
|
*/
|
512
|
echo "<br /><u>Adding table mod_captcha_control</u><br />";
|
513
|
$table = TABLE_PREFIX.'mod_captcha_control';
|
514
|
$database->query("DROP TABLE IF EXISTS `$table`");
|
515
|
$database->query("CREATE TABLE `$table` (
|
516
|
`enabled_captcha` VARCHAR(1) NOT NULL DEFAULT '1',
|
517
|
`enabled_asp` VARCHAR(1) NOT NULL DEFAULT '1',
|
518
|
`captcha_type` VARCHAR(255) NOT NULL DEFAULT 'calc_text',
|
519
|
`asp_session_min_age` INT(11) NOT NULL DEFAULT '20',
|
520
|
`asp_view_min_age` INT(11) NOT NULL DEFAULT '10',
|
521
|
`asp_input_min_age` INT(11) NOT NULL DEFAULT '5',
|
522
|
`ct_text` LONGTEXT NOT NULL DEFAULT ''
|
523
|
)"
|
524
|
);
|
525
|
$database->query("
|
526
|
INSERT INTO `$table`
|
527
|
(`enabled_captcha`, `enabled_asp`, `captcha_type`)
|
528
|
VALUES
|
529
|
('1', '1', 'calc_text')
|
530
|
");
|
531
|
|
532
|
|
533
|
/**********************************************************
|
534
|
* - multi-group
|
535
|
*/
|
536
|
db_add_field('groups_id', 'users', "VARCHAR( 255 ) NOT NULL DEFAULT '0' AFTER group_id");
|
537
|
$table = TABLE_PREFIX.'users';
|
538
|
if($query_group = $database->query("SELECT user_id,group_id,groups_id FROM $table")) {
|
539
|
while($group = $query_group->fetchRow()) {
|
540
|
if($group['groups_id'] == '0') {
|
541
|
if($database->query("UPDATE $table SET groups_id = group_id WHERE user_id = {$group['user_id']}")) {
|
542
|
echo 'groups_id updated successfully<br>';
|
543
|
}
|
544
|
echo mysql_error().'<br />';
|
545
|
}
|
546
|
}
|
547
|
}
|
548
|
|
549
|
|
550
|
/**********************************************************
|
551
|
* -Javascript Admin
|
552
|
*/
|
553
|
echo "<br /><u>Adding table mod_jsadmin</u><br />";
|
554
|
$table = TABLE_PREFIX ."mod_jsadmin";
|
555
|
$database->query("DROP TABLE IF EXISTS `$table`");
|
556
|
|
557
|
$database->query("
|
558
|
CREATE TABLE `$table` (
|
559
|
`id` INT(11) NOT NULL DEFAULT '0',
|
560
|
`name` VARCHAR(255) NOT NULL DEFAULT '0',
|
561
|
`value` INT(11) NOT NULL DEFAULT '0',
|
562
|
PRIMARY KEY (`id`)
|
563
|
)
|
564
|
");
|
565
|
|
566
|
global $database;
|
567
|
$database->query("INSERT INTO ".$table." (id,name,value) VALUES ('1','mod_jsadmin_persist_order','0')");
|
568
|
$database->query("INSERT INTO ".$table." (id,name,value) VALUES ('2','mod_jsadmin_ajax_order_pages','0')");
|
569
|
$database->query("INSERT INTO ".$table." (id,name,value) VALUES ('3','mod_jsadmin_ajax_order_sections','0')");
|
570
|
|
571
|
|
572
|
/**********************************************************
|
573
|
* - Output Filter
|
574
|
*/
|
575
|
echo "<br /><u>Adding table mod_outputfilter</u><br />";
|
576
|
$table = TABLE_PREFIX .'mod_output_filter';
|
577
|
$database->query("DROP TABLE IF EXISTS `$table`");
|
578
|
|
579
|
$database->query("CREATE TABLE `$table` (
|
580
|
`email_filter` VARCHAR(1) NOT NULL DEFAULT '0',
|
581
|
`mailto_filter` VARCHAR(1) NOT NULL DEFAULT '0',
|
582
|
`at_replacement` VARCHAR(255) NOT NULL DEFAULT '(at)',
|
583
|
`dot_replacement` VARCHAR(255) NOT NULL DEFAULT '(dot)'
|
584
|
)"
|
585
|
);
|
586
|
|
587
|
// add default values to the module table
|
588
|
$database->query("INSERT INTO ".TABLE_PREFIX
|
589
|
."mod_output_filter (email_filter, mailto_filter, at_replacement, dot_replacement) VALUES ('0', '0', '(at)', '(dot)')");
|
590
|
|
591
|
|
592
|
/**********************************************************
|
593
|
* - Form Modul
|
594
|
*/
|
595
|
db_add_field('success_email_subject', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
|
596
|
db_add_field('success_email_text', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
|
597
|
db_add_field('success_email_from', 'mod_form_settings', "VARCHAR(255) NOT NULL AFTER `email_subject`");
|
598
|
db_add_field('success_email_to', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
|
599
|
db_add_field('success_page', 'mod_form_settings', "TEXT NOT NULL AFTER `email_subject`");
|
600
|
db_add_field('email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER email_from");
|
601
|
db_add_field('success_email_fromname', 'mod_form_settings', "VARCHAR( 255 ) NOT NULL AFTER success_email_from");
|
602
|
|
603
|
echo "<BR><B>Deleting field success_message from table mod_form_settings</B><BR>";
|
604
|
|
605
|
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
|
606
|
echo 'Database field success_message droped successfully<br>';
|
607
|
}
|
608
|
echo mysql_error().'<br />';
|
609
|
|
610
|
// These are the default setting
|
611
|
$success_page = 'none';
|
612
|
$success_email_to = '';
|
613
|
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
|
614
|
$success_email_text = addslashes($success_email_text);
|
615
|
$success_email_subject = 'You have submitted a form';
|
616
|
|
617
|
// Insert default settings into database
|
618
|
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
|
619
|
while($result = $query_dates->fetchRow()) {
|
620
|
|
621
|
echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
|
622
|
$section_id = $result['section_id'];
|
623
|
|
624
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
|
625
|
echo 'Database data success_page added successfully<br>';
|
626
|
}
|
627
|
echo mysql_error().'<br />';
|
628
|
|
629
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
|
630
|
echo 'Database data success_email_to added successfully<br>';
|
631
|
}
|
632
|
echo mysql_error().'<br />';
|
633
|
|
634
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
|
635
|
echo 'Database data success_email_text added successfully<br>';
|
636
|
}
|
637
|
echo mysql_error().'<br />';
|
638
|
|
639
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
|
640
|
echo 'Database data success_email_subject added successfully<br>';
|
641
|
}
|
642
|
echo mysql_error().'<br />';
|
643
|
|
644
|
}
|
645
|
|
646
|
// copy field email_to to success_email_from
|
647
|
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
|
648
|
while($result = $query_dates->fetchRow()) {
|
649
|
|
650
|
echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
|
651
|
$section_id = $result['section_id'];
|
652
|
|
653
|
$success_email_from = $result['email_to'];
|
654
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
|
655
|
echo 'Copyied field email_to to success_email_from successfully<br>';
|
656
|
}
|
657
|
echo mysql_error().'<br />';
|
658
|
}
|
659
|
|
660
|
|
661
|
/**********************************************************
|
662
|
* - News Modul
|
663
|
*/
|
664
|
db_add_field('published_when', 'mod_news_posts', "INT NOT NULL AFTER `commenting`");
|
665
|
db_add_field('published_until', 'mod_news_posts', "INT NOT NULL AFTER `published_when`");
|
666
|
|
667
|
// These are the default setting
|
668
|
$header = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"98%\">';
|
669
|
$post_loop = '<tr class=\"post_top\">
|
670
|
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
|
671
|
<td class=\"post_date\">[MODI_TIME], [MODI_DATE]</td>
|
672
|
</tr>
|
673
|
<tr>
|
674
|
<td class=\"post_short\" colspan=\"2\">
|
675
|
[SHORT]
|
676
|
<a href=\"[LINK]\">[TEXT_READ_MORE]</a>
|
677
|
</td>
|
678
|
</tr>';
|
679
|
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
680
|
<tr>
|
681
|
<td height="30"><h1>[TITLE]</h1></td>
|
682
|
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
|
683
|
</tr>
|
684
|
<tr>
|
685
|
<td valign="top"><b>Posted by [DISPLAY_NAME] ([USERNAME]) on [PUBL_DATE]</b></td>
|
686
|
</tr>
|
687
|
<tr style="display: [DISPLAY_GROUP]">
|
688
|
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
|
689
|
</tr>
|
690
|
</table>
|
691
|
<p style="text-align: justify;">');
|
692
|
$post_footer = '</p><p>Last changed: [MODI_DATE] at [MODI_TIME]</p>
|
693
|
<a href=\"[BACK]\">Back</a>';
|
694
|
$comments_header = addslashes('<br /><br />
|
695
|
<h2>Comments</h2>
|
696
|
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
|
697
|
|
698
|
// Insert default settings into database
|
699
|
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
|
700
|
while($result = $query_dates->fetchRow()) {
|
701
|
|
702
|
echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
|
703
|
$section_id = $result['section_id'];
|
704
|
|
705
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
|
706
|
echo 'Database data header added successfully<br>';
|
707
|
}
|
708
|
echo mysql_error().'<br />';
|
709
|
|
710
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
|
711
|
echo 'Database data post_loop added successfully<br>';
|
712
|
}
|
713
|
echo mysql_error().'<br />';
|
714
|
|
715
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
|
716
|
echo 'Database data post_header added successfully<br>';
|
717
|
}
|
718
|
echo mysql_error().'<br />';
|
719
|
|
720
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
|
721
|
echo 'Database data post_footer added successfully<br>';
|
722
|
}
|
723
|
echo mysql_error().'<br />';
|
724
|
|
725
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
|
726
|
echo 'Database data comments_header added successfully<br>';
|
727
|
}
|
728
|
echo mysql_error().'<br />';
|
729
|
|
730
|
}
|
731
|
|
732
|
// MIGRATING FIELD DATES to POSTED_WHEN
|
733
|
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
|
734
|
if($query_dates->numRows() > 0) {
|
735
|
echo "<B>Copying field posted_when value to published_when</B><BR>";
|
736
|
}
|
737
|
while($result = $query_dates->fetchRow()) {
|
738
|
$pid = $result['post_id'];
|
739
|
$NEW_DATE = $result['posted_when'];
|
740
|
if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
|
741
|
echo 'Copying posted_when value to published_when successfully<br>';
|
742
|
}
|
743
|
echo mysql_error().'<br />';
|
744
|
}
|
745
|
|
746
|
|
747
|
/**********************************************************
|
748
|
* - Add Admintools to Administrator group
|
749
|
*/
|
750
|
echo "<br /><u>Add Admintools to Adminsitrator group</u><br />";
|
751
|
$full_system_permissions = 'pages,pages_view,pages_add,pages_add_l0,pages_settings,pages_modify,pages_intro,pages_delete,media,media_view,media_upload,media_rename,media_delete,media_create,addons,modules,modules_view,modules_install,modules_uninstall,templates,templates_view,templates_install,templates_uninstall,languages,languages_view,languages_install,languages_uninstall,settings,settings_basic,settings_advanced,access,users,users_view,users_add,users_modify,users_delete,groups,groups_view,groups_add,groups_modify,groups_delete,admintools';
|
752
|
$database->query("UPDATE `".TABLE_PREFIX."groups` SET `system_permissions` = '$full_system_permissions' WHERE `name` = 'Administrators'");
|
753
|
|
754
|
|
755
|
/**********************************************************
|
756
|
* - Add Mailer Settings to settings table
|
757
|
*/
|
758
|
echo "<br /><u>Add Mailer Settings to settings table</u><br />";
|
759
|
//delete rows to prevent double entries
|
760
|
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_routine'");
|
761
|
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'server_email'");
|
762
|
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_default_sendername'");
|
763
|
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_host'");
|
764
|
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_auth'");
|
765
|
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_username'");
|
766
|
$database->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name = 'wbmailer_smtp_password'");
|
767
|
//add new rows with default values
|
768
|
$settings_rows= "INSERT INTO `".TABLE_PREFIX."settings` "
|
769
|
." (name, value) VALUES "
|
770
|
." ('wbmailer_routine', 'phpmail'),"
|
771
|
." ('server_email', 'admin@yourdomain.com')," // avoid that mail provider (e.g. mail.com) reject mails like yourname@mail.com
|
772
|
." ('wbmailer_default_sendername', 'WB Mailer'),"
|
773
|
." ('wbmailer_smtp_host', ''),"
|
774
|
." ('wbmailer_smtp_auth', ''),"
|
775
|
." ('wbmailer_smtp_username', ''),"
|
776
|
." ('wbmailer_smtp_password', '')";
|
777
|
$database->query($settings_rows);
|
778
|
|
779
|
|
780
|
/**********************************************************
|
781
|
* - Reload all addons
|
782
|
*/
|
783
|
|
784
|
//delete modules
|
785
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
|
786
|
// Load all modules
|
787
|
if($handle = opendir(WB_PATH.'/modules/')) {
|
788
|
while(false !== ($file = readdir($handle))) {
|
789
|
if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
|
790
|
load_module(WB_PATH.'/modules/'.$file);
|
791
|
}
|
792
|
}
|
793
|
closedir($handle);
|
794
|
}
|
795
|
echo '<br />Modules reloaded<br />';
|
796
|
|
797
|
//delete templates
|
798
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
|
799
|
// Load all templates
|
800
|
if($handle = opendir(WB_PATH.'/templates/')) {
|
801
|
while(false !== ($file = readdir($handle))) {
|
802
|
if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
|
803
|
load_template(WB_PATH.'/templates/'.$file);
|
804
|
}
|
805
|
}
|
806
|
closedir($handle);
|
807
|
}
|
808
|
echo '<br />Templates reloaded<br />';
|
809
|
|
810
|
//delete languages
|
811
|
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
|
812
|
// Load all languages
|
813
|
if($handle = opendir(WB_PATH.'/languages/')) {
|
814
|
while(false !== ($file = readdir($handle))) {
|
815
|
if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
|
816
|
load_language(WB_PATH.'/languages/'.$file);
|
817
|
}
|
818
|
}
|
819
|
closedir($handle);
|
820
|
}
|
821
|
echo '<br />Languages reloaded<br />';
|
822
|
|
823
|
/**********************************************************
|
824
|
* - Set Version to WB 2.7
|
825
|
*/
|
826
|
echo "<br /><u>Set Version number to 2.7</u><br />";
|
827
|
$version = '2.7';
|
828
|
$database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'");
|
829
|
|
830
|
|
831
|
/**********************************************************
|
832
|
* - End of upgrade script
|
833
|
*/
|
834
|
echo "<br /><br />Done<br />";
|
835
|
|
836
|
}
|
837
|
?>
|
838
|
</div>
|
839
|
</body>
|
840
|
</html>
|