LongToIPv4TransformationsPlugin.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Abstract class for the long to IPv4 transformations plugins
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage LongToIPv4
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Abs;
  10. use PhpMyAdmin\Plugins\TransformationsPlugin;
  11. use PhpMyAdmin\Util;
  12. /**
  13. * Provides common methods for all of the long to IPv4 transformations plugins.
  14. *
  15. * @package PhpMyAdmin
  16. */
  17. abstract class LongToIPv4TransformationsPlugin extends TransformationsPlugin
  18. {
  19. /**
  20. * Gets the transformation description of the specific plugin
  21. *
  22. * @return string
  23. */
  24. public static function getInfo()
  25. {
  26. return __(
  27. 'Converts an (IPv4) Internet network address stored as a BIGINT'
  28. . ' into a string in Internet standard dotted format.'
  29. );
  30. }
  31. /**
  32. * Does the actual work of each specific transformations plugin.
  33. *
  34. * @param string $buffer text to be transformed
  35. * @param array $options transformation options
  36. * @param string $meta meta information
  37. *
  38. * @return string
  39. */
  40. public function applyTransformation($buffer, array $options = array(), $meta = '')
  41. {
  42. if (! Util::isInteger($buffer) || $buffer < 0 || $buffer > 4294967295) {
  43. return htmlspecialchars($buffer);
  44. }
  45. return long2ip((int) $buffer);
  46. }
  47. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  48. /**
  49. * Gets the transformation name of the specific plugin
  50. *
  51. * @return string
  52. */
  53. public static function getName()
  54. {
  55. return "Long To IPv4";
  56. }
  57. }