ImportAjax.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Handles plugins that show the upload progress
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Display;
  9. use PhpMyAdmin\Core;
  10. /**
  11. * PhpMyAdmin\Display\ImportAjax class
  12. *
  13. * @package PhpMyAdmin
  14. */
  15. class ImportAjax
  16. {
  17. /**
  18. * Sets up some variables for upload progress
  19. *
  20. * @return array
  21. */
  22. public static function uploadProgressSetup()
  23. {
  24. /**
  25. * constant for differentiating array in $_SESSION variable
  26. */
  27. $SESSION_KEY = '__upload_status';
  28. /**
  29. * sets default plugin for handling the import process
  30. */
  31. $_SESSION[$SESSION_KEY]["handler"] = "";
  32. /**
  33. * unique ID for each upload
  34. */
  35. $upload_id = uniqid("");
  36. /**
  37. * list of available plugins
  38. */
  39. $plugins = array(
  40. // PHP 5.4 session-based upload progress is problematic, see bug 3964
  41. //"session",
  42. "progress",
  43. "apc",
  44. "noplugin"
  45. );
  46. // select available plugin
  47. foreach ($plugins as $plugin) {
  48. $check = $plugin . "Check";
  49. if (self::$check()) {
  50. $upload_class = 'PhpMyAdmin\Plugins\Import\Upload\Upload' . ucwords(
  51. $plugin
  52. );
  53. $_SESSION[$SESSION_KEY]["handler"] = $upload_class;
  54. break;
  55. }
  56. }
  57. return array($SESSION_KEY, $upload_id, $plugins);
  58. }
  59. /**
  60. * Checks if APC bar extension is available and configured correctly.
  61. *
  62. * @return boolean true if APC extension is available and if rfc1867 is enabled,
  63. * false if it is not
  64. */
  65. public static function apcCheck()
  66. {
  67. if (! extension_loaded('apc')
  68. || ! function_exists('apc_fetch')
  69. || ! function_exists('getallheaders')
  70. ) {
  71. return false;
  72. }
  73. return (ini_get('apc.enabled') && ini_get('apc.rfc1867'));
  74. }
  75. /**
  76. * Checks if PhpMyAdmin\Plugins\Import\Upload\UploadProgress bar extension is
  77. * available.
  78. *
  79. * @return boolean true if PhpMyAdmin\Plugins\Import\Upload\UploadProgress
  80. * extension is available, false if it is not
  81. */
  82. public static function progressCheck()
  83. {
  84. return function_exists("uploadprogress_get_info")
  85. && function_exists('getallheaders');
  86. }
  87. /**
  88. * Checks if PHP 5.4 session upload-progress feature is available.
  89. *
  90. * @return boolean true if PHP 5.4 session upload-progress is available,
  91. * false if it is not
  92. */
  93. public static function sessionCheck()
  94. {
  95. return ini_get('session.upload_progress.enabled');
  96. }
  97. /**
  98. * Default plugin for handling import.
  99. * If no other plugin is available, noplugin is used.
  100. *
  101. * @return boolean true
  102. */
  103. public static function nopluginCheck()
  104. {
  105. return true;
  106. }
  107. /**
  108. * The function outputs json encoded status of uploaded.
  109. * It uses PMA_getUploadStatus, which is defined in plugin's file.
  110. *
  111. * @param string $id ID of transfer, usually $upload_id
  112. *
  113. * @return void
  114. */
  115. public static function status($id)
  116. {
  117. Core::headerJSON();
  118. echo json_encode(
  119. $_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getUploadStatus($id)
  120. );
  121. }
  122. }