~ubuntu-fr-webteam/ubuntu-fr-map/trunk

« back to all changes in this revision

Viewing changes to api.php

  • Committer: root
  • Date: 2011-07-30 19:01:24 UTC
  • Revision ID: root@ubuntu-fr.kofuke.org-20110730190124-gqz34e0becpzw2eb
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * Copyright (C) 2010 Thomas Cort <linuxgeek@gmail.com>
 
4
 *
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted (subject to the limitations in the
 
9
 * disclaimer below) provided that the following conditions are met:
 
10
 *
 
11
 *  * Redistributions of source code must retain the above copyright
 
12
 *    notice, this list of conditions and the following disclaimer.
 
13
 *
 
14
 *  * Redistributions in binary form must reproduce the above copyright
 
15
 *    notice, this list of conditions and the following disclaimer in the
 
16
 *    documentation and/or other materials provided with the
 
17
 *    distribution.
 
18
 *
 
19
 *  * Neither the name of Thomas Cort nor the names of its
 
20
 *    contributors may be used to endorse or promote products derived
 
21
 *    from this software without specific prior written permission.
 
22
 *
 
23
 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
 
24
 * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
 
25
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 
26
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
27
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
28
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 
29
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
30
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
31
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 
32
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
33
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
34
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 
35
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
36
 */
 
37
 
 
38
// UTF-8 enable this script
 
39
mb_language('uni');
 
40
mb_internal_encoding('UTF-8');
 
41
 
 
42
require_once('config.php');
 
43
require_once('classes/NoCache.php');
 
44
require_once('classes/FileCache.php');
 
45
require_once('classes/MySQLDatabase.php');
 
46
require_once('classes/POIManager.php');
 
47
 
 
48
if (strcmp($_REQUEST["action"], "getPOI") == 0) {
 
49
 
 
50
        // Input parameters
 
51
        $tllon = $_REQUEST["tllon"];
 
52
        $tllat = $_REQUEST["tllat"];
 
53
        $brlon = $_REQUEST["brlon"];
 
54
        $brlat = $_REQUEST["brlat"];
 
55
        $zoom  = $_REQUEST["zoom"];
 
56
 
 
57
        // Validate the input parameters
 
58
        if (is_numeric($tllon) && -180.0 <= $tllon && $tllon < 180.0 && is_numeric($tllat) && -90.0 <= $tllat && $tllat <= 90.0 && is_numeric($brlon) && -180.0 <= $brlon && $brlon < 180.0 && is_numeric($brlat) && -90.0 <= $brlat && $brlat <= 90.0 && is_numeric($zoom) && $zoom >= 0 && $zoom < 20) {
 
59
                $min_lat = ($tllat < $brlat) ? $tllat : $brlat;
 
60
                $max_lat = ($tllat > $brlat) ? $tllat : $brlat;
 
61
                $min_lon = ($tllon < $brlon) ? $tllon : $brlon;
 
62
                $max_lon = ($tllon > $brlon) ? $tllon : $brlon;
 
63
 
 
64
                $key = "poi_" . $min_lat . "_" . $max_lat . "_" . $min_lon . "_" . $max_lon . "_" . $zoom;
 
65
 
 
66
                if (strcmp($cache_type,"FileCache") == 0) { 
 
67
                        $cache = new FileCache();
 
68
                } else {
 
69
                        $cache = new NoCache();
 
70
                }
 
71
 
 
72
                $xml = $cache->get($key);
 
73
                if ($xml == FALSE) {
 
74
                        $db = new MySQLDatabase($hostname, $database, $username, $password);
 
75
                        $db->connect();
 
76
                        $poi = new POIManager($db);
 
77
                        $gpx = $poi->getWpts($min_lat, $max_lat, $min_lon, $max_lon, $zoom);
 
78
                        $xml = $gpx->toXml();
 
79
                        $db->disconnect();
 
80
 
 
81
                        $cache->put($key,$xml);
 
82
                }
 
83
 
 
84
                header("Content-type: text/xml; charset=utf-8");
 
85
                print $xml;
 
86
        } else {
 
87
                header("Content-type: text/plain; charset=utf-8");
 
88
                print "Invalid Input";
 
89
        }
 
90
} else {
 
91
        header("Content-type: text/plain; charset=utf-8");
 
92
        print "Unsupported Action";
 
93
}
 
94
 
 
95
?>