ok, let's recode other text fields too...

git-svn-id: file:///svn/phpbb/trunk@6858 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2007-01-07 18:53:15 +00:00
parent 0ac5a3bdbe
commit 6f20a87425
2 changed files with 135 additions and 115 deletions

View file

@ -321,11 +321,11 @@ if (!$get_info)
array('topic_id', 'posts.topic_id', ''),
array('in_message', 0, ''),
array('is_orphan', 0, ''),
array('poster_id', 'attachments.user_id_1', 'phpbb_user_id'),
array('poster_id', 'attachments.user_id_1 AS poster_id', 'phpbb_user_id'),
array('physical_filename', 'attachments_desc.physical_filename', 'import_attachment'),
array('real_filename', 'attachments_desc.real_filename', ''),
array('download_count', 'attachments_desc.download_count', ''),
array('attach_comment', 'attachments_desc.comment', 'utf8_htmlspecialchars'),
array('attach_comment', 'attachments_desc.comment', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('extension', 'attachments_desc.extension', ''),
array('mimetype', 'attachments_desc.mimetype', ''),
array('filesize', 'attachments_desc.filesize', ''),
@ -345,11 +345,11 @@ if (!$get_info)
array('topic_id', 0, ''),
array('in_message', 1, ''),
array('is_orphan', 0, ''),
array('poster_id', 'attachments.user_id_1', 'phpbb_user_id'),
array('poster_id', 'attachments.user_id_1 AS poster_id', 'phpbb_user_id'),
array('physical_filename', 'attachments_desc.physical_filename', 'import_attachment'),
array('real_filename', 'attachments_desc.real_filename', ''),
array('download_count', 'attachments_desc.download_count', ''),
array('attach_comment', 'attachments_desc.comment', 'utf8_htmlspecialchars'),
array('attach_comment', 'attachments_desc.comment', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('extension', 'attachments_desc.extension', ''),
array('mimetype', 'attachments_desc.mimetype', ''),
array('filesize', 'attachments_desc.filesize', ''),
@ -374,7 +374,7 @@ if (!$get_info)
'query_first' => (defined('MOD_ATTACHMENT')) ? $convert->truncate_statement . EXTENSION_GROUPS_TABLE : '',
array('group_id', 'extension_groups.group_id', ''),
array('group_name', 'extension_groups.group_name', 'utf8_htmlspecialchars'),
array('group_name', 'extension_groups.group_name', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('cat_id', 'extension_groups.cat_id', 'phpbb_attachment_category'),
array('allow_group', 'extension_groups.allow_group', ''),
array('download_mode', 1, ''),
@ -407,7 +407,7 @@ if (!$get_info)
'target' => DISALLOW_TABLE,
'query_first' => $convert->truncate_statement . DISALLOW_TABLE,
array('disallow_username', 'disallow.disallow_username', ''),
array('disallow_username', 'disallow.disallow_username', 'phpbb_set_encoding'),
),
array(
@ -415,7 +415,7 @@ if (!$get_info)
'query_first' => $convert->truncate_statement . RANKS_TABLE,
array('rank_id', 'ranks.rank_id', ''),
array('rank_title', 'ranks.rank_title', 'utf8_htmlspecialchars'),
array('rank_title', 'ranks.rank_title', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('rank_min', 'ranks.rank_min', array('typecast' => 'int', 'execute' => '{RESULT} = ({VALUE}[0] < 0) ? 0 : {VALUE}[0];')),
array('rank_special', 'ranks.rank_special', ''),
array('rank_image', 'ranks.rank_image', 'import_rank'),
@ -429,9 +429,9 @@ if (!$get_info)
array('topic_id', 'topics.topic_id', ''),
array('forum_id', 'topics.forum_id', ''),
array('icon_id', 0, ''),
array('topic_poster', 'topics.topic_poster', 'phpbb_user_id'),
array('topic_poster', 'topics.topic_poster AS poster_id', 'phpbb_user_id'),
array('topic_attachment', ((defined('MOD_ATTACHMENT')) ? 'topics.topic_attachment' : 0), ''),
array('topic_title', 'topics.topic_title', ''),
array('topic_title', 'topics.topic_title', 'phpbb_set_encoding'),
array('topic_time', 'topics.topic_time', ''),
array('topic_views', 'topics.topic_views', ''),
array('topic_replies', 'topics.topic_replies', ''),
@ -442,7 +442,7 @@ if (!$get_info)
array('topic_type', 'topics.topic_type', 'phpbb_convert_topic_type'),
array('topic_first_post_id', 'topics.topic_first_post_id', ''),
array('poll_title', 'vote_desc.vote_text', array('function1' => 'null_to_str', 'function2' => 'utf8_htmlspecialchars')),
array('poll_title', 'vote_desc.vote_text', array('function1' => 'null_to_str', 'function2' => 'phpbb_set_encoding', 'function3' => 'utf8_htmlspecialchars')),
array('poll_start', 'vote_desc.vote_start', 'null_to_zero'),
array('poll_length', 'vote_desc.vote_length', 'null_to_zero'),
array('poll_max_options', 1, ''),
@ -459,9 +459,9 @@ if (!$get_info)
array('topic_id', 'topics.topic_id', ''),
array('forum_id', 'topics.forum_id', ''),
array('icon_id', 0, ''),
array('topic_poster', 'topics.topic_poster', 'phpbb_user_id'),
array('topic_poster', 'topics.topic_poster AS poster_id', 'phpbb_user_id'),
array('topic_attachment', ((defined('MOD_ATTACHMENT')) ? 'topics.topic_attachment' : 0), ''),
array('topic_title', 'topics.topic_title', ''),
array('topic_title', 'topics.topic_title', 'phpbb_set_encoding'),
array('topic_time', 'topics.topic_time', ''),
array('topic_views', 'topics.topic_views', ''),
array('topic_replies', 'topics.topic_replies', ''),
@ -472,7 +472,7 @@ if (!$get_info)
array('topic_type', 'topics.topic_type', 'phpbb_convert_topic_type'),
array('topic_first_post_id', 'topics.topic_first_post_id', ''),
array('poll_title', 'vote_desc.vote_text', array('function1' => 'null_to_str', 'function2' => 'utf8_htmlspecialchars')),
array('poll_title', 'vote_desc.vote_text', array('function1' => 'null_to_str', 'function2' => 'phpbb_set_encoding', 'function3' => 'utf8_htmlspecialchars')),
array('poll_start', 'vote_desc.vote_start', 'null_to_zero'),
array('poll_length', 'vote_desc.vote_length', 'null_to_zero'),
array('poll_max_options', 1, ''),
@ -497,8 +497,8 @@ if (!$get_info)
'query_first' => $convert->truncate_statement . SMILIES_TABLE,
array('smiley_id', 'smilies.smilies_id', ''),
array('code', 'smilies.code', ''),
array('emotion', 'smilies.emoticon', ''),
array('code', 'smilies.code', 'phpbb_set_encoding'),
array('emotion', 'smilies.emoticon', 'phpbb_set_encoding'),
array('smiley_url', 'smilies.smile_url', 'import_smiley'),
array('smiley_width', 'smilies.smile_url', 'get_smiley_width'),
array('smiley_height', 'smilies.smile_url', 'get_smiley_height'),
@ -517,10 +517,12 @@ if (!$get_info)
array('poll_option_id', 'vote_results.vote_option_id', ''),
array('topic_id', 'vote_desc.topic_id', ''),
array('poll_option_text', 'vote_results.vote_option_text', 'utf8_htmlspecialchars'),
array('', 'topics.topic_poster AS poster_id', ''),
array('poll_option_text', 'vote_results.vote_option_text', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('poll_option_total', 'vote_results.vote_result', ''),
'where' => 'vote_results.vote_id = vote_desc.vote_id',
'left_join' => 'vote_desc LEFT JOIN topics ON topics.topic_id = vote_desc.topic_id',
),
array(
@ -542,8 +544,8 @@ if (!$get_info)
'query_first' => $convert->truncate_statement . WORDS_TABLE,
array('word_id', 'words.word_id', ''),
array('word', 'words.word', ''),
array('replacement', 'words.replacement', ''),
array('word', 'words.word', 'phpbb_set_encoding'),
array('replacement', 'words.replacement', 'phpbb_set_encoding'),
),
array(
@ -566,8 +568,8 @@ if (!$get_info)
array('enable_smilies', 'posts.enable_smilies', ''),
array('enable_sig', 'posts.enable_sig', ''),
array('enable_magic_url', 1, ''),
array('post_username', 'posts.post_username', ''),
array('post_subject', 'posts_text.post_subject', ''),
array('post_username', 'posts.post_username', 'phpbb_set_encoding'),
array('post_subject', 'posts_text.post_subject', 'phpbb_set_encoding'),
array('post_attachment', ((defined('MOD_ATTACHMENT')) ? 'posts.post_attachment' : 0), ''),
array('post_edit_time', 'posts.post_edit_time', array('typecast' => 'int')),
array('post_edit_count', 'posts.post_edit_count', ''),
@ -612,7 +614,7 @@ if (!$get_info)
array('enable_smilies', 'privmsgs.privmsgs_enable_smilies AS enable_smilies', ''),
array('enable_magic_url', 1, ''),
array('enable_sig', 'privmsgs.privmsgs_attach_sig', ''),
array('message_subject', 'privmsgs.privmsgs_subject', 'utf8_htmlspecialchars'),
array('message_subject', 'privmsgs.privmsgs_subject', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('message_attachment', ((defined('MOD_ATTACHMENT')) ? 'privmsgs.privmsgs_attachment' : 0), ''),
array('message_edit_reason', '', ''),
array('message_edit_user', 0, ''),
@ -744,8 +746,8 @@ if (!$get_info)
array('group_id', 'groups.group_id', ''),
array('group_type', 'groups.group_type', 'phpbb_convert_group_type'),
array('group_display', 0, ''),
array('group_name', 'groups.group_name', 'phpbb_convert_group_name'),
array('group_desc', 'groups.group_description', ''),
array('group_name', 'groups.group_name', 'phpbb_convert_group_name'), // phpbb_set_encoding called in phpbb_convert_group_name
array('group_desc', 'groups.group_description', 'phpbb_set_encoding'),
'where' => 'groups.group_single_user = 0',
),
@ -788,8 +790,8 @@ if (!$get_info)
array('user_type', 'users.user_active', 'set_user_type'),
array('group_id', 'users.user_level', 'phpbb_set_primary_group'),
array('user_regdate', 'users.user_regdate', ''),
array('username', 'users.username', ''),
array('username_clean', 'users.username', 'utf8_clean_string'),
array('username', 'users.username', 'phpbb_set_default_encoding'), // recode to utf8 with default lang
array('username_clean', 'users.username', array('function1' => 'phpbb_set_default_encoding', 'function2' => 'utf8_clean_string')),
array('user_password', 'users.user_password', ''),
array('user_pass_convert', 1, ''),
array('user_posts', 'users.user_posts', ''),
@ -798,20 +800,21 @@ if (!$get_info)
array('user_birthday', ((defined('MOD_BIRTHDAY')) ? 'users.user_birthday' : ''), 'phpbb_get_birthday'),
array('user_lastvisit', 'users.user_lastvisit', ''),
array('user_lang', $config['default_lang'], ''),
array('', 'users.user_lang', ''),
array('user_timezone', 'users.user_timezone', ''),
array('user_dateformat', 'users.user_dateformat', ''),
array('user_inactive_reason', '', 'phpbb_inactive_reason'),
array('user_inactive_time', '', 'phpbb_inactive_time'),
array('user_interests', 'users.user_interests', 'utf8_htmlspecialchars'),
array('user_occ', 'users.user_occ', 'utf8_htmlspecialchars'),
array('user_interests', 'users.user_interests', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('user_occ', 'users.user_occ', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('user_website', 'users.user_website', 'validate_website'),
array('user_jabber', '', ''),
array('user_msnm', 'users.user_msnm', ''),
array('user_yim', 'users.user_yim', ''),
array('user_aim', 'users.user_aim', ''),
array('user_icq', 'users.user_icq', ''),
array('user_from', 'users.user_from', 'utf8_htmlspecialchars'),
array('user_from', 'users.user_from', array('function1' => 'phpbb_set_encoding', 'function2' => 'utf8_htmlspecialchars')),
array('user_rank', 'users.user_rank', ''),
array('user_permissions', '', ''),

View file

@ -70,7 +70,7 @@ function phpbb_insert_forums()
{
$sql_ary = array(
'forum_id' => $max_forum_id,
'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_encoding($row['cat_title']), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'],
'forum_name' => ($row['cat_title']) ? htmlspecialchars(phpbb_set_encoding($row['cat_title'], false), ENT_COMPAT, 'UTF-8') : $user->lang['CATEGORY'],
'parent_id' => 0,
'forum_parents' => '',
'forum_desc' => '',
@ -170,10 +170,10 @@ function phpbb_insert_forums()
// Define the new forums sql ary
$sql_ary = array(
'forum_id' => (int) $row['forum_id'],
'forum_name' => htmlspecialchars(phpbb_set_encoding($row['forum_name']), ENT_COMPAT, 'UTF-8'),
'forum_name' => htmlspecialchars(phpbb_set_encoding($row['forum_name'], false), ENT_COMPAT, 'UTF-8'),
'parent_id' => $cats_added[$row['cat_id']],
'forum_parents' => '',
'forum_desc' => htmlspecialchars(phpbb_set_encoding($row['forum_desc']), ENT_COMPAT, 'UTF-8'),
'forum_desc' => htmlspecialchars(phpbb_set_encoding($row['forum_desc'], false), ENT_COMPAT, 'UTF-8'),
'forum_type' => FORUM_POST,
'forum_status' => is_item_locked($row['forum_status']),
'enable_prune' => $row['prune_enable'],
@ -239,24 +239,113 @@ function phpbb_insert_forums()
$db->sql_freeresult($result);
}
function phpbb_set_encoding($text)
/**
* Function for recoding text with the default language
*
* @param string $text text to recode to utf8
* @param bool $grab_user_lang if set to true the function tries to use $convert_row['user_lang'] (and falls back to $convert_row['poster_id']) instead of the boards default language
*/
function phpbb_set_encoding($text, $grab_user_lang = true)
{
global $lang_enc_array;
global $lang_enc_array, $convert_row;
global $convert, $phpEx;
$default_lang = trim(get_config_value('default_lang'));
/*static $lang_enc_array = array(
'korean' => 'euc-kr',
'serbian' => 'windows-1250',
'polish' => 'iso-8859-2',
'kurdish' => 'windows-1254',
'slovak' => 'Windows-1250',
'russian' => 'windows-1251',
'estonian' => 'iso-8859-4',
'chinese_simplified' => 'gb2312',
'macedonian' => 'windows-1251',
'azerbaijani' => 'UTF-8',
'romanian' => 'iso-8859-2',
'romanian_diacritice' => 'iso-8859-2',
'lithuanian' => 'windows-1257',
'turkish' => 'iso-8859-9',
'ukrainian' => 'windows-1251',
'japanese' => 'shift_jis',
'hungarian' => 'ISO-8859-2',
'romanian_no_diacritics' => 'iso-8859-2',
'mongolian' => 'UTF-8',
'slovenian' => 'windows-1250',
'bosnian' => 'windows-1250',
'czech' => 'Windows-1250',
'farsi' => 'Windows-1256',
'croatian' => 'windows-1250',
'greek' => 'iso-8859-7',
'russian_tu' => 'windows-1251',
'sakha' => 'UTF-8',
'serbian_cyrillic' => 'windows-1251',
'bulgarian' => 'windows-1251',
'chinese_traditional_taiwan' => 'big5',
'chinese_traditional' => 'big5',
'arabic' => 'windows-1256',
'hebrew' => 'WINDOWS-1255',
'thai' => 'windows-874',
//'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-(
);*/
if (!isset($lang_enc_array[$default_lang]))
if (empty($lang_enc_array))
{
global $phpEx, $convert;
include($convert->convertor_status['forum_path'] . '/language/lang_' . $default_lang . '/lang_main.' . $phpEx);
$lang_enc_array[$default_lang] = $lang['ENCODING'];
unset($lang);
$lang_enc_array = array();
}
return utf8_recode($text, $lang_enc_array[$default_lang]);
$get_lang = trim(get_config_value('default_lang'));
// Do we need the users language encoding?
if ($grab_user_lang && !empty($convert_row))
{
if (!empty($convert_row['user_lang']))
{
$get_lang = trim($convert_row['user_lang']);
}
else if (!empty($convert_row['poster_id']))
{
global $db;
$sql = 'SELECT user_lang
FROM ' . $convert->src_table_prefix . 'users
WHERE user_id = ' . (int) $convert_row['poster_id'];
$result = $db->sql_query($sql);
$get_lang = (string) $db->sql_fetchfield('user_lang');
$db->sql_freeresult($result);
$get_lang = (!trim($get_lang)) ? trim(get_config_value('default_lang')) : trim($get_lang);
}
}
if (!isset($lang_enc_array[$get_lang]))
{
$filename = $convert->convertor_status['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx;
if (!file_exists($filename))
{
$get_lang = trim(get_config_value('default_lang'));
}
if (!isset($lang_enc_array[$get_lang]))
{
include($convert->convertor_status['forum_path'] . '/language/lang_' . $get_lang . '/lang_main.' . $phpEx);
$lang_enc_array[$get_lang] = $lang['ENCODING'];
unset($lang);
}
}
$encoding = $lang_enc_array[$get_lang];
return utf8_recode($text, $lang_enc_array[$get_lang]);
}
/**
* Same as phpbb_set_encoding, but forcing boards default language
*/
function phpbb_set_default_encoding($text)
{
return phpbb_set_encoding($text, false);
}
/**
* Convert Birthday from Birthday MOD to phpBB Format
@ -855,7 +944,7 @@ function phpbb_convert_group_name($group_name)
return 'phpBB2 - ' . $group_name;
}
return phpbb_set_encoding($group_name);
return phpbb_set_encoding($group_name, false);
}
/**
@ -915,45 +1004,6 @@ function phpbb_convert_topic_type($topic_type)
function phpbb_prepare_message($message)
{
global $phpbb_root_path, $phpEx, $db, $convert, $user, $config, $cache, $convert_row, $message_parser;
global $lang_enc_array;
/*static $lang_enc_array = array(
'korean' => 'euc-kr',
'serbian' => 'windows-1250',
'polish' => 'iso-8859-2',
'kurdish' => 'windows-1254',
'slovak' => 'Windows-1250',
'russian' => 'windows-1251',
'estonian' => 'iso-8859-4',
'chinese_simplified' => 'gb2312',
'macedonian' => 'windows-1251',
'azerbaijani' => 'UTF-8',
'romanian' => 'iso-8859-2',
'romanian_diacritice' => 'iso-8859-2',
'lithuanian' => 'windows-1257',
'turkish' => 'iso-8859-9',
'ukrainian' => 'windows-1251',
'japanese' => 'shift_jis',
'hungarian' => 'ISO-8859-2',
'romanian_no_diacritics' => 'iso-8859-2',
'mongolian' => 'UTF-8',
'slovenian' => 'windows-1250',
'bosnian' => 'windows-1250',
'czech' => 'Windows-1250',
'farsi' => 'Windows-1256',
'croatian' => 'windows-1250',
'greek' => 'iso-8859-7',
'russian_tu' => 'windows-1251',
'sakha' => 'UTF-8',
'serbian_cyrillic' => 'windows-1251',
'bulgarian' => 'windows-1251',
'chinese_traditional_taiwan' => 'big5',
'chinese_traditional' => 'big5',
'arabic' => 'windows-1256',
'hebrew' => 'WINDOWS-1255',
'thai' => 'windows-874',
//'chinese_traditional_taiwan' => 'utf-8' // custom modified, we may have to do an include :-(
);*/
if (!$message)
{
@ -974,45 +1024,12 @@ function phpbb_prepare_message($message)
$user_id = $convert->row['poster_id'];
$sql = 'SELECT user_lang
FROM ' . $convert->src_table_prefix . 'users
WHERE user_id = ' . (int) $user_id;
$result = $db->sql_query($sql);
$user_lang = (string) $db->sql_fetchfield('user_lang');
$db->sql_freeresult($result);
if (empty($lang_enc_array))
{
$lang_enc_array = array();
}
$user_lang = (!trim($user_lang)) ? trim(get_config_value('default_lang')) : trim($user_lang);
if (!isset($lang_enc_array[$user_lang]))
{
$filename = $convert->convertor_status['forum_path'] . '/language/lang_' . $user_lang . '/lang_main.' . $phpEx;
if (!file_exists($filename))
{
$user_lang = trim(get_config_value('default_lang'));
}
if (!isset($lang_enc_array[$user_lang]))
{
include($convert->convertor_status['forum_path'] . '/language/lang_' . $user_lang . '/lang_main.' . $phpEx);
$lang_enc_array[$user_lang] = $lang['ENCODING'];
unset($lang);
}
}
$encoding = $lang_enc_array[$user_lang];
$message = str_replace('<', '&lt;', $message);
$message = str_replace('>', '&gt;', $message);
$message = str_replace('<br />', "\n", $message);
// make the post UTF-8
$message = utf8_recode($message, $encoding);
$message = phpbb_set_encoding($message);
$message_parser->warn_msg = array(); // Reset the errors from the previous message
$message_parser->bbcode_uid = make_uid($convert->row['post_time']);