summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-09-22 00:45:02 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-09-22 00:45:02 -0400
commit485cc0fad823d50ed07df15f629ff824d2332ece (patch)
tree041655882fafa27cbcc4a431f33695c37fa10313 /src
parentb58a642ab0463426b9f0d1d519bc5964b1453c3e (diff)
Implement actual plugin management. I was tired of doing the SQL queries by hand :)
Diffstat (limited to 'src')
-rw-r--r--src/controllers/Plugins.class.php57
-rw-r--r--src/lib/PluginManager.class.php7
-rw-r--r--src/views/pages/plugins.php61
-rw-r--r--src/views/pages/plugins/index.html.php38
4 files changed, 100 insertions, 63 deletions
diff --git a/src/controllers/Plugins.class.php b/src/controllers/Plugins.class.php
index 40d3fc0..e2b500c 100644
--- a/src/controllers/Plugins.class.php
+++ b/src/controllers/Plugins.class.php
@@ -1,5 +1,7 @@
<?php
require_once('Login.class.php');
+require_once('Plugin.class.php');
+require_once('PluginManager.class.php');
Router::register('plugins', 'Plugins');
@@ -10,7 +12,60 @@ class Plugins extends Controller {
$this->http401($routed, $remainder);
return;
}
- // TODO
+
+ $method = $_SERVER['REQUEST_METHOD'];
+ switch ($method) {
+ case 'PUT': $_POST = $_PUT;
+ case 'POST':
+ // We're PUTing an updated user index.
+ $this->update();
+ break;
+ }
+ $this->show_index();
+ }
+
+ private function update() {
+ global $mm;
+ $db = $mm->database();
+
+ if (isset($_POST['plugins'])) {
+ $string = $db->arrayToValue($_POST['plugins']);
+ $db->setSysConf('plugins', $string);
+ }
+
+ if (isset($_POST['config'])) {
+ foreach ($_POST['config'] as $plugin_name => $plugin) {
+ foreach ($plugin as $param => $value) {
+ $db->setPluginConf($plugin_name,
+ $param,
+ $value);
+ }
+ }
+ }
+ }
+
+ private function show_index() {
+ global $mm; $pm = $mm->pluginManager();
+ $all_plugins = $pm->listPlugins();
+ $enabled_plugins = $pm->getActivePlugins();
+
+ $plugin_data = array();
+ foreach ($all_plugins as $plugin_name) {
+ $plugin = array();
+ $plugin['name'] = $plugin_name;
+ $plugin['key'] = 'config['.$plugin_name.']';
+ $plugin['active'] =
+ in_array($plugin_name, $enabled_plugins);
+ $plugin['description'] =
+ $pm->staticHook($plugin_name, 'description');
+ $plugin['config'] =
+ $pm->staticHook($plugin_name, 'configList');
+ $plugin_data[] = $plugin;
+ }
+
+ $vars = array();
+ $vars['plugins'] = $plugin_data;
+ $this->showView('plugins/index', $vars);
}
public function http401($routed, $remainder) {
diff --git a/src/lib/PluginManager.class.php b/src/lib/PluginManager.class.php
index 417eecc..2e3dd2b 100644
--- a/src/lib/PluginManager.class.php
+++ b/src/lib/PluginManager.class.php
@@ -3,6 +3,7 @@
class PluginManager {
public $plugins = array();
private $loaded = false;
+
/**
* Return an instance of the plugin with $plugin_name
*/
@@ -87,4 +88,10 @@ class PluginManager {
}
return $ret;
}
+
+ public function staticHook($plugin_name, $hook) {
+ require_once("$plugin_name.class.php");
+ return call_user_func("$plugin_name::$hook");
+ }
+
}
diff --git a/src/views/pages/plugins.php b/src/views/pages/plugins.php
deleted file mode 100644
index a526871..0000000
--- a/src/views/pages/plugins.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-global $m;
-require_once('MessageManager.class.php');
-$m = new MessageManager($BASE.'/conf.php');
-
-$uid = $m->isLoggedIn();
-$auth = ($uid!==false) && ($m->getStatus($uid)>=2);
-
-if (!$auth) {
- $m->status('401 Unauthorized');
- $m->header('Unauthorized');
- $t = $m->template();
- $t->tag('h1',array(),"401: Unauthorized");
- $t->paragraph('You need to be logged in as an admin (at least user '.
- 'level 2) to edit global plugin settings. :(');
- $m->footer();
- exit();
-}
-
-$m->header('Administrator Plugin Management');
-
-$t = $m->template();
-
-$t->openTag('form',array('method'=>'post','action'=>$m->baseUrl().plugins));
-
-global $BASE;
-set_include_path(get_include_path().PATH_SEPARATOR."$BASE/src/plugins");
-
-$plugin_list = $m->getSysConf('plugins');
-$plugins = explode(',', $plugin_list);
-foreach ($plugins as $plugin) {
- $t->openFieldSet($plugin);
-
- require_once("$plugin.class.php");
- $description = call_user_func("$plugin::description");
- $params = call_user_func("$plugin::configList");
-
- $t->inputP($description);
-
- foreach ($params as $param => $type) {
- $name = $plugin.'_'.$param;
- if (isset($_POST[$name])) {
- $m->setPluginConf($plugin, $param, $_POST[$name]);
- }
- $value = $m->getPluginConf($plugin, $param);
- $hint = "Type: $type";
- switch ($type) {
- case 'text':
- case 'int':
- $t->inputText( $name, $param, $hint, $value); break;
- case 'password':
- $t->inputPassword($name, $param, $hint, $value); break;
- }
- }
- $t->closeFieldSet();
-}
-
-$t->tag('input', array('type'=>'submit', 'value'=>'Save'));
-$t->closeTag('form');
-$m->footer(); \ No newline at end of file
diff --git a/src/views/pages/plugins/index.html.php b/src/views/pages/plugins/index.html.php
index d62b555..1f89344 100644
--- a/src/views/pages/plugins/index.html.php
+++ b/src/views/pages/plugins/index.html.php
@@ -1,5 +1,41 @@
-<?php global $VARS;
+<?php global $VARS, $mm;
$t = $VARS['template'];
+$plugins = $VARS['plugins'];
+$db = $mm->database();
$t->header('Administrator Plugin Management');
$t->openTag('form',array('method'=>'post','action'=>$t->url('plugins')));
+
+foreach ($plugins as $plugin) {
+ $t->setRet(true);
+ $props = array('type'=>'checkbox',
+ 'name'=>'plugins[]',
+ 'id'=>'plugins_'.$plugin['name'],
+ 'value'=>$plugin['name']);
+ if ($plugin['active']==true) {
+ $props['checked'] = 'checked';
+ }
+ $box = $t->tag('input', $props);
+ $t->setRet(false);
+ $t->openFieldset($plugin['name'].$box);
+
+ $t->inputP($plugin['description']);
+ foreach ($plugin['config'] as $param => $type) {
+ $name = $plugin['key'].'['.$param.']';
+ $value = $db->getPluginConf($plugin['name'], $param);
+ $hint = "Type: $type";
+ switch ($type) {
+ case 'text':
+ case 'int':
+ $t->inputText( $name, $param, $hint, $value); break;
+ case 'password':
+ $t->inputPassword($name, $param, $hint, $value); break;
+ }
+ }
+ $t->closeFieldset();
+}
+
+$t->tag('input', array('type'=>'submit',
+ 'value'=>'Save/Update'));
+$t->closeTag('form');
+$t->footer();