Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        backend
5
 * @package         installation
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id: upgrade-script.php 1484 2011-07-31 19:42:13Z Luisehahne $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/upgrade-script.php $
15
 * @lastmodified    $Date: 2011-07-31 21:42:13 +0200 (Sun, 31 Jul 2011) $
16
 *
17
 */
18

    
19
@require_once('config.php');
20

    
21
require_once(WB_PATH.'/framework/functions.php');
22
require_once(WB_PATH.'/framework/class.admin.php');
23
$admin = new admin('Addons', 'modules', false, false);
24

    
25
/* display a status message on the screen **************************************
26
 * @param string $message: the message to show
27
 * @param string $class:   kind of message as a css-class
28
 * @param string $element: witch HTML-tag use to cover the message
29
 * @return void
30
 */
31
function status_msg($message, $class='check', $element='span')
32
{
33
	// returns a status message
34
	$msg  = '<'.$element.' class="'.$class.'">';
35
	$msg .= '<strong>'.strtoupper(strtok($class, ' ')).'</strong><br />';
36
	$msg .= $message.'</'.$element.'>';
37
	echo $msg;
38
}
39

    
40
// database tables including in WB package
41
$table_list = array (
42
    'settings','groups','addons','pages','sections','search','users',
43
    'mod_captcha_control','mod_code','mod_droplets','mod_form_fields',
44
    'mod_form_settings','mod_form_submissions','mod_jsadmin','mod_menu_link',
45
    'mod_news_comments','mod_news_groups','mod_news_posts','mod_news_settings',
46
    'mod_output_filter','mod_wrapper','mod_wysiwyg'
47
);
48

    
49
$OK            = ' <span class="ok">OK</span> ';
50
$FAIL          = ' <span class="error">FAILED</span> ';
51
$DEFAULT_THEME = 'wb_theme';
52

    
53
$files2remove = array(
54

    
55
			'[ADMIN]/preferences/details.php',
56
			'[ADMIN]/preferences/email.php',
57
			'[ADMIN]/preferences/password.php',
58
/*
59
			'[TEMPLATE]/allcss/',
60
			'[TEMPLATE]/blank/',
61
			'[TEMPLATE]/round/',
62
			'[TEMPLATE]/simple/',
63
*/
64
		 );
65

    
66

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

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

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

    
100
// check existings tables for upgrade or install
101
function check_wb_tables()
102
{
103
    global $database,$table_list;
104

    
105
 // if prefix inludes '_' or '%'
106
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
107
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
108

    
109
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
110
        $all_tables = array();
111
        if($get_result->numRows() > 0)
112
        {
113
            while ($data = $get_result->fetchRow())
114
            {
115
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
116
                if(in_array($tmp,$table_list))
117
                {
118
                    $all_tables[] = $tmp;
119
                }
120
            }
121
        }
122
     return $all_tables;
123
}
124

    
125
// check existing tables
126
$all_tables = check_wb_tables();
127

    
128
?>
129
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
130
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
131
<head>
132
<title>Upgrade script</title>
133
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
134
<style type="text/css">
135
html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
136

    
137
body {
138
	margin:0;
139
	padding:0;
140
	border:0;
141
	background: #EBF7FC;
142
	color:#000;
143
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
144
	font-size: small;
145
	height:101%;
146
}
147

    
148
#container {
149
	width:85%;
150
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
151
	border:1px solid #000;
152
	color:#000;
153
	margin:2em auto;
154
	padding:0 15px;
155
	min-height: 500px;
156
	text-align:left;
157
}
158

    
159
p { line-height:1.5em; }
160

    
161
h1,h2,h3,h4,h5,h6 {
162
	font-family: Verdana, Arial, Helvetica, sans-serif;
163
	color: #369;
164
	margin-top: 1.0em;
165
	margin-bottom: 0.1em;
166
}
167

    
168
h1 { font-size:150%; }
169
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
170
h3 { font-size: 120%; }
171

    
172
.ok, .error { font-weight:bold; }
173
.ok { color:green; }
174
.error { color:red; }
175
.check { color:#555; }
176

    
177
.warning {
178
	width: 98%;
179
	background:#FFDBDB;
180
	padding:0.2em;
181
	margin-top:0.5em;
182
	border: 1px solid black;
183
}
184
.info {
185
	width: 98%;
186
	background:#99CC99;
187
	padding:0.2em;
188
	margin-top:0.5em;
189
	border: 1px solid black;
190
}
191

    
192
</style>
193
</head>
194
<body>
195
<div id="container">
196
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
197
<h1>WebsiteBaker Upgrade</h1>
198
<?php
199
	if( version_compare( WB_VERSION, '2.7.0', '<' )) {
200
		status_msg('<strong>Warning:</strong><br />It is not possible to upgrade from WebsiteBaker Versions before 2.7.0.<br />For upgrading to version '.VERSION.' you must upgrade first to v.2.7.0 at least!!!', 'warning', 'div');
201
		echo '<br /><br />';
202
		echo "</div>
203
		</body>
204
		</html>
205
		";
206
		exit();
207
	}
208
?>
209
<p>This script upgrades an existing WebsiteBaker <strong>Version <?php echo WB_VERSION; ?></strong> installation to the <strong>Version <?php echo VERSION ?></strong>. The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
210

    
211
<?php
212
/**
213
 * Check if disclaimer was accepted
214
 */
215
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
216
<h2>Step 1: Backup your files</h2>
217
<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>
218

    
219
<form name="send" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
220
<textarea cols="80" rows="5">DISCLAIMER: The WebsiteBaker 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 WebsiteBaker MySQL database was created before you can proceed.</textarea>
221
<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.
222
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
223
</form>
224
<br />
225

    
226
<?php
227
	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');
228
	echo '<br /><br />';
229
    echo "</div>
230
    </body>
231
    </html>
232
    ";
233
	exit();
234
}
235
echo '<h2>Step 2: Updating database entries</h2>';
236

    
237
// function to add a var/value-pair into settings-table
238
function db_add_key_value($key, $value) {
239
	global $database; global $OK; global $FAIL;
240
	$table = TABLE_PREFIX.'settings';
241
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
242
	if($query->numRows() > 0) {
243
		echo "$key: already exists. $OK.<br />";
244
		return true;
245
	} else {
246
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
247
		echo (mysql_error()?mysql_error().'<br />':'');
248
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
249
		if($query->numRows() > 0) {
250
			echo "$key: $OK.<br />";
251
			return true;
252
		} else {
253
			echo "$key: $FAIL!<br />";
254
			return false;
255
		}
256
	}
257
}
258

    
259
// function to add a new field into a table
260
function db_add_field($field, $table, $desc) {
261
	global $database; global $OK; global $FAIL;
262
	$table = TABLE_PREFIX.$table;
263
	$query = $database->query("DESCRIBE $table '$field'");
264
	if($query->numRows() == 0) { // add field
265
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
266
		echo (mysql_error()?mysql_error().'<br />':'');
267
		$query = $database->query("DESCRIBE $table '$field'");
268
		echo (mysql_error()?mysql_error().'<br />':'');
269
		if($query->numRows() > 0) {
270
			echo "'$field' added. $OK.<br />";
271
		} else {
272
			echo "adding '$field' $FAIL!<br />";
273
		}
274
	} else {
275
		echo "'$field' already exists. $OK.<br />";
276
	}
277
}
278

    
279
/**********************************************************
280
 *  - Adding field default_theme to settings table
281
 */
282
echo "<br />Adding default_theme to settings table<br />";
283
db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
284
/*
285
$cfg = array(
286
	'default_theme' => 'wb_theme'
287
);
288
foreach($cfg as $key=>$value) {
289
	db_add_key_value($key, $value);
290
}
291
*/
292
/**********************************************************
293
 *  - install droplets
294
 */
295
    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
296
    echo $drops;
297

    
298
     $file_name = (!in_array ( "mod_droplets", $all_tables)) ? "install.php" : "upgrade.php";
299
     require_once (WB_PATH."/modules/droplets/".$file_name);
300

    
301
// check again all tables, to get a new array
302
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
303
/**********************************************************
304
 *  - check tables comin with WebsiteBaker
305
 */
306
    $check_text = 'total ';
307
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
308

    
309
    if(sizeof($all_tables) == 22)
310
    {
311
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
312
    }
313
    else
314
    {
315
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
316
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
317
        $result = array_diff ( $table_list, $all_tables );
318
        echo '<h4 class="warning"><br />';
319
        while ( list ( $key, $val ) = each ( $result ) )
320
        {
321
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
322
        }
323
        echo '<br /></h4>';
324
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
325
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
326
    	echo '</form>';
327
        if(defined('ADMIN_URL'))
328
        {
329
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
330
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
331
        	echo '</form>';
332
        }
333
        echo "<br /><br /></div>
334
        </body>
335
        </html>
336
        ";
337
        exit();
338
    }
339

    
340
/**********************************************************
341
 *  - Adding field sec_anchor to settings table
342
 */
343
echo "<br />Adding sec_anchor to settings table<br />";
344
$cfg = array(
345
	'sec_anchor' => 'wb_'
346
);
347
foreach($cfg as $key=>$value) {
348
	db_add_key_value($key, $value);
349
}
350

    
351
/**********************************************************
352
 *  - Adding redirect timer to settings table
353
 */
354
echo "<br />Adding redirect timer to settings table<br />";
355
$cfg = array(
356
	'redirect_timer' => '1500'
357
);
358
foreach($cfg as $key=>$value) {
359
	db_add_key_value($key, $value);
360
}
361

    
362
/**********************************************************
363
 *  - Adding mediasettings to settings table
364
 */
365
echo "<br />Adding mediasettings to settings table<br />";
366
$cfg = array(
367
	'mediasettings' => '',
368
	'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
369
);
370
db_update_key_value('settings', 'rename_files_on_upload', $cfg['rename_files_on_upload']);
371

    
372
foreach($cfg as $key=>$value) {
373
	db_add_key_value($key, $value);
374
}
375

    
376
/**********************************************************
377
 *  - Adding fingerprint_with_ip_octets to settings table
378
 */
379
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
380
$cfg = array(
381
	'fingerprint_with_ip_octets' => '2',
382
	'secure_form_module' => ''
383
);
384
foreach($cfg as $key=>$value) {
385
	db_add_key_value($key, $value);
386
}
387

    
388
/**********************************************************
389
 *  - Add field "redirect_type" to table "mod_menu_link"
390
 */
391
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
392
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
393

    
394
if (version_compare(WB_VERSION, '2.8.0') < 0)
395
{
396
    /**********************************************************
397
     *  - Update search no results database filed to create
398
     *  valid XHTML if search is empty
399
     */
400
    echo "<br />Updating database field `no_results` of search table: ";
401
    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
402
    $sql = "UPDATE `" . TABLE_PREFIX . "search` SET `value` = '$search_no_results' WHERE `name`= 'no_results'";
403
    $database->query($sql);
404
    echo ($database->query($sql)) ? " $OK<br />" : " $FAIL<br />";
405
    /**********************************************************
406
     *  - Update settings of News Modul
407
     */
408

    
409
    // These are the default setting
410
    $header = '<table cellpadding=\"0\" cellspacing=\"0\" class=\"loop-header\">'."\n";
411
    $post_loop = '<tr class=\"post_top\">
412
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
413
<td class=\"post_date\">[PUBLISHED_TIME], [PUBLISHED_DATE]</td>
414
</tr>
415
<tr>
416
<td class=\"post_short\" colspan=\"2\">
417
[SHORT]
418
<span style=\"visibility:[SHOW_READ_MORE];\"><a href=\"[LINK]\">[TEXT_READ_MORE]</a></span>
419
</td>
420
</tr>';
421
    $footer = '</table>
422
<table cellpadding="0" cellspacing="0" class="page-header" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
423
<tr>
424
<td class="page-left">[PREVIOUS_PAGE_LINK]</td>
425
<td class="page-center">[OF]</td>
426
<td class="page-right">[NEXT_PAGE_LINK]</td>
427
</tr>
428
</table>';
429
    $post_header = addslashes('<table cellpadding="0" cellspacing="0" class="post-header">
430
<tr>
431
<td><h1>[TITLE]</h1></td>
432
<td rowspan="3" style="display: [DISPLAY_IMAGE]">[GROUP_IMAGE]</td>
433
</tr>
434
<tr>
435
<td class="public-info"><b>[TEXT_POSTED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [PUBLISHED_DATE]</b></td>
436
</tr>
437
<tr style="display: [DISPLAY_GROUP]">
438
<td class="group-page"><a href="[BACK]">[PAGE_TITLE]</a> &gt;&gt; <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
439
</tr>
440
</table>');
441
    $post_footer = '<p>[TEXT_LAST_CHANGED]: [MODI_DATE] [TEXT_AT] [MODI_TIME]</p>
442
<a href=\"[BACK]\">[TEXT_BACK]</a>';
443
    $comments_header = addslashes('<br /><br />
444
<h2>[TEXT_COMMENTS]</h2>
445
<table cellpadding="2" cellspacing="0" class="comment-header">');
446
    $comments_loop = addslashes('<tr>
447
<td class="comment_title">[TITLE]</td>
448
<td class="comment_info">[TEXT_BY] [DISPLAY_NAME] [TEXT_ON] [DATE] [TEXT_AT] [TIME]</td>
449
</tr>
450
<tr>
451
<td colspan="2" class="comment_text">[COMMENT]</td>
452
</tr>');
453
    $comments_footer = '</table>
454
<br /><a href=\"[ADD_COMMENT_URL]\">[TEXT_ADD_COMMENT]</a>';
455
    $comments_page = '<h1>[TEXT_COMMENT]</h1>
456
<h2>[POST_TITLE]</h2>
457
<br />';
458

    
459
	if(in_array('mod_news_settings', $all_tables))
460
	{
461
	   // Insert default settings into database
462
	   $query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
463
	   if($query_dates->numRows() > 1)
464
	   {
465
	        while($result = $query_dates->fetchRow())
466
	        {
467

    
468
	        	echo "<br /><u>Add default settings to database for news section_id= ".$result['section_id']."</u><br />";
469
	        	$section_id = $result['section_id'];
470

    
471
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
472
	        		echo 'Database data header added successfully';
473
	        	}
474
	        	echo mysql_error().'<br />';
475

    
476
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
477
	        		echo 'Database data post_loop added successfully';
478
	        	}
479
	        	echo mysql_error().'<br />';
480

    
481
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `footer` = '$footer' WHERE `section_id` = $section_id")) {
482
	        		echo 'Database data footer added successfully';
483
	        	}
484
	        	echo mysql_error().'<br />';
485

    
486
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
487
	        		echo 'Database data post_header added successfully';
488
	        	}
489
	        	echo mysql_error().'<br />';
490

    
491
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
492
	        		echo 'Database data post_footer added successfully';
493
	        	}
494
	        	echo mysql_error().'<br />';
495

    
496
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
497
	        		echo 'Database data comments_header added successfully';
498
	        	}
499
	        	echo mysql_error().'<br />';
500

    
501
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_loop` = '$comments_loop' WHERE `section_id` = $section_id")) {
502
	        		echo 'Database data comments_loop added successfully';
503
	        	}
504
	        	echo mysql_error().'<br />';
505

    
506
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_footer` = '$comments_footer' WHERE `section_id` = $section_id")) {
507
	        		echo 'Database data comments_footer added successfully';
508
	        	}
509
	        	echo mysql_error().'<br />';
510

    
511
	        	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_page` = '$comments_page' WHERE `section_id` = $section_id")) {
512
	        		echo 'Database data comments_page added successfully';
513
	        	}
514
	        	echo mysql_error().'<br />';
515

    
516
	        }
517
	     }
518
	   }
519
}
520
/**********************************************************
521
 * upgrade media folder index protect files
522
 */
523
$dir = (WB_PATH.MEDIA_DIRECTORY);
524
echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4><br />';
525
$array = rebuildFolderProtectFile($dir);
526
if( sizeof( $array ) ){
527
	print '<br /><strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
528
} else {
529
	print '<br /><strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
530
	print implode ('<br />',$array);
531
}
532

    
533
/**********************************************************
534
 * upgrade news if newer version is available
535
 */
536
	if(file_exists(WB_PATH.'/modules/news/upgrade.php'))
537
	{
538
		$currNewsVersion = get_modul_version ('news', false);
539
		$newNewsVersion =  get_modul_version ('news', true);
540
		if((version_compare($currNewsVersion, $newNewsVersion) <= 0)) {
541
			echo '<h4>Upgrade existings basically news module</h4><br />';
542
			// change old postfiles to new postfiles
543
			require_once(WB_PATH."/modules/news/upgrade.php");
544
		}
545
	}
546
/**********************************************************
547
 *  - Set Version to new Version
548
 */
549
echo '<br />Update database version number to '.VERSION.' : ';
550
// echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value`='".VERSION."' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
551
db_update_key_value('settings', 'wb_version', VERSION);
552

    
553
/* *****************************************************************************
554
 * - check for deprecated / never needed files
555
 */
556
?>
557
<h2>Step 3: Remove deprecated and old files</h2>
558
<?php
559

    
560
	$searches = array(
561
		'[ADMIN]',
562
		'[MEDIA]',
563
		'[PAGES]'
564
	);
565
	$replacements = array(
566
		substr(ADMIN_PATH, strlen(WB_PATH)),
567
		MEDIA_DIRECTORY,
568
		PAGES_DIRECTORY
569
	);
570

    
571
	$msg = '';
572
	foreach( $files2remove as $file )
573
	{
574
		$file = str_replace($searches, $replacements, $file);
575
		$file = WB_PATH.'/'.$file;
576
		if( file_exists( $file ))
577
		{ // try to unlink file
578
			if(!unlink($file))
579
			{ // save in err-list, if failed
580
				$msg .= $file.'<br />';
581
			}
582
		}
583
	}
584

    
585
	if($msg != '')
586
	{
587
		$msg = 'Following files are deprecated, outdated or a security risk and
588
			    can not be removed automatically.<br /><br />Please delete them
589
				using FTP and restart upgrade-script!<br /><br />'.$msg;
590
        status_msg($msg, 'error warning', 'div');
591
		echo '<br /><br /></div></body></html>';
592
		exit();
593
	}
594
/**********************************************************
595
 *  - Reload all addons
596
 */
597

    
598
////delete modules
599
//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
600
// Load all modules
601
if( ($handle = opendir(WB_PATH.'/modules/')) ) {
602
	while(false !== ($file = readdir($handle))) {
603
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
604
			load_module(WB_PATH.'/modules/'.$file );
605
		   // 	upgrade_module($file, true);
606
		}
607
	}
608
	closedir($handle);
609
}
610
echo '<br />Modules reloaded<br />';
611

    
612
////delete templates
613
//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
614
// Load all templates
615
if( ($handle = opendir(WB_PATH.'/templates/')) ) {
616
	while(false !== ($file = readdir($handle))) {
617
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
618
			load_template(WB_PATH.'/templates/'.$file);
619
		}
620
	}
621
	closedir($handle);
622
}
623
echo '<br />Templates reloaded<br />';
624

    
625
////delete languages
626
//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
627
// Load all languages
628
if( ($handle = opendir(WB_PATH.'/languages/')) ) {
629
	while(false !== ($file = readdir($handle))) {
630
		if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
631
			load_language(WB_PATH.'/languages/'.$file);
632
		}
633
	}
634
	closedir($handle);
635
}
636
echo '<br />Languages reloaded<br />';
637

    
638

    
639
/**********************************************************
640
 *  - End of upgrade script
641
 */
642

    
643
// require(WB_PATH.'/framework/initialize.php');
644

    
645
if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
646
if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
647

    
648
echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
649
status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
650
// show buttons to go to the backend or frontend
651
echo '<br />';
652
if(defined('WB_URL')) {
653
	echo '<form action="'.WB_URL.'">';
654
	echo '<input type="submit" value="kick me to the Frontend" style="float:left;" />';
655
	echo '</form>';
656
}
657
if(defined('ADMIN_URL')) {
658
	echo '<form action="'.ADMIN_URL.'">';
659
	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
660
	echo '</form>';
661
}
662
echo '<p>&nbsp;</p>';
663

    
664
?>
665
</div>
666
</body>
667
</html>
(5-5/5)