summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Auth.class.php110
-rw-r--r--src/lib/ContactMethod.class.php30
-rw-r--r--src/lib/Database.class.php4
-rw-r--r--src/lib/Group.class.php23
-rw-r--r--src/lib/Login.class.php2
-rw-r--r--src/lib/MessageHandler.class.php49
-rw-r--r--src/lib/MessageManager.class.php14
-rw-r--r--src/lib/Model.class.php3
-rw-r--r--src/lib/PluginManager.class.php16
-rw-r--r--src/lib/SenderBroadcast.class.php7
-rw-r--r--src/lib/SenderPrivate.class.php7
-rw-r--r--src/lib/User.class.php25
12 files changed, 12 insertions, 278 deletions
diff --git a/src/lib/Auth.class.php b/src/lib/Auth.class.php
deleted file mode 100644
index e49ebf7..0000000
--- a/src/lib/Auth.class.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-require_once('MessageManager.class.php');
-
-class Auth {
- protected $mm = null;
- protected $uid = false;
- public function __construct($uid) {
- global $mm;
- $this->mm = $mm;
- $this->uid = $uid;
- }
- public function getUID() {
- return $this->uid;
- }
-
- /**********************************************************************\
- * The 'auth' table. *
- \**********************************************************************/
-
- // Row Type ////////////////////////////////////////////////////////////
- /**
- * @return 0=unverified 1=user 2=admin 3=group
- */
- protected function getType() {
- $type = $this->mm->getStatus($this->uid);
- return $type;
- }
- protected function setType($type) {
- $logged_in_uid = $this->mm->isLoggedIn();
- $logged_in_obj = $this->mm->getAuthObj($logged_in_uid);
- $is_admin = $logged_in_obj->isAdmin();
- if (!$is_admin) return false;
-
- return $this->mm->setStatus($this->uid, $type);
- }
- public function isUser() {
- $type = $this->getType();
- return ($type===1) || ($type===2);
- }
- public function isAdmin() {
- $type = $this->getType();
- return ($type===2);
- }
- public function isGroup() {
- $type = $this->getType();
- return ($type===3);
- }
- public function setUser($is_user) {
- $is_user = ($is_user?true:false);
- if ($this->isUser() != $is_user) {
- $this->setType($is_user?1:0);
- }
- }
- public function setAdmin($is_admin) {
- $is_admin = ($is_admin?true:false);
- $is_user = $this->isUser();
- $this->setType($is_admin?2:($is_user?1:0));
- }
-
- // Permissions /////////////////////////////////////////////////////////
- public function canRead() {
- $logged_in_uid = $this->mm->isLoggedIn();
- $is_me = ($logged_in_uid === $this->uid);
-
- $logged_in_obj = $this->mm->getAuthObj($logged_in_uid);
- $is_user = $logged_in_obj->isUser();
-
- return ($is_me || $is_user);
- }
- public function canEdit() {
- $logged_in_uid = $this->mm->isLoggedIn();
- $is_me = ($logged_in_uid === $this->uid);
-
- $logged_in_obj = $this->mm->getAuthObj($logged_in_uid);
- $is_admin = $logged_in_obj->isAdmin();
-
- return ($is_me || $is_admin);
- }
-
- // [user|group]name ////////////////////////////////////////////////////
- public function getName() {
- if (!$this->canRead()) return false;
- return $this->mm->getUsername($this->uid);
- }
- public function setName($new_name) {
- if (!$this->canEdit()) return false;
- return $this->mm->setUsername($this->uid, $new_name);
- }
-
- /**********************************************************************\
- * The 'users' table. *
- \**********************************************************************/
-
- public function getConf($setting) {
- if (!$this->canRead()) return false;
- return $this->mm->getUserConf($this->uid, $setting);
- }
- public function setConf($setting, $value) {
- if (!$this->canEdit()) return false;
- return $this->mm->setUserConf($this->uid, $setting, $value);
- }
- public function getConfArray($setting) {
- $string = $this->getConf($setting);
- return $this->mm->valueToArray($string);
- }
- public function setConfArray($setting, $list) {
- $string = $this->mm->arrayToValue($list);
- return $this->setConf($setting, $string);
- }
-}
diff --git a/src/lib/ContactMethod.class.php b/src/lib/ContactMethod.class.php
deleted file mode 100644
index b01e7d3..0000000
--- a/src/lib/ContactMethod.class.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-global $CONTACT_METHODS;
-if (!isset($CONTACT_METHODS)) {
- $CONTACT_METHODS = array();
-}
-
-class ContactMethod {
- public $verb_slug = ''; // sms
- public $addr_slug = ''; // phone
- public $verb_text = ''; // text message
- public $addr_text = ''; // phone number
-
- public $handler = null;
-
- public function __construct($verb_slug, $addr_slug,
- $verb_text, $addr_text)
- {
- $this->verb_slug = $verb_slug;
- $this->addr_slug = $addr_slug;
- $this->verb_text = $verb_text;
- $this->addr_text = $addr_text;
-
- global $CONTACT_METHODS;
- $CONTACT_METHODS[$verb_slug] = $this;
- }
- public function setHandler($handler) {
- $this->handler = $handler;
- }
-}
diff --git a/src/lib/Database.class.php b/src/lib/Database.class.php
index 03c227f..b7e5bcd 100644
--- a/src/lib/Database.class.php
+++ b/src/lib/Database.class.php
@@ -381,7 +381,7 @@ class Database {
* key-value store in the database.
*/
public static function arrayToValue($list) {
- $out_list = $this->sanitizeArray($list);
+ $out_list = self::sanitizeArray($list);
return ','.implode(',', $out_list).',';
}
/**
@@ -389,7 +389,7 @@ class Database {
*/
public static function valueToArray($value) {
$raw_list = explode(',', $value);
- $out_list = $this->sanitizeArray($raw_list);
+ $out_list = self::sanitizeArray($raw_list);
return $out_list;
}
diff --git a/src/lib/Group.class.php b/src/lib/Group.class.php
deleted file mode 100644
index 96c5e2c..0000000
--- a/src/lib/Group.class.php
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-require_once('Auth.class.php');
-
-class User extends Auth {
- public function __construct($uid) {
- parent::__construct($uid);
- }
- public function getUID() {
- return $this->uid;
- }
-
- /**********************************************************************\
- * The 'auth' table. *
- \**********************************************************************/
-
- /**********************************************************************\
- * The 'users' table. *
- \**********************************************************************/
-
- public function getMembers() {
- return $this->mm->getUsersInGroup($this->getName());
- }
-}
diff --git a/src/lib/Login.class.php b/src/lib/Login.class.php
index 26d11dd..14e3ecb 100644
--- a/src/lib/Login.class.php
+++ b/src/lib/Login.class.php
@@ -1,6 +1,8 @@
<?php
class Login {
+ public function __construct() {}
+
public static function login($username, $password) {
global $mm;
$uid = $mm->database()->getUID($username);
diff --git a/src/lib/MessageHandler.class.php b/src/lib/MessageHandler.class.php
deleted file mode 100644
index 1fa9faf..0000000
--- a/src/lib/MessageHandler.class.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-class MessageHandler {
- public function __constructor() {
-
- }
- public function loadPlugin($plugin_name) {
- global $m;
-
- require_once("$plugin.class.php");
- $obj = new $plugin;
- $params = call_user_func("$plugin::configList");
- foreach ($params as $param => $type) {
- $value = $m->getPluginConf($plugin, $param);
- if ($value!==false) {
- switch ($type) {
- case 'text':
- case 'password':
- $value = "$value";
- break;
- case 'int':
- $value = (int)$value;
- break;
- }
- $obj->configSet($param, $value);
- }
- }
- return $obj;
- }
- public function main() {
- global $BASE;
-
- $private_senders = array();
- $broadcast_senders = array();
-
- $plugin_list = $m->getSysConf('plugins');
- $plugins = explode(',', $plugin_list);
- foreach ($plugins as $plugin) {
- require_once("$plugin.class.php");
- if (is_subclass_of($plugin, 'SenderPrivate')) {
- $private_senders[] = $this->loadPlugin($plugin);
- }
- if (is_subclass_of($plugin, 'SenderBroadcast')) {
- $broadcast_senders[] = $this->loadPlugin($plugin);
- }
- }
- //foreach ($private_senders)
- }
-} \ No newline at end of file
diff --git a/src/lib/MessageManager.class.php b/src/lib/MessageManager.class.php
index 645643e..d327eb7 100644
--- a/src/lib/MessageManager.class.php
+++ b/src/lib/MessageManager.class.php
@@ -82,18 +82,4 @@ class MessageManager {
}
return $this->base;
}
-
- public function getAuthObj($uid) {
- if (!isset($this->users[$uid])) {
- $is_group = ($this->database()->getStatus($uid)===3);
- if ($is_group) {
- require_once('Group.class.php');
- $this->users[$uid] = new Group($uid);
- } else {
- require_once('User.class.php');
- $this->users[$uid] = new User($uid);
- }
- }
- return $this->users[$uid];
- }
}
diff --git a/src/lib/Model.class.php b/src/lib/Model.class.php
deleted file mode 100644
index 523976e..0000000
--- a/src/lib/Model.class.php
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-class Model {}
diff --git a/src/lib/PluginManager.class.php b/src/lib/PluginManager.class.php
index 22d7b0c..417eecc 100644
--- a/src/lib/PluginManager.class.php
+++ b/src/lib/PluginManager.class.php
@@ -7,13 +7,13 @@ class PluginManager {
* Return an instance of the plugin with $plugin_name
*/
public function loadPlugin($plugin_name) {
- global $mm;
+ global $mm; $db = $mm->database();
require_once("$plugin_name.class.php");
$obj = new $plugin_name;
$params = call_user_func("$plugin_name::configList");
foreach ($params as $param => $type) {
- $value = $mm->getPluginConf($plugin_name, $param);
+ $value = $db->getPluginConf($plugin_name, $param);
if ($value!==false) {
switch ($type) {
case 'text':
@@ -52,18 +52,18 @@ class PluginManager {
* Return an array of enabled plugin names.
*/
public function getActivePlugins() {
- global $mm;
- $string = $mm->getSysConf('plugins');
- return $mm->valueToArray($string);
+ global $mm; $db = $mm->database();
+ $string = $db->getSysConf('plugins');
+ return $db->valueToArray($string);
}
/**
* Set the enabled plugins.
*/
public function setActivePlugins($plugins) {
- global $mm;
- $string = $mm->arrayToValue($plugins);
- return $mm->setSysConf('plugins', $string);
+ global $mm; $db = $mm->database();
+ $string = $db->arrayToValue($plugins);
+ return $db->setSysConf('plugins', $string);
}
/**
diff --git a/src/lib/SenderBroadcast.class.php b/src/lib/SenderBroadcast.class.php
deleted file mode 100644
index 7510ff2..0000000
--- a/src/lib/SenderBroadcast.class.php
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-require_once('Plugin.class.php');
-
-abstract class SenderBroadcast extends Plugin {
- public abstract function send($id, $subject, $body);
-}
diff --git a/src/lib/SenderPrivate.class.php b/src/lib/SenderPrivate.class.php
deleted file mode 100644
index e6f2807..0000000
--- a/src/lib/SenderPrivate.class.php
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-require_once('Plugin.class.php');
-
-abstract class SenderPrivate extends Plugin {
- public abstract function send($to, $id, $subject, $body);
-}
diff --git a/src/lib/User.class.php b/src/lib/User.class.php
deleted file mode 100644
index c1888b5..0000000
--- a/src/lib/User.class.php
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-require_once('Auth.class.php');
-
-class User extends Auth {
- public function __construct($uid) {
- parent::__construct($uid);
- }
- public function getUID() {
- return $this->uid;
- }
-
- /**********************************************************************\
- * The 'auth' table. *
- \**********************************************************************/
-
- public function setPassword($password) {
- if (!$this->canEdit()) return false;
- return $this->mm->setPassword($this->uid, $password);
- }
-
- /**********************************************************************\
- * The 'users' table. *
- \**********************************************************************/
-
-}