TextImageLinkTransformationsPlugin.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the image link transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage ImageLink
  8. */
  9. if (! defined('PHPMYADMIN')) {
  10. exit;
  11. }
  12. /* Get the transformations interface */
  13. require_once 'libraries/plugins/TransformationsPlugin.class.php';
  14. /**
  15. * Provides common methods for all of the image link transformations plugins.
  16. *
  17. * @package PhpMyAdmin
  18. */
  19. abstract class TextImageLinkTransformationsPlugin 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 an image and a link; the column contains the filename. The'
  30. . ' first option is a URL prefix like "http://www.example.com/". The'
  31. . ' second and third options are the width and the height in pixels.'
  32. );
  33. }
  34. /**
  35. * Does the actual work of each specific transformations plugin.
  36. *
  37. * @param string $buffer text to be transformed
  38. * @param array $options transformation options
  39. * @param string $meta meta information
  40. *
  41. * @return void
  42. */
  43. public function applyTransformation($buffer, $options = array(), $meta = '')
  44. {
  45. $url = (isset($options[0]) ? $options[0] : '') . $buffer;
  46. $parsed = parse_url($url);
  47. /* Do not allow javascript links */
  48. if (! isset($parsed['scheme']) || ! in_array(strtolower($parsed['scheme']), array('http', 'https', 'ftp', 'mailto'))) {
  49. return htmlspecialchars($url);
  50. }
  51. return '<a href="' . htmlspecialchars($url)
  52. . '" rel="noopener noreferrer" target="_blank"><img src="' . htmlspecialchars($url)
  53. . '" border="0" width="' . (isset($options[1]) ? intval($options[1]) : 100)
  54. . '" height="' . (isset($options[2]) ? intval($options[2]) : 50) . '" />'
  55. . htmlspecialchars($buffer) . '</a>';
  56. }
  57. /**
  58. * This method is called when any PluginManager to which the observer
  59. * is attached calls PluginManager::notify()
  60. *
  61. * @param SplSubject $subject The PluginManager notifying the observer
  62. * of an update.
  63. *
  64. * @todo implement
  65. * @return void
  66. */
  67. public function update (SplSubject $subject)
  68. {
  69. ;
  70. }
  71. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  72. /**
  73. * Gets the transformation name of the specific plugin
  74. *
  75. * @return string
  76. */
  77. public static function getName()
  78. {
  79. return "Image Link";
  80. }
  81. }
  82. ?>