InlineTransformationsPlugin.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the inline transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage Inline
  8. */
  9. declare(strict_types=1);
  10. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  11. use PhpMyAdmin\Plugins\TransformationsPlugin;
  12. use stdClass;
  13. /**
  14. * Provides common methods for all of the inline transformations plugins.
  15. *
  16. * @package PhpMyAdmin
  17. */
  18. abstract class InlineTransformationsPlugin extends TransformationsPlugin
  19. {
  20. /**
  21. * Gets the transformation description of the specific plugin
  22. *
  23. * @return string
  24. */
  25. public static function getInfo()
  26. {
  27. return __(
  28. 'Displays a clickable thumbnail. The options are the maximum width'
  29. . ' and height in pixels. The original aspect ratio is preserved.'
  30. );
  31. }
  32. /**
  33. * Does the actual work of each specific transformations plugin.
  34. *
  35. * @param string $buffer text to be transformed
  36. * @param array $options transformation options
  37. * @param stdClass|null $meta meta information
  38. *
  39. * @return string
  40. */
  41. public function applyTransformation($buffer, array $options = [], ?stdClass $meta = null)
  42. {
  43. $cfg = $GLOBALS['cfg'];
  44. $options = $this->getOptions($options, $cfg['DefaultTransformations']['Inline']);
  45. if (PMA_IS_GD2) {
  46. return '<a href="transformation_wrapper.php'
  47. . $options['wrapper_link']
  48. . '" rel="noopener noreferrer" target="_blank"><img src="transformation_wrapper.php'
  49. . $options['wrapper_link'] . '&amp;resize=jpeg&amp;newWidth='
  50. . intval($options[0]) . '&amp;newHeight='
  51. . intval($options[1])
  52. . '" alt="[' . htmlspecialchars($buffer) . ']" border="0"></a>';
  53. } else {
  54. return '<img src="transformation_wrapper.php'
  55. . $options['wrapper_link']
  56. . '" alt="[' . htmlspecialchars($buffer) . ']" width="320" height="240">';
  57. }
  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 "Inline";
  68. }
  69. }