Index: trunk/wb/include/htmlarea/popups/link.php
===================================================================
--- trunk/wb/include/htmlarea/popups/link.php	(revision 4)
+++ trunk/wb/include/htmlarea/popups/link.php	(revision 5)
@@ -73,7 +73,7 @@
 // Function to generate page list
 function gen_page_list($parent) {
 	global $template, $database;
-	$get_pages = $database->query("SELECT page_id,menu_title,link,level FROM ".TABLE_PREFIX."pages WHERE parent = '$parent'");
+	$get_pages = $database->query("SELECT page_id,menu_title,link,level FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' AND visibility!='deleted'");
 	while($page = $get_pages->fetchRow()) {
 		$title = stripslashes($page['menu_title']);
 		// Add leading -'s so we can tell what level a page is at
@@ -91,7 +91,7 @@
 // Get pages and put them into the pages list
 $template->set_block('main_block', 'page_list_block', 'page_list');
 $database = new database();
-$get_pages = $database->query("SELECT page_id,menu_title,link FROM ".TABLE_PREFIX."pages WHERE parent = '0'");
+$get_pages = $database->query("SELECT page_id,menu_title,link FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND visibility!='deleted'");
 if($get_pages > 0) {
 	// Add 'Please select...'
 	$template->set_var('TITLE', 'Please select...');
@@ -115,4 +115,4 @@
 $template->parse('main', 'main_block', false);
 $template->pparse('output', 'page');
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/install/save.php
===================================================================
--- trunk/wb/install/save.php	(revision 4)
+++ trunk/wb/install/save.php	(revision 5)
@@ -1,6 +1,6 @@
 <?php
 
-// $Id: save.php,v 1.15 2005/04/25 11:53:12 rdjurovich Exp $+// $Id: save.php,v 1.15 2005/04/25 11:53:12 rdjurovich Exp $
 
 /*
 
@@ -21,64 +21,64 @@
  along with Website Baker; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-*/
-
-// Start a session
-if(!defined('SESSION_STARTED')) {
-	session_name('wb_session_id');
-	session_start();
-	define('SESSION_STARTED', true);
-}
+*/
 
-// Function to set error
-function set_error($message) {
-	global $_POST;
-	if(isset($message) AND $message != '') {
-		// Copy values entered into session so user doesn't have to re-enter everything
-		if(isset($_POST['website_title'])) {
-			$_SESSION['wb_url'] = $_POST['wb_url'];
-			$_SESSION['wb_path'] = $_POST['wb_path'];
-			$_SESSION['default_timezone'] = $_POST['default_timezone'];
-			if(!isset($_POST['operating_system'])) {
-				$_SESSION['operating_system'] = 'linux';
-			} else {
-				$_SESSION['operating_system'] = $_POST['operating_system'];
-			}
-			if(!isset($_POST['world_writeable'])) {
-				$_SESSION['world_writeable'] = false;
-			} else {
-				$_SESSION['world_writeable'] = true;
-			}
-			$_SESSION['database_host'] = $_POST['database_host'];
-			$_SESSION['database_username'] = $_POST['database_username'];
-			$_SESSION['database_password'] = $_POST['database_password'];
-			$_SESSION['database_name'] = $_POST['database_name'];
-			$_SESSION['table_prefix'] = $_POST['table_prefix'];
-			if(!isset($_POST['install_tables'])) {
-				$_SESSION['install_tables'] = false;
-			} else {
-				$_SESSION['install_tables'] = true;
-			}
-			$_SESSION['website_title'] = $_POST['website_title'];
-			$_SESSION['admin_username'] = $_POST['admin_username'];
-			$_SESSION['admin_email'] = $_POST['admin_email'];
-			$_SESSION['admin_password'] = $_POST['admin_password'];
-		}
-		// Set the message
-		$_SESSION['message'] = $message;
-		// Specify that session support is enabled
-		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
-		// Redirect to first page again and exit
-		header('Location: index.php?sessions_checked=true');
-		exit();
-	}
-}
+// Start a session
+if(!defined('SESSION_STARTED')) {
+	session_name('wb_session_id');
+	session_start();
+	define('SESSION_STARTED', true);
+}
 
-// Function to workout what the default permissions are for files created by the webserver
-function default_file_mode($temp_dir) {
+// Function to set error
+function set_error($message) {
+	global $_POST;
+	if(isset($message) AND $message != '') {
+		// Copy values entered into session so user doesn't have to re-enter everything
+		if(isset($_POST['website_title'])) {
+			$_SESSION['wb_url'] = $_POST['wb_url'];
+			$_SESSION['wb_path'] = $_POST['wb_path'];
+			$_SESSION['default_timezone'] = $_POST['default_timezone'];
+			if(!isset($_POST['operating_system'])) {
+				$_SESSION['operating_system'] = 'linux';
+			} else {
+				$_SESSION['operating_system'] = $_POST['operating_system'];
+			}
+			if(!isset($_POST['world_writeable'])) {
+				$_SESSION['world_writeable'] = false;
+			} else {
+				$_SESSION['world_writeable'] = true;
+			}
+			$_SESSION['database_host'] = $_POST['database_host'];
+			$_SESSION['database_username'] = $_POST['database_username'];
+			$_SESSION['database_password'] = $_POST['database_password'];
+			$_SESSION['database_name'] = $_POST['database_name'];
+			$_SESSION['table_prefix'] = $_POST['table_prefix'];
+			if(!isset($_POST['install_tables'])) {
+				$_SESSION['install_tables'] = false;
+			} else {
+				$_SESSION['install_tables'] = true;
+			}
+			$_SESSION['website_title'] = $_POST['website_title'];
+			$_SESSION['admin_username'] = $_POST['admin_username'];
+			$_SESSION['admin_email'] = $_POST['admin_email'];
+			$_SESSION['admin_password'] = $_POST['admin_password'];
+		}
+		// Set the message
+		$_SESSION['message'] = $message;
+		// Specify that session support is enabled
+		$_SESSION['session_support'] = '<font class="good">Enabled</font>';
+		// Redirect to first page again and exit
+		header('Location: index.php?sessions_checked=true');
+		exit();
+	}
+}
+
+// Function to workout what the default permissions are for files created by the webserver
+function default_file_mode($temp_dir) {
 	$v = explode(".",PHP_VERSION);
 	$v = $v[0].$v[1];
-	if($v > 41 AND is_writable($temp_dir)) {
+	if($v > 41 AND is_writable($temp_dir)) {
 		$filename = $temp_dir.'/test_permissions.txt';
 		$handle = fopen($filename, 'w');
 		fwrite($handle, 'This file is to get the default file permissions');
@@ -91,7 +91,7 @@
 	return $default_file_mode;
 }
 
-// Function to workout what the default permissions are for directories created by the webserver
+// Function to workout what the default permissions are for directories created by the webserver
 function default_dir_mode($temp_dir) {
 	$v = explode(".",PHP_VERSION);
 	$v = $v[0].$v[1];
@@ -104,81 +104,81 @@
 		$default_dir_mode = '0777';
 	}
 	return $default_dir_mode;
-}
-
-// Begin check to see if form was even submitted
-	// Set error if no post vars found
-	if(!isset($_POST['website_title'])) {
-		set_error('Please fill-in the form below');
-	}
+}
+
+// Begin check to see if form was even submitted
+	// Set error if no post vars found
+	if(!isset($_POST['website_title'])) {
+		set_error('Please fill-in the form below');
+	}
 // End check to see if form was even submitted
-
+
 // Begin path and timezone details code
-	// Check if user has entered the installation path
-	if(!isset($_POST['wb_path']) OR $_POST['wb_path'] == '') {
-		set_error('Please enter an absolute path');
-	} else {
-		$wb_path = $_POST['wb_path'];
-	}
-	// Check if user has entered the installation url
-	if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
-		set_error('Please enter an absolute URL');
-	} else {
-		$wb_url = $_POST['wb_url'];
-	}
-	// Remove any slashes at the end of the URL and path
+	// Check if user has entered the installation path
+	if(!isset($_POST['wb_path']) OR $_POST['wb_path'] == '') {
+		set_error('Please enter an absolute path');
+	} else {
+		$wb_path = $_POST['wb_path'];
+	}
+	// Check if user has entered the installation url
+	if(!isset($_POST['wb_url']) OR $_POST['wb_url'] == '') {
+		set_error('Please enter an absolute URL');
+	} else {
+		$wb_url = $_POST['wb_url'];
+	}
+	// Remove any slashes at the end of the URL and path
 	if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
 		$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
 	}
 	if(substr($wb_path, strlen($wb_path)-1, 1) == "/") {
 		$wb_path = substr($wb_path, 0, strlen($wb_path)-1);
-	}
+	}
 	if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
 		$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
 	}
 	if(substr($wb_path, strlen($wb_path)-1, 1) == "\\") {
 		$wb_path = substr($wb_path, 0, strlen($wb_path)-1);
-	}
+	}
 	if(substr($wb_url, strlen($wb_url)-1, 1) == "/") {
 		$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
 	}
 	if(substr($wb_path, strlen($wb_path)-1, 1) == "/") {
 		$wb_path = substr($wb_path, 0, strlen($wb_path)-1);
-	}
+	}
 	if(substr($wb_url, strlen($wb_url)-1, 1) == "\\") {
 		$wb_url = substr($wb_url, 0, strlen($wb_url)-1);
 	}
 	if(substr($wb_path, strlen($wb_path)-1, 1) == "\\") {
 		$wb_path = substr($wb_path, 0, strlen($wb_path)-1);
-	}
-	// Get the default time zone
-	if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
-		set_error('Please select a valid default timezone');
-	} else {
-		$default_timezone = $_POST['default_timezone']*60*60;
-	}
-// End path and timezone details code
-
-// Begin operating system specific code
-	// Get operating system
-	if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
-		set_error('Please select a valid operating system');
-	} else {
-		$operating_system = $_POST['operating_system'];
-	}
-	// Work-out file permissions
-	if($operating_system == 'windows') {
-		$file_mode = '0777';
-		$dir_mode = '0777';
-	} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
-		$file_mode = '0777';
-		$dir_mode = '0777';
-	} else {
+	}
+	// Get the default time zone
+	if(!isset($_POST['default_timezone']) OR !is_numeric($_POST['default_timezone'])) {
+		set_error('Please select a valid default timezone');
+	} else {
+		$default_timezone = $_POST['default_timezone']*60*60;
+	}
+// End path and timezone details code
+
+// Begin operating system specific code
+	// Get operating system
+	if(!isset($_POST['operating_system']) OR $_POST['operating_system'] != 'linux' AND $_POST['operating_system'] != 'windows') {
+		set_error('Please select a valid operating system');
+	} else {
+		$operating_system = $_POST['operating_system'];
+	}
+	// Work-out file permissions
+	if($operating_system == 'windows') {
+		$file_mode = '0777';
+		$dir_mode = '0777';
+	} elseif(isset($_POST['world_writeable']) AND $_POST['world_writeable'] == 'true') {
+		$file_mode = '0777';
+		$dir_mode = '0777';
+	} else {
 		$file_mode = default_file_mode('../temp');
-		$dir_mode = default_dir_mode('../temp');
-	}
-// End operating system specific code
-
+		$dir_mode = default_dir_mode('../temp');
+	}
+// End operating system specific code
+
 // Begin database details code
 	// Check if user has entered a database host
 	if(!isset($_POST['database_host']) OR $_POST['database_host'] == '') {
@@ -205,57 +205,57 @@
 		$database_name = $_POST['database_name'];
 	}
 	// Get table prefix
-	$table_prefix = $_POST['table_prefix'];
-	// Find out if the user wants to install tables and data
-	if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
-		$install_tables = true;
-	} else {
-		$install_tables = false;
+	$table_prefix = $_POST['table_prefix'];
+	// Find out if the user wants to install tables and data
+	if(isset($_POST['install_tables']) AND $_POST['install_tables'] == 'true') {
+		$install_tables = true;
+	} else {
+		$install_tables = false;
 	}
 // End database details code
-
-// Begin website title code
-	// Get website title
-	if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
-		set_error('Please enter a website title');
-	} else {
-		$website_title = addslashes($_POST['website_title']);
-	}
-// End website title code
-
-// Begin admin user details code
-	// Get admin username
-	if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
-		set_error('Please enter a username for the Administrator account');
-	} else {
-		$admin_username = $_POST['admin_username'];
-	}
-	// Get admin email and validate it
-	if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
-		set_error('Please enter an email for the Administrator account');
-	} else {
-		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['admin_email'])) {
-			$admin_email = $_POST['admin_email'];
-		} else {
-			set_error('Please enter a valid email address for the Administrator account');
-		}
-	}
-	// Get the two admin passwords entered, and check that they match
-	if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
-		set_error('Please enter a password for the Administrator account');
-	} else {
-		$admin_password = $_POST['admin_password'];
-	}
-	if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
-		set_error('Please make sure you re-enter the password for the Administrator account');
-	} else {
-		$admin_repassword = $_POST['admin_repassword'];
-	}
-	if($admin_password != $admin_repassword) {
-		set_error('Sorry, the two Administrator account passwords you entered do not match');
-	}
-// End admin user details code
-
+
+// Begin website title code
+	// Get website title
+	if(!isset($_POST['website_title']) OR $_POST['website_title'] == '') {
+		set_error('Please enter a website title');
+	} else {
+		$website_title = addslashes($_POST['website_title']);
+	}
+// End website title code
+
+// Begin admin user details code
+	// Get admin username
+	if(!isset($_POST['admin_username']) OR $_POST['admin_username'] == '') {
+		set_error('Please enter a username for the Administrator account');
+	} else {
+		$admin_username = $_POST['admin_username'];
+	}
+	// Get admin email and validate it
+	if(!isset($_POST['admin_email']) OR $_POST['admin_email'] == '') {
+		set_error('Please enter an email for the Administrator account');
+	} else {
+		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['admin_email'])) {
+			$admin_email = $_POST['admin_email'];
+		} else {
+			set_error('Please enter a valid email address for the Administrator account');
+		}
+	}
+	// Get the two admin passwords entered, and check that they match
+	if(!isset($_POST['admin_password']) OR $_POST['admin_password'] == '') {
+		set_error('Please enter a password for the Administrator account');
+	} else {
+		$admin_password = $_POST['admin_password'];
+	}
+	if(!isset($_POST['admin_repassword']) OR $_POST['admin_repassword'] == '') {
+		set_error('Please make sure you re-enter the password for the Administrator account');
+	} else {
+		$admin_repassword = $_POST['admin_repassword'];
+	}
+	if($admin_password != $admin_repassword) {
+		set_error('Sorry, the two Administrator account passwords you entered do not match');
+	}
+// End admin user details code
+
 // Try and write settings to config file
 $config_content = "" .
 "<?php\n".
@@ -277,28 +277,28 @@
 "define('DEFAULT_TIMEZONE', '$default_timezone');\n".
 "define('DEFAULT_DATE_FORMAT', 'M d Y');\n".
 "define('DEFAULT_TIME_FORMAT', 'g:i A');\n".
-"\n".
-"define('HOME_FOLDERS', true);\n".
 "\n".
-"define('DEFAULT_TEMPLATE', 'round');\n".
-"define('MULTIPLE_MENUS', false);\n".
-"\n".
-"define('PAGE_LEVEL_LIMIT', '4');\n".
-"define('INTRO_PAGE', false);\n".
-"define('PAGE_TRASH', 'disabled');\n".
-"define('HOMEPAGE_REDIRECTION', false);\n".
+"define('HOME_FOLDERS', true);\n".
+"\n".
+"define('DEFAULT_TEMPLATE', 'round');\n".
+"define('MULTIPLE_MENUS', false);\n".
+"\n".
+"define('PAGE_LEVEL_LIMIT', '4');\n".
+"define('INTRO_PAGE', false);\n".
+"define('PAGE_TRASH', 'disabled');\n".
+"define('HOMEPAGE_REDIRECTION', false);\n".
 "define('PAGE_LANGUAGES', false);\n".
-"\n".
-"define('WYSIWYG_STYLE', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;');\n".
 "\n".
-"define('MANAGE_SECTIONS', true);\n".
-"define('SECTION_BLOCKS', false);\n".
+"define('WYSIWYG_STYLE', 'font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;');\n".
 "\n".
+"define('MANAGE_SECTIONS', true);\n".
+"define('SECTION_BLOCKS', false);\n".
+"\n".
 "define('SMART_LOGIN', false);\n".
 "define('FRONTEND_LOGIN', false);\n".
 "define('FRONTEND_SIGNUP', '');\n".
 "\n".
-"define('SERVER_EMAIL', '".$admin_email."');\n".
+"define('SERVER_EMAIL', '".$admin_email."');\n".
 "\n".
 "define('SEARCH', 'public');\n".
 "\n".
@@ -307,7 +307,7 @@
 "\n".
 "define('PAGES_DIRECTORY', '/pages');\n".
 "define('MEDIA_DIRECTORY', '/media');\n".
-"\n".
+"\n".
 "define('OPERATING_SYSTEM', '$operating_system');\n".
 "define('OCTAL_FILE_MODE', $file_mode);\n".
 "define('STRING_FILE_MODE', '$file_mode');\n".
@@ -337,34 +337,32 @@
 	}
 } else {
 	set_error("The configuration file $config_filename is not writable. Change its permissions so it is, then re-run step 4.");
-}
+}
 
 // Include configuration file
-require('../config.php');
-
-// Check if the user has entered a correct path
-if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
-	set_error('It appears the Absolute path that you entered is incorrect');
-}
-
-// Include WB functions file
-if(!defined('FUNCTIONS_FILE_LOADED')) {
-	require(WB_PATH.'/framework/functions.php');
-}
+require('../config.php');
 
+// Check if the user has entered a correct path
+if(!file_exists(WB_PATH.'/framework/class.admin.php')) {
+	set_error('It appears the Absolute path that you entered is incorrect');
+}
+
+// Include WB functions file
+require_once(WB_PATH.'/framework/functions.php');
+
 // Try connecting to database	
-if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
-	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
-}
-
+if(!mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) {
+	set_error('Database host name, username and/or password incorrect. MySQL Error:<br />'.mysql_error());
+}
+
 // Try to create the database
-mysql_query('CREATE DATABASE '.$database_name);
-
-// Close the mysql connection
-mysql_close();
-
-// Re-connect to the database, this time using in-build database class
-require(WB_PATH.'/framework/class.admin.php');
+mysql_query('CREATE DATABASE '.$database_name);
+
+// Close the mysql connection
+mysql_close();
+
+// Re-connect to the database, this time using in-build database class
+require(WB_PATH.'/framework/class.admin.php');
 $database = new database();
 
 // Check if we should install tables
@@ -403,12 +401,12 @@
 	       . ' `page_title` VARCHAR( 255 ) NOT NULL ,'
 	       . ' `menu_title` VARCHAR( 255 ) NOT NULL ,'
 	       . ' `description` TEXT NOT NULL ,'
-	       . ' `keywords` TEXT NOT NULL ,'
+	       . ' `keywords` TEXT NOT NULL ,'
 	       . ' `page_trail` TEXT NOT NULL ,'
 	       . ' `template` VARCHAR( 255 ) NOT NULL ,'
 	       . ' `visibility` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `position` INT NOT NULL ,'
-	       . ' `menu` INT NOT NULL ,'
+	       . ' `position` INT NOT NULL ,'
+	       . ' `menu` INT NOT NULL ,'
 	       . ' `language` VARCHAR( 5 ) NOT NULL ,'
 	       . ' `searching` INT NOT NULL ,'
 	       . ' `admin_groups` TEXT NOT NULL ,'
@@ -425,7 +423,7 @@
 	$pages = 'CREATE TABLE `'.TABLE_PREFIX.'sections` ( `section_id` INT NOT NULL auto_increment,'
 	       . ' `page_id` INT NOT NULL ,'
 	       . ' `position` INT NOT NULL ,'
-	       . ' `module` VARCHAR( 255 ) NOT NULL ,'
+	       . ' `module` VARCHAR( 255 ) NOT NULL ,'
 	       . ' `block` VARCHAR( 255 ) NOT NULL ,'
 	       . ' PRIMARY KEY ( `section_id` ) )'
 	       . ' ';
@@ -452,7 +450,7 @@
 	       . ' `timezone` INT NOT NULL ,'
 	       . ' `date_format` VARCHAR( 255 ) NOT NULL ,'
 	       . ' `time_format` VARCHAR( 255 ) NOT NULL ,'
-	       . ' `language` VARCHAR( 5 ) NOT NULL ,'
+	       . ' `language` VARCHAR( 5 ) NOT NULL ,'
 	       . ' `home_folder` TEXT NOT NULL ,'
 	       . ' `login_when` INT NOT NULL ,'
 	       . ' `login_ip` VARCHAR( 15 ) NOT NULL ,'
@@ -535,18 +533,18 @@
 	$search_footer = addslashes('');
 	$insert_search_footer = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'footer', '$search_footer', '')";
 	$database->query($insert_search_footer);
-	// Search results header
-	$search_results_header = addslashes(''.
-'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
+	// Search results header
+	$search_results_header = addslashes(''.
+'[TEXT_RESULTS_FOR] \'<b>[SEARCH_STRING]</b>\':
 <table cellpadding="2" cellspacing="0" border="0" width="100%" style="padding-top: 10px;">');
 	$insert_search_results_header = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_header', '$search_results_header', '')";
 	$database->query($insert_search_results_header);
 	// Search results loop
-	$search_results_loop = addslashes(''.
-'<tr style="background-color: #F0F0F0;">
-<td><a href="[LINK]">[TITLE]</a></td>
-<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
-</tr>
+	$search_results_loop = addslashes(''.
+'<tr style="background-color: #F0F0F0;">
+<td><a href="[LINK]">[TITLE]</a></td>
+<td align="right">[TEXT_LAST_UPDATED_BY] [DISPLAY_NAME] ([USERNAME]) [TEXT_ON] [DATE]</td>
+</tr>
 <tr><td colspan="2" style="text-align: justify; padding-bottom: 10px;">[DESCRIPTION]</td></tr>');
 	$insert_search_results_loop = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'results_loop', '$search_results_loop', '')";
 	$database->query($insert_search_results_loop);
@@ -559,7 +557,7 @@
 	$insert_search_no_results = "INSERT INTO `".TABLE_PREFIX."search` VALUES ('', 'no_results', '$search_no_results', '')";
 	$database->query($insert_search_no_results);
 	// Search template
-	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
+	$database->query("INSERT INTO `".TABLE_PREFIX."search` (name) VALUES ('template')");
 	
 	// Include the pre-installed module install scripts
 	require(WB_PATH.'/modules/wysiwyg/install.php');
@@ -568,35 +566,35 @@
 	require(WB_PATH.'/modules/form/install.php');
 	require(WB_PATH.'/modules/wrapper/install.php');
 	
-	// Check if there was a database error
+	// Check if there was a database error
 	if($database->is_error()) {
 		set_error($database->get_error());
-	}
+	}
 	
 }
 
-// Log the user in and go to Website Baker Administration
-require(WB_PATH.'/framework/class.login.php');
-$thisApp = new Login(
-							array(
-									"MAX_ATTEMPS" => "50",
-									"WARNING_URL" => ADMIN_URL."/login/warning.html",
-									"USERNAME_FIELDNAME" => 'admin_username',
-									"PASSWORD_FIELDNAME" => 'admin_password',
-									"REMEMBER_ME_OPTION" => SMART_LOGIN,
-									"MIN_USERNAME_LEN" => "2",
-									"MIN_PASSWORD_LEN" => "2",
-									"MAX_USERNAME_LEN" => "30",
-									"MAX_PASSWORD_LEN" => "30",
-									'LOGIN_URL' => ADMIN_URL."/login/index.php",
-									'DEFAULT_URL' => ADMIN_URL."/start/index.php",
-									'TEMPLATE_DIR' => ADMIN_PATH."/login",
-									'TEMPLATE_FILE' => "template.html",
-									'FRONTEND' => false,
-									'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
-									'USERS_TABLE' => TABLE_PREFIX."users",
-									'GROUPS_TABLE' => TABLE_PREFIX."groups",
-							)
-					);
+// Log the user in and go to Website Baker Administration
+require(WB_PATH.'/framework/class.login.php');
+$thisApp = new Login(
+							array(
+									"MAX_ATTEMPS" => "50",
+									"WARNING_URL" => ADMIN_URL."/login/warning.html",
+									"USERNAME_FIELDNAME" => 'admin_username',
+									"PASSWORD_FIELDNAME" => 'admin_password',
+									"REMEMBER_ME_OPTION" => SMART_LOGIN,
+									"MIN_USERNAME_LEN" => "2",
+									"MIN_PASSWORD_LEN" => "2",
+									"MAX_USERNAME_LEN" => "30",
+									"MAX_PASSWORD_LEN" => "30",
+									'LOGIN_URL' => ADMIN_URL."/login/index.php",
+									'DEFAULT_URL' => ADMIN_URL."/start/index.php",
+									'TEMPLATE_DIR' => ADMIN_PATH."/login",
+									'TEMPLATE_FILE' => "template.html",
+									'FRONTEND' => false,
+									'FORGOTTEN_DETAILS_APP' => ADMIN_URL."/login/forgot/index.php",
+									'USERS_TABLE' => TABLE_PREFIX."users",
+									'GROUPS_TABLE' => TABLE_PREFIX."groups",
+							)
+					);
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/admin/pages/settings.php
===================================================================
--- trunk/wb/admin/pages/settings.php	(revision 4)
+++ trunk/wb/admin/pages/settings.php	(revision 5)
@@ -100,15 +100,15 @@
 	$template->set_var('TEXT_MANAGE_SECTIONS', $HEADING['MANAGE_SECTIONS']);
 } else {
 	$template->set_var('DISPLAY_MANAGE_SECTIONS', 'none');
-}
+}
 
 // Visibility
 if($results_array['visibility'] == 'public') {
 	$template->set_var('PUBLIC_SELECTED', ' selected');
 } elseif($results_array['visibility'] == 'private') {
-	$template->set_var('PRIVATE_SELECTED', ' selected');
+	$template->set_var('PRIVATE_SELECTED', ' selected');
 } elseif($results_array['visibility'] == 'registered') {
-	$template->set_var('REGISTERED_SELECTED', ' registered');
+	$template->set_var('REGISTERED_SELECTED', ' selected');
 } elseif($results_array['visibility'] == 'hidden') {
 	$template->set_var('HIDDEN_SELECTED', ' selected');
 } elseif($results_array['visibility'] == 'none') {
@@ -309,60 +309,60 @@
 				$template->parse('template_list', 'template_list_block', true);
 			}
 		}
-	}
-	// Unset all menu arrays
+	}
+	// Unset all menu arrays
 	unset($menu);
-}
-
-// Menu list
-if(MULTIPLE_MENUS == false) {
-	$template->set_var('DISPLAY_MENU_LIST', 'none');
-}
-// Include template info file (if it exists)
-if($results_array['template'] != '') {
-	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
-} else {
-	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
-}
-if(file_exists($template_location)) {
-	require($template_location);
-}
-// Check if $menu is set
-if(!isset($menu[1]) OR $menu[1] == '') {
-	// Make our own menu list
-	$menu[1] = $TEXT['MAIN'];
-}
-// Add menu options to the list
-$template->set_block('main_block', 'menu_list_block', 'menu_list');
-foreach($menu AS $number => $name) {
-	$template->set_var('NAME', $name);
-	$template->set_var('VALUE', $number);
-	if($results_array['menu'] == $number) {
-		$template->set_var('SELECTED', 'selected');
-	} else {
-		$template->set_var('SELECTED', '');
-	}
-	$template->parse('menu_list', 'menu_list_block', true);
-}
-
-// Language list
-if($handle = opendir(WB_PATH.'/languages/')) {
+}
+
+// Menu list
+if(MULTIPLE_MENUS == false) {
+	$template->set_var('DISPLAY_MENU_LIST', 'none');
+}
+// Include template info file (if it exists)
+if($results_array['template'] != '') {
+	$template_location = WB_PATH.'/templates/'.$results_array['template'].'/info.php';
+} else {
+	$template_location = WB_PATH.'/templates/'.DEFAULT_TEMPLATE.'/info.php';
+}
+if(file_exists($template_location)) {
+	require($template_location);
+}
+// Check if $menu is set
+if(!isset($menu[1]) OR $menu[1] == '') {
+	// Make our own menu list
+	$menu[1] = $TEXT['MAIN'];
+}
+// Add menu options to the list
+$template->set_block('main_block', 'menu_list_block', 'menu_list');
+foreach($menu AS $number => $name) {
+	$template->set_var('NAME', $name);
+	$template->set_var('VALUE', $number);
+	if($results_array['menu'] == $number) {
+		$template->set_var('SELECTED', 'selected');
+	} else {
+		$template->set_var('SELECTED', '');
+	}
+	$template->parse('menu_list', 'menu_list_block', true);
+}
+
+// Language list
+if($handle = opendir(WB_PATH.'/languages/')) {
 	$template->set_block('main_block', 'language_list_block', 'language_list');
 	while (false !== ($file = readdir($handle))) {
-		if($file != '.' AND $file != '..' AND $file != 'CVS' AND $file != 'index.php') {
-			// Include the languages info file
-			require(WB_PATH.'/languages/'.$file);
-			// Work-out if this language is selected
-			if($language_code == $results_array['language']) { $selected = ' selected'; } else { $selected = ''; }
-			// Set the language info
-			$template->set_var(array('VALUE' => $language_code, 'SELECTED' => $selected, 'NAME' => $language_name));
-			// Parse row
-			$template->parse('language_list', 'language_list_block', true);
-		}
-	}
-}
-// Restore to original language
-require(WB_PATH.'/languages/'.LANGUAGE.'.php');
+		if($file != '.' AND $file != '..' AND $file != 'CVS' AND $file != 'index.php') {
+			// Include the languages info file
+			require(WB_PATH.'/languages/'.$file);
+			// Work-out if this language is selected
+			if($language_code == $results_array['language']) { $selected = ' selected'; } else { $selected = ''; }
+			// Set the language info
+			$template->set_var(array('VALUE' => $language_code, 'SELECTED' => $selected, 'NAME' => $language_name));
+			// Parse row
+			$template->parse('language_list', 'language_list_block', true);
+		}
+	}
+}
+// Restore to original language
+require(WB_PATH.'/languages/'.LANGUAGE.'.php');
 
 // Select disabled if searching is disabled
 if($results_array['searching'] == 0) {
@@ -384,14 +384,14 @@
 								'LAST_MODIFIED' => $MESSAGE['PAGES']['LAST_MODIFIED'],
 								'TEXT_PAGE_TITLE' => $TEXT['PAGE_TITLE'],
 								'TEXT_MENU_TITLE' => $TEXT['MENU_TITLE'],
-								'TEXT_TYPE' => $TEXT['TYPE'],
+								'TEXT_TYPE' => $TEXT['TYPE'],
 								'TEXT_MENU' => $TEXT['MENU'],
 								'TEXT_PARENT' => $TEXT['PARENT'],
 								'TEXT_VISIBILITY' => $TEXT['VISIBILITY'],
 								'TEXT_PUBLIC' => $TEXT['PUBLIC'],
-								'TEXT_PRIVATE' => $TEXT['PRIVATE'],
+								'TEXT_PRIVATE' => $TEXT['PRIVATE'],
 								'TEXT_REGISTERED' => $TEXT['REGISTERED'],
-								'TEXT_NONE' => $TEXT['NONE'],
+								'TEXT_NONE' => $TEXT['NONE'],
 								'TEXT_HIDDEN' => $TEXT['HIDDEN'],
 								'TEXT_TEMPLATE' => $TEXT['TEMPLATE'],
 								'TEXT_TARGET' => $TEXT['TARGET'],
@@ -400,11 +400,11 @@
 								'TEXT_NEW_WINDOW' => $TEXT['NEW_WINDOW'],
 								'TEXT_SAME_WINDOW' => $TEXT['SAME_WINDOW'],
 								'TEXT_ADMINISTRATORS' => $TEXT['ADMINISTRATORS'],
-								'TEXT_PRIVATE_VIEWERS' => $TEXT['PRIVATE_VIEWERS'],
+								'TEXT_PRIVATE_VIEWERS' => $TEXT['PRIVATE_VIEWERS'],
 								'TEXT_REGISTERED_VIEWERS' => $TEXT['REGISTERED_VIEWERS'],
 								'TEXT_DESCRIPTION' => $TEXT['DESCRIPTION'],
 								'TEXT_KEYWORDS' => $TEXT['KEYWORDS'],
-								'TEXT_SEARCHING' => $TEXT['SEARCHING'],
+								'TEXT_SEARCHING' => $TEXT['SEARCHING'],
 								'TEXT_LANGUAGE' => $TEXT['LANGUAGE'],
 								'TEXT_ENABLED' => $TEXT['ENABLED'],
 								'TEXT_DISABLED' => $TEXT['DISABLED'],
@@ -421,4 +421,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/admin/pages/add.php
===================================================================
--- trunk/wb/admin/pages/add.php	(revision 4)
+++ trunk/wb/admin/pages/add.php	(revision 5)
@@ -78,9 +78,9 @@
 $get_same_page = $database->query("SELECT page_id FROM ".TABLE_PREFIX."pages WHERE link = '$link'");
 if($get_same_page->numRows() > 0) {
 	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
-} elseif(file_exists(WB_PATH.$link.'.php')) {
+} elseif(file_exists(WB_PATH.PAGES_DIRECTORY.$link.'.php')) {
 	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
-} elseif(file_exists(WB_PATH.$link.'/')) {
+} elseif(file_exists(WB_PATH.PAGES_DIRECTORY.$link.'/')) {
 	$admin->print_error($MESSAGE['PAGES']['PAGE_EXISTS']);
 }
 
@@ -150,4 +150,4 @@
 // Print admin footer
 $admin->print_footer();
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/modules/wysiwyg/view.php
===================================================================
--- trunk/wb/modules/wysiwyg/view.php	(revision 4)
+++ trunk/wb/modules/wysiwyg/view.php	(revision 5)
@@ -27,17 +27,9 @@
 $get_content = $database->query("SELECT content FROM ".TABLE_PREFIX."mod_wysiwyg WHERE section_id = '$section_id'");
 $fetch_content = $get_content->fetchRow();
 $content = stripslashes($fetch_content['content']);
-// Replace [wblink--PAGE_ID--] with real link
-$pattern = '/\[wblink(.+?)\]/s';
-preg_match_all($pattern,$content,$ids);
-foreach($ids[1] AS $page_id) {
-	$pattern = '/\[wblink'.$page_id.'\]/s';
-	// Get page link
-	$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
-	$fetch_link = $get_link->fetchRow();
-	$link = page_link($fetch_link['link']);
-	$content = preg_replace($pattern,$link,$content);
-}
+
+$this->preprocess($content);
+
 echo $content;
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/modules/news/comment.php
===================================================================
--- trunk/wb/modules/news/comment.php	(revision 4)
+++ trunk/wb/modules/news/comment.php	(revision 5)
@@ -1,73 +1,71 @@
-<?php
-
-// $Id: comment.php,v 1.2 2005/04/02 06:25:56 rdjurovich Exp $
+<?php
 
-/*
-
- Website Baker Project <http://www.websitebaker.org/>
- Copyright (C) 2004-2005, Ryan Djurovich
-
- Website Baker is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Website Baker 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.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Website Baker; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
+// $Id: comment.php,v 1.2 2005/04/02 06:25:56 rdjurovich Exp $
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker 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.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
 */
-
-// Include config file
-require('../../config.php');
-
-// Check if there is a post id
-if(!isset($_GET['id']) OR !is_numeric($_GET['id'])) {
-	if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
-		header('Location: '.WB_URL.'/pages/');
-	} else {
-		$post_id = $_POST['post_id'];
-	}
-} else {
-	$post_id = $_GET['id'];
-}
-
-// Include database class
-if(!defined('DATABASE_CLASS_LOADED')) {
-	require(WB_PATH.'/framework/class.database.php');
-}
-$database = new database();
-
-// Query post for page id
-$query_post = $database->query("SELECT post_id,title,section_id,page_id FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
-if($query_post->numRows() == 0) {
-	header('Location: '.WB_URL.'/pages/');
-} else {
-	$fetch_post = $query_post->fetchRow();
-	$page_id = $fetch_post['page_id'];
-	$section_id = $fetch_post['section_id'];
-	$post_id = $fetch_post['post_id'];
-	$post_title = $fetch_post['title'];
-	define('SECTION_ID', $section_id);
-	define('POST_ID', $post_id);
-	define('POST_TITLE', $post_title);
-	// Get page details
-	$query_page = $database->query("SELECT parent,page_title,menu_title,keywords,description,visibility FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
-	if($query_page->numRows() == 0) {
-		header('Location: '.WB_URL.'/pages/');
-	} else {
-		$page = $query_page->fetchRow();
-		// Required page details
-		define('PAGE_CONTENT', WB_PATH.'/modules/news/comment_page.php');
-		// Include index (wrapper) file
-		require(WB_PATH.'/index.php');
-	}
-}
-
-
-?>
\ No newline at end of file
+
+// Include config file
+require('../../config.php');
+
+// Check if there is a post id
+if(!isset($_GET['id']) OR !is_numeric($_GET['id'])) {
+	if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
+		header('Location: '.WB_URL.'/pages/');
+	} else {
+		$post_id = $_POST['post_id'];
+	}
+} else {
+	$post_id = $_GET['id'];
+}
+
+// Include database class
+require_once(WB_PATH.'/framework/class.database.php');
+$database = new database();
+
+// Query post for page id
+$query_post = $database->query("SELECT post_id,title,section_id,page_id FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '$post_id'");
+if($query_post->numRows() == 0) {
+	header('Location: '.WB_URL.'/pages/');
+} else {
+	$fetch_post = $query_post->fetchRow();
+	$page_id = $fetch_post['page_id'];
+	$section_id = $fetch_post['section_id'];
+	$post_id = $fetch_post['post_id'];
+	$post_title = $fetch_post['title'];
+	define('SECTION_ID', $section_id);
+	define('POST_ID', $post_id);
+	define('POST_TITLE', $post_title);
+	// Get page details
+	$query_page = $database->query("SELECT parent,page_title,menu_title,keywords,description,visibility FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
+	if($query_page->numRows() == 0) {
+		header('Location: '.WB_URL.'/pages/');
+	} else {
+		$page = $query_page->fetchRow();
+		// Required page details
+		define('PAGE_CONTENT', WB_PATH.'/modules/news/comment_page.php');
+		// Include index (wrapper) file
+		require(WB_PATH.'/index.php');
+	}
+}
+
+
+?>
Index: trunk/wb/modules/news/view.php
===================================================================
--- trunk/wb/modules/news/view.php	(revision 4)
+++ trunk/wb/modules/news/view.php	(revision 5)
@@ -1,342 +1,323 @@
-<?php
-
-// $Id: view.php,v 1.7 2005/06/21 09:11:27 rdjurovich Exp $
+<?php
 
-/*
-
- Website Baker Project <http://www.websitebaker.org/>
- Copyright (C) 2004-2005, Ryan Djurovich
-
- Website Baker is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Website Baker 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.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Website Baker; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-*/
+// $Id: view.php,v 1.7 2005/06/21 09:11:27 rdjurovich Exp $
 
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker 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.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
 // Must include code to stop this file being access directly
 if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
-
-// Check if there is a start point defined
-if(isset($_GET['p']) AND is_numeric($_GET['p']) AND $_GET['p'] >= 0) {
-	$position = $_GET['p'];
-} else {
-	$position = 0;
-}
-
-// Get user's username, display name, email, and id - needed for insertion into post info
-$users = array();
-$query_users = $database->query("SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users");
-if($query_users->numRows() > 0) {
-	while($user = $query_users->fetchRow()) {
-		// Insert user info into users array
-		$user_id = $user['user_id'];
-		$users[$user_id]['username'] = $user['username'];
-		$users[$user_id]['display_name'] = $user['display_name'];
-		$users[$user_id]['email'] = $user['email'];
-	}
-}
-
-// Get groups (title, if they are active, and their image [if one has been uploaded])
-$groups[0]['title'] = '';
-$groups[0]['active'] = true;
-$groups[0]['image'] = '';
-$query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC");
-if($query_users->numRows() > 0) {
-	while($group = $query_users->fetchRow()) {
-		// Insert user info into users array
-		$group_id = $group['group_id'];
-		$groups[$group_id]['title'] = stripslashes($group['title']);
-		$groups[$group_id]['active'] = $group['active'];
-		if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
-			$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
-		} else {
-			$groups[$group_id]['image'] = '';
-		}
-	}
-}
-
-// Check if we should show the main page or a post itself
-if(!defined('POST_ID') OR !is_numeric(POST_ID)) {
-	
-	// Check if we should only list posts from a certain group
-	if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
-		$query_extra = " AND group_id = '".$_GET['g']."'";
-		?>
-		<style type="text/css">.selected_group_title { font-size: 14px; text-align: center; }</style>
-		<?php
-	} else {
-		$query_extra = '';
-	}
-	
+
+// Check if there is a start point defined
+if(isset($_GET['p']) AND is_numeric($_GET['p']) AND $_GET['p'] >= 0) {
+	$position = $_GET['p'];
+} else {
+	$position = 0;
+}
+
+// Get user's username, display name, email, and id - needed for insertion into post info
+$users = array();
+$query_users = $database->query("SELECT user_id,username,display_name,email FROM ".TABLE_PREFIX."users");
+if($query_users->numRows() > 0) {
+	while($user = $query_users->fetchRow()) {
+		// Insert user info into users array
+		$user_id = $user['user_id'];
+		$users[$user_id]['username'] = $user['username'];
+		$users[$user_id]['display_name'] = $user['display_name'];
+		$users[$user_id]['email'] = $user['email'];
+	}
+}
+
+// Get groups (title, if they are active, and their image [if one has been uploaded])
+$groups[0]['title'] = '';
+$groups[0]['active'] = true;
+$groups[0]['image'] = '';
+$query_users = $database->query("SELECT group_id,title,active FROM ".TABLE_PREFIX."mod_news_groups WHERE section_id = '$section_id' ORDER BY position ASC");
+if($query_users->numRows() > 0) {
+	while($group = $query_users->fetchRow()) {
+		// Insert user info into users array
+		$group_id = $group['group_id'];
+		$groups[$group_id]['title'] = stripslashes($group['title']);
+		$groups[$group_id]['active'] = $group['active'];
+		if(file_exists(WB_PATH.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg')) {
+			$groups[$group_id]['image'] = WB_URL.MEDIA_DIRECTORY.'/.news/image'.$group_id.'.jpg';
+		} else {
+			$groups[$group_id]['image'] = '';
+		}
+	}
+}
+
+// Check if we should show the main page or a post itself
+if(!defined('POST_ID') OR !is_numeric(POST_ID)) {
+	
+	// Check if we should only list posts from a certain group
+	if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
+		$query_extra = " AND group_id = '".$_GET['g']."'";
+		?>
+		<style type="text/css">.selected_group_title { font-size: 14px; text-align: center; }</style>
+		<?php
+	} else {
+		$query_extra = '';
+	}
+	
 	// Get settings
-	$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
-	if($query_settings->numRows() > 0) {
-		$fetch_settings = $query_settings->fetchRow();
-		$setting_header = stripslashes($fetch_settings['header']);
-		$setting_post_loop = stripslashes($fetch_settings['post_loop']);
-		$setting_footer = stripslashes($fetch_settings['footer']);
-		$setting_posts_per_page = $fetch_settings['posts_per_page'];
-	} else {
-		$setting_header = '';
-		$setting_post_loop = '';
-		$setting_footer = '';
-		$setting_posts_per_page = '';
-	}
-	
-	// Get total number of posts
-	$query_total_num = $database->query("SELECT post_id FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra");
-	$total_num = $query_total_num->numRows();
-
-	// Work-out if we need to add limit code to sql
-	if($setting_posts_per_page != 0) {
-		$limit_sql = " LIMIT $position,$setting_posts_per_page";
-	} else {
-		$limit_sql = "";
-	}
-	
-	// Query posts (for this page)
-	$query_posts = $database->query("SELECT group_id,post_id,title,link,short,posted_by,posted_when FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra ORDER BY position DESC".$limit_sql);
-	$num_posts = $query_posts->numRows();
-	
-	// Create previous and next links
-	if($setting_posts_per_page != 0) {
-		if($position > 0) {
-			if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
-				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'&g='.$_GET['g'].'"><< ';
-			} else {
-				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'"><< ';
-			}
-			$pl_append = '</a>';
-			$previous_link = $pl_prepend.$TEXT['PREVIOUS'].$pl_append;
-			$previous_page_link = $pl_prepend.$TEXT['PREVIOUS_PAGE'].$pl_append;
-		} else {
-			$previous_link = '';
-			$previous_page_link = '';
-		}
-		if($position+$setting_posts_per_page >= $total_num) {
-			$next_link = '';
-			$next_page_link = '';
-		} else {
-			if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
-				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'&g='.$_GET['g'].'"> ';
-			} else {
-				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'"> ';
-			}
-			$nl_append = ' >></a>';
-			$next_link = $nl_prepend.$TEXT['NEXT'].$nl_append;
-			$next_page_link = $nl_prepend.$TEXT['NEXT_PAGE'].$nl_append;
-		}
-		if($position+$setting_posts_per_page > $total_num) {
-			$num_of = $position+$num_posts;
-		} else {
-			$num_of = $position+$setting_posts_per_page;
-		}
-		$out_of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OUT_OF']).' '.$total_num;
-		$of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OF']).' '.$total_num;
-		$display_previous_next_links = '';
-	} else {
-		$display_previous_next_links = 'none';
-	}
-		
-	// Print header
-	if($display_previous_next_links == 'none') {
-		echo  str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_header);
-	} else {
-		echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_header);
-	}
-	
-	if($num_posts > 0) {
-		if($query_extra != '') {
-			?>
-			<div class="selected_group_title">
-				<?php echo '<a href="'.$_SERVER['PHP_SELF'].'">'.PAGE_TITLE.'</a> >> '.$groups[$_GET['g']]['title']; ?>
-			</div>
-			<?php
-		}
-		while($post = $query_posts->fetchRow()) {
-			if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
-				$uid = $post['posted_by']; // User who last modified the post
-				// Workout date and time of last modified post
-				$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
-				$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
-				// Work-out the post link
-				$post_link = page_link($post['link']);
-				if(isset($_GET['p']) AND $position > 0) {
-					$post_link .= '?p='.$position;
-				}
-				if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
-					if(isset($_GET['p']) AND $position > 0) { $post_link .= '&'; } else { $post_link .= '?'; }
-					$post_link .= 'g='.$_GET['g'];
-				}
-				// Get group id, title, and image
-				$group_id = $post['group_id'];
-				$group_title = $groups[$group_id]['title'];
-				$group_image = $groups[$group_id]['image'];
-				if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
-				if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
-				// Replace [wblink--PAGE_ID--] with real link
-				$short = stripslashes($post['short']);
-				$pattern = '/\[wblink(.+?)\]/s';
-				preg_match_all($pattern,$short,$ids);
-				foreach($ids[1] AS $page_id) {
-					$pattern = '/\[wblink'.$page_id.'\]/s';
-					// Get page link
-					$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
-					$fetch_link = $get_link->fetchRow();
-					$link = page_link($fetch_link['link']);
-					$short = preg_replace($pattern,$link,$short);
-				}
-				// Replace vars with values
-				$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[LINK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]', '[TEXT_READ_MORE]');
-				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
-					$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $TEXT['READ_MORE']);
-				} else {
-					$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, '', '', '', '', $TEXT['READ_MORE']);
-				}
-				echo str_replace($vars, $values, $setting_post_loop);
-			}
-		}
-	}
-	
-	// Print footer
-	if($display_previous_next_links == 'none') {
-		echo  str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_footer);
-	} else {
-		echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_footer);
-	}
-	
-} elseif(defined('POST_ID') AND is_numeric(POST_ID)) {
-	
-	// Get settings
-	$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
-	if($query_settings->numRows() > 0) {
-		$fetch_settings = $query_settings->fetchRow();
-		$setting_post_header = stripslashes($fetch_settings['post_header']);
-		$setting_post_footer = stripslashes($fetch_settings['post_footer']);
-		$setting_comments_header = stripslashes($fetch_settings['comments_header']);
-		$setting_comments_loop = stripslashes($fetch_settings['comments_loop']);
-		$setting_comments_footer = stripslashes($fetch_settings['comments_footer']);
-	} else {
-		$setting_post_header = '';
-		$setting_post_footer = '';
-		$setting_comments_header = '';
-		$setting_comments_loop = '';
-		$setting_comments_footer = '';
-	}
-	
-	// Get page info
-	$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'");
-	if($query_page->numRows() > 0) {
-		$page = $query_page->fetchRow();
-		$page_link = page_link($page['link']);
-		if(isset($_GET['p']) AND $position > 0) {
-			$page_link .= '?p='.$_GET['p'];
-		}
-		if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
-			if(isset($_GET['p']) AND $position > 0) { $page_link .= '&'; } else { $page_link .= '?'; }
-			$page_link .= 'g='.$_GET['g'];
-		}
-	} else {
-		exit('Page not found');
-	}
-	
-	// Get post info
-	$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '".POST_ID."' AND active = '1'");
-	if($query_post->numRows() > 0) {
-		$post = $query_post->fetchRow();
-		if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
-			$uid = $post['posted_by']; // User who last modified the post
-			// Workout date and time of last modified post
-			$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
-			$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
-			// Get group id, title, and image
-			$group_id = $post['group_id'];
-			$group_title = $groups[$group_id]['title'];
-			$group_image = $groups[$group_id]['image'];
-			if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
-			if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
-			$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[BACK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]');
-			if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
-				$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']);
-			} else {
-				$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, '', '', '', '');
-			}
-			$post_long = stripslashes($post['long']);
-		}
-	} else {
-		header('Location: '.WB_URL.'/pages/');
-	}
-	
-	// Print post header
-	echo str_replace($vars, $values, $setting_post_header);
-	
-	// Replace [wblink--PAGE_ID--] with real link
-	$pattern = '/\[wblink(.+?)\]/s';
-	preg_match_all($pattern,$post_long,$ids);
-	foreach($ids[1] AS $page_id) {
-		$pattern = '/\[wblink'.$page_id.'\]/s';
-		// Get page link
-		$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
-		$fetch_link = $get_link->fetchRow();
-		$link = page_link($fetch_link['link']);
-		$post_long = preg_replace($pattern,$link,$post_long);
-	}
-	
-	// Print long
-	echo $post_long;
-	
-	// Print post footer
-	echo str_replace($vars, $values, $setting_post_footer);
-	
-	// Show comments section if we have to
-	if($post['commenting'] == 'private' AND isset($admin) AND $admin->is_authenticated() == true OR $post['commenting'] == 'public') {
-		
-		// Print comments header
-		echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_header);
-		
-		// Query for comments
-		$query_comments = $database->query("SELECT title,comment,commented_when,commented_by FROM ".TABLE_PREFIX."mod_news_comments WHERE post_id = '".POST_ID."' ORDER BY commented_when ASC");
-		if($query_comments->numRows() > 0) {
-			while($comment = $query_comments->fetchRow()) {
-				// Display Comments without slashes, but with new-line characters
-				$comment['comment'] = nl2br(stripslashes($comment['comment']));
-				$comment['title'] = stripslashes($comment['title']);
-				// Print comments loop
-				$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE);
-				$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE);
-				$uid = $comment['commented_by'];
-				$vars = array('[TITLE]','[COMMENT]','[DATE]','[TIME]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]');
-				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
-					$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, $uid, stripslashes($users[$uid]['username']), stripslashes($users[$uid]['display_name']), stripslashes($users[$uid]['email']));
-				} else {
-					$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, '0', strtolower($TEXT['UNKNOWN']), $TEXT['UNKNOWN'], '');
-				}
-				echo str_replace($vars, $values, $setting_comments_loop);
-			}
-		} else {
-			// Say no comments found
-			if(isset($TEXT['NONE_FOUND'])) {
-				echo $TEXT['NONE_FOUND'].'<br />';
-			} else {
-				echo 'None Found<br />';
-			}
-		}
-		
-		// Print comments footer
-		echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_footer);
-		
-	}
-		
-}
+	$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
+	if($query_settings->numRows() > 0) {
+		$fetch_settings = $query_settings->fetchRow();
+		$setting_header = stripslashes($fetch_settings['header']);
+		$setting_post_loop = stripslashes($fetch_settings['post_loop']);
+		$setting_footer = stripslashes($fetch_settings['footer']);
+		$setting_posts_per_page = $fetch_settings['posts_per_page'];
+	} else {
+		$setting_header = '';
+		$setting_post_loop = '';
+		$setting_footer = '';
+		$setting_posts_per_page = '';
+	}
+	
+	// Get total number of posts
+	$query_total_num = $database->query("SELECT post_id FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra");
+	$total_num = $query_total_num->numRows();
 
-?>
\ No newline at end of file
+	// Work-out if we need to add limit code to sql
+	if($setting_posts_per_page != 0) {
+		$limit_sql = " LIMIT $position,$setting_posts_per_page";
+	} else {
+		$limit_sql = "";
+	}
+	
+	// Query posts (for this page)
+	$query_posts = $database->query("SELECT group_id,post_id,title,link,short,posted_by,posted_when FROM ".TABLE_PREFIX."mod_news_posts WHERE section_id = '$section_id' AND active = '1' AND title != ''$query_extra ORDER BY position DESC".$limit_sql);
+	$num_posts = $query_posts->numRows();
+	
+	// Create previous and next links
+	if($setting_posts_per_page != 0) {
+		if($position > 0) {
+			if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
+				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'&g='.$_GET['g'].'"><< ';
+			} else {
+				$pl_prepend = '<a href="?p='.($position-$setting_posts_per_page).'"><< ';
+			}
+			$pl_append = '</a>';
+			$previous_link = $pl_prepend.$TEXT['PREVIOUS'].$pl_append;
+			$previous_page_link = $pl_prepend.$TEXT['PREVIOUS_PAGE'].$pl_append;
+		} else {
+			$previous_link = '';
+			$previous_page_link = '';
+		}
+		if($position+$setting_posts_per_page >= $total_num) {
+			$next_link = '';
+			$next_page_link = '';
+		} else {
+			if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
+				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'&g='.$_GET['g'].'"> ';
+			} else {
+				$nl_prepend = '<a href="?p='.($position+$setting_posts_per_page).'"> ';
+			}
+			$nl_append = ' >></a>';
+			$next_link = $nl_prepend.$TEXT['NEXT'].$nl_append;
+			$next_page_link = $nl_prepend.$TEXT['NEXT_PAGE'].$nl_append;
+		}
+		if($position+$setting_posts_per_page > $total_num) {
+			$num_of = $position+$num_posts;
+		} else {
+			$num_of = $position+$setting_posts_per_page;
+		}
+		$out_of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OUT_OF']).' '.$total_num;
+		$of = ($position+1).'-'.$num_of.' '.strtolower($TEXT['OF']).' '.$total_num;
+		$display_previous_next_links = '';
+	} else {
+		$display_previous_next_links = 'none';
+	}
+		
+	// Print header
+	if($display_previous_next_links == 'none') {
+		echo  str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_header);
+	} else {
+		echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_header);
+	}
+	
+	if($num_posts > 0) {
+		if($query_extra != '') {
+			?>
+			<div class="selected_group_title">
+				<?php echo '<a href="'.$_SERVER['PHP_SELF'].'">'.PAGE_TITLE.'</a> >> '.$groups[$_GET['g']]['title']; ?>
+			</div>
+			<?php
+		}
+		while($post = $query_posts->fetchRow()) {
+			if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
+				$uid = $post['posted_by']; // User who last modified the post
+				// Workout date and time of last modified post
+				$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
+				$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
+				// Work-out the post link
+				$post_link = page_link($post['link']);
+				if(isset($_GET['p']) AND $position > 0) {
+					$post_link .= '?p='.$position;
+				}
+				if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
+					if(isset($_GET['p']) AND $position > 0) { $post_link .= '&'; } else { $post_link .= '?'; }
+					$post_link .= 'g='.$_GET['g'];
+				}
+				// Get group id, title, and image
+				$group_id = $post['group_id'];
+				$group_title = $groups[$group_id]['title'];
+				$group_image = $groups[$group_id]['image'];
+				if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
+				if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
+				// Replace [wblink--PAGE_ID--] with real link
+				$short = stripslashes($post['short']);
+				$this->preprocess($short);
+				// Replace vars with values
+				$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[LINK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]', '[TEXT_READ_MORE]');
+				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
+					$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email'], $TEXT['READ_MORE']);
+				} else {
+					$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), $short, $post_link, $post_date, $post_time, '', '', '', '', $TEXT['READ_MORE']);
+				}
+				echo str_replace($vars, $values, $setting_post_loop);
+			}
+		}
+	}
+	
+	// Print footer
+	if($display_previous_next_links == 'none') {
+		echo  str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array('','','','','','', $display_previous_next_links), $setting_footer);
+	} else {
+		echo str_replace(array('[NEXT_PAGE_LINK]','[NEXT_LINK]','[PREVIOUS_PAGE_LINK]','[PREVIOUS_LINK]','[OUT_OF]','[OF]','[DISPLAY_PREVIOUS_NEXT_LINKS]'), array($next_page_link, $next_link, $previous_page_link, $previous_link, $out_of, $of, $display_previous_next_links), $setting_footer);
+	}
+	
+} elseif(defined('POST_ID') AND is_numeric(POST_ID)) {
+	
+	// Get settings
+	$query_settings = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_settings WHERE section_id = '$section_id'");
+	if($query_settings->numRows() > 0) {
+		$fetch_settings = $query_settings->fetchRow();
+		$setting_post_header = stripslashes($fetch_settings['post_header']);
+		$setting_post_footer = stripslashes($fetch_settings['post_footer']);
+		$setting_comments_header = stripslashes($fetch_settings['comments_header']);
+		$setting_comments_loop = stripslashes($fetch_settings['comments_loop']);
+		$setting_comments_footer = stripslashes($fetch_settings['comments_footer']);
+	} else {
+		$setting_post_header = '';
+		$setting_post_footer = '';
+		$setting_comments_header = '';
+		$setting_comments_loop = '';
+		$setting_comments_footer = '';
+	}
+	
+	// Get page info
+	$query_page = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '".PAGE_ID."'");
+	if($query_page->numRows() > 0) {
+		$page = $query_page->fetchRow();
+		$page_link = page_link($page['link']);
+		if(isset($_GET['p']) AND $position > 0) {
+			$page_link .= '?p='.$_GET['p'];
+		}
+		if(isset($_GET['g']) AND is_numeric($_GET['g'])) {
+			if(isset($_GET['p']) AND $position > 0) { $page_link .= '&'; } else { $page_link .= '?'; }
+			$page_link .= 'g='.$_GET['g'];
+		}
+	} else {
+		exit('Page not found');
+	}
+	
+	// Get post info
+	$query_post = $database->query("SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE post_id = '".POST_ID."' AND active = '1'");
+	if($query_post->numRows() > 0) {
+		$post = $query_post->fetchRow();
+		if(isset($groups[$post['group_id']]['active']) AND $groups[$post['group_id']]['active'] != false) { // Make sure parent group is active
+			$uid = $post['posted_by']; // User who last modified the post
+			// Workout date and time of last modified post
+			$post_date = gmdate(DATE_FORMAT, $post['posted_when']+TIMEZONE);
+			$post_time = gmdate(TIME_FORMAT, $post['posted_when']+TIMEZONE);
+			// Get group id, title, and image
+			$group_id = $post['group_id'];
+			$group_title = $groups[$group_id]['title'];
+			$group_image = $groups[$group_id]['image'];
+			if($group_image == '') { $display_image = 'none'; } else { $display_image = ''; }
+			if($group_id == 0) { $display_group = 'none'; } else { $display_group = ''; }
+			$vars = array('[PAGE_TITLE]', '[GROUP_ID]', '[GROUP_TITLE]', '[GROUP_IMAGE]', '[DISPLAY_GROUP]', '[DISPLAY_IMAGE]', '[TITLE]', '[SHORT]', '[BACK]', '[DATE]', '[TIME]', '[USER_ID]', '[USERNAME]', '[DISPLAY_NAME]', '[EMAIL]');
+			if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
+				$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, $uid, $users[$uid]['username'], $users[$uid]['display_name'], $users[$uid]['email']);
+			} else {
+				$values = array(PAGE_TITLE, $group_id, $group_title, $group_image, $display_group, $display_image, stripslashes($post['title']), stripslashes($post['short']), $page_link, $post_date, $post_time, '', '', '', '');
+			}
+			$post_long = stripslashes($post['long']);
+		}
+	} else {
+		header('Location: '.WB_URL.'/pages/');
+	}
+	
+	// Print post header
+	echo str_replace($vars, $values, $setting_post_header);
+	
+	// Replace [wblink--PAGE_ID--] with real link
+  	$this->preprocess($postlong);
+	// Print long
+	echo $post_long;
+	
+	// Print post footer
+	echo str_replace($vars, $values, $setting_post_footer);
+	
+	// Show comments section if we have to
+	if($post['commenting'] == 'private' AND isset($admin) AND $admin->is_authenticated() == true OR $post['commenting'] == 'public') {
+		
+		// Print comments header
+		echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_header);
+		
+		// Query for comments
+		$query_comments = $database->query("SELECT title,comment,commented_when,commented_by FROM ".TABLE_PREFIX."mod_news_comments WHERE post_id = '".POST_ID."' ORDER BY commented_when ASC");
+		if($query_comments->numRows() > 0) {
+			while($comment = $query_comments->fetchRow()) {
+				// Display Comments without slashes, but with new-line characters
+				$comment['comment'] = nl2br(stripslashes($comment['comment']));
+				$comment['title'] = stripslashes($comment['title']);
+				// Print comments loop
+				$commented_date = gmdate(DATE_FORMAT, $comment['commented_when']+TIMEZONE);
+				$commented_time = gmdate(TIME_FORMAT, $comment['commented_when']+TIMEZONE);
+				$uid = $comment['commented_by'];
+				$vars = array('[TITLE]','[COMMENT]','[DATE]','[TIME]','[USER_ID]','[USERNAME]','[DISPLAY_NAME]', '[EMAIL]');
+				if(isset($users[$uid]['username']) AND $users[$uid]['username'] != '') {
+					$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, $uid, stripslashes($users[$uid]['username']), stripslashes($users[$uid]['display_name']), stripslashes($users[$uid]['email']));
+				} else {
+					$values = array(stripslashes($comment['title']), stripslashes($comment['comment']), $commented_date, $commented_time, '0', strtolower($TEXT['UNKNOWN']), $TEXT['UNKNOWN'], '');
+				}
+				echo str_replace($vars, $values, $setting_comments_loop);
+			}
+		} else {
+			// Say no comments found
+			if(isset($TEXT['NONE_FOUND'])) {
+				echo $TEXT['NONE_FOUND'].'<br />';
+			} else {
+				echo 'None Found<br />';
+			}
+		}
+		
+		// Print comments footer
+		echo str_replace('[ADD_COMMENT_URL]', WB_URL.'/modules/news/comment.php?id='.POST_ID, $setting_comments_footer);
+		
+	}
+		
+}
+
+?>
Index: trunk/wb/framework/compatibility.php
===================================================================
--- trunk/wb/framework/compatibility.php	(nonexistent)
+++ trunk/wb/framework/compatibility.php	(revision 5)
@@ -0,0 +1,107 @@
+<?php
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker 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.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+/*
+	This file is purely for ensuring compatibility with 3rd party
+	contributions made for WB version 2.5.2 or below
+*/
+
+function page_link($link) {
+	global $wb;
+	$wb->page_link($link);
+}
+
+
+function page_content($block=1) {
+	global $wb;
+	$wb->page_content($block);
+}
+
+// Old menu call invokes new menu function
+function page_menu($parent = 0, $menu_number = 1, $item_template = '<li><span[class]>[a][menu_title][/a]</span>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $recurse = LEVEL) {
+	global $wb;
+	$wb->menu($menu_number, 0, -1, true, $item_template, '</li>', $menu_header, $menu_footer, $default_class, $current_class, $parent);
+//	$wb->page_menu($parent, $menu_number, $item_template.'</li>', $menu_header, $menu_footer, $default_class, $current_class, $recurse);
+}
+
+// Function for page title
+function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
+	global $wb;
+	$wb->page_title($spacer,$template);
+}
+
+// Function for page description
+function page_description() {
+	global $wb;
+	$wb->page_description();
+}
+// Function for page keywords
+function page_keywords() {
+	global $wb;
+	$wb->page_keywords();
+}
+// Function for page header
+function page_header($date_format = 'Y') {
+	global $wb;
+	$wb->page_header($date_format);
+}
+// Function for page footer
+function page_footer($date_format = 'Y') {
+	global $wb;
+	$wb->page_footer($date_format);
+}
+
+// references to objects and variables that changed their names
+
+$admin = &$wb;
+
+$default_link=&$wb->default_link;
+
+$page_trail=&$wb->page_trail;
+$page_description=&$wb->page_description;
+$page_keywords=&$wb->page_keywords;
+$page_link=&$wb->link;
+
+$extra_sql=&$wb->extra_sql;
+$extra_where_sql=&$wb->extra_where_sql;
+
+
+// Begin WB < 2.4.x template compatibility code
+	// Make extra_sql accessable through private_sql
+	$private_sql = $extra_sql;
+	$private_where_sql = $extra_where_sql;
+	// Query pages for menu
+	$menu1 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND $extra_where_sql ORDER BY position ASC");
+	// Check if current pages is a parent page and if we need its submenu
+	if(PARENT == 0) {
+		// Get the pages submenu
+		$menu2 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '".PAGE_ID."' AND $extra_where_sql ORDER BY position ASC");
+	} else {
+		// Get the pages submenu
+		$menu2 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '".PARENT."' AND $extra_where_sql ORDER BY position ASC");
+	}
+// End WB < 2.4.x template compatibility code
+// Include template file
+
+
+?>
Index: trunk/wb/framework/class.admin.php
===================================================================
--- trunk/wb/framework/class.admin.php	(revision 4)
+++ trunk/wb/framework/class.admin.php	(revision 5)
@@ -32,27 +32,15 @@
 
 */
 
-// Stop this file from being accessed directly
-if(!defined('WB_PATH')) { exit('Direct access to this file is not allowed'); }
 
-// Say that this file has been loaded
-define('ADMIN_CLASS_LOADED', true);
-	
-// Load the other required class files if they are not already loaded
-require_once(WB_PATH.'/framework/class.database.php');
-if(!isset($database)) {
-	$database = new database();
-}
 
+require_once(WB_PATH.'/framework/class.wb.php');
+
+require_once(WB_PATH.'/framework/initialize.php');
+
 // Include PHPLIB template class
 require_once(WB_PATH."/include/phplib/template.inc");
 
-// Start a session
-if(!defined('SESSION_STARTED')) {
-	session_name(APP_NAME.'_session_id');
-	session_start();
-	define('SESSION_STARTED', true);
-}
 
 // Get WB version
 require_once(ADMIN_PATH.'/interface/version.php');
@@ -60,53 +48,8 @@
 /*
 Begin user changeable settings
 */
-if(!defined('FRONTEND_LOADED')) {
-	// Get users language
-	if(!defined('LANGUAGE')) {
-		if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
-			define('LANGUAGE', $_SESSION['LANGUAGE']);
-		} else {
-			define('LANGUAGE', DEFAULT_LANGUAGE);
-		}
-	}
-	// Get users timezone
-	if(!defined('TIMEZONE')) {
-		if(isset($_SESSION['TIMEZONE'])) {
-			define('TIMEZONE', $_SESSION['TIMEZONE']);
-		} else {
-			define('TIMEZONE', DEFAULT_TIMEZONE);
-		}
-	}
-	// Get users date format
-	if(!defined('DATE_FORMAT')) {
-		if(isset($_SESSION['DATE_FORMAT'])) {
-			define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
-		} else {
-			define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
-		}
-	}
-	// Get users time format
-	if(!defined('TIME_FORMAT')) {
-		if(isset($_SESSION['TIME_FORMAT'])) {
-			define('TIME_FORMAT', $_SESSION['TIME_FORMAT']);
-		} else {
-			define('TIME_FORMAT', DEFAULT_TIME_FORMAT);
-		}
-	}
-	// Load the language file
-	if(!defined('LANGUAGE_LOADED')) {
-		if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
-			exit('Error loading language file '.LANGUAGE.', please check configuration');
-		} else {
-			require(WB_PATH.'/languages/'.LANGUAGE.'.php');
-		}
-	}
-}
-/*
-End user changeable settings
-*/
 
-class admin {
+class admin extends wb {
 	// Authenticate user then auto print the header
 	function admin($section_name, $section_permission = 'start', $auto_header = true, $auto_auth = true) {
 		global $MESSAGE;
@@ -229,7 +172,7 @@
 		}
 		exit();
 	}
-	
+
 	// Return a system permission
 	function get_permission($name, $type = 'system') {
 		// Append to permission type
@@ -260,7 +203,7 @@
 			}
 		}
 	}
-	
+
 	// Returns a system permission for a menu link
 	function get_link_permission($title) {
 		$title = str_replace('_blank', '', $title);
@@ -280,129 +223,6 @@
 			}
 		}
 	}
-	
-	// Check whether we should show a page or not (for front-end)
-	function show_page($page) {
-		// First check if the page is set to private
-		if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
-			// Check if the user is logged in
-			if($this->is_authenticated() == true) {
-				// Now check if the user has perms to view it
-				$viewing_groups = explode(',', $page['viewing_groups']);
-				$viewing_users = explode(',', $page['viewing_users']);
-				if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
-					return true;
-				} else {
-					return false;
-				}
-			} else {
-				return false;
-			}
-		} elseif($page['visibility'] == 'public') {
-			return true;
-		} else {
-			return false;
-		}
-	}
-	
-	// Check if the user is already authenticated or not
-	function is_authenticated() {
-		if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
-			return true;
-		} else {
-			return false;
-		}
-	}
-	
-	// Get POST data
-	function get_post($field) {
-		if(isset($_POST[$field])) {
-			return $_POST[$field];
-		} else {
-			return null;
-		}
-	}
-	
-	// Get GET data
-	function get_get($field) {
-		if(isset($_GET[$field])) {
-			return $_GET[$field];
-		} else {
-			return null;
-		}
-	}
-	
-	// Get SESSION data
-	function get_session($field) {
-		if(isset($_SESSION[$field])) {
-			return $_SESSION[$field];
-		} else {
-			return null;
-		}
-	}
-	
-	// Get SERVER data
-	function get_server($field) {
-		if(isset($_SERVER[$field])) {
-			return $_SERVER[$field];
-		} else {
-			return null;
-		}
-	}
-	
-	// Get the current users id
-	function get_user_id() {
-		return $_SESSION['USER_ID'];
-	}
-	
-	// Get the current users group id
-	function get_group_id() {
-		return $_SESSION['GROUP_ID'];
-	}
-	
-	// Get the current users group name
-	function get_group_name() {
-		return $_SESSION['GROUP_NAME'];
-	}
-	
-	// Get the current users username
-	function get_username() {
-		return $_SESSION['USERNAME'];
-	}
-	
-	// Get the current users display name
-	function get_display_name() {
-		return stripslashes($_SESSION['DISPLAY_NAME']);
-	}
-	
-	// Get the current users email address
-	function get_email() {
-		return $_SESSION['EMAIL'];
-	}
-	
-	// Get the current users home folder
-	function get_home_folder() {
-		return $_SESSION['HOME_FOLDER'];
-	}
-	
-	// Get the current users timezone
-	function get_timezone() {
-		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
-			return $_SESSION['TIMEZONE'];
-		} else {
-			return '-72000';
-		}
-	}
-	
-	// Validate supplied email address
-	function validate_email($email) {
-		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
-			return true;
-		} else {
-			return false;
-		}
-	}
-	
 }
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/framework/class.login.php
===================================================================
--- trunk/wb/framework/class.login.php	(revision 4)
+++ trunk/wb/framework/class.login.php	(revision 5)
@@ -43,6 +43,7 @@
 	function login($config_array) {
 		// Get language vars
 		global $MESSAGE;
+		$this->wb();
 		// Get configuration values
 		$this->USERS_TABLE = $config_array['USERS_TABLE'];
 		$this->GROUPS_TABLE = $config_array['GROUPS_TABLE'];
@@ -356,4 +357,4 @@
 	
 }
 
-?>
\ No newline at end of file
+?>
Index: trunk/wb/framework/class.wb.php
===================================================================
--- trunk/wb/framework/class.wb.php	(nonexistent)
+++ trunk/wb/framework/class.wb.php	(revision 5)
@@ -0,0 +1,162 @@
+<?php
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker 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.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+/*
+
+wb class
+
+This class is the basis for admin and frontend classes.
+
+*/
+
+
+class wb
+{
+	function wb() {
+	}
+
+	// Check whether we should show a page or not (for front-end)
+	function show_page($page) {
+		// First check if the page is set to private
+		if($page['visibility'] == 'private' OR $page['visibility'] == 'registered') {
+			// Check if the user is logged in
+			if($this->is_authenticated() == true) {
+				// Now check if the user has perms to view it
+				$viewing_groups = explode(',', $page['viewing_groups']);
+				$viewing_users = explode(',', $page['viewing_users']);
+				if(is_numeric(array_search($this->get_group_id(), $viewing_groups)) OR is_numeric(array_search($this->get_user_id(), $viewing_users))) {
+					return true;
+				} else {
+					return false;
+				}
+			} else {
+				return false;
+			}
+		} elseif($page['visibility'] == 'public') {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	// Check if the user is already authenticated or not
+	function is_authenticated() {
+		if(isset($_SESSION['USER_ID']) AND $_SESSION['USER_ID'] != "" AND is_numeric($_SESSION['USER_ID'])) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	// Get POST data
+	function get_post($field) {
+		if(isset($_POST[$field])) {
+			return $_POST[$field];
+		} else {
+			return null;
+		}
+	}
+
+	// Get GET data
+	function get_get($field) {
+		if(isset($_GET[$field])) {
+			return $_GET[$field];
+		} else {
+			return null;
+		}
+	}
+
+	// Get SESSION data
+	function get_session($field) {
+		if(isset($_SESSION[$field])) {
+			return $_SESSION[$field];
+		} else {
+			return null;
+		}
+	}
+
+	// Get SERVER data
+	function get_server($field) {
+		if(isset($_SERVER[$field])) {
+			return $_SERVER[$field];
+		} else {
+			return null;
+		}
+	}
+
+	// Get the current users id
+	function get_user_id() {
+		return $_SESSION['USER_ID'];
+	}
+
+	// Get the current users group id
+	function get_group_id() {
+		return $_SESSION['GROUP_ID'];
+	}
+
+	// Get the current users group name
+	function get_group_name() {
+		return $_SESSION['GROUP_NAME'];
+	}
+
+	// Get the current users username
+	function get_username() {
+		return $_SESSION['USERNAME'];
+	}
+
+	// Get the current users display name
+	function get_display_name() {
+		return stripslashes($_SESSION['DISPLAY_NAME']);
+	}
+
+	// Get the current users email address
+	function get_email() {
+		return $_SESSION['EMAIL'];
+	}
+
+	// Get the current users home folder
+	function get_home_folder() {
+		return $_SESSION['HOME_FOLDER'];
+	}
+
+	// Get the current users timezone
+	function get_timezone() {
+		if(!isset($_SESSION['USE_DEFAULT_TIMEZONE'])) {
+			return $_SESSION['TIMEZONE'];
+		} else {
+			return '-72000';
+		}
+	}
+
+	// Validate supplied email address
+	function validate_email($email) {
+		if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	
+}
+?>
Index: trunk/wb/framework/initialize.php
===================================================================
--- trunk/wb/framework/initialize.php	(nonexistent)
+++ trunk/wb/framework/initialize.php	(revision 5)
@@ -0,0 +1,82 @@
+<?php
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker 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.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+/*
+	Initializations common to frontend and backend
+*/
+
+// Setup database object
+require_once(WB_PATH.'/framework/class.database.php');
+if (!defined('DATABASE_CLASS_LOADED')) {
+  	define('DATABASE_CLASS_LOADED',true);
+}
+if(!isset($database)) {
+	$database = new database();
+}
+
+// Start a session
+if(!defined('SESSION_STARTED')) {
+	session_name(APP_NAME.'_session_id');
+	session_start();
+	define('SESSION_STARTED', true);
+}
+
+// Get users language
+if(isset($_GET['lang']) AND $_GET['lang'] != '' AND !is_numeric($_GET['lang']) AND strlen($_GET['lang']) == 2) {
+  	define('LANGUAGE', strtoupper($_GET['lang']));
+	$_SESSION['LANGUAGE']=LANGUAGE;
+} else {
+	if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
+		define('LANGUAGE', $_SESSION['LANGUAGE']);
+	} else {
+		define('LANGUAGE', DEFAULT_LANGUAGE);
+	}
+}
+
+// Get users timezone
+if(!defined('TIMEZONE')) {
+	if(isset($_SESSION['TIMEZONE'])) {
+		define('TIMEZONE', $_SESSION['TIMEZONE']);
+	} else {
+		define('TIMEZONE', DEFAULT_TIMEZONE);
+	}
+}
+// Get users date format
+if(!defined('DATE_FORMAT')) {
+	if(isset($_SESSION['DATE_FORMAT'])) {
+		define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
+	} else {
+		define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
+	}
+}
+
+// Load Language file
+if(!defined('LANGUAGE_LOADED')) {
+	if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
+		exit('Error loading language file '.LANGUAGE.', please check configuration');
+	} else {
+		require_once(WB_PATH.'/languages/'.LANGUAGE.'.php');
+	}
+}
+
+?>
Index: trunk/wb/framework/class.frontend.php
===================================================================
--- trunk/wb/framework/class.frontend.php	(nonexistent)
+++ trunk/wb/framework/class.frontend.php	(revision 5)
@@ -0,0 +1,451 @@
+<?php
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker 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.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+/*
+
+Frontend class
+
+*/
+
+
+
+require_once(WB_PATH.'/framework/class.wb.php');
+
+class frontend extends wb {
+	// defaults
+	var	$default_link,$default_page_id;
+
+	// page details
+	// page database row
+	var $page;
+	var $page_id,$page_title,$menu_title,$parent,$root_parent,$level,$visibility;
+	var $page_description,$page_keywords,$page_link_original,$page_link;
+	var $page_trail=array();
+	
+	var $page_access_denied;
+	
+	// website settings
+	var $website_title,$website_description,$website_keywords,$website_header,$website_footer;
+
+	// ugly database stuff
+	var $extra_sql,$extra_where_sql;
+
+	function frontend() {
+		$this->wb();
+	}
+	
+	function page_select() {
+		global $page_id,$no_intro;
+		global $database;
+		// We have no page id and are supposed to show the intro page
+		if((INTRO_PAGE AND !isset($no_intro)) AND (!isset($page_id) OR !is_numeric($page_id))) {
+			// Since we have no page id check if we should go to intro page or default page
+			// Get intro page content
+			$filename = WB_PATH.PAGES_DIRECTORY.'/intro.php';
+			if(file_exists($filename)) {
+				$handle = fopen($filename, "r");
+				$content = fread($handle, filesize($filename));
+				fclose($handle);
+				$this->preprocess($content);
+				echo stripslashes($content);
+				return false;
+			}
+		}
+		// Check if we should add page language sql code
+		if(PAGE_LANGUAGES) {
+			$this->sql_where_language = " AND language = '".LANGUAGE."'";
+		}
+		// Get default page
+		// Check for a page id
+		$query_default = "SELECT page_id,link FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND visibility = 'public'$this->sql_where_language ORDER BY position ASC LIMIT 1";
+		$get_default = $database->query($query_default);
+		$default_num_rows = $get_default->numRows();
+		if(!isset($page_id) OR !is_numeric($page_id)){
+			// Go to or show default page
+			if($default_num_rows > 0) {
+				$fetch_default = $get_default->fetchRow();
+				$this->default_link = $fetch_default['link'];
+				$default_page_id = $fetch_default['page_id'];
+				// Check if we should redirect or include page inline
+				if(HOMEPAGE_REDIRECTION) {
+					// Redirect to page
+					header("Location: ".page_link($this->default_link));
+					exit();
+				} else {
+					// Include page inline
+					$this->page_id = $default_page_id;
+				}
+			} else {
+		   		// No pages have been added, so print under construction page
+				$this->print_under_construction();
+				exit();
+			}
+		} else {
+			$this->page_id=$page_id;
+		}
+		// Get default page link
+		if(!isset($fetch_default)) {
+		  	$fetch_default = $get_default->fetchRow();
+	 		$this->default_link = $fetch_default['link'];
+		}
+		return true;
+	}
+
+	function get_page_details() {
+		global $database;
+	    if($this->page_id != 0) {
+			// Query page details
+			$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '{$this->page_id}'";
+			$get_page = $database->query($query_page);
+			// Make sure page was found in database
+			if($get_page->numRows() == 0) {
+				// Print page not found message
+				exit("Page not found");
+			}
+			// Fetch page details
+			$this->page = $get_page->fetchRow();
+			// Check if the page language is also the selected language. If not, send headers again.
+			if ($this->page['language']!=LANGUAGE) {
+				require_once(WB_PATH.'/framework/functions.php');
+				header('Location: '.page_link($this->page['link']).'?lang='.$this->page['language']);
+				exit();
+			}
+			// Begin code to set details as either variables of constants
+			// Page ID
+			define('PAGE_ID', $this->page['page_id']);
+			$this->page_id=$this->page['page_id'];
+			// Page Title
+			define('PAGE_TITLE', stripslashes($this->page['page_title']));
+			$this->page_title=PAGE_TITLE;
+			// Menu Title
+			$menu_title = stripslashes($this->page['menu_title']);
+			if($menu_title != '') {
+				define('MENU_TITLE', $menu_title);
+			} else {
+				define('MENU_TITLE', PAGE_TITLE);
+			}
+			$this->menu_title=MENU_TITLE;
+			// Page parent
+			define('PARENT', $this->page['parent']);
+			$this->parent=$this->page['parent'];
+			// Page root parent
+			define('ROOT_PARENT', $this->page['root_parent']);
+			$this->root_parent=$this->page['root_parent'];
+			// Page level
+			define('LEVEL', $this->page['level']);
+			$this->level=$this->page['level'];
+			// Page visibility
+			define('VISIBILITY', $this->page['visibility']);
+			$this->visibility=$this->page['visibility'];
+			// Page trail
+			foreach(explode(',', $this->page['page_trail']) AS $pid) {
+				$this->page_trail[$pid]=$pid;
+			}
+			// Page description
+			$this->page_description=$this->page['description'];
+			// Page keywords
+			$this->page_keywords=$this->page['keywords'];
+			// Page link
+			$this->link=$this->page_link($this->page['link']);
+
+		// End code to set details as either variables of constants
+		}
+
+		// Work-out if any possible in-line search boxes should be shown
+		if(SEARCH == 'public') {
+			define('SHOW_SEARCH', true);
+		} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
+			define('SHOW_SEARCH', true);
+		} elseif(SEARCH == 'private' AND $wb->is_authenticated() == true) {
+			define('SHOW_SEARCH', true);
+		} else {
+			define('SHOW_SEARCH', false);
+		}
+		// Work-out if menu should be shown
+		if(!defined('SHOW_MENU')) {
+			define('SHOW_MENU', true);
+		}
+		// Work-out if login menu constants should be set
+		if(FRONTEND_LOGIN) {
+			// Set login menu constants
+			define('LOGIN_URL', WB_URL.'/account/login'.PAGE_EXTENSION);
+			define('LOGOUT_URL', WB_URL.'/account/logout'.PAGE_EXTENSION);
+			define('FORGOT_URL', WB_URL.'/account/forgot'.PAGE_EXTENSION);
+			define('PREFERENCES_URL', WB_URL.'/account/preferences'.PAGE_EXTENSION);
+			define('SIGNUP_URL', WB_URL.'/account/signup'.PAGE_EXTENSION);
+		}
+
+		// Figure out what template to use
+		if(!defined('TEMPLATE')) {
+			if(isset($this->page['template']) AND $this->page['template'] != '') {
+				if(file_exists(WB_PATH.'/templates/'.$this->page['template'].'/index.php')) {
+					define('TEMPLATE', $this->page['template']);
+				} else {
+					define('TEMPLATE', DEFAULT_TEMPLATE);
+				}
+			} else {
+				define('TEMPLATE', DEFAULT_TEMPLATE);
+			}
+		}
+		// Set the template dir
+		define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
+
+		// Check if user is allow to view this page
+		if(FRONTEND_LOGIN AND VISIBILITY == 'private' OR FRONTEND_LOGIN AND VISIBILITY == 'registered') {
+			// Double-check front-end login is enabled
+			if(FRONTEND_LOGIN != true) {
+				// Users shouldnt be allowed to view private pages
+				header("Location: ".WB_URL.PAGES_DIRECTORY."/index".PAGE_EXTENSION);
+			}
+			// Check if the user is authenticated
+			if($this->is_authenticated() == false) {
+				// User needs to login first
+				header("Location: ".WB_URL."/account/login".PAGE_EXTENSION);
+			}
+			// Check if we should show this page
+			if($this->show_page($this->page) == false) {
+				$this->page_access_denied=true;
+			}
+			// Set extra private sql code
+			$this->extra_sql = ",viewing_groups,viewing_users";
+			$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
+		} elseif(!FRONTEND_LOGIN AND VISIBILITY == 'private' OR !FRONTEND_LOGIN AND VISIBILITY == 'registered') {
+			// User isnt allowed on this page so tell them
+			$this->page_access_denied=true;
+		} elseif(VISIBILITY == 'deleted') {
+			// User isnt allowed on this page so tell them
+			$this->page_access_denied=true;
+		}
+		if(!isset($this->extra_sql)) {
+			// Set extra private sql code
+			if(FRONTEND_LOGIN == 'enabled') {
+				if($this->is_authenticated()) {
+					$this->extra_sql = '';
+					$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
+				} else {
+					$this->extra_sql = '';
+					$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted' AND visibility != 'private'";
+				}
+			} else {
+				$this->extra_sql = '';
+				$this->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted' AND visibility != 'private' AND visibility != 'registered'";
+			}
+		}
+		$this->extra_where_sql .= $this->sql_where_language;
+	}
+
+	function get_website_settings() {
+		global $database;
+		// Get website settings (title, keywords, description, header, and footer)
+		$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings";
+		$get_settings = $database->query($query_settings);
+		while($setting = $get_settings->fetchRow()) {
+			switch($setting['name']) {
+				case 'title':
+					define('WEBSITE_TITLE', stripslashes($setting['value']));
+					$this->website_title=WEBSITE_TITLE;
+				break;
+				case 'description':
+					if($page_description != '') {
+						define('WEBSITE_DESCRIPTION', $page_description);
+					} else {
+						define('WEBSITE_DESCRIPTION', stripslashes($setting['value']));
+					}
+					$this->website_description=WEBSITE_DESCRIPTION;
+				break;
+				case 'keywords':
+					if($page_keywords != '') {
+						define('WEBSITE_KEYWORDS', stripslashes($setting['value']).' '.$page_keywords);
+					} else {
+						define('WEBSITE_KEYWORDS', stripslashes($setting['value']));
+					}
+					$this->website_keywords=WEBSITE_KEYWORDS;
+				break;
+				case 'header':
+					define('WEBSITE_HEADER', stripslashes($setting['value']));
+					$this->website_header=WEBSITE_HEADER;
+				break;
+				case 'footer':
+					define('WEBSITE_FOOTER', stripslashes($setting['value']));
+					$this->website_footer=WEBSITE_FOOTER;
+				break;
+			}
+		}
+	}
+	
+	function page_link($link){
+		// Check for :// in the link (used in URL's)
+		if(strstr($link, '://') == '') {
+			return WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
+		} else {
+			return $link;
+		}
+	}
+	
+	function preprocess(&$content) {
+		global $database;
+		// Replace [wblink--PAGE_ID--] with real link
+		$pattern = '/\[wblink(.+?)\]/s';
+		preg_match_all($pattern,$content,$ids);
+		foreach($ids[1] AS $page_id) {
+			$pattern = '/\[wblink'.$page_id.'\]/s';
+			// Get page link
+			$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
+			$fetch_link = $get_link->fetchRow();
+			$link = page_link($fetch_link['link']);
+			$content = preg_replace($pattern,$link,$content);
+		}
+	}
+	
+	function menu($menu_number = 1, $start_level=0, $recurse = -1, $collapse = true, $item_template = '<li><span[class]>[a][menu_title][/a]</span>', $item_footer = '</li>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $parent = 0) {
+	   global $database;
+	   if ($recurse==0)
+	       return;
+	   if ($start_level>0) {
+	       $key_array=array_keys($this->page_trail);
+	       $real_start=$key_array[$start_level-1];
+	       if (isset($real_start))
+	       {
+	          menu($menu_number, 0, $recurse,$collapse,$item_template, $item_footer, $menu_header, $menu_footer, $default_class, $current_class, $real_start);
+	      }
+	       return;
+	   }
+	   // Check if we should add menu number check to query
+	   if($parent == 0) {
+	       $menu_number = "menu = '$menu_number'";
+	   } else {
+	      $menu_number = '1';
+	   }
+	   // Query pages
+	   $query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility$this->extra_sql FROM ".
+	TABLE_PREFIX."pages WHERE parent = '$parent' AND $menu_number AND $this->extra_where_sql ORDER BY position ASC");
+	   // Check if there are any pages to show
+	   if($query_menu->numRows() > 0) {
+	      // Print menu header
+	      echo "\n".$menu_header;
+	      // Loop through pages
+	      while($page = $query_menu->fetchRow()) {
+	         // Check if this page should be shown
+	         // Create vars
+	         $vars = array('[class]','[a]', '[/a]', '[menu_title]', '[page_title]');
+	         // Work-out class
+	         if($page['page_id'] == PAGE_ID) {
+	            $class = $current_class;
+	         } else {
+	            $class = $default_class;
+	         }
+	         // Check if link is same as first page link, and if so change to WB URL
+	         if($page['link'] == $default_link AND !INTRO_PAGE) {
+	            $link = WB_URL;
+	         } else {
+	            $link = page_link($page['link']);
+	         }
+	         // Create values
+	         $values = array($class,'<a href="'.$link.'" target="'.$page['target'].'" '.$class.'>', '</a>', stripslashes($page['menu_title']), stripslashes($page['page_title']));
+	         // Replace vars with value and print
+	         echo "\n".str_replace($vars, $values, $item_template);
+	         // Generate sub-menu
+	         if($collapse==false OR ($collapse==true AND isset($this->page_trail[$page['page_id']]))) {
+	            $this->menu($menu_number, 0, $recurse-1, $collapse, $item_template, $item_footer, $menu_header, $menu_footer, $default_class, $current_class, $page['page_id']);
+	         }
+	         echo "\n".$item_footer;
+	      }
+	      // Print menu footer
+	      echo "\n".$menu_footer;
+	   }
+	}
+
+	function page_content($block = 1) {
+		// Get outside objects
+		global $database,$TEXT,$MENU,$HEADING,$MESSAGE;
+		global $globals;
+		if ($this->page_access_denied==true) {
+            echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
+			exit();
+		}
+		if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
+		// Make sure block is numeric
+		if(!is_numeric($block)) { $block = 1; }
+		// Include page content
+		if(!defined('PAGE_CONTENT')) {
+			// First get all sections for this page
+			$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '".PAGE_ID."' AND block = '$block' ORDER BY position");
+			if($query_sections->numRows() > 0) {
+				// Loop through them and include there modules file
+				while($section = $query_sections->fetchRow()) {
+					$section_id = $section['section_id'];
+					$module = $section['module'];
+					require(WB_PATH.'/modules/'.$module.'/view.php');
+				}
+			}
+		} else {
+			if($block == 1) {
+				require(PAGE_CONTENT);
+			}
+		}
+	}
+
+	// Function for page title
+	function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
+		$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
+		$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
+		echo str_replace($vars, $values, $template);
+	}
+
+	// Function for page description
+	function page_description() {
+		echo WEBSITE_DESCRIPTION;
+	}
+	// Function for page keywords
+	function page_keywords() {
+		echo WEBSITE_KEYWORDS;
+	}
+	// Function for page header
+	function page_header($date_format = 'Y') {
+		echo WEBSITE_HEADER;
+	}
+
+	// Function for page footer
+	function page_footer($date_format = 'Y') {
+		global $starttime;
+   		$vars = array('[YEAR]', '[PROCESSTIME]');
+   		$processtime=(microtime()>$starttime)?microtime()-$starttime:microtime()-$starttime+1;
+		$values = array(date($date_format),$processtime);
+		echo str_replace($vars, $values, WEBSITE_FOOTER);
+	}
+
+	// Function to show the "Under Construction" page
+	function print_under_construction() {
+		global $MESSAGE;
+		require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
+		echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+		<head><title>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION'].'</title>
+		<style type="text/css"><!-- body { font-family: Verdana, Arial, Helvetica, sans-serif;
+		font-size: 12px; color: #000000;	background-color: #FFFFFF;	margin: 20px; text-align: center; }
+		h1 { margin: 0; padding: 0; }--></style></head><body>
+		<h1>'.$MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION'];'.</h1><br />
+		'.$MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON'].'</body></html>';
+	}
+}
+
+?>
Index: trunk/wb/framework/functions.php
===================================================================
--- trunk/wb/framework/functions.php	(revision 4)
+++ trunk/wb/framework/functions.php	(revision 5)
@@ -32,9 +32,9 @@
 
 // Stop this file from being accessed directly
 if(!defined('WB_PATH')) { exit('Direct access to this file is not allowed'); }
-
+
 // Define that this file has been loaded
-define('FUNCTIONS_FILE_LOADED', true);
+define('FUNCTIONS_FILE_LOADED', true);
 
 // Function to remove a non-empty directory
 function rm_full_dir($directory)
@@ -145,81 +145,81 @@
 
 	// Now delete the folder
 	return $list;
-}
-
-// Function to get a list of home folders not to show
-function get_home_folders() {
-	global $database, $admin;
-	$home_folders = array();
-	// Only return home folders is this feature is enabled
-	if(HOME_FOLDERS) {
-		$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
-		if($query_home_folders->numRows() > 0) {
-			while($folder = $query_home_folders->fetchRow()) {
-				$home_folders[$folder['home_folder']] = $folder['home_folder'];
-			}
-		}
-		function remove_home_subs($directory = '/', $home_folders) {
+}
+
+// Function to get a list of home folders not to show
+function get_home_folders() {
+	global $database, $admin;
+	$home_folders = array();
+	// Only return home folders is this feature is enabled
+	if(HOME_FOLDERS) {
+		$query_home_folders = $database->query("SELECT home_folder FROM ".TABLE_PREFIX."users WHERE home_folder != '".$admin->get_home_folder()."'");
+		if($query_home_folders->numRows() > 0) {
+			while($folder = $query_home_folders->fetchRow()) {
+				$home_folders[$folder['home_folder']] = $folder['home_folder'];
+			}
+		}
+		function remove_home_subs($directory = '/', $home_folders) {
 			if($handle = opendir(WB_PATH.MEDIA_DIRECTORY.$directory)) {
-				// Loop through the dirs to check the home folders sub-dirs are not shown
+				// Loop through the dirs to check the home folders sub-dirs are not shown
 			   while(false !== ($file = readdir($handle))) {
 					if(substr($file, 0, 1) != '.' AND $file != 'CVS' AND $file != 'index.php') {
-						if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
-							if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
-							foreach($home_folders AS $hf) {
-								$hf_length = strlen($hf);
-								if($hf_length > 0) {
-									if(substr($file, 0, $hf_length+1) == $hf) {
-										$home_folders[$file] = $file;
-									}
-								}
-							}
-							$home_folders = remove_home_subs($file, $home_folders);
-						}
-					}
-				}
-			}
-			return $home_folders;
-		}
-		$home_folders = remove_home_subs('/', $home_folders);
-	}
-	return $home_folders;
-}
-
-// Function to create directories
-function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE) {
-	if(!file_exists($dir_name)) {
-		$umask = umask(0);
-		mkdir($dir_name, $dir_mode);
-		umask($umask);
-		return true;
-	} else {
-		return false;	
-	}
-}
-
-// Function to chmod files and directories
-function change_mode($name) {
-	if(OPERATING_SYSTEM != 'windows') {
-		// Only chmod if os is not windows
-		if(is_dir($name)) {
-			$mode = OCTAL_DIR_MODE;
-		} else {
-			$mode = OCTAL_FILE_MODE;
-		}
-		if(file_exists($name)) {
-			$umask = umask(0);
-			chmod($name, $mode);
-			umask($umask);
-			return true;
-		} else {
-			return false;	
-		}
-	} else {
-		return true;
-	}
+						if(is_dir(WB_PATH.MEDIA_DIRECTORY.$directory.'/'.$file)) {
+							if($directory != '/') { $file = $directory.'/'.$file; } else { $file = '/'.$file; }
+							foreach($home_folders AS $hf) {
+								$hf_length = strlen($hf);
+								if($hf_length > 0) {
+									if(substr($file, 0, $hf_length+1) == $hf) {
+										$home_folders[$file] = $file;
+									}
+								}
+							}
+							$home_folders = remove_home_subs($file, $home_folders);
+						}
+					}
+				}
+			}
+			return $home_folders;
+		}
+		$home_folders = remove_home_subs('/', $home_folders);
+	}
+	return $home_folders;
 }
 
+// Function to create directories
+function make_dir($dir_name, $dir_mode = OCTAL_DIR_MODE) {
+	if(!file_exists($dir_name)) {
+		$umask = umask(0);
+		mkdir($dir_name, $dir_mode);
+		umask($umask);
+		return true;
+	} else {
+		return false;	
+	}
+}
+
+// Function to chmod files and directories
+function change_mode($name) {
+	if(OPERATING_SYSTEM != 'windows') {
+		// Only chmod if os is not windows
+		if(is_dir($name)) {
+			$mode = OCTAL_DIR_MODE;
+		} else {
+			$mode = OCTAL_FILE_MODE;
+		}
+		if(file_exists($name)) {
+			$umask = umask(0);
+			chmod($name, $mode);
+			umask($umask);
+			return true;
+		} else {
+			return false;	
+		}
+	} else {
+		return true;
+	}
+}
+
 // Function to figure out if a parent exists
 function is_parent($page_id) {
 	global $database;
@@ -310,13 +310,13 @@
 		$ids = array_merge($ids, $parent_ids);
 	}
 	return $ids;
-}
-
-// Function to genereate page trail
-function get_page_trail($page_id) {
-	return implode(',', array_reverse(get_parent_ids($page_id)));
 }
 
+// Function to genereate page trail
+function get_page_trail($page_id) {
+	return implode(',', array_reverse(get_parent_ids($page_id)));
+}
+
 // Function to get all sub pages id's
 function get_subs($parent, $subs) {
 	// Connect to the database
@@ -333,74 +333,74 @@
 	// Return subs array
 	return $subs;
 }
-
+
 // Function to convert a page title to a page filename
-function page_filename($string) {
-	// First, translate any non-english characters to their english equivalents
-	require(WB_PATH.'/framework/convert.php');
-   $string = strtr($string, $conversion_array);
-	// Now replace spaces with page spcacer
-	$string = str_replace(' ', PAGE_SPACER, $string);
-	// Now remove all bad characters
-	$bad = array(
-	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
-	'{', /* { */	'}', /* } */	'[', /* [ */	']', /* ] */	'`', /* ` */
-	'!', /* ! */	'@', /* @ */	'#', /* # */	'$', /* $ */	'%', /* % */
-	'^', /* ^ */	'&', /* & */	'*', /* * */	'(', /* ( */	')', /* ) */
-	'=', /* = */	'+', /* + */	'|', /* | */	'/', /* / */	'\\', /* \ */
-	';', /* ; */	':', /* : */	',', /* , */	'?' /* ? */
-	);
-	$string = str_replace($bad, '', $string);
-	// Now convert to lower-case
-	$string = strtolower($string);
-	// Now remove multiple page spacers
-	$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
-	// Clean any page spacers at the end of string
-	$string = str_replace(PAGE_SPACER, ' ', $string);
-	$string = trim($string);
-	$string = str_replace(' ', PAGE_SPACER, $string);
-	// If there are any weird language characters, this will protect us against possible problems they could cause
-	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
+function page_filename($string) {
+	// First, translate any non-english characters to their english equivalents
+	require(WB_PATH.'/framework/convert.php');
+   $string = strtr($string, $conversion_array);
+	// Now replace spaces with page spcacer
+	$string = str_replace(' ', PAGE_SPACER, $string);
+	// Now remove all bad characters
+	$bad = array(
+	'\'', /* /  */ '"', /* " */	'<', /* < */	'>', /* > */
+	'{', /* { */	'}', /* } */	'[', /* [ */	']', /* ] */	'`', /* ` */
+	'!', /* ! */	'@', /* @ */	'#', /* # */	'$', /* $ */	'%', /* % */
+	'^', /* ^ */	'&', /* & */	'*', /* * */	'(', /* ( */	')', /* ) */
+	'=', /* = */	'+', /* + */	'|', /* | */	'/', /* / */	'\\', /* \ */
+	';', /* ; */	':', /* : */	',', /* , */	'?' /* ? */
+	);
+	$string = str_replace($bad, '', $string);
+	// Now convert to lower-case
+	$string = strtolower($string);
+	// Now remove multiple page spacers
+	$string = str_replace(PAGE_SPACER.PAGE_SPACER, PAGE_SPACER, $string);
+	// Clean any page spacers at the end of string
+	$string = str_replace(PAGE_SPACER, ' ', $string);
+	$string = trim($string);
+	$string = str_replace(' ', PAGE_SPACER, $string);
+	// If there are any weird language characters, this will protect us against possible problems they could cause
+	$string = str_replace(array('%2F', '%'), array('/', ''), urlencode($string));
 	// Finally, return the cleaned string
 	return $string;
-}
-
+}
+
 // Function to convert a desired media filename to a clean filename
-function media_filename($string) {
-	// First, translate any non-english characters to their english equivalents
-	require(WB_PATH.'/framework/convert.php');
+function media_filename($string) {
+	// First, translate any non-english characters to their english equivalents
+	require(WB_PATH.'/framework/convert.php');
    $string = strtr($string, $conversion_array);
-	// Now remove all bad characters
-	$bad = array(
-	'\'', // '
-	'"', // "
-	'`', // `
-	'!', // !
-	'@', // @
-	'#', // #
-	'$', // $
-	'%', // %
-	'^', // ^
-	'&', // &
-	'*', // *
-	'=', // =
-	'+', // +
-	'|', // |
-	'/', // /
-	'\\', // \
-	';', // ;
-	':', // :
-	',', // ,
-	'?' // ?
-	);
-	$string = str_replace($bad, '', $string);
-	// Clean any page spacers at the end of string
-	$string = trim($string);
+	// Now remove all bad characters
+	$bad = array(
+	'\'', // '
+	'"', // "
+	'`', // `
+	'!', // !
+	'@', // @
+	'#', // #
+	'$', // $
+	'%', // %
+	'^', // ^
+	'&', // &
+	'*', // *
+	'=', // =
+	'+', // +
+	'|', // |
+	'/', // /
+	'\\', // \
+	';', // ;
+	':', // :
+	',', // ,
+	'?' // ?
+	);
+	$string = str_replace($bad, '', $string);
+	// Clean any page spacers at the end of string
+	$string = trim($string);
 	// Finally, return the cleaned string
 	return $string;
-}
+}
 
-// Function to work out a page link
+// Function to work out a page link
 if(!function_exists('page_link')) {
 	function page_link($link) {
 		// Check for :// in the link (used in URL's)
@@ -409,11 +409,12 @@
 		} else {
 			return $link;
 		}
-	}
+	}
 }
 
 // Create a new file in the pages directory
 function create_access_file($filename,$page_id,$level) {
+	global $admin;
 	if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
 		$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
 	} else {
@@ -431,7 +432,7 @@
 		// The depth of the page directory in the directory hierarchy
 		// '/pages' is at depth 1
 		$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
-		// Work-out how many ../'s we need to get to the index page
+		// Work-out how many ../'s we need to get to the index page
 		$index_location = '';
 		for($i = 0; $i < $level + $pages_dir_depth; $i++) {
 			$index_location .= '../';
@@ -607,76 +608,76 @@
 	// And finally, return either true or false
 	return $$action;
 }
-
-// Function to delete a page
-function delete_page($page_id) {
-	
-	global $admin, $database;
-	
-	// Find out more about the page
-	$database = new database();
-	$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
-	$results = $database->query($query);
-	if($database->is_error()) {
-		$admin->print_error($database->get_error());
-	}
-	if($results->numRows() == 0) {
-		$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
-	}
-	$results_array = $results->fetchRow();
-	$parent = $results_array['parent'];
-	$level = $results_array['level'];
-	$link = $results_array['link'];
-	$page_title = stripslashes($results_array['page_title']);
-	$menu_title = stripslashes($results_array['menu_title']);
-	
-	// Get the sections that belong to the page
-	$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
-	if($query_sections->numRows() > 0) {
-		while($section = $query_sections->fetchRow()) {
-			// Set section id
-			$section_id = $section['section_id'];
-			// Include the modules delete file if it exists
-			if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
-				require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
-			}
-		}
-	}
-	
-	// Update the pages table
-	$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
-	$database->query($query);
-	if($database->is_error()) {
-		$admin->print_error($database->get_error());
-	}
-	
-	// Update the sections table
-	$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
-	$database->query($query);
-	if($database->is_error()) {
-		$admin->print_error($database->get_error());
-	}
-	
-	// Include the ordering class or clean-up ordering
-	require_once(WB_PATH.'/framework/class.order.php');
-	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
-	$order->clean($parent);
-	
-	// Unlink the page access file and directory
-	$directory = WB_PATH.PAGES_DIRECTORY.$link;
-	$filename = $directory.'.php';
-	$directory .= '/';
-	if(file_exists($filename)) {
-		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
-			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
-		} else {
-			unlink($filename);
-			if(file_exists($directory)) {
-				rm_full_dir($directory);
-			}
-		}
-	}
-	
-}
 
-?>
\ No newline at end of file
+// Function to delete a page
+function delete_page($page_id) {
+	
+	global $admin, $database;
+	
+	// Find out more about the page
+	$database = new database();
+	$query = "SELECT page_id,menu_title,page_title,level,link,parent,modified_by,modified_when FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
+	$results = $database->query($query);
+	if($database->is_error()) {
+		$admin->print_error($database->get_error());
+	}
+	if($results->numRows() == 0) {
+		$admin->print_error($MESSAGE['PAGES']['NOT_FOUND']);
+	}
+	$results_array = $results->fetchRow();
+	$parent = $results_array['parent'];
+	$level = $results_array['level'];
+	$link = $results_array['link'];
+	$page_title = stripslashes($results_array['page_title']);
+	$menu_title = stripslashes($results_array['menu_title']);
+	
+	// Get the sections that belong to the page
+	$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'");
+	if($query_sections->numRows() > 0) {
+		while($section = $query_sections->fetchRow()) {
+			// Set section id
+			$section_id = $section['section_id'];
+			// Include the modules delete file if it exists
+			if(file_exists(WB_PATH.'/modules/'.$section['module'].'/delete.php')) {
+				require(WB_PATH.'/modules/'.$section['module'].'/delete.php');
+			}
+		}
+	}
+	
+	// Update the pages table
+	$query = "DELETE FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
+	$database->query($query);
+	if($database->is_error()) {
+		$admin->print_error($database->get_error());
+	}
+	
+	// Update the sections table
+	$query = "DELETE FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id'";
+	$database->query($query);
+	if($database->is_error()) {
+		$admin->print_error($database->get_error());
+	}
+	
+	// Include the ordering class or clean-up ordering
+	require_once(WB_PATH.'/framework/class.order.php');
+	$order = new order(TABLE_PREFIX.'pages', 'position', 'page_id', 'parent');
+	$order->clean($parent);
+	
+	// Unlink the page access file and directory
+	$directory = WB_PATH.PAGES_DIRECTORY.$link;
+	$filename = $directory.'.php';
+	$directory .= '/';
+	if(file_exists($filename)) {
+		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
+			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
+		} else {
+			unlink($filename);
+			if(file_exists($directory)) {
+				rm_full_dir($directory);
+			}
+		}
+	}
+	
+}
+
+?>
Index: trunk/wb/index.php
===================================================================
--- trunk/wb/index.php	(revision 4)
+++ trunk/wb/index.php	(revision 5)
@@ -1,493 +1,59 @@
-<?php
-
-// $Id: index.php,v 1.20 2005/06/22 05:41:23 rdjurovich Exp $
-
-/*
-
- Website Baker Project <http://www.websitebaker.org/>
- Copyright (C) 2004-2005, Ryan Djurovich
-
- Website Baker is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- Website Baker 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.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Website Baker; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-*/
-
-// Include config file
-if(!defined('WB_URL')) {
-	require('config.php');
-}
-// Say that this file has been loaded
-if(!defined('FRONTEND_LOADED')) {
-	define('FRONTEND_LOADED', true);
-}
-// Check if the config file has been set-up
-if(!defined('WB_PATH')) {
-	// Work-out where to go to get to the installer
-	if(isset($no_intro) AND $no_intro == true) {
-		header("Location: ../install/index.php");
-	} else {
-		header("Location: install/index.php");
-	}
-}
-// Get language (if set)
-if(isset($_GET['lang']) AND $_GET['lang'] != '' AND !is_numeric($_GET['lang']) AND strlen($_GET['lang']) == 2) {
-	define('LANGUAGE', strtoupper($_GET['lang']));
-	define('GET_LANGUAGE', true);
-}
-// Function to work out a page link
-function page_link($link) {
-	// Check for :// in the link (used in URL's)
-	if(strstr($link, '://') == '') {
-		return WB_URL.PAGES_DIRECTORY.$link.PAGE_EXTENSION;
-	} else {
-		return $link;
-	}
-}
-// Work-out if we should include the database class file or admin class file
-if(FRONTEND_LOGIN) {
-	// Include admin class file
-	require_once(WB_PATH.'/framework/class.admin.php');
-	// Create new admin object
-	if(!isset($admin)) {
-		$admin = new admin('Start', 'start', false, false);
-	}
-} else {
-	// Include database class file
-	require_once(WB_PATH.'/framework/class.database.php');
-	// Create new database object
-	if(!isset($admin)) {
-		$database = new database();
-	}
-}
-/*
-Begin user-changeable settings
-*/
-// Get users language
-if(!defined('LANGUAGE')) {
-	if(isset($_SESSION['LANGUAGE']) AND $_SESSION['LANGUAGE'] != '') {
-		define('LANGUAGE', $_SESSION['LANGUAGE']);
-		define('USER_LANGUAGE', true);
-	} else {
-		define('LANGUAGE', DEFAULT_LANGUAGE);
-	}
-}
-// Get users timezone
-if(!defined('TIMEZONE')) {
-	if(isset($_SESSION['TIMEZONE'])) {
-		define('TIMEZONE', $_SESSION['TIMEZONE']);
-	} else {
-		define('TIMEZONE', DEFAULT_TIMEZONE);
-	}
-}
-// Get users date format
-if(!defined('DATE_FORMAT')) {
-	if(isset($_SESSION['DATE_FORMAT'])) {
-		define('DATE_FORMAT', $_SESSION['DATE_FORMAT']);
-	} else {
-		define('DATE_FORMAT', DEFAULT_DATE_FORMAT);
-	}
-}
-// Get users time format
-if(!defined('TIME_FORMAT')) {
-	if(isset($_SESSION['TIME_FORMAT'])) {
-		define('TIME_FORMAT', $_SESSION['TIME_FORMAT']);
-	} else {
-		define('TIME_FORMAT', DEFAULT_TIME_FORMAT);
-	}
-}
-// Load the language file
-if(!defined('LANGUAGE_LOADED')) {
-	if(!file_exists(WB_PATH.'/languages/'.LANGUAGE.'.php')) {
-		exit('Error loading language file '.LANGUAGE.', please check configuration');
-	} else {
-		require(WB_PATH.'/languages/'.LANGUAGE.'.php');
-	}
-}
-/*
-End user-changeable settings
-*/
-/*
-Begin page-select code
-*/
-// Get default page
-$query_default = "SELECT page_id,link FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND visibility = 'public' ORDER BY position ASC LIMIT 1";
-$get_default = $database->query($query_default);
-$default_num_rows = $get_default->numRows();
-// Check for a page id
-if(!isset($page_id) OR !is_numeric($page_id)) {
-	// Since we have no page id check if we should go to intro page or default page
-	if(INTRO_PAGE AND !isset($no_intro)) {
-		// Get intro page content
-		$filename = WB_PATH.PAGES_DIRECTORY.'/intro.php';
-		if(file_exists($filename)) {
-			$handle = fopen($filename, "r");
-			$content = fread($handle, filesize($filename));
-			fclose($handle);
-			// Replace [wblink--PAGE_ID--] with real link
-			$pattern = '/\[wblink(.+?)\]/s';
-			preg_match_all($pattern,$content,$ids);
-			foreach($ids[1] AS $page_id) {
-				$pattern = '/\[wblink'.$page_id.'\]/s';
-				// Get page link
-				$get_link = $database->query("SELECT link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id' LIMIT 1");
-				$fetch_link = $get_link->fetchRow();
-				$link = page_link($fetch_link['link']);
-				$content = preg_replace($pattern,$link,$content);
-			}
-			echo stripslashes($content);
-			exit();
-		} else {
-			header("Location: ".WB_URL.PAGES_DIRECTORY."/index".PAGE_EXTENSION);
-			exit();
-		}
-	} else {
-		// Go to or show default page
-		if($default_num_rows > 0) {
-			$fetch_default = $get_default->fetchRow();
-			$default_link = $fetch_default['link'];
-			$default_page_id = $fetch_default['page_id'];
-			// Check if we should redirect or include page inline
-			if(HOMEPAGE_REDIRECTION) {
-				// Redirect to page
-				header("Location: ".page_link($default_link));
-				exit();
-			} else {
-				// Include page inline
-				$page_id = $default_page_id;
-			}
-		} else {
-			// No pages have been added, so print under construction page
-			require_once(WB_PATH.'/languages/'.DEFAULT_LANGUAGE.'.php');
-			?>
-			<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-			<head><title><?php echo $MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION']; ?></title>
-			<style type="text/css"><!-- body { font-family: Verdana, Arial, Helvetica, sans-serif;
-			font-size: 12px; color: #000000;	background-color: #FFFFFF;	margin: 20px; text-align: center; }
-			h1 { margin: 0; padding: 0; }--></style></head><body>
-			<h1><?php echo $MESSAGE['GENERIC']['WEBSITE_UNDER_CONTRUCTION']; ?></h1><br />
-			<?php echo $MESSAGE['GENERIC']['PLEASE_CHECK_BACK_SOON']; ?></body></html>
-			<?php
-			exit();
-		}
-	}
-}
-// Get default page link
-if(!isset($fetch_default)) { $fetch_default = $get_default->fetchRow(); $default_link = $fetch_default['link']; }
-/*
-End page-select code
-*/
-/*
-Begin page details code
-*/
-// Get page details
-if($page_id != 0) {
-	// Query page details
-	$query_page = "SELECT * FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
-	$get_page = $database->query($query_page);
-	// Make sure page was found in database
-	if($get_page->numRows() == 0) {
-		// Print page not found message
-		exit("Page not found");
-	}
-	// Fetch page details
-	$page = $get_page->fetchRow();
-	// Begin code to set details as either variables of constants
-		// Page ID
-		define('PAGE_ID', $page['page_id']);
-		// Page Title
-		define('PAGE_TITLE', stripslashes($page['page_title']));
-		// Menu Title
-		$menu_title = stripslashes($page['menu_title']);
-		if($menu_title != '') {
-			define('MENU_TITLE', $menu_title);
-		} else {
-			define('MENU_TITLE', PAGE_TITLE);
-		}
-		// Page parent
-		define('PARENT', $page['parent']);
-		// Page root parent
-		define('ROOT_PARENT', $page['root_parent']);
-		// Page level
-		define('LEVEL', $page['level']);
-		// Page visibility
-		define('VISIBILITY', $page['visibility']);
-		// Page trail
-		$page_trail = array();
-		foreach(explode(',', $page['page_trail']) AS $pid) {
-			$page_trail[$pid] = $pid;
-		}
-		// Page description
-		$page_description = $page['description'];
-		// Page keywords
-		$page_keywords = $page['keywords'];
-		// Page link
-		$page_link_original = $page['link'];
-		$page_link = page_link($page_link_original);
-	// End code to set details as either variables of constants
-}
-// Work-out if any possible in-line search boxes should be shown
-if(SEARCH == 'public') {
-	define('SHOW_SEARCH', true);
-} elseif(SEARCH == 'private' AND VISIBILITY == 'private') {
-	define('SHOW_SEARCH', true);
-} elseif(SEARCH == 'private' AND isset($admin) AND $admin->is_authenticated() == true) {
-	define('SHOW_SEARCH', true);
-} else {
-	define('SHOW_SEARCH', false);
-}
-// Work-out if menu should be shown
-if(!defined('SHOW_MENU')) {
-	define('SHOW_MENU', true);
-}
-// Work-out if login menu constants should be set
-if(FRONTEND_LOGIN) {
-	// Set login menu constants
-	define('LOGIN_URL', WB_URL.'/account/login'.PAGE_EXTENSION);
-	define('LOGOUT_URL', WB_URL.'/account/logout'.PAGE_EXTENSION);
-	define('FORGOT_URL', WB_URL.'/account/forgot'.PAGE_EXTENSION);
-	define('PREFERENCES_URL', WB_URL.'/account/preferences'.PAGE_EXTENSION);
-	define('SIGNUP_URL', WB_URL.'/account/signup'.PAGE_EXTENSION);
-}
-// Check user is allow to view this page
-if(FRONTEND_LOGIN AND VISIBILITY == 'private' OR FRONTEND_LOGIN AND VISIBILITY == 'registered') {
-	// Double-check front-end login is enabled
-	if(FRONTEND_LOGIN != true) {
-		// Users shouldnt be allowed to view private pages
-		header("Location: ".WB_URL.PAGES_DIRECTORY."/index".PAGE_EXTENSION);
-	}
-	// Check if the user is authenticated
-	if($admin->is_authenticated() == false) {
-		// User needs to login first
-		header("Location: ".WB_URL."/account/login".PAGE_EXTENSION);
-	}
-	// Check if we should show this page
-	if($admin->show_page($page, $admin) == false) {
-		// User isnt allowed on this page so tell them
-		function page_content($block = 1) {
-			global $MESSAGE;
-			echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
-		}
-	}
-	// Set extra private sql code
-	$extra_sql = ",viewing_groups,viewing_users";
-	$extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
-} elseif(!FRONTEND_LOGIN AND VISIBILITY == 'private' OR !FRONTEND_LOGIN AND VISIBILITY == 'registered') {
-	// User isnt allowed on this page so tell them
-	function page_content($block = 1) {
-		global $MESSAGE;
-		echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
-	}
-} elseif(VISIBILITY == 'deleted') {
-	// User isnt allowed on this page so tell them
-	function page_content($block = 1) {
-		global $MESSAGE;
-		echo $MESSAGE['FRONTEND']['SORRY_NO_VIEWING_PERMISSIONS'];
-	}
-}
-if(!isset($extra_sql)) {
-	// Set extra private sql code
-	if(FRONTEND_LOGIN == 'enabled') {
-		if($admin->is_authenticated()) {
-			$extra_sql = '';
-			$extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
-		} else {
-			$extra_sql = '';
-			$extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted' AND visibility != 'private'";
-		}
-	} else {
-		$extra_sql = '';
-		$extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted' AND visibility != 'private' AND visibility != 'registered'";
-	}
-}
-// Check if we should add page language sql code
-if(PAGE_LANGUAGES) {
-	if(defined('GET_LANGUAGE')) {
-		$extra_where_sql .= " AND language = '".LANGUAGE."'";
-	} elseif(defined('USER_LANGUAGE')) {
-		$extra_where_sql .= " AND language = '".DEFAULT_LANGUAGE."'";
-	} else {
-		$extra_where_sql .= " AND language = '".DEFAULT_LANGUAGE."'";
-	}
-}
-// Get website settings (title, keywords, description, header, and footer)
-$query_settings = "SELECT name,value FROM ".TABLE_PREFIX."settings";
-$get_settings = $database->query($query_settings);
-while($setting = $get_settings->fetchRow()) {
-	switch($setting['name']) {
-		case 'title':
-			define('WEBSITE_TITLE', stripslashes($setting['value']));
-		break;
-		case 'description':
-			if($page_description != '') {
-				define('WEBSITE_DESCRIPTION', $page_description);
-			} else {
-				define('WEBSITE_DESCRIPTION', stripslashes($setting['value']));
-			}
-		break;
-		case 'keywords':
-			if($page_keywords != '') {
-				define('WEBSITE_KEYWORDS', stripslashes($setting['value']).' '.$page_keywords);
-			} else {
-				define('WEBSITE_KEYWORDS', stripslashes($setting['value']));
-			}
-		break;
-		case 'header':
-			define('WEBSITE_HEADER', stripslashes($setting['value']));
-		break;
-		case 'footer':
-			define('WEBSITE_FOOTER', stripslashes($setting['value']));
-		break;
-	}
-}
-// Figure out what template to use
-if(!defined('TEMPLATE')) {
-	if(isset($page['template']) AND $page['template'] != '') {
-		if(file_exists(WB_PATH.'/templates/'.$page['template'].'/index.php')) {
-			define('TEMPLATE', $page['template']);
-		} else {
-			define('TEMPLATE', DEFAULT_TEMPLATE);
-		}
-	} else {
-		define('TEMPLATE', DEFAULT_TEMPLATE);
-	}
-}
-// Set the template dir
-define('TEMPLATE_DIR', WB_URL.'/templates/'.TEMPLATE);
-/*
-End page details code
-*/
-/*
-Begin Template functions
-*/
-// Function for page title
-function page_title($spacer = ' - ', $template = '[WEBSITE_TITLE][SPACER][PAGE_TITLE]') {
-	$vars = array('[WEBSITE_TITLE]', '[PAGE_TITLE]', '[MENU_TITLE]', '[SPACER]');
-	$values = array(WEBSITE_TITLE, PAGE_TITLE, MENU_TITLE, $spacer);
-	echo str_replace($vars, $values, $template);
-}
-// Function for page description
-function page_description() {
-	echo WEBSITE_DESCRIPTION;
-}
-// Function for page keywords
-function page_keywords() {
-	echo WEBSITE_KEYWORDS;
-}
-// Function for page header
-function page_header($date_format = 'Y') {
-	echo WEBSITE_HEADER;
-}
-// Function for page footer
-function page_footer($date_format = 'Y') {
-	echo str_replace('[YEAR]', date($date_format), WEBSITE_FOOTER);
-}
-// Function to generate menu
-function page_menu($parent = 0, $menu_number = 1, $item_template = '<li[class]>[a][menu_title][/a]</li>', $menu_header = '<ul>', $menu_footer = '</ul>', $default_class = ' class="menu_default"', $current_class = ' class="menu_current"', $recurse = LEVEL) {
-	global $database, $admin, $page_id, $page_trail, $default_link, $extra_sql, $extra_where_sql;
-	// Check if we should add menu number check to query
-	if($parent == 0) {
-		 $menu_number = "menu = '$menu_number'";
-	} else {
-		$menu_number = '1';
-	}
-	// Query pages
-	$query_menu = $database->query("SELECT page_id,menu_title,page_title,link,target,level,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '$parent' AND $menu_number AND $extra_where_sql ORDER BY position ASC");
-	// Check if there are any pages to show
-	if($query_menu->numRows() > 0) {
-		// Print menu header
-		echo $menu_header;
-		// Loop through pages
-		while($page = $query_menu->fetchRow()) {
-			// Create vars
-			$vars = array('[class]', '[a]', '[/a]', '[menu_title]', '[page_title]');
-			// Work-out class
-			if($page['page_id'] == PAGE_ID) {
-				$class = $current_class;
-			} else {
-				$class = $default_class;
-			}
-			// Check if link is same as first page link, and if so change to WB URL
-			if($page['link'] == $default_link AND !INTRO_PAGE) {
-				$link = WB_URL;
-			} else {
-				$link = page_link($page['link']);
-			}
-			// Create values
-			$values = array($class, '<a href="'.$link.'" target="'.$page['target'].'">', '</a>', stripslashes($page['menu_title']), stripslashes($page['page_title']));
-			// Replace vars with value and print
-			echo str_replace($vars, $values, $item_template);
-			// Generate sub-menu
-			if(isset($page_trail[$page['page_id']])) {
-				page_menu($page['page_id'], $menu_number, $item_template, $menu_header, $menu_footer, $default_class, $current_class, $recurse-1);
-			}
-		}
-		// Print menu footer
-		echo $menu_footer;
-	}
-}
-// Function for page content
-$globals[] = 'database';
-$globals[] = 'admin';
-$globals[] = 'TEXT';
-$globals[] = 'MENU';
-$globals[] = 'HEADING';
-$globals[] = 'MESSAGE';
-if(!function_exists('page_content')) {
-	function page_content($block = 1) {
-		// Get outside objects
-		global $globals;
-		if(isset($globals) AND is_array($globals)) { foreach($globals AS $global_name) { global $$global_name; } }
-		// Make sure block is numeric
-		if(!is_numeric($block)) { $block = 1; }
-		// Include page content
-		if(!defined('PAGE_CONTENT')) {
-			// First get all sections for this page
-			$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE page_id = '".PAGE_ID."' AND block = '$block' ORDER BY position");
-			if($query_sections->numRows() > 0) {
-				// Loop through them and include there modules file
-				while($section = $query_sections->fetchRow()) {
-					$section_id = $section['section_id'];
-					$module = $section['module'];
-					require(WB_PATH.'/modules/'.$module.'/view.php');
-				}
-			}
-		} else {
-			if($block == 1) {
-				require(PAGE_CONTENT);
-			}
-		}
-	}
-}
-/*
-End Template functions
-*/
-// Begin WB < 2.4.x template compatibility code
-	// Make extra_sql accessable through private_sql
-	$private_sql = $extra_sql;
-	$private_where_sql = $extra_where_sql;
-	// Query pages for menu
-	$menu1 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '0' AND $extra_where_sql ORDER BY position ASC");
-	// Check if current pages is a parent page and if we need its submenu
-	if(PARENT == 0) {
-		// Get the pages submenu
-		$menu2 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '".PAGE_ID."' AND $extra_where_sql ORDER BY position ASC");
-	} else {
-		// Get the pages submenu
-		$menu2 = $database->query("SELECT page_id,menu_title,page_title,link,target,visibility$extra_sql FROM ".TABLE_PREFIX."pages WHERE parent = '".PARENT."' AND $extra_where_sql ORDER BY position ASC");
-	}
-// End WB < 2.4.x template compatibility code
-// Include template file
-require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');
-
-?>
\ No newline at end of file
+<?php
+
+/*
+
+ Website Baker Project <http://www.websitebaker.org/>
+ Copyright (C) 2004-2005, Ryan Djurovich
+
+ Website Baker is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Website Baker 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.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Website Baker; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+*/
+
+$starttime=microtime();
+
+// Include config file
+require_once('config.php');
+
+// Check if the config file has been set-up
+if(!defined('WB_PATH')) {
+	header("Location: install/index.php");
+}
+
+require_once(WB_PATH.'/framework/class.frontend.php');
+// Create new frontend object
+$wb = new frontend();
+
+// Perform general initializations:
+// session start, language files loading, basic settings.
+require_once(WB_PATH.'/framework/initialize.php');
+
+// Figure out which page to display
+// Stop processing if intro page was shown
+$wb->page_select() or die();
+
+// Collect info about the currently viewed page
+// and check permissions
+$wb->get_page_details();
+
+// Collect general website settings
+$wb->get_website_settings();
+
+// Load some ugly compatibility code
+require(WB_PATH.'/framework/compatibility.php');
+
+// Display the template
+require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');
+
+?>
