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

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

JavaScripts fuer v6

Alle Scripte aus v5 in einzelne Dateien rueberkopiert, kompatibel zum neuen System gemacht. Mit einem RessourceLoader-aehnlichen Konzept werden nun alle Javascripts serverseitig gebuendelt und komprimiert, dabei werden auch die Messages von PHP ueber JSON zur Ladezeit mitgegeben. Seitenspezifische Conf wird ueber das Template injektziert.

Bugfixes

  • navigation.xml (en/de): Tote Links zu Navigationszwecken brauchbar gemacht, mit "#DUMME-VERLINKUNG" als Anker um auf inkonsistentes Navigationskonzept hinzuweisen
  • de/news.php: Exemplarische Deeplinks angepasst, funktionieren jetzt
  • de-v6/rechnertechnik/ic-technik.php: Kleiner Designfix (uralte Klasse "h-ul" durch Inlinecode ersetzt wie in en)
  • lib/menu.php: Bugfix
  • lib/messages.php: Neue Nachrichten, vom JS-System
  • etc.
File size: 8.1 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       
46        /**
47         * Main caching and output system.
48         * Parameters (global configuration):
49         *    skip_cache  -  if true, skips writing output to cache file
50         *    purge_cache -  if true, forces creation of new cache file
51         *                   (does not change behaviour of this file's code)
52         **/
53        function create_cache() {
54                ob_start();
55                $this->print_header();
56                register_shutdown_function(array($this, 'create_cache_shutdown'));
57        }
58       
59        function create_cache_shutdown() {
60                $this->print_footer();
61                $whole_page = ob_get_flush();
62                if($this->conf['skip_cache']) {
63                        echo "<!-- debug mode, skipped cache and cache saving. -->";
64                        return; // do not save anything
65                }
66               
67                if(!file_exists($this->conf['cache_file'])) {
68                        self::mkdir_recursive(dirname($this->conf['cache_file']));
69                }
70
71                if(file_put_contents($this->conf['cache_file'], $whole_page))
72                        print "<!-- Wrote output cache successfully -->\n";
73        }
74
75        public static function mkdir_recursive($pathname) {
76                is_dir(dirname($pathname)) || self::mkdir_recursive(dirname($pathname));
77                return is_dir($pathname) || @mkdir($pathname);
78        }
79
80        function print_header() {
81                $p = $this->msg->get_shorthand_printer();
82                $_ = $this->msg->get_shorthand_returner();
83?>
84<!doctype html>
85<html class="no-js" lang="<?php echo $this->conf['lang']; ?>">
86<head>
87  <meta charset="utf-8">
88  <title><?php isset($this->conf['titel']) ? $this->conf['titel'].' - ' : ''; $p('html-title'); ?></title>
89  <meta name="description" content="Produziert am 08.01.2012">
90  <meta name="author" content="Sven">
91  <meta name="generator" content="t29v6 $Id$">
92  <meta name="t29.cachedate" content="<?php print date('r'); ?>">
93 
94  <?php
95        foreach(array_merge(array("first" => t29Menu::dom_new_link($this->conf['lang_path'], $_('head-rel-first'))),
96          $this->page_relations) as $rel => $a) {
97                if($rel == 'start') continue; // not in standard
98                printf("\n  <link rel='%s' href='%s' title='%s' />",
99                        $rel, $a['href'], sprintf($_('head-rel-'.$rel), $a)
100                );
101        }
102  ?>
103 
104  <link rel="copyright" href="<?php echo $this->conf['legal_pagename']; ?>" title="<?php $p('footer-legal-link'); ?>">
105  <?php
106        // print interlanguage links for all languages except the active one
107        foreach($this->interlang_links as $lang => $a) {
108                if($lang != $this->conf['lang']) {
109                        printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">',
110                                $a['href'], $lang, sprintf($_('head-rel-interlang'), $a)
111                        );
112                }
113        }
114  ?>
115 
116  <meta name="viewport" content="width=device-width,initial-scale=1">
117  <link rel="stylesheet" href="/shared/css-v6/boiler.css">
118  <link rel="stylesheet" href="/shared/css-v6/style.css">
119  <link rel="stylesheet" href="/shared/css/common.css">
120
121  <script src="/shared/js-v6/libs/modernizr-2.0.6.min.js"></script>
122</head>
123
124<body class="<?php echo implode(' ', $this->body_classes) ?>">
125<div id="footer-background-container"><!-- helper -->
126  <div id="container">
127        <h1 role="banner"><a href="/" title="<?php $p('head-h1-title'); ?>"><?php $p('head-h1'); ?></a></h1>
128        <div id="background-color-container"><!-- helper -->
129        <section class="main content" role="main" id="content">
130                <!--<header class="teaser">
131                        <h2 id="pdp8L">Wissenschaftliche Rechner und Minicomputer</h2>
132                        <img width=880 src="http://www.technikum29.de/shared/photos/rechnertechnik/univac/panorama-rechts.jpg">
133                </header>-->
134        <!-- start content -->
135<?php 
136} // function print_header().
137
138        function print_footer() {
139                $p = $this->msg->get_shorthand_printer();
140                $_ = $this->msg->get_shorthand_returner();
141        ?>
142        <!-- end content -->
143        </section>
144        <hr>
145        <section class="sidebar">
146                        <h2 class="visuallyhidden"><?php $p("sidebar-h2-tour"); ?></h2>
147                        <nav class="side">
148                                <?php $this->menu->print_menu(t29Menu::sidebar_menu); ?>
149                        </nav>
150                        <!-- menu changing buttons are made with javascript -->
151        </section>
152        </div><!-- div id="background-color-container" helper end -->
153        <hr>
154        <header class="banner">
155                <h2 class="visuallyhidden"><?php $p("sidebar-h2-mainnav"); ?></h2>
156                <nav class="horizontal">
157                        <?php $this->menu->print_menu(t29Menu::horizontal_menu); ?>
158                </nav>
159                <nav class="top">
160                        <h3 class="visuallyhidden"><?php $p("sidebar-h2-lang"); ?></h3>
161                        <ul>
162                                <?php
163                                        foreach($this->interlang_links as $lang => $a) {
164                                                printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n",
165                                                        ($lang == $this->conf['lang'] ? ' class="active"' : ''),
166                                                        $a['href'], sprintf($_('topnav-interlang-title'), $a),
167                                                        $this->conf['languages'][$lang][0] // verbose language name
168                                                );
169                                        }
170                                ?>
171                        </ul>
172                        <form method="get" action="#"><?php printf('
173                                <span class="no-js">%s:</span>
174                                <input type="text" value="" data-defaultvalue="%s" name="q" class="text">
175                                <input type="submit" value="%s" class="button">
176                                ', $_('topnav-search-label'), $_('topnav-search-label'), $_('topnav-search-label')); ?>
177                        </form>
178                </nav>
179    </header>
180        <hr>
181    <footer>
182                <nav class="guide">
183                        <!-- hier wird nav.side die Liste per JS reinkopiert -->
184                </nav>
185                <nav class="rel clearfix">
186                <ul>
187                        <?php
188                                foreach($this->page_relations as $rel => $a) {
189                                        printf("\t<li class='%s'><a href='%s' title='%s'>%s <strong>%s</strong></a>\n",
190                                                $rel, $a['href'], 'TITLE', $_('nav-rel-'.$rel), $a
191                                        );
192                                }
193                        ?>
194                </ul>
195                </nav>
196                <div class="right">
197                        <img src="/shared/img-v6/logo.footer.png" title="technikum29 Logo" alt="Logo" class="logo">
198                        <?php $p('footer-copyright-tag'); ?>
199                        <br/><?php printf('<a href="%s">%s</a>', $this->conf['legal_pagename'], $_('footer-legal-link')); ?>
200                        <div class="icons">
201                                <a href="<?php echo $this->conf['legal_pagename']; ?>#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a>
202                                <!--<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>-->
203                        </div>
204                        <!--CC<br>Viele Bilder können unter einer CreativeCommons-Lizenz
205                        verwendet werden. Erkundigen Sie sich.-->
206                </div>
207                               
208                <!--Copyright-Hinweis<br>
209                technikum29-Logo, Link aufs Impressum, Kontakt<br>
210                Creative-Commons-Tag<br>
211                Designed by Ufopixel<br>-->
212    </footer>
213  </div> <!--! end of #container -->
214
215
216  <!-- JavaScript at the bottom for fast page loading -->
217
218  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
219  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
220  <script>window.jQuery || document.write('<script src="/shared/js-v6/libs/jquery-1.7.2.min.js"><\/script>')</script>
221
222  <!--<script src="/lib/messages.php?pre=t29MSGDATA%3D&post=<?php echo urlencode('$(function(){t29.msg.setup();});'); ?>"></script>-->
223  <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script>
224  <script src="/lib/js.php"></script>
225</div><!-- end of div id="footer-background-container" helper -->
226</body>
227</html>
228<?php
229        } // function print_footer()
230       
231} // 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