CodeMirrorEditorTransformationPlugin.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Abstract class for syntax highlighted editors using CodeMirror
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  7. use PhpMyAdmin\FieldMetadata;
  8. use PhpMyAdmin\Plugins\IOTransformationsPlugin;
  9. use function htmlspecialchars;
  10. use function strtolower;
  11. /**
  12. * Provides common methods for all the CodeMirror syntax highlighted editors
  13. */
  14. abstract class CodeMirrorEditorTransformationPlugin extends IOTransformationsPlugin
  15. {
  16. /**
  17. * Does the actual work of each specific transformations plugin.
  18. *
  19. * @param string $buffer text to be transformed
  20. * @param array $options transformation options
  21. * @param FieldMetadata|null $meta meta information
  22. *
  23. * @return string
  24. */
  25. public function applyTransformation($buffer, array $options = [], ?FieldMetadata $meta = null)
  26. {
  27. return $buffer;
  28. }
  29. /**
  30. * Returns the html for input field to override default textarea.
  31. * Note: Return empty string if default textarea is required.
  32. *
  33. * @param array $column column details
  34. * @param int $row_id row number
  35. * @param string $column_name_appendix the name attribute
  36. * @param array $options transformation options
  37. * @param string $value Current field value
  38. * @param string $text_dir text direction
  39. * @param int $tabindex tab index
  40. * @param int $tabindex_for_value offset for the values tabindex
  41. * @param int $idindex id index
  42. *
  43. * @return string the html for input field
  44. */
  45. public function getInputHtml(
  46. array $column,
  47. $row_id,
  48. $column_name_appendix,
  49. array $options,
  50. $value,
  51. $text_dir,
  52. $tabindex,
  53. $tabindex_for_value,
  54. $idindex
  55. ) {
  56. $html = '';
  57. if (! empty($value)) {
  58. $html = '<input type="hidden" name="fields_prev' . $column_name_appendix
  59. . '" value="' . htmlspecialchars($value) . '">';
  60. }
  61. $class = 'transform_' . strtolower(static::getName()) . '_editor';
  62. return $html . '<textarea name="fields' . $column_name_appendix . '"'
  63. . ' dir="' . $text_dir . '" class="' . $class . '">'
  64. . htmlspecialchars($value) . '</textarea>';
  65. }
  66. }