示例#1
0
    $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');
示例#2
0
    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));
示例#3
0
        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) {
    $shortfilename = str_replace($CFG->dirroot, '', $jsfile);
    $js = "// ---- {$shortfilename} ----\n";
    $js .= file_get_contents($jsfile) . "\n";
    // Inject the module name into the define.
    $replace = 'define(\'' . $modulename . '\', ';
    $search = 'define(';
    if (strpos($js, $search) === false) {
        // We can't call debugging because we only have minimal config loaded.
        header('HTTP/1.0 500 error');
        die('JS file: ' . $shortfilename . ' does not contain a javascript module in AMD format. "define()" not found.');
    }
    // Replace only the first occurrence.
    $js = implode($replace, explode($search, $js, 2));
    $content .= $js;
}
js_send_uncached($content, 'requirejs.php');
    $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);
示例#5
0
    $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 {
        // The JS needs minfifying, so we're gonna have to load our full Moodle
        // environment to process it..
        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";
        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);