| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
           // This file is part of the universe theme for Moodle
  | 
        
        
            | 
            | 
           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 | 
            * Theme universe renderer file.
  | 
        
        
            | 
            | 
           19 | 
            *
  | 
        
        
            | 
            | 
           20 | 
            * @package    theme_universe
  | 
        
        
            | 
            | 
           21 | 
            * @copyright  2016 onwards Onlinecampus Virtuelle PH
  | 
        
        
            | 
            | 
           22 | 
            * @author     Bas Brands
  | 
        
        
            | 
            | 
           23 | 
            * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           24 | 
            */
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           namespace theme_universe\output;
  | 
        
        
            | 
            | 
           27 | 
              | 
        
        
            | 
            | 
           28 | 
           use custom_menu;
  | 
        
        
            | 
            | 
           29 | 
           use html_writer;
  | 
        
        
            | 
            | 
           30 | 
           use moodle_url;
  | 
        
        
            | 
            | 
           31 | 
           use stdClass;
  | 
        
        
            | 
            | 
           32 | 
           use theme_config;
  | 
        
        
            | 
            | 
           33 | 
              | 
        
        
            | 
            | 
           34 | 
           class html_renderer extends \plugin_renderer_base {
  | 
        
        
            | 
            | 
           35 | 
              | 
        
        
            | 
            | 
           36 | 
               protected static $instance;
  | 
        
        
            | 
            | 
           37 | 
               private $theme;
  | 
        
        
            | 
            | 
           38 | 
              | 
        
        
            | 
            | 
           39 | 
               public static function get_instance() {
  | 
        
        
            | 
            | 
           40 | 
                   if (!is_object(self::$instance)) {
  | 
        
        
            | 
            | 
           41 | 
                       self::$instance = new self();
  | 
        
        
            | 
            | 
           42 | 
                   }
  | 
        
        
            | 
            | 
           43 | 
                   return self::$instance;
  | 
        
        
            | 
            | 
           44 | 
               }
  | 
        
        
            | 
            | 
           45 | 
              | 
        
        
            | 
            | 
           46 | 
               public function page_header() {
  | 
        
        
            | 
            | 
           47 | 
                   $o = '';
  | 
        
        
            | 
            | 
           48 | 
              | 
        
        
            | 
            | 
           49 | 
                   if (empty($this->theme)) {
  | 
        
        
            | 
            | 
           50 | 
                       $this->theme = theme_config::load('universe');
  | 
        
        
            | 
            | 
           51 | 
                   }
  | 
        
        
            | 
            | 
           52 | 
              | 
        
        
            | 
            | 
           53 | 
                   if (!empty($this->theme->settings->navbarposition)) {
  | 
        
        
            | 
            | 
           54 | 
                       if ($this->theme->settings->navbarposition == 'fixed') {
  | 
        
        
            | 
            | 
           55 | 
                           $fixednavbar = true;
  | 
        
        
            | 
            | 
           56 | 
                       } else {
  | 
        
        
            | 
            | 
           57 | 
                           $fixednavbar = false;
  | 
        
        
            | 
            | 
           58 | 
                       }
  | 
        
        
            | 
            | 
           59 | 
                   } else {
  | 
        
        
            | 
            | 
           60 | 
                       $fixednavbar = false;
  | 
        
        
            | 
            | 
           61 | 
                   }
  | 
        
        
            | 
            | 
           62 | 
              | 
        
        
            | 
            | 
           63 | 
                   $o .= $this->image_header($fixednavbar);
  | 
        
        
            | 
            | 
           64 | 
                   $o .= $this->navigation_menu($fixednavbar);
  | 
        
        
            | 
            | 
           65 | 
              | 
        
        
            | 
            | 
           66 | 
                   return $o;
  | 
        
        
            | 
            | 
           67 | 
               }
  | 
        
        
            | 
            | 
           68 | 
              | 
        
        
            | 
            | 
           69 | 
               /**
  | 
        
        
            | 
            | 
           70 | 
                * Render the top image menu.
  | 
        
        
            | 
            | 
           71 | 
                */
  | 
        
        
            | 
            | 
           72 | 
               protected function image_header($fixednavbar = false) {
  | 
        
        
            | 
            | 
           73 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           74 | 
                   if (empty($this->theme)) {
  | 
        
        
            | 
            | 
           75 | 
                       $this->theme = theme_config::load('universe');
  | 
        
        
            | 
            | 
           76 | 
                   }
  | 
        
        
            | 
            | 
           77 | 
                   $settings = $this->theme->settings;
  | 
        
        
            | 
            | 
           78 | 
                   $template = new \stdClass();
  | 
        
        
            | 
            | 
           79 | 
              | 
        
        
            | 
            | 
           80 | 
                   $template->homeurl = new moodle_url('/');
  | 
        
        
            | 
            | 
           81 | 
              | 
        
        
            | 
            | 
           82 | 
                   if (isset($settings->logoposition) && $settings->logoposition == 'right') {
  | 
        
        
            | 
            | 
           83 | 
                       $template->logocontainerclass = 'col-sm-3 col-md-3 push-sm-9 push-md-9 logo right';
  | 
        
        
            | 
            | 
           84 | 
                       $template->headerbgcontainerclass = 'col-sm-9 col-md-9 pull-sm-3 pull-md-3  right background';
  | 
        
        
            | 
            | 
           85 | 
              | 
        
        
            | 
            | 
           86 | 
                       if (isset($settings->headerlayout) && ($settings->headerlayout == 1)) {
  | 
        
        
            | 
            | 
           87 | 
                           $template->logocontainerclass = 'col-sm-3 col-md-3 push-sm-9 push-md-9 logo right logo fixed';
  | 
        
        
            | 
            | 
           88 | 
                           $template->headerbgcontainerclass = 'col-sm-12 background';
  | 
        
        
            | 
            | 
           89 | 
                       }
  | 
        
        
            | 
            | 
           90 | 
                   } else {
  | 
        
        
            | 
            | 
           91 | 
                       $template->logocontainerclass = 'col-sm-3 col-md-3 col-lg-2 logo left p-0';
  | 
        
        
            | 
            | 
           92 | 
                       $template->headerbgcontainerclass = 'col-sm-9 col-md-9 col-lg-10 grid background p-0';
  | 
        
        
            | 
            | 
           93 | 
              | 
        
        
            | 
            | 
           94 | 
                       if (isset($settings->headerlayout) && ($settings->headerlayout == 1)) {
  | 
        
        
            | 
            | 
           95 | 
                           $template->logocontainerclass = 'col-sm-3 col-md-3 col-lg-2 logo left fixed';
  | 
        
        
            | 
            | 
           96 | 
                           $template->headerbgcontainerclass = 'col-sm-12 background';
  | 
        
        
            | 
            | 
           97 | 
                       }
  | 
        
        
            | 
            | 
           98 | 
                   }
  | 
        
        
            | 
            | 
           99 | 
              | 
        
        
            | 
            | 
           100 | 
                   $images = array('logo', 'logosmall', 'headerbg', 'headerbgsmall');
  | 
        
        
            | 
            | 
           101 | 
              | 
        
        
            | 
            | 
           102 | 
                   foreach ($images as $image) {
  | 
        
        
            | 
            | 
           103 | 
                       if (!empty($settings->$image)) {
  | 
        
        
            | 
            | 
           104 | 
                           $template->$image = $this->theme->setting_file_url($image, $image);
  | 
        
        
            | 
            | 
           105 | 
                       } else {
  | 
        
        
            | 
            | 
           106 | 
                           if ($CFG->branch >= 33) {
  | 
        
        
            | 
            | 
           107 | 
                               $template->$image = $this->image_url($image, 'theme_universe');
  | 
        
        
            | 
            | 
           108 | 
                           } else {
  | 
        
        
            | 
            | 
           109 | 
                               $template->$image = $this->pix_url($image, 'theme_universe');
  | 
        
        
            | 
            | 
           110 | 
                           }
  | 
        
        
            | 
            | 
           111 | 
                       }
  | 
        
        
            | 
            | 
           112 | 
                   }
  | 
        
        
            | 
            | 
           113 | 
              | 
        
        
            | 
            | 
           114 | 
                   if ($fixednavbar) {
  | 
        
        
            | 
            | 
           115 | 
                       $template->fixednavbar = true;
  | 
        
        
            | 
            | 
           116 | 
                   }
  | 
        
        
            | 
            | 
           117 | 
              | 
        
        
            | 
            | 
           118 | 
                   return $this->render_from_template('theme_universe/imageheading', $template);
  | 
        
        
            | 
            | 
           119 | 
               }
  | 
        
        
            | 
            | 
           120 | 
              | 
        
        
            | 
            | 
           121 | 
               /**
  | 
        
        
            | 
            | 
           122 | 
                * Full top Navbar. Returns Mustache rendered menu.
  | 
        
        
            | 
            | 
           123 | 
                */
  | 
        
        
            | 
            | 
           124 | 
               protected function navigation_menu($fixednavbar = false) {
  | 
        
        
            | 
            | 
           125 | 
                   $template = new \stdClass();
  | 
        
        
            | 
            | 
           126 | 
                   $template->output = $this->output;
  | 
        
        
            | 
            | 
           127 | 
                   $template->navpositionfixed = $fixednavbar;
  | 
        
        
            | 
            | 
           128 | 
                   return $this->render_from_template('theme_universe/navigation', $template);
  | 
        
        
            | 
            | 
           129 | 
               }
  | 
        
        
            | 
            | 
           130 | 
              | 
        
        
            | 
            | 
           131 | 
               /**
  | 
        
        
            | 
            | 
           132 | 
                * Render the social icons shown in the page footer.
  | 
        
        
            | 
            | 
           133 | 
                */
  | 
        
        
            | 
            | 
           134 | 
               public function universe_socialicons() {
  | 
        
        
            | 
            | 
           135 | 
                   global $CFG;
  | 
        
        
            | 
            | 
           136 | 
                   $content = '';
  | 
        
        
            | 
            | 
           137 | 
              | 
        
        
            | 
            | 
           138 | 
                   if (empty($this->theme)) {
  | 
        
        
            | 
            | 
           139 | 
                       $this->theme = theme_config::load('universe');
  | 
        
        
            | 
            | 
           140 | 
                   }
  | 
        
        
            | 
            | 
           141 | 
              | 
        
        
            | 
            | 
           142 | 
                   $template = new stdClass();
  | 
        
        
            | 
            | 
           143 | 
                   $template->icons = array();
  | 
        
        
            | 
            | 
           144 | 
              | 
        
        
            | 
            | 
           145 | 
                   $socialicons = array('instagramlink', 'twitterlink', 'facebooklink', 'youtubelink');
  | 
        
        
            | 
            | 
           146 | 
              | 
        
        
            | 
            | 
           147 | 
                   if ($CFG->branch >= 33) {
  | 
        
        
            | 
            | 
           148 | 
                       $imageurlfunc = 'image_url';
  | 
        
        
            | 
            | 
           149 | 
                   } else {
  | 
        
        
            | 
            | 
           150 | 
                       $imageurlfunc = 'pix_url';
  | 
        
        
            | 
            | 
           151 | 
                   }
  | 
        
        
            | 
            | 
           152 | 
                   foreach ($socialicons as $si) {
  | 
        
        
            | 
            | 
           153 | 
                       if (!empty($this->theme->settings->$si)) {
  | 
        
        
            | 
            | 
           154 | 
                           $icon = new stdClass();
  | 
        
        
            | 
            | 
           155 | 
                           $icon->url = $this->theme->settings->$si;
  | 
        
        
            | 
            | 
           156 | 
                           $icon->name = str_replace('link', '', $si);
  | 
        
        
            | 
            | 
           157 | 
                           $icon->image = $this->output->$imageurlfunc($icon->name, 'theme');
  | 
        
        
            | 
            | 
           158 | 
                           $template->icons[] = $icon;
  | 
        
        
            | 
            | 
           159 | 
                       }
  | 
        
        
            | 
            | 
           160 | 
                   }
  | 
        
        
            | 
            | 
           161 | 
                   return $this->render_from_template('theme_universe/socialicons', $template);
  | 
        
        
            | 
            | 
           162 | 
               }
  | 
        
        
            | 
            | 
           163 | 
              | 
        
        
            | 
            | 
           164 | 
               /**
  | 
        
        
            | 
            | 
           165 | 
                * Render the language menu.
  | 
        
        
            | 
            | 
           166 | 
                */
  | 
        
        
            | 
            | 
           167 | 
               public function languagemenu() {
  | 
        
        
            | 
            | 
           168 | 
              | 
        
        
            | 
            | 
           169 | 
                   if (empty($this->theme)) {
  | 
        
        
            | 
            | 
           170 | 
                       $this->theme = theme_config::load('universe');
  | 
        
        
            | 
            | 
           171 | 
                   }
  | 
        
        
            | 
            | 
           172 | 
              | 
        
        
            | 
            | 
           173 | 
                   $haslangmenu = $this->output->lang_menu() != '';
  | 
        
        
            | 
            | 
           174 | 
                   $langmenu = new stdClass();
  | 
        
        
            | 
            | 
           175 | 
              | 
        
        
            | 
            | 
           176 | 
                   if ($haslangmenu) {
  | 
        
        
            | 
            | 
           177 | 
                       $langs = get_string_manager()->get_list_of_translations();
  | 
        
        
            | 
            | 
           178 | 
                       $strlang = get_string('language');
  | 
        
        
            | 
            | 
           179 | 
                       $currentlang = current_language();
  | 
        
        
            | 
            | 
           180 | 
                       if (isset($langs[$currentlang])) {
  | 
        
        
            | 
            | 
           181 | 
                           $langmenu->currentlang = $langs[$currentlang];
  | 
        
        
            | 
            | 
           182 | 
                       } else {
  | 
        
        
            | 
            | 
           183 | 
                           $langmenu->currentlang = $strlang;
  | 
        
        
            | 
            | 
           184 | 
                       }
  | 
        
        
            | 
            | 
           185 | 
                       $langmenu->languages = array();
  | 
        
        
            | 
            | 
           186 | 
                       foreach ($langs as $type => $name) {
  | 
        
        
            | 
            | 
           187 | 
                           $thislang = new stdClass();
  | 
        
        
            | 
            | 
           188 | 
                           $thislang->langname = $name;
  | 
        
        
            | 
            | 
           189 | 
                           $thislang->langurl = new moodle_url($this->page->url, array('lang' => $type));
  | 
        
        
            | 
            | 
           190 | 
                           $langmenu->languages[] = $thislang;
  | 
        
        
            | 
            | 
           191 | 
                       }
  | 
        
        
            | 
            | 
           192 | 
                       return $this->render_from_template('theme_universe/language', $langmenu);
  | 
        
        
            | 
            | 
           193 | 
                   }
  | 
        
        
            | 
            | 
           194 | 
               }
  | 
        
        
            | 
            | 
           195 | 
              | 
        
        
            | 
            | 
           196 | 
               /**
  | 
        
        
            | 
            | 
           197 | 
                * Render the text shown in the page footer.
  | 
        
        
            | 
            | 
           198 | 
                */
  | 
        
        
            | 
            | 
           199 | 
               public function footer() {
  | 
        
        
            | 
            | 
           200 | 
              | 
        
        
            | 
            | 
           201 | 
                   if (empty($this->theme)) {
  | 
        
        
            | 
            | 
           202 | 
                       $this->theme = theme_config::load('universe');
  | 
        
        
            | 
            | 
           203 | 
                   }
  | 
        
        
            | 
            | 
           204 | 
              | 
        
        
            | 
            | 
           205 | 
                   $template = new stdClass();
  | 
        
        
            | 
            | 
           206 | 
                   $template->coursefooter = $this->output->course_footer();
  | 
        
        
            | 
            | 
           207 | 
              | 
        
        
            | 
            | 
           208 | 
                   $template->list = array();
  | 
        
        
            | 
            | 
           209 | 
              | 
        
        
            | 
            | 
           210 | 
                   if (isset($this->theme->settings->footertext)) {
  | 
        
        
            | 
            | 
           211 | 
                       $footertext = $this->theme->settings->footertext;
  | 
        
        
            | 
            | 
           212 | 
                       $menu = new custom_menu($footertext, current_language());
  | 
        
        
            | 
            | 
           213 | 
                       foreach ($menu->get_children() as $item) {
  | 
        
        
            | 
            | 
           214 | 
                           $listitem = new stdClass();
  | 
        
        
            | 
            | 
           215 | 
                           $listitem->text = $item->get_text();
  | 
        
        
            | 
            | 
           216 | 
                           $listitem->url = $item->get_url();
  | 
        
        
            | 
            | 
           217 | 
                           $template->list[] = $listitem;
  | 
        
        
            | 
            | 
           218 | 
                       }
  | 
        
        
            | 
            | 
           219 | 
                   }
  | 
        
        
            | 
            | 
           220 | 
              | 
        
        
            | 
            | 
           221 | 
                   $template->socialicons = $this->universe_socialicons();
  | 
        
        
            | 
            | 
           222 | 
              | 
        
        
            | 
            | 
           223 | 
                   if (!empty($this->theme->settings->footnote)) {
  | 
        
        
            | 
            | 
           224 | 
                       $template->footnote = $this->theme->settings->footnote;
  | 
        
        
            | 
            | 
           225 | 
                   }
  | 
        
        
            | 
            | 
           226 | 
              | 
        
        
            | 
            | 
           227 | 
                   $template->logininfo = $this->output->login_info();
  | 
        
        
            | 
            | 
           228 | 
                   $template->standardfooterhtml = $this->standard_footer_html();
  | 
        
        
            | 
            | 
           229 | 
              | 
        
        
            | 
            | 
           230 | 
                   return $this->render_from_template('theme_universe/footer', $template);
  | 
        
        
            | 
            | 
           231 | 
               }
  | 
        
        
            | 
            | 
           232 | 
              | 
        
        
            | 
            | 
           233 | 
               /**
  | 
        
        
            | 
            | 
           234 | 
                * Find the toplevel category for use in the bodyclasses
  | 
        
        
            | 
            | 
           235 | 
                */
  | 
        
        
            | 
            | 
           236 | 
               public function toplevel_category() {
  | 
        
        
            | 
            | 
           237 | 
                   if (empty($this->theme)) {
  | 
        
        
            | 
            | 
           238 | 
                       $this->theme = theme_config::load('universe');
  | 
        
        
            | 
            | 
           239 | 
                   }
  | 
        
        
            | 
            | 
           240 | 
                   foreach ($this->page->categories as $cat) {
  | 
        
        
            | 
            | 
           241 | 
                       if ($cat->depth == 1) {
  | 
        
        
            | 
            | 
           242 | 
                           return 'category-' . $cat->id;
  | 
        
        
            | 
            | 
           243 | 
                       }
  | 
        
        
            | 
            | 
           244 | 
                   }
  | 
        
        
            | 
            | 
           245 | 
               }
  | 
        
        
            | 
            | 
           246 | 
           }
  |