[ Index ] |
PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12) |
[Summary view] [Print] [Text view]
1 <?php 2 /************************************************************************************* 3 Copyright notice 4 5 (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved. 6 7 This script is part of PHPWCMS. The PHPWCMS web content management system is 8 free software; you can redistribute it and/or modify it under the terms of 9 the GNU General Public License as published by the Free Software Foundation; 10 either version 2 of the License, or (at your option) any later version. 11 12 The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html 13 A copy is found in the textfile GPL.txt and important notices to the license 14 from the author is found in LICENSE.txt distributed with these scripts. 15 16 This script is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 18 PARTICULAR PURPOSE. See the GNU General Public License for more details. 19 20 This copyright notice MUST APPEAR in all copies of the script! 21 *************************************************************************************/ 22 23 // ---------------------------------------------------------------- 24 // obligate check for phpwcms constants 25 if (!defined('PHPWCMS_INCLUDE_CHECK')) { 26 die("You Cannot Access This Script Directly, Have a Nice Day."); 27 } 28 // ---------------------------------------------------------------- 29 30 /** 31 * Render @@Text@@ based on browser language and store in related language file 32 * which allows easy translation at later time and when needed. The Text between 33 * @@Default@@ will be taken as default text if no translation exists. 34 * 35 * Based on work and ideas of 36 * Dr.-Ing. Tobias Schittkowski (http://www.schittkowski.de/index.php?q=node/20) 37 * André Rabold (http://smarty.incutio.com/?page=SmartyMultilanguageSupport) 38 **/ 39 40 // language which is selected by user (defined in the browser settings) 41 function i18n_get_language($complex=false) { 42 global $phpwcms; 43 if(!empty($phpwcms['i18_lang'])) { 44 return $phpwcms['i18_lang']; 45 } elseif(empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { 46 $phpwcms['i18_lang'] = $phpwcms['default_lang']; 47 return $phpwcms['i18_lang']; 48 } 49 $complex = isset($phpwcms['i18n_complex']) ? $phpwcms['i18n_complex'] : $complex; 50 if($complex) { 51 $lang = explode(';', trim($_SERVER['HTTP_ACCEPT_LANGUAGE']), 2); 52 $lang = explode(',', $lang[0], 2); 53 $phpwcms['i18_lang'] = preg_replace('/[^a-z0-9\-_\.]/', '', strtolower(trim($lang[0]))); 54 } else { 55 $phpwcms['i18_lang'] = strtolower(substr( trim($_SERVER['HTTP_ACCEPT_LANGUAGE']) , 0, 2)); 56 } 57 if(empty($phpwcms['i18_lang'])) { 58 $phpwcms['i18_lang'] = $phpwcms['default_lang']; 59 } 60 return $phpwcms['i18_lang']; 61 } 62 // get the template file name 63 function i18n_get_filename() { 64 return PHPWCMS_TEMPLATE . 'template_lang/' . i18n_get_language(true) . '.php'; 65 } 66 function i18n_get_file_open_text() { 67 $text = '<?php ' . LF; 68 $text .= '// phpwcms template language file "' . i18n_get_language(true) . '" (' . now('Y-m-d H:i:s') . ')' . LF; 69 $text .= '// ATTENTION! Never add the closing PHP tag "? >" at the end of this file!' . LF . LF; 70 return $text; 71 } 72 // substitutes a single token 73 function i18n_substitute_text_token($token) { 74 global $i18n_tokens; 75 $a = trim($token[1]); 76 if(isset($i18n_tokens[$a])) { 77 return $i18n_tokens[$a]; 78 } else { 79 $f = i18n_get_filename(); 80 if(is_readable($f)) { 81 include($f); 82 } elseif($handle = fopen($f, 'ab')) { 83 fwrite($handle, i18n_get_file_open_text() ); 84 fclose($handle); 85 } else { 86 return $a; 87 } 88 if(isset($i18n_tokens[$a])) { 89 return $i18n_tokens[$a]; 90 } 91 $i18n_tokens[$a] = $a; 92 $as = str_replace("'", "\\'", $a); 93 $s = '$i18n_tokens' . "['" . $as . "']" . " = '" . $as . "'; // NEW " . now('Y-m-d H:i:s') . LF; 94 if($handle = fopen($f, 'ab')) { 95 fwrite($handle, $s); 96 fclose($handle); 97 } 98 } 99 return $a; 100 } 101 // all contents starting and ending with @@ are replaced 102 function i18n_substitute_text($tpl_output) { 103 global $i18n_tokens; 104 $f = i18n_get_filename(); 105 if(!isset($i18n_tokens)) { 106 if(is_readable($f)) { 107 include($f); 108 } elseif($handle = fopen($f, 'ab')) { 109 fwrite($handle, i18n_get_file_open_text() ); 110 fclose($handle); 111 } 112 } 113 return preg_replace_callback('/@@(.+?)@@/', 'i18n_substitute_text_token', $tpl_output); 114 } 115 /////////////////////////////////////////////////////////////////////////////////////////////// 116 117 118 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Jan 29 16:31:14 2012 | Cross-referenced by PHPXref 0.7.1 |