TextFileUploadTransformationsPlugin.php 2.9 KB

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