From 461d5e51c171543a87fc0c62f8eb9f7cb6b2b578 Mon Sep 17 00:00:00 2001
From: Denis Walker <dez@sucs.org>
Date: Mon, 26 Nov 2007 16:24:15 +0000
Subject: [PATCH] Makes settings constants rather than an array

---
 components/contents.php  |  8 ++++----
 components/library.php   |  2 +-
 components/milliways.php |  2 +-
 components/mw.php        |  6 +++---
 components/options.php   |  5 ++---
 components/pagemap.php   |  4 ++--
 components/pastebin.php  |  2 +-
 components/planet.php    |  2 +-
 components/static.php    | 10 +++++-----
 htdocs/index.php         | 27 +++++++++++++--------------
 settingstemplate         | 19 +++++++++++++------
 11 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/components/contents.php b/components/contents.php
index 64e673f..395c32f 100644
--- a/components/contents.php
+++ b/components/contents.php
@@ -1,15 +1,15 @@
 <?php
 
 function listdir($mypath, $recurse, $summaries) {
-	global $DB, $settings;
+	global $DB;
 
-	$dirlist = @scandir($settings['base']."static".$mypath);
+	$dirlist = @scandir(SUCS_BASEDIR."static".$mypath);
 	$output = array();
 	if (is_array($dirlist)) foreach($dirlist as $file) {
 		// Hide files starting with a .
 		if ($file[0]!=".") {
 			$element = array();
-			if (!is_dir($settings['base']."static".$mypath."/".$file)) {
+			if (!is_dir(SUCS_BASEDIR."static".$mypath."/".$file)) {
 				$pagename = ereg_replace("\.txt", "", $file);
 				if ($summaries) $element['summary'] = $DB->GetOne("select summary from static where path=?", array($mypath."/".$pagename));
 				if ($pagename!=@$lastdir) $output[$pagename]=$element;
@@ -36,7 +36,7 @@ if ($path==$component['path']) {
 	include("static.php");
 
 	if ($title!="File not found") {
-		if (!is_dir($settings['base']."static".$path)) {
+		if (!is_dir(SUCS_BASEDIR."static".$path)) {
 			$pos = strrpos($path, "/");
 			$path = substr($path, 0, $pos);
 		}
diff --git a/components/library.php b/components/library.php
index b6cfee1..057471a 100644
--- a/components/library.php
+++ b/components/library.php
@@ -87,7 +87,7 @@ if (isset($_REQUEST['search']) && (trim($_REQUEST['search']) != "")) {
 			// someone wants to check out this book
 			$msgbody = "User {$session->username} would like to take out";
 			$msgbody .= " {$book['title']} by {$book['author']} from the library.\n\n";
-			$msgbody .= "Visit https://$settings['preferred_hostname']$path to process this request.";
+			$msgbody .= "Visit https://".SUCS_PREFERRED_HOSTNAME."$path to process this request.";
 			mail($librarian_mail, "Book Request", $msgbody);
 			
 			$smarty->assign("checkout_request", true);
diff --git a/components/milliways.php b/components/milliways.php
index 98ac220..ef9da2c 100644
--- a/components/milliways.php
+++ b/components/milliways.php
@@ -12,7 +12,7 @@ foreach ($wholist as $person) {
 }
 
 $smarty->assign("people",$people);
-$output = $smarty->fetch($settings['base']."templates/milliways.tpl");
+$output = $smarty->fetch(SUCS_BASEDIR."templates/milliways.tpl");
 $smarty->assign("title", "Milliways");
 $smarty->assign("body", $output);
 $smarty->assign("refresh", 120);
diff --git a/components/mw.php b/components/mw.php
index bc3bc01..577df89 100755
--- a/components/mw.php
+++ b/components/mw.php
@@ -176,7 +176,7 @@ if (isset($pathlist[3])) {
 				$sub = fetch_sub($all, $all[$artno]['ref']);
 				$smarty->assign_by_ref("articles", $sub);
 				$smarty->assign("howmany",count($sub));
-				$output = $smarty->fetch($settings['base']."templates/mw-article.tpl");
+				$output = $smarty->fetch(SUCS_BASEDIR."templates/mw-article.tpl");
 
 			}
 		} else {
@@ -200,7 +200,7 @@ if (isset($pathlist[3])) {
 
 			$smarty->assign("title", htmlentities("Milliways - Folder $name"));
 			$smarty->assign_by_ref("articles", $top);
-			$output = $smarty->fetch($settings['base']."templates/mw-list.tpl");
+			$output = $smarty->fetch(SUCS_BASEDIR."templates/mw-list.tpl");
 		}
 	} else {
 		$output = "Error, no such folder $name";
@@ -218,7 +218,7 @@ if (isset($pathlist[3])) {
 		$folders[$k]['lastpost'] = $lastone['date'];
 	}
 	$smarty->assign("title", "Milliways - Topic List");
-	$output = $smarty->fetch($settings['base']."templates/mw-folders.tpl");
+	$output = $smarty->fetch(SUCS_BASEDIR."templates/mw-folders.tpl");
 	$smarty->assign("body", $output);
 }
 
diff --git a/components/options.php b/components/options.php
index d439955..4c1356b 100644
--- a/components/options.php
+++ b/components/options.php
@@ -143,8 +143,7 @@ function clearHackergotchi() {
 
 // construct the filesystem path to a user's hackergotchi picture
 function hackergotchiPath($username) {
-	global $settings; 
-	$path = $settings['base']."htdocs/pictures/people/".$username.".png"; 
+	$path = SUCS_BASEDIR."htdocs/pictures/people/".$username.".png"; 
 	return $path;
 }
 
@@ -217,7 +216,7 @@ if ($session->loggedin === TRUE) {
 	// Some checking could be done here to ensure we have a members record. Ideally we should
 	// be able to assume this though if they are logged in.
 
-	if (is_file($settings['base']."htdocs/pictures/people/".$session->username.".png")) $smarty->assign('hackergotchi', TRUE);
+	if (is_file(SUCS_BASEDIR."htdocs/pictures/people/".$session->username.".png")) $smarty->assign('hackergotchi', TRUE);
 
 
 	$member = $sucsDB->GetRow("select * from members where username='".$session->username."'");
diff --git a/components/pagemap.php b/components/pagemap.php
index 801a327..366ec72 100644
--- a/components/pagemap.php
+++ b/components/pagemap.php
@@ -9,7 +9,7 @@ if (@$pathlist[3] == "Edit") {
 		$res = $DB->GetAll("SELECT * FROM pagemap where id=?", array($id));
 		if ($res && count($res) > 0) {
 			$smarty->assign("oldmap",$res[0]);
-			$output = $smarty->fetch($settings['base']."templates/pagemap_edit.tpl");
+			$output = $smarty->fetch(SUCS_BASEDIR."templates/pagemap_edit.tpl");
 		} else {
 			header("Location: /Admin/Pagemap");
 			exit;
@@ -22,7 +22,7 @@ if (@$pathlist[3] == "Edit") {
 
 if (!isset($output)) {
 	$smarty->assign("map",$DB->GetAll("SELECT * FROM pagemap ORDER BY depth, path"));
-	$output = $smarty->fetch($settings['base']."templates/pagemap.tpl");
+	$output = $smarty->fetch(SUCS_BASEDIR."templates/pagemap.tpl");
 }
 $smarty->assign("title", "Page Map");
 $smarty->assign("body", $output);
diff --git a/components/pastebin.php b/components/pastebin.php
index c90fd0b..532b1d9 100755
--- a/components/pastebin.php
+++ b/components/pastebin.php
@@ -230,7 +230,7 @@ if(!empty($pblang) && $pblang != 'NONE') {
 $smarty->assign('pasteLanguages', $LANGUAGES);
 
 // Load templates etc
-$smarty->assign("extra_styles", array("$settings['baseurl']/css/pastebin.css"));
+$smarty->assign("extra_styles", array(SUCS_BASEURL"/css/pastebin.css"));
 $result = $smarty->fetch('pastebin.tpl');
 $sidebar = $smarty->fetch('pastebin-sidebar.tpl');
 $smarty->assign('title', 'PasteBin');
diff --git a/components/planet.php b/components/planet.php
index b10274b..32253c3 100644
--- a/components/planet.php
+++ b/components/planet.php
@@ -4,7 +4,7 @@ $smarty->assign("title", "Planet SUCS");
 $smarty->assign("rss_url", "http://planet.sucs.org/rss20.xml");
 $smarty->assign("atom_url", "http://planet.sucs.org/atom.xml");
 // Read planet output from where (we hope) Planet wrote it
-$body = file_get_contents($settings['base']."static/Community/Planet.txt");
+$body = file_get_contents(SUCS_BASEDIR."static/Community/Planet.txt");
 $smarty->assign("body", $body);
 
 ?>
diff --git a/components/static.php b/components/static.php
index 6dbe955..0594b6e 100644
--- a/components/static.php
+++ b/components/static.php
@@ -5,11 +5,11 @@
 $permission = "html";
 
 // Get the right filename...
-$myfile = $settings['base']."static".$path.$language['file'].".txt";
-$secondaryfile = $settings['base']."static".$path.$language['file']."-secondary.txt";
+$myfile = SUCS_BASEDIR."static".$path.$language['file'].".txt";
+$secondaryfile = SUCS_BASEDIR."static".$path.$language['file']."-secondary.txt";
 if (!file_exists($myfile)) {
-	$myfile = $settings['base']."static$path.txt";
-	$secondaryfile = $settings['base']."static$path-secondary.txt";
+	$myfile = SUCS_BASEDIR."static$path.txt";
+	$secondaryfile = SUCS_BASEDIR."static$path-secondary.txt";
 	// If the file doesn't exist...
 	if (!file_exists($myfile)) {
 		if (isset($session->groups[$permission]) && @$_REQUEST['action']=="create") {
@@ -31,7 +31,7 @@ if (!file_exists($myfile)) {
 			} else {
 				// ...serve a 404 error
 				header("HTTP/1.1 404 Not Found");
-				$body = @file_get_contents($settings['base']."static/404.txt");
+				$body = @file_get_contents(SUCS_BASEDIR."static/404.txt");
 				$smarty->assign("pathlist", array("", "Error"));
 				$title = "File not found";
 				$smarty->assign("title", $title);
diff --git a/htdocs/index.php b/htdocs/index.php
index 38f659f..140696e 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -15,7 +15,7 @@ if (@$displaytime) {
    -------------------------------------------------------- */
 
 include("settings.php");
-if (!(isset($settings))) {
+if (!defined('SUCS_BASEDIR')) {
 	echo "Website unconfigured";
 	exit();
 }
@@ -28,23 +28,22 @@ require("../lib/error.php");
 
 
 // Include the Smarty templating engine
-define('SMARTY_DIR', '/usr/share/Smarty/');
-require("/usr/share/Smarty/Smarty.class.php");
+require(SMARTY_PATH."Smarty.class.php");
 $smarty = new Smarty;
-$smarty->template_dir = $settings['base']."templates";
-$smarty->compile_dir = $settings['base']."templates_c";
-$smarty->plugins_dir[] = $settings['base']."plugins";
+$smarty->template_dir = SUCS_BASEDIR."templates";
+$smarty->compile_dir = SUCS_BASEDIR."templates_c";
+$smarty->plugins_dir[] = SUCS_BASEDIR."plugins";
 
-$smarty->assign("baseurl", $settings['baseurl']);
+$smarty->assign("baseurl", SUCS_BASEURL);
 
 // Initialise the database
-require("/var/www/adodb/adodb.inc.php");
-$DB = NewADOConnection('postgres8');
-$DB->Connect('dbname='.$settings['dbname']);
+require(ADODB_DIR."adodb.inc.php");
+$DB = NewADOConnection(SUCS_DBTYPE);
+$DB->Connect('dbname='.SUCS_DBNAME);
 $DB->SetFetchMode(ADODB_FETCH_ASSOC);
 
 // Include the session library
-require($settings['base']."lib/session.php");
+require(SUCS_BASEDIR."lib/session.php");
 $session = new Session;
 $smarty->assign_by_ref("session", $session);
 
@@ -90,7 +89,7 @@ $smarty->assign("language", $language);
 // SSL?
 $ssl_path = @$_SERVER['REQUEST_URI'];
 if (($n=strpos($ssl_path,"?"))!==FALSE) $ssl_path=substr($ssl_path,0,$n);
-$ssl_url = "https://".$settings['preferred_hostname'].$ssl_path;
+$ssl_url = "https://".SUCS_PREFERRED_HOSTNAME.$ssl_path;
 $smarty->assign("ssl_url", $ssl_url);
 
 
@@ -130,10 +129,10 @@ if ($path == "") $path="/";
 $smarty->assign("title", "Set Me");
 $smarty->assign("body", "Empty Body");
 
-include($settings['base']."components/menu.php");
+include(SUCS_BASEDIR."components/menu.php");
 
 // Load the component
-$comppath = $settings['base']."components/".$component['component'].".php";
+$comppath = SUCS_BASEDIR."components/".$component['component'].".php";
 $compoutput = "";
 if (file_exists($comppath)) {
 	ob_start();
diff --git a/settingstemplate b/settingstemplate
index 7dd5119..430cdd4 100644
--- a/settingstemplate
+++ b/settingstemplate
@@ -1,15 +1,22 @@
 <?php
-$settings = array(
 // root directory for website - *with* trailing /
-"base" => "$BASEDIR/",
+define('SUCS_BASEDIR', '$BASEDIR/');
 
 // path to root dir on web server
-"baseurl" => "/~$USERNAME/sucssite",
+define('SUCS_BASEURL', '/~$USERNAME/sucssite');
 
 // Hostname of the server
-"preferred_hostname" => "sucs.org",
+define('SUCS_PREFERRED_HOSTNAME', 'sucs.org');
+
+// Path of ADOdb
+define('ADODB_DIR', '/usr/share/adodb/');
+
+// Path of Smarty
+define('SMARTY_DIR', '/usr/share/Smarty/');
+
+// Database type
+define('SUCS_DBTYPE', 'postgres8');
 
 // Name of the database
-"dbname" => "beta"
-);
+define('SUCS_DBNAME', 'beta');
 ?>
-- 
GitLab