1
0

BxMapShowModule.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup MapShow Display last sign up users on map
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_MAP_SHOW_IP_2_LOCATION_URL', 'https://freegeoip.app/json/');
  12. class BxMapShowModule extends BxDolModule
  13. {
  14. function __construct(&$aModule)
  15. {
  16. parent::__construct($aModule);
  17. }
  18. public function addIpInfoToDb($iAccountId, $sIp)
  19. {
  20. $sLngLatInfo = $this->callApi($sIp);
  21. if ($sLngLatInfo != ''){
  22. $oLngLatInfo = json_decode($sLngLatInfo);
  23. if (isset($oLngLatInfo->longitude) && isset($oLngLatInfo->latitude)){
  24. $sLng = $oLngLatInfo->longitude;
  25. $sLat = $oLngLatInfo->latitude;
  26. if ($sLng != "0" && $sLat != "0")
  27. $this->_oDb->addIpInfo($iAccountId, $sIp, $sLng, $sLat);
  28. }
  29. }
  30. }
  31. /**
  32. * @page service Service Calls
  33. * @section bx_mapshow MapShow
  34. * @subsection bx_mapshow-other Other
  35. * @subsubsection bx_mapshow-get_map
  36. *
  37. * @code bx_srv('bx_mapshow', 'get_map', [...]); @endcode
  38. *
  39. * Get html for map
  40. *
  41. * @return string - html for map .
  42. *
  43. * @see BxMapShowModule::serviceGetMap
  44. */
  45. /**
  46. * @ref bx_mapshow-get_map "get_map"
  47. */
  48. public function serviceGetMap()
  49. {
  50. return $this->_oTemplate->getMap();
  51. }
  52. public function actionGetMapPoints($Id = 0)
  53. {
  54. $aData = $this->_oDb->getLngLatData($Id);
  55. header('Content-Type: application/json');
  56. echo json_encode($aData);
  57. }
  58. private function callApi($sIp)
  59. {
  60. $sApiUrl = BX_MAP_SHOW_IP_2_LOCATION_URL . $sIp;
  61. return bx_file_get_contents($sApiUrl);
  62. }
  63. }
  64. /** @} */