TextLinkTransformationsPlugin.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. 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 link transformations plugins.
  16. *
  17. * @package PhpMyAdmin
  18. */
  19. abstract class TextLinkTransformationsPlugin 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 link; the column contains the filename. The first option'
  30. . ' is a URL prefix like "http://www.example.com/". The second option'
  31. . ' is a title for the link.'
  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] : '') . ((isset($options[2]) && $options[2]) ? '' : $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="'
  52. . htmlspecialchars($url)
  53. . '" title="'
  54. . htmlspecialchars(isset($options[1]) ? $options[1] : '')
  55. . '" target="_blank" rel="noopener noreferrer">'
  56. . htmlspecialchars(isset($options[1]) ? $options[1] : $buffer)
  57. . '</a>';
  58. }
  59. /**
  60. * This method is called when any PluginManager to which the observer
  61. * is attached calls PluginManager::notify()
  62. *
  63. * @param SplSubject $subject The PluginManager notifying the observer
  64. * of an update.
  65. *
  66. * @todo implement
  67. * @return void
  68. */
  69. public function update (SplSubject $subject)
  70. {
  71. ;
  72. }
  73. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  74. /**
  75. * Gets the transformation name of the specific plugin
  76. *
  77. * @return string
  78. */
  79. public static function getName()
  80. {
  81. return "Link";
  82. }
  83. }
  84. ?>