. /** * Theme squared renderer file. * * @package theme_squared * @copyright 2016 onwards Onlinecampus Virtuelle PH * @author Bas Brands * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace theme_squared\output; defined('MOODLE_INTERNAL') || die; use custom_menu; use html_writer; use moodle_url; use stdClass; use theme_config; class html_renderer extends \plugin_renderer_base { protected static $instance; private $theme; public static function get_instance() { if (!is_object(self::$instance)) { self::$instance = new self(); } return self::$instance; } public function page_header() { $o = ''; if (empty($this->theme)) { $this->theme = theme_config::load('squared'); } if (!empty($this->theme->settings->navbarposition)) { if ($this->theme->settings->navbarposition == 'fixed') { $fixednavbar = true; } else { $fixednavbar = false; } } else { $fixednavbar = false; } $o .= $this->image_header($fixednavbar); $o .= $this->navigation_menu($fixednavbar); return $o; } /** * Render the top image menu. */ protected function image_header($fixednavbar = false) { global $CFG; if (empty($this->theme)) { $this->theme = theme_config::load('squared'); } $settings = $this->theme->settings; $template = new \stdClass(); $template->homeurl = new moodle_url('/'); if (isset($settings->logoposition) && $settings->logoposition == 'right') { $template->logocontainerclass = 'col-sm-3 col-md-3 push-sm-9 push-md-9 logo right'; $template->headerbgcontainerclass = 'col-sm-9 col-md-9 pull-sm-3 pull-md-3 right background'; if (isset($settings->headerlayout) && ($settings->headerlayout == 1)) { $template->logocontainerclass = 'col-sm-3 col-md-3 push-sm-9 push-md-9 logo right logo fixed'; $template->headerbgcontainerclass = 'col-sm-12 background'; } } else { $template->logocontainerclass = 'col-sm-3 col-md-3 col-lg-2 logo left p-0'; $template->headerbgcontainerclass = 'col-sm-9 col-md-9 col-lg-10 grid background p-0'; if (isset($settings->headerlayout) && ($settings->headerlayout == 1)) { $template->logocontainerclass = 'col-sm-3 col-md-3 col-lg-2 logo left fixed'; $template->headerbgcontainerclass = 'col-sm-12 background'; } } $images = array('logo', 'logosmall', 'headerbg', 'headerbgsmall'); foreach ($images as $image) { if (!empty($settings->$image)) { $template->$image = $this->theme->setting_file_url($image, $image); } else { if ($CFG->branch >= 33) { $template->$image = $this->image_url($image, 'theme_squared'); } else { $template->$image = $this->pix_url($image, 'theme_squared'); } } } if ($fixednavbar) { $template->fixednavbar = true; } return $this->render_from_template('theme_squared/imageheading', $template); } /** * Full top Navbar. Returns Mustache rendered menu. */ protected function navigation_menu($fixednavbar = false) { global $OUTPUT; $template = new \stdClass(); $template->output = $OUTPUT; $template->navpositionfixed = $fixednavbar; return $this->render_from_template('theme_squared/navigation', $template); } /** * Render the social icons shown in the page footer. */ public function squared_socialicons() { global $OUTPUT, $CFG; $content = ''; if (empty($this->theme)) { $this->theme = theme_config::load('squared'); } $template = new stdClass(); $template->icons = array(); $socialicons = array('instagramlink', 'twitterlink', 'facebooklink', 'youtubelink'); if ($CFG->branch >= 33) { $imageurlfunc = 'image_url'; } else { $imageurlfunc = 'pix_url'; } foreach ($socialicons as $si) { if (!empty($this->theme->settings->$si)) { $icon = new stdClass(); $icon->url = $this->theme->settings->$si; $icon->name = str_replace('link', '', $si); $icon->image = $OUTPUT->$imageurlfunc($icon->name, 'theme'); $template->icons[] = $icon; } } return $this->render_from_template('theme_squared/socialicons', $template); } /** * Render the language menu. */ public function languagemenu() { global $OUTPUT; if (empty($this->theme)) { $this->theme = theme_config::load('squared'); } $haslangmenu = $OUTPUT->lang_menu() != ''; $langmenu = new stdClass(); if ($haslangmenu) { $langs = get_string_manager()->get_list_of_translations(); $strlang = get_string('language'); $currentlang = current_language(); if (isset($langs[$currentlang])) { $langmenu->currentlang = $langs[$currentlang]; } else { $langmenu->currentlang = $strlang; } $langmenu->languages = array(); foreach ($langs as $type => $name) { $thislang = new stdClass(); $thislang->langname = $name; $thislang->langurl = new moodle_url($this->page->url, array('lang' => $type)); $langmenu->languages[] = $thislang; } return $this->render_from_template('theme_squared/language', $langmenu); } } /** * Render the text shown in the page footer. */ public function footer() { global $OUTPUT; if (empty($this->theme)) { $this->theme = theme_config::load('squared'); } $template = new stdClass(); $template->coursefooter = $OUTPUT->course_footer(); $template->list = array(); if (isset($this->theme->settings->footertext)) { $footertext = $this->theme->settings->footertext; $menu = new custom_menu($footertext, current_language()); foreach ($menu->get_children() as $item) { $listitem = new stdClass(); $listitem->text = $item->get_text(); $listitem->url = $item->get_url(); $template->list[] = $listitem; } } $template->socialicons = $this->squared_socialicons(); if (!empty($this->theme->settings->footnote)) { $template->footnote = $this->theme->settings->footnote; } $template->logininfo = $OUTPUT->login_info(); $template->standardfooterhtml = $this->standard_footer_html(); return $this->render_from_template('theme_squared/footer', $template); } /** * Find the toplevel category for use in the bodyclasses */ public function toplevel_category() { if (empty($this->theme)) { $this->theme = theme_config::load('squared'); } foreach ($this->page->categories as $cat) { if ($cat->depth == 1) { return 'category-' . $cat->id; } } } }