]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/geocode.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / actions / geocode.php
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
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Geocode action class
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Craig Andrews <candrews@integralblue.com>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  */
43 class GeocodeAction extends Action
44 {
45     var $lat = null;
46     var $lon = null;
47     var $location = null;
48
49     function prepare($args)
50     {
51         parent::prepare($args);
52         $token = $this->trimmed('token');
53         if (!$token || $token != common_session_token()) {
54             $this->clientError(_('There was a problem with your session token. '.
55                                  'Try again, please.'));
56         }
57         $this->lat = $this->trimmed('lat');
58         $this->lon = $this->trimmed('lon');
59         $this->location = Location::fromLatLon($this->lat, $this->lon);
60         return true;
61     }
62
63     /**
64      * Class handler
65      *
66      * @param array $args query arguments
67      *
68      * @return nothing
69      *
70      **/
71     function handle($args)
72     {
73         header('Content-Type: application/json; charset=utf-8');
74         $location_object = array();
75         $location_object['lat']=$this->lat;
76         $location_object['lon']=$this->lon;
77         if($this->location) {
78             $location_object['location_id']=$this->location->location_id;
79             $location_object['location_ns']=$this->location->location_ns;
80             $location_object['name']=$this->location->getName();
81             $location_object['url']=$this->location->getUrl();
82         }
83         print(json_encode($location_object));
84     }
85
86     /**
87      * Is this action read-only?
88      *
89      * @return boolean true
90      */
91
92     function isReadOnly($args)
93     {
94         return true;
95     }
96 }