Use plugins for extension and MIME type.

This commit is contained in:
Michal Čihař
2006-04-26 17:49:47 +00:00
parent 5c82bf4b29
commit 9199199219
11 changed files with 59 additions and 72 deletions

View File

@@ -22,6 +22,7 @@ $Source$
plugins are independant piece of code (RFE #1325937).
* db_operations.php, tbl_properties_operations.php,
libraries/Table.class.php: Adapt to changes in export.
* export.php, libraries/export/*: Use plugins for extension and MIME type.
2006-04-26 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* themes/*:

View File

@@ -7,14 +7,19 @@
*/
require_once('./libraries/common.lib.php');
require_once('./libraries/zip.lib.php');
require_once('./libraries/plugin_interface.lib.php');
PMA_checkParameters(array('what', 'export_type'));
// What type of export are we doing?
if ($what == 'excel') {
$type = 'csv';
} else {
$type = $what;
// Scan plugins
$export_list = PMA_getPlugins('./libraries/export/', array('export_type' => $export_type, 'single_table' => isset($single_table)));
// Backward compatbility
$type = $what;
// Check export type
if (!isset($export_list[$type])) {
die('Bad type!');
}
// Get the functions specific to the export type
@@ -224,37 +229,9 @@ if ($asfile) {
$filename = PMA_convert_string($convcharset, 'iso-8859-1', $filename);
}
// Generate basic dump extension
if ($type == 'csv') {
$filename .= '.csv';
$mime_type = 'text/comma-separated-values';
} elseif ($type == 'htmlexcel') {
$filename .= '.xls';
$mime_type = 'application/vnd.ms-excel';
} elseif ($type == 'htmlword') {
$filename .= '.doc';
$mime_type = 'application/vnd.ms-word';
} elseif ($type == 'xls') {
$filename .= '.xls';
$mime_type = 'application/vnd.ms-excel';
} elseif ($type == 'xml') {
$filename .= '.xml';
$mime_type = 'text/xml';
} elseif ($type == 'latex') {
$filename .= '.tex';
$mime_type = 'application/x-tex';
} elseif ($type == 'pdf') {
$filename .= '.pdf';
$mime_type = 'application/pdf';
} else {
$filename .= '.sql';
// text/x-sql is correct MIME type, however safari ignores further
// Content-Disposition header, so we must force it to download it this
// way...
$mime_type = PMA_USR_BROWSER_AGENT == 'SAFARI'
? 'application/octet-stream'
: 'text/x-sql';
}
// Grab basic dump extension and mime type
$filename .= '.' . $export_list[$type]['extension'];
$mime_type = $export_list[$type]['mime_type'];
// If dump is going to be compressed, set correct encoding or mime_type and add
// compression to extension
@@ -429,7 +406,7 @@ if ($export_type == 'server') {
break 2;
}
$tables = PMA_DBI_get_tables($current_db);
$views = array();
$views = array();
foreach ($tables as $table) {
// if this is a view, collect it for later; views must be exported
// after the tables
@@ -472,7 +449,7 @@ if ($export_type == 'server') {
$tmp_select = '|' . $tmp_select . '|';
}
$i = 0;
$views = array();
$views = array();
foreach ($tables as $table) {
// if this is a view, collect it for later; views must be exported after
// the tables
@@ -539,7 +516,7 @@ if ($export_type == 'server') {
break;
}
}
// I think we have to export data for a single view; for example PDF report
// I think we have to export data for a single view; for example PDF report
//if (isset($GLOBALS[$what . '_data']) && ! PMA_table::isView($db, $table)) {
if (isset($GLOBALS[$what . '_data'])) {
if (!PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {

View File

@@ -10,14 +10,15 @@ if (isset($plugin_list)) {
$plugin_list['csv'] = array(
'text' => 'strStrucCSV',
'extension' => 'csv',
'mime_type' => 'text/comma-separated-values',
'options' => array(
array('type' => 'text', 'name' => 'separator', 'text' => 'strFieldsTerminatedBy'),
array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy'),
array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy'),
array('type' => 'text', 'name' => 'terminated', 'text' => 'strLinesTerminatedBy'),
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'hidden', 'name' => 'data'),
array('type' => 'text', 'name' => 'separator', 'text' => 'strFieldsTerminatedBy'),
array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy'),
array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy'),
array('type' => 'text', 'name' => 'terminated', 'text' => 'strLinesTerminatedBy'),
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'hidden', 'name' => 'data'),
),
'options_text' => 'strCSVOptions',
);

View File

@@ -10,11 +10,12 @@ if (isset($plugin_list)) {
$plugin_list['excel'] = array(
'text' => 'strStrucExcelCSV',
'extension' => 'xls',
'mime_type' => 'application/vnd.ms-excel',
'options' => array(
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'select', 'name' => 'edition', 'values' => array('win' => 'Windows', 'mac' => 'Excel 2003 / Macintosh'), 'text' => 'strExcelEdition'),
array('type' => 'hidden', 'name' => 'data'),
array('type' => 'hidden', 'name' => 'data'),
),
'options_text' => 'strExcelOptions',
);

View File

@@ -10,10 +10,11 @@ if (isset($plugin_list)) {
$plugin_list['htmlexcel'] = array(
'text' => 'strHTMLExcel',
'extension' => 'xsl',
'mime_type' => 'application/vnd.ms-excel',
'options' => array(
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'hidden', 'name' => 'data'),
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'bool', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'hidden', 'name' => 'data'),
),
'options_text' => 'strHTMLExcelOptions',
);

View File

@@ -10,6 +10,7 @@ if (isset($plugin_list)) {
$plugin_list['htmlword'] = array(
'text' => 'strHTMLWord',
'extension' => 'doc',
'mime_type' => 'application/vnd.ms-word',
'options' => array(
array('type' => 'bool', 'name' => 'structure', 'text' => 'strStructure', 'force' => 'data'),
array('type' => 'bgroup', 'name' => 'data', 'text' => 'strData', 'force' => 'structure'),

View File

@@ -14,6 +14,7 @@ if (isset($plugin_list)) {
$plugin_list['latex'] = array(
'text' => 'strLaTeX',
'extension' => 'tex',
'mime_type' => 'application/x-tex',
'options' => array(
array('type' => 'bool', 'name' => 'caption', 'text' => 'strLatexIncludeCaption'),
),

View File

@@ -3,16 +3,17 @@
// vim: expandtab sw=4 ts=4 sts=4:
/**
* Produce a PDF report (export) from a query
* Produce a PDF report (export) from a query
*/
if (isset($plugin_list)) {
$plugin_list['pdf'] = array(
'text' => 'strPDF',
'extension' => 'pdf',
'mime_type' => 'application/pdf',
'options' => array(
array('type' => 'text', 'name' => 'report_title', 'text' => 'strPDFReportTitle'),
array('type' => 'hidden', 'name' => 'data'),
array('type' => 'text', 'name' => 'report_title', 'text' => 'strPDFReportTitle'),
array('type' => 'hidden', 'name' => 'data'),
),
'options_text' => 'strPDFOptions',
);
@@ -35,14 +36,14 @@ define('FPDF_FONTPATH', './libraries/fpdf/font/');
// Adapted from a LGPL script by Philip Clarke
class PMA_PDF extends PMA_FPDF
class PMA_PDF extends PMA_FPDF
{
var $tablewidths;
var $headerset;
var $footerset;
// overloading of a fpdf function:
function _beginpage($orientation)
function _beginpage($orientation)
{
$this->page++;
// solved the problem of overwriting a page, if it already exists
@@ -54,7 +55,7 @@ class PMA_PDF extends PMA_FPDF
$this->y = $this->tMargin;
$this->lasth = 0;
$this->FontFamily = '';
//Page orientation
if (!$orientation) {
$orientation = $this->DefOrientation;
@@ -82,7 +83,7 @@ class PMA_PDF extends PMA_FPDF
}
}
function Header()
function Header()
{
global $maxY;
@@ -122,7 +123,7 @@ class PMA_PDF extends PMA_FPDF
$this->SetY($maxY);
}
function Footer()
function Footer()
{
// Check if footer for this page already exists
if (!isset($this->footerset[$this->page])) {
@@ -135,7 +136,7 @@ class PMA_PDF extends PMA_FPDF
}
}
function morepagestable($lineheight=8)
function morepagestable($lineheight=8)
{
// some things to set and 'remember'
$l = $this->lMargin;
@@ -290,7 +291,7 @@ class PMA_PDF extends PMA_FPDF
$this->morepagestable($this->FontSizePt);
PMA_DBI_free_result($this->results);
} // end of mysql_report function
} // end of mysql_report function
} // end of PMA_PDF class
@@ -301,7 +302,7 @@ class PMA_PDF extends PMA_FPDF
*
* @return bool Whether it suceeded
*/
function PMA_exportComment($text)
function PMA_exportComment($text)
{
return TRUE;
}
@@ -313,7 +314,7 @@ function PMA_exportComment($text)
*
* @access public
*/
function PMA_exportFooter()
function PMA_exportFooter()
{
return TRUE;
}
@@ -325,7 +326,7 @@ function PMA_exportFooter()
*
* @access public
*/
function PMA_exportHeader()
function PMA_exportHeader()
{
return TRUE;
}
@@ -339,7 +340,7 @@ function PMA_exportHeader()
*
* @access public
*/
function PMA_exportDBHeader($db)
function PMA_exportDBHeader($db)
{
return TRUE;
}
@@ -353,7 +354,7 @@ function PMA_exportDBHeader($db)
*
* @access public
*/
function PMA_exportDBFooter($db)
function PMA_exportDBFooter($db)
{
return TRUE;
}
@@ -367,7 +368,7 @@ function PMA_exportDBFooter($db)
*
* @access public
*/
function PMA_exportDBCreate($db)
function PMA_exportDBCreate($db)
{
return TRUE;
}
@@ -385,7 +386,7 @@ function PMA_exportDBCreate($db)
*
* @access public
*/
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
{
global $what;
global $pdf_report_title;

View File

@@ -16,6 +16,7 @@ if (isset($plugin_list)) {
$plugin_list['sql'] = array(
'text' => 'strSQL',
'extension' => 'sql',
'mime_type' => 'text/x-sql',
'options' => array(
array('type' => 'text', 'name' => 'header_comment', 'text' => 'strAddHeaderComment'),
array('type' => 'bool', 'name' => 'use_transaction', 'text' => 'strEncloseInTransaction'),

View File

@@ -20,10 +20,11 @@ if ($xls) {
$plugin_list['xls'] = array(
'text' => 'strStrucNativeExcel',
'extension' => 'xls',
'mime_type' => 'application/vnd.ms-excel',
'options' => array(
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'text', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'hidden', 'name' => 'data'),
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
array('type' => 'text', 'name' => 'columns', 'text' => 'strPutColNames'),
array('type' => 'hidden', 'name' => 'data'),
),
'options_text' => 'strStrucNativeExcelOptions',
);

View File

@@ -12,6 +12,7 @@ if (isset($plugin_list)) {
$plugin_list['xml'] = array(
'text' => 'strXML',
'extension' => 'xml',
'mime_type' => 'text/xml',
'options' => array(
),
'options_text' => 'strXMLOptions',