| 1 | efrain | 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 |  * This file is responsible for serving of individual style sheets in designer mode.
 | 
        
           |  |  | 19 |  *
 | 
        
           |  |  | 20 |  * @package   core
 | 
        
           |  |  | 21 |  * @copyright 2009 Petr Skoda (skodak)  {@link http://skodak.org}
 | 
        
           |  |  | 22 |  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 23 |  */
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | // Disable moodle specific debug messages and any errors in output,
 | 
        
           |  |  | 26 | // comment out when debugging or better look into error log!
 | 
        
           |  |  | 27 | define('NO_DEBUG_DISPLAY', true);
 | 
        
           |  |  | 28 | define('NO_UPGRADE_CHECK', true);
 | 
        
           |  |  | 29 | define('NO_MOODLE_COOKIES', true);
 | 
        
           |  |  | 30 |   | 
        
           |  |  | 31 | require('../config.php');
 | 
        
           |  |  | 32 | require_once($CFG->dirroot.'/lib/csslib.php');
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | $themename = optional_param('theme', 'standard', PARAM_SAFEDIR);
 | 
        
           |  |  | 35 | $type      = optional_param('type', '', PARAM_SAFEDIR);
 | 
        
           |  |  | 36 | $subtype   = optional_param('subtype', '', PARAM_SAFEDIR);
 | 
        
           |  |  | 37 | $sheet     = optional_param('sheet', '', PARAM_SAFEDIR);
 | 
        
           |  |  | 38 | $usesvg    = optional_param('svg', 1, PARAM_BOOL);
 | 
        
           |  |  | 39 | $rtl       = optional_param('rtl', false, PARAM_BOOL);
 | 
        
           |  |  | 40 |   | 
        
           |  |  | 41 | if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
 | 
        
           |  |  | 42 |     // The theme exists in standard location - ok.
 | 
        
           |  |  | 43 | } else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) {
 | 
        
           |  |  | 44 |     // Alternative theme location contains this theme - ok.
 | 
        
           |  |  | 45 | } else {
 | 
        
           |  |  | 46 |     css_send_css_not_found();
 | 
        
           |  |  | 47 | }
 | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 | $theme = theme_config::load($themename);
 | 
        
           |  |  | 50 | $theme->force_svg_use($usesvg);
 | 
        
           |  |  | 51 | $theme->set_rtl_mode($rtl);
 | 
        
           |  |  | 52 |   | 
        
           |  |  | 53 | if ($type === 'editor') {
 | 
        
           |  |  | 54 |     $csscontent = $theme->get_css_content_editor();
 | 
        
           |  |  | 55 |     css_send_uncached_css($csscontent);
 | 
        
           |  |  | 56 | }
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 | // We need some kind of caching here because otherwise the page navigation becomes
 | 
        
           |  |  | 59 | // way too slow in theme designer mode. Feel free to create full cache definition later...
 | 
        
           |  |  | 60 | $key = "$type $subtype $sheet $usesvg $rtl";
 | 
        
           |  |  | 61 | $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'themedesigner', array('theme' => $themename));
 | 
        
           |  |  | 62 | if ($content = $cache->get($key)) {
 | 
        
           |  |  | 63 |     if ($content['created'] > time() - THEME_DESIGNER_CACHE_LIFETIME) {
 | 
        
           |  |  | 64 |         $csscontent = $content['data'];
 | 
        
           |  |  | 65 |         css_send_uncached_css($csscontent);
 | 
        
           |  |  | 66 |     }
 | 
        
           |  |  | 67 | }
 | 
        
           |  |  | 68 |   | 
        
           |  |  | 69 | $csscontent = $theme->get_css_content_debug($type, $subtype, $sheet);
 | 
        
           |  |  | 70 | $cache->set($key, array('data' => $csscontent, 'created' => time()));
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 | css_send_uncached_css($csscontent);
 |