/** * Formats the INSERT statements depending on the target (screen/file) of the * cvs export * * Revisions: 2001-05-07, Lem9: added $add_character * 2001-07-12, loic1: $crlf should be used only if there is no EOL * character defined by the user * * @param string the insert statement * * @global string the character to add at the end of lines * @global string the buffer containing formatted strings */ 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'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : ''); } // Result has to be displayed on screen if (empty($GLOBALS['asfile'])) { echo htmlspecialchars($sql_insert) . $add_character; } else { if (!isset($GLOBALS['zip']) && !isset($GLOBALS['bzip']) && !isset($GLOBALS['gzip'])) { echo $sql_insert . $add_character; } else { $tmp_buffer .= $sql_insert . $add_character; } } }
if ($sql_query == FALSE) { $message = $strFileCouldNotBeRead; } } // Convert the file's charset if necessary if ($cfg['AllowAnywhereRecoding'] && $allow_recoding && isset($charset_of_file) && $charset_of_file != $charset) { $sql_query = PMA_convert_string($charset_of_file, $charset, $sql_query); } } // end uploaded file stuff } // 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, isset($xkana) ? $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)) { $prev_sql_query = urldecode($prev_sql_query); if ($sql_query == trim(htmlspecialchars($prev_sql_query))) { $sql_query = $prev_sql_query; } } // Drop database is not allowed -> ensure the query can be run if (!$cfg['AllowUserDropDatabase'] && preg_match('@DROP[[:space:]]+(IF EXISTS[[:space:]]+)?DATABASE @i', $sql_query)) { // Checks if the user is a Superuser
/** * Output handler for all exports, if needed buffering, it stores data into * $dump_buffer, otherwise it prints thems out. * * @param string the insert statement * * @return bool Whether output suceeded */ function PMA_exportOutputHandler($line) { global $time_start, $dump_buffer, $dump_buffer_len, $save_filename; // Kanji encoding convert feature if ($GLOBALS['output_kanji_conversion']) { $line = PMA_kanji_str_conv($line, $GLOBALS['knjenc'], isset($GLOBALS['xkana']) ? $GLOBALS['xkana'] : ''); } // If we have to buffer data, we will perform everything at once at the end if ($GLOBALS['buffer_needed']) { $dump_buffer .= $line; if ($GLOBALS['onfly_compression']) { $dump_buffer_len += strlen($line); if ($dump_buffer_len > $GLOBALS['memory_limit']) { if ($GLOBALS['output_charset_conversion']) { $dump_buffer = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $dump_buffer); } // as bzipped if ($GLOBALS['compression'] == 'bzip' && @function_exists('bzcompress')) { $dump_buffer = bzcompress($dump_buffer); } elseif ($GLOBALS['compression'] == 'gzip' && @function_exists('gzencode')) { // without the optional parameter level because it bug $dump_buffer = gzencode($dump_buffer); } if ($GLOBALS['save_on_server']) { $write_result = @fwrite($GLOBALS['file_handle'], $dump_buffer); if (!$write_result || $write_result != strlen($dump_buffer)) { $GLOBALS['message'] = PMA_Message::error('strNoSpace'); $GLOBALS['message']->addParam($save_filename); return false; } } else { echo $dump_buffer; } $dump_buffer = ''; $dump_buffer_len = 0; } } else { $time_now = time(); if ($time_start >= $time_now + 30) { $time_start = $time_now; header('X-pmaPing: Pong'); } // end if } } else { if ($GLOBALS['asfile']) { if ($GLOBALS['output_charset_conversion']) { $line = PMA_convert_string($GLOBALS['charset'], $GLOBALS['charset_of_file'], $line); } if ($GLOBALS['save_on_server'] && strlen($line) > 0) { $write_result = @fwrite($GLOBALS['file_handle'], $line); if (!$write_result || $write_result != strlen($line)) { $GLOBALS['message'] = PMA_Message::error('strNoSpace'); $GLOBALS['message']->addParam($save_filename); return false; } $time_now = time(); if ($time_start >= $time_now + 30) { $time_start = $time_now; header('X-pmaPing: Pong'); } // end if } else { // We export as file - output normally echo $line; } } else { // We export as html - replace special chars echo htmlspecialchars($line); } } return true; }
/** * 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; }