. /** * Renderers to align Moodle's HTML with that expected by Bootstrap * * @package theme_bootstrapbase * @copyright 2012 Bas Brands, www.basbrands.nl * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class theme_bootstrapbase_core_renderer extends core_renderer { /** @var custom_menu_item language The language menu if created */ protected $language = null; /** * The standard tags that should be included in the tag * including a meta description for the front page * * @return string HTML fragment. */ public function standard_head_html() { global $SITE, $PAGE; $output = parent::standard_head_html(); if ($PAGE->pagelayout == 'frontpage') { $summary = s(strip_tags(format_text($SITE->summary, FORMAT_HTML))); if (!empty($summary)) { $output .= "\n"; } } return $output; } /* * This renders the navbar. * Uses bootstrap compatible html. */ public function navbar() { $items = $this->page->navbar->get_items(); if (empty($items)) { return ''; } $breadcrumbs = array(); foreach ($items as $item) { $item->hideicon = true; $breadcrumbs[] = $this->render($item); } $divider = ''.get_separator().''; $list_items = '
  • '.join(" $divider
  • ", $breadcrumbs).'
  • '; $title = ''.get_string('pagepath').''; return $title . ""; } /* * Overriding the custom_menu function ensures the custom menu is * always shown, even if no menu items are configured in the global * theme settings page. */ public function custom_menu($custommenuitems = '') { global $CFG; if (empty($custommenuitems) && !empty($CFG->custommenuitems)) { $custommenuitems = $CFG->custommenuitems; } $custommenu = new custom_menu($custommenuitems, current_language()); return $this->render_custom_menu($custommenu); } /* * This renders the bootstrap top menu. * * This renderer is needed to enable the Bootstrap style navigation. */ protected function render_custom_menu(custom_menu $menu) { global $CFG; $langs = get_string_manager()->get_list_of_translations(); $haslangmenu = $this->lang_menu() != ''; if (!$menu->has_children() && !$haslangmenu) { return ''; } if ($haslangmenu) { $strlang = get_string('language'); $currentlang = current_language(); if (isset($langs[$currentlang])) { $currentlang = $langs[$currentlang]; } else { $currentlang = $strlang; } $this->language = $menu->add($currentlang, new moodle_url('#'), $strlang, 10000); foreach ($langs as $langtype => $langname) { $this->language->add($langname, new moodle_url($this->page->url, array('lang' => $langtype)), $langname); } } $content = ''; } /* * This code renders the custom menu items for the * bootstrap dropdown menu. */ protected function render_custom_menu_item(custom_menu_item $menunode, $level = 0 ) { static $submenucount = 0; $content = ''; if ($menunode->has_children()) { if ($level == 1) { $class = 'dropdown'; } else { $class = 'dropdown-submenu'; } if ($menunode === $this->language) { $class .= ' langmenu'; } $content = html_writer::start_tag('li', array('class' => $class)); // 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::start_tag('a', array('href'=>$url, 'class'=>'dropdown-toggle', 'data-toggle'=>'dropdown', 'title'=>$menunode->get_title())); $content .= $menunode->get_text(); if ($level == 1) { $content .= ''; } $content .= ''; $content .= ''; } else { // The node doesn't have children so produce a final menuitem. // Also, if the node's text matches '####', add a class so we can treat it as a divider. if (preg_match("/^#+$/", $menunode->get_text())) { // This is a divider. $content = '
  •  
  • '; } else { $content = '
  • '; 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 .= '
  • '; } } return $content; } /** * This code renders the navbar button to control the display of the custom menu * on smaller screens. * * Do not display the button if the menu is empty. * * @return string HTML fragment */ protected function navbar_button() { global $CFG; if (empty($CFG->custommenuitems) && $this->lang_menu() == '') { return ''; } $iconbar = html_writer::tag('span', '', array('class' => 'icon-bar')); $button = html_writer::tag('a', $iconbar . "\n" . $iconbar. "\n" . $iconbar, array( 'class' => 'btn btn-navbar', 'data-toggle' => 'collapse', 'data-target' => '.nav-collapse' )); return $button; } /** * Renders tabtree * * @param tabtree $tabtree * @return string */ protected function render_tabtree(tabtree $tabtree) { if (empty($tabtree->subtree)) { return ''; } $firstrow = $secondrow = ''; foreach ($tabtree->subtree as $tab) { $firstrow .= $this->render($tab); if (($tab->selected || $tab->activated) && !empty($tab->subtree) && $tab->subtree !== array()) { $secondrow = $this->tabtree($tab->subtree); } } return html_writer::tag('ul', $firstrow, array('class' => 'nav nav-tabs')) . $secondrow; } /** * Renders tabobject (part of tabtree) * * This function is called from {@link core_renderer::render_tabtree()} * and also it calls itself when printing the $tabobject subtree recursively. * * @param tabobject $tabobject * @return string HTML fragment */ protected function render_tabobject(tabobject $tab) { if (($tab->selected and (!$tab->linkedwhenselected)) or $tab->activated) { return html_writer::tag('li', html_writer::tag('a', $tab->text), array('class' => 'active')); } else if ($tab->inactive) { return html_writer::tag('li', html_writer::tag('a', $tab->text), array('class' => 'disabled')); } else { if (!($tab->link instanceof moodle_url)) { // backward compartibility when link was passed as quoted string $link = "link\" title=\"$tab->title\">$tab->text"; } else { $link = html_writer::link($tab->link, $tab->text, array('title' => $tab->title)); } $params = $tab->selected ? array('class' => 'active') : null; return html_writer::tag('li', $link, $params); } } } /** * Overridden core maintenance renderer. * * This renderer gets used instead of the standard core_renderer during maintenance * tasks such as installation and upgrade. * We override it in order to style those scenarios consistently with the regular * bootstrap look and feel. * * @package theme_bootstrapbase * @copyright 2014 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class theme_bootstrapbase_core_renderer_maintenance extends core_renderer_maintenance { }