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

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

Added svn:keywords = Id Property to de-v6, en-v6, lib. and ignore all files in shared/cache.

  • Property svn:keywords set to Id
File size: 8.5 KB
Line 
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.)
9 *  $titel = Seitentitel
10 *  $header_cache_file, $footer_cache_file.
11 **/
12 
13class t29Template {
14        public $conf, $menu, $msg;
15        public $body_classes = array();
16        public $javascript_config = array();
17        public $page_relations, $interlang_links;
18
19        function __construct($conf_array) {
20                $this->conf = $conf_array;
21
22                // create a menu:
23                require_once $this->conf['lib'].'/menu.php';
24                $this->menu = new t29Menu($this->conf);
25
26                // create localisation class:
27                require_once $this->conf['lib'].'/messages.php';
28                $this->msg = new t29Messages($this->conf['lang']);
29
30                // fill up configuration
31                $this->conf['legal_pagename'] = $this->conf['lang_path'] . $this->msg->_('footer-legal-file');
32
33                // setup body classes:
34                $this->body_classes[] = "lang-" . $this->conf['lang'];
35                $this->body_classes[] = "page-" . $this->conf['seiten_id'];
36               
37                // setup javascript configuration
38                $this->javascript_config['lang'] = $this->conf['lang'];
39                $this->javascript_config['seiten_id'] = $this->conf['seiten_id'];
40               
41                // get all kind of relations
42                $this->page_relations = $this->menu->get_page_relations();
43                $this->interlang_links = $this->menu->get_interlanguage_link();
44               
45                // check and load additional css
46                $this->conf['pagecss'] = '/shared/css-v6/pagestyles/'.$this->conf['seiten_id'].'.css';
47                $this->conf['has_pagecss'] = file_exists($this->conf['webroot'].$this->conf['pagecss']);
48                // FIXME: There is no caching check yet for this setting
49                //        (new pagecss file won't be detected and wont purge the tmpl cache)
50        }
51       
52        /**
53         * Main caching and output system.
54         * Parameters (global configuration):
55         *    skip_cache  -  if true, skips writing output to cache file
56         *    purge_cache -  if true, forces creation of new cache file
57         *                   (does not change behaviour of this file's code)
58         **/
59        function create_cache() {
60                ob_start();
61                $this->print_header();
62                register_shutdown_function(array($this, 'create_cache_shutdown'));
63        }
64       
65        function create_cache_shutdown() {
66                $this->print_footer();
67                $whole_page = ob_get_flush();
68                if($this->conf['skip_cache']) {
69                        echo "<!-- debug mode, skipped cache and cache saving. -->";
70                        return; // do not save anything
71                }
72               
73                if(!file_exists($this->conf['cache_file'])) {
74                        if(!self::mkdir_recursive(dirname($this->conf['cache_file']))) {
75                                print "<div class='error'>Could not create recursive caching directories</div>";
76                        }
77                }
78               
79                if(@file_put_contents($this->conf['cache_file'], $whole_page))
80                        print "<!-- Wrote output cache successfully -->\n";
81                else
82                        print "<div class='error'>Could not write page output cache to ".$this->conf['cache_file']."</div>";
83        }
84
85        public static function mkdir_recursive($pathname) {
86                is_dir(dirname($pathname)) || self::mkdir_recursive(dirname($pathname));
87                return is_dir($pathname) || @mkdir($pathname);
88        }
89
90        function print_header() {
91                $p = $this->msg->get_shorthand_printer();
92                $_ = $this->msg->get_shorthand_returner();
93?>
94<!doctype html>
95<html class="no-js" lang="<?php echo $this->conf['lang']; ?>">
96<head>
97  <meta charset="utf-8">
98  <title><?php echo isset($this->conf['titel']) ? $this->conf['titel'].' - ' : ''; $p('html-title'); ?></title>
99  <meta name="description" content="Produziert am 08.01.2012">
100  <meta name="author" content="Sven">
101  <meta name="generator" content="t29v6 $Id: template.php 262 2012-05-28 23:35:30Z sven $">
102  <meta name="t29.cachedate" content="<?php print date('r'); ?>">
103 
104  <?php
105        foreach(array_merge(array("first" => t29Menu::dom_new_link($this->conf['lang_path'], $_('head-rel-first'))),
106          $this->page_relations) as $rel => $a) {
107                if($rel == 'start') continue; // not in standard
108                printf("\n  <link rel='%s' href='%s' title='%s' />",
109                        $rel, $a['href'], sprintf($_('head-rel-'.$rel), $a)
110                );
111        }
112  ?>
113 
114  <link rel="copyright" href="<?php echo $this->conf['legal_pagename']; ?>" title="<?php $p('footer-legal-link'); ?>">
115  <?php
116        // print interlanguage links for all languages except the active one
117        foreach($this->interlang_links as $lang => $a) {
118                if($lang != $this->conf['lang']) {
119                        printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">',
120                                $a['href'], $lang, sprintf($_('head-rel-interlang'), $a)
121                        );
122                }
123        }
124  ?>
125 
126  <meta name="viewport" content="width=device-width,initial-scale=1">
127  <link rel="stylesheet" href="/shared/css-v6/boiler.css">
128  <link rel="stylesheet" href="/shared/css-v6/style.css">
129  <link rel="stylesheet" href="/shared/css/common.css">
130  <?php
131        if($this->conf['has_pagecss'])
132                printf('<link rel="stylesheet" href="%s">', $this->conf['pagecss']);
133  ?>
134
135  <script src="/shared/js-v6/libs/modernizr-2.0.6.min.js"></script>
136</head>
137
138<body class="<?php echo implode(' ', $this->body_classes) ?>">
139<div id="footer-background-container"><!-- helper -->
140  <div id="container">
141        <h1 role="banner"><a href="/" title="<?php $p('head-h1-title'); ?>"><?php $p('head-h1'); ?></a></h1>
142        <div id="background-color-container"><!-- helper -->
143        <section class="main content" role="main" id="content">
144                <!--<header class="teaser">
145                        <h2 id="pdp8L">Wissenschaftliche Rechner und Minicomputer</h2>
146                        <img width=880 src="http://www.technikum29.de/shared/photos/rechnertechnik/univac/panorama-rechts.jpg">
147                </header>-->
148        <!-- start content -->
149<?php 
150} // function print_header().
151
152        function print_footer() {
153                $p = $this->msg->get_shorthand_printer();
154                $_ = $this->msg->get_shorthand_returner();
155        ?>
156        <!-- end content -->
157        </section>
158        <hr>
159        <section class="sidebar">
160                        <h2 class="visuallyhidden"><?php $p("sidebar-h2-tour"); ?></h2>
161                        <nav class="side">
162                                <?php $this->menu->print_menu(t29Menu::sidebar_menu); ?>
163                        </nav>
164                        <!-- menu changing buttons are made with javascript -->
165        </section>
166        </div><!-- div id="background-color-container" helper end -->
167        <hr>
168        <header class="banner">
169                <h2 class="visuallyhidden"><?php $p("sidebar-h2-mainnav"); ?></h2>
170                <nav class="horizontal">
171                        <?php $this->menu->print_menu(t29Menu::horizontal_menu); ?>
172                </nav>
173                <nav class="top">
174                        <h3 class="visuallyhidden"><?php $p("sidebar-h2-lang"); ?></h3>
175                        <ul>
176                                <?php
177                                        foreach($this->interlang_links as $lang => $a) {
178                                                printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n",
179                                                        ($lang == $this->conf['lang'] ? ' class="active"' : ''),
180                                                        $a['href'], sprintf($_('topnav-interlang-title'), $a),
181                                                        $this->conf['languages'][$lang][0] // verbose language name
182                                                );
183                                        }
184                                ?>
185                        </ul>
186                        <form method="get" action="#"><?php printf('
187                                <span class="no-js">%s:</span>
188                                <input type="text" value="" data-defaultvalue="%s" name="q" class="text">
189                                <input type="submit" value="%s" class="button">
190                                ', $_('topnav-search-label'), $_('topnav-search-label'), $_('topnav-search-label')); ?>
191                        </form>
192                </nav>
193    </header>
194        <hr>
195    <footer>
196                <nav class="guide">
197                        <!-- hier wird nav.side die Liste per JS reinkopiert -->
198                </nav>
199                <nav class="rel clearfix">
200                <ul>
201                        <?php
202                                foreach($this->page_relations as $rel => $a) {
203                                        printf("\t<li class='%s'><a href='%s' title='%s'>%s <strong>%s</strong></a>\n",
204                                                $rel, $a['href'], 'TITLE', $_('nav-rel-'.$rel), $a
205                                        );
206                                }
207                        ?>
208                </ul>
209                </nav>
210                <div class="right">
211                        <img src="/shared/img-v6/logo.footer.png" title="technikum29 Logo" alt="Logo" class="logo">
212                        <?php $p('footer-copyright-tag'); ?>
213                        <br/><?php printf('<a href="%s">%s</a>', $this->conf['legal_pagename'], $_('footer-legal-link')); ?>
214                        <div class="icons">
215                                <a href="<?php echo $this->conf['legal_pagename']; ?>#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a>
216                                <!--<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>-->
217                        </div>
218                        <!--CC<br>Viele Bilder können unter einer CreativeCommons-Lizenz
219                        verwendet werden. Erkundigen Sie sich.-->
220                </div>
221    </footer>
222  </div> <!--! end of #container -->
223
224
225  <!-- JavaScript at the bottom for fast page loading -->
226
227  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
228  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
229  <script>window.jQuery || document.write('<script src="/shared/js-v6/libs/jquery-1.7.2.min.js"><\/script>')</script>
230
231  <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script>
232  <script src="/lib/js.php"></script>
233</div><!-- end of div id="footer-background-container" helper -->
234</body>
235</html>
236<?php
237        } // function print_footer()
238       
239} // 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