InlineTransformationsPlugin.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Abstract class for the inline 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 array_merge;
  11. use function defined;
  12. use function htmlspecialchars;
  13. /**
  14. * Provides common methods for all of the inline transformations plugins.
  15. */
  16. abstract class InlineTransformationsPlugin extends TransformationsPlugin
  17. {
  18. /**
  19. * Gets the transformation description of the specific plugin
  20. *
  21. * @return string
  22. */
  23. public static function getInfo()
  24. {
  25. return __(
  26. 'Displays a clickable thumbnail. The options are the maximum width'
  27. . ' and height in pixels. The original aspect ratio is preserved.'
  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']['Inline']);
  43. if (defined('PMA_IS_GD2') && PMA_IS_GD2 === 1) {
  44. return '<a href="' . Url::getFromRoute('/transformation/wrapper', $options['wrapper_params'])
  45. . '" rel="noopener noreferrer" target="_blank"><img src="'
  46. . Url::getFromRoute('/transformation/wrapper', array_merge($options['wrapper_params'], [
  47. 'resize' => 'jpeg',
  48. 'newWidth' => (int) $options[0],
  49. 'newHeight' => (int) $options[1],
  50. ]))
  51. . '" alt="[' . htmlspecialchars($buffer) . ']" border="0"></a>';
  52. }
  53. return '<img src="' . Url::getFromRoute('/transformation/wrapper', $options['wrapper_params'])
  54. . '" alt="[' . htmlspecialchars($buffer) . ']" width="320" height="240">';
  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 'Inline';
  65. }
  66. }