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 | |
---|
13 | class t29Template { |
---|
14 | public $conf, $menu, $msg; |
---|
15 | public $body_classes = array(); |
---|
16 | public $javascript_config = array(); |
---|
17 | public $page_relations, $interlang_links; |
---|
18 | public $log; // lightweight logging system |
---|
19 | |
---|
20 | function __construct($conf_array) { |
---|
21 | $this->conf = $conf_array; |
---|
22 | |
---|
23 | // fetch the lightweight logging object: |
---|
24 | require_once $this->conf['lib'].'/logging.php'; |
---|
25 | $this->log = t29Log::get(); |
---|
26 | |
---|
27 | // create a menu: |
---|
28 | require_once $this->conf['lib'].'/menu.php'; |
---|
29 | $this->menu = new t29Menu($this->conf); |
---|
30 | |
---|
31 | // create localisation class: |
---|
32 | require_once $this->conf['lib'].'/messages.php'; |
---|
33 | $this->msg = new t29Messages($this->conf['lang']); |
---|
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); |
---|
40 | |
---|
41 | // fill up configuration |
---|
42 | |
---|
43 | // optional html headers which can be filled by hooks or parts |
---|
44 | if(!isset($this->conf['header_prepend'])) |
---|
45 | $this->conf['header_prepend'] = array(); // list |
---|
46 | |
---|
47 | // as t29Host for configuration fillup fillup |
---|
48 | $this->conf['host']->fillup_template_conf($this->conf); |
---|
49 | |
---|
50 | // Path names in messages |
---|
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)); |
---|
53 | |
---|
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 | |
---|
59 | // setup body classes: |
---|
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 | } |
---|
75 | |
---|
76 | // setup javascript configuration |
---|
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]; |
---|
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(); |
---|
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) |
---|
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'] . ' - '; |
---|
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" |
---|
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'); |
---|
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 | **/ |
---|
111 | function create_cache($cache_object) { |
---|
112 | $cache_object->start_cache(array($this, 'print_footer')); |
---|
113 | $this->print_header(); |
---|
114 | } |
---|
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 | } |
---|
133 | |
---|
134 | function print_header() { |
---|
135 | $p = $this->msg->get_shorthand_printer(); |
---|
136 | $_ = $this->msg->get_shorthand_returner(); |
---|
137 | ?> |
---|
138 | <!doctype html> |
---|
139 | <html class="no-js" lang="<?php echo $this->conf['lang']; ?>"> |
---|
140 | <head> |
---|
141 | <meta charset="utf-8"> |
---|
142 | <title><?php echo $this->conf['html_title']; ?></title> |
---|
143 | <meta name="description" content="Produziert am 08.01.2012"> |
---|
144 | <meta name="author" content="technikum29-Team"> |
---|
145 | <meta name="generator" content="t29v6/<?php print $this->conf['host']->hostname; ?>"> |
---|
146 | <meta name="t29.cachedate" content="<?php print date('r'); ?>"> |
---|
147 | <?php |
---|
148 | foreach($this->conf['header_prepend'] as $h) print $h."\n "; |
---|
149 | |
---|
150 | if(isset($this->conf['version'])) printf('<meta name="t29.version" content="%s">', $this->conf['version']); |
---|
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'); |
---|
154 | ?> |
---|
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' />", |
---|
161 | $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a)) |
---|
162 | ); |
---|
163 | } |
---|
164 | ?> |
---|
165 | |
---|
166 | <link rel="copyright" href="<?php $p('footer-legal-file'); ?>" title="<?php $p('footer-legal-link'); ?>"> |
---|
167 | <link rel="search" type="application/opensearchdescription+xml" href="<?php $p('topnav-search-page'); print '?action=opensearch-desc&lang='.$this->conf['lang']; ?>" title="<?php $p('opensearch-desc'); ?>"> |
---|
168 | <?php |
---|
169 | // print interlanguage links for all languages except the active one |
---|
170 | foreach($this->interlang_links as $lang => $a) { |
---|
171 | if($lang != $this->conf['lang'] && !is_null($a)) { |
---|
172 | printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">', |
---|
173 | $a['href'], $lang, sprintf($_('head-rel-interlang', $lang), $a) |
---|
174 | ); |
---|
175 | } |
---|
176 | } |
---|
177 | ?> |
---|
178 | |
---|
179 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
---|
180 | <?php |
---|
181 | $this->print_ressourceloader_links('css', PHP_EOL . ' <link rel="stylesheet" href="%s">'); |
---|
182 | ?> |
---|
183 | |
---|
184 | <script src="/shared/js-v6/libs/modernizr-2.0.6.min.js"></script> |
---|
185 | </head> |
---|
186 | |
---|
187 | <body class="<?php echo implode(' ', $this->body_classes) ?>"> |
---|
188 | <div id="container"> |
---|
189 | <h1 role="banner"><a href="/" title="<?php $p('head-h1-title'); ?>"><?php $p('head-h1'); ?></a></h1> |
---|
190 | <div id="background-color-container"><!-- helper --> |
---|
191 | <section class="main content" role="main" id="content"> |
---|
192 | <?php |
---|
193 | if(!$this->log->is_empty()) { |
---|
194 | print '<div class="errorpane">'; |
---|
195 | $this->log->print_all(); |
---|
196 | print '</div>'; |
---|
197 | } |
---|
198 | ?> |
---|
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>--> |
---|
203 | <!-- start content --> |
---|
204 | <?php |
---|
205 | } // function print_header(). |
---|
206 | |
---|
207 | function print_footer() { |
---|
208 | $p = $this->msg->get_shorthand_printer(); |
---|
209 | $_ = $this->msg->get_shorthand_returner(); |
---|
210 | ?> |
---|
211 | <!-- end content --> |
---|
212 | </section> |
---|
213 | <hr> |
---|
214 | <section class="sidebar top"> |
---|
215 | <h2 class="visuallyhidden"><?php $p("sidebar-h2-tour"); ?></h2> |
---|
216 | <nav class="side"> |
---|
217 | <?php $this->menu->print_menu(t29Menu::sidebar_menu); ?> |
---|
218 | </nav> |
---|
219 | <!-- menu changing buttons are made with javascript --> |
---|
220 | </section> |
---|
221 | <section class="sidebar bottom"> |
---|
222 | <!-- inhalte die unten ueber dem header sind --> |
---|
223 | </section> |
---|
224 | </div><!-- div id="background-color-container" helper end --> |
---|
225 | <hr> |
---|
226 | <header class="banner"> |
---|
227 | <h2 class="visuallyhidden"><?php $p("sidebar-h2-mainnav"); ?></h2> |
---|
228 | <nav class="horizontal"> |
---|
229 | <?php $this->menu->print_menu(t29Menu::horizontal_menu); ?> |
---|
230 | </nav> |
---|
231 | <nav class="top"> |
---|
232 | <h3 class="visuallyhidden"><?php $p("sidebar-h2-lang"); ?></h3> |
---|
233 | <ul> |
---|
234 | <?php |
---|
235 | foreach($this->interlang_links as $lang => $a) { |
---|
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 | } |
---|
250 | printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n", |
---|
251 | (empty($class) ? '' : " class='$class'"), |
---|
252 | $a['href'], htmlspecialchars($title), |
---|
253 | $this->conf['languages'][$lang][0] // verbose language name |
---|
254 | ); |
---|
255 | } |
---|
256 | ?> |
---|
257 | </ul> |
---|
258 | <form method="get" action="<?php $p('topnav-search-page'); ?>"> |
---|
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"> |
---|
262 | </form> |
---|
263 | </nav> |
---|
264 | </header> |
---|
265 | <hr> |
---|
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"; ?>"> |
---|
271 | <nav class="guide"> |
---|
272 | <!-- hier wird nav.side die Liste per JS reinkopiert --> |
---|
273 | </nav> |
---|
274 | <nav class="rel clearfix"> |
---|
275 | <ul> |
---|
276 | <?php |
---|
277 | if($print_footer_menu) |
---|
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", |
---|
280 | $rel, $a['href'], sprintf($_('head-rel-'.$rel), $this->relational_link_to_string($a)), |
---|
281 | $_('nav-rel-'.$rel), $this->relational_link_to_string($a) |
---|
282 | ); |
---|
283 | } |
---|
284 | ?> |
---|
285 | </ul> |
---|
286 | </nav> |
---|
287 | <div class="right"> |
---|
288 | <!-- text der rechts unten steht --> |
---|
289 | </div> |
---|
290 | </footer> |
---|
291 | </div> <!--! end of #container --> |
---|
292 | <footer class="attached"> |
---|
293 | <div class="legacy"><?php $p('footer-legacy-text'); ?></div> |
---|
294 | <!-- |
---|
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> |
---|
308 | --> |
---|
309 | </footer> |
---|
310 | </div><!-- end of div id="footer-background-container" helper --> |
---|
311 | |
---|
312 | <? /* JavaScript at the bottom for fast page loading */ ?> |
---|
313 | <script src="/shared/js-v6/libs/jquery-1.7.2.min.js"></script> |
---|
314 | <script>window.t29={'conf': <?php print json_encode($this->javascript_config); ?>};</script> |
---|
315 | <?php |
---|
316 | $this->print_ressourceloader_links('js', ' <script src="%s"></script>'.PHP_EOL); |
---|
317 | ?> |
---|
318 | <? /* Piwik Noscript, Script selbst wird asynchron im JS-Bereich aufgerufen */ ?> |
---|
319 | <noscript><img src="<? $p("js-piwik-noscript-imgsrc"); ?>" alt="" /></noscript> |
---|
320 | </body> |
---|
321 | </html> |
---|
322 | <?php |
---|
323 | } // function print_footer() |
---|
324 | |
---|
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 | } |
---|
331 | |
---|
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); |
---|
340 | } |
---|
341 | |
---|
342 | |
---|
343 | } // class t29Template |
---|