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