/theme/bootstrap/renderers.php
PHP | 1377 lines | 1005 code | 198 blank | 174 comment | 202 complexity | 41410d965b4c280b4a21cb4638029d19 MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0, BSD-3-Clause, LGPL-2.1, AGPL-3.0, MPL-2.0-no-copyleft-exception, LGPL-3.0
- <?php
- /* renderers to align Moodle's HTML with that expected by Bootstrap */
- class theme_bootstrap_core_renderer extends core_renderer {
- static $icons_ignore = array(
- 'icon' => '?', // all the module icons have this name
- 't/groups' => '?',
- 't/groupn' => '?',
- 't/groupv' => '?' );
- static $icons = array(
- 'docs' => 'question-sign',
- 'book' => 'book',
- 'chapter' => 'file',
- 'spacer' => 'spacer',
- 'generate' => 'gift',
- 'add' => 'plus',
- 't/hide' => 'eye-open',
- 'i/hide' => 'eye-open',
- 't/show' => 'eye-close',
- 'i/show' => 'eye-close',
- 't/add' => 'plus',
- 't/right' => 'arrow-right',
- 't/left' => 'arrow-left',
- 't/up' => 'arrow-up',
- 't/down' => 'arrow-down',
- 't/edit' => 'edit',
- 't/editstring' => 'tag',
- 't/delete' => 'remove',
- 'i/edit' => 'pencil',
- 't/copy' => 'copy', // created png from font awesome
- 'i/settings' => 'list-alt',
- 'i/grades' => 'grades',
- 'i/group' => 'user',
- 't/switch_plus' => 'plus-sign',
- 't/switch_minus' => 'minus-sign',
- 'i/filter' => 'filter',
- 't/move' => 'resize-vertical',
- 'i/move_2d' => 'move',
- 'i/backup' => 'cog',
- 'i/restore' => 'cog',
- 'i/return' => 'repeat',
- 'i/reload' => 'refresh',
- 'i/roles' => 'user',
- 'i/user' => 'user',
- 'i/users' => 'user',
- 'i/publish' => 'publish',
- 'i/navigationitem' => 'chevron-right' );
- protected static function icon($name, $text=null) {
- if (!$text) {$text = $name;}
- return "<i class=icon-$name>$text</i>";
- }
- protected static function moodle_icon($name) {
- return self::icon(self::$icons[$name]);
- }
- public function icon_help() {
- return self::icon('question-sign');
- }
- protected static function a($attributes, $content) {
- return html_writer::tag('a', $content, $attributes);
- }
- protected static function div($attributes, $content) {
- return html_writer::tag('div', $content, $attributes);
- }
- protected static function span($attributes, $content) {
- return html_writer::tag('span', $content, $attributes);
- }
- protected static function ul($items) {
- $lis = array();
- foreach ($items as $key => $string) {
- $lis[] = "<li>$string</li>";
- }
- return '<ul class=unstyled>'.implode($lis).'</ul>';
- }
- public function action_icon($url, pix_icon $pixicon, component_action $action = null, array $attributes = null, $linktext=false) {
- if (!($url instanceof moodle_url)) {
- $url = new moodle_url($url);
- }
- $attributes = (array)$attributes;
- if (empty($attributes['class'])) {
- // let ppl override the class via $options
- $attributes['class'] = 'action-icon';
- }
- $icon = $this->render($pixicon);
- if ($linktext) {
- $text = $pixicon->attributes['alt'];
- } else {
- $text = '';
- }
- return $this->action_link($url, $text.$icon, $action, $attributes);
- }
- public function home_link() {
- global $CFG, $SITE;
- $text = '';
- $linktext = 'Moodle';
- if ($this->page->pagetype == 'site-index') {
- $div_attributes['class'] = "sitelink";
- $text = 'Made with ';
- $a_attributes['href'] = 'http://moodle.org/';
- } else if (!empty($CFG->target_release) &&
- $CFG->target_release != $CFG->release) {
- // Special case for during install/upgrade.
- $div_attributes['class'] = "sitelink";
- $text = 'help with ';
- $a_attributes['href'] = 'http://docs.moodle.org/en/Administrator_documentation';
- $a_attributes['target'] = '_blank';
- } else if ($this->page->course->id == $SITE->id ||
- strpos($this->page->pagetype, 'course-view') === 0) {
- $div_attributes['class'] = "homelink";
- $linktext = get_string('home');
- $a_attributes['href'] = $CFG->wwwroot . '/';
- } else {
- $div_attributes['class'] = "homelink";
- $linktext = format_string($this->page->course->shortname, true, array('context' => $this->page->context));
- $a_attributes['href'] = $CFG->wwwroot . '/course/view.php?id=' . $this->page->course->id;
- }
- return self::div($div_attributes, $text . self::a($a_attributes, $linktext));
- }
- protected function render_pix_icon(pix_icon $icon) {
- if (isset(self::$icons_ignore[$icon->pix])) {
- return parent::render_pix_icon($icon);
- } else if (isset(self::$icons[$icon->pix])) {
- return self::icon(self::$icons[$icon->pix]);
- } else {
- return parent::render_pix_icon($icon);
- //return '<i class=icon-not-assigned data-debug-icon="'.$icon->pix.'"></i>';
- }
- }
- protected function render_custom_menu(custom_menu $menu) {
- if (!$menu->has_children()) {
- return '';
- }
- $content = '<div class="navbar navbar-fixed-top">' .
- '<div class=navbar-inner>' .
- '<div class=container>' .
- '<ul class=nav>';
- foreach ($menu->get_children() as $item) {
- $content .= $this->render_custom_menu_item($item);
- }
- $content .= '</ul></div></div><div>';
- return $content;
- }
- protected function render_custom_menu_item(custom_menu_item $menunode) {
- // Required to ensure we get unique trackable id's
- static $submenucount = 0;
- if ($menunode->has_children()) {
- $content = '<li class=dropdown>';
- // If the child has menus render it as a sub menu
- $submenucount++;
- if ($menunode->get_url() !== null) {
- $url = $menunode->get_url();
- } else {
- $url = '#cm_submenu_'.$submenucount;
- }
- //$content .= html_writer::link($url, $menunode->get_text(), array('title'=>,));
- $content .= '<a href="'.$url.'" class=dropdown-toggle data-toggle=dropdown>';
- $content .= $menunode->get_title();
- $content .= '<b class=caret></b></a>';
- $content .= '<ul class=dropdown-menu>';
- foreach ($menunode->get_children() as $menunode) {
- $content .= $this->render_custom_menu_item($menunode);
- }
- $content .= '</ul>';
- } else {
- $content = '<li>';
- // The node doesn't have children so produce a final menuitem
- if ($menunode->get_url() !== null) {
- $url = $menunode->get_url();
- } else {
- $url = '#';
- }
- $content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
- }
- $content .= '<li>';
- return $content;
- }
- public function block_controls($controls) {
- if (empty($controls)) {
- return '';
- }
- $controlshtml = array();
- foreach ($controls as $control) {
- $controlshtml[] = self::a(array('href'=>$control['url'], 'title'=>$control['caption']), self::moodle_icon($control['icon']));
- }
- return self::div(array('class'=>'commands'), implode($controlshtml));
- }
- public function list_block_contents($icons, $items) {
- return self::ul($items);
- }
- public function doc_link($path, $text = '') {
- $attributes['href'] = new moodle_url(get_docs_url($path));
- if ($text == '') {
- $linktext = $this->icon_help();
- } else {
- $linktext = $this->icon_help().' '.$text; }
- return self::a($attributes, $linktext);
- }
- public function icon_spacer(array $attributes = null, $br = false) {
- return self::icon('spacer', '');
- // don't output br's or attributes
- }
- public function error_text($message) {
- if (empty($message)) { return ''; }
- return self::span(array('class'=>'label label-important'), $message);
- }
- public function notification($message, $classes = 'notifyproblem') {
- // TODO rewrite recognized classnames to bootstrap alert equivalent
- if ($classes = 'notifyproblem') { $classes = 'alert-error';}
- if ($classes = 'notifysuccess') { $classes = 'alert-success';}
- return self::div(array('class'=>'alert '.$classes), clean_text($message));
- }
- protected function render_paging_bar(paging_bar $pagingbar) {
- // this is more complicated than it needs to be, see MDL-35367
- $pagingbar->maxdisplay = 11; // odd number for symmetry
- $pagingbar = clone($pagingbar);
- $pagingbar->prepare($this, $this->page, $this->target);
- $show_pagingbar = ($pagingbar->totalcount > $pagingbar->perpage);
- if ($show_pagingbar) {
- $baseurl = $pagingbar->baseurl;
- $pagevar = $pagingbar->pagevar;
- $maxdisplay = max($pagingbar->maxdisplay, 5);
- $page = $pagingbar->page;
- $output = '<div class="pagination pagination-centered"><ul>';
- // Note: page 0 is displayed to users as page 1 and so on.
- if ($pagingbar->perpage > 0) {
- $lastpage = floor($pagingbar->totalcount / $pagingbar->perpage);
- } else {
- $lastpage = 0;
- }
- if ($page != 0) {
- $previouslink = html_writer::link(new moodle_url($baseurl, array($pagevar=>$page-1)), get_string('previous'));
- $output .= "<li>$previouslink</li>";
- } else {
- $output .= '<li class=disabled><span>'.get_string('previous').'</span></li>';
- }
- $start = 0;
- $stop = $lastpage;
- $truncate = $lastpage + 1 > $maxdisplay ;
- $start_margin = floor($maxdisplay / 2);
- $end_margin = $lastpage - ceil($maxdisplay / 2);
- $near_to_start = $page < $start_margin;
- $near_to_end = $page > $end_margin;
- if ($truncate && $near_to_start) {
- $stop = $maxdisplay - 3;
- } else if ($truncate && $near_to_end) {
- $start = $lastpage - $maxdisplay + 3;
- } else if ($truncate) { // truncate both sides, centered on current page
- $before_current = ceil(($maxdisplay - 5) / 2) ;
- $start = $page - $before_current;
- $stop = $start + $maxdisplay - 5;
- }
- if ($truncate && !$near_to_start) {
- $link = html_writer::link(new moodle_url($baseurl, array($pagevar=>'0')), '1');
- $output .= "<li>$link</li>" . "<li class=disabled><span>…</span></li>";
- }
- for ($i = $start; $i <= $stop; $i++) {
- if ($page == $i) {
- $pagename = $page + 1;
- $output .= "<li class=active><span>$pagename</span></li>";
- } else {
- $link = html_writer::link(new moodle_url($baseurl, array($pagevar=>$i)), $i+1);
- $output .= "<li>$link</li>";
- }
- }
- if ($truncate && !$near_to_end) {
- $output .= "<li class=disabled><span>…</span>";
- $link = html_writer::link(new moodle_url($baseurl, array($pagevar=>$lastpage)), $lastpage + 1);
- $output .= "<li>$link</li>";
- }
- if ($page != $lastpage) {
- $nextlink = html_writer::link(new moodle_url($baseurl, array($pagevar=>$page+1)), get_string('next'));
- $output .= "<li>$nextlink</li>";
- } else {
- $output .= '<li class=disabled><span>'.get_string('next').'</span></li>';
- }
- return $output."</ul></div>";
- }
- }
- public function navbar() {
- $items = $this->page->navbar->get_items();
- $htmlblocks = array();
- //$divider = '<span class="divider">'.get_separator().'</span>';
- $divider = self::span(array('class'=>'divider'), '/');
- $navbarcontent = '<ul class=breadcrumb>';
- $itemcount = count($items);
- $lis = array();
- for ($i=1;$i <= $itemcount;$i++) {
- $item = $items[$i-1];
- $item->hideicon = true;
- if ($i===$itemcount) {
- $li= "<li>".$this->render($item)."</li>";
- } else {
- $li= "<li>".$this->render($item)." $divider</li>";
- }
- $lis[] = $li;
- }
- $navbarcontent .= join('', $lis).'</ul>';
- return $navbarcontent;
- }
- protected function render_single_button(single_button $button) {
- $attributes = array('type' => 'submit',
- 'class' => 'btn',
- 'value' => $button->label,
- 'disabled' => $button->disabled ? 'disabled' : null,
- 'title' => $button->tooltip);
- if ($button->actions) {
- $id = html_writer::random_id('single_button');
- $attributes['id'] = $id;
- foreach ($button->actions as $action) {
- $this->add_action_handler($action, $id);
- }
- }
- // first the input element
- $output = html_writer::empty_tag('input', $attributes);
- // then hidden fields
- $params = $button->url->params();
- if ($button->method === 'post') {
- $params['sesskey'] = sesskey();
- }
- foreach ($params as $var => $val) {
- $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $var, 'value' => $val));
- }
- // then div wrapper for xhtml strictness
- $output = html_writer::tag('div', $output);
- // now the form itself around it
- if ($button->method === 'get') {
- $url = $button->url->out_omit_querystring(true); // url without params, the anchor part allowed
- } else {
- $url = $button->url->out_omit_querystring(); // url without params, the anchor part not allowed
- }
- if ($url === '') {
- $url = '#'; // there has to be always some action
- }
- $attributes = array('method' => $button->method,
- 'class' => 'form-inline',
- 'action' => $url,
- 'id' => $button->formid);
- $output = html_writer::tag('form', $output, $attributes);
- return self::div(array('class' => $button->class), $output);
- }
- protected function render_single_select(single_select $select) {
- $select = clone($select);
- if (empty($select->formid)) {
- $select->formid = html_writer::random_id('single_select_f');
- }
- $output = '';
- $params = $select->url->params();
- if ($select->method === 'post') {
- $params['sesskey'] = sesskey();
- }
- foreach ($params as $name=>$value) {
- $output .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$name, 'value'=>$value));
- }
- if (empty($select->attributes['id'])) {
- $select->attributes['id'] = html_writer::random_id('single_select');
- }
- if ($select->disabled) {
- $select->attributes['disabled'] = 'disabled';
- }
- if ($select->tooltip) {
- $select->attributes['title'] = $select->tooltip;
- }
- if ($select->label) {
- $output .= html_writer::label($select->label, $select->attributes['id'], false, $select->labelattributes);
- }
- if ($select->helpicon instanceof help_icon) {
- $output .= $this->render($select->helpicon);
- } else if ($select->helpicon instanceof old_help_icon) {
- $output .= $this->render($select->helpicon);
- }
- $output .= html_writer::select($select->options, $select->name, $select->selected, $select->nothing, $select->attributes);
- $go = html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('go')));
- $output .= html_writer::tag('noscript', $go);
- $nothing = empty($select->nothing) ? false : key($select->nothing);
- $this->page->requires->js_init_call('M.util.init_select_autosubmit', array($select->formid, $select->attributes['id'], $nothing));
- // then div wrapper for xhtml strictness
- $output = html_writer::tag('div', $output);
- // now the form itself around it
- if ($select->method === 'get') {
- $url = $select->url->out_omit_querystring(true); // url without params, the anchor part allowed
- } else {
- $url = $select->url->out_omit_querystring(); // url without params, the anchor part not allowed
- }
- $formattributes = array('method' => $select->method,
- 'class' => 'form-inline',
- 'action' => $url,
- 'id' => $select->formid);
- $output = html_writer::tag('form', $output, $formattributes);
- // and finally one more wrapper with class
- return self::div(array('class' => $select->class), $output);
- }
- protected function init_block_hider_js(block_contents $bc) { }
- }
- include_once($CFG->dirroot . "/admin/renderer.php");
- class theme_bootstrap_core_admin_renderer extends core_admin_renderer {
-
- /**
- * Display the 'Do you acknowledge the terms of the GPL' page. The first page
- * during install.
- * @return string HTML to output.
- */
- public function install_licence_page() {
- global $CFG;
- $output = '';
- $copyrightnotice = text_to_html(get_string('gpl3'));
- $copyrightnotice = str_replace('target="_blank"', 'onclick="this.target=\'_blank\'"', $copyrightnotice); // extremely ugly validation hack
- $continue = new single_button(new moodle_url('/admin/index.php', array('lang'=>$CFG->lang, 'agreelicense'=>1)), get_string('continue'), 'get');
- $output .= $this->header();
- $output .= $this->heading('<a href="http://moodle.org">Moodle</a> - Modular Object-Oriented Dynamic Learning Environment');
- $output .= $this->heading(get_string('copyrightnotice'));
- $output .= $this->box($copyrightnotice, 'copyrightnotice');
- $output .= html_writer::empty_tag('br');
- $output .= $this->confirm(get_string('doyouagree'), $continue, "http://docs.moodle.org/dev/License");
- $output .= $this->footer();
- return $output;
- }
- /**
- * Display page explaining proper upgrade process,
- * there can not be any PHP file leftovers...
- *
- * @return string HTML to output.
- */
- public function upgrade_stale_php_files_page() {
- $output = '';
- $output .= $this->header();
- $output .= $this->heading(get_string('upgradestalefiles', 'admin'));
- $output .= $this->box_start('generalbox', 'notice');
- $output .= format_text(get_string('upgradestalefilesinfo', 'admin', get_docs_url('Upgrading')), FORMAT_MARKDOWN);
- $output .= html_writer::empty_tag('br');
- $output .= html_writer::tag('div', $this->single_button($this->page->url, get_string('reload'), 'get'), array('class' => 'buttons'));
- $output .= $this->box_end();
- $output .= $this->footer();
- return $output;
- }
- /**
- * Display the 'environment check' page that is displayed during install.
- * @param int $maturity
- * @param boolean $envstatus final result of the check (true/false)
- * @param array $environment_results array of results gathered
- * @param string $release moodle release
- * @return string HTML to output.
- */
- public function install_environment_page($maturity, $envstatus, $environment_results, $release) {
- global $CFG;
- $output = '';
- $output .= $this->header();
- $output .= $this->maturity_warning($maturity);
- $output .= $this->heading("Moodle $release");
- $output .= $this->release_notes_link();
- $output .= $this->environment_check_table($envstatus, $environment_results);
- if (!$envstatus) {
- $output .= $this->upgrade_reload(new moodle_url('/admin/index.php', array('agreelicense' => 1, 'lang' => $CFG->lang)));
- } else {
- $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
- $output .= $this->continue_button(new moodle_url('/admin/index.php', array('agreelicense'=>1, 'confirmrelease'=>1, 'lang'=>$CFG->lang)));
- }
- $output .= $this->footer();
- return $output;
- }
- /**
- * Displays the list of plugins with unsatisfied dependencies
- *
- * @param double|string|int $version Moodle on-disk version
- * @param array $failed list of plugins with unsatisfied dependecies
- * @param moodle_url $reloadurl URL of the page to recheck the dependencies
- * @return string HTML
- */
- public function unsatisfied_dependencies_page($version, array $failed, moodle_url $reloadurl) {
- $output = '';
- $output .= $this->header();
- $output .= $this->heading(get_string('pluginscheck', 'admin'));
- $output .= $this->warning(get_string('pluginscheckfailed', 'admin', array('pluginslist' => implode(', ', array_unique($failed)))));
- $output .= $this->plugins_check_table(plugin_manager::instance(), $version, array('xdep' => true));
- $output .= $this->warning(get_string('pluginschecktodo', 'admin'));
- $output .= $this->continue_button($reloadurl);
- $output .= $this->footer();
- return $output;
- }
- /**
- * Display the 'You are about to upgrade Moodle' page. The first page
- * during upgrade.
- * @param string $strnewversion
- * @param int $maturity
- * @return string HTML to output.
- */
- public function upgrade_confirm_page($strnewversion, $maturity) {
- $output = '';
- $continueurl = new moodle_url('index.php', array('confirmupgrade' => 1));
- $cancelurl = new moodle_url('index.php');
- $output .= $this->header();
- $output .= $this->maturity_warning($maturity);
- $output .= $this->confirm(get_string('upgradesure', 'admin', $strnewversion), $continueurl, $cancelurl);
- $output .= $this->footer();
- return $output;
- }
- /**
- * Display the environment page during the upgrade process.
- * @param string $release
- * @param boolean $envstatus final result of env check (true/false)
- * @param array $environment_results array of results gathered
- * @return string HTML to output.
- */
- public function upgrade_environment_page($release, $envstatus, $environment_results) {
- global $CFG;
- $output = '';
- $output .= $this->header();
- $output .= $this->heading("Moodle $release");
- $output .= $this->release_notes_link();
- $output .= $this->environment_check_table($envstatus, $environment_results);
- if (!$envstatus) {
- $output .= $this->upgrade_reload(new moodle_url('/admin/index.php'), array('confirmupgrade' => 1));
- } else {
- $output .= $this->notification(get_string('environmentok', 'admin'), 'notifysuccess');
- if (empty($CFG->skiplangupgrade) and current_language() !== 'en') {
- $output .= $this->box(get_string('langpackwillbeupdated', 'admin'), 'generalbox', 'notice');
- }
- $output .= $this->continue_button(new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)));
- }
- $output .= $this->footer();
- return $output;
- }
- /**
- * Display the upgrade page that lists all the plugins that require attention.
- * @param plugin_manager $pluginman provides information about the plugins.
- * @param available_update_checker $checker provides information about available updates.
- * @param int $version the version of the Moodle code from version.php.
- * @param bool $showallplugins
- * @param moodle_url $reloadurl
- * @param moodle_url $continueurl
- * @return string HTML to output.
- */
- public function upgrade_plugin_check_page(plugin_manager $pluginman, available_update_checker $checker,
- $version, $showallplugins, $reloadurl, $continueurl) {
- global $CFG;
- $output = '';
- $output .= $this->header();
- $output .= $this->box_start('generalbox');
- $output .= $this->container_start('generalbox', 'notice');
- $output .= html_writer::tag('p', get_string('pluginchecknotice', 'core_plugin'));
- if (empty($CFG->disableupdatenotifications)) {
- $output .= $this->container_start('checkforupdates');
- $output .= $this->single_button(new moodle_url($reloadurl, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
- if ($timefetched = $checker->get_last_timefetched()) {
- $output .= $this->container(get_string('checkforupdateslast', 'core_plugin',
- userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'))));
- }
- $output .= $this->container_end();
- }
- $output .= $this->container_end();
- $output .= $this->plugins_check_table($pluginman, $version, array('full' => $showallplugins));
- $output .= $this->box_end();
- $output .= $this->upgrade_reload($reloadurl);
- if ($pluginman->some_plugins_updatable()) {
- $output .= $this->container_start('upgradepluginsinfo');
- $output .= $this->help_icon('upgradepluginsinfo', 'core_admin', get_string('upgradepluginsfirst', 'core_admin'));
- $output .= $this->container_end();
- }
- $button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get');
- $button->class = 'continuebutton';
- $output .= $this->render($button);
- $output .= $this->footer();
- return $output;
- }
- /**
- * Output a warning message, of the type that appears on the admin notifications page.
- * @param string $message the message to display.
- * @param string $type type class
- * @return string HTML to output.
- */
- protected function warning($message, $type = '') {
- if ($type == 'error') { $type = ' alert-error';}
- return html_writer::tag('div', $message, array('class'=>('alert' . $type)));
- }
- /**
- * Display a warning about installing development code if necesary.
- * @param int $maturity
- * @return string HTML to output.
- */
- protected function maturity_warning($maturity) {
- if ($maturity == MATURITY_STABLE) {
- return ''; // No worries.
- }
- $maturitylevel = get_string('maturity' . $maturity, 'admin');
- return html_writer::tag('div',
- $this->container(get_string('maturitycorewarning', 'admin', $maturitylevel)) .
- $this->container($this->doc_link('admin/versions', get_string('morehelp'))),
- 'alert maturitywarning');
- }
- /**
- * Output the copyright notice.
- * @return string HTML to output.
- */
- protected function moodle_copyright() {
- global $CFG;
- //////////////////////////////////////////////////////////////////////////////////////////////////
- //// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
- $copyrighttext = '<p><a href="http://moodle.org/">Moodle</a> '.
- '<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a></p>'.
- '<p>Copyright © 1999 onwards, Martin Dougiamas '.
- 'and <a href="http://docs.moodle.org/dev/Credits">many other contributors</a>.</p>'.
- '<p><a href="http://docs.moodle.org/dev/License">GNU Public License</a><p>';
- //////////////////////////////////////////////////////////////////////////////////////////////////
- return html_writer::tag('div', $copyrighttext, array('class'=>'alert alert-info copyright'));
- }
- /**
- * Display a warning about installing development code if necesary.
- * @param int $maturity
- * @return string HTML to output.
- */
- protected function maturity_info($maturity) {
- if ($maturity == MATURITY_STABLE) {
- return ''; // No worries.
- }
- $maturitylevel = get_string('maturity' . $maturity, 'admin');
- return $this->box(
- get_string('maturitycoreinfo', 'admin', $maturitylevel) . ' ' .
- $this->doc_link('admin/versions', get_string('morehelp')),
- 'alert maturityinfo maturity'.$maturity);
- }
- /**
- * Displays the info about available Moodle updates
- *
- * @param array|null $updates array of available_update_info objects or null
- * @param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
- * @return string
- */
- protected function available_updates($updates, $fetch) {
- $updateinfo = $this->box_start('alert alert-info availableupdatesinfo');
- if (is_array($updates)) {
- $updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
- foreach ($updates as $update) {
- $updateinfo .= $this->moodle_available_update_info($update);
- }
- } else {
- $now = time();
- if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
- $updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
- }
- }
- $updateinfo .= $this->container_start('checkforupdates');
- $updateinfo .= $this->single_button(new moodle_url($this->page->url, array('fetchupdates' => 1)), get_string('checkforupdates', 'core_plugin'));
- if ($fetch) {
- $updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
- userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
- }
- $updateinfo .= $this->container_end();
- $updateinfo .= $this->box_end();
- return $updateinfo;
- }
- function upgrade_reload($url) {
- return '<div><a class=btn href="' . $url. '"><i class=icon-refresh></i> ' . get_string('reload') . '</a></div>';
- }
- /**
- * Displays all known plugins and information about their installation or upgrade
- *
- * This default implementation renders all plugins into one big table. The rendering
- * options support:
- * (bool)full = false: whether to display up-to-date plugins, too
- * (bool)xdep = false: display the plugins with unsatisified dependecies only
- *
- * @param plugin_manager $pluginman provides information about the plugins.
- * @param int $version the version of the Moodle code from version.php.
- * @param array $options rendering options
- * @return string HTML code
- */
- public function plugins_check_table(plugin_manager $pluginman, $version, array $options = array()) {
- global $CFG;
- $plugininfo = $pluginman->get_plugins();
- if (empty($plugininfo)) {
- return '';
- }
- $options['full'] = isset($options['full']) ? (bool)$options['full'] : false;
- $options['xdep'] = isset($options['xdep']) ? (bool)$options['xdep'] : false;
- $table = new html_table();
- $table->id = 'plugins-check';
- $table->head = array(
- get_string('displayname', 'core_plugin'),
- get_string('rootdir', 'core_plugin'),
- get_string('source', 'core_plugin'),
- get_string('versiondb', 'core_plugin'),
- get_string('versiondisk', 'core_plugin'),
- get_string('requires', 'core_plugin'),
- get_string('status', 'core_plugin'),
- );
- $table->colclasses = array(
- 'displayname', 'rootdir', 'source', 'versiondb', 'versiondisk', 'requires', 'status',
- );
- $table->data = array();
- $numofhighlighted = array(); // number of highlighted rows per this subsection
- foreach ($plugininfo as $type => $plugins) {
- $header = new html_table_cell($pluginman->plugintype_name_plural($type));
- $header->header = true;
- $header->colspan = count($table->head);
- $header = new html_table_row(array($header));
- $header->attributes['class'] = 'plugintypeheader type-' . $type;
- $numofhighlighted[$type] = 0;
- if (empty($plugins) and $options['full']) {
- $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
- $msg->colspan = count($table->head);
- $row = new html_table_row(array($msg));
- $row->attributes['class'] .= 'warning msg-noneinstalled';
- $table->data[] = $header;
- $table->data[] = $row;
- continue;
- }
- $plugintyperows = array();
- foreach ($plugins as $name => $plugin) {
- $row = new html_table_row();
- $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
- if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
- $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
- } else {
- //$icon = this::icon_spacer();
- }
- $displayname = $icon . ' ' . $plugin->displayname;
- $displayname = new html_table_cell($displayname);
- $rootdir = new html_table_cell($plugin->get_dir());
- if ($isstandard = $plugin->is_standard()) {
- $row->attributes['class'] .= ' standard';
- $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
- } else {
- $row->attributes['class'] .= ' extension';
- $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
- }
- $versiondb = new html_table_cell($plugin->versiondb);
- $versiondisk = new html_table_cell($plugin->versiondisk);
- $statuscode = $plugin->get_status();
- $row->attributes['class'] .= ' status-' . $statuscode;
- $status = get_string('status_' . $statuscode, 'core_plugin');
- $availableupdates = $plugin->available_updates();
- if (!empty($availableupdates) and empty($CFG->disableupdatenotifications)) {
- foreach ($availableupdates as $availableupdate) {
- $status .= $this->plugin_available_update_info($availableupdate);
- }
- }
- $status = new html_table_cell($status);
- $requires = new html_table_cell($this->required_column($plugin, $pluginman, $version));
- $statusisboring = in_array($statuscode, array(
- plugin_manager::PLUGIN_STATUS_NODB, plugin_manager::PLUGIN_STATUS_UPTODATE));
- $coredependency = $plugin->is_core_dependency_satisfied($version);
- $otherpluginsdependencies = $pluginman->are_dependencies_satisfied($plugin->get_other_required_plugins());
- $dependenciesok = $coredependency && $otherpluginsdependencies;
- if ($options['xdep']) {
- // we want to see only plugins with failed dependencies
- if ($dependenciesok) {
- continue;
- }
- } else if ($isstandard and $statusisboring and $dependenciesok and empty($availableupdates)) {
- // no change is going to happen to the plugin - display it only
- // if the user wants to see the full list
- if (empty($options['full'])) {
- continue;
- }
- }
- // ok, the plugin should be displayed
- $numofhighlighted[$type]++;
- $row->cells = array($displayname, $rootdir, $source,
- $versiondb, $versiondisk, $requires, $status);
- $plugintyperows[] = $row;
- }
- if (empty($numofhighlighted[$type]) and empty($options['full'])) {
- continue;
- }
- $table->data[] = $header;
- $table->data = array_merge($table->data, $plugintyperows);
- }
- $sumofhighlighted = array_sum($numofhighlighted);
- if ($options['xdep']) {
- // we do not want to display no heading and links in this mode
- $out = '';
- } else if ($sumofhighlighted == 0) {
- $out = $this->output->container_start('nonehighlighted', 'plugins-check-info');
- $out .= $this->output->heading(get_string('nonehighlighted', 'core_plugin'));
- if (empty($options['full'])) {
- $out .= html_writer::link(new moodle_url('/admin/index.php',
- array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
- get_string('nonehighlightedinfo', 'core_plugin'));
- }
- $out .= $this->output->container_end();
- } else {
- $out = $this->output->container_start('somehighlighted', 'plugins-check-info');
- $out .= $this->output->heading(get_string('somehighlighted', 'core_plugin', $sumofhighlighted));
- if (empty($options['full'])) {
- $out .= html_writer::link(new moodle_url('/admin/index.php',
- array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 1)),
- get_string('somehighlightedinfo', 'core_plugin'));
- } else {
- $out .= html_writer::link(new moodle_url('/admin/index.php',
- array('confirmupgrade' => 1, 'confirmrelease' => 1, 'showallplugins' => 0)),
- get_string('somehighlightedonly', 'core_plugin'));
- }
- $out .= $this->output->container_end();
- }
- if ($sumofhighlighted > 0 or $options['full']) {
- $out .= html_writer::table($table);
- }
- return $out;
- }
- /**
- * Formats the information that needs to go in the 'Requires' column.
- * @param plugininfo_base $plugin the plugin we are rendering the row for.
- * @param plugin_manager $pluginman provides data on all the plugins.
- * @param string $version
- * @return string HTML code
- */
- protected function required_column(plugininfo_base $plugin, plugin_manager $pluginman, $version) {
- $requires = array();
- if (!empty($plugin->versionrequires)) {
- if ($plugin->versionrequires <= $version) {
- $class = 'requires-ok';
- } else {
- $class = 'requires-failed';
- }
- $requires[] = html_writer::tag('li',
- get_string('moodleversion', 'core_plugin', $plugin->versionrequires),
- array('class' => $class));
- }
- foreach ($plugin->get_other_required_plugins() as $component => $requiredversion) {
- $ok = true;
- $otherplugin = $pluginman->get_plugin_info($component);
- if (is_null($otherplugin)) {
- $ok = false;
- } else if ($requiredversion != ANY_VERSION and $otherplugin->versiondisk < $requiredversion) {
- $ok = false;
- }
- if ($ok) {
- $class = 'requires-ok';
- } else {
- $class = 'requires-failed';
- }
- if ($requiredversion != ANY_VERSION) {
- $str = 'otherpluginversion';
- } else {
- $str = 'otherplugin';
- }
- $requires[] = html_writer::tag('li',
- get_string($str, 'core_plugin',
- array('component' => $component, 'version' => $requiredversion)),
- array('class' => $class));
- }
- if (!$requires) {
- return '';
- }
- return html_writer::tag('ul', implode("\n", $requires));
- }
- /**
- * Prints an overview about the plugins - number of installed, number of extensions etc.
- *
- * @param plugin_manager $pluginman provides information about the plugins
- * @return string as usually
- */
- public function plugins_overview_panel(plugin_manager $pluginman) {
- global $CFG;
- $plugininfo = $pluginman->get_plugins();
- $numtotal = $numdisabled = $numextension = $numupdatable = 0;
- foreach ($plugininfo as $type => $plugins) {
- foreach ($plugins as $name => $plugin) {
- if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
- continue;
- }
- $numtotal++;
- if ($plugin->is_enabled() === false) {
- $numdisabled++;
- }
- if (!$plugin->is_standard()) {
- $numextension++;
- }
- if (empty($CFG->disableupdatenotifications) and $plugin->available_updates()) {
- $numupdatable++;
- }
- }
- }
- $info = array();
- $info[] = html_writer::tag('span', get_string('numtotal', 'core_plugin', $numtotal), array('class' => 'info total'));
- $info[] = html_writer::tag('span', get_string('numdisabled', 'core_plugin', $numdisabled), array('class' => 'info disabled'));
- $info[] = html_writer::tag('span', get_string('numextension', 'core_plugin', $numextension), array('class' => 'info extension'));
- if ($numupdatable > 0) {
- $info[] = html_writer::tag('span', get_string('numupdatable', 'core_plugin', $numupdatable), array('class' => 'info updatable'));
- }
- return $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '', 'plugins-overview-panel');
- }
- /**
- * Displays all known plugins and links to manage them
- *
- * This default implementation renders all plugins into one big table.
- *
- * @param plugin_manager $pluginman provides information about the plugins.
- * @return string HTML code
- */
- public function plugins_control_panel(plugin_manager $pluginman) {
- global $CFG;
- $plugininfo = $pluginman->get_plugins();
- if (empty($plugininfo)) {
- return '';
- }
- $table = new html_table();
- $table->id = 'plugins-control-panel';
- $table->head = array(
- get_string('displayname', 'core_plugin'),
- get_string('source', 'core_plugin'),
- get_string('version', 'core_plugin'),
- get_string('availability', 'core_plugin'),
- get_string('actions', 'core_plugin'),
- get_string('notes','core_plugin'),
- );
- $table->colclasses = array(
- 'pluginname', 'source', 'version', 'availability', 'actions', 'notes'
- );
- foreach ($plugininfo as $type => $plugins) {
- $header = new html_table_cell($pluginman->plugintype_name_plural($type));
- $header->header = true;
- $header->colspan = count($table->head);
- $header = new html_table_row(array($header));
- $header->attributes['class'] = 'plugintypeheader type-' . $type;
- $table->data[] = $header;
- if (empty($plugins)) {
- $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
- $msg->colspan = count($table->head);
- $row = new html_table_row(array($msg));
- $row->attributes['class'] .= 'msg msg-noneinstalled';
- $table->data[] = $row;
- continue;
- }
- foreach ($plugins as $name => $plugin) {
- $row = new html_table_row();
- $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
- if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
- $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
- } else {
- $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
- }
- if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
- $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
- $row->attributes['class'] .= ' missingfromdisk';
- } else {
- $msg = '';
- }
- $pluginname = html_writer::tag('div', $icon . ' ' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')).
- html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
- $pluginname = new html_table_cell($pluginname);
- if ($plugin->is_standard()) {
- $row->attributes['class'] .= ' standard';
- $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
- } else {
- $row->attributes['class'] .= ' extension';
- $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
- }
- $version = new html_table_cell($plugin->versiondb);
- $isenabled = $plugin->is_enabled();
- if (is_null($isenabled)) {
- $availability = new html_table_cell('');
- } else if ($isenabled) {
- $row->attributes['class'] .= ' enabled';
- $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
- $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
- } else {
- $row->attributes['class'] .= ' disabled';
- $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
- $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
- }
- $actions = array();
- $settingsurl = $plugin->get_settings_url();
- if (!is_null($settingsurl)) {
- $actions[] = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
- }
- $uninstallurl = $plugin->get_uninstall_url();
- if (!is_null($uninstallurl)) {
- $actions[] = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'), array('class' => 'uninstall'));
- }
- $actions = new html_table_cell(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $actions));
- $requriedby = $pluginman->other_plugins_that_require($plugin->component);
- if ($requriedby) {
- $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)),
- array('class' => 'requiredby'));
- } else {
- $requiredby = '';
- }
- $updateinfo = '';
- if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
- foreach ($plugin->available_updates() as $availableupdate) {
- $updateinfo .= $this->plugin_available_update_info($availableupdate);
- }
- }
- $notes = new html_table_cell($requiredby.$updateinfo);
- $row->cells = array(
- $pluginname, $source, $version, $availability, $actions, $notes
- );
- $table->data[] = $row;
- }
- }
- return html_writer::table($table);
- }
- /**
- * Helper method to render the information about the available plugin update
- *
- * The passed objects always provides at least the 'version' property containing
- * the (higher) version of the plugin available.
- *
- * @param available_update_info $updateinfo information about the available update for the plugin
- */
- protected function plugin_available_update_info(available_update_info $updateinfo) {
- $boxclasses = 'pluginupdateinfo';
- $info = array();
- if (isset($updateinfo->release)) {
- $info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
- array('class' => 'info release'));
- }
- if (isset($updateinfo->maturity)) {
- $info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
- array('class' => 'info maturity'));
- $boxclasses .= ' maturity'.$updateinfo->maturity;
- }
- if (isset($updateinfo->download)) {
- $info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
- }
- if (isset($updateinfo->url)) {
- $info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
- array('class' => 'info more'));
- }
- $box = $this->output->box_start($boxclasses);
- $box .= html_writer::tag('div', get_string('updateavailable', 'core_plugin', $updateinfo->version), array('class' => 'version'));
- $box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
- $box .= $this->output->box_end();
- return $box;
- }
- /**
- * This function will render one beautiful table with all the environmental
- * configuration and how it suits Moodle needs.
- *
- * @param boolean $result final result of the check (true/false)
- * @param array $environment_results array of results gathered
- * @return string HTML to output.
- */
- public function environment_check_table($result, $environment_results) {
- global $CFG;
- // Table headers
- $servertable = new html_table();//table for server checks
- $servertable->head = array(
- get_string('name'),
- get_string('info'),
- get_string('report'),
- get_string('status'),
- );
- $servertable->wrap = array('nowrap', '', '', 'nowrap');
- $servertable->attributes['class'] = 'table environmenttable generaltable';
- $serverdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
- $othertable = new html_table();//table for custom checks
- $othertable->head = array(
- get_string('info'),
- get_string('report'),
- get_string('status'),
- );
- $othertable->wrap = array('', '', 'nowrap');
- $othertable->attributes['class'] = 'table environmenttable generaltable';
- $otherdata = array('ok'=>array(), 'warn'=>array(), 'error'=>array());
- // Iterate over each environment_result
- $continue = true;
- foreach ($environment_results as $environment_result) {
- $errorline = false;
- $warningline = false;
- $stringtouse = '';
- if ($continue) {
- $type = $environment_result->getPart();
- $info = $environment_result->getInfo();
- $status = $environment_result->getStatus();
- $error_code = $environment_result->getErrorCode();
- // Process Report field
- $rec = new stdClass();
- // Something has gone wrong at parsing time
- if ($error_code) {
- $stringtouse = 'environmentxmlerror';
- $rec->error_code = $error_code;
- $status = get_string('error');
- $errorline = true;
- $continue = false;
- }
- if ($continue) {
- if ($rec->needed = $environment_result->getNeededVersion()) {
- // We are comparing versions
- $rec->current = $environment_result->getCurrentVersion();
- if ($environment_result->getLevel() == 'required') {
- $stringtouse = 'environmentrequireversion';
- } else {
- $stringtouse = 'environmentrecommendversion';
- }
- } else if ($environment_result->getPart() == 'custom_check') {
- // We are checking installed & enabled things
- if ($environment_result->getLevel() == 'required') {
- $stringtouse = 'environmentrequirecustomcheck';
- } else {
- $stringtouse = 'environmentrecommendcustomcheck';
- }
- } else if ($environment_result->getPart() == 'php_setting') {
- if ($status) {
- $stringtouse = 'environmentsettingok';
- } else if ($environment_result->getLevel() == 'required') {
- $stringtouse = 'environmentmustfixsetting';
- } else {
- $stringtouse = 'environmentshouldfixsetting';
- }
- } else {
- if ($environment_result->getLevel() == 'required') {
- $stringtouse = 'environmentrequireinstall';
- } else {
- $stringtouse = 'environmentrecommendinstall';
- }
- }
- // Calculate the status value
- if ($environment_result->getBypassStr() != '') { //Handle bypassed result (warning)
- $status = get_string('bypassed');
- $warningline = true;
- } else if ($environment_result->getRestrictStr() != '') { //Handle restricted result (error)
- $status = get_string('restricted');
- $errorline = true;
- } else {
- if ($status) { //Handle ok result (ok)
- $status = get_string('ok');
- } else {
- if ($environment_result->getLevel() == 'optional') {//Handle check result (warning)
- $status = get_string('check');
- $warningline = true;
- } else { //Handle error result (error)
- $status = get_string('check');
- $errorline = true;
- }
- }
- }
- }
- // Build the text
- $linkparts = array();
- $linkparts[] = 'admin/environment';
- $linkparts[] = $type;
- if (!empty($info)){
- $linkparts[] = $info;
- }
- if (empty($CFG->docroot)) {
- $report = get_string($stringtouse, 'admin', $rec);
- } else {
- $report = $this->doc_link(join($linkparts, '/'), get_string($stringtouse, 'admin', $rec));
- }
- // Format error or warning line
- if ($errorline || $warningline) {
- $messagetype = $errorline? 'important':'warning';
- } else {
- $messagetype = 'success';
- }
- $status = '<span class="label label-'.$messagetype.'">'.$status.'</span>';
- // Here we'll store all the feedback found
- $feedbacktext = '';
- // Append the feedback if there is some
- $feedbacktext .= $environment_result->strToReport($environment_result->getFeedbackStr(), 'alert alert-'.$messagetype);
- //Append the bypass if there is some
- $feedbacktext .= $environment_result->strToReport($environment_result->getBypassStr(), 'alert');
- //Append the restrict if there is some
- $feedbacktext .= $environment_result->strToReport($environment_result->getRestrictStr(), 'alert alert-error');
- $report .= $feedbacktext;
- // Add the row to the table
- if ($environment_result->getPart() == 'custom_check'){
- $otherdata[$messagetype][] = array ($info, $report, $status);
- } else {
- $serverdata[$messagetype][] = array ($type, $info, $report, $status);
- }
- }
- }
- //put errors first in
- $servertable->data = array_merge($serverdata['important'], $serverdata['warning'], $serverdata['success']);
- $othertable->data = array_merge($otherdata['important'], $otherdata['warning'], $otherdata['success']);
- // Print table
- $output = '';
- $output .= $this->heading(get_string('serverchecks', 'admin'));
- $output .= html_writer::table($servertable);
- if (count($othertable->data)){
- $output .= $this->heading(get_string('customcheck', 'admin'));
- $output .= html_writer::table($othertable);
- }
- // Finally, if any error has happened, print the summary box
- if (!$result) {
- $output .= $this->box(get_string('environmenterrortodo', 'admin'), 'alert alert-error');
- }
- return $output;
- }
- }