[269] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * t29 ressource loading system. |
---|
[271] | 4 | * |
---|
[269] | 5 | * Entry point for loading javascript and css style sheet files in a bundled and |
---|
[271] | 6 | * compressed manner, including caching. This file only checks up the caches and |
---|
| 7 | * contains the main configuration. See ressourceloader.php for all constructing |
---|
| 8 | * code. |
---|
[269] | 9 | * |
---|
| 10 | **/ |
---|
[273] | 11 | |
---|
| 12 | if(!defined('T29_GRAB_LOADER_DEFS')) { |
---|
| 13 | $lib = dirname(__FILE__); |
---|
| 14 | $webroot = realpath("$lib/../"); # file path to root of t29 web installation |
---|
[269] | 15 | |
---|
[273] | 16 | if(!isset($_GET['type'])) { |
---|
| 17 | die("Provide ?type=js or ?type=css."); |
---|
| 18 | } |
---|
[269] | 19 | } |
---|
| 20 | |
---|
| 21 | $types = array('js', 'css'); // mapping position (numeric key) => $conf array position |
---|
| 22 | $conf = array( |
---|
| 23 | 'cache_file' => array('compressed.js', 'style.css'), |
---|
| 24 | 'module_dir' => array("$webroot/shared/js-v6/modules", "$webroot/shared/css-v6/modules"), |
---|
[301] | 25 | 'page_dir' => array("$webroot/shared/js-v6/pagescripts", "$webroot/shared/css-v6/pagestyles"), |
---|
[269] | 26 | 'glob_pattern' => array('*.js', '*.css'), |
---|
| 27 | 'content_types' => array('application/javascript', 'text/css'), |
---|
| 28 | 'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'), |
---|
[273] | 29 | 'modules' => function($conf){ return glob($conf['module_dir'] . '/' . $conf['glob_pattern']); }, |
---|
[269] | 30 | ); |
---|
[273] | 31 | $conf_for_type = function($type, $debug_flag=false) use ($conf, $types) { |
---|
| 32 | $typepos = array_search($type, $types); |
---|
| 33 | if($typepos === FALSE) return null; |
---|
| 34 | array_walk($conf, function(&$val, $key) use($typepos) { if(is_array($val)) $val = $val[$typepos]; }); |
---|
| 35 | $conf['type'] = $type; |
---|
| 36 | $conf['modules'] = call_user_func($conf['modules'], $conf); |
---|
| 37 | $conf['debug'] = $debug_flag; // skip cache and just concat everything |
---|
| 38 | return $conf; |
---|
| 39 | }; |
---|
[269] | 40 | |
---|
[273] | 41 | if(defined('T29_GRAB_LOADER_DEFS')) { |
---|
| 42 | return; // just grab the vars in the local scope |
---|
| 43 | } |
---|
| 44 | |
---|
[269] | 45 | $type = $_GET['type']; |
---|
[273] | 46 | $conf = $conf_for_type($type, isset($_GET['debug'])); |
---|
| 47 | if($conf == null) |
---|
[269] | 48 | die("Illegal type. Valid types are: ". implode($types)); |
---|
| 49 | extract($conf); // for saving long human reading times :D |
---|
| 50 | |
---|
| 51 | require "$lib/cache.php"; |
---|
| 52 | $js_cache = new t29Cache(); |
---|
| 53 | $js_cache->test_files = $modules; |
---|
| 54 | $js_cache->set_cache_file($webroot, $cache_file); |
---|
[271] | 55 | |
---|
| 56 | header("Content-Type: $content_types"); |
---|
[269] | 57 | if(!$debug) $js_cache->try_cache_and_exit(); |
---|
| 58 | |
---|
| 59 | # so we are still in the game |
---|
| 60 | require "$lib/ressourceloader.php"; |
---|
| 61 | $loader = new $class($conf); |
---|
[277] | 62 | if(!$debug) $js_cache->start_cache(array($loader, 'compression_filter'), true); |
---|
[269] | 63 | $loader->run(); |
---|