From d3d031d9eec485a05afdcc367ca8a8cca24e98e5 Mon Sep 17 00:00:00 2001
From: Bart van Bragt <bartvb@users.sourceforge.net>
Date: Fri, 9 Mar 2001 23:33:06 +0000
Subject: Moved include files

git-svn-id: file:///svn/phpbb/trunk@94 89ea8834-ac86-4346-8a33-228a782c2dd0
---
 phpBB/common.php               |  11 +-
 phpBB/config.php               |  70 +-------
 phpBB/db.php                   |  51 ------
 phpBB/functions/error.php      |   4 +-
 phpBB/includes/constants.php   |  91 +++++++++++
 phpBB/includes/db.php          |  51 ++++++
 phpBB/includes/page_header.php | 134 ++++++++++++++++
 phpBB/includes/page_tail.php   |  63 ++++++++
 phpBB/includes/template.inc    | 351 +++++++++++++++++++++++++++++++++++++++++
 phpBB/index.php                |   9 +-
 phpBB/page_header.php          | 134 ----------------
 phpBB/page_tail.php            |  63 --------
 phpBB/posting.php              | 238 ++++++++++++++--------------
 phpBB/template.inc             | 351 -----------------------------------------
 phpBB/viewforum.php            |  10 +-
 phpBB/viewtopic.php            |  11 +-
 16 files changed, 837 insertions(+), 805 deletions(-)
 delete mode 100644 phpBB/db.php
 create mode 100644 phpBB/includes/constants.php
 create mode 100644 phpBB/includes/db.php
 create mode 100644 phpBB/includes/page_header.php
 create mode 100644 phpBB/includes/page_tail.php
 create mode 100644 phpBB/includes/template.inc
 delete mode 100644 phpBB/page_header.php
 delete mode 100644 phpBB/page_tail.php
 delete mode 100644 phpBB/template.inc

(limited to 'phpBB')

diff --git a/phpBB/common.php b/phpBB/common.php
index 62bc288885..c79b681fba 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -23,25 +23,24 @@
  ***************************************************************************/ 
 
 include('config.'.$phpEx);
+include('includes/constants.'.$phpEx);
 
 // Find Users real IP (if possible)
 $ip = ($HTTP_X_FORWARDED_FOR) ? $HTTP_X_FORWARDED_FOR : $REMOTE_ADDR;
 define("USER_IP",$ip);
 unset($ip);
 
-include('template.inc');
 // Setup what template to use. Currently just use default
+include('includes/template.inc');
 $template = new Template("./templates/Default", "remove");
 
 include('functions/error.'.$phpEx);
 include('functions/sessions.'.$phpEx);
 include('functions/auth.'.$phpEx);
 include('functions/functions.'.$phpEx);
-include('db.'.$phpEx);
+include('includes/db.'.$phpEx);
 
-// Initalize these variables to keep them safe.
-$user_logged_in = 0;
-$logged_in = 0;
+// Initalize to keep safe
 $userdata = Array();
 
 // Setup forum wide options.
@@ -68,7 +67,9 @@ else
 	$default_lang = $config[0]["default_lang"];
 	$sys_lang = $default_lang;            
 }
+
 include('language/lang_'.$default_lang.'.'.$phpEx);
+
 // Check if user is banned
 if(!auth("ip ban", $db, "", USER_IP))
 {
diff --git a/phpBB/config.php b/phpBB/config.php
index 6b04d9c636..ea871eb736 100644
--- a/phpBB/config.php
+++ b/phpBB/config.php
@@ -22,53 +22,6 @@
  * 
  ***************************************************************************/ 
 
-// Constants
-// Debug Level
-define(DEBUG, 1); // Debugging on
-//define(DEBUG, 0); // Debugging off
-
-// User Levels
-define(ADMIN, 4);
-define(SUPERMOD, 3);
-define(MODERATOR, 2);
-define(USER, 1);
-define(DELETED, -1);
-define(ANONYMOUS, -1);
-
-// Forum access levels
-define(PUBLIC, 1);
-define(PRIVATE, 2);
-
-// Forum posting levels
-define(ANONALLOWED, 2);
-define(REGONLY, 1);
-define(MODONLY, 3);
-
-// Topic state
-define(UNLOCKED, 0);
-define(LOCKED, 1);
-
-// Ban time types
-define(SECONDS, 1);
-define(MINUTES, 2);
-define(HOURS, 3);
-define(DAYS, 4);
-define(YEARS, 5);
-
-// Error codes
-define(SQL_CONNECT, 1);
-define(BANNED, 2);
-define(QUERY_ERROR, 3);
-define(SESSION_CREATE, 4);
-define(NO_TOPICS, 5);
-define(GENERAL_ERROR, 6);
-define(LOGIN_FAILED, 7);
-
-// URL PARAMETERS
-define(POST_TOPIC_URL, 't');
-define(POST_FORUM_URL, 'f');
-define(POST_USERS_URL, 'u');
-
 // Session data
 $session_cookie = "phpBBsession";
 $session_cookie_time = 3600; 
@@ -81,28 +34,11 @@ $dbuser = "";
 $dbpasswd = "";
 
 // Date format (needs to go into DB)
-$date_format = "M d Y h:i:s a";
+$date_format = "M d Y h:i:s a"; // American datesformat
+//$date_format = "d-m-Y H:i:s"; // European datesformat
 
-// DB table config
+// DB table prefix
 $table_prefix = "phpbb_";
-define('BANLIST_TABLE', $table_prefix.'banlist');
-define('CATEGORIES_TABLE', $table_prefix.'categories');
-define('CONFIG_TABLE', $table_prefix.'config');
-define('DISALLOW_TABLE', $table_prefix.'disallow');
-define('FORUM_ACCESS_TABLE', $table_prefix.'forum_access');
-define('FORUM_MODS_TABLE', $table_prefix.'forum_mods');
-define('FORUMS_TABLE', $table_prefix.'forums');
-define('HEADERMETAFOOTER_TABLE', $table_prefix.'headermetafooter');
-define('POSTS_TABLE', $table_prefix.'posts');
-define('POSTS_TEXT_TABLE', $table_prefix.'posts_text');
-define('PRIV_MSGS_TABLE', $table_prefix.'priv_msgs');
-define('RANKS_TABLE', $table_prefix.'ranks');
-define('SESSIONS_TABLE', $table_prefix.'sessions');
-define('THEMES_TABLE', $table_prefix.'themes');
-define('TOPICS_TABLE', $table_prefix.'topics');
-define('USERS_TABLE', $table_prefix.'users');
-define('WHOSONLINE_TABLE', $table_prefix.'whosonline');
-define('WORDS_TABLE', $table_prefix.'words');
 
 $url_images = "images";
 $image_quote = "$url_images/quote.gif";
diff --git a/phpBB/db.php b/phpBB/db.php
deleted file mode 100644
index 874f4a8ac4..0000000000
--- a/phpBB/db.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-/***************************************************************************  
- *                                 db.php
- *                            -------------------                         
- *   begin                : Saturday, Feb 13, 2001 
- *   copyright            : (C) 2001 The phpBB Group        
- *   email                : support@phpbb.com                           
- *                                                          
- *   $Id$                                                           
- *                                                            
- * 
- ***************************************************************************/ 
-
-/***************************************************************************  
- *                                                     
- *   This program 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.                      
- *                                                          
- * 
- ***************************************************************************/ 
-
-switch($dbms)
-{
-	case 'mysql':
-		include('db/mysql.'.$phpEx);
-		break;
-	case 'postgres':
-		include('db/postgres7.'.$phpEx);
-		break;
-	case 'mssql':
-		include('db/mssql.'.$phpEx);
-		break;
-	case 'odbc':
-		include('db/odbc.'.$phpEx);
-		break;
-	case 'oracle':
-		include('db/oracle.'.$phpEx);
-		break;
-}
-
-// Make the database connection.
-$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
-if(!$db) 
-{
-   $db_error = $db->sql_error();
-   error_die($db, SQL_CONNECT, $db_error["message"]);
-}
-
-?>
diff --git a/phpBB/functions/error.php b/phpBB/functions/error.php
index 5bb0b73000..14f9e14073 100644
--- a/phpBB/functions/error.php
+++ b/phpBB/functions/error.php
@@ -36,7 +36,7 @@ function error_die($db, $error_code = "", $error_msg = "")
 	  {
 	     include('language/lang_english.'.$phpEx);
 	  }
-	include('page_header.'.$phpEx);
+	include('includes/page_header.'.$phpEx);
      }
    if(!$error_msg)
    {
@@ -77,7 +77,7 @@ function error_die($db, $error_code = "", $error_msg = "")
    $template->set_file(array("error_body" => "error_body.tpl"));
    $template->set_var(array("ERROR_MESSAGE" => $error_msg));
    $template->pparse("output", "error_body");
-   include('page_tail.'.$phpEx);
+   include('includes/page_tail.'.$phpEx);
    exit();
 }
    
diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php
new file mode 100644
index 0000000000..c4cddbf6c2
--- /dev/null
+++ b/phpBB/includes/constants.php
@@ -0,0 +1,91 @@
+<?php
+/***************************************************************************  
+ *                               includes.php  
+ *                            -------------------                         
+ *   begin                : Saturday, Feb 13, 2001 
+ *   copyright            : (C) 2001 The phpBB Group        
+ *   email                : support@phpbb.com                           
+ *                                                          
+ *   $Id$                                                           
+ *                                                            
+ * 
+ ***************************************************************************/ 
+
+
+/***************************************************************************  
+ *                                                     
+ *   This program 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.                      
+ *                                                          
+ * 
+ ***************************************************************************/ 
+
+// Constants
+// Debug Level
+define(DEBUG, 1); // Debugging on
+//define(DEBUG, 0); // Debugging off
+
+// User Levels
+define(ADMIN, 4);
+define(SUPERMOD, 3);
+define(MODERATOR, 2);
+define(USER, 1);
+define(DELETED, -1);
+define(ANONYMOUS, -1);
+
+// Forum access levels
+define(PUBLIC, 1);
+define(PRIVATE, 2);
+
+// Forum posting levels
+define(ANONALLOWED, 2);
+define(REGONLY, 1);
+define(MODONLY, 3);
+
+// Topic state
+define(UNLOCKED, 0);
+define(LOCKED, 1);
+
+// Ban time types
+define(SECONDS, 1);
+define(MINUTES, 2);
+define(HOURS, 3);
+define(DAYS, 4);
+define(YEARS, 5);
+
+// Error codes
+define(SQL_CONNECT, 1);
+define(BANNED, 2);
+define(QUERY_ERROR, 3);
+define(SESSION_CREATE, 4);
+define(NO_TOPICS, 5);
+define(GENERAL_ERROR, 6);
+define(LOGIN_FAILED, 7);
+
+// URL PARAMETERS
+define(POST_TOPIC_URL, 't');
+define(POST_FORUM_URL, 'f');
+define(POST_USERS_URL, 'u');
+
+define('BANLIST_TABLE', $table_prefix.'banlist');
+define('CATEGORIES_TABLE', $table_prefix.'categories');
+define('CONFIG_TABLE', $table_prefix.'config');
+define('DISALLOW_TABLE', $table_prefix.'disallow');
+define('FORUM_ACCESS_TABLE', $table_prefix.'forum_access');
+define('FORUM_MODS_TABLE', $table_prefix.'forum_mods');
+define('FORUMS_TABLE', $table_prefix.'forums');
+define('HEADERMETAFOOTER_TABLE', $table_prefix.'headermetafooter');
+define('POSTS_TABLE', $table_prefix.'posts');
+define('POSTS_TEXT_TABLE', $table_prefix.'posts_text');
+define('PRIV_MSGS_TABLE', $table_prefix.'priv_msgs');
+define('RANKS_TABLE', $table_prefix.'ranks');
+define('SESSIONS_TABLE', $table_prefix.'sessions');
+define('THEMES_TABLE', $table_prefix.'themes');
+define('TOPICS_TABLE', $table_prefix.'topics');
+define('USERS_TABLE', $table_prefix.'users');
+define('WHOSONLINE_TABLE', $table_prefix.'whosonline');
+define('WORDS_TABLE', $table_prefix.'words');
+
+?>
diff --git a/phpBB/includes/db.php b/phpBB/includes/db.php
new file mode 100644
index 0000000000..874f4a8ac4
--- /dev/null
+++ b/phpBB/includes/db.php
@@ -0,0 +1,51 @@
+<?php
+/***************************************************************************  
+ *                                 db.php
+ *                            -------------------                         
+ *   begin                : Saturday, Feb 13, 2001 
+ *   copyright            : (C) 2001 The phpBB Group        
+ *   email                : support@phpbb.com                           
+ *                                                          
+ *   $Id$                                                           
+ *                                                            
+ * 
+ ***************************************************************************/ 
+
+/***************************************************************************  
+ *                                                     
+ *   This program 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.                      
+ *                                                          
+ * 
+ ***************************************************************************/ 
+
+switch($dbms)
+{
+	case 'mysql':
+		include('db/mysql.'.$phpEx);
+		break;
+	case 'postgres':
+		include('db/postgres7.'.$phpEx);
+		break;
+	case 'mssql':
+		include('db/mssql.'.$phpEx);
+		break;
+	case 'odbc':
+		include('db/odbc.'.$phpEx);
+		break;
+	case 'oracle':
+		include('db/oracle.'.$phpEx);
+		break;
+}
+
+// Make the database connection.
+$db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, false);
+if(!$db) 
+{
+   $db_error = $db->sql_error();
+   error_die($db, SQL_CONNECT, $db_error["message"]);
+}
+
+?>
diff --git a/phpBB/includes/page_header.php b/phpBB/includes/page_header.php
new file mode 100644
index 0000000000..903ed4dd69
--- /dev/null
+++ b/phpBB/includes/page_header.php
@@ -0,0 +1,134 @@
+<?php
+/***************************************************************************  
+ *                              page_header.php
+ *                            -------------------                         
+ *   begin                : Saturday, Feb 13, 2001 
+ *   copyright            : (C) 2001 The phpBB Group        
+ *   email                : support@phpbb.com                           
+ *                                                          
+ *   $Id$
+ *                                                            
+ * 
+ ***************************************************************************/ 
+
+
+/***************************************************************************  
+ *                                                     
+ *   This program 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.                      
+ *                                                          
+ * 
+ ***************************************************************************/ 
+
+// Parse and show the overall header.  
+$template->set_file(array("overall_header" => "overall_header.tpl",
+			  "overall_footer" => "overall_footer.tpl"));
+
+if($user_logged_in)
+{
+      $logged_in_status = "You are logged in as <b>".$userdata["username"]."</b>.";
+}
+else
+{
+      $logged_in_status = "You are not logged in.";
+}
+
+$template->set_var(array("SITENAME" => $sitename,
+			"PHPEX" => $phpEx,
+			 "PAGE_TITLE" => $page_title,
+			 "LOGIN_STATUS" => $logged_in_status,
+			 "META_INFO" => $meta_tags,
+			 "L_USERNAME" => $l_username,
+			 "L_PASSWORD" => $l_password,
+			 "L_WELCOMETO" => $l_welcometo,
+			 "L_REGISTER" => $l_register,
+			 "L_PROFILE" => $l_profile,
+			 "L_SEARCH" => $l_search,
+			 "L_PRIVATEMSGS" => $l_privmsgs,
+			 "L_MEMBERLIST" => $l_memberslist,
+			 "L_FAQ" => $l_faq,
+			 "L_FORUM" => $l_forum,
+			 "L_TOPICS" => $l_topics,
+			 "L_REPLIES" => $l_replies,
+			 "L_VIEWS" => $l_views,
+			 "L_POSTS" => $l_posts,
+			 "L_LASTPOST" => $l_lastpost,
+			 "L_MODERATOR" => $l_moderator,
+			 "L_MESSAGES" => $l_messages,
+			 "L_POSTEDTOTAL" => $l_postedtotal,
+			 "L_WEHAVE" => $l_wehave,
+			 "L_REGUSERS" => $l_regedusers,
+			 "L_NEWESTUSER" => $l_newestuser,
+			 "L_BROWSING" => $l_browsing,
+			 "L_ARECURRENTLY" => $l_arecurrently,
+			 "L_THEFORUMS" => $l_theforums,
+			 "L_NONEWPOSTS" => $l_nonewposts,
+			 "L_NEWPOSTS" => $l_newposts));
+
+$template->pparse("output", "overall_header");
+
+// Do a switch on page type, this way we only load the templates that we need at the time
+switch($pagetype) 
+{
+ case 'index':
+   $template->set_file(array("header" => "index_header.tpl",
+			     "body" => "index_body.tpl",
+			     "footer" => "index_footer.tpl"));
+   
+   $template->set_var(array("TOTAL_POSTS" => $total_posts,
+			    "TOTAL_USERS" => $total_users,
+			    "NEWEST_USER" => $newest_user,
+			    "NEWEST_UID" => $newest_uid,
+			    "USERS_BROWSING" => $users_browsing));
+   
+   $template->pparse("output", "header");
+   break;
+   
+ case 'viewforum':
+   $template->set_file(array("header" => "viewforum_header.tpl",
+			     "body" => "viewforum_body.tpl",
+			     "jumpbox" => "jumpbox.tpl",
+			     "footer" => "viewforum_footer.tpl"));
+   
+   $jumpbox = make_jumpbox($db);
+   $template->set_var(array("JUMPBOX_LIST" => $jumpbox,
+			    "JUMPBOX_ACTION" => "viewforum.".$phpEx,
+			    "SELECT_NAME" => "forum_id"));
+   $template->parse("JUMPBOX","jumpbox");
+   
+   $template->set_var(array("FORUM_ID" => $forum_id,
+			    "FORUM_NAME" => $forum_name,
+			    "MODERATORS" => $forum_moderators));
+   
+   $template->pparse("output", "header");
+   break;
+ case 'viewtopic':
+   $template->set_file(array("header" => "viewtopic_header.tpl",
+			     "body" => "viewtopic_body.tpl",
+			     "jumpbox" => "jumpbox.tpl",
+			     "footer" => "viewtopic_footer.tpl"));
+   $jumpbox = make_jumpbox($db);
+   $template->set_var(array("JUMPBOX_LIST" => $jumpbox,
+			    "JUMPBOX_ACTION" => "viewforum.".$phpEx,
+			    "SELECT_NAME" => "forum_id"));
+   $template->parse("JUMPBOX","jumpbox");
+   
+   $template->set_var(array("FORUM_ID" => $forum_id,
+			    "FORUM_NAME" => $forum_name,
+			    "TOPIC_ID" => $topic_id,
+			    "TOPIC_TITLE" => $topic_title));
+   $template->pparse("output", "header");
+   break;
+ case 'newtopic':
+   $template->set_file(array("header" => "newtopic_header.tpl",
+			     "body" => "posting_body.tpl"));
+   $template->set_var(array("FORUM_ID" => $forum_id,
+			    "FORUM_NAME" => $forum_name,
+			    "L_POSTNEWIN" => $l_postnewin));
+   $template->pparse("output", "header");
+   break;
+}
+			    
+?>
diff --git a/phpBB/includes/page_tail.php b/phpBB/includes/page_tail.php
new file mode 100644
index 0000000000..a9f5ee8086
--- /dev/null
+++ b/phpBB/includes/page_tail.php
@@ -0,0 +1,63 @@
+<?php
+/***************************************************************************  
+ *                              page_tail.php
+ *                            -------------------                         
+ *   begin                : Saturday, Feb 13, 2001 
+ *   copyright            : (C) 2001 The phpBB Group        
+ *   email                : support@phpbb.com                           
+ *                                                          
+ *   $Id$
+ *                                                            
+ * 
+ ***************************************************************************/ 
+
+
+/***************************************************************************  
+ *                                                     
+ *   This program 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.                      
+ *                                                          
+ * 
+ ***************************************************************************/ 
+
+// Load/parse the footer template we need based on pagetype.
+switch($pagetype) 
+{
+ case 'index':
+   $template->pparse("output", "footer");
+   break;
+   
+ case 'viewforum':
+   
+   $template->set_var(array("PHPEX" => $phpEx,
+			    "FORUM_ID" => $forum_id));	
+   $template->pparse("output", "footer");
+   break;
+ case 'viewtopic':
+   $template->pparse("output", "footer");
+   break;
+}
+
+// Show the overall footer.
+if($user_logged_in) 
+{
+   $admin_link = "<a href=\"admin/index.php\">Administration Panel</a>";
+}
+$template->set_var(array("PHPBB_VERSION" => "2.0-alpha",
+			 "ADMIN_LINK" => $admin_link));
+$template->pparse("output", "overall_footer");
+
+// Close our DB connection.
+$db->sql_close();
+
+$mtime = microtime();
+$mtime = explode(" ",$mtime);
+$mtime = $mtime[1] + $mtime[0];
+$endtime = $mtime;
+$totaltime = ($endtime - $starttime);
+
+printf("<center><font size=-2>phpBB Created this page in %f seconds.</font></center>", $totaltime);
+
+?>
diff --git a/phpBB/includes/template.inc b/phpBB/includes/template.inc
new file mode 100644
index 0000000000..a6d4e1a22b
--- /dev/null
+++ b/phpBB/includes/template.inc
@@ -0,0 +1,351 @@
+<?php
+/*
+ * Session Management for PHP3
+ *
+ * (C) Copyright 1999-2000 NetUSE GmbH
+ *                    Kristian Koehntopp
+ *
+ * $Id$
+ *
+ * This code was NOT written by the phpBB group. It is part of the PHPLib 
+ * package written by NetUSE GmbH and Kristian Koehntopp.
+ * This code is released under the GNU General Public Licence and used in
+ * accordance with said licence.
+ */ 
+
+class Template {
+  var $classname = "Template";
+
+  /* if set, echo assignments */
+  var $debug     = false;
+
+  /* $file[handle] = "filename"; */
+  var $file  = array();
+
+  /* relative filenames are relative to this pathname */
+  var $root   = "";
+
+  /* $varkeys[key] = "key"; $varvals[key] = "value"; */
+  var $varkeys = array();
+  var $varvals = array();
+
+  /* "remove"  => remove undefined variables
+   * "comment" => replace undefined variables with comments
+   * "keep"    => keep undefined variables
+   */
+  var $unknowns = "remove";
+  
+  /* "yes" => halt, "report" => report error, continue, "no" => ignore error quietly */
+  var $halt_on_error  = "yes";
+  
+  /* last error message is retained here */
+  var $last_error     = "";
+
+
+  /***************************************************************************/
+  /* public: Constructor.
+   * root:     template directory.
+   * unknowns: how to handle unknown variables.
+   */
+  function Template($root = ".", $unknowns = "remove") {
+    $this->set_root($root);
+    $this->set_unknowns($unknowns);
+  }
+
+  /* public: setroot(pathname $root)
+   * root:   new template directory.
+   */  
+  function set_root($root) {
+    if (!is_dir($root)) {
+      $this->halt("set_root: $root is not a directory.");
+      return false;
+    }
+    
+    $this->root = $root;
+    return true;
+  }
+
+  /* public: set_unknowns(enum $unknowns)
+   * unknowns: "remove", "comment", "keep"
+   *
+   */
+  function set_unknowns($unknowns = "keep") {
+    $this->unknowns = $unknowns;
+  }
+
+  /* public: set_file(array $filelist)
+   * filelist: array of handle, filename pairs.
+   *
+   * public: set_file(string $handle, string $filename)
+   * handle: handle for a filename,
+   * filename: name of template file
+   */
+  function set_file($handle, $filename = "") {
+    if (!is_array($handle)) {
+      if ($filename == "") {
+        $this->halt("set_file: For handle $handle filename is empty.");
+        return false;
+      }
+      $this->file[$handle] = $this->filename($filename);
+    } else {
+      reset($handle);
+      while(list($h, $f) = each($handle)) {
+        $this->file[$h] = $this->filename($f);
+      }
+    }
+  }
+
+  /* public: set_block(string $parent, string $handle, string $name = "")
+   * extract the template $handle from $parent, 
+   * place variable {$name} instead.
+   */
+  function set_block($parent, $handle, $name = "") {
+    if (!$this->loadfile($parent)) {
+      $this->halt("subst: unable to load $parent.");
+      return false;
+    }
+    if ($name == "")
+      $name = $handle;
+
+    $str = $this->get_var($parent);
+    $reg = "/<!--\s+BEGIN $handle\s+-->(.*)\n\s*<!--\s+END $handle\s+-->/sm";
+    preg_match_all($reg, $str, $m);
+    $str = preg_replace($reg, "{" . "$name}", $str);
+    $this->set_var($handle, $m[1][0]);
+    $this->set_var($parent, $str);
+  }
+  
+  /* public: set_var(array $values)
+   * values: array of variable name, value pairs.
+   *
+   * public: set_var(string $varname, string $value)
+   * varname: name of a variable that is to be defined
+   * value:   value of that variable
+   */
+  function set_var($varname, $value = "") {
+    if (!is_array($varname)) {
+      if (!empty($varname))
+        if ($this->debug) print "scalar: set *$varname* to *$value*<br>\n";
+        $this->varkeys[$varname] = "/".$this->varname($varname)."/";
+        $this->varvals[$varname] = $value;
+    } else {
+      reset($varname);
+      while(list($k, $v) = each($varname)) {
+        if (!empty($k))
+          if ($this->debug) print "array: set *$k* to *$v*<br>\n";
+          $this->varkeys[$k] = "/".$this->varname($k)."/";
+          $this->varvals[$k] = $v;
+      }
+    }
+  }
+
+  /* public: subst(string $handle)
+   * handle: handle of template where variables are to be substituted.
+   */
+  function subst($handle) {
+    if (!$this->loadfile($handle)) {
+      $this->halt("subst: unable to load $handle.");
+      return false;
+    }
+
+    $str = $this->get_var($handle);
+    $str = @preg_replace($this->varkeys, $this->varvals, $str);
+    return $str;
+  }
+  
+  /* public: psubst(string $handle)
+   * handle: handle of template where variables are to be substituted.
+   */
+  function psubst($handle) {
+    print $this->subst($handle);
+    
+    return false;
+  }
+
+  /* public: parse(string $target, string $handle, boolean append)
+   * public: parse(string $target, array  $handle, boolean append)
+   * target: handle of variable to generate
+   * handle: handle of template to substitute
+   * append: append to target handle
+   */
+  function parse($target, $handle, $append = false) {
+    if (!is_array($handle)) {
+      $str = $this->subst($handle);
+      if ($append) {
+        $this->set_var($target, $this->get_var($target) . $str);
+      } else {
+        $this->set_var($target, $str);
+      }
+    } else {
+      reset($handle);
+      while(list($i, $h) = each($handle)) {
+        $str = $this->subst($h);
+        $this->set_var($target, $str);
+      }
+    }
+    
+    return $str;
+  }
+  
+  function pparse($target, $handle, $append = false) {
+    print $this->parse($target, $handle, $append);
+    return false;
+  }
+  
+  /* public: get_vars()
+   */
+  function get_vars() {
+    reset($this->varkeys);
+    while(list($k, $v) = each($this->varkeys)) {
+      $result[$k] = $this->varvals[$k];
+    }
+    
+    return $result;
+  }
+  
+  /* public: get_var(string varname)
+   * varname: name of variable.
+   *
+   * public: get_var(array varname)
+   * varname: array of variable names
+   */
+  function get_var($varname) {
+    if (!is_array($varname)) {
+      return $this->varvals[$varname];
+    } else {
+      reset($varname);
+      while(list($k, $v) = each($varname)) {
+        $result[$k] = $this->varvals[$k];
+      }
+      
+      return $result;
+    }
+  }
+  
+  /* public: get_undefined($handle)
+   * handle: handle of a template.
+   */
+  function get_undefined($handle) {
+    if (!$this->loadfile($handle)) {
+      $this->halt("get_undefined: unable to load $handle.");
+      return false;
+    }
+    
+    preg_match_all("/\{([^}]+)\}/", $this->get_var($handle), $m);
+    $m = $m[1];
+    if (!is_array($m))
+      return false;
+
+    reset($m);
+    while(list($k, $v) = each($m)) {
+      if (!isset($this->varkeys[$v]))
+        $result[$v] = $v;
+    }
+    
+    if (count($result))
+      return $result;
+    else
+      return false;
+  }
+
+  /* public: finish(string $str)
+   * str: string to finish.
+   */
+  function finish($str) {
+    switch ($this->unknowns) {
+      case "keep":
+      break;
+      
+      case "remove":
+        $str = preg_replace('/{[^ \t\r\n}]+}/', "", $str);
+      break;
+
+      case "comment":
+        $str = preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template $handle: Variable \\1 undefined -->", $str);
+      break;
+    }
+    
+    return $str;
+  }
+
+  /* public: p(string $varname)
+   * varname: name of variable to print.
+   */
+  function p($varname) {
+    print $this->finish($this->get_var($varname));
+  }
+
+  function get($varname) {
+    return $this->finish($this->get_var($varname));
+  }
+    
+  /***************************************************************************/
+  /* private: filename($filename)
+   * filename: name to be completed.
+   */
+  function filename($filename) {
+    if (substr($filename, 0, 1) != "/") {
+      $filename = $this->root."/".$filename;
+    }
+    
+    if (!file_exists($filename))
+      $this->halt("filename: file $filename does not exist.");
+
+    return $filename;
+  }
+  
+  /* private: varname($varname)
+   * varname: name of a replacement variable to be protected.
+   */
+  function varname($varname) {
+    return preg_quote("{".$varname."}");
+  }
+
+  /* private: loadfile(string $handle)
+   * handle:  load file defined by handle, if it is not loaded yet.
+   */
+  function loadfile($handle) {
+    if (isset($this->varkeys[$handle]) and !empty($this->varvals[$handle]))
+      return true;
+
+    if (!isset($this->file[$handle])) {
+      $this->halt("loadfile: $handle is not a valid handle.");
+      return false;
+    }
+    $filename = $this->file[$handle];
+
+    $str = implode("", @file($filename));
+    if (empty($str)) {
+      $this->halt("loadfile: While loading $handle, $filename does not exist or is empty.");
+      return false;
+    }
+
+    $this->set_var($handle, $str);
+    
+    return true;
+  }
+
+  /***************************************************************************/
+  /* public: halt(string $msg)
+   * msg:    error message to show.
+   */
+  function halt($msg) {
+    $this->last_error = $msg;
+    
+    if ($this->halt_on_error != "no")
+      $this->haltmsg($msg);
+    
+    if ($this->halt_on_error == "yes")
+      die("<b>Halted.</b>");
+    
+    return false;
+  }
+  
+  /* public, override: haltmsg($msg)
+   * msg: error message to show.
+   */
+  function haltmsg($msg) {
+    printf("<b>Template Error:</b> %s<br>\n", $msg);
+  }
+}
+?>
diff --git a/phpBB/index.php b/phpBB/index.php
index b42b3a6bdd..af3d5dccb1 100644
--- a/phpBB/index.php
+++ b/phpBB/index.php
@@ -24,6 +24,9 @@
 include('extension.inc');
 include('common.'.$phpEx);
 
+$pagetype = "index";
+$page_title = "Forum Index";
+
 $total_users = get_user_count($db, "");
 $total_posts = get_total_posts($db, "");
 $newest_userdata = get_newest_user($db, "");
@@ -36,9 +39,7 @@ if(empty($viewcat))
 	$viewcat = -1;
 }
 
-$pagetype = "index";
-$page_title = "Forum Index";
-include('page_header.'.$phpEx);
+include('includes/page_header.'.$phpEx);
 
 $template->set_block("body", "catrow", "cats");
 $template->set_block("catrow", "forumrow", "forums");
@@ -182,5 +183,5 @@ else
 }
 $template->pparse("output", "body");
 
-include('page_tail.'.$phpEx);
+include('includes/page_tail.'.$phpEx);
 ?>
diff --git a/phpBB/page_header.php b/phpBB/page_header.php
deleted file mode 100644
index 903ed4dd69..0000000000
--- a/phpBB/page_header.php
+++ /dev/null
@@ -1,134 +0,0 @@
-<?php
-/***************************************************************************  
- *                              page_header.php
- *                            -------------------                         
- *   begin                : Saturday, Feb 13, 2001 
- *   copyright            : (C) 2001 The phpBB Group        
- *   email                : support@phpbb.com                           
- *                                                          
- *   $Id$
- *                                                            
- * 
- ***************************************************************************/ 
-
-
-/***************************************************************************  
- *                                                     
- *   This program 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.                      
- *                                                          
- * 
- ***************************************************************************/ 
-
-// Parse and show the overall header.  
-$template->set_file(array("overall_header" => "overall_header.tpl",
-			  "overall_footer" => "overall_footer.tpl"));
-
-if($user_logged_in)
-{
-      $logged_in_status = "You are logged in as <b>".$userdata["username"]."</b>.";
-}
-else
-{
-      $logged_in_status = "You are not logged in.";
-}
-
-$template->set_var(array("SITENAME" => $sitename,
-			"PHPEX" => $phpEx,
-			 "PAGE_TITLE" => $page_title,
-			 "LOGIN_STATUS" => $logged_in_status,
-			 "META_INFO" => $meta_tags,
-			 "L_USERNAME" => $l_username,
-			 "L_PASSWORD" => $l_password,
-			 "L_WELCOMETO" => $l_welcometo,
-			 "L_REGISTER" => $l_register,
-			 "L_PROFILE" => $l_profile,
-			 "L_SEARCH" => $l_search,
-			 "L_PRIVATEMSGS" => $l_privmsgs,
-			 "L_MEMBERLIST" => $l_memberslist,
-			 "L_FAQ" => $l_faq,
-			 "L_FORUM" => $l_forum,
-			 "L_TOPICS" => $l_topics,
-			 "L_REPLIES" => $l_replies,
-			 "L_VIEWS" => $l_views,
-			 "L_POSTS" => $l_posts,
-			 "L_LASTPOST" => $l_lastpost,
-			 "L_MODERATOR" => $l_moderator,
-			 "L_MESSAGES" => $l_messages,
-			 "L_POSTEDTOTAL" => $l_postedtotal,
-			 "L_WEHAVE" => $l_wehave,
-			 "L_REGUSERS" => $l_regedusers,
-			 "L_NEWESTUSER" => $l_newestuser,
-			 "L_BROWSING" => $l_browsing,
-			 "L_ARECURRENTLY" => $l_arecurrently,
-			 "L_THEFORUMS" => $l_theforums,
-			 "L_NONEWPOSTS" => $l_nonewposts,
-			 "L_NEWPOSTS" => $l_newposts));
-
-$template->pparse("output", "overall_header");
-
-// Do a switch on page type, this way we only load the templates that we need at the time
-switch($pagetype) 
-{
- case 'index':
-   $template->set_file(array("header" => "index_header.tpl",
-			     "body" => "index_body.tpl",
-			     "footer" => "index_footer.tpl"));
-   
-   $template->set_var(array("TOTAL_POSTS" => $total_posts,
-			    "TOTAL_USERS" => $total_users,
-			    "NEWEST_USER" => $newest_user,
-			    "NEWEST_UID" => $newest_uid,
-			    "USERS_BROWSING" => $users_browsing));
-   
-   $template->pparse("output", "header");
-   break;
-   
- case 'viewforum':
-   $template->set_file(array("header" => "viewforum_header.tpl",
-			     "body" => "viewforum_body.tpl",
-			     "jumpbox" => "jumpbox.tpl",
-			     "footer" => "viewforum_footer.tpl"));
-   
-   $jumpbox = make_jumpbox($db);
-   $template->set_var(array("JUMPBOX_LIST" => $jumpbox,
-			    "JUMPBOX_ACTION" => "viewforum.".$phpEx,
-			    "SELECT_NAME" => "forum_id"));
-   $template->parse("JUMPBOX","jumpbox");
-   
-   $template->set_var(array("FORUM_ID" => $forum_id,
-			    "FORUM_NAME" => $forum_name,
-			    "MODERATORS" => $forum_moderators));
-   
-   $template->pparse("output", "header");
-   break;
- case 'viewtopic':
-   $template->set_file(array("header" => "viewtopic_header.tpl",
-			     "body" => "viewtopic_body.tpl",
-			     "jumpbox" => "jumpbox.tpl",
-			     "footer" => "viewtopic_footer.tpl"));
-   $jumpbox = make_jumpbox($db);
-   $template->set_var(array("JUMPBOX_LIST" => $jumpbox,
-			    "JUMPBOX_ACTION" => "viewforum.".$phpEx,
-			    "SELECT_NAME" => "forum_id"));
-   $template->parse("JUMPBOX","jumpbox");
-   
-   $template->set_var(array("FORUM_ID" => $forum_id,
-			    "FORUM_NAME" => $forum_name,
-			    "TOPIC_ID" => $topic_id,
-			    "TOPIC_TITLE" => $topic_title));
-   $template->pparse("output", "header");
-   break;
- case 'newtopic':
-   $template->set_file(array("header" => "newtopic_header.tpl",
-			     "body" => "posting_body.tpl"));
-   $template->set_var(array("FORUM_ID" => $forum_id,
-			    "FORUM_NAME" => $forum_name,
-			    "L_POSTNEWIN" => $l_postnewin));
-   $template->pparse("output", "header");
-   break;
-}
-			    
-?>
diff --git a/phpBB/page_tail.php b/phpBB/page_tail.php
deleted file mode 100644
index a9f5ee8086..0000000000
--- a/phpBB/page_tail.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-/***************************************************************************  
- *                              page_tail.php
- *                            -------------------                         
- *   begin                : Saturday, Feb 13, 2001 
- *   copyright            : (C) 2001 The phpBB Group        
- *   email                : support@phpbb.com                           
- *                                                          
- *   $Id$
- *                                                            
- * 
- ***************************************************************************/ 
-
-
-/***************************************************************************  
- *                                                     
- *   This program 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.                      
- *                                                          
- * 
- ***************************************************************************/ 
-
-// Load/parse the footer template we need based on pagetype.
-switch($pagetype) 
-{
- case 'index':
-   $template->pparse("output", "footer");
-   break;
-   
- case 'viewforum':
-   
-   $template->set_var(array("PHPEX" => $phpEx,
-			    "FORUM_ID" => $forum_id));	
-   $template->pparse("output", "footer");
-   break;
- case 'viewtopic':
-   $template->pparse("output", "footer");
-   break;
-}
-
-// Show the overall footer.
-if($user_logged_in) 
-{
-   $admin_link = "<a href=\"admin/index.php\">Administration Panel</a>";
-}
-$template->set_var(array("PHPBB_VERSION" => "2.0-alpha",
-			 "ADMIN_LINK" => $admin_link));
-$template->pparse("output", "overall_footer");
-
-// Close our DB connection.
-$db->sql_close();
-
-$mtime = microtime();
-$mtime = explode(" ",$mtime);
-$mtime = $mtime[1] + $mtime[0];
-$endtime = $mtime;
-$totaltime = ($endtime - $starttime);
-
-printf("<center><font size=-2>phpBB Created this page in %f seconds.</font></center>", $totaltime);
-
-?>
diff --git a/phpBB/posting.php b/phpBB/posting.php
index 2c27fab0d4..657f025b77 100644
--- a/phpBB/posting.php
+++ b/phpBB/posting.php
@@ -46,125 +46,125 @@ else
    switch($mode)
      {
       case 'newtopic':
-	if(!isset($forum_id))
-	  {
-	     error_die($db, GENERAL_ERROR, "Sorry, no there is no such forum");
-	  }
-	
-	$pagetype = "newtopic";
-	$page_title = " $l_postnew";
-	$sql = "SELECT forum_name, forum_access FROM forums WHERE forum_id = '$forum_id'";
-	if(!$result = $db->sql_query($sql))
-	  {
-	     error_die($db, QUERY_ERROR);
-	  }
-	$forum_info = $db->sql_fetchrowset($result);
-	$forum_name = stripslashes($forum_info[0]["forum_name"]);
-	$forum_access = $forum_info[0]["forum_access"];
-	
-	if($forum_access == ANONALLOWED)
-	  {
-	     $about_posting = "$l_anonusers $l_inthisforum $l_anonhint";
-	  }
-	if($forum_access == REGONLY)
-	  {
-	     $about_posting = "$l_regusers $l_inthisforum";
-	  }
-	if($forum_access == MODONLY)
-	  {
-	     $about_posting = "$l_modusers $l_inthisforum";
-	  }
-		
-	include('page_header.'.$phpEx);
-	if($user_logged_in)
-	  {
-	     $username_input = $userdata["username"];
-	     $password_input = "";
-	  }
-	else
-	  {
-	     if(!isset($username))
-	       {
-		  $username = $userdata["username"];
-	       }
-	     $username_input = '<input type="text" name="username" value="'.$username.'" size="25" maxlength="50">';
-	     $password_input = '<input type="password" name="password" size="25" maxlenght="40">';
-	  }
-	$subject_input = '<input type="text" name="subject" value="'.$subject.'" size="50" maxlenght="255">';
-	$message_input = '<textarea name="message" rows="10" cols="35" wrap="virtual">'.$message.'</textarea>';
-	if($allow_html)
-	  {
-	     $html_status = $l_htmlis . " " . $l_on;
-	     $html_toggle = '<input type="checkbox" name="disable_html" ';
-	     if($disable_html) 
-	       {
-		  $html_toggle .= 'checked';
-	       }
-	     $html_toggle .= "> $l_disable $l_html $l_onthispost";
-	  }
-	else
-	  {
-	     $html_status = $l_htmlis . " " . $l_off;
-	  }
-	if($allow_bbcode)
-	  {
-	     $bbcode_status = $l_bbcodeis . " " . $l_on;
-	     $bbcode_toggle = '<input type="checkbox" name="disable_bbcode" ';
-	     if($disable_bbcode)
-	       {
-		  $bbcode_toggle .= "checked";
-	       }
-	     $bbcode_toggle .= "> $l_disable $l_bbcode $l_onthispost";
-	  }
-	else
-	  {
-	     $bbcode_status = $l_bbcodeis . " " . $l_off;
-	  }
-	
-	$smile_toggle = '<input type="checkbox" name="disable_smile" ';
-	if($disable_smile)
-	  {
-	     $smile_toggle .= "checked";
-	  }
-	$smile_toggle .= "> $l_disable $l_smilies $l_onthispost";
-	
-	$sig_toggle = '<input type="checkbox" name="attach_sig" ';
-	if($attach_sig || $userdata["attach_sig"] == 1)
-	  {
-	     $sig_toggle .= "checked";
-	  }
-	$sig_toggle .= "> $l_attachsig";
-	
-	$notify_toggle = '<input type="checkbox" name="notify" ';
-	if($notify || $userdata["always_notify"] == 1)
-	  {
-	     $notify_toggle .= "checked";
-	  }
-	$notify_toggle .= "> $l_notify";
-	
-	
-	$template->set_var(array("L_ABOUTPOST" => $l_aboutpost,
-				 "L_SUBJECT" => $l_subject,
-				 "L_MESSAGEBODY" => $l_body,
-				 "L_OPTIONS" => $l_options,
-				 "L_PREVIEW" => $l_preview,
-				 "L_SUBMIT" => $l_submit,
-				 "L_CANCEL" => $l_cancelpost,
-				 "MODE" => $mode,
-				 "ABOUT_POSTING" => $about_posting,
-				 "USERNAME_INPUT" => $username_input,
-				 "PASSWORD_INPUT" => $password_input,
-				 "SUBJECT_INPUT" => $subject_input,
-				 "MESSAGE_INPUT" => $message_input,
-				 "HTML_STATUS" => $html_status,
-				 "HTML_TOGGLE" => $html_toggle,
-				 "SMILE_TOGGLE" => $smile_toggle,
-				 "SIG_TOGGLE" => $sig_toggle,
-				 "NOTIFY_TOGGLE" => $notify_toggle,
-				 "BBCODE_TOGGLE" => $bbcode_toggle,
-				 "BBCODE_STATUS" => $bbcode_status));
-	$template->pparse("output", "body");
-	include('page_tail.'.$phpEx);
+			if(!isset($forum_id))
+			{
+				error_die($db, GENERAL_ERROR, "Sorry, no there is no such forum");
+			}
+			
+			$pagetype = "newtopic";
+			$page_title = " $l_postnew";
+			$sql = "SELECT forum_name, forum_access FROM forums WHERE forum_id = '$forum_id'";
+			if(!$result = $db->sql_query($sql))
+			{
+				error_die($db, QUERY_ERROR);
+			}
+			$forum_info = $db->sql_fetchrowset($result);
+			$forum_name = stripslashes($forum_info[0]["forum_name"]);
+			$forum_access = $forum_info[0]["forum_access"];
+			
+			if($forum_access == ANONALLOWED)
+			{
+				$about_posting = "$l_anonusers $l_inthisforum $l_anonhint";
+			}
+			if($forum_access == REGONLY)
+			{
+				$about_posting = "$l_regusers $l_inthisforum";
+			}
+			if($forum_access == MODONLY)
+			{
+				$about_posting = "$l_modusers $l_inthisforum";
+			}
+				
+			include('includes/page_header.'.$phpEx);
+			if($user_logged_in)
+			{
+				$username_input = $userdata["username"];
+				$password_input = "";
+			}
+			else
+			{
+				if(!isset($username))
+				{
+					$username = $userdata["username"];
+				}
+				$username_input = '<input type="text" name="username" value="'.$username.'" size="25" maxlength="50">';
+				$password_input = '<input type="password" name="password" size="25" maxlenght="40">';
+			}
+			$subject_input = '<input type="text" name="subject" value="'.$subject.'" size="50" maxlenght="255">';
+			$message_input = '<textarea name="message" rows="10" cols="35" wrap="virtual">'.$message.'</textarea>';
+			if($allow_html)
+			{
+				$html_status = $l_htmlis . " " . $l_on;
+				$html_toggle = '<input type="checkbox" name="disable_html" ';
+				if($disable_html) 
+				{
+					$html_toggle .= 'checked';
+				}
+				$html_toggle .= "> $l_disable $l_html $l_onthispost";
+			}
+			else
+			{
+				$html_status = $l_htmlis . " " . $l_off;
+			}
+			if($allow_bbcode)
+			{
+				$bbcode_status = $l_bbcodeis . " " . $l_on;
+				$bbcode_toggle = '<input type="checkbox" name="disable_bbcode" ';
+				if($disable_bbcode)
+				{
+					$bbcode_toggle .= "checked";
+				}
+				$bbcode_toggle .= "> $l_disable $l_bbcode $l_onthispost";
+			}
+			else
+			{
+				$bbcode_status = $l_bbcodeis . " " . $l_off;
+			}
+			
+			$smile_toggle = '<input type="checkbox" name="disable_smile" ';
+			if($disable_smile)
+			{
+				$smile_toggle .= "checked";
+			}
+			$smile_toggle .= "> $l_disable $l_smilies $l_onthispost";
+			
+			$sig_toggle = '<input type="checkbox" name="attach_sig" ';
+			if($attach_sig || $userdata["attach_sig"] == 1)
+			{
+				$sig_toggle .= "checked";
+			}
+			$sig_toggle .= "> $l_attachsig";
+			
+			$notify_toggle = '<input type="checkbox" name="notify" ';
+			if($notify || $userdata["always_notify"] == 1)
+			{
+				$notify_toggle .= "checked";
+			}
+			$notify_toggle .= "> $l_notify";
+			
+			
+			$template->set_var(array("L_ABOUTPOST" => $l_aboutpost,
+											"L_SUBJECT" => $l_subject,
+											"L_MESSAGEBODY" => $l_body,
+											"L_OPTIONS" => $l_options,
+											"L_PREVIEW" => $l_preview,
+											"L_SUBMIT" => $l_submit,
+											"L_CANCEL" => $l_cancelpost,
+											"MODE" => $mode,
+											"ABOUT_POSTING" => $about_posting,
+											"USERNAME_INPUT" => $username_input,
+											"PASSWORD_INPUT" => $password_input,
+											"SUBJECT_INPUT" => $subject_input,
+											"MESSAGE_INPUT" => $message_input,
+											"HTML_STATUS" => $html_status,
+											"HTML_TOGGLE" => $html_toggle,
+											"SMILE_TOGGLE" => $smile_toggle,
+											"SIG_TOGGLE" => $sig_toggle,
+											"NOTIFY_TOGGLE" => $notify_toggle,
+											"BBCODE_TOGGLE" => $bbcode_toggle,
+											"BBCODE_STATUS" => $bbcode_status));
+			$template->pparse("output", "body");
+			include('includes/page_tail.'.$phpEx);
 	break;
       case 'reply':
 	
diff --git a/phpBB/template.inc b/phpBB/template.inc
deleted file mode 100644
index a6d4e1a22b..0000000000
--- a/phpBB/template.inc
+++ /dev/null
@@ -1,351 +0,0 @@
-<?php
-/*
- * Session Management for PHP3
- *
- * (C) Copyright 1999-2000 NetUSE GmbH
- *                    Kristian Koehntopp
- *
- * $Id$
- *
- * This code was NOT written by the phpBB group. It is part of the PHPLib 
- * package written by NetUSE GmbH and Kristian Koehntopp.
- * This code is released under the GNU General Public Licence and used in
- * accordance with said licence.
- */ 
-
-class Template {
-  var $classname = "Template";
-
-  /* if set, echo assignments */
-  var $debug     = false;
-
-  /* $file[handle] = "filename"; */
-  var $file  = array();
-
-  /* relative filenames are relative to this pathname */
-  var $root   = "";
-
-  /* $varkeys[key] = "key"; $varvals[key] = "value"; */
-  var $varkeys = array();
-  var $varvals = array();
-
-  /* "remove"  => remove undefined variables
-   * "comment" => replace undefined variables with comments
-   * "keep"    => keep undefined variables
-   */
-  var $unknowns = "remove";
-  
-  /* "yes" => halt, "report" => report error, continue, "no" => ignore error quietly */
-  var $halt_on_error  = "yes";
-  
-  /* last error message is retained here */
-  var $last_error     = "";
-
-
-  /***************************************************************************/
-  /* public: Constructor.
-   * root:     template directory.
-   * unknowns: how to handle unknown variables.
-   */
-  function Template($root = ".", $unknowns = "remove") {
-    $this->set_root($root);
-    $this->set_unknowns($unknowns);
-  }
-
-  /* public: setroot(pathname $root)
-   * root:   new template directory.
-   */  
-  function set_root($root) {
-    if (!is_dir($root)) {
-      $this->halt("set_root: $root is not a directory.");
-      return false;
-    }
-    
-    $this->root = $root;
-    return true;
-  }
-
-  /* public: set_unknowns(enum $unknowns)
-   * unknowns: "remove", "comment", "keep"
-   *
-   */
-  function set_unknowns($unknowns = "keep") {
-    $this->unknowns = $unknowns;
-  }
-
-  /* public: set_file(array $filelist)
-   * filelist: array of handle, filename pairs.
-   *
-   * public: set_file(string $handle, string $filename)
-   * handle: handle for a filename,
-   * filename: name of template file
-   */
-  function set_file($handle, $filename = "") {
-    if (!is_array($handle)) {
-      if ($filename == "") {
-        $this->halt("set_file: For handle $handle filename is empty.");
-        return false;
-      }
-      $this->file[$handle] = $this->filename($filename);
-    } else {
-      reset($handle);
-      while(list($h, $f) = each($handle)) {
-        $this->file[$h] = $this->filename($f);
-      }
-    }
-  }
-
-  /* public: set_block(string $parent, string $handle, string $name = "")
-   * extract the template $handle from $parent, 
-   * place variable {$name} instead.
-   */
-  function set_block($parent, $handle, $name = "") {
-    if (!$this->loadfile($parent)) {
-      $this->halt("subst: unable to load $parent.");
-      return false;
-    }
-    if ($name == "")
-      $name = $handle;
-
-    $str = $this->get_var($parent);
-    $reg = "/<!--\s+BEGIN $handle\s+-->(.*)\n\s*<!--\s+END $handle\s+-->/sm";
-    preg_match_all($reg, $str, $m);
-    $str = preg_replace($reg, "{" . "$name}", $str);
-    $this->set_var($handle, $m[1][0]);
-    $this->set_var($parent, $str);
-  }
-  
-  /* public: set_var(array $values)
-   * values: array of variable name, value pairs.
-   *
-   * public: set_var(string $varname, string $value)
-   * varname: name of a variable that is to be defined
-   * value:   value of that variable
-   */
-  function set_var($varname, $value = "") {
-    if (!is_array($varname)) {
-      if (!empty($varname))
-        if ($this->debug) print "scalar: set *$varname* to *$value*<br>\n";
-        $this->varkeys[$varname] = "/".$this->varname($varname)."/";
-        $this->varvals[$varname] = $value;
-    } else {
-      reset($varname);
-      while(list($k, $v) = each($varname)) {
-        if (!empty($k))
-          if ($this->debug) print "array: set *$k* to *$v*<br>\n";
-          $this->varkeys[$k] = "/".$this->varname($k)."/";
-          $this->varvals[$k] = $v;
-      }
-    }
-  }
-
-  /* public: subst(string $handle)
-   * handle: handle of template where variables are to be substituted.
-   */
-  function subst($handle) {
-    if (!$this->loadfile($handle)) {
-      $this->halt("subst: unable to load $handle.");
-      return false;
-    }
-
-    $str = $this->get_var($handle);
-    $str = @preg_replace($this->varkeys, $this->varvals, $str);
-    return $str;
-  }
-  
-  /* public: psubst(string $handle)
-   * handle: handle of template where variables are to be substituted.
-   */
-  function psubst($handle) {
-    print $this->subst($handle);
-    
-    return false;
-  }
-
-  /* public: parse(string $target, string $handle, boolean append)
-   * public: parse(string $target, array  $handle, boolean append)
-   * target: handle of variable to generate
-   * handle: handle of template to substitute
-   * append: append to target handle
-   */
-  function parse($target, $handle, $append = false) {
-    if (!is_array($handle)) {
-      $str = $this->subst($handle);
-      if ($append) {
-        $this->set_var($target, $this->get_var($target) . $str);
-      } else {
-        $this->set_var($target, $str);
-      }
-    } else {
-      reset($handle);
-      while(list($i, $h) = each($handle)) {
-        $str = $this->subst($h);
-        $this->set_var($target, $str);
-      }
-    }
-    
-    return $str;
-  }
-  
-  function pparse($target, $handle, $append = false) {
-    print $this->parse($target, $handle, $append);
-    return false;
-  }
-  
-  /* public: get_vars()
-   */
-  function get_vars() {
-    reset($this->varkeys);
-    while(list($k, $v) = each($this->varkeys)) {
-      $result[$k] = $this->varvals[$k];
-    }
-    
-    return $result;
-  }
-  
-  /* public: get_var(string varname)
-   * varname: name of variable.
-   *
-   * public: get_var(array varname)
-   * varname: array of variable names
-   */
-  function get_var($varname) {
-    if (!is_array($varname)) {
-      return $this->varvals[$varname];
-    } else {
-      reset($varname);
-      while(list($k, $v) = each($varname)) {
-        $result[$k] = $this->varvals[$k];
-      }
-      
-      return $result;
-    }
-  }
-  
-  /* public: get_undefined($handle)
-   * handle: handle of a template.
-   */
-  function get_undefined($handle) {
-    if (!$this->loadfile($handle)) {
-      $this->halt("get_undefined: unable to load $handle.");
-      return false;
-    }
-    
-    preg_match_all("/\{([^}]+)\}/", $this->get_var($handle), $m);
-    $m = $m[1];
-    if (!is_array($m))
-      return false;
-
-    reset($m);
-    while(list($k, $v) = each($m)) {
-      if (!isset($this->varkeys[$v]))
-        $result[$v] = $v;
-    }
-    
-    if (count($result))
-      return $result;
-    else
-      return false;
-  }
-
-  /* public: finish(string $str)
-   * str: string to finish.
-   */
-  function finish($str) {
-    switch ($this->unknowns) {
-      case "keep":
-      break;
-      
-      case "remove":
-        $str = preg_replace('/{[^ \t\r\n}]+}/', "", $str);
-      break;
-
-      case "comment":
-        $str = preg_replace('/{([^ \t\r\n}]+)}/', "<!-- Template $handle: Variable \\1 undefined -->", $str);
-      break;
-    }
-    
-    return $str;
-  }
-
-  /* public: p(string $varname)
-   * varname: name of variable to print.
-   */
-  function p($varname) {
-    print $this->finish($this->get_var($varname));
-  }
-
-  function get($varname) {
-    return $this->finish($this->get_var($varname));
-  }
-    
-  /***************************************************************************/
-  /* private: filename($filename)
-   * filename: name to be completed.
-   */
-  function filename($filename) {
-    if (substr($filename, 0, 1) != "/") {
-      $filename = $this->root."/".$filename;
-    }
-    
-    if (!file_exists($filename))
-      $this->halt("filename: file $filename does not exist.");
-
-    return $filename;
-  }
-  
-  /* private: varname($varname)
-   * varname: name of a replacement variable to be protected.
-   */
-  function varname($varname) {
-    return preg_quote("{".$varname."}");
-  }
-
-  /* private: loadfile(string $handle)
-   * handle:  load file defined by handle, if it is not loaded yet.
-   */
-  function loadfile($handle) {
-    if (isset($this->varkeys[$handle]) and !empty($this->varvals[$handle]))
-      return true;
-
-    if (!isset($this->file[$handle])) {
-      $this->halt("loadfile: $handle is not a valid handle.");
-      return false;
-    }
-    $filename = $this->file[$handle];
-
-    $str = implode("", @file($filename));
-    if (empty($str)) {
-      $this->halt("loadfile: While loading $handle, $filename does not exist or is empty.");
-      return false;
-    }
-
-    $this->set_var($handle, $str);
-    
-    return true;
-  }
-
-  /***************************************************************************/
-  /* public: halt(string $msg)
-   * msg:    error message to show.
-   */
-  function halt($msg) {
-    $this->last_error = $msg;
-    
-    if ($this->halt_on_error != "no")
-      $this->haltmsg($msg);
-    
-    if ($this->halt_on_error == "yes")
-      die("<b>Halted.</b>");
-    
-    return false;
-  }
-  
-  /* public, override: haltmsg($msg)
-   * msg: error message to show.
-   */
-  function haltmsg($msg) {
-    printf("<b>Template Error:</b> %s<br>\n", $msg);
-  }
-}
-?>
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index ba63bcab54..cb5b69d7af 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -23,6 +23,9 @@
 include('extension.inc');
 include('common.'.$phpEx);
 
+$pagetype = "viewforum";
+$page_title = "View Forum - $forum_name";
+
 // Check if the user has acutally sent a forum ID with his/her request
 // If not give them a nice error page.
 if(isset($forum_id))
@@ -68,9 +71,8 @@ for($x = 0; $x < $db->sql_numrows($result); $x++)
      $forum_moderators .= ", ";
    $forum_moderators .= "<a href=\"profile.$phpEx?mode=viewprofile&user_id=".$forum_row[$x]["user_id"]."\">".$forum_row[$x]["username"]."</a>";
 }
-$pagetype = "viewforum";
-$page_title = "View Forum - $forum_name";
-include('page_header.'.$phpEx);
+
+include('includes/page_header.'.$phpEx);
 
 $template->set_block("body", "topicrow", "topics");
 
@@ -150,6 +152,6 @@ else
 	error_die($db, NO_POSTS);
 }
 			       
-include('page_tail.'.$phpEx);
+include('includes/page_tail.'.$phpEx);
 
 ?>
diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php
index add38f5f1b..0452f63843 100644
--- a/phpBB/viewtopic.php
+++ b/phpBB/viewtopic.php
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *				 viewtopic.php
+ *				 						   viewtopic.php
  *                            -------------------
  *   begin                : Saturday, Feb 13, 2001
  *   copyright            : (C) 2001 The phpBB Group
@@ -23,6 +23,9 @@
 include('extension.inc');
 include('common.'.$phpEx);
 
+$page_title = "View Topic - $topic_title";
+$topic_title = stripslashes($topic_info[0]["topic_title"]);
+
 if(!isset($HTTP_GET_VARS['topic']))  // For backward compatibility
 {
 	$topic_id = $HTTP_GET_VARS[POST_TOPIC_URL];
@@ -73,11 +76,9 @@ for($x = 0; $x < $total_rows; $x++)
 // Add checking for private forums here
 //
 
-$page_title = "View Topic - $topic_title";
-$topic_title = stripslashes($topic_info[0]["topic_title"]);
 $total_replies = $topic_info[0]["topic_replies"] + 1;
 $pagetype = "viewtopic";
-include('page_header.'.$phpEx);
+include('includes/page_header.'.$phpEx);
 
 if(!isset($start))
 {
@@ -252,6 +253,6 @@ $template->set_var(array("PAGES" => $pages,
 
 $template->pparse("output", array("posts", "body"));
 
-include('page_tail.'.$phpEx);
+include('includes/page_tail.'.$phpEx);
 
 ?>
-- 
cgit v1.2.1