InlineTransformationsPlugin.php 2.3 KB

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