} $result[$parts[0]][$parts[1]] = $value; } // Add subplugin strings, accept only those with proper pluginname prefix with colon. foreach (get_plugin_list('tinymce') as $component => $ignored) { $componentstrings = get_string_manager()->load_component_strings('tinymce_' . $component, $lang); foreach ($componentstrings as $key => $value) { if (strpos($key, "{$component}:") !== 0) { // Ignore normal lang strings. continue; } $parts = explode(':', $key); if (count($parts) != 2) { // Ignore malformed strings with more colons. continue; } $component = $parts[0]; $string = $parts[1]; $result[$component][$string] = $value; } } $output = 'tinyMCE.addI18n({' . $lang . ':' . json_encode($result) . '});'; if ($rev > -1) { js_write_cache_file_content($candidate, $output); // verify nothing failed in cache file creation clearstatcache(); if (file_exists($candidate)) { js_send_cached($candidate, $etag, 'all_strings.php'); } } js_send_uncached($output, 'all_strings.php');
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));
} $jsfiles[] = $jsfile; } if (!$jsfiles) { // bad luck - no valid files die; } $etag = sha1($rev . implode(',', $jsfiles)); $candidate = $CFG->cachedir . '/js/' . $etag; if ($rev > -1) { if (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); } else { js_write_cache_file_content($candidate, js_minify($jsfiles)); // verify nothing failed in cache file creation clearstatcache(); if (file_exists($candidate)) { js_send_cached($candidate, $etag); } } } $content = ''; foreach ($jsfiles as $jsfile) { $content .= file_get_contents($jsfile) . "\n"; } js_send_uncached($content, $etag);
// If-Modified-Since requests so there is no need to handle them specially. header('Expires: ' . date('r', time() + 365 * 24 * 3600)); header('Cache-Control: max-age=' . 365 * 24 * 3600); // Pragma is set to no-cache by default so must be overridden. header('Pragma:'); } // Get the right MIME type. $mimetype = mimeinfo('type', $file); // For JS files, these can be minified and stored in cache. if ($mimetype === 'application/x-javascript' && $allowcache) { // The cached file is stored without version number etc. This is okay // because $CFG->cachedir is cleared each time there is a plugin update, // such as a new version of a tinymce plugin. // Flatten filename and include cache location. $cache = $CFG->cachedir . '/editor_tinymce/pluginjs'; $cachefile = $cache . '/' . $tinymceplugin . str_replace('/', '_', $innerpath); // If it doesn't exist, minify it and save to that location. if (!file_exists($cachefile)) { $content = js_minify(array($file)); js_write_cache_file_content($cachefile, $content); } $file = $cachefile; } else { if ($mimetype === 'text/html') { header('X-UA-Compatible: IE=edge'); } } // Serve file. header('Content-Length: ' . filesize($file)); header('Content-Type: ' . $mimetype); readfile($file);
} else { // Here we respond to the request by returning ALL amd modules. This saves // round trips in production. $jsfiles = core_requirejs::find_all_amd_modules(); } $content = ''; foreach ($jsfiles as $modulename => $jsfile) { $js = file_get_contents($jsfile) . "\n"; // Inject the module name into the define. $replace = 'define(\'' . $modulename . '\', '; $search = 'define('; // Replace only the first occurrence. $js = implode($replace, explode($search, $js, 2)); $content .= $js; } js_write_cache_file_content($candidate, $content); // Verify nothing failed in cache file creation. clearstatcache(); if (file_exists($candidate)) { js_send_cached($candidate, $etag, 'requirejs.php'); exit(0); } } } if ($lazyload) { $jsfiles = core_requirejs::find_one_amd_module($component, $module, true); } else { $jsfiles = core_requirejs::find_all_amd_modules(true); } $content = ''; foreach ($jsfiles as $modulename => $jsfile) {
$jsfiles[] = $jsfile; } if (!$jsfiles) { // bad luck - no valid files die; } $etag = sha1($rev . implode(',', $jsfiles)); // Use the caching only for meaningful revision numbers which prevents future cache poisoning. if ($rev > 0 and $rev < time() + 60 * 60) { $candidate = $CFG->localcachedir . '/js/' . $etag; if (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); } else { js_write_cache_file_content($candidate, core_minify::js_files($jsfiles)); // verify nothing failed in cache file creation clearstatcache(); if (file_exists($candidate)) { js_send_cached($candidate, $etag); } } } $content = ''; foreach ($jsfiles as $jsfile) { $content .= file_get_contents($jsfile) . "\n"; } js_send_uncached($content, $etag);