From ab5579b69cf0596c429f0afb046dd1e2bf81eb5d Mon Sep 17 00:00:00 2001
From: Denis Walker <dez@sucs.org>
Date: Mon, 26 Nov 2007 17:24:19 +0000
Subject: [PATCH] Tidies up index.php a bit - e.g. uses require_once for
 libraries Moves all uses of constants from settings.php in Smarty templates
 to $smarty.const.CONSTANT_NAME

---
 htdocs/index.php       | 13 +++++--------
 templates/head.tpl     | 22 +++++++++++-----------
 templates/login.tpl    |  2 +-
 templates/members.tpl  |  2 +-
 templates/menu.tpl     |  6 +++---
 templates/options.tpl  |  2 +-
 templates/pastebin.tpl |  2 +-
 7 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/htdocs/index.php b/htdocs/index.php
index 304aad4..87e441a 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -14,7 +14,7 @@ if (@$displaytime) {
     Settings
    -------------------------------------------------------- */
 
-include("settings.php");
+require_once("settings.php");
 if (!defined('SUCS_BASEDIR')) {
 	echo "Website unconfigured";
 	exit();
@@ -24,20 +24,18 @@ if (!defined('SUCS_BASEDIR')) {
     Libraries
    -------------------------------------------------------- */
 // Include our custom error handling business
-require("../lib/error.php");
+require_once("../lib/error.php");
 
 
 // Include the Smarty templating engine
-require(SMARTY_DIR."Smarty.class.php");
+require_once(SMARTY_DIR."Smarty.class.php");
 $smarty = new Smarty;
 $smarty->template_dir = SUCS_BASEDIR."templates";
 $smarty->compile_dir = SUCS_BASEDIR."templates_c";
 $smarty->plugins_dir[] = SUCS_BASEDIR."plugins";
 
-$smarty->assign("baseurl", SUCS_BASEURL);
-
 // Initialise the database
-require(ADODB_DIR."adodb.inc.php");
+require_once(ADODB_DIR."adodb.inc.php");
 $DB = NewADOConnection(SUCS_DBTYPE);
 $DB->Connect('dbname='.SUCS_DBNAME);
 $DB->SetFetchMode(ADODB_FETCH_ASSOC);
@@ -52,7 +50,7 @@ $smarty->assign_by_ref("session", $session);
    -------------------------------------------------------- */
 
 // Turn on adodb debugging by uncommenting:
-//$DB->debug = true;
+//$DB->debug = TRUE;
 
 // Turn on Smarty debugging by uncommenting:
 //$smarty->assign("debug",TRUE);
@@ -181,5 +179,4 @@ $smarty->display("foot".$language['file'].".tpl");
 // Save any changes made to the session data
 $session->save();
 
-
 ?>
diff --git a/templates/head.tpl b/templates/head.tpl
index 50cd7f6..2f8ed49 100644
--- a/templates/head.tpl
+++ b/templates/head.tpl
@@ -8,16 +8,16 @@
 
 	<script type="text/javascript" src="/js/cb.js"></script>
 
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/common.css" media="screen,print" />
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/sucs.css" media="screen" />
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/box.css" media="screen" />
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/downloads.css" media="screen" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/common.css" media="screen,print" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/sucs.css" media="screen" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/box.css" media="screen" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/downloads.css" media="screen" />
 {if isset($extra_styles)}
 {foreach from=$extra_styles item=style}
 	<link rel="stylesheet" type="text/css" href="{$style}" media="screen" />
 {/foreach}	
 {/if}
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/print.css" media="print" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/print.css" media="print" />
 
 {if isset($rss_url)}
 	<link rel="alternate" type="application/rss+xml" title="{$title}" href="{$rss_url}" />
@@ -31,8 +31,8 @@
 {if $refresh}	<meta http-equiv="REFRESH" content="{$refresh}" />{/if}
                         
 {if $action=="edit"}
-	<script language="javascript" type="text/javascript" src="{$baseurl}/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
-	<script language="javascript" type="text/javascript" src="{$baseurl}/js/tiny_mce.js"></script>
+	<script language="javascript" type="text/javascript" src="{$smarty.const.SUCS_BASEURL}/js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
+	<script language="javascript" type="text/javascript" src="{$smarty.const.SUCS_BASEURL}/js/tiny_mce.js"></script>
 {/if}
 
 {if isset($extra_scripts)}
@@ -42,14 +42,14 @@
 {/if}
 
 <!--[if IE]>
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/ie.css" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/ie.css" />
 <![endif]-->
 
 <!--[if lt IE 7]>
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/ielt7.css" media="screen" />
-	<link rel="stylesheet" type="text/css" href="{$baseurl}/css/boxie.css" media="screen" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/ielt7.css" media="screen" />
+	<link rel="stylesheet" type="text/css" href="{$smarty.const.SUCS_BASEURL}/css/boxie.css" media="screen" />
 
-	<script defer type="text/javascript" language="JavaScript" src="{$baseurl}/js/pngfix.js"></script>
+	<script defer type="text/javascript" language="JavaScript" src="{$smarty.const.SUCS_BASEURL}/js/pngfix.js"></script>
 
 <![endif]-->
 
diff --git a/templates/login.tpl b/templates/login.tpl
index 1dff7d3..d1bea99 100644
--- a/templates/login.tpl
+++ b/templates/login.tpl
@@ -3,7 +3,7 @@
 					<div>
 {if $session->loggedin}
 Logged in as {$session->username}<br />
-<a href="{$baseurl}/Options">Membership Options</a><br />
+<a href="{$smarty.const.SUCS_BASEURL}/Options">Membership Options</a><br />
 
 {if $session->email_forward}
 Mail forwarded to {$session->email_forward}<br />
diff --git a/templates/members.tpl b/templates/members.tpl
index fbc331a..8993d51 100644
--- a/templates/members.tpl
+++ b/templates/members.tpl
@@ -12,7 +12,7 @@
 <div class="boxhead"><h2>Membership Details for {$results[0].uid}</h2></div>
 <div class="boxcontent">
 {if isset($results[0].picture) }
-	<img class="emblem" src="{$baseurl}{$results[0].picture}" alt="Picture of {$results[0].uid}" />
+	<img class="emblem" src="{$smarty.const.SUCS_BASEURL}{$results[0].picture}" alt="Picture of {$results[0].uid}" />
 {/if}
 <dl class="member">
 	<dt>Username</dt>
diff --git a/templates/menu.tpl b/templates/menu.tpl
index 9ed0c7c..835131b 100644
--- a/templates/menu.tpl
+++ b/templates/menu.tpl
@@ -1,13 +1,13 @@
 	<div id="navigationC">
 	<ul>
 {foreach name=menu from=$menu key=name item=target}
-			<li>{if is_array($target)}<a href="{$baseurl}/{$name}"{if $select==$name} class="select"{/if}>{$name}</a>
+			<li>{if is_array($target)}<a href="{$smarty.const.SUCS_BASEURL}/{$name}"{if $select==$name} class="select"{/if}>{$name}</a>
 			<ul>
 {foreach name=submenu from=$target key=subitem item=subname}
-				<li><a href="{$baseurl}{$subname}"{if $subselect==$subitem} class="select"{/if}>{if $smarty.foreach.submenu.last}<span>{/if}{$subitem}{if $smarty.foreach.submenu.last}</span>{/if}</a></li>
+				<li><a href="{$smarty.const.SUCS_BASEURL}{$subname}"{if $subselect==$subitem} class="select"{/if}>{if $smarty.foreach.submenu.last}<span>{/if}{$subitem}{if $smarty.foreach.submenu.last}</span>{/if}</a></li>
 {/foreach}
 			</ul>
-			{else}<a href="{$baseurl}{$target}"{if $select==$name} class="select"{/if}><span>{$name}</span></a>{/if}</li>
+			{else}<a href="{$smarty.const.SUCS_BASEURL}{$target}"{if $select==$name} class="select"{/if}><span>{$name}</span></a>{/if}</li>
 {/foreach}
 	</ul>
 	</div>
diff --git a/templates/options.tpl b/templates/options.tpl
index 63f84fd..3162a33 100644
--- a/templates/options.tpl
+++ b/templates/options.tpl
@@ -48,7 +48,7 @@
 		<label for="hackergotchi">Hackergotchi:</label>
 		<span class="textinput" id="hackergotchi">
 {if $hackergotchi}
-			<img src="{$baseurl}/pictures/people/{$session->username}.png" />
+			<img src="{$smarty.const.SUCS_BASEURL}/pictures/people/{$session->username}.png" />
 	<form action="{$self}" method="post">
 		<input type="hidden" name="action" value="clearhackergotchi" />
 		<input type="submit" value="Clear Hackergotchi" />
diff --git a/templates/pastebin.tpl b/templates/pastebin.tpl
index 7812c7e..4005ef2 100644
--- a/templates/pastebin.tpl
+++ b/templates/pastebin.tpl
@@ -19,7 +19,7 @@
 {/if}
 
 {if $session->loggedin}
-	<form action="{$baseurl}{$path}" method="post">
+	<form action="{$smarty.const.SUCS_BASEURL}{$path}" method="post">
 		<div class="box">
 			<div class="boxhead"><h2>Paste an item</h2></div>
 			<div class="boxcontent">
-- 
GitLab