Project

General

Profile

1 552 thorn
<?php
2
3 554 Ruebenwurz
// $Id$
4 552 thorn
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 578 thorn
		$database->query("INSERT INTO ".TABLE_PREFIX."search (name,value,extra) VALUES ('$key', '$value', '')");
70 579 thorn
		echo mysql_error()?mysql_error().'<br />':'';
71 552 thorn
		$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 579 thorn
		echo mysql_error()?mysql_error().'<br />':'';
111 552 thorn
		$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 579 thorn
		echo mysql_error()?mysql_error().'<br />':'';
138 552 thorn
		$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 579 thorn
	echo mysql_error()?mysql_error().'<br />':'';
179 552 thorn
	$query = $database->query("DESCRIBE $table 'publ_start'");
180 579 thorn
	echo mysql_error()?mysql_error().'<br />':'';
181 552 thorn
	if($query->numRows() > 0) {
182
		echo "'publ_start' added. $OK.<br />";
183
	} else {
184
		echo "adding 'publ_start' $FAIL!<br />";
185
	}
186
} else {
187
	echo "'publ_start' allready there. $OK.<br />";
188
}
189
$query = $database->query("DESCRIBE $table 'publ_end'");
190
if($query->numRows() == 0) { // add field
191
	$query = $database->query("ALTER TABLE $table ADD publ_end INT NOT NULL DEFAULT '0'");
192 579 thorn
	echo mysql_error()?mysql_error().'<br />':'';
193 552 thorn
	$query = $database->query("DESCRIBE $table 'publ_end'");
194
	if($query->numRows() > 0) {
195
		echo "'publ_end' added. $OK.<br />";
196
	} else {
197
		echo "adding 'publ_end' $FAIL!<br />";
198
	}
199
} else {
200
	echo "'publ_end' allready there. $OK<br />";
201
}
202
203
204 566 thorn
/**********************************************************
205
 *  - core-module menu_link
206
 */
207
// create table
208
$table = TABLE_PREFIX ."mod_menu_link";
209
$database->query("DROP TABLE IF EXISTS `$table`");
210
$database->query("
211
	CREATE TABLE `$table` (
212
		`section_id` INT(11) NOT NULL DEFAULT '0',
213
		`page_id` INT(11) NOT NULL DEFAULT '0',
214
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
215 575 thorn
		`anchor` VARCHAR(255) NOT NULL DEFAULT '0' ,
216 566 thorn
		PRIMARY KEY (`section_id`)
217
	)
218
");
219
// fetch all menu_link-pages in $pages
220
$pages = array();
221
$table_p = TABLE_PREFIX.'pages';
222
$table_s = TABLE_PREFIX.'sections';
223
$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'");
224
if($query_page->numRows() > 0) {
225
	while($page = $query_page->fetchRow()) {
226
		$pages[$page['page_id']]['page_details'] = $page;
227
	}
228
}
229
// get all related files with content from pages/ in $pages, too
230
function list_files_dirs($dir, $depth=true, $files=array(), $dirs=array()) {
231
	$dh=opendir($dir);
232
	while(($file = readdir($dh)) !== false) {
233
		if($file == '.' || $file == '..') {
234
			continue;
235
		}
236
		if(is_dir($dir.'/'.$file)) {
237
			if($depth) {
238
				$dirs[] = $dir.'/'.$file;
239
				list($files, $dirs) = list_files_dirs($dir.'/'.$file, $depth, $files, $dirs);
240
			}
241
		} else {
242
			$files[] = $dir.'/'.$file;
243
		}
244
	}
245
	closedir($dh);
246
	natcasesort($files);
247
	natcasesort($dirs);
248
	return(array($files, $dirs));
249
}
250
list($files, $dirs) = list_files_dirs(WB_PATH.PAGES_DIRECTORY);
251
foreach($files as $file) {
252
	if(($content = implode('', file($file))) !== FALSE) {
253
		if(preg_match('/\$page_id = (\d+)/', $content, $matches)) {
254
			if(array_key_exists($matches[1], $pages)) {
255
				$pages[$matches[1]]['file_content'] = $content;
256
				$pages[$matches[1]]['filename'] = $file;
257
			}
258
		}
259
	}
260
}
261
// try to convert old menu_links to new ones
262 579 thorn
$table_p = TABLE_PREFIX.'pages';
263
$table_s = TABLE_PREFIX.'sections';
264
$table_mm = TABLE_PREFIX ."mod_menu_link";
265 566 thorn
foreach($pages as $p) {
266
	$page = $p['page_details'];
267
	$file_content = $p['file_content'];
268
	$filename = $p['filename'];
269
	$link = $p['page_details']['link'];
270 579 thorn
	$page_trail = $p['page_details']['page_trail'];
271
	$page_id = $p['page_details']['page_id'];
272
	//var_dump($page);var_dump($file_content);var_dump($filename);var_dump($link);var_dump($page_trail);
273 562 Ruebenwurz
274 579 thorn
	// - aus wb_pages.page_trail aktuelle Position bestimmen
275
	// - daraus link bestimmen und in wb_pages eintragen
276
	// - Datei in pages wenn nötig verschieben
277
	//ok - Ãœber $link die page_id der Zielseite feststellen (--> $target_page_id), und nach mod_menu_link speichern, anchor leer.
278
	if($query_pid = $database->query("SELECT p.page_id, s.section_id FROM $table_p AS p, $table_s AS s WHERE p.page_id = s.page_id AND p.link = '$link' AND p.page_id != '$page_id'")) {
279
		$res = $query_pid->fetchRow();
280
		$target_page_id = $res['page_id'];
281
		$section_id = $res['section_id'];
282
		$database->query("INSERT INTO $table_mm (page_id, section_id, target_page_id, anchor) VALUES ('$page_id', '$section_id', '$target_page_id', '0')");
283
		echo mysql_error()?mysql_error().'<br />':'';
284
	}
285
//var_dump("-------------------");
286
	// This part is still missing
287 566 thorn
288
289
}
290
291
292 560 Ruebenwurz
//******************************************************************************
293 562 Ruebenwurz
//Start of upgrade script for the form modul
294 560 Ruebenwurz
//******************************************************************************
295 552 thorn
296 560 Ruebenwurz
echo "<BR><B>Adding new field to database table mod_form_settings</B><BR>";
297
298
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_subject` VARCHAR(255) NOT NULL AFTER `success_message`")) {
299
	echo 'Database Field success_email_subject added successfully<br />';
300
}
301
echo mysql_error().'<br />';
302
303
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_text` TEXT NOT NULL AFTER `success_message`")) {
304
	echo 'Database Field success_email_text added successfully<br />';
305
}
306
echo mysql_error().'<br />';
307
308
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_from` VARCHAR(255) NOT NULL AFTER `success_message`")) {
309
	echo 'Database Field success_email_from added successfully<br />';
310
}
311
echo mysql_error().'<br />';
312
313
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_email_to` TEXT NOT NULL AFTER `success_message`")) {
314
	echo 'Database Field success_email_to added successfully<br />';
315
}
316
echo mysql_error().'<br />';
317
318
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` ADD `success_page` TEXT NOT NULL AFTER `success_message`")) {
319
	echo 'Database Field success_page added successfully<br />';
320
}
321
echo mysql_error().'<br />';
322
323
echo "<BR><B>Deleting field success_message from table mod_form_settings</B><BR>";
324
325
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_form_settings` DROP `success_message`")) {
326
	echo 'Database field success_message droped successfully<br>';
327
}
328
echo mysql_error().'<br />';
329
330
331
// UPDATING DATA INTO FIELDS
332
echo "<BR>";
333
334
// These are the default setting
335
$success_page = 'none';
336
$success_email_to = '';
337
$success_email_text = 'Thank you for submitting your form on '.WEBSITE_TITLE;
338
$success_email_text = addslashes($success_email_text);
339
$success_email_subject = 'You have submitted a form';
340
341
// Insert default settings into database
342
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
343
while($result = $query_dates->fetchRow()) {
344
345
	echo "<B>Add default settings data to database for form section_id= ".$result['section_id']."</b><BR>";
346
	$section_id = $result['section_id'];
347
348
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_page` = '$success_page' WHERE `section_id` = $section_id")) {
349
		echo 'Database data success_page added successfully<br>';
350
	}
351
	echo mysql_error().'<br />';
352
353
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_to` = '$success_email_to' WHERE `section_id` = $section_id")) {
354
		echo 'Database data success_email_to added successfully<br>';
355
	}
356
	echo mysql_error().'<br />';
357
358
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_text` = '$success_email_text' WHERE `section_id` = $section_id")) {
359
		echo 'Database data success_email_text added successfully<br>';
360
	}
361
	echo mysql_error().'<br />';
362
363
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_subject` = '$success_email_subject' WHERE `section_id` = $section_id")) {
364
		echo 'Database data success_email_subject added successfully<br>';
365
	}
366
	echo mysql_error().'<br />';
367
368
}
369
370
// copy field email_to to success_email_from
371
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_form_settings where section_id != 0 and page_id != 0");
372
while($result = $query_dates->fetchRow()) {
373
374
	echo "<B>Copying field email_to to success_email_from for form section_id= ".$result['section_id']."</B><BR>";
375
	$section_id = $result['section_id'];
376
377
	$success_email_from = $result['email_to'];
378
	if($database->query("UPDATE `".TABLE_PREFIX."mod_form_settings` SET `success_email_from` = '$success_email_from' WHERE `section_id` = $section_id")) {
379
		echo 'Copyied field email_to to success_email_from successfully<br>';
380
	}
381
	echo mysql_error().'<br />';
382
}
383
384
//******************************************************************************
385
//End of upgrade script for the form modul
386
//******************************************************************************
387
388 562 Ruebenwurz
//******************************************************************************
389
//Start of upgrade script for the news modul
390
//******************************************************************************
391
392
echo "<BR><B>Adding new field to database table mod_news_posts</B><BR>";
393
if($database->query("ALTER TABLE `".TABLE_PREFIX."mod_news_posts` ADD `published_when` INT NOT NULL AFTER `commenting`")) {
394
	echo 'Database Field published_when added successfully<br />';
395
}
396
echo mysql_error().'<br />';
397
398
// UPDATING DATA INTO FIELDS
399
echo "<BR>";
400
401
// These are the default setting
402
$header = '<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"98%\">';
403
$post_loop = '<tr class=\"post_top\">
404
<td class=\"post_title\"><a href=\"[LINK]\">[TITLE]</a></td>
405
<td class=\"post_date\">[MODI_TIME], [MODI_DATE]</td>
406
</tr>
407
<tr>
408
<td class=\"post_short\" colspan=\"2\">
409
[SHORT]
410
<a href=\"[LINK]\">[TEXT_READ_MORE]</a>
411
</td>
412
</tr>';
413
$post_header = addslashes('<table cellpadding="0" cellspacing="0" border="0" width="100%">
414
<tr>
415
<td height="30"><h1>[TITLE]</h1></td>
416
<td rowspan="3" style="display: [DISPLAY_IMAGE]"><img src="[GROUP_IMAGE]" alt="[GROUP_TITLE]" /></td>
417
</tr>
418
<tr>
419
<td valign="top"><b>Posted by [DISPLAY_NAME] ([USERNAME]) on [PUBL_DATE]</b></td>
420
</tr>
421
<tr style="display: [DISPLAY_GROUP]">
422
<td valign="top"><a href="[BACK]">[PAGE_TITLE]</a> >> <a href="[BACK]?g=[GROUP_ID]">[GROUP_TITLE]</a></td>
423
</tr>
424
</table>
425
<p style="text-align: justify;">');
426
$post_footer = '</p><p>Last changed: [MODI_DATE] at [MODI_TIME]</p>
427
<a href=\"[BACK]\">Back</a>';
428
$comments_header = addslashes('<br /><br />
429
<h2>Comments</h2>
430
<table cellpadding="2" cellspacing="0" border="0" width="98%">');
431
432
// Insert default settings into database
433
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings where section_id != 0 and page_id != 0");
434
while($result = $query_dates->fetchRow()) {
435
436
	echo "<B>Add default settings data to database for news section_id= ".$result['section_id']."</b><BR>";
437
	$section_id = $result['section_id'];
438
439
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `header` = '$header' WHERE `section_id` = $section_id")) {
440
		echo 'Database data header added successfully<br>';
441
	}
442
	echo mysql_error().'<br />';
443
444
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_loop` = '$post_loop' WHERE `section_id` = $section_id")) {
445
		echo 'Database data post_loop added successfully<br>';
446
	}
447
	echo mysql_error().'<br />';
448
449
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_header` = '$post_header' WHERE `section_id` = $section_id")) {
450
		echo 'Database data post_header added successfully<br>';
451
	}
452
	echo mysql_error().'<br />';
453
454
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `post_footer` = '$post_footer' WHERE `section_id` = $section_id")) {
455
		echo 'Database data post_footer added successfully<br>';
456
	}
457
	echo mysql_error().'<br />';
458
459
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_settings` SET `comments_header` = '$comments_header' WHERE `section_id` = $section_id")) {
460
		echo 'Database data comments_header added successfully<br>';
461
	}
462
	echo mysql_error().'<br />';
463
464
}
465
466
// MIGRATING FIELD DATES to POSTED_WHEN
467
echo "<B>Copying field posted_when value to published_when</B><BR>";
468
$query_dates = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts where section_id != 0 and page_id != 0");
469
470
while($result = $query_dates->fetchRow()) {
471
	$pid = $result['post_id'];
472
	$NEW_DATE = $result['posted_when'];
473
	if($database->query("UPDATE `".TABLE_PREFIX."mod_news_posts` SET `published_when` = '$NEW_DATE' WHERE `post_id` = $pid")) {
474
		echo 'Copying posted_when value to published_when successfully<br>';
475
	}
476
	echo mysql_error().'<br />';
477
}
478
479
//******************************************************************************
480
//End of upgrade script for the news modul
481
//******************************************************************************
482
483 552 thorn
echo "<br /><br />Done<br />";
484
485
?>
486
487
</body>
488 575 thorn
</html>