【php开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了php开源代码-latex.php的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
<?php
/* $Id: latex.php,v 2.16 2006/01/19 15:39:29 cybot_tm Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Set of functions used to build dumps of tables
*/
/**
* Escapes some special characters for use in TeX/LaTeX
*
* @param string the string to convert
*
* @return string the converted string with escape codes
*
* @access private
*/
function PMA_texEscape($string) {
$escape = array('$', '%', '{', '}', '&', '#', '_', '^');
$cnt_escape = count($escape);
for ($k=0; $k < $cnt_escape; $k++) {
$string = str_replace($escape[$k], '\\' . $escape[$k], $string);
}
return $string;
}
/**
* Outputs comment
*
* @param string Text of comment
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text) {
return PMA_exportOutputHandler('% ' . $text . $GLOBALS['crlf']);
}
/**
* Outputs export footer
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportFooter() {
return TRUE;
}
/**
* Outputs export header
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportHeader() {
global $crlf;
global $cfg;
$head = '% phpMyAdmin LaTeX Dump' . $crlf
. '% version ' . PMA_VERSION . $crlf
. '% http://www.phpmyadmin.net' . $crlf
. '%' . $crlf
. '% ' . $GLOBALS['strHost'] . ': ' . $cfg['Server']['host'];
if (!empty($cfg['Server']['port'])) {
$head .= ':' . $cfg['Server']['port'];
}
$head .= $crlf
. '% ' . $GLOBALS['strGenTime'] . ': ' . PMA_localisedDate() . $crlf
. '% ' . $GLOBALS['strServerVersion'] . ': ' . substr(PMA_MYSQL_INT_VERSION, 0, 1) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 1, 2) . '.' . (int) substr(PMA_MYSQL_INT_VERSION, 3) . $crlf
. '% ' . $GLOBALS['str
PHPVersion'] . ': ' . phpversion() . $crlf;
return PMA_exportOutputHandler($head);
}
/**
* Outputs database header
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBHeader($db) {
global $crlf;
$head = '% ' . $crlf
. '% ' . $GLOBALS['strDatabase'] . ': ' . (isset($GLOBALS['use_backquotes']) ? PMA_backquote($db) : '\'' . $db . '\''). $crlf
. '% ' . $crlf;
return PMA_exportOutputHandler($head);
}
/**
* Outputs database footer
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBFooter($db) {
return TRUE;
}
/**
* Outputs create database database
*
* @param string Database name
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportDBCreate($db) {
return TRUE;
}
/**
* Outputs the content of a table in LaTeX table/sideways table environment
*
* @param string the database name
* @param string the table name
* @param string the end of line sequence
* @param string the url to go back in case of error
* @param string SQL query for obtaining data
*
* @return bool Whether it suceeded
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
$result = PMA_DBI_try_query($
sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
$columns_cnt = PMA_DBI_num_fields($result);
for ($i = 0; $i < $columns_cnt; $i++) {
$columns[$i] = PMA_DBI_field_name($result, $i);
}
unset($i);
$buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strData'] . ': ' . $table . $crlf . '%' . $crlf
. ' \\begin{longtable}{|';
for ($index=0;$index<$columns_cnt;$index++) {
$buffer .= 'l|';
}
$buffer .= '} ' . $crlf ;
$buffer .= ' \\hline \\endhead \\hline \\endfoot \\hline ' . $crlf;
if (isset($GLOBALS['latex_caption'])) {
$buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_caption'])
. '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_data_label']) . '} \\\\';
}
if (!PMA_exportOutputHandler($buffer)) {
return FALSE;
}
// show column names
if (isset($GLOBALS['latex_showcolumns'])) {
$buffer = '\\hline ';
for ($i = 0; $i < $columns_cnt; $i++) {
$buffer .= '\\multicolumn{1}{|c|}{\\textbf{' . PMA_texEscape(stripslashes($columns[$i])) . '}} & ';
}
$buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline ';
if (!PMA_exportOutputHandler($buffer . ' \\endfirsthead ' . $crlf)) {
return FALSE;
}
if (isset($GLOBALS['latex_caption'])) {
if (!PMA_exportOutputHandler('\\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_data_continued_caption']) . '} \\\\ ')) return FALSE;
}
if (!PMA_exportOutputHandler($buffer . '\\endhead \\endfoot' . $crlf)) {
return FALSE;
}
} else {
if (!PMA_exportOutputHandler('\\\\ \