-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
144 lines (128 loc) · 3.78 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
//
// produces data in V1 format but from the old GWEM Feed
//
// https://groups.theramblers.org.uk/?v=1&latitude=51.4589653&longitude=-2.52582669&maxpoints=100&dist=30
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('assert.warning', 1);
// Code to
// http://www.ramblers.org.uk/api/lbs/groups/
define("VERSION_NUMBER", "0.0.1");
define("GROUPFILEV1", "cache/allgroupsv1.json");
define("GROUPFILEV2", "cache/allgroupsv2.json");
define("V1", "1");
define("V2", "2");
// First Release
if (version_compare(PHP_VERSION, '8.3.0') < 0) {
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode(new Errorreturn("You MUST be running on PHP version 8.3.0 or higher, running version", 500), JSON_PRETTY_PRINT);
return;
}
// set current directory to current run directory
$exepath = dirname(__FILE__);
//echo $exepath;
//define('BASE_PATH', dirname(realpath(dirname(__FILE__))));
define('BASE_PATH', $exepath);
chdir($exepath);
//echo BASE_PATH;
$key = NULL;
require('classes/autoload.php');
spl_autoload_register('autoload');
$opts = new Options();
$no = $opts->noGets();
$version = $opts->gets("v");
$versionSpecified = $version !== null;
if ($versionSpecified) {
$no -= 1;
} else {
$version = V1;
}
if ($version !== V1 && $version !== V2) {
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode(new Errorreturn("Invalid calling sequence", 501), JSON_PRETTY_PRINT);
return;
}
// which group types to return
$types = $opts->gets("types");
if ($types === null) {
$types = "A,G";
} else {
$types = strtoupper($types);
$no -= 1;
}
$groups = new GroupsFile($version, $types);
// return all groups
If ($no === 0) {
// return all groups
$allGroups = $groups->allGroups();
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode($allGroups, JSON_PRETTY_PRINT);
return;
}
// return groups by name search
$search = $opts->gets("search");
if ($search != null) {
// do a name search
$number = $opts->gets("number");
if ($number == null) {
$number = 20;
}
$groups = $groups->search($search, $number);
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode($groups, JSON_PRETTY_PRINT);
return;
}
// return group by group code
$group = $opts->gets("group");
if ($group != null) {
// return single record for one group
$groups = $groups->singleGroup($group);
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode($groups, JSON_PRETTY_PRINT);
return;
}
// return groups by area code
$area = $opts->gets("area");
if ($area != null) {
// return single record for one group
$groups = $groups->areaGroups($area);
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode($groups, JSON_PRETTY_PRINT);
return;
}
// do a location search
$latitude = $opts->gets("latitude");
$longitude = $opts->gets("longitude");
$distance = $opts->gets("dist");
$maxpoints = $opts->gets("maxpoints");
$code = 0;
if ($latitude === null) {
$code = 502;
}
if ($longitude === null) {
$code = 503;
}
if ($distance === null) {
$code = 504;
}
if ($maxpoints === null) {
$code = 505;
}
if ($code > 0) {
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode(new Errorreturn("Invalid calling sequence", $code), JSON_PRETTY_PRINT);
return;
}
$closestGroups = $groups->process($latitude, $longitude, $distance, $maxpoints);
header("Access-Control-Allow-Origin: *");
header("Content-type: application/json");
echo json_encode($closestGroups, JSON_PRETTY_PRINT);
return;