summaryrefslogtreecommitdiff
path: root/src/controllers
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 /src/controllers
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 'src/controllers')
-rw-r--r--src/controllers/AuthPage.class.php4
-rw-r--r--src/controllers/Config.class.php2
-rw-r--r--src/controllers/Messages.class.php3
-rw-r--r--src/controllers/Plugins.class.php9
-rw-r--r--src/controllers/Users.class.php33
5 files changed, 26 insertions, 25 deletions
diff --git a/src/controllers/AuthPage.class.php b/src/controllers/AuthPage.class.php
index b31d938..1f46f72 100644
--- a/src/controllers/AuthPage.class.php
+++ b/src/controllers/AuthPage.class.php
@@ -1,5 +1,6 @@
<?php
require_once('Login.class.php');
+require_once('Auth.class.php');
Router::register('auth', 'AuthPage');
@@ -41,12 +42,11 @@ class AuthPage extends Controller {
$this->showView('auth/logout');
}
private function maybe_login() {
- global $mm;
$uid = Login::isLoggedIn();
if ($uid===false) {
$this->login();
} else {
- $username = $mm->database()->getUsername($uid);
+ $username = Auth::getInstance($uid)->getName();
$this->showView('auth/index',
array('username'=>$username));
}
diff --git a/src/controllers/Config.class.php b/src/controllers/Config.class.php
index 37d1f09..dc6a884 100644
--- a/src/controllers/Config.class.php
+++ b/src/controllers/Config.class.php
@@ -6,7 +6,7 @@ Router::register('config', 'Config', 'index');
class Config extends Controller {
public function index($routed, $remainder) {
$uid = Login::isLoggedIn();
- if ($uid===false || !Auth::getObj($uid)->isAdmin()) {
+ if ($uid===false || !Auth::getInstance($uid)->isAdmin()) {
$this->http401($routed, $remainder);
return;
}
diff --git a/src/controllers/Messages.class.php b/src/controllers/Messages.class.php
index d28d968..717e18e 100644
--- a/src/controllers/Messages.class.php
+++ b/src/controllers/Messages.class.php
@@ -1,5 +1,6 @@
<?php
require_once('Login.class.php');
+require_once('Auth.class.php');
Router::register('messages', 'Messages', 'index');
Router::register('messages/index', 'Messages', 'index');
@@ -41,7 +42,7 @@ class Messages extends Controller {
public function message($routed, $remainder) {
$uid = Login::isLoggedIn();
- if ($uid===false || !Auth::getObj($uid)->isUser()) {
+ if ($uid===false || !Auth::getInstance($uid)->isUser()) {
$this->http401($routed, $remainder);
return;
}
diff --git a/src/controllers/Plugins.class.php b/src/controllers/Plugins.class.php
index e2b500c..2ed6e7a 100644
--- a/src/controllers/Plugins.class.php
+++ b/src/controllers/Plugins.class.php
@@ -2,13 +2,15 @@
require_once('Login.class.php');
require_once('Plugin.class.php');
require_once('PluginManager.class.php');
+require_once('Auth.class.php');
+require_once('Database.class.php');
Router::register('plugins', 'Plugins');
class Plugins extends Controller {
public function index($routed, $remainder) {
$uid = Login::isLoggedIn();
- if ($uid===false || !Auth::getObj($uid)->isAdmin()) {
+ if ($uid===false || !Auth::getInstance($uid)->isAdmin()) {
$this->http401($routed, $remainder);
return;
}
@@ -25,8 +27,7 @@ class Plugins extends Controller {
}
private function update() {
- global $mm;
- $db = $mm->database();
+ $db = Database::getInstance();
if (isset($_POST['plugins'])) {
$string = $db->arrayToValue($_POST['plugins']);
@@ -45,7 +46,7 @@ class Plugins extends Controller {
}
private function show_index() {
- global $mm; $pm = $mm->pluginManager();
+ $pm = PluginManager::getInstance();
$all_plugins = $pm->listPlugins();
$enabled_plugins = $pm->getActivePlugins();
diff --git a/src/controllers/Users.class.php b/src/controllers/Users.class.php
index 447a70f..9978ef8 100644
--- a/src/controllers/Users.class.php
+++ b/src/controllers/Users.class.php
@@ -2,6 +2,8 @@
require_once('Login.class.php');
require_once('Auth.class.php');
require_once('DB.class.php');
+require_once('PluginManager.class.php');
+require_once('Database.class.php');
Router::register('users/new' , 'Users', 'new_user');
Router::register('users/index', 'Users', 'index_file');
@@ -73,9 +75,8 @@ class Users extends Controller {
}
if (!isset($vars['errors'])) $vars['errors'] = array();
- global $mm;
- $pm = $mm->pluginManager();
- $db = $mm->database();
+ $db = Database::getInstance();
+ $pm = PluginManager::getInstance();
$vars['antispam_html'] = $pm->callHook('antispam_html');
$vars['userlist'] = $db->getSysConf('anon_userlist');
@@ -83,9 +84,8 @@ class Users extends Controller {
}
public function individual($routed, $remainder) {
- global $mm; // also used for pluginmanager
- $db = $mm->database();
- $pm = $mm->pluginManager();
+ $db = Database::getInstance();
+ $pm = PluginManager::getInstance();
$username = implode('/', $remainder);
if ($username == 'all') {
@@ -97,7 +97,7 @@ class Users extends Controller {
$vars = array();
if (count($uids)<2) {
- $user = Auth::getObj($uid);
+ $user = Auth::getInstance($uid);
if ($user->isGroup()) $uid = false; // ignore groups.
@@ -127,7 +127,7 @@ class Users extends Controller {
$vars['users'] = array();
foreach ($uids as $uid) {
- $vars['users'][] = Auth::getObj($uid);
+ $vars['users'][] = Auth::getInstance($uid);
}
$vars['username'] = $username;
$vars['config_options'] = $config_options;
@@ -155,9 +155,8 @@ class Users extends Controller {
* explained.
*/
private function create_user() {
- global $mm;
- $db = $mm->database();
- $pm = $mm->pluginManager();
+ $db = Database::getInstance();
+ $pm = PluginManager::getInstance();
$vars = array();
@$vars['username' ] = $_POST['auth_name'];
@@ -238,8 +237,8 @@ class Users extends Controller {
// Change information //////////////////////////////////////////
$config_options = array();
- global $mm;
- $mm->pluginManager()->callHook('userConfig', &$config_options);
+ $pm = PluginManager::getInstance();
+ $pm->callHook('userConfig', &$config_options);
foreach ($config_options as $group=>$options) {
foreach ($options as $option) {
@@ -311,9 +310,9 @@ class Users extends Controller {
* This will show the user index.
*/
private function show_index($routed, $remainder) {
- global $mm; $db = $mm->database();
+ $db = Database::getInstance();
- $logged_in_user = Auth::getObj(Login::isLoggedIn());
+ $logged_in_user = Auth::getInstance(Login::isLoggedIn());
$anon_userlist = $db->getSysConf('anon_userlist')=='true';
if (!$anon_userlist && !$logged_in_user->isUser()) {
$this->http401($routed, $remainder);
@@ -339,7 +338,7 @@ class Users extends Controller {
return array('key'=>$key, 'name'=>$name, 'type'=>$type);
}
private function getIndexAttribs() {
- $user = Auth::getObj(Login::isLoggedIn());
+ $user = Auth::getInstance(Login::isLoggedIn());
$attribs = array();
$attribs[] = $this->attrib('auth_uid', 'UID');
@@ -361,7 +360,7 @@ class Users extends Controller {
}
private function registrationOpen() {
- global $mm; $db = $mm->database();
+ $db = Database::getInstance();
$val = $db->getSysConf('registration_open');
switch ($val) {
case 'true': return true;