okapi r863: GPX gc_ocde:attr option
@@ -814,7 +814,7 @@ class Okapi
|
||||
{
|
||||
public static $data_store;
|
||||
public static $server;
|
||||
public static $revision = 857; # This gets replaced in automatically deployed packages
|
||||
public static $revision = 863; # This gets replaced in automatically deployed packages
|
||||
private static $okapi_vars = null;
|
||||
|
||||
/** Get a variable stored in okapi_vars. If variable not found, return $default. */
|
||||
|
||||
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 4.6 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.8 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
@@ -14,6 +14,8 @@ use okapi\InvalidParam;
|
||||
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 @@ class WebService
|
||||
{
|
||||
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 @@ class WebService
|
||||
);
|
||||
$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 @@ class WebService
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
# 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 @@ http://www.gsak.net/xmlv1/5 http://www.gsak.net/xmlv1/5/gsak.xsd
|
||||
<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>
|
||||
|
||||