Beispiel #1
0
 public function activate_plugins()
 {
     // extract checked plugin IDs from $_POST
     $plugin_ids = array();
     foreach ($this->handler_vars as $id => $activate) {
         if (preg_match('/plugin_([a-f0-9]{8})/u', $id, $matches) && $activate) {
             $plugin_ids[] = $matches[1];
         } elseif (preg_match('/plugin_(.+)/u', $id, $matches) && $activate) {
             $plugin_ids[] = $matches[1];
         }
     }
     if (count($plugin_ids) == 0) {
         return;
     }
     // set the user_id in the session in case plugin activation methods need it
     if (!($u = User::get_by_name($this->handler_vars['admin_username']))) {
         // @todo die gracefully
         die(_t('No admin user found'));
     }
     $u->remember();
     // loop through all plugins to find matching plugin files
     $plugin_files = Plugins::list_all();
     foreach ($plugin_files as $file) {
         if (in_array(basename($file), $plugin_ids)) {
             Plugins::activate_plugin($file);
             continue;
         }
         $id = Plugins::id_from_file($file);
         if (in_array($id, $plugin_ids)) {
             Plugins::activate_plugin($file);
         }
     }
     // unset the user_id session variable
     Session::clear_userid($_SESSION['user_id']);
     unset($_SESSION['user_id']);
 }
Beispiel #2
0
 /**
  * Handles plugin activation or deactivation.
  */
 public function get_plugin_toggle()
 {
     $extract = $this->handler_vars->filter_keys('plugin_id', 'action');
     foreach ($extract as $key => $value) {
         ${$key} = $value;
     }
     $plugins = Plugins::list_all();
     foreach ($plugins as $file) {
         if (Plugins::id_from_file($file) == $plugin_id) {
             switch (strtolower($action)) {
                 case 'activate':
                     if (Plugins::activate_plugin($file)) {
                         $plugins = Plugins::get_active();
                         Session::notice(_t("Activated plugin '%s'", array($plugins[Plugins::id_from_file($file)]->info->name)), $plugins[Plugins::id_from_file($file)]->plugin_id);
                     }
                     break;
                 case 'deactivate':
                     if (Plugins::deactivate_plugin($file)) {
                         $plugins = Plugins::get_active();
                         Session::notice(_t("Deactivated plugin '%s'", array($plugins[Plugins::id_from_file($file)]->info->name)), $plugins[Plugins::id_from_file($file)]->plugin_id);
                     }
                     break;
                 default:
                     Plugins::act('adminhandler_get_plugin_toggle_action', $action, $file, $plugin_id, $plugins);
                     break;
             }
         }
     }
     Utils::redirect(URL::get('admin', 'page=plugins'));
 }
Beispiel #3
0
	public function activate_plugins()
	{
		// extract checked plugin IDs from $_POST
		$plugin_ids = array();
		foreach ( $_POST as $id => $activate ) {
			if ( preg_match( '/plugin_\w+/u', $id ) && $activate ) {
				$id = substr( $id, 7 );
				$plugin_ids[] = $id;
			}
		}

		// set the user_id in the session in case plugin activation methods need it
		if ( ! $u = User::get_by_name( $this->handler_vars['admin_username'] ) ) {
			// @todo die gracefully
			die( _t( 'No admin user found' ) );
		}
		$u->remember();

		// loop through all plugins to find matching plugin files
		$plugin_files = Plugins::list_all();
		foreach ( $plugin_files as $file ) {
			$id = Plugins::id_from_file( $file );
			if ( in_array( $id, $plugin_ids ) ) {
				Plugins::activate_plugin( $file );
			}
		}

		// unset the user_id session variable
		Session::clear_userid( $_SESSION['user_id'] );
		unset( $_SESSION['user_id'] );
	}