public function get_csswww()
 {
     global $CFG;
     if (!$this->theme_essential_lte_ie9()) {
         if (right_to_left()) {
             $moodlecss = 'essential-rtl.css';
         } else {
             $moodlecss = 'essential.css';
         }
         $syscontext = context_system::instance();
         $itemid = theme_get_revision();
         $url = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecss}");
         $url = preg_replace('|^https?://|i', '//', $url->out(false));
         return '<link rel="stylesheet" href="' . $url . '">';
     } else {
         if (right_to_left()) {
             $moodlecssone = 'essential-rtl_ie9-blessed1.css';
             $moodlecsstwo = 'essential-rtl_ie9.css';
         } else {
             $moodlecssone = 'essential_ie9-blessed1.css';
             $moodlecsstwo = 'essential_ie9.css';
         }
         $syscontext = context_system::instance();
         $itemid = theme_get_revision();
         $urlone = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecssone}");
         $urlone = preg_replace('|^https?://|i', '//', $urlone->out(false));
         $urltwo = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/theme_essential/style/{$itemid}/{$moodlecsstwo}");
         $urltwo = preg_replace('|^https?://|i', '//', $urltwo->out(false));
         return '<link rel="stylesheet" href="' . $urlone . '"><link rel="stylesheet" href="' . $urltwo . '">';
     }
 }
예제 #2
0
 /**
  * Return an instance of the mustache class.
  *
  * @since 2.9
  * @return Mustache_Engine
  */
 protected function get_mustache()
 {
     global $CFG;
     if ($this->mustache === null) {
         require_once $CFG->dirroot . '/lib/mustache/src/Mustache/Autoloader.php';
         Mustache_Autoloader::register();
         $themename = $this->page->theme->name;
         $themerev = theme_get_revision();
         $cachedir = make_localcache_directory("mustache/{$themerev}/{$themename}");
         $loader = new \core\output\mustache_filesystem_loader();
         $stringhelper = new \core\output\mustache_string_helper();
         $jshelper = new \core\output\mustache_javascript_helper($this->page->requires);
         $pixhelper = new \core\output\mustache_pix_helper($this);
         // We only expose the variables that are exposed to JS templates.
         $safeconfig = $this->page->requires->get_config_for_javascript($this->page, $this);
         $helpers = array('config' => $safeconfig, 'str' => array($stringhelper, 'str'), 'js' => array($jshelper, 'help'), 'pix' => array($pixhelper, 'pix'));
         $this->mustache = new Mustache_Engine(array('cache' => $cachedir, 'escape' => 's', 'loader' => $loader, 'helpers' => $helpers, 'pragmas' => [Mustache_Engine::PRAGMA_BLOCKS]));
     }
     return $this->mustache;
 }
예제 #3
0
파일: toolbox.php 프로젝트: syedhameed/sc
    static public function get_csswww() {
        global $CFG;

        if (!self::lte_ie9()) {
            if (\right_to_left()) {
                $moodlecss = 'essential-rtl.css';
            } else {
                $moodlecss = 'essential.css';
            }

            $syscontext = \context_system::instance();
            $itemid = \theme_get_revision();
            $url = \moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
                            "/$syscontext->id/theme_essential/style/$itemid/$moodlecss");
            $url = preg_replace('|^https?://|i', '//', $url->out(false));
            return '<link rel="stylesheet" href="' . $url . '">';
        } else {
            if (\right_to_left()) {
                $moodlecssone = 'essential-rtl_ie9-blessed1.css';
                $moodlecsstwo = 'essential-rtl_ie9.css';
            } else {
                $moodlecssone = 'essential_ie9-blessed1.css';
                $moodlecsstwo = 'essential_ie9.css';
            }

            $syscontext = \context_system::instance();
            $itemid = \theme_get_revision();
            $urlone = \moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
                            "/$syscontext->id/theme_essential/style/$itemid/$moodlecssone");
            $urlone = preg_replace('|^https?://|i', '//', $urlone->out(false));
            $urltwo = \moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php",
                            "/$syscontext->id/theme_essential/style/$itemid/$moodlecsstwo");
            $urltwo = preg_replace('|^https?://|i', '//', $urltwo->out(false));
            return '<link rel="stylesheet" href="'.$urlone . '"><link rel="stylesheet" href="'.$urltwo.'">';
        }
    }
예제 #4
0
파일: lib.php 프로젝트: evltuma/moodle
/**
 * File serving.
 *
 * @param stdClass $course The course object.
 * @param stdClass $cm The cm object.
 * @param context $context The context object.
 * @param string $filearea The file area.
 * @param array $args List of arguments.
 * @param bool $forcedownload Whether or not to force the download of the file.
 * @param array $options Array of options.
 * @return void|false
 */
function core_admin_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array())
{
    global $CFG;
    if (in_array($filearea, ['logo', 'logocompact'])) {
        $size = array_shift($args);
        // The path hides the size.
        $itemid = clean_param(array_shift($args), PARAM_INT);
        $filename = clean_param(array_shift($args), PARAM_FILE);
        $themerev = theme_get_revision();
        if ($themerev <= 0) {
            // Normalise to 0 as -1 doesn't place well with paths.
            $themerev = 0;
        }
        // Extract the requested width and height.
        $maxwidth = 0;
        $maxheight = 0;
        if (preg_match('/^\\d+x\\d+$/', $size)) {
            list($maxwidth, $maxheight) = explode('x', $size);
            $maxwidth = clean_param($maxwidth, PARAM_INT);
            $maxheight = clean_param($maxheight, PARAM_INT);
        }
        $lifetime = 0;
        if ($itemid > 0 && $themerev == $itemid) {
            // The itemid is $CFG->themerev, when 0 or less no caching. Also no caching when they don't match.
            $lifetime = DAYSECS * 60;
        }
        // Anyone, including guests and non-logged in users, can view the logos.
        $options = ['cacheability' => 'public'];
        // Check if we've got a cached file to return. When lifetime is 0 then we don't want to cached one.
        $candidate = $CFG->localcachedir . "/core_admin/{$themerev}/{$filearea}/{$maxwidth}x{$maxheight}/{$filename}";
        if (file_exists($candidate) && $lifetime > 0) {
            send_file($candidate, $filename, $lifetime, 0, false, false, '', false, $options);
        }
        // Find the original file.
        $fs = get_file_storage();
        $filepath = "/{$context->id}/core_admin/{$filearea}/0/{$filename}";
        if (!($file = $fs->get_file_by_hash(sha1($filepath)))) {
            send_file_not_found();
        }
        // No need for resizing, but if the file should be cached we save it so we can serve it fast next time.
        if (empty($maxwidth) && empty($maxheight)) {
            if ($lifetime) {
                file_safe_save_content($file->get_content(), $candidate);
            }
            send_stored_file($file, $lifetime, 0, false, $options);
        }
        // Proceed with the resizing.
        $filedata = $file->resize_image($maxwidth, $maxheight);
        if (!$filedata) {
            send_file_not_found();
        }
        // If we don't want to cached the file, serve now and quit.
        if (!$lifetime) {
            send_content_uncached($filedata, $filename);
        }
        // Save, serve and quit.
        file_safe_save_content($filedata, $candidate);
        send_file($candidate, $filename, $lifetime, 0, false, false, '', false, $options);
    }
    send_file_not_found();
}
 /**
  * Initialise with the bits of JavaScript that every Moodle page should have.
  *
  * @param moodle_page $page
  * @param core_renderer $renderer
  */
 protected function init_requirements_data(moodle_page $page, core_renderer $renderer)
 {
     global $CFG;
     // JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
     // Otherwise, in some situations, users will get warnings about insecure content
     // on secure pages from their web browser.
     $this->M_cfg = array('wwwroot' => $CFG->httpswwwroot, 'sesskey' => sesskey(), 'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false), 'themerev' => theme_get_revision(), 'slasharguments' => (int) (!empty($CFG->slasharguments)), 'theme' => $page->theme->name, 'jsrev' => (empty($CFG->cachejs) or empty($CFG->jsrev)) ? -1 : $CFG->jsrev, 'svgicons' => $page->theme->use_svg_icons());
     if (debugging('', DEBUG_DEVELOPER)) {
         $this->M_cfg['developerdebug'] = true;
     }
     if (defined('BEHAT_SITE_RUNNING')) {
         $this->M_cfg['behatsiterunning'] = true;
     }
     // Accessibility stuff.
     $this->skip_link_to('maincontent', get_string('tocontent', 'access'));
     // Add strings used on many pages.
     $this->string_for_js('confirmation', 'admin');
     $this->string_for_js('cancel', 'moodle');
     $this->string_for_js('yes', 'moodle');
     // Alter links in top frame to break out of frames.
     if ($page->pagelayout === 'frametop') {
         $this->js_init_call('M.util.init_frametop');
     }
     // Include block drag/drop if editing is on
     if ($page->user_is_editing()) {
         $params = array('courseid' => $page->course->id, 'pagetype' => $page->pagetype, 'pagelayout' => $page->pagelayout, 'subpage' => $page->subpage, 'regions' => $page->blocks->get_regions(), 'contextid' => $page->context->id);
         if (!empty($page->cm->id)) {
             $params['cmid'] = $page->cm->id;
         }
         $page->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true);
     }
 }
예제 #6
0
 /**
  * Initialise with the bits of JavaScript that every Moodle page should have.
  *
  * @param moodle_page $page
  * @param core_renderer $output
  */
 protected function init_requirements_data(moodle_page $page, core_renderer $renderer)
 {
     global $CFG;
     // JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
     // Otherwise, in some situations, users will get warnings about insecure content
     // on secure pages from their web browser.
     $this->M_cfg = array('wwwroot' => $CFG->httpswwwroot, 'sesskey' => sesskey(), 'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false), 'themerev' => theme_get_revision(), 'theme' => $page->theme->name, 'jsrev' => (empty($CFG->cachejs) or empty($CFG->jsrev)) ? -1 : $CFG->jsrev);
     if (debugging('', DEBUG_DEVELOPER)) {
         $this->M_cfg['developerdebug'] = true;
         $this->yui2_lib('logger');
     }
     // accessibility stuff
     $this->skip_link_to('maincontent', get_string('tocontent', 'access'));
     // to be removed soon
     $this->yui2_lib('dom');
     // at least javascript-static.js needs to be migrated to YUI3
     $this->string_for_js('confirmation', 'admin');
     $this->string_for_js('cancel', 'moodle');
     $this->string_for_js('yes', 'moodle');
     if ($page->pagelayout === 'frametop') {
         $this->js_init_call('M.util.init_frametop');
     }
 }
예제 #7
0
 /**
  * Return the site's compact logo URL, if any.
  *
  * @param int $maxwidth The maximum width, or null when the maximum width does not matter.
  * @param int $maxheight The maximum height, or null when the maximum height does not matter.
  * @return moodle_url|false
  */
 public function get_compact_logo_url($maxwidth = 100, $maxheight = 100)
 {
     global $CFG;
     $logo = get_config('core_admin', 'logocompact');
     if (empty($logo)) {
         return false;
     }
     // Hide the requested size in the file path.
     $filepath = (int) $maxwidth . 'x' . (int) $maxheight . '/';
     // Use $CFG->themerev to prevent browser caching when the file changes.
     return moodle_url::make_pluginfile_url(context_system::instance()->id, 'core_admin', 'logocompact', $filepath, theme_get_revision(), $logo);
 }
예제 #8
0
 /**
  * Return the safe config values that get set for javascript in "M.cfg".
  *
  * @since 2.9
  * @return array List of safe config values that are available to javascript.
  */
 public function get_config_for_javascript(moodle_page $page, renderer_base $renderer)
 {
     global $CFG;
     if (empty($this->M_cfg)) {
         // JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
         // Otherwise, in some situations, users will get warnings about insecure content
         // on secure pages from their web browser.
         $this->M_cfg = array('wwwroot' => $CFG->httpswwwroot, 'sesskey' => sesskey(), 'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false), 'themerev' => theme_get_revision(), 'slasharguments' => (int) (!empty($CFG->slasharguments)), 'theme' => $page->theme->name, 'jsrev' => $this->get_jsrev(), 'admin' => $CFG->admin, 'svgicons' => $page->theme->use_svg_icons());
         if ($CFG->debugdeveloper) {
             $this->M_cfg['developerdebug'] = true;
         }
         if (defined('BEHAT_SITE_RUNNING')) {
             $this->M_cfg['behatsiterunning'] = true;
         }
     }
     return $this->M_cfg;
 }
예제 #9
0
 /**
  * Returns URL to the stored file via pluginfile.php.
  *
  * Note the theme must also implement pluginfile.php handler,
  * theme revision is used instead of the itemid.
  *
  * @param string $setting
  * @param string $filearea
  * @return string protocol relative URL or null if not present
  */
 public function setting_file_url($setting, $filearea)
 {
     global $CFG;
     if (empty($this->settings->{$setting})) {
         return null;
     }
     $component = 'theme_' . $this->name;
     $itemid = theme_get_revision();
     $filepath = $this->settings->{$setting};
     $syscontext = context_system::instance();
     $url = moodle_url::make_file_url("{$CFG->wwwroot}/pluginfile.php", "/{$syscontext->id}/{$component}/{$filearea}/{$itemid}" . $filepath);
     // Now this is tricky because the we can not hardcode http or https here, lets use the relative link.
     // Note: unfortunately moodle_url does not support //urls yet.
     $url = preg_replace('|^https?://|i', '//', $url->out(false));
     return $url;
 }
예제 #10
0
if ($rev > 0 and file_exists($candidate)) {
    if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) || !empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
        // we do not actually need to verify the etag value because our files
        // never change in cache because we increment the rev parameter
        js_send_unmodified(filemtime($candidate), $etag);
    }
    js_send_cached($candidate, $etag);
}
//=================================================================================
// ok, now we need to start normal moodle script, we need to load all libs and $DB
define('ABORT_AFTER_CONFIG_CANCEL', true);
define('NO_MOODLE_COOKIES', true);
// Session not used here
define('NO_UPGRADE_CHECK', true);
// Ignore upgrade check
require "{$CFG->dirroot}/lib/setup.php";
$theme = theme_config::load($themename);
$themerev = theme_get_revision();
if ($themerev <= 0 or $rev != $themerev) {
    // Do not send caching headers if they do not request current revision,
    // we do not want to pollute browser caches with outdated JS.
    js_send_uncached($theme->javascript_content($type));
}
make_localcache_directory('theme', false);
js_write_cache_file_content($candidate, core_minify::js_files($theme->javascript_files($type)));
// Verify nothing failed in cache file creation.
clearstatcache();
if (file_exists($candidate)) {
    js_send_cached($candidate, $etag);
}
js_send_uncached($theme->javascript_content($type));
예제 #11
0
 /**
  * Initialise with the bits of JavaScript that every Moodle page should have.
  *
  * @param moodle_page $page
  * @param core_renderer $renderer
  */
 protected function init_requirements_data(moodle_page $page, core_renderer $renderer)
 {
     global $CFG;
     // JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
     // Otherwise, in some situations, users will get warnings about insecure content
     // on secure pages from their web browser.
     $this->M_cfg = array('wwwroot' => $CFG->httpswwwroot, 'sesskey' => sesskey(), 'loadingicon' => $renderer->pix_url('i/loading_small', 'moodle')->out(false), 'themerev' => theme_get_revision(), 'slasharguments' => (int) (!empty($CFG->slasharguments)), 'theme' => $page->theme->name, 'jsrev' => (empty($CFG->cachejs) or empty($CFG->jsrev)) ? -1 : $CFG->jsrev);
     if (debugging('', DEBUG_DEVELOPER)) {
         $this->M_cfg['developerdebug'] = true;
     }
     // Accessibility stuff.
     $this->skip_link_to('maincontent', get_string('tocontent', 'access'));
     // Add strings used on many pages.
     $this->string_for_js('confirmation', 'admin');
     $this->string_for_js('cancel', 'moodle');
     $this->string_for_js('yes', 'moodle');
     // Alter links in top frame to break out of frames.
     if ($page->pagelayout === 'frametop') {
         $this->js_init_call('M.util.init_frametop');
     }
 }
예제 #12
0
파일: outputlib.php 프로젝트: nicusX/moodle
 /**
  * Return the URL for an image
  *
  * @param string $imagename the name of the icon.
  * @param string $component specification of one plugin like in get_string()
  * @return moodle_url
  */
 public function pix_url($imagename, $component)
 {
     global $CFG;
     $params = array('theme' => $this->name);
     if (empty($component) or $component === 'moodle' or $component === 'core') {
         $params['component'] = 'core';
     } else {
         $params['component'] = $component;
     }
     $rev = theme_get_revision();
     if ($rev != -1) {
         $params['rev'] = $rev;
     }
     $params['image'] = $imagename;
     if (!empty($CFG->slasharguments) and $rev > 0) {
         $url = new moodle_url("{$CFG->httpswwwroot}/theme/image.php");
         $url->set_slashargument('/' . $params['theme'] . '/' . $params['component'] . '/' . $params['rev'] . '/' . $params['image'], 'noparam', true);
     } else {
         $url = new moodle_url("{$CFG->httpswwwroot}/theme/image.php", $params);
     }
     return $url;
 }
예제 #13
0
파일: outputlib.php 프로젝트: Burick/moodle
 /**
  * Return the URL for an image
  *
  * @param string $imagename the name of the icon.
  * @param string $component specification of one plugin like in get_string()
  * @return moodle_url
  */
 public function pix_url($imagename, $component)
 {
     global $CFG;
     $params = array('theme' => $this->name);
     $svg = $this->use_svg_icons();
     if (empty($component) or $component === 'moodle' or $component === 'core') {
         $params['component'] = 'core';
     } else {
         $params['component'] = $component;
     }
     $rev = theme_get_revision();
     if ($rev != -1) {
         $params['rev'] = $rev;
     }
     $params['image'] = $imagename;
     $url = new moodle_url("{$CFG->httpswwwroot}/theme/image.php");
     if (!empty($CFG->slasharguments) and $rev > 0) {
         $path = '/' . $params['theme'] . '/' . $params['component'] . '/' . $params['rev'] . '/' . $params['image'];
         if (!$svg) {
             // We add a simple /_s to the start of the path.
             // The underscore is used to ensure that it isn't a valid theme name.
             $path = '/_s' . $path;
         }
         $url->set_slashargument($path, 'noparam', true);
     } else {
         if (!$svg) {
             // We add an SVG param so that we know not to serve SVG images.
             // We do this because all modern browsers support SVG and this param will one day be removed.
             $params['svg'] = '0';
         }
         $url->params($params);
     }
     return $url;
 }
예제 #14
0
 /**
  * Return an instance of the mustache class.
  *
  * @since 2.9
  * @return Mustache_Engine
  */
 protected function get_mustache()
 {
     global $CFG;
     if ($this->mustache === null) {
         require_once $CFG->dirroot . '/lib/mustache/src/Mustache/Autoloader.php';
         Mustache_Autoloader::register();
         $themename = $this->page->theme->name;
         $themerev = theme_get_revision();
         $target = $this->target;
         $cachedir = make_localcache_directory("mustache/{$themerev}/{$themename}/{$target}");
         $loaderoptions = array();
         // Where are all the places we should look for templates?
         $suffix = $this->component;
         if ($this->subtype !== null) {
             $suffix .= '_' . $this->subtype;
         }
         // Start with an empty list.
         $loader = new Mustache_Loader_CascadingLoader(array());
         $loaderdir = $CFG->dirroot . '/theme/' . $themename . '/templates/' . $suffix;
         if (is_dir($loaderdir)) {
             $loader->addLoader(new \core\output\mustache_filesystem_loader($loaderdir, $loaderoptions));
         }
         // Search each of the parent themes second.
         foreach ($this->page->theme->parents as $parent) {
             $loaderdir = $CFG->dirroot . '/theme/' . $parent . '/templates/' . $suffix;
             if (is_dir($loaderdir)) {
                 $loader->addLoader(new \core\output\mustache_filesystem_loader($loaderdir, $loaderoptions));
             }
         }
         // Look in a components templates dir for a base implementation.
         $compdirectory = core_component::get_component_directory($suffix);
         if ($compdirectory) {
             $loaderdir = $compdirectory . '/templates';
             if (is_dir($loaderdir)) {
                 $loader->addLoader(new \core\output\mustache_filesystem_loader($loaderdir, $loaderoptions));
             }
         }
         // Look in the core templates dir as a final fallback.
         $compdirectory = $CFG->libdir;
         if ($compdirectory) {
             $loaderdir = $compdirectory . '/templates';
             if (is_dir($loaderdir)) {
                 $loader->addLoader(new \core\output\mustache_filesystem_loader($loaderdir, $loaderoptions));
             }
         }
         $stringhelper = new \core\output\mustache_string_helper();
         $jshelper = new \core\output\mustache_javascript_helper($this->page->requires);
         $pixhelper = new \core\output\mustache_pix_helper($this);
         // We only expose the variables that are exposed to JS templates.
         $safeconfig = $this->page->requires->get_config_for_javascript($this->page, $this);
         $helpers = array('config' => $safeconfig, 'str' => array($stringhelper, 'str'), 'js' => array($jshelper, 'help'), 'pix' => array($pixhelper, 'pix'));
         $this->mustache = new Mustache_Engine(array('cache' => $cachedir, 'escape' => 's', 'loader' => $loader, 'helpers' => $helpers));
     }
     return $this->mustache;
 }
예제 #15
0
 /**
  * Return the URL for an image
  *
  * @param string $imagename the name of the icon.
  * @param string $component specification of one plugin like in get_string()
  * @return moodle_url
  */
 public function pix_url($imagename, $component)
 {
     global $CFG;
     $params = array('theme' => $this->name, 'image' => $imagename);
     $rev = theme_get_revision();
     if ($rev != -1) {
         $params['rev'] = $rev;
     }
     if (!empty($component) and $component !== 'moodle' and $component !== 'core') {
         $params['component'] = $component;
     }
     return new moodle_url("{$CFG->httpswwwroot}/theme/image.php", $params);
 }