Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/javascript.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 // we need just the values from config.php and minlib.php
00028 define('ABORT_AFTER_CONFIG', true);
00029 require('../config.php'); // this stops immediately at the beginning of lib/setup.php
00030 
00031 ini_set('zlib.output_compression', 'Off');
00032 
00033 // setup include path
00034 set_include_path($CFG->libdir . '/minify/lib' . PATH_SEPARATOR . get_include_path());
00035 require_once('Minify.php');
00036 
00037 $file = min_optional_param('file', '', 'RAW');
00038 $rev  = min_optional_param('rev', 0, 'INT');
00039 
00040 // some security first - pick only files with .js extension in dirroot
00041 $jsfiles = array();
00042 $files = explode(',', $file);
00043 foreach ($files as $fsfile) {
00044     $jsfile = realpath($CFG->dirroot.$fsfile);
00045     if ($jsfile === false) {
00046         // does not exist
00047         continue;
00048     }
00049     if (strpos($jsfile, $CFG->dirroot . DIRECTORY_SEPARATOR) !== 0) {
00050         // hackers - not in dirroot
00051         continue;
00052     }
00053     if (substr($jsfile, -3) !== '.js') {
00054         // hackers - not a JS file
00055         continue;
00056     }
00057     $jsfiles[] = $jsfile;
00058 }
00059 
00060 if (!$jsfiles) {
00061     // bad luck - no valid files
00062     die();
00063 }
00064 
00065 minify($jsfiles);
00066 
00067 function minify($files) {
00068     global $CFG;
00069 
00070     $cachedir = $CFG->cachedir.'/js';
00071     // make sure the cache dir exist
00072     if (!file_exists($cachedir)) {
00073         @mkdir($cachedir, $CFG->directorypermissions, true);
00074     }
00075 
00076     if (0 === stripos(PHP_OS, 'win')) {
00077         Minify::setDocRoot(); // IIS may need help
00078     }
00079     Minify::setCache($cachedir, true);
00080 
00081     $options = array(
00082         // Maximum age to cache
00083         'maxAge' => (60*60*24*20),
00084         // The files to minify
00085         'files' => $files
00086     );
00087 
00088     Minify::serve('Files', $options);
00089     die();
00090 }
 All Data Structures Namespaces Files Functions Variables Enumerations