Elgg  Version 1.9
plugins.php
Go to the documentation of this file.
1 <?php
11 elgg_load_js('lightbox');
12 elgg_load_css('lightbox');
13 
14 // @todo this should occur in the controller code
16 
18 $show_category = get_input('category', 'all');
19 $sort = get_input('sort', 'priority');
20 
21 // Get a list of the all categories
22 // and trim down the plugin list if we're not viewing all categories.
23 // @todo this could be cached somewhere after have the manifest loaded
24 $categories = array();
25 
26 foreach ($installed_plugins as $id => $plugin) {
27  if (!$plugin->isValid()) {
28  if ($plugin->isActive()) {
29  // force disable and warn
30  elgg_add_admin_notice('invalid_and_deactivated_' . $plugin->getID(),
31  elgg_echo('ElggPlugin:InvalidAndDeactivated', array($plugin->getId())));
32  $plugin->deactivate();
33  }
34  continue;
35  }
36 
37  $plugin_categories = $plugin->getManifest()->getCategories();
38 
39  // handle plugins that don't declare categories
40  // unset them here because this is the list we foreach
41  switch ($show_category) {
42  case 'all':
43  break;
44  case 'active':
45  if (!$plugin->isActive()) {
46  unset($installed_plugins[$id]);
47  }
48  break;
49  case 'inactive':
50  if ($plugin->isActive()) {
51  unset($installed_plugins[$id]);
52  }
53  break;
54  case 'nonbundled':
55  if (in_array('bundled', $plugin_categories)) {
56  unset($installed_plugins[$id]);
57  }
58  break;
59  default:
60  if (!in_array($show_category, $plugin_categories)) {
61  unset($installed_plugins[$id]);
62  }
63  break;
64  }
65 
66  if (isset($plugin_categories)) {
67  foreach ($plugin_categories as $category) {
68  if (!array_key_exists($category, $categories)) {
70  }
71  }
72  }
73 }
74 
75 $guids = array();
76 foreach ($installed_plugins as $plugin) {
77  $guids[] = $plugin->getGUID();
78 }
79 
80 // sort plugins
81 switch ($sort) {
82  case 'date':
83  $plugin_list = array();
84  foreach ($installed_plugins as $plugin) {
85  $create_date = $plugin->getTimeCreated();
86  while (isset($plugin_list[$create_date])) {
87  $create_date++;
88  }
89  $plugin_list[$create_date] = $plugin;
90  }
91  krsort($plugin_list);
92  break;
93  case 'alpha':
94  $plugin_list = array();
95  foreach ($installed_plugins as $plugin) {
96  $plugin_list[$plugin->getFriendlyName()] = $plugin;
97  }
98  ksort($plugin_list);
99  break;
100  case 'priority':
101  default:
102  $plugin_list = $installed_plugins;
103  break;
104 }
105 
106 
107 
108 asort($categories);
109 
110 // we want bundled/nonbundled pulled to be at the top of the list
111 unset($categories['bundled']);
112 unset($categories['nonbundled']);
113 
115  'all' => elgg_echo('admin:plugins:category:all'),
116  'active' => elgg_echo('admin:plugins:category:active'),
117  'inactive' => elgg_echo('admin:plugins:category:inactive'),
118  'bundled' => elgg_echo('admin:plugins:category:bundled'),
119  'nonbundled' => elgg_echo('admin:plugins:category:nonbundled'),
120 );
121 
123 // security - only want a defined option
124 if (!array_key_exists($show_category, $categories)) {
125  $show_category = reset($categories);
126 }
127 
128 $category_form = elgg_view_form('admin/plugins/filter', array(
129  'action' => 'admin/plugins',
130  'method' => 'get',
131  'disable_security' => true,
132 ), array(
133  'category' => $show_category,
134  'category_options' => $categories,
135  'sort' => $sort,
136 ));
137 
138 
140  'priority' => elgg_echo('sort:priority'),
141  'alpha' => elgg_echo('sort:alpha'),
142  'date' => elgg_echo('sort:newest'),
143 );
144 // security - only want a defined option
145 if (!array_key_exists($sort, $sort_options)) {
146  $sort = reset($sort_options);
147 }
148 
149 $sort_form = elgg_view_form('admin/plugins/sort', array(
150  'action' => 'admin/plugins',
151  'method' => 'get',
152  'disable_security' => true,
153 ), array(
154  'sort' => $sort,
155  'sort_options' => $sort_options,
156  'category' => $show_category,
157 ));
158 
159 $buttons = "<div class=\"clearfix mbm\">";
160 $buttons .= elgg_view_form('admin/plugins/change_state', array(
161  'action' => 'action/admin/plugins/activate_all',
162  'class' => 'float',
163 ), array(
164  'guids' => $guids,
165  'action' => 'activate',
166 ));
167 $buttons .= elgg_view_form('admin/plugins/change_state', array(
168  'action' => 'action/admin/plugins/deactivate_all',
169  'class' => 'float',
170 ), array(
171  'guids' => $guids,
172  'action' => 'deactivate',
173 ));
174 $buttons .= "</div>";
175 
177 
178 // construct page header
179 ?>
180 <div id="content_header" class="mbm clearfix">
181  <div class="content-header-options"><?php echo $buttons ?></div>
182 </div>
183 
184 <div id="elgg-plugin-list">
185 <?php
186 
187 $options = array(
188  'limit' => 0,
189  'full_view' => true,
190  'list_type_toggle' => false,
191  'pagination' => false,
192 );
193 if ($show_category == 'all' && $sort == 'priority') {
194  $options['display_reordering'] = true;
195 }
196 echo elgg_view_entity_list($plugin_list, $options);
197 
198 ?>
199 </div>
$plugin
$installed_plugins
Definition: plugins.php:17
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_view_entity_list($entities, $vars=array(), $offset=0, $limit=10, $full_view=true, $list_type_toggle=true, $pagination=true)
Returns a rendered list of entities with pagination.
Definition: views.php:969
$sort_options
Definition: plugins.php:139
elgg_add_admin_notice($id, $message)
Write a persistent message to the admin view.
Definition: admin.php:77
fieldset div
Definition: admin.php:462
$options
Definition: index.php:14
if(!array_key_exists($show_category, $categories)) $category_form
Definition: plugins.php:128
elgg_load_css($name)
Load a CSS file for this page.
Definition: elgglib.php:256
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
foreach($installed_plugins as $id=> $plugin) $guids
Definition: plugins.php:75
elgg echo
Translates a string.
Definition: languages.js:43
static getFriendlyCategory($category)
Returns a category&#39;s friendly name.
if(!array_key_exists($sort, $sort_options)) $sort_form
Definition: plugins.php:149
elgg_get_plugins($status= 'active', $site_guid=null)
Returns an ordered list of plugins.
Definition: plugins.php:372
$common_categories
Definition: plugins.php:114
elgg_load_js($name)
Load a JavaScript resource on this page.
Definition: elgglib.php:190
$sort
Definition: plugins.php:19
$categories
Definition: plugins.php:24
$buttons
Definition: plugins.php:159
if(!$collection_name) $id
Definition: add.php:17
elgg_view_form($action, $form_vars=array(), $body_vars=array())
Definition: views.php:1280
_elgg_generate_plugin_entities()
Discovers plugins in the plugins_path setting and creates ElggPlugin entities for them if they don&#39;t ...
Definition: plugins.php:93
$show_category
Definition: plugins.php:18