SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/ColModifierHexIP.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. /**
  17. * Converts a hex-packed IP back into readable form
  18. *
  19. * Packing:
  20. * bin2hex(inet_pton($ip))
  21. *
  22. * Unpacking:
  23. * Use this ColModifier
  24. **/
  25. class ColModifierHexIP extends ColModifier
  26. {
  27.  
  28. /**
  29.   * Modify a column value
  30.   * This value will be html/csv/etc encoded afterwards.
  31.   *
  32.   * @param string $val The incoming value
  33.   * @param string $field_name The name of the field being modified
  34.   * @return string The modified value
  35.   **/
  36. public function modify($val, $field_name)
  37. {
  38. if ($val == '') return '';
  39. return inet_ntop(pack("H*" , $val));
  40. }
  41.  
  42. }
  43.  
  44.  
  45.