language.inc.php (5286B)
1 <?php 2 // OpenRat Content Management System 3 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 20 /** 21 * Diese Funktion stellt ein Wort in der eingestellten 22 * Sprache zur Verfuegung. 23 * 24 * @var String Name der Sprachvariablen 25 * @var Array Liste (Assoziatives Array) von Variablen 26 * 27 * @package openrat.functions 28 */ 29 function lang( $textVar,$vars = array() ) 30 { 31 global $conf; 32 $lang = $conf['language']; 33 34 $text = strtoupper($textVar); 35 36 // Abfrage, ob Textvariable vorhanden ist 37 if ( !isset( $lang[$text] ) && substr($text,0,9)=='GLOBAL_' ) 38 $text = substr($text,7); 39 40 // Abfrage, ob Textvariable vorhanden ist 41 if ( !isset( $lang[$text] )) 42 $text = 'GLOBAL_'.$text; 43 44 // Abfrage, ob Textvariable vorhanden ist 45 if ( isset( $lang[$text] ) ) 46 { 47 $text = $lang[$text]; 48 49 // Fuellen der Variablen im Text 50 foreach( $vars as $var=>$value ) 51 $text = str_replace('{'.$var.'}',$value,$text); 52 53 str_replace("''",'"',$text); 54 55 return $text; 56 } 57 58 // Wenn Textvariable nicht vorhanden ist, dann als letzten Ausweg nur den Variablennamen zurueckgeben 59 Logger::warn('Message-Key not found: '.$textVar); 60 return( '?'.$textVar.'?' ); 61 } 62 63 64 65 66 /** 67 * Diese Funktion stellt ein Wort in der eingestellten 68 * Sprache zur Verfuegung. Sonderzeichen werden als HTML maskiert. 69 * 70 * @var String Name der Sprachvariablen 71 * @var Array Liste (Assoziatives Array) von Variablen 72 * 73 * @package openrat.functions 74 * @param $key 75 * @return unknown_type 76 */ 77 function langHtml( $key,$vars = array() ) { 78 79 return encodeHtml( lang($key,$vars) ); 80 } 81 82 /** 83 * Ersetzt alle Zeichen mit dem Ordinalwert > 127 mit einer HTML-Maskierung. 84 * 85 * @return String 86 */ 87 function encodeHtml($text) 88 { 89 return translateutf8tohtml($text); 90 } 91 92 93 94 95 // Source: http://de.php.net/manual/de/function.htmlentities.php#96648 96 // Thx to silverbeat! 97 // When using UTF-8 as a charset, htmlentities will only convert 1-byte and 2-byte characters. 98 // Use this function if you also want to convert 3-byte and 4-byte characters: 99 // converts a UTF8-string into HTML entities 100 function translateutf8tohtml($txt) { 101 //$txt = html_entity_decode($txt); 102 $txt2 = ''; 103 for ($i=0;$i<strlen($txt);$i++) { 104 $o = ord($txt{$i}); 105 if ($o<128) { 106 // 0..127: raw 107 $txt2 .= $txt{$i}; 108 } else { 109 $o1 = 0; 110 $o2 = 0; 111 $o3 = 0; 112 if ($i<strlen($txt)-1) $o1 = ord($txt{$i+1}); 113 if ($i<strlen($txt)-2) $o2 = ord($txt{$i+2}); 114 if ($i<strlen($txt)-3) $o3 = ord($txt{$i+3}); 115 $hexval = 0; 116 if ($o>=0xc0 && $o<0xc2) { 117 // INVALID --- should never occur: 2-byte UTF-8 although value < 128 118 $hexval = $o1; 119 $i++; 120 } elseif ($o>=0xc2 && $o<0xe0 && $o1>=0x80) { 121 // 194..223: 2-byte UTF-8 122 $hexval |= ($o & 0x1f) << 6; // 1. byte: five bits of 1. char 123 $hexval |= ($o1 & 0x3f); // 2. byte: six bits of 2. char 124 $i++; 125 } elseif ($o>=0xe0 && $o<0xf0 && $o1>=0x80 && $o2>=0x80) { 126 // 224..239: 3-byte UTF-8 127 $hexval |= ($o & 0x0f) << 12; // 1. byte: four bits of 1. char 128 $hexval |= ($o1 & 0x3f) << 6; // 2.+3. byte: six bits of 2.+3. char 129 $hexval |= ($o2 & 0x3f); 130 $i += 2; 131 } elseif ($o>=0xf0 && $o<0xf4 && $o1>=0x80) { 132 // 240..244: 4-byte UTF-8 133 $hexval |= ($o & 0x07) << 18; // 1. byte: three bits of 1. char 134 $hexval |= ($o1 & 0x3f) << 12; // 2.-4. byte: six bits of 2.-4. char 135 $hexval |= ($o2 & 0x3f) << 6; 136 $hexval |= ($o3 & 0x3f); 137 $i += 3; 138 } else { 139 // don't know ... just encode 140 $hexval = $o; 141 } 142 $hexstring = dechex($hexval); 143 if (strlen($hexstring)%2) $hexstring = '0' . $hexstring; 144 $txt2 .= '&#x' . $hexstring . ';'; 145 } 146 } 147 $result = $txt2; 148 149 return $result; 150 } 151 152 153 154 155 156 157 158 /** 159 * Diese Funktion prueft, ob ein Sprachelement vorhanden ist 160 * 161 * @var String Name der Sprachvariablen 162 * 163 * @package openrat.functions 164 */ 165 function hasLang( $text ) 166 { 167 $text = strtoupper($text); 168 169 global $conf; 170 $lang = $conf['language']; 171 172 return isset( $lang[$text] ); 173 } 174 175 176 ?>