Register
phpBB.com Wiki · Home Projects Help

root / tags / release_2_0_1 / phpBB / upgrade.php

1 1242 bartvb
<?php
2 1242 bartvb
/***************************************************************************
3 1242 bartvb
*                                  upgrade.php
4 1242 bartvb
*                              -------------------
5 1242 bartvb
*     begin                : Wed Sep 05 2001
6 1242 bartvb
*     copyright            : (C) 2001 The phpBB Group
7 1242 bartvb
*     email                : support@phpbb.com
8 1242 bartvb
*
9 1753 psotfx
*     $Id$
10 1242 bartvb
*
11 1242 bartvb
****************************************************************************/
12 1242 bartvb
13 1242 bartvb
/***************************************************************************
14 1242 bartvb
 *
15 1242 bartvb
 *   This program is free software; you can redistribute it and/or modify
16 1242 bartvb
 *   it under the terms of the GNU General Public License as published by
17 1242 bartvb
 *   the Free Software Foundation; either version 2 of the License, or
18 1242 bartvb
 *   (at your option) any later version.
19 1242 bartvb
 *
20 1242 bartvb
 ***************************************************************************/
21 1752 psotfx
22 2305 psotfx
define('IN_PHPBB', true);
23 2305 psotfx
24 1299 the_systech
if ( !defined('INSTALLING') )
25 1299 the_systech
{
26 2093 psotfx
	error_reporting  (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
27 2093 psotfx
	set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
28 2093 psotfx
29 1299 the_systech
	//
30 1299 the_systech
	// If we are being called from the install script then we don't need these
31 1299 the_systech
	// as they are already included.
32 1299 the_systech
	//
33 1299 the_systech
	include('extension.inc');
34 1299 the_systech
	include('config.'.$phpEx);
35 1299 the_systech
	include('includes/constants.'.$phpEx);
36 1558 bartvb
	include('includes/functions.'.$phpEx);
37 2088 psotfx
38 2088 psotfx
	if( defined("PHPBB_INSTALLED") )
39 2088 psotfx
	{
40 2575 psotfx
		$header_location = ( @preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE')) ) ? 'Refresh: 0; URL=' : 'Location: ';
41 2575 psotfx
		header($header_location . " index.$phpEx");
42 2088 psotfx
		exit;
43 2088 psotfx
	}
44 1299 the_systech
}
45 1752 psotfx
46 1752 psotfx
//
47 1438 bartvb
// Force the DB type to be MySQL
48 1752 psotfx
//
49 1438 bartvb
$dbms = 'mysql';
50 1752 psotfx
51 1242 bartvb
include('includes/db.'.$phpEx);
52 1242 bartvb
include('includes/bbcode.'.$phpEx);
53 2305 psotfx
include('includes/functions_search.'.$phpEx);
54 1242 bartvb
55 1438 bartvb
set_time_limit(0); // Unlimited execution time
56 1242 bartvb
57 1242 bartvb
$months = array(
58 1242 bartvb
	'Jan' => 1,
59 1242 bartvb
	'Feb' => 2,
60 1242 bartvb
	'Mar' => 3,
61 1242 bartvb
	'Apr' => 4,
62 1242 bartvb
	'May' => 5,
63 1242 bartvb
	'Jun' => 6,
64 1242 bartvb
	'Jul' => 7,
65 1242 bartvb
	'Aug' => 8,
66 1242 bartvb
	'Sep' => 9,
67 1242 bartvb
	'Sept' => 9,
68 1242 bartvb
	'Oct' => 10,
69 1242 bartvb
	'Nov' => 11,
70 1242 bartvb
	'Dec' => 12
71 1752 psotfx
);
72 1242 bartvb
73 1752 psotfx
// ---------------
74 1752 psotfx
// Begin functions
75 1752 psotfx
//
76 1242 bartvb
function common_header()
77 1242 bartvb
{
78 1242 bartvb
?>
79 2093 psotfx
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
80 2093 psotfx
<html>
81 2093 psotfx
<head>
82 2093 psotfx
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
83 2093 psotfx
<meta http-equiv="Content-Style-Type" content="text/css">
84 2093 psotfx
<style type="text/css">
85 2093 psotfx
<!--
86 2093 psotfx
/* Specifiy background images for selected styles
87 2093 psotfx
   This can't be done within the external style sheet as NS4 sees image paths relative to
88 2093 psotfx
   the page which called the style sheet (i.e. this page in the root phpBB directory)
89 2093 psotfx
   whereas all other browsers see image paths relative to the style sheet. Stupid NS again!
90 2093 psotfx
*/
91 2093 psotfx
TH			{ background-image: url(templates/subSilver/images/cellpic3.gif) }
92 2093 psotfx
TD.cat		{ background-image: url(templates/subSilver/images/cellpic1.gif) }
93 2093 psotfx
TD.rowpic	{ background-image: url(templates/subSilver/images/cellpic2.jpg); background-repeat: repeat-y }
94 2093 psotfx
td.icqback	{ background-image: url(templates/subSilver/images/icon_icq_add.gif); background-repeat: no-repeat }
95 2093 psotfx
TD.catHead,TD.catSides,TD.catLeft,TD.catRight,TD.catBottom { background-image: url(templates/subSilver/images/cellpic1.gif) }
96 2093 psotfx
97 2093 psotfx
font,th,td,p,body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11pt }
98 2093 psotfx
a:link,a:active,a:visited { font-family: Verdana, Arial, Helvetica, sans-serif; color : #006699; font-size:11pt }
99 2093 psotfx
a:hover		{ font-family: Verdana, Arial, Helvetica, sans-serif;  text-decoration: underline; color : #DD6900; font-size:11pt }
100 2093 psotfx
hr	{ height: 0px; border: solid #D1D7DC 0px; border-top-width: 1px;}
101 2093 psotfx
102 2093 psotfx
.maintitle,h1,h2	{font-weight: bold; font-size: 22px; font-family: "Trebuchet MS",Verdana, Arial, Helvetica, sans-serif; text-decoration: none; line-height : 120%; color : #000000;}
103 2093 psotfx
104 2093 psotfx
.ok {color:green}
105 2093 psotfx
106 2093 psotfx
/* Import the fancy styles for IE only (NS4.x doesn't use the @import function) */
107 2093 psotfx
@import url("templates/subSilver/formIE.css");
108 2093 psotfx
-->
109 2093 psotfx
</style>
110 2093 psotfx
</head>
111 2093 psotfx
<body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#5584AA">
112 2093 psotfx
113 2093 psotfx
<table width="100%" border="0" cellspacing="0" cellpadding="10" align="center">
114 2093 psotfx
	<tr>
115 2093 psotfx
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
116 2093 psotfx
			<tr>
117 2093 psotfx
				<td><img src="templates/subSilver/images/logo_phpBB.gif" border="0" alt="Forum Home" vspace="1" /></td>
118 2093 psotfx
				<td align="center" width="100%" valign="middle"><span class="maintitle">Upgrading to phpBB 2.0</span></td>
119 2093 psotfx
			</tr>
120 2093 psotfx
		</table></td>
121 2093 psotfx
	</tr>
122 2093 psotfx
</table>
123 2093 psotfx
124 2093 psotfx
<br clear="all" />
125 2093 psotfx
126 1242 bartvb
<?
127 1242 bartvb
	return;
128 1242 bartvb
}
129 1242 bartvb
130 1752 psotfx
function common_footer()
131 1752 psotfx
{
132 1752 psotfx
?>
133 2093 psotfx
134 2093 psotfx
<br clear="all" />
135 2093 psotfx
136 2093 psotfx
</body>
137 2093 psotfx
</html>
138 1752 psotfx
<?
139 1752 psotfx
	return;
140 1752 psotfx
}
141 1752 psotfx
142 1242 bartvb
function query($sql, $errormsg)
143 1242 bartvb
{
144 1242 bartvb
	global $db;
145 2093 psotfx
146 2093 psotfx
	if ( !($result = $db->sql_query($sql)) )
147 1242 bartvb
	{
148 1242 bartvb
		print "<br><font color=\"red\">\n";
149 1242 bartvb
		print "$errormsg<br>";
150 2093 psotfx
151 1242 bartvb
		$sql_error = $db->sql_error();
152 1242 bartvb
		print $sql_error['code'] .": ". $sql_error['message']. "<br>\n";
153 2093 psotfx
154 1242 bartvb
		print "<pre>$sql</pre>";
155 1242 bartvb
		print "</font>\n";
156 2093 psotfx
157 1242 bartvb
		return FALSE;
158 1242 bartvb
	}
159 1242 bartvb
	else
160 1242 bartvb
	{
161 1242 bartvb
		return $result;
162 1242 bartvb
	}
163 1242 bartvb
}
164 1242 bartvb
165 2511 psotfx
function smiley_replace($text = '')
166 1558 bartvb
{
167 1558 bartvb
	global $db;
168 1558 bartvb
169 1752 psotfx
	static $search, $replace;
170 1558 bartvb
171 1558 bartvb
	// Did we get the smiley info in a previous call?
172 2093 psotfx
	if ( !is_array($search) )
173 1558 bartvb
	{
174 1752 psotfx
		$sql = "SELECT code, smile_url
175 1752 psotfx
			FROM smiles";
176 1558 bartvb
		$result = query($sql, "Unable to get list of smilies from the DB");
177 1752 psotfx
178 1752 psotfx
		$smilies = $db->sql_fetchrowset($result);
179 2093 psotfx
		@usort($smilies, 'smiley_sort');
180 1752 psotfx
181 1752 psotfx
		$search = array();
182 1752 psotfx
		$replace = array();
183 1752 psotfx
		for($i = 0; $i < count($smilies); $i++)
184 1558 bartvb
		{
185 1752 psotfx
			$search[] = '/<IMG SRC=".*?\/' . phpbb_preg_quote($smilies[$i]['smile_url'], '/') .'">/i';
186 1752 psotfx
			$replace[] = $smilies[$i]['code'];
187 1558 bartvb
		}
188 1558 bartvb
	}
189 1752 psotfx
190 2511 psotfx
	return ( $text != '' ) ? preg_replace($search, $replace, $text) : '';
191 1558 bartvb
192 1558 bartvb
}
193 1558 bartvb
194 1242 bartvb
function get_schema()
195 1242 bartvb
{
196 1438 bartvb
	global $table_prefix;
197 1752 psotfx
198 1438 bartvb
	$schemafile = file('db/schemas/mysql_schema.sql');
199 1242 bartvb
	$tabledata = 0;
200 1752 psotfx
201 1242 bartvb
	for($i=0; $i < count($schemafile); $i++)
202 1242 bartvb
	{
203 1242 bartvb
		$line = $schemafile[$i];
204 1752 psotfx
205 2511 psotfx
		if ( preg_match('/^CREATE TABLE (\w+)/i', $line, $matches) )
206 1242 bartvb
		{
207 1438 bartvb
			// Start of a new table definition, set some variables and go to the next line.
208 1242 bartvb
			$tabledata = 1;
209 1438 bartvb
			// Replace the 'phpbb_' prefix by the user defined prefix.
210 2511 psotfx
			$table = str_replace('phpbb_', $table_prefix, $matches[1]);
211 1438 bartvb
			$table_def[$table] = "CREATE TABLE $table (\n";
212 1242 bartvb
			continue;
213 1242 bartvb
		}
214 1752 psotfx
215 2511 psotfx
		if ( preg_match('/^\);/', $line) )
216 1242 bartvb
		{
217 1438 bartvb
			// End of the table definition
218 1438 bartvb
			// After this we will skip everything until the next 'CREATE' line
219 1242 bartvb
			$tabledata = 0;
220 2511 psotfx
			$table_def[$table] .= ')'; // We don't need the closing semicolon
221 1242 bartvb
		}
222 1752 psotfx
223 2093 psotfx
		if ( $tabledata == 1 )
224 1242 bartvb
		{
225 1438 bartvb
			// We are inside a table definition, parse this line.
226 1438 bartvb
			// Add the current line to the complete table definition:
227 1242 bartvb
			$table_def[$table] .= $line;
228 2511 psotfx
			if ( preg_match('/^\s*(\w+)\s+(\w+)\(([\d,]+)\)(.*)$/', $line, $matches) )
229 1438 bartvb
			{
230 1438 bartvb
				// This is a column definition
231 1438 bartvb
				$field = $matches[1];
232 1438 bartvb
				$type = $matches[2];
233 1438 bartvb
				$size = $matches[3];
234 2093 psotfx
235 2511 psotfx
				preg_match('/DEFAULT (NULL|\'.*?\')[,\s](.*)$/i', $matches[4], $match);
236 1438 bartvb
				$default = $match[1];
237 2093 psotfx
238 2511 psotfx
				$notnull = ( preg_match('/NOT NULL/i', $matches[4]) ) ? 1 : 0;
239 2511 psotfx
				$auto_increment = ( preg_match('/auto_increment/i', $matches[4]) ) ? 1 : 0;
240 2093 psotfx
241 1438 bartvb
				$field_def[$table][$field] = array(
242 1438 bartvb
					'type' => $type,
243 1438 bartvb
					'size' => $size,
244 1438 bartvb
					'default' => $default,
245 1438 bartvb
					'notnull' => $notnull,
246 1438 bartvb
					'auto_increment' => $auto_increment
247 1438 bartvb
				);
248 1242 bartvb
			}
249 1438 bartvb
250 2511 psotfx
			if ( preg_match('/\s*PRIMARY\s+KEY\s*\((.*)\).*/', $line, $matches) )
251 1242 bartvb
			{
252 1438 bartvb
				// Primary key
253 1438 bartvb
				$key_def[$table]['PRIMARY'] = $matches[1];
254 1242 bartvb
			}
255 2511 psotfx
			else if ( preg_match('/\s*KEY\s+(\w+)\s*\((.*)\)/', $line, $matches) )
256 1242 bartvb
			{
257 1438 bartvb
				// Normal key
258 1438 bartvb
				$key_def[$table][$matches[1]] = $matches[2];
259 1242 bartvb
			}
260 2511 psotfx
			else if ( preg_match('/^\s*(\w+)\s*(.*?),?\s*$/', $line, $matches) )
261 1438 bartvb
			{
262 1438 bartvb
				// Column definition
263 1438 bartvb
				$create_def[$table][$matches[1]] = $matches[2];
264 1438 bartvb
			}
265 1438 bartvb
			else
266 1438 bartvb
			{
267 1438 bartvb
				// It's a bird! It's a plane! It's something we didn't expect ;(
268 1438 bartvb
			}
269 1242 bartvb
		}
270 1242 bartvb
	}
271 2093 psotfx
272 1242 bartvb
	$schema['field_def'] = $field_def;
273 1242 bartvb
	$schema['table_def'] = $table_def;
274 1438 bartvb
	$schema['create_def'] = $create_def;
275 1438 bartvb
	$schema['key_def'] = $key_def;
276 2093 psotfx
277 1242 bartvb
	return $schema;
278 1242 bartvb
}
279 1242 bartvb
280 1242 bartvb
function get_inserts()
281 1242 bartvb
{
282 1438 bartvb
	global $table_prefix;
283 1752 psotfx
284 2511 psotfx
	$insertfile = file('db/schemas/mysql_basic.sql');
285 1752 psotfx
286 2093 psotfx
	for($i = 0; $i < count($insertfile); $i++)
287 1242 bartvb
	{
288 2511 psotfx
		if ( preg_match('/(INSERT INTO (\w+)\s.*);/i', str_replace('phpbb_', $table_prefix, $insertfile[$i]), $matches) )
289 1242 bartvb
		{
290 1242 bartvb
			$returnvalue[$matches[2]][] = $matches[1];
291 1242 bartvb
		}
292 1242 bartvb
	}
293 1752 psotfx
294 1242 bartvb
	return $returnvalue;
295 1242 bartvb
}
296 1242 bartvb
297 1242 bartvb
function lock_tables($state, $tables= '')
298 1242 bartvb
{
299 2093 psotfx
	if ( $state == 1 )
300 1242 bartvb
	{
301 2093 psotfx
		if ( is_array($tables) )
302 1242 bartvb
		{
303 1242 bartvb
			$tables = join(' WRITE, ', $tables);
304 1242 bartvb
		}
305 2093 psotfx
306 2093 psotfx
		query("LOCK TABLES $tables WRITE", "Couldn't do: $sql");
307 1242 bartvb
	}
308 1242 bartvb
	else
309 1242 bartvb
	{
310 1242 bartvb
		query("UNLOCK TABLES", "Couldn't unlock all tables");
311 1242 bartvb
	}
312 1242 bartvb
}
313 1242 bartvb
314 2093 psotfx
function output_table_content($content)
315 2093 psotfx
{
316 2093 psotfx
	echo $content . "\n";
317 1242 bartvb
318 1242 bartvb
	return;
319 1242 bartvb
}
320 1242 bartvb
321 1242 bartvb
//
322 1242 bartvb
// Nathan's bbcode2 conversion routines
323 1242 bartvb
//
324 2093 psotfx
function bbdecode($message)
325 2093 psotfx
{
326 2093 psotfx
	// Undo [code]
327 2511 psotfx
	$code_start_html = '<!-- BBCode Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Code:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><PRE>';
328 2511 psotfx
	$code_end_html = '</PRE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode End -->';
329 2511 psotfx
	$message = str_replace($code_start_html, '[code]', $message);
330 2511 psotfx
	$message = str_replace($code_end_html, '[/code]', $message);
331 1242 bartvb
332 2093 psotfx
	// Undo [quote]
333 2511 psotfx
	$quote_start_html = '<!-- BBCode Quote Start --><TABLE BORDER=0 ALIGN=CENTER WIDTH=85%><TR><TD><font size=-1>Quote:</font><HR></TD></TR><TR><TD><FONT SIZE=-1><BLOCKQUOTE>';
334 2511 psotfx
	$quote_end_html = '</BLOCKQUOTE></FONT></TD></TR><TR><TD><HR></TD></TR></TABLE><!-- BBCode Quote End -->';
335 2511 psotfx
	$message = str_replace($quote_start_html, '[quote]', $message);
336 2511 psotfx
	$message = str_replace($quote_end_html, '[/quote]', $message);
337 1242 bartvb
338 2093 psotfx
	// Undo [b] and [i]
339 2093 psotfx
	$message = preg_replace("#<!-- BBCode Start --><B>(.*?)</B><!-- BBCode End -->#s", "[b]\\1[/b]", $message);
340 2093 psotfx
	$message = preg_replace("#<!-- BBCode Start --><I>(.*?)</I><!-- BBCode End -->#s", "[i]\\1[/i]", $message);
341 1242 bartvb
342 2093 psotfx
	// Undo [url] (long form)
343 2093 psotfx
	$message = preg_replace("#<!-- BBCode u2 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u2 End -->#s", "[url=\\1\\2]\\3[/url]", $message);
344 1242 bartvb
345 2093 psotfx
	// Undo [url] (short form)
346 2093 psotfx
	$message = preg_replace("#<!-- BBCode u1 Start --><A HREF=\"([a-z]+?://)(.*?)\" TARGET=\"_blank\">(.*?)</A><!-- BBCode u1 End -->#s", "[url]\\3[/url]", $message);
347 1242 bartvb
348 2093 psotfx
	// Undo [email]
349 2093 psotfx
	$message = preg_replace("#<!-- BBCode Start --><A HREF=\"mailto:(.*?)\">(.*?)</A><!-- BBCode End -->#s", "[email]\\1[/email]", $message);
350 1242 bartvb
351 2093 psotfx
	// Undo [img]
352 2093 psotfx
	$message = preg_replace("#<!-- BBCode Start --><IMG SRC=\"(.*?)\" BORDER=\"0\"><!-- BBCode End -->#s", "[img]\\1[/img]", $message);
353 1242 bartvb
354 2093 psotfx
	// Undo lists (unordered/ordered)
355 1242 bartvb
356 2093 psotfx
	// <li> tags:
357 2511 psotfx
	$message = str_replace('<!-- BBCode --><LI>', '[*]', $message);
358 1242 bartvb
359 2093 psotfx
	// [list] tags:
360 2511 psotfx
	$message = str_replace('<!-- BBCode ulist Start --><UL>', '[list]', $message);
361 1242 bartvb
362 2093 psotfx
	// [list=x] tags:
363 2511 psotfx
	$message = preg_replace('#<!-- BBCode olist Start --><OL TYPE=([A1])>#si', "[list=\\1]", $message);
364 1242 bartvb
365 2093 psotfx
	// [/list] tags:
366 2511 psotfx
	$message = str_replace('</UL><!-- BBCode ulist End -->', '[/list]', $message);
367 2511 psotfx
	$message = str_replace('</OL><!-- BBCode olist End -->', '[/list]', $message);
368 1242 bartvb
369 2093 psotfx
	return $message;
370 1242 bartvb
}
371 1242 bartvb
372 1242 bartvb
//
373 1242 bartvb
// Alternative for in_array() which is only available in PHP4
374 1242 bartvb
//
375 2093 psotfx
function inarray($needle, $haystack)
376 2093 psotfx
{
377 2093 psotfx
	for( $i = 0 ; $i < sizeof($haystack) ; $i++ )
378 1242 bartvb
	{
379 2093 psotfx
		if ( $haystack[$i] == $needle )
380 1242 bartvb
		{
381 1242 bartvb
			return true;
382 1242 bartvb
		}
383 1242 bartvb
	}
384 2093 psotfx
385 2093 psotfx
	return false;
386 1242 bartvb
}
387 1242 bartvb
388 1242 bartvb
function end_step($next)
389 1242 bartvb
{
390 1242 bartvb
	global $debug;
391 2093 psotfx
392 2093 psotfx
	print "<hr /><a href=\"$PHP_SELF?next=$next\">Next step: <b>$next</b></a><br /><br />\n";
393 1242 bartvb
}
394 1242 bartvb
//
395 1752 psotfx
// End functions
396 1752 psotfx
// -------------
397 1242 bartvb
398 1242 bartvb
399 1752 psotfx
//
400 1242 bartvb
// Start at the beginning if the user hasn't specified a specific starting point.
401 1752 psotfx
//
402 1752 psotfx
$next = ( isset($HTTP_GET_VARS['next']) ) ? $HTTP_GET_VARS['next'] : 'start';
403 1242 bartvb
404 1242 bartvb
// If debug is set we'll do all steps in one go.
405 1752 psotfx
$debug = 1;
406 1242 bartvb
407 1438 bartvb
// Parse the MySQL schema file into some arrays.
408 1438 bartvb
$schema = get_schema();
409 2093 psotfx
410 1438 bartvb
$table_def = $schema['table_def'];
411 1438 bartvb
$field_def = $schema['field_def'];
412 1438 bartvb
$key_def = $schema['key_def'];
413 1438 bartvb
$create_def = $schema['create_def'];
414 1438 bartvb
415 1752 psotfx
//
416 1752 psotfx
// Get mysql_basic data
417 1752 psotfx
//
418 1752 psotfx
$inserts = get_inserts();
419 1558 bartvb
420 1752 psotfx
//
421 1752 psotfx
// Get smiley data
422 1752 psotfx
//
423 1752 psotfx
smiley_replace();
424 1752 psotfx
425 2093 psotfx
common_header();
426 2093 psotfx
427 2093 psotfx
if ( !empty($next) )
428 1242 bartvb
{
429 1242 bartvb
	switch($next)
430 1242 bartvb
	{
431 1752 psotfx
		case 'start':
432 2093 psotfx
			end_step('initial_drops');
433 2093 psotfx
434 2093 psotfx
		case 'initial_drops':
435 2093 psotfx
			print " * Dropping sessions and themes tables :: ";
436 1766 psotfx
			flush();
437 1242 bartvb
438 1766 psotfx
			query("DROP TABLE sessions", "Couldn't drop table 'sessions'");
439 1766 psotfx
			query("DROP TABLE themes", "Couldn't drop t