Example #1
0
 /**
  * Get coords by user IP
  * @return type
  */
 public function ajaxGetCoordsByIp()
 {
     $objResponse = new JAXResponse();
     $config = CFactory::getConfig();
     $curl = new CCurl();
     /* Because this function is called by ajax. We can't detect real vistor IP in this function than we need to get it from session */
     $ip = JFactory::getSession()->get('jomsocial_userip');
     /**
      * We do request to 3rd service with our IP to get coords than return ajax to update current coords
      * We can use many method here to get fews of coords. Just update it into our javascript
      * @todo We can allow extend via addon files ?
      */
     /**
      * @url http://www.ipinfodb.com/ip_location_api.php
      */
     $ipinfodbAPIKey = $config->get('geolocation_ipinfodb_key', '40955706fc1ec858891c0a7e1c76672d02c766cf7cee9b3e3bf00bcb1575d252');
     $ipinfodbRequestUrl = 'http://api.ipinfodb.com/v3/ip-city/?key=' . $ipinfodbAPIKey . '&format=json';
     if ($ip) {
         $ipinfodbRequestUrl .= '&ip=' . $ip;
     }
     $response = $curl->post($ipinfodbRequestUrl);
     $body = $response->getBody();
     if ($body) {
         $body = json_decode($body);
         /* We'll response data as much as we have */
         if ($body->latitude != 0 && $body->longitude != 0) {
             $coords['coords'] = $body;
             $objResponse->addScriptCall('joms.location.updateCoords', $coords);
         }
     }
     return $objResponse->sendResponse();
 }