Import.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * functions for displaying import for: server, database and table
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Display;
  9. use PhpMyAdmin\Core;
  10. use PhpMyAdmin\Display\ImportAjax;
  11. use PhpMyAdmin\Encoding;
  12. use PhpMyAdmin\Message;
  13. use PhpMyAdmin\Plugins;
  14. use PhpMyAdmin\Template;
  15. /**
  16. * PhpMyAdmin\Display\Import class
  17. *
  18. * @package PhpMyAdmin
  19. */
  20. class Import
  21. {
  22. /**
  23. * Gets HTML to display import dialogs
  24. *
  25. * @param string $importType Import type: server|database|table
  26. * @param string $db Selected DB
  27. * @param string $table Selected Table
  28. * @param int $maxUploadSize Max upload size
  29. *
  30. * @return string HTML
  31. */
  32. public static function get($importType, $db, $table, $maxUploadSize)
  33. {
  34. global $cfg;
  35. global $SESSION_KEY;
  36. list(
  37. $SESSION_KEY,
  38. $uploadId,
  39. ) = ImportAjax::uploadProgressSetup();
  40. /* Scan for plugins */
  41. /* @var $importList \PhpMyAdmin\Plugins\ImportPlugin[] */
  42. $importList = Plugins::getPlugins(
  43. "import",
  44. 'libraries/classes/Plugins/Import/',
  45. $importType
  46. );
  47. /* Fail if we didn't find any plugin */
  48. if (empty($importList)) {
  49. Message::error(
  50. __(
  51. 'Could not load import plugins, please check your installation!'
  52. )
  53. )->display();
  54. exit;
  55. }
  56. if (Core::isValid($_REQUEST['offset'], 'numeric')) {
  57. $offset = intval($_REQUEST['offset']);
  58. }
  59. if (isset($_REQUEST['timeout_passed'])) {
  60. $timeoutPassed = $_REQUEST['timeout_passed'];
  61. }
  62. $localImportFile = '';
  63. if (isset($_REQUEST['local_import_file'])) {
  64. $localImportFile = $_REQUEST['local_import_file'];
  65. }
  66. // zip, gzip and bzip2 encode features
  67. $compressions = array();
  68. if ($cfg['GZipDump'] && function_exists('gzopen')) {
  69. $compressions[] = 'gzip';
  70. }
  71. if ($cfg['BZipDump'] && function_exists('bzopen')) {
  72. $compressions[] = 'bzip2';
  73. }
  74. if ($cfg['ZipDump'] && function_exists('zip_open')) {
  75. $compressions[] = 'zip';
  76. }
  77. return Template::get('display/import/import')->render([
  78. 'upload_id' => $uploadId,
  79. 'handler' => $_SESSION[$SESSION_KEY]["handler"],
  80. 'id_key' => $_SESSION[$SESSION_KEY]['handler']::getIdKey(),
  81. 'pma_theme_image' => $GLOBALS['pmaThemeImage'],
  82. 'import_type' => $importType,
  83. 'db' => $db,
  84. 'table' => $table,
  85. 'max_upload_size' => $maxUploadSize,
  86. 'import_list' => $importList,
  87. 'local_import_file' => $localImportFile,
  88. 'is_upload' => $GLOBALS['is_upload'],
  89. 'upload_dir' => isset($cfg['UploadDir']) ? $cfg['UploadDir'] : null,
  90. 'timeout_passed_global' => isset($GLOBALS['timeout_passed']) ? $GLOBALS['timeout_passed'] : null,
  91. 'compressions' => $compressions,
  92. 'is_encoding_supported' => Encoding::isSupported(),
  93. 'encodings' => Encoding::listEncodings(),
  94. 'import_charset' => isset($cfg['Import']['charset']) ? $cfg['Import']['charset'] : null,
  95. 'dbi' => $GLOBALS['dbi'],
  96. 'disable_is' => $cfg['Server']['DisableIS'],
  97. 'timeout_passed' => isset($timeoutPassed) ? $timeoutPassed : null,
  98. 'offset' => isset($offset) ? $offset : null,
  99. 'can_convert_kanji' => Encoding::canConvertKanji(),
  100. ]);
  101. }
  102. }