forked from geokrety/geokrety-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.php
269 lines (203 loc) · 20.2 KB
/
api.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?php
require_once '__sentry.php';
$smarty_cache_this_page = 0; // this page should be cached for n seconds
require_once 'smarty_start.php';
$TYTUL = _('GK XML interface');
$one_hour_before = date('YmdHis', time() - (1 * 60 * 60));
$TRESC = '
Jump to: <a href="#read">Read</a> | <a href="#write">Write</a>
<h1>Read</h1>
<h2>General</h2>
<h3>Logtypes (state)</h3>
0 = Dropped to;
1 = Grabbed from;
2 = A comment;
3 = Seen in;
4 = Archived;
5 = Visiting;
<h3>GK Types (type)</h3>
0 = Traditional;
1 = A book/CD/DVD...;
2 = A human;
3 = A coin;
4 = KretyPost;
<h3>Reference number and id conversion</h3>
<div style="background: #f0f0f0; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">
$id=hexdec(substr($gk, 2, 4));
$gk=sprintf("GK%04X",$id);
</pre></div>
<h2>Database synchronising</h2>
<p>This can be used to synchronize your database with GK database - useful for OpenCaching and other geocaching projects as well as for other purposes ;) <u>Please note, all opencaching sites should be using Method 2!</u></p>
<p><b>Note:</b> export*.php has a limit of retrieved data set at 10 days (ie you can download data changed in the past 10 days only). This should be enough to sync local OC nodes or other databases. To get older data check: <a href="https://cdn.geokrety.org/exports/">here</a>.</p>
<h3>Method 1: All GeoKrety & logs information (slow and large volume of data)</h3>
To get list of GK created after the date and moves registered after the date:<br />
'.$config['adres'].'export.php?modifiedsince=20090901000000
<p>Sample output (without headers):</p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #507090"><?xml version="1.0" encoding="UTF-8" standalone="yes" ?></span>
<span style="color: #007000"><gkxml</span> <span style="color: #0000C0">version=</span><span style="background-color: #fff0f0">"1.0"</span> <span style="color: #0000C0">date=</span><span style="background-color: #fff0f0">"2013-01-05 13:00:49"</span><span style="color: #007000">></span>
<span style="color: #007000"><geokret</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"6664"</span><span style="color: #007000">></span>
<span style="color: #007000"><name></span><span style="color: #507090"><![CDATA[Piramidy]]></span><span style="color: #007000"></name></span>
<span style="color: #007000"><description></span><span style="color: #507090"><![CDATA[by Terry Pratchett]]></span><span style="color: #007000"></description></span>
<span style="color: #007000"><owner</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"3807"</span><span style="color: #007000">></span><span style="color: #507090"><![CDATA[meteor2017]]></span><span style="color: #007000"></owner></span>
<span style="color: #007000"><datecreated></span>2010-01-17 17:43:50<span style="color: #007000"></datecreated></span>
<span style="color: #007000"><distancetravelled></span>408<span style="color: #007000"></distancetravelled></span>
<span style="color: #007000"><state></span>0<span style="color: #007000"></state></span>
<span style="color: #007000"><missing></span>0<span style="color: #007000"></missing></span>
<span style="color: #007000"><position</span> <span style="color: #0000C0">latitude=</span><span style="background-color: #fff0f0">"49.48972"</span> <span style="color: #0000C0">longitude=</span><span style="background-color: #fff0f0">"18.96848"</span> <span style="color: #007000">/></span>
<span style="color: #007000"><waypoints></span>
<span style="color: #007000"><waypoint></span><span style="color: #507090"><![CDATA[OP41A1]]></span><span style="color: #007000"></waypoint></span>
<span style="color: #007000"></waypoints></span>
<span style="color: #007000"><type</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"1"</span><span style="color: #007000">></span><span style="color: #507090"><![CDATA[A book/CD/DVD...]]></span><span style="color: #007000"></type></span>
<span style="color: #007000"></geokret></span>
<span style="color: #007000"><moves</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"284778"</span><span style="color: #007000">></span>
<span style="color: #007000"><geokret</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"28328"</span><span style="color: #007000">></span><span style="color: #507090"><![CDATA[Indián 2]]></span><span style="color: #007000"></geokret></span>
<span style="color: #007000"><position</span> <span style="color: #0000C0">latitude=</span><span style="background-color: #fff0f0">"50.33383"</span> <span style="color: #0000C0">longitude=</span><span style="background-color: #fff0f0">"13.51802"</span> <span style="color: #007000">/></span>
<span style="color: #007000"><waypoints></span>
<span style="color: #007000"><waypoint></span><span style="color: #507090"><![CDATA[GC1W85C]]></span><span style="color: #007000"></waypoint></span>
<span style="color: #007000"></waypoints></span>
<span style="color: #007000"><date</span> <span style="color: #0000C0">moved=</span><span style="background-color: #fff0f0">"2013-01-05 12:00:00"</span> <span style="color: #0000C0">logged=</span><span style="background-color: #fff0f0">"2013-01-05 12:48:01"</span> <span style="color: #007000">/></span>
<span style="color: #007000"><user</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"17715"</span><span style="color: #007000">></span><span style="color: #507090"><![CDATA[sacreecoeur]]></span><span style="color: #007000"></user></span>
<span style="color: #007000"><comment></span><span style="color: #507090"><![CDATA[Moje první GeoKrety]]></span><span style="color: #007000"></comment></span>
<span style="color: #007000"><logtype</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"0"</span><span style="color: #007000">></span><span style="color: #507090"><![CDATA[Dropped to]]></span><span style="color: #007000"></logtype></span>
<span style="color: #007000"></moves></span>
<span style="color: #007000"></gkxml></span>
</pre></div>
<h3>Method 2: Only GeoKrety information (fast, only most important data; designed for OC sites)</h3>
To get list of GK that changed location during last hour: '.$config['adres'].'export_oc.php?modifiedsince='.$one_hour_before.'<br/>
<p>State field may have different value than in other versions of export scripts. This is because OC sites only need to know if a geokret is in a cache or in the hands of some geocacher. So if someone dips a geokret, its state will be 1 (grabbed).</p>
<p><b>Note:</b> export*.php has a limit of retrieved data set at 10 days (ie you can download data changed in the past 10 days only). This should be enough to sync local OC nodes or other databases. To get older data check: <a href="https://cdn.geokrety.org/exports/">here</a>.</p>
<p>Sample output:</p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #007000"><geokret</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"4849"</span><span style="color: #007000">></span>
<span style="color: #007000"><name></span><span style="color: #507090"><![CDATA[B&B's Dragonfly]]></span><span style="color: #007000"></name></span>
<span style="color: #007000"><distancetravelled></span>1959<span style="color: #007000"></distancetravelled></span>
<span style="color: #007000"><state></span>0<span style="color: #007000"></state></span>
<span style="color: #007000"><position</span> <span style="color: #0000C0">latitude=</span><span style="background-color: #fff0f0">"53.73917"</span> <span style="color: #0000C0">longitude=</span><span style="background-color: #fff0f0">"17.40568"</span> <span style="color: #007000">/></span>
<span style="color: #007000"><waypoints></span>
<span style="color: #007000"><waypoint></span><span style="color: #507090"><![CDATA[OP1003]]></span><span style="color: #007000"></waypoint></span>
<span style="color: #007000"></waypoints></span>
<span style="color: #007000"></geokret></span>
<span style="color: #007000"><geokret</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"3249"</span><span style="color: #007000">></span>
<span style="color: #007000"><name></span><span style="color: #507090"><![CDATA[Geokretynka]]></span><span style="color: #007000"></name></span>
<span style="color: #007000"><distancetravelled></span>113<span style="color: #007000"></distancetravelled></span>
<span style="color: #007000"><state></span>1<span style="color: #007000"></state></span>
<span style="color: #007000"><position</span> <span style="color: #0000C0">latitude=</span><span style="background-color: #fff0f0">"0.00000"</span> <span style="color: #0000C0">longitude=</span><span style="background-color: #fff0f0">"0.00000"</span> <span style="color: #007000">/></span>
<span style="color: #007000"><waypoints></span>
<span style="color: #007000"><waypoint></span><span style="color: #507090"><![CDATA[]]></span><span style="color: #007000"></waypoint></span>
<span style="color: #007000"></waypoints></span>
<span style="color: #007000"></geokret></span>
</pre></div>
<h2>Retriving information</h2>
<p><b>Note:</b> export*.php has a limit of retrieved data set at 10 days (ie you can download data changed in the past 10 days only). This should be enough to sync local OC nodes or other databases. To get older data check: <a href="https://cdn.geokrety.org/exports/">here</a>.</p>
<p><b><u>'.$config['adres'].'export2.php</b></u></p>
<p>sample output:</p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #507090"><?xml version="1.0" encoding="UTF-8" standalone="yes" ?></span>
<span style="color: #007000"><gkxml</span> <span style="color: #0000C0">version=</span><span style="background-color: #fff0f0">"1.0"</span> <span style="color: #0000C0">date=</span><span style="background-color: #fff0f0">"2010-12-09 19:10:03"</span><span style="color: #007000">></span>
<span style="color: #007000"><geokrety></span>
<span style="color: #007000"><geokret</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"8143"</span> <span style="color: #0000C0">dist=</span><span style="background-color: #fff0f0">"251"</span> <span style="color: #0000C0">lat=</span><span style="background-color: #fff0f0">"53.14598"</span> <span style="color: #0000C0">lon=</span><span style="background-color: #fff0f0">"23.18567"</span>
<span style="color: #0000C0">waypoint=</span><span style="background-color: #fff0f0">"OP2FD9"</span> <span style="color: #0000C0">owner_id=</span><span style="background-color: #fff0f0">"3813"</span> <span style="color: #0000C0">state=</span><span style="background-color: #fff0f0">"0"</span> <span style="color: #0000C0">type=</span><span style="background-color: #fff0f0">"0"</span>
<span style="color: #0000CC">last_pos_id=</span><span style="background-color: #fff0f0">"11536"</span> <span style="color: #0000CC">last_log_id=</span><span style="background-color: #fff0f0">"11553"</span>
<span style="color: #0000C0">image=</span><span style="background-color: #fff0f0">"1273660644jr8sm.jpg"</span><span style="color: #007000">></span>
<span style="color: #507090"><![CDATA[Wiewireczka]]></span>
<span style="color: #007000"></geokret></span>
<span style="color: #007000"></geokrety></span>
<span style="color: #007000"></gkxml></span>
</pre></div>
last_pos_id - id of the last position (waypoint); last_log_id - id of the last log (may be a waypoint, comment etc)
<h3>General purpose swiches:</h3>
<ul>
<li>modifiedsince*; list of GK with the timestamp of the last move >modifiedsince; (required for some queries) example:<br />
'.$config['adres'].'export2.php?modifiedsince=20100901000000</li>
<li>swiches defining the area of places, where GK are:<br />
latNE latSW lonNE lonSW; example:<br />
'.$config['adres'].'export2.php?latNE=50&latSW=40&lonNE=50&lonSW=0</li>
<li>userid; lists GK owned by userid; example:<br />
'.$config['adres'].'export2.php?userid=1</li>
<li>gkid: lists only one GK, example:<br />
'.$config['adres'].'export2.php?gkid=141</li>
<li>wpt: lists GK which are in the cache with specified waypoint, eg:<br />
'.$config['adres'].'export2.php?wpt=op05e5<br />
it can be used to show GK in caches with defined waypoint\'s prefix; eg
to show all GK in romanian caches (prefix GR), just enter:<br />
'.$config['adres'].'export2.php?wpt=gr</li>
</ul>
<p>Above swiches can be mixed. Eg to list my (ownerid=1) geokrets
which are in GC caches, just enter:<br />
'.$config['adres'].'export2.php?userid=1&wpt=gc
</p>
<h3>Retriving user\'s inventory:</h3>
<p><ul>
<li>userid and inventory=1: list GKs in user\'s inventory, eg:<br />
'.$config['adres'].'export2.php?userid=1&inventory=1</li>
<li>the same but with secid user\'s identification:<br />
'.$config['adres'].'export2.php?secid=....&inventory=1<br />
this request returns also the secret tracking codes (the <b>nr</b> variable) for all geokrets in user\'s inventory</li>
</ul></p>
<h3>Compressing output</h3>
<ul>
<li>adding <b>gzip=1</b> swich makes output is compressed with gzip (gzencode), eg:<br />
'.$config['adres'].'export2.php?userid=1&inventory=1&gzip=1
</li>
</ul>
<a id="write"></a><h1>Write</h1>
<p><b>this part of API is highly experimental!</b></p>
<p><b>(1) secid</b></p> <p>Logging of geokrety is possible by passing to appropriate script variable <b>secid</b> via POST method. The <b>secid</b> is 128 characters long string, unique for all users (it should be kept secret like a password). The <b>secid</b> can be obtained by passing variables <b>login</b> and <b>password</b> to the script:</p>
<p>'.$config['adres'].'api-login2secid.php</p>
<p>via POST method. If correct login credentials are supplied, the <b>secid</b> is returned.</p>
<p><b>(2) logging</b></p>
<p>To log a geokret, you have to pass to the <b><a href="'.$config['adres'].'ruchy.php">'.$config['adres'].'ruchy.php</a></b> script the <b>secid</b> as well as other data you normally pass via form:</p>
<table>
<tr><th>variable</th><th>description</th><th>example</th></tr>
<tr><td><b>secid</b></td><td>authentication string - see above</td><td></td></tr>
<tr><td><b>nr</b></td><td>geokret\'s tracking code</td><td>GH68MA</td></tr>
<tr><td><b>formname = \'ruchy\'</b></td> <td>(must be set this way)</td><td>ruchy</td></tr>
<tr><td><b>logtype</b></td><td>see <i>logtypes</i>on the top of this document</td><td>0</td></tr>
<tr><td><b>data</b></td><td>the log date YYYY-MM-DD</td><td>2012-12-15</td></tr>
<tr><td><b>godzina</b></td><td>hour HH</td><td>15</td></tr>
<tr><td><b>minuta</b></td><td>minutes MM</td><td>23</td></tr>
<tr><td><b>comment</b></td><td>(<i>optional</i>) comment to the log</td><td>It is a good place for this geokret!</td></tr>
<tr><td><b>app</b></td><td>(<i>optional</i>) application name, <=16 chars</td><td>Locus</td></tr>
<tr><td><b>app_ver</b></td><td>(<i>optional</i>) application version, <=16 chars</td><td>1.16dev</td></tr>
<tr><td><b>mobile_lang</b></td><td><i>(optional)</i> error messages language;<br />for list of avaliable languages <a href="/rzeczy/lang/">see here</a></td><td>pl_PL.UTF-8</td></tr>
<tr><td><b></b></td><td></td><td></td></tr>
</table>
<p>The new position of geokret should be set by one of the following variables:</p>
<table>
<tr><th>variable</th><th>description</th><th>example</th></tr>
<tr><td><b>latlon</b></td><td>latitude and longitude (<a href="/help.php#acceptableformats">various formats acceptable</a>)</td><td>52.1534 21.0539</td></tr>
<tr><td><b>wpt</b></td><td>waypoint</td><td>OP05E5</td></tr>
</table>
<p>All those via POST method. After successful logging the geokret, the xml is returned, like <a href="'.$config['adres'].'export2.php?gkid=29001">in this example</a>.</p>
<p>After <b>successful</b> data submission the "no errors" code is returned along with gk number:</p>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #507090"><?xml version="1.0" ?></span>
<span style="color: #007000"><gkxml</span> <span style="color: #0000C0">version=</span><span style="background-color: #fff0f0">"1.0"</span> <span style="color: #0000C0">date=</span><span style="background-color: #fff0f0">"2013-01-03 21:29:11"</span><span style="color: #007000">></span>
<span style="color: #007000"><errors></span>
<span style="color: #007000"><error></error></span>
<span style="color: #007000"></errors></span>
<span style="color: #007000"><geokrety></span>
<span style="color: #007000"><geokret</span> <span style="color: #0000C0">id=</span><span style="background-color: #fff0f0">"27334"</span><span style="color: #007000">/></span>
<span style="color: #007000"></geokrety></span>
<span style="color: #007000"></gkxml></span>
</pre></div>
<p>If <b>errors</b> occurs, the XML error list is returned in the defined language, eg:
<pre>
<div style="background: #ffffff; overflow:auto;width:auto;color:black;background:white;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #507090"><?xml version="1.0" ?></span>
<span style="color: #007000"><gkxml</span> <span style="color: #0000C0">version=</span><span style="background-color: #fff0f0">"1.0"</span> <span style="color: #0000C0">date=</span><span style="background-color: #fff0f0">"2013-01-03 21:13:51"</span><span style="color: #007000">></span>
<span style="color: #007000"><errors></span>
<span style="color: #007000"><error></span>Wrong secid<span style="color: #007000"></error></span>
<span style="color: #007000"><error></span>Wrond date or time<span style="color: #007000"></error></span>
<span style="color: #007000"></errors></span>
<span style="color: #007000"></gkxml></span>
</pre></div>
</pre>
</p>
<p>If you provide an <b>app</b> name, it would be nice to send us an application icon (16x16, png, eg <img src="'.CONFIG_CDN_IMAGES.'/api/icons/16/Opencaching.png" alt="app icon" />), that we could add short info about application in the log entry.</p>
<p>If you have any idea, how to improve this API or any function-request, feel free to <a href="kontakt.php">contact us</a>!</p>
<h3>Sample scripts</h3>
<p>Here are sample scripts for using GK api</p>
<ul>
<li><a href="https://gist.github.com/filipsPL/d5a1b191a69ea6775ba2">pyGK (python)</a></li>
<li>phpGK (php)</li>
</ul>
';
// --------------------------------------------------------------- SMARTY ---------------------------------------- //
require_once 'smarty.php';