Project

General

Profile

1
<?php
2

    
3
// $Id: upgrade-script.php 566 2008-01-19 15:15:10Z thorn $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
//
27
// upgrade-script for Website Baker from version 2.6.7 to 2.7
28
//
29

    
30
require('config.php');
31
require(WB_PATH.'/framework/functions.php');
32

    
33
?>
34

    
35
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
36
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
37
<head>
38
<title>Upgrade-Script</title>
39
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
40
</head>
41
<body>
42
<style type="text/css">
43
<!--
44
*.red { background-color:#FF0000 }
45
*.green { background-color:#00FF00 }
46
-->
47
</style>
48

    
49
<h2>Upgrade-script</h2>
50
<p>
51
will upgrade Website Baker 2.6.5 / 2.6.7 to version 2.7
52
</p>
53
<?php
54

    
55
$OK   = '<span class="green">OK</span>';
56
$FAIL = '<span class="red">failed</span>';
57

    
58

    
59
/**********************************************************
60
 *  - modules-based search
61
 */
62
function db_add_search_key_value($key, $value) {
63
	global $database; global $OK; global $FAIL;
64
	$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = '$key' LIMIT 1");
65
	if($query->numRows() > 0) {
66
		echo "$key: allready there. $OK.<br />";
67
		return true;
68
	} else {
69
		$database->query("INSERT INTO D".TABLE_PREFIX."search (name,value,extra) VALUES ('$key', '$value', '')");
70
		echo mysql_error()?'<br />':'';
71
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = '$key' LIMIT 1");
72
		if($query->numRows() > 0) {
73
			echo "$key: $OK.<br />";
74
			return true;
75
		} else {
76
			echo "$key: $FAIL!<br />";
77
			return false;
78
		}
79
	}
80
}
81

    
82

    
83
echo "<br /><u>Adding module_order and max_excerpt to search-table</u><br />";
84
// module_order - in which order to show the search-results
85
// max_excerpt - how many lines of excerpt to print per matching page
86

    
87
$cfg = array(
88
	'module_order' => 'faqbaker,manual,wysiwyg',
89
	'max_excerpt' => '15'
90
);
91
foreach($cfg as $key=>$value) {
92
	db_add_search_key_value($key, $value);
93
}
94

    
95

    
96
echo "<br /><u>Changing results_loop in search-table</u><br />";
97
// adding [EXCERPT]
98

    
99
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
100
if($query->numRows() > 0) {
101
	$fetch_results_loop = $query->fetchRow();
102
	$string = $fetch_results_loop['value'];
103
	if(preg_match("/\[EXCERPT\]/", $string)) {
104
		echo "[EXCERPT] is allready there. $OK.<br />";
105
	} else {
106
		$string = preg_replace("/10px;\">\[DESCRIPTION\]/", "5px;\">[DESCRIPTION]", $string);
107
		$string .= "<tr><td colspan=\"2\" style=\"text-align: justify; padding-bottom: 10px;\">[EXCERPT]</td></tr>";
108
		$string = addslashes($string);
109
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='results_loop',value='".$string."',extra='' WHERE name = 'results_loop' LIMIT 1");
110
		echo mysql_error().'<br />';
111
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'results_loop' LIMIT 1");
112
		if($query->numRows() > 0) {
113
			$fetch_results_loop = $query->fetchRow();
114
			$string = $fetch_results_loop['value'];
115
			if(preg_match("/\[EXCERPT\]/", $string)) {
116
				echo "[EXCERPT] added. $OK.<br />";
117
			} else {
118
				echo "adding [EXCERPT] $FAIL!<br />";
119
			}
120
		}
121
	}
122
}
123

    
124
echo "<br /><u>Changing \"Header:\" in search-table</u><br />";
125
// adding [SEARCH_PATH]
126

    
127
$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
128
if($query->numRows() > 0) {
129
	$fetch_header = $query->fetchRow();
130
	$string = $fetch_header['value'];
131
	if(preg_match("/\[SEARCH_PATH\]/", $string)) {
132
		echo "[SEARCH_PATH] is allready there. $OK.<br />";
133
	} else {
134
		$string = preg_replace("/<input type=\"text\" name=\"string\" value=\"\[SEARCH_STRING\]\" style=\"width: 100%;\" \/>/", "<input type=\"hidden\" name=\"search_path\" value=\"[SEARCH_PATH]\" /><input type=\"text\" name=\"string\" value=\"[SEARCH_STRING]\" style=\"width: 100%;\" />", $string);
135
		$string = addslashes($string);
136
		$database->query("UPDATE ".TABLE_PREFIX."search SET name='header',value='".$string."',extra='' WHERE name = 'header' LIMIT 1");
137
		echo mysql_error().'<br />';
138
		$query = $database->query("SELECT value FROM ".TABLE_PREFIX."search WHERE name = 'header' LIMIT 1");
139
		if($query->numRows() > 0) {
140
			$fetch_header = $query->fetchRow();
141
			$string = $fetch_header['value'];
142
			if(preg_match("/\[SEARCH_PATH\]/", $string)) {
143
				echo "[SEARCH_PATH] added. $OK.<br />";
144
			} else {
145
				echo "adding [SEARCH_PATH] $FAIL!<br />";
146
			}
147
		}
148
	}
149
}
150

    
151
echo "<br /><u>Adding some internal config-elements to search-table</u><br />";
152
// These are global config-elements which don't appear in settings-page. Change them in the database if needed.
153
// cfg_show_description - whether to show page-description on the results page (true/false), def: true
154
// cfg_search_description - whether to search in page-description (true/false), def: true [only used while searching title/link/description/keywords]
155
// cfg_search_keywords - whether to search in page-keywords (true/false), def: true [only used while searching title/link/description/keywords]
156
// cfg_enable_old_search - use old search-method, too (true/false), def: true [use old method as fallback]
157
$cfg = array(
158
	'cfg_show_description' => 'true',
159
	'cfg_search_description' => 'true',
160
	'cfg_search_keywords' => 'true',
161
	'cfg_enable_old_search' => 'true'
162
);
163
foreach($cfg as $key=>$value) {
164
	db_add_search_key_value($key, $value);
165
}
166

    
167

    
168
/**********************************************************
169
 *  - publish-by-date
170
 */
171
echo "<br /><u>Adding fields 'publ_start' and 'publ_end' to table 'sections'</u><br />";
172
// Add fields "publ_start" and "publ_end" to table "sections"
173
// check if fields are present
174
$table = TABLE_PREFIX."sections";
175
$query = $database->query("DESCRIBE $table 'publ_start'");
176
if($query->numRows() == 0) { // add field
177
	$query = $database->query("ALTER TABLE $table ADD publ_start INT NOT NULL DEFAULT '0'");
178
	$query = $database->query("DESCRIBE $table 'publ_start'");
179
	if($query->numRows() > 0) {
180
		echo "'publ_start' added. $OK.<br />";
181
	} else {
182
		echo "adding 'publ_start' $FAIL!<br />";
183
	}
184
} else {
185
	echo "'publ_start' allready there. $OK.<br />";
186
}
187
$query = $database->query("DESCRIBE $table 'publ_end'");
188
if($query->numRows() == 0) { // add field
189
	$query = $database->query("ALTER TABLE $table ADD publ_end INT NOT NULL DEFAULT '0'");
190
	$query = $database->query("DESCRIBE $table 'publ_end'");
191
	if($query->numRows() > 0) {
192
		echo "'publ_end' added. $OK.<br />";
193
	} else {
194
		echo "adding 'publ_end' $FAIL!<br />";
195
	}
196
} else {
197
	echo "'publ_end' allready there. $OK<br />";
198
}
199

    
200

    
201
/**********************************************************
202
 *  - core-module menu_link
203
 */
204
// create table
205
$table = TABLE_PREFIX ."mod_menu_link";
206
$database->query("DROP TABLE IF EXISTS `$table`");
207
$database->query("
208
	CREATE TABLE `$table` (
209
		`section_id` INT(11) NOT NULL DEFAULT '0',
210
		`page_id` INT(11) NOT NULL DEFAULT '0',
211
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
212
		`anchor` VARCHAR(255) NOT NULL DEFAULT '' ,
213
		PRIMARY KEY (`section_id`)
214
	)
215
");
216
// fetch all menu_link-pages in $pages
217
$pages = array();
218
$table_p = TABLE_PREFIX.'pages';
219
$table_s = TABLE_PREFIX.'sections';
220
$query_page = $database->query("SELECT p.* FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module = 'menu_link'");
221
if($query_page->numRows() > 0) {
222
	while($page = $query_page->fetchRow()) {
223
		$pages[$page['page_id']]['page_details'] = $page;
224
	}
225
}
226
// get all related files with content from pages/ in $pages, too
227
function list_files_dirs($dir, $depth=true, $files=array(), $dirs=array()) {
228
	$dh=opendir($dir);
229
	while(($file = readdir($dh)) !== false) {
230
		if($file == '.' || $file == '..') {
231
			continue;
232
		}
233
		if(is_dir($dir.'/'.$file)) {
234
			if($depth) {
235
				$dirs[] = $dir.'/'.$file;
236
				list($files, $dirs) = list_files_dirs($dir.'/'.$file, $depth, $files, $dirs);
237
			}
238
		} else {
239
			$files[] = $dir.'/'.$file;
240
		}
241
	}
242
	closedir($dh);
243
	natcasesort($files);
244
	natcasesort($dirs);
245
	return(array($files, $dirs));
246
}
247
list($files, $dirs) = list_files_dirs(WB_PATH.PAGES_DIRECTORY);
248
foreach($files as $file) {
249
	if(($content = implode('', file($file))) !== FALSE) {
250
		if(preg_match('/\$page_id = (\d+)/', $content, $matches)) {
251
			if(array_key_exists($matches[1], $pages)) {
252
				$pages[$matches[1]]['file_content'] = $content;
253
				$pages[$matches[1]]['filename'] = $file;
254
			}
255
		}
256
	}
257
}
258
// try to convert old menu_links to new ones
259
foreach($pages as $p) {
260
	$page = $p['page_details'];
261
	$file_content = $p['file_content'];
262
	$filename = $p['filename'];
263
	$link = $p['page_details']['link'];
264
//var_dump($page);var_dump($file_content);var_dump($filename);var_dump($link);
265

    
266
// This part is still missing
267

    
268

    
269
}
270

    
271

    
272
//******************************************************************************
273
//Start of upgrade script for the form modul
274
//******************************************************************************
275

    
276
echo "<BR><B>Adding new field to database table mod_form_settings</B><BR>";
277

    
278
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_subject` VARCHAR(255) NOT NULL AFTER `success_message`")) {
279
	echo 'Database Field success_email_subject added successfully<br />';
280
}
281
echo mysql_error().'<br />';
282

    
283
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_text` TEXT NOT NULL AFTER `success_message`")) {
284
	echo 'Database Field success_email_text added successfully<br />';
285
}
286
echo mysql_error().'<br />';
287

    
288
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_from` VARCHAR(255) NOT NULL AFTER `success_message`")) {
289
	echo 'Database Field success_email_from added successfully<br />';
290
}
291
echo mysql_error().'<br />';
292

    
293
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_to` TEXT NOT NULL AFTER `success_message`")) {
294
	echo 'Database Field success_email_to added successfully<br />';
295
}
296
echo mysql_error().'<br />';
297

    
298
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_page` TEXT NOT NULL AFTER `success_message`")) {
299
	echo 'Database Field success_page added successfully<br />';
300
}
301
echo mysql_error().'<br />';
302

    
303
echo "<BR><B>Deleting field success_message from table mod_form_settings</B><BR>";
304

    
305
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
306
	echo 'Database field success_message droped successfully<br>';
307
}
308
echo mysql_error().'<br />';
309

    
310

    
311
// UPDATING DATA INTO FIELDS
312
echo "<BR>";
313

    
314
// These are the default setting
315
$success_page = 'none';
316
$success_email_to = '';
317
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
318
$success_email_text = addslashes($success_email_text);
319
$success_email_subject = 'You have submitted a form';
320

    
321
// Insert default settings into database
322
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
323
while($result = $query_dates->fetchRow()) {
324
	
325
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
326
	$section_id = $result['section_id'];
327

    
328
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
329
		echo 'Database data success_page added successfully<br>';
330
	}
331
	echo mysql_error().'<br />';
332
	
333
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
334
		echo 'Database data success_email_to added successfully<br>';
335
	}
336
	echo mysql_error().'<br />';
337
	
338
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
339
		echo 'Database data success_email_text added successfully<br>';
340
	}
341
	echo mysql_error().'<br />';
342
	
343
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
344
		echo 'Database data success_email_subject added successfully<br>';
345
	}
346
	echo mysql_error().'<br />';
347
	
348
}
349

    
350
// copy field email_to to success_email_from
351
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
352
while($result = $query_dates->fetchRow()) {
353
	
354
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
355
	$section_id = $result['section_id'];
356

    
357
	$success_email_from = $result['email_to'];
358
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
359
		echo 'Copyied field email_to to success_email_from successfully<br>';
360
	}
361
	echo mysql_error().'<br />';
362
}
363

    
364
//******************************************************************************
365
//End of upgrade script for the form modul
366
//******************************************************************************
367

    
368
//******************************************************************************
369
//Start of upgrade script for the news modul
370
//******************************************************************************
371

    
372
echo "<BR><B>Adding new field to database table mod_news_posts</B><BR>";
373
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_news_posts` ADD `published_when` INT NOT NULL AFTER `commenting`")) {
374
	echo 'Database Field published_when added successfully<br />';
375
}
376
echo mysql_error().'<br />';
377

    
378
// UPDATING DATA INTO FIELDS
379
echo "<BR>";
380

    
381
// These are the default setting
382
$header = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"98%\">';
383
$post_loop = '<tr class=\"post_top\">
384
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
385
<td class=\"post_date\">[MODI_TIME], [MODI_DATE]</td>
386
</tr>
387
<tr>
388
<td class=\"post_short\" colspan=\"2\">
389
[SHORT] 
390
<a href=\"[LINK]\">[TEXT_READ_MORE]</a>
391
</td>
392
</tr>';
393
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="100%">
394
<tr>
395
<td height="30"><h1>[TITLE]</h1></td>
396
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
397
</tr>
398
<tr>
399
<td valign="top"><b>Posted by [DISPLAY_NAME] ([USERNAME]) on [PUBL_DATE]</b></td>
400
</tr>
401
<tr style="display: [DISPLAY_GROUP]">
402
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
403
</tr>
404
</table>
405
<p style="text-align: justify;">');
406
$post_footer = '</p><p>Last changed: [MODI_DATE] at [MODI_TIME]</p>
407
<a href=\"[BACK]\">Back</a>';
408
$comments_header = addslashes('<br /><br />
409
<h2>Comments</h2>
410
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
411

    
412
// Insert default settings into database
413
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
414
while($result = $query_dates->fetchRow()) {
415
	
416
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><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<br>';
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<br>';
426
	}
427
	echo mysql_error().'<br />';
428
	
429
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
430
		echo 'Database data post_header added successfully<br>';
431
	}
432
	echo mysql_error().'<br />';
433
	
434
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
435
		echo 'Database data post_footer added successfully<br>';
436
	}
437
	echo mysql_error().'<br />';
438
	
439
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
440
		echo 'Database data comments_header added successfully<br>';
441
	}
442
	echo mysql_error().'<br />';
443

    
444
}
445

    
446
// MIGRATING FIELD DATES to POSTED_WHEN
447
echo "<B>Copying field posted_when value to published_when</B><BR>";
448
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
449

    
450
while($result = $query_dates->fetchRow()) {
451
	$pid = $result['post_id'];
452
	$NEW_DATE = $result['posted_when'];
453
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
454
		echo 'Copying posted_when value to published_when successfully<br>';
455
	}
456
	echo mysql_error().'<br />';
457
}
458

    
459
//******************************************************************************
460
//End of upgrade script for the news modul
461
//******************************************************************************
462

    
463
echo "<br /><br />Done<br />";
464

    
465
?>
466

    
467
</body>
468
</html>
(4-4/4)