PreApPendTransformationsPlugin.php 1.9 KB

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