Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
787ae98b4a
@ -20,8 +20,8 @@ require_once 'libraries/mysql_charsets.lib.php';
|
||||
|
||||
// add a javascript file for jQuery functions to handle Ajax actions
|
||||
$response = PMA_Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
$scripts->addFile('db_operations.js');
|
||||
|
||||
/**
|
||||
@ -135,11 +135,21 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) {
|
||||
$views = array();
|
||||
|
||||
// remove all foreign key constraints, otherwise we can get errors
|
||||
include_once 'libraries/export/sql.php';
|
||||
$export_sql_plugin = PMA_getPlugin(
|
||||
"export",
|
||||
"sql",
|
||||
'libraries/plugins/export/',
|
||||
array(
|
||||
'export_type' => $export_type,
|
||||
'single_table' => isset($single_table)
|
||||
)
|
||||
);
|
||||
foreach ($tables_full as $each_table => $tmp) {
|
||||
$sql_constraints = '';
|
||||
$sql_drop_foreign_keys = '';
|
||||
$sql_structure = PMA_getTableDef($db, $each_table, "\n", '', false, false);
|
||||
$sql_structure = $export_sql_plugin->getTableDef(
|
||||
$db, $each_table, "\n", '', false, false
|
||||
);
|
||||
if ($move && ! empty($sql_drop_foreign_keys)) {
|
||||
PMA_DBI_query($sql_drop_foreign_keys);
|
||||
}
|
||||
@ -157,7 +167,9 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) {
|
||||
if (PMA_Table::isView($db, $each_table)) {
|
||||
$views[] = $each_table;
|
||||
// Create stand-in definition to resolve view dependencies
|
||||
$sql_view_standin = PMA_getTableDefStandIn($db, $each_table, "\n");
|
||||
$sql_view_standin = $export_sql_plugin->getTableDefStandIn(
|
||||
$db, $each_table, "\n"
|
||||
);
|
||||
PMA_DBI_select_db($newname);
|
||||
PMA_DBI_query($sql_view_standin);
|
||||
$GLOBALS['sql_query'] .= "\n" . $sql_view_standin;
|
||||
|
||||
111
export.php
111
export.php
@ -23,9 +23,11 @@ foreach ($_POST as $one_post_param => $one_post_value) {
|
||||
|
||||
PMA_checkParameters(array('what', 'export_type'));
|
||||
|
||||
// Scan plugins
|
||||
$export_list = PMA_getPlugins(
|
||||
'libraries/export/',
|
||||
// export class instance, not array of properties, as before
|
||||
$export_plugin = PMA_getPlugin(
|
||||
"export",
|
||||
$what,
|
||||
'libraries/plugins/export/',
|
||||
array(
|
||||
'export_type' => $export_type,
|
||||
'single_table' => isset($single_table)
|
||||
@ -36,8 +38,10 @@ $export_list = PMA_getPlugins(
|
||||
$type = $what;
|
||||
|
||||
// Check export type
|
||||
if (! isset($export_list[$type])) {
|
||||
if (! isset($export_plugin)) {
|
||||
PMA_fatalError(__('Bad type!'));
|
||||
} else {
|
||||
$export_plugin_properties = $export_plugin->getProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +90,8 @@ if ($_REQUEST['output_format'] == 'astext') {
|
||||
}
|
||||
|
||||
// Does export require to be into file?
|
||||
if (isset($export_list[$type]['force_file']) && ! $asfile) {
|
||||
if (isset($export_plugin_properties['force_file']) && ! $asfile) {
|
||||
|
||||
$message = PMA_Message::error(__('Selected export type has to be saved in file!'));
|
||||
if ($export_type == 'server') {
|
||||
$active_page = 'server_export.php';
|
||||
@ -118,9 +123,6 @@ if ($export_type == 'server') {
|
||||
PMA_fatalError(__('Bad parameters!'));
|
||||
}
|
||||
|
||||
// Get the functions specific to the export type
|
||||
require 'libraries/export/' . PMA_securePath($type) . '.php';
|
||||
|
||||
/**
|
||||
* Increase time limit for script execution and initializes some variables
|
||||
*/
|
||||
@ -321,15 +323,14 @@ if ($asfile) {
|
||||
$filename = PMA_sanitizeFilename($filename);
|
||||
|
||||
// Grab basic dump extension and mime type
|
||||
// Check if the user already added extension;
|
||||
// get the substring where the extension would be if it was included
|
||||
$extension_start_pos = strlen($filename) - strlen($export_list[$type]['extension']) - 1;
|
||||
// Check if the user already added extension; get the substring where the extension would be if it was included
|
||||
$extension_start_pos = strlen($filename) - strlen($export_plugin_properties['extension']) - 1;
|
||||
$user_extension = substr($filename, $extension_start_pos, strlen($filename));
|
||||
$required_extension = "." . $export_list[$type]['extension'];
|
||||
$required_extension = "." . $export_plugin_properties['extension'];
|
||||
if (strtolower($user_extension) != $required_extension) {
|
||||
$filename .= $required_extension;
|
||||
}
|
||||
$mime_type = $export_list[$type]['mime_type'];
|
||||
$mime_type = $export_plugin_properties['mime_type'];
|
||||
|
||||
// If dump is going to be compressed, set correct mime_type and add
|
||||
// compression to extension
|
||||
@ -352,17 +353,25 @@ if ($save_on_server) {
|
||||
unset($message);
|
||||
if (file_exists($save_filename)
|
||||
&& ((! $quick_export && empty($onserverover))
|
||||
|| ($quick_export && $_REQUEST['quick_export_onserverover'] != 'saveitover'))
|
||||
|| ($quick_export
|
||||
&& $_REQUEST['quick_export_onserverover'] != 'saveitover'))
|
||||
) {
|
||||
$message = PMA_Message::error(__('File %s already exists on server, change filename or check overwrite option.'));
|
||||
$message = PMA_Message::error(__(
|
||||
'File %s already exists on server, change filename or check'
|
||||
. ' overwrite option.'
|
||||
));
|
||||
$message->addParam($save_filename);
|
||||
} else {
|
||||
if (is_file($save_filename) && ! is_writable($save_filename)) {
|
||||
$message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
|
||||
$message = PMA_Message::error(__(
|
||||
'The web server does not have permission to save the file %s.'
|
||||
));
|
||||
$message->addParam($save_filename);
|
||||
} else {
|
||||
if (! $file_handle = @fopen($save_filename, 'w')) {
|
||||
$message = PMA_Message::error(__('The web server does not have permission to save the file %s.'));
|
||||
$message = PMA_Message::error(__(
|
||||
'The web server does not have permission to save the file %s.'
|
||||
));
|
||||
$message->addParam($save_filename);
|
||||
}
|
||||
}
|
||||
@ -452,7 +461,7 @@ if (! $save_on_server) {
|
||||
do {
|
||||
|
||||
// Add possibly some comments to export
|
||||
if (! PMA_exportHeader()) {
|
||||
if (! $export_plugin->exportHeader($db)) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -468,7 +477,7 @@ do {
|
||||
}
|
||||
|
||||
// Include dates in export?
|
||||
$do_dates = isset($GLOBALS[$what . '_dates']);
|
||||
$do_dates = isset($GLOBALS[$what . '_dates']);
|
||||
|
||||
/**
|
||||
* Builds the dump
|
||||
@ -485,17 +494,17 @@ do {
|
||||
&& strpos(' ' . $tmp_select, '|' . $current_db . '|'))
|
||||
|| ! isset($tmp_select)
|
||||
) {
|
||||
if (! PMA_exportDBHeader($current_db)) {
|
||||
if (! $export_plugin->exportDBHeader($current_db)) {
|
||||
break 2;
|
||||
}
|
||||
if (! PMA_exportDBCreate($current_db)) {
|
||||
if (! $export_plugin->exportDBCreate($current_db)) {
|
||||
break 2;
|
||||
}
|
||||
if (function_exists('PMA_exportRoutines')
|
||||
if (method_exists($export_plugin, 'exportRoutines')
|
||||
&& strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
|
||||
&& isset($GLOBALS['sql_procedure_function'])
|
||||
) {
|
||||
PMA_exportRoutines($current_db);
|
||||
$export_plugin->exportRoutines($current_db);
|
||||
}
|
||||
|
||||
$tables = PMA_DBI_get_tables($current_db);
|
||||
@ -512,7 +521,7 @@ do {
|
||||
) {
|
||||
// for a view, export a stand-in definition of the table
|
||||
// to resolve view dependencies
|
||||
if (! PMA_exportStructure(
|
||||
if (! $export_plugin->exportStructure(
|
||||
$current_db, $table, $crlf, $err_url,
|
||||
$is_view ? 'stand_in' : 'create_table', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -527,7 +536,7 @@ do {
|
||||
) {
|
||||
$local_query = 'SELECT * FROM ' . PMA_backquote($current_db)
|
||||
. '.' . PMA_backquote($table);
|
||||
if (! PMA_exportData($current_db, $table, $crlf, $err_url, $local_query)) {
|
||||
if (! $export_plugin->exportData($current_db, $table, $crlf, $err_url, $local_query)) {
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
@ -536,7 +545,7 @@ do {
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|
||||
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
|
||||
) {
|
||||
if (! PMA_exportStructure(
|
||||
if (! $export_plugin->exportStructure(
|
||||
$current_db, $table, $crlf, $err_url,
|
||||
'triggers', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -550,7 +559,7 @@ do {
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|
||||
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
|
||||
) {
|
||||
if (! PMA_exportStructure(
|
||||
if (! $export_plugin->exportStructure(
|
||||
$current_db, $view, $crlf, $err_url,
|
||||
'create_view', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -559,21 +568,21 @@ do {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! PMA_exportDBFooter($current_db)) {
|
||||
if (! $export_plugin->exportDBFooter($current_db)) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($export_type == 'database') {
|
||||
if (! PMA_exportDBHeader($db)) {
|
||||
if (! $export_plugin->exportDBHeader($db)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (function_exists('PMA_exportRoutines')
|
||||
if (method_exists($export_plugin, 'exportRoutines')
|
||||
&& strpos($GLOBALS['sql_structure_or_data'], 'structure') !== false
|
||||
&& isset($GLOBALS['sql_procedure_function'])
|
||||
) {
|
||||
PMA_exportRoutines($db);
|
||||
$export_plugin->exportRoutines($db);
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
@ -591,7 +600,7 @@ do {
|
||||
) {
|
||||
// for a view, export a stand-in definition of the table
|
||||
// to resolve view dependencies
|
||||
if (! PMA_exportStructure(
|
||||
if (! $export_plugin->exportStructure(
|
||||
$db, $table, $crlf, $err_url,
|
||||
$is_view ? 'stand_in' : 'create_table', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -606,16 +615,14 @@ do {
|
||||
) {
|
||||
$local_query = 'SELECT * FROM ' . PMA_backquote($db)
|
||||
. '.' . PMA_backquote($table);
|
||||
if (! PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
|
||||
if (! $export_plugin->exportData($db, $table, $crlf, $err_url, $local_query)) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
// now export the triggers (needs to be done after the data because
|
||||
// triggers can modify already imported tables)
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|
||||
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
|
||||
) {
|
||||
if (! PMA_exportStructure(
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
|
||||
if (! $export_plugin->exportStructure(
|
||||
$db, $table, $crlf, $err_url,
|
||||
'triggers', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -626,10 +633,8 @@ do {
|
||||
}
|
||||
foreach ($views as $view) {
|
||||
// no data export for a view
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|
||||
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
|
||||
) {
|
||||
if (! PMA_exportStructure(
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
|
||||
if (! $export_plugin->exportStructure(
|
||||
$db, $view, $crlf, $err_url,
|
||||
'create_view', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -639,11 +644,11 @@ do {
|
||||
}
|
||||
}
|
||||
|
||||
if (! PMA_exportDBFooter($db)) {
|
||||
if (! $export_plugin->exportDBFooter($db)) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (! PMA_exportDBHeader($db)) {
|
||||
if (! $export_plugin->exportDBHeader($db)) {
|
||||
break;
|
||||
}
|
||||
// We export just one table
|
||||
@ -657,10 +662,8 @@ do {
|
||||
}
|
||||
|
||||
$is_view = PMA_Table::isView($db, $table);
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|
||||
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
|
||||
) {
|
||||
if (! PMA_exportStructure(
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure' || $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data') {
|
||||
if (! $export_plugin->exportStructure(
|
||||
$db, $table, $crlf, $err_url,
|
||||
$is_view ? 'create_view' : 'create_table', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -684,10 +687,12 @@ do {
|
||||
$local_query = $sql_query . $add_query;
|
||||
PMA_DBI_select_db($db);
|
||||
} else {
|
||||
$local_query = 'SELECT * FROM ' . PMA_backquote($db)
|
||||
. '.' . PMA_backquote($table) . $add_query;
|
||||
$local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.'
|
||||
. PMA_backquote($table) . $add_query;
|
||||
}
|
||||
if (! PMA_exportData($db, $table, $crlf, $err_url, $local_query)) {
|
||||
if (! $export_plugin->exportData($db, $table, $crlf, $err_url,
|
||||
$local_query
|
||||
)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -696,7 +701,7 @@ do {
|
||||
if ($GLOBALS[$what . '_structure_or_data'] == 'structure'
|
||||
|| $GLOBALS[$what . '_structure_or_data'] == 'structure_and_data'
|
||||
) {
|
||||
if (! PMA_exportStructure(
|
||||
if (! $export_plugin->exportStructure(
|
||||
$db, $table, $crlf, $err_url,
|
||||
'triggers', $export_type,
|
||||
$do_relation, $do_comments, $do_mime, $do_dates
|
||||
@ -704,11 +709,11 @@ do {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
if (! PMA_exportDBFooter($db)) {
|
||||
if (! $export_plugin->exportDBFooter($db)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! PMA_exportFooter()) {
|
||||
if (! $export_plugin->exportFooter()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
15
import.php
15
import.php
@ -428,13 +428,20 @@ if (! $error && isset($skip)) {
|
||||
|
||||
if (! $error) {
|
||||
// Check for file existance
|
||||
if (!file_exists('libraries/import/' . $format . '.php')) {
|
||||
require_once("libraries/plugin_interface.lib.php");
|
||||
$import_plugin = PMA_getPlugin(
|
||||
"import",
|
||||
$format,
|
||||
'libraries/plugins/import/'
|
||||
);
|
||||
if ($import_plugin == null) {
|
||||
$error = true;
|
||||
$message = PMA_Message::error(__('Could not load import plugins, please check your installation!'));
|
||||
$message = PMA_Message::error(
|
||||
__('Could not load import plugins, please check your installation!')
|
||||
);
|
||||
} else {
|
||||
// Do the real import
|
||||
$plugin_param = $import_type;
|
||||
include 'libraries/import/' . $format . '.php';
|
||||
$import_plugin->doImport();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -751,12 +751,21 @@ class PMA_Table
|
||||
|
||||
// do not create the table if dataonly
|
||||
if ($what != 'dataonly') {
|
||||
include_once './libraries/export/sql.php';
|
||||
// get Export SQL instance
|
||||
$export_sql_plugin = PMA_getPlugin(
|
||||
"export",
|
||||
"sql",
|
||||
'libraries/plugins/export/',
|
||||
array(
|
||||
'export_type' => $export_type,
|
||||
'single_table' => isset($single_table)
|
||||
)
|
||||
);
|
||||
|
||||
$no_constraints_comments = true;
|
||||
$GLOBALS['sql_constraints_query'] = '';
|
||||
|
||||
$sql_structure = PMA_getTableDef(
|
||||
$sql_structure = $export_sql_plugin->getTableDef(
|
||||
$source_db, $source_table, "\n", $err_url, false, false
|
||||
);
|
||||
unset($no_constraints_comments);
|
||||
@ -947,11 +956,11 @@ class PMA_Table
|
||||
if ($GLOBALS['cfgRelation']['commwork']) {
|
||||
// Get all comments and MIME-Types for current table
|
||||
$comments_copy_query = 'SELECT
|
||||
column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
|
||||
FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
|
||||
WHERE
|
||||
db_name = \'' . PMA_sqlAddSlashes($source_db) . '\' AND
|
||||
table_name = \'' . PMA_sqlAddSlashes($source_table) . '\'';
|
||||
column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . '
|
||||
FROM ' . PMA_backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_backquote($GLOBALS['cfgRelation']['column_info']) . '
|
||||
WHERE
|
||||
db_name = \'' . PMA_sqlAddSlashes($source_db) . '\' AND
|
||||
table_name = \'' . PMA_sqlAddSlashes($source_table) . '\'';
|
||||
$comments_copy_rs = PMA_queryAsControlUser($comments_copy_query);
|
||||
|
||||
// Write every comment as new copied entry. [MIME]
|
||||
|
||||
@ -257,7 +257,16 @@ class PMA_Tracker
|
||||
$tracking_set = self::$default_tracking_set;
|
||||
}
|
||||
|
||||
include_once './libraries/export/sql.php';
|
||||
// get Export SQL instance
|
||||
$export_sql_plugin = PMA_getPlugin(
|
||||
"export",
|
||||
"sql",
|
||||
'libraries/plugins/export/',
|
||||
array(
|
||||
'export_type' => $export_type,
|
||||
'single_table' => isset($single_table)
|
||||
)
|
||||
);
|
||||
|
||||
$sql_backquotes = true;
|
||||
|
||||
@ -295,7 +304,7 @@ class PMA_Tracker
|
||||
}
|
||||
|
||||
$create_sql .= self::getLogComment() .
|
||||
PMA_getTableDef($dbname, $tablename, "\n", "");
|
||||
$export_sql_plugin->getTableDef($dbname, $tablename, "\n", "");
|
||||
|
||||
// Save version
|
||||
|
||||
|
||||
@ -1,133 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to run config authentication (ie no authentication).
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage Config
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth()
|
||||
{
|
||||
return true;
|
||||
} // end of the 'PMA_auth()' function
|
||||
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_check()
|
||||
{
|
||||
return true;
|
||||
} // end of the 'PMA_auth_check()' function
|
||||
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_set_user()
|
||||
{
|
||||
return true;
|
||||
} // end of the 'PMA_auth_set_user()' function
|
||||
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @global string the MySQL error message PHP returns
|
||||
* @global string the connection type (persistent or not)
|
||||
* @global string the MySQL server port to use
|
||||
* @global string the MySQL socket port to use
|
||||
* @global array the current server settings
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
* @global boolean tell the "PMA_mysqlDie()" function headers have been
|
||||
* sent
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_fails()
|
||||
{
|
||||
$conn_error = PMA_DBI_getError();
|
||||
if (! $conn_error) {
|
||||
$conn_error = __('Cannot connect: invalid settings.');
|
||||
}
|
||||
|
||||
/* HTML header */
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setTitle(__('Access denied'));
|
||||
$header->disableMenu();
|
||||
|
||||
?>
|
||||
<br /><br />
|
||||
<center>
|
||||
<h1><?php echo sprintf(__('Welcome to %s'), ' phpMyAdmin '); ?></h1>
|
||||
</center>
|
||||
<br />
|
||||
<table cellpadding="0" cellspacing="3" style="margin: 0 auto" width="80%">
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
|
||||
if (isset($GLOBALS['allowDeny_forbidden']) && $GLOBALS['allowDeny_forbidden']) {
|
||||
trigger_error(__('Access denied'), E_USER_NOTICE);
|
||||
} else {
|
||||
// Check whether user has configured something
|
||||
if ($GLOBALS['PMA_Config']->source_mtime == 0) {
|
||||
echo '<p>' . sprintf(__('You probably did not create a configuration file. You might want to use the %1$ssetup script%2$s to create one.'), '<a href="setup/">', '</a>') . '</p>' . "\n";
|
||||
} elseif (! isset($GLOBALS['errno'])
|
||||
|| (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002)
|
||||
&& $GLOBALS['errno'] != 2003
|
||||
) {
|
||||
// if we display the "Server not responding" error, do not confuse users
|
||||
// by telling them they have a settings problem
|
||||
// (note: it's true that they could have a badly typed host name, but
|
||||
// anyway the current message tells that the server
|
||||
// rejected the connection, which is not really what happened)
|
||||
// 2002 is the error given by mysqli
|
||||
// 2003 is the error given by mysql
|
||||
trigger_error(__('phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.'), E_USER_WARNING);
|
||||
}
|
||||
PMA_mysqlDie($conn_error, '', true, '', false);
|
||||
}
|
||||
$GLOBALS['error_handler']->dispUserErrors();
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if (count($GLOBALS['cfg']['Servers']) > 1) {
|
||||
// offer a chance to login to other servers if the current one failed
|
||||
include_once './libraries/select_server.lib.php';
|
||||
echo '<tr>' . "\n";
|
||||
echo ' <td>' . "\n";
|
||||
PMA_selectServer(true, true);
|
||||
echo ' </td>' . "\n";
|
||||
echo '</tr>' . "\n";
|
||||
}
|
||||
echo '</table>' . "\n";
|
||||
exit;
|
||||
return true;
|
||||
} // end of the 'PMA_auth_fails()' function
|
||||
|
||||
?>
|
||||
@ -1,643 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to run cookie based authentication.
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage Cookie
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remember where to redirect the user
|
||||
* in case of an expired session.
|
||||
*/
|
||||
if (! empty($_REQUEST['target'])) {
|
||||
$GLOBALS['target'] = $_REQUEST['target'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Swekey authentication functions.
|
||||
*/
|
||||
require './libraries/auth/swekey/swekey.auth.lib.php';
|
||||
|
||||
if (function_exists('mcrypt_encrypt')) {
|
||||
/**
|
||||
* Uses faster mcrypt library if available
|
||||
* (as this is not called from anywhere else, put the code in-line
|
||||
* for faster execution)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialization
|
||||
* Store the initialization vector because it will be needed for
|
||||
* further decryption. I don't think necessary to have one iv
|
||||
* per server so I don't put the server number in the cookie name.
|
||||
*/
|
||||
if (empty($_COOKIE['pma_mcrypt_iv'])
|
||||
|| false === ($iv = base64_decode($_COOKIE['pma_mcrypt_iv'], true))
|
||||
) {
|
||||
srand((double) microtime() * 1000000);
|
||||
$td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
|
||||
if ($td === false) {
|
||||
PMA_fatalError(__('Failed to use Blowfish from mcrypt!'));
|
||||
}
|
||||
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||
$GLOBALS['PMA_Config']->setCookie('pma_mcrypt_iv', base64_encode($iv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Encryption using blowfish algorithm (mcrypt)
|
||||
*
|
||||
* @param string $data original data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string the encrypted result
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function PMA_blowfish_encrypt($data, $secret)
|
||||
{
|
||||
global $iv;
|
||||
return base64_encode(
|
||||
mcrypt_encrypt(MCRYPT_BLOWFISH, $secret, $data, MCRYPT_MODE_CBC, $iv)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decryption using blowfish algorithm (mcrypt)
|
||||
*
|
||||
* @param string $encdata encrypted data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string original data
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function PMA_blowfish_decrypt($encdata, $secret)
|
||||
{
|
||||
global $iv;
|
||||
$data = base64_decode($encdata);
|
||||
$decrypted = mcrypt_decrypt(
|
||||
MCRYPT_BLOWFISH,
|
||||
$secret,
|
||||
$data,
|
||||
MCRYPT_MODE_CBC,
|
||||
$iv
|
||||
);
|
||||
return trim($decrypted);
|
||||
}
|
||||
|
||||
} else {
|
||||
include_once './libraries/blowfish.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns blowfish secret or generates one if needed.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function PMA_get_blowfish_secret()
|
||||
{
|
||||
if (empty($GLOBALS['cfg']['blowfish_secret'])) {
|
||||
if (empty($_SESSION['auto_blowfish_secret'])) {
|
||||
// this returns 23 characters
|
||||
$_SESSION['auto_blowfish_secret'] = uniqid('', true);
|
||||
}
|
||||
return $_SESSION['auto_blowfish_secret'];
|
||||
} else {
|
||||
// apply md5() to work around too long secrets (returns 32 characters)
|
||||
return md5($GLOBALS['cfg']['blowfish_secret']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* this function MUST exit/quit the application
|
||||
*
|
||||
* @global string the last connection error
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth()
|
||||
{
|
||||
global $conn_error;
|
||||
|
||||
$response = PMA_Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
$response->isSuccess(false);
|
||||
if (! empty($conn_error)) {
|
||||
$response->addJSON('message', $conn_error);
|
||||
} else {
|
||||
$response->addJSON('message', PMA_Message::error(__('Your session has expired. Please login again.')));
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Perform logout to custom URL */
|
||||
if (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* No recall if blowfish secret is not configured as it would produce garbage */
|
||||
if ($GLOBALS['cfg']['LoginCookieRecall']
|
||||
&& ! empty($GLOBALS['cfg']['blowfish_secret'])
|
||||
) {
|
||||
$default_user = $GLOBALS['PHP_AUTH_USER'];
|
||||
$default_server = $GLOBALS['pma_auth_server'];
|
||||
$autocomplete = '';
|
||||
} else {
|
||||
$default_user = '';
|
||||
$default_server = '';
|
||||
// skip the IE autocomplete feature.
|
||||
$autocomplete = ' autocomplete="off"';
|
||||
}
|
||||
|
||||
$cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right';
|
||||
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setBodyId('loginform');
|
||||
$header->setTitle('phpMyAdmin');
|
||||
$header->disableMenu();
|
||||
$header->disableWarnings();
|
||||
|
||||
if (file_exists(CUSTOM_HEADER_FILE)) {
|
||||
include CUSTOM_HEADER_FILE;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="container">
|
||||
<a href="<?php echo PMA_linkURL('http://www.phpmyadmin.net/'); ?>" target="_blank" class="logo"><?php
|
||||
$logo_image = $GLOBALS['pmaThemeImage'] . 'logo_right.png';
|
||||
if (@file_exists($logo_image)) {
|
||||
echo '<img src="' . $logo_image
|
||||
. '" id="imLogo" name="imLogo" alt="phpMyAdmin" border="0" />';
|
||||
} else {
|
||||
echo '<img name="imLogo" id="imLogo" src="'
|
||||
. $GLOBALS['pmaThemeImage'] . 'pma_logo.png' . '" '
|
||||
. 'border="0" width="88" height="31" alt="phpMyAdmin" />';
|
||||
}
|
||||
?></a>
|
||||
<h1>
|
||||
<?php
|
||||
echo sprintf(
|
||||
__('Welcome to %s'),
|
||||
'<bdo dir="ltr" lang="en">phpMyAdmin</bdo>'
|
||||
);
|
||||
?>
|
||||
</h1>
|
||||
<?php
|
||||
|
||||
// Show error message
|
||||
if (! empty($conn_error)) {
|
||||
PMA_Message::rawError($conn_error)->display();
|
||||
}
|
||||
|
||||
echo "<noscript>\n";
|
||||
PMA_message::error(__("Javascript must be enabled past this point"))->display();
|
||||
echo "</noscript>\n";
|
||||
|
||||
echo "<div class='hide js-show'>";
|
||||
// Displays the languages form
|
||||
if (empty($GLOBALS['cfg']['Lang'])) {
|
||||
include_once './libraries/display_select_lang.lib.php';
|
||||
// use fieldset, don't show doc link
|
||||
PMA_select_language(true, false);
|
||||
}
|
||||
echo "</div>";
|
||||
|
||||
?>
|
||||
<br />
|
||||
<!-- Login form -->
|
||||
<form method="post" action="index.php" name="login_form"<?php echo $autocomplete; ?> target="_top" class="login hide js-show">
|
||||
<fieldset>
|
||||
<legend>
|
||||
<?php
|
||||
echo __('Log in');
|
||||
echo PMA_showDocu('');
|
||||
?>
|
||||
</legend>
|
||||
|
||||
<?php if ($GLOBALS['cfg']['AllowArbitraryServer']) { ?>
|
||||
<div class="item">
|
||||
<label for="input_servername" title="<?php echo __('You can enter hostname/IP address and port separated by space.'); ?>"><?php echo __('Server:'); ?></label>
|
||||
<input type="text" name="pma_servername" id="input_servername" value="<?php echo htmlspecialchars($default_server); ?>" size="24" class="textfield" title="<?php echo __('You can enter hostname/IP address and port separated by space.'); ?>" />
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="item">
|
||||
<label for="input_username"><?php echo __('Username:'); ?></label>
|
||||
<input type="text" name="pma_username" id="input_username" value="<?php echo htmlspecialchars($default_user); ?>" size="24" class="textfield"/>
|
||||
</div>
|
||||
<div class="item">
|
||||
<label for="input_password"><?php echo __('Password:'); ?></label>
|
||||
<input type="password" name="pma_password" id="input_password" value="" size="24" class="textfield" />
|
||||
</div>
|
||||
<?php
|
||||
if (count($GLOBALS['cfg']['Servers']) > 1) {
|
||||
?>
|
||||
<div class="item">
|
||||
<label for="select_server"><?php echo __('Server Choice'); ?>:</label>
|
||||
<select name="server" id="select_server"
|
||||
<?php
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']) {
|
||||
echo ' onchange="document.forms[\'login_form\'].elements[\'pma_servername\'].value = \'\'" ';
|
||||
}
|
||||
echo '>';
|
||||
|
||||
include_once './libraries/select_server.lib.php';
|
||||
PMA_selectServer(false, false);
|
||||
|
||||
echo '</select></div>';
|
||||
} else {
|
||||
echo ' <input type="hidden" name="server" value="' . $GLOBALS['server'] . '" />';
|
||||
} // end if (server choice)
|
||||
?>
|
||||
</fieldset>
|
||||
<fieldset class="tblFooters">
|
||||
<input value="<?php echo __('Go'); ?>" type="submit" id="input_go" />
|
||||
<?php
|
||||
$_form_params = array();
|
||||
if (! empty($GLOBALS['target'])) {
|
||||
$_form_params['target'] = $GLOBALS['target'];
|
||||
}
|
||||
if (! empty($GLOBALS['db'])) {
|
||||
$_form_params['db'] = $GLOBALS['db'];
|
||||
}
|
||||
if (! empty($GLOBALS['table'])) {
|
||||
$_form_params['table'] = $GLOBALS['table'];
|
||||
}
|
||||
// do not generate a "server" hidden field as we want the "server"
|
||||
// drop-down to have priority
|
||||
echo PMA_generate_common_hidden_inputs($_form_params, '', 0, 'server');
|
||||
?>
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
// BEGIN Swekey Integration
|
||||
Swekey_login('input_username', 'input_go');
|
||||
// END Swekey Integration
|
||||
|
||||
// show the "Cookies required" message only if cookies are disabled
|
||||
// (we previously tried to set some cookies)
|
||||
if (empty($_COOKIE)) {
|
||||
trigger_error(__('Cookies must be enabled past this point.'), E_USER_NOTICE);
|
||||
}
|
||||
if ($GLOBALS['error_handler']->hasDisplayErrors()) {
|
||||
echo '<div>';
|
||||
$GLOBALS['error_handler']->dispErrors();
|
||||
echo '</div>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
if (file_exists(CUSTOM_FOOTER_FILE)) {
|
||||
include CUSTOM_FOOTER_FILE;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
// show login form in top frame.
|
||||
if (top != self || ! $('body#loginform').length) {
|
||||
window.top.location.href=location;
|
||||
}
|
||||
//]]>
|
||||
</script>
|
||||
<?php
|
||||
exit;
|
||||
} // end of the 'PMA_auth()' function
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* this function DOES NOT check authentication - it just checks/provides
|
||||
* authentication credentials required to connect to the MySQL server
|
||||
* usually with PMA_DBI_connect()
|
||||
*
|
||||
* it returns false if something is missing - which usually leads to
|
||||
* PMA_auth() which displays login form
|
||||
*
|
||||
* it returns true if all seems ok which usually leads to PMA_auth_set_user()
|
||||
*
|
||||
* it directly switches to PMA_auth_fails() if user inactivity timout is reached
|
||||
*
|
||||
* @todo AllowArbitraryServer on does not imply that the user wants an
|
||||
* arbitrary server, or? so we should also check if this is filled and
|
||||
* not only if allowed
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_check()
|
||||
{
|
||||
// Initialization
|
||||
/**
|
||||
* @global $GLOBALS['pma_auth_server'] the user provided server to connect to
|
||||
*/
|
||||
$GLOBALS['pma_auth_server'] = '';
|
||||
|
||||
$GLOBALS['PHP_AUTH_USER'] = $GLOBALS['PHP_AUTH_PW'] = '';
|
||||
$GLOBALS['from_cookie'] = false;
|
||||
|
||||
// BEGIN Swekey Integration
|
||||
if (! Swekey_auth_check()) {
|
||||
return false;
|
||||
}
|
||||
// END Swekey Integration
|
||||
|
||||
if (defined('PMA_CLEAR_COOKIES')) {
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaServer-' . $key);
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaUser-' . $key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['old_usr'])) {
|
||||
// The user wants to be logged out
|
||||
// -> delete his choices that were stored in session
|
||||
|
||||
// according to the PHP manual we should do this before the destroy:
|
||||
//$_SESSION = array();
|
||||
|
||||
session_destroy();
|
||||
// -> delete password cookie(s)
|
||||
if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
|
||||
if (isset($_COOKIE['pmaPass-' . $key])) {
|
||||
unset($_COOKIE['pmaPass-' . $key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $GLOBALS['server']);
|
||||
if (isset($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
|
||||
unset($_COOKIE['pmaPass-' . $GLOBALS['server']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['pma_username'])) {
|
||||
// The user just logged in
|
||||
$GLOBALS['PHP_AUTH_USER'] = $_REQUEST['pma_username'];
|
||||
$GLOBALS['PHP_AUTH_PW'] = empty($_REQUEST['pma_password'])
|
||||
? ''
|
||||
: $_REQUEST['pma_password'];
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& isset($_REQUEST['pma_servername'])
|
||||
) {
|
||||
$GLOBALS['pma_auth_server'] = $_REQUEST['pma_servername'];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// At the end, try to set the $GLOBALS['PHP_AUTH_USER']
|
||||
// and $GLOBALS['PHP_AUTH_PW'] variables from cookies
|
||||
|
||||
// servername
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& ! empty($_COOKIE['pmaServer-' . $GLOBALS['server']])
|
||||
) {
|
||||
$GLOBALS['pma_auth_server'] = $_COOKIE['pmaServer-' . $GLOBALS['server']];
|
||||
}
|
||||
|
||||
// username
|
||||
if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$GLOBALS['PHP_AUTH_USER'] = PMA_blowfish_decrypt(
|
||||
$_COOKIE['pmaUser-' . $GLOBALS['server']],
|
||||
PMA_get_blowfish_secret()
|
||||
);
|
||||
|
||||
// user was never logged in since session start
|
||||
if (empty($_SESSION['last_access_time'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// User inactive too long
|
||||
if ($_SESSION['last_access_time'] < time() - $GLOBALS['cfg']['LoginCookieValidity']) {
|
||||
PMA_cacheUnset('is_create_db_priv', true);
|
||||
PMA_cacheUnset('is_process_priv', true);
|
||||
PMA_cacheUnset('is_reload_priv', true);
|
||||
PMA_cacheUnset('db_to_create', true);
|
||||
PMA_cacheUnset('dbs_where_create_table_allowed', true);
|
||||
$GLOBALS['no_activity'] = true;
|
||||
PMA_auth_fails();
|
||||
exit;
|
||||
}
|
||||
|
||||
// password
|
||||
if (empty($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$GLOBALS['PHP_AUTH_PW'] = PMA_blowfish_decrypt(
|
||||
$_COOKIE['pmaPass-' . $GLOBALS['server']],
|
||||
PMA_get_blowfish_secret()
|
||||
);
|
||||
|
||||
if ($GLOBALS['PHP_AUTH_PW'] == "\xff(blank)") {
|
||||
$GLOBALS['PHP_AUTH_PW'] = '';
|
||||
}
|
||||
|
||||
$GLOBALS['from_cookie'] = true;
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_auth_check()' function
|
||||
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_set_user()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
// Ensures valid authentication mode, 'only_db', bookmark database and
|
||||
// table names and relation table name are used
|
||||
if ($cfg['Server']['user'] != $GLOBALS['PHP_AUTH_USER']) {
|
||||
foreach ($cfg['Servers'] as $idx => $current) {
|
||||
if ($current['host'] == $cfg['Server']['host']
|
||||
&& $current['port'] == $cfg['Server']['port']
|
||||
&& $current['socket'] == $cfg['Server']['socket']
|
||||
&& $current['ssl'] == $cfg['Server']['ssl']
|
||||
&& $current['connect_type'] == $cfg['Server']['connect_type']
|
||||
&& $current['user'] == $GLOBALS['PHP_AUTH_USER']
|
||||
) {
|
||||
$GLOBALS['server'] = $idx;
|
||||
$cfg['Server'] = $current;
|
||||
break;
|
||||
}
|
||||
} // end foreach
|
||||
} // end if
|
||||
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& ! empty($GLOBALS['pma_auth_server'])
|
||||
) {
|
||||
/* Allow to specify 'host port' */
|
||||
$parts = explode(' ', $GLOBALS['pma_auth_server']);
|
||||
if (count($parts) == 2) {
|
||||
$tmp_host = $parts[0];
|
||||
$tmp_port = $parts[1];
|
||||
} else {
|
||||
$tmp_host = $GLOBALS['pma_auth_server'];
|
||||
$tmp_port = '';
|
||||
}
|
||||
if ($cfg['Server']['host'] != $GLOBALS['pma_auth_server']) {
|
||||
$cfg['Server']['host'] = $tmp_host;
|
||||
if (! empty($tmp_port)) {
|
||||
$cfg['Server']['port'] = $tmp_port;
|
||||
}
|
||||
}
|
||||
unset($tmp_host, $tmp_port, $parts);
|
||||
}
|
||||
$cfg['Server']['user'] = $GLOBALS['PHP_AUTH_USER'];
|
||||
$cfg['Server']['password'] = $GLOBALS['PHP_AUTH_PW'];
|
||||
|
||||
// Avoid showing the password in phpinfo()'s output
|
||||
unset($GLOBALS['PHP_AUTH_PW']);
|
||||
unset($_SERVER['PHP_AUTH_PW']);
|
||||
|
||||
$_SESSION['last_access_time'] = time();
|
||||
|
||||
// Name and password cookies need to be refreshed each time
|
||||
// Duration = one month for username
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaUser-' . $GLOBALS['server'],
|
||||
PMA_blowfish_encrypt(
|
||||
$cfg['Server']['user'], PMA_get_blowfish_secret()
|
||||
)
|
||||
);
|
||||
|
||||
// Duration = as configured
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaPass-' . $GLOBALS['server'],
|
||||
PMA_blowfish_encrypt(
|
||||
! empty($cfg['Server']['password']) ? $cfg['Server']['password'] : "\xff(blank)",
|
||||
PMA_get_blowfish_secret()
|
||||
),
|
||||
null,
|
||||
$GLOBALS['cfg']['LoginCookieStore']
|
||||
);
|
||||
|
||||
// Set server cookies if required (once per session) and, in this case, force
|
||||
// reload to ensure the client accepts cookies
|
||||
if (! $GLOBALS['from_cookie']) {
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']) {
|
||||
if (! empty($GLOBALS['pma_auth_server'])) {
|
||||
// Duration = one month for servername
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaServer-' . $GLOBALS['server'],
|
||||
$cfg['Server']['host']
|
||||
);
|
||||
} else {
|
||||
// Delete servername cookie
|
||||
$GLOBALS['PMA_Config']->removeCookie(
|
||||
'pmaServer-' . $GLOBALS['server']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// URL where to go:
|
||||
$redirect_url = $cfg['PmaAbsoluteUri'] . 'index.php';
|
||||
|
||||
// any parameters to pass?
|
||||
$url_params = array();
|
||||
if (strlen($GLOBALS['db'])) {
|
||||
$url_params['db'] = $GLOBALS['db'];
|
||||
}
|
||||
if (strlen($GLOBALS['table'])) {
|
||||
$url_params['table'] = $GLOBALS['table'];
|
||||
}
|
||||
// any target to pass?
|
||||
if (! empty($GLOBALS['target']) && $GLOBALS['target'] != 'index.php') {
|
||||
$url_params['target'] = $GLOBALS['target'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear user cache.
|
||||
*/
|
||||
PMA_clearUserCache();
|
||||
|
||||
PMA_Response::getInstance()->disable();
|
||||
|
||||
PMA_sendHeaderLocation(
|
||||
$redirect_url . PMA_generate_common_url($url_params, '&'),
|
||||
true
|
||||
);
|
||||
exit;
|
||||
} // end if
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_auth_set_user()' function
|
||||
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* prepares error message and switches to PMA_auth() which display the error
|
||||
* and the login form
|
||||
*
|
||||
* this function MUST exit/quit the application,
|
||||
* currently doen by call to PMA_auth()
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_fails()
|
||||
{
|
||||
global $conn_error;
|
||||
|
||||
// Deletes password cookie and displays the login form
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $GLOBALS['server']);
|
||||
|
||||
if (! empty($GLOBALS['login_without_password_is_forbidden'])) {
|
||||
$conn_error = __('Login without a password is forbidden by configuration (see AllowNoPassword)');
|
||||
} elseif (! empty($GLOBALS['allowDeny_forbidden'])) {
|
||||
$conn_error = __('Access denied');
|
||||
} elseif (! empty($GLOBALS['no_activity'])) {
|
||||
$conn_error = sprintf(__('No activity within %s seconds; please log in again'), $GLOBALS['cfg']['LoginCookieValidity']);
|
||||
// Remember where we got timeout to return on same place
|
||||
if (PMA_getenv('SCRIPT_NAME')) {
|
||||
$GLOBALS['target'] = basename(PMA_getenv('SCRIPT_NAME'));
|
||||
// avoid "missing parameter: field" on re-entry
|
||||
if ('tbl_alter.php' == $GLOBALS['target']) {
|
||||
$GLOBALS['target'] = 'tbl_structure.php';
|
||||
}
|
||||
}
|
||||
} elseif (PMA_DBI_getError()) {
|
||||
$conn_error = '#' . $GLOBALS['errno'] . ' '
|
||||
. __('Cannot log in to the MySQL server');
|
||||
} else {
|
||||
$conn_error = __('Cannot log in to the MySQL server');
|
||||
}
|
||||
|
||||
// needed for PHP-CGI (not need for FastCGI or mod-php)
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
|
||||
PMA_auth();
|
||||
} // end of the 'PMA_auth_fails()' function
|
||||
|
||||
?>
|
||||
@ -1,235 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to run http authentication.
|
||||
* NOTE: Requires PHP loaded as a Apache module.
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth()
|
||||
{
|
||||
/* Perform logout to custom URL */
|
||||
if (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($GLOBALS['cfg']['Server']['auth_http_realm'])) {
|
||||
if (empty($GLOBALS['cfg']['Server']['verbose'])) {
|
||||
$server_message = $GLOBALS['cfg']['Server']['host'];
|
||||
} else {
|
||||
$server_message = $GLOBALS['cfg']['Server']['verbose'];
|
||||
}
|
||||
$realm_message = 'phpMyAdmin ' . $server_message;
|
||||
} else {
|
||||
$realm_message = $GLOBALS['cfg']['Server']['auth_http_realm'];
|
||||
}
|
||||
// remove non US-ASCII to respect RFC2616
|
||||
$realm_message = preg_replace('/[^\x20-\x7e]/i', '', $realm_message);
|
||||
header('WWW-Authenticate: Basic realm="' . $realm_message . '"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
if (php_sapi_name() !== 'cgi-fcgi') {
|
||||
header('status: 401 Unauthorized');
|
||||
}
|
||||
|
||||
/* HTML header */
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setTitle(__('Access denied'));
|
||||
$header->disableMenu();
|
||||
|
||||
?>
|
||||
<br /><br />
|
||||
<center>
|
||||
<h1><?php echo sprintf(__('Welcome to %s'), ' phpMyAdmin'); ?></h1>
|
||||
</center>
|
||||
<br />
|
||||
|
||||
<?php
|
||||
PMA_Message::error(__('Wrong username/password. Access denied.'))->display();
|
||||
|
||||
if (file_exists(CUSTOM_FOOTER_FILE)) {
|
||||
include CUSTOM_FOOTER_FILE;
|
||||
}
|
||||
|
||||
exit;
|
||||
} // end of the 'PMA_auth()' function
|
||||
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @global string the username if register_globals is on
|
||||
* @global string the password if register_globals is on
|
||||
* @global array the array of server variables if register_globals is
|
||||
* off
|
||||
* @global array the array of environment variables if register_globals
|
||||
* is off
|
||||
* @global string the username for the ? server
|
||||
* @global string the password for the ? server
|
||||
* @global string the username for the WebSite Professional server
|
||||
* @global string the password for the WebSite Professional server
|
||||
* @global string the username of the user who logs out
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_check()
|
||||
{
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
global $old_usr;
|
||||
|
||||
// Grabs the $PHP_AUTH_USER variable whatever are the values of the
|
||||
// 'register_globals' and the 'variables_order' directives
|
||||
if (empty($PHP_AUTH_USER)) {
|
||||
if (PMA_getenv('PHP_AUTH_USER')) {
|
||||
$PHP_AUTH_USER = PMA_getenv('PHP_AUTH_USER');
|
||||
} elseif (PMA_getenv('REMOTE_USER')) {
|
||||
// CGI, might be encoded, see below
|
||||
$PHP_AUTH_USER = PMA_getenv('REMOTE_USER');
|
||||
} elseif (PMA_getenv('REDIRECT_REMOTE_USER')) {
|
||||
// CGI, might be encoded, see below
|
||||
$PHP_AUTH_USER = PMA_getenv('REDIRECT_REMOTE_USER');
|
||||
} elseif (PMA_getenv('AUTH_USER')) {
|
||||
// WebSite Professional
|
||||
$PHP_AUTH_USER = PMA_getenv('AUTH_USER');
|
||||
} elseif (PMA_getenv('HTTP_AUTHORIZATION')
|
||||
&& false === strpos(PMA_getenv('HTTP_AUTHORIZATION'), '<')
|
||||
) {
|
||||
// IIS, might be encoded, see below; also prevent XSS
|
||||
$PHP_AUTH_USER = PMA_getenv('HTTP_AUTHORIZATION');
|
||||
} elseif (PMA_getenv('Authorization')) {
|
||||
// FastCGI, might be encoded, see below
|
||||
$PHP_AUTH_USER = PMA_getenv('Authorization');
|
||||
}
|
||||
}
|
||||
// Grabs the $PHP_AUTH_PW variable whatever are the values of the
|
||||
// 'register_globals' and the 'variables_order' directives
|
||||
if (empty($PHP_AUTH_PW)) {
|
||||
if (PMA_getenv('PHP_AUTH_PW')) {
|
||||
$PHP_AUTH_PW = PMA_getenv('PHP_AUTH_PW');
|
||||
} elseif (PMA_getenv('REMOTE_PASSWORD')) {
|
||||
// Apache/CGI
|
||||
$PHP_AUTH_PW = PMA_getenv('REMOTE_PASSWORD');
|
||||
} elseif (PMA_getenv('AUTH_PASSWORD')) {
|
||||
// WebSite Professional
|
||||
$PHP_AUTH_PW = PMA_getenv('AUTH_PASSWORD');
|
||||
}
|
||||
}
|
||||
|
||||
// Decode possibly encoded information (used by IIS/CGI/FastCGI)
|
||||
// (do not use explode() because a user might have a colon in his password
|
||||
if (strcmp(substr($PHP_AUTH_USER, 0, 6), 'Basic ') == 0) {
|
||||
$usr_pass = base64_decode(substr($PHP_AUTH_USER, 6));
|
||||
if (! empty($usr_pass)) {
|
||||
$colon = strpos($usr_pass, ':');
|
||||
if ($colon) {
|
||||
$PHP_AUTH_USER = substr($usr_pass, 0, $colon);
|
||||
$PHP_AUTH_PW = substr($usr_pass, $colon + 1);
|
||||
}
|
||||
unset($colon);
|
||||
}
|
||||
unset($usr_pass);
|
||||
}
|
||||
|
||||
// User logged out -> ensure the new username is not the same
|
||||
if (!empty($old_usr)
|
||||
&& (isset($PHP_AUTH_USER) && $old_usr == $PHP_AUTH_USER)
|
||||
) {
|
||||
$PHP_AUTH_USER = '';
|
||||
// -> delete user's choices that were stored in session
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
// Returns whether we get authentication settings or not
|
||||
if (empty($PHP_AUTH_USER)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} // end of the 'PMA_auth_check()' function
|
||||
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @global array the valid servers settings
|
||||
* @global integer the id of the current server
|
||||
* @global array the current server settings
|
||||
* @global string the current username
|
||||
* @global string the current password
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_set_user()
|
||||
{
|
||||
global $cfg, $server;
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
// Ensures valid authentication mode, 'only_db', bookmark database and
|
||||
// table names and relation table name are used
|
||||
if ($cfg['Server']['user'] != $PHP_AUTH_USER) {
|
||||
$servers_cnt = count($cfg['Servers']);
|
||||
for ($i = 1; $i <= $servers_cnt; $i++) {
|
||||
if (isset($cfg['Servers'][$i])
|
||||
&& ($cfg['Servers'][$i]['host'] == $cfg['Server']['host']
|
||||
&& $cfg['Servers'][$i]['user'] == $PHP_AUTH_USER)
|
||||
) {
|
||||
$server = $i;
|
||||
$cfg['Server'] = $cfg['Servers'][$i];
|
||||
break;
|
||||
}
|
||||
} // end for
|
||||
} // end if
|
||||
|
||||
$cfg['Server']['user'] = $PHP_AUTH_USER;
|
||||
$cfg['Server']['password'] = $PHP_AUTH_PW;
|
||||
|
||||
// Avoid showing the password in phpinfo()'s output
|
||||
unset($GLOBALS['PHP_AUTH_PW']);
|
||||
unset($_SERVER['PHP_AUTH_PW']);
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_auth_set_user()' function
|
||||
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_fails()
|
||||
{
|
||||
$error = PMA_DBI_getError();
|
||||
if ($error && $GLOBALS['errno'] != 1045) {
|
||||
PMA_fatalError($error);
|
||||
} else {
|
||||
PMA_auth();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // end of the 'PMA_auth_fails()' function
|
||||
|
||||
?>
|
||||
@ -1,259 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to run single signon authentication.
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage Signon
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth()
|
||||
{
|
||||
unset($_SESSION['LAST_SIGNON_URL']);
|
||||
if (empty($GLOBALS['cfg']['Server']['SignonURL'])) {
|
||||
PMA_fatalError('You must set SignonURL!');
|
||||
} elseif (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
/* Perform logout to custom URL */
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
} else {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['SignonURL']);
|
||||
}
|
||||
exit();
|
||||
} // end of the 'PMA_auth()' function
|
||||
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @global string the username if register_globals is on
|
||||
* @global string the password if register_globals is on
|
||||
* @global array the array of server variables if register_globals is
|
||||
* off
|
||||
* @global array the array of environment variables if register_globals
|
||||
* is off
|
||||
* @global string the username for the ? server
|
||||
* @global string the password for the ? server
|
||||
* @global string the username for the WebSite Professional server
|
||||
* @global string the password for the WebSite Professional server
|
||||
* @global string the username of the user who logs out
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_check()
|
||||
{
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
/* Check if we're using same sigon server */
|
||||
if (isset($_SESSION['LAST_SIGNON_URL'])
|
||||
&& $_SESSION['LAST_SIGNON_URL'] != $GLOBALS['cfg']['Server']['SignonURL']
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Script name */
|
||||
$script_name = $GLOBALS['cfg']['Server']['SignonScript'];
|
||||
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Login URL */
|
||||
$signon_url = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
|
||||
/* Current host */
|
||||
$single_signon_host = $GLOBALS['cfg']['Server']['host'];
|
||||
|
||||
/* Current port */
|
||||
$single_signon_port = $GLOBALS['cfg']['Server']['port'];
|
||||
|
||||
/* No configuration updates */
|
||||
$single_signon_cfgupdate = array();
|
||||
|
||||
/* Are we requested to do logout? */
|
||||
$do_logout = !empty($_REQUEST['old_usr']);
|
||||
|
||||
/* Handle script based auth */
|
||||
if (!empty($script_name)) {
|
||||
if (! file_exists($script_name)) {
|
||||
PMA_fatalError(
|
||||
__('Can not find signon authentication script:') . ' ' . $script_name
|
||||
);
|
||||
}
|
||||
include $script_name;
|
||||
|
||||
list ($PHP_AUTH_USER, $PHP_AUTH_PW)
|
||||
= get_login_credentials($cfg['Server']['user']);
|
||||
|
||||
} elseif (isset($_COOKIE[$session_name])) { /* Does session exist? */
|
||||
/* End current session */
|
||||
$old_session = session_name();
|
||||
$old_id = session_id();
|
||||
session_write_close();
|
||||
|
||||
/* Load single signon session */
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_start();
|
||||
|
||||
/* Clear error message */
|
||||
unset($_SESSION['PMA_single_signon_error_message']);
|
||||
|
||||
/* Grab credentials if they exist */
|
||||
if (isset($_SESSION['PMA_single_signon_user'])) {
|
||||
if ($do_logout) {
|
||||
$PHP_AUTH_USER = '';
|
||||
} else {
|
||||
$PHP_AUTH_USER = $_SESSION['PMA_single_signon_user'];
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION['PMA_single_signon_password'])) {
|
||||
if ($do_logout) {
|
||||
$PHP_AUTH_PW = '';
|
||||
} else {
|
||||
$PHP_AUTH_PW = $_SESSION['PMA_single_signon_password'];
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION['PMA_single_signon_host'])) {
|
||||
$single_signon_host = $_SESSION['PMA_single_signon_host'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_port'])) {
|
||||
$single_signon_port = $_SESSION['PMA_single_signon_port'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_cfgupdate'])) {
|
||||
$single_signon_cfgupdate = $_SESSION['PMA_single_signon_cfgupdate'];
|
||||
}
|
||||
|
||||
|
||||
/* Also get token as it is needed to access subpages */
|
||||
if (isset($_SESSION['PMA_single_signon_token'])) {
|
||||
/* No need to care about token on logout */
|
||||
$pma_token = $_SESSION['PMA_single_signon_token'];
|
||||
}
|
||||
|
||||
/* End single signon session */
|
||||
session_write_close();
|
||||
|
||||
/* Restart phpMyAdmin session */
|
||||
session_name($old_session);
|
||||
if (!empty($old_id)) {
|
||||
session_id($old_id);
|
||||
}
|
||||
session_start();
|
||||
|
||||
/* Set the single signon host */
|
||||
$GLOBALS['cfg']['Server']['host'] = $single_signon_host;
|
||||
|
||||
/* Set the single signon port */
|
||||
$GLOBALS['cfg']['Server']['port'] = $single_signon_port;
|
||||
|
||||
/* Configuration update */
|
||||
$GLOBALS['cfg']['Server'] = array_merge(
|
||||
$GLOBALS['cfg']['Server'],
|
||||
$single_signon_cfgupdate
|
||||
);
|
||||
|
||||
/* Restore our token */
|
||||
if (!empty($pma_token)) {
|
||||
$_SESSION[' PMA_token '] = $pma_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear user cache.
|
||||
*/
|
||||
PMA_clearUserCache();
|
||||
}
|
||||
|
||||
// Returns whether we get authentication settings or not
|
||||
if (empty($PHP_AUTH_USER)) {
|
||||
unset($_SESSION['LAST_SIGNON_URL']);
|
||||
return false;
|
||||
} else {
|
||||
$_SESSION['LAST_SIGNON_URL'] = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
return true;
|
||||
}
|
||||
} // end of the 'PMA_auth_check()' function
|
||||
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @global array the valid servers settings
|
||||
* @global integer the id of the current server
|
||||
* @global array the current server settings
|
||||
* @global string the current username
|
||||
* @global string the current password
|
||||
*
|
||||
* @return boolean always true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_set_user()
|
||||
{
|
||||
global $cfg;
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
$cfg['Server']['user'] = $PHP_AUTH_USER;
|
||||
$cfg['Server']['password'] = $PHP_AUTH_PW;
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_auth_set_user()' function
|
||||
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_auth_fails()
|
||||
{
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Does session exist? */
|
||||
if (isset($_COOKIE[$session_name])) {
|
||||
/* End current session */
|
||||
$old_session = session_name();
|
||||
$old_id = session_id();
|
||||
session_write_close();
|
||||
|
||||
/* Load single signon session */
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_start();
|
||||
|
||||
/* Set error message */
|
||||
if (! empty($GLOBALS['login_without_password_is_forbidden'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __('Login without a password is forbidden by configuration (see AllowNoPassword)');
|
||||
} elseif (! empty($GLOBALS['allowDeny_forbidden'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __('Access denied');
|
||||
} elseif (! empty($GLOBALS['no_activity'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = sprintf(__('No activity within %s seconds; please log in again'), $GLOBALS['cfg']['LoginCookieValidity']);
|
||||
} elseif (PMA_DBI_getError()) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = PMA_sanitize(PMA_DBI_getError());
|
||||
} else {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __('Cannot log in to the MySQL server');
|
||||
}
|
||||
}
|
||||
PMA_auth();
|
||||
} // end of the 'PMA_auth_fails()' function
|
||||
|
||||
?>
|
||||
@ -478,59 +478,5 @@ class Horde_Cipher_blowfish
|
||||
|
||||
return pack("NN", $R ^ $this->p[0], $L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// higher-level functions:
|
||||
/**
|
||||
* Encryption using blowfish algorithm
|
||||
*
|
||||
* @param string $data original data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string the encrypted result
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function PMA_blowfish_encrypt($data, $secret)
|
||||
{
|
||||
$pma_cipher = new Horde_Cipher_blowfish;
|
||||
$encrypt = '';
|
||||
|
||||
$mod = strlen($data) % 8;
|
||||
|
||||
if ($mod > 0) {
|
||||
$data .= str_repeat("\0", 8 - $mod);
|
||||
}
|
||||
|
||||
foreach (str_split($data, 8) as $chunk) {
|
||||
$encrypt .= $pma_cipher->encryptBlock($chunk, $secret);
|
||||
}
|
||||
return base64_encode($encrypt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decryption using blowfish algorithm
|
||||
*
|
||||
* @param string $encdata encrypted data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string original data
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
function PMA_blowfish_decrypt($encdata, $secret)
|
||||
{
|
||||
$pma_cipher = new Horde_Cipher_blowfish;
|
||||
$decrypt = '';
|
||||
$data = base64_decode($encdata);
|
||||
|
||||
foreach (str_split($data, 8) as $chunk) {
|
||||
$decrypt .= $pma_cipher->decryptBlock($chunk, $secret);
|
||||
}
|
||||
return trim($decrypt);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -136,7 +136,8 @@ function PMA_analyseShowGrant()
|
||||
|
||||
PMA_DBI_free_result($rs_usr);
|
||||
|
||||
// must also PMA_cacheUnset() them in libraries/auth/cookie.auth.lib.php
|
||||
// must also PMA_cacheUnset() them in
|
||||
// libraries/plugins/auth/AuthenticationCookie.class.php
|
||||
PMA_cacheSet('is_create_db_priv', $GLOBALS['is_create_db_priv'], true);
|
||||
PMA_cacheSet('is_process_priv', $GLOBALS['is_process_priv'], true);
|
||||
PMA_cacheSet('is_reload_priv', $GLOBALS['is_reload_priv'], true);
|
||||
|
||||
@ -839,21 +839,28 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
||||
|
||||
// to allow HTTP or http
|
||||
$cfg['Server']['auth_type'] = strtolower($cfg['Server']['auth_type']);
|
||||
if (! file_exists('./libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php')) {
|
||||
PMA_fatalError(
|
||||
__('Invalid authentication method set in configuration:') . ' ' . $cfg['Server']['auth_type']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* the required auth type plugin
|
||||
*/
|
||||
include_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
|
||||
if (! PMA_auth_check()) {
|
||||
$auth_class = "Authentication" . ucfirst($cfg['Server']['auth_type']);
|
||||
if (! file_exists('./libraries/plugins/auth/' . $auth_class . '.class.php')) {
|
||||
PMA_fatalError(
|
||||
__('Invalid authentication method set in configuration:')
|
||||
. ' ' . $cfg['Server']['auth_type']
|
||||
);
|
||||
}
|
||||
include_once './libraries/plugins/auth/' . $auth_class . '.class.php';
|
||||
// todo: add plugin manager
|
||||
$plugin_manager = null;
|
||||
$auth_plugin = new $auth_class($plugin_manager);
|
||||
|
||||
if (! $auth_plugin->authCheck()) {
|
||||
/* Force generating of new session on login */
|
||||
PMA_secureSession();
|
||||
PMA_auth();
|
||||
$auth_plugin->auth();
|
||||
} else {
|
||||
PMA_auth_set_user();
|
||||
$auth_plugin->authSetUser();
|
||||
}
|
||||
|
||||
// Check IP-based Allow/Deny rules as soon as possible to reject the
|
||||
@ -897,7 +904,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
||||
// Ejects the user if banished
|
||||
if ($allowDeny_forbidden) {
|
||||
PMA_log_user($cfg['Server']['user'], 'allow-denied');
|
||||
PMA_auth_fails();
|
||||
$auth_plugin->authFails();
|
||||
}
|
||||
} // end if
|
||||
|
||||
@ -905,14 +912,14 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
||||
if (!$cfg['Server']['AllowRoot'] && $cfg['Server']['user'] == 'root') {
|
||||
$allowDeny_forbidden = true;
|
||||
PMA_log_user($cfg['Server']['user'], 'root-denied');
|
||||
PMA_auth_fails();
|
||||
$auth_plugin->authFails();
|
||||
}
|
||||
|
||||
// is a login without password allowed?
|
||||
if (!$cfg['Server']['AllowNoPassword'] && $cfg['Server']['password'] == '') {
|
||||
$login_without_password_is_forbidden = true;
|
||||
PMA_log_user($cfg['Server']['user'], 'empty-denied');
|
||||
PMA_auth_fails();
|
||||
$auth_plugin->authFails();
|
||||
}
|
||||
|
||||
// if using TCP socket is not needed
|
||||
|
||||
@ -3326,13 +3326,19 @@ function PMA_getTitleForTarget($target)
|
||||
*
|
||||
* @param string $string Text where to do expansion.
|
||||
* @param function $escape Function to call for escaping variable values.
|
||||
* @param function $class The name of the class, if the above function is
|
||||
* actually a method inside a class.
|
||||
* @param array $updates Array with overrides for default parameters
|
||||
* (obtained from GLOBALS).
|
||||
* (obtained from GLOBALS).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_expandUserString($string, $escape = null, $updates = array())
|
||||
{
|
||||
function PMA_expandUserString(
|
||||
$string,
|
||||
$escape = null,
|
||||
$class = null,
|
||||
$updates = array()
|
||||
) {
|
||||
/* Content */
|
||||
$vars['http_host'] = PMA_getenv('HTTP_HOST');
|
||||
$vars['server_name'] = $GLOBALS['cfg']['Server']['host'];
|
||||
@ -3374,7 +3380,13 @@ function PMA_expandUserString($string, $escape = null, $updates = array())
|
||||
/* Optional escaping */
|
||||
if (! is_null($escape)) {
|
||||
foreach ($replace as $key => $val) {
|
||||
$replace[$key] = $escape($val);
|
||||
if (is_null($class)) {
|
||||
// Use as function
|
||||
$replace[$key] = $escape($val);
|
||||
} else {
|
||||
// Use as method
|
||||
call_user_func($class . "::" . $escape, $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -3390,7 +3402,16 @@ function PMA_expandUserString($string, $escape = null, $updates = array())
|
||||
$column_names = array();
|
||||
foreach ($columns_list as $column) {
|
||||
if (! is_null($escape)) {
|
||||
$column_names[] = $escape($column['Field']);
|
||||
if (is_null($class)) {
|
||||
// Use as function
|
||||
$column_names[] = $escape($column['Field']);
|
||||
} else {
|
||||
// Use as method
|
||||
$column_names[] = call_user_func(
|
||||
$class . "::" . $escape,
|
||||
$column['Field']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$column_names[] = $column['Field'];
|
||||
}
|
||||
@ -3457,17 +3478,19 @@ function PMA_getSelectUploadFileBlock($import_list, $uploaddir)
|
||||
. '</label>';
|
||||
|
||||
$extensions = '';
|
||||
foreach ($import_list as $val) {
|
||||
foreach ($import_list as $plugin) {
|
||||
$properties = $plugin->getProperties();
|
||||
if (! empty($extensions)) {
|
||||
$extensions .= '|';
|
||||
}
|
||||
$extensions .= $val['extension'];
|
||||
$extensions .= $properties['extension'];
|
||||
}
|
||||
|
||||
$matcher = '@\.(' . $extensions . ')(\.('
|
||||
. PMA_supportedDecompressions() . '))?$@';
|
||||
|
||||
$active = (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed']
|
||||
$active = (isset($GLOBALS['timeout_passed'])
|
||||
&& $GLOBALS['timeout_passed']
|
||||
&& isset($local_import_file))
|
||||
? $local_import_file
|
||||
: '';
|
||||
@ -3653,6 +3676,7 @@ function PMA_getGISDatatypes($upper_case = false)
|
||||
$gis_data_types[$i] = strtoupper($gis_data_types[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $gis_data_types;
|
||||
}
|
||||
|
||||
|
||||
@ -1680,9 +1680,9 @@ $cfg['Export']['pdf_structure_or_data'] = 'data';
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @global string $cfg['Export']['php_array_structure_or_data']
|
||||
* @global string $cfg['Export']['phparray_structure_or_data']
|
||||
*/
|
||||
$cfg['Export']['php_array_structure_or_data'] = 'data';
|
||||
$cfg['Export']['phparray_structure_or_data'] = 'data';
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@ -122,7 +122,8 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu
|
||||
// go back to main login if it fails
|
||||
if (! $auxiliary_connection) {
|
||||
PMA_log_user($user, 'drizzle-denied');
|
||||
PMA_auth_fails();
|
||||
global $auth_plugin;
|
||||
$auth_plugin->authFails();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -125,7 +125,8 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu
|
||||
// go back to main login if it fails
|
||||
if (! $auxiliary_connection) {
|
||||
PMA_log_user($user, 'mysql-denied');
|
||||
PMA_auth_fails();
|
||||
global $auth_plugin;
|
||||
$auth_plugin->authFails();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -199,7 +199,8 @@ function PMA_DBI_connect($user, $password, $is_controluser = false, $server = nu
|
||||
// go back to main login if it fails
|
||||
if (! $auxiliary_connection) {
|
||||
PMA_log_user($user, 'mysql-denied');
|
||||
PMA_auth_fails();
|
||||
global $auth_plugin;
|
||||
$auth_plugin->authFails();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -33,11 +33,20 @@ function PMA_exportIsActive($what, $val)
|
||||
}
|
||||
|
||||
/* Scan for plugins */
|
||||
$export_list = PMA_getPlugins('./libraries/export/', array('export_type' => $export_type, 'single_table' => isset($single_table)));
|
||||
$export_list = PMA_getPlugins(
|
||||
"export",
|
||||
'libraries/plugins/export/',
|
||||
array(
|
||||
'export_type' => $export_type,
|
||||
'single_table' => isset($single_table)
|
||||
)
|
||||
);
|
||||
|
||||
/* Fail if we didn't find any plugin */
|
||||
if (empty($export_list)) {
|
||||
PMA_Message::error(__('Could not load export plugins, please check your installation!'))->display();
|
||||
PMA_Message::error(__(
|
||||
'Could not load export plugins, please check your installation!'
|
||||
))->display();
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
@ -16,11 +16,17 @@ require_once './libraries/plugin_interface.lib.php';
|
||||
require_once './libraries/display_import_ajax.lib.php';
|
||||
|
||||
/* Scan for plugins */
|
||||
$import_list = PMA_getPlugins('./libraries/import/', $import_type);
|
||||
$import_list = PMA_getPlugins(
|
||||
"import",
|
||||
'libraries/plugins/import/',
|
||||
$import_type
|
||||
);
|
||||
|
||||
/* Fail if we didn't find any plugin */
|
||||
if (empty($import_list)) {
|
||||
PMA_Message::error(__('Could not load import plugins, please check your installation!'))->display();
|
||||
PMA_Message::error(__(
|
||||
'Could not load import plugins, please check your installation!'
|
||||
))->display();
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
@ -38,7 +44,7 @@ if (empty($import_list)) {
|
||||
$('#upload_form_status').css("display", "inline"); // show progress bar
|
||||
$('#upload_form_status_info').css("display", "inline"); // - || -
|
||||
<?php
|
||||
if ($_SESSION[$SESSION_KEY]["handler"] != "noplugin") {
|
||||
if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
|
||||
?>
|
||||
var finished = false;
|
||||
var percent = 0.0;
|
||||
@ -155,10 +161,12 @@ if ($_SESSION[$SESSION_KEY]["handler"] != "noplugin") {
|
||||
</script>
|
||||
<form action="import.php" method="post" enctype="multipart/form-data"
|
||||
name="import"<?php
|
||||
if ($_SESSION[$SESSION_KEY]["handler"] != "noplugin") {
|
||||
if ($_SESSION[$SESSION_KEY]["handler"] != "UploadNoplugin") {
|
||||
echo ' target="import_upload_iframe"';
|
||||
} ?>>
|
||||
<input type="hidden" name="<?php echo $ID_KEY; ?>" value="<?php echo $upload_id ; ?>" />
|
||||
<input type="hidden" name="<?php
|
||||
echo $_SESSION[$SESSION_KEY]["handler"]::getIdKey();
|
||||
?>" value="<?php echo $upload_id ; ?>" />
|
||||
<?php
|
||||
if ($import_type == 'server') {
|
||||
echo PMA_generate_common_hidden_inputs('', '', 1);
|
||||
|
||||
@ -5,10 +5,10 @@
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* constant for differenciating array in $_SESSION variable
|
||||
*/
|
||||
@ -32,7 +32,7 @@ $upload_id = uniqid("");
|
||||
*/
|
||||
$plugins = array(
|
||||
"session",
|
||||
"uploadprogress",
|
||||
"progress",
|
||||
"apc",
|
||||
"noplugin"
|
||||
);
|
||||
@ -42,8 +42,9 @@ foreach ($plugins as $plugin) {
|
||||
$check = "PMA_import_" . $plugin . "Check";
|
||||
|
||||
if ($check()) {
|
||||
$_SESSION[$SESSION_KEY]["handler"] = $plugin;
|
||||
include_once "import/upload/" . $plugin . ".php";
|
||||
$upload_class = "Upload" . ucwords($plugin);
|
||||
$_SESSION[$SESSION_KEY]["handler"] = $upload_class;
|
||||
include_once "plugins/import/upload/" . $upload_class . ".class.php";
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -71,7 +72,7 @@ function PMA_import_apcCheck()
|
||||
* @return boolean true if UploadProgress extension is available,
|
||||
* false if it is not
|
||||
*/
|
||||
function PMA_import_uploadprogressCheck()
|
||||
function PMA_import_progressCheck()
|
||||
{
|
||||
if (! function_exists("uploadprogress_get_info")
|
||||
|| ! function_exists('getallheaders')
|
||||
|
||||
@ -1,456 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build NHibernate dumps of tables
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage Codegen
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets executed twice so avoid a notice
|
||||
*/
|
||||
if (! defined('CG_FORMAT_NHIBERNATE_CS')) {
|
||||
define("CG_FORMAT_NHIBERNATE_CS", "NHibernate C# DO");
|
||||
define("CG_FORMAT_NHIBERNATE_XML", "NHibernate XML");
|
||||
|
||||
define("CG_HANDLER_NHIBERNATE_CS_BODY", "handleNHibernateCSBody");
|
||||
define("CG_HANDLER_NHIBERNATE_XML_BODY", "handleNHibernateXMLBody");
|
||||
}
|
||||
|
||||
$CG_FORMATS = array(
|
||||
CG_FORMAT_NHIBERNATE_CS,
|
||||
CG_FORMAT_NHIBERNATE_XML
|
||||
);
|
||||
$CG_HANDLERS = array(
|
||||
CG_HANDLER_NHIBERNATE_CS_BODY,
|
||||
CG_HANDLER_NHIBERNATE_XML_BODY
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['codegen'] = array(
|
||||
'text' => 'CodeGen',
|
||||
'extension' => 'cs',
|
||||
'mime_type' => 'text/cs',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['codegen']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array('type' => 'select',
|
||||
'name' => 'format',
|
||||
'text' => __('Format:'),
|
||||
'values' => $CG_FORMATS
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Set of functions used to build exports of tables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $CG_FORMATS, $CG_HANDLERS, $what;
|
||||
$format = $GLOBALS[$what . '_format'];
|
||||
if (isset($CG_FORMATS[$format])) {
|
||||
return PMA_exportOutputHandler(
|
||||
$CG_HANDLERS[$format]($db, $table, $crlf)
|
||||
);
|
||||
}
|
||||
return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
|
||||
}
|
||||
|
||||
/**
|
||||
* TableProperty class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage Codegen
|
||||
*/
|
||||
class TableProperty
|
||||
{
|
||||
public $name;
|
||||
public $type;
|
||||
public $nullable;
|
||||
public $key;
|
||||
public $defaultValue;
|
||||
public $ext;
|
||||
function __construct($row)
|
||||
{
|
||||
$this->name = trim($row[0]);
|
||||
$this->type = trim($row[1]);
|
||||
$this->nullable = trim($row[2]);
|
||||
$this->key = trim($row[3]);
|
||||
$this->defaultValue = trim($row[4]);
|
||||
$this->ext = trim($row[5]);
|
||||
}
|
||||
function getPureType()
|
||||
{
|
||||
$pos=strpos($this->type, "(");
|
||||
if ($pos > 0) {
|
||||
return substr($this->type, 0, $pos);
|
||||
}
|
||||
return $this->type;
|
||||
}
|
||||
function isNotNull()
|
||||
{
|
||||
return $this->nullable == "NO" ? "true" : "false";
|
||||
}
|
||||
function isUnique()
|
||||
{
|
||||
return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
|
||||
}
|
||||
function getDotNetPrimitiveType()
|
||||
{
|
||||
if (strpos($this->type, "int") === 0) {
|
||||
return "int";
|
||||
}
|
||||
if (strpos($this->type, "long") === 0) {
|
||||
return "long";
|
||||
}
|
||||
if (strpos($this->type, "char") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "varchar") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "text") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "longtext") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "tinyint") === 0) {
|
||||
return "bool";
|
||||
}
|
||||
if (strpos($this->type, "datetime") === 0) {
|
||||
return "DateTime";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
function getDotNetObjectType()
|
||||
{
|
||||
if (strpos($this->type, "int") === 0) {
|
||||
return "Int32";
|
||||
}
|
||||
if (strpos($this->type, "long") === 0) {
|
||||
return "Long";
|
||||
}
|
||||
if (strpos($this->type, "char") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "varchar") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "text") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "longtext") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "tinyint") === 0) {
|
||||
return "Boolean";
|
||||
}
|
||||
if (strpos($this->type, "datetime") === 0) {
|
||||
return "DateTime";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
function getIndexName()
|
||||
{
|
||||
if (strlen($this->key) > 0) {
|
||||
return "index=\""
|
||||
. htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8')
|
||||
. "\"";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
function isPK()
|
||||
{
|
||||
return $this->key=="PRI";
|
||||
}
|
||||
function formatCs($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#name#",
|
||||
cgMakeIdentifier($this->name, false),
|
||||
$text
|
||||
);
|
||||
return $this->format($text);
|
||||
}
|
||||
function formatXml($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#name#",
|
||||
htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#indexName#",
|
||||
$this->getIndexName(),
|
||||
$text
|
||||
);
|
||||
return $this->format($text);
|
||||
}
|
||||
function format($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#ucfirstName#",
|
||||
cgMakeIdentifier($this->name),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#dotNetPrimitiveType#",
|
||||
$this->getDotNetPrimitiveType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#dotNetObjectType#",
|
||||
$this->getDotNetObjectType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#type#",
|
||||
$this->getPureType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#notNull#",
|
||||
$this->isNotNull(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#unique#",
|
||||
$this->isUnique(),
|
||||
$text
|
||||
);
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
function cgMakeIdentifier($str, $ucfirst = true)
|
||||
{
|
||||
// remove unsafe characters
|
||||
$str = preg_replace('/[^\p{L}\p{Nl}_]/u', '', $str);
|
||||
// make sure first character is a letter or _
|
||||
if (! preg_match('/^\pL/u', $str)) {
|
||||
$str = '_' . $str;
|
||||
}
|
||||
if ($ucfirst) {
|
||||
$str = ucfirst($str);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
function handleNHibernateCSBody($db, $table, $crlf)
|
||||
{
|
||||
$lines = array();
|
||||
$result = PMA_DBI_query(
|
||||
sprintf('DESC %s.%s', PMA_backquote($db), PMA_backquote($table))
|
||||
);
|
||||
if ($result) {
|
||||
$tableProperties = array();
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$tableProperties[] = new TableProperty($row);
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
$lines[] = 'using System;';
|
||||
$lines[] = 'using System.Collections;';
|
||||
$lines[] = 'using System.Collections.Generic;';
|
||||
$lines[] = 'using System.Text;';
|
||||
$lines[] = 'namespace ' . cgMakeIdentifier($db);
|
||||
$lines[] = '{';
|
||||
$lines[] = ' #region ' . cgMakeIdentifier($table);
|
||||
$lines[] = ' public class ' . cgMakeIdentifier($table);
|
||||
$lines[] = ' {';
|
||||
$lines[] = ' #region Member Variables';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' protected #dotNetPrimitiveType# _#name#;'
|
||||
);
|
||||
}
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' #region Constructors';
|
||||
$lines[] = ' public ' . cgMakeIdentifier($table).'() { }';
|
||||
$temp = array();
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
if (! $tableProperty->isPK()) {
|
||||
$temp[] = $tableProperty->formatCs(
|
||||
'#dotNetPrimitiveType# #name#'
|
||||
);
|
||||
}
|
||||
}
|
||||
$lines[] = ' public '
|
||||
. cgMakeIdentifier($table)
|
||||
. '('
|
||||
. implode(', ', $temp)
|
||||
. ')';
|
||||
$lines[] = ' {';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
if (! $tableProperty->isPK()) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' this._#name#=#name#;'
|
||||
);
|
||||
}
|
||||
}
|
||||
$lines[] = ' }';
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' #region Public Properties';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' public virtual #dotNetPrimitiveType# #ucfirstName#'
|
||||
. "\n"
|
||||
. ' {' . "\n"
|
||||
. ' get {return _#name#;}' . "\n"
|
||||
. ' set {_#name#=value;}' . "\n"
|
||||
. ' }'
|
||||
);
|
||||
}
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' }';
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = '}';
|
||||
}
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
function handleNHibernateXMLBody($db, $table, $crlf)
|
||||
{
|
||||
$lines = array();
|
||||
$lines[] = '<?xml version="1.0" encoding="utf-8" ?' . '>';
|
||||
$lines[] = '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" '
|
||||
. 'namespace="' . cgMakeIdentifier($db) . '" '
|
||||
. 'assembly="' . cgMakeIdentifier($db) . '">';
|
||||
$lines[] = ' <class '
|
||||
. 'name="' . cgMakeIdentifier($table) . '" '
|
||||
. 'table="' . cgMakeIdentifier($table) . '">';
|
||||
$result = PMA_DBI_query(
|
||||
sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table))
|
||||
);
|
||||
if ($result) {
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$tableProperty = new TableProperty($row);
|
||||
if ($tableProperty->isPK()) {
|
||||
$lines[] = $tableProperty->formatXml(
|
||||
' <id name="#ucfirstName#" type="#dotNetObjectType#"'
|
||||
. ' unsaved-value="0">' . "\n"
|
||||
. ' <column name="#name#" sql-type="#type#"'
|
||||
. ' not-null="#notNull#" unique="#unique#"'
|
||||
. ' index="PRIMARY"/>' . "\n"
|
||||
. ' <generator class="native" />' . "\n"
|
||||
. ' </id>'
|
||||
);
|
||||
} else {
|
||||
$lines[] = $tableProperty->formatXml(
|
||||
' <property name="#ucfirstName#"'
|
||||
. ' type="#dotNetObjectType#">' . "\n"
|
||||
. ' <column name="#name#" sql-type="#type#"'
|
||||
. ' not-null="#notNull#" #indexName#/>' . "\n"
|
||||
. ' </property>'
|
||||
);
|
||||
}
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
}
|
||||
$lines[] = ' </class>';
|
||||
$lines[] = '</hibernate-mapping>';
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build CSV dumps of tables for excel
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage CSV-Excel
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['excel'] = array(
|
||||
'text' => __('CSV for MS Excel'),
|
||||
'extension' => 'csv',
|
||||
'mime_type' => 'text/comma-separated-values',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['excel']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'removeCRLF',
|
||||
'text' => __(
|
||||
'Remove carriage return/line feed characters within columns'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'name' => 'edition',
|
||||
'values' => array(
|
||||
'win' => 'Windows',
|
||||
'mac_excel2003' => 'Excel 2003 / Macintosh',
|
||||
'mac_excel2008' => 'Excel 2008 / Macintosh'),
|
||||
'text' => __('Excel edition:')),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
/* Everything rest is coded in csv plugin */
|
||||
include './libraries/export/csv.php';
|
||||
}
|
||||
?>
|
||||
@ -1,334 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build MediaWiki dumps of tables
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage MediaWiki
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['mediawiki'] = array(
|
||||
'text' => __('MediaWiki Table'),
|
||||
'extension' => 'mediawiki',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
// general options
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
);
|
||||
|
||||
// what to dump (structure/data/both)
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'begin_subgroup',
|
||||
'subgroup_header' => array(
|
||||
'type' => 'message_only',
|
||||
'text' => __('Dump table')
|
||||
)
|
||||
);
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
);
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'end_subgroup'
|
||||
);
|
||||
|
||||
// export table name
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'caption',
|
||||
'text' => __('Export table names')
|
||||
);
|
||||
|
||||
// export table headers
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'headers',
|
||||
'text' => __('Export table headers')
|
||||
);
|
||||
|
||||
// end general options
|
||||
$plugin_list['mediawiki']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Outputs comments containing info about the exported tables
|
||||
*
|
||||
* @param string $text Text of comment
|
||||
*
|
||||
* @return string The formatted comment
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function PMA_exportComment($text = '')
|
||||
{
|
||||
// see http://www.mediawiki.org/wiki/Help:Formatting
|
||||
$comment = PMA_exportCRLF();
|
||||
$comment .= '<!--' . PMA_exportCRLF();
|
||||
$comment .= $text . PMA_exportCRLF();
|
||||
$comment .= '-->' . str_repeat(PMA_exportCRLF(), 2);
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CRLF
|
||||
*
|
||||
* @return string CRLF
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function PMA_exportCRLF()
|
||||
{
|
||||
// The CRLF expected by the mediawiki format is "\n"
|
||||
return "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $export_mode 'create_table','triggers','create_view',
|
||||
* 'stand_in'
|
||||
* @param string $export_type 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column comments
|
||||
* as comments in the structure; this is deprecated
|
||||
* but the parameter is left here because export.php
|
||||
* calls PMA_exportStructure() also for other export
|
||||
* types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
$error_url,
|
||||
$export_mode,
|
||||
$export_type,
|
||||
$do_relation = false,
|
||||
$do_comments = false,
|
||||
$do_mime = false,
|
||||
$dates = false
|
||||
) {
|
||||
switch($export_mode) {
|
||||
case 'create_table':
|
||||
$columns = PMA_DBI_get_columns($db, $table);
|
||||
$columns = array_values($columns);
|
||||
$row_cnt = count($columns);
|
||||
|
||||
// Print structure comment
|
||||
$output = PMA_exportComment(
|
||||
"Table structure for "
|
||||
. PMA_backquote($table)
|
||||
);
|
||||
|
||||
// Begin the table construction
|
||||
$output .= "{| class=\"wikitable\" style=\"text-align:center;\""
|
||||
. PMA_exportCRLF();
|
||||
|
||||
// Add the table name
|
||||
if ($GLOBALS['mediawiki_caption']) {
|
||||
$output .= "|+'''" . $table . "'''" . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
if ($GLOBALS['mediawiki_headers']) {
|
||||
$output .= "|- style=\"background:#ffdead;\"" . PMA_exportCRLF();
|
||||
$output .= "! style=\"background:#ffffff\" | " . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Field']. PMA_exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the table structure
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Type" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Type'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Null" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Null'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Default" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Default'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
$output .= "! Extra" . PMA_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Extra'] . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|}" . str_repeat(PMA_exportCRLF(), 2);
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
return PMA_exportOutputHandler($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in MediaWiki format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
$error_url,
|
||||
$sql_query
|
||||
) {
|
||||
// Print data comment
|
||||
$output = PMA_exportComment("Table data for ". PMA_backquote($table));
|
||||
|
||||
// Begin the table construction
|
||||
// Use the "wikitable" class for style
|
||||
// Use the "sortable" class for allowing tables to be sorted by column
|
||||
$output .= "{| class=\"wikitable sortable\" style=\"text-align:center;\""
|
||||
. PMA_exportCRLF();
|
||||
|
||||
// Add the table name
|
||||
if ($GLOBALS['mediawiki_caption']) {
|
||||
$output .= "|+'''" . $table . "'''" . PMA_exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
if ($GLOBALS['mediawiki_headers']) {
|
||||
// Get column names
|
||||
$column_names = PMA_DBI_get_column_names($db, $table);
|
||||
|
||||
// Add column names as table headers
|
||||
if ( ! is_null($column_names) ) {
|
||||
// Use '|-' for separating rows
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
|
||||
// Use '!' for separating table headers
|
||||
foreach ($column_names as $column) {
|
||||
$output .= " ! " . $column . "" . PMA_exportCRLF();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the table data from the database
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$output .= "|-" . PMA_exportCRLF();
|
||||
|
||||
// Use '|' for separating table columns
|
||||
for ($i = 0; $i < $fields_cnt; ++ $i) {
|
||||
$output .= " | " . $row[$i] . "" . PMA_exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
// End table construction
|
||||
$output .= "|}" . str_repeat(PMA_exportCRLF(), 2);
|
||||
return PMA_exportOutputHandler($output);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,520 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Produce a PDF report (export) from a query
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage PDF
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['pdf'] = array(
|
||||
'text' => __('PDF'),
|
||||
'extension' => 'pdf',
|
||||
'mime_type' => 'application/pdf',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['pdf']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'message_only',
|
||||
'name' => 'explanation',
|
||||
'text' => __(
|
||||
'(Generates a report containing the data of a single table)'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'report_title',
|
||||
'text' => __('Report title:')
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
include_once './libraries/PDF.class.php';
|
||||
|
||||
/**
|
||||
* Adapted from a LGPL script by Philip Clarke
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage PDF
|
||||
*/
|
||||
class PMA_Export_PDF extends PMA_PDF
|
||||
{
|
||||
var $tablewidths;
|
||||
var $headerset;
|
||||
|
||||
function checkPageBreak($h = 0, $y = '', $addpage = true)
|
||||
{
|
||||
if ($this->empty_string($y)) {
|
||||
$y = $this->y;
|
||||
}
|
||||
$current_page = $this->page;
|
||||
if ((($y + $h) > $this->PageBreakTrigger)
|
||||
AND (! $this->InFooter)
|
||||
AND ($this->AcceptPageBreak())
|
||||
) {
|
||||
if ($addpage) {
|
||||
//Automatic page break
|
||||
$x = $this->x;
|
||||
$this->AddPage($this->CurOrientation);
|
||||
$this->y = $this->dataY;
|
||||
$oldpage = $this->page - 1;
|
||||
|
||||
$this_page_orm = $this->pagedim[$this->page]['orm'];
|
||||
$old_page_orm = $this->pagedim[$oldpage]['orm'];
|
||||
$this_page_olm = $this->pagedim[$this->page]['olm'];
|
||||
$old_page_olm = $this->pagedim[$oldpage]['olm'];
|
||||
if ($this->rtl) {
|
||||
if ($this_page_orm!= $old_page_orm) {
|
||||
$this->x = $x - ($this_page_orm - $old_page_orm);
|
||||
} else {
|
||||
$this->x = $x;
|
||||
}
|
||||
} else {
|
||||
if ($this_page_olm != $old_page_olm) {
|
||||
$this->x = $x + ($this_page_olm - $old_page_olm);
|
||||
} else {
|
||||
$this->x = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ($current_page != $this->page) {
|
||||
// account for columns mode
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Header()
|
||||
{
|
||||
global $maxY;
|
||||
// Check if header for this page already exists
|
||||
if (! isset($this->headerset[$this->page])) {
|
||||
$fullwidth = 0;
|
||||
foreach ($this->tablewidths as $width) {
|
||||
$fullwidth += $width;
|
||||
}
|
||||
$this->SetY(($this->tMargin) - ($this->FontSizePt / $this->k) * 5);
|
||||
$this->cellFontSize = $this->FontSizePt ;
|
||||
$this->SetFont(
|
||||
PMA_PDF_FONT,
|
||||
'',
|
||||
($this->titleFontSize
|
||||
? $this->titleFontSize
|
||||
: $this->FontSizePt)
|
||||
);
|
||||
$this->Cell(0, $this->FontSizePt, $this->titleText, 0, 1, 'C');
|
||||
$this->SetFont(PMA_PDF_FONT, '', $this->cellFontSize);
|
||||
$this->SetY(($this->tMargin) - ($this->FontSizePt / $this->k) * 2.5);
|
||||
$this->Cell(
|
||||
0,
|
||||
$this->FontSizePt,
|
||||
__('Database') . ': ' . $this->currentDb . ', '
|
||||
. __('Table') . ': ' . $this->currentTable,
|
||||
0, 1, 'L'
|
||||
);
|
||||
$l = ($this->lMargin);
|
||||
foreach ($this->colTitles as $col => $txt) {
|
||||
$this->SetXY($l, ($this->tMargin));
|
||||
$this->MultiCell(
|
||||
$this->tablewidths[$col],
|
||||
$this->FontSizePt,
|
||||
$txt
|
||||
);
|
||||
$l += $this->tablewidths[$col] ;
|
||||
$maxY = ($maxY < $this->getY()) ? $this->getY() : $maxY ;
|
||||
}
|
||||
$this->SetXY($this->lMargin, $this->tMargin);
|
||||
$this->setFillColor(200, 200, 200);
|
||||
$l = ($this->lMargin);
|
||||
foreach ($this->colTitles as $col => $txt) {
|
||||
$this->SetXY($l, $this->tMargin);
|
||||
$this->cell(
|
||||
$this->tablewidths[$col],
|
||||
$maxY-($this->tMargin),
|
||||
'',
|
||||
1,
|
||||
0,
|
||||
'L',
|
||||
1
|
||||
);
|
||||
$this->SetXY($l, $this->tMargin);
|
||||
$this->MultiCell(
|
||||
$this->tablewidths[$col],
|
||||
$this->FontSizePt,
|
||||
$txt,
|
||||
0,
|
||||
'C'
|
||||
);
|
||||
$l += $this->tablewidths[$col];
|
||||
}
|
||||
$this->setFillColor(255, 255, 255);
|
||||
// set headerset
|
||||
$this->headerset[$this->page] = 1;
|
||||
}
|
||||
|
||||
$this->dataY = $maxY;
|
||||
}
|
||||
|
||||
function morepagestable($lineheight=8)
|
||||
{
|
||||
// some things to set and 'remember'
|
||||
$l = $this->lMargin;
|
||||
$startheight = $h = $this->dataY;
|
||||
$startpage = $currpage = $this->page;
|
||||
|
||||
// calculate the whole width
|
||||
$fullwidth = 0;
|
||||
foreach ($this->tablewidths as $width) {
|
||||
$fullwidth += $width;
|
||||
}
|
||||
|
||||
// Now let's start to write the table
|
||||
$row = 0;
|
||||
$tmpheight = array();
|
||||
$maxpage = $this->page;
|
||||
|
||||
while ($data = PMA_DBI_fetch_row($this->results)) {
|
||||
$this->page = $currpage;
|
||||
// write the horizontal borders
|
||||
$this->Line($l, $h, $fullwidth+$l, $h);
|
||||
// write the content and remember the height of the highest col
|
||||
foreach ($data as $col => $txt) {
|
||||
$this->page = $currpage;
|
||||
$this->SetXY($l, $h);
|
||||
if ($this->tablewidths[$col] > 0) {
|
||||
$this->MultiCell(
|
||||
$this->tablewidths[$col],
|
||||
$lineheight,
|
||||
$txt,
|
||||
0,
|
||||
$this->colAlign[$col]
|
||||
);
|
||||
$l += $this->tablewidths[$col];
|
||||
}
|
||||
|
||||
if (! isset($tmpheight[$row.'-'.$this->page])) {
|
||||
$tmpheight[$row.'-'.$this->page] = 0;
|
||||
}
|
||||
if ($tmpheight[$row.'-'.$this->page] < $this->GetY()) {
|
||||
$tmpheight[$row.'-'.$this->page] = $this->GetY();
|
||||
}
|
||||
if ($this->page > $maxpage) {
|
||||
$maxpage = $this->page;
|
||||
}
|
||||
unset($data[$col]);
|
||||
}
|
||||
|
||||
// get the height we were in the last used page
|
||||
$h = $tmpheight[$row.'-'.$maxpage];
|
||||
// set the "pointer" to the left margin
|
||||
$l = $this->lMargin;
|
||||
// set the $currpage to the last page
|
||||
$currpage = $maxpage;
|
||||
unset($data[$row]);
|
||||
$row++;
|
||||
}
|
||||
// draw the borders
|
||||
// we start adding a horizontal line on the last page
|
||||
$this->page = $maxpage;
|
||||
$this->Line($l, $h, $fullwidth+$l, $h);
|
||||
// now we start at the top of the document and walk down
|
||||
for ($i = $startpage; $i <= $maxpage; $i++) {
|
||||
$this->page = $i;
|
||||
$l = $this->lMargin;
|
||||
$t = ($i == $startpage) ? $startheight : $this->tMargin;
|
||||
$lh = ($i == $maxpage) ? $h : $this->h-$this->bMargin;
|
||||
$this->Line($l, $t, $l, $lh);
|
||||
foreach ($this->tablewidths as $width) {
|
||||
$l += $width;
|
||||
$this->Line($l, $t, $l, $lh);
|
||||
}
|
||||
}
|
||||
// set it to the last page, if not it'll cause some problems
|
||||
$this->page = $maxpage;
|
||||
}
|
||||
|
||||
function setAttributes($attr = array())
|
||||
{
|
||||
foreach ($attr as $key => $val) {
|
||||
$this->$key = $val ;
|
||||
}
|
||||
}
|
||||
|
||||
function setTopMargin($topMargin)
|
||||
{
|
||||
$this->tMargin = $topMargin;
|
||||
}
|
||||
|
||||
function mysqlReport($query)
|
||||
{
|
||||
unset($this->tablewidths);
|
||||
unset($this->colTitles);
|
||||
unset($this->titleWidth);
|
||||
unset($this->colFits);
|
||||
unset($this->display_column);
|
||||
unset($this->colAlign);
|
||||
|
||||
/**
|
||||
* Pass 1 for column widths
|
||||
*/
|
||||
$this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$this->numFields = PMA_DBI_num_fields($this->results);
|
||||
$this->fields = PMA_DBI_get_fields_meta($this->results);
|
||||
|
||||
// sColWidth = starting col width (an average size width)
|
||||
$availableWidth = $this->w - $this->lMargin - $this->rMargin;
|
||||
$this->sColWidth = $availableWidth / $this->numFields;
|
||||
$totalTitleWidth = 0;
|
||||
|
||||
// loop through results header and set initial
|
||||
// col widths/ titles/ alignment
|
||||
// if a col title is less than the starting col width,
|
||||
// reduce that column size
|
||||
$colFits = array();
|
||||
for ($i = 0; $i < $this->numFields; $i++) {
|
||||
$stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ;
|
||||
// save the real title's width
|
||||
$titleWidth[$i] = $stringWidth;
|
||||
$totalTitleWidth += $stringWidth;
|
||||
|
||||
// set any column titles less than the start width to
|
||||
// the column title width
|
||||
if ($stringWidth < $this->sColWidth) {
|
||||
$colFits[$i] = $stringWidth ;
|
||||
}
|
||||
$this->colTitles[$i] = $this->fields[$i]->name;
|
||||
$this->display_column[$i] = true;
|
||||
|
||||
switch ($this->fields[$i]->type) {
|
||||
case 'int':
|
||||
$this->colAlign[$i] = 'R';
|
||||
break;
|
||||
case 'blob':
|
||||
case 'tinyblob':
|
||||
case 'mediumblob':
|
||||
case 'longblob':
|
||||
/**
|
||||
* @todo do not deactivate completely the display
|
||||
* but show the field's name and [BLOB]
|
||||
*/
|
||||
if (stristr($this->fields[$i]->flags, 'BINARY')) {
|
||||
$this->display_column[$i] = false;
|
||||
unset($this->colTitles[$i]);
|
||||
}
|
||||
$this->colAlign[$i] = 'L';
|
||||
break;
|
||||
default:
|
||||
$this->colAlign[$i] = 'L';
|
||||
}
|
||||
}
|
||||
|
||||
// title width verification
|
||||
if ($totalTitleWidth > $availableWidth) {
|
||||
$adjustingMode = true;
|
||||
} else {
|
||||
$adjustingMode = false;
|
||||
// we have enough space for all the titles at their
|
||||
// original width so use the true title's width
|
||||
foreach ($titleWidth as $key => $val) {
|
||||
$colFits[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// loop through the data; any column whose contents
|
||||
// is greater than the column size is resized
|
||||
/**
|
||||
* @todo force here a LIMIT to avoid reading all rows
|
||||
*/
|
||||
while ($row = PMA_DBI_fetch_row($this->results)) {
|
||||
foreach ($colFits as $key => $val) {
|
||||
$stringWidth = $this->getstringwidth($row[$key]) + 6 ;
|
||||
if ($adjustingMode && ($stringWidth > $this->sColWidth)) {
|
||||
// any column whose data's width is bigger than
|
||||
// the start width is now discarded
|
||||
unset($colFits[$key]);
|
||||
} else {
|
||||
// if data's width is bigger than the current column width,
|
||||
// enlarge the column (but avoid enlarging it if the
|
||||
// data's width is very big)
|
||||
if ($stringWidth > $val
|
||||
&& $stringWidth < ($this->sColWidth * 3)
|
||||
) {
|
||||
$colFits[$key] = $stringWidth ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$totAlreadyFitted = 0;
|
||||
foreach ($colFits as $key => $val) {
|
||||
// set fitted columns to smallest size
|
||||
$this->tablewidths[$key] = $val;
|
||||
// to work out how much (if any) space has been freed up
|
||||
$totAlreadyFitted += $val;
|
||||
}
|
||||
|
||||
if ($adjustingMode) {
|
||||
$surplus = (sizeof($colFits) * $this->sColWidth) - $totAlreadyFitted;
|
||||
$surplusToAdd = $surplus / ($this->numFields - sizeof($colFits));
|
||||
} else {
|
||||
$surplusToAdd = 0;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->numFields; $i++) {
|
||||
if (! in_array($i, array_keys($colFits))) {
|
||||
$this->tablewidths[$i] = $this->sColWidth + $surplusToAdd;
|
||||
}
|
||||
if ($this->display_column[$i] == false) {
|
||||
$this->tablewidths[$i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($this->tablewidths);
|
||||
|
||||
PMA_DBI_free_result($this->results);
|
||||
|
||||
// Pass 2
|
||||
|
||||
$this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$this->setY($this->tMargin);
|
||||
$this->AddPage();
|
||||
$this->SetFont(PMA_PDF_FONT, '', 9);
|
||||
$this->morepagestable($this->FontSizePt);
|
||||
PMA_DBI_free_result($this->results);
|
||||
|
||||
} // end of mysqlReport function
|
||||
|
||||
} // end of PMA_Export_PDF class
|
||||
|
||||
$pdf = new PMA_Export_PDF('L', 'pt', 'A3');
|
||||
|
||||
/**
|
||||
* Finalize the pdf.
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
{
|
||||
global $pdf;
|
||||
|
||||
// instead of $pdf->Output():
|
||||
if (! PMA_exportOutputHandler($pdf->getPDFData())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the pdf to export data.
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
{
|
||||
global $pdf_report_title;
|
||||
global $pdf;
|
||||
|
||||
$pdf->Open();
|
||||
|
||||
$attr = array('titleFontSize' => 18, 'titleText' => $pdf_report_title);
|
||||
$pdf->setAttributes($attr);
|
||||
$pdf->setTopMargin(30);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in PDF format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $pdf;
|
||||
|
||||
$attr = array('currentDb' => $db, 'currentTable' => $table);
|
||||
$pdf->setAttributes($attr);
|
||||
$pdf->mysqlReport($sql_query);
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_exportData()' function
|
||||
}
|
||||
?>
|
||||
@ -1,529 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* CSV import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo add an option for handling NULL values
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage CSV
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$analyze = false;
|
||||
|
||||
if ($plugin_param !== 'table') {
|
||||
$analyze = true;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['csv'] = array(
|
||||
'text' => __('CSV'),
|
||||
'extension' => 'csv',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['csv']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'replace',
|
||||
'text' => __('Replace table data with file')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'ignore',
|
||||
'text' => __('Do not abort on INSERT error')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'terminated',
|
||||
'text' => __('Columns separated with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'enclosed',
|
||||
'text' => __('Columns enclosed with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'escaped',
|
||||
'text' => __('Columns escaped with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'new_line',
|
||||
'text' => __('Lines terminated with:'),
|
||||
'size' => 2
|
||||
)
|
||||
);
|
||||
|
||||
if ($plugin_param !== 'table') {
|
||||
$plugin_list['csv']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'col_names',
|
||||
'text' => __(
|
||||
'The first line of the file contains the table column names <i>'
|
||||
. '(if this is unchecked, the first line will become part of the'
|
||||
. ' data)</i>'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$hint = new PMA_Message(
|
||||
__(
|
||||
'If the data in each row of the file is not'
|
||||
. ' in the same order as in the database, list the corresponding'
|
||||
. ' column names here. Column names must be separated by commas'
|
||||
. ' and not enclosed in quotations.'
|
||||
)
|
||||
);
|
||||
$plugin_list['csv']['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'columns',
|
||||
'text' => __('Column names: ') . PMA_showHint($hint)
|
||||
);
|
||||
}
|
||||
|
||||
$plugin_list['csv']['options'][] = array('type' => 'end_group');
|
||||
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$replacements = array(
|
||||
'\\n' => "\n",
|
||||
'\\t' => "\t",
|
||||
'\\r' => "\r",
|
||||
);
|
||||
$csv_terminated = strtr($csv_terminated, $replacements);
|
||||
$csv_enclosed = strtr($csv_enclosed, $replacements);
|
||||
$csv_escaped = strtr($csv_escaped, $replacements);
|
||||
$csv_new_line = strtr($csv_new_line, $replacements);
|
||||
|
||||
$param_error = false;
|
||||
if (strlen($csv_terminated) != 1) {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Columns terminated by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
// The default dialog of MS Excel when generating a CSV produces a
|
||||
// semi-colon-separated file with no chance of specifying the
|
||||
// enclosing character. Thus, users who want to import this file
|
||||
// tend to remove the enclosing character on the Import dialog.
|
||||
// I could not find a test case where having no enclosing characters
|
||||
// confuses this script.
|
||||
// But the parser won't work correctly with strings so we allow just
|
||||
// one character.
|
||||
} elseif (strlen($csv_enclosed) > 1) {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Columns enclosed by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
} elseif (strlen($csv_escaped) != 1) {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Columns escaped by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
} elseif (strlen($csv_new_line) != 1 && $csv_new_line != 'auto') {
|
||||
$message = PMA_Message::error(__('Invalid parameter for CSV import: %s'));
|
||||
$message->addParam(__('Lines terminated by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
}
|
||||
|
||||
// If there is an error in the parameters entered, indicate that immediately.
|
||||
if ($param_error) {
|
||||
PMA_mysqlDie($message->getMessage(), '', '', $err_url);
|
||||
}
|
||||
|
||||
$buffer = '';
|
||||
$required_fields = 0;
|
||||
|
||||
if (! $analyze) {
|
||||
if (isset($csv_replace)) {
|
||||
$sql_template = 'REPLACE';
|
||||
} else {
|
||||
$sql_template = 'INSERT';
|
||||
if (isset($csv_ignore)) {
|
||||
$sql_template .= ' IGNORE';
|
||||
}
|
||||
}
|
||||
$sql_template .= ' INTO ' . PMA_backquote($table);
|
||||
|
||||
$tmp_fields = PMA_DBI_get_columns($db, $table);
|
||||
|
||||
if (empty($csv_columns)) {
|
||||
$fields = $tmp_fields;
|
||||
} else {
|
||||
$sql_template .= ' (';
|
||||
$fields = array();
|
||||
$tmp = preg_split('/,( ?)/', $csv_columns);
|
||||
foreach ($tmp as $key => $val) {
|
||||
if (count($fields) > 0) {
|
||||
$sql_template .= ', ';
|
||||
}
|
||||
/* Trim also `, if user already included backquoted fields */
|
||||
$val = trim($val, " \t\r\n\0\x0B`");
|
||||
$found = false;
|
||||
foreach ($tmp_fields as $id => $field) {
|
||||
if ($field['Field'] == $val) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $found) {
|
||||
$message = PMA_Message::error(
|
||||
__(
|
||||
'Invalid column (%s) specified! Ensure that columns names'
|
||||
. ' are spelled correctly, separated by commas, and not'
|
||||
. ' enclosed in quotes.'
|
||||
)
|
||||
);
|
||||
$message->addParam($val);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
$fields[] = $field;
|
||||
$sql_template .= PMA_backquote($val);
|
||||
}
|
||||
$sql_template .= ') ';
|
||||
}
|
||||
|
||||
$required_fields = count($fields);
|
||||
|
||||
$sql_template .= ' VALUES (';
|
||||
}
|
||||
|
||||
// Defaults for parser
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$line = 1;
|
||||
$lasti = -1;
|
||||
$values = array();
|
||||
$csv_finish = false;
|
||||
|
||||
$tempRow = array();
|
||||
$rows = array();
|
||||
$col_names = array();
|
||||
$tables = array();
|
||||
|
||||
$col_count = 0;
|
||||
$max_cols = 0;
|
||||
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// Handle rest of buffer
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
// Do not parse string when we're not at the end
|
||||
// and don't have new line inside
|
||||
if (($csv_new_line == 'auto'
|
||||
&& strpos($buffer, "\r") === false
|
||||
&& strpos($buffer, "\n") === false)
|
||||
|| ($csv_new_line != 'auto'
|
||||
&& strpos($buffer, $csv_new_line) === false)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Current length of our buffer
|
||||
$len = strlen($buffer);
|
||||
// Currently parsed char
|
||||
$ch = $buffer[$i];
|
||||
while ($i < $len) {
|
||||
// Deadlock protection
|
||||
if ($lasti == $i && $lastlen == $len) {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid format of CSV input on line %d.')
|
||||
);
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
$lasti = $i;
|
||||
$lastlen = $len;
|
||||
|
||||
// This can happen with auto EOL and \r at the end of buffer
|
||||
if (! $csv_finish) {
|
||||
// Grab empty field
|
||||
if ($ch == $csv_terminated) {
|
||||
if ($i == $len - 1) {
|
||||
break;
|
||||
}
|
||||
$values[] = '';
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab one field
|
||||
$fallbacki = $i;
|
||||
if ($ch == $csv_enclosed) {
|
||||
if ($i == $len - 1) {
|
||||
break;
|
||||
}
|
||||
$need_end = true;
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
} else {
|
||||
$need_end = false;
|
||||
}
|
||||
$fail = false;
|
||||
$value = '';
|
||||
while (($need_end
|
||||
&& ( $ch != $csv_enclosed || $csv_enclosed == $csv_escaped ))
|
||||
|| ( ! $need_end
|
||||
&& ! ( $ch == $csv_terminated
|
||||
|| $ch == $csv_new_line
|
||||
|| ( $csv_new_line == 'auto'
|
||||
&& ( $ch == "\r" || $ch == "\n" ) ) ) )
|
||||
) {
|
||||
if ($ch == $csv_escaped) {
|
||||
if ($i == $len - 1) {
|
||||
$fail = true;
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
if ($csv_enclosed == $csv_escaped
|
||||
&& ($ch == $csv_terminated
|
||||
|| $ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n")))
|
||||
) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$value .= $ch;
|
||||
if ($i == $len - 1) {
|
||||
if (! $finished) {
|
||||
$fail = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
|
||||
// unquoted NULL string
|
||||
if (false === $need_end && $value === 'NULL') {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($fail) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
}
|
||||
// Need to strip trailing enclosing char?
|
||||
if ($need_end && $ch == $csv_enclosed) {
|
||||
if ($finished && $i == $len - 1) {
|
||||
$ch = null;
|
||||
} elseif ($i == $len - 1) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
} else {
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
}
|
||||
// Are we at the end?
|
||||
if ($ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))
|
||||
|| ($finished && $i == $len - 1)
|
||||
) {
|
||||
$csv_finish = true;
|
||||
}
|
||||
// Go to next char
|
||||
if ($ch == $csv_terminated) {
|
||||
if ($i == $len - 1) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
// If everything went okay, store value
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
// End of line
|
||||
if ($csv_finish
|
||||
|| $ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))
|
||||
) {
|
||||
if ($csv_new_line == 'auto' && $ch == "\r") { // Handle "\r\n"
|
||||
if ($i >= ($len - 2) && ! $finished) {
|
||||
break; // We need more data to decide new line
|
||||
}
|
||||
if ($buffer[$i + 1] == "\n") {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
// We didn't parse value till the end of line, so there was empty one
|
||||
if (! $csv_finish) {
|
||||
$values[] = '';
|
||||
}
|
||||
|
||||
if ($analyze) {
|
||||
foreach ($values as $ley => $val) {
|
||||
$tempRow[] = $val;
|
||||
++$col_count;
|
||||
}
|
||||
|
||||
if ($col_count > $max_cols) {
|
||||
$max_cols = $col_count;
|
||||
}
|
||||
$col_count = 0;
|
||||
|
||||
$rows[] = $tempRow;
|
||||
$tempRow = array();
|
||||
} else {
|
||||
// Do we have correct count of values?
|
||||
if (count($values) != $required_fields) {
|
||||
|
||||
// Hack for excel
|
||||
if ($values[count($values) - 1] == ';') {
|
||||
unset($values[count($values) - 1]);
|
||||
} else {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid column count in CSV input on line %d.')
|
||||
);
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$first = true;
|
||||
$sql = $sql_template;
|
||||
foreach ($values as $key => $val) {
|
||||
if (! $first) {
|
||||
$sql .= ', ';
|
||||
}
|
||||
if ($val === null) {
|
||||
$sql .= 'NULL';
|
||||
} else {
|
||||
$sql .= '\'' . PMA_sqlAddSlashes($val) . '\'';
|
||||
}
|
||||
|
||||
$first = false;
|
||||
}
|
||||
$sql .= ')';
|
||||
|
||||
/**
|
||||
* @todo maybe we could add original line to verbose SQL in comment
|
||||
*/
|
||||
PMA_importRunQuery($sql, $sql);
|
||||
}
|
||||
|
||||
$line++;
|
||||
$csv_finish = false;
|
||||
$values = array();
|
||||
$buffer = substr($buffer, $i + 1);
|
||||
$len = strlen($buffer);
|
||||
$i = 0;
|
||||
$lasti = -1;
|
||||
$ch = $buffer[0];
|
||||
}
|
||||
} // End of parser loop
|
||||
} // End of import loop
|
||||
|
||||
if ($analyze) {
|
||||
/* Fill out all rows */
|
||||
$num_rows = count($rows);
|
||||
for ($i = 0; $i < $num_rows; ++$i) {
|
||||
for ($j = count($rows[$i]); $j < $max_cols; ++$j) {
|
||||
$rows[$i][] = 'NULL';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['csv_col_names'])) {
|
||||
$col_names = array_splice($rows, 0, 1);
|
||||
$col_names = $col_names[0];
|
||||
}
|
||||
|
||||
if ((isset($col_names) && count($col_names) != $max_cols)
|
||||
|| ! isset($col_names)
|
||||
) {
|
||||
// Fill out column names
|
||||
for ($i = 0; $i < $max_cols; ++$i) {
|
||||
$col_names[] = 'COL '.($i+1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($db)) {
|
||||
$result = PMA_DBI_fetch_result('SHOW TABLES');
|
||||
$tbl_name = 'TABLE '.(count($result) + 1);
|
||||
} else {
|
||||
$tbl_name = 'TBL_NAME';
|
||||
}
|
||||
|
||||
$tables[] = array($tbl_name, $col_names, $rows);
|
||||
|
||||
/* Obtain the best-fit MySQL types for each column */
|
||||
$analyses = array();
|
||||
$analyses[] = PMA_analyzeTable($tables[0]);
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'CSV_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
/* Non-applicable parameters */
|
||||
$create = null;
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
}
|
||||
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
|
||||
if (count($values) != 0 && ! $error) {
|
||||
$message = PMA_Message::error(__('Invalid format of CSV input on line %d.'));
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
}
|
||||
?>
|
||||
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* DocSQL import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage DocSQL
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load relations.
|
||||
*/
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
/**
|
||||
* We need relations enabled and we work only on database
|
||||
*/
|
||||
if ($plugin_param !== 'database' || $GLOBALS['num_tables'] < 1
|
||||
|| ! $cfgRelation['relwork'] || ! $cfgRelation['commwork']
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['docsql'] = array( // set name of your plugin
|
||||
'text' => __('DocSQL'), // text to be displayed as choice
|
||||
'extension' => '', // extension this plugin can handle
|
||||
'options' => array( // array of options for your plugin (optional)
|
||||
array('type' => 'begin_group', 'name' => 'general_opts'),
|
||||
array('type' => 'text', 'name' => 'table', 'text' => __('Table name')),
|
||||
array('type' => 'end_group')
|
||||
),
|
||||
'options_text' => __('Options'), // text to describe plugin options (must be set if options are used)
|
||||
);
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$tab = $_POST['docsql_table'];
|
||||
$buffer = '';
|
||||
/* Read whole buffer, we except it is small enough */
|
||||
while (!$finished && !$error && !$timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// nothing to read
|
||||
break;
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
}
|
||||
} // End of import loop
|
||||
/* Process the data */
|
||||
if ($data === true && !$error && !$timeout_passed) {
|
||||
$buffer = str_replace("\r\n", "\n", $buffer);
|
||||
$buffer = str_replace("\r", "\n", $buffer);
|
||||
$lines = explode("\n", $buffer);
|
||||
foreach ($lines AS $lkey => $line) {
|
||||
//echo '<p>' . $line . '</p>';
|
||||
$inf = explode('|', $line);
|
||||
if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
|
||||
$qry = '
|
||||
INSERT INTO
|
||||
' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['column_info']) . '
|
||||
(db_name, table_name, column_name, comment)
|
||||
VALUES (
|
||||
\'' . PMA_sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($tab)) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($inf[0])) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($inf[1])) . '\')';
|
||||
PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]), true);
|
||||
} // end inf[1] exists
|
||||
if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
|
||||
$for = explode('->', $inf[2]);
|
||||
$qry = '
|
||||
INSERT INTO
|
||||
' . PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['relation']) . '
|
||||
(master_db, master_table, master_field, foreign_db, foreign_table, foreign_field)
|
||||
VALUES (
|
||||
\'' . PMA_sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($tab)) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($inf[0])) . '\',
|
||||
\'' . PMA_sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($for[0])) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($for[1])) . '\')';
|
||||
PMA_importRunQuery($qry, $qry . '-- ' . htmlspecialchars($tab) . '.' . htmlspecialchars($inf[0]) . '(' . htmlspecialchars($inf[2]) . ')', true);
|
||||
} // end inf[2] exists
|
||||
} // End lines loop
|
||||
} // End import
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
?>
|
||||
@ -1,155 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* CSV import plugin for phpMyAdmin using LOAD DATA
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage LDI
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if ($plugin_param !== 'table') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = false;
|
||||
|
||||
$result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';');
|
||||
if ($result != false && PMA_DBI_num_rows($result) > 0) {
|
||||
$tmp = PMA_DBI_fetch_row($result);
|
||||
if ($tmp[1] == 'ON') {
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = true;
|
||||
}
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
unset($result);
|
||||
}
|
||||
$plugin_list['ldi'] = array(
|
||||
'text' => __('CSV using LOAD DATA'),
|
||||
// Following is nonsense, however we want to default to our parser for csv
|
||||
'extension' => 'ldi',
|
||||
'options' => array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'replace',
|
||||
'text' => __('Replace table data with file')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'ignore',
|
||||
'text' => __('Do not abort on INSERT error')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'terminated',
|
||||
'text' => __('Columns terminated by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'enclosed',
|
||||
'text' => __('Columns enclosed by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'escaped',
|
||||
'text' => __('Columns escaped by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'new_line',
|
||||
'text' => __('Lines terminated by'),
|
||||
'size' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'columns',
|
||||
'text' => __('Column names')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'local_option',
|
||||
'text' => __('Use LOCAL keyword')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
|
||||
// We handle only some kind of data!
|
||||
$message = PMA_Message::error(__('This plugin does not support compressed imports!'));
|
||||
$error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'LOAD DATA';
|
||||
if (isset($ldi_local_option)) {
|
||||
$sql .= ' LOCAL';
|
||||
}
|
||||
$sql .= ' INFILE \'' . PMA_sqlAddSlashes($import_file) . '\'';
|
||||
if (isset($ldi_replace)) {
|
||||
$sql .= ' REPLACE';
|
||||
} elseif (isset($ldi_ignore)) {
|
||||
$sql .= ' IGNORE';
|
||||
}
|
||||
$sql .= ' INTO TABLE ' . PMA_backquote($table);
|
||||
|
||||
if (strlen($ldi_terminated) > 0) {
|
||||
$sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
|
||||
}
|
||||
if (strlen($ldi_enclosed) > 0) {
|
||||
$sql .= ' ENCLOSED BY \'' . PMA_sqlAddSlashes($ldi_enclosed) . '\'';
|
||||
}
|
||||
if (strlen($ldi_escaped) > 0) {
|
||||
$sql .= ' ESCAPED BY \'' . PMA_sqlAddSlashes($ldi_escaped) . '\'';
|
||||
}
|
||||
if (strlen($ldi_new_line) > 0) {
|
||||
if ($ldi_new_line == 'auto') {
|
||||
$ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n';
|
||||
}
|
||||
$sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
|
||||
}
|
||||
if ($skip_queries > 0) {
|
||||
$sql .= ' IGNORE ' . $skip_queries . ' LINES';
|
||||
$skip_queries = 0;
|
||||
}
|
||||
if (strlen($ldi_columns) > 0) {
|
||||
$sql .= ' (';
|
||||
$tmp = preg_split('/,( ?)/', $ldi_columns);
|
||||
$cnt_tmp = count($tmp);
|
||||
for ($i = 0; $i < $cnt_tmp; $i++) {
|
||||
if ($i > 0) {
|
||||
$sql .= ', ';
|
||||
}
|
||||
/* Trim also `, if user already included backquoted fields */
|
||||
$sql .= PMA_backquote(trim($tmp[$i], " \t\r\n\0\x0B`"));
|
||||
} // end for
|
||||
$sql .= ')';
|
||||
}
|
||||
|
||||
PMA_importRunQuery($sql, $sql);
|
||||
PMA_importRunQuery();
|
||||
$finished = true;
|
||||
?>
|
||||
@ -1,489 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* MediaWiki import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage MediaWiki
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$analyze = false;
|
||||
if ($plugin_param !== 'table') {
|
||||
$analyze = true;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['mediawiki'] = array(
|
||||
'text' => __('MediaWiki Table'),
|
||||
'extension' => 'txt',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
|
||||
// We do not define function when plugin is just
|
||||
// queried for information above
|
||||
return;
|
||||
}
|
||||
|
||||
// Defaults for parser
|
||||
|
||||
// The buffer that will be used to store chunks read from the imported file
|
||||
$buffer = '';
|
||||
|
||||
// Used as storage for the last part of the current chunk data
|
||||
// Will be appended to the first line of the next chunk, if there is one
|
||||
$last_chunk_line = '';
|
||||
|
||||
// Remembers whether the current buffer line is part of a comment
|
||||
$inside_comment = false;
|
||||
// Remembers whether the current buffer line is part of a data comment
|
||||
$inside_data_comment = false;
|
||||
// Remembers whether the current buffer line is part of a structure comment
|
||||
$inside_structure_comment = false;
|
||||
|
||||
// MediaWiki only accepts "\n" as row terminator
|
||||
$mediawiki_new_line = "\n";
|
||||
|
||||
// Initialize the name of the current table
|
||||
$cur_table_name = "";
|
||||
|
||||
while (! $finished && ! $error && ! $timeout_passed ) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
|
||||
if ($data === false) {
|
||||
// Subtract data we didn't handle yet and stop processing
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// Handle rest of buffer
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer = $data;
|
||||
unset($data);
|
||||
// Don't parse string if we're not at the end
|
||||
// and don't have a new line inside
|
||||
if ( strpos($buffer, $mediawiki_new_line) === false ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Because of reading chunk by chunk, the first line from the buffer
|
||||
// contains only a portion of an actual line from the imported file.
|
||||
// Therefore, we have to append it to the last line from the previous
|
||||
// chunk. If we are at the first chunk, $last_chunk_line should be empty.
|
||||
$buffer = $last_chunk_line . $buffer;
|
||||
|
||||
// Process the buffer line by line
|
||||
$buffer_lines = explode($mediawiki_new_line, $buffer);
|
||||
|
||||
$full_buffer_lines_count = count($buffer_lines);
|
||||
// If the reading is not finalised, the final line of the current chunk
|
||||
// will not be complete
|
||||
if (! $finished) {
|
||||
$full_buffer_lines_count -= 1;
|
||||
$last_chunk_line = $buffer_lines[$full_buffer_lines_count];
|
||||
}
|
||||
|
||||
for ($line_nr = 0; $line_nr < $full_buffer_lines_count; ++ $line_nr) {
|
||||
$cur_buffer_line = trim($buffer_lines[$line_nr]);
|
||||
|
||||
// If the line is empty, go to the next one
|
||||
if ( $cur_buffer_line === '' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$first_character = $cur_buffer_line[0];
|
||||
$matches = array();
|
||||
|
||||
// Check beginnning of comment
|
||||
if (! strcmp(substr($cur_buffer_line, 0, 4), "<!--")) {
|
||||
$inside_comment = true;
|
||||
continue;
|
||||
} elseif ($inside_comment) {
|
||||
// Check end of comment
|
||||
if (! strcmp(substr($cur_buffer_line, 0, 4), "-->")) {
|
||||
// Only data comments are closed. The structure comments will
|
||||
// be closed when a data comment begins (in order to skip
|
||||
// structure tables)
|
||||
if ($inside_data_comment) {
|
||||
$inside_data_comment = false;
|
||||
}
|
||||
|
||||
// End comments that are not related to table structure
|
||||
if (! $inside_structure_comment) {
|
||||
$inside_comment = false;
|
||||
}
|
||||
} else {
|
||||
// Check table name
|
||||
$match_table_name = array();
|
||||
if (preg_match(
|
||||
"/^Table data for `(.*)`$/",
|
||||
$cur_buffer_line,
|
||||
$match_table_name
|
||||
)
|
||||
) {
|
||||
$cur_table_name = $match_table_name[1];
|
||||
$inside_data_comment = true;
|
||||
|
||||
// End ignoring structure rows
|
||||
if ($inside_structure_comment) {
|
||||
$inside_structure_comment = false;
|
||||
}
|
||||
} elseif (preg_match(
|
||||
"/^Table structure for `(.*)`$/",
|
||||
$cur_buffer_line,
|
||||
$match_table_name
|
||||
)
|
||||
) {
|
||||
// The structure comments will be ignored
|
||||
$inside_structure_comment = true;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
} elseif (preg_match('/^\{\|(.*)$/', $cur_buffer_line, $matches)) {
|
||||
// Check start of table
|
||||
|
||||
// This will store all the column info on all rows from
|
||||
// the current table read from the buffer
|
||||
$cur_temp_table = array();
|
||||
|
||||
// Will be used as storage for the current row in the buffer
|
||||
// Once all its columns are read, it will be added to
|
||||
// $cur_temp_table and then it will be emptied
|
||||
$cur_temp_line = array();
|
||||
|
||||
// Helps us differentiate the header columns
|
||||
// from the normal columns
|
||||
$in_table_header = false;
|
||||
// End processing because the current line does not
|
||||
// contain any column information
|
||||
} elseif (substr($cur_buffer_line, 0, 2) === '|-'
|
||||
|| substr($cur_buffer_line, 0, 2) === '|+'
|
||||
|| substr($cur_buffer_line, 0, 2) === '|}'
|
||||
) {
|
||||
// Check begin row or end table
|
||||
|
||||
// Add current line to the values storage
|
||||
if (! empty($cur_temp_line)) {
|
||||
// If the current line contains header cells ( marked with '!' ),
|
||||
// it will be marked as table header
|
||||
if ( $in_table_header ) {
|
||||
// Set the header columns
|
||||
$cur_temp_table_headers = $cur_temp_line;
|
||||
} else {
|
||||
// Normal line, add it to the table
|
||||
$cur_temp_table [] = $cur_temp_line;
|
||||
}
|
||||
}
|
||||
|
||||
// Empty the temporary buffer
|
||||
$cur_temp_line = array();
|
||||
|
||||
// No more processing required at the end of the table
|
||||
if (substr($cur_buffer_line, 0, 2) === '|}') {
|
||||
$current_table = array(
|
||||
$cur_table_name,
|
||||
$cur_temp_table_headers,
|
||||
$cur_temp_table
|
||||
);
|
||||
|
||||
// Import the current table data into the database
|
||||
PMA_importDataOneTable($current_table);
|
||||
|
||||
// Reset table name
|
||||
$cur_table_name = "";
|
||||
}
|
||||
// What's after the row tag is now only attributes
|
||||
|
||||
} elseif (($first_character === '|') || ($first_character === '!')) {
|
||||
// Check cell elements
|
||||
|
||||
// Header cells
|
||||
if ($first_character === '!') {
|
||||
// Mark as table header, but treat as normal row
|
||||
$cur_buffer_line = str_replace('!!', '||', $cur_buffer_line);
|
||||
// Will be used to set $cur_temp_line as table header
|
||||
$in_table_header = true;
|
||||
} else {
|
||||
$in_table_header = false;
|
||||
}
|
||||
|
||||
// Loop through each table cell
|
||||
$cells = PMA_explodeMarkup($cur_buffer_line);
|
||||
foreach ($cells as $cell) {
|
||||
// A cell could contain both parameters and data
|
||||
$cell_data = explode('|', $cell, 2);
|
||||
|
||||
// A '|' inside an invalid link should not
|
||||
// be mistaken as delimiting cell parameters
|
||||
if (strpos($cell_data[0], '[[') === true ) {
|
||||
if (count($cell_data) == 1) {
|
||||
$cell = $cell_data[0];
|
||||
} else {
|
||||
$cell = $cell_data[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the beginning of the column, if there is one
|
||||
$cell = trim($cell);
|
||||
$col_start_chars = array( "|", "!");
|
||||
foreach ($col_start_chars as $col_start_char) {
|
||||
if (strpos($cell, $col_start_char) === 0) {
|
||||
$cell = trim(substr($cell, 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the cell to the row
|
||||
$cur_temp_line [] = $cell;
|
||||
} // foreach $cells
|
||||
} else {
|
||||
// If it's none of the above, then the current line has a bad format
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid format of mediawiki input on line: <br />%s.')
|
||||
);
|
||||
$message->addParam($cur_buffer_line);
|
||||
$error = true;
|
||||
}
|
||||
} // End treating full buffer lines
|
||||
} // while - finished parsing buffer
|
||||
|
||||
/**
|
||||
* Imports data from a single table
|
||||
*
|
||||
* @param array $table containing all table info:
|
||||
* <code>
|
||||
* $table[0] - string containing table name
|
||||
* $table[1] - array[] of table headers
|
||||
* $table[2] - array[][] of table content rows
|
||||
* </code>
|
||||
*
|
||||
* @global bool $analyze whether to scan for column types
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_importDataOneTable ($table)
|
||||
{
|
||||
global $analyze;
|
||||
if ($analyze) {
|
||||
// Set the table name
|
||||
PMA_setTableName($table[0]);
|
||||
|
||||
// Set generic names for table headers if they don't exist
|
||||
PMA_setTableHeaders($table[1], $table[2][0]);
|
||||
|
||||
// Create the tables array to be used in PMA_buildSQL()
|
||||
$tables = array();
|
||||
$tables [] = array($table[0], $table[1], $table[2]);
|
||||
|
||||
// Obtain the best-fit MySQL types for each column
|
||||
$analyses = array();
|
||||
$analyses [] = PMA_analyzeTable($tables[0]);
|
||||
|
||||
PMA_executeImportTables($tables, $analyses);
|
||||
}
|
||||
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table name
|
||||
*
|
||||
* @param string &$table_name reference to the name of the table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_setTableName(&$table_name)
|
||||
{
|
||||
if (empty($table_name)) {
|
||||
$result = PMA_DBI_fetch_result('SHOW TABLES');
|
||||
// todo check if the name below already exists
|
||||
$table_name = 'TABLE '.(count($result) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set generic names for table headers, if they don't exist
|
||||
*
|
||||
* @param array &$table_headers reference to the array containing the headers
|
||||
* of a table
|
||||
* @param array $table_row array containing the first content row
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_setTableHeaders(&$table_headers, $table_row)
|
||||
{
|
||||
if (empty($table_headers)) {
|
||||
// The first table row should contain the number of columns
|
||||
// If they are not set, generic names will be given (COL 1, COL 2, etc)
|
||||
$num_cols = count($table_row);
|
||||
for ($i = 0; $i < $num_cols; ++ $i) {
|
||||
$table_headers [$i] = 'COL '. ($i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database name and additional options and calls PMA_buildSQL()
|
||||
* Used in PMA_importDataAllTables() and PMA_importDataOneTable()
|
||||
*
|
||||
* @param array &$tables structure:
|
||||
* array(
|
||||
* array(table_name, array() column_names, array()() rows)
|
||||
* )
|
||||
* @param array &$analyses structure:
|
||||
* $analyses = array(
|
||||
* array(array() column_types, array() column_sizes)
|
||||
* )
|
||||
*
|
||||
* @global string $db name of the database to import in
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function PMA_executeImportTables(&$tables, &$analyses)
|
||||
{
|
||||
global $db;
|
||||
|
||||
// $db_name : The currently selected database name, if applicable
|
||||
// No backquotes
|
||||
// $options : An associative array of options
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'mediawiki_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
// Array of SQL strings
|
||||
// Non-applicable parameters
|
||||
$create = null;
|
||||
|
||||
// Create and execute necessary SQL statements from data
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces all instances of the '||' separator between delimiters
|
||||
* in a given string
|
||||
*
|
||||
* @param string $start_delim start delimiter
|
||||
* @param string $end_delim end delimiter
|
||||
* @param string $replace the string to be replaced with
|
||||
* @param string $subject the text to be replaced
|
||||
*
|
||||
* @return string with replacements
|
||||
*/
|
||||
function PMA_delimiterReplace($start_delim, $end_delim, $replace, $subject)
|
||||
{
|
||||
// String that will be returned
|
||||
$cleaned = "";
|
||||
// Possible states of current character
|
||||
$inside_tag = false;
|
||||
$inside_attribute = false;
|
||||
// Attributes can be declared with either " or '
|
||||
$start_attribute_character = false;
|
||||
|
||||
// The full separator is "||";
|
||||
// This rembembers if the previous character was '|'
|
||||
$partial_separator = false;
|
||||
|
||||
// Parse text char by char
|
||||
for ($i = 0; $i < strlen($subject); $i ++) {
|
||||
$cur_char = $subject[$i];
|
||||
// Check for separators
|
||||
if ($cur_char == '|') {
|
||||
// If we're not inside a tag, then this is part of a real separator,
|
||||
// so we append it to the current segment
|
||||
if (! $inside_attribute) {
|
||||
$cleaned .= $cur_char;
|
||||
if ($partial_separator) {
|
||||
$inside_tag = false;
|
||||
$inside_attribute = false;
|
||||
}
|
||||
} elseif ($partial_separator) {
|
||||
// If we are inside a tag, we replace the current char with
|
||||
// the placeholder and append that to the current segment
|
||||
$cleaned .= $replace;
|
||||
}
|
||||
|
||||
// If the previous character was also '|', then this ends a
|
||||
// full separator. If not, this may be the beginning of one
|
||||
$partial_separator = ! $partial_separator;
|
||||
} else {
|
||||
// If we're inside a tag attribute and the current character is
|
||||
// not '|', but the previous one was, it means that the single '|'
|
||||
// was not appended, so we append it now
|
||||
if ($partial_separator && $inside_attribute) {
|
||||
$cleaned .= "|";
|
||||
}
|
||||
// If the char is different from "|", no separator can be formed
|
||||
$partial_separator = false;
|
||||
|
||||
// any other character should be appended to the current segment
|
||||
$cleaned .= $cur_char;
|
||||
|
||||
if ($cur_char == '<' && ! $inside_attribute) {
|
||||
// start of a tag
|
||||
$inside_tag = true;
|
||||
} elseif ($cur_char == '>' && ! $inside_attribute) {
|
||||
// end of a tag
|
||||
$inside_tag = false;
|
||||
} elseif (($cur_char == '"' || $cur_char == "'") && $inside_tag) {
|
||||
// start or end of an attribute
|
||||
if (! $inside_attribute) {
|
||||
$inside_attribute = true;
|
||||
// remember the attribute`s declaration character (" or ')
|
||||
$start_attribute_character = $cur_char;
|
||||
} else {
|
||||
if ($cur_char == $start_attribute_character) {
|
||||
$inside_attribute = false;
|
||||
// unset attribute declaration character
|
||||
$start_attribute_character = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end for each character in $subject
|
||||
|
||||
return $cleaned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates a string into items, similarly to explode
|
||||
* Uses the '||' separator (which is standard in the mediawiki format)
|
||||
* and ignores any instances of it inside markup tags
|
||||
* Used in parsing buffer lines containing data cells
|
||||
*
|
||||
* @param string $text text to be split
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function PMA_explodeMarkup($text)
|
||||
{
|
||||
$separator = "||";
|
||||
$placeholder = "\x00";
|
||||
|
||||
// Remove placeholder instances
|
||||
$text = str_replace($placeholder, '', $text);
|
||||
|
||||
// Replace instances of the separator inside HTML-like
|
||||
// tags with the placeholder
|
||||
$cleaned = PMA_delimiterReplace("<", ">", $placeholder, $text);
|
||||
// Explode, then put the replaced separators back in
|
||||
$items = explode($separator, $cleaned);
|
||||
foreach ($items as $i => $str) {
|
||||
$items[$i] = str_replace($placeholder, $separator, $str);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
?>
|
||||
@ -1,329 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* OpenDocument Spreadsheet import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo Pretty much everything
|
||||
* @todo Importing of accented characters seems to fail
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ODS
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need way to disable external XML entities processing.
|
||||
*/
|
||||
if (!function_exists('libxml_disable_entity_loader')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The possible scopes for $plugin_param are: 'table', 'database', and 'server'
|
||||
*/
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['ods'] = array(
|
||||
'text' => __('Open Document Spreadsheet'),
|
||||
'extension' => 'ods',
|
||||
'options' => array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'col_names',
|
||||
'text' => __('The first line of the file contains the table column names <i>(if this is unchecked, the first line will become part of the data)</i>')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'empty_rows',
|
||||
'text' => __('Do not import empty rows')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'recognize_percentages',
|
||||
'text' => __('Import percentages as proper decimals <i>(ex. 12.00% to .12)</i>')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'recognize_currency',
|
||||
'text' => __('Import currencies <i>(ex. $5.00 to 5.00)</i>')
|
||||
),
|
||||
array('type' => 'end_group')
|
||||
),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$buffer = "";
|
||||
|
||||
/**
|
||||
* Read in the file via PMA_importGetNextChunk so that
|
||||
* it can process compressed files
|
||||
*/
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
/* subtract data we didn't handle yet and stop processing */
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
/* Handle rest of buffer */
|
||||
} else {
|
||||
/* Append new data to buffer */
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
/**
|
||||
* Disable loading of external XML entities.
|
||||
*/
|
||||
libxml_disable_entity_loader();
|
||||
|
||||
/**
|
||||
* Load the XML string
|
||||
*
|
||||
* The option LIBXML_COMPACT is specified because it can
|
||||
* result in increased performance without the need to
|
||||
* alter the code in any way. It's basically a freebee.
|
||||
*/
|
||||
$xml = simplexml_load_string($buffer, "SimpleXMLElement", LIBXML_COMPACT);
|
||||
|
||||
unset($buffer);
|
||||
|
||||
if ($xml === false) {
|
||||
$sheets = array();
|
||||
$message = PMA_Message::error(__('The XML file specified was either malformed or incomplete. Please correct the issue and try again.'));
|
||||
$error = true;
|
||||
} else {
|
||||
$sheets = $xml->children('office', true)->{'body'}->{'spreadsheet'}->children('table', true);
|
||||
}
|
||||
|
||||
$tables = array();
|
||||
|
||||
$max_cols = 0;
|
||||
|
||||
$row_count = 0;
|
||||
$col_count = 0;
|
||||
$col_names = array();
|
||||
|
||||
$tempRow = array();
|
||||
$tempRows = array();
|
||||
$rows = array();
|
||||
|
||||
/* Iterate over tables */
|
||||
foreach ($sheets as $sheet) {
|
||||
$col_names_in_first_row = isset($_REQUEST['ods_col_names']);
|
||||
|
||||
/* Iterate over rows */
|
||||
foreach ($sheet as $row) {
|
||||
$type = $row->getName();
|
||||
if (! strcmp('table-row', $type)) {
|
||||
/* Iterate over columns */
|
||||
foreach ($row as $cell) {
|
||||
$text = $cell->children('text', true);
|
||||
$cell_attrs = $cell->attributes('office', true);
|
||||
|
||||
if (count($text) != 0) {
|
||||
$attr = $cell->attributes('table', true);
|
||||
$num_repeat = (int) $attr['number-columns-repeated'];
|
||||
$num_iterations = $num_repeat ? $num_repeat : 1;
|
||||
|
||||
for ($k = 0; $k < $num_iterations; $k++) {
|
||||
if ($_REQUEST['ods_recognize_percentages']
|
||||
&& ! strcmp('percentage', $cell_attrs['value-type'])
|
||||
) {
|
||||
$value = (double)$cell_attrs['value'];
|
||||
} elseif ($_REQUEST['ods_recognize_currency']
|
||||
&& !strcmp('currency', $cell_attrs['value-type'])
|
||||
) {
|
||||
$value = (double)$cell_attrs['value'];
|
||||
} else {
|
||||
/* We need to concatenate all paragraphs */
|
||||
$values = array();
|
||||
foreach ($text as $paragraph) {
|
||||
$values[] = (string)$paragraph;
|
||||
}
|
||||
$value = implode("\n", $values);
|
||||
}
|
||||
if (! $col_names_in_first_row) {
|
||||
$tempRow[] = $value;
|
||||
} else {
|
||||
$col_names[] = $value;
|
||||
}
|
||||
|
||||
++$col_count;
|
||||
}
|
||||
} else {
|
||||
/* Number of blank columns repeated */
|
||||
if ($col_count < count($row->children('table', true)) - 1) {
|
||||
$attr = $cell->attributes('table', true);
|
||||
$num_null = (int)$attr['number-columns-repeated'];
|
||||
|
||||
if ($num_null) {
|
||||
if (! $col_names_in_first_row) {
|
||||
for ($i = 0; $i < $num_null; ++$i) {
|
||||
$tempRow[] = 'NULL';
|
||||
++$col_count;
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < $num_null; ++$i) {
|
||||
$col_names[] = PMA_getColumnAlphaName($col_count + 1);
|
||||
++$col_count;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (! $col_names_in_first_row) {
|
||||
$tempRow[] = 'NULL';
|
||||
} else {
|
||||
$col_names[] = PMA_getColumnAlphaName($col_count + 1);
|
||||
}
|
||||
|
||||
++$col_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the widest row */
|
||||
if ($col_count > $max_cols) {
|
||||
$max_cols = $col_count;
|
||||
}
|
||||
|
||||
/* Don't include a row that is full of NULL values */
|
||||
if (! $col_names_in_first_row) {
|
||||
if ($_REQUEST['ods_empty_rows']) {
|
||||
foreach ($tempRow as $cell) {
|
||||
if (strcmp('NULL', $cell)) {
|
||||
$tempRows[] = $tempRow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$tempRows[] = $tempRow;
|
||||
}
|
||||
}
|
||||
|
||||
$col_count = 0;
|
||||
$col_names_in_first_row = false;
|
||||
$tempRow = array();
|
||||
}
|
||||
}
|
||||
|
||||
/* Skip over empty sheets */
|
||||
if (count($tempRows) == 0 || count($tempRows[0]) == 0) {
|
||||
$col_names = array();
|
||||
$tempRow = array();
|
||||
$tempRows = array();
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill out each row as necessary to make
|
||||
* every one exactly as wide as the widest
|
||||
* row. This included column names.
|
||||
*/
|
||||
|
||||
/* Fill out column names */
|
||||
for ($i = count($col_names); $i < $max_cols; ++$i) {
|
||||
$col_names[] = PMA_getColumnAlphaName($i + 1);
|
||||
}
|
||||
|
||||
/* Fill out all rows */
|
||||
$num_rows = count($tempRows);
|
||||
for ($i = 0; $i < $num_rows; ++$i) {
|
||||
for ($j = count($tempRows[$i]); $j < $max_cols; ++$j) {
|
||||
$tempRows[$i][] = 'NULL';
|
||||
}
|
||||
}
|
||||
|
||||
/* Store the table name so we know where to place the row set */
|
||||
$tbl_attr = $sheet->attributes('table', true);
|
||||
$tables[] = array((string)$tbl_attr['name']);
|
||||
|
||||
/* Store the current sheet in the accumulator */
|
||||
$rows[] = array((string)$tbl_attr['name'], $col_names, $tempRows);
|
||||
$tempRows = array();
|
||||
$col_names = array();
|
||||
$max_cols = 0;
|
||||
}
|
||||
|
||||
unset($tempRow);
|
||||
unset($tempRows);
|
||||
unset($col_names);
|
||||
unset($sheets);
|
||||
unset($xml);
|
||||
|
||||
/**
|
||||
* Bring accumulated rows into the corresponding table
|
||||
*/
|
||||
$num_tbls = count($tables);
|
||||
for ($i = 0; $i < $num_tbls; ++$i) {
|
||||
for ($j = 0; $j < count($rows); ++$j) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], $rows[$j][TBL_NAME])) {
|
||||
if (! isset($tables[$i][COL_NAMES])) {
|
||||
$tables[$i][] = $rows[$j][COL_NAMES];
|
||||
}
|
||||
|
||||
$tables[$i][ROWS] = $rows[$j][ROWS];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* No longer needed */
|
||||
unset($rows);
|
||||
|
||||
/* Obtain the best-fit MySQL types for each column */
|
||||
$analyses = array();
|
||||
|
||||
$len = count($tables);
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$analyses[] = PMA_analyzeTable($tables[$i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'ODS_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
/* Non-applicable parameters */
|
||||
$create = null;
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
|
||||
/* Commit any possible data in buffers */
|
||||
PMA_importRunQuery();
|
||||
?>
|
||||
@ -1,508 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* ESRI Shape file import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Drizzle does not suppost GIS data types
|
||||
if (PMA_DRIZZLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['shp'] = array(
|
||||
'text' => __('ESRI Shape File'),
|
||||
'extension' => 'shp',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
} else {
|
||||
|
||||
if ((int) ini_get('memory_limit') < 512) {
|
||||
@ini_set('memory_limit', '512M');
|
||||
}
|
||||
@set_time_limit(300);
|
||||
|
||||
|
||||
// Append the bfShapeFiles directory to the include path variable
|
||||
set_include_path(
|
||||
get_include_path() . PATH_SEPARATOR . getcwd() . '/libraries/bfShapeFiles/'
|
||||
);
|
||||
include_once './libraries/bfShapeFiles/ShapeFile.lib.php';
|
||||
|
||||
$GLOBALS['finished'] = false;
|
||||
$buffer = '';
|
||||
$eof = false;
|
||||
|
||||
// Returns specified number of bytes from the buffer.
|
||||
// Buffer automatically fetches next chunk of data when the buffer falls short.
|
||||
// Sets $eof when $GLOBALS['finished'] is set and the buffer falls short.
|
||||
function readFromBuffer($length)
|
||||
{
|
||||
global $buffer, $eof;
|
||||
|
||||
if (strlen($buffer) < $length) {
|
||||
if ($GLOBALS['finished']) {
|
||||
$eof = true;
|
||||
} else {
|
||||
$buffer .= PMA_importGetNextChunk();
|
||||
}
|
||||
}
|
||||
$result = substr($buffer, 0, $length);
|
||||
$buffer = substr($buffer, $length);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class extends ShapeFile class to cater the following phpMyAdmin
|
||||
* specific requirements.
|
||||
* 1) To load data from .dbf file only when the dBase extension is available.
|
||||
* 2) To use PMA_importGetNextChunk() functionality to read data, rather than
|
||||
* reading directly from a file. Using readFromBuffer() in place of fread().
|
||||
* This makes it possible to use compressions.
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
class PMA_ShapeFile extends ShapeFile
|
||||
{
|
||||
/**
|
||||
* Returns whether the 'dbase' extension is loaded
|
||||
*
|
||||
* @return boolean whether the 'dbase' extension is loaded
|
||||
*/
|
||||
function _isDbaseLoaded()
|
||||
{
|
||||
return extension_loaded('dbase');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads ESRI shape data from the imported file
|
||||
*
|
||||
* @param string $FileName not used, it's here only to match the method
|
||||
* signature of the method being overidden
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeFile::loadFromFile()
|
||||
*/
|
||||
function loadFromFile($FileName)
|
||||
{
|
||||
$this->_loadHeaders();
|
||||
$this->_loadRecords();
|
||||
if ($this->_isDbaseLoaded()) {
|
||||
$this->_closeDBFFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads metadata from the ESRI shape file header
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeFile::_loadHeaders()
|
||||
*/
|
||||
function _loadHeaders()
|
||||
{
|
||||
readFromBuffer(24);
|
||||
$this->fileLength = loadData("N", readFromBuffer(4));
|
||||
|
||||
readFromBuffer(4);
|
||||
$this->shapeType = loadData("V", readFromBuffer(4));
|
||||
|
||||
$this->boundingBox = array();
|
||||
$this->boundingBox["xmin"] = loadData("d", readFromBuffer(8));
|
||||
$this->boundingBox["ymin"] = loadData("d", readFromBuffer(8));
|
||||
$this->boundingBox["xmax"] = loadData("d", readFromBuffer(8));
|
||||
$this->boundingBox["ymax"] = loadData("d", readFromBuffer(8));
|
||||
|
||||
if ($this->_isDbaseLoaded() && $this->_openDBFFile()) {
|
||||
$this->DBFHeader = $this->_loadDBFHeader();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads geometry data from the ESRI shape file
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeFile::_loadRecords()
|
||||
*/
|
||||
function _loadRecords()
|
||||
{
|
||||
global $eof;
|
||||
readFromBuffer(32);
|
||||
while (true) {
|
||||
$record = new PMA_ShapeRecord(-1);
|
||||
$record->loadFromFile($this->SHPFile, $this->DBFFile);
|
||||
if ($record->lastError != "") {
|
||||
return false;
|
||||
}
|
||||
if ($eof) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->records[] = $record;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This class extends ShapeRecord class to cater the following phpMyAdmin
|
||||
* specific requirements.
|
||||
* 1) To load data from .dbf file only when the dBase extension is available.
|
||||
* 2) To use PMA_importGetNextChunk() functionality to read data, rather than
|
||||
* reading directly from a file. Using readFromBuffer() in place of fread().
|
||||
* This makes it possible to use compressions.
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
class PMA_ShapeRecord extends ShapeRecord
|
||||
{
|
||||
/**
|
||||
* Loads a geometry data record from the file
|
||||
*
|
||||
* @param object &$SHPFile .shp file
|
||||
* @param object &$DBFFile .dbf file
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::loadFromFile()
|
||||
*/
|
||||
function loadFromFile(&$SHPFile, &$DBFFile)
|
||||
{
|
||||
$this->DBFFile = $DBFFile;
|
||||
$this->_loadHeaders();
|
||||
|
||||
switch ($this->shapeType) {
|
||||
case 0:
|
||||
$this->_loadNullRecord();
|
||||
break;
|
||||
case 1:
|
||||
$this->_loadPointRecord();
|
||||
break;
|
||||
case 3:
|
||||
$this->_loadPolyLineRecord();
|
||||
break;
|
||||
case 5:
|
||||
$this->_loadPolygonRecord();
|
||||
break;
|
||||
case 8:
|
||||
$this->_loadMultiPointRecord();
|
||||
break;
|
||||
default:
|
||||
$this->setError(
|
||||
sprintf(
|
||||
__("Geometry type '%s' is not supported by MySQL."),
|
||||
$this->shapeType
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
if (extension_loaded('dbase') && isset($this->DBFFile)) {
|
||||
$this->_loadDBFData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads metadata from the ESRI shape record header
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadHeaders()
|
||||
*/
|
||||
function _loadHeaders()
|
||||
{
|
||||
$this->recordNumber = loadData("N", readFromBuffer(4));
|
||||
readFromBuffer(4);
|
||||
$this->shapeType = loadData("V", readFromBuffer(4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a point record
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadPoint()
|
||||
*/
|
||||
function _loadPoint()
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$data["x"] = loadData("d", readFromBuffer(8));
|
||||
$data["y"] = loadData("d", readFromBuffer(8));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a multipoint record
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadMultiPointRecord()
|
||||
*/
|
||||
function _loadMultiPointRecord()
|
||||
{
|
||||
$this->SHPData = array();
|
||||
$this->SHPData["xmin"] = loadData("d", readFromBuffer(8));
|
||||
$this->SHPData["ymin"] = loadData("d", readFromBuffer(8));
|
||||
$this->SHPData["xmax"] = loadData("d", readFromBuffer(8));
|
||||
$this->SHPData["ymax"] = loadData("d", readFromBuffer(8));
|
||||
|
||||
$this->SHPData["numpoints"] = loadData("V", readFromBuffer(4));
|
||||
|
||||
for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
|
||||
$this->SHPData["points"][] = $this->_loadPoint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a polyline record
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadPolyLineRecord()
|
||||
*/
|
||||
function _loadPolyLineRecord()
|
||||
{
|
||||
$this->SHPData = array();
|
||||
$this->SHPData["xmin"] = loadData("d", readFromBuffer(8));
|
||||
$this->SHPData["ymin"] = loadData("d", readFromBuffer(8));
|
||||
$this->SHPData["xmax"] = loadData("d", readFromBuffer(8));
|
||||
$this->SHPData["ymax"] = loadData("d", readFromBuffer(8));
|
||||
|
||||
$this->SHPData["numparts"] = loadData("V", readFromBuffer(4));
|
||||
$this->SHPData["numpoints"] = loadData("V", readFromBuffer(4));
|
||||
|
||||
for ($i = 0; $i < $this->SHPData["numparts"]; $i++) {
|
||||
$this->SHPData["parts"][$i] = loadData("V", readFromBuffer(4));
|
||||
}
|
||||
|
||||
$readPoints = 0;
|
||||
reset($this->SHPData["parts"]);
|
||||
while (list($partIndex, $partData) = each($this->SHPData["parts"])) {
|
||||
if (! isset($this->SHPData["parts"][$partIndex]["points"])
|
||||
|| !is_array($this->SHPData["parts"][$partIndex]["points"])
|
||||
) {
|
||||
$this->SHPData["parts"][$partIndex] = array();
|
||||
$this->SHPData["parts"][$partIndex]["points"] = array();
|
||||
}
|
||||
while (! in_array($readPoints, $this->SHPData["parts"])
|
||||
&& ($readPoints < ($this->SHPData["numpoints"]))
|
||||
) {
|
||||
$this->SHPData["parts"][$partIndex]["points"][]
|
||||
= $this->_loadPoint();
|
||||
$readPoints++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$shp = new PMA_ShapeFile(1);
|
||||
// If the zip archive has more than one file,
|
||||
// get the correct content to the buffer from .shp file.
|
||||
if ($compression == 'application/zip'
|
||||
&& PMA_getNoOfFilesInZip($import_file) > 1
|
||||
) {
|
||||
$zip_content = PMA_getZipContents($import_file, '/^.*\.shp$/i');
|
||||
$GLOBALS['import_text'] = $zip_content['data'];
|
||||
}
|
||||
|
||||
$temp_dbf_file = false;
|
||||
// We need dbase extension to handle .dbf file
|
||||
if (extension_loaded('dbase')) {
|
||||
// If we can extract the zip archive to 'TempDir'
|
||||
// and use the files in it for import
|
||||
if ($compression == 'application/zip'
|
||||
&& ! empty($cfg['TempDir'])
|
||||
&& is_writable($cfg['TempDir'])
|
||||
) {
|
||||
$dbf_file_name = PMA_findFileFromZipArchive(
|
||||
'/^.*\.dbf$/i', $import_file
|
||||
);
|
||||
// If the corresponding .dbf file is in the zip archive
|
||||
if ($dbf_file_name) {
|
||||
// Extract the .dbf file and point to it.
|
||||
$extracted = PMA_zipExtract(
|
||||
$import_file,
|
||||
realpath($cfg['TempDir']),
|
||||
array($dbf_file_name)
|
||||
);
|
||||
if ($extracted) {
|
||||
$dbf_file_path = realpath($cfg['TempDir'])
|
||||
. (PMA_IS_WINDOWS ? '\\' : '/') . $dbf_file_name;
|
||||
$temp_dbf_file = true;
|
||||
// Replace the .dbf with .*, as required
|
||||
// by the bsShapeFiles library.
|
||||
$file_name = substr(
|
||||
$dbf_file_path, 0, strlen($dbf_file_path) - 4
|
||||
) . '.*';
|
||||
$shp->FileName = $file_name;
|
||||
}
|
||||
}
|
||||
} elseif (! empty($local_import_file)
|
||||
&& ! empty($cfg['UploadDir'])
|
||||
&& $compression == 'none'
|
||||
) {
|
||||
// If file is in UploadDir, use .dbf file in the same UploadDir
|
||||
// to load extra data.
|
||||
// Replace the .shp with .*,
|
||||
// so the bsShapeFiles library correctly locates .dbf file.
|
||||
$file_name = substr($import_file, 0, strlen($import_file) - 4) . '.*';
|
||||
$shp->FileName = $file_name;
|
||||
}
|
||||
}
|
||||
|
||||
// Load data
|
||||
$shp->loadFromFile('');
|
||||
if ($shp->lastError != "") {
|
||||
$error = true;
|
||||
$message = PMA_Message::error(__('There was an error importing the ESRI shape file: "%s".'));
|
||||
$message->addParam($shp->lastError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete the .dbf file extracted to 'TempDir'
|
||||
if ($temp_dbf_file) {
|
||||
unlink($dbf_file_path);
|
||||
}
|
||||
|
||||
$esri_types = array(
|
||||
0 => 'Null Shape',
|
||||
1 => 'Point',
|
||||
3 => 'PolyLine',
|
||||
5 => 'Polygon',
|
||||
8 => 'MultiPoint',
|
||||
11 => 'PointZ',
|
||||
13 => 'PolyLineZ',
|
||||
15 => 'PolygonZ',
|
||||
18 => 'MultiPointZ',
|
||||
21 => 'PointM',
|
||||
23 => 'PolyLineM',
|
||||
25 => 'PolygonM',
|
||||
28 => 'MultiPointM',
|
||||
31 => 'MultiPatch',
|
||||
);
|
||||
|
||||
switch ($shp->shapeType) {
|
||||
// ESRI Null Shape
|
||||
case 0:
|
||||
break;
|
||||
// ESRI Point
|
||||
case 1:
|
||||
$gis_type = 'point';
|
||||
break;
|
||||
// ESRI PolyLine
|
||||
case 3:
|
||||
$gis_type = 'multilinestring';
|
||||
break;
|
||||
// ESRI Polygon
|
||||
case 5:
|
||||
$gis_type = 'multipolygon';
|
||||
break;
|
||||
// ESRI MultiPoint
|
||||
case 8:
|
||||
$gis_type = 'multipoint';
|
||||
break;
|
||||
default:
|
||||
$error = true;
|
||||
if (! isset($esri_types[$shp->shapeType])) {
|
||||
$message = PMA_Message::error(__('You tried to import an invalid file or the imported file contains invalid data'));
|
||||
} else {
|
||||
$message = PMA_Message::error(__('MySQL Spatial Extension does not support ESRI type "%s".'));
|
||||
$message->addParam($param);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($gis_type)) {
|
||||
include_once './libraries/gis/pma_gis_factory.php';
|
||||
$gis_obj = PMA_GIS_Factory::factory($gis_type);
|
||||
} else {
|
||||
$gis_obj = null;
|
||||
}
|
||||
|
||||
$num_rows = count($shp->records);
|
||||
// If .dbf file is loaded, the number of extra data columns
|
||||
$num_data_cols = isset($shp->DBFHeader) ? count($shp->DBFHeader) : 0;
|
||||
|
||||
$rows = array();
|
||||
$col_names = array();
|
||||
if ($num_rows != 0) {
|
||||
foreach ($shp->records as $record) {
|
||||
$tempRow = array();
|
||||
if ($gis_obj == null) {
|
||||
$tempRow[] = null;
|
||||
} else {
|
||||
$tempRow[] = "GeomFromText('"
|
||||
. $gis_obj->getShape($record->SHPData) . "')";
|
||||
}
|
||||
|
||||
if (isset($shp->DBFHeader)) {
|
||||
foreach ($shp->DBFHeader as $c) {
|
||||
$cell = trim($record->DBFData[$c[0]]);
|
||||
|
||||
if (! strcmp($cell, '')) {
|
||||
$cell = 'NULL';
|
||||
}
|
||||
|
||||
$tempRow[] = $cell;
|
||||
}
|
||||
}
|
||||
$rows[] = $tempRow;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($rows) == 0) {
|
||||
$error = true;
|
||||
$message = PMA_Message::error(__('The imported file does not contain any data'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Column names for spatial column and the rest of the columns,
|
||||
// if they are available
|
||||
$col_names[] = 'SPATIAL';
|
||||
for ($n = 0; $n < $num_data_cols; $n++) {
|
||||
$col_names[] = $shp->DBFHeader[$n][0];
|
||||
}
|
||||
|
||||
// Set table name based on the number of tables
|
||||
if (strlen($db)) {
|
||||
$result = PMA_DBI_fetch_result('SHOW TABLES');
|
||||
$table_name = 'TABLE '.(count($result) + 1);
|
||||
} else {
|
||||
$table_name = 'TBL_NAME';
|
||||
}
|
||||
$tables = array(array($table_name, $col_names, $rows));
|
||||
|
||||
// Use data from shape file to chose best-fit MySQL types for each column
|
||||
$analyses = array();
|
||||
$analyses[] = PMA_analyzeTable($tables[0]);
|
||||
|
||||
$table_no = 0; $spatial_col = 0;
|
||||
$analyses[$table_no][TYPES][$spatial_col] = GEOMETRY;
|
||||
$analyses[$table_no][FORMATTEDSQL][$spatial_col] = true;
|
||||
|
||||
// Set database name to the currently selected one, if applicable
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'SHP_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
// Created and execute necessary SQL statements from data
|
||||
$null_param = null;
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $null_param, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
|
||||
$finished = true;
|
||||
$error = false;
|
||||
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
?>
|
||||
@ -1,346 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* SQL import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage SQL
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['sql'] = array(
|
||||
'text' => __('SQL'),
|
||||
'extension' => 'sql',
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
$compats = PMA_DBI_getCompatibilities();
|
||||
if (count($compats) > 0) {
|
||||
$values = array();
|
||||
foreach ($compats as $val) {
|
||||
$values[$val] = $val;
|
||||
}
|
||||
$plugin_list['sql']['options'] = array(
|
||||
array('type' => 'begin_group', 'name' => 'general_opts'),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'name' => 'compatibility',
|
||||
'text' => __('SQL compatibility mode:'),
|
||||
'values' => $values,
|
||||
'doc' => array(
|
||||
'manual_MySQL_Database_Administration',
|
||||
'Server_SQL_mode',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'no_auto_value_on_zero',
|
||||
'text' => __('Do not use <code>AUTO_INCREMENT</code> for zero values'),
|
||||
'doc' => array(
|
||||
'manual_MySQL_Database_Administration',
|
||||
'Server_SQL_mode',
|
||||
'sqlmode_no_auto_value_on_zero'
|
||||
),
|
||||
|
||||
),
|
||||
array('type' => 'end_group'),
|
||||
);
|
||||
}
|
||||
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$buffer = '';
|
||||
// Defaults for parser
|
||||
$sql = '';
|
||||
$start_pos = 0;
|
||||
$i = 0;
|
||||
$len= 0;
|
||||
$big_value = 2147483647;
|
||||
$delimiter_keyword = 'DELIMITER '; // include the space because it's mandatory
|
||||
$length_of_delimiter_keyword = strlen($delimiter_keyword);
|
||||
|
||||
if (isset($_POST['sql_delimiter'])) {
|
||||
$sql_delimiter = $_POST['sql_delimiter'];
|
||||
} else {
|
||||
$sql_delimiter = ';';
|
||||
}
|
||||
|
||||
// Handle compatibility options
|
||||
$sql_modes = array();
|
||||
if (isset($_REQUEST['sql_compatibility'])
|
||||
&& 'NONE' != $_REQUEST['sql_compatibility']
|
||||
) {
|
||||
$sql_modes[] = $_REQUEST['sql_compatibility'];
|
||||
}
|
||||
if (isset($_REQUEST['sql_no_auto_value_on_zero'])) {
|
||||
$sql_modes[] = 'NO_AUTO_VALUE_ON_ZERO';
|
||||
}
|
||||
if (count($sql_modes) > 0) {
|
||||
PMA_DBI_try_query('SET SQL_MODE="' . implode(',', $sql_modes) . '"');
|
||||
}
|
||||
unset($sql_modes);
|
||||
|
||||
/**
|
||||
* will be set in PMA_importGetNextChunk()
|
||||
*
|
||||
* @global boolean $GLOBALS['finished']
|
||||
*/
|
||||
$GLOBALS['finished'] = false;
|
||||
|
||||
while (! ($GLOBALS['finished'] && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// Handle rest of buffer
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
// free memory
|
||||
unset($data);
|
||||
// Do not parse string when we're not at the end and don't have ; inside
|
||||
if ((strpos($buffer, $sql_delimiter, $i) === false)
|
||||
&& ! $GLOBALS['finished']
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Current length of our buffer
|
||||
$len = strlen($buffer);
|
||||
|
||||
// Grab some SQL queries out of it
|
||||
while ($i < $len) {
|
||||
$found_delimiter = false;
|
||||
// Find first interesting character
|
||||
$old_i = $i;
|
||||
// this is about 7 times faster that looking for each sequence i
|
||||
// one by one with strpos()
|
||||
$match = preg_match(
|
||||
'/(\'|"|#|-- |\/\*|`|(?i)(?<![A-Z0-9_])' . $delimiter_keyword . ')/',
|
||||
$buffer,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE,
|
||||
$i
|
||||
);
|
||||
if ($match) {
|
||||
// in $matches, index 0 contains the match for the complete
|
||||
// expression but we don't use it
|
||||
$first_position = $matches[1][1];
|
||||
} else {
|
||||
$first_position = $big_value;
|
||||
}
|
||||
/**
|
||||
* @todo we should not look for a delimiter that might be
|
||||
* inside quotes (or even double-quotes)
|
||||
*/
|
||||
// the cost of doing this one with preg_match() would be too high
|
||||
$first_sql_delimiter = strpos($buffer, $sql_delimiter, $i);
|
||||
if ($first_sql_delimiter === false) {
|
||||
$first_sql_delimiter = $big_value;
|
||||
} else {
|
||||
$found_delimiter = true;
|
||||
}
|
||||
|
||||
// set $i to the position of the first quote,
|
||||
// comment.start or delimiter found
|
||||
$i = min($first_position, $first_sql_delimiter);
|
||||
|
||||
if ($i == $big_value) {
|
||||
// none of the above was found in the string
|
||||
|
||||
$i = $old_i;
|
||||
if (!$GLOBALS['finished']) {
|
||||
break;
|
||||
}
|
||||
// at the end there might be some whitespace...
|
||||
if (trim($buffer) == '') {
|
||||
$buffer = '';
|
||||
$len = 0;
|
||||
break;
|
||||
}
|
||||
// We hit end of query, go there!
|
||||
$i = strlen($buffer) - 1;
|
||||
}
|
||||
|
||||
// Grab current character
|
||||
$ch = $buffer[$i];
|
||||
|
||||
// Quotes
|
||||
if (strpos('\'"`', $ch) !== false) {
|
||||
$quote = $ch;
|
||||
$endq = false;
|
||||
while (!$endq) {
|
||||
// Find next quote
|
||||
$pos = strpos($buffer, $quote, $i + 1);
|
||||
/*
|
||||
* Behave same as MySQL and accept end of query as end of backtick.
|
||||
* I know this is sick, but MySQL behaves like this:
|
||||
*
|
||||
* SELECT * FROM `table
|
||||
*
|
||||
* is treated like
|
||||
*
|
||||
* SELECT * FROM `table`
|
||||
*/
|
||||
if ($pos === false && $quote == '`' && $found_delimiter) {
|
||||
$pos = $first_sql_delimiter - 1;
|
||||
} elseif ($pos === false) { // No quote? Too short string
|
||||
// We hit end of string => unclosed quote,
|
||||
// but we handle it as end of query
|
||||
if ($GLOBALS['finished']) {
|
||||
$endq = true;
|
||||
$i = $len - 1;
|
||||
}
|
||||
$found_delimiter = false;
|
||||
break;
|
||||
}
|
||||
// Was not the quote escaped?
|
||||
$j = $pos - 1;
|
||||
while ($buffer[$j] == '\\') {
|
||||
$j--;
|
||||
}
|
||||
// Even count means it was not escaped
|
||||
$endq = (((($pos - 1) - $j) % 2) == 0);
|
||||
// Skip the string
|
||||
$i = $pos;
|
||||
|
||||
if ($first_sql_delimiter < $pos) {
|
||||
$found_delimiter = false;
|
||||
}
|
||||
}
|
||||
if (!$endq) {
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
// Aren't we at the end?
|
||||
if ($GLOBALS['finished'] && $i == $len) {
|
||||
$i--;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Not enough data to decide
|
||||
if ((($i == ($len - 1) && ($ch == '-' || $ch == '/'))
|
||||
|| ($i == ($len - 2) && (($ch == '-' && $buffer[$i + 1] == '-')
|
||||
|| ($ch == '/' && $buffer[$i + 1] == '*')))) && !$GLOBALS['finished']
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Comments
|
||||
if ($ch == '#'
|
||||
|| ($i < ($len - 1) && $ch == '-' && $buffer[$i + 1] == '-'
|
||||
&& (($i < ($len - 2) && $buffer[$i + 2] <= ' ')
|
||||
|| ($i == ($len - 1) && $GLOBALS['finished'])))
|
||||
|| ($i < ($len - 1) && $ch == '/' && $buffer[$i + 1] == '*')
|
||||
) {
|
||||
// Copy current string to SQL
|
||||
if ($start_pos != $i) {
|
||||
$sql .= substr($buffer, $start_pos, $i - $start_pos);
|
||||
}
|
||||
// Skip the rest
|
||||
$start_of_comment = $i;
|
||||
// do not use PHP_EOL here instead of "\n", because the export
|
||||
// file might have been produced on a different system
|
||||
$i = strpos($buffer, $ch == '/' ? '*/' : "\n", $i);
|
||||
// didn't we hit end of string?
|
||||
if ($i === false) {
|
||||
if ($GLOBALS['finished']) {
|
||||
$i = $len - 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Skip *
|
||||
if ($ch == '/') {
|
||||
$i++;
|
||||
}
|
||||
// Skip last char
|
||||
$i++;
|
||||
// We need to send the comment part in case we are defining
|
||||
// a procedure or function and comments in it are valuable
|
||||
$sql .= substr($buffer, $start_of_comment, $i - $start_of_comment);
|
||||
// Next query part will start here
|
||||
$start_pos = $i;
|
||||
// Aren't we at the end?
|
||||
if ($i == $len) {
|
||||
$i--;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Change delimiter, if redefined, and skip it (don't send to server!)
|
||||
if (strtoupper(substr($buffer, $i, $length_of_delimiter_keyword)) == $delimiter_keyword
|
||||
&& ($i + $length_of_delimiter_keyword < $len)
|
||||
) {
|
||||
// look for EOL on the character immediately after 'DELIMITER '
|
||||
// (see previous comment about PHP_EOL)
|
||||
$new_line_pos = strpos($buffer, "\n", $i + $length_of_delimiter_keyword);
|
||||
// it might happen that there is no EOL
|
||||
if (false === $new_line_pos) {
|
||||
$new_line_pos = $len;
|
||||
}
|
||||
$sql_delimiter = substr(
|
||||
$buffer,
|
||||
$i + $length_of_delimiter_keyword,
|
||||
$new_line_pos - $i - $length_of_delimiter_keyword
|
||||
);
|
||||
$i = $new_line_pos + 1;
|
||||
// Next query part will start here
|
||||
$start_pos = $i;
|
||||
continue;
|
||||
}
|
||||
|
||||
// End of SQL
|
||||
if ($found_delimiter || ($GLOBALS['finished'] && ($i == $len - 1))) {
|
||||
$tmp_sql = $sql;
|
||||
if ($start_pos < $len) {
|
||||
$length_to_grab = $i - $start_pos;
|
||||
|
||||
if (! $found_delimiter) {
|
||||
$length_to_grab++;
|
||||
}
|
||||
$tmp_sql .= substr($buffer, $start_pos, $length_to_grab);
|
||||
unset($length_to_grab);
|
||||
}
|
||||
// Do not try to execute empty SQL
|
||||
if (! preg_match('/^([\s]*;)*$/', trim($tmp_sql))) {
|
||||
$sql = $tmp_sql;
|
||||
PMA_importRunQuery(
|
||||
$sql,
|
||||
substr($buffer, 0, $i + strlen($sql_delimiter))
|
||||
);
|
||||
$buffer = substr($buffer, $i + strlen($sql_delimiter));
|
||||
// Reset parser:
|
||||
$len = strlen($buffer);
|
||||
$sql = '';
|
||||
$i = 0;
|
||||
$start_pos = 0;
|
||||
// Any chance we will get a complete query?
|
||||
//if ((strpos($buffer, ';') === false) && !$GLOBALS['finished']) {
|
||||
if (strpos($buffer, $sql_delimiter) === false
|
||||
&& ! $GLOBALS['finished']
|
||||
) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$i++;
|
||||
$start_pos = $i;
|
||||
}
|
||||
}
|
||||
} // End of parser loop
|
||||
} // End of import loop
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery('', substr($buffer, 0, $len));
|
||||
PMA_importRunQuery();
|
||||
?>
|
||||
@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$ID_KEY = 'APC_UPLOAD_PROGRESS';
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for APC extension.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
function PMA_getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
global $ID_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => $ID_KEY
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (! PMA_import_apcCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
$status = apc_fetch('upload_' . $id);
|
||||
|
||||
if ($status) {
|
||||
$ret['finished'] = (bool)$status['done'];
|
||||
$ret['total'] = $status['total'];
|
||||
$ret['complete'] = $status['current'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
|
||||
if ($ret['percent'] == 100) {
|
||||
$ret['finished'] = (bool)true;
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
?>
|
||||
@ -1,45 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$ID_KEY = 'noplugin';
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation when no webserver support exists,
|
||||
* so it returns just zeroes.
|
||||
*
|
||||
* @param string $id
|
||||
* @return array|null
|
||||
*/
|
||||
function PMA_getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
global $ID_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => $ID_KEY
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
return $ret;
|
||||
}
|
||||
?>
|
||||
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$ID_KEY = ini_get('session.upload_progress.name');
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for session.upload_progress in PHP 5.4+.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
function PMA_getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
global $ID_KEY;
|
||||
|
||||
if (trim($id) == '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => $ID_KEY
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (! PMA_import_sessionCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$status = false;
|
||||
$sessionkey = ini_get('session.upload_progress.prefix') . $id;
|
||||
|
||||
if (isset($_SESSION[$sessionkey])) {
|
||||
$status = $_SESSION[$sessionkey];
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$ret['finished'] = $status['done'];
|
||||
$ret['total'] = $status['content_length'];
|
||||
$ret['complete'] = $status['bytes_processed'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
} else {
|
||||
$ret = array(
|
||||
'id' => $id,
|
||||
'finished' => true,
|
||||
'percent' => 100,
|
||||
'total' => $ret['total'],
|
||||
'complete' => $ret['total'],
|
||||
'plugin' => $ID_KEY
|
||||
);
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
?>
|
||||
@ -1,76 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$ID_KEY = "UPLOAD_IDENTIFIER";
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for uploadprogress extension.
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
function PMA_getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
global $ID_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => $ID_KEY
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (! PMA_import_uploadprogressCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$status = uploadprogress_get_info($id);
|
||||
|
||||
if ($status) {
|
||||
if ($status['bytes_uploaded'] == $status['bytes_total']) {
|
||||
$ret['finished'] = true;
|
||||
} else {
|
||||
$ret['finished'] = false;
|
||||
}
|
||||
$ret['total'] = $status['bytes_total'];
|
||||
$ret['complete'] = $status['bytes_uploaded'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
} else {
|
||||
$ret = array(
|
||||
'id' => $id,
|
||||
'finished' => true,
|
||||
'percent' => 100,
|
||||
'total' => $ret['total'],
|
||||
'complete' => $ret['total'],
|
||||
'plugin' => $ID_KEY
|
||||
);
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
?>
|
||||
@ -1,318 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* XML import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo Improve efficiency
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage XML
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need way to disable external XML entities processing.
|
||||
*/
|
||||
if (!function_exists('libxml_disable_entity_loader')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The possible scopes for $plugin_param are: 'table', 'database', and 'server'
|
||||
*/
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['xml'] = array(
|
||||
'text' => __('XML'),
|
||||
'extension' => 'xml',
|
||||
'options' => array(
|
||||
),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
/* We do not define function when plugin is just queried for information above */
|
||||
return;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$buffer = "";
|
||||
|
||||
/**
|
||||
* Read in the file via PMA_importGetNextChunk so that
|
||||
* it can process compressed files
|
||||
*/
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
/* subtract data we didn't handle yet and stop processing */
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
/* Handle rest of buffer */
|
||||
} else {
|
||||
/* Append new data to buffer */
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
/**
|
||||
* Disable loading of external XML entities.
|
||||
*/
|
||||
libxml_disable_entity_loader();
|
||||
|
||||
/**
|
||||
* Load the XML string
|
||||
*
|
||||
* The option LIBXML_COMPACT is specified because it can
|
||||
* result in increased performance without the need to
|
||||
* alter the code in any way. It's basically a freebee.
|
||||
*/
|
||||
$xml = simplexml_load_string($buffer, "SimpleXMLElement", LIBXML_COMPACT);
|
||||
|
||||
unset($buffer);
|
||||
|
||||
/**
|
||||
* The XML was malformed
|
||||
*/
|
||||
if ($xml === false) {
|
||||
PMA_Message::error(__('The XML file specified was either malformed or incomplete. Please correct the issue and try again.'))->display();
|
||||
unset($xml);
|
||||
$GLOBALS['finished'] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Table accumulator
|
||||
*/
|
||||
$tables = array();
|
||||
/**
|
||||
* Row accumulator
|
||||
*/
|
||||
$rows = array();
|
||||
|
||||
/**
|
||||
* Temp arrays
|
||||
*/
|
||||
$tempRow = array();
|
||||
$tempCells = array();
|
||||
|
||||
/**
|
||||
* CREATE code included (by default: no)
|
||||
*/
|
||||
$struct_present = false;
|
||||
|
||||
/**
|
||||
* Analyze the data in each table
|
||||
*/
|
||||
$namespaces = $xml->getNameSpaces(true);
|
||||
|
||||
/**
|
||||
* Get the database name, collation and charset
|
||||
*/
|
||||
$db_attr = $xml->children($namespaces['pma'])->{'structure_schemas'}->{'database'};
|
||||
|
||||
if ($db_attr instanceof SimpleXMLElement) {
|
||||
$db_attr = $db_attr->attributes();
|
||||
$db_name = (string)$db_attr['name'];
|
||||
$collation = (string)$db_attr['collation'];
|
||||
$charset = (string)$db_attr['charset'];
|
||||
} else {
|
||||
/**
|
||||
* If the structure section is not present
|
||||
* get the database name from the data section
|
||||
*/
|
||||
$db_attr = $xml->children()->attributes();
|
||||
$db_name = (string)$db_attr['name'];
|
||||
$collation = null;
|
||||
$charset = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The XML was malformed
|
||||
*/
|
||||
if ($db_name === null) {
|
||||
PMA_Message::error(__('The XML file specified was either malformed or incomplete. Please correct the issue and try again.'))->display();
|
||||
unset($xml);
|
||||
$GLOBALS['finished'] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the structure information
|
||||
*/
|
||||
if (isset($namespaces['pma'])) {
|
||||
/**
|
||||
* Get structures for all tables
|
||||
*/
|
||||
$struct = $xml->children($namespaces['pma']);
|
||||
|
||||
$create = array();
|
||||
|
||||
foreach ($struct as $tier1 => $val1) {
|
||||
foreach ($val1 as $tier2 => $val2) {
|
||||
// Need to select the correct database for the creation of tables,
|
||||
// views, triggers, etc.
|
||||
/**
|
||||
* @todo Generating a USE here blocks importing of a table
|
||||
* into another database.
|
||||
*/
|
||||
$attrs = $val2->attributes();
|
||||
$create[] = "USE " . PMA_backquote($attrs["name"]);
|
||||
|
||||
foreach ($val2 as $val3) {
|
||||
/**
|
||||
* Remove the extra cosmetic spacing
|
||||
*/
|
||||
$val3 = str_replace(" ", "", (string)$val3);
|
||||
$create[] = $val3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$struct_present = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move down the XML tree to the actual data
|
||||
*/
|
||||
$xml = $xml->children()->children();
|
||||
|
||||
$data_present = false;
|
||||
|
||||
/**
|
||||
* Only attempt to analyze/collect data if there is data present
|
||||
*/
|
||||
if ($xml && @$xml->count()) {
|
||||
$data_present = true;
|
||||
|
||||
/**
|
||||
* Process all database content
|
||||
*/
|
||||
foreach ($xml as $k1 => $v1) {
|
||||
$tbl_attr = $v1->attributes();
|
||||
|
||||
$isInTables = false;
|
||||
for ($i = 0; $i < count($tables); ++$i) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], (string)$tbl_attr['name'])) {
|
||||
$isInTables = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isInTables == false) {
|
||||
$tables[] = array((string)$tbl_attr['name']);
|
||||
}
|
||||
|
||||
foreach ($v1 as $k2 => $v2) {
|
||||
$row_attr = $v2->attributes();
|
||||
if (! array_search((string)$row_attr['name'], $tempRow)) {
|
||||
$tempRow[] = (string)$row_attr['name'];
|
||||
}
|
||||
$tempCells[] = (string)$v2;
|
||||
}
|
||||
|
||||
$rows[] = array((string)$tbl_attr['name'], $tempRow, $tempCells);
|
||||
|
||||
$tempRow = array();
|
||||
$tempCells = array();
|
||||
}
|
||||
|
||||
unset($tempRow);
|
||||
unset($tempCells);
|
||||
unset($xml);
|
||||
|
||||
/**
|
||||
* Bring accumulated rows into the corresponding table
|
||||
*/
|
||||
$num_tbls = count($tables);
|
||||
for ($i = 0; $i < $num_tbls; ++$i) {
|
||||
for ($j = 0; $j < count($rows); ++$j) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], $rows[$j][TBL_NAME])) {
|
||||
if (! isset($tables[$i][COL_NAMES])) {
|
||||
$tables[$i][] = $rows[$j][COL_NAMES];
|
||||
}
|
||||
|
||||
$tables[$i][ROWS][] = $rows[$j][ROWS];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($rows);
|
||||
|
||||
if (! $struct_present) {
|
||||
$analyses = array();
|
||||
|
||||
$len = count($tables);
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$analyses[] = PMA_analyzeTable($tables[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($xml);
|
||||
unset($tempRows);
|
||||
unset($tempCells);
|
||||
unset($rows);
|
||||
|
||||
/**
|
||||
* Only build SQL from data if there is data present
|
||||
*/
|
||||
if ($data_present) {
|
||||
/**
|
||||
* Set values to NULL if they were not present
|
||||
* to maintain PMA_buildSQL() call integrity
|
||||
*/
|
||||
if (! isset($analyses)) {
|
||||
$analyses = null;
|
||||
if (! $struct_present) {
|
||||
$create = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
/* Override the database name in the XML file, if one is selected */
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
if ($db_name === null) {
|
||||
$db_name = 'XML_DB';
|
||||
}
|
||||
|
||||
/* Set database collation/charset */
|
||||
$options = array(
|
||||
'db_collation' => $collation,
|
||||
'db_charset' => $charset,
|
||||
);
|
||||
}
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($analyses);
|
||||
unset($tables);
|
||||
unset($create);
|
||||
|
||||
/* Commit any possible data in buffers */
|
||||
PMA_importRunQuery();
|
||||
?>
|
||||
@ -7,16 +7,49 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Reads all plugin information from directory $plugins_dir.
|
||||
* Includes and instantiates the specified plugin type for a certain format
|
||||
*
|
||||
* @param string $plugins_dir directrory with plugins
|
||||
* @param mixed $plugin_param parameter to plugin by which they can
|
||||
* decide whether they can work
|
||||
* @param string $plugin_type the type of the plugin (import, export, etc)
|
||||
* @param string $plugin_format the format of the plugin (sql, xml, et )
|
||||
* @param string $plugins_dir directrory with plugins
|
||||
* @param mixed $plugin_param parameter to plugin by which they can
|
||||
* decide whether they can work
|
||||
*
|
||||
* @return array list of plugins
|
||||
* @return new plugin instance
|
||||
*/
|
||||
function PMA_getPlugins($plugins_dir, $plugin_param)
|
||||
function PMA_getPlugin(
|
||||
$plugin_type,
|
||||
$plugin_format,
|
||||
$plugins_dir,
|
||||
$plugin_param = false
|
||||
){
|
||||
$GLOBALS['plugin_param'] = $plugin_param;
|
||||
$class_name = strtoupper($plugin_type[0])
|
||||
. strtolower(substr($plugin_type, 1))
|
||||
. strtoupper($plugin_format[0])
|
||||
. strtolower(substr($plugin_format, 1));
|
||||
$file = $class_name . ".class.php";
|
||||
if (is_file($plugins_dir . $file)) {
|
||||
include_once $plugins_dir . $file;
|
||||
return new $class_name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all plugin information from directory $plugins_dir
|
||||
*
|
||||
* @param string $plugin_type the type of the plugin (import, export, etc)
|
||||
* @param string $plugins_dir directrory with plugins
|
||||
* @param mixed $plugin_param parameter to plugin by which they can
|
||||
* decide whether they can work
|
||||
*
|
||||
* @return array list of plugin instances
|
||||
*/
|
||||
function PMA_getPlugins($plugin_type, $plugins_dir, $plugin_param)
|
||||
{
|
||||
$GLOBALS['plugin_param'] = $plugin_param;
|
||||
/* Scan for plugins */
|
||||
$plugin_list = array();
|
||||
if ($handle = @opendir($plugins_dir)) {
|
||||
@ -25,8 +58,21 @@ function PMA_getPlugins($plugins_dir, $plugin_param)
|
||||
// (for example ._csv.php) so the following regexp
|
||||
// matches a file which does not start with a dot but ends
|
||||
// with ".php"
|
||||
if (is_file($plugins_dir . $file) && preg_match('@^[^\.](.)*\.php$@i', $file)) {
|
||||
$class_type = strtoupper($plugin_type[0])
|
||||
. strtolower(substr($plugin_type, 1));
|
||||
if (is_file($plugins_dir . $file)
|
||||
&& preg_match(
|
||||
'@^' . $class_type . '(.+)\.class\.php$@i',
|
||||
$file,
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$GLOBALS['skip_import'] = false;
|
||||
include_once $plugins_dir . $file;
|
||||
if (! $GLOBALS['skip_import']) {
|
||||
$class_name = $class_type . $matches[1];
|
||||
$plugin_list [] = new $class_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,8 +107,11 @@ function PMA_pluginCheckboxCheck($section, $opt)
|
||||
// If the form is being repopulated using $_GET data, that is priority
|
||||
if (isset($_GET[$opt])
|
||||
|| ! isset($_GET['repopulate'])
|
||||
&& ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($_REQUEST[$opt]))
|
||||
|| (isset($GLOBALS['cfg'][$section][$opt]) && $GLOBALS['cfg'][$section][$opt]))
|
||||
&& ((isset($GLOBALS['timeout_passed'])
|
||||
&& $GLOBALS['timeout_passed']
|
||||
&& isset($_REQUEST[$opt]))
|
||||
|| (isset($GLOBALS['cfg'][$section][$opt])
|
||||
&& $GLOBALS['cfg'][$section][$opt]))
|
||||
) {
|
||||
return ' checked="checked"';
|
||||
}
|
||||
@ -109,7 +158,7 @@ function PMA_pluginGetDefault($section, $opt)
|
||||
* @param string $section name of config section in
|
||||
* $GLOBALS['cfg'][$section] for plugin
|
||||
* @param string $name name of select element
|
||||
* @param array &$list array with plugin configuration defined in plugin file
|
||||
* @param array &$list array with plugin instances
|
||||
* @param string $cfgname name of config value, if none same as $name
|
||||
*
|
||||
* @return string html select tag
|
||||
@ -121,20 +170,30 @@ function PMA_pluginGetChoice($section, $name, &$list, $cfgname = null)
|
||||
}
|
||||
$ret = '<select id="plugins" name="' . $name . '">';
|
||||
$default = PMA_pluginGetDefault($section, $cfgname);
|
||||
foreach ($list as $plugin_name => $val) {
|
||||
foreach ($list as $plugin) {
|
||||
$plugin_name = strtolower(substr(get_class($plugin), strlen($section)));
|
||||
$properties = $plugin->getProperties();
|
||||
$ret .= '<option';
|
||||
// If the form is being repopulated using $_GET data, that is priority
|
||||
if (isset($_GET[$name]) && $plugin_name == $_GET[$name] || ! isset($_GET[$name]) && $plugin_name == $default) {
|
||||
if (isset($_GET[$name])
|
||||
&& $plugin_name == $_GET[$name]
|
||||
|| ! isset($_GET[$name])
|
||||
&& $plugin_name == $default
|
||||
) {
|
||||
$ret .= ' selected="selected"';
|
||||
}
|
||||
$ret .= ' value="' . $plugin_name . '">' . PMA_getString($val['text']) . '</option>' . "\n";
|
||||
$ret .= ' value="' . $plugin_name . '">'
|
||||
. PMA_getString($properties['text'])
|
||||
. '</option>' . "\n";
|
||||
}
|
||||
$ret .= '</select>' . "\n";
|
||||
|
||||
// Whether each plugin has to be saved as a file
|
||||
foreach ($list as $plugin_name => $val) {
|
||||
foreach ($list as $plugin) {
|
||||
$plugin_name = strtolower(substr(get_class($plugin), strlen($section)));
|
||||
$properties = $plugin->getProperties();
|
||||
$ret .= '<input type="hidden" id="force_file_' . $plugin_name . '" value="';
|
||||
if (isset($val['force_file'])) {
|
||||
if (isset($properties['force_file'])) {
|
||||
$ret .= 'true';
|
||||
} else {
|
||||
$ret .= 'false';
|
||||
@ -259,7 +318,7 @@ function PMA_pluginGetOneOption($section, $plugin_name, $id, &$opt)
|
||||
* Returns html div with editable options for plugin
|
||||
*
|
||||
* @param string $section name of config section in $GLOBALS['cfg'][$section]
|
||||
* @param array &$list array with plugin configuration defined in plugin file
|
||||
* @param array &$list array with plugin instances
|
||||
*
|
||||
* @return string html fieldset with plugin options
|
||||
*/
|
||||
@ -268,13 +327,20 @@ function PMA_pluginGetOptions($section, &$list)
|
||||
$ret = '';
|
||||
$default = PMA_pluginGetDefault('Export', 'format');
|
||||
// Options for plugins that support them
|
||||
foreach ($list as $plugin_name => $val) {
|
||||
foreach ($list as $plugin) {
|
||||
$plugin_name = strtolower(substr(get_class($plugin), strlen($section)));
|
||||
$properties = $plugin->getProperties();
|
||||
$ret .= '<div id="' . $plugin_name . '_options" class="format_specific_options">';
|
||||
$count = 0;
|
||||
$ret .= '<h3>' . PMA_getString($val['text']) . '</h3>';
|
||||
if (isset($val['options']) && count($val['options']) > 0) {
|
||||
foreach ($val['options'] as $id => $opt) {
|
||||
if ($opt['type'] != 'hidden' && $opt['type'] != 'begin_group' && $opt['type'] != 'end_group' && $opt['type'] != 'begin_subgroup' && $opt['type'] != 'end_subgroup') {
|
||||
$ret .= '<h3>' . PMA_getString($properties['text']) . '</h3>';
|
||||
if (isset($properties['options']) && count($properties['options']) > 0) {
|
||||
foreach ($properties['options'] as $id => $opt) {
|
||||
if ($opt['type'] != 'hidden'
|
||||
&& $opt['type'] != 'begin_group'
|
||||
&& $opt['type'] != 'end_group'
|
||||
&& $opt['type'] != 'begin_subgroup'
|
||||
&& $opt['type'] != 'end_subgroup'
|
||||
) {
|
||||
$count++;
|
||||
}
|
||||
$ret .= PMA_pluginGetOneOption($section, $plugin_name, $id, $opt);
|
||||
|
||||
51
libraries/plugins/AuthenticationPlugin.class.php
Normal file
51
libraries/plugins/AuthenticationPlugin.class.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Abstract class for the authentication plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* This class extends the PluginObserver class */
|
||||
require_once "PluginObserver.class.php";
|
||||
|
||||
/**
|
||||
* Provides a common interface that will have to implemented by all of the
|
||||
* authentication plugins.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
abstract class AuthenticationPlugin extends PluginObserver
|
||||
{
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function auth();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function authCheck();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function authSetUser();
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function authFails();
|
||||
}
|
||||
?>
|
||||
409
libraries/plugins/ExportPlugin.class.php
Normal file
409
libraries/plugins/ExportPlugin.class.php
Normal file
@ -0,0 +1,409 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Abstract class for the export plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* This class extends the PluginObserver class */
|
||||
require_once "PluginObserver.class.php";
|
||||
|
||||
/**
|
||||
* Provides a common interface that will have to implemented by all of the
|
||||
* export plugins. Some of the plugins will also implement other public
|
||||
* methods, but those are not declared here, because they are not implemented
|
||||
* by all export plugins.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
abstract class ExportPlugin extends PluginObserver
|
||||
{
|
||||
/**
|
||||
* Array containing the specific export plugin type properties
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* Type of the newline character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_crlf;
|
||||
|
||||
/**
|
||||
* Database name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_db;
|
||||
|
||||
/**
|
||||
* Contains configuration settings
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_cfg;
|
||||
|
||||
|
||||
/**
|
||||
* Relation configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_cfgRelation;
|
||||
|
||||
/**
|
||||
* The type of the export plugin
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_what;
|
||||
|
||||
/**
|
||||
* Parameter to plugin by which it can decide whether it can work
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_pluginParam;
|
||||
|
||||
/**
|
||||
* File Charset
|
||||
*
|
||||
* @var type String
|
||||
*/
|
||||
private $_charsetOfFile;
|
||||
|
||||
/**
|
||||
* Common methods, must be overwritten by all export plugins
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
abstract public function exportHeader ();
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
abstract public function exportFooter ();
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
abstract public function exportDBHeader ($db);
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
abstract public function exportDBFooter ($db);
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
abstract public function exportDBCreate($db);
|
||||
|
||||
/**
|
||||
* Outputs the content of a table
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
abstract public function exportData ($db, $table, $crlf, $error_url, $sql_query);
|
||||
|
||||
|
||||
/**
|
||||
* The following methods are used in export.php or in db_operations.php,
|
||||
* but they are not implemented by all export plugins
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Exports routines (procedures and functions)
|
||||
*
|
||||
* @param string $db Database
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportRoutines($db)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $export_mode 'create_table','triggers','create_view',
|
||||
* 'stand_in'
|
||||
* @param string $export_type 'server', 'database', 'table'
|
||||
* @param bool $relation whether to include relation comments
|
||||
* @param bool $comments whether to include the pmadb-style column comments
|
||||
* as comments in the structure; this is deprecated
|
||||
* but the parameter is left here because export.php
|
||||
* calls exportStructure() also for other export
|
||||
* types which use this parameter
|
||||
* @param bool $mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
$error_url,
|
||||
$export_mode,
|
||||
$export_type,
|
||||
$relation = false,
|
||||
$comments = false,
|
||||
$mime = false,
|
||||
$dates = false
|
||||
) {
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a stand-in CREATE definition to resolve view dependencies
|
||||
*
|
||||
* @param string $db the database name
|
||||
* @param string $view the view name
|
||||
* @param string $crlf the end of line sequence
|
||||
*
|
||||
* @return string resulting definition
|
||||
*/
|
||||
public function getTableDefStandIn($db, $view, $crlf)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs triggers
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
*
|
||||
* @return string Formatted triggers list
|
||||
*/
|
||||
protected function getTriggers($db, $table)
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the specific variables for each export plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initSpecificVariables()
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Gets the export specific format plugin properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export plugins properties and is implemented by each export
|
||||
* plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function setProperties();
|
||||
|
||||
/**
|
||||
* Gets the type of the newline character
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCrlf()
|
||||
{
|
||||
return $this->_crlf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the newline character
|
||||
*
|
||||
* @param String $crlf type of the newline character
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setCrlf($crlf)
|
||||
{
|
||||
$this->_crlf = $crlf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDb()
|
||||
{
|
||||
return $this->_db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database name
|
||||
*
|
||||
* @param String $db database name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setDb($db)
|
||||
{
|
||||
$this->_db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration settings
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCfg()
|
||||
{
|
||||
return $this->_cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the configuration settings
|
||||
*
|
||||
* @param array $cfg array with configuration settings
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setCfg($cfg)
|
||||
{
|
||||
$this->_cfg = $cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relation configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCfgRelation()
|
||||
{
|
||||
return $this->_cfgRelation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the relation configuration
|
||||
*
|
||||
* @param array $cfgRelation relation configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function setCfgRelation($cfgRelation)
|
||||
{
|
||||
$this->_cfgRelation = $cfgRelation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of the export plugin
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getWhat()
|
||||
{
|
||||
return $this->_what;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the export plugin
|
||||
*
|
||||
* @param string $what type of the export plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setWhat($what)
|
||||
{
|
||||
$this->_what = $what;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameter to plugin by which it can decide whether it can work
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getPluginParam()
|
||||
{
|
||||
return $this->_pluginParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter to plugin by which it can decide whether it can work
|
||||
*
|
||||
* @param mixed $pluginParam plugin parameter
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setPluginParam($pluginParam)
|
||||
{
|
||||
$this->_pluginParam = $pluginParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file charset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCharsetOfFile()
|
||||
{
|
||||
return $this->_charsetOfFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file charset
|
||||
*
|
||||
* @param string $charsetOfFile file charset
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setCharsetOfFile($charsetOfFile)
|
||||
{
|
||||
$this->_charsetOfFile = $charsetOfFile;
|
||||
}
|
||||
}
|
||||
?>
|
||||
59
libraries/plugins/ImportPlugin.class.php
Normal file
59
libraries/plugins/ImportPlugin.class.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Abstract class for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* This class extends the PluginObserver class */
|
||||
require_once "PluginObserver.class.php";
|
||||
|
||||
/**
|
||||
* Provides a common interface that will have to implemented by all of the
|
||||
* import plugins.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
abstract class ImportPlugin extends PluginObserver
|
||||
{
|
||||
/**
|
||||
* Array containing the import plugin properties
|
||||
*
|
||||
* @var type array
|
||||
*/
|
||||
protected $properties;
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function doImport();
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Gets the import specific format plugin properties
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProperties()
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export plugins properties and is implemented by each import
|
||||
* plugin
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function setProperties();
|
||||
}
|
||||
?>
|
||||
131
libraries/plugins/PluginManager.class.php
Normal file
131
libraries/plugins/PluginManager.class.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* The PluginManager class is used alongside PluginObserver to implement
|
||||
* the Observer Design Pattern.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class implements the SplSubject interface
|
||||
*
|
||||
* @link http://php.net/manual/en/class.splsubject.php
|
||||
* @todo implement all methods
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class PluginManager implements SplSubject
|
||||
{
|
||||
/**
|
||||
* Contains a list with all the plugins that attach to it
|
||||
*
|
||||
* @var type SplObjectStorage
|
||||
*/
|
||||
private $_storage;
|
||||
|
||||
/**
|
||||
* Contains information about the current plugin state
|
||||
*
|
||||
* @var type string
|
||||
*/
|
||||
private $_status;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Initializes $_storage with an empty SplObjectStorage
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_storage = new SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches an SplObserver so that it can be notified of updates
|
||||
*
|
||||
* @param SplObserver $observer The SplObserver to attach
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function attach (SplObserver $observer )
|
||||
{
|
||||
$this->_storage->attach($observer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detaches an observer from the subject to no longer notify it of updates
|
||||
*
|
||||
* @param SplObserver $observer The SplObserver to detach
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function detach (SplObserver $observer)
|
||||
{
|
||||
$this->_storage->detach($observer);
|
||||
}
|
||||
|
||||
/**
|
||||
* It is called after setStatus() was run by a certain plugin, and has
|
||||
* the role of sending a notification to all of the plugins in $_storage,
|
||||
* by calling the update() method for each of them.
|
||||
*
|
||||
* @todo implement
|
||||
* @return void
|
||||
*/
|
||||
function notify ()
|
||||
{
|
||||
}
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
/**
|
||||
* Gets the list with all the plugins that attach to it
|
||||
*
|
||||
* @return type SplObjectStorage
|
||||
*/
|
||||
public function getStorage()
|
||||
{
|
||||
return $this->_storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for $_storage
|
||||
*
|
||||
* @param SplObjectStorage $_storage the list with all the plugins that
|
||||
* attach to it
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setStorage($_storage)
|
||||
{
|
||||
$this->_storage = $_storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the information about the current plugin state
|
||||
* It is called by all the plugins in $_storage in their update() method
|
||||
*
|
||||
* @return type mixed
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->_status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for $_status
|
||||
* If a plugin changes its status, this has to be remembered in order to
|
||||
* notify the rest of the plugins that they should update
|
||||
*
|
||||
* @param mixed $_status contains information about the current plugin state
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setStatus($_status)
|
||||
{
|
||||
$this->_status = $_status;
|
||||
}
|
||||
}
|
||||
?>
|
||||
81
libraries/plugins/PluginObserver.class.php
Normal file
81
libraries/plugins/PluginObserver.class.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* The PluginObserver class is used alongside PluginManager to implement
|
||||
* the Observer Design Pattern.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Each PluginObserver instance contains a PluginManager instance */
|
||||
require_once "PluginManager.class.php";
|
||||
|
||||
/**
|
||||
* This class implements the SplObserver interface
|
||||
*
|
||||
* @link http://php.net/manual/en/class.splobserver.php
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
abstract class PluginObserver implements SplObserver
|
||||
{
|
||||
/**
|
||||
* PluginManager instance that contains a list with all the observer
|
||||
* plugins that attach to it
|
||||
*
|
||||
* @var type PluginManager
|
||||
*/
|
||||
private $_pluginManager;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param PluginManager $pluginManager The Plugin Manager instance
|
||||
*/
|
||||
public function __construct($pluginManager)
|
||||
{
|
||||
$this->_pluginManager = $pluginManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function update (SplSubject $subject);
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Gets the PluginManager instance that contains the list with all the
|
||||
* plugins that attached to it
|
||||
*
|
||||
* @return type PluginManager
|
||||
*/
|
||||
public function getPluginManager()
|
||||
{
|
||||
return $this->_pluginManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for $_pluginManager
|
||||
*
|
||||
* @param PluginManager $_pluginManager the private instance that it will
|
||||
* attach to
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPluginManager($_pluginManager)
|
||||
{
|
||||
$this->_pluginManager = $_pluginManager;
|
||||
}
|
||||
}
|
||||
?>
|
||||
48
libraries/plugins/TransformationsInterface.int.php
Normal file
48
libraries/plugins/TransformationsInterface.int.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Interface for the transformations plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a common interface that will have to implemented by all of the
|
||||
* transformations plugins.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
interface TransformationsInterface {
|
||||
/**
|
||||
* Gets the transformation description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getInfo();
|
||||
|
||||
/**
|
||||
* Gets the specific MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType();
|
||||
|
||||
/**
|
||||
* Gets the specific MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype();
|
||||
|
||||
/**
|
||||
* Gets the transformation name of the specific plugin
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName();
|
||||
}
|
||||
|
||||
?>
|
||||
49
libraries/plugins/TransformationsPlugin.class.php
Normal file
49
libraries/plugins/TransformationsPlugin.class.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Abstract class for the transformations plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* It extends the PluginObserver abstract class */
|
||||
require_once "PluginObserver.class.php";
|
||||
/* It also implements the transformations interface */
|
||||
require_once "TransformationsInterface.int.php";
|
||||
|
||||
/**
|
||||
* Extends PluginObserver and provides a common interface that will have to
|
||||
* be implemented by all of the transformations plugins.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
abstract class TransformationsPlugin extends PluginObserver
|
||||
implements TransformationsInterface
|
||||
{
|
||||
/**
|
||||
* Does the actual work of each specific transformations plugin.
|
||||
*
|
||||
* @param array $options transformation options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function applyTransformationNoWrap($options = array())
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the actual work of each specific transformations plugin.
|
||||
*
|
||||
* @param string $buffer text to be transformed
|
||||
* @param array $options transformation options
|
||||
* @param string $meta meta information
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function applyTransformation($buffer, $options, $meta);
|
||||
}
|
||||
?>
|
||||
35
libraries/plugins/UploadInterface.int.php
Normal file
35
libraries/plugins/UploadInterface.int.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Interface for the import->upload plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a common interface that will have to implemented by all of the
|
||||
* import->upload plugins.
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
interface UploadInterface {
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey();
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id);
|
||||
}
|
||||
?>
|
||||
160
libraries/plugins/auth/AuthenticationConfig.class.php
Normal file
160
libraries/plugins/auth/AuthenticationConfig.class.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Config Authentication plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
* @subpackage Config
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the authentication interface */
|
||||
require_once "libraries/plugins/AuthenticationPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the config authentication method
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
*/
|
||||
class AuthenticationConfig extends AuthenticationPlugin
|
||||
{
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @return boolean always true
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @return boolean always true
|
||||
*/
|
||||
public function authCheck()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @return boolean always true
|
||||
*/
|
||||
public function authSetUser()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @global string the MySQL error message PHP returns
|
||||
* @global string the connection type (persistent or not)
|
||||
* @global string the MySQL server port to use
|
||||
* @global string the MySQL socket port to use
|
||||
* @global array the current server settings
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
* @global boolean tell the "PMA_mysqlDie()" function headers have been
|
||||
* sent
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*/
|
||||
public function authFails()
|
||||
{
|
||||
$conn_error = PMA_DBI_getError();
|
||||
if (! $conn_error) {
|
||||
$conn_error = __('Cannot connect: invalid settings.');
|
||||
}
|
||||
|
||||
/* HTML header */
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setTitle(__('Access denied'));
|
||||
$header->disableMenu();
|
||||
echo '<br /><br />
|
||||
<center>
|
||||
<h1>';
|
||||
echo sprintf(__('Welcome to %s'), ' phpMyAdmin ');
|
||||
echo '</h1>
|
||||
</center>
|
||||
<br />
|
||||
<table cellpadding="0" cellspacing="3" style="margin: 0 auto" width="80%">
|
||||
<tr>
|
||||
<td>';
|
||||
if (isset($GLOBALS['allowDeny_forbidden'])
|
||||
&& $GLOBALS['allowDeny_forbidden']
|
||||
) {
|
||||
trigger_error(__('Access denied'), E_USER_NOTICE);
|
||||
} else {
|
||||
// Check whether user has configured something
|
||||
if ($GLOBALS['PMA_Config']->source_mtime == 0) {
|
||||
echo '<p>' . sprintf(
|
||||
__(
|
||||
'You probably did not create a configuration file.'
|
||||
. ' You might want to use the %1$ssetup script%2$s to'
|
||||
. ' create one.'
|
||||
),
|
||||
'<a href="setup/">',
|
||||
'</a>'
|
||||
) . '</p>' . "\n";
|
||||
} elseif (! isset($GLOBALS['errno'])
|
||||
|| (isset($GLOBALS['errno']) && $GLOBALS['errno'] != 2002)
|
||||
&& $GLOBALS['errno'] != 2003
|
||||
) {
|
||||
// if we display the "Server not responding" error, do not confuse
|
||||
// users by telling them they have a settings problem
|
||||
// (note: it's true that they could have a badly typed host name,
|
||||
// but anyway the current message tells that the server
|
||||
// rejected the connection, which is not really what happened)
|
||||
// 2002 is the error given by mysqli
|
||||
// 2003 is the error given by mysql
|
||||
trigger_error(
|
||||
__(
|
||||
'phpMyAdmin tried to connect to the MySQL server, and the'
|
||||
. ' server rejected the connection. You should check the'
|
||||
. ' host, username and password in your configuration and'
|
||||
. ' make sure that they correspond to the information given'
|
||||
. ' by the administrator of the MySQL server.'
|
||||
), E_USER_WARNING
|
||||
);
|
||||
}
|
||||
PMA_mysqlDie($conn_error, '', true, '', false);
|
||||
}
|
||||
$GLOBALS['error_handler']->dispUserErrors();
|
||||
echo '</td>
|
||||
</tr>';
|
||||
if (count($GLOBALS['cfg']['Servers']) > 1) {
|
||||
// offer a chance to login to other servers if the current one failed
|
||||
include_once './libraries/select_server.lib.php';
|
||||
echo '<tr>' . "\n";
|
||||
echo ' <td>' . "\n";
|
||||
PMA_selectServer(true, true);
|
||||
echo ' </td>' . "\n";
|
||||
echo '</tr>' . "\n";
|
||||
}
|
||||
echo '</table>' . "\n";
|
||||
exit;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
}
|
||||
689
libraries/plugins/auth/AuthenticationCookie.class.php
Normal file
689
libraries/plugins/auth/AuthenticationCookie.class.php
Normal file
@ -0,0 +1,689 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Cookie Authentication plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
* @subpackage Cookie
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the authentication interface */
|
||||
require_once "libraries/plugins/AuthenticationPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Remember where to redirect the user
|
||||
* in case of an expired session.
|
||||
*/
|
||||
if (! empty($_REQUEST['target'])) {
|
||||
$GLOBALS['target'] = $_REQUEST['target'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Swekey authentication functions.
|
||||
*/
|
||||
require './libraries/plugins/auth/swekey/swekey.auth.lib.php';
|
||||
|
||||
/**
|
||||
* Initialization
|
||||
* Store the initialization vector because it will be needed for
|
||||
* further decryption. I don't think necessary to have one iv
|
||||
* per server so I don't put the server number in the cookie name.
|
||||
*/
|
||||
if (function_exists('mcrypt_encrypt')) {
|
||||
if (empty($_COOKIE['pma_mcrypt_iv'])
|
||||
|| ! ($iv = base64_decode($_COOKIE['pma_mcrypt_iv'], true))
|
||||
) {
|
||||
srand((double) microtime() * 1000000);
|
||||
$td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, '');
|
||||
if ($td === false) {
|
||||
PMA_fatalError(__('Failed to use Blowfish from mcrypt!'));
|
||||
}
|
||||
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pma_mcrypt_iv',
|
||||
base64_encode($iv)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the cookie authentication method
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
*/
|
||||
class AuthenticationCookie extends AuthenticationPlugin
|
||||
{
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* this function MUST exit/quit the application
|
||||
*
|
||||
* @global string the last connection error
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
global $conn_error;
|
||||
|
||||
$response = PMA_Response::getInstance();
|
||||
if ($response->isAjax()) {
|
||||
$response->isSuccess(false);
|
||||
if (! empty($conn_error)) {
|
||||
$response->addJSON('message', $conn_error);
|
||||
} else {
|
||||
$response->addJSON(
|
||||
'message',
|
||||
PMA_Message::error(
|
||||
__('Your session has expired. Please login again.')
|
||||
)
|
||||
);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Perform logout to custom URL */
|
||||
if (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// No recall if blowfish secret is not configured as it would produce
|
||||
// garbage
|
||||
if ($GLOBALS['cfg']['LoginCookieRecall']
|
||||
&& ! empty($GLOBALS['cfg']['blowfish_secret'])
|
||||
) {
|
||||
$default_user = $GLOBALS['PHP_AUTH_USER'];
|
||||
$default_server = $GLOBALS['pma_auth_server'];
|
||||
$autocomplete = '';
|
||||
} else {
|
||||
$default_user = '';
|
||||
$default_server = '';
|
||||
// skip the IE autocomplete feature.
|
||||
$autocomplete = ' autocomplete="off"';
|
||||
}
|
||||
|
||||
$cell_align = ($GLOBALS['text_dir'] == 'ltr') ? 'left' : 'right';
|
||||
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setBodyId('loginform');
|
||||
$header->setTitle('phpMyAdmin');
|
||||
$header->disableMenu();
|
||||
$header->disableWarnings();
|
||||
|
||||
if (file_exists(CUSTOM_HEADER_FILE)) {
|
||||
include CUSTOM_HEADER_FILE;
|
||||
}
|
||||
echo '
|
||||
<div class="container">
|
||||
<a href="';
|
||||
echo PMA_linkURL('http://www.phpmyadmin.net/');
|
||||
echo '" target="_blank" class="logo">';
|
||||
$logo_image = $GLOBALS['pmaThemeImage'] . 'logo_right.png';
|
||||
if (@file_exists($logo_image)) {
|
||||
echo '<img src="' . $logo_image
|
||||
. '" id="imLogo" name="imLogo" alt="phpMyAdmin" border="0" />';
|
||||
} else {
|
||||
echo '<img name="imLogo" id="imLogo" src="'
|
||||
. $GLOBALS['pmaThemeImage'] . 'pma_logo.png' . '" '
|
||||
. 'border="0" width="88" height="31" alt="phpMyAdmin" />';
|
||||
}
|
||||
echo '</a>
|
||||
<h1>';
|
||||
echo sprintf(
|
||||
__('Welcome to %s'),
|
||||
'<bdo dir="ltr" lang="en">phpMyAdmin</bdo>'
|
||||
);
|
||||
echo "</h1>";
|
||||
|
||||
// Show error message
|
||||
if (! empty($conn_error)) {
|
||||
PMA_Message::rawError($conn_error)->display();
|
||||
}
|
||||
|
||||
echo "<noscript>\n";
|
||||
PMA_message::error(
|
||||
__("Javascript must be enabled past this point")
|
||||
)->display();
|
||||
echo "</noscript>\n";
|
||||
|
||||
echo "<div class='hide js-show'>";
|
||||
// Displays the languages form
|
||||
if (empty($GLOBALS['cfg']['Lang'])) {
|
||||
include_once './libraries/display_select_lang.lib.php';
|
||||
// use fieldset, don't show doc link
|
||||
PMA_select_language(true, false);
|
||||
}
|
||||
echo '</div>
|
||||
<br />
|
||||
<!-- Login form -->
|
||||
<form method="post" action="index.php" name="login_form"' . $autocomplete .
|
||||
' target="_top" class="login hide js-show">
|
||||
<fieldset>
|
||||
<legend>';
|
||||
echo __('Log in');
|
||||
echo PMA_showDocu('');
|
||||
echo '</legend>';
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']) {
|
||||
echo '
|
||||
<div class="item">
|
||||
<label for="input_servername" title="';
|
||||
echo __(
|
||||
'You can enter hostname/IP address and port separated by space.'
|
||||
);
|
||||
echo '">';
|
||||
echo __('Server:');
|
||||
echo '</label>
|
||||
<input type="text" name="pma_servername" id="input_servername"';
|
||||
echo ' value="';
|
||||
echo htmlspecialchars($default_server);
|
||||
echo '" size="24" class="textfield" title="';
|
||||
echo __(
|
||||
'You can enter hostname/IP address and port separated by space.'
|
||||
); echo '" />
|
||||
</div>';
|
||||
}
|
||||
echo '<div class="item">
|
||||
<label for="input_username">' . __('Username:') . '</label>
|
||||
<input type="text" name="pma_username" id="input_username" '
|
||||
. 'value="' . htmlspecialchars($default_user) . '" size="24"'
|
||||
. ' class="textfield"/>
|
||||
</div>
|
||||
<div class="item">
|
||||
<label for="input_password">' . __('Password:') . '</label>
|
||||
<input type="password" name="pma_password" id="input_password"'
|
||||
. ' value="" size="24" class="textfield" />
|
||||
</div>';
|
||||
if (count($GLOBALS['cfg']['Servers']) > 1) {
|
||||
echo '<div class="item">
|
||||
<label for="select_server">' . __('Server Choice') .':</label>
|
||||
<select name="server" id="select_server"';
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']) {
|
||||
echo ' onchange="document.forms[\'login_form\'].'
|
||||
. 'elements[\'pma_servername\'].value = \'\'" ';
|
||||
}
|
||||
echo '>';
|
||||
|
||||
include_once './libraries/select_server.lib.php';
|
||||
PMA_selectServer(false, false);
|
||||
|
||||
echo '</select></div>';
|
||||
} else {
|
||||
echo ' <input type="hidden" name="server" value="'
|
||||
. $GLOBALS['server'] . '" />';
|
||||
} // end if (server choice)
|
||||
|
||||
echo '</fieldset>
|
||||
<fieldset class="tblFooters">
|
||||
<input value="' . __('Go') . '" type="submit" id="input_go" />';
|
||||
$_form_params = array();
|
||||
if (! empty($GLOBALS['target'])) {
|
||||
$_form_params['target'] = $GLOBALS['target'];
|
||||
}
|
||||
if (! empty($GLOBALS['db'])) {
|
||||
$_form_params['db'] = $GLOBALS['db'];
|
||||
}
|
||||
if (! empty($GLOBALS['table'])) {
|
||||
$_form_params['table'] = $GLOBALS['table'];
|
||||
}
|
||||
// do not generate a "server" hidden field as we want the "server"
|
||||
// drop-down to have priority
|
||||
echo PMA_generate_common_hidden_inputs($_form_params, '', 0, 'server');
|
||||
echo '</fieldset>
|
||||
</form>';
|
||||
|
||||
// BEGIN Swekey Integration
|
||||
Swekey_login('input_username', 'input_go');
|
||||
// END Swekey Integration
|
||||
|
||||
// show the "Cookies required" message only if cookies are disabled
|
||||
// (we previously tried to set some cookies)
|
||||
if (empty($_COOKIE)) {
|
||||
trigger_error(__('Cookies must be enabled past this point.'), E_USER_NOTICE);
|
||||
}
|
||||
if ($GLOBALS['error_handler']->hasDisplayErrors()) {
|
||||
echo '<div>';
|
||||
$GLOBALS['error_handler']->dispErrors();
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div>';
|
||||
if (file_exists(CUSTOM_FOOTER_FILE)) {
|
||||
include CUSTOM_FOOTER_FILE;
|
||||
}
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
// show login form in top frame.
|
||||
if (top != self || ! $(\'body#loginform\').length) {
|
||||
window.top.location.href=location;
|
||||
}
|
||||
//]]>
|
||||
</script>';
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* this function DOES NOT check authentication - it just checks/provides
|
||||
* authentication credentials required to connect to the MySQL server
|
||||
* usually with PMA_DBI_connect()
|
||||
*
|
||||
* it returns false if something is missing - which usually leads to
|
||||
* auth() which displays login form
|
||||
*
|
||||
* it returns true if all seems ok which usually leads to auth_set_user()
|
||||
*
|
||||
* it directly switches to authFails() if user inactivity timout is reached
|
||||
*
|
||||
* @todo AllowArbitraryServer on does not imply that the user wants an
|
||||
* arbitrary server, or? so we should also check if this is filled
|
||||
* and not only if allowed
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*/
|
||||
public function authCheck()
|
||||
{
|
||||
// Initialization
|
||||
/**
|
||||
* @global $GLOBALS['pma_auth_server'] the user provided server to
|
||||
* connect to
|
||||
*/
|
||||
$GLOBALS['pma_auth_server'] = '';
|
||||
|
||||
$GLOBALS['PHP_AUTH_USER'] = $GLOBALS['PHP_AUTH_PW'] = '';
|
||||
$GLOBALS['from_cookie'] = false;
|
||||
|
||||
// BEGIN Swekey Integration
|
||||
if (! Swekey_auth_check()) {
|
||||
return false;
|
||||
}
|
||||
// END Swekey Integration
|
||||
|
||||
if (defined('PMA_CLEAR_COOKIES')) {
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaServer-' . $key);
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaUser-' . $key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['old_usr'])) {
|
||||
// The user wants to be logged out
|
||||
// -> delete his choices that were stored in session
|
||||
|
||||
// according to the PHP manual we should do this before the destroy:
|
||||
//$_SESSION = array();
|
||||
|
||||
session_destroy();
|
||||
// -> delete password cookie(s)
|
||||
if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
|
||||
foreach ($GLOBALS['cfg']['Servers'] as $key => $val) {
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $key);
|
||||
if (isset($_COOKIE['pmaPass-' . $key])) {
|
||||
unset($_COOKIE['pmaPass-' . $key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$GLOBALS['PMA_Config']->removeCookie(
|
||||
'pmaPass-' . $GLOBALS['server']
|
||||
);
|
||||
if (isset($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
|
||||
unset($_COOKIE['pmaPass-' . $GLOBALS['server']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($_REQUEST['pma_username'])) {
|
||||
// The user just logged in
|
||||
$GLOBALS['PHP_AUTH_USER'] = $_REQUEST['pma_username'];
|
||||
$GLOBALS['PHP_AUTH_PW'] = empty($_REQUEST['pma_password'])
|
||||
? ''
|
||||
: $_REQUEST['pma_password'];
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& isset($_REQUEST['pma_servername'])
|
||||
) {
|
||||
$GLOBALS['pma_auth_server'] = $_REQUEST['pma_servername'];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// At the end, try to set the $GLOBALS['PHP_AUTH_USER']
|
||||
// and $GLOBALS['PHP_AUTH_PW'] variables from cookies
|
||||
|
||||
// servername
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& ! empty($_COOKIE['pmaServer-' . $GLOBALS['server']])
|
||||
) {
|
||||
$GLOBALS['pma_auth_server']
|
||||
= $_COOKIE['pmaServer-' . $GLOBALS['server']];
|
||||
}
|
||||
|
||||
// username
|
||||
if (empty($_COOKIE['pmaUser-' . $GLOBALS['server']])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$GLOBALS['PHP_AUTH_USER'] = $this->blowfishDecrypt(
|
||||
$_COOKIE['pmaUser-' . $GLOBALS['server']],
|
||||
$this->_getBlowfishSecret()
|
||||
);
|
||||
|
||||
// user was never logged in since session start
|
||||
if (empty($_SESSION['last_access_time'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// User inactive too long
|
||||
$last_access_time = time() - $GLOBALS['cfg']['LoginCookieValidity'];
|
||||
if ($_SESSION['last_access_time'] < $last_access_time
|
||||
) {
|
||||
PMA_cacheUnset('is_create_db_priv', true);
|
||||
PMA_cacheUnset('is_process_priv', true);
|
||||
PMA_cacheUnset('is_reload_priv', true);
|
||||
PMA_cacheUnset('db_to_create', true);
|
||||
PMA_cacheUnset('dbs_where_create_table_allowed', true);
|
||||
$GLOBALS['no_activity'] = true;
|
||||
$this->authFails();
|
||||
exit;
|
||||
}
|
||||
|
||||
// password
|
||||
if (empty($_COOKIE['pmaPass-' . $GLOBALS['server']])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$GLOBALS['PHP_AUTH_PW'] = $this->blowfishDecrypt(
|
||||
$_COOKIE['pmaPass-' . $GLOBALS['server']],
|
||||
$this->_getBlowfishSecret()
|
||||
);
|
||||
|
||||
if ($GLOBALS['PHP_AUTH_PW'] == "\xff(blank)") {
|
||||
$GLOBALS['PHP_AUTH_PW'] = '';
|
||||
}
|
||||
|
||||
$GLOBALS['from_cookie'] = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @return boolean always true
|
||||
*/
|
||||
public function authSetUser()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
// Ensures valid authentication mode, 'only_db', bookmark database and
|
||||
// table names and relation table name are used
|
||||
if ($cfg['Server']['user'] != $GLOBALS['PHP_AUTH_USER']) {
|
||||
foreach ($cfg['Servers'] as $idx => $current) {
|
||||
if ($current['host'] == $cfg['Server']['host']
|
||||
&& $current['port'] == $cfg['Server']['port']
|
||||
&& $current['socket'] == $cfg['Server']['socket']
|
||||
&& $current['ssl'] == $cfg['Server']['ssl']
|
||||
&& $current['connect_type'] == $cfg['Server']['connect_type']
|
||||
&& $current['user'] == $GLOBALS['PHP_AUTH_USER']
|
||||
) {
|
||||
$GLOBALS['server'] = $idx;
|
||||
$cfg['Server'] = $current;
|
||||
break;
|
||||
}
|
||||
} // end foreach
|
||||
} // end if
|
||||
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']
|
||||
&& ! empty($GLOBALS['pma_auth_server'])
|
||||
) {
|
||||
/* Allow to specify 'host port' */
|
||||
$parts = explode(' ', $GLOBALS['pma_auth_server']);
|
||||
if (count($parts) == 2) {
|
||||
$tmp_host = $parts[0];
|
||||
$tmp_port = $parts[1];
|
||||
} else {
|
||||
$tmp_host = $GLOBALS['pma_auth_server'];
|
||||
$tmp_port = '';
|
||||
}
|
||||
if ($cfg['Server']['host'] != $GLOBALS['pma_auth_server']) {
|
||||
$cfg['Server']['host'] = $tmp_host;
|
||||
if (! empty($tmp_port)) {
|
||||
$cfg['Server']['port'] = $tmp_port;
|
||||
}
|
||||
}
|
||||
unset($tmp_host, $tmp_port, $parts);
|
||||
}
|
||||
$cfg['Server']['user'] = $GLOBALS['PHP_AUTH_USER'];
|
||||
$cfg['Server']['password'] = $GLOBALS['PHP_AUTH_PW'];
|
||||
|
||||
// Avoid showing the password in phpinfo()'s output
|
||||
unset($GLOBALS['PHP_AUTH_PW']);
|
||||
unset($_SERVER['PHP_AUTH_PW']);
|
||||
|
||||
$_SESSION['last_access_time'] = time();
|
||||
|
||||
// Name and password cookies need to be refreshed each time
|
||||
// Duration = one month for username
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaUser-' . $GLOBALS['server'],
|
||||
$this->blowfishEncrypt(
|
||||
$cfg['Server']['user'],
|
||||
$this->_getBlowfishSecret()
|
||||
)
|
||||
);
|
||||
|
||||
// Duration = as configured
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaPass-' . $GLOBALS['server'],
|
||||
$this->blowfishEncrypt(
|
||||
! empty($cfg['Server']['password'])
|
||||
? $cfg['Server']['password'] : "\xff(blank)",
|
||||
$this->_getBlowfishSecret()
|
||||
),
|
||||
null,
|
||||
$GLOBALS['cfg']['LoginCookieStore']
|
||||
);
|
||||
|
||||
// Set server cookies if required (once per session) and, in this case,
|
||||
// force reload to ensure the client accepts cookies
|
||||
if (! $GLOBALS['from_cookie']) {
|
||||
if ($GLOBALS['cfg']['AllowArbitraryServer']) {
|
||||
if (! empty($GLOBALS['pma_auth_server'])) {
|
||||
// Duration = one month for servername
|
||||
$GLOBALS['PMA_Config']->setCookie(
|
||||
'pmaServer-' . $GLOBALS['server'],
|
||||
$cfg['Server']['host']
|
||||
);
|
||||
} else {
|
||||
// Delete servername cookie
|
||||
$GLOBALS['PMA_Config']->removeCookie(
|
||||
'pmaServer-' . $GLOBALS['server']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// URL where to go:
|
||||
$redirect_url = $cfg['PmaAbsoluteUri'] . 'index.php';
|
||||
|
||||
// any parameters to pass?
|
||||
$url_params = array();
|
||||
if (strlen($GLOBALS['db'])) {
|
||||
$url_params['db'] = $GLOBALS['db'];
|
||||
}
|
||||
if (strlen($GLOBALS['table'])) {
|
||||
$url_params['table'] = $GLOBALS['table'];
|
||||
}
|
||||
// any target to pass?
|
||||
if (! empty($GLOBALS['target'])
|
||||
&& $GLOBALS['target'] != 'index.php'
|
||||
) {
|
||||
$url_params['target'] = $GLOBALS['target'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear user cache.
|
||||
*/
|
||||
PMA_clearUserCache();
|
||||
|
||||
PMA_Response::getInstance()->disable();
|
||||
|
||||
PMA_sendHeaderLocation(
|
||||
$redirect_url . PMA_generate_common_url($url_params, '&'),
|
||||
true
|
||||
);
|
||||
exit;
|
||||
} // end if
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* prepares error message and switches to auth() which display the error
|
||||
* and the login form
|
||||
*
|
||||
* this function MUST exit/quit the application,
|
||||
* currently doen by call to auth()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function authFails()
|
||||
{
|
||||
global $conn_error;
|
||||
|
||||
// Deletes password cookie and displays the login form
|
||||
$GLOBALS['PMA_Config']->removeCookie('pmaPass-' . $GLOBALS['server']);
|
||||
|
||||
if (! empty($GLOBALS['login_without_password_is_forbidden'])) {
|
||||
$conn_error = __(
|
||||
'Login without a password is forbidden by configuration'
|
||||
. ' (see AllowNoPassword)'
|
||||
);
|
||||
} elseif (! empty($GLOBALS['allowDeny_forbidden'])) {
|
||||
$conn_error = __('Access denied');
|
||||
} elseif (! empty($GLOBALS['no_activity'])) {
|
||||
$conn_error = sprintf(
|
||||
__('No activity within %s seconds; please log in again'),
|
||||
$GLOBALS['cfg']['LoginCookieValidity']
|
||||
);
|
||||
// Remember where we got timeout to return on same place
|
||||
if (PMA_getenv('SCRIPT_NAME')) {
|
||||
$GLOBALS['target'] = basename(PMA_getenv('SCRIPT_NAME'));
|
||||
// avoid "missing parameter: field" on re-entry
|
||||
if ('tbl_alter.php' == $GLOBALS['target']) {
|
||||
$GLOBALS['target'] = 'tbl_structure.php';
|
||||
}
|
||||
}
|
||||
} elseif (PMA_DBI_getError()) {
|
||||
$conn_error = '#' . $GLOBALS['errno'] . ' '
|
||||
. __('Cannot log in to the MySQL server');
|
||||
} else {
|
||||
$conn_error = __('Cannot log in to the MySQL server');
|
||||
}
|
||||
|
||||
// needed for PHP-CGI (not need for FastCGI or mod-php)
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
|
||||
$this->auth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns blowfish secret or generates one if needed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getBlowfishSecret()
|
||||
{
|
||||
if (empty($GLOBALS['cfg']['blowfish_secret'])) {
|
||||
if (empty($_SESSION['auto_blowfish_secret'])) {
|
||||
// this returns 23 characters
|
||||
$_SESSION['auto_blowfish_secret'] = uniqid('', true);
|
||||
}
|
||||
return $_SESSION['auto_blowfish_secret'];
|
||||
} else {
|
||||
// apply md5() to work around too long secrets (returns 32 characters)
|
||||
return md5($GLOBALS['cfg']['blowfish_secret']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encryption using blowfish algorithm (mcrypt)
|
||||
*
|
||||
* @param string $data original data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string the encrypted result
|
||||
*/
|
||||
public function blowfishEncrypt($data, $secret)
|
||||
{
|
||||
global $iv;
|
||||
if (! function_exists('mcrypt_encrypt')) {
|
||||
include_once "HordeCipherBlowfishOperations.class.php";
|
||||
return HordeCipherBlowfishOperations::blowfishEncrypt($data, $secret);
|
||||
}
|
||||
|
||||
return base64_encode(
|
||||
mcrypt_encrypt(
|
||||
MCRYPT_BLOWFISH,
|
||||
$secret,
|
||||
$data,
|
||||
MCRYPT_MODE_CBC,
|
||||
$iv
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decryption using blowfish algorithm (mcrypt)
|
||||
*
|
||||
* @param string $encdata encrypted data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string original data
|
||||
*/
|
||||
public function blowfishDecrypt($encdata, $secret)
|
||||
{
|
||||
global $iv;
|
||||
if (! function_exists('mcrypt_encrypt')) {
|
||||
include_once "HordeCipherBlowfishOperations.class.php";
|
||||
return HordeCipherBlowfishOperations::blowfishDecrypt(
|
||||
$encdata,
|
||||
$secret
|
||||
);
|
||||
}
|
||||
|
||||
$data = base64_decode($encdata);
|
||||
$decrypted = mcrypt_decrypt(
|
||||
MCRYPT_BLOWFISH,
|
||||
$secret,
|
||||
$data,
|
||||
MCRYPT_MODE_CBC,
|
||||
$iv
|
||||
);
|
||||
return trim($decrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
}
|
||||
248
libraries/plugins/auth/AuthenticationHttp.class.php
Normal file
248
libraries/plugins/auth/AuthenticationHttp.class.php
Normal file
@ -0,0 +1,248 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* HTTP Authentication plugin for phpMyAdmin.
|
||||
* NOTE: Requires PHP loaded as a Apache module.
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
* @subpackage HTTP
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the authentication interface */
|
||||
require_once "libraries/plugins/AuthenticationPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the HTTP authentication methods
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
*/
|
||||
class AuthenticationHttp extends AuthenticationPlugin
|
||||
{
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
/* Perform logout to custom URL */
|
||||
if (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (empty($GLOBALS['cfg']['Server']['auth_http_realm'])) {
|
||||
if (empty($GLOBALS['cfg']['Server']['verbose'])) {
|
||||
$server_message = $GLOBALS['cfg']['Server']['host'];
|
||||
} else {
|
||||
$server_message = $GLOBALS['cfg']['Server']['verbose'];
|
||||
}
|
||||
$realm_message = 'phpMyAdmin ' . $server_message;
|
||||
} else {
|
||||
$realm_message = $GLOBALS['cfg']['Server']['auth_http_realm'];
|
||||
}
|
||||
// remove non US-ASCII to respect RFC2616
|
||||
$realm_message = preg_replace('/[^\x20-\x7e]/i', '', $realm_message);
|
||||
header('WWW-Authenticate: Basic realm="' . $realm_message . '"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
if (php_sapi_name() !== 'cgi-fcgi') {
|
||||
header('status: 401 Unauthorized');
|
||||
}
|
||||
|
||||
/* HTML header */
|
||||
$response = PMA_Response::getInstance();
|
||||
$response->getFooter()->setMinimal();
|
||||
$header = $response->getHeader();
|
||||
$header->setTitle(__('Access denied'));
|
||||
$header->disableMenu();
|
||||
echo '
|
||||
<br /><br />
|
||||
<center>
|
||||
<h1>';
|
||||
echo sprintf(__('Welcome to %s'), ' phpMyAdmin');
|
||||
echo ' </h1>
|
||||
</center>
|
||||
<br />' .
|
||||
PMA_Message::error(
|
||||
__('Wrong username/password. Access denied.')
|
||||
)->display();
|
||||
|
||||
if (file_exists(CUSTOM_FOOTER_FILE)) {
|
||||
include CUSTOM_FOOTER_FILE;
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @global string the username if register_globals is on
|
||||
* @global string the password if register_globals is on
|
||||
* @global array the array of server variables if register_globals is
|
||||
* off
|
||||
* @global array the array of environment variables if register_globals
|
||||
* is off
|
||||
* @global string the username for the ? server
|
||||
* @global string the password for the ? server
|
||||
* @global string the username for the WebSite Professional server
|
||||
* @global string the password for the WebSite Professional server
|
||||
* @global string the username of the user who logs out
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*/
|
||||
public function authCheck()
|
||||
{
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
global $old_usr;
|
||||
|
||||
// Grabs the $PHP_AUTH_USER variable whatever are the values of the
|
||||
// 'register_globals' and the 'variables_order' directives
|
||||
if (empty($PHP_AUTH_USER)) {
|
||||
if (PMA_getenv('PHP_AUTH_USER')) {
|
||||
$PHP_AUTH_USER = PMA_getenv('PHP_AUTH_USER');
|
||||
} elseif (PMA_getenv('REMOTE_USER')) {
|
||||
// CGI, might be encoded, see below
|
||||
$PHP_AUTH_USER = PMA_getenv('REMOTE_USER');
|
||||
} elseif (PMA_getenv('REDIRECT_REMOTE_USER')) {
|
||||
// CGI, might be encoded, see below
|
||||
$PHP_AUTH_USER = PMA_getenv('REDIRECT_REMOTE_USER');
|
||||
} elseif (PMA_getenv('AUTH_USER')) {
|
||||
// WebSite Professional
|
||||
$PHP_AUTH_USER = PMA_getenv('AUTH_USER');
|
||||
} elseif (PMA_getenv('HTTP_AUTHORIZATION')
|
||||
&& false === strpos(PMA_getenv('HTTP_AUTHORIZATION'), '<')
|
||||
) {
|
||||
// IIS, might be encoded, see below; also prevent XSS
|
||||
$PHP_AUTH_USER = PMA_getenv('HTTP_AUTHORIZATION');
|
||||
} elseif (PMA_getenv('Authorization')) {
|
||||
// FastCGI, might be encoded, see below
|
||||
$PHP_AUTH_USER = PMA_getenv('Authorization');
|
||||
}
|
||||
}
|
||||
// Grabs the $PHP_AUTH_PW variable whatever are the values of the
|
||||
// 'register_globals' and the 'variables_order' directives
|
||||
if (empty($PHP_AUTH_PW)) {
|
||||
if (PMA_getenv('PHP_AUTH_PW')) {
|
||||
$PHP_AUTH_PW = PMA_getenv('PHP_AUTH_PW');
|
||||
} elseif (PMA_getenv('REMOTE_PASSWORD')) {
|
||||
// Apache/CGI
|
||||
$PHP_AUTH_PW = PMA_getenv('REMOTE_PASSWORD');
|
||||
} elseif (PMA_getenv('AUTH_PASSWORD')) {
|
||||
// WebSite Professional
|
||||
$PHP_AUTH_PW = PMA_getenv('AUTH_PASSWORD');
|
||||
}
|
||||
}
|
||||
|
||||
// Decode possibly encoded information (used by IIS/CGI/FastCGI)
|
||||
// (do not use explode() because a user might have a colon in his password
|
||||
if (strcmp(substr($PHP_AUTH_USER, 0, 6), 'Basic ') == 0) {
|
||||
$usr_pass = base64_decode(substr($PHP_AUTH_USER, 6));
|
||||
if (! empty($usr_pass)) {
|
||||
$colon = strpos($usr_pass, ':');
|
||||
if ($colon) {
|
||||
$PHP_AUTH_USER = substr($usr_pass, 0, $colon);
|
||||
$PHP_AUTH_PW = substr($usr_pass, $colon + 1);
|
||||
}
|
||||
unset($colon);
|
||||
}
|
||||
unset($usr_pass);
|
||||
}
|
||||
|
||||
// User logged out -> ensure the new username is not the same
|
||||
if (!empty($old_usr)
|
||||
&& (isset($PHP_AUTH_USER) && $old_usr == $PHP_AUTH_USER)
|
||||
) {
|
||||
$PHP_AUTH_USER = '';
|
||||
// -> delete user's choices that were stored in session
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
// Returns whether we get authentication settings or not
|
||||
if (empty($PHP_AUTH_USER)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @global array the valid servers settings
|
||||
* @global integer the id of the current server
|
||||
* @global array the current server settings
|
||||
* @global string the current username
|
||||
* @global string the current password
|
||||
*
|
||||
* @return boolean always true
|
||||
*/
|
||||
public function authSetUser()
|
||||
{
|
||||
global $cfg, $server;
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
// Ensures valid authentication mode, 'only_db', bookmark database and
|
||||
// table names and relation table name are used
|
||||
if ($cfg['Server']['user'] != $PHP_AUTH_USER) {
|
||||
$servers_cnt = count($cfg['Servers']);
|
||||
for ($i = 1; $i <= $servers_cnt; $i++) {
|
||||
if (isset($cfg['Servers'][$i])
|
||||
&& ($cfg['Servers'][$i]['host'] == $cfg['Server']['host']
|
||||
&& $cfg['Servers'][$i]['user'] == $PHP_AUTH_USER)
|
||||
) {
|
||||
$server = $i;
|
||||
$cfg['Server'] = $cfg['Servers'][$i];
|
||||
break;
|
||||
}
|
||||
} // end for
|
||||
} // end if
|
||||
|
||||
$cfg['Server']['user'] = $PHP_AUTH_USER;
|
||||
$cfg['Server']['password'] = $PHP_AUTH_PW;
|
||||
|
||||
// Avoid showing the password in phpinfo()'s output
|
||||
unset($GLOBALS['PHP_AUTH_PW']);
|
||||
unset($_SERVER['PHP_AUTH_PW']);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*/
|
||||
public function authFails()
|
||||
{
|
||||
$error = PMA_DBI_getError();
|
||||
if ($error && $GLOBALS['errno'] != 1045) {
|
||||
PMA_fatalError($error);
|
||||
} else {
|
||||
$this->auth();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
}
|
||||
284
libraries/plugins/auth/AuthenticationSignon.class.php
Normal file
284
libraries/plugins/auth/AuthenticationSignon.class.php
Normal file
@ -0,0 +1,284 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* SignOn Authentication plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
* @subpackage SignOn
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the authentication interface */
|
||||
require_once "libraries/plugins/AuthenticationPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the SignOn authentication method
|
||||
*
|
||||
* @package PhpMyAdmin-Authentication
|
||||
*/
|
||||
class AuthenticationSignon extends AuthenticationPlugin
|
||||
{
|
||||
/**
|
||||
* Displays authentication form
|
||||
*
|
||||
* @global string the font face to use in case of failure
|
||||
* @global string the default font size to use in case of failure
|
||||
* @global string the big font size to use in case of failure
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*/
|
||||
public function auth()
|
||||
{
|
||||
unset($_SESSION['LAST_SIGNON_URL']);
|
||||
if (empty($GLOBALS['cfg']['Server']['SignonURL'])) {
|
||||
PMA_fatalError('You must set SignonURL!');
|
||||
} elseif (! empty($_REQUEST['old_usr'])
|
||||
&& ! empty($GLOBALS['cfg']['Server']['LogoutURL'])
|
||||
) {
|
||||
/* Perform logout to custom URL */
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['LogoutURL']);
|
||||
} else {
|
||||
PMA_sendHeaderLocation($GLOBALS['cfg']['Server']['SignonURL']);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets advanced authentication settings
|
||||
*
|
||||
* @global string the username if register_globals is on
|
||||
* @global string the password if register_globals is on
|
||||
* @global array the array of server variables if register_globals is
|
||||
* off
|
||||
* @global array the array of environment variables if register_globals
|
||||
* is off
|
||||
* @global string the username for the ? server
|
||||
* @global string the password for the ? server
|
||||
* @global string the username for the WebSite Professional server
|
||||
* @global string the password for the WebSite Professional server
|
||||
* @global string the username of the user who logs out
|
||||
*
|
||||
* @return boolean whether we get authentication settings or not
|
||||
*/
|
||||
public function authCheck()
|
||||
{
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
/* Check if we're using same sigon server */
|
||||
$signon_url = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
if (isset($_SESSION['LAST_SIGNON_URL'])
|
||||
&& $_SESSION['LAST_SIGNON_URL'] != $signon_url
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Script name */
|
||||
$script_name = $GLOBALS['cfg']['Server']['SignonScript'];
|
||||
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Login URL */
|
||||
$signon_url = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
|
||||
/* Current host */
|
||||
$single_signon_host = $GLOBALS['cfg']['Server']['host'];
|
||||
|
||||
/* Current port */
|
||||
$single_signon_port = $GLOBALS['cfg']['Server']['port'];
|
||||
|
||||
/* No configuration updates */
|
||||
$single_signon_cfgupdate = array();
|
||||
|
||||
/* Are we requested to do logout? */
|
||||
$do_logout = !empty($_REQUEST['old_usr']);
|
||||
|
||||
/* Handle script based auth */
|
||||
if (!empty($script_name)) {
|
||||
if (! file_exists($script_name)) {
|
||||
PMA_fatalError(
|
||||
__('Can not find signon authentication script:')
|
||||
. ' '. $script_name
|
||||
);
|
||||
}
|
||||
include $script_name;
|
||||
|
||||
list ($PHP_AUTH_USER, $PHP_AUTH_PW)
|
||||
= get_login_credentials($cfg['Server']['user']);
|
||||
|
||||
} elseif (isset($_COOKIE[$session_name])) { /* Does session exist? */
|
||||
/* End current session */
|
||||
$old_session = session_name();
|
||||
$old_id = session_id();
|
||||
session_write_close();
|
||||
|
||||
/* Load single signon session */
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_start();
|
||||
|
||||
/* Clear error message */
|
||||
unset($_SESSION['PMA_single_signon_error_message']);
|
||||
|
||||
/* Grab credentials if they exist */
|
||||
if (isset($_SESSION['PMA_single_signon_user'])) {
|
||||
if ($do_logout) {
|
||||
$PHP_AUTH_USER = '';
|
||||
} else {
|
||||
$PHP_AUTH_USER = $_SESSION['PMA_single_signon_user'];
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION['PMA_single_signon_password'])) {
|
||||
if ($do_logout) {
|
||||
$PHP_AUTH_PW = '';
|
||||
} else {
|
||||
$PHP_AUTH_PW = $_SESSION['PMA_single_signon_password'];
|
||||
}
|
||||
}
|
||||
if (isset($_SESSION['PMA_single_signon_host'])) {
|
||||
$single_signon_host = $_SESSION['PMA_single_signon_host'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_port'])) {
|
||||
$single_signon_port = $_SESSION['PMA_single_signon_port'];
|
||||
}
|
||||
|
||||
if (isset($_SESSION['PMA_single_signon_cfgupdate'])) {
|
||||
$single_signon_cfgupdate = $_SESSION['PMA_single_signon_cfgupdate'];
|
||||
}
|
||||
|
||||
|
||||
/* Also get token as it is needed to access subpages */
|
||||
if (isset($_SESSION['PMA_single_signon_token'])) {
|
||||
/* No need to care about token on logout */
|
||||
$pma_token = $_SESSION['PMA_single_signon_token'];
|
||||
}
|
||||
|
||||
/* End single signon session */
|
||||
session_write_close();
|
||||
|
||||
/* Restart phpMyAdmin session */
|
||||
session_name($old_session);
|
||||
if (!empty($old_id)) {
|
||||
session_id($old_id);
|
||||
}
|
||||
session_start();
|
||||
|
||||
/* Set the single signon host */
|
||||
$GLOBALS['cfg']['Server']['host'] = $single_signon_host;
|
||||
|
||||
/* Set the single signon port */
|
||||
$GLOBALS['cfg']['Server']['port'] = $single_signon_port;
|
||||
|
||||
/* Configuration update */
|
||||
$GLOBALS['cfg']['Server'] = array_merge(
|
||||
$GLOBALS['cfg']['Server'],
|
||||
$single_signon_cfgupdate
|
||||
);
|
||||
|
||||
/* Restore our token */
|
||||
if (!empty($pma_token)) {
|
||||
$_SESSION[' PMA_token '] = $pma_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear user cache.
|
||||
*/
|
||||
PMA_clearUserCache();
|
||||
}
|
||||
|
||||
// Returns whether we get authentication settings or not
|
||||
if (empty($PHP_AUTH_USER)) {
|
||||
unset($_SESSION['LAST_SIGNON_URL']);
|
||||
return false;
|
||||
} else {
|
||||
$_SESSION['LAST_SIGNON_URL'] = $GLOBALS['cfg']['Server']['SignonURL'];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the user and password after last checkings if required
|
||||
*
|
||||
* @global array the valid servers settings
|
||||
* @global integer the id of the current server
|
||||
* @global array the current server settings
|
||||
* @global string the current username
|
||||
* @global string the current password
|
||||
*
|
||||
* @return boolean always true
|
||||
*/
|
||||
public function authSetUser()
|
||||
{
|
||||
global $cfg;
|
||||
global $PHP_AUTH_USER, $PHP_AUTH_PW;
|
||||
|
||||
$cfg['Server']['user'] = $PHP_AUTH_USER;
|
||||
$cfg['Server']['password'] = $PHP_AUTH_PW;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* User is not allowed to login to MySQL -> authentication failed
|
||||
*
|
||||
* @return boolean always true (no return indeed)
|
||||
*/
|
||||
public function authFails()
|
||||
{
|
||||
/* Session name */
|
||||
$session_name = $GLOBALS['cfg']['Server']['SignonSession'];
|
||||
|
||||
/* Does session exist? */
|
||||
if (isset($_COOKIE[$session_name])) {
|
||||
/* End current session */
|
||||
$old_session = session_name();
|
||||
$old_id = session_id();
|
||||
session_write_close();
|
||||
|
||||
/* Load single signon session */
|
||||
session_name($session_name);
|
||||
session_id($_COOKIE[$session_name]);
|
||||
session_start();
|
||||
|
||||
/* Set error message */
|
||||
if (! empty($GLOBALS['login_without_password_is_forbidden'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __(
|
||||
'Login without a password is forbidden by configuration '
|
||||
. '(see AllowNoPassword)'
|
||||
);
|
||||
} elseif (! empty($GLOBALS['allowDeny_forbidden'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __('Access denied');
|
||||
} elseif (! empty($GLOBALS['no_activity'])) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = sprintf(
|
||||
__('No activity within %s seconds; please log in again'),
|
||||
$GLOBALS['cfg']['LoginCookieValidity']
|
||||
);
|
||||
} elseif (PMA_DBI_getError()) {
|
||||
$_SESSION['PMA_single_signon_error_message'] = PMA_sanitize(
|
||||
PMA_DBI_getError()
|
||||
);
|
||||
} else {
|
||||
$_SESSION['PMA_single_signon_error_message'] = __(
|
||||
'Cannot log in to the MySQL server'
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->auth();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Auxiliary functions for cookie authentication
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
* @subpackage Cookie
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the Horde_Cipher_blowfish class */
|
||||
require_once './libraries/blowfish.php';
|
||||
|
||||
/**
|
||||
* The HordeCipherBlowfishOperations provides encrypt and decrypt functions
|
||||
* using the Horde_Cipher_blowfish class
|
||||
*
|
||||
* @package PhpMyAdmin-Auth
|
||||
*/
|
||||
class HordeCipherBlowfishOperations
|
||||
{
|
||||
/**
|
||||
* Encryption using blowfish algorithm
|
||||
*
|
||||
* @param string $data original data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string the encrypted result
|
||||
*/
|
||||
public static function blowfishEncrypt($data, $secret)
|
||||
{
|
||||
$pma_cipher = new Horde_Cipher_blowfish;
|
||||
$encrypt = '';
|
||||
|
||||
$mod = strlen($data) % 8;
|
||||
|
||||
if ($mod > 0) {
|
||||
$data .= str_repeat("\0", 8 - $mod);
|
||||
}
|
||||
|
||||
foreach (str_split($data, 8) as $chunk) {
|
||||
$encrypt .= $pma_cipher->encryptBlock($chunk, $secret);
|
||||
}
|
||||
return base64_encode($encrypt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decryption using blowfish algorithm
|
||||
*
|
||||
* @param string $encdata encrypted data
|
||||
* @param string $secret the secret
|
||||
*
|
||||
* @return string original data
|
||||
*/
|
||||
public static function blowfishDecrypt($encdata, $secret)
|
||||
{
|
||||
$pma_cipher = new Horde_Cipher_blowfish;
|
||||
$decrypt = '';
|
||||
$data = base64_decode($encdata);
|
||||
|
||||
foreach (str_split($data, 8) as $chunk) {
|
||||
$decrypt .= $pma_cipher->decryptBlock($chunk, $secret);
|
||||
}
|
||||
return trim($decrypt);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -79,7 +79,7 @@ function Swekey_auth_error()
|
||||
return null;
|
||||
}
|
||||
|
||||
include_once './libraries/auth/swekey/authentication.inc.php';
|
||||
include_once './libraries/plugins/auth/swekey/authentication.inc.php';
|
||||
|
||||
?>
|
||||
<script>
|
||||
@ -132,7 +132,7 @@ function Swekey_auth_error()
|
||||
return sprintf(__('File %s does not contain any key id'), $GLOBALS['cfg']['Server']['auth_swekey_config']);
|
||||
}
|
||||
|
||||
include_once "libraries/auth/swekey/swekey.php";
|
||||
include_once "libraries/plugins/auth/swekey/swekey.php";
|
||||
|
||||
Swekey_SetCheckServer($_SESSION['SWEKEY']['CONF_SERVER_CHECK']);
|
||||
Swekey_SetRndTokenServer($_SESSION['SWEKEY']['CONF_SERVER_RNDTOKEN']);
|
||||
405
libraries/plugins/export/ExportCodegen.class.php
Normal file
405
libraries/plugins/export/ExportCodegen.class.php
Normal file
@ -0,0 +1,405 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build NHibernate dumps of tables
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage CodeGen
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
/* Get the table property class */
|
||||
require_once "libraries/plugins/export/TableProperty.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the CodeGen class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class ExportCodegen extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* CodeGen Formats
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_cgFormats;
|
||||
|
||||
/**
|
||||
* CodeGen Handlers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_cgHandlers;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// initialize the specific export CodeGen variables
|
||||
$this->initSpecificVariables();
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the local variables that are used for export CodeGen
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initSpecificVariables()
|
||||
{
|
||||
$this->_setCgFormats(
|
||||
array(
|
||||
"NHibernate C# DO",
|
||||
"NHibernate XML"
|
||||
)
|
||||
);
|
||||
|
||||
$this->_setCgHandlers(
|
||||
array(
|
||||
"_handleNHibernateCSBody",
|
||||
"_handleNHibernateXMLBody"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export CodeGen properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => 'CodeGen',
|
||||
'extension' => 'cs',
|
||||
'mime_type' => 'text/cs',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'name' => 'format',
|
||||
'text' => __('Format:'),
|
||||
'values' => $this->_getCgFormats()
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportHeader ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
$CG_FORMATS = $this->_getCgFormats();
|
||||
$CG_HANDLERS = $this->_getCgHandlers();
|
||||
|
||||
$format = $GLOBALS['codegen_format'];
|
||||
if (isset($CG_FORMATS[$format])) {
|
||||
return PMA_exportOutputHandler(
|
||||
$this->$CG_HANDLERS[$format]($db, $table, $crlf)
|
||||
);
|
||||
}
|
||||
return PMA_exportOutputHandler(sprintf("%s is not supported.", $format));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to make identifiers (from table or database names)
|
||||
*
|
||||
* @param string $str name to be converted
|
||||
* @param bool $ucfirst whether to make the first character uppercase
|
||||
*
|
||||
* @return string identifier
|
||||
*/
|
||||
public static function cgMakeIdentifier($str, $ucfirst = true)
|
||||
{
|
||||
// remove unsafe characters
|
||||
$str = preg_replace('/[^\p{L}\p{Nl}_]/u', '', $str);
|
||||
// make sure first character is a letter or _
|
||||
if (! preg_match('/^\pL/u', $str)) {
|
||||
$str = '_' . $str;
|
||||
}
|
||||
if ($ucfirst) {
|
||||
$str = ucfirst($str);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* C# Handler
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf line separator
|
||||
*
|
||||
* @return string containing C# code lines, separated by "\n"
|
||||
*/
|
||||
private function _handleNHibernateCSBody($db, $table, $crlf)
|
||||
{
|
||||
$lines = array();
|
||||
$result = PMA_DBI_query(
|
||||
sprintf('DESC %s.%s', PMA_backquote($db), PMA_backquote($table))
|
||||
);
|
||||
if ($result) {
|
||||
$tableProperties = array();
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$tableProperties[] = new TableProperty($row);
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
$lines[] = 'using System;';
|
||||
$lines[] = 'using System.Collections;';
|
||||
$lines[] = 'using System.Collections.Generic;';
|
||||
$lines[] = 'using System.Text;';
|
||||
$lines[] = 'namespace ' . ExportCodegen::cgMakeIdentifier($db);
|
||||
$lines[] = '{';
|
||||
$lines[] = ' #region ' . ExportCodegen::cgMakeIdentifier($table);
|
||||
$lines[] = ' public class ' . ExportCodegen::cgMakeIdentifier($table);
|
||||
$lines[] = ' {';
|
||||
$lines[] = ' #region Member Variables';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' protected #dotNetPrimitiveType# _#name#;'
|
||||
);
|
||||
}
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' #region Constructors';
|
||||
$lines[] = ' public '
|
||||
. ExportCodegen::cgMakeIdentifier($table) . '() { }';
|
||||
$temp = array();
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
if (! $tableProperty->isPK()) {
|
||||
$temp[] = $tableProperty->formatCs(
|
||||
'#dotNetPrimitiveType# #name#'
|
||||
);
|
||||
}
|
||||
}
|
||||
$lines[] = ' public '
|
||||
. ExportCodegen::cgMakeIdentifier($table)
|
||||
. '('
|
||||
. implode(', ', $temp)
|
||||
. ')';
|
||||
$lines[] = ' {';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
if (! $tableProperty->isPK()) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' this._#name#=#name#;'
|
||||
);
|
||||
}
|
||||
}
|
||||
$lines[] = ' }';
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' #region Public Properties';
|
||||
foreach ($tableProperties as $tableProperty) {
|
||||
$lines[] = $tableProperty->formatCs(
|
||||
' public virtual #dotNetPrimitiveType# #ucfirstName#'
|
||||
. "\n"
|
||||
. ' {' . "\n"
|
||||
. ' get {return _#name#;}' . "\n"
|
||||
. ' set {_#name#=value;}' . "\n"
|
||||
. ' }'
|
||||
);
|
||||
}
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = ' }';
|
||||
$lines[] = ' #endregion';
|
||||
$lines[] = '}';
|
||||
}
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* XML Handler
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf line separator
|
||||
*
|
||||
* @return string containing XML code lines, separated by "\n"
|
||||
*/
|
||||
private function _handleNHibernateXMLBody($db, $table, $crlf)
|
||||
{
|
||||
$lines = array();
|
||||
$lines[] = '<?xml version="1.0" encoding="utf-8" ?' . '>';
|
||||
$lines[] = '<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" '
|
||||
. 'namespace="' . ExportCodegen::cgMakeIdentifier($db) . '" '
|
||||
. 'assembly="' . ExportCodegen::cgMakeIdentifier($db) . '">';
|
||||
$lines[] = ' <class '
|
||||
. 'name="' . ExportCodegen::cgMakeIdentifier($table) . '" '
|
||||
. 'table="' . ExportCodegen::cgMakeIdentifier($table) . '">';
|
||||
$result = PMA_DBI_query(
|
||||
sprintf("DESC %s.%s", PMA_backquote($db), PMA_backquote($table))
|
||||
);
|
||||
if ($result) {
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$tableProperty = new TableProperty($row);
|
||||
if ($tableProperty->isPK()) {
|
||||
$lines[] = $tableProperty->formatXml(
|
||||
' <id name="#ucfirstName#" type="#dotNetObjectType#"'
|
||||
. ' unsaved-value="0">' . "\n"
|
||||
. ' <column name="#name#" sql-type="#type#"'
|
||||
. ' not-null="#notNull#" unique="#unique#"'
|
||||
. ' index="PRIMARY"/>' . "\n"
|
||||
. ' <generator class="native" />' . "\n"
|
||||
. ' </id>'
|
||||
);
|
||||
} else {
|
||||
$lines[] = $tableProperty->formatXml(
|
||||
' <property name="#ucfirstName#"'
|
||||
. ' type="#dotNetObjectType#">' . "\n"
|
||||
. ' <column name="#name#" sql-type="#type#"'
|
||||
. ' not-null="#notNull#" #indexName#/>' . "\n"
|
||||
. ' </property>'
|
||||
);
|
||||
}
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
}
|
||||
$lines[] = ' </class>';
|
||||
$lines[] = '</hibernate-mapping>';
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Getter for CodeGen formats
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getCgFormats()
|
||||
{
|
||||
return $this->_cgFormats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for CodeGen formats
|
||||
*
|
||||
* @param array $CG_FORMATS contains CodeGen Formats
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setCgFormats($CG_FORMATS)
|
||||
{
|
||||
$this->_cgFormats = $CG_FORMATS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for CodeGen handlers
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getCgHandlers()
|
||||
{
|
||||
return $this->_cgHandlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for CodeGen handlers
|
||||
*
|
||||
* @param array $CG_HANDLERS contains CodeGen handler methods
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setCgHandlers($CG_HANDLERS)
|
||||
{
|
||||
$this->_cgHandlers = $CG_HANDLERS;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -10,20 +10,88 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Set of functions used to build CSV dumps of tables
|
||||
* Handles the export for the CSV format
|
||||
*
|
||||
* @todo add descriptions for all vars/methods
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class ExportCsv extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* The string used to end lines
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_csvTerminated;
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['csv'] = array(
|
||||
'text' => __('CSV'),
|
||||
'extension' => 'csv',
|
||||
'mime_type' => 'text/comma-separated-values',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
/**
|
||||
* The string used to separate columns
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_csvSeparator;
|
||||
|
||||
$plugin_list['csv']['options'] = array(
|
||||
/**
|
||||
* The string used to enclose columns
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_csvEnclosed;
|
||||
|
||||
/**
|
||||
* The string used to escape columns
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_csvEscaped;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// initialize the specific export csv variables
|
||||
$this->initSpecificVariables();
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the variables that are used for export CSV
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initSpecificVariables()
|
||||
{
|
||||
global $csv_terminated;
|
||||
global $csv_separator;
|
||||
global $csv_enclosed;
|
||||
global $csv_escaped;
|
||||
$this->setCsvTerminated($csv_terminated);
|
||||
$this->setCsvSeparator($csv_separator);
|
||||
$this->setCsvEnclosed($csv_enclosed);
|
||||
$this->setCsvEscaped($csv_escaped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export CSV properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('CSV'),
|
||||
'extension' => 'csv',
|
||||
'mime_type' => 'text/comma-separated-values',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
@ -72,39 +140,43 @@ if (isset($plugin_list)) {
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
// The type of the export plugin only has to be set once and then
|
||||
// it will remain unchanged. This is the first time
|
||||
global $what;
|
||||
global $csv_terminated;
|
||||
global $csv_separator;
|
||||
global $csv_enclosed;
|
||||
global $csv_escaped;
|
||||
$this->setWhat($what);
|
||||
|
||||
$csv_terminated = $this->getCsvTerminated();
|
||||
$csv_separator = $this->getCsvSeparator();
|
||||
$csv_enclosed = $this->getCsvEnclosed();
|
||||
$csv_escaped = $this->getCsvEscaped();
|
||||
|
||||
|
||||
// Here we just prepare some values for export
|
||||
if ($what == 'excel') {
|
||||
$csv_terminated = "\015\012";
|
||||
$csv_terminated = "\015\012";
|
||||
switch($GLOBALS['excel_edition']) {
|
||||
case 'win':
|
||||
// as tested on Windows with Excel 2002 and Excel 2007
|
||||
@ -132,6 +204,23 @@ if (isset($plugin_list)) {
|
||||
} // end if
|
||||
$csv_separator = str_replace('\\t', "\011", $csv_separator);
|
||||
}
|
||||
|
||||
// remember the modifications
|
||||
$this->setCsvTerminated($csv_terminated);
|
||||
$this->setCsvSeparator($csv_separator);
|
||||
$this->setCsvEnclosed($csv_enclosed);
|
||||
$this->setCsvEscaped($csv_escaped);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -141,10 +230,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -155,10 +242,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -169,10 +254,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -187,19 +270,17 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $what;
|
||||
global $csv_terminated;
|
||||
global $csv_separator;
|
||||
global $csv_enclosed;
|
||||
global $csv_escaped;
|
||||
$what = $this->getWhat();
|
||||
$csv_terminated = $this->getCsvTerminated();
|
||||
$csv_separator = $this->getCsvSeparator();
|
||||
$csv_enclosed = $this->getCsvEnclosed();
|
||||
$csv_escaped = $this->getCsvEscaped();
|
||||
|
||||
// Gets the data from the database
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
|
||||
// If required, get fields name at the first line
|
||||
@ -292,7 +373,98 @@ if (isset($plugin_list)) {
|
||||
PMA_DBI_free_result($result);
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_getTableCsv()' function
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Gets the string used to terminate lines
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCsvTerminated()
|
||||
{
|
||||
return $this->_csvTerminated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string used to terminate lines
|
||||
*
|
||||
* @param string $csvTerminated lines terminator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setCsvTerminated($csvTerminated)
|
||||
{
|
||||
$this->_csvTerminated = $csvTerminated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string used to separate columns
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCsvSeparator()
|
||||
{
|
||||
return $this->_csvSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string used to separate columns
|
||||
*
|
||||
* @param string $csvSeparator columns separator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setCsvSeparator($csvSeparator)
|
||||
{
|
||||
$this->_csvSeparator = $csvSeparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string used to enclose columns
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCsvEnclosed()
|
||||
{
|
||||
return $this->_csvEnclosed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string used to enclose columns
|
||||
*
|
||||
* @param string $csvEnclosed columns encloser
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setCsvEnclosed($csvEnclosed)
|
||||
{
|
||||
$this->_csvEnclosed = $csvEnclosed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string used to escape columns
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCsvEscaped()
|
||||
{
|
||||
return $this->_csvEscaped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the string used to escape columns
|
||||
*
|
||||
* @param string $csvEscaped columns escaper
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setCsvEscaped($csvEscaped)
|
||||
{
|
||||
$this->_csvEscaped = $csvEscaped;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
92
libraries/plugins/export/ExportExcel.class.php
Normal file
92
libraries/plugins/export/ExportExcel.class.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Class for exporting CSV dumps of tables for excel
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage CSV-Excel
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Extend the export CSV class */
|
||||
require_once "libraries/plugins/export/ExportCsv.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the CSV-Excel format
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class ExportExcel extends ExportCsv
|
||||
{
|
||||
/**
|
||||
* Sets the export CSV for Excel properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('CSV for MS Excel'),
|
||||
'extension' => 'csv',
|
||||
'mime_type' => 'text/comma-separated-values',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'removeCRLF',
|
||||
'text' => __(
|
||||
'Remove carriage return/line feed characters within columns'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'name' => 'edition',
|
||||
'values' => array(
|
||||
'win' => 'Windows',
|
||||
'mac_excel2003' => 'Excel 2003 / Macintosh',
|
||||
'mac_excel2008' => 'Excel 2008 / Macintosh'),
|
||||
'text' => __('Excel edition:')
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,93 +1,115 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to export a set of queries to a MS Word document
|
||||
* HTML-Word export code
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage HTMLWord
|
||||
* @subpackage HTML-Word
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the HTML-Word format
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['htmlword'] = array(
|
||||
'text' => __('Microsoft Word 2000'),
|
||||
'extension' => 'doc',
|
||||
'mime_type' => 'application/vnd.ms-word',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['htmlword']['options'] = array(
|
||||
/* what to dump (structure/data/both) */
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'dump_what',
|
||||
'text' => __('Dump table')
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
),
|
||||
|
||||
/* data options */
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
class ExportHtmlword extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
* Sets the export HTML-Word properties
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('Microsoft Word 2000'),
|
||||
'extension' => 'doc',
|
||||
'mime_type' => 'application/vnd.ms-word',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
/* what to dump (structure/data/both) */
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'dump_what',
|
||||
'text' => __('Dump table')
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
),
|
||||
|
||||
/* data options */
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
return PMA_exportOutputHandler('</body></html>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
global $charset_of_file;
|
||||
$this->setCharsetOfFile($charset_of_file);
|
||||
|
||||
return PMA_exportOutputHandler(
|
||||
'<html xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
xmlns:x="urn:schemas-microsoft-com:office:word"
|
||||
@ -98,22 +120,30 @@ if (isset($plugin_list)) {
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-type" content="text/html;charset='
|
||||
. (isset($charset_of_file) ? $charset_of_file : 'utf-8') . '" />
|
||||
. (isset($charsetOfFile) ? $charsetOfFile : 'utf-8') . '" />
|
||||
</head>
|
||||
<body>'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return PMA_exportOutputHandler('</body></html>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return PMA_exportOutputHandler(
|
||||
'<h1>' . __('Database') . ' ' . htmlspecialchars($db) . '</h1>'
|
||||
@ -126,10 +156,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -140,16 +168,14 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in HTML (Microsoft Word) format
|
||||
* Outputs the content of a table in HTML-Word format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -158,12 +184,11 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $what;
|
||||
$this->setWhat($what);
|
||||
|
||||
if (! PMA_exportOutputHandler(
|
||||
'<h2>'
|
||||
@ -179,7 +204,7 @@ if (isset($plugin_list)) {
|
||||
}
|
||||
|
||||
// Gets the data from the database
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
|
||||
// If required, get fields name at the first line
|
||||
@ -234,32 +259,30 @@ if (isset($plugin_list)) {
|
||||
* @param string $crlf the end of line sequence
|
||||
*
|
||||
* @return string resulting definition
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTableDefStandIn($db, $view, $crlf)
|
||||
public function getTableDefStandIn($db, $view, $crlf)
|
||||
{
|
||||
$schema_insert = '<table class="width100" cellspacing="1">';
|
||||
$schema_insert .= '<tr class="print-category">';
|
||||
$schema_insert .= '<th class="print">'
|
||||
$schema_insert = '<table class="width100" cellspacing="1">'
|
||||
. '<tr class="print-category">'
|
||||
. '<th class="print">'
|
||||
. __('Column')
|
||||
. '</th>';
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
. '</th>'
|
||||
. '<td class="print"><strong>'
|
||||
. __('Type')
|
||||
. '</strong></td>';
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
. '</strong></td>'
|
||||
. '<td class="print"><strong>'
|
||||
. __('Null')
|
||||
. '</strong></td>';
|
||||
$schema_insert .= '<td class="print"><strong>'
|
||||
. '</strong></td>'
|
||||
. '<td class="print"><strong>'
|
||||
. __('Default')
|
||||
. '</strong></td>';
|
||||
$schema_insert .= '</tr>';
|
||||
. '</strong></td>'
|
||||
. '</tr>';
|
||||
|
||||
/**
|
||||
* Get the unique keys in the table
|
||||
*/
|
||||
$unique_keys = array();
|
||||
$keys = PMA_DBI_get_table_indexes($db, $table);
|
||||
$keys = PMA_DBI_get_table_indexes($db, $table);
|
||||
foreach ($keys as $key) {
|
||||
if ($key['Non_unique'] == 0) {
|
||||
$unique_keys[] = $key['Column_name'];
|
||||
@ -268,7 +291,10 @@ if (isset($plugin_list)) {
|
||||
|
||||
$columns = PMA_DBI_get_columns($db, $view);
|
||||
foreach ($columns as $column) {
|
||||
$schema_insert .= PMA_formatOneColumnDefinition($column, $unique_keys);
|
||||
$schema_insert .= $this->formatOneColumnDefinition(
|
||||
$column,
|
||||
$unique_keys
|
||||
);
|
||||
$schema_insert .= '</tr>';
|
||||
}
|
||||
|
||||
@ -297,10 +323,8 @@ if (isset($plugin_list)) {
|
||||
* @param bool $view whether we're handling a view
|
||||
*
|
||||
* @return string resulting schema
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTableDef(
|
||||
public function getTableDef(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -312,7 +336,10 @@ if (isset($plugin_list)) {
|
||||
$add_semicolon = true,
|
||||
$view = false
|
||||
) {
|
||||
// set $cfgRelation here, because there is a chance that it's modified
|
||||
// since the class initialization
|
||||
global $cfgRelation;
|
||||
$this->setCfgRelation($cfgRelation);
|
||||
|
||||
$schema_insert = '';
|
||||
|
||||
@ -389,14 +416,17 @@ if (isset($plugin_list)) {
|
||||
* Get the unique keys in the table
|
||||
*/
|
||||
$unique_keys = array();
|
||||
$keys = PMA_DBI_get_table_indexes($db, $table);
|
||||
$keys = PMA_DBI_get_table_indexes($db, $table);
|
||||
foreach ($keys as $key) {
|
||||
if ($key['Non_unique'] == 0) {
|
||||
$unique_keys[] = $key['Column_name'];
|
||||
}
|
||||
}
|
||||
foreach ($columns as $column) {
|
||||
$schema_insert .= PMA_formatOneColumnDefinition($column, $unique_keys);
|
||||
$schema_insert .= $this->formatOneColumnDefinition(
|
||||
$column,
|
||||
$unique_keys
|
||||
);
|
||||
$field_name = $column['Field'];
|
||||
|
||||
if ($do_relation && $have_rel) {
|
||||
@ -425,7 +455,7 @@ if (isset($plugin_list)) {
|
||||
}
|
||||
|
||||
$schema_insert .= '</tr>';
|
||||
} // end foreach
|
||||
} // end foreach
|
||||
|
||||
$schema_insert .= '</table>';
|
||||
return $schema_insert;
|
||||
@ -438,10 +468,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $table table name
|
||||
*
|
||||
* @return string Formatted triggers list
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTriggers($db, $table)
|
||||
protected function getTriggers($db, $table)
|
||||
{
|
||||
$dump = '<table class="width100" cellspacing="1">';
|
||||
$dump .= '<tr class="print-category">';
|
||||
@ -495,10 +523,8 @@ if (isset($plugin_list)) {
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure(
|
||||
public function exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -517,7 +543,7 @@ if (isset($plugin_list)) {
|
||||
$dump .= '<h2>'
|
||||
. __('Table structure for table') . ' ' . htmlspecialchars($table)
|
||||
. '</h2>';
|
||||
$dump .= PMA_getTableDef(
|
||||
$dump .= $this->getTableDef(
|
||||
$db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime,
|
||||
$dates
|
||||
);
|
||||
@ -529,14 +555,14 @@ if (isset($plugin_list)) {
|
||||
$dump .= '<h2>'
|
||||
. __('Triggers') . ' ' . htmlspecialchars($table)
|
||||
. '</h2>';
|
||||
$dump .= PMA_getTriggers($db, $table);
|
||||
$dump .= $this->getTriggers($db, $table);
|
||||
}
|
||||
break;
|
||||
case 'create_view':
|
||||
$dump .= '<h2>'
|
||||
. __('Structure for view') . ' ' . htmlspecialchars($table)
|
||||
. '</h2>';
|
||||
$dump .= PMA_getTableDef(
|
||||
$dump .= $this->getTableDef(
|
||||
$db, $table, $crlf, $error_url, $do_relation, $do_comments, $do_mime,
|
||||
$dates, true, true
|
||||
);
|
||||
@ -546,23 +572,21 @@ if (isset($plugin_list)) {
|
||||
. __('Stand-in structure for view') . ' ' . htmlspecialchars($table)
|
||||
. '</h2>';
|
||||
// export a stand-in definition to resolve view dependencies
|
||||
$dump .= PMA_getTableDefStandIn($db, $table, $crlf);
|
||||
$dump .= $this->getTableDefStandIn($db, $table, $crlf);
|
||||
} // end switch
|
||||
|
||||
return PMA_exportOutputHandler($dump);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the definition for one column
|
||||
* Formats the definition for one column
|
||||
*
|
||||
* @param array $column info about this column
|
||||
* @param array $unique_keys unique keys of the table
|
||||
*
|
||||
* @return string Formatted column definition
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_formatOneColumnDefinition(
|
||||
protected function formatOneColumnDefinition(
|
||||
$column, $unique_keys
|
||||
) {
|
||||
$definition = '<tr class="print-category">';
|
||||
@ -588,16 +612,16 @@ if (isset($plugin_list)) {
|
||||
$fmt_pre = '<em>' . $fmt_pre;
|
||||
$fmt_post = $fmt_post . '</em>';
|
||||
}
|
||||
$definition .= '<td class="print">' . $fmt_pre
|
||||
$definition .= '<td class="print">' . $fmt_pre
|
||||
. htmlspecialchars($column['Field']) . $fmt_post . '</td>';
|
||||
$definition .= '<td class="print">' . htmlspecialchars($type)
|
||||
. '</td>';
|
||||
$definition .= '<td class="print">'
|
||||
. (($column['Null'] == '' || $column['Null'] == 'NO')
|
||||
? __('No')
|
||||
: __('Yes'))
|
||||
$definition .= '<td class="print">'
|
||||
. (($column['Null'] == '' || $column['Null'] == 'NO')
|
||||
? __('No')
|
||||
: __('Yes'))
|
||||
. '</td>';
|
||||
$definition .= '<td class="print">'
|
||||
$definition .= '<td class="print">'
|
||||
. htmlspecialchars(
|
||||
isset($column['Default'])
|
||||
? $column['Default']
|
||||
@ -608,4 +632,4 @@ if (isset($plugin_list)) {
|
||||
return $definition;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build dumps of tables as JSON
|
||||
* Set of methods used to build dumps of tables as JSON
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage JSON
|
||||
@ -10,57 +10,73 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the JSON format
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['json'] = array(
|
||||
'text' => 'JSON',
|
||||
'extension' => 'json',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['json']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data',
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
class ExportJson extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Set of functions used to build exports of tables
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export JSON properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => 'JSON',
|
||||
'extension' => 'json',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data',
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
PMA_exportOutputHandler(
|
||||
'/**' . $GLOBALS['crlf']
|
||||
@ -71,16 +87,24 @@ if (isset($plugin_list)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
PMA_exportOutputHandler('// Database \'' . $db . '\'' . $GLOBALS['crlf']);
|
||||
return true;
|
||||
@ -92,10 +116,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -106,16 +128,14 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in JSON format
|
||||
* Outputs the content of a table in CSV format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -124,13 +144,10 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$columns_cnt = PMA_DBI_num_fields($result);
|
||||
|
||||
// Get field information
|
||||
@ -156,11 +173,8 @@ if (isset($plugin_list)) {
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
|
||||
$isLastLine = ($i + 1 >= $columns_cnt);
|
||||
|
||||
$column = $columns[$i];
|
||||
|
||||
if (is_null($record[$i])) {
|
||||
$buffer .= '"' . addslashes($column)
|
||||
. '": null'
|
||||
@ -190,8 +204,7 @@ if (isset($plugin_list)) {
|
||||
}
|
||||
|
||||
PMA_DBI_free_result($result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build LaTeX dumps of tables
|
||||
* Set of methods used to build dumps of tables as Latex
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage Latex
|
||||
@ -10,223 +10,250 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Messages used in default captions */
|
||||
$GLOBALS['strLatexContent'] = __('Content of table @TABLE@');
|
||||
$GLOBALS['strLatexContinued'] = __('(continued)');
|
||||
$GLOBALS['strLatexStructure'] = __('Structure of table @TABLE@');
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the Latex format
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$hide_structure = false;
|
||||
if ($plugin_param['export_type'] == 'table' && ! $plugin_param['single_table']) {
|
||||
$hide_structure = true;
|
||||
class ExportLatex extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// initialize the specific export sql variables
|
||||
$this->initSpecificVariables();
|
||||
|
||||
$this->setProperties();
|
||||
}
|
||||
$plugin_list['latex'] = array(
|
||||
'text' => __('LaTeX'),
|
||||
'extension' => 'tex',
|
||||
'mime_type' => 'application/x-tex',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['latex']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'caption',
|
||||
'text' => __('Include table caption')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
/* what to dump (structure/data/both) */
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'dump_what',
|
||||
'text' => __('Dump table')
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
/**
|
||||
* Initialize the local variables that are used for export Latex
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initSpecificVariables()
|
||||
{
|
||||
/* Messages used in default captions */
|
||||
$GLOBALS['strLatexContent'] = __('Content of table @TABLE@');
|
||||
$GLOBALS['strLatexContinued'] = __('(continued)');
|
||||
$GLOBALS['strLatexStructure'] = __('Structure of table @TABLE@');
|
||||
}
|
||||
|
||||
/* Structure options */
|
||||
if (! $hide_structure) {
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'structure',
|
||||
'text' => __('Object creation options'),
|
||||
'force' => 'data'
|
||||
/**
|
||||
* Sets the export Latex properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$plugin_param = $this->getPluginParam();
|
||||
$hide_structure = false;
|
||||
if ($plugin_param['export_type'] == 'table'
|
||||
&& ! $plugin_param['single_table']
|
||||
) {
|
||||
$hide_structure = true;
|
||||
}
|
||||
|
||||
$this->properties = array(
|
||||
'text' => __('LaTeX'),
|
||||
'extension' => 'tex',
|
||||
'mime_type' => 'application/x-tex',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'caption',
|
||||
'text' => __('Include table caption')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
|
||||
/* what to dump (structure/data/both) */
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'dump_what',
|
||||
'text' => __('Dump table')
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
|
||||
/* Structure options */
|
||||
if (! $hide_structure) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'structure',
|
||||
'text' => __('Object creation options'),
|
||||
'force' => 'data'
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'structure_caption',
|
||||
'text' => __('Table caption'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'structure_continued_caption',
|
||||
'text' => __('Table caption (continued)'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'structure_label',
|
||||
'text' => __('Label key'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['relation'])) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'relation',
|
||||
'text' => __('Display foreign key relationships')
|
||||
);
|
||||
}
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'comments',
|
||||
'text' => __('Display comments')
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['mimework'])) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'mime',
|
||||
'text' => __('Display MIME types')
|
||||
);
|
||||
}
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
}
|
||||
|
||||
/* Data */
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'structure_caption',
|
||||
'name' => 'data_caption',
|
||||
'text' => __('Table caption'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'structure_continued_caption',
|
||||
'name' => 'data_continued_caption',
|
||||
'text' => __('Table caption (continued)'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'structure_label',
|
||||
'name' => 'data_label',
|
||||
'text' => __('Label key'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['relation'])) {
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'relation',
|
||||
'text' => __('Display foreign key relationships')
|
||||
);
|
||||
}
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'comments',
|
||||
'text' => __('Display comments')
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['mimework'])) {
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'mime',
|
||||
'text' => __('Display MIME types')
|
||||
);
|
||||
}
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
}
|
||||
|
||||
/* Data */
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'data_caption',
|
||||
'text' => __('Table caption'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'data_continued_caption',
|
||||
'text' => __('Table caption (continued)'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'data_label',
|
||||
'text' => __('Label key'),
|
||||
'doc' => 'faq6_27'
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
);
|
||||
$plugin_list['latex']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Escapes some special characters for use in TeX/LaTeX
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param string $string the string to convert
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return string the converted string with escape codes
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function PMA_texEscape($string)
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
$escape = array('$', '%', '{', '}', '&', '#', '_', '^');
|
||||
$cnt_escape = count($escape);
|
||||
for ($k = 0; $k < $cnt_escape; $k++) {
|
||||
$string = str_replace($escape[$k], '\\' . $escape[$k], $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
global $crlf;
|
||||
global $cfg;
|
||||
$this->setCrlf($crlf);
|
||||
$this->setCfg($cfg);
|
||||
|
||||
$head = '% phpMyAdmin LaTeX Dump' . $crlf
|
||||
. '% version ' . PMA_VERSION . $crlf
|
||||
. '% http://www.phpmyadmin.net' . $crlf
|
||||
. '%' . $crlf
|
||||
. '% ' . __('Host') . ': ' . $cfg['Server']['host'];
|
||||
$head = '% phpMyAdmin LaTeX Dump' . $crlf
|
||||
. '% version ' . PMA_VERSION . $crlf
|
||||
. '% http://www.phpmyadmin.net' . $crlf
|
||||
. '%' . $crlf
|
||||
. '% ' . __('Host') . ': ' . $cfg['Server']['host'];
|
||||
if (! empty($cfg['Server']['port'])) {
|
||||
$head .= ':' . $cfg['Server']['port'];
|
||||
}
|
||||
$head .= $crlf
|
||||
. '% ' . __('Generation Time') . ': ' . PMA_localisedDate() . $crlf
|
||||
. '% ' . __('Server version') . ': ' . PMA_MYSQL_STR_VERSION . $crlf
|
||||
. '% ' . __('PHP Version') . ': ' . phpversion() . $crlf;
|
||||
. '% ' . __('Generation Time') . ': ' . PMA_localisedDate() . $crlf
|
||||
. '% ' . __('Server version') . ': ' . PMA_MYSQL_STR_VERSION . $crlf
|
||||
. '% ' . __('PHP Version') . ': ' . phpversion() . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
global $crlf;
|
||||
$crlf = $this->getCrlf();
|
||||
$head = '% ' . $crlf
|
||||
. '% ' . __('Database') . ': ' . '\'' . $db . '\'' . $crlf
|
||||
. '% ' . $crlf;
|
||||
. '% ' . __('Database') . ': ' . '\'' . $db . '\'' . $crlf
|
||||
. '% ' . $crlf;
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
@ -236,10 +263,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -250,16 +275,14 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in LaTeX table/sideways table environment
|
||||
* Outputs the content of a table in JSON format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -268,12 +291,10 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
$result = PMA_DBI_try_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$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++) {
|
||||
@ -281,7 +302,7 @@ if (isset($plugin_list)) {
|
||||
}
|
||||
unset($i);
|
||||
|
||||
$buffer = $crlf . '%' . $crlf . '% ' . __('Data') . ': ' . $table
|
||||
$buffer = $crlf . '%' . $crlf . '% ' . __('Data') . ': ' . $table
|
||||
. $crlf . '%' . $crlf . ' \\begin{longtable}{|';
|
||||
|
||||
for ($index = 0; $index < $columns_cnt; $index++) {
|
||||
@ -294,13 +315,15 @@ if (isset($plugin_list)) {
|
||||
$buffer .= ' \\caption{'
|
||||
. PMA_expandUserString(
|
||||
$GLOBALS['latex_data_caption'],
|
||||
'PMA_texEscape',
|
||||
'texEscape',
|
||||
get_class($this),
|
||||
array('table' => $table, 'database' => $db)
|
||||
)
|
||||
. '} \\label{'
|
||||
. PMA_expandUserString(
|
||||
$GLOBALS['latex_data_label'],
|
||||
null,
|
||||
null,
|
||||
array('table' => $table, 'database' => $db)
|
||||
)
|
||||
. '} \\\\';
|
||||
@ -314,7 +337,7 @@ if (isset($plugin_list)) {
|
||||
$buffer = '\\hline ';
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
$buffer .= '\\multicolumn{1}{|c|}{\\textbf{'
|
||||
. PMA_texEscape(stripslashes($columns[$i])) . '}} & ';
|
||||
. $this::texEscape(stripslashes($columns[$i])) . '}} & ';
|
||||
}
|
||||
|
||||
$buffer = substr($buffer, 0, -2) . '\\\\ \\hline \hline ';
|
||||
@ -326,7 +349,8 @@ if (isset($plugin_list)) {
|
||||
'\\caption{'
|
||||
. PMA_expandUserString(
|
||||
$GLOBALS['latex_data_continued_caption'],
|
||||
'PMA_texEscape',
|
||||
'texEscape',
|
||||
get_class($this),
|
||||
array('table' => $table, 'database' => $db)
|
||||
)
|
||||
. '} \\\\ '
|
||||
@ -345,7 +369,6 @@ if (isset($plugin_list)) {
|
||||
|
||||
// print the whole table
|
||||
while ($record = PMA_DBI_fetch_assoc($result)) {
|
||||
|
||||
$buffer = '';
|
||||
// print each row
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
@ -353,7 +376,7 @@ if (isset($plugin_list)) {
|
||||
|| ! is_null($record[$columns[$i]]))
|
||||
&& isset($record[$columns[$i]])
|
||||
) {
|
||||
$column_value = PMA_texEscape(
|
||||
$column_value = $this::texEscape(
|
||||
stripslashes($record[$columns[$i]])
|
||||
);
|
||||
} else {
|
||||
@ -380,7 +403,6 @@ if (isset($plugin_list)) {
|
||||
|
||||
PMA_DBI_free_result($result);
|
||||
return true;
|
||||
|
||||
} // end getTableLaTeX
|
||||
|
||||
/**
|
||||
@ -398,16 +420,14 @@ if (isset($plugin_list)) {
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because export.php calls
|
||||
* PMA_exportStructure() also for other
|
||||
* exportStructure() also for other
|
||||
* export types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure(
|
||||
public function exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -420,12 +440,13 @@ if (isset($plugin_list)) {
|
||||
$dates = false
|
||||
) {
|
||||
global $cfgRelation;
|
||||
$this->setCfgRelation($cfgRelation);
|
||||
|
||||
/**
|
||||
* Get the unique keys in the table
|
||||
*/
|
||||
$unique_keys = array();
|
||||
$keys = PMA_DBI_get_table_indexes($db, $table);
|
||||
$keys = PMA_DBI_get_table_indexes($db, $table);
|
||||
foreach ($keys as $key) {
|
||||
if ($key['Non_unique'] == 0) {
|
||||
$unique_keys[] = $key['Column_name'];
|
||||
@ -499,13 +520,15 @@ if (isset($plugin_list)) {
|
||||
$buffer .= ' \\caption{'
|
||||
. PMA_expandUserString(
|
||||
$GLOBALS['latex_structure_caption'],
|
||||
'PMA_texEscape',
|
||||
'texEscape',
|
||||
get_class($this),
|
||||
array('table' => $table, 'database' => $db)
|
||||
)
|
||||
. '} \\label{'
|
||||
. PMA_expandUserString(
|
||||
$GLOBALS['latex_structure_label'],
|
||||
null,
|
||||
null,
|
||||
array('table' => $table, 'database' => $db)
|
||||
)
|
||||
. '} \\\\' . $crlf;
|
||||
@ -517,7 +540,8 @@ if (isset($plugin_list)) {
|
||||
$buffer .= ' \\caption{'
|
||||
. PMA_expandUserString(
|
||||
$GLOBALS['latex_structure_continued_caption'],
|
||||
'PMA_texEscape',
|
||||
'texEscape',
|
||||
get_class($this),
|
||||
array('table' => $table, 'database' => $db)
|
||||
)
|
||||
. '} \\\\ ' . $crlf;
|
||||
@ -572,7 +596,7 @@ if (isset($plugin_list)) {
|
||||
);
|
||||
}
|
||||
}
|
||||
$local_buffer = PMA_texEscape($local_buffer);
|
||||
$local_buffer = $this::texEscape($local_buffer);
|
||||
if ($row['Key']=='PRI') {
|
||||
$pos=strpos($local_buffer, "\000");
|
||||
$local_buffer = '\\textit{'
|
||||
@ -595,7 +619,23 @@ if (isset($plugin_list)) {
|
||||
|
||||
$buffer = ' \\end{longtable}' . $crlf;
|
||||
return PMA_exportOutputHandler($buffer);
|
||||
} // end of the 'PMA_exportStructure' function
|
||||
} // end of the 'exportStructure' method
|
||||
|
||||
} // end else
|
||||
?>
|
||||
/**
|
||||
* Escapes some special characters for use in TeX/LaTeX
|
||||
*
|
||||
* @param string $string the string to convert
|
||||
*
|
||||
* @return string the converted string with escape codes
|
||||
*/
|
||||
public static function 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
355
libraries/plugins/export/ExportMediawiki.class.php
Normal file
355
libraries/plugins/export/ExportMediawiki.class.php
Normal file
@ -0,0 +1,355 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Set of functions used to build MediaWiki dumps of tables
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage MediaWiki
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the MediaWiki class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class ExportMediawiki extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export MediaWiki properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('MediaWiki Table'),
|
||||
'extension' => 'mediawiki',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
// general options
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
);
|
||||
|
||||
// what to dump (structure/data/both)
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_subgroup',
|
||||
'subgroup_header' => array(
|
||||
'type' => 'message_only',
|
||||
'text' => __('Dump table')
|
||||
)
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_subgroup'
|
||||
);
|
||||
|
||||
// export table name
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'caption',
|
||||
'text' => __('Export table names')
|
||||
);
|
||||
|
||||
// export table headers
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'headers',
|
||||
'text' => __('Export table headers')
|
||||
);
|
||||
|
||||
// end general options
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportHeader ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs table's structure
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $export_mode 'create_table','triggers','create_view',
|
||||
* 'stand_in'
|
||||
* @param string $export_type 'server', 'database', 'table'
|
||||
* @param bool $do_relation whether to include relation comments
|
||||
* @param bool $do_comments whether to include the pmadb-style column
|
||||
* comments as comments in the structure; this is
|
||||
* deprecated but the parameter is left here
|
||||
* because export.php calls exportStructure()
|
||||
* also for other export types which use this
|
||||
* parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
$error_url,
|
||||
$export_mode,
|
||||
$export_type,
|
||||
$do_relation = false,
|
||||
$do_comments = false,
|
||||
$do_mime = false,
|
||||
$dates = false
|
||||
) {
|
||||
switch($export_mode) {
|
||||
case 'create_table':
|
||||
$columns = PMA_DBI_get_columns($db, $table);
|
||||
$columns = array_values($columns);
|
||||
$row_cnt = count($columns);
|
||||
|
||||
// Print structure comment
|
||||
$output = $this->_exportComment(
|
||||
"Table structure for "
|
||||
. PMA_backquote($table)
|
||||
);
|
||||
|
||||
// Begin the table construction
|
||||
$output .= "{| class=\"wikitable\" style=\"text-align:center;\""
|
||||
. $this->_exportCRLF();
|
||||
|
||||
// Add the table name
|
||||
if ($GLOBALS['mediawiki_caption']) {
|
||||
$output .= "|+'''" . $table . "'''" . $this->_exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
if ($GLOBALS['mediawiki_headers']) {
|
||||
$output .= "|- style=\"background:#ffdead;\"" . $this->_exportCRLF();
|
||||
$output .= "! style=\"background:#ffffff\" | "
|
||||
. $this->_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Field']. $this->_exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
// Add the table structure
|
||||
$output .= "|-" . $this->_exportCRLF();
|
||||
$output .= "! Type" . $this->_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Type'] . $this->_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . $this->_exportCRLF();
|
||||
$output .= "! Null" . $this->_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Null'] . $this->_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . $this->_exportCRLF();
|
||||
$output .= "! Default" . $this->_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Default'] . $this->_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|-" . $this->_exportCRLF();
|
||||
$output .= "! Extra" . $this->_exportCRLF();
|
||||
for ($i = 0; $i < $row_cnt; ++$i) {
|
||||
$output .= " | " . $columns[$i]['Extra'] . $this->_exportCRLF();
|
||||
}
|
||||
|
||||
$output .= "|}" . str_repeat($this->_exportCRLF(), 2);
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
return PMA_exportOutputHandler($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in MediaWiki format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportData(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
$error_url,
|
||||
$sql_query
|
||||
) {
|
||||
// Print data comment
|
||||
$output = $this->_exportComment("Table data for ". PMA_backquote($table));
|
||||
|
||||
// Begin the table construction
|
||||
// Use the "wikitable" class for style
|
||||
// Use the "sortable" class for allowing tables to be sorted by column
|
||||
$output .= "{| class=\"wikitable sortable\" style=\"text-align:center;\""
|
||||
. $this->_exportCRLF();
|
||||
|
||||
// Add the table name
|
||||
if ($GLOBALS['mediawiki_caption']) {
|
||||
$output .= "|+'''" . $table . "'''" . $this->_exportCRLF();
|
||||
}
|
||||
|
||||
// Add the table headers
|
||||
if ($GLOBALS['mediawiki_headers']) {
|
||||
// Get column names
|
||||
$column_names = PMA_DBI_get_column_names($db, $table);
|
||||
|
||||
// Add column names as table headers
|
||||
if ( ! is_null($column_names) ) {
|
||||
// Use '|-' for separating rows
|
||||
$output .= "|-" . $this->_exportCRLF();
|
||||
|
||||
// Use '!' for separating table headers
|
||||
foreach ($column_names as $column) {
|
||||
$output .= " ! " . $column . "" . $this->_exportCRLF();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the table data from the database
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
|
||||
while ($row = PMA_DBI_fetch_row($result)) {
|
||||
$output .= "|-" . $this->_exportCRLF();
|
||||
|
||||
// Use '|' for separating table columns
|
||||
for ($i = 0; $i < $fields_cnt; ++ $i) {
|
||||
$output .= " | " . $row[$i] . "" . $this->_exportCRLF();
|
||||
}
|
||||
}
|
||||
|
||||
// End table construction
|
||||
$output .= "|}" . str_repeat($this->_exportCRLF(), 2);
|
||||
return PMA_exportOutputHandler($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs comments containing info about the exported tables
|
||||
*
|
||||
* @param string $text Text of comment
|
||||
*
|
||||
* @return string The formatted comment
|
||||
*/
|
||||
private function _exportComment($text = '')
|
||||
{
|
||||
// see http://www.mediawiki.org/wiki/Help:Formatting
|
||||
$comment = $this->_exportCRLF();
|
||||
$comment .= '<!--' . $this->_exportCRLF();
|
||||
$comment .= $text . $this->_exportCRLF();
|
||||
$comment .= '-->' . str_repeat($this->_exportCRLF(), 2);
|
||||
|
||||
return $comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CRLF
|
||||
*
|
||||
* @return string CRLF
|
||||
*/
|
||||
private function _exportCRLF()
|
||||
{
|
||||
// The CRLF expected by the mediawiki format is "\n"
|
||||
return "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -10,78 +10,87 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
$GLOBALS['ods_buffer'] = '';
|
||||
require_once 'libraries/opendocument.lib.php';
|
||||
|
||||
/**
|
||||
* Handles the export for the ODS class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['ods'] = array(
|
||||
'text' => __('Open Document Spreadsheet'),
|
||||
'extension' => 'ods',
|
||||
'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['ods']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
$GLOBALS['ods_buffer'] = '';
|
||||
include_once './libraries/opendocument.lib.php';
|
||||
class ExportOds extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
* Sets the export ODS properties
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
protected function setProperties()
|
||||
{
|
||||
$GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
|
||||
. '</office:body>'
|
||||
. '</office:document-content>';
|
||||
if (! PMA_exportOutputHandler(
|
||||
PMA_createOpenDocument(
|
||||
'application/vnd.oasis.opendocument.spreadsheet',
|
||||
$GLOBALS['ods_buffer']
|
||||
$this->properties = array(
|
||||
'text' => __('Open Document Spreadsheet'),
|
||||
'extension' => 'ods',
|
||||
'mime_type' => 'application/vnd.oasis.opendocument.spreadsheet',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
$GLOBALS['ods_buffer'] .= '<?xml version="1.0" encoding="utf-8"?' . '>'
|
||||
. '<office:document-content '
|
||||
@ -131,16 +140,35 @@ if (isset($plugin_list)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
$GLOBALS['ods_buffer'] .= '</office:spreadsheet>'
|
||||
. '</office:body>'
|
||||
. '</office:document-content>';
|
||||
if (! PMA_exportOutputHandler(
|
||||
PMA_createOpenDocument(
|
||||
'application/vnd.oasis.opendocument.spreadsheet',
|
||||
$GLOBALS['ods_buffer']
|
||||
)
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -151,10 +179,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -165,16 +191,14 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in ODS format
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -183,16 +207,15 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $what;
|
||||
$this->setWhat($what);
|
||||
|
||||
// Gets the data from the database
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
$fields_meta = PMA_DBI_get_fields_meta($result);
|
||||
$field_flags = array();
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
@ -295,6 +318,5 @@ if (isset($plugin_list)) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@ -4,115 +4,164 @@
|
||||
* Set of functions used to build OpenDocument Text dumps of tables
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage ODT
|
||||
* @subpackage ODS
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
$GLOBALS['odt_buffer'] = '';
|
||||
require_once 'libraries/opendocument.lib.php';
|
||||
|
||||
/**
|
||||
* Handles the export for the ODT class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$hide_structure = false;
|
||||
if ($plugin_param['export_type'] == 'table'
|
||||
&& ! $plugin_param['single_table']
|
||||
) {
|
||||
$hide_structure = true;
|
||||
class ExportOdt extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
$plugin_list['odt'] = array(
|
||||
'text' => __('Open Document Text'),
|
||||
'extension' => 'odt',
|
||||
'mime_type' => 'application/vnd.oasis.opendocument.text',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
/* what to dump (structure/data/both) */
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'text' => __('Dump table'),
|
||||
'name' => 'general_opts'
|
||||
);
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
);
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
/**
|
||||
* Sets the export ODT properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$plugin_param = $this->getPluginParam();
|
||||
$hide_structure = false;
|
||||
if ($plugin_param['export_type'] == 'table'
|
||||
&& ! $plugin_param['single_table']
|
||||
) {
|
||||
$hide_structure = true;
|
||||
}
|
||||
|
||||
/* Structure options */
|
||||
if (! $hide_structure) {
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
$this->properties = array(
|
||||
'text' => __('Open Document Text'),
|
||||
'extension' => 'odt',
|
||||
'mime_type' => 'application/vnd.oasis.opendocument.text',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
/* what to dump (structure/data/both) */
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'structure',
|
||||
'text' => __('Object creation options'),
|
||||
'force' => 'data'
|
||||
'text' => __('Dump table'),
|
||||
'name' => 'general_opts'
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['relation'])) {
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
|
||||
/* Structure options */
|
||||
if (! $hide_structure) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'structure',
|
||||
'text' => __('Object creation options'),
|
||||
'force' => 'data'
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['relation'])) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'relation',
|
||||
'text' => __('Display foreign key relationships')
|
||||
);
|
||||
}
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'relation',
|
||||
'text' => __('Display foreign key relationships')
|
||||
'name' => 'comments',
|
||||
'text' => __('Display comments')
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['mimework'])) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'mime',
|
||||
'text' => __('Display MIME types')
|
||||
);
|
||||
}
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
}
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
|
||||
/* Data */
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'comments',
|
||||
'text' => __('Display comments')
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
);
|
||||
if (! empty($GLOBALS['cfgRelation']['mimework'])) {
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'mime',
|
||||
'text' => __('Display MIME types')
|
||||
);
|
||||
}
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
}
|
||||
|
||||
/* Data */
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
);
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
);
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL with:')
|
||||
);
|
||||
$plugin_list['odt']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
} else {
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
$GLOBALS['odt_buffer'] = '';
|
||||
include_once './libraries/opendocument.lib.php';
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportHeader ()
|
||||
{
|
||||
$GLOBALS['odt_buffer'] .= '<?xml version="1.0" encoding="utf-8"?' . '>'
|
||||
. '<office:document-content '
|
||||
. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
|
||||
. '<office:body>'
|
||||
. '<office:text>';
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
public function exportFooter ()
|
||||
{
|
||||
$GLOBALS['odt_buffer'] .= '</office:text>'
|
||||
. '</office:body>'
|
||||
@ -128,33 +177,14 @@ if (isset($plugin_list)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
{
|
||||
$GLOBALS['odt_buffer'] .= '<?xml version="1.0" encoding="utf-8"?' . '>'
|
||||
. '<office:document-content '
|
||||
. $GLOBALS['OpenDocumentNS'] . 'office:version="1.0">'
|
||||
. '<office:body>'
|
||||
. '<office:text>';
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
$GLOBALS['odt_buffer'] .=
|
||||
'<text:h text:outline-level="1" text:style-name="Heading_1"'
|
||||
@ -170,10 +200,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -184,16 +212,13 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in ODT format
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -202,16 +227,15 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $what;
|
||||
$this->setWhat($what);
|
||||
|
||||
// Gets the data from the database
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$fields_cnt = PMA_DBI_num_fields($result);
|
||||
$fields_meta = PMA_DBI_get_fields_meta($result);
|
||||
$field_flags = array();
|
||||
for ($j = 0; $j < $fields_cnt; $j++) {
|
||||
@ -221,7 +245,7 @@ if (isset($plugin_list)) {
|
||||
$GLOBALS['odt_buffer'] .=
|
||||
'<text:h text:outline-level="2" text:style-name="Heading_2"'
|
||||
. ' text:is-list-header="true">'
|
||||
. __('Dumping data for table') . ' ' . htmlspecialchars($table)
|
||||
. __('Dumping data for table') . ' ' . htmlspecialchars($table)
|
||||
. '</text:h>'
|
||||
. '<table:table'
|
||||
. ' table:name="' . htmlspecialchars($table) . '_structure">'
|
||||
@ -300,10 +324,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $crlf the end of line sequence
|
||||
*
|
||||
* @return bool true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTableDefStandIn($db, $view, $crlf)
|
||||
public function getTableDefStandIn($db, $view, $crlf)
|
||||
{
|
||||
/**
|
||||
* Gets fields properties
|
||||
@ -338,7 +360,7 @@ if (isset($plugin_list)) {
|
||||
|
||||
$columns = PMA_DBI_get_columns($db, $view);
|
||||
foreach ($columns as $column) {
|
||||
$GLOBALS['odt_buffer'] .= PMA_formatOneColumnDefinition($column);
|
||||
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
|
||||
$GLOBALS['odt_buffer'] .= '</table:table-row>';
|
||||
} // end foreach
|
||||
|
||||
@ -364,12 +386,10 @@ if (isset($plugin_list)) {
|
||||
* @param bool $add_semicolon whether to add semicolon and end-of-line at
|
||||
* the end
|
||||
* @param bool $view whether we're handling a view
|
||||
*
|
||||
*
|
||||
* @return bool true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTableDef(
|
||||
public function getTableDef(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -382,6 +402,7 @@ if (isset($plugin_list)) {
|
||||
$view = false
|
||||
) {
|
||||
global $cfgRelation;
|
||||
$this->setCfgRelation($cfgRelation);
|
||||
|
||||
/**
|
||||
* Gets fields properties
|
||||
@ -456,7 +477,7 @@ if (isset($plugin_list)) {
|
||||
$columns = PMA_DBI_get_columns($db, $table);
|
||||
foreach ($columns as $column) {
|
||||
$field_name = $column['Field'];
|
||||
$GLOBALS['odt_buffer'] .= PMA_formatOneColumnDefinition($column);
|
||||
$GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column);
|
||||
|
||||
if ($do_relation && $have_rel) {
|
||||
if (isset($res_rel[$field_name])) {
|
||||
@ -508,7 +529,7 @@ if (isset($plugin_list)) {
|
||||
|
||||
$GLOBALS['odt_buffer'] .= '</table:table>';
|
||||
return true;
|
||||
} // end of the 'PMA_getTableDef()' function
|
||||
} // end of the '$this->getTableDef()' function
|
||||
|
||||
/**
|
||||
* Outputs triggers
|
||||
@ -517,10 +538,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $table table name
|
||||
*
|
||||
* @return bool true
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTriggers($db, $table)
|
||||
protected function getTriggers($db, $table)
|
||||
{
|
||||
$GLOBALS['odt_buffer'] .= '<table:table'
|
||||
. ' table:name="' . htmlspecialchars($table) . '_triggers">'
|
||||
@ -592,10 +611,8 @@ if (isset($plugin_list)) {
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure(
|
||||
public function exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -615,7 +632,7 @@ if (isset($plugin_list)) {
|
||||
. __('Table structure for table') . ' ' .
|
||||
htmlspecialchars($table)
|
||||
. '</text:h>';
|
||||
PMA_getTableDef(
|
||||
$this->getTableDef(
|
||||
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
|
||||
$do_mime, $dates
|
||||
);
|
||||
@ -629,7 +646,7 @@ if (isset($plugin_list)) {
|
||||
. __('Triggers') . ' '
|
||||
. htmlspecialchars($table)
|
||||
. '</text:h>';
|
||||
PMA_getTriggers($db, $table);
|
||||
$this->getTriggers($db, $table);
|
||||
}
|
||||
break;
|
||||
case 'create_view':
|
||||
@ -639,7 +656,7 @@ if (isset($plugin_list)) {
|
||||
. __('Structure for view') . ' '
|
||||
. htmlspecialchars($table)
|
||||
. '</text:h>';
|
||||
PMA_getTableDef(
|
||||
$this->getTableDef(
|
||||
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
|
||||
$do_mime, $dates, true, true
|
||||
);
|
||||
@ -652,11 +669,11 @@ if (isset($plugin_list)) {
|
||||
. htmlspecialchars($table)
|
||||
. '</text:h>';
|
||||
// export a stand-in definition to resolve view dependencies
|
||||
PMA_getTableDefStandIn($db, $table, $crlf);
|
||||
$this->getTableDefStandIn($db, $table, $crlf);
|
||||
} // end switch
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_exportStructure' function
|
||||
} // end of the '$this->exportStructure' function
|
||||
|
||||
/**
|
||||
* Formats the definition for one column
|
||||
@ -664,10 +681,8 @@ if (isset($plugin_list)) {
|
||||
* @param array $column info about this column
|
||||
*
|
||||
* @return string Formatted column definition
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_formatOneColumnDefinition($column)
|
||||
protected function formatOneColumnDefinition($column)
|
||||
{
|
||||
$field_name = $column['Field'];
|
||||
$definition = '<table:table-row>';
|
||||
@ -705,5 +720,5 @@ if (isset($plugin_list)) {
|
||||
. '</table:table-cell>';
|
||||
return $definition;
|
||||
}
|
||||
} // end else
|
||||
?>
|
||||
}
|
||||
?>
|
||||
257
libraries/plugins/export/ExportPdf.class.php
Normal file
257
libraries/plugins/export/ExportPdf.class.php
Normal file
@ -0,0 +1,257 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Produce a PDF report (export) from a query
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage PDF
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
/* Get the PMA_ExportPdf class */
|
||||
require_once 'libraries/plugins/export/PMA_ExportPdf.class.php';
|
||||
|
||||
/**
|
||||
* Handles the export for the PDF class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class ExportPdf extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* PMA_ExportPdf instance
|
||||
*
|
||||
* @var PMA_ExportPdf
|
||||
*/
|
||||
private $_pdf;
|
||||
|
||||
/**
|
||||
* PDF Report Title
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_pdfReportTitle;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// initialize the specific export PDF variables
|
||||
$this->initSpecificVariables();
|
||||
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the local variables that are used for export PDF
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initSpecificVariables()
|
||||
{
|
||||
$this->_setPdfReportTitle("");
|
||||
$this->_setPdf(new PMA_ExportPdf('L', 'pt', 'A3'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export PDF properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('PDF'),
|
||||
'extension' => 'pdf',
|
||||
'mime_type' => 'application/pdf',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'message_only',
|
||||
'name' => 'explanation',
|
||||
'text' => __(
|
||||
'(Generates a report containing the data of a single table)'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'report_title',
|
||||
'text' => __('Report title:')
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportHeader ()
|
||||
{
|
||||
$pdf_report_title = $this->_getPdfReportTitle();
|
||||
$pdf = $this->_getPdf();
|
||||
$pdf->Open();
|
||||
|
||||
$attr = array('titleFontSize' => 18, 'titleText' => $pdf_report_title);
|
||||
$pdf->setAttributes($attr);
|
||||
$pdf->setTopMargin(30);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
$pdf = $this->_getPdf();
|
||||
|
||||
// instead of $pdf->Output():
|
||||
if (! PMA_exportOutputHandler($pdf->getPDFData())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database footer
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs CREATE DATABASE statement
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
* @param string $crlf the end of line sequence
|
||||
* @param string $error_url the url to go back in case of error
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
$pdf = $this->_getPdf();
|
||||
|
||||
$attr = array('currentDb' => $db, 'currentTable' => $table);
|
||||
$pdf->setAttributes($attr);
|
||||
$pdf->mysqlReport($sql_query);
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_exportData()' function
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Gets the PMA_ExportPdf instance
|
||||
*
|
||||
* @return PMA_ExportPdf
|
||||
*/
|
||||
private function _getPdf()
|
||||
{
|
||||
return $this->_pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates the PMA_ExportPdf class
|
||||
*
|
||||
* @param string $pdf PMA_ExportPdf instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setPdf($pdf)
|
||||
{
|
||||
$this->_pdf = $pdf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PDF report title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _getPdfReportTitle()
|
||||
{
|
||||
return $this->_pdfReportTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the PDF report title
|
||||
*
|
||||
* @param string $pdfReportTitle PDF report title
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setPdfReportTitle($pdfReportTitle)
|
||||
{
|
||||
$this->_pdfReportTitle = $pdfReportTitle;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -10,57 +10,73 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the PHP Array class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['php_array'] = array(
|
||||
'text' => __('PHP array'),
|
||||
'extension' => 'php',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['php_array']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data',
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
class ExportPhparray extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Set of functions used to build exports of tables
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export PHP Array properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('PHP array'),
|
||||
'extension' => 'php',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data',
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
PMA_exportOutputHandler(
|
||||
'<?php' . $GLOBALS['crlf']
|
||||
@ -72,16 +88,24 @@ if (isset($plugin_list)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
PMA_exportOutputHandler(
|
||||
'//' . $GLOBALS['crlf']
|
||||
@ -97,10 +121,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -111,16 +133,14 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table as a fragment of PHP code
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -129,12 +149,10 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
|
||||
$columns_cnt = PMA_DBI_num_fields($result);
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
@ -144,12 +162,12 @@ if (isset($plugin_list)) {
|
||||
|
||||
// fix variable names (based on
|
||||
// http://www.php.net/manual/language.variables.basics.php)
|
||||
if (preg_match(
|
||||
if (! preg_match(
|
||||
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/',
|
||||
$table
|
||||
) == false
|
||||
) {
|
||||
// fix invalid chars in variable names by replacing them with underscores
|
||||
)) {
|
||||
// fix invalid characters in variable names by replacing them with
|
||||
// underscores
|
||||
$tablefixed = preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '_', $table);
|
||||
|
||||
// variable name must not start with a number or dash...
|
||||
@ -163,10 +181,9 @@ if (isset($plugin_list)) {
|
||||
$buffer = '';
|
||||
$record_cnt = 0;
|
||||
while ($record = PMA_DBI_fetch_row($result)) {
|
||||
|
||||
$record_cnt++;
|
||||
|
||||
// Output table name as comment if this is the first record of the table
|
||||
// Output table name as comment if it's the first record of the table
|
||||
if ($record_cnt == 1) {
|
||||
$buffer .= $crlf . '// '. PMA_backquote($db) . '.'
|
||||
. PMA_backquote($table) . $crlf;
|
||||
@ -191,8 +208,7 @@ if (isset($plugin_list)) {
|
||||
}
|
||||
|
||||
PMA_DBI_free_result($result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@ -4,85 +4,115 @@
|
||||
* Export to Texy! text.
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage Texy
|
||||
* @subpackage Texy!text
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['texytext'] = array(
|
||||
'text' => __('Texy! text'),
|
||||
'extension' => 'txt',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
$plugin_list['texytext']['options'] = array(
|
||||
/* what to dump (structure/data/both) */
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'text' => __('Dump table'),
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
),
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL by')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
/**
|
||||
* Handles the export for the Texy! text class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class ExportTexytext extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
* Sets the export Texy! text properties
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('Texy! text'),
|
||||
'extension' => 'txt',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
/* what to dump (structure/data/both) */
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'text' => __('Dump table'),
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'name' => 'structure_or_data',
|
||||
'values' => array(
|
||||
'structure' => __('structure'),
|
||||
'data' => __('data'),
|
||||
'structure_and_data' => __('structure and data')
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
),
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options'),
|
||||
'force' => 'structure'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'null',
|
||||
'text' => __('Replace NULL by')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'columns',
|
||||
'text' => __('Put columns names in the first row')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -93,10 +123,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return PMA_exportOutputHandler(
|
||||
'===' . __('Database') . ' ' . $db . "\n\n"
|
||||
@ -109,10 +137,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -123,16 +149,13 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in Texy format
|
||||
* Outputs the content of a table in NHibernate format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -141,12 +164,11 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
global $what;
|
||||
$this->setWhat($what);
|
||||
|
||||
if (! PMA_exportOutputHandler(
|
||||
'== ' . __('Dumping data for table') . ' ' . $table . "\n\n"
|
||||
@ -207,10 +229,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $crlf the end of line sequence
|
||||
*
|
||||
* @return string resulting definition
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTableDefStandIn($db, $view, $crlf)
|
||||
function getTableDefStandIn($db, $view, $crlf)
|
||||
{
|
||||
$text_output = '';
|
||||
|
||||
@ -218,7 +238,7 @@ if (isset($plugin_list)) {
|
||||
* Get the unique keys in the table
|
||||
*/
|
||||
$unique_keys = array();
|
||||
$keys = PMA_DBI_get_table_indexes($db, $view);
|
||||
$keys = PMA_DBI_get_table_indexes($db, $view);
|
||||
foreach ($keys as $key) {
|
||||
if ($key['Non_unique'] == 0) {
|
||||
$unique_keys[] = $key['Column_name'];
|
||||
@ -234,16 +254,16 @@ if (isset($plugin_list)) {
|
||||
* Displays the table structure
|
||||
*/
|
||||
|
||||
$text_output .= "|------\n";
|
||||
$text_output .= '|' . __('Column');
|
||||
$text_output .= '|' . __('Type');
|
||||
$text_output .= '|' . __('Null');
|
||||
$text_output .= '|' . __('Default');
|
||||
$text_output .= "\n|------\n";
|
||||
$text_output .= "|------\n"
|
||||
. '|' . __('Column')
|
||||
. '|' . __('Type')
|
||||
. '|' . __('Null')
|
||||
. '|' . __('Default')
|
||||
. "\n|------\n";
|
||||
|
||||
$columns = PMA_DBI_get_columns($db, $view);
|
||||
foreach ($columns as $column) {
|
||||
$text_output .= PMA_formatOneColumnDefinition($column, $unique_keys);
|
||||
$text_output .= $this->formatOneColumnDefinition($column, $unique_keys);
|
||||
$text_output .= "\n";
|
||||
} // end foreach
|
||||
|
||||
@ -262,7 +282,7 @@ if (isset($plugin_list)) {
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because export.php calls
|
||||
* PMA_exportStructure() also for other
|
||||
* $this->exportStructure() also for other
|
||||
* export types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $show_dates whether to include creation/update/check dates
|
||||
@ -271,10 +291,8 @@ if (isset($plugin_list)) {
|
||||
* @param bool $view whether we're handling a view
|
||||
*
|
||||
* @return string resulting schema
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTableDef(
|
||||
function getTableDef(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -287,6 +305,7 @@ if (isset($plugin_list)) {
|
||||
$view = false
|
||||
) {
|
||||
global $cfgRelation;
|
||||
$this->setCfgRelation($cfgRelation);
|
||||
|
||||
$text_output = '';
|
||||
|
||||
@ -356,7 +375,7 @@ if (isset($plugin_list)) {
|
||||
|
||||
$columns = PMA_DBI_get_columns($db, $table);
|
||||
foreach ($columns as $column) {
|
||||
$text_output .= PMA_formatOneColumnDefinition($column, $unique_keys);
|
||||
$text_output .= $this->formatOneColumnDefinition($column, $unique_keys);
|
||||
$field_name = $column['Field'];
|
||||
|
||||
if ($do_relation && $have_rel) {
|
||||
@ -387,7 +406,7 @@ if (isset($plugin_list)) {
|
||||
} // end foreach
|
||||
|
||||
return $text_output;
|
||||
} // end of the 'PMA_getTableDef()' function
|
||||
} // end of the '$this->getTableDef()' function
|
||||
|
||||
/**
|
||||
* Outputs triggers
|
||||
@ -396,10 +415,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $table table name
|
||||
*
|
||||
* @return string Formatted triggers list
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_getTriggers($db, $table)
|
||||
function getTriggers($db, $table)
|
||||
{
|
||||
$text_output .= "|------\n";
|
||||
$text_output .= '|' . __('Column');
|
||||
@ -443,16 +460,14 @@ if (isset($plugin_list)) {
|
||||
* comments as comments in the structure;
|
||||
* this is deprecated but the parameter is
|
||||
* left here because export.php calls
|
||||
* PMA_exportStructure() also for other
|
||||
* $this->exportStructure() also for other
|
||||
* export types which use this parameter
|
||||
* @param bool $do_mime whether to include mime comments
|
||||
* @param bool $dates whether to include creation/update/check dates
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportStructure(
|
||||
function exportStructure(
|
||||
$db,
|
||||
$table,
|
||||
$crlf,
|
||||
@ -469,7 +484,7 @@ if (isset($plugin_list)) {
|
||||
switch($export_mode) {
|
||||
case 'create_table':
|
||||
$dump .= '== ' . __('Table structure for table') . ' ' .$table . "\n\n";
|
||||
$dump .= PMA_getTableDef(
|
||||
$dump .= $this->getTableDef(
|
||||
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
|
||||
$do_mime, $dates
|
||||
);
|
||||
@ -479,12 +494,12 @@ if (isset($plugin_list)) {
|
||||
$triggers = PMA_DBI_get_triggers($db, $table);
|
||||
if ($triggers) {
|
||||
$dump .= '== ' . __('Triggers') . ' ' .$table . "\n\n";
|
||||
$dump .= PMA_getTriggers($db, $table);
|
||||
$dump .= $this->getTriggers($db, $table);
|
||||
}
|
||||
break;
|
||||
case 'create_view':
|
||||
$dump .= '== ' . __('Structure for view') . ' ' .$table . "\n\n";
|
||||
$dump .= PMA_getTableDef(
|
||||
$dump .= $this->getTableDef(
|
||||
$db, $table, $crlf, $error_url, $do_relation, $do_comments,
|
||||
$do_mime, $dates, true, true
|
||||
);
|
||||
@ -493,23 +508,21 @@ if (isset($plugin_list)) {
|
||||
$dump .= '== ' . __('Stand-in structure for view')
|
||||
. ' ' .$table . "\n\n";
|
||||
// export a stand-in definition to resolve view dependencies
|
||||
$dump .= PMA_getTableDefStandIn($db, $table, $crlf);
|
||||
$dump .= $this->getTableDefStandIn($db, $table, $crlf);
|
||||
} // end switch
|
||||
|
||||
return PMA_exportOutputHandler($dump);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the definition for one column
|
||||
* Formats the definition for one column
|
||||
*
|
||||
* @param array $column info about this column
|
||||
* @param array $unique_keys unique keys for this table
|
||||
*
|
||||
* @return string Formatted column definition
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_formatOneColumnDefinition(
|
||||
function formatOneColumnDefinition(
|
||||
$column, $unique_keys
|
||||
) {
|
||||
$extracted_columnspec = PMA_extractColumnSpec($column['Type']);
|
||||
@ -547,4 +560,4 @@ if (isset($plugin_list)) {
|
||||
return $definition;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@ -9,117 +9,166 @@
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if (! strlen($GLOBALS['db'])) { /* Can't do server export */
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['xml'] = array(
|
||||
'text' => __('XML'),
|
||||
'extension' => 'xml',
|
||||
'mime_type' => 'text/xml',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
$plugin_list['xml']['options'] = array(
|
||||
array(
|
||||
/**
|
||||
* Handles the export for the XML class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class ExportXml extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_table;
|
||||
|
||||
/**
|
||||
* Table names
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_tables;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the local variables that are used for export PDF
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function initSpecificVariables()
|
||||
{
|
||||
global $table, $tables;
|
||||
$this->_setTable($table);
|
||||
$this->_setTables($tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export XML properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('XML'),
|
||||
'extension' => 'xml',
|
||||
'mime_type' => 'text/xml',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
|
||||
/* Export structure */
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data'
|
||||
),
|
||||
array(
|
||||
'name' => 'structure',
|
||||
'text' => __('Object creation options (all are recommended)')
|
||||
);
|
||||
if (! PMA_DRIZZLE) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_functions',
|
||||
'text' => __('Functions')
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_procedures',
|
||||
'text' => __('Procedures')
|
||||
);
|
||||
}
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_tables',
|
||||
'text' => __('Tables')
|
||||
);
|
||||
if (! PMA_DRIZZLE) {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_triggers',
|
||||
'text' => __('Triggers')
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_views',
|
||||
'text' => __('Views')
|
||||
);
|
||||
}
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
|
||||
/* Export structure */
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'structure',
|
||||
'text' => __('Object creation options (all are recommended)')
|
||||
);
|
||||
if (! PMA_DRIZZLE) {
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_functions',
|
||||
'text' => __('Functions')
|
||||
);
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_procedures',
|
||||
'text' => __('Procedures')
|
||||
);
|
||||
}
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_tables',
|
||||
'text' => __('Tables')
|
||||
);
|
||||
if (! PMA_DRIZZLE) {
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_triggers',
|
||||
'text' => __('Triggers')
|
||||
);
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_views',
|
||||
'text' => __('Views')
|
||||
);
|
||||
}
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
|
||||
/* Data */
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options')
|
||||
);
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_contents',
|
||||
'text' => __('Export contents')
|
||||
);
|
||||
$plugin_list['xml']['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
{
|
||||
$foot = '</pma_xml_export>';
|
||||
|
||||
return PMA_exportOutputHandler($foot);
|
||||
/* Data */
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'data',
|
||||
'text' => __('Data dump options')
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'export_contents',
|
||||
'text' => __('Export contents')
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'end_group'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header. It is the first method to be called, so all
|
||||
* the required variables are initialized here.
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
global $crlf;
|
||||
global $cfg;
|
||||
global $db;
|
||||
global $table;
|
||||
global $tables;
|
||||
$this->initSpecificVariables();
|
||||
global $crlf, $cfg, $db;
|
||||
$this->setCrlf($crlf);
|
||||
$this->setCfg($cfg);
|
||||
$this->setDb($db);
|
||||
$table = $this->_getTable();
|
||||
$tables = $this->_getTables();
|
||||
|
||||
$export_struct = isset($GLOBALS['xml_export_functions'])
|
||||
|| isset($GLOBALS['xml_export_procedures'])
|
||||
@ -310,18 +359,28 @@ if (isset($plugin_list)) {
|
||||
return PMA_exportOutputHandler($head);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
$foot = '</pma_xml_export>';
|
||||
|
||||
return PMA_exportOutputHandler($foot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
global $crlf;
|
||||
$crlf = $this->getCrlf();
|
||||
|
||||
if (isset($GLOBALS['xml_export_contents'])
|
||||
&& $GLOBALS['xml_export_contents']
|
||||
@ -343,12 +402,10 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
global $crlf;
|
||||
$crlf = $this->getCrlf();
|
||||
|
||||
if (isset($GLOBALS['xml_export_contents'])
|
||||
&& $GLOBALS['xml_export_contents']
|
||||
@ -365,10 +422,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -383,10 +438,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData ($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
if (isset($GLOBALS['xml_export_contents'])
|
||||
&& $GLOBALS['xml_export_contents']
|
||||
@ -429,6 +482,54 @@ if (isset($plugin_list)) {
|
||||
}
|
||||
|
||||
return true;
|
||||
} // end of the 'PMA_getTableXML()' function
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Gets the table name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _getTable()
|
||||
{
|
||||
return $this->_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table name
|
||||
*
|
||||
* @param string $table table name
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setTable($table)
|
||||
{
|
||||
$this->_table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the table names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getTables()
|
||||
{
|
||||
return $this->_tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table names
|
||||
*
|
||||
* @param array $tables table names
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setTables($tables)
|
||||
{
|
||||
$this->_tables = $tables;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
@ -10,59 +10,74 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the export interface */
|
||||
require_once "libraries/plugins/ExportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the export for the YAML format
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
if (isset($plugin_list)) {
|
||||
$plugin_list['yaml'] = array(
|
||||
'text' => 'YAML',
|
||||
'extension' => 'yml',
|
||||
'mime_type' => 'text/yaml',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$plugin_list['yaml']['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data',
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
class ExportYaml extends ExportPlugin
|
||||
{
|
||||
/**
|
||||
* Set of functions used to build exports of tables
|
||||
* Constructor
|
||||
*/
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportFooter()
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the export YAML properties
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => 'YAML',
|
||||
'extension' => 'yml',
|
||||
'mime_type' => 'text/yaml',
|
||||
'force_file' => true,
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'structure_or_data',
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export header
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportHeader()
|
||||
public function exportHeader ()
|
||||
{
|
||||
PMA_exportOutputHandler(
|
||||
'%YAML 1.1' . $GLOBALS['crlf'] . '---' . $GLOBALS['crlf']
|
||||
@ -70,16 +85,25 @@ if (isset($plugin_list)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs export footer
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*/
|
||||
public function exportFooter ()
|
||||
{
|
||||
PMA_exportOutputHandler('...' . $GLOBALS['crlf']);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs database header
|
||||
*
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBHeader($db)
|
||||
public function exportDBHeader ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -90,10 +114,8 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBFooter($db)
|
||||
public function exportDBFooter ($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -104,16 +126,14 @@ if (isset($plugin_list)) {
|
||||
* @param string $db Database name
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportDBCreate($db)
|
||||
public function exportDBCreate($db)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content of a table in YAML format
|
||||
* Outputs the content of a table in JSON format
|
||||
*
|
||||
* @param string $db database name
|
||||
* @param string $table table name
|
||||
@ -122,12 +142,10 @@ if (isset($plugin_list)) {
|
||||
* @param string $sql_query SQL query for obtaining data
|
||||
*
|
||||
* @return bool Whether it succeeded
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
public function exportData($db, $table, $crlf, $error_url, $sql_query)
|
||||
{
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
|
||||
$columns_cnt = PMA_DBI_num_fields($result);
|
||||
for ($i = 0; $i < $columns_cnt; $i++) {
|
||||
@ -180,7 +198,6 @@ if (isset($plugin_list)) {
|
||||
PMA_DBI_free_result($result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // end getTableYAML
|
||||
}
|
||||
?>
|
||||
?>
|
||||
372
libraries/plugins/export/PMA_ExportPdf.class.php
Normal file
372
libraries/plugins/export/PMA_ExportPdf.class.php
Normal file
@ -0,0 +1,372 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* TableProperty class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage PDF
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the PDF class */
|
||||
require_once 'libraries/PDF.class.php';
|
||||
|
||||
/**
|
||||
* Adapted from a LGPL script by Philip Clarke
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage PDF
|
||||
*/
|
||||
class PMA_ExportPdf extends PMA_PDF
|
||||
{
|
||||
var $tablewidths;
|
||||
var $headerset;
|
||||
|
||||
function checkPageBreak($h = 0, $y = '', $addpage = true)
|
||||
{
|
||||
if ($this->empty_string($y)) {
|
||||
$y = $this->y;
|
||||
}
|
||||
$current_page = $this->page;
|
||||
if ((($y + $h) > $this->PageBreakTrigger)
|
||||
AND (! $this->InFooter)
|
||||
AND ($this->AcceptPageBreak())
|
||||
) {
|
||||
if ($addpage) {
|
||||
//Automatic page break
|
||||
$x = $this->x;
|
||||
$this->AddPage($this->CurOrientation);
|
||||
$this->y = $this->dataY;
|
||||
$oldpage = $this->page - 1;
|
||||
|
||||
$this_page_orm = $this->pagedim[$this->page]['orm'];
|
||||
$old_page_orm = $this->pagedim[$oldpage]['orm'];
|
||||
$this_page_olm = $this->pagedim[$this->page]['olm'];
|
||||
$old_page_olm = $this->pagedim[$oldpage]['olm'];
|
||||
if ($this->rtl) {
|
||||
if ($this_page_orm!= $old_page_orm) {
|
||||
$this->x = $x - ($this_page_orm - $old_page_orm);
|
||||
} else {
|
||||
$this->x = $x;
|
||||
}
|
||||
} else {
|
||||
if ($this_page_olm != $old_page_olm) {
|
||||
$this->x = $x + ($this_page_olm - $old_page_olm);
|
||||
} else {
|
||||
$this->x = $x;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if ($current_page != $this->page) {
|
||||
// account for columns mode
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Header()
|
||||
{
|
||||
global $maxY;
|
||||
// Check if header for this page already exists
|
||||
if (! isset($this->headerset[$this->page])) {
|
||||
$fullwidth = 0;
|
||||
foreach ($this->tablewidths as $width) {
|
||||
$fullwidth += $width;
|
||||
}
|
||||
$this->SetY(($this->tMargin) - ($this->FontSizePt / $this->k) * 5);
|
||||
$this->cellFontSize = $this->FontSizePt ;
|
||||
$this->SetFont(
|
||||
PMA_PDF_FONT,
|
||||
'',
|
||||
($this->titleFontSize
|
||||
? $this->titleFontSize
|
||||
: $this->FontSizePt)
|
||||
);
|
||||
$this->Cell(0, $this->FontSizePt, $this->titleText, 0, 1, 'C');
|
||||
$this->SetFont(PMA_PDF_FONT, '', $this->cellFontSize);
|
||||
$this->SetY(($this->tMargin) - ($this->FontSizePt / $this->k) * 2.5);
|
||||
$this->Cell(
|
||||
0,
|
||||
$this->FontSizePt,
|
||||
__('Database') . ': ' . $this->currentDb . ', '
|
||||
. __('Table') . ': ' . $this->currentTable,
|
||||
0, 1, 'L'
|
||||
);
|
||||
$l = ($this->lMargin);
|
||||
foreach ($this->colTitles as $col => $txt) {
|
||||
$this->SetXY($l, ($this->tMargin));
|
||||
$this->MultiCell(
|
||||
$this->tablewidths[$col],
|
||||
$this->FontSizePt,
|
||||
$txt
|
||||
);
|
||||
$l += $this->tablewidths[$col] ;
|
||||
$maxY = ($maxY < $this->getY()) ? $this->getY() : $maxY ;
|
||||
}
|
||||
$this->SetXY($this->lMargin, $this->tMargin);
|
||||
$this->setFillColor(200, 200, 200);
|
||||
$l = ($this->lMargin);
|
||||
foreach ($this->colTitles as $col => $txt) {
|
||||
$this->SetXY($l, $this->tMargin);
|
||||
$this->cell(
|
||||
$this->tablewidths[$col],
|
||||
$maxY-($this->tMargin),
|
||||
'',
|
||||
1,
|
||||
0,
|
||||
'L',
|
||||
1
|
||||
);
|
||||
$this->SetXY($l, $this->tMargin);
|
||||
$this->MultiCell(
|
||||
$this->tablewidths[$col],
|
||||
$this->FontSizePt,
|
||||
$txt,
|
||||
0,
|
||||
'C'
|
||||
);
|
||||
$l += $this->tablewidths[$col];
|
||||
}
|
||||
$this->setFillColor(255, 255, 255);
|
||||
// set headerset
|
||||
$this->headerset[$this->page] = 1;
|
||||
}
|
||||
|
||||
$this->dataY = $maxY;
|
||||
}
|
||||
|
||||
function morepagestable($lineheight=8)
|
||||
{
|
||||
// some things to set and 'remember'
|
||||
$l = $this->lMargin;
|
||||
$startheight = $h = $this->dataY;
|
||||
$startpage = $currpage = $this->page;
|
||||
|
||||
// calculate the whole width
|
||||
$fullwidth = 0;
|
||||
foreach ($this->tablewidths as $width) {
|
||||
$fullwidth += $width;
|
||||
}
|
||||
|
||||
// Now let's start to write the table
|
||||
$row = 0;
|
||||
$tmpheight = array();
|
||||
$maxpage = $this->page;
|
||||
|
||||
while ($data = PMA_DBI_fetch_row($this->results)) {
|
||||
$this->page = $currpage;
|
||||
// write the horizontal borders
|
||||
$this->Line($l, $h, $fullwidth+$l, $h);
|
||||
// write the content and remember the height of the highest col
|
||||
foreach ($data as $col => $txt) {
|
||||
$this->page = $currpage;
|
||||
$this->SetXY($l, $h);
|
||||
if ($this->tablewidths[$col] > 0) {
|
||||
$this->MultiCell(
|
||||
$this->tablewidths[$col],
|
||||
$lineheight,
|
||||
$txt,
|
||||
0,
|
||||
$this->colAlign[$col]
|
||||
);
|
||||
$l += $this->tablewidths[$col];
|
||||
}
|
||||
|
||||
if (! isset($tmpheight[$row.'-'.$this->page])) {
|
||||
$tmpheight[$row.'-'.$this->page] = 0;
|
||||
}
|
||||
if ($tmpheight[$row.'-'.$this->page] < $this->GetY()) {
|
||||
$tmpheight[$row.'-'.$this->page] = $this->GetY();
|
||||
}
|
||||
if ($this->page > $maxpage) {
|
||||
$maxpage = $this->page;
|
||||
}
|
||||
unset($data[$col]);
|
||||
}
|
||||
|
||||
// get the height we were in the last used page
|
||||
$h = $tmpheight[$row.'-'.$maxpage];
|
||||
// set the "pointer" to the left margin
|
||||
$l = $this->lMargin;
|
||||
// set the $currpage to the last page
|
||||
$currpage = $maxpage;
|
||||
unset($data[$row]);
|
||||
$row++;
|
||||
}
|
||||
// draw the borders
|
||||
// we start adding a horizontal line on the last page
|
||||
$this->page = $maxpage;
|
||||
$this->Line($l, $h, $fullwidth+$l, $h);
|
||||
// now we start at the top of the document and walk down
|
||||
for ($i = $startpage; $i <= $maxpage; $i++) {
|
||||
$this->page = $i;
|
||||
$l = $this->lMargin;
|
||||
$t = ($i == $startpage) ? $startheight : $this->tMargin;
|
||||
$lh = ($i == $maxpage) ? $h : $this->h-$this->bMargin;
|
||||
$this->Line($l, $t, $l, $lh);
|
||||
foreach ($this->tablewidths as $width) {
|
||||
$l += $width;
|
||||
$this->Line($l, $t, $l, $lh);
|
||||
}
|
||||
}
|
||||
// set it to the last page, if not it'll cause some problems
|
||||
$this->page = $maxpage;
|
||||
}
|
||||
|
||||
function setAttributes($attr = array())
|
||||
{
|
||||
foreach ($attr as $key => $val) {
|
||||
$this->$key = $val ;
|
||||
}
|
||||
}
|
||||
|
||||
function setTopMargin($topMargin)
|
||||
{
|
||||
$this->tMargin = $topMargin;
|
||||
}
|
||||
|
||||
function mysqlReport($query)
|
||||
{
|
||||
unset($this->tablewidths);
|
||||
unset($this->colTitles);
|
||||
unset($this->titleWidth);
|
||||
unset($this->colFits);
|
||||
unset($this->display_column);
|
||||
unset($this->colAlign);
|
||||
|
||||
/**
|
||||
* Pass 1 for column widths
|
||||
*/
|
||||
$this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$this->numFields = PMA_DBI_num_fields($this->results);
|
||||
$this->fields = PMA_DBI_get_fields_meta($this->results);
|
||||
|
||||
// sColWidth = starting col width (an average size width)
|
||||
$availableWidth = $this->w - $this->lMargin - $this->rMargin;
|
||||
$this->sColWidth = $availableWidth / $this->numFields;
|
||||
$totalTitleWidth = 0;
|
||||
|
||||
// loop through results header and set initial
|
||||
// col widths/ titles/ alignment
|
||||
// if a col title is less than the starting col width,
|
||||
// reduce that column size
|
||||
$colFits = array();
|
||||
for ($i = 0; $i < $this->numFields; $i++) {
|
||||
$stringWidth = $this->getstringwidth($this->fields[$i]->name) + 6 ;
|
||||
// save the real title's width
|
||||
$titleWidth[$i] = $stringWidth;
|
||||
$totalTitleWidth += $stringWidth;
|
||||
|
||||
// set any column titles less than the start width to
|
||||
// the column title width
|
||||
if ($stringWidth < $this->sColWidth) {
|
||||
$colFits[$i] = $stringWidth ;
|
||||
}
|
||||
$this->colTitles[$i] = $this->fields[$i]->name;
|
||||
$this->display_column[$i] = true;
|
||||
|
||||
switch ($this->fields[$i]->type) {
|
||||
case 'int':
|
||||
$this->colAlign[$i] = 'R';
|
||||
break;
|
||||
case 'blob':
|
||||
case 'tinyblob':
|
||||
case 'mediumblob':
|
||||
case 'longblob':
|
||||
/**
|
||||
* @todo do not deactivate completely the display
|
||||
* but show the field's name and [BLOB]
|
||||
*/
|
||||
if (stristr($this->fields[$i]->flags, 'BINARY')) {
|
||||
$this->display_column[$i] = false;
|
||||
unset($this->colTitles[$i]);
|
||||
}
|
||||
$this->colAlign[$i] = 'L';
|
||||
break;
|
||||
default:
|
||||
$this->colAlign[$i] = 'L';
|
||||
}
|
||||
}
|
||||
|
||||
// title width verification
|
||||
if ($totalTitleWidth > $availableWidth) {
|
||||
$adjustingMode = true;
|
||||
} else {
|
||||
$adjustingMode = false;
|
||||
// we have enough space for all the titles at their
|
||||
// original width so use the true title's width
|
||||
foreach ($titleWidth as $key => $val) {
|
||||
$colFits[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// loop through the data; any column whose contents
|
||||
// is greater than the column size is resized
|
||||
/**
|
||||
* @todo force here a LIMIT to avoid reading all rows
|
||||
*/
|
||||
while ($row = PMA_DBI_fetch_row($this->results)) {
|
||||
foreach ($colFits as $key => $val) {
|
||||
$stringWidth = $this->getstringwidth($row[$key]) + 6 ;
|
||||
if ($adjustingMode && ($stringWidth > $this->sColWidth)) {
|
||||
// any column whose data's width is bigger than
|
||||
// the start width is now discarded
|
||||
unset($colFits[$key]);
|
||||
} else {
|
||||
// if data's width is bigger than the current column width,
|
||||
// enlarge the column (but avoid enlarging it if the
|
||||
// data's width is very big)
|
||||
if ($stringWidth > $val
|
||||
&& $stringWidth < ($this->sColWidth * 3)
|
||||
) {
|
||||
$colFits[$key] = $stringWidth ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$totAlreadyFitted = 0;
|
||||
foreach ($colFits as $key => $val) {
|
||||
// set fitted columns to smallest size
|
||||
$this->tablewidths[$key] = $val;
|
||||
// to work out how much (if any) space has been freed up
|
||||
$totAlreadyFitted += $val;
|
||||
}
|
||||
|
||||
if ($adjustingMode) {
|
||||
$surplus = (sizeof($colFits) * $this->sColWidth) - $totAlreadyFitted;
|
||||
$surplusToAdd = $surplus / ($this->numFields - sizeof($colFits));
|
||||
} else {
|
||||
$surplusToAdd = 0;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $this->numFields; $i++) {
|
||||
if (! in_array($i, array_keys($colFits))) {
|
||||
$this->tablewidths[$i] = $this->sColWidth + $surplusToAdd;
|
||||
}
|
||||
if ($this->display_column[$i] == false) {
|
||||
$this->tablewidths[$i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ksort($this->tablewidths);
|
||||
|
||||
PMA_DBI_free_result($this->results);
|
||||
|
||||
// Pass 2
|
||||
|
||||
$this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED);
|
||||
$this->setY($this->tMargin);
|
||||
$this->AddPage();
|
||||
$this->SetFont(PMA_PDF_FONT, '', 9);
|
||||
$this->morepagestable($this->FontSizePt);
|
||||
PMA_DBI_free_result($this->results);
|
||||
|
||||
} // end of mysqlReport function
|
||||
|
||||
} // end of PMA_Export_PDF class
|
||||
?>
|
||||
287
libraries/plugins/export/TableProperty.class.php
Normal file
287
libraries/plugins/export/TableProperty.class.php
Normal file
@ -0,0 +1,287 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* TableProperty class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
* @subpackage CodeGen
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the TableProperty class
|
||||
*
|
||||
* @package PhpMyAdmin-Export
|
||||
*/
|
||||
class TableProperty
|
||||
{
|
||||
/**
|
||||
* Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* Wheter the key is nullable or not
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $nullable;
|
||||
|
||||
/**
|
||||
* The key
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $key;
|
||||
|
||||
/**
|
||||
* Default value
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $defaultValue;
|
||||
|
||||
/**
|
||||
* Extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ext;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $row table row
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct($row)
|
||||
{
|
||||
$this->name = trim($row[0]);
|
||||
$this->type = trim($row[1]);
|
||||
$this->nullable = trim($row[2]);
|
||||
$this->key = trim($row[3]);
|
||||
$this->defaultValue = trim($row[4]);
|
||||
$this->ext = trim($row[5]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the pure type
|
||||
*
|
||||
* @return string type
|
||||
*/
|
||||
function getPureType()
|
||||
{
|
||||
$pos = strpos($this->type, "(");
|
||||
if ($pos > 0) {
|
||||
return substr($this->type, 0, $pos);
|
||||
}
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the key is null or not
|
||||
*
|
||||
* @return bool true if the key is not null, false otherwise
|
||||
*/
|
||||
function isNotNull()
|
||||
{
|
||||
return $this->nullable == "NO" ? "true" : "false";
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the key is unique or not
|
||||
*
|
||||
* @return bool true if the key is unique, false otherwise
|
||||
*/
|
||||
function isUnique()
|
||||
{
|
||||
return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the .NET primitive type
|
||||
*
|
||||
* @return string type
|
||||
*/
|
||||
function getDotNetPrimitiveType()
|
||||
{
|
||||
if (strpos($this->type, "int") === 0) {
|
||||
return "int";
|
||||
}
|
||||
if (strpos($this->type, "long") === 0) {
|
||||
return "long";
|
||||
}
|
||||
if (strpos($this->type, "char") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "varchar") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "text") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "longtext") === 0) {
|
||||
return "string";
|
||||
}
|
||||
if (strpos($this->type, "tinyint") === 0) {
|
||||
return "bool";
|
||||
}
|
||||
if (strpos($this->type, "datetime") === 0) {
|
||||
return "DateTime";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the .NET object type
|
||||
*
|
||||
* @return string type
|
||||
*/
|
||||
function getDotNetObjectType()
|
||||
{
|
||||
if (strpos($this->type, "int") === 0) {
|
||||
return "Int32";
|
||||
}
|
||||
if (strpos($this->type, "long") === 0) {
|
||||
return "Long";
|
||||
}
|
||||
if (strpos($this->type, "char") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "varchar") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "text") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "longtext") === 0) {
|
||||
return "String";
|
||||
}
|
||||
if (strpos($this->type, "tinyint") === 0) {
|
||||
return "Boolean";
|
||||
}
|
||||
if (strpos($this->type, "datetime") === 0) {
|
||||
return "DateTime";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index name
|
||||
*
|
||||
* @return string containing the name of the index
|
||||
*/
|
||||
function getIndexName()
|
||||
{
|
||||
if (strlen($this->key) > 0) {
|
||||
return "index=\""
|
||||
. htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8')
|
||||
. "\"";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the key is primary or not
|
||||
*
|
||||
* @return bool true if the key is primary, false otherwise
|
||||
*/
|
||||
function isPK()
|
||||
{
|
||||
return $this->key=="PRI";
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string for C#
|
||||
*
|
||||
* @param string $text string to be formatted
|
||||
*
|
||||
* @return string formatted text
|
||||
*/
|
||||
function formatCs($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#name#",
|
||||
ExportCodegen::cgMakeIdentifier($this->name, false),
|
||||
$text
|
||||
);
|
||||
return $this->format($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string for XML
|
||||
*
|
||||
* @param string $text string to be formatted
|
||||
*
|
||||
* @return string formatted text
|
||||
*/
|
||||
function formatXml($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#name#",
|
||||
htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#indexName#",
|
||||
$this->getIndexName(),
|
||||
$text
|
||||
);
|
||||
return $this->format($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a string
|
||||
*
|
||||
* @param string $text string to be formatted
|
||||
*
|
||||
* @return string formatted text
|
||||
*/
|
||||
function format($text)
|
||||
{
|
||||
$text = str_replace(
|
||||
"#ucfirstName#",
|
||||
ExportCodegen::cgMakeIdentifier($this->name),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#dotNetPrimitiveType#",
|
||||
$this->getDotNetPrimitiveType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#dotNetObjectType#",
|
||||
$this->getDotNetObjectType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#type#",
|
||||
$this->getPureType(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#notNull#",
|
||||
$this->isNotNull(),
|
||||
$text
|
||||
);
|
||||
$text = str_replace(
|
||||
"#unique#",
|
||||
$this->isUnique(),
|
||||
$text
|
||||
);
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
?>
|
||||
622
libraries/plugins/import/ImportCsv.class.php
Normal file
622
libraries/plugins/import/ImportCsv.class.php
Normal file
@ -0,0 +1,622 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* CSV import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo add an option for handling NULL values
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage CSV
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the import interface */
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the import for the CSV format
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportCsv extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Whether to analyze tables
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_analyze;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->_setAnalyze(false);
|
||||
|
||||
if ($GLOBALS['plugin_param'] !== 'table') {
|
||||
$this->_setAnalyze(true);
|
||||
}
|
||||
|
||||
$this->properties = array(
|
||||
'text' => __('CSV'),
|
||||
'extension' => 'csv',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'replace',
|
||||
'text' => __('Replace table data with file')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'ignore',
|
||||
'text' => __('Do not abort on INSERT error')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'terminated',
|
||||
'text' => __('Columns separated with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'enclosed',
|
||||
'text' => __('Columns enclosed with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'escaped',
|
||||
'text' => __('Columns escaped with:'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'new_line',
|
||||
'text' => __('Lines terminated with:'),
|
||||
'size' => 2
|
||||
)
|
||||
);
|
||||
|
||||
if ($GLOBALS['plugin_param'] !== 'table') {
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'bool',
|
||||
'name' => 'col_names',
|
||||
'text' => __(
|
||||
'The first line of the file contains the table column names <i>'
|
||||
. '(if this is unchecked, the first line will become part of the'
|
||||
. ' data)</i>'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$hint = new PMA_Message(
|
||||
__(
|
||||
'If the data in each row of the file is not'
|
||||
. ' in the same order as in the database, list the corresponding'
|
||||
. ' column names here. Column names must be separated by commas'
|
||||
. ' and not enclosed in quotations.'
|
||||
)
|
||||
);
|
||||
$this->properties['options'][] = array(
|
||||
'type' => 'text',
|
||||
'name' => 'columns',
|
||||
'text' => __('Column names: ') . PMA_showHint($hint)
|
||||
);
|
||||
}
|
||||
|
||||
$this->properties['options'][] = array('type' => 'end_group');
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $db, $csv_terminated, $csv_enclosed, $csv_escaped, $csv_new_line;
|
||||
global $error, $timeout_passed, $finished;
|
||||
|
||||
$replacements = array(
|
||||
'\\n' => "\n",
|
||||
'\\t' => "\t",
|
||||
'\\r' => "\r",
|
||||
);
|
||||
$csv_terminated = strtr($csv_terminated, $replacements);
|
||||
$csv_enclosed = strtr($csv_enclosed, $replacements);
|
||||
$csv_escaped = strtr($csv_escaped, $replacements);
|
||||
$csv_new_line = strtr($csv_new_line, $replacements);
|
||||
|
||||
$param_error = false;
|
||||
if (strlen($csv_terminated) != 1) {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid parameter for CSV import: %s')
|
||||
);
|
||||
$message->addParam(__('Columns terminated by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
// The default dialog of MS Excel when generating a CSV produces a
|
||||
// semi-colon-separated file with no chance of specifying the
|
||||
// enclosing character. Thus, users who want to import this file
|
||||
// tend to remove the enclosing character on the Import dialog.
|
||||
// I could not find a test case where having no enclosing characters
|
||||
// confuses this script.
|
||||
// But the parser won't work correctly with strings so we allow just
|
||||
// one character.
|
||||
} elseif (strlen($csv_enclosed) > 1) {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid parameter for CSV import: %s')
|
||||
);
|
||||
$message->addParam(__('Columns enclosed by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
} elseif (strlen($csv_escaped) != 1) {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid parameter for CSV import: %s')
|
||||
);
|
||||
$message->addParam(__('Columns escaped by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
} elseif (strlen($csv_new_line) != 1 && $csv_new_line != 'auto') {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid parameter for CSV import: %s')
|
||||
);
|
||||
$message->addParam(__('Lines terminated by'), false);
|
||||
$error = true;
|
||||
$param_error = true;
|
||||
}
|
||||
|
||||
// If there is an error in the parameters entered,
|
||||
// indicate that immediately.
|
||||
if ($param_error) {
|
||||
PMA_mysqlDie($message->getMessage(), '', '', $err_url);
|
||||
}
|
||||
|
||||
$buffer = '';
|
||||
$required_fields = 0;
|
||||
|
||||
if (! $this->_getAnalyze()) {
|
||||
if (isset($csv_replace)) {
|
||||
$sql_template = 'REPLACE';
|
||||
} else {
|
||||
$sql_template = 'INSERT';
|
||||
if (isset($csv_ignore)) {
|
||||
$sql_template .= ' IGNORE';
|
||||
}
|
||||
}
|
||||
$sql_template .= ' INTO ' . PMA_backquote($table);
|
||||
|
||||
$tmp_fields = PMA_DBI_get_columns($db, $table);
|
||||
|
||||
if (empty($csv_columns)) {
|
||||
$fields = $tmp_fields;
|
||||
} else {
|
||||
$sql_template .= ' (';
|
||||
$fields = array();
|
||||
$tmp = preg_split('/,( ?)/', $csv_columns);
|
||||
foreach ($tmp as $key => $val) {
|
||||
if (count($fields) > 0) {
|
||||
$sql_template .= ', ';
|
||||
}
|
||||
/* Trim also `, if user already included backquoted fields */
|
||||
$val = trim($val, " \t\r\n\0\x0B`");
|
||||
$found = false;
|
||||
foreach ($tmp_fields as $id => $field) {
|
||||
if ($field['Field'] == $val) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! $found) {
|
||||
$message = PMA_Message::error(
|
||||
__(
|
||||
'Invalid column (%s) specified! Ensure that columns'
|
||||
. ' names are spelled correctly, separated by commas'
|
||||
. ', and not enclosed in quotes.'
|
||||
)
|
||||
);
|
||||
$message->addParam($val);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
$fields[] = $field;
|
||||
$sql_template .= PMA_backquote($val);
|
||||
}
|
||||
$sql_template .= ') ';
|
||||
}
|
||||
|
||||
$required_fields = count($fields);
|
||||
|
||||
$sql_template .= ' VALUES (';
|
||||
}
|
||||
|
||||
// Defaults for parser
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$line = 1;
|
||||
$lasti = -1;
|
||||
$values = array();
|
||||
$csv_finish = false;
|
||||
|
||||
$tempRow = array();
|
||||
$rows = array();
|
||||
$col_names = array();
|
||||
$tables = array();
|
||||
|
||||
$col_count = 0;
|
||||
$max_cols = 0;
|
||||
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// Handle rest of buffer
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
// Do not parse string when we're not at the end
|
||||
// and don't have new line inside
|
||||
if (($csv_new_line == 'auto'
|
||||
&& strpos($buffer, "\r") === false
|
||||
&& strpos($buffer, "\n") === false)
|
||||
|| ($csv_new_line != 'auto'
|
||||
&& strpos($buffer, $csv_new_line) === false)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Current length of our buffer
|
||||
$len = strlen($buffer);
|
||||
// Currently parsed char
|
||||
$ch = $buffer[$i];
|
||||
while ($i < $len) {
|
||||
// Deadlock protection
|
||||
if ($lasti == $i && $lastlen == $len) {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid format of CSV input on line %d.')
|
||||
);
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
$lasti = $i;
|
||||
$lastlen = $len;
|
||||
|
||||
// This can happen with auto EOL and \r at the end of buffer
|
||||
if (! $csv_finish) {
|
||||
// Grab empty field
|
||||
if ($ch == $csv_terminated) {
|
||||
if ($i == $len - 1) {
|
||||
break;
|
||||
}
|
||||
$values[] = '';
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab one field
|
||||
$fallbacki = $i;
|
||||
if ($ch == $csv_enclosed) {
|
||||
if ($i == $len - 1) {
|
||||
break;
|
||||
}
|
||||
$need_end = true;
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
} else {
|
||||
$need_end = false;
|
||||
}
|
||||
$fail = false;
|
||||
$value = '';
|
||||
while (($need_end
|
||||
&& ( $ch != $csv_enclosed || $csv_enclosed == $csv_escaped ))
|
||||
|| ( ! $need_end
|
||||
&& ! ( $ch == $csv_terminated
|
||||
|| $ch == $csv_new_line
|
||||
|| ( $csv_new_line == 'auto'
|
||||
&& ( $ch == "\r" || $ch == "\n" ) ) ) )
|
||||
) {
|
||||
if ($ch == $csv_escaped) {
|
||||
if ($i == $len - 1) {
|
||||
$fail = true;
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
if ($csv_enclosed == $csv_escaped
|
||||
&& ($ch == $csv_terminated
|
||||
|| $ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto'
|
||||
&& ($ch == "\r" || $ch == "\n")))
|
||||
) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$value .= $ch;
|
||||
if ($i == $len - 1) {
|
||||
if (! $finished) {
|
||||
$fail = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
|
||||
// unquoted NULL string
|
||||
if (false === $need_end && $value === 'NULL') {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
if ($fail) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
}
|
||||
// Need to strip trailing enclosing char?
|
||||
if ($need_end && $ch == $csv_enclosed) {
|
||||
if ($finished && $i == $len - 1) {
|
||||
$ch = null;
|
||||
} elseif ($i == $len - 1) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
} else {
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
}
|
||||
// Are we at the end?
|
||||
if ($ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))
|
||||
|| ($finished && $i == $len - 1)
|
||||
) {
|
||||
$csv_finish = true;
|
||||
}
|
||||
// Go to next char
|
||||
if ($ch == $csv_terminated) {
|
||||
if ($i == $len - 1) {
|
||||
$i = $fallbacki;
|
||||
$ch = $buffer[$i];
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
$ch = $buffer[$i];
|
||||
}
|
||||
// If everything went okay, store value
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
// End of line
|
||||
if ($csv_finish
|
||||
|| $ch == $csv_new_line
|
||||
|| ($csv_new_line == 'auto' && ($ch == "\r" || $ch == "\n"))
|
||||
) {
|
||||
if ($csv_new_line == 'auto' && $ch == "\r") { // Handle "\r\n"
|
||||
if ($i >= ($len - 2) && ! $finished) {
|
||||
break; // We need more data to decide new line
|
||||
}
|
||||
if ($buffer[$i + 1] == "\n") {
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
// We didn't parse value till the end of line, so there was
|
||||
// empty one
|
||||
if (! $csv_finish) {
|
||||
$values[] = '';
|
||||
}
|
||||
|
||||
if ($this->_getAnalyze()) {
|
||||
foreach ($values as $ley => $val) {
|
||||
$tempRow[] = $val;
|
||||
++$col_count;
|
||||
}
|
||||
|
||||
if ($col_count > $max_cols) {
|
||||
$max_cols = $col_count;
|
||||
}
|
||||
$col_count = 0;
|
||||
|
||||
$rows[] = $tempRow;
|
||||
$tempRow = array();
|
||||
} else {
|
||||
// Do we have correct count of values?
|
||||
if (count($values) != $required_fields) {
|
||||
|
||||
// Hack for excel
|
||||
if ($values[count($values) - 1] == ';') {
|
||||
unset($values[count($values) - 1]);
|
||||
} else {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid column count in CSV input on line %d.')
|
||||
);
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$first = true;
|
||||
$sql = $sql_template;
|
||||
foreach ($values as $key => $val) {
|
||||
if (! $first) {
|
||||
$sql .= ', ';
|
||||
}
|
||||
if ($val === null) {
|
||||
$sql .= 'NULL';
|
||||
} else {
|
||||
$sql .= '\'' . PMA_sqlAddSlashes($val) . '\'';
|
||||
}
|
||||
|
||||
$first = false;
|
||||
}
|
||||
$sql .= ')';
|
||||
|
||||
/**
|
||||
* @todo maybe we could add original line to verbose
|
||||
* SQL in comment
|
||||
*/
|
||||
PMA_importRunQuery($sql, $sql);
|
||||
}
|
||||
|
||||
$line++;
|
||||
$csv_finish = false;
|
||||
$values = array();
|
||||
$buffer = substr($buffer, $i + 1);
|
||||
$len = strlen($buffer);
|
||||
$i = 0;
|
||||
$lasti = -1;
|
||||
$ch = $buffer[0];
|
||||
}
|
||||
} // End of parser loop
|
||||
} // End of import loop
|
||||
|
||||
if ($this->_getAnalyze()) {
|
||||
/* Fill out all rows */
|
||||
$num_rows = count($rows);
|
||||
for ($i = 0; $i < $num_rows; ++$i) {
|
||||
for ($j = count($rows[$i]); $j < $max_cols; ++$j) {
|
||||
$rows[$i][] = 'NULL';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_REQUEST['csv_col_names'])) {
|
||||
$col_names = array_splice($rows, 0, 1);
|
||||
$col_names = $col_names[0];
|
||||
}
|
||||
|
||||
if ((isset($col_names) && count($col_names) != $max_cols)
|
||||
|| ! isset($col_names)
|
||||
) {
|
||||
// Fill out column names
|
||||
for ($i = 0; $i < $max_cols; ++$i) {
|
||||
$col_names[] = 'COL '.($i+1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($db)) {
|
||||
$result = PMA_DBI_fetch_result('SHOW TABLES');
|
||||
$tbl_name = 'TABLE '.(count($result) + 1);
|
||||
} else {
|
||||
$tbl_name = 'TBL_NAME';
|
||||
}
|
||||
|
||||
$tables[] = array($tbl_name, $col_names, $rows);
|
||||
|
||||
/* Obtain the best-fit MySQL types for each column */
|
||||
$analyses = array();
|
||||
$analyses[] = PMA_analyzeTable($tables[0]);
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'CSV_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
/* Non-applicable parameters */
|
||||
$create = null;
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
}
|
||||
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
|
||||
if (count($values) != 0 && ! $error) {
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid format of CSV input on line %d.')
|
||||
);
|
||||
$message->addParam($line);
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the table should be analyzed, false otherwise
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function _getAnalyze()
|
||||
{
|
||||
return $this->_analyze;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets to true if the table should be analyzed, false otherwise
|
||||
*
|
||||
* @param bool $analyze status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setAnalyze($analyze)
|
||||
{
|
||||
$this->_analyze = $analyze;
|
||||
}
|
||||
}
|
||||
204
libraries/plugins/import/ImportDocsql.class.php
Normal file
204
libraries/plugins/import/ImportDocsql.class.php
Normal file
@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* DocSQL import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage DocSQL
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the import interface */
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
|
||||
// We need relations enabled and we work only on database
|
||||
if ($GLOBALS['plugin_param'] !== 'database') {
|
||||
$GLOBALS['skip_import'] = true;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the import for the DocSQL format
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportDocsql extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Relations configuration
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_cfgRelation;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->_setCfgRelation(PMA_getRelationsParam());
|
||||
$cfgRelation = $this->_getCfgRelation();
|
||||
if ( $GLOBALS['num_tables'] < 1
|
||||
|| ! $cfgRelation['relwork']
|
||||
|| ! $cfgRelation['commwork']
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->properties = array(
|
||||
'text' => __('DocSQL'),
|
||||
'extension' => '',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'table',
|
||||
'text' => __('Table name')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $error, $timeout_passed, $finished;
|
||||
$cfgRelation = $this->_getCfgRelation();
|
||||
|
||||
$tab = $_POST['docsql_table'];
|
||||
$buffer = '';
|
||||
|
||||
/* Read whole buffer, we except it is small enough */
|
||||
while (! $finished && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// nothing to read
|
||||
break;
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
}
|
||||
} // End of import loop
|
||||
|
||||
/* Process the data */
|
||||
if ($data === true && ! $error && ! $timeout_passed) {
|
||||
$buffer = str_replace("\r\n", "\n", $buffer);
|
||||
$buffer = str_replace("\r", "\n", $buffer);
|
||||
$lines = explode("\n", $buffer);
|
||||
foreach ($lines AS $lkey => $line) {
|
||||
//echo '<p>' . $line . '</p>';
|
||||
$inf = explode('|', $line);
|
||||
if (!empty($inf[1]) && strlen(trim($inf[1])) > 0) {
|
||||
$qry = '
|
||||
INSERT INTO
|
||||
' . PMA_backquote($cfgRelation['db']) . '.'
|
||||
. PMA_backquote($cfgRelation['column_info']) . '
|
||||
(db_name, table_name, column_name, comment)
|
||||
VALUES (
|
||||
\'' . PMA_sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($tab)) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($inf[0])) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($inf[1])) . '\')';
|
||||
|
||||
PMA_importRunQuery(
|
||||
$qry, $qry . '-- ' . htmlspecialchars($tab)
|
||||
. '.' . htmlspecialchars($inf[0]), true
|
||||
);
|
||||
} // end inf[1] exists
|
||||
|
||||
if (!empty($inf[2]) && strlen(trim($inf[2])) > 0) {
|
||||
$for = explode('->', $inf[2]);
|
||||
$qry = '
|
||||
INSERT INTO
|
||||
' . PMA_backquote($cfgRelation['db']) . '.'
|
||||
. PMA_backquote($cfgRelation['relation']) . '
|
||||
(master_db, master_table, master_field,'
|
||||
. ' foreign_db, foreign_table, foreign_field)
|
||||
VALUES (
|
||||
\'' . PMA_sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($tab)) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($inf[0])) . '\',
|
||||
\'' . PMA_sqlAddSlashes($GLOBALS['db']) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($for[0])) . '\',
|
||||
\'' . PMA_sqlAddSlashes(trim($for[1])) . '\')';
|
||||
|
||||
PMA_importRunQuery(
|
||||
$qry, $qry . '-- ' . htmlspecialchars($tab)
|
||||
. '.' . htmlspecialchars($inf[0])
|
||||
. '(' . htmlspecialchars($inf[2]) . ')', true
|
||||
);
|
||||
} // end inf[2] exists
|
||||
} // End lines loop
|
||||
} // End import
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Gets relation configuration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getCfgRelation()
|
||||
{
|
||||
return $this->_cfgRelation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets relation configuration
|
||||
*
|
||||
* @param array $cfgRelation relation configuration
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setCfgRelation($cfgRelation)
|
||||
{
|
||||
$this->_cfgRelation = $cfgRelation;
|
||||
}
|
||||
}
|
||||
211
libraries/plugins/import/ImportLdi.class.php
Normal file
211
libraries/plugins/import/ImportLdi.class.php
Normal file
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* CSV import plugin for phpMyAdmin using LOAD DATA
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage LDI
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the import interface */
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
|
||||
// We need relations enabled and we work only on database
|
||||
if ($GLOBALS['plugin_param'] !== 'table') {
|
||||
$GLOBALS['skip_import'] = true;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the import for the CSV format using load data
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportLdi extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = false;
|
||||
|
||||
$result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';');
|
||||
if ($result != false && PMA_DBI_num_rows($result) > 0) {
|
||||
$tmp = PMA_DBI_fetch_row($result);
|
||||
if ($tmp[1] == 'ON') {
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = true;
|
||||
}
|
||||
}
|
||||
PMA_DBI_free_result($result);
|
||||
unset($result);
|
||||
}
|
||||
|
||||
$this->properties = array(
|
||||
'text' => __('CSV using LOAD DATA'),
|
||||
// Following is nonsense, however we want to default to our
|
||||
// parser for csv
|
||||
'extension' => 'ldi',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'replace',
|
||||
'text' => __('Replace table data with file')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'ignore',
|
||||
'text' => __('Do not abort on INSERT error')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'terminated',
|
||||
'text' => __('Columns terminated by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'enclosed',
|
||||
'text' => __('Columns enclosed by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'escaped',
|
||||
'text' => __('Columns escaped by'),
|
||||
'size' => 2,
|
||||
'len' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'new_line',
|
||||
'text' => __('Lines terminated by'),
|
||||
'size' => 2
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'name' => 'columns',
|
||||
'text' => __('Column names')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'local_option',
|
||||
'text' => __('Use LOCAL keyword')
|
||||
),
|
||||
array(
|
||||
'type' => 'end_group'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $finished, $error, $import_file, $compression, $charset_conversion;
|
||||
global $ldi_local_option, $ldi_replace, $ldi_terminated, $ldi_enclosed,
|
||||
$ldi_escaped, $ldi_new_line, $skip_queries, $ldi_columns;
|
||||
|
||||
if ($import_file == 'none'
|
||||
|| $compression != 'none'
|
||||
|| $charset_conversion
|
||||
) {
|
||||
// We handle only some kind of data!
|
||||
$message = PMA_Message::error(
|
||||
__('This plugin does not support compressed imports!')
|
||||
);
|
||||
$error = true;
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'LOAD DATA';
|
||||
if (isset($ldi_local_option)) {
|
||||
$sql .= ' LOCAL';
|
||||
}
|
||||
$sql .= ' INFILE \'' . PMA_sqlAddSlashes($import_file) . '\'';
|
||||
if (isset($ldi_replace)) {
|
||||
$sql .= ' REPLACE';
|
||||
} elseif (isset($ldi_ignore)) {
|
||||
$sql .= ' IGNORE';
|
||||
}
|
||||
$sql .= ' INTO TABLE ' . PMA_backquote($table);
|
||||
|
||||
if (strlen($ldi_terminated) > 0) {
|
||||
$sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
|
||||
}
|
||||
if (strlen($ldi_enclosed) > 0) {
|
||||
$sql .= ' ENCLOSED BY \'' . PMA_sqlAddSlashes($ldi_enclosed) . '\'';
|
||||
}
|
||||
if (strlen($ldi_escaped) > 0) {
|
||||
$sql .= ' ESCAPED BY \'' . PMA_sqlAddSlashes($ldi_escaped) . '\'';
|
||||
}
|
||||
if (strlen($ldi_new_line) > 0) {
|
||||
if ($ldi_new_line == 'auto') {
|
||||
$ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n';
|
||||
}
|
||||
$sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
|
||||
}
|
||||
if ($skip_queries > 0) {
|
||||
$sql .= ' IGNORE ' . $skip_queries . ' LINES';
|
||||
$skip_queries = 0;
|
||||
}
|
||||
if (strlen($ldi_columns) > 0) {
|
||||
$sql .= ' (';
|
||||
$tmp = preg_split('/,( ?)/', $ldi_columns);
|
||||
$cnt_tmp = count($tmp);
|
||||
for ($i = 0; $i < $cnt_tmp; $i++) {
|
||||
if ($i > 0) {
|
||||
$sql .= ', ';
|
||||
}
|
||||
/* Trim also `, if user already included backquoted fields */
|
||||
$sql .= PMA_backquote(trim($tmp[$i], " \t\r\n\0\x0B`"));
|
||||
} // end for
|
||||
$sql .= ')';
|
||||
}
|
||||
|
||||
PMA_importRunQuery($sql, $sql);
|
||||
PMA_importRunQuery();
|
||||
$finished = true;
|
||||
}
|
||||
}
|
||||
568
libraries/plugins/import/ImportMediawiki.class.php
Normal file
568
libraries/plugins/import/ImportMediawiki.class.php
Normal file
@ -0,0 +1,568 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* MediaWiki import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage MediaWiki
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the import interface */
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the import for the MediaWiki format
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportMediawiki extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Whether to analyze tables
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_analyze;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->_setAnalyze(false);
|
||||
if ($GLOBALS['plugin_param'] !== 'table') {
|
||||
$this->_setAnalyze(true);
|
||||
}
|
||||
|
||||
$this->properties = array(
|
||||
'text' => __('MediaWiki Table'),
|
||||
'extension' => 'txt',
|
||||
'mime_type' => 'text/plain',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $error, $timeout_passed, $finished;
|
||||
|
||||
// Defaults for parser
|
||||
|
||||
// The buffer that will be used to store chunks read from the imported file
|
||||
$buffer = '';
|
||||
|
||||
// Used as storage for the last part of the current chunk data
|
||||
// Will be appended to the first line of the next chunk, if there is one
|
||||
$last_chunk_line = '';
|
||||
|
||||
// Remembers whether the current buffer line is part of a comment
|
||||
$inside_comment = false;
|
||||
// Remembers whether the current buffer line is part of a data comment
|
||||
$inside_data_comment = false;
|
||||
// Remembers whether the current buffer line is part of a structure comment
|
||||
$inside_structure_comment = false;
|
||||
|
||||
// MediaWiki only accepts "\n" as row terminator
|
||||
$mediawiki_new_line = "\n";
|
||||
|
||||
// Initialize the name of the current table
|
||||
$cur_table_name = "";
|
||||
|
||||
while (! $finished && ! $error && ! $timeout_passed ) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
|
||||
if ($data === false) {
|
||||
// Subtract data we didn't handle yet and stop processing
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// Handle rest of buffer
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer = $data;
|
||||
unset($data);
|
||||
// Don't parse string if we're not at the end
|
||||
// and don't have a new line inside
|
||||
if ( strpos($buffer, $mediawiki_new_line) === false ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Because of reading chunk by chunk, the first line from the buffer
|
||||
// contains only a portion of an actual line from the imported file.
|
||||
// Therefore, we have to append it to the last line from the previous
|
||||
// chunk. If we are at the first chunk, $last_chunk_line should be empty.
|
||||
$buffer = $last_chunk_line . $buffer;
|
||||
|
||||
// Process the buffer line by line
|
||||
$buffer_lines = explode($mediawiki_new_line, $buffer);
|
||||
|
||||
$full_buffer_lines_count = count($buffer_lines);
|
||||
// If the reading is not finalised, the final line of the current chunk
|
||||
// will not be complete
|
||||
if (! $finished) {
|
||||
$full_buffer_lines_count -= 1;
|
||||
$last_chunk_line = $buffer_lines[$full_buffer_lines_count];
|
||||
}
|
||||
|
||||
for ($line_nr = 0; $line_nr < $full_buffer_lines_count; ++ $line_nr) {
|
||||
$cur_buffer_line = trim($buffer_lines[$line_nr]);
|
||||
|
||||
// If the line is empty, go to the next one
|
||||
if ( $cur_buffer_line === '' ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$first_character = $cur_buffer_line[0];
|
||||
$matches = array();
|
||||
|
||||
// Check beginnning of comment
|
||||
if (! strcmp(substr($cur_buffer_line, 0, 4), "<!--")) {
|
||||
$inside_comment = true;
|
||||
continue;
|
||||
} elseif ($inside_comment) {
|
||||
// Check end of comment
|
||||
if (! strcmp(substr($cur_buffer_line, 0, 4), "-->")) {
|
||||
// Only data comments are closed. The structure comments
|
||||
// will be closed when a data comment begins (in order to
|
||||
// skip structure tables)
|
||||
if ($inside_data_comment) {
|
||||
$inside_data_comment = false;
|
||||
}
|
||||
|
||||
// End comments that are not related to table structure
|
||||
if (! $inside_structure_comment) {
|
||||
$inside_comment = false;
|
||||
}
|
||||
} else {
|
||||
// Check table name
|
||||
$match_table_name = array();
|
||||
if (preg_match(
|
||||
"/^Table data for `(.*)`$/",
|
||||
$cur_buffer_line,
|
||||
$match_table_name
|
||||
)
|
||||
) {
|
||||
$cur_table_name = $match_table_name[1];
|
||||
$inside_data_comment = true;
|
||||
|
||||
// End ignoring structure rows
|
||||
if ($inside_structure_comment) {
|
||||
$inside_structure_comment = false;
|
||||
}
|
||||
} elseif (preg_match(
|
||||
"/^Table structure for `(.*)`$/",
|
||||
$cur_buffer_line,
|
||||
$match_table_name
|
||||
)
|
||||
) {
|
||||
// The structure comments will be ignored
|
||||
$inside_structure_comment = true;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
} elseif (preg_match('/^\{\|(.*)$/', $cur_buffer_line, $matches)) {
|
||||
// Check start of table
|
||||
|
||||
// This will store all the column info on all rows from
|
||||
// the current table read from the buffer
|
||||
$cur_temp_table = array();
|
||||
|
||||
// Will be used as storage for the current row in the buffer
|
||||
// Once all its columns are read, it will be added to
|
||||
// $cur_temp_table and then it will be emptied
|
||||
$cur_temp_line = array();
|
||||
|
||||
// Helps us differentiate the header columns
|
||||
// from the normal columns
|
||||
$in_table_header = false;
|
||||
// End processing because the current line does not
|
||||
// contain any column information
|
||||
} elseif (substr($cur_buffer_line, 0, 2) === '|-'
|
||||
|| substr($cur_buffer_line, 0, 2) === '|+'
|
||||
|| substr($cur_buffer_line, 0, 2) === '|}'
|
||||
) {
|
||||
// Check begin row or end table
|
||||
|
||||
// Add current line to the values storage
|
||||
if (! empty($cur_temp_line)) {
|
||||
// If the current line contains header cells
|
||||
// ( marked with '!' ),
|
||||
// it will be marked as table header
|
||||
if ( $in_table_header ) {
|
||||
// Set the header columns
|
||||
$cur_temp_table_headers = $cur_temp_line;
|
||||
} else {
|
||||
// Normal line, add it to the table
|
||||
$cur_temp_table [] = $cur_temp_line;
|
||||
}
|
||||
}
|
||||
|
||||
// Empty the temporary buffer
|
||||
$cur_temp_line = array();
|
||||
|
||||
// No more processing required at the end of the table
|
||||
if (substr($cur_buffer_line, 0, 2) === '|}') {
|
||||
$current_table = array(
|
||||
$cur_table_name,
|
||||
$cur_temp_table_headers,
|
||||
$cur_temp_table
|
||||
);
|
||||
|
||||
// Import the current table data into the database
|
||||
$this->_importDataOneTable($current_table);
|
||||
|
||||
// Reset table name
|
||||
$cur_table_name = "";
|
||||
}
|
||||
// What's after the row tag is now only attributes
|
||||
|
||||
} elseif (($first_character === '|') || ($first_character === '!')) {
|
||||
// Check cell elements
|
||||
|
||||
// Header cells
|
||||
if ($first_character === '!') {
|
||||
// Mark as table header, but treat as normal row
|
||||
$cur_buffer_line = str_replace('!!', '||', $cur_buffer_line);
|
||||
// Will be used to set $cur_temp_line as table header
|
||||
$in_table_header = true;
|
||||
} else {
|
||||
$in_table_header = false;
|
||||
}
|
||||
|
||||
// Loop through each table cell
|
||||
$cells = $this->_explodeMarkup($cur_buffer_line);
|
||||
foreach ($cells as $cell) {
|
||||
// A cell could contain both parameters and data
|
||||
$cell_data = explode('|', $cell, 2);
|
||||
|
||||
// A '|' inside an invalid link should not
|
||||
// be mistaken as delimiting cell parameters
|
||||
if (strpos($cell_data[0], '[[') === true ) {
|
||||
if (count($cell_data) == 1) {
|
||||
$cell = $cell_data[0];
|
||||
} else {
|
||||
$cell = $cell_data[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the beginning of the column, if there is one
|
||||
$cell = trim($cell);
|
||||
$col_start_chars = array( "|", "!");
|
||||
foreach ($col_start_chars as $col_start_char) {
|
||||
if (strpos($cell, $col_start_char) === 0) {
|
||||
$cell = trim(substr($cell, 1));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the cell to the row
|
||||
$cur_temp_line [] = $cell;
|
||||
} // foreach $cells
|
||||
} else {
|
||||
// If it's none of the above, then the current line has a bad
|
||||
// format
|
||||
$message = PMA_Message::error(
|
||||
__('Invalid format of mediawiki input on line: <br />%s.')
|
||||
);
|
||||
$message->addParam($cur_buffer_line);
|
||||
$error = true;
|
||||
}
|
||||
} // End treating full buffer lines
|
||||
} // while - finished parsing buffer
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports data from a single table
|
||||
*
|
||||
* @param array $table containing all table info:
|
||||
* <code>
|
||||
* $table[0] - string containing table name
|
||||
* $table[1] - array[] of table headers
|
||||
* $table[2] - array[][] of table content rows
|
||||
* </code>
|
||||
*
|
||||
* @global bool $analyze whether to scan for column types
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _importDataOneTable ($table)
|
||||
{
|
||||
$analyze = $this->_getAnalyze();
|
||||
if ($analyze) {
|
||||
// Set the table name
|
||||
$this->_setTableName($table[0]);
|
||||
|
||||
// Set generic names for table headers if they don't exist
|
||||
$this->_setTableHeaders($table[1], $table[2][0]);
|
||||
|
||||
// Create the tables array to be used in PMA_buildSQL()
|
||||
$tables = array();
|
||||
$tables [] = array($table[0], $table[1], $table[2]);
|
||||
|
||||
// Obtain the best-fit MySQL types for each column
|
||||
$analyses = array();
|
||||
$analyses [] = PMA_analyzeTable($tables[0]);
|
||||
|
||||
$this->_executeImportTables($tables, $analyses);
|
||||
}
|
||||
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table name
|
||||
*
|
||||
* @param string &$table_name reference to the name of the table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setTableName(&$table_name)
|
||||
{
|
||||
if (empty($table_name)) {
|
||||
$result = PMA_DBI_fetch_result('SHOW TABLES');
|
||||
// todo check if the name below already exists
|
||||
$table_name = 'TABLE '.(count($result) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set generic names for table headers, if they don't exist
|
||||
*
|
||||
* @param array &$table_headers reference to the array containing the headers
|
||||
* of a table
|
||||
* @param array $table_row array containing the first content row
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setTableHeaders(&$table_headers, $table_row)
|
||||
{
|
||||
if (empty($table_headers)) {
|
||||
// The first table row should contain the number of columns
|
||||
// If they are not set, generic names will be given (COL 1, COL 2, etc)
|
||||
$num_cols = count($table_row);
|
||||
for ($i = 0; $i < $num_cols; ++ $i) {
|
||||
$table_headers [$i] = 'COL '. ($i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the database name and additional options and calls PMA_buildSQL()
|
||||
* Used in PMA_importDataAllTables() and $this->_importDataOneTable()
|
||||
*
|
||||
* @param array &$tables structure:
|
||||
* array(
|
||||
* array(table_name, array() column_names, array()() rows)
|
||||
* )
|
||||
* @param array &$analyses structure:
|
||||
* $analyses = array(
|
||||
* array(array() column_types, array() column_sizes)
|
||||
* )
|
||||
*
|
||||
* @global string $db name of the database to import in
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _executeImportTables(&$tables, &$analyses)
|
||||
{
|
||||
global $db;
|
||||
|
||||
// $db_name : The currently selected database name, if applicable
|
||||
// No backquotes
|
||||
// $options : An associative array of options
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'mediawiki_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
// Array of SQL strings
|
||||
// Non-applicable parameters
|
||||
$create = null;
|
||||
|
||||
// Create and execute necessary SQL statements from data
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces all instances of the '||' separator between delimiters
|
||||
* in a given string
|
||||
*
|
||||
* @param string $start_delim start delimiter
|
||||
* @param string $end_delim end delimiter
|
||||
* @param string $replace the string to be replaced with
|
||||
* @param string $subject the text to be replaced
|
||||
*
|
||||
* @return string with replacements
|
||||
*/
|
||||
private function _delimiterReplace($start_delim, $end_delim, $replace, $subject)
|
||||
{
|
||||
// String that will be returned
|
||||
$cleaned = "";
|
||||
// Possible states of current character
|
||||
$inside_tag = false;
|
||||
$inside_attribute = false;
|
||||
// Attributes can be declared with either " or '
|
||||
$start_attribute_character = false;
|
||||
|
||||
// The full separator is "||";
|
||||
// This rembembers if the previous character was '|'
|
||||
$partial_separator = false;
|
||||
|
||||
// Parse text char by char
|
||||
for ($i = 0; $i < strlen($subject); $i ++) {
|
||||
$cur_char = $subject[$i];
|
||||
// Check for separators
|
||||
if ($cur_char == '|') {
|
||||
// If we're not inside a tag, then this is part of a real separator,
|
||||
// so we append it to the current segment
|
||||
if (! $inside_attribute) {
|
||||
$cleaned .= $cur_char;
|
||||
if ($partial_separator) {
|
||||
$inside_tag = false;
|
||||
$inside_attribute = false;
|
||||
}
|
||||
} elseif ($partial_separator) {
|
||||
// If we are inside a tag, we replace the current char with
|
||||
// the placeholder and append that to the current segment
|
||||
$cleaned .= $replace;
|
||||
}
|
||||
|
||||
// If the previous character was also '|', then this ends a
|
||||
// full separator. If not, this may be the beginning of one
|
||||
$partial_separator = ! $partial_separator;
|
||||
} else {
|
||||
// If we're inside a tag attribute and the current character is
|
||||
// not '|', but the previous one was, it means that the single '|'
|
||||
// was not appended, so we append it now
|
||||
if ($partial_separator && $inside_attribute) {
|
||||
$cleaned .= "|";
|
||||
}
|
||||
// If the char is different from "|", no separator can be formed
|
||||
$partial_separator = false;
|
||||
|
||||
// any other character should be appended to the current segment
|
||||
$cleaned .= $cur_char;
|
||||
|
||||
if ($cur_char == '<' && ! $inside_attribute) {
|
||||
// start of a tag
|
||||
$inside_tag = true;
|
||||
} elseif ($cur_char == '>' && ! $inside_attribute) {
|
||||
// end of a tag
|
||||
$inside_tag = false;
|
||||
} elseif (($cur_char == '"' || $cur_char == "'") && $inside_tag) {
|
||||
// start or end of an attribute
|
||||
if (! $inside_attribute) {
|
||||
$inside_attribute = true;
|
||||
// remember the attribute`s declaration character (" or ')
|
||||
$start_attribute_character = $cur_char;
|
||||
} else {
|
||||
if ($cur_char == $start_attribute_character) {
|
||||
$inside_attribute = false;
|
||||
// unset attribute declaration character
|
||||
$start_attribute_character = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end for each character in $subject
|
||||
|
||||
return $cleaned;
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates a string into items, similarly to explode
|
||||
* Uses the '||' separator (which is standard in the mediawiki format)
|
||||
* and ignores any instances of it inside markup tags
|
||||
* Used in parsing buffer lines containing data cells
|
||||
*
|
||||
* @param string $text text to be split
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _explodeMarkup($text)
|
||||
{
|
||||
$separator = "||";
|
||||
$placeholder = "\x00";
|
||||
|
||||
// Remove placeholder instances
|
||||
$text = str_replace($placeholder, '', $text);
|
||||
|
||||
// Replace instances of the separator inside HTML-like
|
||||
// tags with the placeholder
|
||||
$cleaned = $this->_delimiterReplace("<", ">", $placeholder, $text);
|
||||
// Explode, then put the replaced separators back in
|
||||
$items = explode($separator, $cleaned);
|
||||
foreach ($items as $i => $str) {
|
||||
$items[$i] = str_replace($placeholder, $separator, $str);
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the table should be analyzed, false otherwise
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function _getAnalyze()
|
||||
{
|
||||
return $this->_analyze;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets to true if the table should be analyzed, false otherwise
|
||||
*
|
||||
* @param bool $analyze status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setAnalyze($analyze)
|
||||
{
|
||||
$this->_analyze = $analyze;
|
||||
}
|
||||
}
|
||||
386
libraries/plugins/import/ImportOds.class.php
Normal file
386
libraries/plugins/import/ImportOds.class.php
Normal file
@ -0,0 +1,386 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* OpenDocument Spreadsheet import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo Pretty much everything
|
||||
* @todo Importing of accented characters seems to fail
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ODS
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need way to disable external XML entities processing.
|
||||
*/
|
||||
if (!function_exists('libxml_disable_entity_loader')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the import interface */
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the import for the ODS format
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportOds extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('Open Document Spreadsheet'),
|
||||
'extension' => 'ods',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
|
||||
$this->properties['options'] = array(
|
||||
array(
|
||||
'type' => 'begin_group',
|
||||
'name' => 'general_opts'
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'col_names',
|
||||
'text' => __('The first line of the file contains the table column names <i>(if this is unchecked, the first line will become part of the data)</i>')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'empty_rows',
|
||||
'text' => __('Do not import empty rows')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'recognize_percentages',
|
||||
'text' => __('Import percentages as proper decimals <i>(ex. 12.00% to .12)</i>')
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'recognize_currency',
|
||||
'text' => __('Import currencies <i>(ex. $5.00 to 5.00)</i>')
|
||||
),
|
||||
array('type' => 'end_group')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $db, $error, $timeout_passed, $finished;
|
||||
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$buffer = "";
|
||||
|
||||
/**
|
||||
* Read in the file via PMA_importGetNextChunk so that
|
||||
* it can process compressed files
|
||||
*/
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
/* subtract data we didn't handle yet and stop processing */
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
/* Handle rest of buffer */
|
||||
} else {
|
||||
/* Append new data to buffer */
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
/**
|
||||
* Disable loading of external XML entities.
|
||||
*/
|
||||
libxml_disable_entity_loader();
|
||||
|
||||
/**
|
||||
* Load the XML string
|
||||
*
|
||||
* The option LIBXML_COMPACT is specified because it can
|
||||
* result in increased performance without the need to
|
||||
* alter the code in any way. It's basically a freebee.
|
||||
*/
|
||||
$xml = simplexml_load_string($buffer, "SimpleXMLElement", LIBXML_COMPACT);
|
||||
|
||||
unset($buffer);
|
||||
|
||||
if ($xml === false) {
|
||||
$sheets = array();
|
||||
$message = PMA_Message::error(
|
||||
__(
|
||||
'The XML file specified was either malformed or incomplete.'
|
||||
. ' Please correct the issue and try again.'
|
||||
)
|
||||
);
|
||||
$error = true;
|
||||
} else {
|
||||
$sheets = $xml->children('office', true)->{'body'}->{'spreadsheet'}
|
||||
->children('table', true);
|
||||
}
|
||||
|
||||
$tables = array();
|
||||
|
||||
$max_cols = 0;
|
||||
|
||||
$row_count = 0;
|
||||
$col_count = 0;
|
||||
$col_names = array();
|
||||
|
||||
$tempRow = array();
|
||||
$tempRows = array();
|
||||
$rows = array();
|
||||
|
||||
/* Iterate over tables */
|
||||
foreach ($sheets as $sheet) {
|
||||
$col_names_in_first_row = isset($_REQUEST['ods_col_names']);
|
||||
|
||||
/* Iterate over rows */
|
||||
foreach ($sheet as $row) {
|
||||
$type = $row->getName();
|
||||
if (! strcmp('table-row', $type)) {
|
||||
/* Iterate over columns */
|
||||
foreach ($row as $cell) {
|
||||
$text = $cell->children('text', true);
|
||||
$cell_attrs = $cell->attributes('office', true);
|
||||
|
||||
if (count($text) != 0) {
|
||||
$attr = $cell->attributes('table', true);
|
||||
$num_repeat = (int) $attr['number-columns-repeated'];
|
||||
$num_iterations = $num_repeat ? $num_repeat : 1;
|
||||
|
||||
for ($k = 0; $k < $num_iterations; $k++) {
|
||||
if ($_REQUEST['ods_recognize_percentages']
|
||||
&& ! strcmp(
|
||||
'percentage',
|
||||
$cell_attrs['value-type']
|
||||
)
|
||||
) {
|
||||
$value = (double)$cell_attrs['value'];
|
||||
} elseif ($_REQUEST['ods_recognize_currency']
|
||||
&& !strcmp('currency', $cell_attrs['value-type'])
|
||||
) {
|
||||
$value = (double)$cell_attrs['value'];
|
||||
} else {
|
||||
/* We need to concatenate all paragraphs */
|
||||
$values = array();
|
||||
foreach ($text as $paragraph) {
|
||||
$values[] = (string)$paragraph;
|
||||
}
|
||||
$value = implode("\n", $values);
|
||||
}
|
||||
if (! $col_names_in_first_row) {
|
||||
$tempRow[] = $value;
|
||||
} else {
|
||||
$col_names[] = $value;
|
||||
}
|
||||
|
||||
++$col_count;
|
||||
}
|
||||
} else {
|
||||
/* Number of blank columns repeated */
|
||||
if ($col_count < count($row->children('table', true)) - 1
|
||||
) {
|
||||
$attr = $cell->attributes('table', true);
|
||||
$num_null = (int)$attr['number-columns-repeated'];
|
||||
|
||||
if ($num_null) {
|
||||
if (! $col_names_in_first_row) {
|
||||
for ($i = 0; $i < $num_null; ++$i) {
|
||||
$tempRow[] = 'NULL';
|
||||
++$col_count;
|
||||
}
|
||||
} else {
|
||||
for ($i = 0; $i < $num_null; ++$i) {
|
||||
$col_names[] = PMA_getColumnAlphaName(
|
||||
$col_count + 1
|
||||
);
|
||||
++$col_count;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (! $col_names_in_first_row) {
|
||||
$tempRow[] = 'NULL';
|
||||
} else {
|
||||
$col_names[] = PMA_getColumnAlphaName(
|
||||
$col_count + 1
|
||||
);
|
||||
}
|
||||
|
||||
++$col_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Find the widest row */
|
||||
if ($col_count > $max_cols) {
|
||||
$max_cols = $col_count;
|
||||
}
|
||||
|
||||
/* Don't include a row that is full of NULL values */
|
||||
if (! $col_names_in_first_row) {
|
||||
if ($_REQUEST['ods_empty_rows']) {
|
||||
foreach ($tempRow as $cell) {
|
||||
if (strcmp('NULL', $cell)) {
|
||||
$tempRows[] = $tempRow;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$tempRows[] = $tempRow;
|
||||
}
|
||||
}
|
||||
|
||||
$col_count = 0;
|
||||
$col_names_in_first_row = false;
|
||||
$tempRow = array();
|
||||
}
|
||||
}
|
||||
|
||||
/* Skip over empty sheets */
|
||||
if (count($tempRows) == 0 || count($tempRows[0]) == 0) {
|
||||
$col_names = array();
|
||||
$tempRow = array();
|
||||
$tempRows = array();
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill out each row as necessary to make
|
||||
* every one exactly as wide as the widest
|
||||
* row. This included column names.
|
||||
*/
|
||||
|
||||
/* Fill out column names */
|
||||
for ($i = count($col_names); $i < $max_cols; ++$i) {
|
||||
$col_names[] = PMA_getColumnAlphaName($i + 1);
|
||||
}
|
||||
|
||||
/* Fill out all rows */
|
||||
$num_rows = count($tempRows);
|
||||
for ($i = 0; $i < $num_rows; ++$i) {
|
||||
for ($j = count($tempRows[$i]); $j < $max_cols; ++$j) {
|
||||
$tempRows[$i][] = 'NULL';
|
||||
}
|
||||
}
|
||||
|
||||
/* Store the table name so we know where to place the row set */
|
||||
$tbl_attr = $sheet->attributes('table', true);
|
||||
$tables[] = array((string)$tbl_attr['name']);
|
||||
|
||||
/* Store the current sheet in the accumulator */
|
||||
$rows[] = array((string)$tbl_attr['name'], $col_names, $tempRows);
|
||||
$tempRows = array();
|
||||
$col_names = array();
|
||||
$max_cols = 0;
|
||||
}
|
||||
|
||||
unset($tempRow);
|
||||
unset($tempRows);
|
||||
unset($col_names);
|
||||
unset($sheets);
|
||||
unset($xml);
|
||||
|
||||
/**
|
||||
* Bring accumulated rows into the corresponding table
|
||||
*/
|
||||
$num_tbls = count($tables);
|
||||
for ($i = 0; $i < $num_tbls; ++$i) {
|
||||
for ($j = 0; $j < count($rows); ++$j) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], $rows[$j][TBL_NAME])) {
|
||||
if (! isset($tables[$i][COL_NAMES])) {
|
||||
$tables[$i][] = $rows[$j][COL_NAMES];
|
||||
}
|
||||
|
||||
$tables[$i][ROWS] = $rows[$j][ROWS];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* No longer needed */
|
||||
unset($rows);
|
||||
|
||||
/* Obtain the best-fit MySQL types for each column */
|
||||
$analyses = array();
|
||||
|
||||
$len = count($tables);
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$analyses[] = PMA_analyzeTable($tables[$i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'ODS_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
/* Non-applicable parameters */
|
||||
$create = null;
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
|
||||
/* Commit any possible data in buffers */
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
}
|
||||
333
libraries/plugins/import/ImportShp.class.php
Normal file
333
libraries/plugins/import/ImportShp.class.php
Normal file
@ -0,0 +1,333 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* ESRI Shape file import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Drizzle does not support GIS data types
|
||||
if (PMA_DRIZZLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the import interface*/
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
/* Get the ShapeFile class */
|
||||
require_once "libraries/bfShapeFiles/ShapeFile.lib.php";
|
||||
require_once "libraries/plugins/import/PMA_ShapeFile.class.php";
|
||||
require_once "libraries/plugins/import/PMA_ShapeRecord.class.php";
|
||||
|
||||
/**
|
||||
* Handles the import for ESRI Shape files
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportShp extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('ESRI Shape File'),
|
||||
'extension' => 'shp',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $db, $error, $finished;
|
||||
|
||||
if ((int) ini_get('memory_limit') < 512) {
|
||||
@ini_set('memory_limit', '512M');
|
||||
}
|
||||
@set_time_limit(300);
|
||||
|
||||
$GLOBALS['finished'] = false;
|
||||
$buffer = '';
|
||||
$eof = false;
|
||||
|
||||
|
||||
$shp = new PMA_ShapeFile(1);
|
||||
// If the zip archive has more than one file,
|
||||
// get the correct content to the buffer from .shp file.
|
||||
if ($compression == 'application/zip'
|
||||
&& PMA_getNoOfFilesInZip($import_file) > 1
|
||||
) {
|
||||
$zip_content = PMA_getZipContents($import_file, '/^.*\.shp$/i');
|
||||
$GLOBALS['import_text'] = $zip_content['data'];
|
||||
}
|
||||
|
||||
$temp_dbf_file = false;
|
||||
// We need dbase extension to handle .dbf file
|
||||
if (extension_loaded('dbase')) {
|
||||
// If we can extract the zip archive to 'TempDir'
|
||||
// and use the files in it for import
|
||||
if ($compression == 'application/zip'
|
||||
&& ! empty($cfg['TempDir'])
|
||||
&& is_writable($cfg['TempDir'])
|
||||
) {
|
||||
$dbf_file_name = PMA_findFileFromZipArchive(
|
||||
'/^.*\.dbf$/i', $import_file
|
||||
);
|
||||
// If the corresponding .dbf file is in the zip archive
|
||||
if ($dbf_file_name) {
|
||||
// Extract the .dbf file and point to it.
|
||||
$extracted = PMA_zipExtract(
|
||||
$import_file,
|
||||
realpath($cfg['TempDir']),
|
||||
array($dbf_file_name)
|
||||
);
|
||||
if ($extracted) {
|
||||
$dbf_file_path = realpath($cfg['TempDir'])
|
||||
. (PMA_IS_WINDOWS ? '\\' : '/') . $dbf_file_name;
|
||||
$temp_dbf_file = true;
|
||||
// Replace the .dbf with .*, as required
|
||||
// by the bsShapeFiles library.
|
||||
$file_name = substr(
|
||||
$dbf_file_path, 0, strlen($dbf_file_path) - 4
|
||||
) . '.*';
|
||||
$shp->FileName = $file_name;
|
||||
}
|
||||
}
|
||||
} elseif (! empty($local_import_file)
|
||||
&& ! empty($cfg['UploadDir'])
|
||||
&& $compression == 'none'
|
||||
) {
|
||||
// If file is in UploadDir, use .dbf file in the same UploadDir
|
||||
// to load extra data.
|
||||
// Replace the .shp with .*,
|
||||
// so the bsShapeFiles library correctly locates .dbf file.
|
||||
$file_name = substr($import_file, 0, strlen($import_file) - 4)
|
||||
. '.*';
|
||||
$shp->FileName = $file_name;
|
||||
}
|
||||
}
|
||||
|
||||
// Load data
|
||||
$shp->loadFromFile('');
|
||||
if ($shp->lastError != "") {
|
||||
$error = true;
|
||||
$message = PMA_Message::error(
|
||||
__('There was an error importing the ESRI shape file: "%s".')
|
||||
);
|
||||
$message->addParam($shp->lastError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete the .dbf file extracted to 'TempDir'
|
||||
if ($temp_dbf_file) {
|
||||
unlink($dbf_file_path);
|
||||
}
|
||||
|
||||
$esri_types = array(
|
||||
0 => 'Null Shape',
|
||||
1 => 'Point',
|
||||
3 => 'PolyLine',
|
||||
5 => 'Polygon',
|
||||
8 => 'MultiPoint',
|
||||
11 => 'PointZ',
|
||||
13 => 'PolyLineZ',
|
||||
15 => 'PolygonZ',
|
||||
18 => 'MultiPointZ',
|
||||
21 => 'PointM',
|
||||
23 => 'PolyLineM',
|
||||
25 => 'PolygonM',
|
||||
28 => 'MultiPointM',
|
||||
31 => 'MultiPatch',
|
||||
);
|
||||
|
||||
switch ($shp->shapeType) {
|
||||
// ESRI Null Shape
|
||||
case 0:
|
||||
break;
|
||||
// ESRI Point
|
||||
case 1:
|
||||
$gis_type = 'point';
|
||||
break;
|
||||
// ESRI PolyLine
|
||||
case 3:
|
||||
$gis_type = 'multilinestring';
|
||||
break;
|
||||
// ESRI Polygon
|
||||
case 5:
|
||||
$gis_type = 'multipolygon';
|
||||
break;
|
||||
// ESRI MultiPoint
|
||||
case 8:
|
||||
$gis_type = 'multipoint';
|
||||
break;
|
||||
default:
|
||||
$error = true;
|
||||
if (! isset($esri_types[$shp->shapeType])) {
|
||||
$message = PMA_Message::error(
|
||||
__(
|
||||
'You tried to import an invalid file or the imported file'
|
||||
. ' contains invalid data'
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$message = PMA_Message::error(
|
||||
__('MySQL Spatial Extension does not support ESRI type "%s".')
|
||||
);
|
||||
$message->addParam($param);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($gis_type)) {
|
||||
include_once './libraries/gis/pma_gis_factory.php';
|
||||
$gis_obj = PMA_GIS_Factory::factory($gis_type);
|
||||
} else {
|
||||
$gis_obj = null;
|
||||
}
|
||||
|
||||
$num_rows = count($shp->records);
|
||||
// If .dbf file is loaded, the number of extra data columns
|
||||
$num_data_cols = isset($shp->DBFHeader) ? count($shp->DBFHeader) : 0;
|
||||
|
||||
$rows = array();
|
||||
$col_names = array();
|
||||
if ($num_rows != 0) {
|
||||
foreach ($shp->records as $record) {
|
||||
$tempRow = array();
|
||||
if ($gis_obj == null) {
|
||||
$tempRow[] = null;
|
||||
} else {
|
||||
$tempRow[] = "GeomFromText('"
|
||||
. $gis_obj->getShape($record->SHPData) . "')";
|
||||
}
|
||||
|
||||
if (isset($shp->DBFHeader)) {
|
||||
foreach ($shp->DBFHeader as $c) {
|
||||
$cell = trim($record->DBFData[$c[0]]);
|
||||
|
||||
if (! strcmp($cell, '')) {
|
||||
$cell = 'NULL';
|
||||
}
|
||||
|
||||
$tempRow[] = $cell;
|
||||
}
|
||||
}
|
||||
$rows[] = $tempRow;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($rows) == 0) {
|
||||
$error = true;
|
||||
$message = PMA_Message::error(
|
||||
__('The imported file does not contain any data')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Column names for spatial column and the rest of the columns,
|
||||
// if they are available
|
||||
$col_names[] = 'SPATIAL';
|
||||
for ($n = 0; $n < $num_data_cols; $n++) {
|
||||
$col_names[] = $shp->DBFHeader[$n][0];
|
||||
}
|
||||
|
||||
// Set table name based on the number of tables
|
||||
if (strlen($db)) {
|
||||
$result = PMA_DBI_fetch_result('SHOW TABLES');
|
||||
$table_name = 'TABLE '.(count($result) + 1);
|
||||
} else {
|
||||
$table_name = 'TBL_NAME';
|
||||
}
|
||||
$tables = array(array($table_name, $col_names, $rows));
|
||||
|
||||
// Use data from shape file to chose best-fit MySQL types for each column
|
||||
$analyses = array();
|
||||
$analyses[] = PMA_analyzeTable($tables[0]);
|
||||
|
||||
$table_no = 0; $spatial_col = 0;
|
||||
$analyses[$table_no][TYPES][$spatial_col] = GEOMETRY;
|
||||
$analyses[$table_no][FORMATTEDSQL][$spatial_col] = true;
|
||||
|
||||
// Set database name to the currently selected one, if applicable
|
||||
if (strlen($db)) {
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
$db_name = 'SHP_DB';
|
||||
$options = null;
|
||||
}
|
||||
|
||||
// Created and execute necessary SQL statements from data
|
||||
$null_param = null;
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $null_param, $options);
|
||||
|
||||
unset($tables);
|
||||
unset($analyses);
|
||||
|
||||
$finished = true;
|
||||
$error = false;
|
||||
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns specified number of bytes from the buffer.
|
||||
* Buffer automatically fetches next chunk of data when the buffer
|
||||
* falls short.
|
||||
* Sets $eof when $GLOBALS['finished'] is set and the buffer falls short.
|
||||
*
|
||||
* @param int $length number of bytes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function readFromBuffer($length)
|
||||
{
|
||||
global $buffer, $eof;
|
||||
|
||||
if (strlen($buffer) < $length) {
|
||||
if ($GLOBALS['finished']) {
|
||||
$eof = true;
|
||||
} else {
|
||||
$buffer .= PMA_importGetNextChunk();
|
||||
}
|
||||
}
|
||||
$result = substr($buffer, 0, $length);
|
||||
$buffer = substr($buffer, $length);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
414
libraries/plugins/import/ImportSql.class.php
Normal file
414
libraries/plugins/import/ImportSql.class.php
Normal file
@ -0,0 +1,414 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* SQL import plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage SQL
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the import interface */
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the import for the SQL format
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportSql extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('SQL'),
|
||||
'extension' => 'sql',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options'),
|
||||
);
|
||||
|
||||
$compats = PMA_DBI_getCompatibilities();
|
||||
if (count($compats) > 0) {
|
||||
$values = array();
|
||||
foreach ($compats as $val) {
|
||||
$values[$val] = $val;
|
||||
}
|
||||
$this->properties['options'] = array(
|
||||
array('type' => 'begin_group', 'name' => 'general_opts'),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'name' => 'compatibility',
|
||||
'text' => __('SQL compatibility mode:'),
|
||||
'values' => $values,
|
||||
'doc' => array(
|
||||
'manual_MySQL_Database_Administration',
|
||||
'Server_SQL_mode',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'type' => 'bool',
|
||||
'name' => 'no_auto_value_on_zero',
|
||||
'text' => __(
|
||||
'Do not use <code>AUTO_INCREMENT</code> for zero values'
|
||||
),
|
||||
'doc' => array(
|
||||
'manual_MySQL_Database_Administration',
|
||||
'Server_SQL_mode',
|
||||
'sqlmode_no_auto_value_on_zero'
|
||||
),
|
||||
),
|
||||
array('type' => 'end_group'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $error, $timeout_passed;
|
||||
|
||||
$buffer = '';
|
||||
// Defaults for parser
|
||||
$sql = '';
|
||||
$start_pos = 0;
|
||||
$i = 0;
|
||||
$len= 0;
|
||||
$big_value = 2147483647;
|
||||
// include the space because it's mandatory
|
||||
$delimiter_keyword = 'DELIMITER ';
|
||||
$length_of_delimiter_keyword = strlen($delimiter_keyword);
|
||||
|
||||
if (isset($_POST['sql_delimiter'])) {
|
||||
$sql_delimiter = $_POST['sql_delimiter'];
|
||||
} else {
|
||||
$sql_delimiter = ';';
|
||||
}
|
||||
|
||||
// Handle compatibility options
|
||||
$sql_modes = array();
|
||||
if (isset($_REQUEST['sql_compatibility'])
|
||||
&& 'NONE' != $_REQUEST['sql_compatibility']
|
||||
) {
|
||||
$sql_modes[] = $_REQUEST['sql_compatibility'];
|
||||
}
|
||||
if (isset($_REQUEST['sql_no_auto_value_on_zero'])) {
|
||||
$sql_modes[] = 'NO_AUTO_VALUE_ON_ZERO';
|
||||
}
|
||||
if (count($sql_modes) > 0) {
|
||||
PMA_DBI_try_query('SET SQL_MODE="' . implode(',', $sql_modes) . '"');
|
||||
}
|
||||
unset($sql_modes);
|
||||
|
||||
/**
|
||||
* will be set in PMA_importGetNextChunk()
|
||||
*
|
||||
* @global boolean $GLOBALS['finished']
|
||||
*/
|
||||
$GLOBALS['finished'] = false;
|
||||
|
||||
while (! ($GLOBALS['finished'] && $i >= $len)
|
||||
&& ! $error
|
||||
&& ! $timeout_passed
|
||||
) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
// subtract data we didn't handle yet and stop processing
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
// Handle rest of buffer
|
||||
} else {
|
||||
// Append new data to buffer
|
||||
$buffer .= $data;
|
||||
// free memory
|
||||
unset($data);
|
||||
// Do not parse string when we're not at the end
|
||||
// and don't have ; inside
|
||||
if ((strpos($buffer, $sql_delimiter, $i) === false)
|
||||
&& ! $GLOBALS['finished']
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Current length of our buffer
|
||||
$len = strlen($buffer);
|
||||
|
||||
// Grab some SQL queries out of it
|
||||
while ($i < $len) {
|
||||
$found_delimiter = false;
|
||||
// Find first interesting character
|
||||
$old_i = $i;
|
||||
// this is about 7 times faster that looking for each sequence i
|
||||
// one by one with strpos()
|
||||
$match = preg_match(
|
||||
'/(\'|"|#|-- |\/\*|`|(?i)(?<![A-Z0-9_])'
|
||||
. $delimiter_keyword . ')/',
|
||||
$buffer,
|
||||
$matches,
|
||||
PREG_OFFSET_CAPTURE,
|
||||
$i
|
||||
);
|
||||
if ($match) {
|
||||
// in $matches, index 0 contains the match for the complete
|
||||
// expression but we don't use it
|
||||
$first_position = $matches[1][1];
|
||||
} else {
|
||||
$first_position = $big_value;
|
||||
}
|
||||
/**
|
||||
* @todo we should not look for a delimiter that might be
|
||||
* inside quotes (or even double-quotes)
|
||||
*/
|
||||
// the cost of doing this one with preg_match() would be too high
|
||||
$first_sql_delimiter = strpos($buffer, $sql_delimiter, $i);
|
||||
if ($first_sql_delimiter === false) {
|
||||
$first_sql_delimiter = $big_value;
|
||||
} else {
|
||||
$found_delimiter = true;
|
||||
}
|
||||
|
||||
// set $i to the position of the first quote,
|
||||
// comment.start or delimiter found
|
||||
$i = min($first_position, $first_sql_delimiter);
|
||||
|
||||
if ($i == $big_value) {
|
||||
// none of the above was found in the string
|
||||
|
||||
$i = $old_i;
|
||||
if (! $GLOBALS['finished']) {
|
||||
break;
|
||||
}
|
||||
// at the end there might be some whitespace...
|
||||
if (trim($buffer) == '') {
|
||||
$buffer = '';
|
||||
$len = 0;
|
||||
break;
|
||||
}
|
||||
// We hit end of query, go there!
|
||||
$i = strlen($buffer) - 1;
|
||||
}
|
||||
|
||||
// Grab current character
|
||||
$ch = $buffer[$i];
|
||||
|
||||
// Quotes
|
||||
if (strpos('\'"`', $ch) !== false) {
|
||||
$quote = $ch;
|
||||
$endq = false;
|
||||
while (! $endq) {
|
||||
// Find next quote
|
||||
$pos = strpos($buffer, $quote, $i + 1);
|
||||
/*
|
||||
* Behave same as MySQL and accept end of query as end
|
||||
* of backtick.
|
||||
* I know this is sick, but MySQL behaves like this:
|
||||
*
|
||||
* SELECT * FROM `table
|
||||
*
|
||||
* is treated like
|
||||
*
|
||||
* SELECT * FROM `table`
|
||||
*/
|
||||
if ($pos === false && $quote == '`' && $found_delimiter) {
|
||||
$pos = $first_sql_delimiter - 1;
|
||||
} elseif ($pos === false) { // No quote? Too short string
|
||||
// We hit end of string => unclosed quote,
|
||||
// but we handle it as end of query
|
||||
if ($GLOBALS['finished']) {
|
||||
$endq = true;
|
||||
$i = $len - 1;
|
||||
}
|
||||
$found_delimiter = false;
|
||||
break;
|
||||
}
|
||||
// Was not the quote escaped?
|
||||
$j = $pos - 1;
|
||||
while ($buffer[$j] == '\\') {
|
||||
$j--;
|
||||
}
|
||||
// Even count means it was not escaped
|
||||
$endq = (((($pos - 1) - $j) % 2) == 0);
|
||||
// Skip the string
|
||||
$i = $pos;
|
||||
|
||||
if ($first_sql_delimiter < $pos) {
|
||||
$found_delimiter = false;
|
||||
}
|
||||
}
|
||||
if (! $endq) {
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
// Aren't we at the end?
|
||||
if ($GLOBALS['finished'] && $i == $len) {
|
||||
$i--;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Not enough data to decide
|
||||
if ((($i == ($len - 1) && ($ch == '-' || $ch == '/'))
|
||||
|| ($i == ($len - 2) && (($ch == '-' && $buffer[$i + 1] == '-')
|
||||
|| ($ch == '/' && $buffer[$i + 1] == '*'))))
|
||||
&& ! $GLOBALS['finished']
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Comments
|
||||
if ($ch == '#'
|
||||
|| ($i < ($len - 1) && $ch == '-' && $buffer[$i + 1] == '-'
|
||||
&& (($i < ($len - 2) && $buffer[$i + 2] <= ' ')
|
||||
|| ($i == ($len - 1) && $GLOBALS['finished'])))
|
||||
|| ($i < ($len - 1) && $ch == '/' && $buffer[$i + 1] == '*')
|
||||
) {
|
||||
// Copy current string to SQL
|
||||
if ($start_pos != $i) {
|
||||
$sql .= substr($buffer, $start_pos, $i - $start_pos);
|
||||
}
|
||||
// Skip the rest
|
||||
$start_of_comment = $i;
|
||||
// do not use PHP_EOL here instead of "\n", because the export
|
||||
// file might have been produced on a different system
|
||||
$i = strpos($buffer, $ch == '/' ? '*/' : "\n", $i);
|
||||
// didn't we hit end of string?
|
||||
if ($i === false) {
|
||||
if ($GLOBALS['finished']) {
|
||||
$i = $len - 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Skip *
|
||||
if ($ch == '/') {
|
||||
$i++;
|
||||
}
|
||||
// Skip last char
|
||||
$i++;
|
||||
// We need to send the comment part in case we are defining
|
||||
// a procedure or function and comments in it are valuable
|
||||
$sql .= substr(
|
||||
$buffer,
|
||||
$start_of_comment,
|
||||
$i - $start_of_comment
|
||||
);
|
||||
// Next query part will start here
|
||||
$start_pos = $i;
|
||||
// Aren't we at the end?
|
||||
if ($i == $len) {
|
||||
$i--;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Change delimiter, if redefined, and skip it
|
||||
// (don't send to server!)
|
||||
if (($i + $length_of_delimiter_keyword < $len)
|
||||
&& strtoupper(
|
||||
substr($buffer, $i, $length_of_delimiter_keyword)
|
||||
) == $delimiter_keyword
|
||||
) {
|
||||
// look for EOL on the character immediately after 'DELIMITER '
|
||||
// (see previous comment about PHP_EOL)
|
||||
$new_line_pos = strpos(
|
||||
$buffer,
|
||||
"\n",
|
||||
$i + $length_of_delimiter_keyword
|
||||
);
|
||||
// it might happen that there is no EOL
|
||||
if (false === $new_line_pos) {
|
||||
$new_line_pos = $len;
|
||||
}
|
||||
$sql_delimiter = substr(
|
||||
$buffer,
|
||||
$i + $length_of_delimiter_keyword,
|
||||
$new_line_pos - $i - $length_of_delimiter_keyword
|
||||
);
|
||||
$i = $new_line_pos + 1;
|
||||
// Next query part will start here
|
||||
$start_pos = $i;
|
||||
continue;
|
||||
}
|
||||
|
||||
// End of SQL
|
||||
if ($found_delimiter
|
||||
|| ($GLOBALS['finished']
|
||||
&& ($i == $len - 1))
|
||||
) {
|
||||
$tmp_sql = $sql;
|
||||
if ($start_pos < $len) {
|
||||
$length_to_grab = $i - $start_pos;
|
||||
|
||||
if (! $found_delimiter) {
|
||||
$length_to_grab++;
|
||||
}
|
||||
$tmp_sql .= substr($buffer, $start_pos, $length_to_grab);
|
||||
unset($length_to_grab);
|
||||
}
|
||||
// Do not try to execute empty SQL
|
||||
if (! preg_match('/^([\s]*;)*$/', trim($tmp_sql))) {
|
||||
$sql = $tmp_sql;
|
||||
PMA_importRunQuery(
|
||||
$sql,
|
||||
substr($buffer, 0, $i + strlen($sql_delimiter))
|
||||
);
|
||||
$buffer = substr($buffer, $i + strlen($sql_delimiter));
|
||||
// Reset parser:
|
||||
$len = strlen($buffer);
|
||||
$sql = '';
|
||||
$i = 0;
|
||||
$start_pos = 0;
|
||||
// Any chance we will get a complete query?
|
||||
//if ((strpos($buffer, ';') === false)
|
||||
//&& ! $GLOBALS['finished']) {
|
||||
if (strpos($buffer, $sql_delimiter) === false
|
||||
&& ! $GLOBALS['finished']
|
||||
) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$i++;
|
||||
$start_pos = $i;
|
||||
}
|
||||
}
|
||||
} // End of parser loop
|
||||
} // End of import loop
|
||||
// Commit any possible data in buffers
|
||||
PMA_importRunQuery('', substr($buffer, 0, $len));
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
}
|
||||
371
libraries/plugins/import/ImportXml.class.php
Normal file
371
libraries/plugins/import/ImportXml.class.php
Normal file
@ -0,0 +1,371 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* XML import plugin for phpMyAdmin
|
||||
*
|
||||
* @todo Improve efficiency
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage XML
|
||||
*/
|
||||
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need way to disable external XML entities processing.
|
||||
*/
|
||||
if (!function_exists('libxml_disable_entity_loader')) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get the import interface */
|
||||
require_once "libraries/plugins/ImportPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the import for the XML format
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
*/
|
||||
class ImportXml extends ImportPlugin
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->setProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the import plugin properties.
|
||||
* Called in the constructor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setProperties()
|
||||
{
|
||||
$this->properties = array(
|
||||
'text' => __('XML'),
|
||||
'extension' => 'xml',
|
||||
'mime_type' => 'text/xml',
|
||||
'options' => array(),
|
||||
'options_text' => __('Options')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when any PluginManager to which the observer
|
||||
* is attached calls PluginManager::notify()
|
||||
*
|
||||
* @param SplSubject $subject The PluginManager notifying the observer
|
||||
* of an update.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function update (SplSubject $subject)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the whole import logic
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function doImport()
|
||||
{
|
||||
global $error, $timeout_passed, $finished, $db;
|
||||
|
||||
$i = 0;
|
||||
$len = 0;
|
||||
$buffer = "";
|
||||
|
||||
/**
|
||||
* Read in the file via PMA_importGetNextChunk so that
|
||||
* it can process compressed files
|
||||
*/
|
||||
while (! ($finished && $i >= $len) && ! $error && ! $timeout_passed) {
|
||||
$data = PMA_importGetNextChunk();
|
||||
if ($data === false) {
|
||||
/* subtract data we didn't handle yet and stop processing */
|
||||
$offset -= strlen($buffer);
|
||||
break;
|
||||
} elseif ($data === true) {
|
||||
/* Handle rest of buffer */
|
||||
} else {
|
||||
/* Append new data to buffer */
|
||||
$buffer .= $data;
|
||||
unset($data);
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
|
||||
/**
|
||||
* Disable loading of external XML entities.
|
||||
*/
|
||||
libxml_disable_entity_loader();
|
||||
|
||||
/**
|
||||
* Load the XML string
|
||||
*
|
||||
* The option LIBXML_COMPACT is specified because it can
|
||||
* result in increased performance without the need to
|
||||
* alter the code in any way. It's basically a freebee.
|
||||
*/
|
||||
$xml = simplexml_load_string($buffer, "SimpleXMLElement", LIBXML_COMPACT);
|
||||
|
||||
unset($buffer);
|
||||
|
||||
/**
|
||||
* The XML was malformed
|
||||
*/
|
||||
if ($xml === false) {
|
||||
PMA_Message::error(
|
||||
__(
|
||||
'The XML file specified was either malformed or incomplete.'
|
||||
. ' Please correct the issue and try again.'
|
||||
)
|
||||
)->display();
|
||||
unset($xml);
|
||||
$GLOBALS['finished'] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Table accumulator
|
||||
*/
|
||||
$tables = array();
|
||||
/**
|
||||
* Row accumulator
|
||||
*/
|
||||
$rows = array();
|
||||
|
||||
/**
|
||||
* Temp arrays
|
||||
*/
|
||||
$tempRow = array();
|
||||
$tempCells = array();
|
||||
|
||||
/**
|
||||
* CREATE code included (by default: no)
|
||||
*/
|
||||
$struct_present = false;
|
||||
|
||||
/**
|
||||
* Analyze the data in each table
|
||||
*/
|
||||
$namespaces = $xml->getNameSpaces(true);
|
||||
|
||||
/**
|
||||
* Get the database name, collation and charset
|
||||
*/
|
||||
$db_attr = $xml->children($namespaces['pma'])
|
||||
->{'structure_schemas'}->{'database'};
|
||||
|
||||
if ($db_attr instanceof SimpleXMLElement) {
|
||||
$db_attr = $db_attr->attributes();
|
||||
$db_name = (string)$db_attr['name'];
|
||||
$collation = (string)$db_attr['collation'];
|
||||
$charset = (string)$db_attr['charset'];
|
||||
} else {
|
||||
/**
|
||||
* If the structure section is not present
|
||||
* get the database name from the data section
|
||||
*/
|
||||
$db_attr = $xml->children()->attributes();
|
||||
$db_name = (string)$db_attr['name'];
|
||||
$collation = null;
|
||||
$charset = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The XML was malformed
|
||||
*/
|
||||
if ($db_name === null) {
|
||||
PMA_Message::error(
|
||||
__(
|
||||
'The XML file specified was either malformed or incomplete.'
|
||||
. ' Please correct the issue and try again.'
|
||||
)
|
||||
)->display();
|
||||
unset($xml);
|
||||
$GLOBALS['finished'] = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the structure information
|
||||
*/
|
||||
if (isset($namespaces['pma'])) {
|
||||
/**
|
||||
* Get structures for all tables
|
||||
*/
|
||||
$struct = $xml->children($namespaces['pma']);
|
||||
|
||||
$create = array();
|
||||
|
||||
foreach ($struct as $tier1 => $val1) {
|
||||
foreach ($val1 as $tier2 => $val2) {
|
||||
// Need to select the correct database for the creation of
|
||||
// tables, views, triggers, etc.
|
||||
/**
|
||||
* @todo Generating a USE here blocks importing of a table
|
||||
* into another database.
|
||||
*/
|
||||
$attrs = $val2->attributes();
|
||||
$create[] = "USE " . PMA_backquote($attrs["name"]);
|
||||
|
||||
foreach ($val2 as $val3) {
|
||||
/**
|
||||
* Remove the extra cosmetic spacing
|
||||
*/
|
||||
$val3 = str_replace(" ", "", (string)$val3);
|
||||
$create[] = $val3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$struct_present = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move down the XML tree to the actual data
|
||||
*/
|
||||
$xml = $xml->children()->children();
|
||||
|
||||
$data_present = false;
|
||||
|
||||
/**
|
||||
* Only attempt to analyze/collect data if there is data present
|
||||
*/
|
||||
if ($xml && @$xml->count()) {
|
||||
$data_present = true;
|
||||
|
||||
/**
|
||||
* Process all database content
|
||||
*/
|
||||
foreach ($xml as $k1 => $v1) {
|
||||
$tbl_attr = $v1->attributes();
|
||||
|
||||
$isInTables = false;
|
||||
for ($i = 0; $i < count($tables); ++$i) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], (string)$tbl_attr['name'])) {
|
||||
$isInTables = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isInTables == false) {
|
||||
$tables[] = array((string)$tbl_attr['name']);
|
||||
}
|
||||
|
||||
foreach ($v1 as $k2 => $v2) {
|
||||
$row_attr = $v2->attributes();
|
||||
if (! array_search((string)$row_attr['name'], $tempRow)) {
|
||||
$tempRow[] = (string)$row_attr['name'];
|
||||
}
|
||||
$tempCells[] = (string)$v2;
|
||||
}
|
||||
|
||||
$rows[] = array((string)$tbl_attr['name'], $tempRow, $tempCells);
|
||||
|
||||
$tempRow = array();
|
||||
$tempCells = array();
|
||||
}
|
||||
|
||||
unset($tempRow);
|
||||
unset($tempCells);
|
||||
unset($xml);
|
||||
|
||||
/**
|
||||
* Bring accumulated rows into the corresponding table
|
||||
*/
|
||||
$num_tbls = count($tables);
|
||||
for ($i = 0; $i < $num_tbls; ++$i) {
|
||||
for ($j = 0; $j < count($rows); ++$j) {
|
||||
if (! strcmp($tables[$i][TBL_NAME], $rows[$j][TBL_NAME])) {
|
||||
if (! isset($tables[$i][COL_NAMES])) {
|
||||
$tables[$i][] = $rows[$j][COL_NAMES];
|
||||
}
|
||||
|
||||
$tables[$i][ROWS][] = $rows[$j][ROWS];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($rows);
|
||||
|
||||
if (! $struct_present) {
|
||||
$analyses = array();
|
||||
|
||||
$len = count($tables);
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
$analyses[] = PMA_analyzeTable($tables[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($xml);
|
||||
unset($tempRows);
|
||||
unset($tempCells);
|
||||
unset($rows);
|
||||
|
||||
/**
|
||||
* Only build SQL from data if there is data present
|
||||
*/
|
||||
if ($data_present) {
|
||||
/**
|
||||
* Set values to NULL if they were not present
|
||||
* to maintain PMA_buildSQL() call integrity
|
||||
*/
|
||||
if (! isset($analyses)) {
|
||||
$analyses = null;
|
||||
if (! $struct_present) {
|
||||
$create = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* string $db_name (no backquotes)
|
||||
*
|
||||
* array $table = array(table_name, array() column_names, array()() rows)
|
||||
* array $tables = array of "$table"s
|
||||
*
|
||||
* array $analysis = array(array() column_types, array() column_sizes)
|
||||
* array $analyses = array of "$analysis"s
|
||||
*
|
||||
* array $create = array of SQL strings
|
||||
*
|
||||
* array $options = an associative array of options
|
||||
*/
|
||||
|
||||
/* Set database name to the currently selected one, if applicable */
|
||||
if (strlen($db)) {
|
||||
/* Override the database name in the XML file, if one is selected */
|
||||
$db_name = $db;
|
||||
$options = array('create_db' => false);
|
||||
} else {
|
||||
if ($db_name === null) {
|
||||
$db_name = 'XML_DB';
|
||||
}
|
||||
|
||||
/* Set database collation/charset */
|
||||
$options = array(
|
||||
'db_collation' => $collation,
|
||||
'db_charset' => $charset,
|
||||
);
|
||||
}
|
||||
|
||||
/* Created and execute necessary SQL statements from data */
|
||||
PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
|
||||
|
||||
unset($analyses);
|
||||
unset($tables);
|
||||
unset($create);
|
||||
|
||||
/* Commit any possible data in buffers */
|
||||
PMA_importRunQuery();
|
||||
}
|
||||
}
|
||||
102
libraries/plugins/import/PMA_ShapeFile.class.php
Normal file
102
libraries/plugins/import/PMA_ShapeFile.class.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* This class extends ShapeFile class to cater the following phpMyAdmin
|
||||
* specific requirements.
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1) To load data from .dbf file only when the dBase extension is available.
|
||||
* 2) To use PMA_importGetNextChunk() functionality to read data, rather than
|
||||
* reading directly from a file. Using ImportShp::readFromBuffer() in place
|
||||
* of fread(). This makes it possible to use compressions.
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
class PMA_ShapeFile extends ShapeFile
|
||||
{
|
||||
/**
|
||||
* Returns whether the 'dbase' extension is loaded
|
||||
*
|
||||
* @return boolean whether the 'dbase' extension is loaded
|
||||
*/
|
||||
function _isDbaseLoaded()
|
||||
{
|
||||
return extension_loaded('dbase');
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads ESRI shape data from the imported file
|
||||
*
|
||||
* @param string $FileName not used, it's here only to match the method
|
||||
* signature of the method being overidden
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeFile::loadFromFile()
|
||||
*/
|
||||
function loadFromFile($FileName)
|
||||
{
|
||||
$this->_loadHeaders();
|
||||
$this->_loadRecords();
|
||||
if ($this->_isDbaseLoaded()) {
|
||||
$this->_closeDBFFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads metadata from the ESRI shape file header
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeFile::_loadHeaders()
|
||||
*/
|
||||
function _loadHeaders()
|
||||
{
|
||||
ImportShp::readFromBuffer(24);
|
||||
$this->fileLength = loadData("N", ImportShp::readFromBuffer(4));
|
||||
|
||||
ImportShp::readFromBuffer(4);
|
||||
$this->shapeType = loadData("V", ImportShp::readFromBuffer(4));
|
||||
|
||||
$this->boundingBox = array();
|
||||
$this->boundingBox["xmin"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->boundingBox["ymin"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->boundingBox["xmax"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->boundingBox["ymax"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
|
||||
if ($this->_isDbaseLoaded() && $this->_openDBFFile()) {
|
||||
$this->DBFHeader = $this->_loadDBFHeader();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads geometry data from the ESRI shape file
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeFile::_loadRecords()
|
||||
*/
|
||||
function _loadRecords()
|
||||
{
|
||||
global $eof;
|
||||
ImportShp::readFromBuffer(32);
|
||||
while (true) {
|
||||
$record = new PMA_ShapeRecord(-1);
|
||||
$record->loadFromFile($this->SHPFile, $this->DBFFile);
|
||||
if ($record->lastError != "") {
|
||||
return false;
|
||||
}
|
||||
if ($eof) {
|
||||
break;
|
||||
}
|
||||
|
||||
$this->records[] = $record;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
161
libraries/plugins/import/PMA_ShapeRecord.class.php
Normal file
161
libraries/plugins/import/PMA_ShapeRecord.class.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* This class extends ShapeRecord class to cater the following phpMyAdmin
|
||||
* specific requirements.
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1) To load data from .dbf file only when the dBase extension is available.
|
||||
* 2) To use PMA_importGetNextChunk() functionality to read data, rather than
|
||||
* reading directly from a file. Using ImportShp::readFromBuffer() in place
|
||||
* of fread(). This makes it possible to use compressions.
|
||||
*
|
||||
* @package PhpMyAdmin-Import
|
||||
* @subpackage ESRI_Shape
|
||||
*/
|
||||
class PMA_ShapeRecord extends ShapeRecord
|
||||
{
|
||||
/**
|
||||
* Loads a geometry data record from the file
|
||||
*
|
||||
* @param object &$SHPFile .shp file
|
||||
* @param object &$DBFFile .dbf file
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::loadFromFile()
|
||||
*/
|
||||
function loadFromFile(&$SHPFile, &$DBFFile)
|
||||
{
|
||||
$this->DBFFile = $DBFFile;
|
||||
$this->_loadHeaders();
|
||||
|
||||
switch ($this->shapeType) {
|
||||
case 0:
|
||||
$this->_loadNullRecord();
|
||||
break;
|
||||
case 1:
|
||||
$this->_loadPointRecord();
|
||||
break;
|
||||
case 3:
|
||||
$this->_loadPolyLineRecord();
|
||||
break;
|
||||
case 5:
|
||||
$this->_loadPolygonRecord();
|
||||
break;
|
||||
case 8:
|
||||
$this->_loadMultiPointRecord();
|
||||
break;
|
||||
default:
|
||||
$this->setError(
|
||||
sprintf(
|
||||
__("Geometry type '%s' is not supported by MySQL."),
|
||||
$this->shapeType
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
if (extension_loaded('dbase') && isset($this->DBFFile)) {
|
||||
$this->_loadDBFData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads metadata from the ESRI shape record header
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadHeaders()
|
||||
*/
|
||||
function _loadHeaders()
|
||||
{
|
||||
$this->recordNumber = loadData("N", ImportShp::readFromBuffer(4));
|
||||
ImportShp::readFromBuffer(4);
|
||||
$this->shapeType = loadData("V", ImportShp::readFromBuffer(4));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a point record
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadPoint()
|
||||
*/
|
||||
function _loadPoint()
|
||||
{
|
||||
$data = array();
|
||||
|
||||
$data["x"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$data["y"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a multipoint record
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadMultiPointRecord()
|
||||
*/
|
||||
function _loadMultiPointRecord()
|
||||
{
|
||||
$this->SHPData = array();
|
||||
$this->SHPData["xmin"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->SHPData["ymin"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->SHPData["xmax"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->SHPData["ymax"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
|
||||
$this->SHPData["numpoints"] = loadData("V", ImportShp::readFromBuffer(4));
|
||||
|
||||
for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
|
||||
$this->SHPData["points"][] = $this->_loadPoint();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads data from a polyline record
|
||||
*
|
||||
* @return void
|
||||
* @see ShapeRecord::_loadPolyLineRecord()
|
||||
*/
|
||||
function _loadPolyLineRecord()
|
||||
{
|
||||
$this->SHPData = array();
|
||||
$this->SHPData["xmin"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->SHPData["ymin"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->SHPData["xmax"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
$this->SHPData["ymax"] = loadData("d", ImportShp::readFromBuffer(8));
|
||||
|
||||
$this->SHPData["numparts"] = loadData("V", ImportShp::readFromBuffer(4));
|
||||
$this->SHPData["numpoints"] = loadData("V", ImportShp::readFromBuffer(4));
|
||||
|
||||
for ($i = 0; $i < $this->SHPData["numparts"]; $i++) {
|
||||
$this->SHPData["parts"][$i] = loadData(
|
||||
"V", ImportShp::readFromBuffer(4)
|
||||
);
|
||||
}
|
||||
|
||||
$readPoints = 0;
|
||||
reset($this->SHPData["parts"]);
|
||||
while (list($partIndex, $partData) = each($this->SHPData["parts"])) {
|
||||
if (! isset($this->SHPData["parts"][$partIndex]["points"])
|
||||
|| !is_array($this->SHPData["parts"][$partIndex]["points"])
|
||||
) {
|
||||
$this->SHPData["parts"][$partIndex] = array();
|
||||
$this->SHPData["parts"][$partIndex]["points"] = array();
|
||||
}
|
||||
while (! in_array($readPoints, $this->SHPData["parts"])
|
||||
&& ($readPoints < ($this->SHPData["numpoints"]))
|
||||
) {
|
||||
$this->SHPData["parts"][$partIndex]["points"][]
|
||||
= $this->_loadPoint();
|
||||
$readPoints++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -1,3 +1,5 @@
|
||||
Todo: Rewrite!
|
||||
|
||||
This directory holds import plugins for phpMyAdmin. Plugin should
|
||||
basically look like following code. Official plugins need to have str*
|
||||
messages with their definition in language files, if you build some
|
||||
84
libraries/plugins/import/upload/UploadApc.class.php
Normal file
84
libraries/plugins/import/upload/UploadApc.class.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* Implementation for the APC extension
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadApc implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return 'APC_UPLOAD_PROGRESS';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for APC extension.
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadApc::getIdKey()
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (! PMA_import_apcCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
$status = apc_fetch('upload_' . $id);
|
||||
|
||||
if ($status) {
|
||||
$ret['finished'] = (bool)$status['done'];
|
||||
$ret['total'] = $status['total'];
|
||||
$ret['complete'] = $status['current'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
|
||||
if ($ret['percent'] == 100) {
|
||||
$ret['finished'] = (bool)true;
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
64
libraries/plugins/import/upload/UploadNoplugin.class.php
Normal file
64
libraries/plugins/import/upload/UploadNoplugin.class.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* Implementation for no plugin
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadNoplugin implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return 'noplugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation when no webserver support exists,
|
||||
* so it returns just zeroes.
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadNoplugin::getIdKey()
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
94
libraries/plugins/import/upload/UploadProgress.class.php
Normal file
94
libraries/plugins/import/upload/UploadProgress.class.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* Implementation for upload progress
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadProgress implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return 'UPLOAD_IDENTIFIER';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for upload progress
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == "") {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadProgress::getIdKey()
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (! PMA_import_progressCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$status = uploadprogress_get_info($id);
|
||||
|
||||
if ($status) {
|
||||
if ($status['bytes_uploaded'] == $status['bytes_total']) {
|
||||
$ret['finished'] = true;
|
||||
} else {
|
||||
$ret['finished'] = false;
|
||||
}
|
||||
$ret['total'] = $status['bytes_total'];
|
||||
$ret['complete'] = $status['bytes_uploaded'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
} else {
|
||||
$ret = array(
|
||||
'id' => $id,
|
||||
'finished' => true,
|
||||
'percent' => 100,
|
||||
'total' => $ret['total'],
|
||||
'complete' => $ret['total'],
|
||||
'plugin' => UploadProgress::getIdKey()
|
||||
);
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
96
libraries/plugins/import/upload/UploadSession.class.php
Normal file
96
libraries/plugins/import/upload/UploadSession.class.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Provides upload functionalities for the import plugins
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the transformations interface */
|
||||
require_once "libraries/plugins/UploadInterface.int.php";
|
||||
|
||||
/**
|
||||
* Implementation for session
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class UploadSession implements UploadInterface
|
||||
{
|
||||
/**
|
||||
* Gets the specific upload ID Key
|
||||
*
|
||||
* @return string ID Key
|
||||
*/
|
||||
public static function getIdKey()
|
||||
{
|
||||
return ini_get('session.upload_progress.name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns upload status.
|
||||
*
|
||||
* This is implementation for session.upload_progress in PHP 5.4+.
|
||||
*
|
||||
* @param string $id upload id
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getUploadStatus($id)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
|
||||
if (trim($id) == '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! array_key_exists($id, $_SESSION[$SESSION_KEY])) {
|
||||
$_SESSION[$SESSION_KEY][$id] = array(
|
||||
'id' => $id,
|
||||
'finished' => false,
|
||||
'percent' => 0,
|
||||
'total' => 0,
|
||||
'complete' => 0,
|
||||
'plugin' => UploadSession::getIdKey()
|
||||
);
|
||||
}
|
||||
$ret = $_SESSION[$SESSION_KEY][$id];
|
||||
|
||||
if (! PMA_import_sessionCheck() || $ret['finished']) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
$status = false;
|
||||
$sessionkey = ini_get('session.upload_progress.prefix') . $id;
|
||||
|
||||
if (isset($_SESSION[$sessionkey])) {
|
||||
$status = $_SESSION[$sessionkey];
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$ret['finished'] = $status['done'];
|
||||
$ret['total'] = $status['content_length'];
|
||||
$ret['complete'] = $status['bytes_processed'];
|
||||
|
||||
if ($ret['total'] > 0) {
|
||||
$ret['percent'] = $ret['complete'] / $ret['total'] * 100;
|
||||
}
|
||||
} else {
|
||||
$ret = array(
|
||||
'id' => $id,
|
||||
'finished' => true,
|
||||
'percent' => 100,
|
||||
'total' => $ret['total'],
|
||||
'complete' => $ret['total'],
|
||||
'plugin' => UploadSession::getIdKey()
|
||||
);
|
||||
}
|
||||
|
||||
$_SESSION[$SESSION_KEY][$id] = $ret;
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Application OctetStream Download Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Download
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
/* Get the download transformations interface */
|
||||
require_once "abstract/DownloadTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the download transformation for application octetstream
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Application_Octetstream_Download extends DownloadTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Application";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "OctetStream";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Application OctetStream Hex Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Hex
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the hex transformations interface */
|
||||
require_once "abstract/HexTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the hex transformation for application octetstream
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Application_Octetstream_Hex extends HexTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Application";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "OctetStream";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Image JPEG Inline Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Inline
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the inline transformations interface */
|
||||
require_once "abstract/InlineTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the inline transformation for image jpeg
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Image_JPEG_Inline extends InlineTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Image";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "JPEG";
|
||||
}
|
||||
}
|
||||
?>
|
||||
43
libraries/plugins/transformations/Image_JPEG_Link.class.php
Normal file
43
libraries/plugins/transformations/Image_JPEG_Link.class.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Image JPEG Link Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Link
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the link transformations interface */
|
||||
require_once "abstract/ImageLinkTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the link transformation for image jpeg
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Image_JPEG_Link extends ImageLinkTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Image";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "JPEG";
|
||||
}
|
||||
}
|
||||
?>
|
||||
43
libraries/plugins/transformations/Image_PNG_Inline.class.php
Normal file
43
libraries/plugins/transformations/Image_PNG_Inline.class.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Image PNG Inline Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Inline
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the inline transformations interface */
|
||||
require_once "abstract/InlineTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the inline transformation for image png
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Image_PNG_Inline extends InlineTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Image";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "PNG";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain Append Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Append
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the append transformations interface */
|
||||
require_once "abstract/AppendTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the append transformation for text plain.
|
||||
* Has one option: the text to be appended (default '')
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_Append extends AppendTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain Date Format Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage DateFormat
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the date format transformations interface */
|
||||
require_once "abstract/DateFormatTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the date format transformation for text plain
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_Dateformat extends DateFormatTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain External Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage External
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the external transformations interface */
|
||||
require_once "abstract/ExternalTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the external transformation for text plain
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_External extends ExternalTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain Formatted Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Formatted
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the formatted transformations interface */
|
||||
require_once "abstract/FormattedTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the formatted transformation for text plain
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_Formatted extends FormattedTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain Image Link Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage ImageLink
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the image link transformations interface */
|
||||
require_once "abstract/TextImageLinkTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the image link transformation for text plain
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_Imagelink extends TextImageLinkTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
43
libraries/plugins/transformations/Text_Plain_Link.class.php
Normal file
43
libraries/plugins/transformations/Text_Plain_Link.class.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain Link Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage Link
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the link transformations interface */
|
||||
require_once "abstract/TextLinkTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the link transformation for text plain
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_Link extends TextLinkTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain Long To IPv4 Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage LongToIPv4
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the long to ipv4 transformations interface */
|
||||
require_once "abstract/LongToIPv4TransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the long to ipv4 transformation for text plain
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_Longtoipv4 extends LongToIPv4TransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
43
libraries/plugins/transformations/Text_Plain_Sql.class.php
Normal file
43
libraries/plugins/transformations/Text_Plain_Sql.class.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Text Plain SQL Transformations plugin for phpMyAdmin
|
||||
*
|
||||
* @package PhpMyAdmin-Transformations
|
||||
* @subpackage SQL
|
||||
*/
|
||||
if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/* Get the sql transformations interface */
|
||||
require_once "abstract/SQLTransformationsPlugin.class.php";
|
||||
|
||||
/**
|
||||
* Handles the sql transformation for text plain
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class Text_Plain_Sql extends SQLTransformationsPlugin
|
||||
{
|
||||
/**
|
||||
* Gets the plugin`s MIME type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMEType()
|
||||
{
|
||||
return "Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the plugin`s MIME subtype
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getMIMESubtype()
|
||||
{
|
||||
return "Plain";
|
||||
}
|
||||
}
|
||||
?>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user