TextImageLinkTransformationsPlugin.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Abstract class for the image link transformations plugins
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  7. use PhpMyAdmin\Plugins\TransformationsPlugin;
  8. use PhpMyAdmin\Sanitize;
  9. use PhpMyAdmin\Template;
  10. use stdClass;
  11. use function htmlspecialchars;
  12. /**
  13. * Provides common methods for all of the image link transformations plugins.
  14. */
  15. abstract class TextImageLinkTransformationsPlugin extends TransformationsPlugin
  16. {
  17. /**
  18. * Gets the transformation description of the specific plugin
  19. *
  20. * @return string
  21. */
  22. public static function getInfo()
  23. {
  24. return __(
  25. 'Displays an image and a link; the column contains the filename. The'
  26. . ' first option is a URL prefix like "https://www.example.com/". The'
  27. . ' second and third options are the width and the height in pixels.'
  28. );
  29. }
  30. /**
  31. * Does the actual work of each specific transformations plugin.
  32. *
  33. * @param string $buffer text to be transformed
  34. * @param array $options transformation options
  35. * @param stdClass|null $meta meta information
  36. *
  37. * @return string
  38. */
  39. public function applyTransformation($buffer, array $options = [], ?stdClass $meta = null)
  40. {
  41. $cfg = $GLOBALS['cfg'];
  42. $options = $this->getOptions($options, $cfg['DefaultTransformations']['TextImageLink']);
  43. $url = $options[0] . $buffer;
  44. /* Do not allow javascript links */
  45. if (! Sanitize::checkLink($url, true, true)) {
  46. return htmlspecialchars($url);
  47. }
  48. $template = new Template();
  49. return $template->render('plugins/text_image_link_transformations', [
  50. 'url' => $url,
  51. 'width' => (int) $options[1],
  52. 'height' => (int) $options[2],
  53. 'buffer' => $buffer,
  54. ]);
  55. }
  56. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  57. /**
  58. * Gets the transformation name of the specific plugin
  59. *
  60. * @return string
  61. */
  62. public static function getName()
  63. {
  64. return 'Image Link';
  65. }
  66. }