Project

General

Profile

1
<?php
2
/*
3
*
4
*                       About WebsiteBaker
5
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10
*                       LICENSE INFORMATION
11
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29
*/
30
/**
31
 *
32
 * @category        backend
33
 * @package         installation
34
 * @author          WebsiteBaker Project
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @link			http://www.websitebaker2.org/
38
 * @license         http://www.gnu.org/licenses/gpl.html
39
 * @platform        WebsiteBaker 2.8.x
40
 * @requirements    PHP 4.3.4 and higher
41
 * @version         $Id: upgrade-script.php 1273 2010-01-24 08:26:18Z Luisehahne $
42
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
43
 * @lastmodified    $Date: 2010-01-24 09:26:18 +0100 (Sun, 24 Jan 2010) $
44
 *
45
 */
46

    
47
@require_once('config.php');
48

    
49
// this function checks the basic configurations of an existing WB intallation
50
function status_msg($message, $class='check', $element='span') {
51
	// returns a status message
52
	echo '<'.$element .' class="' .$class .'">' .$message .'</' .$element.'>';
53
}
54

    
55
$version = '2.8.1';
56
// database tables including in WB package
57
$table_list = array (
58
    'settings','groups','addons','pages','sections','search','users',
59
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
60
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
61
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
62
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
63
);
64

    
65
// analyze/check database tables
66
function mysqlCheckTables( $dbName )
67
{
68
    global $table_list;
69
    $table_prefix = TABLE_PREFIX;
70
    $sql = "SHOW TABLES FROM " . $dbName;
71
    $result = @mysql_query( $sql );
72
    $data = array();
73
    $x = 0;
74

    
75
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
76
    {
77
        $tmp = str_replace($table_prefix, '', $row[0]);
78

    
79
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
80
        {
81
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
82
            $analyze = @mysql_query( $sql );
83
            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
84
            $data[$x]['Op'] = $rowFetch["Op"];
85
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
86
            $msgColor = '<span class="error">';
87
            $data[$x]['Table'] = $row[0];
88
           // print  " ";
89
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
90
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
91
           // print  "<br />";
92
            $x++;
93
        }
94
    }
95
    return $data;
96
}
97

    
98
 // check existings tables for upgrade or install
99
/*
100
$get_result = mysql_list_tables (DB_NAME); */
101
$get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
102
$all_tables = array();
103
if($get_result->numRows() > 0)
104
{
105
    while ($data = $get_result->fetchRow())
106
    {
107
        $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
108
        if(in_array($tmp,$table_list))
109
        {
110
            $all_tables[] = $tmp;
111
        }
112
    }
113
    }
114

    
115

    
116
function show_array($array=array())
117
{
118
    print '<pre>';
119
    print_r ($array);
120
    print '</pre>';
121
}
122

    
123
?>
124
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
125
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
126
<head>
127
<title>Upgrade script</title>
128
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
129
<style type="text/css">
130
body {
131
	margin:0;
132
	padding:0;
133
	border:0;
134
	background: #EBF7FC;
135
	color:#000;
136
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
137
	font-size: small;
138
	height:101%;
139
}
140

    
141
#container {
142
	width:85%;
143
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
144
	border:1px solid #000;
145
	color:#000;
146
	margin:2em auto;
147
	padding:0 15px;
148
	min-height: 500px;
149
	text-align:left;
150
}
151

    
152
p { line-height:1.5em; }
153

    
154
h1,h2,h3,h4,h5,h6 {
155
	font-family: Verdana, Arial, Helvetica, sans-serif;
156
	color: #369;
157
	margin-top: 1.0em;
158
	margin-bottom: 0.1em;
159
}
160

    
161
h1 { font-size:150%; }
162
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
163
h3 { font-size: 120%; }
164

    
165
.ok, .error { font-weight:bold; }
166
.ok { color:green; }
167
.error { color:red; }
168
.check { color:#555; }
169

    
170
.warning {
171
	width: 98%;
172
	background:#FFDBDB;
173
	padding:0.2em;
174
	margin-top:0.5em;
175
	border: 1px solid black;
176
}
177
</style>
178
</head>
179
<body>
180
<div id="container">
181
<img src="templates/wb_theme/images/logo.png" alt="Website Baker Logo" />
182

    
183
<h1>Website Baker Upgrade</h1>
184
<p>This script upgrades an existing Website Baker <strong>Version 2.7</strong> installation to the <strong>Version <?php print $version ?></strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
185

    
186
<?php
187
/**
188
 * Check if disclaimer was accepted
189
 */
190
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
191
<h2>Step 1: Backup your files</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.<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>
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
	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');
203
	echo '<br /><br />';
204
    echo "</div>
205
    </body>
206
    </html>
207
    ";
208
	exit();
209
}
210

    
211
echo '<h2>Step 2: Updating database entries</h2>';
212
if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', 'wb_theme'); }
213

    
214
require_once(WB_PATH.'/framework/functions.php');
215
require_once(WB_PATH.'/framework/class.admin.php');
216
$admin = new admin('Addons', 'modules', false, false);
217
require_once(WB_PATH.'/framework/initialize.php');
218

    
219
$OK   = '<span class="ok">OK</span>';
220
$FAIL = '<span class="error">FAILED</span>';
221

    
222
    $check_text = 'total ';
223
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
224

    
225
    if(sizeof($all_tables) == 22)
226
    {
227
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
228
    }
229
    else
230
    {
231
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
232
    	echo '<h4>Install missing tables, you can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
233
        $result = array_diff ( $table_list, $all_tables );
234
        echo '<h4>';
235
        while ( list ( $key, $val ) = each ( $result ) )
236
        {
237
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
238
        }
239
        echo '</h4>';
240
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
241
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
242
    	echo '</form><br /><br />';
243
        echo "</div>
244
        </body>
245
        </html>
246
        ";
247
        exit();
248
    }
249
// function to add a var/value-pair into settings-table
250
function db_add_key_value($key, $value) {
251
	global $database; global $OK; global $FAIL;
252
	$table = TABLE_PREFIX.'settings';
253
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
254
	if($query->numRows() > 0) {
255
		echo "$key: already exists. $OK.<br />";
256
		return true;
257
	} else {
258
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
259
		echo (mysql_error()?mysql_error().'<br />':'');
260
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
261
		if($query->numRows() > 0) {
262
			echo "$key: $OK.<br />";
263
			return true;
264
		} else {
265
			echo "$key: $FAIL!<br />";
266
			return false;
267
		}
268
	}
269
}
270

    
271
// function to add a new field into a table
272
function db_add_field($field, $table, $desc) {
273
	global $database; global $OK; global $FAIL;
274
	$table = TABLE_PREFIX.$table;
275
	$query = $database->query("DESCRIBE $table '$field'");
276
	if($query->numRows() == 0) { // add field
277
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
278
		echo (mysql_error()?mysql_error().'<br />':'');
279
		$query = $database->query("DESCRIBE $table '$field'");
280
		echo (mysql_error()?mysql_error().'<br />':'');
281
		if($query->numRows() > 0) {
282
			echo "'$field' added. $OK.<br />";
283
		} else {
284
			echo "adding '$field' $FAIL!<br />";
285
		}
286
	} else {
287
		echo "'$field' already exists. $OK.<br />";
288
	}
289
}
290

    
291
/**********************************************************
292
 *  - Adding field sec_anchor to settings table
293
 */
294

    
295
echo "<br />Adding sec_anchor to settings table<br />";
296
$cfg = array(
297
	'sec_anchor' => 'wb_'
298
);
299
foreach($cfg as $key=>$value) {
300
	db_add_key_value($key, $value);
301
}
302

    
303
/**********************************************************
304
 *  - Adding field default_theme to settings table
305
 */
306
echo "<br />Adding default_theme to settings table<br />";
307
$cfg = array(
308
	'default_theme' => 'wb_theme'
309
);
310
foreach($cfg as $key=>$value) {
311
	db_add_key_value($key, $value);
312
}
313

    
314
/**********************************************************
315
 *  - Adding redirect timer to settings table
316
 */
317
echo "<br />Adding redirect timer to settings table<br />";
318
$cfg = array(
319
	'redirect_timer' => '1500'
320
);
321
foreach($cfg as $key=>$value) {
322
	db_add_key_value($key, $value);
323
}
324

    
325
/**********************************************************
326
 *  - Adding mediasettings to settings table
327
 */
328
echo "<br />Adding mediasettings to settings table<br />";
329
$cfg = array(
330
	'mediasettings' => ''
331
);
332
foreach($cfg as $key=>$value) {
333
	db_add_key_value($key, $value);
334
}
335

    
336
/**********************************************************
337
 *  - Add field "redirect_type" to table "mod_menu_link"
338
 */
339
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
340
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
341

    
342
/**********************************************************
343
 *  - Update search no results database filed to create
344
 *  valid XHTML if search is empty
345
 */
346
echo "<br />Updating database field `no_results` of search table: ";
347
$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
348
$sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
349
$database->query($sql);
350
echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
351

    
352

    
353
if (version_compare(VERSION, '2.8.0') <= 0)
354
{
355
    /**********************************************************
356
     *  - Update settings of News Modul
357
     */
358

    
359
    // These are the default setting
360
    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
361
    $post_loop = '<tr class=\"post_top\">
362
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
363
<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
364
</tr>
365
<tr>
366
<td class=\"post_short\" colspan=\"2\">
367
[SHORT]
368
<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
369
</td>
370
</tr>';
371
    $footer = '</table>
372
<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
373
<tr>
374
<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
375
<td class="page-center">[OF]</td>
376
<td class="page-right">[NEXT_PAGE_LINK]</td>
377
</tr>
378
</table>';
379
    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
380
<tr>
381
<td><h1>[TITLE]</h1></td>
382
<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
383
</tr>
384
<tr>
385
<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
386
</tr>
387
<tr style="display: [DISPLAY_GROUP]">
388
<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
389
</tr>
390
</table>');
391
    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
392
<a href=\"[BACK]\">[TEXT_BACK]</a>';
393
    $comments_header = addslashes('<br /><br />
394
<h2>[TEXT_COMMENTS]</h2>
395
<table cellpadding="2" cellspacing="0" class="comment-header">');
396
    $comments_loop = addslashes('<tr>
397
<td class="comment_title">[TITLE]</td>
398
<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
399
</tr>
400
<tr>
401
<td colspan="2" class="comment_text">[COMMENT]</td>
402
</tr>');
403
    $comments_footer = '</table>
404
<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
405
    $comments_page = '<h1>[TEXT_COMMENT]</h1>
406
<h2>[POST_TITLE]</h2>
407
<br />';
408

    
409
    if(in_array('mod_news_settings', $all_tables))
410
    {
411
        // Insert default settings into database
412
        $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
413
        while($result = $query_dates->fetchRow())
414
        {
415

    
416
        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
417
        	$section_id = $result['section_id'];
418

    
419
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
420
        		echo 'Database data header added successfully';
421
        	}
422
        	echo mysql_error().'<br />';
423

    
424
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
425
        		echo 'Database data post_loop added successfully';
426
        	}
427
        	echo mysql_error().'<br />';
428

    
429
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
430
        		echo 'Database data footer added successfully';
431
        	}
432
        	echo mysql_error().'<br />';
433

    
434
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
435
        		echo 'Database data post_header added successfully';
436
        	}
437
        	echo mysql_error().'<br />';
438

    
439
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
440
        		echo 'Database data post_footer added successfully';
441
        	}
442
        	echo mysql_error().'<br />';
443

    
444
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
445
        		echo 'Database data comments_header added successfully';
446
        	}
447
        	echo mysql_error().'<br />';
448

    
449
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
450
        		echo 'Database data comments_loop added successfully';
451
        	}
452
        	echo mysql_error().'<br />';
453

    
454
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
455
        		echo 'Database data comments_footer added successfully';
456
        	}
457
        	echo mysql_error().'<br />';
458

    
459
        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
460
        		echo 'Database data comments_page added successfully';
461
        	}
462
        	echo mysql_error().'<br />';
463

    
464
        }
465
    }
466
    else
467
    {
468
        echo 'Missing database table '.TABLE_PREFIX.'mod_news_settings '.$FAIL.'<br />';
469
    }
470

    
471
    if(file_exists(WB_PATH."/modules/news/upgrade.php"))
472
    {
473
        echo '<h4>Upgrade existings postfiles to new format</h4><br />';
474
        // change old postfiles to new postfiles
475
        require_once(WB_PATH."/modules/news/upgrade.php");
476
}
477
}
478

    
479
/**********************************************************
480
 *  - Set Version to WB 2.8.1
481
 */
482
echo "<br />Update database version number to 2.8.1 : ";
483
echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value` = '$version' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
484

    
485
/**********************************************************
486
 *  - install droplets
487
 */
488
$drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
489
echo $drops;
490

    
491
 $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
492
 require_once (WB_PATH."/modules/droplets/".$file_name);
493

    
494
/**********************************************************
495
 *  - Reload all addons
496
 */
497

    
498
//delete modules
499
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
500
// Load all modules
501
if($handle = opendir(WB_PATH.'/modules/')) {
502
	while(false !== ($file = readdir($handle))) {
503
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
504
			load_module(WB_PATH.'/modules/'.$file);
505
		}
506
	}
507
	closedir($handle);
508
}
509
echo '<br />Modules reloaded<br />';
510

    
511
//delete templates		
512
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
513
// Load all templates
514
if($handle = opendir(WB_PATH.'/templates/')) {
515
	while(false !== ($file = readdir($handle))) {
516
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
517
			load_template(WB_PATH.'/templates/'.$file);
518
		}
519
	}
520
	closedir($handle);
521
}
522
echo '<br />Templates reloaded<br />';
523

    
524
//delete languages
525
$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
526
// Load all languages
527
if($handle = opendir(WB_PATH.'/languages/')) {
528
	while(false !== ($file = readdir($handle))) {
529
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
530
			load_language(WB_PATH.'/languages/'.$file);
531
		}
532
	}
533
	closedir($handle);
534
}
535
echo '<br />Languages reloaded<br />';
536

    
537

    
538
/**********************************************************
539
 *  - End of upgrade script
540
 */
541
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
542
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
543
// show buttons to go to the backend or frontend
544
echo '<br />';
545
if(defined('WB_URL')) {
546
	echo '<form action="'.WB_URL.'" target="_self">';
547
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
548
	echo '</form>';
549
}
550
if(defined('ADMIN_URL')) {
551
	echo '<form action="'.ADMIN_URL.'" target="_self">';
552
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
553
	echo '</form>';
554
}
555
echo '<p>&nbsp;</p>';
556

    
557
?>
558
</div>
559
</body>
560
</html>
(4-4/4)