FormattedTransformationsPlugin.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Abstract class for the formatted transformations plugins
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  7. use PhpMyAdmin\FieldMetadata;
  8. use PhpMyAdmin\Plugins\TransformationsPlugin;
  9. use function __;
  10. use function strtr;
  11. /**
  12. * Provides common methods for all of the formatted transformations plugins.
  13. */
  14. abstract class FormattedTransformationsPlugin extends TransformationsPlugin
  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. 'Displays the contents of the column as-is, without running it'
  25. . ' through htmlspecialchars(). That is, the column is assumed'
  26. . ' to contain valid HTML.'
  27. );
  28. }
  29. /**
  30. * Does the actual work of each specific transformations plugin.
  31. *
  32. * @param string $buffer text to be transformed
  33. * @param array $options transformation options
  34. * @param FieldMetadata|null $meta meta information
  35. *
  36. * @return string
  37. */
  38. public function applyTransformation($buffer, array $options = [], ?FieldMetadata $meta = null)
  39. {
  40. return '<iframe srcdoc="'
  41. . strtr($buffer, '"', '\'')
  42. . '" sandbox=""></iframe>';
  43. }
  44. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  45. /**
  46. * Gets the transformation name of the specific plugin
  47. *
  48. * @return string
  49. */
  50. public static function getName()
  51. {
  52. return 'Formatted';
  53. }
  54. }