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

Last change on this file since 357 was 357, checked in by sven, 11 years ago

t29Host-Webroot-System entwickelt.

Damit können Installationen der technikum29-Website ab nun auch in Unterverzeichnissen
(bislang allerdings nur unterhalb des DocumentRoots) installiert werden, was einem
größere Flexibilität beim lokalen Aufsetzen der Seite liefert

File size: 3.0 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                print "<html><pre>The t29v6 Ressource loader.\n";
18                print "Provide ?type=js or ?type=css.\n";
19                print '<a href="https://labs.technikum29.de/browser/technikum29%20Website/lib/loader.php">Read my sourcecode</a>';
20                exit;
21        }
22}
23
24$types = array('js', 'css'); // mapping position (numeric key) => $conf array position
25$conf = array(
26        'cache_file' => array('compressed.js', 'style.css'),
27        'module_dir' => array("$webroot/shared/js-v6/modules", "$webroot/shared/css-v6/modules"),
28        'page_dir' => array("$webroot/shared/js-v6/pagescripts", "$webroot/shared/css-v6/pagestyles"),
29        'glob_pattern' => array('*.js', '*.css'),
30        'content_types' => array('application/javascript', 'text/css'),
31        'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'),
32        'modules' => function($conf){ return glob($conf['module_dir'] . '/' . $conf['glob_pattern']); },
33);
34$conf_for_type = function($type, $debug_flag=false) use ($conf, $types) {
35        $typepos = array_search($type, $types);
36        if($typepos === FALSE) return null;
37        array_walk($conf, function(&$val, $key) use($typepos) { if(is_array($val)) $val = $val[$typepos]; });
38        $conf['type'] = $type;
39        $conf['modules'] = call_user_func($conf['modules'], $conf);
40        $conf['debug'] = $debug_flag; // skip cache and just concat everything
41        return $conf;
42};
43
44if(defined('T29_GRAB_LOADER_DEFS')) {
45        return; // just grab the vars in the local scope
46}
47
48$type = $_GET['type'];
49$conf = $conf_for_type($type, isset($_GET['debug']));
50if($conf == null)
51        die("Illegal type. Valid types are: ". implode($types));
52extract($conf); // for saving long human reading times :D
53
54require "$lib/cache.php";
55$js_cache = new t29Cache();
56$js_cache->test_files = $modules;
57$js_cache->set_cache_file($webroot, $cache_file);
58
59header("Content-Type: $content_types");
60if(!$debug) $js_cache->try_cache_and_exit();
61
62# so we are still in the game
63require "$lib/ressourceloader.php";
64$loader = new $class($conf);
65// TODO: there is a known bug with the filter function issue: Since t29Host variable web prefixes the
66//       filter function for CSS also does path rewriting which doesn't work when it is in debug mode.
67//       Anyway a page in debug mode also imports all untouched CSS files, anyway
68if(!$debug)
69        $js_cache->start_cache(array(
70                'shutdown_func' => null, // nothing to do afterwards for the cache
71                'filter_func'   => array($loader, 'compression_filter'), // compress if not debugging
72                'write_cache'   => true, // write the cache if not debugging
73        ));
74$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