summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-10-23 17:08:41 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-10-23 17:08:41 -0400
commita580549d814adf828bf2bc6461a5572183ba114c (patch)
treec53a06e55039252e06839aff9929878c62507a3a /index.php
parentea13b80f93469d6d7790e02bfc4983918daa0315 (diff)
Refactor to *finally* get rid of the god-class "MessageManager".
Accomplish this largely by using singletons. Now, I know this breaks the "build", at least in PHP 5.2. But there's a lot here that's good stuff, so just wait for the next commit. Now, a *LOT* changed, as you can see by the size of the diff; it's about a day and a half of editing worth of editing. I'll describe a little of it, but I'm not going to go into a ton of detail, and won't bother trying to break it into separate commits (they're all so interconnected, it would be mental masturbation). 'Cause I'm the only one looking at it at this point. 1. MessageManager did 3 things: A. Act as a global site class. This has been moved into `lib/Site.class.php' B. Act as a registry for singletons. Now there's a `lib/Singleton.class.php' abstract class to let them manage themselves. : Note: With the possible exception of Database, none of the : : singletons *need* to be singletons, but to create : : multiple of them would be wasteful. : C. Check if the database conf file exists, and if it doesn't show an error message. This has been moved into index.php, and the message has been turned into a proper view. 2. Recognize `Auth.class.php' for what it is, a multiton. Rename Auth::getObj to Auth::getInstance to be consistant with singletons. 3. Make Site->baseUrl() (formerly `MessageManager->baseUrl()') figure the base URL each time, either with or without the database. This way we can be more flexible with initing the Template. 4. Init Template (now a singleton) sanely. We can now use views with no DB. I will use the above to shorten the below file changes: index.php: [1C] Also, just tidy up. src/controllers/Users.class.php: [1B] [2] src/lib/Controller.class.php: [4] src/lib/DB.class.php: [1B] [2] src/lib/Database.class.php: [1B] src/lib/Hasher.class.php: [1B] (new file) A singleton wrapper around `ext/PasswordHash.class.php', use bcrypt while exposing fewer internals. src/lib/Login.class.php: [1B] src/lib/MessageManager.class.php: [1] src/lib/Model.class.php: [1B] (new file) A abstract class for models, so they don't have to worry about initing the DB. src/lib/PluginManager.class.php: [1B] src/lib/Singleton.class.php: [1B] (new file) An abstract class that will take care of being a singleton for you; in order to make a class a singleton, just extend Singleton. src/lib/Site.class.php: [1A] [3] (new file) src/lib/View.class.php: [4] src/models/Auth.class.php: [2] [1B] Also make getUsername safely return false if the DB isn't connected. src/models/ContactMethod: extend `Model' src/views/Template.class.php: [1B] [3] src/views/pages/no-conf.html.php: [1C] src/views/pages/plugins/index.html.php: [1B] src/views/pages/users/500.html.php: [1B]
Diffstat (limited to 'index.php')
-rw-r--r--index.php49
1 files changed, 29 insertions, 20 deletions
diff --git a/index.php b/index.php
index ad16995..231b4d6 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,8 @@
<?php
-// What directory are we in on the server.
+// What directory are we in on the server? /////////////////////////////////////
define('BASEPATH', dirname(__FILE__));
+// Check for xss attacks. //////////////////////////////////////////////////////
$xss_file = BASEPATH.'/xss-check.php';
if (file_exists($xss_file)) {
require($xss_file);
@@ -11,14 +12,13 @@ if (file_exists($xss_file)) {
}
}
-// Decide where to look for things
-define('LIBPATH', BASEPATH.'/src/lib'.PATH_SEPARATOR.BASEPATH.'/src/ext');
-define('MODELPATH', BASEPATH.'/src/models');
-define('VIEWPATH', BASEPATH.'/src/views');// views are not objects
-define('CONTROLLERPATH', BASEPATH.'/src/controllers');
-define('PLUGINPATH', BASEPATH.'/src/plugins');
+// Decide where to look for things. ////////////////////////////////////////////
+define('LIBPATH', BASEPATH.'/src/lib'.PATH_SEPARATOR.BASEPATH.'/src/ext');
+define('MODELPATH', BASEPATH.'/src/models');
+define('VIEWPATH', BASEPATH.'/src/views');// views are not objects
+define('CONTROLLERPATH',BASEPATH.'/src/controllers');
+define('PLUGINPATH', BASEPATH.'/src/plugins');
-// Modify our include path to catch our class files.
set_include_path(get_include_path()
.PATH_SEPARATOR.LIBPATH
.PATH_SEPARATOR.MODELPATH
@@ -26,9 +26,10 @@ set_include_path(get_include_path()
.PATH_SEPARATOR.PLUGINPATH
);
-// Figure what page is trying to be loaded. Don't worry if we're
-// looking for a real file, if the requested page exists as a real
-// file, .htaccess won't even let us load this file.
+// Figure what page is trying to be loaded. ////////////////////////////////////
+// We don't have to do any check if it's a real file being looked for, if the
+// requested page exists as a real file, .htaccess won't even let us load
+// thisfile.
@$PAGE_RAW = $_GET['p'];
$PAGE_PARTS = explode('/', $PAGE_RAW);
$FILE = array_pop($PAGE_PARTS);
@@ -45,18 +46,26 @@ if ($PAGE=='') $PAGE = 'index';
define('PAGE', $PAGE); unset($PAGE);
define('PAGE_EXT', $EXT); unset($EXT);
-// Get ready
-//require_once('Model.class.php');
+// Include base MVC classes ////////////////////////////////////////////////////
+require_once('Model.class.php');
+require_once('View.class.php');
require_once('Controller.class.php');
-require_once('Router.class.php');
-require_once('ContactMethod.class.php');
-require('conf-contacts.php');
+// Check if we have a database configuration ///////////////////////////////////
+if (file_exists($conf_file)) {
+ new Database($conf_file);
+ session_start();
+} else {
+ $view = new View('no-conf');
+ $view->show(array());
+ exit();
+}
-global $mm;
-require_once('MessageManager.class.php');
-$mm = new MessageManager(BASEPATH.'/conf.php');
+// Kludgy ugly hacky hack //////////////////////////////////////////////////////
+require_once('ContactMethod.class.php');
+require(BASEPATH.'/conf-contacts.php');
-// Actually do stuff
+// Business ////////////////////////////////////////////////////////////////////
+require_once('Router.class.php');
$router = new Router(CONTROLLERPATH);
$router->route(PAGE);