123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- require INSTALLDIR . "/lib/pluginenableform.php";
- require INSTALLDIR . "/lib/plugindisableform.php";
- class PluginList extends Widget
- {
- var $plugins = array();
- function __construct($plugins, $out)
- {
- parent::__construct($out);
- $this->plugins = $plugins;
- }
- 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->plugins as $plugin) {
- $pli = $this->newListItem($plugin);
- $pli->show();
- }
- }
- function newListItem($plugin)
- {
- return new PluginListItem($plugin, $this->out);
- }
- }
- class PluginListItem extends Widget
- {
-
- var $plugin = null;
-
- protected static $versions = false;
- function __construct($plugin, $out)
- {
- parent::__construct($out);
- $this->plugin = $plugin;
- }
- function show()
- {
- $meta = $this->metaInfo();
- $this->out->elementStart('tr', array('id' => 'plugin-' . $this->plugin));
-
- $this->out->elementStart('td');
- $this->out->elementStart('div');
- if (!empty($meta['homepage'])) {
- $this->out->elementStart('a', array('href' => $meta['homepage']));
- }
- $this->out->text($this->plugin);
- if (!empty($meta['homepage'])) {
- $this->out->elementEnd('a');
- }
- $this->out->elementEnd('div');
- $form = $this->getControlForm();
- $form->show();
- $this->out->elementEnd('td');
-
- $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');
-
- $this->out->elementStart('td');
- if (!empty($meta['rawdescription'])) {
- $this->out->raw($meta['rawdescription']);
- }
- $this->out->elementEnd('td');
- $this->out->elementEnd('tr');
- }
-
- protected function getControlForm()
- {
- $key = 'disable-' . $this->plugin;
- if (common_config('plugins', $key)) {
- return new PluginEnableForm($this->out, $this->plugin);
- } else {
- return new PluginDisableForm($this->out, $this->plugin);
- }
- }
-
- function metaInfo()
- {
- $versions = self::getPluginVersions();
- $found = false;
- foreach ($versions as $info) {
-
- list($name, ) = explode(' ', $info['name']);
- if ($name == $this->plugin) {
- if ($found) {
-
- $found['rawdescription'] .= "<br />\n" . $info['rawdescription'];
- } else {
- $found = $info;
- }
- }
- }
- if ($found) {
- return $found;
- } else {
- return array('name' => $this->plugin,
-
- 'rawdescription' => _m('plugin-description','(The plugin description is unavailable when a plugin has been disabled.)'));
- }
- }
-
- protected static function getPluginVersions()
- {
- if (!is_array(self::$versions)) {
- $versions = array();
- Event::handle('PluginVersion', array(&$versions));
- self::$versions = $versions;
- }
- return self::$versions;
- }
- }
|