diff --git a/ChangeLog b/ChangeLog index e43ae1c96..397d93fc5 100755 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,11 @@ $Source$ list on import tab, prepare generic framework to be used elsewhere (RFE #1303145). * tbl_change.php: Use file common file listing. + * libraries/common.lib.php, libraries/display_import.lib.php, + libraries/file_listing.php, libraries/sql_query_form.lib.php: Use common + file listing in query window, remove no more used functions. Please note + that file import from query windows is currently half rewritten, so + compressed imports will not work. 2005-09-26 Sebastian Mendel * libraries/database_interface.lib.php: fixed bug in PMA_DBI_fetch_*() diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 70b5f4d6a..166055b10 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -2526,34 +2526,6 @@ if (typeof(document.getElementById) != 'undefined' define('PMA_MULTIBYTE_ENCODING', 1); } // end if - /** - * Function to check valid extension of file. It accepts entered - * extensions and bz2 and gz if supported. - * - * @param string File name to be tested. - * @param string Extension that is valid. - * - * @access public - * @author Michal Cihar (nijel@users.sourceforge.net) - * @return bool Whether extension is valid - */ - function PMA_checkFileExtensions($file, $extension) { - if (substr($file, -1 * strlen($extension)) == $extension) { - return TRUE; - } - if ($GLOBALS['cfg']['GZipDump'] && @function_exists('gzopen')) { - if (substr($file, -3 - strlen($extension)) == $extension . '.gz') { - return TRUE; - } - } - if ($GLOBALS['cfg']['BZipDump'] && @function_exists('bzdecompress')) { - if (substr($file, -4 - strlen($extension)) == $extension . '.bz2') { - return TRUE; - } - } - return FALSE; - } // end function - /** * Function to generate unique condition for specified row. * diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index 80c2c7108..311f8b775 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -137,28 +137,12 @@ echo PMA_displayMaximumUploadSize($max_upload_size); echo PMA_generateHiddenMaxFileSize($max_upload_size) . "\n"; if (!empty($cfg['UploadDir'])) { - if (substr($cfg['UploadDir'], -1) != '/') { - $cfg['UploadDir'] .= '/'; - } $extensions = ''; foreach($import_list as $key => $val) { if (!empty($extensions)) $extensions .= '|'; $extensions .= $val['extension']; } - $compressions = ''; - if ($cfg['GZipDump'] && @function_exists('gzopen')) { - if (!empty($compressions)) $compressions .= '|'; - $compressions .= 'gz'; - } - if ($cfg['BZipDump'] && @function_exists('bzopen')) { - if (!empty($compressions)) $compressions .= '|'; - $compressions .= 'bz2'; - } - if ($cfg['ZipDump'] && @function_exists('gzinflate')) { - if (!empty($compressions)) $compressions .= '|'; - $compressions .= 'zip'; - } - $matcher = '@\.(' . $extensions . ')(\.(' .$compressions . '))?$@'; + $matcher = '@\.(' . $extensions . ')(\.(' . PMA_supportedDecompressions() . '))?$@'; $files = PMA_getFileSelectOptions($cfg['UploadDir'], $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ? $local_import_file : ''); diff --git a/libraries/file_listing.php b/libraries/file_listing.php index ceed5f569..c7a9812c0 100644 --- a/libraries/file_listing.php +++ b/libraries/file_listing.php @@ -50,3 +50,29 @@ function PMA_getFileSelectOptions($dir, $extensions = '', $active = '') { } return $result; } + +/** + * Get currently supported decompressions. + * + * @returns string | separated list of extensions usable in PMA_getDirContent + */ +function PMA_supportedDecompressions() { + global $cfg; + + $compressions = ''; + + if ($cfg['GZipDump'] && @function_exists('gzopen')) { + if (!empty($compressions)) $compressions .= '|'; + $compressions .= 'gz'; + } + if ($cfg['BZipDump'] && @function_exists('bzopen')) { + if (!empty($compressions)) $compressions .= '|'; + $compressions .= 'bz2'; + } + if ($cfg['ZipDump'] && @function_exists('gzinflate')) { + if (!empty($compressions)) $compressions .= '|'; + $compressions .= 'zip'; + } + + return $compressions; +} diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php index 425a8d878..5c1d2b8e9 100644 --- a/libraries/sql_query_form.lib.php +++ b/libraries/sql_query_form.lib.php @@ -11,6 +11,8 @@ * @usedby querywindow.php */ +require_once('./libraries/file_listing.php'); // used for file listing + /** * prints the sql query boxes * @@ -452,46 +454,23 @@ function PMA_sqlQueryFormBookmark( $display_tab = 'full' ) { * @uses $GLOBALS['allow_recoding'] * @uses $GLOBALS['charset'] * @uses $GLOBALS['max_upload_size'] - * @uses PMA_checkFileExtensions() + * @uses PMA_supportedDecompressions() + * @uses PMA_getFileSelectOptions() * @uses PMA_displayMaximumUploadSize() * @uses PMA_generateCharsetDropdownBox() * @uses PMA_generateHiddenMaxFileSize() * @uses PMA_MYSQL_INT_VERSION * @uses PMA_CSDROPDOWN_CHARSET - * @uses closedir() - * @uses count() - * @uses function_exists() - * @uses htmlspecialchars() - * @uses opendir() - * @uses readdir() + * @uses empty() * @param string $display_tab current tab displayed if in querywindow */ function PMA_sqlQueryFormUpload( $display_tab = 'full' ) { - $uploaded_files = array(); - $errors = array(); - $is_gzip = ($GLOBALS['cfg']['GZipDump'] && @function_exists('gzopen')); - $is_bzip = ($GLOBALS['cfg']['BZipDump'] && @function_exists('bzdecompress')); - - if ( ! empty( $GLOBALS['cfg']['UploadDir'] ) ) { - if ( substr($GLOBALS['cfg']['UploadDir'], -1) != '/' ) { - $GLOBALS['cfg']['UploadDir'] .= '/'; - } - if ( $handle = @opendir( $GLOBALS['cfg']['UploadDir'] ) ) { - while ( $file = @readdir( $handle ) ) { - if ( is_file( $GLOBALS['cfg']['UploadDir'] . $file ) - && PMA_checkFileExtensions( $file, '.sql' ) ) - { - $uploaded_files[] = $file; - } - } // end while - @closedir( $handle ); - } - else { - $errors[$GLOBALS['strError']] = - $GLOBALS['strWebServerUploadDirectoryError']; - } - } // end if (web-server upload directory) - + $errors = array (); + + $matcher = '@\.sql(\.(' . PMA_supportedDecompressions() . '))?$@'; // we allow only SQL here + + $files = PMA_getFileSelectOptions($GLOBALS['cfg']['UploadDir'], $matcher, (isset($timeout_passed) && $timeout_passed && isset($local_import_file)) ? $local_import_file : ''); + // start output echo '
'; echo ''; @@ -501,49 +480,20 @@ function PMA_sqlQueryFormUpload( $display_tab = 'full' ) { echo PMA_displayMaximumUploadSize( $GLOBALS['max_upload_size'] ); // some browsers should respect this :) echo PMA_generateHiddenMaxFileSize( $GLOBALS['max_upload_size'] ) . "\n"; - echo ''; + echo ''; - if ( $is_bzip || $is_gzip ) { + if ($files === FALSE) { + $errors[$GLOBALS['strError']] = $GLOBALS['strWebServerUploadDirectoryError']; + } elseif (!empty($files)) { echo '
'; - echo $GLOBALS['strCompression'] . ': ' . "\n" - .'' - .'' . "\n" - .'' - .'' . "\n"; - if ( $is_gzip ) { - echo '' - .'' . "\n"; - } - if ( $is_bzip ) { - echo '' - .'' . "\n"; - } - echo '
'; - } else { - echo ''; - } - - if ( count( $uploaded_files ) > 0 ) { - echo '' . $GLOBALS['strWebServerUploadDirectory'] - .':' . "\n"; + echo '' . $GLOBALS['strWebServerUploadDirectory'] .':' . "\n"; echo '' . "\n"; + echo ''; } + echo '
' . "\n"; echo '
';