/
content.systemextensions.php
executable file
·269 lines (227 loc) · 8.78 KB
/
content.systemextensions.php
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
/**
* @package content
*/
/**
* This page generates the Extensions index which shows all Extensions
* that are available in this Symphony installation.
*/
require_once(TOOLKIT . '/class.administrationpage.php');
require_once(CONTENT . '/class.sortable.php');
Class contentSystemExtensions extends AdministrationPage{
public function sort(&$sort, &$order, $params){
if(is_null($sort)) $sort = 'name';
return ExtensionManager::fetch(array(), array(), $sort . ' ' . $order);
}
public function __viewIndex(){
$this->setPageType('table');
$this->setTitle(__('%1$s – %2$s', array(__('Extensions'), __('Symphony'))));
$this->appendSubheading(__('Extensions'));
$this->Form->setAttribute('action', SYMPHONY_URL . '/system/extensions/');
Sortable::initialize($this, $extensions, $sort, $order);
$columns = array(
array(
'label' => __('Name'),
'sortable' => true,
'handle' => 'name'
),
array(
'label' => __('Installed Version'),
'sortable' => false,
),
array(
'label' => __('Enabled'),
'sortable' => false,
),
array(
'label' => __('Authors'),
'sortable' => true,
'handle' => 'author'
)
);
$aTableHead = Sortable::buildTableHeaders(
$columns, $sort, $order, (isset($_REQUEST['filter']) ? '&filter=' . $_REQUEST['filter'] : '')
);
$aTableBody = array();
if(!is_array($extensions) || empty($extensions)){
$aTableBody = array(
Widget::TableRow(array(Widget::TableData(__('None found.'), 'inactive', NULL, count($aTableHead))), 'odd')
);
}
else{
foreach($extensions as $name => $about){
$td1 = Widget::TableData($about['name']);
$installed_version = Symphony::ExtensionManager()->fetchInstalledVersion($name);
$td2 = Widget::TableData(is_null($installed_version) ? __('Not Installed') : $installed_version);
// If the extension is using the new `extension.meta.xml` format, check the
// compatibility of the extension. This won't prevent a user from installing
// it, but it will let them know that it requires a version of Symphony greater
// then what they have.
if(in_array(EXTENSION_NOT_INSTALLED, $about['status'])) {
$td3 = Widget::TableData(__('Enable to install %s', array($about['version'])));
}
if(in_array(EXTENSION_NOT_COMPATIBLE, $about['status'])) {
$td3 = Widget::TableData(__('Requires Symphony %s', array($about['required_version'])));
}
if(in_array(EXTENSION_ENABLED, $about['status'])) {
$td3 = Widget::TableData(__('Yes'));
}
if(in_array(EXTENSION_REQUIRES_UPDATE, $about['status'])) {
if(in_array(EXTENSION_NOT_COMPATIBLE, $about['status']))
$td3 = Widget::TableData(__('New version %1$s, Requires Symphony %2$s', array($about['version'], $about['required_version'])));
else
$td3 = Widget::TableData(__('Enable to update to %s', array($about['version'])));
}
if(in_array(EXTENSION_DISABLED, $about['status'])) {
$td3 = Widget::TableData(__('Disabled'));
}
$td4 = Widget::TableData(NULL);
if(isset($about['author'][0]) && is_array($about['author'][0])) {
$authors = '';
foreach($about['author'] as $i => $author) {
if(isset($author['website']))
$link = Widget::Anchor($author['name'], General::validateURL($author['website']));
else if(isset($author['email']))
$link = Widget::Anchor($author['name'], 'mailto:' . $author['email']);
else
$link = $author['name'];
$authors .= ($link instanceof XMLElement ? $link->generate() : $link)
. ($i != count($about['author']) - 1 ? ", " : "");
}
$td4->setValue($authors);
}
else {
if(isset($about['author']['website']))
$link = Widget::Anchor($about['author']['name'], General::validateURL($about['author']['website']));
else if(isset($about['author']['email']))
$link = Widget::Anchor($about['author']['name'], 'mailto:' . $about['author']['email']);
else
$link = $about['author']['name'];
$td4->setValue($link instanceof XMLElement ? $link->generate() : $link);
}
$td4->appendChild(Widget::Input('items['.$name.']', 'on', 'checkbox'));
// Add a row to the body array, assigning each cell to the row
$aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4), (in_array(EXTENSION_NOT_INSTALLED, $about['status']) ? 'inactive' : NULL));
}
}
$table = Widget::Table(
Widget::TableHead($aTableHead),
NULL,
Widget::TableBody($aTableBody),
'selectable'
);
$this->Form->appendChild($table);
$version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array(
'id' => 'version'
));
$this->Form->appendChild($version);
$tableActions = new XMLElement('div');
$tableActions->setAttribute('class', 'actions');
$options = array(
array(NULL, false, __('With Selected...')),
array('enable', false, __('Enable/Install')),
array('disable', false, __('Disable')),
array('uninstall', false, __('Uninstall'), 'confirm', null, array(
'data-message' => __('Are you sure you want to uninstall the selected extensions?')
))
);
/**
* Allows an extension to modify the existing options for this page's
* With Selected menu. If the `$options` parameter is an empty array,
* the 'With Selected' menu will not be rendered.
*
* @delegate AddCustomActions
* @since Symphony 2.3.2
* @param string $context
* '/system/extensions/'
* @param array $options
* An array of arrays, where each child array represents an option
* in the With Selected menu. Options should follow the same format
* expected by `Widget::__SelectBuildOption`. Passed by reference.
*/
Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/system/extensions/', array(
'options' => &$options
));
if(!empty($options)) {
$tableActions->appendChild(Widget::Apply($options));
$this->Form->appendChild($tableActions);
}
}
public function __actionIndex() {
$checked = (is_array($_POST['items'])) ? array_keys($_POST['items']) : null;
/**
* Extensions can listen for any custom actions that were added
* through `AddCustomPreferenceFieldsets` or `AddCustomActions`
* delegates.
*
* @delegate CustomActions
* @since Symphony 2.3.2
* @param string $context
* '/system/extensions/'
* @param array $checked
* An array of the selected rows. The value is usually the ID of the
* the associated object.
*/
Symphony::ExtensionManager()->notifyMembers('CustomActions', '/system/extensions/', array(
'checked' => $checked
));
if(isset($_POST['with-selected']) && is_array($checked) && !empty($checked)) {
try{
switch($_POST['with-selected']) {
case 'enable':
/**
* Notifies just before an Extension is to be enabled.
*
* @delegate ExtensionPreEnable
* @since Symphony 2.2
* @param string $context
* '/system/extensions/'
* @param array $extensions
* An array of all the extension name's to be enabled, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('ExtensionPreEnable', '/system/extensions/', array('extensions' => &$checked));
foreach($checked as $name){
if(Symphony::ExtensionManager()->enable($name) === false) return;
}
break;
case 'disable':
/**
* Notifies just before an Extension is to be disabled.
*
* @delegate ExtensionPreDisable
* @since Symphony 2.2
* @param string $context
* '/system/extensions/'
* @param array $extensions
* An array of all the extension name's to be disabled, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('ExtensionPreDisable', '/system/extensions/', array('extensions' => &$checked));
foreach($checked as $name){
Symphony::ExtensionManager()->disable($name);
}
break;
case 'uninstall':
/**
* Notifies just before an Extension is to be uninstalled
*
* @delegate ExtensionPreUninstall
* @since Symphony 2.2
* @param string $context
* '/system/extensions/'
* @param array $extensions
* An array of all the extension name's to be uninstalled, passed by reference
*/
Symphony::ExtensionManager()->notifyMembers('ExtensionPreUninstall', '/system/extensions/', array('extensions' => &$checked));
foreach($checked as $name){
Symphony::ExtensionManager()->uninstall($name);
}
break;
}
redirect(Administration::instance()->getCurrentPageURL());
}
catch(Exception $e) {
$this->pageAlert($e->getMessage(), Alert::ERROR);
}
}
}
}