Skip to content
Permalink
Browse files

Upgrade the "attrs" parameter of the "gpx" method.

Fixes issue 190.
  • Loading branch information...
wrygiel committed Jun 25, 2013
1 parent c5f222e commit f7023f821fb02462ae76e7e30b7d60dde37274e9
@@ -93,9 +93,18 @@ public static function call(OkapiRequest $request)
$tmp = $request->get_parameter('attrs');
if (!$tmp) $tmp = 'desc:text';
if (!in_array($tmp, array('none', 'desc:text', 'ox:tags')))
throw new InvalidParam('attrs', "'$tmp'");
$vars['attrs'] = $tmp;
$tmp = explode("|", $tmp);
$vars['attrs'] = array();
foreach ($tmp as $elem)
{
if ($elem == 'none') {
/* pass */
} elseif (in_array($elem, array('desc:text', 'ox:tags', 'gc:attrs'))) {
$vars['attrs'][] = $elem;
} else {
throw new InvalidParam('attrs', "Invalid list entry: '$elem'");
}
}
$tmp = $request->get_parameter('trackables');
if (!$tmp) $tmp = 'none';
@@ -114,15 +123,14 @@ public static function call(OkapiRequest $request)
$user_uuid = $request->get_parameter('user_uuid');
# We can get all the data we need from the services/caches/geocaches method.
# We don't need to do any additional queries here.
# Which fields of the services/caches/geocaches method do we need?
$fields = 'code|name|location|date_created|url|type|status|size|size2|oxsize'.
'|difficulty|terrain|description|hint2|rating|owner|url|internal_id';
if ($vars['images'] != 'none')
$fields .= "|images";
if ($vars['attrs'] != 'none')
$fields .= "|attrnames";
if (count($vars['attrs']) > 0)
$fields .= "|attrnames|attr_acodes";
if ($vars['trackables'] == 'desc:list')
$fields .= "|trackables";
elseif ($vars['trackables'] == 'desc:count')
@@ -138,14 +146,44 @@ public static function call(OkapiRequest $request)
if ($vars['mark_found'])
$fields .= "|is_found";
$vars['caches'] = OkapiServiceRunner::call('services/caches/geocaches', new OkapiInternalRequest(
$request->consumer, $request->token, array('cache_codes' => $cache_codes,
'langpref' => $langpref, 'fields' => $fields, 'lpc' => $lpc, 'user_uuid' => $user_uuid,
'log_fields' => 'uuid|date|user|type|comment|internal_id|was_recommended')));
$vars['installation'] = OkapiServiceRunner::call('services/apisrv/installation', new OkapiInternalRequest(
new OkapiInternalConsumer(), null, array()));
$vars['caches'] = OkapiServiceRunner::call(
'services/caches/geocaches', new OkapiInternalRequest(
$request->consumer, $request->token, array(
'cache_codes' => $cache_codes,
'langpref' => $langpref,
'fields' => $fields,
'lpc' => $lpc,
'user_uuid' => $user_uuid,
'log_fields' => 'uuid|date|user|type|comment|internal_id|was_recommended'
)
)
);
# Get all the other data need.
$vars['installation'] = OkapiServiceRunner::call(
'services/apisrv/installation', new OkapiInternalRequest(
new OkapiInternalConsumer(), null, array()
)
);
$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
* the data we MAY need. This is often far too much, but thanks to
* caching, it will work fast. */
$vars['attr_index'] = OkapiServiceRunner::call(
'services/attrs/attribute_index', new OkapiInternalRequest(
$request->consumer, $request->token, array(
'only_locally_used' => 'true',
'langpref' => $langpref,
'fields' => 'name|gc_equivs'
)
)
);
}
/* OC sites always used internal user_ids in their generated GPX files.
* This might be considered an error in itself (Groundspeak's XML namespace
@@ -24,7 +24,7 @@
</opt>
<opt name='ns_ground' default='false'>
Boolean. If <b>true</b> then response will include
<a href='http://www.groundspeak.com/cache/1/0/cache.xsd'>Groundspeak's
<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='http://www.geocaching.com/'>geocaching.com</a> and <b>many others</b>.
This namespace was initially associatied with geocaching.com, but now seems to
@@ -72,14 +72,27 @@
</opt>
<opt name='attrs' default='desc:text'>
<p>This argument controls wether cache attributes are included and how they are included.
One of the following values:</p>
Pipe-separated list consisting of any set of the following values:</p>

<ul>
<li><b>none</b> - no attributes will be included,</li>
<li><b>desc:text</b> - attributes will be listed (in plain-text) within the cache description,</li>
<li><b>ox:tags</b> - attributes will be converted to Garmin's ox:tag elements.</li>
<li><b>desc:text</b> - attributes will be listed (in plain-text) within
the cache description (<b>ns_ground</b> has to be <b>true</b>),</li>
<li><b>ox:tags</b> - attributes will be listed as Garmin's <i>ox:tag</i>
elements (<b>ns_ox</b> has to be <b>true</b>),</li>
<li>
<p><b>gc:attrs</b> - attributes will be listed as Grounspeak's
<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>
</ul>
<p>Note: When using "desc:" mode, remember to set <b>ns_ground</b> to <b>true</b>.</p>
<p>Note: When using "ox:" mode, remember to set <b>ns_ox</b> to <b>true</b>.</p>

<p>If you don't want any attributes to be included, you must pass a single
<b>none</b> as the <b>attrs</b> value. Passing an empty string won't work - it will
trigger the default (desc:text) to be selected (for backward-compatibility).</p>
</opt>
<opt name='trackables' default='none'>
<p>This argument controls wether information on trackables is included and how it is included.
@@ -40,6 +40,20 @@
<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? */ ?>
<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>";
}
}
?>
</groundspeak:attributes>
<? } ?>
<groundspeak:difficulty><?= $c['difficulty'] ?></groundspeak:difficulty>
<groundspeak:terrain><?= $c['terrain'] ?></groundspeak:terrain>
<groundspeak:long_description html="True">
@@ -58,7 +72,7 @@
&lt;p&gt;&lt;b&gt;<?= _("Personal notes") ?>:&lt;/b&gt; <?= Okapi::xmlescape($c['my_notes']) ?>&lt;/p&gt;
<? } ?>

<? if ($vars['attrs'] == 'desc:text' && count($c['attrnames']) > 0) { /* Does user want us to include attributes? */ ?>
<? if (in_array('desc:text', $vars['attrs']) && count($c['attrnames']) > 0) { /* Does user want us to include attributes? */ ?>
&lt;p&gt;<?= _("Attributes") ?>:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;<?= implode("&lt;/li&gt;&lt;li&gt;", $c['attrnames']) ?>&lt;/li&gt;&lt;/ul&gt;
<? } ?>
@@ -137,7 +151,7 @@
<? if ($c['oxsize'] !== null) { ?><ox:size><?= $c['oxsize'] ?></ox:size><? } ?>
<ox:terrain><?= $c['terrain'] ?></ox:terrain>
</ox:ratings>
<? if ($vars['attrs'] == 'ox:tags' && count($c['attrnames']) > 0) { /* Does user want us to include ox:tags? */ ?>
<? if (in_array('ox:tags', $vars['attrs']) && count($c['attrnames']) > 0) { /* Does user want us to include ox:tags? */ ?>
<ox:tags><ox:tag><?= implode("</ox:tag><ox:tag>", $c['attrnames']) ?></ox:tag></ox:tags>
<? } ?>
<? if ((strpos($vars['images'], "ox:") === 0) && count($c['images']) > 0) { /* Does user want us to include ox:image references? */ ?>

0 comments on commit f7023f8

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