[ Index ]

MailPress 7.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/options/ip/providers/ -> ipapi.php (source)

   1  <?php
   2  class MP_Ip_ipapi extends MP_ip_provider_
   3  {
   4      var $id     = 'ipapi';
   5      var $url    = 'https://ipapi.co/%1$s/xml/';
   6      var $credit = 'https://ipapi.co';
   7      var $type     = 'xml';
   8  
   9  	function content( $valid, $content )
  10      {
  11          if ( strpos( $content, '<error>True</error>' ) == true ) return false;
  12          return $valid;
  13      }
  14  
  15  	function data( $content, $ip )
  16      {
  17          $skip = array( 'ip', 'continent_code', 'in_eu', 'timezone', 'utc_offset', 'country_calling_code' );
  18          $html = '';
  19  
  20          $xml = $this->xml2array( $content );
  21          foreach ( $xml as $k => $v )
  22          {
  23              if ( empty( $v ) )   continue;
  24              if ( $v == 'NA' ) continue;
  25  
  26              if ( in_array( $k, $skip ) ) continue;
  27  
  28              if ( in_array( $k, array( 'country', 'region_code', 'latitude', 'longitude' ) ) ) {$$k = $v; continue;}
  29  
  30              $html .= '<p style="margin:3px;"><b>' . $k . '</b> : ' . $v . '</p>';
  31          }
  32          $geo = ( isset( $latitude ) && isset( $longitude ) ) ? array( 'lat' => $latitude, 'lng' => $longitude ) : array();
  33          $country = ( isset( $country ) ) ? strtoupper( substr( $country, 0, 2 ) ) : '';
  34          if ( 'US' == $country )
  35          {
  36              $region_code = ( isset( $region_code ) ) ? $region_code : MP_Ip::get_USstate( $ip );
  37          }
  38          else $region_code = MP_Ip::no_state;
  39          $region =  ( isset( $region_code  ) ) ? $region_code : '';
  40          return $this->cache_custom( $ip, $geo, $country, $region_code, $html );
  41      }
  42  }
  43  new MP_Ip_ipapi();


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1