. * * @category Settings * @package StatusNet * @author Brion Vibber * @copyright 2010 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ if (!defined('STATUSNET')) { exit(1); } require INSTALLDIR . '/lib/pluginenableform.php'; require INSTALLDIR . '/lib/plugindisableform.php'; /** * Plugin list * * @category Admin * @package StatusNet * @author Brion Vibber * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ class PluginList extends Widget { var $pluginNames = array(); function __construct(array $pluginNames, Action $out=null) { parent::__construct($out); $this->pluginNames = $pluginNames; } function show() { $this->startList(); $this->showPlugins(); $this->endList(); } function startList() { $this->out->elementStart('table', 'plugin_list'); } function endList() { $this->out->elementEnd('table'); } function showPlugins() { foreach ($this->pluginNames as $pluginName) { $pli = $this->newListItem($pluginName); $pli->show(); } } function newListItem($pluginName) { return new PluginListItem($pluginName, $this->out); } } class PluginListItem extends Widget { /** Current plugin. */ private $pluginName = null; /** Local cache for plugin version info */ protected static $versions = false; function __construct($pluginName, Action $out=null) { parent::__construct($out); $this->pluginName = $pluginName; } function show() { $meta = $this->metaInfo(); $this->out->elementStart('tr', array('id' => 'plugin-' . $this->pluginName)); // Name and controls $this->out->elementStart('td'); $this->out->elementStart('div'); if (!empty($meta['homepage'])) { $this->out->elementStart('a', array('href' => $meta['homepage'])); } $this->out->text($this->pluginName); if (!empty($meta['homepage'])) { $this->out->elementEnd('a'); } $this->out->elementEnd('div'); $form = $this->getControlForm(); $form->show(); $this->out->elementEnd('td'); // Version and authors $this->out->elementStart('td'); if (!empty($meta['version'])) { $this->out->elementStart('div'); $this->out->text($meta['version']); $this->out->elementEnd('div'); } if (!empty($meta['author'])) { $this->out->elementStart('div'); $this->out->text($meta['author']); $this->out->elementEnd('div'); } $this->out->elementEnd('td'); // Description $this->out->elementStart('td'); if (!empty($meta['rawdescription'])) { $this->out->raw($meta['rawdescription']); } $this->out->elementEnd('td'); $this->out->elementEnd('tr'); } /** * Pull up the appropriate control form for this plugin, depending * on its current state. * * @return Form */ protected function getControlForm() { $key = 'disable-' . $this->pluginName; if (common_config('plugins', $key)) { return new PluginEnableForm($this->out, $this->pluginName); } else { return new PluginDisableForm($this->out, $this->pluginName); } } /** * Grab metadata about this plugin... * Warning: horribly inefficient and may explode! * Doesn't work for disabled plugins either. * * @fixme pull structured data from plugin source */ function metaInfo() { $versions = self::getPluginVersions(); $found = false; foreach ($versions as $info) { // hack for URL shorteners... "LilUrl (ur1.ca)" etc list($name, ) = explode(' ', $info['name']); if ($name == $this->pluginName) { if ($found) { // hack for URL shorteners... $found['rawdescription'] .= "
\n" . $info['rawdescription']; } else { $found = $info; } } } if ($found) { return $found; } else { return array('name' => $this->pluginName, // TRANS: Plugin description for a disabled plugin. 'rawdescription' => _m('plugin-description','(The plugin description is unavailable when a plugin has been disabled.)')); } } /** * Lazy-load the set of active plugin version info * @return array */ protected static function getPluginVersions() { if (!is_array(self::$versions)) { $versions = array(); Event::handle('PluginVersion', array(&$versions)); self::$versions = $versions; } return self::$versions; } }