From 10e16a21748cd4309a4a1a6a48b5529a08f2c48e Mon Sep 17 00:00:00 2001
From: following
Date: Wed, 8 May 2013 14:50:04 +0200
Subject: [PATCH] okapi r786: added geocaches.gc_code field
---
htdocs/okapi/core.php | 2 +-
htdocs/okapi/services/caches/geocache.xml | 8 +++++++-
htdocs/okapi/services/caches/geocaches.php | 14 +++++++++++---
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/htdocs/okapi/core.php b/htdocs/okapi/core.php
index e24dc9fa..c507e805 100644
--- a/htdocs/okapi/core.php
+++ b/htdocs/okapi/core.php
@@ -799,7 +799,7 @@ class Okapi
{
public static $data_store;
public static $server;
- public static $revision = 781; # This gets replaced in automatically deployed packages
+ public static $revision = 786; # 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. */
diff --git a/htdocs/okapi/services/caches/geocache.xml b/htdocs/okapi/services/caches/geocache.xml
index 9a8e0af0..30e4b96e 100644
--- a/htdocs/okapi/services/caches/geocache.xml
+++ b/htdocs/okapi/services/caches/geocache.xml
@@ -19,7 +19,13 @@
Selected fields will be included in the response.
Currently available fields:
- - code - unique code of the geocache,
+ - code - unique Opencaching code of the geocache,
+ gc_code - geocaching.com code (GC code) of the geocache;
+ null if not crosslisted or unknown.
+ Please note that many cache owners do not provide this information.
+ It may be missing or wrong, or the GC listing may be inactive
+ (Discussion).
+
- name - name of the geocache,
- names - a dictionary (language code => plain-text string) of
names of the geocache (at this time, there will be only one language,
diff --git a/htdocs/okapi/services/caches/geocaches.php b/htdocs/okapi/services/caches/geocaches.php
index 9a1139c9..9c1bc390 100644
--- a/htdocs/okapi/services/caches/geocaches.php
+++ b/htdocs/okapi/services/caches/geocaches.php
@@ -32,7 +32,7 @@ class WebService
'my_notes', 'trackables_count', 'trackables', 'alt_wpts', 'last_found',
'last_modified', 'date_created', 'date_hidden', 'internal_id', 'is_watched',
'is_ignored', 'willattends', 'country', 'state', 'preview_image',
- 'trip_time', 'trip_distance', 'attribution_note');
+ 'trip_time', 'trip_distance', 'attribution_note','gc_code');
public static function call(OkapiRequest $request)
{
@@ -157,7 +157,7 @@ class WebService
select
c.cache_id, c.name, c.longitude, c.latitude, c.listing_last_modified as last_modified,
c.date_created, c.type, c.status, c.date_hidden, c.size, c.difficulty,
- c.terrain, c.wp_oc, c.logpw, c.user_id,
+ c.terrain, c.wp_oc, c.wp_gc, c.logpw, c.user_id,
if(c.search_time=0, null, c.search_time) as trip_time,
if(c.way_length=0, null, c.way_length) as trip_distance,
@@ -189,7 +189,7 @@ class WebService
select
c.cache_id, c.name, c.longitude, c.latitude, c.last_modified,
c.date_created, c.type, c.status, c.date_hidden, c.size, c.difficulty,
- c.terrain, c.wp_oc, c.logpw, c.user_id,
+ c.terrain, c.wp_oc, c.wp_gc, c.logpw, c.user_id,
if(c.search_time=0, null, c.search_time) as trip_time,
if(c.way_length=0, null, c.way_length) as trip_distance,
@@ -220,6 +220,14 @@ class WebService
switch ($field)
{
case 'code': $entry['code'] = $row['wp_oc']; break;
+ case 'gc_code':
+ // OC software allows entering anything here, and that's what users do.
+ // We do a formal verification so that only a valid GC code is returned:
+ if (preg_match('/^\s*[Gg][Cc][A-Za-z0-9]+\s*$/', $row['wp_gc']))
+ $entry['gc_code'] = strtoupper(trim($row['wp_gc']));
+ else
+ $entry['gc_code'] = null;
+ break;
case 'name': $entry['name'] = $row['name']; break;
case 'names': $entry['names'] = array(Settings::get('SITELANG') => $row['name']); break; // for the future
case 'location': $entry['location'] = round($row['latitude'], 6)."|".round($row['longitude'], 6); break;