Project

General

Profile

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