- Timestamp:
- Jun 2, 2012, 8:15:28 PM (11 years ago)
- Location:
- lib
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/cache.php
r270 r273 115 115 * header! Therefore consider using the convenience method print_cache_and_exit() 116 116 * instead of this one or exit on yourself. 117 **/ 118 function print_cache() { 117 * 118 * @param $ignore_http_caching Don't check the clients HTTP cache 119 **/ 120 function print_cache($ignore_http_caching=false) { 119 121 // make sure we already have called is_valid 120 122 if($this->mtime_cache_file === null) … … 126 128 } 127 129 128 if( @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $this->mtime_cache_file) {130 if(!$ignore_http_caching && @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $this->mtime_cache_file) { 129 131 // client already has page cached locally 130 132 if($this->debug) { … … 234 236 * will be assumed (as start_cache fires it) and content will be 235 237 * extracted with ob_get_flush. 236 **/ 237 function write_cache($content=null) { 238 * @param $content Content to be used as cache content or OB content 239 * @param $clear_ob_cache Use ob_get_clean instead of flushing it. If given, 240 * will return $content instead of printing/keeping it. 241 **/ 242 function write_cache($content=null, $clear_ob_cache=false) { 238 243 if(!$content) 239 $content = ob_get_flush();244 $content = ($clear_ob_cache ? ob_get_clean() : ob_get_flush()); 240 245 241 246 if($this->skip) { … … 253 258 else 254 259 $this->print_error('Could not write page output cache to '.$this->cache_file); 260 261 if($clear_ob_cache) 262 return $content; 255 263 } 256 264 -
lib/loader.php
r271 r273 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 installation 11 15 12 $lib = dirname(__FILE__); 13 $webroot = realpath("$lib/../"); # file path to root of t29 web installation 14 15 if(!isset($_GET['type'])) { 16 die("Read manual."); 16 if(!isset($_GET['type'])) { 17 die("Provide ?type=js or ?type=css."); 18 } 17 19 } 18 20 … … 24 26 'content_types' => array('application/javascript', 'text/css'), 25 27 'class' => array('t29JavaScriptRessourceLoader', 't29StyleSheetRessourceLoader'), 28 'modules' => function($conf){ return glob($conf['module_dir'] . '/' . $conf['glob_pattern']); }, 26 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 } 27 43 28 44 $type = $_GET['type']; 29 $ typepos = array_search($type, $types);30 if($ typepos === FALSE) {45 $conf = $conf_for_type($type, isset($_GET['debug'])); 46 if($conf == null) 31 47 die("Illegal type. Valid types are: ". implode($types)); 32 } 48 extract($conf); // for saving long human reading times :D 33 49 34 array_walk($conf, function(&$val, $key) use($typepos) { $val = $val[$typepos]; });35 $conf['modules'] = glob($conf['module_dir'] . '/' . $conf['glob_pattern']);36 $conf['debug'] = isset($_GET['debug']); // skip cache and just concat everything37 extract($conf); // for saving long human reading times :D38 // alternative approach for direct extract in global namespace39 // (no more applicable because configuration is given as array to constructor):40 // foreach($conf as $var => $val) { $GLOBALS[$var] = $val[$typepos]; }41 50 42 51 require "$lib/cache.php"; -
lib/messages.php
r268 r273 96 96 'topnav-interlang-title' => array('Read this page (%s) in English', 'Diese Seite (%s) auf Deutsch lesen'), 97 97 'topnav-search-label' => array('Suchen', 'Search'), 98 'topnav-search-page' => array('/de-v6/suche.php', '/en-v6/search.php'), 98 'topnav-search-page' => array('/suche.php', '/search.php'), 99 'opensearch-desc' => array('technikum29 (de)', 'technikum29 (en)'), 99 100 100 101 'js-menu-collapse-out' => array('Menü ausklappen', 'Expand menu'), -
lib/ressourceloader.php
r271 r273 21 21 * 22 22 **/ 23 24 /* 25 // test it: 26 $lib = dirname(__FILE__); 27 $webroot = realpath("$lib/../"); 28 $js = t29RessourceLoader::create_from_type('css'); 29 $js->run(); 30 */ 23 31 24 32 class t29RessourceLoader { 25 33 /** 26 * expects: cache_file, module_dir, glob_pattern, content_types, class, modules, debug34 * expects: type, cache_file, module_dir, glob_pattern, content_types, class, modules, debug 27 35 **/ 28 36 public $conf; 37 38 const default_include_url = '/lib/loader.php'; // rel to webroot 29 39 30 40 /** 31 41 * Construct with configuration array. See loader.php for contents of 32 42 * that array. See above for minimum elements which must be present. 33 * */34 /// @param $conf configuration array.43 * @param $conf Configuration array 44 **/ 35 45 function __construct($conf) { 36 46 $this->conf = $conf; 37 47 $this->conf['filenames'] = array_map('basename', $this->conf['modules']); // filenames like foo.js 48 } 49 50 private static $conf_for_type; 51 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']); 60 if($conf === null) return null; 61 62 return new $conf['class']($conf); 63 } 64 65 function get_urls($debug=null) { 66 global $webroot; 67 if(($debug !== null && $debug) || !$this->conf['debug']) { 68 return array(self::default_include_url . '?type=' . $this->conf['type']); 69 } else { 70 $module_dir_rel2webroot = str_replace($webroot, '', $this->conf['module_dir']); 71 return array_map(function($i)use($module_dir_rel2webroot){ return $module_dir_rel2webroot.$i; }, $this->conf['filenames']); 72 } 38 73 } 39 74 -
lib/technikum29.php
r264 r273 30 30 $page_cache = new t29Cache(false, true); // debug, verbose 31 31 $page_cache->set_cache_file($webroot, $file); 32 $page_cache->test_files = array(32 $page_cache->test_files = array( 33 33 __FILE__, 34 34 $_SERVER['SCRIPT_FILENAME'], … … 40 40 ); 41 41 42 $page_cache->try_cache_and_exit(); 42 // dynamical content: 43 $static_page = !isset($dynamischer_inhalt); 43 44 44 // cache missed, rebuild cache 45 require "$lib/template.php"; 46 $tmpl = new t29Template($GLOBALS); 47 $tmpl->create_cache($page_cache); 45 if(!$static_page) { 46 // Pages with dynamical content: only cache header and footer, seperately. 47 // they depend on same test files, so there is only one is_valid check. 48 $header_cache = $page_cache; 49 $footer_cache = clone $page_cache; 50 51 $header_cache->set_cache_file($webroot, $file.'-header'); 52 $footer_cache->set_cache_file($webroot, $file.'-footer'); 53 } 54 55 if($page_cache->shall_use()) { 56 if($static_page) 57 $page_cache->print_cache_and_exit(); 58 else { 59 $header_cache->print_cache(true); 60 register_shutdown_function(function() use ($footer_cache) { 61 $footer_cache->print_cache(true); 62 }); 63 // now print your dynamical stuff in your page, the 64 // footer content will be automatically added afterwards. 65 } 66 } else { 67 // cache missed, rebuild cache 68 require "$lib/template.php"; 69 $tmpl = new t29Template($GLOBALS); 70 if($static_page) 71 // rebuild complete site cache 72 $tmpl->create_cache($page_cache); 73 else 74 // rebuild each header and footer cache 75 $tmpl->create_separate_caches($header_cache, $footer_cache); 76 } 77 48 78 49 79 // end of technikum29.php -
lib/template.php
r271 r273 10 10 * $header_cache_file, $footer_cache_file. 11 11 **/ 12 13 require dirname(__FILE__) . "/ressourceloader.php"; 12 14 13 15 class t29Template { … … 29 31 30 32 // fill up configuration 31 $this->conf['legal_pagename'] = $this->conf['lang_path'] . $this->msg->_('footer-legal-file'); 33 // Path names in messages 34 foreach(array('footer-legal-file', 'topnav-search-page') as $msg) 35 $this->conf[$msg] = $this->conf['lang_path'] . $this->msg->_($msg); 32 36 33 37 // setup body classes: … … 60 64 $cache_object->start_cache(array($this, 'print_footer')); 61 65 $this->print_header(); 66 } 67 68 /** 69 * Write header and footer in separate cache files. 70 **/ 71 function create_separate_caches($header_cache, $footer_cache) { 72 $header_cache->start_cache(); 73 $this->print_header(); 74 $header_cache->write_cache(); // will also print out header immediately. 75 76 $footer_cache->start_cache(); 77 $this->print_footer(); 78 $footer_content = $footer_cache->write_cache(null, true); // don't print footer immediately. 79 80 // print footer on exit. 81 register_shutdown_function(function() use ($footer_content) { 82 print $footer_content; 83 }); 62 84 } 63 85 … … 89 111 ?> 90 112 91 <link rel="copyright" href="<?php echo $this->conf['legal_pagename']; ?>" title="<?php $p('footer-legal-link'); ?>"> 113 <link rel="copyright" href="<?php echo $this->conf['footer-legal-file']; ?>" title="<?php $p('footer-legal-link'); ?>"> 114 <link rel="search" type="application/opensearchdescription+xml" href="<?php print $this->conf['topnav-search-page'] . '?action=opensearch-desc'; ?>" title="<?php $p('opensearch-desc'); ?>"> 92 115 <?php 93 116 // print interlanguage links for all languages except the active one … … 102 125 103 126 <meta name="viewport" content="width=device-width,initial-scale=1"> 104 <link rel="stylesheet" href="/lib/loader.php?type=css"> 105 <?php 127 <?php 128 $csslinktmpl = ' <link rel="stylesheet" href="%s">'.PHP_EOL; 129 foreach($this->get_ressourceloader_links('css') as $css) 130 printf($csslinktmpl, $css); 131 106 132 if($this->conf['has_pagecss']) 107 printf( '<link rel="stylesheet" href="%s">', $this->conf['pagecss']);133 printf($csslinktmpl, $this->conf['pagecss']); 108 134 ?> 109 135 … … 162 188 ?> 163 189 </ul> 164 <form method="get" action="<?php $p('topnav-search-page'); ?>">190 <form method="get" action="<?php print $this->conf['topnav-search-page']; ?>"> 165 191 <span class="no-js"><?php $p('topnav-search-label'); ?>:</span> 166 192 <input type="text" value="" data-defaultvalue="<?php $p('topnav-search-label'); ?>" name="q" class="text"> … … 189 215 <img src="/shared/img-v6/logo.footer.png" title="technikum29 Logo" alt="Logo" class="logo"> 190 216 <?php $p('footer-copyright-tag'); ?> 191 <br/><?php printf('<a href="%s">%s</a>', $this->conf[' legal_pagename'], $_('footer-legal-link')); ?>217 <br/><?php printf('<a href="%s">%s</a>', $this->conf['footer-legal-file'], $_('footer-legal-link')); ?> 192 218 <div class="icons"> 193 <a href="<?php echo $this->conf[' legal_pagename']; ?>#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a>219 <a href="<?php echo $this->conf['footer-legal-file']; ?>#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a> 194 220 <!--<a href="http://ufopixel.de" title="Designed by Ufopixel"><img src="http://svenk.homeip.net/dropbox/Ufopixel/Ufopixel-Design/logo_90x30/ufopixel_logo_90x30_version2.png"></a>--> 195 221 </div> … … 208 234 209 235 <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script> 210 <script src="/lib/loader.php?type=js"></script> 236 <?php 237 foreach($this->get_ressourceloader_links('js') as $js) 238 printf(' <script src="%s"></script>'.PHP_EOL, $js); 239 ?> 211 240 </div><!-- end of div id="footer-background-container" helper --> 212 241 </body> … … 221 250 return isset($a['title']) ? $a['title'] : $a; 222 251 } 223 252 253 function get_ressourceloader_links($type) { 254 $rl = t29RessourceLoader::create_from_type($type, $this->conf); 255 return $rl->get_urls(); 256 } 257 224 258 } // class t29Template
Note: See TracChangeset
for help on using the changeset viewer.