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 915 Ruebenwurz
 Copyright (C) 2004-2009, Ryan Djurovich
9 552 thorn
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 749 doc
@include_once('config.php');
27
28 715 doc
// this function checks the basic configurations of an existing WB intallation
29
function status_msg($message, $class='check', $element='span') {
30
	// returns a status message
31
	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
32
}
33 552 thorn
34
35
?>
36
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
37
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
38
<head>
39 882 Ruebenwurz
<title>Upgrade script</title>
40 719 doc
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
41 692 doc
<style type="text/css">
42 715 doc
body {
43
	margin:0;
44
	padding:0;
45
	border:0;
46
	background: #EBF7FC;
47
	color:#000;
48 882 Ruebenwurz
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
49 715 doc
	font-size: small;
50
	height:101%;
51
}
52 692 doc
53 715 doc
#container {
54
	width:85%;
55 963 Ruebenwurz
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
56 715 doc
	border:1px solid #000;
57
	color:#000;
58
	margin:2em auto;
59
	padding:0 15px;
60
	min-height: 500px;
61
	text-align:left;
62 692 doc
}
63
64
p { line-height:1.5em; }
65
66 715 doc
h1,h2,h3,h4,h5,h6 {
67
	font-family: Verdana, Arial, Helvetica, sans-serif;
68
	color: #369;
69
	margin-top: 1.0em;
70
	margin-bottom: 0.1em;
71
}
72
73
h1 { font-size:150%; }
74
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
75
h3 { font-size: 120%; }
76
77
.ok, .error { font-weight:bold; }
78
.ok { color:green; }
79
.error { color:red; }
80
.check { color:#555; }
81
82
.warning {
83
	width: 98%;
84
	background:#FFDBDB;
85
	padding:0.2em;
86
	margin-top:0.5em;
87
	border: 1px solid black;
88
}
89 692 doc
</style>
90 552 thorn
</head>
91
<body>
92 715 doc
<div id="container">
93 963 Ruebenwurz
<img src="templates/wb_theme/images/logo.png" alt="Website Baker Logo" />
94 715 doc
95
<h1>Website Baker Upgrade</h1>
96 956 doc
<p>This script upgrades an existing Website Baker <strong>Version 2.7</strong> installation to the <strong>Version 2.8</strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.</p>
97 715 doc
98 692 doc
<?php
99 956 doc
/**
100
 * Check if disclaimer was accepted
101
 */
102
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
103
<h2>Step 1: Backup your files</h2>
104
<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.<br /><strong class="error">Note: </strong>The upgrade script alters some settings of your existing database!!! You need to confirm the disclaimer before proceeding.</p>
105 715 doc
106 956 doc
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
107
<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>
108
<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.
109
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
110
</form>
111
<br />
112
113
<?php
114
	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');
115
	echo '<br /><br />';
116
	exit;
117
}
118
119
echo '<h2>Step 2: Updating database entries</h2>';
120
121 719 doc
require_once('config.php');
122
require_once(WB_PATH.'/framework/functions.php');
123 552 thorn
124 720 doc
$OK   = '<span class="ok">OK</span>';
125
$FAIL = '<span class="error">FAILED</span>';
126 552 thorn
127 883 thorn
// function to add a var/value-pair into settings-table
128 882 Ruebenwurz
function db_add_key_value($key, $value) {
129 552 thorn
	global $database; global $OK; global $FAIL;
130 882 Ruebenwurz
	$table = TABLE_PREFIX.'settings';
131 596 thorn
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
132 552 thorn
	if($query->numRows() > 0) {
133 956 doc
		echo "$key: already exists. $OK.<br />";
134 552 thorn
		return true;
135
	} else {
136 882 Ruebenwurz
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
137 648 thorn
		echo (mysql_error()?mysql_error().'<br />':'');
138 596 thorn
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
139 552 thorn
		if($query->numRows() > 0) {
140
			echo "$key: $OK.<br />";
141
			return true;
142
		} else {
143
			echo "$key: $FAIL!<br />";
144
			return false;
145
		}
146
	}
147
}
148
149 883 thorn
// function to add a new field into a table
150
function db_add_field($field, $table, $desc) {
151
	global $database; global $OK; global $FAIL;
152
	$table = TABLE_PREFIX.$table;
153
	$query = $database->query("DESCRIBE $table '$field'");
154
	if($query->numRows() == 0) { // add field
155
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
156
		echo (mysql_error()?mysql_error().'<br />':'');
157
		$query = $database->query("DESCRIBE $table '$field'");
158
		echo (mysql_error()?mysql_error().'<br />':'');
159
		if($query->numRows() > 0) {
160
			echo "'$field' added. $OK.<br />";
161
		} else {
162
			echo "adding '$field' $FAIL!<br />";
163
		}
164
	} else {
165 956 doc
		echo "'$field' already exists. $OK.<br />";
166 883 thorn
	}
167
}
168
169
170
/**********************************************************
171
 *  - Adding field sec_anchor to settings table
172
 */
173 944 Ruebenwurz
echo "<br />Adding sec_anchor to settings table<br />";
174 552 thorn
$cfg = array(
175 882 Ruebenwurz
	'sec_anchor' => 'wb_'
176 552 thorn
);
177
foreach($cfg as $key=>$value) {
178 882 Ruebenwurz
	db_add_key_value($key, $value);
179 552 thorn
}
180
181 944 Ruebenwurz
182 929 doc
/**********************************************************
183 944 Ruebenwurz
 *  - Adding field default_theme to settings table
184
 */
185
echo "<br />Adding default_theme to settings table<br />";
186
$cfg = array(
187
	'default_theme' => 'wb_theme'
188
);
189
foreach($cfg as $key=>$value) {
190
	db_add_key_value($key, $value);
191
}
192
193
194
/**********************************************************
195 929 doc
 *  - Adding redirect timer to settings table
196
 */
197
echo "<br />Adding redirect timer to settings table<br />";
198
$cfg = array(
199
	'redirect_timer' => '1500'
200
);
201
foreach($cfg as $key=>$value) {
202
	db_add_key_value($key, $value);
203
}
204 883 thorn
205 944 Ruebenwurz
206 552 thorn
/**********************************************************
207 1035 Ruebenwurz
 *  - Adding mediasettings to settings table
208
 */
209
echo "<br />Adding mediasettings to settings table<br />";
210
$cfg = array(
211
	'mediasettings' => ''
212
);
213
foreach($cfg as $key=>$value) {
214
	db_add_key_value($key, $value);
215
}
216
217
218
/**********************************************************
219 883 thorn
 *  - Add field "redirect_type" to table "mod_menu_link"
220
 */
221
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
222
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
223
224
225
/**********************************************************
226 943 doc
 *  - Update search no results database filed to create
227
 *  valid XHTML if search is empty
228
 */
229
echo "<br />Updating database field `no_results` of search table: ";
230
$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
231
$sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
232
$database->query($sql);
233
echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
234
235 944 Ruebenwurz
236 943 doc
/**********************************************************
237 1054 Ruebenwurz
 *  - Update settings of News Modul
238
 */
239
240
// These are the default setting
241
$post_loop = '<tr class=\"post_top\">
242
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
243
<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
244
</tr>
245
<tr>
246
<td class=\"post_short\" colspan=\"2\">
247
[SHORT]
248
<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
249
</td>
250
</tr>';
251
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="98%">
252
<tr>
253
<td height="30"><h1>[TITLE]</h1></td>
254
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
255
</tr>
256
<tr>
257
<td valign="top"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
258
</tr>
259
<tr style="display: [DISPLAY_GROUP]">
260
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
261
</tr>
262
</table>');
263
$post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
264
<a href=\"[BACK]\">[TEXT_BACK]</a>';
265
$comments_header = addslashes('<br /><br />
266
<h2>[TEXT_COMMENTS]</h2>
267
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
268
$comments_loop = addslashes('<tr>
269
<td class="comment_title">[TITLE]</td>
270
<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
271
</tr>
272
<tr>
273
<td colspan="2" class="comment_text">[COMMENT]</td>
274
</tr>');
275
$comments_footer = '</table>
276
<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
277
$comments_page = '<h1>[TEXT_COMMENT]</h1>
278
<h2>[POST_TITLE]</h2>
279
<br />';
280
281
282
// Insert default settings into database
283
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
284
while($result = $query_dates->fetchRow()) {
285
286
	echo "<b>Add default settings data to database for news section_id= ".$result['section_id']."</b><br />";
287
	$section_id = $result['section_id'];
288
289
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
290
		echo 'Database data post_loop added successfully<br />';
291
	}
292
	echo mysql_error().'<br />';
293
294
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
295
		echo 'Database data post_header added successfully<br />';
296
	}
297
	echo mysql_error().'<br />';
298
299
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
300
		echo 'Database data post_footer added successfully<br />';
301
	}
302
	echo mysql_error().'<br />';
303
304
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
305
		echo 'Database data comments_header added successfully<br />';
306
	}
307
	echo mysql_error().'<br />';
308
309
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
310
		echo 'Database data comments_loop added successfully<br />';
311
	}
312
	echo mysql_error().'<br />';
313
314
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
315
		echo 'Database data comments_footer added successfully<br />';
316
	}
317
	echo mysql_error().'<br />';
318
319
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
320
		echo 'Database data comments_page added successfully<br />';
321
	}
322
	echo mysql_error().'<br />';
323
324
}
325
326
/**********************************************************
327 1040 Ruebenwurz
 *  - Set Version to WB 2.8RC1
328 944 Ruebenwurz
 */
329 1040 Ruebenwurz
echo "<br />Update database version number to 2.8RC1 : ";
330
$version = '2.8RC1';
331 944 Ruebenwurz
echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
332
333
334
/**********************************************************
335 994 Ruebenwurz
 *  - install droplets
336
 */
337
echo "<br />Install droplets<br />";
338
339 995 aldus
$result = mysql_list_tables( DB_NAME );
340
$all_tables = array();
341
for($i=0; $i < mysql_num_rows($result); $i++) $all_tables[] = mysql_table_name($result, $i);
342 994 Ruebenwurz
343 995 aldus
 $file_name = (!in_array ( TABLE_PREFIX."mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
344
 require_once (WB_PATH."/modules/droplets/".$file_name);
345 994 Ruebenwurz
346
/**********************************************************
347 944 Ruebenwurz
 *  - Reload all addons
348
 */
349
350
//delete modules
351
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
352
// Load all modules
353
if($handle = opendir(WB_PATH.'/modules/')) {
354
	while(false !== ($file = readdir($handle))) {
355
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
356
			load_module(WB_PATH.'/modules/'.$file);
357
		}
358
	}
359
	closedir($handle);
360
}
361
echo '<br />Modules reloaded<br />';
362
363
//delete templates
364
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
365
// Load all templates
366
if($handle = opendir(WB_PATH.'/templates/')) {
367
	while(false !== ($file = readdir($handle))) {
368
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
369
			load_template(WB_PATH.'/templates/'.$file);
370
		}
371
	}
372
	closedir($handle);
373
}
374
echo '<br />Templates reloaded<br />';
375
376
//delete languages
377
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
378
// Load all languages
379
if($handle = opendir(WB_PATH.'/languages/')) {
380
	while(false !== ($file = readdir($handle))) {
381
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
382
			load_language(WB_PATH.'/languages/'.$file);
383
		}
384
	}
385
	closedir($handle);
386
}
387
echo '<br />Languages reloaded<br />';
388
389
390
/**********************************************************
391 714 Ruebenwurz
 *  - End of upgrade script
392
 */
393 722 doc
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
394 882 Ruebenwurz
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
395 722 doc
// show buttons to go to the backend or frontend
396
echo '<br />';
397
if(defined('WB_URL')) {
398
	echo '<form action="'.WB_URL.'" target="_self">';
399 724 doc
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
400 722 doc
	echo '</form>';
401 715 doc
}
402 722 doc
if(defined('ADMIN_URL')) {
403
	echo '<form action="'.ADMIN_URL.'" target="_self">';
404 724 doc
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
405 722 doc
	echo '</form>';
406
}
407
echo '<p>&nbsp;</p>';
408 882 Ruebenwurz
409 552 thorn
?>
410 882 Ruebenwurz
411 715 doc
</div>
412 552 thorn
</body>
413 714 Ruebenwurz
</html>