[269] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * t29 ressource loading system. |
---|
| 4 | * Entry point for loading javascript and css style sheet files in a bundled and |
---|
| 5 | * compressed manner, including caching. |
---|
| 6 | * |
---|
| 7 | **/ |
---|
| 8 | |
---|
| 9 | $lib = dirname(__FILE__); |
---|
| 10 | $webroot = realpath("$lib/../"); # file path to root of t29 web installation |
---|
| 11 | |
---|
| 12 | if(!isset($_GET['type'])) { |
---|
| 13 | die("Read manual."); |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | $types = array('js', 'css'); // mapping position (numeric key) => $conf array position |
---|
| 17 | $conf = array( |
---|
| 18 | 'cache_file' => array('compressed.js', 'style.css'), |
---|
| 19 | 'module_dir' => array("$webroot/shared/js-v6/modules", "$webroot/shared/css-v6/modules"), |
---|
| 20 | 'glob_pattern' => array('*.js', '*.css'), |
---|
| 21 | 'content_types' => array('application/javascript', 'text/css'), |
---|
| 22 | 'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'), |
---|
| 23 | ); |
---|
| 24 | |
---|
| 25 | $type = $_GET['type']; |
---|
| 26 | $typepos = array_search($type, $types); |
---|
| 27 | if($typepos === FALSE) { |
---|
| 28 | die("Illegal type. Valid types are: ". implode($types)); |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | array_walk($conf, function(&$val, $key) use($typepos) { $val = $val[$typepos]; }); |
---|
| 32 | $conf['modules'] = glob($conf['module_dir'] . '/' . $conf['glob_pattern']); |
---|
| 33 | $conf['debug'] = isset($_GET['debug']); // skip cache and just concat everything |
---|
| 34 | extract($conf); // for saving long human reading times :D |
---|
| 35 | // alternative approach for direct extract in global namespace |
---|
| 36 | // (no more applicable because configuration is given as array to constructor): |
---|
| 37 | // foreach($conf as $var => $val) { $GLOBALS[$var] = $val[$typepos]; } |
---|
| 38 | header("Content-Type: $content_types"); |
---|
| 39 | |
---|
| 40 | require "$lib/cache.php"; |
---|
| 41 | $js_cache = new t29Cache(); |
---|
| 42 | $js_cache->test_files = $modules; |
---|
| 43 | $js_cache->set_cache_file($webroot, $cache_file); |
---|
| 44 | if(!$debug) $js_cache->try_cache_and_exit(); |
---|
| 45 | |
---|
| 46 | # so we are still in the game |
---|
| 47 | require "$lib/ressourceloader.php"; |
---|
| 48 | $loader = new $class($conf); |
---|
| 49 | $js_cache->start_cache(array($loader, 'compression_filter'), true); |
---|
| 50 | $loader->run(); |
---|