Changeset 516 in t29-www
- Timestamp:
- Feb 19, 2014, 12:39:35 PM (9 years ago)
- Location:
- lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/cache.php
r357 r516 34 34 public $cache_file; // must be set! 35 35 public $test_files = array(); // must be set! 36 public $test_conditions = array(); // can be filled with booleans 36 37 37 38 private $mtime_cache_file = null; // needed for cache header output … … 78 79 print 'Cache file: '; var_dump($this->cache_file); 79 80 print 'Test files: '; var_dump($this->test_files); 81 print 'Test conditions: '; var_dump($this->test_conditions); 80 82 } 81 83 … … 85 87 $this->test_files); 86 88 $mtime_test_max = array_reduce($mtime_test_files, 'max'); 89 // new feature: Testing boolean conditions. If $this->test_conditions is 90 // an empty array, the calculation gives true. 91 $test_conditions = array_reduce($this->test_conditions, function($a,$b){ return $a && $b; }, true); 87 92 $this->is_valid = $this->mtime_cache_file 88 && $mtime_test_max < $this->mtime_cache_file ;93 && $mtime_test_max < $this->mtime_cache_file && $test_conditions; 89 94 90 95 if($this->debug) { -
lib/host.php
r362 r516 49 49 /// This value is computed by setup(). 50 50 public $script_filename; 51 51 52 /// $ressources: CSS and JavaScript file paths ("Assets"), as used by the RessourceLoader, 53 /// the loader.php and technikum29.php entry points and the Template. 54 private function ressources_array($webroot='') { 55 // this is implemented as method, because of 56 // 1. "$webbroot/..." like strings. This isn't a good idea anyway (e.g. in ressourceloader: $module_dir_rel2webroot 57 // 2. Closures: function($conf){...} doesn't work as class attribute. 58 // This is rather dirty, but anyway the supposed way to access these data is the public get_ressources(). 59 $ressources = array( 60 'cache_file' => array('compressed.js', 'style.css'), 61 'module_dir' => array("$webroot/shared/js-v6/modules", "$webroot/shared/css-v6/modules"), 62 'page_dir' => array("$webroot/shared/js-v6/pagescripts", "$webroot/shared/css-v6/pagestyles"), 63 'glob_pattern' => array('*.js', '*.css'), 64 'content_types' => array('application/javascript', 'text/css'), 65 'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'), 66 'modules' => function($conf){ return glob($conf['module_dir'] . '/' . $conf['glob_pattern']); }, 67 ); 68 return $ressources; 69 } 70 71 /// $ressources_types: The Ressources array above consists of numeric arrays. This array 72 /// maps those positions (numeric keys) to $conf array positions. 73 /// Use get_ressources() to resolve this mapping. 74 private $ressources_types = array('js', 'css'); 75 76 public function get_ressources($type, $webroot, $debug_flag=false) { 77 $typepos = array_search($type, $this->ressources_types); 78 if($typepos === FALSE) return null; 79 $conf = array_map(function($val) use($typepos) 80 { return is_array($val) ? $val[$typepos] : $val; }, 81 $this->ressources_array($webroot)); 82 $conf['type'] = $type; 83 // callback functions need the $conf we built. 84 $conf['modules'] = call_user_func($conf['modules'], $conf); 85 $conf['debug'] = $debug_flag; // skip cache and just concat everything 86 return $conf; 87 } 88 89 /** 90 * A special helper class, used by t29Template and technikum29.php entry point. 91 * The general (clean) way would be querying get_ressources(). 92 * There is also t29RessourceLoader::get_page_specific_urls() which basically does 93 * the same, just using the global conf array. 94 **/ 95 public function ressources_get_pagestyle($seiten_id) { 96 // We address the css property directly with the [1] index. Bad! 97 return $this->ressources_array()['page_dir'][1] . '/' . $seiten_id . '.css'; 98 } 99 100 /// Singleton fun for detect() 101 private static $instance; 102 private static function new_singleton($classname) { 103 if(!isset(self::$instance)) 104 self::$instance = new $classname; 105 return self::$instance; 106 } 107 52 108 /** 53 109 * Factory for creating a t29Host instance automatically 54 110 * from the current host. This method will decide which 55 111 * subclass has to be taken. 112 * This function als implements the Singleton pattern, so 113 * you can call it frequently. 56 114 **/ 57 115 static function detect() { … … 64 122 if(class_exists(self::webroot_local_host_classname)) { 65 123 $x = self::webroot_local_host_classname; 66 $host = new $x;124 $host = self::new_singleton($x); 67 125 $host->setup(); 68 126 return $host; … … 76 134 case 'heribert': 77 135 case 'localhost': 78 $localhost = new t29HeribertHost;136 $localhost = self::new_singleton('t29HeribertHost'); 79 137 $localhost->setup(); 80 138 return $localhost; 81 139 } 82 140 83 $publichost = new t29PublicHost;141 $publichost = self::new_singleton('t29PublicHost'); 84 142 $publichost->setup(); 85 143 return $publichost; … … 96 154 * 2. if this host is *not* installed in its own virtualhost (i.e. on docroot). 97 155 **/ 98 function setup() {156 private function setup() { 99 157 $this->is_rewriting_host = isset($_SERVER[self::env_hidesuffix_name]); 100 158 -
lib/loader.php
r357 r516 9 9 * 10 10 **/ 11 12 if(!defined('T29_GRAB_LOADER_DEFS')) {13 $lib = dirname(__FILE__);14 $webroot = realpath("$lib/../"); # file path to root of t29 web installation15 11 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 } 12 $lib = dirname(__FILE__); 13 $webroot = realpath("$lib/../"); # file path to root of t29 web installation 23 14 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 }; 15 require_once "$lib/host.php"; 16 $host = t29Host::detect(); 43 17 44 if(defined('T29_GRAB_LOADER_DEFS')) { 45 return; // just grab the vars in the local scope 18 if(!isset($_GET['type'])) { 19 print "<html><pre>The t29v6 Ressource loader.\n"; 20 print "Provide ?type=js or ?type=css.\n"; 21 print '<a href="https://labs.technikum29.de/browser/technikum29%20Website/lib/loader.php">Read my sourcecode</a>'; 22 exit; 46 23 } 47 24 48 25 $type = $_GET['type']; 49 $conf = $ conf_for_type($type, isset($_GET['debug']));26 $conf = $host->get_ressources($type, $webroot, isset($_GET['debug'])); //$conf_for_type($type, isset($_GET['debug'])); 50 27 if($conf == null) 51 28 die("Illegal type. Valid types are: ". implode($types)); -
lib/ressourceloader.php
r357 r516 48 48 } 49 49 50 private static $conf_for_type;51 50 static function create_from_type($type, $baseconf=null) { 52 global $lib, $webroot; 53 if(!self::$conf_for_type) { 54 define('T29_GRAB_LOADER_DEFS', true); 55 include "$lib/loader.php"; 56 self::$conf_for_type = $conf_for_type; 57 } 58 59 $conf = call_user_func(self::$conf_for_type, $type, isset($baseconf['debug']) && $baseconf['debug']); 51 global $lib, $webroot, $host; 52 $conf = $host->get_ressources($type, $webroot, isset($baseconf['debug']) && $baseconf['debug']); 60 53 if($conf === null) return null; 61 62 return new $conf['class']($conf); 54 55 return new $conf['class']($conf); 63 56 } 64 57 … … 241 234 242 235 function compression_filter($code) { 243 global $lib; 244 require "$lib/host.php"; 245 $host = t29Host::detect(); 236 global $lib, $host; 246 237 if($host->has_web_prefix) 247 238 // rewrite CSS image includes -
lib/technikum29.php
r390 r516 79 79 "$webroot$lang_path/navigation.xml", 80 80 "$webroot$lang_path/news.php", 81 $webroot.$host->ressources_get_pagestyle($seiten_id), 81 82 ); 82 83 -
lib/template.php
r436 r516 114 114 $this->current_link_classes = $this->menu->get_link_classes(); 115 115 116 // check and load additional css 117 $this->conf['pagecss'] = '/shared/css-v6/pagestyles/'.$this->conf['seiten_id'].'.css'; 116 // check and load additional css. 117 // #51: This is now checked by the site caching in technikum29.php. 118 $this->conf['pagecss'] = $this->conf['host']->ressources_get_pagestyle($this->conf['seiten_id']); 118 119 $this->conf['has_pagecss'] = file_exists($this->conf['webroot'].$this->conf['pagecss']); 119 // FIXME: There is no caching check yet for this setting120 // (new pagecss file won't be detected and wont purge the tmpl cache)121 120 122 121 // setup html title
Note: See TracChangeset
for help on using the changeset viewer.