plugins.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?php
  2. /**
  3. * Elgg administration plugin screen
  4. *
  5. * Shows a list of plugins that can be sorted and filtered.
  6. *
  7. * @package Elgg.Core
  8. * @subpackage Admin.Plugins
  9. */
  10. elgg_load_js('lightbox');
  11. elgg_load_css('lightbox');
  12. // @todo this should occur in the controller code
  13. _elgg_generate_plugin_entities();
  14. $installed_plugins = elgg_get_plugins('any');
  15. $show_category = get_input('category', 'all');
  16. $sort = get_input('sort', 'priority');
  17. // Get a list of the all categories
  18. // and trim down the plugin list if we're not viewing all categories.
  19. // @todo this could be cached somewhere after have the manifest loaded
  20. $categories = array();
  21. foreach ($installed_plugins as $id => $plugin) {
  22. if (!$plugin->isValid()) {
  23. if ($plugin->isActive()) {
  24. // force disable and warn
  25. elgg_add_admin_notice('invalid_and_deactivated_' . $plugin->getID(),
  26. elgg_echo('ElggPlugin:InvalidAndDeactivated', array($plugin->getId())));
  27. $plugin->deactivate();
  28. }
  29. continue;
  30. }
  31. $plugin_categories = $plugin->getManifest()->getCategories();
  32. // handle plugins that don't declare categories
  33. // unset them here because this is the list we foreach
  34. switch ($show_category) {
  35. case 'all':
  36. break;
  37. case 'active':
  38. if (!$plugin->isActive()) {
  39. unset($installed_plugins[$id]);
  40. }
  41. break;
  42. case 'inactive':
  43. if ($plugin->isActive()) {
  44. unset($installed_plugins[$id]);
  45. }
  46. break;
  47. case 'nonbundled':
  48. if (in_array('bundled', $plugin_categories)) {
  49. unset($installed_plugins[$id]);
  50. }
  51. break;
  52. default:
  53. if (!in_array($show_category, $plugin_categories)) {
  54. unset($installed_plugins[$id]);
  55. }
  56. break;
  57. }
  58. if (isset($plugin_categories)) {
  59. foreach ($plugin_categories as $category) {
  60. if (!array_key_exists($category, $categories)) {
  61. $categories[$category] = ElggPluginManifest::getFriendlyCategory($category);
  62. }
  63. }
  64. }
  65. }
  66. $guids = array();
  67. foreach ($installed_plugins as $plugin) {
  68. $guids[] = $plugin->getGUID();
  69. }
  70. // sort plugins
  71. switch ($sort) {
  72. case 'date':
  73. $plugin_list = array();
  74. foreach ($installed_plugins as $plugin) {
  75. $create_date = $plugin->getTimeCreated();
  76. while (isset($plugin_list[$create_date])) {
  77. $create_date++;
  78. }
  79. $plugin_list[$create_date] = $plugin;
  80. }
  81. krsort($plugin_list);
  82. break;
  83. case 'alpha':
  84. $plugin_list = array();
  85. foreach ($installed_plugins as $plugin) {
  86. $plugin_list[$plugin->getFriendlyName()] = $plugin;
  87. }
  88. ksort($plugin_list);
  89. break;
  90. case 'priority':
  91. default:
  92. $plugin_list = $installed_plugins;
  93. break;
  94. }
  95. asort($categories);
  96. // we want bundled/nonbundled pulled to be at the top of the list
  97. unset($categories['bundled']);
  98. unset($categories['nonbundled']);
  99. $common_categories = array(
  100. 'all' => elgg_echo('admin:plugins:category:all'),
  101. 'active' => elgg_echo('admin:plugins:category:active'),
  102. 'inactive' => elgg_echo('admin:plugins:category:inactive'),
  103. 'bundled' => elgg_echo('admin:plugins:category:bundled'),
  104. 'nonbundled' => elgg_echo('admin:plugins:category:nonbundled'),
  105. );
  106. $categories = array_merge($common_categories, $categories);
  107. // security - only want a defined option
  108. if (!array_key_exists($show_category, $categories)) {
  109. $show_category = reset($categories);
  110. }
  111. $category_form = elgg_view_form('admin/plugins/filter', array(
  112. 'action' => 'admin/plugins',
  113. 'method' => 'get',
  114. 'disable_security' => true,
  115. ), array(
  116. 'category' => $show_category,
  117. 'category_options' => $categories,
  118. 'sort' => $sort,
  119. ));
  120. $sort_options = array(
  121. 'priority' => elgg_echo('sort:priority'),
  122. 'alpha' => elgg_echo('sort:alpha'),
  123. 'date' => elgg_echo('sort:newest'),
  124. );
  125. // security - only want a defined option
  126. if (!array_key_exists($sort, $sort_options)) {
  127. $sort = reset($sort_options);
  128. }
  129. $sort_form = elgg_view_form('admin/plugins/sort', array(
  130. 'action' => 'admin/plugins',
  131. 'method' => 'get',
  132. 'disable_security' => true,
  133. ), array(
  134. 'sort' => $sort,
  135. 'sort_options' => $sort_options,
  136. 'category' => $show_category,
  137. ));
  138. $buttons = "<div class=\"clearfix mbm\">";
  139. $buttons .= elgg_view_form('admin/plugins/change_state', array(
  140. 'action' => 'action/admin/plugins/activate_all',
  141. 'class' => 'float',
  142. ), array(
  143. 'guids' => $guids,
  144. 'action' => 'activate',
  145. ));
  146. $buttons .= elgg_view_form('admin/plugins/change_state', array(
  147. 'action' => 'action/admin/plugins/deactivate_all',
  148. 'class' => 'float',
  149. ), array(
  150. 'guids' => $guids,
  151. 'action' => 'deactivate',
  152. ));
  153. $buttons .= "</div>";
  154. $buttons .= $category_form . $sort_form;
  155. // construct page header
  156. ?>
  157. <div id="content_header" class="mbm clearfix">
  158. <div class="content-header-options"><?php echo $buttons ?></div>
  159. </div>
  160. <div id="elgg-plugin-list">
  161. <?php
  162. $options = array(
  163. 'limit' => 0,
  164. 'full_view' => true,
  165. 'list_type_toggle' => false,
  166. 'pagination' => false,
  167. );
  168. if ($show_category == 'all' && $sort == 'priority') {
  169. $options['display_reordering'] = true;
  170. }
  171. echo elgg_view_entity_list($plugin_list, $options);
  172. ?>
  173. </div>