Skip to content

Commit 1d66caa

Browse files
authored
Added the Opencaching GPX extension (#511)
1 parent af0236c commit 1d66caa

File tree

3 files changed

+80
-38
lines changed

3 files changed

+80
-38
lines changed

okapi/services/caches/formatters/gpx/WebService.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,33 @@ public static function options()
2424
);
2525
}
2626

27-
/** Maps OKAPI cache type codes to Geocaching.com GPX cache types. */
28-
public static $cache_GPX_types = array(
29-
'Traditional' => 'Traditional Cache',
30-
'Multi' => 'Multi-Cache',
31-
'Quiz' => 'Unknown Cache',
32-
'Event' => 'Event Cache',
33-
'Virtual' => 'Virtual Cache',
34-
'Webcam' => 'Webcam Cache',
35-
'Moving' => 'Unknown Cache',
36-
'Math/Physics' => 'Unknown Cache',
37-
'Drive-In' => 'Traditional Cache',
38-
'Podcast' => 'Unknown Cache',
39-
'Own' => 'Unknown Cache',
40-
'Other' => 'Unknown Cache'
41-
);
42-
43-
/** Maps OKAPI's 'size2' values to geocaching.com size codes. */
44-
public static $cache_GPX_sizes = array(
45-
'none' => 'Virtual',
46-
'nano' => 'Micro',
47-
'micro' => 'Micro',
48-
'small' => 'Small',
49-
'regular' => 'Regular',
50-
'large' => 'Large',
51-
'xlarge' => 'Large',
52-
'other' => 'Other',
53-
);
27+
/** Maps OKAPI cache type codes to GPX cache types. */
28+
public static $cache_GPX_types = [
29+
'Traditional' => ['oc' => 'Traditional Cache', 'gc' => 'Traditional Cache' ],
30+
'Multi' => ['oc' => 'Multi-Cache', 'gc' => 'Multi-Cache' ],
31+
'Quiz' => ['oc' => 'Quiz Cache', 'gc' => 'Unknown Cache' ],
32+
'Event' => ['oc' => 'Event Cache', 'gc' => 'Event Cache' ],
33+
'Virtual' => ['oc' => 'Virtual Cache', 'gc' => 'Virtual Cache' ],
34+
'Webcam' => ['oc' => 'Webcam Cache', 'gc' => 'Webcam Cache' ],
35+
'Moving' => ['oc' => 'Moving Cache', 'gc' => 'Unknown Cache' ],
36+
'Math/Physics' => ['oc' => 'Quiz Cache', 'gc' => 'Unknown Cache' ],
37+
'Drive-In' => ['oc' => 'Traditional Cache', 'gc' => 'Traditional Cache' ],
38+
'Podcast' => ['oc' => 'Podcast Cache', 'gc' => 'Unknown Cache' ],
39+
'Own' => ['oc' => 'Own Cache', 'gc' => 'Unknown Cache' ],
40+
'Other' => ['oc' => 'Other Cache', 'gc' => 'Unknown Cache' ],
41+
];
42+
43+
/** Maps OKAPI's 'size2' values to GPX size codes. */
44+
public static $cache_GPX_sizes = [
45+
'none' => ['oc' => 'No container', 'gc' => 'Virtual' ],
46+
'nano' => ['oc' => 'Nano', 'gc' => 'Micro' ],
47+
'micro' => ['oc' => 'Micro', 'gc' => 'Micro' ],
48+
'small' => ['oc' => 'Small', 'gc' => 'Small' ],
49+
'regular' => ['oc' => 'Regular', 'gc' => 'Regular' ],
50+
'large' => ['oc' => 'Large', 'gc' => 'Large' ],
51+
'xlarge' => ['oc' => 'Very large', 'gc' => 'Large' ],
52+
'other' => ['oc' => 'Other', 'gc' => 'Other' ],
53+
];
5454

5555
/**
5656
* When used in create_gpx() method, enables GGZ index generation.
@@ -95,7 +95,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
9595
$langpref = $request->get_parameter('langpref');
9696
if (!$langpref) $langpref = "en";
9797
$langprefs = explode("|", $langpref);
98-
foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param)
98+
foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'ns_oc', 'latest_logs', 'alt_wpts', 'mark_found') as $param)
9999
{
100100
$val = $request->get_parameter($param);
101101
if (!$val) $val = "false";
@@ -205,7 +205,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
205205
206206
$fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize'.
207207
'|difficulty|terrain|description|hint2|rating|owner|url|internal_id'.
208-
'|protection_areas|short_description';
208+
'|protection_areas|short_description|trip_time|trip_distance|req_passwd|gc_code';
209209
if ($vars['images'] != 'none')
210210
$fields .= "|images";
211211
if (count($vars['attrs']) > 0)
@@ -233,7 +233,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
233233
'fields' => $fields,
234234
'lpc' => $lpc,
235235
'user_uuid' => $user_uuid,
236-
'log_fields' => 'uuid|date|user|type|comment|internal_id|was_recommended'
236+
'log_fields' => 'uuid|date|user|type|comment|oc_team_entry|internal_id|was_recommended'
237237
)
238238
)
239239
);
@@ -467,7 +467,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
467467

468468
$ggz_entry['code'] = $cache_ref['code'];
469469
$ggz_entry['name'] = isset($cache_ref['name_2']) ? $cache_ref['name_2'] : $cache_ref['name'];
470-
$ggz_entry['type'] = $vars['cache_GPX_types'][$cache_ref['type']];
470+
$ggz_entry['type'] = $vars['cache_GPX_types'][$cache_ref['type']]['gc'];
471471
list($lat, $lon) = explode("|", $cache_ref['location']);
472472
$ggz_entry['lat'] = $lat;
473473
$ggz_entry['lon'] = $lon;

okapi/services/caches/formatters/gpx/docs.xml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,26 @@
2525
order of preference in which language will be chosen for GPX entities.</p>
2626
</opt>
2727
<opt name='ns_ground' default='false'>
28-
Boolean. If <b>true</b> then response will include
28+
Boolean. If <b>true</b> then the response will include
2929
<a href='http://www.groundspeak.com/cache/1/0/1/cache.xsd'>Groundspeak's
3030
GPX extension</a>. This namespace declares an extra &lt;cache&gt; element
3131
used by <a href='https://www.geocaching.com/'>geocaching.com</a> and <b>many others</b>.
3232
This namespace was initially associatied with geocaching.com, but now seems to
3333
be used in every geocaching GPX file. You probably want to have it.
3434
</opt>
35+
<opt name='ns_oc' default='false'>
36+
<p>Boolean. If <b>true</b> then the response will include the
37+
<a href='https://github.com/opencaching/gpx-extension-v1/blob/master/schema.xsd'>
38+
Opencaching GPX extension</a>. The GPX files will contain an additional
39+
&lt;oc:cache&gt; element for each geocache, which contains Opencaching-specific
40+
information about the geocache. If <b>latest_logs</b> is set to <b>true</b>,
41+
then it will also contain Opencaching-specific information about log entries.</p>
42+
43+
<p>The Opencaching GPX extension was introduced by OKAPI and is expected to
44+
be included in most OC sites' native GPX files.</p>
45+
</opt>
3546
<opt name='ns_gsak' default='false'>
36-
<p>Boolean. If <b>true</b> then response will include
47+
<p>Boolean. If <b>true</b> then the response will include
3748
<a href='http://www.gsak.net/xmlv1/5/gsak.xsd'>GSAK GPX extension</a>.
3849
This namespace declares an extra &lt;wptExtension&gt; element,
3950
which allows including "waypoint inheritance" information (parent-child relations)
@@ -45,7 +56,7 @@
4556
know, it became a "de facto" standard for expressing "alternate waypoints".</p>
4657
</opt>
4758
<opt name='ns_ox' default='false'>
48-
<p>Boolean. If <b>true</b> then response will include Garmin's
59+
<p>Boolean. If <b>true</b> then the response will include Garmin's
4960
<a href='https://github.com/opencaching/okapi/blob/master/etc/nsox.xsd'>OpenCaching.com
5061
GPX extension</a>. This namespace declares an extra &lt;opencaching&gt; element
5162
used by Garmin's (former) <b>OpenCaching.com</b> site.
@@ -170,7 +181,7 @@
170181
<p>Note: You need to use Level 3 Authentication in order to set it to anything else than "none".</p>
171182
</opt>
172183
<opt name='latest_logs' default='false'>
173-
<p>Boolean. If <b>true</b> then response will include a couple of
184+
<p>Boolean. If <b>true</b> then the response will include a couple of
174185
latest log entries for this cache (see also the <b>lpc</b> argument).</p>
175186
<p>You <b>must</b> set <b>ns_ground</b> argument to <b>true</b> if you want to use this.</p>
176187
</opt>

okapi/services/caches/formatters/gpx/gpxfile.tpl.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1616
xmlns:groundspeak="http://www.groundspeak.com/cache/1/0/1"
1717
xmlns:ox="http://www.opencaching.com/xmlschemas/opencaching/1/0"
18+
xmlns:oc="https://github.com/opencaching/gpx-extension-v1"
1819
xmlns:gsak="http://www.gsak.net/xmlv1/5"
1920
xsi:schemaLocation="
2021
http://www.topografix.com/GPX/1/0
@@ -26,6 +27,9 @@
2627
http://www.opencaching.com/xmlschemas/opencaching/1/0
2728
https://raw.githubusercontent.com/opencaching/okapi/master/etc/nsox.xsd
2829

30+
https://github.com/opencaching/gpx-extension-v1
31+
https://raw.githubusercontent.com/opencaching/gpx-extension-v1/master/schema.xsd
32+
2933
http://www.gsak.net/xmlv1/5
3034
http://www.gsak.net/xmlv1/5/gsak.xsd
3135
"
@@ -53,14 +57,14 @@
5357
<url><?= $c['url'] ?></url>
5458
<urlname><?= Okapi::xmlescape($c['name']) ?></urlname>
5559
<sym><?= ($vars['mark_found'] && $c['is_found']) ? "Geocache Found" : "Geocache" ?></sym>
56-
<type>Geocache|<?= $vars['cache_GPX_types'][$c['type']] ?></type>
60+
<type>Geocache|<?= $vars['cache_GPX_types'][$c['type']]['gc'] ?></type>
5761
<?php if ($vars['ns_ground']) { /* Does user want us to include Groundspeak's <cache> element? */ ?>
5862
<groundspeak:cache archived="<?= ($c['status'] == 'Archived') ? "True" : "False" ?>" available="<?= ($c['status'] == 'Available') ? "True" : "False" ?>" id="<?= $c['internal_id'] ?>">
5963
<groundspeak:name><?= Okapi::xmlescape(isset($c['name_2']) ? $c['name_2'] : $c['name']) ?></groundspeak:name>
6064
<groundspeak:placed_by><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:placed_by>
6165
<groundspeak:owner id="<?= $vars['user_uuid_to_internal_id'][$c['owner']['uuid']] ?>"><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:owner>
62-
<groundspeak:type><?= $vars['cache_GPX_types'][$c['type']] ?></groundspeak:type>
63-
<groundspeak:container><?= $vars['cache_GPX_sizes'][$c['size2']] ?></groundspeak:container>
66+
<groundspeak:type><?= $vars['cache_GPX_types'][$c['type']]['gc'] ?></groundspeak:type>
67+
<groundspeak:container><?= $vars['cache_GPX_sizes'][$c['size2']]['gc'] ?></groundspeak:container>
6468
<?php if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { /* Does user want us to include groundspeak:attributes? */ ?>
6569
<groundspeak:attributes>
6670
<?php
@@ -203,6 +207,33 @@
203207
<?php } ?>
204208
</ox:opencaching>
205209
<?php } ?>
210+
<?php if ($vars['ns_oc']) { /* Does user want us to include the Opencaching <cache> element? */ ?>
211+
<oc:cache>
212+
<oc:type><?= $vars['cache_GPX_types'][$c['type']]['oc'] ?></oc:type>
213+
<oc:size><?= $vars['cache_GPX_sizes'][$c['size2']]['oc'] ?></oc:size>
214+
<?php if ($c['trip_time'] > 0) { ?>
215+
<oc:trip_time><?= $c['trip_time'] ?></oc:trip_time>
216+
<?php } ?>
217+
<?php if ($c['trip_distance'] > 0) { ?>
218+
<oc:trip_distance><?= $c['trip_distance'] ?></oc:trip_distance>
219+
<?php } ?>
220+
<oc:requires_password><?= ($c['req_passwd'] ? "true" : "false") ?></oc:requires_password>
221+
<?php if ($c['gc_code']) { ?>
222+
<oc:other_code><?= $c['gc_code'] ?></oc:other_code>
223+
<?php } ?>
224+
<?php if ($vars['latest_logs']) { /* Does user want us to include latest log entries? */ ?>
225+
<oc:logs>
226+
<?php foreach ($c['latest_logs'] as $log) { ?>
227+
<oc:log id="<?= $log['internal_id'] ?>" uuid="<?= $log['uuid'] ?>">
228+
<?php if ($log['oc_team_entry']) { ?>
229+
<oc:site_team_entry>true</oc:site_team_entry>
230+
<?php } ?>
231+
</oc:log>
232+
<?php } ?>
233+
</oc:logs>
234+
<?php } ?>
235+
</oc:cache>
236+
<?php } ?>
206237
</wpt>
207238
<?php
208239
if (isset($cache_ref['ggz_entry'])) {

0 commit comments

Comments
 (0)