PreApPendTransformationsPlugin.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Abstract class for the prepend/append transformations plugins
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  7. use PhpMyAdmin\Plugins\TransformationsPlugin;
  8. use stdClass;
  9. use function htmlspecialchars;
  10. /**
  11. * Provides common methods for all of the prepend/append transformations plugins.
  12. */
  13. abstract class PreApPendTransformationsPlugin extends TransformationsPlugin
  14. {
  15. /**
  16. * Gets the transformation description of the specific plugin
  17. *
  18. * @return string
  19. */
  20. public static function getInfo()
  21. {
  22. return __(
  23. 'Prepends and/or Appends text to a string. First option is text'
  24. . ' to be prepended, second is appended (enclosed in single'
  25. . ' quotes, default empty string).'
  26. );
  27. }
  28. /**
  29. * Does the actual work of each specific transformations plugin.
  30. *
  31. * @param string $buffer text to be transformed
  32. * @param array $options transformation options
  33. * @param stdClass|null $meta meta information
  34. *
  35. * @return string
  36. */
  37. public function applyTransformation($buffer, array $options = [], ?stdClass $meta = null)
  38. {
  39. $cfg = $GLOBALS['cfg'];
  40. $options = $this->getOptions($options, $cfg['DefaultTransformations']['PreApPend']);
  41. //just prepend and/or append the options to the original text
  42. return htmlspecialchars($options[0]) . htmlspecialchars($buffer)
  43. . htmlspecialchars($options[1]);
  44. }
  45. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  46. /**
  47. * Gets the transformation name of the specific plugin
  48. *
  49. * @return string
  50. */
  51. public static function getName()
  52. {
  53. return 'PreApPend';
  54. }
  55. }