TextLinkTransformationsPlugin.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the link transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage Link
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  10. use PhpMyAdmin\Plugins\TransformationsPlugin;
  11. use PhpMyAdmin\Sanitize;
  12. if (!defined('PHPMYADMIN')) {
  13. exit;
  14. }
  15. /**
  16. * Provides common methods for all of the link transformations plugins.
  17. *
  18. * @package PhpMyAdmin
  19. */
  20. abstract class TextLinkTransformationsPlugin extends TransformationsPlugin
  21. {
  22. /**
  23. * Gets the transformation description of the specific plugin
  24. *
  25. * @return string
  26. */
  27. public static function getInfo()
  28. {
  29. return __(
  30. 'Displays a link; the column contains the filename. The first option'
  31. . ' is a URL prefix like "https://www.example.com/". The second option'
  32. . ' is a title for the link.'
  33. );
  34. }
  35. /**
  36. * Does the actual work of each specific transformations plugin.
  37. *
  38. * @param string $buffer text to be transformed
  39. * @param array $options transformation options
  40. * @param string $meta meta information
  41. *
  42. * @return string
  43. */
  44. public function applyTransformation($buffer, array $options = array(), $meta = '')
  45. {
  46. $cfg = $GLOBALS['cfg'];
  47. $options = $this->getOptions($options, $cfg['DefaultTransformations']['TextLink']);
  48. $url = (isset($options[0]) ? $options[0] : '') . ((isset($options[2]) && $options[2]) ? '' : $buffer);
  49. /* Do not allow javascript links */
  50. if (! Sanitize::checkLink($url, true, true)) {
  51. return htmlspecialchars($url);
  52. }
  53. return '<a href="'
  54. . htmlspecialchars($url)
  55. . '" title="'
  56. . htmlspecialchars(isset($options[1]) ? $options[1] : '')
  57. . '" target="_blank" rel="noopener noreferrer">'
  58. . htmlspecialchars(isset($options[1]) ? $options[1] : $buffer)
  59. . '</a>';
  60. }
  61. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  62. /**
  63. * Gets the transformation name of the specific plugin
  64. *
  65. * @return string
  66. */
  67. public static function getName()
  68. {
  69. return "TextLink";
  70. }
  71. }