Changeset 254 in t29-www for lib/template.php


Ignore:
Timestamp:
May 25, 2012, 7:58:22 AM (12 years ago)
Author:
sven
Message:

Weiterarbeit an t29v6 (5 Stunden):

  • News werden dynamisch als YAML aus einem Heredoc aus news.php rausgelesen und in das Menü eingepflegt (String-Ersetzung)
  • Caching-System: Jede generierte Seite wird nun gecacht
  • Objektorientierung: Der Library-Code ist pseudo-OOP
  • PHP 5.3-Abhängigkeit - keine create_function-Aufrufe mehr sondern Closures
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/template.php

    r252 r254  
    77 *  $seiten_id = kurzkennung der aktuellen seite
    88 *  $root = Seiten-Root fuer URLs ($root/de, $root/shared, etc.)
     9 *  $titel = Seitentitel
     10 *  $header_cache_file, $footer_cache_file.
    911 **/
     12 
     13class t29Template {
     14        public $conf;
     15        public $menu;
    1016
    11 function print_header() {
    12         global $lang, $seiten_id, $root, $lib;
     17        function __construct($conf_array) {
     18                $this->conf = $conf_array;
     19               
     20                // create a menu:
     21                require_once $this->conf['lib'].'/menu.php';
     22                $this->menu = new t29Menu($this->conf);
     23        }
     24       
     25        /**
     26         * Main caching and output system.
     27         * Parameters (global configuration):
     28         *    skip_cache  -  if true, skips writing output to cache file
     29         *    purge_cache -  if true, forces creation of new cache file
     30         *                   (does not change behaviour of this file's code)
     31         **/
     32        function create_cache() {
     33                ob_start();
     34                $this->print_header();
     35                register_shutdown_function(array($this, 'create_cache_shutdown'));
     36        }
     37       
     38        function create_cache_shutdown() {
     39                $this->print_footer();
     40                $whole_page = ob_get_flush();
     41                if($this->conf['skip_cache']) {
     42                        echo "<!-- debug mode, skipped cache and cache saving. -->";
     43                        return; // do not save anything
     44                }
     45               
     46                if(!file_exists($this->conf['cache_file'])) {
     47                        t29Template::mkdir_recursive(dirname($this->conf['cache_file']));
     48                }
    1349
     50                file_put_contents($this->conf['cache_file'], $whole_page);
     51        }
     52
     53        public static function mkdir_recursive($pathname) {
     54                is_dir(dirname($pathname)) || t29Template::mkdir_recursive(dirname($pathname));
     55                return is_dir($pathname) || @mkdir($pathname);
     56        }
     57
     58        function print_header() {
    1459?>
    1560<!doctype html>
     
    1762<head>
    1863  <meta charset="utf-8">
    19 
    20   <title>Mockup t29v6</title>
     64  <title><?php isset($this->conf['titel']) ? $this->conf['titel'].' - ' : ''; ?> technikum29</title>
    2165  <meta name="description" content="Produziert am 08.01.2012">
    2266  <meta name="author" content="Sven">
     67  <meta name="generator" content="t29v6 $Id$">
     68  <meta name="t29.cachedate" content="<?php print date('r'); ?>">
    2369  <meta name="viewport" content="width=device-width,initial-scale=1">
    2470  <link rel="stylesheet" href="/shared/css-v6/boiler.css">
     
    3581        <div id="background-color-container"><!-- helper -->
    3682        <section class="main content" role="main" id="content">
    37         <!--### START EXAMPLE CONTENT ###-->
    3883                <!--<header class="teaser">
    3984                        <h2 id="pdp8L">Wissenschaftliche Rechner und Minicomputer</h2>
    4085                        <img width=880 src="http://www.technikum29.de/shared/photos/rechnertechnik/univac/panorama-rechts.jpg">
    4186                </header>-->
     87        <!-- start content -->
    4288<?php
    4389} // function print_header().
     
    4591function print_footer() {
    4692?>
    47         <!--### END EXAMPLE CONTENT ###-->
     93        <!-- end content -->
    4894        </section>
    4995        <hr>
     
    5197                        <h2 class="visuallyhidden">Museumstour</h2>
    5298                        <nav class="side">
    53                                 <?php print_menu("sidebar") ?>
     99                                <?php $this->menu->print_menu($this->menu->sidebar_menu); ?>
    54100                                <span class="button collapse-menu">Menü ausklappen</span>
    55101                        </nav>
     
    63109                <h2 class="visuallyhidden">Hauptnavigation</h2>
    64110                <nav class="horizontal">
    65                         <?php print_menu("hauptnavigation"); ?>
     111                        <?php $this->menu->print_menu($this->menu->horizontal_menu); ?>
    66112                </nav>
    67113                <nav class="top">
     
    85131                <nav class="rel clearfix">
    86132                <ul>
    87                         <?php print_relations(); ?>
     133                        <?php $this->menu->print_relations(); ?>
    88134                        <!--
    89135                        <li class="prev"><a href="#">vorherige Seite <strong>Univac 9200</strong></a>
     
    98144                        <div class="icons">
    99145                                <a href="/de-v6/impressum.php#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a>
    100                                 <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>
     146                                <!--<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>-->
    101147                        </div>
    102148                        <!--CC<br>Viele Bilder können unter einer CreativeCommons-Lizenz
     
    125171</html>
    126172<?php
    127 } // function print_footer()
    128 ?>
     173        } // function print_footer()
     174       
     175} // class t29Template
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