Documentation TYPO3 par Ameos

mysql_charsets.lib.php

00001 <?php
00002 /* $Id: mysql_charsets.lib.php,v 2.30 2005/08/08 19:54:57 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 if (PMA_MYSQL_INT_VERSION >= 40100){
00006 
00007     $res = PMA_DBI_query('SHOW CHARACTER SET;');
00008 
00009     $mysql_charsets = array();
00010     while ($row = PMA_DBI_fetch_assoc($res)) {
00011         $mysql_charsets[] = $row['Charset'];
00012         $mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen'];
00013         $mysql_charsets_descriptions[$row['Charset']] = $row['Description'];
00014     }
00015     @PMA_DBI_free_result($res);
00016     unset($res, $row);
00017 
00018     $res = PMA_DBI_query('SHOW COLLATION;');
00019 
00020     $mysql_charsets_count = count($mysql_charsets);
00021     sort($mysql_charsets, SORT_STRING);
00022 
00023     $mysql_collations = array_flip($mysql_charsets);
00024     $mysql_default_collations = $mysql_collations_flat = $mysql_charsets_available = $mysql_collations_available = array();
00025     while ($row = PMA_DBI_fetch_assoc($res)) {
00026         if (!is_array($mysql_collations[$row['Charset']])) {
00027             $mysql_collations[$row['Charset']] = array($row['Collation']);
00028         } else {
00029             $mysql_collations[$row['Charset']][] = $row['Collation'];
00030         }
00031         $mysql_collations_flat[] = $row['Collation'];
00032         if ((isset($row['D']) && $row['D'] == 'Y') || (isset($row['Default']) && $row['Default'] == 'Yes')) {
00033             $mysql_default_collations[$row['Charset']] = $row['Collation'];
00034         }
00035         //$mysql_collations_available[$row['Collation']] = !isset($row['Compiled']) || $row['Compiled'] == 'Yes';
00036         $mysql_collations_available[$row['Collation']] = TRUE;
00037         $mysql_charsets_available[$row['Charset']] = !empty($mysql_charsets_available[$row['Charset']]) || !empty($mysql_collations_available[$row['Collation']]);
00038     }
00039 
00040     $mysql_collations_count = count($mysql_collations_flat);
00041     sort($mysql_collations_flat, SORT_STRING);
00042     foreach ($mysql_collations AS $key => $value) {
00043         sort($mysql_collations[$key], SORT_STRING);
00044         reset($mysql_collations[$key]);
00045     }
00046 
00047     @PMA_DBI_free_result($res);
00048     unset($res, $row);
00049 
00050     function PMA_getCollationDescr($collation) {
00051         static $collation_cache;
00052 
00053         if (!is_array($collation_cache)) {
00054             $collation_cache = array();
00055         } elseif (isset($collation_cache[$collation])) {
00056             return $collation_cache[$collation];
00057         }
00058 
00059         if ($collation == 'binary') {
00060             return $GLOBALS['strBinary'];
00061         }
00062         $parts = explode('_', $collation);
00063         if (count($parts) == 1) {
00064             $parts[1] = 'general';
00065         } elseif ($parts[1] == 'ci' || $parts[1] == 'cs') {
00066             $parts[2] = $parts[1];
00067             $parts[1] = 'general';
00068         }
00069         $descr = '';
00070         switch ($parts[1]) {
00071             case 'bulgarian':
00072                 $descr = $GLOBALS['strBulgarian'];
00073                 break;
00074             case 'chinese':
00075                 if ($parts[0] == 'gb2312' || $parts[0] == 'gbk') {
00076                     $descr = $GLOBALS['strSimplifiedChinese'];
00077                 } elseif ($parts[0] == 'big5') {
00078                     $descr = $GLOBALS['strTraditionalChinese'];
00079                 }
00080                 break;
00081             case 'ci':
00082                 $descr = $GLOBALS['strCaseInsensitive'];
00083                 break;
00084             case 'cs':
00085                 $descr = $GLOBALS['strCaseSensitive'];
00086                 break;
00087             case 'croatian':
00088                 $descr = $GLOBALS['strCroatian'];
00089                 break;
00090             case 'czech':
00091                 $descr = $GLOBALS['strCzech'];
00092                 break;
00093             case 'danish':
00094                 $descr = $GLOBALS['strDanish'];
00095                 break;
00096             case 'english':
00097                 $descr = $GLOBALS['strEnglish'];
00098                 break;
00099             case 'estonian':
00100                 $descr = $GLOBALS['strEstonian'];
00101                 break;
00102             case 'german1':
00103                 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strDictionary'] . ')';
00104                 break;
00105             case 'german2':
00106                 $descr = $GLOBALS['strGerman'] . ' (' . $GLOBALS['strPhoneBook'] . ')';
00107                 break;
00108             case 'hungarian':
00109                 $descr = $GLOBALS['strHungarian'];
00110                 break;
00111             case 'icelandic':
00112                 $descr = $GLOBALS['strIcelandic'];
00113                 break;
00114             case 'japanese':
00115                 $descr = $GLOBALS['strJapanese'];
00116                 break;
00117             case 'latvian':
00118                 $descr = $GLOBALS['strLatvian'];
00119                 break;
00120             case 'lithuanian':
00121                 $descr = $GLOBALS['strLithuanian'];
00122                 break;
00123             case 'korean':
00124                 $descr = $GLOBALS['strKorean'];
00125                 break;
00126             case 'persian':
00127                 $descr = $GLOBALS['strPersian'];
00128                 break;
00129             case 'polish':
00130                 $descr = $GLOBALS['strPolish'];
00131                 break;
00132             case 'roman':
00133                 $descr = $GLOBALS['strWestEuropean'];
00134                 break;
00135             case 'romanian':
00136                 $descr = $GLOBALS['strRomanian'];
00137                 break;
00138             case 'slovak':
00139                 $descr = $GLOBALS['strSlovak'];
00140                 break;
00141             case 'slovenian':
00142                 $descr = $GLOBALS['strSlovenian'];
00143                 break;
00144             case 'spanish':
00145                 $descr = $GLOBALS['strSpanish'];
00146                 break;
00147             case 'spanish2':
00148                 $descr = $GLOBALS['strTraditionalSpanish'];
00149                 break;
00150             case 'swedish':
00151                 $descr = $GLOBALS['strSwedish'];
00152                 break;
00153             case 'thai':
00154                 $descr = $GLOBALS['strThai'];
00155                 break;
00156             case 'turkish':
00157                 $descr = $GLOBALS['strTurkish'];
00158                 break;
00159             case 'ukrainian':
00160                 $descr = $GLOBALS['strUkrainian'];
00161                 break;
00162             case 'unicode':
00163                 $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00164                 break;
00165             case 'bin':
00166                 $is_bin = TRUE;
00167             case 'general':
00168                 switch ($parts[0]) {
00169                     // Unicode charsets
00170                     case 'ucs2':
00171                     case 'utf8':
00172                         $descr = $GLOBALS['strUnicode'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00173                         break;
00174                     // West European charsets
00175                     case 'ascii':
00176                     case 'cp850':
00177                     case 'dec8':
00178                     case 'hp8':
00179                     case 'latin1':
00180                     case 'macroman':
00181                         $descr = $GLOBALS['strWestEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00182                         break;
00183                     // Central European charsets
00184                     case 'cp1250':
00185                     case 'cp852':
00186                     case 'latin2':
00187                     case 'macce':
00188                         $descr = $GLOBALS['strCentralEuropean'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00189                         break;
00190                     // Russian charsets
00191                     case 'cp866':
00192                     case 'koi8r':
00193                         $descr = $GLOBALS['strRussian'];
00194                         break;
00195                     // Simplified Chinese charsets
00196                     case 'gb2312':
00197                     case 'gbk':
00198                         $descr = $GLOBALS['strSimplifiedChinese'];
00199                         break;
00200                     // Japanese charsets
00201                     case 'sjis':
00202                     case 'ujis':
00203                     case 'cp932':
00204                     case 'eucjpms':
00205                         $descr = $GLOBALS['strJapanese'];
00206                         break;
00207                     // Baltic charsets
00208                     case 'cp1257':
00209                     case 'latin7':
00210                         $descr = $GLOBALS['strBaltic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00211                         break;
00212                     // Other
00213                     case 'armscii8':
00214                     case 'armscii':
00215                         $descr = $GLOBALS['strArmenian'];
00216                         break;
00217                     case 'big5':
00218                         $descr = $GLOBALS['strTraditionalChinese'];
00219                         break;
00220                     case 'cp1251':
00221                         $descr = $GLOBALS['strCyrillic'] . ' (' . $GLOBALS['strMultilingual'] . ')';
00222                         break;
00223                     case 'cp1256':
00224                         $descr = $GLOBALS['strArabic'];
00225                         break;
00226                     case 'euckr':
00227                         $descr = $GLOBALS['strKorean'];
00228                         break;
00229                     case 'hebrew':
00230                         $descr = $GLOBALS['strHebrew'];
00231                         break;
00232                     case 'geostd8':
00233                         $descr = $GLOBALS['strGeorgian'];
00234                         break;
00235                     case 'greek':
00236                         $descr = $GLOBALS['strGreek'];
00237                         break;
00238                     case 'keybcs2':
00239                         $descr = $GLOBALS['strCzechSlovak'];
00240                         break;
00241                     case 'koi8u':
00242                         $descr = $GLOBALS['strUkrainian'];
00243                         break;
00244                     case 'latin5':
00245                         $descr = $GLOBALS['strTurkish'];
00246                         break;
00247                     case 'swe7':
00248                         $descr = $GLOBALS['strSwedish'];
00249                         break;
00250                     case 'tis620':
00251                         $descr = $GLOBALS['strThai'];
00252                         break;
00253                     default:
00254                         $descr = $GLOBALS['strUnknown'];
00255                         break;
00256                 }
00257                 if (!empty($is_bin)) {
00258                     $descr .= ', ' . $GLOBALS['strBinary'];
00259                 }
00260                 break;
00261             default: $descr = $GLOBALS['strUnknown'];
00262         }
00263         if (!empty($parts[2])) {
00264             if ($parts[2] == 'ci') {
00265                 $descr .= ', ' . $GLOBALS['strCaseInsensitive'];
00266             } elseif ($parts[2] == 'cs') {
00267                 $descr .= ', ' . $GLOBALS['strCaseSensitive'];
00268             }
00269         }
00270 
00271         $collation_cache[$collation] = $descr;
00272         return $descr;
00273     }
00274 
00275     function PMA_getDbCollation($db) {
00276         global $userlink;
00277         if (PMA_MYSQL_INT_VERSION >= 50000 && $db == 'information_schema') {
00278             // We don't have to check the collation of the virtual
00279             // information_schema database: We know it!
00280             return 'utf8_general_ci';
00281         }
00282         if (PMA_MYSQL_INT_VERSION >= 40101) {
00283             // MySQL 4.1.0 does not support seperate charset settings
00284             // for databases.
00285             $res = PMA_DBI_query('SHOW CREATE DATABASE ' . PMA_backquote($db) . ';', NULL, PMA_DBI_QUERY_STORE);
00286             $row = PMA_DBI_fetch_row($res);
00287             PMA_DBI_free_result($res);
00288             $tokenized = explode(' ', $row[1]);
00289             unset($row, $res);
00290 
00291             for ($i = 1; $i + 3 < count($tokenized); $i++) {
00292                 if ($tokenized[$i] == 'DEFAULT' && $tokenized[$i + 1] == 'CHARACTER' && $tokenized[$i + 2] == 'SET') {
00293                     // We've found the character set!
00294                     if (isset($tokenized[$i + 5]) && $tokenized[$i + 4] == 'COLLATE') {
00295                         return $tokenized[$i + 5]; // We found the collation!
00296                     } else {
00297                         // We did not find the collation, so let's return the
00298                         // default collation for the charset we've found.
00299                         return $GLOBALS['mysql_default_collations'][$tokenized [$i + 3]];
00300                     }
00301                 }
00302             }
00303         }
00304         return '';
00305     }
00306 
00307     define('PMA_CSDROPDOWN_COLLATION', 0);
00308     define('PMA_CSDROPDOWN_CHARSET',   1);
00309 
00310     function PMA_generateCharsetDropdownBox($type = PMA_CSDROPDOWN_COLLATION, $name = NULL, $id = NULL, $default = NULL, $label = TRUE, $indent = 0, $submitOnChange = FALSE, $displayUnavailable = FALSE) {
00311         global $mysql_charsets, $mysql_charsets_descriptions, $mysql_charsets_available, $mysql_collations, $mysql_collations_available;
00312 
00313         if (empty($name)) {
00314             if ($type == PMA_CSDROPDOWN_COLLATION) {
00315                 $name = 'collation';
00316             } else {
00317                 $name = 'character_set';
00318             }
00319         }
00320 
00321         $spacer = '';
00322         for ($i = 1; $i <= $indent; $i++) $spacer .= '    ';
00323 
00324         $return_str  = $spacer . '<select name="' . htmlspecialchars($name) . '"' . (empty($id) ? '' : ' id="' . htmlspecialchars($id) . '"') . ($submitOnChange ? ' onchange="this.form.submit();"' : '') . '>' . "\n";
00325         if ($label) {
00326             $return_str .= $spacer . '    <option value="">' . ($type == PMA_CSDROPDOWN_COLLATION ? $GLOBALS['strCollation'] : $GLOBALS['strCharset']) . '</option>' . "\n";
00327         }
00328         $return_str .= $spacer . '    <option value=""></option>' . "\n";
00329         foreach ($mysql_charsets as $current_charset) {
00330             if (!$mysql_charsets_available[$current_charset]) {
00331                 continue;
00332             }
00333             $current_cs_descr = empty($mysql_charsets_descriptions[$current_charset]) ? $current_charset : $mysql_charsets_descriptions[$current_charset];
00334             if ($type == PMA_CSDROPDOWN_COLLATION) {
00335                 $return_str .= $spacer . '    <optgroup label="' . $current_charset . '" title="' . $current_cs_descr . '">' . "\n";
00336                 foreach ($mysql_collations[$current_charset] as $current_collation) {
00337                     if (!$mysql_collations_available[$current_collation]) {
00338                         continue;
00339                     }
00340                     $return_str .= $spacer . '        <option value="' . $current_collation . '" title="' . PMA_getCollationDescr($current_collation) . '"' . ($default == $current_collation ? ' selected="selected"' : '') . '>' . $current_collation . '</option>' . "\n";
00341                 }
00342                 $return_str .= $spacer . '    </optgroup>' . "\n";
00343             } else {
00344                 $return_str .= $spacer . '    <option value="' . $current_charset . '" title="' . $current_cs_descr . '"' . ($default == $current_charset ? ' selected="selected"' : '') . '>' . $current_charset . '</option>' . "\n";
00345             }
00346         }
00347         $return_str .= $spacer . '</select>' . "\n";
00348 
00349         return $return_str;
00350     }
00351 
00352     function PMA_generateCharsetQueryPart($collation) {
00353         list($charset) = explode('_', $collation);
00354         return ' CHARACTER SET ' . $charset . ($charset == $collation ? '' : ' COLLATE ' . $collation);
00355     }
00356 
00357 }
00358 
00359 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6