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 944 Ruebenwurz
	background: #A8BCCB url(<?php echo THEME_URL;?>/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 944 Ruebenwurz
<img src="<?php echo THEME_URL;?>/images/logo.png" alt="Website Baker Logo" />
94 715 doc
95
<h1>Website Baker Upgrade</h1>
96
97 692 doc
<?php
98 715 doc
99 719 doc
require_once('config.php');
100
require_once(WB_PATH.'/framework/functions.php');
101 552 thorn
102 720 doc
$OK   = '<span class="ok">OK</span>';
103
$FAIL = '<span class="error">FAILED</span>';
104 552 thorn
105 883 thorn
// function to add a var/value-pair into settings-table
106 882 Ruebenwurz
function db_add_key_value($key, $value) {
107 552 thorn
	global $database; global $OK; global $FAIL;
108 882 Ruebenwurz
	$table = TABLE_PREFIX.'settings';
109 596 thorn
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
110 552 thorn
	if($query->numRows() > 0) {
111
		echo "$key: allready there. $OK.<br />";
112
		return true;
113
	} else {
114 882 Ruebenwurz
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
115 648 thorn
		echo (mysql_error()?mysql_error().'<br />':'');
116 596 thorn
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
117 552 thorn
		if($query->numRows() > 0) {
118
			echo "$key: $OK.<br />";
119
			return true;
120
		} else {
121
			echo "$key: $FAIL!<br />";
122
			return false;
123
		}
124
	}
125
}
126
127 883 thorn
// function to add a new field into a table
128
function db_add_field($field, $table, $desc) {
129
	global $database; global $OK; global $FAIL;
130
	$table = TABLE_PREFIX.$table;
131
	$query = $database->query("DESCRIBE $table '$field'");
132
	if($query->numRows() == 0) { // add field
133
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
134
		echo (mysql_error()?mysql_error().'<br />':'');
135
		$query = $database->query("DESCRIBE $table '$field'");
136
		echo (mysql_error()?mysql_error().'<br />':'');
137
		if($query->numRows() > 0) {
138
			echo "'$field' added. $OK.<br />";
139
		} else {
140
			echo "adding '$field' $FAIL!<br />";
141
		}
142
	} else {
143
		echo "'$field' allready there. $OK.<br />";
144
	}
145
}
146
147
148
/**********************************************************
149
 *  - Adding field sec_anchor to settings table
150
 */
151 944 Ruebenwurz
echo "<br />Adding sec_anchor to settings table<br />";
152 552 thorn
$cfg = array(
153 882 Ruebenwurz
	'sec_anchor' => 'wb_'
154 552 thorn
);
155
foreach($cfg as $key=>$value) {
156 882 Ruebenwurz
	db_add_key_value($key, $value);
157 552 thorn
}
158
159 944 Ruebenwurz
160 929 doc
/**********************************************************
161 944 Ruebenwurz
 *  - Adding field default_theme to settings table
162
 */
163
echo "<br />Adding default_theme to settings table<br />";
164
$cfg = array(
165
	'default_theme' => 'wb_theme'
166
);
167
foreach($cfg as $key=>$value) {
168
	db_add_key_value($key, $value);
169
}
170
171
172
/**********************************************************
173 929 doc
 *  - Adding redirect timer to settings table
174
 */
175
echo "<br />Adding redirect timer to settings table<br />";
176
$cfg = array(
177
	'redirect_timer' => '1500'
178
);
179
foreach($cfg as $key=>$value) {
180
	db_add_key_value($key, $value);
181
}
182 883 thorn
183 944 Ruebenwurz
184 552 thorn
/**********************************************************
185 883 thorn
 *  - Add field "redirect_type" to table "mod_menu_link"
186
 */
187
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
188
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
189
190
191
/**********************************************************
192 943 doc
 *  - Update search no results database filed to create
193
 *  valid XHTML if search is empty
194
 */
195
echo "<br />Updating database field `no_results` of search table: ";
196
$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
197
$sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
198
$database->query($sql);
199
echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
200
201 944 Ruebenwurz
202 943 doc
/**********************************************************
203 944 Ruebenwurz
 *  - Set Version to WB 2.8 BETA
204
 */
205
echo "<br />Update database version number to 2.8 BETA : ";
206
$version = '2.8 BETA';
207
echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
208
209
210
/**********************************************************
211
 *  - Reload all addons
212
 */
213
214
//delete modules
215
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
216
// Load all modules
217
if($handle = opendir(WB_PATH.'/modules/')) {
218
	while(false !== ($file = readdir($handle))) {
219
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
220
			load_module(WB_PATH.'/modules/'.$file);
221
		}
222
	}
223
	closedir($handle);
224
}
225
echo '<br />Modules reloaded<br />';
226
227
//delete templates
228
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
229
// Load all templates
230
if($handle = opendir(WB_PATH.'/templates/')) {
231
	while(false !== ($file = readdir($handle))) {
232
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
233
			load_template(WB_PATH.'/templates/'.$file);
234
		}
235
	}
236
	closedir($handle);
237
}
238
echo '<br />Templates reloaded<br />';
239
240
//delete languages
241
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
242
// Load all languages
243
if($handle = opendir(WB_PATH.'/languages/')) {
244
	while(false !== ($file = readdir($handle))) {
245
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
246
			load_language(WB_PATH.'/languages/'.$file);
247
		}
248
	}
249
	closedir($handle);
250
}
251
echo '<br />Languages reloaded<br />';
252
253
254
/**********************************************************
255 714 Ruebenwurz
 *  - End of upgrade script
256
 */
257 722 doc
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
258 882 Ruebenwurz
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
259 722 doc
// show buttons to go to the backend or frontend
260
echo '<br />';
261
if(defined('WB_URL')) {
262
	echo '<form action="'.WB_URL.'" target="_self">';
263 724 doc
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
264 722 doc
	echo '</form>';
265 715 doc
}
266 722 doc
if(defined('ADMIN_URL')) {
267
	echo '<form action="'.ADMIN_URL.'" target="_self">';
268 724 doc
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
269 722 doc
	echo '</form>';
270
}
271
echo '<p>&nbsp;</p>';
272 882 Ruebenwurz
273 552 thorn
?>
274 882 Ruebenwurz
275 715 doc
</div>
276 552 thorn
</body>
277 714 Ruebenwurz
</html>