Text_Plain_Binarytoip.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Handles the binary to IPv4/IPv6 transformation for text plain
  5. *
  6. * @package PhpMyAdmin-Transformations
  7. * @subpackage BinaryToIP
  8. */
  9. namespace PhpMyAdmin\Plugins\Transformations\Output;
  10. use PhpMyAdmin\Plugins\TransformationsPlugin;
  11. /**
  12. * Handles the binary to IPv4/IPv6 transformation for text plain
  13. *
  14. * @package PhpMyAdmin-Transformations
  15. * @subpackage BinaryToIP
  16. */
  17. // @codingStandardsIgnoreLine
  18. class Text_Plain_Binarytoip extends TransformationsPlugin
  19. {
  20. /**
  21. * Gets the transformation description of the plugin
  22. *
  23. * @return string
  24. */
  25. public static function getInfo()
  26. {
  27. return __(
  28. 'Converts an Internet network address stored as a binary string'
  29. . ' into a string in Internet standard (IPv4/IPv6) format.'
  30. );
  31. }
  32. /**
  33. * Does the actual work of each specific transformations plugin.
  34. *
  35. * @param string $buffer text to be transformed. a binary string containing
  36. * an IP address, as returned from MySQL's INET6_ATON
  37. * function
  38. * @param array $options transformation options
  39. * @param string $meta meta information
  40. *
  41. * @return string IP address
  42. */
  43. public function applyTransformation($buffer, array $options = array(), $meta = '')
  44. {
  45. $length = strlen($buffer);
  46. if ($length == 4 || $length == 16) {
  47. $val = @inet_ntop(pack('A' . $length, $buffer));
  48. if ($val !== false) {
  49. return $val;
  50. }
  51. }
  52. return $buffer;
  53. }
  54. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  55. /**
  56. * Gets the transformation name of the plugin
  57. *
  58. * @return string
  59. */
  60. public static function getName()
  61. {
  62. return "Binary To IPv4/IPv6";
  63. }
  64. /**
  65. * Gets the plugin`s MIME type
  66. *
  67. * @return string
  68. */
  69. public static function getMIMEType()
  70. {
  71. return "Text";
  72. }
  73. /**
  74. * Gets the plugin`s MIME subtype
  75. *
  76. * @return string
  77. */
  78. public static function getMIMESubtype()
  79. {
  80. return "Plain";
  81. }
  82. }