Change to support different page code in HTML output

This commit is contained in:
Laurent Destailleur
2008-10-09 17:29:32 +00:00
parent 427310a77d
commit 248a7d7ee2
9 changed files with 169 additions and 137 deletions

View File

@@ -40,7 +40,7 @@ class Conf
//! Objet des caracteristiques de connexions
var $db;
//! Charset for HTML output
var $character_set_client;
var $character_set_client; // ISO-8859-1, UTF8
var $externalrss;
var $commande;

View File

@@ -104,7 +104,7 @@ $dolibarr_main_db_type="";
# dolibarr_main_db_character_set
# Database character set used to store data.
# Database character set used to store data (forced during database creation).
# Default value: depends on database driver
# Examples:
# dolibarr_main_db_character_set="latin1";
@@ -113,7 +113,7 @@ $dolibarr_main_db_character_set="latin1";
# dolibarr_main_db_collation
# Database character set used to sort data.
# Database character set used to sort data (forced during database creation).
# Default value: depends on database driver
# Examples:
# dolibarr_main_db_collation="latin1_swedish_ci";
@@ -124,7 +124,7 @@ $dolibarr_main_db_collation="latin1_swedish_ci";
# character_set_client
# Page code for HTML outputs.
# Default value: ISO-8859-1
# Possible values: ISO-8859-1
# Possible values: ISO-8859-1, UTF-8
#
$character_set_client="ISO-8859-1";

View File

@@ -128,11 +128,11 @@ class box_external_rss extends ModeleBoxes {
//$item['atom_content']
}
if (is_numeric($date)) $date=dolibarr_print_date($date,"dayhour");
$result = $this->utf8_check($title);
if ($result)
{
$title=utf8_decode($title);
}
$isutf8 = utf8_check($title);
if (! $isutf8 && $conf->character_set_client == 'UTF-8') $title=utf8_encode($title);
elseif ($isutf8 && $conf->character_set_client == 'ISO-8859-1') $title=utf8_decode($title);
$title=ereg_replace("([[:alnum:]])\?([[:alnum:]])","\\1'\\2",$title); // G<>re probl<62>me des apostrophes mal cod<6F>e/d<>cod<6F>e par utf8
$title=ereg_replace("^\s+","",$title); // Supprime espaces de d<>but
$this->info_box_contents["$href"]="$title";
@@ -148,26 +148,6 @@ class box_external_rss extends ModeleBoxes {
}
}
/**
* \brief V<>rifie si le flux est en UTF8
* \param $Str chaine <20> v<>rifier
*/
function utf8_check($Str) {
for ($i=0; $i<strlen($Str); $i++) {
if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
else return false; # Does not match any model
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
return false;
}
}
return true;
}
function showBox()
{

View File

@@ -61,7 +61,7 @@ else
$includeconferror='';
$conffile = "../conf/conf.php";
$charset="ISO-8859-1";
$charset="UTF-8"; // If not output format found in any conf file
if (! defined('DONOTLOADCONF') && file_exists($conffile))
{
$result=include_once($conffile); // Load conf file
@@ -204,7 +204,7 @@ function conf($dolibarr_main_document_root)
$conf->db->pass = trim($dolibarr_main_db_pass);
if (empty($character_set_client)) $character_set_client=$charset;
$conf->character_set_client=$character_set_client;
$conf->character_set_client=strtoupper($character_set_client);
if (empty($dolibarr_main_db_charset)) $dolibarr_main_db_charset='latin1';
$conf->db->character_set=$dolibarr_main_db_charset;
if (empty($dolibarr_main_db_collation)) $dolibarr_main_db_collation='latin1_swedish_ci';

View File

@@ -40,9 +40,9 @@ class DoliDb
var $db;
//! Nom du gestionnaire
var $type='mssql';
//! Charset
//! Charset used to force charset when creating database
var $forcecharset='latin1';
//! Collate
//! Collate used to force collate when creating database
var $forcecollate='latin1_swedish_ci';
//! Version min database
var $versionmin=array(2000);

View File

@@ -22,7 +22,7 @@
/**
* \file htdocs/lib/databases/mysql.lib.php
* \brief Fichier de la classe permettant de g<>rer une base mysql
* \brief Class file to manage Dolibarr database access for a Mysql database
* \version $Id$
*/
// For compatibility during upgrade
@@ -32,17 +32,17 @@ if (! defined('ADODB_DATE_VERSION')) include_once(DOL_DOCUMENT_ROOT."/includes/a
/**
* \class DoliDb
* \brief Classe de gestion de la database de dolibarr
* \brief Class to manage Dolibarr database access for a Mysql database
*/
class DoliDb
{
//! Handler de base
//! Database handler
var $db;
//! Nom du gestionnaire
//! Database type
var $type='mysql';
//! Charset
//! Charset used to force charset when creating database
var $forcecharset='latin1';
//! Collate
//! Collate used to force collate when creating database
var $forcecollate='latin1_swedish_ci';
//! Version min database
var $versionmin=array(3,1,0);
@@ -129,7 +129,7 @@ class DoliDb
dolibarr_syslog("DoliDB::DoliDB : Erreur Connect mysql_error=".$this->error,LOG_ERR);
}
// Si connexion serveur ok et si connexion base demand<EFBFBD>e, on essaie connexion base
// Si connexion serveur ok et si connexion base demandee, on essaie connexion base
if ($this->connected && $name)
{
if ($this->select_db($name))
@@ -138,13 +138,15 @@ class DoliDb
$this->database_name = $name;
$this->ok = 1;
// If client connected with different charset than Dolibarr database
// (La base Dolibarr was forced to this->forcecharset during install)
/*if (mysql_client_encoding ( $this->db ) != $this->getDefaultCharacterSetDatabase())
// If client connected with different charset than Dolibarr HTML output
$clientmustbe='';
if (eregi('UTF-8',$conf->character_set_client)) $clientmustbe='utf8';
if (eregi('ISO-8859-1',$conf->character_set_client)) $clientmustbe='latin1';
if (mysql_client_encoding($this->db) != $clientmustbe)
{
$this->query("SET NAMES '".$this->forcecharset."'", $this->db);
$this->query("SET CHARACTER SET ". $this->forcecharset);
}*/
$this->query("SET NAMES '".$clientmustbe."'", $this->db);
//$this->query("SET CHARACTER SET ". $this->forcecharset);
}
}
else
{
@@ -159,6 +161,19 @@ class DoliDb
{
// Pas de selection de base demandee, ok ou ko
$this->database_selected = 0;
if ($this->connected)
{
// If client connected with different charset than Dolibarr HTML output
$clientmustbe='';
if (eregi('UTF-8',$conf->character_set_client)) $clientmustbe='utf8';
if (eregi('ISO-8859-1',$conf->character_set_client)) $clientmustbe='latin1';
if (mysql_client_encoding($this->db) != $clientmustbe)
{
$this->query("SET NAMES '".$clientmustbe."'", $this->db);
//$this->query("SET CHARACTER SET ". $this->forcecharset);
}
}
}
return $this->ok;
@@ -186,7 +201,7 @@ class DoliDb
}
/**
* \brief Connection vers le serveur
* \brief Connexion to server
* \param host database server host
* \param login login
* \param passwd password
@@ -205,17 +220,7 @@ class DoliDb
if ($port) $newhost.=':'.$port;
$this->db = @mysql_connect($newhost, $login, $passwd);
// Force recors to latin1 if database is in utf8 by default
// Removed becasue faile on my PHP-Mysql.
// De plus, la base est forcement en latin1 avec
// les nouvelles version de Dolibarr car force par l'install Dolibarr.
//$this->query('SET NAMES '.$this->forcecharset);
//print "Resultat fonction connect: ".$this->db;
if ($this->db)
{
$this->query("SET NAMES '".$this->forcecharset."'", $this->db);
$this->query("SET CHARACTER SET '".$this->forcecharset."'", $this->db);
}
//print "Resultat fonction connect: ".$this->db;
return $this->db;
}
@@ -672,21 +677,23 @@ class DoliDb
/**
\brief Cr<EFBFBD>ation d'une nouvelle base de donn<6E>e
\param database nom de la database <20> cr<63>er
\return resource resource d<EFBFBD>finie si ok, null si k
\remarks Ne pas utiliser les fonctions xxx_create_db (xxx=mysql, ...) car elles sont deprecated
On force creation de la base avec le charset forcecharset
* \brief Create a new database
* \param database Database name to create
* \return resource resource defined if OK, null if KO
* \remarks Do not use function xxx_create_db (xxx=mysql, ...) as they are deprecated
* We force to create database with charset this->forcecharset and collate this->forcecollate
*/
function DDLCreateDb($database)
{
// ALTER DATABASE dolibarr_db DEFAULT CHARACTER SET latin DEFAULT COLLATE latin1_swedish_ci
$sql = 'CREATE DATABASE '.$database;
$sql.= ' DEFAULT CHARACTER SET '.$this->forcecharset.' DEFAULT COLLATE '.$this->forcecollate;
dolibarr_syslog($sql,LOG_DEBUG);
$ret=$this->query($sql);
if (! $ret)
{
// On r<>essaie pour compatibilit<EFBFBD> avec Mysql < 4.1.1
// We try again for compatibility with Mysql < 4.1.1
$sql = 'CREATE DATABASE '.$database;
$ret=$this->query($sql);
}
@@ -900,6 +907,10 @@ class DoliDb
return $liste['Value'];
}
/**
* \brief Return list of available charset that can be used to store data in database
* \return array List of Charset
*/
function getListOfCharacterSet()
{
$resql=$this->query('SHOW CHARSET');
@@ -937,7 +948,12 @@ class DoliDb
return $liste['Value'];
}
function getListOfCollation(){
/**
* \brief Return list of available collation that can be used for database
* \return array Liste of Collation
*/
function getListOfCollation()
{
$resql=$this->query('SHOW COLLATION');
$liste = array();
if ($resql)

View File

@@ -3026,4 +3026,30 @@ function array2tr($data,$troptions='',$tdoptions=''){
$text.= '</tr>' ;
return $text ;
}
/**
* \brief Check if a string is in UTF8
* \param $Str String to check
* \return boolean True if string is UTF8, false if not
*/
function utf8_check($Str)
{
for ($i=0; $i<strlen($Str); $i++)
{
if (ord($Str[$i]) < 0x80) continue; # 0bbbbbbb
elseif ((ord($Str[$i]) & 0xE0) == 0xC0) $n=1; # 110bbbbb
elseif ((ord($Str[$i]) & 0xF0) == 0xE0) $n=2; # 1110bbbb
elseif ((ord($Str[$i]) & 0xF8) == 0xF0) $n=3; # 11110bbb
elseif ((ord($Str[$i]) & 0xFC) == 0xF8) $n=4; # 111110bb
elseif ((ord($Str[$i]) & 0xFE) == 0xFC) $n=5; # 1111110b
else return false; # Does not match any model
for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ?
if ((++$i == strlen($Str)) || ((ord($Str[$i]) & 0xC0) != 0x80))
return false;
}
}
return true;
}
?>

View File

@@ -139,9 +139,10 @@ $conf->db->dolibarr_main_db_collation=$dolibarr_main_db_collation;
$conf->main_authentication = $dolibarr_main_authentication;
// Force https
$conf->main_force_https = $dolibarr_main_force_https;
// Identifiant propre au client
if (empty($character_set_client)) $character_set_client='ISO-8859-1';
$conf->character_set_client=$character_set_client;
// Define charset for HTML Output
$charset='ISO-8859-1'; // If not output format found in any conf file
if (empty($character_set_client)) $character_set_client=$charset;
$conf->character_set_client=strtoupper($character_set_client);
// Defini prefix
if (isset($_SERVER["LLX_DBNAME"])) $dolibarr_main_db_prefix=$_SERVER["LLX_DBNAME"];

View File

@@ -20,7 +20,7 @@
/**
* \file htdocs/translate.class.php
* \brief File for tanslation class
* \brief File for Tanslate class
* \author Eric Seigne
* \author Laurent Destailleur
* \version $Id$
@@ -43,8 +43,8 @@ class Translate {
var $cache_labels=array(); // Cache for labels
var $charset_inputfile='ISO-8859-1'; // Codage du contenu du fichier langue
var $charset_output='UTF-8'; // Codage par defaut de la sortie de la methode trans
var $charset_inputfile='ISO-8859-1'; // Codage used to encode lang files (used if CHARSET not found in file)
var $charset_output='UTF-8'; // Codage used by defaut for "trans" method output if $conf->character_set_client not defined (character_set_client in conf.php)
/**
@@ -54,13 +54,12 @@ class Translate {
*/
function Translate($dir = "",$conf)
{
// Si charset output defini
if (isset($conf->character_set_client) && $conf->character_set_client)
// If charset output is forced
if (! empty($conf->character_set_client))
{
$this->charset_output=$conf->character_set_client;
}
$this->dir=(! $dir ? DOL_DOCUMENT_ROOT ."/langs" : $dir);
// For developpement purpose
$this->dir_bis=(defined('DOL_DOCUMENT_ROOT_BIS') ? DOL_DOCUMENT_ROOT_BIS ."/langs" : "");
}
@@ -484,17 +483,23 @@ class Translate {
/**
* \brief Renvoi le fichier $filename dans la version de la langue courante, sinon alternative
* \param filename nom du fichier <EFBFBD> rechercher
* \param filename nom du fichier a rechercher
* \param searchalt cherche aussi dans langue alternative
* \return boolean
*/
function print_file($filename,$searchalt=0)
{
global $conf;
// Test si fichier dans repertoire de la langue
$htmlfile=$this->dir."/".$this->defaultlang."/".$filename;
if (is_readable($htmlfile))
{
include $htmlfile;
$content=file_get_contents($htmlfile);
$isutf8=utf8_check($content);
if (! $isutf8 && $conf->character_set_client == 'UTF-8') print utf8_encode($content);
elseif ($isutf8 && $conf->character_set_client == 'ISO-8859-1') print utf8_decode($content);
else print $content;
return true;
}
@@ -504,7 +509,11 @@ class Translate {
else $htmlfilealt = $this->dir."/fr_FR/".$filename;
if (is_readable($htmlfilealt))
{
include $htmlfilealt;
$content=file_get_contents($htmlfile);
$isutf8=utf8_check($content);
if (! $isutf8 && $conf->character_set_client == 'UTF-8') print utf8_encode($content);
elseif ($isutf8 && $conf->character_set_client == 'ISO-8859-1') print utf8_decode($content);
else print $content;
return true;
}
}