/
content.systemextensions.php
executable file
·202 lines (159 loc) · 6.52 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
<?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');
Class contentSystemExtensions extends AdministrationPage{
public function __viewIndex(){
$this->setPageType('table');
$this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Extensions'))));
$this->appendSubheading(__('Extensions'));
$this->Form->setAttribute('action', SYMPHONY_URL . '/system/extensions/');
$extensions = Symphony::ExtensionManager()->listAll();
## Sort by extensions name:
uasort($extensions, array('ExtensionManager', 'sortByName'));
$aTableHead = array(
array(__('Name'), 'col'),
array(__('Installed Version'), 'col'),
array(__('Enabled'), 'col'),
array(__('Author'), 'col'),
);
$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((!empty($about['table-link']) && $about['status'] == EXTENSION_ENABLED ? Widget::Anchor($about['name'], Administration::instance()->getCurrentPageURL() . 'extension/' . trim($about['table-link'], '/') . '/') : $about['name']));
$installed_version = Symphony::ExtensionManager()->fetchInstalledVersion($name);
$td2 = Widget::TableData(is_null($installed_version) ? __('Not Installed') : $installed_version);
if($about['status'] == EXTENSION_ENABLED) {
$td3 = Widget::TableData(__('Yes'));
}
else if($about['status'] == EXTENSION_DISABLED) {
$td3 = Widget::TableData(__('Disabled'));
}
else if($about['status'] == EXTENSION_NOT_INSTALLED) {
$td3 = Widget::TableData(__('Enable to install %s', array($about['version'])));
}
else if($about['status'] == EXTENSION_REQUIRES_UPDATE) {
$td3 = Widget::TableData(__('Enable to update to %s', array($about['version'])));
}
$td4 = Widget::TableData(NULL);
if($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), ($about['status'] == EXTENSION_NOT_INSTALLED ? 'inactive' : NULL));
}
}
$table = Widget::Table(
Widget::TableHead($aTableHead),
NULL,
Widget::TableBody($aTableBody),
'selectable'
);
$this->Form->appendChild($table);
$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?')
))
);
$tableActions->appendChild(Widget::Select('with-selected', $options));
$tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit'));
$this->Form->appendChild($tableActions);
}
public function __actionIndex(){
$checked = (is_array($_POST['items'])) ? array_keys($_POST['items']) : null;
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);
}
}
}
}