TextLinkTransformationsPlugin.class.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /* For PMA_Transformation_globalHtmlReplace */
  15. require_once 'libraries/transformations.lib.php';
  16. /**
  17. * Provides common methods for all of the link transformations plugins.
  18. *
  19. * @package PhpMyAdmin
  20. */
  21. abstract class TextLinkTransformationsPlugin extends TransformationsPlugin
  22. {
  23. /**
  24. * Gets the transformation description of the specific plugin
  25. *
  26. * @return string
  27. */
  28. public static function getInfo()
  29. {
  30. return __(
  31. 'Displays a link; the column contains the filename. The first option'
  32. . ' is a URL prefix like "http://www.example.com/". The second option'
  33. . ' is a title for the link.'
  34. );
  35. }
  36. /**
  37. * Does the actual work of each specific transformations plugin.
  38. *
  39. * @param string $buffer text to be transformed
  40. * @param array $options transformation options
  41. * @param string $meta meta information
  42. *
  43. * @return string
  44. */
  45. public function applyTransformation($buffer, $options = array(), $meta = '')
  46. {
  47. $append_part = (isset($options[2]) && $options[2]) ? '' : $buffer;
  48. $transform_options = array (
  49. 'string' => '<a href="'
  50. . PMA_linkURL((isset($options[0]) ? $options[0] : '') . $append_part)
  51. . '" title="'
  52. . htmlspecialchars(isset($options[1]) ? $options[1] : '')
  53. . '" target="_new">'
  54. . htmlspecialchars(isset($options[1]) ? $options[1] : $buffer)
  55. . '</a>'
  56. );
  57. return PMA_Transformation_globalHtmlReplace(
  58. $buffer,
  59. $transform_options
  60. );
  61. }
  62. /**
  63. * This method is called when any PluginManager to which the observer
  64. * is attached calls PluginManager::notify()
  65. *
  66. * @param SplSubject $subject The PluginManager notifying the observer
  67. * of an update.
  68. *
  69. * @todo implement
  70. * @return void
  71. */
  72. public function update (SplSubject $subject)
  73. {
  74. ;
  75. }
  76. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  77. /**
  78. * Gets the transformation name of the specific plugin
  79. *
  80. * @return string
  81. */
  82. public static function getName()
  83. {
  84. return "TextLink";
  85. }
  86. }
  87. ?>