Skip to content
Permalink
Browse files

added GPX gs_ocde:attrs option; filter out duplicate GPS GS attributes

fixes issue 271
  • Loading branch information...
following09
following09 committed Jul 9, 2013
1 parent 1d92a60 commit de6ebb2beaaca8d931dfc9e24310c7ba6ef8f680
@@ -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.
@@ -84,10 +84,18 @@
<i>groundspeak:attribute</i> elements (<b>ns_ground</b> has to be <b>true</b>),
compatible with Geocaching.com (see the list
<a href='http://www.geocaching.com/about/icons.aspx'>here</a>).</p>

<p>Note that most Opencaching attributes don't have Geocaching.com counterparts.
Such attributes cannot be included as gc:attrs and will be ignored.</p>
</li>
<li>
<p><b>gc_ocde:attrs</b> - attributes will be listed as Groundspeak's
<i>groundspeak:attribute</i> elements (<b>ns_ground</b> has to be <b>true</b>).
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.</p>
<p>Note that this option is supported only by some OC sites. Other sites will
handle <b>gc_ocde:attrs</b> in the same way as <b>gc:attrs</b>.</p>
</li>
</ul>

<p>If you don't want any attributes to be included, you must set the <b>attrs</b>
@@ -40,16 +40,14 @@
<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>
<? if (in_array('gc:attrs', $vars['attrs'])) { /* Does user want us to include groundspeak:attributes? */ ?>
<? if ($vars['gc_attrs'] || $vars['gc_ocde_attrs']) { /* Does user want us to include groundspeak:attributes? */ ?>
<groundspeak:attributes>
<?
foreach ($c['attr_acodes'] as $acode) {
foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc) {
print "<groundspeak:attribute id=\"".$gc['id']."\" ";
print "inc=\"".$gc['inc']."\">";
print Okapi::xmlescape($gc['name']);
print "</groundspeak:attribute>";
}
foreach ($c['gc_attrs'] as $gc_id => $gc_attr) {
print "<groundspeak:attribute id=\"".$gc_id."\" ";
print "inc=\"".$gc_attr['inc']."\">";
print Okapi::xmlescape($gc_attr['name']);
print "</groundspeak:attribute>";
}
?>
</groundspeak:attributes>

0 comments on commit de6ebb2

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