/branches/coding-style/admin/panels/plugin/admin.plugin.php
PHP | 127 lines | 73 code | 10 blank | 44 comment | 8 complexity | 935fc2bd9d38010228a788d4b27a73af MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MIT
- <?php
- /**
- * Plugin control panel
- *
- * @author NoWhereMan <real_nowhereman at users dot sf dot com>
- */
- /*
- function admin_plugin_adminheader() {
- $f = ADMIN_DIR .'/panels/plugin/admin.plugin.js';
- echo '<script src="'.$f.'" type="text/javascript"></script>';
- }
- add_action('wp_head', 'admin_plugin_adminheader');
- */
- /**
- * Enter description here...
- *
- */
- class admin_plugin extends AdminPanel {
- var $panelname = 'plugin';
- var $actions = array('default' => true);
- }
- class admin_plugin_default extends AdminPanelAction {
- var $commands = array('enable', 'disable');
- var $errors = array();
-
- /**
- * Enter description here...
- *
- */
- function setup() {
- $this->pluginid = isset($_GET['plugin'])? $_GET['plugin'] : null;
- $pi =& new plugin_indexer;
- $plist = $pi->getList();
- sort($plist);
- $this->smarty->assign('pluginlist', $plist);
- $this->errors = @$pi->getEnableds(true);
- $this->fp_plugins = $pi->enabledlist;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $id
- * @return int
- */
- function dodisable($id) {
- $fp_plugins = $this->fp_plugins;
- $success = -1;
- if (plugin_exists($id)) {
- $success = 1;
- if (false !== $i = array_search($id, $fp_plugins)) {
- unset($fp_plugins[$i]);
- sort($fp_plugins); /* compact indices */
- do_action('deactivate_'. $id);
- $success = system_save(CONFIG_DIR .'plugins.conf.php', compact('fp_plugins'));
- } else {
- $success = -1;
- }
- }
- if ($success) {
- $this->smarty->assign('success', $success);
- }
- return PANEL_REDIRECT_CURRENT;
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $id
- * @return int
- */
- function doenable($id) {
- $success = -1;
- $fp_plugins = $this->fp_plugins;
- if (plugin_exists($id)) {
- $success = 1;
- if (!in_array($id, $fp_plugins)) {
- $fp_plugins[] = $id;
- sort($fp_plugins);
- plugin_load($id, false, false);
- do_action('activate_'. $id);
- $success = system_save(CONFIG_DIR .'plugins.conf.php', compact('fp_plugins'));
- } else {
- $success = -1;
- }
- }
- if ($success) {
- $this->smarty->assign('success', $success);
- }
- return PANEL_REDIRECT_CURRENT;
- }
- /**
- * Enter description here...
- *
- * @return int
- */
- function main() {
- //$conf = io_load_file(CONFIG_DIR . 'plugins.conf.php');
- $this->smarty->assign('warnings', $this->errors);
- $this->smarty->assign('enabledlist', $this->fp_plugins);
- lang_load('admin.plugin');
- return 0;
- }
-
- /**
- * Enter description here...
- *
- * @return int
- */
- function onsave() {
- $fp_plugins = array_keys($_POST['plugin_enabled']);
- $success = system_save(CONFIG_DIR . 'plugins.conf.php', compact('fp_plugins'));
- $retval = $success
- ? 1
- : -1 ;
- $this->smarty->assign('success', $retval);
- //$this->smarty->assign('pluginconf', $str);
- return $retval;
- }
- }
- ?>