[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezi18n/classes/ -> ezcharsetinfo.php (source)

   1  <?php
   2  //
   3  // Definition of eZCharsetInfo class
   4  //
   5  // Created on: <10-Jul-2002 16:44:29 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezcharsetinfo.php
  30    Provides information on charset.
  31  */
  32  
  33  /*!
  34    \class eZCharsetInfo ezcharsetinfo.php
  35    \ingroup eZI18N
  36    \brief Allows for quering information about charsets
  37  
  38    A charset can be known by multiple names but the internationlization
  39    system only works with one name. To fetch the real internal name use
  40    the static realCharsetCode() function.
  41    Each charset also has a specific encoding scheme associated with it
  42    which can be fetched with characterEncodingScheme().
  43  
  44  */
  45  
  46  class eZCharsetInfo
  47  {
  48      /*!
  49       \private
  50       \static
  51       \return the hash table with aliases, creates if it doesn't already exist.
  52      */
  53      function &aliasTable()
  54      {
  55          $aliasTable =& $GLOBALS['eZCharsetInfoTable'];
  56          if ( !is_array( $aliasTable ) )
  57          {
  58              $aliasTable = array( 'ascii' => 'us-ascii',
  59                                   'latin1' => 'iso-8859-1',
  60                                   'latin2' => 'iso-8859-2',
  61                                   'latin3' => 'iso-8859-3',
  62                                   'latin4' => 'iso-8859-4',
  63                                   'latin5' => 'iso-8859-9',
  64                                   'latin6' => 'iso-8859-10',
  65                                   'latin7' => 'iso-8859-13',
  66                                   'latin8' => 'iso-8859-14',
  67                                   'latin9' => 'iso-8859-15',
  68                                   'cyrillic' => 'iso-8859-5',
  69                                   'arabic' => 'iso-8859-6',
  70                                   'greek' => 'iso-8859-7',
  71                                   'hebrew' => 'iso-8859-8',
  72                                   'thai' => 'iso-8859-11',
  73  
  74                                   'koi8-r' => 'koi8-r',
  75                                   'koi-8-r' => 'koi8-r',
  76                                   'koi8r' => 'koi8-r',
  77  
  78                                   'koi8-u' => 'koi8-u',
  79                                   'koi-8-u' => 'koi8-u',
  80                                   'koi8u' => 'koi8-u',
  81  
  82                                   'cp1250' => 'windows-1250',
  83                                   'cp1251' => 'windows-1251',
  84                                   'cp1252' => 'windows-1252',
  85                                   'cp1253' => 'windows-1253',
  86                                   'cp1254' => 'windows-1254',
  87                                   'cp1255' => 'windows-1255',
  88                                   'cp1256' => 'windows-1256',
  89                                   'cp1257' => 'windows-1257',
  90                                   'cp1258' => 'windows-1258',
  91                                   'winlatin1' => 'windows-1252',
  92                                   'winlatin2' => 'windows-1250',
  93                                   'wincyrillic' => 'windows-1251',
  94                                   'wingreek' => 'windows-1253',
  95                                   'winturkish' => 'windows-1254',
  96                                   'winhebrew' => 'windows-1255',
  97                                   'winarabic' => 'windows-1256',
  98                                   'winbaltic' => 'windows-1257',
  99                                   'winvietnamese' => 'windows-1258',
 100  
 101                                   'doslatinus' => 'cp437',
 102                                   'dosgreek' => 'cp737',
 103                                   'dosbaltrim' => 'cp775',
 104                                   'doslatin1' => 'cp850',
 105                                   'doslatin2' => 'cp852',
 106                                   'doscyrillic' => 'cp855',
 107                                   'dosturkish' => 'cp857',
 108                                   'dosportuguese' => 'cp860',
 109                                   'dosicelandic' => 'cp861',
 110                                   'doshebrew' => 'cp862',
 111                                   'doscanadaf' => 'cp863',
 112                                   'dosarabic' => 'cp864',
 113                                   'dosnordic' => 'cp865',
 114                                   'dosgreek2' => 'cp869',
 115                                   'doscyrillicrussian' => 'cp866',
 116                                   'dosthai' => 'cp874',
 117  
 118                                   'macroman' => 'macintosh',
 119                                   'nextstep' => 'next',
 120  
 121                                   'utf8' => 'utf-8',
 122                                   'utf7' => 'utf-7',
 123  
 124                                   'utf16' => 'utf-16',
 125                                   'utf16be' => 'utf-16be',
 126                                   'utf16le' => 'utf-16le',
 127  
 128                                   'utf32' => 'utf-32',
 129                                   'utf32be' => 'utf-32be',
 130                                   'utf32le' => 'utf-32le',
 131  
 132                                   'ucs2le' => 'ucs-2le',
 133  
 134                                   'ucs4' => 'ucs-4',
 135                                   'ucs4be' => 'ucs-4be',
 136                                   'ucs4le' => 'ucs-4le',
 137  
 138                                   'ucs2' => 'ucs-2',
 139                                   'ucs2be' => 'ucs-2be',
 140                                   'ucs2le' => 'ucs-2le',
 141  
 142                                   'shift-jis' => 'cp932',
 143                                   'gbk' => 'gbk',
 144                                   'euc-cn' => 'euc-cn',
 145                                   'unifiedhangul' => 'cp849',
 146                                   'uhc' => 'cp849',
 147                                   'big5' => 'cp850'
 148                                   );
 149              for ( $i = 1; $i <= 15; ++$i )
 150              {
 151                  $aliasTable["iso8859-$i"] = "iso-8859-$i";
 152                  $aliasTable["iso8859$i"] = "iso-8859-$i";
 153              }
 154              $aliasTable['unicode'] = 'unicode';
 155          }
 156          return $aliasTable;
 157      }
 158  
 159      /*!
 160       \private
 161       \static
 162       \return the character encoding hash table, creates it if it does not exist.
 163       The table will map from a character encoding scheme to an array of character sets.
 164       \sa reverseEncodingTable
 165      */
 166      function &encodingTable()
 167      {
 168          $encodingTable =& $GLOBALS['eZCharsetInfoEncodingTable'];
 169          if ( !is_array( $encodingTable ) )
 170          {
 171              $encodingTable = array( 'doublebyte' => array( 'cp932',
 172                                                             'GBK',
 173                                                             'euc-cn',
 174                                                             'cp849',
 175                                                             'cp850' ),
 176                                      'unicode' => array( 'unicode' ),
 177                                      'utf-8' => array( 'utf-8' ) );
 178          }
 179          return $encodingTable;
 180      }
 181  
 182      /*!
 183       \private
 184       \static
 185       \return the reverse character encoding hash table, creates it if it does not exist.
 186       The table will map from a character set to a character encoding scheme.
 187       \sa encodingTable
 188      */
 189      function &reverseEncodingTable()
 190      {
 191          $reverseEncodingTable =& $GLOBALS['eZCharsetInfoReverseEncodingTable'];
 192          if ( !is_array( $reverseEncodingTable ) )
 193          {
 194              $encodingTable =& eZCharsetInfo::encodingTable();
 195              $reverseEncodingTable = array();
 196              foreach( $encodingTable as $encodingScheme => $charsetMatches )
 197              {
 198                  foreach( $charsetMatches as $charsetMatch )
 199                      $reverseEncodingTable[$charsetMatch] = $encodingScheme;
 200              }
 201          }
 202          return $reverseEncodingTable;
 203      }
 204  
 205      /*!
 206       Tries to find an alias for the charset code and returns it. If no
 207       alias code could be find the original charset code is returned.
 208       \note The resulting charset code will be an all lowercase letters.
 209      */
 210      function realCharsetCode( $charsetCode )
 211      {
 212          $aliasTable =& eZCharsetInfo::aliasTable();
 213          $charsetCode = strtolower( $charsetCode );
 214          if ( isset( $aliasTable[$charsetCode] ) )
 215              return $aliasTable[$charsetCode];
 216          // Check alias without any dashes
 217          $charsetCodeNoDash = str_replace( '-', '', $charsetCode );
 218          if ( isset( $aliasTable[$charsetCodeNoDash] ) )
 219              return $aliasTable[$charsetCodeNoDash];
 220          return $charsetCode;
 221      }
 222  
 223      /*!
 224       Tries to figure out the character encoding scheme for the given character set.
 225       It uses realCharsetCode() to get the correct internal charset so any charset
 226       can be given to this function.
 227       Either returns the found encoding scheme or 'singlebyte' if no scheme was found.
 228       \sa realCharsetCode
 229      */
 230      function characterEncodingScheme( $charsetCode, $isRealCharset = false )
 231      {
 232          if ( !$isRealCharset )
 233              $charsetCode = eZCharsetInfo::realCharsetCode( $charsetCode );
 234          $reverseEncodingTable =& eZCharsetInfo::reverseEncodingTable();
 235          if ( isset( $reverseEncodingTable[$charsetCode] ) )
 236              return $reverseEncodingTable[$charsetCode];
 237          return 'singlebyte';
 238      }
 239  }
 240  
 241  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7