Japanese kanji encoding conversion feature thanks to Yukihiro Kawada

This commit is contained in:
Loïc Chapeaux
2002-02-24 18:46:40 +00:00
parent 907af92ab4
commit b106eb60d1
13 changed files with 258 additions and 10 deletions

View File

@@ -11,6 +11,14 @@ $Source$
in an "UPDATE" statement.
* lang/japanese-*: updated thanks to "luc".
* sql.php3: use "[[:space:]]" class inside all regular expressions.
* db_details.php3, lines 585-589 & 729-734; Documentation.html;
ldi_check.php3, lines 32-35; ldi_table.php3, lines 60-69;
read_dump.php3, lines 279-287; sql.php3, lines 267-271; tbl_dump.php3;
tbl_properties.php3; lang/japanese-*;
libraries/common.lib.php3, lines 1026-1034;
libraries/kanji-encoding.lib.php3: japanese kanji encoding conversion
feature thanks to Yukihiro Kawada aka "luc"
<kawada at den.fujifilm.co.jp>.
2002-02-23 Marc Delisle <lem9@users.sourceforge.net>
* swedish updates thanks to Bj<42>rn T. Hallberg

View File

@@ -1076,10 +1076,11 @@
</p>
<p>
<b>I have problems with mysql.user field names.</b>
<b>I have problems with <i>mysql.user</i> field names.</b>
<br />
In older MySQL versions, the User and Password fields were named user and
password. Please modify your field names to align with current standards.
In older MySQL versions, the <tt>User</tt> and <tt>Password</tt> fields
were named <tt>user</tt> and <tt>password</tt>. Please modify your field
names to align with current standards.
</p>
<h3>[Configuration]</h3>
@@ -1590,6 +1591,8 @@ code since version 2.1.0:
for multiple table printviews.
- Garvin Hicking &lt;hicking at faktor-e.de&gt; who builds the patch for
vertical display of table rows.
- Yukihiro Kawada &lt;kawada at den.fujifilm.co.jp&gt; for the japanese kanji
encoding conversion feature.
- Piotr Roszatycki &lt;d3xter at users.sourceforge.net&gt; and Dan Wilson, for
the Cookie authentication mode.
- Axel Sander &lt;n8falke at users.sourceforge.net&gt; for the table

View File

@@ -582,6 +582,11 @@ if ($cfgBookmark['db'] && $cfgBookmark['table']) {
echo ' </div>' . "\n";
}
}
// Encoding setting form appended by Y.Kawada
if (function_exists('PMA_set_enc_form')) {
echo PMA_set_enc_form(' ');
}
?>
<input type="submit" name="SQL" value="<?php echo $strGo; ?>" />
</form>
@@ -721,6 +726,12 @@ if ($num_tables > 0) {
}
}
echo "\n";
// Encoding setting form appended by Y.Kawada
if (function_exists('PMA_set_enc_form')) {
echo ' <br />' . "\n"
. PMA_set_enc_form(' ');
}
?>
</td>
</tr>

View File

@@ -344,5 +344,9 @@ $strYes = '
$strZip = '"zip<69><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"';
// japanese only
$strXkana = '<27><><EFBFBD>ѥ<EFBFBD><D1A5>ʤ<EFBFBD><CAA4>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD>'; // convert to X208-kana
$strEncto = '<27><><EFBFBD>󥳡<EFBFBD><F3A5B3A1>ǥ<EFBFBD><C7A5>󥰤<EFBFBD><F3A5B0A4>Ѵ<EFBFBD><D1B4><EFBFBD><EFBFBD><EFBFBD>'; // encoding convert
// To translate
?>

View File

@@ -344,5 +344,9 @@ $strYes = '
$strZip = '"zip<69><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"';
// japanese only
$strXkana = '<27>S<EFBFBD>p<EFBFBD>J<EFBFBD>i<EFBFBD>֕ϊ<D695><CF8A><EFBFBD><EFBFBD><EFBFBD>'; // convert to X208-kana
$strEncto = '<27>G<EFBFBD><47><EFBFBD>R<EFBFBD>[<5B>f<EFBFBD>B<EFBFBD><42><EFBFBD>O<EFBFBD>֕ϊ<D695><CF8A><EFBFBD><EFBFBD><EFBFBD>'; // encoding convert
// To translate
?>

View File

@@ -29,6 +29,10 @@ if (isset($btnLDI) && ($textfile != 'none')) {
$replace = '';
}
// Kanji encoding convert appended by Y.Kawada
if (function_exists('PMA_kanji_file_conv')) {
$textfile = PMA_kanji_file_conv($textfile, $knjenc, $xkana);
}
// Formats the data posted to this script
$textfile = PMA_sqlAddslashes($textfile);
if (get_magic_quotes_gpc()) {

View File

@@ -57,6 +57,16 @@ require('./header.inc.php3');
<td><input type="text" name="column_name" /></td>
<td><?php echo $strIfYouWish; ?></td>
</tr>
<?php
// 2002/2/22 appended by Y.Kawada: Kanji encoding convert controls
if (function_exists('PMA_set_enc_form')) {
echo ' <tr>' . "\n"
. ' <td>Kanji encoding convert</td>' . "\n"
. ' <td colspan=2>' . "\n"
. PMA_set_enc_form(' ')
. ' </td>' . "\n"
. ' </tr>' . "\n";
?>
<tr>
<td colspan="3" align="center"><?php print PMA_showDocuShort('L/O/LOAD_DATA.html'); ?></td>
</tr>

View File

@@ -1024,5 +1024,14 @@ window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?>');
return strftime($date, $timestamp);
} // end of the 'PMA_localisedDate()' function
// Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
if (PMA_PHP_INT_VERSION >= 40006
&& @function_exists('mb_convert_encoding')
&& strpos(' ' . $lang, 'ja-')
&& file_exists('./libraries/kanji-encoding.lib.php3')) {
include('./libraries/kanji-encoding.lib.php3');
} // end if
} // $__PMA_COMMON_LIB__
?>

View File

@@ -0,0 +1,152 @@
<?php
/* $Id$ */
/**
* Set of functions for kanji-encoding convert (available only with japanese
* language)
*
* PHP4 configure requirements:
* --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex
*
* 2002/2/22 - by Yukihiro Kawada <kawada@den.fujifilm.co.jp>
*/
if (!defined('PMA_ENCODING_LIB_INCLUDED')) {
define('PMA_ENCODING_LIB_INCLUDED', 1);
/**
* Gets the php internal encoding codes and sets the available encoding
* codes list
* 2002/1/4 by Y.Kawada
*
* @global string the current encoding code
* @global string the available encoding codes list
*
* @return boolean always true
*/
function PMA_internal_enc_check() {
global $internal_enc, $enc_list;
$internal_enc = mb_internal_encoding();
if ($internal_enc == 'EUC-JP') {
$enc_list = 'ASCII,EUC-JP,SJIS,JIS';
} else {
$enc_list = 'ASCII,SJIS,EUC-JP,JIS';
}
return TRUE;
} // end of the 'PMA_internal_enc_check' function
/**
* Reverses SJIS & EUC-JP position in the encoding codes list
* 2002/1/4 by Y.Kawada
*
* @global string the available encoding codes list
*
* @return boolean always true
*/
function PMA_change_enc_order() {
global $enc_list;
$p = split(',', $enc_list);
if ($p[1] == 'EUC-JP') {
$enc_list = 'ASCII,SJIS,EUC-JP,JIS';
} else {
$enc_list = 'ASCII,EUC-JP,SJIS,JIS';
}
return TRUE;
} // end of the 'PMA_change_enc_order' function
/**
* Kanji string encoding convert
* 2002/1/4 by Y.Kawada
*
* @param string the string to convert
* @param string the destinasion encoding code
* @param string set 'kana' convert to JIS-X208-kana
*
* @global string the available encoding codes list
*
* @return string the converted string
*/
function PMA_kanji_str_conv($str, $enc, $kana) {
global $enc_list;
if ($enc == '' && $kana == '') {
return $str;
}
$nw = mb_detect_encoding($str, $enc_list);
if ($kana == 'kana') {
$dist = mb_convert_kana($str, 'KV', $nw);
$str = $dist;
}
if ($nw != $enc && $enc) {
$dist = mb_convert_encoding($str, $enc, $nw);
} else {
$dist = $str;
}
return $dist;
} // end of the 'PMA_kanji_str_conv' function
/**
* Kanji file encoding convert
* 2002/1/4 by Y.Kawada
*
* @param string the name of the file to convert
* @param string the destinasion encoding code
* @param string set 'kana' convert to JIS-X208-kana
*
* @return string the name of the converted file
*/
function PMA_kanji_file_conv($file, $enc, $kana) {
if ($enc == '' && $kana == '') {
return $file;
}
$tmpfname = tempnam('', $enc);
$fpd = fopen($tmpfname, 'wb');
$fps = fopen($file, 'r');
PMA_change_enc_order();
while (!feof($fps)) {
$line = fgets($fps, 4096);
$dist = PMA_kanji_str_conv($line, $enc, $kana);
fputs($fpd, $dist);
} // end while
PMA_change_enc_order();
fclose($fps);
fclose($fpd);
unlink($file);
return $tmpfname;
} // end of the 'PMA_kanji_file_conv' function
/**
* Defines radio form fields to switch between encoding modes
* 2002/1/4 by Y.Kawada
*
* @param string spaces character to prepend the output with
*
* @return string xhtml code for the radio controls
*/
function PMA_set_enc_form($spaces) {
return "\n"
. $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n"
. $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n"
. $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n"
. $spaces . '&nbsp;' . $GLOBALS['strEncto'] . '<br />' . "\n"
. $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
. $spaces . '&nbsp;' . $GLOBALS['strXkana'] . '<br />' . "\n";
} // end of the 'PMA_set_enc_form' function
PMA_internal_enc_check();
} // $__PMA_ENCODING_LIB_INCLUDED
?>

View File

@@ -275,7 +275,17 @@ if ($sql_file != 'none') {
else if (empty($id_bookmark) && get_magic_quotes_gpc() == 1) {
$sql_query = stripslashes($sql_query);
}
$sql_query = trim($sql_query);
// Kanji convert SQL textfile 2002/1/4 by Y.Kawada
if (@function_exists('PMA_kanji_str_conv')) {
$sql_tmp = trim($sql_query);
PMA_change_enc_order();
$sql_query = PMA_kanji_str_conv($sql_tmp, $knjenc, $xkana);
PMA_change_enc_order();
} else {
$sql_query = trim($sql_query);
}
// $sql_query come from the query textarea, if it's a reposted query gets its
// 'true' value
if (!empty($prev_sql_query)) {

View File

@@ -264,6 +264,11 @@ else {
PMA_mysqlDie($error, $full_sql_query, '', $full_err_url);
}
// tmpfile remove after convert encoding appended by Y.Kawada
if (function_exists('PMA_kanji_file_conv') && file_exists($textfile)) {
unlink($textfile);
}
// Gets the number of rows affected/returned
if (!$is_affected) {
$num_rows = @mysql_num_rows($result);

View File

@@ -14,6 +14,10 @@ function PMA_myHandler($sql_insert)
{
global $tmp_buffer;
// Kanji encoding convert feature appended by Y.Kawada (2001/2/21)
if (function_exists('PMA_kanji_str_conv')) {
$sql_insert = PMA_kanji_str_conv($sql_insert, $GLOBALS['knjenc'], $GLOBALS['xkana']);
}
// Defines the end of line delimiter to use
$eol_dlm = (isset($GLOBALS['extended_ins']) && ($GLOBALS['current_row'] < $GLOBALS['rows_cnt']))
? ','
@@ -51,6 +55,10 @@ function PMA_myCsvHandler($sql_insert)
global $add_character;
global $tmp_buffer;
// Kanji encoding convert feature appended by Y.Kawada (2001/2/21)
if (function_exists('PMA_kanji_str_conv')) {
$sql_insert = PMA_kanji_str_conv($sql_insert, $GLOBALS['knjenc'], $GLOBALS['xkana']);
}
// Result has to be displayed on screen
if (empty($GLOBALS['asfile'])) {
echo htmlspecialchars($sql_insert) . $add_character;
@@ -218,17 +226,25 @@ else {
: '\'' . $table . '\'';
// If only datas, no need to displays table name
if ($what != 'dataonly') {
$dump_buffer.= '# --------------------------------------------------------' . $crlf
. $crlf . '#' . $crlf
. '# ' . $strTableStructure . ' ' . $formatted_table_name . $crlf
. '#' . $crlf . $crlf
. PMA_getTableDef($db, $table, $crlf, $err_url) . ';' . $crlf;
$dump_buffer .= '# --------------------------------------------------------' . $crlf
. $crlf . '#' . $crlf
. '# ' . $strTableStructure . ' ' . $formatted_table_name . $crlf
. '#' . $crlf . $crlf
. PMA_getTableDef($db, $table, $crlf, $err_url) . ';' . $crlf;
}
if (function_exists('PMA_kanji_str_conv')) { // Y.Kawada
$dump_buffer = PMA_kanji_str_conv($dump_buffer, $knjenc, $xkana);
}
// At least data
if (($what == 'data') || ($what == 'dataonly')) {
$dump_buffer .= $crlf . '#' . $crlf
$tcmt = $crlf . '#' . $crlf
. '# ' . $strDumpingData . ' ' . $formatted_table_name . $crlf
. '#' . $crlf .$crlf;
if (function_exists('PMA_kanji_str_conv')) { // Y.Kawada
$dump_buffer .= PMA_kanji_str_conv($tcmt, $knjenc, $xkana);
} else {
$dump_buffer .= $tcmt;
}
$tmp_buffer = '';
if (!isset($limit_from) || !isset($limit_to)) {
$limit_from = $limit_to = 0;
@@ -239,6 +255,7 @@ else {
$dump_buffer = '';
}
PMA_getTableContent($db, $table, $limit_from, $limit_to, 'PMA_myHandler', $err_url);
$dump_buffer .= $tmp_buffer;
} // end if
$i++;

View File

@@ -732,6 +732,11 @@ if ($is_upload) {
} // end if
echo "\n";
// Encoding setting form appended by Y.Kawada
if (function_exists('PMA_set_enc_form')) {
echo PMA_set_enc_form(' ');
}
// Bookmark Support
if ($cfgBookmark['db'] && $cfgBookmark['table']) {
if (($bookmark_list = PMA_listBookmarks($db, $cfgBookmark)) && count($bookmark_list) > 0) {
@@ -898,6 +903,12 @@ if (PMA_PHP_INT_VERSION >= 40004) {
}
}
echo "\n";
// Encoding setting form appended by Y.Kawada
if (function_exists('PMA_set_enc_form')) {
echo '<br />' . "\n"
. PMA_set_enc_form(' ');
}
?>
</td>
</tr>