Commit | Line | Data |
---|---|---|
b9934a17 DM |
1 | <?php |
2 | // This file is part of Moodle - http://moodle.org/ | |
3 | // | |
4 | // Moodle is free software: you can redistribute it and/or modify | |
5 | // it under the terms of the GNU General Public License as published by | |
6 | // the Free Software Foundation, either version 3 of the License, or | |
7 | // (at your option) any later version. | |
8 | // | |
9 | // Moodle is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | // | |
14 | // You should have received a copy of the GNU General Public License | |
15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
17 | /** | |
18 | * Renderer for core_admin subsystem | |
19 | * | |
20 | * @package core | |
21 | * @subpackage admin | |
22 | * @copyright 2011 David Mudrak <david@moodle.com> | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
25 | ||
26 | defined('MOODLE_INTERNAL') || die(); | |
27 | ||
28 | require_once($CFG->libdir . '/pluginlib.php'); | |
29 | ||
30 | /** | |
31 | * Standard HTML output renderer for core_admin subsystem | |
32 | */ | |
33 | class core_admin_renderer extends plugin_renderer_base { | |
34 | ||
35 | /** | |
36 | * Displays all known plugins and information about their installation or upgrade | |
37 | * | |
38 | * This default implementation renders all plugins into one big table. The rendering | |
39 | * options support: | |
40 | * (bool)full = false: whether to display up-to-date plugins, too | |
41 | * | |
36ca62ca | 42 | * @param plugin_manager $pluginman provides information about the plugins. |
b9934a17 DM |
43 | * @param array $options rendering options |
44 | * @return string HTML code | |
45 | */ | |
36ca62ca TH |
46 | public function plugins_check(plugin_manager $pluginman, array $options = null) { |
47 | global $CFG; | |
48 | $plugininfo = $pluginman->get_plugins(); | |
b9934a17 DM |
49 | |
50 | if (empty($plugininfo)) { | |
51 | return ''; | |
52 | } | |
53 | ||
54 | if (empty($options)) { | |
55 | $options = array( | |
56 | 'full' => false, | |
57 | ); | |
58 | } | |
59 | ||
b9934a17 DM |
60 | $table = new html_table(); |
61 | $table->id = 'plugins-check'; | |
62 | $table->head = array( | |
63 | get_string('displayname', 'core_plugin'), | |
64 | get_string('rootdir', 'core_plugin'), | |
65 | get_string('source', 'core_plugin'), | |
66 | get_string('versiondb', 'core_plugin'), | |
67 | get_string('versiondisk', 'core_plugin'), | |
36ca62ca | 68 | get_string('requires', 'core_plugin'), |
b9934a17 DM |
69 | get_string('status', 'core_plugin'), |
70 | ); | |
71 | $table->colclasses = array( | |
36ca62ca | 72 | 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status', |
b9934a17 DM |
73 | ); |
74 | $table->data = array(); | |
75 | ||
76 | $numofhighlighted = array(); // number of highlighted rows per this subsection | |
77 | ||
78 | foreach ($plugininfo as $type => $plugins) { | |
79 | ||
80 | $header = new html_table_cell($pluginman->plugintype_name_plural($type)); | |
81 | $header->header = true; | |
82 | $header->colspan = count($table->head); | |
83 | $header = new html_table_row(array($header)); | |
84 | $header->attributes['class'] = 'plugintypeheader type-' . $type; | |
85 | ||
86 | $numofhighlighted[$type] = 0; | |
87 | ||
88 | if (empty($plugins) and $options['full']) { | |
89 | $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin')); | |
90 | $msg->colspan = count($table->head); | |
91 | $row = new html_table_row(array($msg)); | |
92 | $row->attributes['class'] .= 'msg msg-noneinstalled'; | |
93 | $table->data[] = $header; | |
94 | $table->data[] = $row; | |
95 | continue; | |
96 | } | |
97 | ||
98 | $plugintyperows = array(); | |
99 | ||
100 | foreach ($plugins as $name => $plugin) { | |
101 | $row = new html_table_row(); | |
102 | $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name; | |
103 | ||
104 | if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) { | |
105 | $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon')); | |
106 | } else { | |
107 | $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon')); | |
108 | } | |
109 | $displayname = $icon . ' ' . $plugin->displayname; | |
110 | $displayname = new html_table_cell($displayname); | |
111 | ||
112 | $rootdir = new html_table_cell($plugin->get_dir()); | |
113 | ||
114 | if ($isstandard = $plugin->is_standard()) { | |
115 | $row->attributes['class'] .= ' standard'; | |
116 | $source = new html_table_cell(get_string('sourcestd', 'core_plugin')); | |
117 | } else { | |
118 | $row->attributes['class'] .= ' extension'; | |
119 | $source = new html_table_cell(get_string('sourceext', 'core_plugin')); | |
120 | } | |
121 | ||
122 | $versiondb = new html_table_cell($plugin->versiondb); | |
123 | $versiondisk = new html_table_cell($plugin->versiondisk); | |
124 | ||
125 | $statuscode = $plugin->get_status(); | |
126 | $row->attributes['class'] .= ' status-' . $statuscode; | |
127 | ||
128 | $status = new html_table_cell(get_string('status_' . $statuscode, 'core_plugin')); | |
129 | ||
36ca62ca TH |
130 | $requires = new html_table_cell($this->required_column($plugin, $pluginman)); |
131 | ||
132 | $statusisboring = in_array($statuscode, array( | |
133 | plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE)); | |
134 | $dependanciesok = $pluginman->are_dependancies_satisfied( | |
135 | $plugin->get_other_required_plugins()); | |
136 | if ($isstandard and $statusisboring and $dependanciesok) { | |
b9934a17 DM |
137 | if (empty($options['full'])) { |
138 | continue; | |
139 | } | |
140 | } else { | |
141 | $numofhighlighted[$type]++; | |
142 | } | |
143 | ||
36ca62ca TH |
144 | $row->cells = array($displayname, $rootdir, $source, |
145 | $versiondb, $versiondisk, $requires, $status); | |
b9934a17 DM |
146 | $plugintyperows[] = $row; |
147 | } | |
148 | ||
149 | if (empty($numofhighlighted[$type]) and empty($options['full'])) { | |
150 | continue; | |
151 | } | |
152 | ||
153 | $table->data[] = $header; | |
154 | $table->data = array_merge($table->data, $plugintyperows); | |
155 | } | |
156 | ||
157 | $sumofhighlighted = array_sum($numofhighlighted); | |
158 | ||
159 | if ($sumofhighlighted == 0) { | |
160 | $out = $this->output->container_start('nonehighlighted', 'plugins-check-info'); | |
161 | $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin')); | |
162 | if (empty($options['full'])) { | |
163 | $out .= html_writer::link(new moodle_url('/admin/index.php', | |
164 | array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)), | |
165 | get_string('nonehighlightedinfo', 'core_plugin')); | |
166 | } | |
167 | $out .= $this->output->container_end(); | |
168 | ||
169 | } else { | |
170 | $out = $this->output->container_start('somehighlighted', 'plugins-check-info'); | |
171 | $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted)); | |
172 | if (empty($options['full'])) { | |
173 | $out .= html_writer::link(new moodle_url('/admin/index.php', | |
174 | array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)), | |
175 | get_string('somehighlightedinfo', 'core_plugin')); | |
176 | } | |
177 | $out .= $this->output->container_end(); | |
178 | } | |
179 | ||
180 | if ($sumofhighlighted > 0 or $options['full']) { | |
181 | $out .= html_writer::table($table); | |
182 | } | |
183 | ||
184 | return $out; | |
185 | } | |
186 | ||
36ca62ca TH |
187 | /** |
188 | * Formats the information that needs to go in the 'Requires' column. | |
189 | * @param plugin_information $plugin the plugin we are rendering the row for. | |
190 | * @param plugin_manager $pluginman provides data on all the plugins. | |
191 | */ | |
192 | protected function required_column($plugin, $pluginman) { | |
193 | global $CFG; | |
194 | $requires = array(); | |
195 | ||
196 | if (!empty($plugin->versionrequires)) { | |
197 | if ($plugin->versionrequires <= $CFG->version) { | |
198 | $class = 'requires-ok'; | |
199 | } else { | |
200 | $class = 'requires-failed'; | |
201 | } | |
202 | $requires[] = html_writer::tag('li', | |
203 | get_string('moodleversion', 'core_plugin', $plugin->versionrequires), | |
204 | array('class' => $class)); | |
205 | } | |
206 | ||
207 | foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) { | |
208 | $ok = true; | |
209 | $otherplugin = $pluginman->get_plugin_info($component); | |
210 | ||
211 | if (is_null($otherplugin)) { | |
212 | $ok = false; | |
213 | } | |
214 | if ($requiredversion != ANY_VERSION and $otherplugin->versiondb < $requiredversion) { | |
215 | $ok = false; | |
216 | } | |
217 | ||
218 | if ($ok) { | |
219 | $class = 'requires-ok'; | |
220 | } else { | |
221 | $class = 'requires-failed'; | |
222 | } | |
223 | ||
224 | if ($requiredversion != ANY_VERSION) { | |
225 | $str = 'otherpluginversion'; | |
226 | } else { | |
227 | $str = 'otherplugin'; | |
228 | } | |
229 | $requires[] = html_writer::tag('li', | |
230 | get_string($str, 'core_plugin', | |
231 | array('component' => $component, 'version' => $requiredversion)), | |
232 | array('class' => $class)); | |
233 | } | |
234 | ||
235 | if (!$requires) { | |
236 | return ''; | |
237 | } | |
238 | return html_writer::tag('ul', implode("\n", $requires)); | |
239 | } | |
240 | ||
b9934a17 DM |
241 | /** |
242 | * Displays all known plugins and links to manage them | |
243 | * | |
244 | * This default implementation renders all plugins into one big table. | |
245 | * | |
36ca62ca | 246 | * @param plugin_manager $pluginman provides information about the plugins. |
b9934a17 DM |
247 | * @return string HTML code |
248 | */ | |
36ca62ca TH |
249 | public function plugins_control_panel(plugin_manager $pluginman) { |
250 | $plugininfo = $pluginman->get_plugins(); | |
b9934a17 DM |
251 | |
252 | if (empty($plugininfo)) { | |
253 | return ''; | |
254 | } | |
255 | ||
b9934a17 DM |
256 | $table = new html_table(); |
257 | $table->id = 'plugins-control-panel'; | |
258 | $table->head = array( | |
259 | get_string('displayname', 'core_plugin'), | |
260 | get_string('systemname', 'core_plugin'), | |
261 | get_string('source', 'core_plugin'), | |
262 | get_string('version', 'core_plugin'), | |
263 | get_string('availability', 'core_plugin'), | |
264 | get_string('settings', 'core_plugin'), | |
265 | get_string('uninstall','core_plugin'), | |
266 | ); | |
267 | $table->colclasses = array( | |
268 | 'displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall', | |
269 | ); | |
270 | ||
271 | foreach ($plugininfo as $type => $plugins) { | |
272 | ||
273 | $header = new html_table_cell($pluginman->plugintype_name_plural($type)); | |
274 | $header->header = true; | |
275 | $header->colspan = count($table->head); | |
276 | $header = new html_table_row(array($header)); | |
277 | $header->attributes['class'] = 'plugintypeheader type-' . $type; | |
278 | $table->data[] = $header; | |
279 | ||
280 | if (empty($plugins)) { | |
281 | $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin')); | |
282 | $msg->colspan = count($table->head); | |
283 | $row = new html_table_row(array($msg)); | |
284 | $row->attributes['class'] .= 'msg msg-noneinstalled'; | |
285 | $table->data[] = $row; | |
286 | continue; | |
287 | } | |
288 | ||
289 | foreach ($plugins as $name => $plugin) { | |
290 | $row = new html_table_row(); | |
291 | $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name; | |
292 | ||
293 | if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) { | |
294 | $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon')); | |
295 | } else { | |
296 | $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon')); | |
297 | } | |
298 | if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) { | |
299 | $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem')); | |
300 | $row->attributes['class'] .= ' missingfromdisk'; | |
301 | } else { | |
302 | $msg = ''; | |
303 | } | |
304 | $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg; | |
305 | $displayname = new html_table_cell($displayname); | |
306 | ||
307 | $systemname = new html_table_cell($plugin->type . '_' . $plugin->name); | |
308 | ||
309 | if ($plugin->is_standard()) { | |
310 | $row->attributes['class'] .= ' standard'; | |
311 | $source = new html_table_cell(get_string('sourcestd', 'core_plugin')); | |
312 | } else { | |
313 | $row->attributes['class'] .= ' extension'; | |
314 | $source = new html_table_cell(get_string('sourceext', 'core_plugin')); | |
315 | } | |
316 | ||
317 | $version = new html_table_cell($plugin->versiondb); | |
318 | ||
319 | $isenabled = $plugin->is_enabled(); | |
320 | if (is_null($isenabled)) { | |
321 | $availability = new html_table_cell(''); | |
322 | } else if ($isenabled) { | |
323 | $row->attributes['class'] .= ' enabled'; | |
324 | $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin')); | |
325 | $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin')); | |
326 | } else { | |
327 | $row->attributes['class'] .= ' disabled'; | |
328 | $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin')); | |
329 | $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin')); | |
330 | } | |
331 | ||
332 | $settingsurl = $plugin->get_settings_url(); | |
333 | if (is_null($settingsurl)) { | |
334 | $settings = new html_table_cell(''); | |
335 | } else { | |
336 | $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin')); | |
337 | $settings = new html_table_cell($settings); | |
338 | } | |
339 | ||
340 | $uninstallurl = $plugin->get_uninstall_url(); | |
341 | if (is_null($uninstallurl)) { | |
342 | $uninstall = new html_table_cell(''); | |
343 | } else { | |
344 | $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin')); | |
345 | $uninstall = new html_table_cell($uninstall); | |
346 | } | |
347 | ||
348 | $row->cells = array( | |
349 | $displayname, $systemname, $source, $version, $availability, $settings, $uninstall | |
350 | ); | |
351 | $table->data[] = $row; | |
352 | } | |
353 | } | |
354 | ||
355 | return html_writer::table($table); | |
356 | } | |
da2fdc3f TH |
357 | |
358 | /** | |
359 | * @global object | |
360 | */ | |
361 | function upgrade_reload($url) { | |
362 | return html_writer::empty_tag('br') . | |
363 | html_writer::tag('div', | |
364 | html_writer::link($url, $this->pix_icon('i/reload', '') . | |
365 | get_string('reload'), array('title' => get_string('reload'))), | |
366 | array('class' => 'continuebutton')) . html_writer::empty_tag('br'); | |
367 | } | |
b9934a17 | 368 | } |