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