[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/theme/clean/ -> lib.php (source)

   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   * Moodle's Clean theme, an example of how to make a Bootstrap theme
  19   *
  20   * DO NOT MODIFY THIS THEME!
  21   * COPY IT FIRST, THEN RENAME THE COPY AND MODIFY IT INSTEAD.
  22   *
  23   * For full information about creating Moodle themes, see:
  24   * http://docs.moodle.org/dev/Themes_2.0
  25   *
  26   * @package   theme_clean
  27   * @copyright 2013 Moodle, moodle.org
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  
  31  /**
  32   * Parses CSS before it is cached.
  33   *
  34   * This function can make alterations and replace patterns within the CSS.
  35   *
  36   * @param string $css The CSS
  37   * @param theme_config $theme The theme config object.
  38   * @return string The parsed CSS The parsed CSS.
  39   */
  40  function theme_clean_process_css($css, $theme) {
  41  
  42      // Set the background image for the logo.
  43      $logo = $theme->setting_file_url('logo', 'logo');
  44      $css = theme_clean_set_logo($css, $logo);
  45  
  46      // Set custom CSS.
  47      if (!empty($theme->settings->customcss)) {
  48          $customcss = $theme->settings->customcss;
  49      } else {
  50          $customcss = null;
  51      }
  52      $css = theme_clean_set_customcss($css, $customcss);
  53  
  54      return $css;
  55  }
  56  
  57  /**
  58   * Adds the logo to CSS.
  59   *
  60   * @param string $css The CSS.
  61   * @param string $logo The URL of the logo.
  62   * @return string The parsed CSS
  63   */
  64  function theme_clean_set_logo($css, $logo) {
  65      $tag = '[[setting:logo]]';
  66      $replacement = $logo;
  67      if (is_null($replacement)) {
  68          $replacement = '';
  69      }
  70  
  71      $css = str_replace($tag, $replacement, $css);
  72  
  73      return $css;
  74  }
  75  
  76  /**
  77   * Serves any files associated with the theme settings.
  78   *
  79   * @param stdClass $course
  80   * @param stdClass $cm
  81   * @param context $context
  82   * @param string $filearea
  83   * @param array $args
  84   * @param bool $forcedownload
  85   * @param array $options
  86   * @return bool
  87   */
  88  function theme_clean_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
  89      if ($context->contextlevel == CONTEXT_SYSTEM and ($filearea === 'logo' || $filearea === 'smalllogo')) {
  90          $theme = theme_config::load('clean');
  91          // By default, theme files must be cache-able by both browsers and proxies.
  92          if (!array_key_exists('cacheability', $options)) {
  93              $options['cacheability'] = 'public';
  94          }
  95          return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
  96      } else {
  97          send_file_not_found();
  98      }
  99  }
 100  
 101  /**
 102   * Adds any custom CSS to the CSS before it is cached.
 103   *
 104   * @param string $css The original CSS.
 105   * @param string $customcss The custom CSS to add.
 106   * @return string The CSS which now contains our custom CSS.
 107   */
 108  function theme_clean_set_customcss($css, $customcss) {
 109      $tag = '[[setting:customcss]]';
 110      $replacement = $customcss;
 111      if (is_null($replacement)) {
 112          $replacement = '';
 113      }
 114  
 115      $css = str_replace($tag, $replacement, $css);
 116  
 117      return $css;
 118  }
 119  
 120  /**
 121   * Returns an object containing HTML for the areas affected by settings.
 122   *
 123   * Do not add Clean specific logic in here, child themes should be able to
 124   * rely on that function just by declaring settings with similar names.
 125   *
 126   * @param renderer_base $output Pass in $OUTPUT.
 127   * @param moodle_page $page Pass in $PAGE.
 128   * @return stdClass An object with the following properties:
 129   *      - navbarclass A CSS class to use on the navbar. By default ''.
 130   *      - heading HTML to use for the heading. A logo if one is selected or the default heading.
 131   *      - footnote HTML to use as a footnote. By default ''.
 132   */
 133  function theme_clean_get_html_for_settings(renderer_base $output, moodle_page $page) {
 134      global $CFG;
 135      $return = new stdClass;
 136  
 137      $return->navbarclass = '';
 138      if (!empty($page->theme->settings->invert)) {
 139          $return->navbarclass .= ' navbar-inverse';
 140      }
 141  
 142      // Only display the logo on the front page and login page, if one is defined.
 143      if (!empty($page->theme->settings->logo) &&
 144              ($page->pagelayout == 'frontpage' || $page->pagelayout == 'login')) {
 145          $return->heading = html_writer::tag('div', '', array('class' => 'logo'));
 146      } else {
 147          $return->heading = $output->page_heading();
 148      }
 149  
 150      $return->footnote = '';
 151      if (!empty($page->theme->settings->footnote)) {
 152          $return->footnote = '<div class="footnote text-center">'.format_text($page->theme->settings->footnote).'</div>';
 153      }
 154  
 155      return $return;
 156  }
 157  
 158  /**
 159   * All theme functions should start with theme_clean_
 160   * @deprecated since 2.5.1
 161   */
 162  function clean_process_css() {
 163      throw new coding_exception('Please call theme_'.__FUNCTION__.' instead of '.__FUNCTION__);
 164  }
 165  
 166  /**
 167   * All theme functions should start with theme_clean_
 168   * @deprecated since 2.5.1
 169   */
 170  function clean_set_logo() {
 171      throw new coding_exception('Please call theme_'.__FUNCTION__.' instead of '.__FUNCTION__);
 172  }
 173  
 174  /**
 175   * All theme functions should start with theme_clean_
 176   * @deprecated since 2.5.1
 177   */
 178  function clean_set_customcss() {
 179      throw new coding_exception('Please call theme_'.__FUNCTION__.' instead of '.__FUNCTION__);
 180  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1