| 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 |  |  | 		$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 |  |  | 
 | 
      
        | 203 |  |  | echo "<br /><br />Done<br />";
 | 
      
        | 204 |  |  | 
 | 
      
        | 205 |  |  | ?>
 | 
      
        | 206 |  |  | 
 | 
      
        | 207 |  |  | </body>
 | 
      
        | 208 |  |  | </html>
 |