Changeset 516 in t29-www


Ignore:
Timestamp:
Feb 19, 2014, 12:39:35 PM (5 years ago)
Author:
sven
Message:

Bug #51 gefixt (http://labs.technikum29.de/ticket/51).
Jetzt sollten neue Pagestyles gleich beim Erstellen erkannt werden.

Location:
lib
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • lib/cache.php

    r357 r516  
    3434        public $cache_file; // must be set!
    3535        public $test_files = array(); // must be set!
     36        public $test_conditions = array(); // can be filled with booleans
    3637
    3738        private $mtime_cache_file = null; // needed for cache header output
     
    7879                        print 'Cache file: '; var_dump($this->cache_file);
    7980                        print 'Test files: '; var_dump($this->test_files);
     81                        print 'Test conditions: '; var_dump($this->test_conditions);
    8082                }
    8183
     
    8587                        $this->test_files);
    8688                $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);
    8792                $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;
    8994                       
    9095                if($this->debug) {
  • lib/host.php

    r362 r516  
    4949        /// This value is computed by setup().
    5050        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
    52108        /**
    53109         * Factory for creating a t29Host instance automatically
    54110         * from the current host. This method will decide which
    55111         * subclass has to be taken.
     112         * This function als implements the Singleton pattern, so
     113         * you can call it frequently.
    56114         **/
    57115        static function detect() {
     
    64122                        if(class_exists(self::webroot_local_host_classname)) {
    65123                                $x = self::webroot_local_host_classname;
    66                                 $host = new $x;
     124                                $host = self::new_singleton($x);
    67125                                $host->setup();
    68126                                return $host;
     
    76134                        case 'heribert':
    77135                        case 'localhost':
    78                                 $localhost = new t29HeribertHost;
     136                                $localhost = self::new_singleton('t29HeribertHost');
    79137                                $localhost->setup();
    80138                                return $localhost;
    81139                }
    82140               
    83                 $publichost = new t29PublicHost;
     141                $publichost = self::new_singleton('t29PublicHost');
    84142                $publichost->setup();
    85143                return $publichost;
     
    96154         *   2. if this host is *not* installed in its own virtualhost (i.e. on docroot).
    97155         **/
    98         function setup() {
     156        private function setup() {
    99157                $this->is_rewriting_host = isset($_SERVER[self::env_hidesuffix_name]);
    100158               
  • lib/loader.php

    r357 r516  
    99 *
    1010 **/
    11  
    12 if(!defined('T29_GRAB_LOADER_DEFS')) {
    13         $lib = dirname(__FILE__);
    14         $webroot = realpath("$lib/../");  # file path to root of t29 web installation
    1511
    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
    2314
    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 };
     15require_once "$lib/host.php";
     16$host = t29Host::detect();
    4317
    44 if(defined('T29_GRAB_LOADER_DEFS')) {
    45         return; // just grab the vars in the local scope
     18if(!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;
    4623}
    4724
    4825$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']));
    5027if($conf == null)
    5128        die("Illegal type. Valid types are: ". implode($types));
  • lib/ressourceloader.php

    r357 r516  
    4848        }
    4949       
    50         private static $conf_for_type;
    5150        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']);
    6053                if($conf === null) return null;
    61                
    62                 return new $conf['class']($conf);
     54       
     55                return new $conf['class']($conf);               
    6356        }
    6457       
     
    241234
    242235        function compression_filter($code) {
    243                 global $lib;
    244                 require "$lib/host.php";
    245                 $host = t29Host::detect();
     236                global $lib, $host;
    246237                if($host->has_web_prefix)
    247238                        // rewrite CSS image includes
  • lib/technikum29.php

    r390 r516  
    7979        "$webroot$lang_path/navigation.xml",
    8080        "$webroot$lang_path/news.php",
     81        $webroot.$host->ressources_get_pagestyle($seiten_id),
    8182);
    8283
  • lib/template.php

    r436 r516  
    114114                $this->current_link_classes = $this->menu->get_link_classes();
    115115               
    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']);
    118119                $this->conf['has_pagecss'] = file_exists($this->conf['webroot'].$this->conf['pagecss']);
    119                 // FIXME: There is no caching check yet for this setting
    120                 //        (new pagecss file won't be detected and wont purge the tmpl cache)
    121120               
    122121                // setup html title
Note: See TracChangeset for help on using the changeset viewer.
© 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