Skip to content

Commit

Permalink
added GPX gs_ocde:attrs option; filter out duplicate GPS GS attributes
Browse files Browse the repository at this point in the history
fixes issue 271
  • Loading branch information
following09 committed Jul 9, 2013
1 parent 1d92a60 commit de6ebb2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 11 deletions.
65 changes: 63 additions & 2 deletions okapi/services/caches/formatters/gpx.php
Expand Up @@ -14,6 +14,8 @@
use okapi\services\caches\search\SearchAssistant; use okapi\services\caches\search\SearchAssistant;
use okapi\OkapiInternalConsumer; use okapi\OkapiInternalConsumer;
use okapi\Db; use okapi\Db;
use okapi\Settings;
use okapi\services\attrs\AttrHelper;


class WebService class WebService
{ {
Expand Down Expand Up @@ -99,8 +101,11 @@ public static function call(OkapiRequest $request)
{ {
if ($elem == 'none') { if ($elem == 'none') {
/* pass */ /* pass */
} elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs'))) { } elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs', 'gc_ocde:attrs'))) {
$vars['attrs'][] = $elem; if ($elem == 'gc_ocde:attrs' && Settings::get('OC_BRANCH') != 'oc.de')
$vars['attrs'][] = 'gc:attrs';
else
$vars['attrs'][] = $elem;
} else { } else {
throw new InvalidParam('attrs', "Invalid list entry: '$elem'"); throw new InvalidParam('attrs', "Invalid list entry: '$elem'");
} }
Expand Down Expand Up @@ -168,6 +173,7 @@ public static function call(OkapiRequest $request)
); );
$vars['cache_GPX_types'] = self::$cache_GPX_types; $vars['cache_GPX_types'] = self::$cache_GPX_types;
$vars['cache_GPX_sizes'] = self::$cache_GPX_sizes; $vars['cache_GPX_sizes'] = self::$cache_GPX_sizes;

if (count($vars['attrs']) > 0) if (count($vars['attrs']) > 0)
{ {
/* The user asked for some kind of attribute output. We'll fetch all /* The user asked for some kind of attribute output. We'll fetch all
Expand 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. /* OC sites always used internal user_ids in their generated GPX files.
Expand Down
10 changes: 9 additions & 1 deletion okapi/services/caches/formatters/gpx.xml
Expand Up @@ -84,10 +84,18 @@
<i>groundspeak:attribute</i> elements (<b>ns_ground</b> has to be <b>true</b>), <i>groundspeak:attribute</i> elements (<b>ns_ground</b> has to be <b>true</b>),
compatible with Geocaching.com (see the list compatible with Geocaching.com (see the list
<a href='http://www.geocaching.com/about/icons.aspx'>here</a>).</p> <a href='http://www.geocaching.com/about/icons.aspx'>here</a>).</p>

<p>Note that most Opencaching attributes don't have Geocaching.com counterparts. <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> Such attributes cannot be included as gc:attrs and will be ignored.</p>
</li> </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> </ul>


<p>If you don't want any attributes to be included, you must set the <b>attrs</b> <p>If you don't want any attributes to be included, you must set the <b>attrs</b>
Expand Down
14 changes: 6 additions & 8 deletions okapi/services/caches/formatters/gpxfile.tpl.php
Expand Up @@ -40,16 +40,14 @@
<groundspeak:owner id="<?= $vars['user_uuid_to_internal_id'][$c['owner']['uuid']] ?>"><?= Okapi::xmlescape($c['owner']['username']) ?></groundspeak:owner> <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:type><?= $vars['cache_GPX_types'][$c['type']] ?></groundspeak:type>
<groundspeak:container><?= $vars['cache_GPX_sizes'][$c['size2']] ?></groundspeak:container> <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> <groundspeak:attributes>
<? <?
foreach ($c['attr_acodes'] as $acode) { foreach ($c['gc_attrs'] as $gc_id => $gc_attr) {
foreach ($vars['attr_index'][$acode]['gc_equivs'] as $gc) { print "<groundspeak:attribute id=\"".$gc_id."\" ";
print "<groundspeak:attribute id=\"".$gc['id']."\" "; print "inc=\"".$gc_attr['inc']."\">";
print "inc=\"".$gc['inc']."\">"; print Okapi::xmlescape($gc_attr['name']);
print Okapi::xmlescape($gc['name']); print "</groundspeak:attribute>";
print "</groundspeak:attribute>";
}
} }
?> ?>
</groundspeak:attributes> </groundspeak:attributes>
Expand Down

0 comments on commit de6ebb2

Please sign in to comment.