source: t29-www/lib/template.php @ 254

Last change on this file since 254 was 254, checked in by sven, 12 years ago

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 size: 5.7 KB
RevLine 
[251]1<?php
2/**
3 * technikum29v6 Page Template
4 *
5 * Global vars:
6 *  $lang = de | en
7 *  $seiten_id = kurzkennung der aktuellen seite
8 *  $root = Seiten-Root fuer URLs ($root/de, $root/shared, etc.)
[254]9 *  $titel = Seitentitel
10 *  $header_cache_file, $footer_cache_file.
[251]11 **/
[254]12 
13class t29Template {
14        public $conf;
15        public $menu;
[251]16
[254]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                }
[251]49
[254]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() {
[251]59?>
60<!doctype html>
61<html class="no-js" lang="de">
62<head>
63  <meta charset="utf-8">
[254]64  <title><?php isset($this->conf['titel']) ? $this->conf['titel'].' - ' : ''; ?> technikum29</title>
[251]65  <meta name="description" content="Produziert am 08.01.2012">
66  <meta name="author" content="Sven">
[254]67  <meta name="generator" content="t29v6 $Id$">
68  <meta name="t29.cachedate" content="<?php print date('r'); ?>">
[251]69  <meta name="viewport" content="width=device-width,initial-scale=1">
70  <link rel="stylesheet" href="/shared/css-v6/boiler.css">
71  <link rel="stylesheet" href="/shared/css-v6/style.css">
72  <link rel="stylesheet" href="/shared/css/common.css">
73
74  <script src="/shared/js-v6/libs/modernizr-2.0.6.min.js"></script>
75</head>
76
77<body>
78<div id="footer-background-container"><!-- helper -->
79  <div id="container">
80        <h1 role="banner"><a href="#/" title="Zur technikum29 Startseite">technikum29</a></h1>
81        <div id="background-color-container"><!-- helper -->
82        <section class="main content" role="main" id="content">
83                <!--<header class="teaser">
84                        <h2 id="pdp8L">Wissenschaftliche Rechner und Minicomputer</h2>
85                        <img width=880 src="http://www.technikum29.de/shared/photos/rechnertechnik/univac/panorama-rechts.jpg">
86                </header>-->
[254]87        <!-- start content -->
[251]88<?php 
89} // function print_header().
90
91function print_footer() {
92?>
[254]93        <!-- end content -->
[251]94        </section>
95        <hr>
96        <section class="sidebar">
97                        <h2 class="visuallyhidden">Museumstour</h2>
98                        <nav class="side">
[254]99                                <?php $this->menu->print_menu($this->menu->sidebar_menu); ?>
[251]100                                <span class="button collapse-menu">Menü ausklappen</span>
101                        </nav>
102                        <!-- hier dann die Buttons, die dynamisch erzeugt werden, zum Aufklappen, etc. -->
103                        <!-- die werden dann mit Javascript gemacht -->
104                        <span class="button get-menu">Menü anzeigen</span>
105        </section>
106        </div><!-- div id="background-color-container" helper end -->
107        <hr>
108        <header class="banner">
109                <h2 class="visuallyhidden">Hauptnavigation</h2>
110                <nav class="horizontal">
[254]111                        <?php $this->menu->print_menu($this->menu->horizontal_menu); ?>
[251]112                </nav>
113                <nav class="top">
114                        <h3 class="visuallyhidden">Sprachauswahl</h3>
115                        <ul>
116                                <li class="active"><a href="#">Deutsch</a>
117                                <li><a href="#">Englisch</a>
118                        </ul>
119                        <form method="get" action="#">
120                                <span class="no-js">Suchen:</span>
121                                <input type="text" value="" data-defaultvalue="Suchen" name="q" class="text">
122                                <input type="submit" value="Suchen" class="button">
123                        </form>
124                </nav>
125    </header>
126        <hr>
127    <footer>
128                <nav class="guide">
129                        <!-- hier wird nav.side die Liste per JS reinkopiert -->
130                </nav>
131                <nav class="rel clearfix">
132                <ul>
[254]133                        <?php $this->menu->print_relations(); ?>
[252]134                        <!--
[251]135                        <li class="prev"><a href="#">vorherige Seite <strong>Univac 9200</strong></a>
136                        <li class="next"><a href="#">nächste Seite <strong>Analog und Hybridrechner</strong></a>
[252]137                        -->
[251]138                </ul>
139                </nav>
140                <div class="right">
[252]141                        <img src="/shared/img-v6/logo.footer.png" title="technikum29 Logo" alt="Logo" class="logo">
[251]142                        &copy; 2003-2012 technikum29.
[252]143                        <br/><a href="/de-v6/impressum.php">Impressum und Kontakt</a>
144                        <div class="icons">
145                                <a href="/de-v6/impressum.php#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a>
[254]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>-->
[251]147                        </div>
148                        <!--CC<br>Viele Bilder können unter einer CreativeCommons-Lizenz
149                        verwendet werden. Erkundigen Sie sich.-->
150                </div>
151                               
152                <!--Copyright-Hinweis<br>
153                technikum29-Logo, Link aufs Impressum, Kontakt<br>
154                Creative-Commons-Tag<br>
155                Designed by Ufopixel<br>-->
156    </footer>
157  </div> <!--! end of #container -->
158
159
160  <!-- JavaScript at the bottom for fast page loading -->
161
162  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
163  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
164  <script>window.jQuery || document.write('<script src="/shared/js-v6/libs/jquery-1.6.2.min.js"><\/script>')</script>
165
166
167  <script defer src="/shared/js-v6/plugins.js"></script>
168  <script defer src="/shared/js-v6/script.js"></script>
169</div><!-- end of div id="footer-background-container" helper -->
170</body>
171</html>
172<?php
[254]173        } // function print_footer()
174       
175} // class t29Template
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