ImageLinkTransformationsPlugin.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Abstract class for the link transformations plugins
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  7. use PhpMyAdmin\Plugins\TransformationsPlugin;
  8. use PhpMyAdmin\Url;
  9. use stdClass;
  10. use function htmlspecialchars;
  11. /**
  12. * Provides common methods for all of the link transformations plugins.
  13. */
  14. abstract class ImageLinkTransformationsPlugin 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. 'Displays a link to download this image.'
  25. );
  26. }
  27. /**
  28. * Does the actual work of each specific transformations plugin.
  29. *
  30. * @param string $buffer text to be transformed
  31. * @param array $options transformation options
  32. * @param stdClass|null $meta meta information
  33. *
  34. * @return string
  35. */
  36. public function applyTransformation($buffer, array $options = [], ?stdClass $meta = null)
  37. {
  38. // must disable the page loader, see
  39. // https://wiki.phpmyadmin.net/pma/Page_loader#Bypassing_the_page_loader
  40. $link = '<a class="disableAjax" target="_blank" rel="noopener noreferrer" href="';
  41. $link .= Url::getFromRoute('/transformation/wrapper', $options['wrapper_params']);
  42. $link .= '" alt="[' . htmlspecialchars($buffer);
  43. $link .= ']">[BLOB]</a>';
  44. return $link;
  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 'ImageLink';
  55. }
  56. }