pluginlist.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Plugins administration panel
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Settings
  23. * @package StatusNet
  24. * @author Brion Vibber <brion@status.net>
  25. * @copyright 2010 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. require INSTALLDIR . "/lib/pluginenableform.php";
  33. require INSTALLDIR . "/lib/plugindisableform.php";
  34. /**
  35. * Plugin list
  36. *
  37. * @category Admin
  38. * @package StatusNet
  39. * @author Brion Vibber <brion@status.net>
  40. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  41. * @link http://status.net/
  42. */
  43. class PluginList extends Widget
  44. {
  45. var $plugins = array();
  46. function __construct($plugins, $out)
  47. {
  48. parent::__construct($out);
  49. $this->plugins = $plugins;
  50. }
  51. function show()
  52. {
  53. $this->startList();
  54. $this->showPlugins();
  55. $this->endList();
  56. }
  57. function startList()
  58. {
  59. $this->out->elementStart('table', 'plugin_list');
  60. }
  61. function endList()
  62. {
  63. $this->out->elementEnd('table');
  64. }
  65. function showPlugins()
  66. {
  67. foreach ($this->plugins as $plugin) {
  68. $pli = $this->newListItem($plugin);
  69. $pli->show();
  70. }
  71. }
  72. function newListItem($plugin)
  73. {
  74. return new PluginListItem($plugin, $this->out);
  75. }
  76. }
  77. class PluginListItem extends Widget
  78. {
  79. /** Current plugin. */
  80. var $plugin = null;
  81. /** Local cache for plugin version info */
  82. protected static $versions = false;
  83. function __construct($plugin, $out)
  84. {
  85. parent::__construct($out);
  86. $this->plugin = $plugin;
  87. }
  88. function show()
  89. {
  90. $meta = $this->metaInfo();
  91. $this->out->elementStart('tr', array('id' => 'plugin-' . $this->plugin));
  92. // Name and controls
  93. $this->out->elementStart('td');
  94. $this->out->elementStart('div');
  95. if (!empty($meta['homepage'])) {
  96. $this->out->elementStart('a', array('href' => $meta['homepage']));
  97. }
  98. $this->out->text($this->plugin);
  99. if (!empty($meta['homepage'])) {
  100. $this->out->elementEnd('a');
  101. }
  102. $this->out->elementEnd('div');
  103. $form = $this->getControlForm();
  104. $form->show();
  105. $this->out->elementEnd('td');
  106. // Version and authors
  107. $this->out->elementStart('td');
  108. if (!empty($meta['version'])) {
  109. $this->out->elementStart('div');
  110. $this->out->text($meta['version']);
  111. $this->out->elementEnd('div');
  112. }
  113. if (!empty($meta['author'])) {
  114. $this->out->elementStart('div');
  115. $this->out->text($meta['author']);
  116. $this->out->elementEnd('div');
  117. }
  118. $this->out->elementEnd('td');
  119. // Description
  120. $this->out->elementStart('td');
  121. if (!empty($meta['rawdescription'])) {
  122. $this->out->raw($meta['rawdescription']);
  123. }
  124. $this->out->elementEnd('td');
  125. $this->out->elementEnd('tr');
  126. }
  127. /**
  128. * Pull up the appropriate control form for this plugin, depending
  129. * on its current state.
  130. *
  131. * @return Form
  132. */
  133. protected function getControlForm()
  134. {
  135. $key = 'disable-' . $this->plugin;
  136. if (common_config('plugins', $key)) {
  137. return new PluginEnableForm($this->out, $this->plugin);
  138. } else {
  139. return new PluginDisableForm($this->out, $this->plugin);
  140. }
  141. }
  142. /**
  143. * Grab metadata about this plugin...
  144. * Warning: horribly inefficient and may explode!
  145. * Doesn't work for disabled plugins either.
  146. *
  147. * @fixme pull structured data from plugin source
  148. */
  149. function metaInfo()
  150. {
  151. $versions = self::getPluginVersions();
  152. $found = false;
  153. foreach ($versions as $info) {
  154. // hack for URL shorteners... "LilUrl (ur1.ca)" etc
  155. list($name, ) = explode(' ', $info['name']);
  156. if ($name == $this->plugin) {
  157. if ($found) {
  158. // hack for URL shorteners...
  159. $found['rawdescription'] .= "<br />\n" . $info['rawdescription'];
  160. } else {
  161. $found = $info;
  162. }
  163. }
  164. }
  165. if ($found) {
  166. return $found;
  167. } else {
  168. return array('name' => $this->plugin,
  169. // TRANS: Plugin description for a disabled plugin.
  170. 'rawdescription' => _m('plugin-description','(The plugin description is unavailable when a plugin has been disabled.)'));
  171. }
  172. }
  173. /**
  174. * Lazy-load the set of active plugin version info
  175. * @return array
  176. */
  177. protected static function getPluginVersions()
  178. {
  179. if (!is_array(self::$versions)) {
  180. $versions = array();
  181. Event::handle('PluginVersion', array(&$versions));
  182. self::$versions = $versions;
  183. }
  184. return self::$versions;
  185. }
  186. }