TextFileUploadTransformationsPlugin.php 3.0 KB

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