geocode.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Geocode action class
  4. *
  5. * PHP version 5
  6. *
  7. * @category Action
  8. * @package StatusNet
  9. * @author Craig Andrews <candrews@integralblue.com>
  10. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  11. * @link http://status.net/
  12. *
  13. * StatusNet - the distributed open-source microblogging tool
  14. * Copyright (C) 2008, 2009, StatusNet, Inc.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. if (!defined('STATUSNET') && !defined('LACONICA')) {
  30. exit(1);
  31. }
  32. /**
  33. * Geocode action class
  34. *
  35. * @category Action
  36. * @package StatusNet
  37. * @author Craig Andrews <candrews@integralblue.com>
  38. * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  39. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  40. * @link http://status.net/
  41. */
  42. class GeocodeAction extends Action
  43. {
  44. var $lat = null;
  45. var $lon = null;
  46. var $location = null;
  47. function prepare(array $args = array())
  48. {
  49. parent::prepare($args);
  50. $token = $this->trimmed('token');
  51. if (!$token || $token != common_session_token()) {
  52. // TRANS: Client error displayed when the session token does not match or is not given.
  53. $this->clientError(_('There was a problem with your session token. '.
  54. 'Try again, please.'));
  55. }
  56. $this->lat = $this->trimmed('lat');
  57. $this->lon = $this->trimmed('lon');
  58. $this->location = Location::fromLatLon($this->lat, $this->lon);
  59. return true;
  60. }
  61. /**
  62. * Class handler
  63. *
  64. * @param array $args query arguments
  65. *
  66. * @return nothing
  67. *
  68. */
  69. function handle()
  70. {
  71. header('Content-Type: application/json; charset=utf-8');
  72. $location_object = array();
  73. $location_object['lat']=$this->lat;
  74. $location_object['lon']=$this->lon;
  75. if($this->location) {
  76. $location_object['location_id']=$this->location->location_id;
  77. $location_object['location_ns']=$this->location->location_ns;
  78. $location_object['name']=$this->location->getName();
  79. $location_object['url']=$this->location->getUrl();
  80. }
  81. print(json_encode($location_object));
  82. }
  83. /**
  84. * Is this action read-only?
  85. *
  86. * @return boolean true
  87. */
  88. function isReadOnly($args)
  89. {
  90. return true;
  91. }
  92. }