TextImageLinkTransformationsPlugin.php 2.2 KB

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