TextFileUploadTransformationsPlugin.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Abstract class for the text file upload input transformations plugins
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  7. use PhpMyAdmin\Plugins\IOTransformationsPlugin;
  8. use stdClass;
  9. use function htmlspecialchars;
  10. /**
  11. * Provides common methods for all of the text file upload
  12. * input transformations plugins.
  13. */
  14. abstract class TextFileUploadTransformationsPlugin extends IOTransformationsPlugin
  15. {
  16. /**
  17. * Gets the transformation description of the specific plugin
  18. *
  19. * @return string
  20. */
  21. public static function getInfo()
  22. {
  23. return __(
  24. 'File upload functionality for TEXT columns. '
  25. . 'It does not have a textarea for input.'
  26. );
  27. }
  28. /**
  29. * Does the actual work of each specific transformations plugin.
  30. *
  31. * @param string $buffer text to be transformed
  32. * @param array $options transformation options
  33. * @param stdClass|null $meta meta information
  34. *
  35. * @return string
  36. */
  37. public function applyTransformation($buffer, array $options = [], ?stdClass $meta = null)
  38. {
  39. return $buffer;
  40. }
  41. /**
  42. * Returns the html for input field to override default textarea.
  43. * Note: Return empty string if default textarea is required.
  44. *
  45. * @param array $column column details
  46. * @param int $row_id row number
  47. * @param string $column_name_appendix the name attribute
  48. * @param array $options transformation options
  49. * @param string $value Current field value
  50. * @param string $text_dir text direction
  51. * @param int $tabindex tab index
  52. * @param int $tabindex_for_value offset for the values tabindex
  53. * @param int $idindex id index
  54. *
  55. * @return string the html for input field
  56. */
  57. public function getInputHtml(
  58. array $column,
  59. $row_id,
  60. $column_name_appendix,
  61. array $options,
  62. $value,
  63. $text_dir,
  64. $tabindex,
  65. $tabindex_for_value,
  66. $idindex
  67. ) {
  68. $html = '';
  69. if (! empty($value)) {
  70. $html = '<input type="hidden" name="fields_prev' . $column_name_appendix
  71. . '" value="' . htmlspecialchars($value) . '">';
  72. $html .= '<input type="hidden" name="fields' . $column_name_appendix
  73. . '" value="' . htmlspecialchars($value) . '">';
  74. }
  75. $html .= '<input type="file" name="fields_upload'
  76. . $column_name_appendix . '">';
  77. return $html;
  78. }
  79. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  80. /**
  81. * Gets the transformation name of the specific plugin
  82. *
  83. * @return string
  84. */
  85. public static function getName()
  86. {
  87. return 'Text file upload';
  88. }
  89. }