1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package content |
5
|
|
|
*/ |
6
|
|
|
/** |
7
|
|
|
* This page generates the Extensions index which shows all Extensions |
8
|
|
|
* that are available in this Symphony installation. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
class contentSystemExtensions extends AdministrationPage |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
public function sort(&$sort, &$order, $params) |
14
|
|
|
{ |
15
|
|
|
$sort = is_null($sort) ? 'name' : General::sanitize($sort); |
16
|
|
|
|
17
|
|
|
return ExtensionManager::fetch(array(), array(), $sort . ' ' . $order); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function __viewIndex() |
21
|
|
|
{ |
22
|
|
|
$canonical_link = '/system/extensions/'; |
23
|
|
|
$this->setPageType('table'); |
24
|
|
|
$this->setTitle(__('%1$s – %2$s', array(__('Extensions'), __('Symphony')))); |
25
|
|
|
$this->addElementToHead(new XMLElement('link', null, array( |
26
|
|
|
'rel' => 'canonical', |
27
|
|
|
'href' => SYMPHONY_URL . $canonical_link, |
|
|
|
|
28
|
|
|
))); |
29
|
|
|
$this->appendSubheading(__('Extensions')); |
30
|
|
|
|
31
|
|
|
$this->Form->setAttribute('action', SYMPHONY_URL . $canonical_link); |
32
|
|
|
|
33
|
|
|
Sortable::initialize($this, $extensions, $sort, $order); |
34
|
|
|
|
35
|
|
|
$columns = array( |
36
|
|
|
array( |
37
|
|
|
'label' => __('Name'), |
38
|
|
|
'sortable' => true, |
39
|
|
|
'handle' => 'name' |
40
|
|
|
), |
41
|
|
|
array( |
42
|
|
|
'label' => __('Version'), |
43
|
|
|
'sortable' => false, |
44
|
|
|
), |
45
|
|
|
array( |
46
|
|
|
'label' => __('Status'), |
47
|
|
|
'sortable' => false, |
48
|
|
|
), |
49
|
|
|
array( |
50
|
|
|
'label' => __('Links'), |
51
|
|
|
'sortable' => false, |
52
|
|
|
'handle' => 'links' |
53
|
|
|
), |
54
|
|
|
array( |
55
|
|
|
'label' => __('Authors'), |
56
|
|
|
'sortable' => true, |
57
|
|
|
'handle' => 'author' |
58
|
|
|
) |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$aTableHead = Sortable::buildTableHeaders( |
62
|
|
|
$columns, |
63
|
|
|
$sort, |
64
|
|
|
$order, |
65
|
|
|
(isset($_REQUEST['filter']) ? '&filter=' . $_REQUEST['filter'] : '') |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$aTableBody = array(); |
69
|
|
|
|
70
|
|
|
if (!is_array($extensions) || empty($extensions)) { |
71
|
|
|
$aTableBody = array( |
72
|
|
|
Widget::TableRow(array( |
73
|
|
|
Widget::TableData(__('None found.'), 'inactive', null, count($aTableHead)) |
74
|
|
|
), 'odd') |
75
|
|
|
); |
76
|
|
|
} else { |
77
|
|
|
foreach ($extensions as $name => $about) { |
78
|
|
|
// Name |
79
|
|
|
$td1 = Widget::TableData($about['name']); |
80
|
|
|
$td1->appendChild(Widget::Label(__('Select %s Extension', array($about['name'])), null, 'accessible', null, array( |
81
|
|
|
'for' => 'extension-' . $name |
82
|
|
|
))); |
83
|
|
|
$td1->appendChild(Widget::Input('items['.$name.']', 'on', 'checkbox', array( |
84
|
|
|
'id' => 'extension-' . $name |
85
|
|
|
))); |
86
|
|
|
|
87
|
|
|
// Version |
88
|
|
|
$installed_version = Symphony::ExtensionManager()->fetchInstalledVersion($name); |
89
|
|
|
|
90
|
|
|
if (in_array(Extension::EXTENSION_NOT_INSTALLED, $about['status'])) { |
91
|
|
|
$td2 = Widget::TableData($about['version']); |
92
|
|
|
} elseif (in_array(Extension::EXTENSION_REQUIRES_UPDATE, $about['status'])) { |
93
|
|
|
$td2 = Widget::TableData($installed_version . '<i> → ' . $about['version'] . '</i>'); |
94
|
|
|
} else { |
95
|
|
|
$td2 = Widget::TableData($installed_version); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
// Status |
99
|
|
|
$trClasses = array(); |
100
|
|
|
$trStatus = ''; |
101
|
|
|
$tdMessage = __('Status unavailable'); |
102
|
|
|
|
103
|
|
|
if (in_array(Extension::EXTENSION_NOT_INSTALLED, $about['status'])) { |
104
|
|
|
$tdMessage = __('Not installed'); |
105
|
|
|
$trClasses[] = 'inactive'; |
106
|
|
|
$trClasses[] = 'extension-can-install'; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if (in_array(Extension::EXTENSION_DISABLED, $about['status'])) { |
110
|
|
|
$tdMessage = __('Disabled'); |
111
|
|
|
$trStatus = 'status-notice'; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if (in_array(Extension::EXTENSION_ENABLED, $about['status'])) { |
115
|
|
|
$tdMessage = __('Enabled'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (in_array(Extension::EXTENSION_REQUIRES_UPDATE, $about['status'])) { |
119
|
|
|
$tdMessage = __('Update available'); |
120
|
|
|
$trClasses[] = 'extension-can-update'; |
121
|
|
|
$trStatus = 'status-ok'; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if (in_array(Extension::EXTENSION_NOT_COMPATIBLE, $about['status'])) { |
125
|
|
|
$tdMessage .= ', ' . __('requires Symphony %s', array($about['required_version'])); |
126
|
|
|
$trStatus = 'status-error'; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$trClasses[] = $trStatus; |
130
|
|
|
$td3 = Widget::TableData($tdMessage); |
131
|
|
|
|
132
|
|
|
// Links |
133
|
|
|
$tdLinks = array(); |
134
|
|
|
|
135
|
|
|
if ($about['github'] != '') { |
136
|
|
|
$tdLinks['github'] = Widget::Anchor(__('GitHub'), General::validateURL($about['github']))->generate(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
if ($about['discuss'] != '') { |
140
|
|
|
$tdLinks['discuss'] = Widget::Anchor(__('Discuss'), General::validateURL($about['discuss']))->generate(); |
141
|
|
|
// Update links to point to our 'new' domain, RE: #1995 |
142
|
|
|
$tdLinks['discuss'] = str_replace('symphony-cms.com', 'getsymphony.com', $tdLinks['discuss']); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
if ($about['homepage'] != '') { |
146
|
|
|
$tdLinks['homepage'] = Widget::Anchor(__('Homepage'), General::validateURL($about['homepage']))->generate(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if ($about['wiki'] != '') { |
150
|
|
|
$tdLinks['wiki'] = Widget::Anchor(__('Wiki'), General::validateURL($about['wiki']))->generate(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if ($about['issues'] != '') { |
154
|
|
|
$tdLinks['issues'] = Widget::Anchor(__('Issues'), General::validateURL($about['issues']))->generate(); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$td4 = Widget::TableData($tdLinks); |
|
|
|
|
158
|
|
|
|
159
|
|
|
// Authors |
160
|
|
|
$tdAuthors = array(); |
161
|
|
|
|
162
|
|
|
if (!is_array($about['author'])) { |
163
|
|
|
$about['author'] = array($about['author']); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
foreach ($about['author'] as $author) { |
167
|
|
|
if (isset($author['website'])) { |
168
|
|
|
$tdAuthors[] = Widget::Anchor($author['name'], General::validateURL($author['website']))->generate(); |
169
|
|
|
} elseif (isset($author['github'])) { |
170
|
|
|
$tdAuthors[] = Widget::Anchor($author['name'], General::validateURL('https://github.com/' . $author['github']))->generate(); |
171
|
|
|
} elseif (isset($author['email'])) { |
172
|
|
|
$tdAuthors[] = Widget::Anchor($author['name'], 'mailto:' . $author['email'])->generate(); |
173
|
|
|
} else { |
174
|
|
|
$tdAuthors[] = $author['name']; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$td5 = Widget::TableData($tdAuthors); |
|
|
|
|
179
|
|
|
|
180
|
|
|
// Create the table row |
181
|
|
|
$tr = Widget::TableRow(array($td1, $td2, $td3, $td4, $td5), implode(' ', $trClasses)); |
182
|
|
|
|
183
|
|
|
// Add some attributes about the extension |
184
|
|
|
$tr->setAttribute('data-handle', $name); |
185
|
|
|
$tr->setAttribute('data-installed-version', $installed_version); |
186
|
|
|
$tr->setAttribute('data-meta-version', $about['version']); |
187
|
|
|
|
188
|
|
|
// Add a row to the body array, assigning each cell to the row |
189
|
|
|
$aTableBody[] = $tr; |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$table = Widget::Table( |
194
|
|
|
Widget::TableHead($aTableHead), |
195
|
|
|
null, |
196
|
|
|
Widget::TableBody($aTableBody), |
197
|
|
|
'selectable', |
198
|
|
|
null, |
199
|
|
|
array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive') |
200
|
|
|
); |
201
|
|
|
|
202
|
|
|
$this->Form->appendChild($table); |
203
|
|
|
|
204
|
|
|
$version = new XMLElement('p', 'Symphony ' . Symphony::Configuration()->get('version', 'symphony'), array( |
205
|
|
|
'id' => 'version' |
206
|
|
|
)); |
207
|
|
|
|
208
|
|
|
$this->Form->appendChild($version); |
209
|
|
|
|
210
|
|
|
$tableActions = new XMLElement('div'); |
211
|
|
|
$tableActions->setAttribute('class', 'actions'); |
212
|
|
|
|
213
|
|
|
$options = array( |
214
|
|
|
array(null, false, __('With Selected...')), |
215
|
|
|
array('enable', false, __('Enable')), |
216
|
|
|
array('disable', false, __('Disable')), |
217
|
|
|
array('uninstall', false, __('Uninstall'), 'confirm', null, array( |
218
|
|
|
'data-message' => __('Are you sure you want to uninstall the selected extensions?') |
219
|
|
|
)) |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Allows an extension to modify the existing options for this page's |
224
|
|
|
* With Selected menu. If the `$options` parameter is an empty array, |
225
|
|
|
* the 'With Selected' menu will not be rendered. |
226
|
|
|
* |
227
|
|
|
* @delegate AddCustomActions |
228
|
|
|
* @since Symphony 2.3.2 |
229
|
|
|
* @param string $context |
230
|
|
|
* '/system/extensions/' |
231
|
|
|
* @param array $options |
232
|
|
|
* An array of arrays, where each child array represents an option |
233
|
|
|
* in the With Selected menu. Options should follow the same format |
234
|
|
|
* expected by `Widget::__SelectBuildOption`. Passed by reference. |
235
|
|
|
*/ |
236
|
|
|
Symphony::ExtensionManager()->notifyMembers('AddCustomActions', '/system/extensions/', array( |
237
|
|
|
'options' => &$options |
238
|
|
|
)); |
239
|
|
|
|
240
|
|
|
if (!empty($options)) { |
241
|
|
|
$tableActions->appendChild(Widget::Apply($options)); |
242
|
|
|
$this->Form->appendChild($tableActions); |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function __actionIndex() |
247
|
|
|
{ |
248
|
|
|
$checked = (is_array($_POST['items'])) ? array_keys($_POST['items']) : null; |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Extensions can listen for any custom actions that were added |
252
|
|
|
* through `AddCustomPreferenceFieldsets` or `AddCustomActions` |
253
|
|
|
* delegates. |
254
|
|
|
* |
255
|
|
|
* @delegate CustomActions |
256
|
|
|
* @since Symphony 2.3.2 |
257
|
|
|
* @param string $context |
258
|
|
|
* '/system/extensions/' |
259
|
|
|
* @param array $checked |
260
|
|
|
* An array of the selected rows. The value is usually the ID of the |
261
|
|
|
* the associated object. |
262
|
|
|
*/ |
263
|
|
|
Symphony::ExtensionManager()->notifyMembers('CustomActions', '/system/extensions/', array( |
264
|
|
|
'checked' => $checked |
265
|
|
|
)); |
266
|
|
|
|
267
|
|
|
if (isset($_POST['with-selected']) && is_array($checked) && !empty($checked)) { |
268
|
|
|
try { |
269
|
|
|
switch ($_POST['with-selected']) { |
270
|
|
|
case 'enable': |
271
|
|
|
/** |
272
|
|
|
* Notifies just before an Extension is to be enabled. |
273
|
|
|
* |
274
|
|
|
* @delegate ExtensionPreEnable |
275
|
|
|
* @since Symphony 2.2 |
276
|
|
|
* @param string $context |
277
|
|
|
* '/system/extensions/' |
278
|
|
|
* @param array $extensions |
279
|
|
|
* An array of all the extension name's to be enabled, passed by reference |
280
|
|
|
*/ |
281
|
|
|
Symphony::ExtensionManager()->notifyMembers('ExtensionPreEnable', '/system/extensions/', array('extensions' => &$checked)); |
282
|
|
|
|
283
|
|
|
foreach ($checked as $name) { |
284
|
|
|
if (Symphony::ExtensionManager()->enable($name) === false) { |
285
|
|
|
return; |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
break; |
289
|
|
|
case 'disable': |
290
|
|
|
/** |
291
|
|
|
* Notifies just before an Extension is to be disabled. |
292
|
|
|
* |
293
|
|
|
* @delegate ExtensionPreDisable |
294
|
|
|
* @since Symphony 2.2 |
295
|
|
|
* @param string $context |
296
|
|
|
* '/system/extensions/' |
297
|
|
|
* @param array $extensions |
298
|
|
|
* An array of all the extension name's to be disabled, passed by reference |
299
|
|
|
*/ |
300
|
|
|
Symphony::ExtensionManager()->notifyMembers('ExtensionPreDisable', '/system/extensions/', array('extensions' => &$checked)); |
301
|
|
|
|
302
|
|
|
foreach ($checked as $name) { |
303
|
|
|
Symphony::ExtensionManager()->disable($name); |
304
|
|
|
} |
305
|
|
|
break; |
306
|
|
|
case 'uninstall': |
307
|
|
|
/** |
308
|
|
|
* Notifies just before an Extension is to be uninstalled |
309
|
|
|
* |
310
|
|
|
* @delegate ExtensionPreUninstall |
311
|
|
|
* @since Symphony 2.2 |
312
|
|
|
* @param string $context |
313
|
|
|
* '/system/extensions/' |
314
|
|
|
* @param array $extensions |
315
|
|
|
* An array of all the extension name's to be uninstalled, passed by reference |
316
|
|
|
*/ |
317
|
|
|
Symphony::ExtensionManager()->notifyMembers('ExtensionPreUninstall', '/system/extensions/', array('extensions' => &$checked)); |
318
|
|
|
|
319
|
|
|
foreach ($checked as $name) { |
320
|
|
|
Symphony::ExtensionManager()->uninstall($name); |
321
|
|
|
} |
|
|
|
|
322
|
|
|
|
323
|
|
|
break; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
redirect(Administration::instance()->getCurrentPageURL()); |
327
|
|
|
} catch (Exception $e) { |
328
|
|
|
$this->pageAlert($e->getMessage(), Alert::ERROR); |
329
|
|
|
} |
330
|
|
|
} |
331
|
|
|
} |
332
|
|
|
} |
333
|
|
|
|
Classes in PHP are usually named in CamelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.
Thus the name database provider becomes
DatabaseProvider
.