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

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

JavaScript-Preferences-System, mit dem die Einstellungen fuers Menue erhalten bleiben. Refactoring des menu.js-Codes. startup.js um Reihenfolge der Scripte festzulegen. Diverse Bugfixes im PHP und Inhalt.

  • Property svn:keywords set to Id
File size: 10.4 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        if(isset($_GET['debug']))
107                foreach(explode(' ','debug rl_debug skip_cache purge_cache verbose_cache') as $x)
108                        printf("\n  <meta name='t29.template.data-%s' content='%s'>", $x, isset($_GET[$x])?'true':'false');
109  ?>
110 
111  <?php
112        foreach(array_merge(array("first" => t29Menu::dom_new_link($this->conf['lang_path'], $_('head-rel-first'))),
113          $this->page_relations) as $rel => $a) {
114                if($rel == 'start') continue; // not in standard
115                printf("\n  <link rel='%s' href='%s' title='%s' />",
116                        $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a))
117                );
118        }
119  ?>
120 
121  <link rel="copyright" href="<?php echo $this->conf['footer-legal-file']; ?>" title="<?php $p('footer-legal-link'); ?>">
122  <link rel="search" type="application/opensearchdescription+xml" href="<?php print $this->conf['topnav-search-page'] . '?action=opensearch-desc'; ?>" title="<?php $p('opensearch-desc'); ?>">
123  <?php
124        // print interlanguage links for all languages except the active one
125        foreach($this->interlang_links as $lang => $a) {
126                if($lang != $this->conf['lang'] && !is_null($a)) {
127                        printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">',
128                                $a['href'], $lang, sprintf($_('head-rel-interlang', $lang), $a)
129                        );
130                }
131        }
132  ?>
133 
134  <meta name="viewport" content="width=device-width,initial-scale=1">
135  <?php
136        $csslinktmpl = PHP_EOL.'  <link rel="stylesheet" href="%s">';
137        foreach($this->get_ressourceloader_links('css') as $css)
138                printf($csslinktmpl, $css);
139 
140        if($this->conf['has_pagecss'])
141                printf($csslinktmpl, $this->conf['pagecss']);
142  ?>
143
144  <script src="/shared/js-v6/libs/modernizr-2.0.6.min.js"></script>
145</head>
146
147<body class="<?php echo implode(' ', $this->body_classes) ?>">
148<div id="footer-background-container"><!-- helper -->
149  <div id="container">
150        <h1 role="banner"><a href="/" title="<?php $p('head-h1-title'); ?>"><?php $p('head-h1'); ?></a></h1>
151        <div id="background-color-container"><!-- helper -->
152        <section class="main content" role="main" id="content">
153                <?php 
154                        if(!$this->log->is_empty()) {
155                                print '<div class="errorpane">';
156                                $this->log->print_all();
157                                print '</div>';
158                        }
159                ?>
160                <!--<header class="teaser">
161                        <h2 id="pdp8L">Wissenschaftliche Rechner und Minicomputer</h2>
162                        <img width=880 src="http://www.technikum29.de/shared/photos/rechnertechnik/univac/panorama-rechts.jpg">
163                </header>-->
164        <!-- start content -->
165<?php 
166} // function print_header().
167
168        function print_footer() {
169                $p = $this->msg->get_shorthand_printer();
170                $_ = $this->msg->get_shorthand_returner();
171        ?>
172        <!-- end content -->
173        </section>
174        <hr>
175        <section class="sidebar top">
176                        <h2 class="visuallyhidden"><?php $p("sidebar-h2-tour"); ?></h2>
177                        <nav class="side">
178                                <?php $this->menu->print_menu(t29Menu::sidebar_menu); ?>
179                        </nav>
180                        <!-- menu changing buttons are made with javascript -->
181        </section>
182        <section class="sidebar bottom">
183                <!-- inhalte die unten ueber dem header sind -->
184        </section>
185        </div><!-- div id="background-color-container" helper end -->
186        <hr>
187        <header class="banner">
188                <h2 class="visuallyhidden"><?php $p("sidebar-h2-mainnav"); ?></h2>
189                <nav class="horizontal">
190                        <?php $this->menu->print_menu(t29Menu::horizontal_menu); ?>
191                </nav>
192                <nav class="top">
193                        <h3 class="visuallyhidden"><?php $p("sidebar-h2-lang"); ?></h3>
194                        <ul>
195                                <?php
196                                        foreach($this->interlang_links as $lang => $a) {
197                                                $is_current_lang = $lang == $this->conf['lang'];
198                                                if(is_null($a)) {
199                                                        // when interlanguage link not present (null) = no translation exists
200                                                        $a = t29Menu::dom_new_link('#', 'not present');
201                                                        $title = sprintf($_('topnav-interlang-nonexistent', $lang));
202                                                        $class = 'nonexistent';
203                                                } elseif($is_current_lang) {
204                                                        $title = sprintf($_('topnav-interlang-active'), $a);
205                                                        $class = 'active';
206                                                } else {
207                                                        // ordinary interlang link
208                                                        $title = sprintf($_('topnav-interlang-title', $lang), $a);
209                                                        $class = '';
210                                                }
211                                                printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n",
212                                                        (empty($class) ? '' : " class='$class'"),
213                                                        $a['href'], htmlspecialchars($title),
214                                                        $this->conf['languages'][$lang][0] // verbose language name
215                                                );
216                                        }
217                                ?>
218                        </ul>
219                        <form method="get" action="<?php print $this->conf['topnav-search-page']; ?>">
220                                <span class="no-js"><?php $p('topnav-search-label'); ?>:</span>
221                                <input type="text" value="" data-defaultvalue="<?php $p('topnav-search-label'); ?>" name="q" class="text">
222                                <input type="submit" value="<? $p('topnav-search-label'); ?>" class="button">
223                        </form>
224                </nav>
225    </header>
226        <hr>
227    <footer>
228                <nav class="guide">
229                        <!-- hier wird nav.side die Liste per JS reinkopiert -->
230                </nav>
231                <nav class="rel clearfix">
232                <ul>
233                        <?php
234                                foreach($this->page_relations as $rel => $a) {
235                                        printf("\t<li class='%s'><a href='%s' title='%s'>%s <strong>%s</strong></a>\n",
236                                                $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a)),
237                                                $_('nav-rel-'.$rel), $this->relational_link_to_string($a)
238                                        );
239                                }
240                        ?>
241                </ul>
242                </nav>
243                <div class="right">
244                        <img src="/shared/img-v6/logo.footer.png" title="technikum29 Logo" alt="Logo" class="logo">
245                        <?php $p('footer-copyright-tag'); ?>
246                        <br/><?php printf('<a href="%s">%s</a>', $this->conf['footer-legal-file'], $_('footer-legal-link')); ?>
247                        <div class="icons">
248                                <a href="<?php echo $this->conf['footer-legal-file']; ?>#image-copyright"><img src="/shared/img-v6/cc-icon.png"></a>
249                                <!--<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>-->
250                        </div>
251                        <!--CC<br>Viele Bilder können unter einer CreativeCommons-Lizenz
252                        verwendet werden. Erkundigen Sie sich.-->
253                </div>
254    </footer>
255  </div> <!--! end of #container -->
256</div><!-- end of div id="footer-background-container" helper -->
257
258  <!-- JavaScript at the bottom for fast page loading -->
259
260  <!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->
261  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
262  <script>window.jQuery || document.write('<script src="/shared/js-v6/libs/jquery-1.7.2.min.js"><\/script>')</script>
263
264  <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script>
265  <?php
266        foreach($this->get_ressourceloader_links('js') as $js)
267                printf('  <script src="%s"></script>'.PHP_EOL, $js);
268  ?>
269</body>
270</html>
271<?php
272        } // function print_footer()
273       
274        // Hilfsfunktionen
275        private function relational_link_to_string($a) {
276                // wenn es bei einem relationalen Link einen Titel gibt, diesen ausgeben, ansonsten die
277                // Linkbeschreibung. Die Links sind XML-Elemente in der Navigation.
278                return isset($a['title']) ? $a['title'] : $a;
279        }
280
281        function get_ressourceloader_links($type) {
282                $rl = t29RessourceLoader::create_from_type($type, $this->conf);
283                return $rl->get_urls( isset($_GET['rl_debug']) );
284        }
285
286} // 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