Skip to content
Permalink
Browse files

Added the Opencaching GPX extension (#511)

  • Loading branch information...
following5 committed Oct 6, 2017
1 parent af0236c commit 1d66caac0b35faf545c8a3deef735803246134c6
@@ -24,33 +24,33 @@ public static function options()
);
}
/** Maps OKAPI cache type codes to Geocaching.com GPX cache types. */
public static $cache_GPX_types = array(
'Traditional' => 'Traditional Cache',
'Multi' => 'Multi-Cache',
'Quiz' => 'Unknown Cache',
'Event' => 'Event Cache',
'Virtual' => 'Virtual Cache',
'Webcam' => 'Webcam Cache',
'Moving' => 'Unknown Cache',
'Math/Physics' => 'Unknown Cache',
'Drive-In' => 'Traditional Cache',
'Podcast' => 'Unknown Cache',
'Own' => 'Unknown Cache',
'Other' => 'Unknown Cache'
);
/** Maps OKAPI's 'size2' values to geocaching.com size codes. */
public static $cache_GPX_sizes = array(
'none' => 'Virtual',
'nano' => 'Micro',
'micro' => 'Micro',
'small' => 'Small',
'regular' => 'Regular',
'large' => 'Large',
'xlarge' => 'Large',
'other' => 'Other',
);
/** Maps OKAPI cache type codes to GPX cache types. */
public static $cache_GPX_types = [
'Traditional' => ['oc' => 'Traditional Cache', 'gc' => 'Traditional Cache' ],
'Multi' => ['oc' => 'Multi-Cache', 'gc' => 'Multi-Cache' ],
'Quiz' => ['oc' => 'Quiz Cache', 'gc' => 'Unknown Cache' ],
'Event' => ['oc' => 'Event Cache', 'gc' => 'Event Cache' ],
'Virtual' => ['oc' => 'Virtual Cache', 'gc' => 'Virtual Cache' ],
'Webcam' => ['oc' => 'Webcam Cache', 'gc' => 'Webcam Cache' ],
'Moving' => ['oc' => 'Moving Cache', 'gc' => 'Unknown Cache' ],
'Math/Physics' => ['oc' => 'Quiz Cache', 'gc' => 'Unknown Cache' ],
'Drive-In' => ['oc' => 'Traditional Cache', 'gc' => 'Traditional Cache' ],
'Podcast' => ['oc' => 'Podcast Cache', 'gc' => 'Unknown Cache' ],
'Own' => ['oc' => 'Own Cache', 'gc' => 'Unknown Cache' ],
'Other' => ['oc' => 'Other Cache', 'gc' => 'Unknown Cache' ],
];
/** Maps OKAPI's 'size2' values to GPX size codes. */
public static $cache_GPX_sizes = [
'none' => ['oc' => 'No container', 'gc' => 'Virtual' ],
'nano' => ['oc' => 'Nano', 'gc' => 'Micro' ],
'micro' => ['oc' => 'Micro', 'gc' => 'Micro' ],
'small' => ['oc' => 'Small', 'gc' => 'Small' ],
'regular' => ['oc' => 'Regular', 'gc' => 'Regular' ],
'large' => ['oc' => 'Large', 'gc' => 'Large' ],
'xlarge' => ['oc' => 'Very large', 'gc' => 'Large' ],
'other' => ['oc' => 'Other', 'gc' => 'Other' ],
];
/**
* When used in create_gpx() method, enables GGZ index generation.
@@ -95,7 +95,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
$langpref = $request->get_parameter('langpref');
if (!$langpref) $langpref = "en";
$langprefs = explode("|", $langpref);
foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'latest_logs', 'alt_wpts', 'mark_found') as $param)
foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'ns_oc', 'latest_logs', 'alt_wpts', 'mark_found') as $param)
{
$val = $request->get_parameter($param);
if (!$val) $val = "false";
@@ -205,7 +205,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
$fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize'.
'|difficulty|terrain|description|hint2|rating|owner|url|internal_id'.
'|protection_areas|short_description';
'|protection_areas|short_description|trip_time|trip_distance|req_passwd|gc_code';
if ($vars['images'] != 'none')
$fields .= "|images";
if (count($vars['attrs']) > 0)
@@ -233,7 +233,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
'fields' => $fields,
'lpc' => $lpc,
'user_uuid' => $user_uuid,
'log_fields' => 'uuid|date|user|type|comment|internal_id|was_recommended'
'log_fields' => 'uuid|date|user|type|comment|oc_team_entry|internal_id|was_recommended'
)
)
);
@@ -467,7 +467,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
$ggz_entry['code'] = $cache_ref['code'];
$ggz_entry['name'] = isset($cache_ref['name_2']) ? $cache_ref['name_2'] : $cache_ref['name'];
$ggz_entry['type'] = $vars['cache_GPX_types'][$cache_ref['type']];
$ggz_entry['type'] = $vars['cache_GPX_types'][$cache_ref['type']]['gc'];
list($lat, $lon) = explode("|", $cache_ref['location']);
$ggz_entry['lat'] = $lat;
$ggz_entry['lon'] = $lon;
@@ -25,15 +25,26 @@
order of preference in which language will be chosen for GPX entities.</p>
</opt>
<opt name='ns_ground' default='false'>
Boolean. If <b>true</b> then response will include
Boolean. If <b>true</b> then the response will include
<a href='http://www.groundspeak.com/cache/1/0/1/cache.xsd'>Groundspeak's
GPX extension</a>. This namespace declares an extra &lt;cache&gt; element
used by <a href='https://www.geocaching.com/'>geocaching.com</a> and <b>many others</b>.
This namespace was initially associatied with geocaching.com, but now seems to
be used in every geocaching GPX file. You probably want to have it.
</opt>
<opt name='ns_oc' default='false'>
<p>Boolean. If <b>true</b> then the response will include the
<a href='https://github.com/opencaching/gpx-extension-v1/blob/master/schema.xsd'>
Opencaching GPX extension</a>. The GPX files will contain an additional
&lt;oc:cache&gt; element for each geocache, which contains Opencaching-specific
information about the geocache. If <b>latest_logs</b> is set to <b>true</b>,
then it will also contain Opencaching-specific information about log entries.</p>

<p>The Opencaching GPX extension was introduced by OKAPI and is expected to
be included in most OC sites' native GPX files.</p>
</opt>
<opt name='ns_gsak' default='false'>
<p>Boolean. If <b>true</b> then response will include
<p>Boolean. If <b>true</b> then the response will include
<a href='http://www.gsak.net/xmlv1/5/gsak.xsd'>GSAK GPX extension</a>.
This namespace declares an extra &lt;wptExtension&gt; element,
which allows including "waypoint inheritance" information (parent-child relations)
@@ -45,7 +56,7 @@
know, it became a "de facto" standard for expressing "alternate waypoints".</p>
</opt>
<opt name='ns_ox' default='false'>
<p>Boolean. If <b>true</b> then response will include Garmin's
<p>Boolean. If <b>true</b> then the response will include Garmin's
<a href='https://github.com/opencaching/okapi/blob/master/etc/nsox.xsd'>OpenCaching.com
GPX extension</a>. This namespace declares an extra &lt;opencaching&gt; element
used by Garmin's (former) <b>OpenCaching.com</b> site.
@@ -170,7 +181,7 @@
<p>Note: You need to use Level 3 Authentication in order to set it to anything else than "none".</p>
</opt>
<opt name='latest_logs' default='false'>
<p>Boolean. If <b>true</b> then response will include a couple of
<p>Boolean. If <b>true</b> then the response will include a couple of
latest log entries for this cache (see also the <b>lpc</b> argument).</p>
<p>You <b>must</b> set <b>ns_ground</b> argument to <b>true</b> if you want to use this.</p>
</opt>
@@ -15,6 +15,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:groundspeak="http://www.groundspeak.com/cache/1/0/1"
xmlns:ox="http://www.opencaching.com/xmlschemas/opencaching/1/0"
xmlns:oc="https://github.com/opencaching/gpx-extension-v1"
xmlns:gsak="http://www.gsak.net/xmlv1/5"
xsi:schemaLocation="
http://www.topografix.com/GPX/1/0
@@ -26,6 +27,9 @@
http://www.opencaching.com/xmlschemas/opencaching/1/0
https://raw.githubusercontent.com/opencaching/okapi/master/etc/nsox.xsd
https://github.com/opencaching/gpx-extension-v1
https://raw.githubusercontent.com/opencaching/gpx-extension-v1/master/schema.xsd
http://www.gsak.net/xmlv1/5
http://www.gsak.net/xmlv1/5/gsak.xsd
"
@@ -53,14 +57,14 @@
<url><?= $c['url'] ?></url>
<urlname><?= Okapi::xmlescape($c['name']) ?></urlname>
<sym><?= ($vars['mark_found'] && $c['is_found']) ? "Geocache Found" : "Geocache" ?></sym>
<type>Geocache|<?= $vars['cache_GPX_types'][$c['type']] ?></type>
<type>Geocache|<?= $vars['cache_GPX_types'][$c['type']]['gc'] ?></type>
<?php if ($vars['ns_ground']) { /* Does user want us to include Groundspeak's <cache> element? */ ?>
<groundspeak:cache archived="<?= ($c['status'] == 'Archived') ? "True" : "False" ?>" available="<?= ($c['status'] == 'Available') ? "True" : "False" ?>" id="<?= $c['internal_id'] ?>">
<groundspeak:name><?= Okapi::xmlescape(isset($c['name_2']) ? $c['name_2'] : $c['name']) ?></groundspeak:name>
<groundspeak:placed_by><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:placed_by>
<groundspeak:owner id="<?= $vars['user_uuid_to_internal_id'][$c['owner']['uuid']] ?>"><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:owner>
<groundspeak:type><?= $vars['cache_GPX_types'][$c['type']] ?></groundspeak:type>
<groundspeak:container><?= $vars['cache_GPX_sizes'][$c['size2']] ?></groundspeak:container>
<groundspeak:type><?= $vars['cache_GPX_types'][$c['type']]['gc'] ?></groundspeak:type>
<groundspeak:container><?= $vars['cache_GPX_sizes'][$c['size2']]['gc'] ?></groundspeak:container>
<?php if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { /* Does user want us to include groundspeak:attributes? */ ?>
<groundspeak:attributes>
<?php
@@ -203,6 +207,33 @@
<?php } ?>
</ox:opencaching>
<?php } ?>
<?php if ($vars['ns_oc']) { /* Does user want us to include the Opencaching <cache> element? */ ?>
<oc:cache>
<oc:type><?= $vars['cache_GPX_types'][$c['type']]['oc'] ?></oc:type>
<oc:size><?= $vars['cache_GPX_sizes'][$c['size2']]['oc'] ?></oc:size>
<?php if ($c['trip_time'] > 0) { ?>
<oc:trip_time><?= $c['trip_time'] ?></oc:trip_time>
<?php } ?>
<?php if ($c['trip_distance'] > 0) { ?>
<oc:trip_distance><?= $c['trip_distance'] ?></oc:trip_distance>
<?php } ?>
<oc:requires_password><?= ($c['req_passwd'] ? "true" : "false") ?></oc:requires_password>
<?php if ($c['gc_code']) { ?>
<oc:other_code><?= $c['gc_code'] ?></oc:other_code>
<?php } ?>
<?php if ($vars['latest_logs']) { /* Does user want us to include latest log entries? */ ?>
<oc:logs>
<?php foreach ($c['latest_logs'] as $log) { ?>
<oc:log id="<?= $log['internal_id'] ?>" uuid="<?= $log['uuid'] ?>">
<?php if ($log['oc_team_entry']) { ?>
<oc:site_team_entry>true</oc:site_team_entry>
<?php } ?>
</oc:log>
<?php } ?>
</oc:logs>
<?php } ?>
</oc:cache>
<?php } ?>
</wpt>
<?php
if (isset($cache_ref['ggz_entry'])) {

0 comments on commit 1d66caa

Please sign in to comment.
You can’t perform that action at this time.