Changeset 2127


Ignore:
Timestamp:
Oct 9, 2007, 3:43:29 AM (17 years ago)
Author:
rvelices
Message:
  • PWG_CHARSET, DB_CHARSET and DB_COLLATE... utf-8 ready
Location:
trunk
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r2095 r2127  
    19901990  trigger_action('invalidate_user_cache');
    19911991}
     1992
     1993/**
     1994 * adds the caracter set to a create table sql query.
     1995 * all CREATE TABLE queries must call this function
     1996 * @param string query - the sql query
     1997 */
     1998function create_table_add_character_set($query)
     1999{
     2000  defined('DB_CHARSET') or die('create_table_add_character_set DB_CHARSET undefined');
     2001  if ('DB_CHARSET'!='')
     2002  {
     2003    if ( version_compare(mysql_get_server_info(), '4.1.0', '<') )
     2004    {
     2005      return $query;
     2006    }
     2007    $charset_collate = " DEFAULT CHARACTER SET ".DB_CHARSET;
     2008    if ('DB_COLLATE'!='')
     2009    {
     2010      $charset_collate .= " COLLATE ".DB_COLLATE;
     2011    }
     2012    $query=trim($query);
     2013    $query=trim($query, ';');
     2014    if (preg_match('/^CREATE\s+TABLE/i',$query))
     2015    {
     2016      $query.=$charset_collate;
     2017    }
     2018    $query .= ';';
     2019  }
     2020  return $query;
     2021}
    19922022?>
  • trunk/include/common.inc.php

    r2126 r2127  
    145145or die ( "Could not connect to database" );
    146146
     147defined('PWG_CHARSET') and defined('DB_CHARSET')
     148  or die('PWG_CHARSET and/or DB_CHARSET is not defined');
     149if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
     150{
     151  if (DB_CHARSET!='')
     152  {
     153    pwg_query('SET NAMES "'.DB_CHARSET.'"');
     154  }
     155}
     156else
     157{
     158  if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
     159  {
     160    die('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
     161  }
     162}
     163
    147164//
    148165// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
  • trunk/include/constants.php

    r2104 r2127  
    2929define('PHPWG_DOMAIN', 'phpwebgallery.net');
    3030define('PHPWG_URL', 'http://www.'.PHPWG_DOMAIN);
    31 define('PHPWG_DEFAULT_LANGUAGE', 'en_UK.iso-8859-1');
     31define('PHPWG_DEFAULT_LANGUAGE', 'en_UK');
    3232define('PHPWG_DEFAULT_TEMPLATE', 'yoga/clear');
    3333
  • trunk/include/functions.inc.php

    r2126 r2127  
    477477 * @returns array
    478478 */
    479 function get_languages()
    480 {
     479function get_languages($target_charset = null)
     480{
     481  if ( empty($target_charset) )
     482  {
     483    $target_charset = get_pwg_charset();
     484  }
     485  $target_charset = strtolower($target_charset);
     486
    481487  $dir = opendir(PHPWG_ROOT_PATH.'language');
    482488  $languages = array();
     
    488494    {
    489495      list($language_name) = @file($path.'/iso.txt');
    490       $languages[$file] = $language_name;
     496
     497      $langdef = explode('.',$file);
     498      if (count($langdef)>1) // (langCode,encoding)
     499      {
     500        $langdef[1] = strtolower($langdef[1]);
     501
     502        if (
     503          $target_charset==$langdef[1]
     504         or
     505          ($target_charset=='utf-8' and $langdef[1]=='iso-8859-1')
     506         or
     507          ($target_charset=='iso-8859-1' and
     508          in_array( substr($langdef[0],2), array('en','fr','de','es','it','nl')))
     509        )
     510        {
     511          $language_name = convert_charset($language_name,
     512              $langdef[1], $target_charset);
     513          $languages[ $langdef[0] ] = $language_name;
     514        }
     515        else
     516          continue; // the language encoding is not compatible with our charset
     517      }
     518      else
     519      { // probably english that is the same in all ISO-xxx and UTF-8
     520        $languages[$file] = $language_name;
     521      }
    491522    }
    492523  }
     
    14301461function get_pwg_charset()
    14311462{
    1432   //TEMP CODE
    1433   global $lang_info;return $lang_info['charset'];
     1463  defined('PWG_CHARSET') or die('load_language PWG_CHARSET undefined');
     1464  return PWG_CHARSET;
    14341465}
    14351466
     
    14501481 */
    14511482function load_language($filename, $dirname = '', $language = '',
    1452     $return_content=false)
    1453 {
    1454   //TEMP CODE
    1455   if (!$return_content) $filename.='.php';
    1456   $f = get_language_filepath($filename, $dirname, $language);
    1457   if ($f === false)
    1458     return false;
    1459   if ($return_content)
    1460     return @file_get_contents($f);
    1461   global $lang, $lang_info;
    1462   @include($f);
    1463   return true;
    1464 }
    1465 
     1483    $return_content=false, $target_charset=null)
     1484{
     1485  global $user;
     1486
     1487  if (!$return_content)
     1488  {
     1489    $filename .= '.php'; //MAYBE to do .. load .po and .mo localization files
     1490  }
     1491  if (empty($dirname))
     1492  {
     1493    $dirname = PHPWG_ROOT_PATH;
     1494  }
     1495  $dirname .= 'language/';
     1496
     1497  $languages = array();
     1498  if ( !empty($language) )
     1499  {
     1500    $languages[] = $language;
     1501  }
     1502
     1503  if ( !empty($user['language']) )
     1504  {
     1505    $languages[] = $user['language'];
     1506  }
     1507  $languages[] = PHPWG_DEFAULT_LANGUAGE;
     1508  $languages = array_unique($languages);
     1509
     1510  if ( empty($target_charset) )
     1511  {
     1512    $target_charset = get_pwg_charset();
     1513  }
     1514  $target_charset = strtolower($target_charset);
     1515  $source_charset = '';
     1516  $source_file    = '';
     1517  foreach ($languages as $language)
     1518  {
     1519    $dir = $dirname.$language;
     1520
     1521    // exact charset match - no conversion required
     1522    $f = $dir.'.'.$target_charset.'/'.$filename;
     1523    if (file_exists($f))
     1524    {
     1525      $source_file = $f;
     1526      break;
     1527    }
     1528
     1529    // universal language (like Eng) no conversion required
     1530    $f = $dir.'/'.$filename;
     1531    if (file_exists($f))
     1532    {
     1533      $source_file = $f;
     1534      break;
     1535    }
     1536
     1537    if ($target_charset=='utf-8')
     1538    { // we accept conversion from ISO-8859-1 to UTF-8
     1539      $f = $dir.'.iso-8859-1/'.$filename;
     1540      if (file_exists($f))
     1541      {
     1542        $source_charset = 'iso-8859-1';
     1543        $source_file = $f;
     1544        break;
     1545      }
     1546    }
     1547
     1548    if ($target_charset=='iso-8859-1' and
     1549      in_array( substr($language,2), array('en','fr','de','es','it','nl') )
     1550      )
     1551    { // we accept conversion from UTF-8 to ISO-8859-1 for backward compatibility ONLY
     1552      $f = $dir.'.utf-8/'.$filename;
     1553      if (file_exists($f))
     1554      {
     1555        $source_charset = 'utf-8';
     1556        $source_file = $f;
     1557        break;
     1558      }
     1559    }
     1560  }
     1561
     1562  if ( !empty($source_file) )
     1563  {
     1564    if (!$return_content)
     1565    {
     1566      @include($source_file);
     1567      $load_lang = @$lang;
     1568      $load_lang_info = @$lang_info;
     1569
     1570      global $lang, $lang_info;
     1571      if ( !isset($lang) ) $lang=array();
     1572      if ( !isset($lang_info) ) $lang_info=array();
     1573
     1574      if ( !empty($source_charset) and $source_charset!=$target_charset)
     1575      {
     1576        if ( is_array($load_lang) )
     1577        {
     1578          foreach ($load_lang as $k => $v)
     1579          {
     1580            if ( is_array($v) )
     1581            {
     1582              $func = create_function('$v', 'return convert_charset($v, "'.$source_charset.'","'.$target_charset.'");' );
     1583              $lang[$k] = array_map($func, $v);
     1584            }
     1585            else
     1586              $lang[$k] = convert_charset($v, $source_charset, $target_charset);
     1587          }
     1588        }
     1589        if ( is_array($load_lang_info) )
     1590        {
     1591          foreach ($load_lang_info as $k => $v)
     1592          {
     1593            $lang_info[$k] = convert_charset($v, $source_charset, $target_charset);
     1594          }
     1595        }
     1596      }
     1597      else
     1598      {
     1599        $lang = array_merge( $lang, $load_lang );
     1600        $lang_info = array_merge( $lang_info, $load_lang_info );
     1601      }
     1602      return true;
     1603    }
     1604    else
     1605    {
     1606      $content = @file_get_contents($source_file);
     1607      if ( !empty($source_charset) and $source_charset!=$target_charset)
     1608      {
     1609        $content = convert_charset($content, $source_charset, $target_charset);
     1610      }
     1611      return $content;
     1612    }
     1613  }
     1614  return false;
     1615}
     1616
     1617/**
     1618 * converts a string from a character set to another character set
     1619 * @param string str the string to be converted
     1620 * @param string source_charset the character set in which the string is encoded
     1621 * @param string dest_charset the destination character set
     1622 */
     1623function convert_charset($str, $source_charset, $dest_charset)
     1624{
     1625  if ($source_charset==$dest_charset)
     1626    return $str;
     1627  if ($source_charset=='iso-8859-1' and $dest_charset=='utf-8')
     1628  {
     1629    return utf8_encode($str);
     1630  }
     1631  if ($source_charset=='utf-8' and $dest_charset=='iso-8859-1')
     1632  {
     1633    return utf8_decode($str);
     1634  }
     1635  if (function_exists('iconv'))
     1636  {
     1637    return iconv($source_charset, $dest_charset, $str);
     1638  }
     1639  if (function_exists('mb_convert_encoding'))
     1640  {
     1641    return mb_convert_encoding( $str, $dest_charset, $source_charset );
     1642  }
     1643  return $str; //???
     1644}
    14661645?>
  • trunk/include/functions_user.inc.php

    r2124 r2127  
    3333//   o check if address is not used by a other user
    3434// If the mail address doesn't correspond, an error message is returned.
    35 // 
     35//
    3636function validate_mail_address($user_id, $mail_address)
    3737{
     
    3939
    4040  if (empty($mail_address) and
    41       !($conf['obligatory_user_mail_address'] and 
     41      !($conf['obligatory_user_mail_address'] and
    4242      in_array(script_basename(), array('register', 'profile'))))
    4343  {
     
    5050    return l10n('reg_err_mail_address');
    5151  }
    52  
     52
    5353  if (defined("PHPWG_INSTALLED") and !empty($mail_address))
    5454  {
     
    157157
    158158  return $errors;
    159 }
    160 
    161 function setup_style($style)
    162 {
    163   return new Template(PHPWG_ROOT_PATH.'template/'.$style);
    164159}
    165160
  • trunk/install.php

    r2124 r2127  
    2828define('PHPWG_ROOT_PATH','./');
    2929
    30 // Guess an initial language ...
    31 function guess_lang()
    32 {
    33   return 'en_UK.iso-8859-1';
    34 }
    35 
    3630//
    3731// Pick a language, any language ...
     
    3933function language_select($default, $select_name = "language")
    4034{
    41   $available_lang = get_languages();
     35  $available_lang = get_languages('utf-8');
    4236
    4337  $lang_select = '<select name="' . $select_name . '" onchange="document.location = \''.PHPWG_ROOT_PATH.'install.php?language=\'+this.options[this.selectedIndex].value;">';
     
    8579      if (!preg_match('/^DROP TABLE/i', $query))
    8680      {
     81        global $install_charset_collate;
     82        if ( !empty($install_charset_collate) )
     83        {
     84          if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) )
     85          {
     86            $query = $matches[1].' '.$install_charset_collate.';';
     87          }
     88        }
    8789        mysql_query($query);
    8890      }
     
    211213create_empty_local_files();
    212214
    213 if ( isset( $_POST['language'] ))
    214 {
    215   $language = strip_tags($_POST['language']);
    216 }
    217 elseif ( isset( $_GET['language'] ))
    218 {
    219   $language = strip_tags($_GET['language']);
    220 }
    221 else
    222 {
    223   $language = guess_lang();
    224 }
    225 
    226 if (!file_exists(PHPWG_ROOT_PATH.'language/'.$language.'/install.lang.php'))
    227 {
    228   $language = 'en_UK.iso-8859-1';
    229 }
    230 
    231 include( './language/'.$language.'/common.lang.php' );
    232 // Never: @include( './language/'.$language.'/local.lang.php' );
    233 include( './language/'.$language.'/admin.lang.php' );
    234 include( './language/'.$language.'/install.lang.php' );
     215if ( isset( $_REQUEST['language'] ))
     216{
     217  $language = strip_tags($_REQUEST['language']);
     218}
     219else
     220{
     221  $language = 'en_UK';
     222}
     223
     224load_language( 'common.lang', '', $language, false, 'utf-8' );
     225load_language( 'admin.lang', '', $language, false, 'utf-8' );
     226load_language( 'install.lang', '', $language, false, 'utf-8' );
     227
    235228//----------------------------------------------------- template initialization
    236 $template=setup_style('yoga');
     229$template=new Template(PHPWG_ROOT_PATH.'template/yoga');
    237230$template->set_filenames( array('install'=>'install.tpl') );
    238231$step = 1;
     
    252245      array_push( $errors, $lang['step1_err_db'] );
    253246    }
     247    if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
     248    {
     249      $pwg_charset='utf-8';
     250      $pwg_db_charset='utf8';
     251      $install_charset_collate = "DEFAULT CHARACTER SET $pwg_db_charset";
     252    }
     253    else
     254    {
     255      $pwg_charset='iso-8859-1';
     256      $pwg_db_charset='latin1';
     257      $install_charset_collate = '';
     258      if ( !array_key_exists($language, get_languages($pwg_charset) ) )
     259      {
     260        $language='en_UK';
     261      }
     262    }
    254263  }
    255264  else
     
    257266    array_push( $errors, $lang['step1_err_server'] );
    258267  }
    259  
     268
    260269  $webmaster = trim(preg_replace( '/\s{2,}/', ' ', $admin_name ));
    261270  if ( empty($webmaster))
     
    267276  if ( empty($admin_mail))
    268277    array_push( $errors, $lang['reg_err_mail_address'] );
    269   else 
     278  else
    270279  {
    271280    $error_mail_address = validate_mail_address(null, $admin_mail);
     
    273282      array_push( $errors, $error_mail_address );
    274283  }
    275  
     284
    276285  if ( count( $errors ) == 0 )
    277286  {
     
    286295
    287296define(\'PHPWG_INSTALLED\', true);
     297define(\'PWG_CHARSET\', \''.$pwg_charset.'\');
     298define(\'DB_CHARSET\', \''.$pwg_db_charset.'\');
     299define(\'DB_COLLATE\', \'\');
     300
    288301?'.'>';
    289    
     302
    290303    @umask(0111);
    291304    // writing the configuration file
     
    303316    @fputs($fp, $file_content, strlen($file_content));
    304317    @fclose($fp);
    305    
     318
    306319    // tables creation, based on phpwebgallery_structure.sql
    307320    execute_sqlfile(
     
    325338      );
    326339    mass_inserts(SITES_TABLE, array_keys($insert), array($insert));
    327    
     340
    328341    // webmaster admin user
    329342    $inserts = array(
     
    371384  array(
    372385    'RELEASE'=>PHPWG_VERSION,
    373  
     386
    374387    'L_BASE_TITLE'=>$lang['Initial_config'],
    375388    'L_LANG_TITLE'=>$lang['Default_lang'],
     
    399412    'L_END_TITLE'=>$lang['install_end_title'],
    400413    'L_END_MESSAGE'=>$lang['install_end_message'],
    401    
     414
    402415    'F_ACTION'=>'install.php',
    403416    'F_DB_HOST'=>$dbhost,
     
    412425    'F_ADMIN_EMAIL'=>$admin_mail,
    413426    'F_LANG_SELECT'=>language_select($language),
    414    
    415     'T_CONTENT_ENCODING' => $lang_info['charset']
     427
     428    'T_CONTENT_ENCODING' => 'utf-8'
    416429    ));
    417430
  • trunk/install/phpwebgallery_structure.sql

    r2084 r2127  
    383383  `status` enum('webmaster','admin','normal','generic','guest') NOT NULL default 'guest',
    384384  `adviser` enum('true','false') NOT NULL default 'false',
    385   `language` varchar(50) NOT NULL default 'en_UK.iso-8859-1',
     385  `language` varchar(50) NOT NULL default 'en_UK',
    386386  `maxwidth` smallint(6) default NULL,
    387387  `maxheight` smallint(6) default NULL,
  • trunk/language/en_UK.iso-8859-1/common.lang.php

    r2122 r2127  
    2828$lang_info['language_name'] = 'English';
    2929$lang_info['country'] = 'Great Britain';
    30 $lang_info['charset'] = 'iso-8859-1';
    3130$lang_info['direction'] = 'ltr';
    3231$lang_info['code'] = 'en';
  • trunk/language/fr_FR.iso-8859-1/common.lang.php

    r2122 r2127  
    2828$lang_info['language_name'] = 'Français';
    2929$lang_info['country'] = 'France';
    30 $lang_info['charset'] = 'iso-8859-1';
    3130$lang_info['direction'] = 'ltr';
    3231$lang_info['code'] = 'fr';
  • trunk/plugins/admin_multi_view/controller.php

    r2073 r2127  
    121121<html>
    122122<head>
     123<meta http-equiv="Content-Type" content="text/html; charset=<?php echo get_pwg_charset() ?>">
    123124<title>Controller</title>
    124 <?php 
     125<?php
    125126// Controller will be displayed  with  the **real admin template** (without Any if it has been removed)
    126127if ( $my_template !== '') {
Note: See TracChangeset for help on using the changeset viewer.