From 0770b19b04a227b5e5a41c9dbed98b0c1a0dcb82 Mon Sep 17 00:00:00 2001
From: Shish <webmaster@shishnet.org>
Date: Sun, 4 Jan 2009 07:57:54 -0800
Subject: [PATCH] more scoreyness

---
 core/config.class.php | 43 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)

diff --git a/core/config.class.php b/core/config.class.php
index a0ddcbe3..a2e21bc9 100644
--- a/core/config.class.php
+++ b/core/config.class.php
@@ -77,11 +77,45 @@ abstract class BaseConfig implements Config {
 
 
 /*
- * A class for easy access to the 'config' table, can always be accessed
- * through "global $config;"
+ * Loads the config list from a PHP file; the file should be in the format:
+ *
+ *  <?php
+ *  $config['foo'] = "bar";
+ *  $config['baz'] = "qux";
+ *  ?>
+ */
+class StaticConfig extends BaseConfig {
+	public function __construct($filename) {
+		if(file_exists($filename)) {
+			require_once $filename;
+			if(isset($config)) {
+				$this->values = $config;
+			}
+			else {
+				throw new Exception("Config file '$filename' doesn't contain any config");
+			}
+		}
+		else {
+			throw new Exception("Config file '$filename' missing");
+		}
+	}
+
+	public function save($name=null) {
+		// static config is static
+	}
+}
+
+
+/*
+ * Loads the config list from a table in a given database, the table should
+ * be called config and have the schema:
+ *
+ *  CREATE TABLE config(
+ *      name VARCHAR(255) NOT NULL,
+ *      value TEXT
+ *  );
  */
 class DatabaseConfig extends BaseConfig {
-	var $values = array();
 	var $database = null;
 
 	/*
@@ -102,11 +136,8 @@ class DatabaseConfig extends BaseConfig {
 			}
 		}
 		else {
-			// does "or update" work with sqlite / postgres?
-			$this->database->db->StartTrans();
 			$this->database->Execute("DELETE FROM config WHERE name = ?", array($name));
 			$this->database->Execute("INSERT INTO config VALUES (?, ?)", array($name, $this->values[$name]));
-			$this->database->db->CommitTrans();
 		}
 	}
 }