SubstringTransformationsPlugin.class.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 string
  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 = $GLOBALS['PMA_String']->substr(
  61. $buffer, $options[0], $options[1]
  62. );
  63. } else {
  64. $newtext = $GLOBALS['PMA_String']->substr($buffer, $options[0]);
  65. }
  66. $length = strlen($newtext);
  67. $baselength = strlen($buffer);
  68. if ($length != $baselength) {
  69. if ($options[0] != 0) {
  70. $newtext = $options[2] . $newtext;
  71. }
  72. if (($length + $options[0]) != $baselength) {
  73. $newtext .= $options[2];
  74. }
  75. }
  76. return $newtext;
  77. }
  78. /**
  79. * This method is called when any PluginManager to which the observer
  80. * is attached calls PluginManager::notify()
  81. *
  82. * @param SplSubject $subject The PluginManager notifying the observer
  83. * of an update.
  84. *
  85. * @todo implement
  86. * @return void
  87. */
  88. public function update (SplSubject $subject)
  89. {
  90. ;
  91. }
  92. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  93. /**
  94. * Gets the transformation name of the specific plugin
  95. *
  96. * @return string
  97. */
  98. public static function getName()
  99. {
  100. return "Substring";
  101. }
  102. }
  103. ?>