okapi r583: waypoint-related changes and fixes

This commit is contained in:
following
2013-03-28 18:38:16 +01:00
parent b5d24350dc
commit 85d0cbc296
4 changed files with 17 additions and 31 deletions

View File

@@ -778,7 +778,7 @@ class Okapi
{ {
public static $data_store; public static $data_store;
public static $server; public static $server;
public static $revision = 576; # This gets replaced in automatically deployed packages public static $revision = 583; # This gets replaced in automatically deployed packages
private static $okapi_vars = null; private static $okapi_vars = null;
/** Get a variable stored in okapi_vars. If variable not found, return $default. */ /** Get a variable stored in okapi_vars. If variable not found, return $default. */

View File

@@ -12,12 +12,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" xsi:schemaLocation="
http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd
http://www.opencaching.com/xmlschemas/opencaching/1/0 http://www.opencaching.com/xmlschemas/opencaching/1/0/opencaching.xsd http://www.opencaching.com/xmlschemas/opencaching/1/0 http://www.opencaching.com/xmlschemas/opencaching/1/0/opencaching.xsd
http://www.groundspeak.com/cache/1/0 http://www.groundspeak.com/cache/1/0/cache.xsd http://www.groundspeak.com/cache/1/0/1 http://www.groundspeak.com/cache/1/0/1/cache.xsd
http://geocaching.com.au/geocache/1 http://geocaching.com.au/geocache/1/geocache.xsd http://geocaching.com.au/geocache/1 http://geocaching.com.au/geocache/1/geocache.xsd
http://www.gsak.net/xmlv1/5 http://www.gsak.net/xmlv1/5/gsak.xsd http://www.gsak.net/xmlv1/5 http://www.gsak.net/xmlv1/5/gsak.xsd
"> ">
<name><?= $vars['installation']['site_name'] ?> Geocache Search Results</name> <name><?= $vars['installation']['site_name'] ?> Geocache Search Results</name>
<desc><?= $vars['installation']['site_name'] ?> Geocache Search Results, downloaded via OKAPI - <?= $vars['installation']['okapi_base_url'] ?></desc> <desc><?= $vars['installation']['site_name'] ?> Geocache Search Results, downloaded via OKAPI - <?= $vars['installation']['okapi_base_url'] . ($vars['alt_wpts'] && $vars['ns_gsak'] ? ' (HasChildren)' : '') ?></desc>
<author><?= $vars['installation']['site_name'] ?></author> <author><?= $vars['installation']['site_name'] ?></author>
<url><?= $vars['installation']['site_url'] ?></url> <url><?= $vars['installation']['site_url'] ?></url>
<urlname><?= $vars['installation']['site_name'] ?></urlname> <urlname><?= $vars['installation']['site_name'] ?></urlname>
@@ -162,9 +162,9 @@ http://www.gsak.net/xmlv1/5 http://www.gsak.net/xmlv1/5/gsak.xsd
<sym><?= $wpt['sym'] ?></sym> <sym><?= $wpt['sym'] ?></sym>
<type>Waypoint|<?= $wpt['sym'] ?></type> <type>Waypoint|<?= $wpt['sym'] ?></type>
<? if ($vars['ns_gsak']) { ?> <? if ($vars['ns_gsak']) { ?>
<wptExtension xmlns="http://www.gsak.net/xmlv1/5"> <gsak:wptExtension xmlns:gsak="http://www.gsak.net/xmlv1/5">
<Parent><?= $c['code'] ?></Parent> <gsak:Parent><?= $c['code'] ?></gsak:Parent>
</wptExtension> </gsak:wptExtension>
<? } ?> <? } ?>
</wpt> </wpt>
<? } ?> <? } ?>

View File

@@ -216,7 +216,7 @@
<p><b>alt_wpts</b> - list of alternate/additional waypoints associated <p><b>alt_wpts</b> - list of alternate/additional waypoints associated
with this geocache. Each item is a dictionary of the following structure:</p> with this geocache. Each item is a dictionary of the following structure:</p>
<ul> <ul>
<li><b>name</b> - plain-text "codename" for the waypoint (not unique),</li> <li><b>name</b> - plain-text, short, unique "codename" for the waypoint,</li>
<li><b>location</b> - location of the waypoint in the "lat|lon" format <li><b>location</b> - location of the waypoint in the "lat|lon" format
(<i>lat</i> and <i>lon</i> are in full degrees with a dot as a decimal point),</li> (<i>lat</i> and <i>lon</i> are in full degrees with a dot as a decimal point),</li>
<li> <li>

View File

@@ -709,7 +709,7 @@ class WebService
{ {
foreach ($results as &$result_ref) foreach ($results as &$result_ref)
$result_ref['alt_wpts'] = array(); $result_ref['alt_wpts'] = array();
$cachelist = implode("','", array_map('mysql_real_escape_string', array_keys($cacheid2wptcode))); $cache_codes_escaped_and_imploded = "'".implode("','", array_map('mysql_real_escape_string', array_keys($cacheid2wptcode)))."'";
if (Settings::get('OC_BRANCH') == 'oc.pl') if (Settings::get('OC_BRANCH') == 'oc.pl')
{ {
@@ -718,14 +718,7 @@ class WebService
# of a multicache). Such hidden waypoints are not exposed by OKAPI. A stage # of a multicache). Such hidden waypoints are not exposed by OKAPI. A stage
# fields is used for ordering and naming. # fields is used for ordering and naming.
$waypoints = Db::select_value(" $waypoints = Db::select_all("
select count(*)
from waypoints
where
cache_id in ('".$cachelist."')
and status = 1
");
$rs = Db::query("
select select
cache_id, stage, latitude, longitude, `desc`, cache_id, stage, latitude, longitude, `desc`,
case type case type
@@ -736,7 +729,7 @@ class WebService
end as sym end as sym
from waypoints from waypoints
where where
cache_id in ('".$cachelist."') cache_id in (".$cache_codes_escaped_and_imploded.")
and status = 1 and status = 1
order by cache_id, stage, `desc` order by cache_id, stage, `desc`
"); ");
@@ -746,14 +739,7 @@ class WebService
# OCDE uses 'coordinates' table (with type=1) to store additional waypoints. # OCDE uses 'coordinates' table (with type=1) to store additional waypoints.
# All waypoints are are public. # All waypoints are are public.
$waypoints = Db::select_value(" $waypoints = Db::select_all("
select count(*)
from coordinates
where
type = 1
and cache_id in ('".$cachelist."')
");
$rs = Db::query("
select select
cache_id, cache_id,
@stage := @stage + 1 as stage, @stage := @stage + 1 as stage,
@@ -770,15 +756,15 @@ class WebService
join (select @stage := 0) s join (select @stage := 0) s
where where
type = 1 type = 1
and cache_id in ('".$cachelist."') and cache_id in (".$cache_codes_escaped_and_imploded.")
order by cache_id, id, `desc` order by cache_id, id, `desc`
"); ");
} }
$wpt_format = "%s-%0" . ($waypoints>0 ? (floor(log10(count($waypoints))) + 1) : "") . "d"; $wpt_format = "%s-%0".strlen(count($waypoints))."d";
while ($row = mysql_fetch_assoc($rs)) foreach ($waypoints as $index => $row)
{ {
$results[$cacheid2wptcode[$row['cache_id']]]['alt_wpts'][] = array( $results[$cacheid2wptcode[$row['cache_id']]]['alt_wpts'][] = array(
'name' => sprintf($wpt_format, $cacheid2wptcode[$row['cache_id']], $row['stage']), 'name' => sprintf($wpt_format, $cacheid2wptcode[$row['cache_id']], $index + 1),
'location' => round($row['latitude'], 6)."|".round($row['longitude'], 6), 'location' => round($row['latitude'], 6)."|".round($row['longitude'], 6),
'sym' => $row['sym'], 'sym' => $row['sym'],
'description' => ($row['stage'] ? _("Stage")." ".$row['stage'].": " : "").$row['desc'], 'description' => ($row['stage'] ? _("Stage")." ".$row['stage'].": " : "").$row['desc'],