1 | <?php |
---|
2 | /** |
---|
3 | * t29 ressource loading system. |
---|
4 | * |
---|
5 | * Entry point for loading javascript and css style sheet files in a bundled and |
---|
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. |
---|
9 | * |
---|
10 | **/ |
---|
11 | |
---|
12 | if(!defined('T29_GRAB_LOADER_DEFS')) { |
---|
13 | $lib = dirname(__FILE__); |
---|
14 | $webroot = realpath("$lib/../"); # file path to root of t29 web installation |
---|
15 | |
---|
16 | if(!isset($_GET['type'])) { |
---|
17 | die("Provide ?type=js or ?type=css."); |
---|
18 | } |
---|
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"), |
---|
25 | 'glob_pattern' => array('*.js', '*.css'), |
---|
26 | 'content_types' => array('application/javascript', 'text/css'), |
---|
27 | 'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'), |
---|
28 | 'modules' => function($conf){ return glob($conf['module_dir'] . '/' . $conf['glob_pattern']); }, |
---|
29 | ); |
---|
30 | $conf_for_type = function($type, $debug_flag=false) use ($conf, $types) { |
---|
31 | $typepos = array_search($type, $types); |
---|
32 | if($typepos === FALSE) return null; |
---|
33 | array_walk($conf, function(&$val, $key) use($typepos) { if(is_array($val)) $val = $val[$typepos]; }); |
---|
34 | $conf['type'] = $type; |
---|
35 | $conf['modules'] = call_user_func($conf['modules'], $conf); |
---|
36 | $conf['debug'] = $debug_flag; // skip cache and just concat everything |
---|
37 | return $conf; |
---|
38 | }; |
---|
39 | |
---|
40 | if(defined('T29_GRAB_LOADER_DEFS')) { |
---|
41 | return; // just grab the vars in the local scope |
---|
42 | } |
---|
43 | |
---|
44 | $type = $_GET['type']; |
---|
45 | $conf = $conf_for_type($type, isset($_GET['debug'])); |
---|
46 | if($conf == null) |
---|
47 | die("Illegal type. Valid types are: ". implode($types)); |
---|
48 | extract($conf); // for saving long human reading times :D |
---|
49 | |
---|
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); |
---|
55 | |
---|
56 | header("Content-Type: $content_types"); |
---|
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); |
---|
62 | $js_cache->start_cache(array($loader, 'compression_filter'), true); |
---|
63 | $loader->run(); |
---|