PageRenderTime 283ms CodeModel.GetById 120ms app.highlight 6ms RepoModel.GetById 155ms app.codeStats 0ms

/branches/coding-style/admin/panels/plugin/admin.plugin.php

https://bitbucket.org/alexandrul/flatpress
PHP | 127 lines | 73 code | 10 blank | 44 comment | 8 complexity | 935fc2bd9d38010228a788d4b27a73af MD5 | raw file
  1<?php
  2
  3/**
  4 * Plugin control panel
  5 * 
  6 * @author NoWhereMan <real_nowhereman at users dot sf dot com>
  7 */
  8
  9/*
 10function admin_plugin_adminheader() {
 11	$f = ADMIN_DIR .'/panels/plugin/admin.plugin.js'; 
 12	echo '<script src="'.$f.'" type="text/javascript"></script>';
 13}
 14add_action('wp_head', 'admin_plugin_adminheader');
 15*/
 16
 17/**
 18 * Enter description here...
 19 *
 20 */
 21class admin_plugin extends AdminPanel {
 22	var $panelname = 'plugin';
 23	var $actions = array('default' => true);
 24}
 25
 26class admin_plugin_default extends AdminPanelAction {
 27	var $commands = array('enable', 'disable'); 
 28	var $errors = array();
 29	
 30	/**
 31	 * Enter description here...
 32	 *
 33	 */
 34	function setup() {
 35		$this->pluginid = isset($_GET['plugin'])? $_GET['plugin'] : null;
 36		$pi =& new plugin_indexer;
 37		$plist = $pi->getList();
 38		sort($plist);
 39		$this->smarty->assign('pluginlist', $plist);
 40		$this->errors = @$pi->getEnableds(true);
 41		$this->fp_plugins = $pi->enabledlist;
 42	}
 43	
 44	/**
 45	 * Enter description here...
 46	 *
 47	 * @param unknown_type $id
 48	 * @return int
 49	 */
 50	function dodisable($id) {
 51		$fp_plugins = $this->fp_plugins;
 52		$success = -1;
 53		if (plugin_exists($id)) {
 54			$success = 1;
 55			if (false !== $i = array_search($id, $fp_plugins)) {
 56				unset($fp_plugins[$i]);
 57				sort($fp_plugins); /* compact indices */
 58				do_action('deactivate_'. $id);
 59				$success = system_save(CONFIG_DIR .'plugins.conf.php', compact('fp_plugins'));
 60			} else {
 61				$success = -1; 
 62			}
 63		}
 64		if ($success) {
 65			$this->smarty->assign('success', $success);
 66		}
 67		return PANEL_REDIRECT_CURRENT;
 68	}
 69	
 70	/**
 71	 * Enter description here...
 72	 *
 73	 * @param unknown_type $id
 74	 * @return int
 75	 */
 76	function doenable($id) {
 77		$success = -1;
 78		$fp_plugins = $this->fp_plugins;
 79		if (plugin_exists($id)) {
 80			$success = 1;
 81			if (!in_array($id, $fp_plugins)) {
 82				$fp_plugins[] = $id;
 83				sort($fp_plugins);
 84				plugin_load($id, false, false);
 85				do_action('activate_'. $id);
 86				$success = system_save(CONFIG_DIR .'plugins.conf.php', compact('fp_plugins'));
 87			} else {
 88				$success = -1;
 89			}
 90		}
 91		if ($success) {
 92			$this->smarty->assign('success', $success);
 93		}
 94		return PANEL_REDIRECT_CURRENT;
 95	}
 96
 97	/**
 98	 * Enter description here...
 99	 *
100	 * @return int
101	 */
102	function main() {
103		//$conf = io_load_file(CONFIG_DIR . 'plugins.conf.php');
104		$this->smarty->assign('warnings', $this->errors);
105		$this->smarty->assign('enabledlist', $this->fp_plugins);
106		lang_load('admin.plugin');
107		return 0;
108	}
109	
110	/**
111	 * Enter description here...
112	 *
113	 * @return int
114	 */
115	function onsave() {
116		$fp_plugins = array_keys($_POST['plugin_enabled']);
117		$success = system_save(CONFIG_DIR . 'plugins.conf.php', compact('fp_plugins'));
118		$retval = $success
119			? 1
120			: -1 ;
121		$this->smarty->assign('success', $retval);
122		//$this->smarty->assign('pluginconf', $str);
123		return $retval;
124	}
125}
126
127?>