From a72e2b146a5e6275319cb2e12ee716dd8600411a Mon Sep 17 00:00:00 2001 From: franzz Date: Fri, 11 Oct 2013 17:30:06 +0200 Subject: [PATCH] UTF-8 encoding conversion todo list --- config.php | 15 +++++++++++++++ index.php | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/config.php b/config.php index e77908b..505cb35 100755 --- a/config.php +++ b/config.php @@ -4495,6 +4495,21 @@ class ToolBox return $asResult; } + + public static function utf8_compliant($sText) + { + if(strlen($sText) == 0) return true; + return (preg_match('/^.{1}/us', $sText, $ar) == 1); + } + + /** + * Only works with ISO-8859-1 and UTF-8 encoding + */ + public static function strlen($sText) + { + if(utf8_compliant($sText)) return strlen(utf8_decode($sText)); + else return strlen($sText); + } } /* Debug */ diff --git a/index.php b/index.php index 27c5cfb..f5b91c4 100644 --- a/index.php +++ b/index.php @@ -168,6 +168,35 @@ if($bUserOk && $sAction!=Databap::EXT_ACCESS) $oMySqlInstall = new MySqlManager(); $sResult = $oMySqlInstall->getFullInstallQuery(); break; + case 'fix_encoding': + /** + * Procedure (from ISO-8859-1, aka Latin-1) + * - Rss.php : switch ISO <-> UTF : $sFeed = ''; + * - .htaccess : ajout UTF-8 par défaut : AddDefaultCharset UTF-8 (+check syntax) + * - config.php : Ajouter dans le constructor de Databap : + * - ini_set('default_charset', 'UTF-8'); + * - header('Content-Type: text/html; charset=utf-8'); + * - config.php : changer tous les ISO en UTF : + * - --> + * - config.php : Enlever la conversion en UTF8 de jsonExport() + * - config.php : Ajouter $this->oConnection->set_charset('utf8'); dans le constructeur de MySqlManager + * - replace strlen with ToolBox::strlen() --> check the so called mb_* functions + * - Re-encode all tables from database using utf8_encode() + * - Replace all
with + * - Alter database and change database generation script in MySqlManager : + * - CREATE DATABASE `my_db` CHARACTER SET = utf8 COLLATE = utf8_general_ci; + * - CREATE TABLE `my_table` ([TABLE spec]) CHARACTER SET = utf8 COLLATE = utf8_general_ci; + * - Convert existing database : + * - mysqldump --default_character_set=latin1 -u root -p my_db > my_db.sql + * - iconv -f iso-8859-1 -t utf8 my_db.sql > my_db-utf8.sql + * - sed s/latin1/utf8/ < my_db-utf8.sql > my_db-utf8-final.sql + * - CREATE DATABASE `my_db` CHARACTER SET = utf8 COLLATE = utf8_general_ci; + * - mysql -u root -p my_db < my_db-utf8-final.sql + * - Switch your editor to UTF-8 (search 'encoding' in Eclipse preferences) + * - check http://webcollab.sourceforge.net/unicode.html + * - add mb_* function : sudo apt-get install php-mbstring --> check http://allseeing-i.com/How-to-setup-your-PHP-site-to-use-UTF8 + */ + break; } } } @@ -188,13 +217,13 @@ elseif($bUserOk && $sAction==Databap::EXT_ACCESS) break; } - //Restricted actions - if($oDatabap->getUserClearance()==Databap::CLEARANCE_ADMIN) - { - switch($sPage) + //Restricted actions + if($oDatabap->getUserClearance()==Databap::CLEARANCE_ADMIN) + { + switch($sPage) { case 'sap_blog': //Syncing SAP BW Blog with database & spreading the news on chat - $sResult = $oDatabap->syncSapBlog(); + $sResult = $oDatabap->syncSapBlog(); break; } }