PreApPendTransformationsPlugin.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\FieldMetadata;
  8. use PhpMyAdmin\Plugins\TransformationsPlugin;
  9. use function __;
  10. use function htmlspecialchars;
  11. /**
  12. * Provides common methods for all of the prepend/append transformations plugins.
  13. */
  14. abstract class PreApPendTransformationsPlugin 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. 'Prepends and/or Appends text to a string. First option is text'
  25. . ' to be prepended, second is appended (enclosed in single'
  26. . ' quotes, default empty string).'
  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. $cfg = $GLOBALS['cfg'];
  41. $options = $this->getOptions($options, $cfg['DefaultTransformations']['PreApPend']);
  42. //just prepend and/or append the options to the original text
  43. return htmlspecialchars($options[0]) . htmlspecialchars($buffer)
  44. . htmlspecialchars($options[1]);
  45. }
  46. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  47. /**
  48. * Gets the transformation name of the specific plugin
  49. *
  50. * @return string
  51. */
  52. public static function getName()
  53. {
  54. return 'PreApPend';
  55. }
  56. }