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

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

Weitere Fixes in den Geräteseiten:

  • Univac-Geräteseiten konvertiert
  • Interlang-System verbessert (bessere Ausgabe bei nicht existierenden Interlang-Links)
  • Property svn:keywords set to Id
File size: 10.2 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
13require dirname(__FILE__) . "/ressourceloader.php";
14
15class t29Template {
16        public $conf, $menu, $msg;
17        public $body_classes = array();
18        public $javascript_config = array();
19        public $page_relations, $interlang_links;
20        public $log; // lightweight logging system
21
22        function __construct($conf_array) {
23                $this->conf = $conf_array;
24               
25                // create a lightweight logging object:
26                require_once $this->conf['lib'].'/logging.php';
27                $this->log = new t29Log();
28
29                // create a menu:
30                require_once $this->conf['lib'].'/menu.php';
31                $this->menu = new t29Menu($this->conf);
32
33                // create localisation class:
34                require_once $this->conf['lib'].'/messages.php';
35                $this->msg = new t29Messages($this->conf['lang']);
36
37                // fill up configuration
38                // Path names in messages
39                foreach(array('footer-legal-file', 'topnav-search-page') as $msg)
40                        $this->conf[$msg] = $this->conf['lang_path'] . $this->msg->_($msg);
41
42                // setup body classes:
43                $this->body_classes[] = "lang-" . $this->conf['lang'];
44                $this->body_classes[] = "page-" . $this->conf['seiten_id'];
45               
46                // setup javascript configuration
47                $this->javascript_config['lang'] = $this->conf['lang'];
48                $this->javascript_config['seiten_id'] = $this->conf['seiten_id'];
49               
50                // get all kind of relations
51                $this->page_relations = $this->menu->get_page_relations();
52                $this->interlang_links = $this->menu->get_interlanguage_link();
53               
54                // check and load additional css
55                $this->conf['pagecss'] = '/shared/css-v6/pagestyles/'.$this->conf['seiten_id'].'.css';
56                $this->conf['has_pagecss'] = file_exists($this->conf['webroot'].$this->conf['pagecss']);
57                // FIXME: There is no caching check yet for this setting
58                //        (new pagecss file won't be detected and wont purge the tmpl cache)
59        }
60       
61        /**
62         * Main caching and output system.
63         * Parameters (global configuration):
64         *    skip_cache  -  if true, skips writing output to cache file
65         *    purge_cache -  if true, forces creation of new cache file
66         *                   (does not change behaviour of this file's code)
67         **/
68        function create_cache($cache_object) {
69                $cache_object->start_cache(array($this, 'print_footer'));
70                $this->print_header();
71        }
72       
73        /**
74         * Write header and footer in separate cache files.
75         **/
76        function create_separate_caches($header_cache, $footer_cache) {
77                $header_cache->start_cache();
78                $this->print_header();
79                $header_cache->write_cache(); // will also print out header immediately.
80               
81                $footer_cache->start_cache();
82                $this->print_footer();
83                $footer_content = $footer_cache->write_cache(null, true); // don't print footer immediately.
84               
85                // print footer on exit.
86                register_shutdown_function(function() use ($footer_content) {
87                        print $footer_content;
88                });
89        }
90
91        function print_header() {
92                $p = $this->msg->get_shorthand_printer();
93                $_ = $this->msg->get_shorthand_returner();
94?>
95<!doctype html>
96<html class="no-js" lang="<?php echo $this->conf['lang']; ?>">
97<head>
98  <meta charset="utf-8">
99  <title><?php echo isset($this->conf['titel']) ? $this->conf['titel'].' - ' : ''; $p('html-title'); ?></title>
100  <meta name="description" content="Produziert am 08.01.2012">
101  <meta name="author" content="Sven">
102  <meta name="generator" content="t29v6">
103  <meta name="t29.cachedate" content="<?php print date('r'); ?>">
104  <?php
105        if(isset($this->conf['version'])) printf('<meta name="t29.version" content="%s">', $this->conf['version']);
106  ?>
107 
108  <?php
109        foreach(array_merge(array("first" => t29Menu::dom_new_link($this->conf['lang_path'], $_('head-rel-first'))),
110          $this->page_relations) as $rel => $a) {
111                if($rel == 'start') continue; // not in standard
112                printf("\n  <link rel='%s' href='%s' title='%s' />",
113                        $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a))
114                );
115        }
116  ?>
117 
118  <link rel="copyright" href="<?php echo $this->conf['footer-legal-file']; ?>" title="<?php $p('footer-legal-link'); ?>">
119  <link rel="search" type="application/opensearchdescription+xml" href="<?php print $this->conf['topnav-search-page'] . '?action=opensearch-desc'; ?>" title="<?php $p('opensearch-desc'); ?>">
120  <?php
121        // print interlanguage links for all languages except the active one
122        foreach($this->interlang_links as $lang => $a) {
123                if($lang != $this->conf['lang'] && !is_null($a)) {
124                        printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">',
125                                $a['href'], $lang, sprintf($_('head-rel-interlang', $lang), $a)
126                        );
127                }
128        }
129  ?>
130 
131  <meta name="viewport" content="width=device-width,initial-scale=1">
132  <?php
133        $csslinktmpl = PHP_EOL.'  <link rel="stylesheet" href="%s">';
134        foreach($this->get_ressourceloader_links('css') as $css)
135                printf($csslinktmpl, $css);
136 
137        if($this->conf['has_pagecss'])
138                printf($csslinktmpl, $this->conf['pagecss']);
139  ?>
140
141  <script src="/shared/js-v6/libs/modernizr-2.0.6.min.js"></script>
142</head>
143
144<body class="<?php echo implode(' ', $this->body_classes) ?>">
145<div id="footer-background-container"><!-- helper -->
146  <div id="container">
147        <h1 role="banner"><a href="/" title="<?php $p('head-h1-title'); ?>"><?php $p('head-h1'); ?></a></h1>
148        <div id="background-color-container"><!-- helper -->
149        <section class="main content" role="main" id="content">
150                <?php 
151                        if(!$this->log->is_empty()) {
152                                print '<div class="errorpane">';
153                                $this->log->print_all();
154                                print '</div>';
155                        }
156                ?>
157                <!--<header class="teaser">
158                        <h2 id="pdp8L">Wissenschaftliche Rechner und Minicomputer</h2>
159                        <img width=880 src="http://www.technikum29.de/shared/photos/rechnertechnik/univac/panorama-rechts.jpg">
160                </header>-->
161        <!-- start content -->
162<?php 
163} // function print_header().
164
165        function print_footer() {
166                $p = $this->msg->get_shorthand_printer();
167                $_ = $this->msg->get_shorthand_returner();
168        ?>
169        <!-- end content -->
170        </section>
171        <hr>
172        <section class="sidebar top">
173                        <h2 class="visuallyhidden"><?php $p("sidebar-h2-tour"); ?></h2>
174                        <nav class="side">
175                                <?php $this->menu->print_menu(t29Menu::sidebar_menu); ?>
176                        </nav>
177                        <!-- menu changing buttons are made with javascript -->
178        </section>
179        <section class="sidebar bottom">
180                <!-- inhalte die unten ueber dem header sind -->
181        </section>
182        </div><!-- div id="background-color-container" helper end -->
183        <hr>
184        <header class="banner">
185                <h2 class="visuallyhidden"><?php $p("sidebar-h2-mainnav"); ?></h2>
186                <nav class="horizontal">
187                        <?php $this->menu->print_menu(t29Menu::horizontal_menu); ?>
188                </nav>
189                <nav class="top">
190                        <h3 class="visuallyhidden"><?php $p("sidebar-h2-lang"); ?></h3>
191                        <ul>
192                                <?php
193                                        foreach($this->interlang_links as $lang => $a) {
194                                                $is_current_lang = $lang == $this->conf['lang'];
195                                                if(is_null($a)) {
196                                                        // when interlanguage link not present (null) = no translation exists
197                                                        $a = t29Menu::dom_new_link('#', 'not present');
198                                                        $title = sprintf($_('topnav-interlang-nonexistent', $lang));
199                                                        $class = 'nonexistent';
200                                                } elseif($is_current_lang) {
201                                                        $title = sprintf($_('topnav-interlang-active'), $a);
202                                                        $class = 'active';
203                                                } else {
204                                                        // ordinary interlang link
205                                                        $title = sprintf($_('topnav-interlang-title', $lang), $a);
206                                                        $class = '';
207                                                }
208                                                printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n",
209                                                        (empty($class) ? '' : " class='$class'"),
210                                                        $a['href'], htmlspecialchars($title),
211                                                        $this->conf['languages'][$lang][0] // verbose language name
212                                                );
213                                        }
214                                ?>
215                        </ul>
216                        <form method="get" action="<?php print $this->conf['topnav-search-page']; ?>">
217                                <span class="no-js"><?php $p('topnav-search-label'); ?>:</span>
218                                <input type="text" value="" data-defaultvalue="<?php $p('topnav-search-label'); ?>" name="q" class="text">
219                                <input type="submit" value="<? $p('topnav-search-label'); ?>" class="button">
220                        </form>
221                </nav>
222    </header>
223        <hr>
224    <footer>
225                <nav class="guide">
226                        <!-- hier wird nav.side die Liste per JS reinkopiert -->
227                </nav>
228                <nav class="rel clearfix">
229                <ul>
230                        <?php
231                                foreach($this->page_relations as $rel => $a) {
232                                        printf("\t<li class='%s'><a href='%s' title='%s'>%s <strong>%s</strong></a>\n",
233                                                $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a)),
234                                                $_('nav-rel-'.$rel), $this->relational_link_to_string($a)
235                                        );
236                                }
237                        ?>
238                </ul>
239                </nav>
240                <div class="right">
241                        <img src="/shared/img-v6/logo.footer.png" title="technikum29 Logo" alt="Logo" class="logo">
242                        <?php $p('footer-copyright-tag'); ?>
243                        <br/><?php printf('<a href="%s">%s</a>', $this->conf['footer-legal-file'], $_('footer-legal-link')); ?>
244                        <div class="icons">
245                                <a href="<?php echo $this->conf['footer-legal-file']; ?>#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a>
246                                <!--<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>-->
247                        </div>
248                        <!--CC<br>Viele Bilder können unter einer CreativeCommons-Lizenz
249                        verwendet werden. Erkundigen Sie sich.-->
250                </div>
251    </footer>
252  </div> <!--! end of #container -->
253
254
255  <!-- JavaScript at the bottom for fast page loading -->
256
257  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
258  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
259  <script>window.jQuery || document.write('<script src="/shared/js-v6/libs/jquery-1.7.2.min.js"><\/script>')</script>
260
261  <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script>
262  <?php
263        foreach($this->get_ressourceloader_links('js') as $js)
264                printf('  <script src="%s"></script>'.PHP_EOL, $js);
265  ?>
266</div><!-- end of div id="footer-background-container" helper -->
267</body>
268</html>
269<?php
270        } // function print_footer()
271       
272        // Hilfsfunktionen
273        private function relational_link_to_string($a) {
274                // wenn es bei einem relationalen Link einen Titel gibt, diesen ausgeben, ansonsten die
275                // Linkbeschreibung. Die Links sind XML-Elemente in der Navigation.
276                return isset($a['title']) ? $a['title'] : $a;
277        }
278
279        function get_ressourceloader_links($type) {
280                $rl = t29RessourceLoader::create_from_type($type, $this->conf);
281                return $rl->get_urls( isset($_GET['rl_debug']) );
282        }
283
284} // 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