00001 <?php
00007 namespace Habari;
00008
00014 class AdminPluginsHandler extends AdminHandler
00015 {
00019 public function get_plugins()
00020 {
00021 $all_plugins = Plugins::list_all();
00022 $active_plugins = Plugins::get_active();
00023
00024 $sort_active_plugins = array();
00025 $sort_inactive_plugins = array();
00026 $providing = array();
00027 $available = array();
00028
00029 foreach ( $all_plugins as $file ) {
00030 $plugin = array();
00031 $plugin_id = Plugins::id_from_file( $file );
00032 $plugin['plugin_id'] = $plugin_id;
00033 $plugin['file'] = $file;
00034
00035 $error = '';
00036
00037 if ( Utils::php_check_file_syntax( $file, $error ) ) {
00038 $plugin['debug'] = false;
00039 $plugin['info'] = Plugins::load_info( $file );
00040 $plugin['core'] = (strpos($file, 'system' . DIRECTORY_SEPARATOR . 'plugins') !== false);
00041 if ( array_key_exists( $plugin_id, $active_plugins ) ) {
00042 $plugin['verb'] = _t( 'Deactivate' );
00043 $pluginobj = $active_plugins[$plugin_id];
00044 $plugin['active'] = true;
00045 $plugin_actions = array();
00046 $plugin_actions1 = Plugins::filter_id( 'plugin_config', $plugin_id, $plugin_actions, $plugin_id );
00047 $plugin_actions = Plugins::filter( 'plugin_config_any', $plugin_actions1, $plugin_id );
00048 $plugin['actions'] = array();
00049 foreach ( $plugin_actions as $plugin_action => $plugin_action_caption ) {
00050 if ( is_numeric( $plugin_action ) ) {
00051 $plugin_action = $plugin_action_caption;
00052 }
00053 $action = array(
00054 'caption' => $plugin_action_caption,
00055 'action' => $plugin_action,
00056 );
00057 $urlparams = array( 'page' => 'plugins', 'configure' => $plugin_id, 'action' => $plugin_action);
00058 $action['href'] = URL::get( 'display_plugins', $urlparams );
00059
00060
00061 if ( $action['caption'] == _t( '?' ) ) {
00062 $q = Controller::get_var('action');
00063 if ( isset( $q ) ) {
00064 $urlparams['action'] = Controller::get_var('action');
00065 }
00066 if ( $_GET['help'] != $plugin_action ) {
00067 $urlparams['help'] = $plugin_action;
00068 }
00069 $action['url'] = URL::get( 'display_plugins', $urlparams );
00070 $plugin['help'] = $action;
00071 }
00072 else {
00073 if ( isset( $_GET['help'] ) ) {
00074 $urlparams['help'] = $_GET['help'];
00075 }
00076 $urlparams['action'] = $plugin_action;
00077 $action['url'] = URL::get( 'display_plugins', $urlparams );
00078 $plugin['actions'][$plugin_action] = $action;
00079 }
00080 }
00081 $plugin['actions']['deactivate'] = array(
00082 'href' => URL::get( 'plugin_toggle' , 'plugin_id=' . $plugin['plugin_id'] . '&action=deactivate' ),
00083 'caption' => _t( 'Deactivate' ),
00084 'action' => 'Deactivate',
00085 );
00086
00087 if ( isset( $plugin['info']->provides ) ) {
00088 foreach ( $plugin['info']->provides->feature as $feature ) {
00089 $providing[(string) $feature] = (string)$feature;
00090 }
00091 }
00092 }
00093 else {
00094
00095
00096 $plugin['active'] = false;
00097 $plugin['verb'] = _t( 'Activate' );
00098 $plugin['actions'] = array(
00099 'activate' => array(
00100 'href' => URL::get( 'plugin_toggle', 'plugin_id=' . $plugin['plugin_id'] . '&action=activate' ),
00101 'caption' => _t( 'Activate' ),
00102 'action' => 'activate',
00103 ),
00104 );
00105 if ( isset( $plugin['info']->help ) ) {
00106 if ( isset( $_GET['action'] ) ) {
00107 $urlparams['action'] = $_GET['action'];
00108 }
00109 if ( $_GET['help'] != '_help' ) {
00110 $urlparams['help'] = '_help';
00111 }
00112
00113 $action['caption'] = _t( '?' );
00114 $action['action'] = '_help';
00115 $urlparams = array( 'page' => 'plugins', 'configure' => $plugin_id );
00116 $action['url'] = URL::get( 'admin', $urlparams );
00117 $plugin['help'] = $action;
00118 }
00119 if ( isset( $plugin['info']->provides ) ) {
00120 foreach ( $plugin['info']->provides->feature as $feature ) {
00121 $available[(string) $feature][$plugin_id] = $plugin['info']->name;
00122 }
00123 }
00124 }
00125 }
00126 else {
00127 $plugin['debug'] = true;
00128 $plugin['error'] = $error;
00129 $plugin['active'] = false;
00130 }
00131 if ( !is_null( Controller::get_var('configure') ) && ( Controller::get_var('configure') == $plugin['plugin_id'] ) ) {
00132 $this->theme->configaction = Controller::get_var('action');
00133 if ( isset( $plugin['help'] ) && Controller::get_var( 'action' ) == $plugin['help']['action'] ) {
00134 $this->theme->config_plugin_caption = _t( 'Help' );
00135 }
00136 else {
00137 if ( isset( $plugin['actions'][Controller::get_var( 'action' )] ) ) {
00138 $this->theme->config_plugin_caption = $plugin['actions'][Controller::get_var( 'action' )]['caption'];
00139 }
00140 else {
00141 $this->theme->config_plugin_caption = Controller::get_var( 'action' );
00142 }
00143 }
00144 unset( $plugin['actions'][Controller::get_var( 'action' )] );
00145 $this->theme->config_plugin = $plugin;
00146 }
00147 else if ( $plugin['active'] ) {
00148 $sort_active_plugins[$plugin_id] = $plugin;
00149 }
00150 else {
00151 $sort_inactive_plugins[$plugin_id] = $plugin;
00152 }
00153 }
00154
00155
00156 $themeinfo = Themes::get_active_data();
00157 if ( isset( $themeinfo['info']->provides ) ) {
00158 foreach ( $themeinfo['info']->provides->feature as $feature ) {
00159 $providing[(string) $feature] = $feature;
00160 }
00161 }
00162 $providing = Plugins::filter( 'provided', $providing );
00163
00164 foreach ( $sort_inactive_plugins as $plugin_id => $plugin ) {
00165 if ( isset( $plugin['info']->requires ) ) {
00166 foreach ( $plugin['info']->requires->feature as $feature ) {
00167 if ( !isset( $providing[(string) $feature] ) ) {
00168 if( isset( $available[(string) $feature] ) ) {
00169 $sort_inactive_plugins[$plugin_id]['available'][(string) $feature] = $available[(string) $feature];
00170 if(count($sort_inactive_plugins[$plugin_id]['available'][(string) $feature]) > 1) {
00171 unset( $sort_inactive_plugins[$plugin_id]['actions']['activate'] );
00172 }
00173 }
00174 else {
00175 if ( !isset( $sort_inactive_plugins[$plugin_id]['missing'] ) ) {
00176 $sort_inactive_plugins[$plugin_id]['missing'] = array();
00177 }
00178 $sort_inactive_plugins[$plugin_id]['missing'][(string) $feature] = isset( $feature['url'] ) ? $feature['url'] : '';
00179 unset( $sort_inactive_plugins[$plugin_id]['actions']['activate'] );
00180 }
00181 }
00182 }
00183 }
00184 }
00185
00186
00187 $this->theme->assign( 'action', Controller::get_var( 'action' ) );
00188 $this->theme->assign( 'helpaction', Controller::get_var( 'help' ) );
00189 $this->theme->assign( 'configure', Controller::get_var( 'configure' ) );
00190 uasort($sort_active_plugins, array( $this, 'compare_names' ) );
00191 uasort($sort_inactive_plugins, array( $this, 'compare_names' ) );
00192 $this->theme->active_plugins = $sort_active_plugins;
00193 $this->theme->inactive_plugins = $sort_inactive_plugins;
00194
00195 $this->theme->plugin_loader = Plugins::filter( 'plugin_loader', '', $this->theme );
00196
00197 $this->display( 'plugins' );
00198 }
00199
00203 public function post_plugins()
00204 {
00205 return $this->get_plugins();
00206 }
00207
00211 public function get_plugin_toggle()
00212 {
00213 $extract = $_GET->filter_keys( 'plugin_id', 'action' );
00214 foreach ( $extract as $key => $value ) {
00215 $$key = $value;
00216 }
00217
00218 $plugins = Plugins::list_all();
00219 foreach ( $plugins as $file ) {
00220 if ( Plugins::id_from_file( $file ) == $plugin_id ) {
00221 switch ( strtolower( $action ) ) {
00222 case 'activate':
00223 if ( Plugins::activate_plugin( $file ) ) {
00224 $plugins = Plugins::get_active();
00225 Session::notice(
00226 _t( "Activated plugin '@plugin'", array( '@plugin' => $plugins[Plugins::id_from_file( $file )]->info->name ) ),
00227 $plugins[Plugins::id_from_file( $file )]->plugin_id
00228 );
00229 }
00230 break;
00231 case 'deactivate':
00232 if ( Plugins::deactivate_plugin( $file ) ) {
00233 $plugins = Plugins::get_active();
00234 Session::notice(
00235 _t( "Deactivated plugin '@plugin'", array( '@plugin' => $plugins[Plugins::id_from_file( $file )]->info->name ) ),
00236 $plugins[Plugins::id_from_file( $file )]->plugin_id
00237 );
00238 }
00239 break;
00240 default:
00241 Plugins::act(
00242 'adminhandler_get_plugin_toggle_action',
00243 $action,
00244 $file,
00245 $plugin_id,
00246 $plugins
00247 );
00248 break;
00249 }
00250 }
00251 }
00252 Utils::redirect( URL::get( 'display_plugins' ) );
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262 protected function compare_names( $a, $b )
00263 {
00264 $aname = isset($a['info']) ? $a['info']->name : '';
00265 $bname = isset($b['info']) ? $b['info']->name : '';
00266 return strcmp( MultiByte::strtolower( $aname), MultiByte::strtolower( $bname ) );
00267 }
00268
00269 }