PageRenderTime 566ms CodeModel.GetById 275ms app.highlight 5ms RepoModel.GetById 283ms app.codeStats 0ms

/trunk/flatpress/admin/panels/plugin/admin.plugin.php

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