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

Last change on this file since 307 was 307, checked in by sven, 11 years ago
  • Fehlerseite (404) mit besserem Text (mehrsprachig) bestückt
  • t29Client PHP-Klasse hinzugefügt (noch keine große Verwendung)
  • Kleines Design für Tablet-Computer und schmale Bildschirme geschrieben
  • Fixes in robots.txt (piwik-Logging-Mountpoint nicht erschliessen)
  • template.php: Klassendurchreichen einer Information ueber leere Footer
  • Property svn:keywords set to Id
File size: 12.4 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 **/
[273]12
[254]13class t29Template {
[297]14        public $conf, $menu, $msg;
[255]15        public $body_classes = array();
16        public $javascript_config = array();
[259]17        public $page_relations, $interlang_links;
[275]18        public $log; // lightweight logging system
[255]19
[254]20        function __construct($conf_array) {
21                $this->conf = $conf_array;
[275]22               
[297]23                // fetch the lightweight logging object:
[275]24                require_once $this->conf['lib'].'/logging.php';
[297]25                $this->log = t29Log::get();
[255]26
[254]27                // create a menu:
28                require_once $this->conf['lib'].'/menu.php';
29                $this->menu = new t29Menu($this->conf);
[255]30
31                // create localisation class:
32                require_once $this->conf['lib'].'/messages.php';
33                $this->msg = new t29Messages($this->conf['lang']);
[301]34               
35                // create the ressourceloaders:
36                require_once $this->conf['lib'].'/ressourceloader.php';
37                $this->rl = array();
38                foreach(array('js','css') as $type)
39                        $this->rl[$type] = t29RessourceLoader::create_from_type($type, $this->conf);
[255]40
[259]41                // fill up configuration
[297]42
43                // optional html headers which can be filled by hooks or parts
[296]44                if(!isset($this->conf['header_prepend']))
45                        $this->conf['header_prepend'] = array(); // list
[297]46
47                // as t29Host for configuration fillup fillup
48                $this->conf['host']->fillup_template_conf($this->conf);
[296]49               
[273]50                // Path names in messages
[289]51                foreach(array('footer-legal-file', 'topnav-search-page') as $msg_id)
52                        $this->msg->set($msg_id, $this->conf['lang_path'].$this->msg->_($msg_id));
[259]53
[279]54                // store informations about the current page
55                $this->conf['seiten_link'] = $this->menu->get_link();
56                $this->conf['seite_in_nav'] = $this->menu->get_link_navigation_class($this->conf['seiten_link']);
57                $this->conf['seite_in_ul'] = $this->menu->get_link_ul_classes($this->conf['seiten_link']);
58
[255]59                // setup body classes:
[279]60                $body_classprefixes = array(
61                        // css prefix => configuration array value
62                        'lang-' => 'lang',
63                        'page-' => 'seiten_id',
64                        'in-nav-' => 'seite_in_nav',
65                        'in-' => 'seite_in_ul',
66                );
67                foreach($body_classprefixes as $prefix => $key) {
68                        if(is_array($this->conf[$key]))
69                                // append each element of array conf values
70                                foreach($this->conf[$key] as $x)
71                                        $this->body_classes[] = $prefix . $x;
72                        elseif($this->conf[$key]) // skip null/false/empty conf values
73                                $this->body_classes[] = $prefix . $this->conf[$key];
74                }
[255]75               
76                // setup javascript configuration
[279]77                $javascript_transfer = array('lang', 'seiten_id', 'seite_in_nav', 'seite_in_ul');
78                foreach($javascript_transfer as $key)
79                        $this->javascript_config[$key] = $this->conf[$key];
[259]80               
81                // get all kind of relations
82                $this->page_relations = $this->menu->get_page_relations();
83                $this->interlang_links = $this->menu->get_interlanguage_link();
[261]84               
85                // check and load additional css
86                $this->conf['pagecss'] = '/shared/css-v6/pagestyles/'.$this->conf['seiten_id'].'.css';
87                $this->conf['has_pagecss'] = file_exists($this->conf['webroot'].$this->conf['pagecss']);
88                // FIXME: There is no caching check yet for this setting
89                //        (new pagecss file won't be detected and wont purge the tmpl cache)
[279]90               
91                // setup html title
92                $this->conf['html_title'] = '';
93                if(isset($this->conf['titel']) && !empty($this->conf['titel']))
94                        $this->conf['html_title'] = $this->conf['titel'] . ' - ';
[299]95                // Startseite macht ihren Titel jetzt selbst (SEO):
96                //elseif($this->conf['seiten_id'] == $this->msg->_('homepage-pagename'))
97                //      {} // nop: Startseitentitel soll nur sein "technikum29"
[279]98                elseif($this->conf['seiten_link'])
99                        // Titel vom Menu nehmen
100                        $this->conf['html_title'] = $this->conf['seiten_link'] . ' - ';
101                $this->conf['html_title'] .= $this->msg->_('html-title');
[254]102        }
103       
104        /**
105         * Main caching and output system.
106         * Parameters (global configuration):
107         *    skip_cache  -  if true, skips writing output to cache file
108         *    purge_cache -  if true, forces creation of new cache file
109         *                   (does not change behaviour of this file's code)
110         **/
[264]111        function create_cache($cache_object) {
112                $cache_object->start_cache(array($this, 'print_footer'));
[254]113                $this->print_header();
114        }
[273]115       
116        /**
117         * Write header and footer in separate cache files.
118         **/
119        function create_separate_caches($header_cache, $footer_cache) {
120                $header_cache->start_cache();
121                $this->print_header();
122                $header_cache->write_cache(); // will also print out header immediately.
123               
124                $footer_cache->start_cache();
125                $this->print_footer();
126                $footer_content = $footer_cache->write_cache(null, true); // don't print footer immediately.
127               
128                // print footer on exit.
129                register_shutdown_function(function() use ($footer_content) {
130                        print $footer_content;
131                });
132        }
[254]133
134        function print_header() {
[259]135                $p = $this->msg->get_shorthand_printer();
136                $_ = $this->msg->get_shorthand_returner();
[251]137?>
138<!doctype html>
[255]139<html class="no-js" lang="<?php echo $this->conf['lang']; ?>">
[251]140<head>
141  <meta charset="utf-8">
[279]142  <title><?php echo $this->conf['html_title']; ?></title>
[251]143  <meta name="description" content="Produziert am 08.01.2012">
[289]144  <meta name="author" content="technikum29-Team">
[297]145  <meta name="generator" content="t29v6/<?php print $this->conf['host']->hostname; ?>">
[254]146  <meta name="t29.cachedate" content="<?php print date('r'); ?>">
[264]147  <?php
[297]148        foreach($this->conf['header_prepend'] as $h) print $h."\n  ";
[296]149 
[264]150        if(isset($this->conf['version'])) printf('<meta name="t29.version" content="%s">', $this->conf['version']);
[277]151        if(isset($_GET['debug']))
152                foreach(explode(' ','debug rl_debug skip_cache purge_cache verbose_cache') as $x)
153                        printf("\n  <meta name='t29.template.data-%s' content='%s'>", $x, isset($_GET[$x])?'true':'false');
[264]154  ?>
[259]155 
156  <?php
157        foreach(array_merge(array("first" => t29Menu::dom_new_link($this->conf['lang_path'], $_('head-rel-first'))),
158          $this->page_relations) as $rel => $a) {
159                if($rel == 'start') continue; // not in standard
160                printf("\n  <link rel='%s' href='%s' title='%s' />",
[266]161                        $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a))
[259]162                );
163        }
164  ?>
165 
[289]166  <link rel="copyright" href="<?php $p('footer-legal-file'); ?>" title="<?php $p('footer-legal-link'); ?>">
[290]167  <link rel="search" type="application/opensearchdescription+xml" href="<?php $p('topnav-search-page'); print '?action=opensearch-desc&amp;lang='.$this->conf['lang']; ?>" title="<?php $p('opensearch-desc'); ?>">
[259]168  <?php
169        // print interlanguage links for all languages except the active one
170        foreach($this->interlang_links as $lang => $a) {
[276]171                if($lang != $this->conf['lang'] && !is_null($a)) {
[259]172                        printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">',
[276]173                                $a['href'], $lang, sprintf($_('head-rel-interlang', $lang), $a)
[259]174                        );
175                }
176        }
177  ?>
178 
[251]179  <meta name="viewport" content="width=device-width,initial-scale=1">
[261]180  <?php
[301]181        $this->print_ressourceloader_links('css', PHP_EOL . '  <link rel="stylesheet" href="%s">');
[261]182  ?>
[251]183
184  <script src="/shared/js-v6/libs/modernizr-2.0.6.min.js"></script>
185</head>
186
[255]187<body class="<?php echo implode(' ', $this->body_classes) ?>">
[251]188  <div id="container">
[259]189        <h1 role="banner"><a href="/" title="<?php $p('head-h1-title'); ?>"><?php $p('head-h1'); ?></a></h1>
[251]190        <div id="background-color-container"><!-- helper -->
191        <section class="main content" role="main" id="content">
[275]192                <?php 
193                        if(!$this->log->is_empty()) {
194                                print '<div class="errorpane">';
195                                $this->log->print_all();
196                                print '</div>';
197                        }
198                ?>
[251]199                <!--<header class="teaser">
200                        <h2 id="pdp8L">Wissenschaftliche Rechner und Minicomputer</h2>
201                        <img width=880 src="http://www.technikum29.de/shared/photos/rechnertechnik/univac/panorama-rechts.jpg">
202                </header>-->
[254]203        <!-- start content -->
[251]204<?php 
205} // function print_header().
206
[259]207        function print_footer() {
208                $p = $this->msg->get_shorthand_printer();
209                $_ = $this->msg->get_shorthand_returner();
210        ?>
[254]211        <!-- end content -->
[251]212        </section>
213        <hr>
[265]214        <section class="sidebar top">
[255]215                        <h2 class="visuallyhidden"><?php $p("sidebar-h2-tour"); ?></h2>
[251]216                        <nav class="side">
[255]217                                <?php $this->menu->print_menu(t29Menu::sidebar_menu); ?>
[251]218                        </nav>
[255]219                        <!-- menu changing buttons are made with javascript -->
[251]220        </section>
[265]221        <section class="sidebar bottom">
222                <!-- inhalte die unten ueber dem header sind -->
223        </section>
[251]224        </div><!-- div id="background-color-container" helper end -->
225        <hr>
226        <header class="banner">
[255]227                <h2 class="visuallyhidden"><?php $p("sidebar-h2-mainnav"); ?></h2>
[251]228                <nav class="horizontal">
[255]229                        <?php $this->menu->print_menu(t29Menu::horizontal_menu); ?>
[251]230                </nav>
231                <nav class="top">
[255]232                        <h3 class="visuallyhidden"><?php $p("sidebar-h2-lang"); ?></h3>
[251]233                        <ul>
[255]234                                <?php
[259]235                                        foreach($this->interlang_links as $lang => $a) {
[276]236                                                $is_current_lang = $lang == $this->conf['lang'];
237                                                if(is_null($a)) {
238                                                        // when interlanguage link not present (null) = no translation exists
239                                                        $a = t29Menu::dom_new_link('#', 'not present');
240                                                        $title = sprintf($_('topnav-interlang-nonexistent', $lang));
241                                                        $class = 'nonexistent';
242                                                } elseif($is_current_lang) {
243                                                        $title = sprintf($_('topnav-interlang-active'), $a);
244                                                        $class = 'active';
245                                                } else {
246                                                        // ordinary interlang link
247                                                        $title = sprintf($_('topnav-interlang-title', $lang), $a);
248                                                        $class = '';
249                                                }
[255]250                                                printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n",
[276]251                                                        (empty($class) ? '' : " class='$class'"),
252                                                        $a['href'], htmlspecialchars($title),
[259]253                                                        $this->conf['languages'][$lang][0] // verbose language name
[255]254                                                );
255                                        }
256                                ?>
[251]257                        </ul>
[289]258                        <form method="get" action="<?php $p('topnav-search-page'); ?>">
[268]259                                <span class="no-js"><?php $p('topnav-search-label'); ?>:</span>
260                                <input type="text" value="" data-defaultvalue="<?php $p('topnav-search-label'); ?>" name="q" class="text">
261                                <input type="submit" value="<? $p('topnav-search-label'); ?>" class="button">
[251]262                        </form>
263                </nav>
264    </header>
265        <hr>
[307]266        <?php
267                // only print menu when in sidebar where it applies
268                $print_footer_menu = ($this->conf['seite_in_nav'] == 'side');
269        ?>
270    <footer class="in-sheet <? if(!$print_footer_menu) print "empty-footer"; ?>">
[251]271                <nav class="guide">
272                        <!-- hier wird nav.side die Liste per JS reinkopiert -->
273                </nav>
274                <nav class="rel clearfix">
275                <ul>
[259]276                        <?php
[307]277                          if($print_footer_menu)
[259]278                                foreach($this->page_relations as $rel => $a) {
279                                        printf("\t<li class='%s'><a href='%s' title='%s'>%s <strong>%s</strong></a>\n",
[266]280                                                $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a)),
281                                                $_('nav-rel-'.$rel), $this->relational_link_to_string($a)
[259]282                                        );
283                                }
284                        ?>
[251]285                </ul>
286                </nav>
287                <div class="right">
[289]288                        <!-- text der rechts unten steht -->
[251]289                </div>
290    </footer>
291  </div> <!--! end of #container -->
[289]292  <footer class="attached">
[291]293    <div class="legacy"><?php $p('footer-legacy-text'); ?></div>
294        <!--
[289]295        <ul class="clearfix">
296        <li class="logo">
297                <a href="<?php $p('footer-legal-file'); ?>" class="img" title="technikum29 Logo">Logo</a>
298                <p><?php $p('footer-copyright-tag'); ?>
299                   <br><?php printf('<a href="%s">%s</a>', $_('footer-legal-file'), $_('footer-legal-link')); ?>
300                </p>
301        </li>
302        <li class="copy">
303                <a href="<?php $p('footer-legal-file'); ?>#image-copyright" class="img">CC</a>
304                <p>Viele Bilder können unter einer <a href="<?php $p('footer-legal-file'); ?>#image-copyright">CreativeCommons-Lizenz</a>
305                   verwendet werden. <a href="<?php $p('footer-legal-file'); ?>#image-copyright">Erkundigen Sie sich</a>.</p>
306        </li>
307        </ul>
[291]308        -->
[289]309  </footer>
[277]310</div><!-- end of div id="footer-background-container" helper -->
[251]311
[306]312  <? /* JavaScript at the bottom for fast page loading */ ?>
[301]313  <script src="/shared/js-v6/libs/jquery-1.7.2.min.js"></script>
[260]314  <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script>
[273]315  <?php
[301]316        $this->print_ressourceloader_links('js', '  <script src="%s"></script>'.PHP_EOL);
[273]317  ?>
[306]318  <? /* Piwik Noscript, Script selbst wird asynchron im JS-Bereich aufgerufen */ ?>
319  <noscript><img src="<? $p("js-piwik-noscript-imgsrc"); ?>" alt="" /></noscript>
[251]320</body>
321</html>
322<?php
[254]323        } // function print_footer()
324       
[266]325        // Hilfsfunktionen
326        private function relational_link_to_string($a) {
327                // wenn es bei einem relationalen Link einen Titel gibt, diesen ausgeben, ansonsten die
328                // Linkbeschreibung. Die Links sind XML-Elemente in der Navigation.
329                return isset($a['title']) ? $a['title'] : $a;
330        }
[273]331
[301]332        function print_ressourceloader_links($type, $template='<!-- RL: %s -->') {
333                $rl = $this->rl[$type];
334                $rl_links = $rl->get_urls( isset($_GET['rl_debug']) );
335                $rl_pagespecific_links = $rl->get_page_specific_urls($this->conf['seiten_id']);
336
337                foreach(array($rl_links, $rl_pagespecific_links) as $rls)
338                        foreach($rls as $link)
339                                printf($template, $link);
[273]340        }
341
[301]342
[254]343} // 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