예제 #1
1
 /**
  * Display the plugin administration page
  */
 public function get_plugins()
 {
     $all_plugins = Plugins::list_all();
     $active_plugins = Plugins::get_active();
     $sort_active_plugins = array();
     $sort_inactive_plugins = array();
     foreach ($all_plugins as $file) {
         $plugin = array();
         $plugin_id = Plugins::id_from_file($file);
         $plugin['plugin_id'] = $plugin_id;
         $plugin['file'] = $file;
         $error = '';
         $providing = array();
         if (Utils::php_check_file_syntax($file, $error)) {
             $plugin['debug'] = false;
             $plugin['info'] = Plugins::load_info($file);
             if (array_key_exists($plugin_id, $active_plugins)) {
                 $plugin['verb'] = _t('Deactivate');
                 $pluginobj = $active_plugins[$plugin_id];
                 $plugin['active'] = true;
                 $plugin_actions = array();
                 $plugin_actions = Plugins::filter('plugin_config', $plugin_actions, $plugin_id);
                 $plugin['actions'] = array();
                 foreach ($plugin_actions as $plugin_action => $plugin_action_caption) {
                     if (is_numeric($plugin_action)) {
                         $plugin_action = $plugin_action_caption;
                     }
                     $action = array('caption' => $plugin_action_caption, 'action' => $plugin_action);
                     $urlparams = array('page' => 'plugins', 'configure' => $plugin_id);
                     $action['url'] = URL::get('admin', $urlparams);
                     if ($action['caption'] == _t('?')) {
                         if (isset($_GET['configaction'])) {
                             $urlparams['configaction'] = $_GET['configaction'];
                         }
                         if ($_GET['help'] != $plugin_action) {
                             $urlparams['help'] = $plugin_action;
                         }
                         $action['url'] = URL::get('admin', $urlparams);
                         $plugin['help'] = $action;
                     } else {
                         if (isset($_GET['help'])) {
                             $urlparams['help'] = $_GET['help'];
                         }
                         $urlparams['configaction'] = $plugin_action;
                         $action['url'] = URL::get('admin', $urlparams);
                         $plugin['actions'][$plugin_action] = $action;
                     }
                 }
                 $plugin['actions']['deactivate'] = array('url' => URL::get('admin', 'page=plugin_toggle&plugin_id=' . $plugin['plugin_id'] . '&action=deactivate'), 'caption' => _t('Deactivate'), 'action' => 'Deactivate');
                 if (isset($plugin['info']->provides)) {
                     foreach ($plugin['info']->provides->feature as $feature) {
                         $providing[(string) $feature] = $feature;
                     }
                 }
             } else {
                 // instantiate this plugin
                 // in order to get its info()
                 $plugin['active'] = false;
                 $plugin['verb'] = _t('Activate');
                 $plugin['actions'] = array('activate' => array('url' => URL::get('admin', 'page=plugin_toggle&plugin_id=' . $plugin['plugin_id'] . '&action=activate'), 'caption' => _t('Activate'), 'action' => 'activate'));
                 if (isset($plugin['info']->help)) {
                     if (isset($_GET['configaction'])) {
                         $urlparams['configaction'] = $_GET['configaction'];
                     }
                     if ($_GET['help'] != '_help') {
                         $urlparams['help'] = '_help';
                     }
                     $action['caption'] = _t('?');
                     $action['action'] = '_help';
                     $urlparams = array('page' => 'plugins', 'configure' => $plugin_id);
                     $action['url'] = URL::get('admin', $urlparams);
                     $plugin['help'] = $action;
                 }
             }
         } else {
             $plugin['debug'] = true;
             $plugin['error'] = $error;
             $plugin['active'] = false;
         }
         if (isset($this->handler_vars['configure']) && $this->handler_vars['configure'] == $plugin['plugin_id']) {
             if (isset($plugin['help']) && Controller::get_var('configaction') == $plugin['help']['action']) {
                 $this->theme->config_plugin_caption = _t('Help');
             } else {
                 if (isset($plugin['actions'][Controller::get_var('configaction')])) {
                     $this->theme->config_plugin_caption = $plugin['actions'][Controller::get_var('configaction')]['caption'];
                 } else {
                     $this->theme->config_plugin_caption = Controller::get_var('configaction');
                 }
             }
             unset($plugin['actions'][Controller::get_var('configaction')]);
             $this->theme->config_plugin = $plugin;
         } else {
             if ($plugin['active']) {
                 $sort_active_plugins[$plugin_id] = $plugin;
             } else {
                 $sort_inactive_plugins[$plugin_id] = $plugin;
             }
         }
     }
     // Get the features that the current theme provides
     $themeinfo = Themes::get_active_data();
     if (isset($themeinfo['info']->provides)) {
         foreach ($themeinfo['info']->provides->feature as $feature) {
             $providing[(string) $feature] = $feature;
         }
     }
     foreach ($sort_inactive_plugins as $plugin_id => $plugin) {
         if (isset($plugin['info']->requires)) {
             foreach ($plugin['info']->requires->feature as $feature) {
                 if (!isset($providing[(string) $feature])) {
                     if (!isset($sort_inactive_plugins[$plugin_id]['missing'])) {
                         $sort_inactive_plugins[$plugin_id]['missing'] = array();
                     }
                     $sort_inactive_plugins[$plugin_id]['missing'][(string) $feature] = isset($feature['url']) ? $feature['url'] : '';
                     unset($sort_inactive_plugins[$plugin_id]['actions']['activate']);
                 }
             }
         }
     }
     //$this->theme->plugins = array_merge($sort_active_plugins, $sort_inactive_plugins);
     $this->theme->assign('configaction', Controller::get_var('configaction'));
     $this->theme->assign('helpaction', Controller::get_var('help'));
     $this->theme->assign('configure', Controller::get_var('configure'));
     $this->theme->active_plugins = $sort_active_plugins;
     $this->theme->inactive_plugins = $sort_inactive_plugins;
     $this->theme->plugin_loader = Plugins::filter('plugin_loader', '', $this->theme);
     $this->display('plugins');
 }
 /**
  * Gets the deactived plugins and themes
  *
  * @todo This makes guesses and is not yet used.
  *
  * @return array An array of deactivated plugins, with an empty array() on failure
  */
 public function get_deactives()
 {
     $active_plugins = Plugins::get_active();
     $deactive_plugins = array();
     foreach (Plugins::list_all() as $fname => $fpath) {
         $id = Plugins::id_from_file($fpath);
         $info = Plugins::load_info($fpath);
         if (is_null($info) || is_null($id)) {
             continue;
         }
         //@todo $info differs from get_option_from_name() output, but would be inefficient to use for 300+ plugins
         if (empty($active_plugins[$id])) {
             $deactive_plugins[$id] = $info;
         }
     }
     return $deactive_plugins;
 }
예제 #3
0
	/**
	 * Stores the list of plugins that are present (not necessarily active) in
	 * the Options table for future comparison.
	 */
	public static function set_present()
	{
		$plugin_files = Plugins::list_all();
		// strip base path
		foreach ( $plugin_files as $plugin_file ) {
			$plugin_file = MultiByte::substr( $file, MultiByte::strlen( HABARI_PATH ) );
		}

		$plugin_data = array_map( create_function( '$a', 'return array( "file" => $a, "checksum" => md5_file( $a ) );' ), $plugin_files );
		Options::set( 'plugins_present', $plugin_data );
	}
예제 #4
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'));
 }
예제 #5
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']);
 }
예제 #6
0
 /**
  * Handles get requests for the system information page.
  */
 public function get_sysinfo()
 {
     $sysinfo = array();
     $siteinfo = array();
     // Assemble Site Info
     $siteinfo[_t('Habari Version')] = Version::get_habariversion();
     if (Version::is_devel()) {
         $siteinfo[_t('Habari Version')] .= " " . Version::get_git_short_hash();
     }
     $siteinfo[_t('Habari API Version')] = Version::get_apiversion();
     $siteinfo[_t('Habari DB Version')] = Version::get_dbversion();
     $siteinfo[_t('Active Theme')] = Options::get('theme_name');
     $siteinfo[_t('System Locale')] = HabariLocale::get();
     $siteinfo[_t('Cache Class')] = Cache::get_class();
     $this->theme->siteinfo = $siteinfo;
     // Assemble System Info
     $sysinfo[_t('PHP Version')] = phpversion();
     $sysinfo[_t('Server Software')] = $_SERVER['SERVER_SOFTWARE'];
     $sysinfo[_t('Database')] = DB::get_driver_name() . ' - ' . DB::get_driver_version();
     $sysinfo[_t('PHP Extensions')] = implode(', ', get_loaded_extensions());
     $sysinfo[_t('PHP Configuration Settings')] = implode("<br>", Utils::get_ini_settings());
     if (defined('PCRE_VERSION')) {
         $sysinfo[_t('PCRE Version')] = PCRE_VERSION;
     } else {
         // probably PHP < 5.2.4
         ob_start();
         phpinfo(8);
         $phpinfo = ob_get_contents();
         ob_end_clean();
         preg_match('/PCRE Library Version.*class="v">(.*)$/mi', $phpinfo, $matches);
         $sysinfo[_t('PCRE Version')] = $matches[1];
     }
     $sysinfo[_t('Browser')] = $_SERVER['HTTP_USER_AGENT'];
     $this->theme->sysinfo = $sysinfo;
     // Assemble Class Info
     $classinfo = Utils::glob(HABARI_PATH . "/user/classes/*.php");
     if (count($classinfo)) {
         $classinfo = array_map('realpath', $classinfo);
     }
     $this->theme->classinfo = $classinfo;
     // Assemble Plugin Info
     $raw_plugins = Plugins::get_active();
     $plugins = array('system' => array(), 'user' => array(), '3rdparty' => array(), 'other' => array());
     foreach ($raw_plugins as $plugin) {
         $file = $plugin->get_file();
         // Catch plugins that are symlinked from other locations as ReflectionClass->getFileName() only returns the ultimate file path, not the symlink path, and we really want the symlink path
         $all_plugins = Plugins::list_all();
         $filename = basename($file);
         if (array_key_exists($filename, $all_plugins) && $all_plugins[$filename] != $file) {
             $file = $all_plugins[$filename];
         }
         if (preg_match('%[\\\\/](system|3rdparty|user)[\\\\/]plugins[\\\\/]%i', $file, $matches)) {
             // A plugin's info is XML, cast the element to a string. See #1026.
             $plugins[strtolower($matches[1])][(string) $plugin->info->name] = $file;
         } else {
             // A plugin's info is XML, cast the element to a string.
             $plugins['other'][(string) $plugin->info->name] = $file;
         }
     }
     $this->theme->plugins = $plugins;
     $this->theme->admin_page = _t('System Information');
     $this->display('sysinfo');
 }
예제 #7
0
 /**
  * Stores the list of plugins that are present (not necessarily active) in
  * the Options table for future comparison.
  */
 public static function set_present()
 {
     $plugin_files = Plugins::list_all();
     // strip base path
     foreach ($plugin_files as $plugin_file) {
         $plugin_file = MultiByte::substr($plugin_file, MultiByte::strlen(HABARI_PATH));
     }
     $plugin_data = array_map(function ($a) {
         return array('file' => $a, 'checksum' => md5_file($a));
     }, $plugin_files);
     Options::set('plugins_present', $plugin_data);
 }
예제 #8
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'] );
	}
예제 #9
0
 public function get_plugins()
 {
     $all_plugins = Plugins::list_all();
     $active_plugins = Plugins::get_active();
     $sort_active_plugins = array();
     $sort_inactive_plugins = array();
     foreach ($all_plugins as $file) {
         $plugin = array();
         $plugin_id = Plugins::id_from_file($file);
         $plugin['plugin_id'] = $plugin_id;
         $plugin['file'] = $file;
         $error = '';
         if (Utils::php_check_file_syntax($file, $error)) {
             $plugin['debug'] = false;
             if (array_key_exists($plugin_id, $active_plugins)) {
                 $plugin['verb'] = _t('Deactivate');
                 $pluginobj = $active_plugins[$plugin_id];
                 $plugin['active'] = true;
                 $plugin_actions = array();
                 $plugin_actions = Plugins::filter('plugin_config', $plugin_actions, $plugin_id);
                 $plugin['actions'] = array();
                 foreach ($plugin_actions as $plugin_action => $plugin_action_caption) {
                     if (is_numeric($plugin_action)) {
                         $plugin_action = $plugin_action_caption;
                     }
                     $action = array('url' => URL::get('admin', 'page=plugins&configure=' . $plugin_id . '&configaction=' . $plugin_action), 'caption' => $plugin_action_caption, 'action' => $plugin_action);
                     if ($action['caption'] == '?') {
                         $plugin['help'] = $action;
                     } else {
                         $plugin['actions'][$plugin_action] = $action;
                     }
                 }
                 $plugin['actions']['deactivate'] = array('url' => URL::get('admin', 'page=plugin_toggle&plugin_id=' . $plugin['plugin_id'] . '&action=deactivate'), 'caption' => _t('Deactivate'), 'action' => 'Deactivate');
             } else {
                 // instantiate this plugin
                 // in order to get its info()
                 include_once $file;
                 Plugins::get_plugin_classes(true);
                 $pluginobj = Plugins::load($file, false);
                 $plugin['active'] = false;
                 $plugin['verb'] = _t('Activate');
                 $plugin['actions'] = array('activate' => array('url' => URL::get('admin', 'page=plugin_toggle&plugin_id=' . $plugin['plugin_id'] . '&action=activate'), 'caption' => _t('Activate'), 'action' => 'activate'));
             }
             $plugin['info'] = $pluginobj->info;
         } else {
             $plugin['debug'] = true;
             $plugin['error'] = $error;
             $plugin['active'] = false;
         }
         if (isset($this->handler_vars['configure']) && $this->handler_vars['configure'] == $plugin['plugin_id']) {
             if (isset($plugin['help']) && Controller::get_var('configaction') == $plugin['help']['action']) {
                 $this->theme->config_plugin_caption = _t('Help');
             } else {
                 if (isset($plugin['actions'][Controller::get_var('configaction')])) {
                     $this->theme->config_plugin_caption = $plugin['actions'][Controller::get_var('configaction')]['caption'];
                 } else {
                     $this->theme->config_plugin_caption = Controller::get_var('configaction');
                 }
             }
             unset($plugin['actions'][Controller::get_var('configaction')]);
             $this->theme->config_plugin = $plugin;
         } else {
             if ($plugin['active']) {
                 $sort_active_plugins[$plugin_id] = $plugin;
             } else {
                 $sort_inactive_plugins[$plugin_id] = $plugin;
             }
         }
     }
     //$this->theme->plugins = array_merge($sort_active_plugins, $sort_inactive_plugins);
     $this->theme->assign('configaction', Controller::get_var('configaction'));
     $this->theme->assign('configure', Controller::get_var('configure'));
     $this->theme->active_plugins = $sort_active_plugins;
     $this->theme->inactive_plugins = $sort_inactive_plugins;
     $this->display('plugins');
 }
예제 #10
0
파일: plugins.php 프로젝트: habari/system
 /**
  * Get a list of features and the active plugins that provide that feature
  * @param null|string $exclude A plugin id to exclude from the results
  * @param bool $include_inactive Default false.  If true, include inactive plugins in the list.
  * @param bool $use_file If true, return a filename as the depenedency. If false (default), return the name of the plugin.
  * @return array An array with keys of the feature name, values are an array of plugin names providing that feature
  */
 public static function provided($exclude = null, $include_inactive = false, $use_file = false)
 {
     if ($include_inactive) {
         $all_plugins = Plugins::list_all();
         $plugin_list = array();
         foreach ($all_plugins as $plugin => $plugin_file) {
             $pdata = new \stdClass();
             $pdata->info = self::load_info($plugin_file);
             $pdata->filename = $plugin_file;
             $plugin_list[self::id_from_file($plugin_file)] = $pdata;
         }
     } else {
         $plugin_list = Plugins::get_active();
     }
     $provided = array();
     foreach ($plugin_list as $plugin_id => $plugin) {
         if ($plugin->info->name == $exclude || $plugin_id == $exclude) {
             continue;
         }
         if (isset($plugin->info->provides)) {
             foreach ($plugin->info->provides->feature as $provide) {
                 if ($use_file) {
                     $provided[(string) $provide][] = isset(self::$plugin_files[get_class($plugin)]) ? self::$plugin_files[get_class($plugin)] : $plugin->filename;
                 } else {
                     $provided[(string) $provide][] = (string) $plugin->info->name;
                 }
             }
         }
     }
     return Plugins::filter('provided', $provided);
 }