fixed whitespace
[moodle.git] / lib / javascript.php
CommitLineData
0139ec3f
PS
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This file is serving optimised JS
20 *
21 * @package moodlecore
22 * @copyright 2010 Petr Skoda (skodak)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26// we need just the values from config.php and minlib.php
27define('ABORT_AFTER_CONFIG', true);
28require('../config.php'); // this stops immediately at the beginning of lib/setup.php
29
045f492c
SH
30// setup include path
31set_include_path($CFG->libdir . '/minify/lib' . PATH_SEPARATOR . get_include_path());
32require_once('Minify.php');
0139ec3f 33
045f492c
SH
34$file = min_optional_param('file', '', 'RAW');
35$rev = min_optional_param('rev', 0, 'INT');
0139ec3f 36
045f492c
SH
37if (strpos($file, ',')) {
38 $jsfiles = explode(',', $file);
39 foreach ($jsfiles as $key=>$file) {
40 $jsfiles[$key] = $CFG->dirroot.$file;
5a75ac0a 41 }
045f492c
SH
42} else {
43 $jsfiles = array($CFG->dirroot.$file);
0139ec3f
PS
44}
45
045f492c 46minify($jsfiles);
baeb20bb 47
045f492c
SH
48function minify($files) {
49 global $CFG;
0139ec3f 50
045f492c
SH
51 if (0 === stripos(PHP_OS, 'win')) {
52 Minify::setDocRoot(); // IIS may need help
53 }
54 Minify::setCache($CFG->dataroot.'/temp', true);
0139ec3f 55
045f492c
SH
56 $options = array(
57 // Maximum age to cache
58 'maxAge' => (60*60*24*20),
59 // The files to minify
60 'files' => $files
61 );
0139ec3f 62
045f492c
SH
63 Minify::serve('Files', $options);
64 die();
5a75ac0a 65}