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\FieldMetadata;
  8. use PhpMyAdmin\Plugins\TransformationsPlugin;
  9. use PhpMyAdmin\Url;
  10. use function __;
  11. use function htmlspecialchars;
  12. /**
  13. * Provides common methods for all of the link transformations plugins.
  14. */
  15. abstract class ImageLinkTransformationsPlugin 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 __('Displays a link to download this image.');
  25. }
  26. /**
  27. * Does the actual work of each specific transformations plugin.
  28. *
  29. * @param string $buffer text to be transformed
  30. * @param array $options transformation options
  31. * @param FieldMetadata|null $meta meta information
  32. *
  33. * @return string
  34. */
  35. public function applyTransformation($buffer, array $options = [], ?FieldMetadata $meta = null)
  36. {
  37. // must disable the page loader, see
  38. // https://wiki.phpmyadmin.net/pma/Page_loader#Bypassing_the_page_loader
  39. $link = '<a class="disableAjax" target="_blank" rel="noopener noreferrer" href="';
  40. $link .= Url::getFromRoute('/transformation/wrapper', $options['wrapper_params']);
  41. $link .= '" alt="[' . htmlspecialchars($buffer);
  42. $link .= ']">[BLOB]</a>';
  43. return $link;
  44. }
  45. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  46. /**
  47. * Gets the transformation name of the specific plugin
  48. *
  49. * @return string
  50. */
  51. public static function getName()
  52. {
  53. return 'ImageLink';
  54. }
  55. }