Text_Plain_Binarytoip.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if (0 !== strpos($buffer, '0x')) {
  46. return $buffer;
  47. }
  48. $ipHex = substr($buffer, 2);
  49. $ipBin = hex2bin($ipHex);
  50. if (false === $ipBin) {
  51. return $buffer;
  52. }
  53. return @inet_ntop($ipBin);
  54. }
  55. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  56. /**
  57. * Gets the transformation name of the plugin
  58. *
  59. * @return string
  60. */
  61. public static function getName()
  62. {
  63. return "Binary To IPv4/IPv6";
  64. }
  65. /**
  66. * Gets the plugin`s MIME type
  67. *
  68. * @return string
  69. */
  70. public static function getMIMEType()
  71. {
  72. return "Text";
  73. }
  74. /**
  75. * Gets the plugin`s MIME subtype
  76. *
  77. * @return string
  78. */
  79. public static function getMIMESubtype()
  80. {
  81. return "Plain";
  82. }
  83. }