diff --git a/okapi/services/caches/formatters/gpx.php b/okapi/services/caches/formatters/gpx.php index eb647a42..6e59959e 100644 --- a/okapi/services/caches/formatters/gpx.php +++ b/okapi/services/caches/formatters/gpx.php @@ -14,6 +14,8 @@ use okapi\services\caches\search\SearchAssistant; use okapi\OkapiInternalConsumer; use okapi\Db; +use okapi\Settings; +use okapi\services\attrs\AttrHelper; class WebService { @@ -99,8 +101,11 @@ public static function call(OkapiRequest $request) { if ($elem == 'none') { /* pass */ - } elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs'))) { - $vars['attrs'][] = $elem; + } elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs', 'gc_ocde:attrs'))) { + if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de') + $vars['attrs'][] = 'gc:attrs'; + else + $vars['attrs'][] = $elem; } else { throw new InvalidParam('attrs', "Invalid list entry: '$elem'"); } @@ -168,6 +173,7 @@ public static function call(OkapiRequest $request) ); $vars['cache_GPX_types'] = self::$cache_GPX_types; $vars['cache_GPX_sizes'] = self::$cache_GPX_sizes; + if (count($vars['attrs']) > 0) { /* The user asked for some kind of attribute output. We'll fetch all @@ -183,6 +189,61 @@ public static function call(OkapiRequest $request) ) ) ); + + # prepare GS attribute data + + $vars['gc_attrs'] = in_array('gc:attrs', $vars['attrs']); + $vars['gc_ocde_attrs'] = in_array('gc_ocde:attrs', $vars['attrs']); + if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) + { + if ($vars['gc_ocde_attrs']) + { + # As this is an OCDE compatibility feature, we use the same Pseudo-GS + # attribute names here as OCDE. Note that this code is specific to OCDE + # database; OCPL stores attribute names in a different way and may use + # different names for equivalent attributes. + + $ocde_attrnames = Db::select_group_by('id'," + select id, name + from cache_attrib + "); + $attr_dict = AttrHelper::get_attrdict(); + } + + foreach ($vars['caches'] as &$cache) + { + $cache['gc_attrs'] = array(); + foreach ($cache['attr_acodes'] as $acode) + { + $has_gc_equivs = false; + foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc) + { + # The assignment via GC-ID as array key will prohibit duplicate + # GC attributes, which can result from + # - assigning the same GC ID to multiple A-Codes, + # - contradicting attributes in one OC listing, e.g. 24/4 + not 24/7. + + $cache['gc_attrs'][$gc['id']] = $gc; + $has_gc_equivs = true; + } + if (!$has_gc_equivs && $vars['gc_ocde_attrs']) + { + # Generate an OCDE pseudo-GS attribute; + # see http://code.google.com/p/opencaching-api/issues/detail?id=190 and + # http://code.google.com/p/opencaching-api/issues/detail?id=271. + # + # Groundspeak uses ID 1..65 (as of June, 2013), and OCDE makeshift + # IDs start at 106, so there is space for 40 new GS attributes. + + $internal_id = $attr_dict[$acode]['internal_id']; + $cache['gc_attrs'][100 + $internal_id] = array( + 'inc' => 1, + 'name' => $ocde_attrnames[$internal_id][0]['name'], + ); + } + } + } + } } /* OC sites always used internal user_ids in their generated GPX files. diff --git a/okapi/services/caches/formatters/gpx.xml b/okapi/services/caches/formatters/gpx.xml index 081d60a2..66283b57 100644 --- a/okapi/services/caches/formatters/gpx.xml +++ b/okapi/services/caches/formatters/gpx.xml @@ -84,10 +84,18 @@ groundspeak:attribute elements (ns_ground has to be true), compatible with Geocaching.com (see the list here).

-

Note that most Opencaching attributes don't have Geocaching.com counterparts. Such attributes cannot be included as gc:attrs and will be ignored.

+
  • +

    gc_ocde:attrs - attributes will be listed as Groundspeak's + groundspeak:attribute elements (ns_ground has to be true). + Opencaching attributes which have no Geocaching.com counterparts will be + included according to an Opencaching.DE convention, using "makeshift IDs" + which may change in the future.

    +

    Note that this option is supported only by some OC sites. Other sites will + handle gc_ocde:attrs in the same way as gc:attrs.

    +
  • If you don't want any attributes to be included, you must set the attrs diff --git a/okapi/services/caches/formatters/gpxfile.tpl.php b/okapi/services/caches/formatters/gpxfile.tpl.php index 6bacabea..c19a7ce1 100644 --- a/okapi/services/caches/formatters/gpxfile.tpl.php +++ b/okapi/services/caches/formatters/gpxfile.tpl.php @@ -40,16 +40,14 @@ - + "; - print Okapi::xmlescape($gc['name']); - print ""; - } + foreach ($c['gc_attrs'] as $gc_id => $gc_attr) { + print ""; + print Okapi::xmlescape($gc_attr['name']); + print ""; } ?>