瀏覽代碼

Feature #272 - Various improvements and unification about dealing with the system encoding, the text direction, the interface language.

Ivan Tcholakov 15 年之前
父節點
當前提交
126bc0b053

+ 7 - 8
main/calendar/calendar.php

@@ -36,12 +36,11 @@ $DaysShort = api_get_week_days_short();
 $DaysLong = api_get_week_days_long();
 // Defining the months of the year to allow translation of the months
 $MonthsLong = api_get_months_long();
-@ $iso_lang = api_get_language_isocode($language_interface);
-if (empty ($iso_lang) )
-{
-	//if there was no valid iso-code, use the english one
-	$iso_lang = 'en';
-}
+
+$iso_lang = api_get_language_isocode($language_interface);
+
+header('Content-Type: text/html; charset='. api_get_system_encoding());
+
 ?>
 <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@@ -49,7 +48,7 @@ if (empty ($iso_lang) )
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $iso_lang; ?>" lang="<?php echo $iso_lang; ?>">
 <head>
 <title>Calendar</title>
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>">
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>">
 <style type="text/css">
 /*<![CDATA[*/
 @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/<?php echo api_get_setting('stylesheets'); ?>/default.css";
@@ -139,7 +138,7 @@ foreach($DaysShort as $index => $day)
 /* ]]> */
 </script>
 </head>
-<body onLoad="javascript: initCalendar();">
+<body dir="<?php echo api_get_text_direction(); ?>" onLoad="javascript: initCalendar();">
 <div id="calendar_data"></div>
 <div id="clock_data"></div>
 </body>

+ 4 - 9
main/exercice/exercise_result.php

@@ -271,14 +271,9 @@ if ($origin != 'learnpath') {
 	Display::display_header($nameTools,"Exercise");
 } else {
 
-	header('Content-Type: text/html; charset='. $charset);
+	header('Content-Type: text/html; charset='.api_get_system_encoding());
 
-	@$document_language = api_get_language_isocode($language_interface);
-	if(empty($document_language))
-	{
-	  //if there was no valid iso-code, use the english one
-	  $document_language = 'en';
-	}
+	$document_language = api_get_language_isocode();
 
 	/*
 	 * HTML HEADER
@@ -291,10 +286,10 @@ if ($origin != 'learnpath') {
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language; ?>" lang="<?php echo $document_language; ?>">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
+<link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css'; ?>" />
 </head>
 
-<body>
-<link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css'; ?>" />
+<body dir="<?php echo api_get_text_direction(); ?>">
 <?php
 }
 

+ 4 - 0
main/inc/global.inc.php

@@ -495,6 +495,10 @@ if (is_array($language_files)) {
 // So, we have to reassign this variable again in order to keep its value right.
 $charset = $charset_initial_value;
 
+// The global variable $text_dir has been defined in the language file trad4all.inc.php.
+// For determing text direction correspondent to the current language we use now information from the internationalization library.
+$text_dir = api_get_text_direction();
+
 //Update of the logout_date field in the table track_e_login (needed for the calculation of the total connection time)
 
 if ($_configuration['tracking_enabled'] && !isset($_SESSION['login_as']) && isset($_user)) {

+ 7 - 24
main/inc/header.inc.php

@@ -17,22 +17,11 @@
  * HTTP HEADER
  */
 
-//Give a default value to $charset. Should change to UTF-8 some time in the future.
-//This parameter should be set in the platform configuration interface in time.
-$charset = api_get_setting('platform_charset');
-if(empty($charset))
-{
-	$charset = 'ISO-8859-15';
-}
-
-//header('Content-Type: text/html; charset='. $charset)
-//	or die ("WARNING : it remains some characters before &lt;?php bracket or after ?&gt end");
-
-header('Content-Type: text/html; charset='. $charset);
+header('Content-Type: text/html; charset='.api_get_system_encoding());
 
 $navigator_info = api_get_navigator();
 //ie6 fix
-if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {	
+if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {
 	$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix_tilebg.js" type="text/javascript" language="javascript"></script>'; //jQuery
 }
 
@@ -45,12 +34,7 @@ if ( isset($httpHeadXtra) && $httpHeadXtra )
 }
 
 // Get language iso-code for this page - ignore errors
-@$document_language = api_get_language_isocode($language_interface);
-if(empty($document_language))
-{
-  //if there was no valid iso-code, use the english one
-  $document_language = 'en';
-}
+$document_language = api_get_language_isocode();
 
 /*
  * HTML HEADER
@@ -80,7 +64,6 @@ echo api_get_setting('siteName');
 /*<![CDATA[*/
 <?php
 
- 
 $platform_theme= api_get_setting('stylesheets'); 	// plataform's css
 $my_style=$platform_theme;
 
@@ -144,10 +127,10 @@ if(empty($my_style)) {
 echo '@import "'.$my_code_path.'css/'.$my_style.'/default.css";'."\n";
 echo '@import "'.$my_code_path.'css/'.$my_style.'/course.css";'."\n";
 
-if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {	
+if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=='6') {
 	echo 'img, div { behavior: url('.api_get_path(WEB_LIBRARY_PATH).'javascript/iepngfix/iepngfix.htc) } ';
 }
-  
+
 ?>
 /*]]>*/
 </style>
@@ -167,7 +150,7 @@ if ($navigator_info['name']=='Internet Explorer' &&  $navigator_info['version']=
 <link href="http://www.chamilo.org/team.php" rel="Author" />
 <link href="http://www.chamilo.org" rel="Copyright" />
 <link rel="shortcut icon" href="<?php echo api_get_path(WEB_PATH); ?>favicon.ico" type="image/x-icon" />
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset ?>" />
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>" />
 
 <script type="text/javascript">
 //<![CDATA[
@@ -216,7 +199,7 @@ include(api_get_path(LIBRARY_PATH).'/javascript/email_links.lib.js.php');
 ?>
 
 </head>
-<body dir="<?php echo  $text_dir ?>" <?php
+<body dir="<?php echo api_get_text_direction(); ?>" <?php
  if(defined('DOKEOS_HOMEPAGE') && DOKEOS_HOMEPAGE)
  echo 'onload="javascript:if(document.formLogin) { document.formLogin.login.focus(); }"'; ?>>
 <div class="skip">

+ 9 - 15
main/inc/lib/fckeditor/editor/plugins/ImageManager/config.inc.php

@@ -16,7 +16,7 @@
        PHP must be able to create files in this directory.
 	   Able to create directories is nice, but not necessary.
 */
-#$IMConfig['base_dir'] = '/var/www/FCKeditor/images/';
+//$IMConfig['base_dir'] = '/var/www/FCKeditor/images/';
 
 /*
  The URL to the above path, the web browser needs to be able to see it.
@@ -27,7 +27,7 @@
  in this directory and its subdirectories.
 */
 $language_file = array('document');
-include ('../../../../../../inc/global.inc.php');
+include '../../../../../../inc/global.inc.php';
 
 // Initialization of the repositories.
 require_once api_get_path(LIBRARY_PATH).'fckeditor/repository.php';
@@ -207,13 +207,13 @@ $IMConfig['allow_overwrite'] = false;
 */
 /*
 $IMConfig['watermarks'] = array	(
-													"imageManager.png",
-													"imageManager.jpg",
-													"devshed.png",
-													"natureWatermark.png"
-												);
+	"imageManager.png",
+	"imageManager.jpg",
+	"devshed.png",
+	"natureWatermark.png"
+);
 */
-$IMConfig['watermarks'] = array	();
+$IMConfig['watermarks'] = array();
 
 /*
 	To limit the width and height for uploaded files, specify the maximum pixeldimensions.
@@ -268,10 +268,4 @@ $IMConfig['tmp_prefix'] = '.editor_';
  Language and text direction.
  */
 $IMConfig['language'] = api_get_language_isocode();
-if (empty($IMConfig['language']))
-{
-	$IMConfig['language'] = 'en';
-}
-$IMConfig['text_direction'] = in_array($IMConfig['language'], array('ar', 'prs', 'he', 'ps', 'fa')) ? 'rtl' : 'ltr';
-
-?>
+$IMConfig['text_direction'] = api_get_text_direction($IMConfig['language']);

+ 7 - 8
main/inc/lib/formvalidator/Element/calendar_popup.php

@@ -36,12 +36,11 @@ $DaysShort = api_get_week_days_short();
 $DaysLong = api_get_week_days_long();
 // Defining the months of the year to allow translation of the months
 $MonthsLong = api_get_months_long();
-@ $iso_lang = api_get_language_isocode($language_interface);
-if (empty ($iso_lang) )
-{
-	//if there was no valid iso-code, use the english one
-	$iso_lang = 'en';
-}
+
+$iso_lang = api_get_language_isocode($language_interface);
+
+header('Content-Type: text/html; charset='. api_get_system_encoding());
+
 ?>
 <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
@@ -49,7 +48,7 @@ if (empty ($iso_lang) )
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $iso_lang; ?>" lang="<?php echo $iso_lang; ?>">
 <head>
 <title>Calendar</title>
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>">
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>">
 <style type="text/css">
 /*<![CDATA[*/
 @import "<?php echo api_get_path(WEB_CODE_PATH); ?>css/<?php echo api_get_setting('stylesheets'); ?>/default.css";
@@ -159,7 +158,7 @@ foreach($DaysShort as $index => $day)
 /* ]]> */
 </script>
 </head>
-<body onLoad="javascript: initCalendar();">
+<body dir="<?php echo api_get_text_direction(); ?>" onLoad="javascript: initCalendar();">
 <div id="calendar_data"></div>
 <div id="clock_data"></div>
 </body>

+ 5 - 11
main/inc/lib/formvalidator/Element/datepicker.php

@@ -32,7 +32,6 @@ class HTML_QuickForm_datepicker extends HTML_QuickForm_date
 	 */
 	function HTML_QuickForm_datepicker($elementName = null, $elementLabel = null, $attributes = null)
 	{
-		global $language_interface;
 		$js_form_name = $attributes['form_name'];
 		unset($attributes['form_name']);
 		HTML_QuickForm_element :: HTML_QuickForm_element($elementName, $elementLabel, $attributes);
@@ -47,21 +46,16 @@ class HTML_QuickForm_datepicker extends HTML_QuickForm_date
 			$popup_link = str_replace($char, "\\".$char, $popup_link);
 			$hour_minute_devider = str_replace($char, "\\".$char, $hour_minute_devider);
 		}
-		@ $editor_lang = api_get_language_isocode($language_interface);
-		if (empty ($editor_lang) )
+		$lang_code = api_get_language_isocode();
+		// If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation
+		if(! array_key_exists($lang_code,$this->_locale))
 		{
-			//if there was no valid iso-code, use the english one
-			$editor_lang = 'en';
-		}
-		// If translation not available in PEAR::HTML_QuickForm_date, add the Dokeos-translation
-		if(! array_key_exists($editor_lang,$this->_locale))
-		{
-			$this->_locale[$editor_lang]['months_long'] = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
+			$this->_locale[$lang_code]['months_long'] = api_get_months_long();
 		}
 		$this->_options['format'] = 'dFY '.$popup_link.'   H '.$hour_minute_devider.' i';
 		$this->_options['minYear'] = date('Y')-7;
 		$this->_options['maxYear'] = date('Y')+15;
-		$this->_options['language'] = $editor_lang;
+		$this->_options['language'] = $lang_code;
 		//$this->_options['addEmptyOption'] = true;
 		//$this->_options['emptyOptionValue'] = 0;
 		//$this->_options['emptyOptionText'] = ' -- ';

+ 6 - 11
main/inc/lib/formvalidator/Element/datepickerdate.php

@@ -31,7 +31,7 @@ class HTML_QuickForm_datepickerdate extends HTML_QuickForm_date
 	 */
 	function HTML_QuickForm_datepickerdate($elementName = null, $elementLabel = null, $attributes = null)
 	{
-		global $language_interface, $myMinYear, $myMaxYear;
+		global $myMinYear, $myMaxYear;
 		$js_form_name = $attributes['form_name'];
 		unset($attributes['form_name']);
 		HTML_QuickForm_element :: HTML_QuickForm_element($elementName, $elementLabel, $attributes);
@@ -44,21 +44,16 @@ class HTML_QuickForm_datepickerdate extends HTML_QuickForm_date
 		{
 			$popup_link = str_replace($char, "\\".$char, $popup_link);
 		}
-		@ $editor_lang = api_get_language_isocode($language_interface);
-		if (empty ($editor_lang) )
+		$lang_code = api_get_language_isocode();
+		// If translation not available in PEAR::HTML_QuickForm_date, add the Chamilo-translation
+		if(! array_key_exists($lang_code,$this->_locale))
 		{
-			//if there was no valid iso-code, use the english one
-			$editor_lang = 'en';
-		}
-		// If translation not available in PEAR::HTML_QuickForm_date, add the Dokeos-translation
-		if(! array_key_exists($editor_lang,$this->_locale))
-		{
-			$this->_locale[$editor_lang]['months_long'] = array (get_lang("JanuaryLong"), get_lang("FebruaryLong"), get_lang("MarchLong"), get_lang("AprilLong"), get_lang("MayLong"), get_lang("JuneLong"), get_lang("JulyLong"), get_lang("AugustLong"), get_lang("SeptemberLong"), get_lang("OctoberLong"), get_lang("NovemberLong"), get_lang("DecemberLong"));
+			$this->_locale[$lang_code]['months_long'] = api_get_months_long();
 		}
 		$this->_options['format'] = 'dFY '.$popup_link;
 		$this->_options['minYear'] = date('Y')-1;
 		$this->_options['maxYear'] = date('Y')+15;
-		$this->_options['language'] = $editor_lang;
+		$this->_options['language'] = $lang_code;
 		//$this->_options['addEmptyOption'] = true;
 		//$this->_options['emptyOptionValue'] = 0;
 		//$this->_options['emptyOptionText'] = ' -- ';

+ 3 - 3
main/inc/lib/formvalidator/Element/tbl_change.js.php

@@ -1,6 +1,6 @@
 <?php
 // $Id: tbl_change.js.php 18078 2009-01-29 17:21:11Z cfasanando $
-require ('../../../global.inc.php');
+require '../../../global.inc.php';
 ?>
 var day;
 var month;
@@ -28,7 +28,7 @@ function openCalendar(form, field) {
 			datevalues[dateindex++] = forminputs[i].value;
 		}
 	}
-    window.open("<?php echo api_get_path(WEB_CODE_PATH); ?>inc/lib/formvalidator/Element/calendar_popup.php", "calendar", "width=220,height=200,status=no");
+    window.open("<?php echo api_get_path(WEB_LIBRARY_PATH); ?>formvalidator/Element/calendar_popup.php", "calendar", "width=260,height=230,status=no");
 	day = datevalues[0];
 	month = datevalues[1];
 	year = datevalues[2];
@@ -180,7 +180,7 @@ function returnDate(d,m,y) {
 	date = new Date();
 	year = 1900;
 	datevalues[2].selectedIndex = (y-year);
-		 
+
 	for(i = 0; i<= 3; i++)
 	{
 		attributes = datevalues[i].attributes;

+ 5 - 19
main/inc/reduced_header.inc.php

@@ -17,17 +17,8 @@
  * HTTP HEADER
  */
 
-//Give a default value to $charset. Should change to UTF-8 some time in the future.
-//This parameter should be set in the platform configuration interface in time.
-if(empty($charset))
-{
-	$charset = 'ISO-8859-15';
-}
-
-//header('Content-Type: text/html; charset='. $charset)
-//	or die ("WARNING : it remains some characters before &lt;?php bracket or after ?&gt end");
+header('Content-Type: text/html; charset='.api_get_system_encoding());
 
-header('Content-Type: text/html; charset='. $charset);
 if ( isset($httpHeadXtra) && $httpHeadXtra )
 {
 	foreach($httpHeadXtra as $thisHttpHead)
@@ -37,12 +28,7 @@ if ( isset($httpHeadXtra) && $httpHeadXtra )
 }
 
 // Get language iso-code for this page - ignore errors
-@$document_language = api_get_language_isocode($language_interface);
-if(empty($document_language))
-{
-  //if there was no valid iso-code, use the english one
-  $document_language = 'en';
-}
+$document_language = api_get_language_isocode();
 
 /*
  * HTML HEADER
@@ -73,8 +59,8 @@ echo api_get_setting('siteName');
  */
 
 $platform_theme = api_get_setting('stylesheets'); 	// plataform's css
-$my_style=$platform_theme;
-if(api_get_setting('user_selected_theme') == 'true')
+$my_style = $platform_theme;
+if (api_get_setting('user_selected_theme') == 'true')
 {
 	$useri = api_get_user_info();
 	$user_theme = $useri['theme'];
@@ -172,7 +158,7 @@ if($my_style!='')
 <link href="http://www.chamilo.org/team.php" rel="Author" />
 <link href="http://www.chamilo.org" rel="Copyright" />
 <link rel="shortcut icon" href="<?php echo api_get_path(WEB_PATH); ?>favicon.ico" type="image/x-icon" />
-<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset ?>" />
+<meta http-equiv="Content-Type" content="text/html; charset=<?php echo api_get_system_encoding(); ?>" />
 
 <script type="text/javascript">
 //<![CDATA[

+ 6 - 10
main/wiki/export_html2pdf.php

@@ -27,13 +27,13 @@
 */
 
 
-include("../inc/global.inc.php");
+include '../inc/global.inc.php';
 api_block_anonymous_users();
 
-require('../inc/lib/html2pdf/html2pdf.class.php');
+require '../inc/lib/html2pdf/html2pdf.class.php';
 
-$contentPDF=stripslashes(api_html_entity_decode($_POST['contentPDF'], ENT_QUOTES, $charset));
-$titlePDF=stripslashes(api_html_entity_decode($_POST['titlePDF'], ENT_QUOTES, $charset));
+$contentPDF = stripslashes(api_html_entity_decode($_POST['contentPDF'], ENT_QUOTES, api_get_system_encoding()));
+$titlePDF = stripslashes(api_html_entity_decode($_POST['titlePDF'], ENT_QUOTES, api_get_system_encoding()));
 
 ob_start();//activate Output -Buffer
 ///////////////////////
@@ -50,18 +50,14 @@ ob_start();//activate Output -Buffer
  <?php
 /////////////////////
 echo $contentPDF;
-$htmlbuffer=ob_get_contents();// Store Output-Buffer in one variable
+$htmlbuffer = ob_get_contents();// Store Output-Buffer in one variable
 ob_end_clean();// delete Output-Buffer
 
 /////bridge to  dokeos lang
-	@ $langhtml2pdf = api_get_language_isocode($language_interface);
+	$langhtml2pdf = api_get_language_isocode();
 
 	// Some code translations are needed.
 	$langhtml2pdf = strtolower(str_replace('_', '-', $langhtml2pdf));
-	if (empty ($langhtml2pdf))
-	{
-		$langhtml2pdf = 'en';
-	}
 	switch ($langhtml2pdf)
 	{
 		case 'uk':

+ 2 - 2
main/wiki/wiki.inc.php

@@ -1721,7 +1721,7 @@ function export2doc($wikiTitle, $wikiContents, $groupId)
 /*]]>*/
 </style>
 </head>
-<body>
+<body dir="{TEXT_DIRECTION}">
 {CONTENT}
 </body>
 </html>';
@@ -1741,7 +1741,7 @@ function export2doc($wikiTitle, $wikiContents, $groupId)
 	$css = str_replace('images/', $root_rel.$css_path.$theme.'images/', $css);
 	$css = str_replace('../../img/', $root_rel.'main/img/', $css);
 
-	$template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TITLE}', '{CSS}'), array(api_get_language_isocode(), api_get_system_encoding(), $wikiTitle, $css), $template);
+	$template = str_replace(array('{LANGUAGE}', '{ENCODING}', '{TEXT_DIRECTION}', '{TITLE}', '{CSS}'), array(api_get_language_isocode(), api_get_system_encoding(), api_get_text_direction(), $wikiTitle, $css), $template);
 
 	if (0 != $groupId)
 	{

+ 12 - 1
tests/main/inc/lib/internationalization.lib.test.php

@@ -1163,7 +1163,7 @@ class TestInternationalization extends UnitTestCase {
 
 	function test_api_get_language_isocode() {
 		$test_language_table = array(
-			'*** invalid entry ***' => null, // An invalid entry.
+			'*** invalid entry ***' => 'en', // An invalid entry.
 			'arabic' => 'ar',
 			'arabic_unicode' => 'ar',
 			'asturian' => 'ast',
@@ -1250,6 +1250,17 @@ class TestInternationalization extends UnitTestCase {
 		//foreach ($res as $language => $test_case) { echo ($test_case['is_ok'] ? '<span style="color: green; font-weight: bold;">Ok</span>' : '<span style="color: red; font-weight: bold;">Failed</span>').' '.$language.' => '.(is_null($test_case['test_result']) ? 'NULL' : $test_case['test_result']).'<br />'; }
 	}
 
+	public function test_api_get_text_direction() {
+		$languages = array('english', 'en', 'arabic', 'ar');
+		$expected_results = array('ltr', 'ltr', 'rtl', 'rtl');
+		$res = array();
+		foreach ($languages as $language) {
+			$res[] = api_get_text_direction($language);
+		}
+		$this->assertTrue($res === $expected_results);
+		//var_dump($res);
+	}
+
 	public function test_api_is_latin1_compatible() {
 		$language = 'portuguese';
 		$res = api_is_latin1_compatible($language);