SubstringTransformationsPlugin.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the substring transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage Substring
  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 substring transformations plugins.
  16. *
  17. * @package PhpMyAdmin
  18. */
  19. abstract class SubstringTransformationsPlugin 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 part of a string. The first option is the number of'
  30. . ' characters to skip from the beginning of the string (Default 0).'
  31. . ' The second option is the number of characters to return (Default:'
  32. . ' until end of string). The third option is the string to append'
  33. . ' and/or prepend when truncation occurs (Default: "…").'
  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 void
  44. */
  45. public function applyTransformation($buffer, $options = array(), $meta = '')
  46. {
  47. // possibly use a global transform and feed it with special options
  48. // further operations on $buffer using the $options[] array.
  49. if (!isset($options[0]) || $options[0] == '') {
  50. $options[0] = 0;
  51. }
  52. if (!isset($options[1]) || $options[1] == '') {
  53. $options[1] = 'all';
  54. }
  55. if (!isset($options[2]) || $options[2] == '') {
  56. $options[2] = '…';
  57. }
  58. $newtext = '';
  59. if ($options[1] != 'all') {
  60. $newtext = PMA_substr($buffer, $options[0], $options[1]);
  61. } else {
  62. $newtext = PMA_substr($buffer, $options[0]);
  63. }
  64. $length = strlen($newtext);
  65. $baselength = strlen($buffer);
  66. if ($length != $baselength) {
  67. if ($options[0] != 0) {
  68. $newtext = $options[2] . $newtext;
  69. }
  70. if (($length + $options[0]) != $baselength) {
  71. $newtext .= $options[2];
  72. }
  73. }
  74. return htmlspecialchars($newtext);
  75. }
  76. /**
  77. * This method is called when any PluginManager to which the observer
  78. * is attached calls PluginManager::notify()
  79. *
  80. * @param SplSubject $subject The PluginManager notifying the observer
  81. * of an update.
  82. *
  83. * @todo implement
  84. * @return void
  85. */
  86. public function update (SplSubject $subject)
  87. {
  88. ;
  89. }
  90. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  91. /**
  92. * Gets the transformation name of the specific plugin
  93. *
  94. * @return string
  95. */
  96. public static function getName()
  97. {
  98. return "Substring";
  99. }
  100. }
  101. ?>