[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  if ( defined('MP_Ip_ipinfodb_ApiKey') )
   3  {
   4  class MP_Ip_ipinfodb extends MP_ip_provider_
   5  {
   6      var $id     = 'ipinfodb';
   7      var $url    = 'http://api.ipinfodb.com/v3/ip-city/?ip=%1$s&key=%2$s&format=xml';
   8      var $credit    = 'http://ipinfodb.com/';
   9      var $type     = 'xml';
  10  
  11  	function content($valid, $content)
  12      {
  13          if (!strpos($content, '<statusCode>OK</statusCode>')) return false;
  14          if (strpos($content, '<latitude>0</latitude>') && strpos($content, '<longitude>0</longitude>')) return false;
  15          return $valid;
  16      }
  17  
  18  	function url($arg)
  19      {
  20          $arg[] = MP_Ip_ipinfodb_ApiKey;
  21          return $arg;
  22      }
  23  
  24  	function data($content, $ip)
  25      {
  26          $skip = array('statusCode', 'statusMessage', 'ipAddress', 'zipCode');
  27          $html = '';
  28  
  29          $xml = $this->xml2array( $content );
  30          foreach ($xml as $k => $v)
  31          {
  32              if ($v == 'n/a') continue;
  33              if (empty($v))   continue;
  34  
  35              if (in_array($k, $skip)) continue;
  36  
  37              if (in_array($k, array('countryCode', 'latitude', 'longitude'))) {$$k = $v; continue;}
  38  
  39              $html .= "<p style='margin:3px;'><b>$k</b> : $v</p>";
  40          }
  41          $geo = (isset($latitude) && isset($longitude)) ? array('lat' => $latitude, 'lng' => $longitude) : array();
  42          $country = (isset($countryCode)) ? $countryCode : '';
  43          $subcountry = ('US' == strtoupper($country)) ? MP_Ip::get_USstate($ip) : MP_Ip::no_state;
  44          return $this->cache_custom($ip, $geo, strtoupper(substr($country, 0, 2)), strtoupper($subcountry), $html);
  45      }
  46  }
  47  new MP_Ip_ipinfodb();
  48  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1