- Timestamp:
- May 28, 2012, 6:07:42 PM (11 years ago)
- Location:
- lib
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/menu.php
r255 r259 1 1 <?php 2 2 /** 3 * Needs conf: 4 * webroot lang_path lang seiten_id languages 5 * 6 **/ 3 7 class t29Menu { 4 8 public $conf; 9 public $xml; 5 10 6 const horizontal_menu = 'hauptnavigation.xml';7 const sidebar_menu = 'sidebar.xml';11 // jeweils relativ zum lang_path 12 const navigation_file = 'navigation.xml'; 8 13 const news_file = 'news.php'; 14 15 // xpath queries to the navigation elements 16 const horizontal_menu = '/html/nav[@class="horizontal"]'; 17 const sidebar_menu = '/html/nav[@class="side"]'; 9 18 10 19 function __construct($conf_array) { 11 20 $this->conf = $conf_array; 21 22 // load xml file 23 $this->xml = simplexml_load_file($this->conf['webroot'].$this->conf['lang_path'] . '/' . self::navigation_file); 12 24 } 13 25 26 ///////////////////// NEWS EXTRACTION 14 27 function load_news_data() { 15 28 $newsfile = $this->conf['webroot'].$this->conf['lang_path']."/".self::news_file; … … 43 56 return $news_ul_content; 44 57 } 58 59 ///////////////////// RETURN INFOS ABOUT SEITEN_ID LINK 60 function get_link_infos($seiten_id=false) { 61 if(!$seiten_id) $seiten_id = $this->conf['seiten_id']; 62 63 $matches = $this->xml->xpath("//a[@seiten_id='$seiten_id']"); 64 if($matches && count($matches)) { 65 // strip the first one 66 return $matches[0]; 67 } 68 } 69 70 ///////////////////// INTER LANGUAGE DETECTION 71 /** 72 * @param seiten_id Get interlanguage link for that seiten_id or default. 73 **/ 74 function get_interlanguage_link($seiten_id=false) { 75 if(!$seiten_id) $seiten_id = $this->conf['seiten_id']; 76 77 $interlinks = array(); // using a loop instead of mappings since php is stupid 78 foreach($this->conf['languages'] as $lang => $lconf) { 79 $foreign_menu = new t29Menu(array( 80 'webroot' => $this->conf['webroot'], 81 'seiten_id' => $this->conf['seiten_id'], 82 'languages' => $this->conf['languages'], 83 'lang' => $lang, 84 'lang_path' => $lconf[1], 85 )); 86 87 $link = $foreign_menu->get_link_infos($seiten_id); 88 $interlinks[$lang] = $link; 89 } 90 91 return $interlinks; 92 } 45 93 46 94 // helper method 47 95 public static function dom_add_class($simplexml_element, $value) { 48 $dom = dom_import_simplexml($simplexml_element); 96 $dom = dom_import_simplexml($simplexml_element); // is a fast operation 49 97 $simplexml_element['class'] = 50 98 ($dom->hasAttribute("class") ? ($simplexml_element['class'].' '):'').$value; 51 99 } 100 101 public static function dom_new_link($href, $label) { 102 return new SimpleXMLElement(sprintf('<a href="%s">%s</a>', $href, $label)); 103 } 52 104 53 function print_menu($file) { 105 ///////////////////// MENU ACTIVE LINK DETECTION 106 /** 107 * @arg $xpath_menu_selection one of the horizontal_menu / sidebar_menu consts. 108 **/ 109 function print_menu($xpath_menu_selection) { 54 110 $seiten_id = $this->conf['seiten_id']; 55 $xml = simplexml_load_file($this->conf['webroot'].$this->conf['lang_path'] . '/' . $file); 56 111 112 // find wanted menu 113 $xml = $this->xml->xpath($xpath_menu_selection); 114 if(!$xml) { 115 print "Menu <i>$xpath_menu_selection</i> not found!"; 116 return false; 117 } 118 $xml = $xml[0]; // just take the first result (should only one result be present) 119 57 120 // aktuelle Seite anmarkern und Hierarchie hochgehen 58 121 // (<ul><li>bla<ul><li>bla<ul><li>hierbin ich <- hochgehen.) … … 74 137 } 75 138 76 if($ file== self::horizontal_menu) {139 if($xpath_menu_selection == self::horizontal_menu) { 77 140 # inject news 78 141 $news_ul_content = $this->convert_news_data(); … … 85 148 } 86 149 87 function print_relations() { 88 $seiten_id = $this->conf['seiten_id']; 89 90 $sidebar = simplexml_load_file($this->conf['webroot'] . $this->conf['lang_path'] . '/' . self::sidebar_menu); 150 ///////////////////// PAGE RELATIONS 151 /** 152 * Usage: 153 * foreach(get_page_relations() as $a) { 154 * echo "Link $a going to $a[href]"; 155 * } 156 * @param $seiten_id A seiten_id string or nothing for taking the current active string 157 * @returns an array(prev=>..., next=>...) or empty array, elements are SimpleXML a links 158 **/ 159 function get_page_relations($seiten_id=false) { 160 if(!$seiten_id) $seiten_id = $this->conf['seiten_id']; 161 162 $xml = $this->xml->xpath(self::sidebar_menu); 163 if(!$xml) { print "<i>Sidebar not found</i>"; return; } 164 $sidebar = $xml[0]; 165 166 $return = array(); 91 167 $current_a = $sidebar->xpath("//a[@seiten_id='$seiten_id']"); 92 168 if(count($current_a)) { 93 $prev = $current_a[0]->xpath("preceding::a[@seiten_id][1]"); 94 if(count($prev)) { 95 $a = $prev[0]; 96 print "<li class='prev'><a href='$a[href]'>vorherige Seite <strong>$a</strong></a></li>"; 97 } 98 $next = $current_a[0]->xpath("following::a[@seiten_id][1]"); 99 if(count($next)) { 100 $a = $next[0]; 101 print "<li class='next'><a href='$a[href]'>nächste Seite <strong>$a</strong></a></li>"; 169 foreach(array( 170 "prev" => "preceding::a[@seiten_id][1]", 171 "next" => "following::a[@seiten_id][1]") as $rel => $xpath) { 172 $node = $current_a[0]->xpath($xpath); 173 if(count($node)) 174 $return[$rel] = $node[0]; # $node[0] = <a href=../> tag 102 175 } 103 176 } else { 104 print '<li class="start"><a href="#">Starte Führung <strong>Blabla</strong></a>'; 177 // TODO PENDING: Der Fall tritt derzeit niemals ein, da das XML 178 // sich dann doch irgendwie auf alles bezieht ($sidebar = alles) und 179 // ueberall gesucht wird. Ist aber okay. oder? 180 $return['start'] = t29Menu::dom_new_link('#', 'bla'); 105 181 } 182 return $return; 106 183 } 107 184 -
lib/messages.php
r255 r259 62 62 'sidebar-h2-mainnav' => array('Hauptnavigation', 'Main Navigation'), 63 63 'sidebar-h2-lang' => array('Sprachauswahl', 'Language'), 64 'sidebar-search-label' => array('Suchen', 'Search'), 64 65 'topnav-interlang-title' => array('Read this page (%s) in English', 'Diese Seite (%s) auf Deutsch lesen'), 66 'topnav-search-label' => array('Suchen', 'Search'), 65 67 66 68 'js-menu-collapse-out' => array('Menü ausklappen', 'Expand menu'), … … 71 73 'footer-copyright-tag' => '© 2003-2012 technikum29.', 72 74 'footer-legal-link' => array('Impressum und Kontakt', 'Legal notices'), 75 'footer-legal-file' => array('/impressum.php', '/contact.php'), 76 77 'nav-rel-prev' => array('vorherige Seite', 'previous page'), 78 'nav-rel-next' => array('nächste Seite', 'next page'), 79 'nav-rel-start' => array('Starte Führrung', 'Start guided tour'), 80 81 'head-rel-first' => array('Deutscher Start', 'English start'), 82 'head-rel-prev' => array('Zur vorherigen Seite (%s)', 'Previous Page (%s)'), 83 'head-rel-next' => array('Zur folgenden Seite (%s)', 'Next Page (%s)'), 84 'head-rel-interlang' => array('Englische Version dieser Seite (%s)', 'Deutsche Version dieser Seite (%s)'), 73 85 ); 74 86 } -
lib/technikum29.php
r255 r259 21 21 ); 22 22 23 $lang = "de"; # must be index in $languages 23 // try to determine the language from the file path 24 $lang = substr($file, 1, 2); 25 if(!in_array($lang, array_keys($languages))) $lang = "de"; # check if language exists 24 26 $lang_path = $languages[$lang][1]; # shorthand, relative to webroot. use "$webroot$lang_path" for local. 25 27 … … 35 37 "$lib/menu.php", 36 38 "$lib/messages.php", 37 "$lib/../de-v6/hauptnavigation.xml", 38 "$lib/../de-v6/sidebar.xml", 39 "$lib/../de-v6/news.php", 39 "$lib$lang_path/navigation.xml", 40 "$lib$lang_path/news.php", 40 41 ); 41 42 -
lib/template.php
r255 r259 12 12 13 13 class t29Template { 14 private static $legal_pagenames = array( // should be const15 # lang => file relative to $lang_path, with starting "/".16 "de" => "/impressum.php",17 "en" => "/contact.php",18 );19 20 14 public $conf, $menu, $msg; 21 15 public $body_classes = array(); 22 16 public $javascript_config = array(); 17 public $page_relations, $interlang_links; 23 18 24 19 function __construct($conf_array) { 25 20 $this->conf = $conf_array; 26 27 // fill up configuration28 $this->conf['legal_pagename'] = $this->conf['lang_path'] . self::$legal_pagenames[$this->conf['lang']];29 21 30 22 // create a menu: … … 35 27 require_once $this->conf['lib'].'/messages.php'; 36 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'); 37 32 38 33 // setup body classes: … … 43 38 $this->javascript_config['lang'] = $this->conf['lang']; 44 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(); 45 44 } 46 45 … … 79 78 80 79 function print_header() { 81 $_ = $this->msg->get_shorthand_printer(); 80 $p = $this->msg->get_shorthand_printer(); 81 $_ = $this->msg->get_shorthand_returner(); 82 82 ?> 83 83 <!doctype html> … … 85 85 <head> 86 86 <meta charset="utf-8"> 87 <title><?php isset($this->conf['titel']) ? $this->conf['titel'].' - ' : ''; $ _('html-title'); ?></title>87 <title><?php isset($this->conf['titel']) ? $this->conf['titel'].' - ' : ''; $p('html-title'); ?></title> 88 88 <meta name="description" content="Produziert am 08.01.2012"> 89 89 <meta name="author" content="Sven"> 90 90 <meta name="generator" content="t29v6 $Id$"> 91 91 <meta name="t29.cachedate" content="<?php print date('r'); ?>"> 92 93 <?php 94 foreach(array_merge(array("first" => t29Menu::dom_new_link($this->conf['lang_path'], $_('head-rel-first'))), 95 $this->page_relations) as $rel => $a) { 96 if($rel == 'start') continue; // not in standard 97 printf("\n <link rel='%s' href='%s' title='%s' />", 98 $rel, $a['href'], sprintf($_('head-rel-'.$rel), $a) 99 ); 100 } 101 ?> 102 103 <link rel="copyright" href="<?php echo $this->conf['legal_pagename']; ?>" title="<?php $p('footer-legal-link'); ?>"> 104 <?php 105 // print interlanguage links for all languages except the active one 106 foreach($this->interlang_links as $lang => $a) { 107 if($lang != $this->conf['lang']) { 108 printf('<link rel="alternate" href="%s" hreflang="%s" title="%s">', 109 $a['href'], $lang, sprintf($_('head-rel-interlang'), $a) 110 ); 111 } 112 } 113 ?> 114 92 115 <meta name="viewport" content="width=device-width,initial-scale=1"> 93 116 <link rel="stylesheet" href="/shared/css-v6/boiler.css"> … … 101 124 <div id="footer-background-container"><!-- helper --> 102 125 <div id="container"> 103 <h1 role="banner"><a href="/" title="<?php $ _('head-h1-title'); ?>"><?php $_('head-h1'); ?></a></h1>126 <h1 role="banner"><a href="/" title="<?php $p('head-h1-title'); ?>"><?php $p('head-h1'); ?></a></h1> 104 127 <div id="background-color-container"><!-- helper --> 105 128 <section class="main content" role="main" id="content"> … … 112 135 } // function print_header(). 113 136 114 function print_footer() {115 $p = $this->msg->get_shorthand_printer();116 $_ = $this->msg->get_shorthand_returner();117 ?>137 function print_footer() { 138 $p = $this->msg->get_shorthand_printer(); 139 $_ = $this->msg->get_shorthand_returner(); 140 ?> 118 141 <!-- end content --> 119 142 </section> … … 137 160 <ul> 138 161 <?php 139 foreach($this-> conf['languages'] as $l => $sets) {162 foreach($this->interlang_links as $lang => $a) { 140 163 printf("\t\t\t\t<li%s><a href='%s' title='%s'>%s</a></li>\n", 141 ($l == $this->conf['lang'] ? ' class="active"' : ''), 142 $sets[1].'#', 143 "View in $sets[0]", 144 $sets[0] 164 ($lang == $this->conf['lang'] ? ' class="active"' : ''), 165 $a['href'], sprintf($_('topnav-interlang-title'), $a), 166 $this->conf['languages'][$lang][0] // verbose language name 145 167 ); 146 147 168 } 148 169 ?> … … 152 173 <input type="text" value="" data-defaultvalue="%s" name="q" class="text"> 153 174 <input type="submit" value="%s" class="button"> 154 ', $_(' sidebar-search-label'), $_('sidebar-search-label'), $_('sidebar-search-label')); ?>175 ', $_('topnav-search-label'), $_('topnav-search-label'), $_('topnav-search-label')); ?> 155 176 </form> 156 177 </nav> … … 163 184 <nav class="rel clearfix"> 164 185 <ul> 165 <?php $this->menu->print_relations(); ?> 166 <!-- 167 <li class="prev"><a href="#">vorherige Seite <strong>Univac 9200</strong></a> 168 <li class="next"><a href="#">nächste Seite <strong>Analog und Hybridrechner</strong></a> 169 --> 186 <?php 187 foreach($this->page_relations as $rel => $a) { 188 printf("\t<li class='%s'><a href='%s' title='%s'>%s <strong>%s</strong></a>\n", 189 $rel, $a['href'], 'TITLE', $_('nav-rel-'.$rel), $a 190 ); 191 } 192 ?> 170 193 </ul> 171 194 </nav>
Note: See TracChangeset
for help on using the changeset viewer.