source: t29-www/lib/loader.php @ 277

Last change on this file since 277 was 277, checked in by sven, 12 years ago

JavaScript-Preferences-System, mit dem die Einstellungen fuers Menue erhalten bleiben. Refactoring des menu.js-Codes. startup.js um Reihenfolge der Scripte festzulegen. Diverse Bugfixes im PHP und Inhalt.

File size: 2.2 KB
Line 
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 
12if(!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
40if(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']));
46if($conf == null)
47        die("Illegal type. Valid types are: ". implode($types));
48extract($conf); // for saving long human reading times :D
49
50require "$lib/cache.php";
51$js_cache = new t29Cache();
52$js_cache->test_files = $modules;
53$js_cache->set_cache_file($webroot, $cache_file);
54
55header("Content-Type: $content_types");
56if(!$debug) $js_cache->try_cache_and_exit();
57
58# so we are still in the game
59require "$lib/ressourceloader.php";
60$loader = new $class($conf);
61if(!$debug) $js_cache->start_cache(array($loader, 'compression_filter'), true);
62$loader->run();
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License