Project

General

Profile

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

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

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

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

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

    
48
$OK            = ' <span class="ok">OK</span> ';
49
$FAIL          = ' <span class="error">FAILED</span> ';
50
$DEFAULT_THEME = 'wb_theme';
51
$stepID = 1;
52
$dirRemove = array(
53
/*
54
			'[TEMPLATE]/allcss/',
55
			'[TEMPLATE]/blank/',
56
			'[TEMPLATE]/round/',
57
			'[TEMPLATE]/simple/',
58
*/
59
			'[ADMIN]/themes/',
60
		 );
61

    
62
$filesRemove['0'] = array(
63

    
64
			'[ADMIN]/preferences/details.php',
65
			'[ADMIN]/preferences/email.php',
66
			'[ADMIN]/preferences/password.php',
67
			'[ADMIN]/pages/settings2.php'
68

    
69
		 );
70

    
71
$filesRemove['1'] = array(
72

    
73
			'[TEMPLATE]/argos_theme/templates/access.htt',
74
			'[TEMPLATE]/argos_theme/templates/addons.htt',
75
			'[TEMPLATE]/argos_theme/templates/admintools.htt',
76
			'[TEMPLATE]/argos_theme/templates/error.htt',
77
			'[TEMPLATE]/argos_theme/templates/groups.htt',
78
			'[TEMPLATE]/argos_theme/templates/groups_form.htt',
79
			'[TEMPLATE]/argos_theme/templates/languages.htt',
80
			'[TEMPLATE]/argos_theme/templates/languages_details.htt',
81
/*
82
			'[TEMPLATE]/argos_theme/templates/login.htt',
83
			'[TEMPLATE]/argos_theme/templates/login_forgot.htt',
84
*/
85
			'[TEMPLATE]/argos_theme/templates/media.htt',
86
			'[TEMPLATE]/argos_theme/templates/media_browse.htt',
87
			'[TEMPLATE]/argos_theme/templates/media_rename.htt',
88
			'[TEMPLATE]/argos_theme/templates/modules.htt',
89
			'[TEMPLATE]/argos_theme/templates/modules_details.htt',
90
			'[TEMPLATE]/argos_theme/templates/pages.htt',
91
			'[TEMPLATE]/argos_theme/templates/pages_modify.htt',
92
			'[TEMPLATE]/argos_theme/templates/pages_sections.htt',
93
			'[TEMPLATE]/argos_theme/templates/pages_settings.htt',
94
			'[TEMPLATE]/argos_theme/templates/preferences.htt',
95
			'[TEMPLATE]/argos_theme/templates/setparameter.htt',
96
			'[TEMPLATE]/argos_theme/templates/settings.htt',
97
			'[TEMPLATE]/argos_theme/templates/start.htt',
98
			'[TEMPLATE]/argos_theme/templates/success.htt',
99
			'[TEMPLATE]/argos_theme/templates/templates.htt',
100
			'[TEMPLATE]/argos_theme/templates/templates_details.htt',
101
			'[TEMPLATE]/argos_theme/templates/users.htt',
102
			'[TEMPLATE]/argos_theme/templates/users_form.htt',
103

    
104
			'[TEMPLATE]/wb_theme/templates/access.htt',
105
			'[TEMPLATE]/wb_theme/templates/addons.htt',
106
			'[TEMPLATE]/wb_theme/templates/admintools.htt',
107
			'[TEMPLATE]/wb_theme/templates/error.htt',
108
			'[TEMPLATE]/wb_theme/templates/groups.htt',
109
			'[TEMPLATE]/wb_theme/templates/groups_form.htt',
110
			'[TEMPLATE]/wb_theme/templates/languages.htt',
111
			'[TEMPLATE]/wb_theme/templates/languages_details.htt',
112

    
113
/*
114
			'[TEMPLATE]/wb_theme/templates/login.htt',
115
			'[TEMPLATE]/wb_theme/templates/login_forgot.htt',
116
*/
117

    
118
			'[TEMPLATE]/wb_theme/templates/media.htt',
119
			'[TEMPLATE]/wb_theme/templates/media_browse.htt',
120
			'[TEMPLATE]/wb_theme/templates/media_rename.htt',
121
			'[TEMPLATE]/wb_theme/templates/modules.htt',
122
			'[TEMPLATE]/wb_theme/templates/modules_details.htt',
123
			'[TEMPLATE]/wb_theme/templates/pages.htt',
124
			'[TEMPLATE]/wb_theme/templates/pages_modify.htt',
125
			'[TEMPLATE]/wb_theme/templates/pages_sections.htt',
126
			'[TEMPLATE]/wb_theme/templates/pages_settings.htt',
127
			'[TEMPLATE]/wb_theme/templates/preferences.htt',
128
			'[TEMPLATE]/wb_theme/templates/setparameter.htt',
129
			'[TEMPLATE]/wb_theme/templates/settings.htt',
130
			'[TEMPLATE]/wb_theme/templates/start.htt',
131
			'[TEMPLATE]/wb_theme/templates/success.htt',
132
			'[TEMPLATE]/wb_theme/templates/templates.htt',
133
			'[TEMPLATE]/wb_theme/templates/templates_details.htt',
134
			'[TEMPLATE]/wb_theme/templates/users.htt',
135
			'[TEMPLATE]/wb_theme/templates/users_form.htt',
136
		 );
137

    
138
// analyze/check database tables
139
function mysqlCheckTables( $dbName )
140
{
141
    global $table_list;
142
    $table_prefix = TABLE_PREFIX;
143
    $sql = "SHOW TABLES FROM " . $dbName;
144
    $result = @mysql_query( $sql );
145
    $data = array();
146
    $x = 0;
147

    
148
    while( ( $row = @mysql_fetch_array( $result, MYSQL_NUM ) ) == true )
149
    {
150
        $tmp = str_replace($table_prefix, '', $row[0]);
151

    
152
        if( stristr( $row[0], $table_prefix )&& in_array($tmp,$table_list) )
153
        {
154
            $sql = "CHECK TABLE " . $dbName . '.' . $row[0];
155
            $analyze = @mysql_query( $sql );
156
            $rowFetch = @mysql_fetch_array( $analyze, MYSQL_ASSOC );
157
            $data[$x]['Op'] = $rowFetch["Op"];
158
            $data[$x]['Msg_type'] = $rowFetch["Msg_type"];
159
            $msgColor = '<span class="error">';
160
            $data[$x]['Table'] = $row[0];
161
           // print  " ";
162
            $msgColor = ($rowFetch["Msg_text"] == 'OK') ? '<span class="ok">' : '<span class="error">';
163
            $data[$x]['Msg_text'] = $msgColor.$rowFetch["Msg_text"].'</span>';
164
           // print  "<br />";
165
            $x++;
166
        }
167
    }
168
    return $data;
169
}
170

    
171
// check existings tables for upgrade or install
172
function check_wb_tables()
173
{
174
    global $database,$table_list;
175

    
176
 // if prefix inludes '_' or '%'
177
 $search_for = addcslashes ( TABLE_PREFIX, '%_' );
178
 $get_result = $database->query( 'SHOW TABLES LIKE "'.$search_for.'%"');
179

    
180
        // $get_result = $database->query( "SHOW TABLES FROM ".DB_NAME);
181
        $all_tables = array();
182
        if($get_result->numRows() > 0)
183
        {
184
            while ($data = $get_result->fetchRow())
185
            {
186
                $tmp = str_replace(TABLE_PREFIX, '', $data[0]);
187
                if(in_array($tmp,$table_list))
188
                {
189
                    $all_tables[] = $tmp;
190
                }
191
            }
192
        }
193
     return $all_tables;
194
}
195

    
196
// check existing tables
197
$all_tables = check_wb_tables();
198

    
199
?>
200
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
201
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
202
<head>
203
<title>Upgrade script</title>
204
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
205
<style type="text/css">
206
html { overflow: -moz-scrollbars-vertical; /* Force firefox to always show room for a vertical scrollbar */ }
207

    
208
body {
209
	margin:0;
210
	padding:0;
211
	border:0;
212
	background: #EBF7FC;
213
	color:#000;
214
	font-family: 'Trebuchet MS', Verdana, Arial, Helvetica, Sans-Serif;
215
	font-size: small;
216
	height:101%;
217
}
218

    
219
#container {
220
	width:85%;
221
	background: #A8BCCB url(templates/wb_theme/images/background.png) repeat-x;
222
	border:1px solid #000;
223
	color:#000;
224
	margin:2em auto;
225
	padding:0 15px;
226
	min-height: 500px;
227
	text-align:left;
228
}
229

    
230
p { line-height:1.5em; }
231

    
232
form {
233
	display: inline-block;
234
	line-height: 20px;
235
	vertical-align: baseline;
236
}
237
input[type="submit"].restart {
238
	background-color: #FFDBDB;
239
	font-weight: bold;
240
}
241

    
242
h1,h2,h3,h4,h5,h6 {
243
	font-family: Verdana, Arial, Helvetica, sans-serif;
244
	color: #369;
245
	margin-top: 1.0em;
246
	margin-bottom: 0.1em;
247
}
248

    
249
h1 { font-size:150%; }
250
h2 { font-size: 130%; border-bottom: 1px #CCC solid; }
251
h3 { font-size: 120%; }
252

    
253
.ok, .error { font-weight:bold; }
254
.ok { color:green; }
255
.error { color:red; }
256
.check { color:#555; }
257

    
258
.warning {
259
	width: 98%;
260
	background:#FFDBDB;
261
	padding:0.2em;
262
	margin-top:0.5em;
263
	border: 1px solid black;
264
}
265
.info {
266
	width: 98%;
267
	background:#99CC99;
268
	padding:0.2em;
269
	margin-top:0.5em;
270
	border: 1px solid black;
271
}
272

    
273
</style>
274
</head>
275
<body>
276
<div id="container">
277
<img src="templates/wb_theme/images/logo.png" alt="WebsiteBaker Project" />
278
<h1>WebsiteBaker Upgrade</h1>
279
<?php
280
	if( version_compare( WB_VERSION, '2.7', '<' )) {
281
		status_msg('<strong>Warning:</strong><br />It is not possible to upgrade from WebsiteBaker Versions before 2.7.<br />For upgrading to version '.VERSION.' you must upgrade first to v.2.7 at least!!!', 'warning', 'div');
282
		echo '<br /><br />';
283
		echo "</div>
284
		</body>
285
		</html>
286
		";
287
		exit();
288
	}
289

    
290
$oldVersion  = 'Version '.WB_VERSION;
291
$oldVersion .= (defined('WB_SP') ? ' '.WB_SP : '');
292
$oldVersion .= (defined('WB_REVISION') ? ' Revision ['.WB_REVISION.'] ' : '') ;
293
$newVersion  = 'Version '.VERSION;
294
$newVersion .= (defined('SP') ? ' '.SP : '');
295
$newVersion .= (defined('REVISION') ? ' Revision ['.REVISION.'] ' : '');
296
// set addition settings if not exists, otherwise upgrade will be breaks
297
if(!defined('WB_SP')) { define('WB_SP',''); }
298
if(!defined('WB_REVISION')) { define('WB_REVISION',''); }
299

    
300
?>
301
<p>This script upgrades an existing WebsiteBaker <strong> <?php echo $oldVersion; ?></strong> installation to the <strong> <?php echo $newVersion ?> </strong>.<br />The upgrade script alters the existing WB database to reflect the changes introduced with WB 2.8.x</p>
302

    
303
<?php
304
/**
305
 * Check if disclaimer was accepted
306
 */
307
if (!(isset($_POST['backup_confirmed']) && $_POST['backup_confirmed'] == 'confirmed')) { ?>
308
<h2>Step 1: Backup your files</h2>
309
<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>
310

    
311
<form name="send" action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
312
<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>
313
<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.
314
<br /><br /><input name="send" type="submit" value="Start upgrade script" />
315
</form>
316
<br />
317

    
318
<?php
319
	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');
320
	echo '<br /><br />';
321
    echo "</div>
322
    </body>
323
    </html>
324
    ";
325
	exit();
326
}
327

    
328
echo '<h2>Step '.(++$stepID).' : Updating database entries</h2>';
329

    
330
// function to add a var/value-pair into settings-table
331
function db_add_key_value($key, $value) {
332
	global $database; global $OK; global $FAIL;
333
	$table = TABLE_PREFIX.'settings';
334
	$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
335
	if($query->numRows() > 0) {
336
		echo "$key: already exists. $OK.<br />";
337
		return true;
338
	} else {
339
		$database->query("INSERT INTO $table (name,value) VALUES ('$key', '$value')");
340
		echo (mysql_error()?mysql_error().'<br />':'');
341
		$query = $database->query("SELECT value FROM $table WHERE name = '$key' LIMIT 1");
342
		if($query->numRows() > 0) {
343
			echo "$key: $OK.<br />";
344
			return true;
345
		} else {
346
			echo "$key: $FAIL!<br />";
347
			return false;
348
		}
349
	}
350
}
351

    
352
// function to add a new field into a table
353
function db_add_field($field, $table, $desc) {
354
	global $database; global $OK; global $FAIL;
355
	$table = TABLE_PREFIX.$table;
356
	$query = $database->query("DESCRIBE $table '$field'");
357
	if($query->numRows() == 0) { // add field
358
		$query = $database->query("ALTER TABLE $table ADD $field $desc");
359
		echo (mysql_error()?mysql_error().'<br />':'');
360
		$query = $database->query("DESCRIBE $table '$field'");
361
		echo (mysql_error()?mysql_error().'<br />':'');
362
		if($query->numRows() > 0) {
363
			echo "'$field' added. $OK.<br />";
364
		} else {
365
			echo "adding '$field' $FAIL!<br />";
366
		}
367
	} else {
368
		echo "'$field' already exists. $OK.<br />";
369
	}
370
}
371

    
372
/**********************************************************
373
 *  - Adding field default_theme to settings table
374
 */
375
echo "<br />Adding default_theme to settings table<br />";
376
db_update_key_value('settings', 'default_theme', $DEFAULT_THEME);
377
/**********************************************************
378
 *  - install droplets
379
 */
380
    $drops = (!in_array ( "mod_droplets", $all_tables)) ? "<br />Install droplets<br />" : "<br />Upgrade droplets<br />";
381
    echo $drops;
382

    
383
     $file_name = (!in_array ( "mod_droplets", $all_tables) ? "install.php" : "upgrade.php");
384
     require_once (WB_PATH."/modules/droplets/".$file_name);
385

    
386
// check again all tables, to get a new array
387
 if(sizeof($all_tables) < 22) { $all_tables = check_wb_tables(); }
388
/**********************************************************
389
 *  - check tables comin with WebsiteBaker
390
 */
391
    $check_text = 'total ';
392
    // $check_tables = mysqlCheckTables( DB_NAME ) ;
393

    
394
    if(sizeof($all_tables) == 22)
395
    {
396
        echo '<h4>NOTICE: Your database '.DB_NAME.' has '.sizeof($all_tables).' '.$check_text.' tables from '.sizeof($table_list).' included in package '.$OK.'</h4>';
397
    }
398
    else
399
    {
400
        status_msg('<strong>WARNING:</strong><br />can\'t run Upgrade, missing tables', 'warning', 'div');
401
    	echo '<h4>Missing required tables. You can install them in backend->addons->modules->advanced. Then again run upgrade-script.php</h4>';
402
        $result = array_diff ( $table_list, $all_tables );
403
        echo '<h4 class="warning"><br />';
404
        while ( list ( $key, $val ) = each ( $result ) )
405
        {
406
            echo TABLE_PREFIX.$val.' '.$FAIL.'<br>';
407
        }
408
        echo '<br /></h4>';
409
    	echo '<br /><form action="'. $_SERVER['PHP_SELF'] .'">';
410
    	echo '<input type="submit" value="kick me back" style="float:left;" />';
411
    	echo '</form>';
412
        if(defined('ADMIN_URL'))
413
        {
414
        	echo '<form action="'.ADMIN_URL.'" target="_self">';
415
        	echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
416
        	echo '</form>';
417
        }
418
        echo "<br /><br /></div>
419
        </body>
420
        </html>
421
        ";
422
        exit();
423
    }
424

    
425
/**********************************************************
426
 *  - Adding field sec_anchor to settings table
427
 */
428
echo "<br />Adding sec_anchor to settings table<br />";
429
$cfg = array(
430
	'sec_anchor' => 'wb_'
431
);
432
foreach($cfg as $key=>$value) {
433
	db_add_key_value($key, $value);
434
}
435

    
436
/**********************************************************
437
 *  - Adding redirect timer to settings table
438
 */
439
echo "<br />Adding redirect timer to settings table<br />";
440
$cfg = array(
441
	'redirect_timer' => '1500'
442
);
443
foreach($cfg as $key=>$value) {
444
	db_add_key_value($key, $value);
445
}
446

    
447
/**********************************************************
448
 *  - Adding rename_files_on_upload to settings table
449
 */
450
echo "<br />Updating rename_files_on_upload to settings table<br />";
451
$cfg = array(
452
	'rename_files_on_upload' => 'ph.*?,cgi,pl,pm,exe,com,bat,pif,cmd,src,asp,aspx,js'
453
);
454
db_update_key_value('settings', 'rename_files_on_upload', $cfg['rename_files_on_upload']);
455

    
456
/**********************************************************
457
 *  - Adding mediasettings to settings table
458
 */
459
echo "<br />Adding mediasettings to settings table<br />";
460
$cfg = array(
461
	'mediasettings' => '',
462
);
463

    
464
foreach($cfg as $key=>$value) {
465
	db_add_key_value($key, $value);
466
}
467

    
468
/**********************************************************
469
 *  - Adding fingerprint_with_ip_octets to settings table
470
 */
471
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
472
$cfg = array(
473
	'fingerprint_with_ip_octets' => '2',
474
	'secure_form_module' => ''
475
);
476
foreach($cfg as $key=>$value) {
477
	db_add_key_value($key, $value);
478
}
479
/**********************************************************
480
 *  - Adding page_icon_dir to settings table
481
 */
482
echo "<br />Adding page_icon_dir to settings table<br />";
483
$cfg = array(
484
	'page_icon_dir' => '/templates/*/title_images',
485
);
486
foreach($cfg as $key=>$value) {
487
	db_add_key_value($key, $value);
488
}
489
/**********************************************************
490
 *  - Adding dev_infos to settings table
491
 */
492
echo "<br />Adding dev_infos to settings table<br />";
493
$cfg = array(
494
	'dev_infos' => 'true',
495
);
496
foreach($cfg as $key=>$value) {
497
	db_add_key_value($key, $value);
498
}
499

    
500
/**********************************************************
501
 *  - Add field "redirect_type" to table "mod_menu_link"
502
 */
503
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
504
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
505

    
506
/**********************************************************
507
 *  - Add field "page_icon" to table "pages"
508
 */
509
echo "<br />Adding field page_icon to pagestable<br />";
510
db_add_field('page_icon', 'pages', "TEXT NOT NULL DEFAULT '' AFTER `page_title`");
511

    
512
/**********************************************************
513
 *  - Add field "menu_icon_0" to table "pages"
514
 */
515
echo "<br />Adding field menu_icon_0 to pages table<br />";
516
db_add_field('menu_icon_0', 'pages', "TEXT NOT NULL DEFAULT '' AFTER `menu_title`");
517

    
518
/**********************************************************
519
 *  - Add field "menu_icon_1" to table "mod_menu_link"
520
 */
521
echo "<br />Adding field menu_icon_1 to pages table<br />";
522
db_add_field('menu_icon_1', 'pages', "TEXT NOT NULL DEFAULT '' AFTER `menu_icon_0`");
523

    
524
/**********************************************************
525
 *  - Update search no results database filed to create
526
 *  valid XHTML if search is empty
527
 */
528
if (version_compare(WB_VERSION, '2.8', '<'))
529
{
530
    echo "<br />Updating database field `no_results` of search table: ";
531
    $search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
532
    $sql  = 'UPDATE `'.TABLE_PREFIX.'search` ';
533
	$sql .= 'SET `value`=\''.$search_no_results.'\' ';
534
	$sql .= 'WHERE `name`=\'no_results\'';
535
    echo ($database->query($sql)) ? ' $OK<br />' : ' $FAIL<br />';
536
}
537
/**********************************************************
538
 * upgrade media folder index protect files
539
 */
540
	$dir = (WB_PATH.MEDIA_DIRECTORY);
541
	echo '<h4>Upgrade '.MEDIA_DIRECTORY.'/ index.php protect files</h4><br />';
542
	$array = rebuildFolderProtectFile($dir);
543
	if( sizeof( $array ) ){
544
		print '<br /><strong>Upgrade '.sizeof( $array ).' '.MEDIA_DIRECTORY.'/ protect files</strong>'." $OK<br />";
545
	} else {
546
		print '<br /><strong>Upgrade '.MEDIA_DIRECTORY.'/ protect files</strong>'." $FAIL!<br />";
547
		print implode ('<br />',$array);
548
	}
549
/**********************************************************
550
 * upgrade posts folder index protect files
551
 */
552
	$sPostsPath = WB_PATH.PAGES_DIRECTORY.'/posts';
553
	echo '<h4>Upgrade /posts/ index.php protect files</h4><br />';
554
	$array = rebuildFolderProtectFile($sPostsPath);
555
	if( sizeof( $array ) ){
556
		print '<br /><strong>Upgrade '.sizeof( $array ).' /posts/ protect files</strong>'." $OK<br />";
557
	} else {
558
		print '<br /><strong>Upgrade /posts/ protect files</strong>'." $FAIL!<br />";
559
		print implode ('<br />',$array);
560
	}
561
/* *****************************************************************************
562
 * - check for deprecated / never needed files
563
 */
564
	if(sizeof($filesRemove)) {
565
		echo '<h2>Step '.(++$stepID).': Remove deprecated and old files</h2>';
566
	}
567
	$searches = array(
568
		'[ADMIN]',
569
		'[MEDIA]',
570
		'[PAGES]',
571
		'[FRAMEWORK]',
572
		'[MODULES]',
573
		'[TEMPLATE]'
574
	);
575
	$replacements = array(
576
		substr(ADMIN_PATH, strlen(WB_PATH)+1),
577
		MEDIA_DIRECTORY,
578
		PAGES_DIRECTORY,
579
		'/framework',
580
		'/modules',
581
		'/templates'
582
	);
583

    
584
	foreach( $filesRemove as $filesId )
585
	{
586
		$msg = '';
587
		foreach( $filesId as $file )
588
		{
589
			$file = str_replace($searches, $replacements, $file);
590
			$file = WB_PATH.'/'.$file;
591
			if( file_exists($file) ) {
592
				// try to unlink file
593
				if(!is_writable( $file ) || !unlink($file)) {
594
					// save in err-list, if failed
595
					$msg .= $file.'<br />';
596
				}
597
			}
598
		}
599

    
600
		if($msg != '')
601
		{
602
			$msg = '<br /><br />Following files are deprecated, outdated or a security risk and
603
				    can not be removed automatically.<br /><br />Please delete them
604
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
605
	        status_msg($msg, 'error warning', 'div');
606
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
607

    
608
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
609
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
610
			echo '</form>';
611
			echo '<br /><br /></div></body></html>';
612
			exit;
613
		}
614
	}
615

    
616

    
617
/**********************************************************
618
 * - check for deprecated / never needed files
619
 */
620
	if(sizeof($dirRemove)) {
621
		echo '<h2>Step  '.(++$stepID).': Remove deprecated and old folders</h2>';
622
		$searches = array(
623
			'[ADMIN]',
624
			'[MEDIA]',
625
			'[PAGES]',
626
			'[TEMPLATE]'
627
		);
628
		$replacements = array(
629
			substr(ADMIN_PATH, strlen(WB_PATH)+1),
630
			MEDIA_DIRECTORY,
631
			PAGES_DIRECTORY,
632
			'/templates',
633
		);
634
		$msg = '';
635
		foreach( $dirRemove as $dir ) {
636
			$dir = str_replace($searches, $replacements, $dir);
637
			$dir = WB_PATH.'/'.$dir;
638
			if( is_dir( $dir )) {
639
			// try to delete dir
640
				if(!is_writable( $dir ) || !rm_full_dir($dir)) {
641
				// save in err-list, if failed
642
					$msg .= str_replace(WB_PATH,'',$dir).'<br />';
643
				}
644
			}
645
		}
646
		if($msg != '') {
647
			$msg = '<br /><br />Following directories are deprecated, outdated or a security risk and
648
					can not be removed automatically.<br /><br />Please delete them
649
					using FTP and restart upgrade-script!<br /><br />'.$msg.'<br />';
650
			status_msg($msg, 'error warning', 'div');
651
			echo '<p style="font-size:120%;"><strong>WARNING: The upgrade script failed ...</strong></p>';
652
			echo '<form action="'.$_SERVER['SCRIPT_NAME'].'">';
653
			echo '&nbsp;<input name="send" type="submit" value="Restart upgrade script" />';
654
			echo '</form>';
655
			echo '<br /><br /></div></body></html>';
656
			exit;
657
		}
658
	}
659

    
660
/**********************************************************
661
 * upgrade modules if newer version is available
662
 */
663
	$aModuleList = array('news');
664
	foreach($aModuleList as $sModul) {
665
		if(file_exists(WB_PATH.'/modules/'.$sModul.'/upgrade.php')) {
666
			$currModulVersion = get_modul_version ($sModul, false);
667
			$newModulVersion =  get_modul_version ($sModul, true);
668
			if((version_compare($currModulVersion, $newModulVersion) <= 0)) {
669
				echo '<h2>Step '.(++$stepID).' : Upgrade module \''.$sModul.'\' to version '.$newModulVersion.'</h2>';
670
				require_once(WB_PATH.'/modules/'.$sModul.'/upgrade.php');
671
			}
672
		}
673
	}
674
/**********************************************************
675
 *  - Reload all addons
676
 */
677

    
678
	echo '<h2>Step '.(++$stepID).' : Reload all addons database entry (no upgrade)</h2>';
679
	////delete modules
680
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'module'");
681
	// Load all modules
682
	if( ($handle = opendir(WB_PATH.'/modules/')) ) {
683
		while(false !== ($file = readdir($handle))) {
684
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'admin.php' AND $file != 'index.php') {
685
				load_module(WB_PATH.'/modules/'.$file );
686
			   // 	upgrade_module($file, true);
687
			}
688
		}
689
		closedir($handle);
690
	}
691
	echo '<br />Modules reloaded<br />';
692

    
693
	////delete templates
694
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'template'");
695
	// Load all templates
696
	if( ($handle = opendir(WB_PATH.'/templates/')) ) {
697
		while(false !== ($file = readdir($handle))) {
698
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
699
				load_template(WB_PATH.'/templates/'.$file);
700
			}
701
		}
702
		closedir($handle);
703
	}
704
	echo '<br />Templates reloaded<br />';
705

    
706
	////delete languages
707
	//$database->query("DELETE FROM ".TABLE_PREFIX."addons WHERE type = 'language'");
708
	// Load all languages
709
	if( ($handle = opendir(WB_PATH.'/languages/')) ) {
710
		while(false !== ($file = readdir($handle))) {
711
			if($file != '' AND substr($file, 0, 1) != '.' AND $file != 'index.php') {
712
				load_language(WB_PATH.'/languages/'.$file);
713
			}
714
		}
715
		closedir($handle);
716
	}
717
	echo '<br />Languages reloaded<br />';
718

    
719
/**********************************************************
720
 *  - End of upgrade script
721
 */
722

    
723
// require(WB_PATH.'/framework/initialize.php');
724

    
725
	if(!defined('DEFAULT_THEME')) { define('DEFAULT_THEME', $DEFAULT_THEME); }
726
	if(!defined('THEME_PATH')) { define('THEME_PATH', WB_PATH.'/templates/'.DEFAULT_THEME);}
727
/**********************************************************
728
 *  - Set Version to new Version
729
 */
730
	echo '<br />Update database version number to '.VERSION.' '.SP.' '.' Revision ['.REVISION.'] : ';
731
	// echo ($database->query("UPDATE `".TABLE_PREFIX."settings` SET `value`='".VERSION."' WHERE `name` = 'wb_version'")) ? " $OK<br />" : " $FAIL<br />";
732
	db_update_key_value('settings', 'wb_version', VERSION);
733
	db_update_key_value('settings', 'wb_revision', REVISION);
734
	db_update_key_value('settings', 'wb_sp', SP);
735

    
736
	echo '<p style="font-size:120%;"><strong>Congratulations: The upgrade script is finished ...</strong></p>';
737
	status_msg('<strong>Warning:</strong><br />Please delete the file <strong>upgrade-script.php</strong> via FTP before proceeding.', 'warning', 'div');
738
	// show buttons to go to the backend or frontend
739
	echo '<br />';
740

    
741
	if(defined('WB_URL')) {
742
		echo '<form action="'.WB_URL.'/">';
743
		echo '&nbsp;<input type="submit" value="kick me to the Frontend" />';
744
		echo '</form>';
745
	}
746
	if(defined('ADMIN_URL')) {
747
		echo '<form action="'.ADMIN_URL.'/">';
748
		echo '&nbsp;<input type="submit" value="kick me to the Backend" />';
749
		echo '</form>';
750
	}
751

    
752
	echo '<br /><br /></div></body></html>';
(5-5/5)