Skip to content

Commit 55c19d6

Browse files
committed
added GPX option 'alt_wpts=desc:table'; closes #226
1 parent bc25bd3 commit 55c19d6

File tree

6 files changed

+105
-36
lines changed

6 files changed

+105
-36
lines changed

okapi/core/Okapi.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,8 @@ public static function fix_oc_html($html, $text_html)
12201220
/**
12211221
* Convert strings such as "2M" or "50k" to bytes.
12221222
*/
1223-
public static function from_human_to_bytes($val) {
1223+
public static function from_human_to_bytes($val)
1224+
{
12241225
$val = trim($val);
12251226
$last = strtolower($val[strlen($val) - 1]);
12261227
switch($last) {
@@ -1245,7 +1246,8 @@ public static function from_human_to_bytes($val) {
12451246
* that the requester is a developer. If he isn't, it die()s.
12461247
* See also issue #524.
12471248
*/
1248-
public static function require_developer_cookie() {
1249+
public static function require_developer_cookie()
1250+
{
12491251
if (
12501252
(!isset($_COOKIE['okapi_devel_key']))
12511253
|| (md5($_COOKIE['okapi_devel_key']) !== '5753f318c1495c01637f7f6b7fc9c5db')
@@ -1262,7 +1264,8 @@ public static function require_developer_cookie() {
12621264
* shouldn't be updated automatically on each Level 3 request (because some of these
12631265
* requests are not necessarilly initiated by the user).
12641266
*/
1265-
public static function update_user_activity($request) {
1267+
public static function update_user_activity($request)
1268+
{
12661269
if ($request && $request->token && $request->token->token_type == "access") {
12671270
Db::execute("
12681271
update user set last_login=now()
@@ -1271,11 +1274,35 @@ public static function update_user_activity($request) {
12711274
}
12721275
}
12731276

1277+
/**
1278+
* Formate a "lat|lon" location in a user-readable way;
1279+
* returns array with latitude and longitude component.
1280+
*/
1281+
public static function format_location($location)
1282+
{
1283+
if (!preg_match('/^([+-]?[0-9]+(\.[0-9]*)?)\|([+-]?[0-9]+(\.[0-9]*)?)$/', $location, $matches))
1284+
throw Exception("invalid location format");
1285+
return [
1286+
self::format_coordinate($matches[1], 'N', 'S'),
1287+
self::format_coordinate($matches[3], 'E', 'W')
1288+
];
1289+
}
1290+
1291+
private static function format_coordinate($deg, $positive_direction, $negative_direction)
1292+
{
1293+
$direction = ($deg < 0 ? $negative_direction : $positive_direction);
1294+
$deg = abs($deg);
1295+
$degrees = floor($deg);
1296+
$minutes = ($deg - $degrees) * 60;
1297+
return sprintf("%s %d° %.3f'", $direction, $degrees, $minutes);
1298+
}
1299+
12741300
/**
12751301
* Take a list of "infotags" (as defined in services/apiref/method), and format
12761302
* them for being displayed in OKAPI public documentation pages.
12771303
*/
1278-
public static function format_infotags($infotags) {
1304+
public static function format_infotags($infotags)
1305+
{
12791306
$chunks = [];
12801307
$url = Settings::get('SITE_URL')."okapi/introduction.html#oc-branch-differences";
12811308
foreach ($infotags as $infotag) {
66 Bytes
Binary file not shown.

okapi/locale/de_DE/LC_MESSAGES/okapi_messages.po

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ msgid ""
22
msgstr ""
33
"Project-Id-Version: OKAPI\n"
44
"Report-Msgid-Bugs-To: \n"
5-
"POT-Creation-Date: 2018-11-12 10:27+0100\n"
6-
"PO-Revision-Date: 2018-11-12 10:27+0100\n"
5+
"POT-Creation-Date: 2018-11-16 11:54+0100\n"
6+
"PO-Revision-Date: 2018-11-16 11:54+0100\n"
77
"Last-Translator: following <following@online.de>\n"
88
"Language-Team: following <following@online.de>\n"
99
"Language: de\n"
@@ -14,7 +14,7 @@ msgstr ""
1414
"X-Poedit-Basepath: ../../..\n"
1515
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
1616
"X-Poedit-SourceCharset: UTF-8\n"
17-
"X-Generator: Poedit 1.8.7\n"
17+
"X-Generator: Poedit 2.2\n"
1818
"X-Poedit-SearchPath-0: .\n"
1919
"X-Poedit-SearchPathExcluded-0: .git\n"
2020

@@ -28,27 +28,27 @@ msgstr "Das Passwort darf nicht länger als %d Zeichen sein."
2828
msgid "%s does not allow log passwords for traditional caches."
2929
msgstr "Tradis können bei %s keine Passwörter haben."
3030

31-
#: services/caches/formatters/gpx/WebService.php:404
31+
#: services/caches/formatters/gpx/WebService.php:423
3232
msgid ""
3333
"<b>Geocache coordinates have been changed.</b> They have been replaced with "
3434
"your own custom coordinates which you have provided for this geocache."
3535
msgstr ""
3636
"<b>Die Koordinaten des Geocaches wurden geändert.</b> Sie wurden durch deine "
3737
"eigenen Koordinaten aus der persönlichen Notiz für diesen Cache ersetzt."
3838

39-
#: services/caches/formatters/gpx/WebService.php:410
39+
#: services/caches/formatters/gpx/WebService.php:429
4040
msgid ""
4141
"<b>Geocache coordinates have been changed.</b> Currently they point to one "
4242
"of the alternate waypoints originally described as:"
4343
msgstr ""
4444
"<b>Die Koordinaten des Geocaches wurden geändert.</b> Sie zeigen zurzeit auf "
4545
"einen der zusätzlichen Wegpunkte mit der ursprünglichen Beschreibung:"
4646

47-
#: services/caches/formatters/gpx/WebService.php:423
47+
#: services/caches/formatters/gpx/WebService.php:442
4848
msgid "Original geocache location"
4949
msgstr "Originalposition des Caches"
5050

51-
#: services/caches/formatters/gpx/WebService.php:425
51+
#: services/caches/formatters/gpx/WebService.php:444
5252
#, php-format
5353
msgid "Original (owner-supplied) location of the %s geocache"
5454
msgstr "Originale, vom Besitzer angegebene Position des Geocaches %s"
@@ -91,37 +91,41 @@ msgstr "Attribute"
9191
msgid "Trackables"
9292
msgstr "Geokrets"
9393

94-
#: services/caches/formatters/gpx/gpxfile.tpl.php:119
95-
#: services/caches/formatters/gpx/gpxfile.tpl.php:135
94+
#: services/caches/formatters/gpx/gpxfile.tpl.php:118
95+
msgid "Additional waypoints"
96+
msgstr "Zusätzliche Wegpunkte"
97+
98+
#: services/caches/formatters/gpx/gpxfile.tpl.php:131
99+
#: services/caches/formatters/gpx/gpxfile.tpl.php:147
96100
msgid "Images"
97101
msgstr "Bilder"
98102

99-
#: services/caches/formatters/gpx/gpxfile.tpl.php:142
103+
#: services/caches/formatters/gpx/gpxfile.tpl.php:154
100104
msgid "Spoilers"
101105
msgstr "Spoiler"
102106

103-
#: services/caches/formatters/gpx/gpxfile.tpl.php:151
107+
#: services/caches/formatters/gpx/gpxfile.tpl.php:163
104108
msgid "Image descriptions"
105109
msgstr "Bildbeschreibungen"
106110

107-
#: services/caches/formatters/gpx/gpxfile.tpl.php:159
111+
#: services/caches/formatters/gpx/gpxfile.tpl.php:171
108112
msgid "The cache probably is located in the following protection areas:"
109113
msgstr ""
110114
"Der Geocache befindet sich wahrscheinlich in den folgenden Schutzgebieten:"
111115

112-
#: services/caches/geocaches/WebService.php:624
116+
#: services/caches/geocaches/WebService.php:622
113117
msgid "Parts of this geocache listing may be outdated."
114118
msgstr "Teile dieser Cachebeschreibung sind wahrscheinlich veraltet."
115119

116-
#: services/caches/geocaches/WebService.php:626
120+
#: services/caches/geocaches/WebService.php:624
117121
msgid "See the log entries for more information."
118122
msgstr "Weitere Informationen dazu finden sich in den Logeinträgen."
119123

120-
#: services/caches/geocaches/WebService.php:643
124+
#: services/caches/geocaches/WebService.php:640
121125
msgid "Annotations by the Opencaching team:"
122126
msgstr "Anmerkungen des Opencaching-Teams:"
123127

124-
#: services/caches/geocaches/WebService.php:645
128+
#: services/caches/geocaches/WebService.php:642
125129
msgid "End of annotations"
126130
msgstr "Ende der Anmerkungen"
127131

@@ -142,15 +146,15 @@ msgstr "Die Koordinaten für den Geocache %s aus deiner persönlichen Notiz"
142146
msgid "National Park / Landscape"
143147
msgstr "Nationalpark / Landschaft"
144148

145-
#: services/caches/geocaches/WebService.php:1578
149+
#: services/caches/geocaches/WebService.php:1580
146150
#, php-format
147151
msgid ""
148152
"This <a href='%s'>geocache</a> description comes from the <a href='%s'>%s</"
149153
"a> site."
150154
msgstr ""
151155
"Diese <a href='%s'>Cache</a>-Beschreibung stammt von <a href='%s'>%s</a>."
152156

153-
#: services/caches/geocaches/WebService.php:1590
157+
#: services/caches/geocaches/WebService.php:1592
154158
#, php-format
155159
msgid ""
156160
"&copy; <a href='%s'>%s</a>, <a href='%s'>%s</a>, <a href='https://"
@@ -161,7 +165,7 @@ msgstr ""
161165
"creativecommons.org/licenses/by-nc-nd/3.0/de/'>CC-BY-NC-ND</a>, Stand: %s; "
162166
"alle Logeinträge &copy; jeweiliger Autor"
163167

164-
#: services/caches/geocaches/WebService.php:1601
168+
#: services/caches/geocaches/WebService.php:1603
165169
#, php-format
166170
msgid ""
167171
"&copy; <a href='%s'>%s</a>, <a href='%s'>%s</a>, <a href='https://"
@@ -364,7 +368,7 @@ msgstr ""
364368
msgid "Event caches cannot \"need maintenance\"."
365369
msgstr "Event-Caches können keine \"Wartung benötigen\"."
366370

367-
#: services/logs/submit/WebService.php:579
371+
#: services/logs/submit/WebService.php:561
368372
msgid "Your cache log entry was posted successfully."
369373
msgstr "Dein Log wurde veröffentlicht."
370374

okapi/services/caches/formatters/gpx/WebService.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
9595
$langpref = $request->get_parameter('langpref');
9696
if (!$langpref) $langpref = "en";
9797
$langprefs = explode("|", $langpref);
98-
foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'ns_oc', 'alt_wpts', 'mark_found') as $param)
98+
foreach (array('ns_ground', 'ns_gsak', 'ns_ox', 'ns_oc', 'mark_found') as $param)
9999
{
100100
$val = $request->get_parameter($param);
101101
if (!$val) $val = 'false';
@@ -104,10 +104,18 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
104104
$vars[$param] = ($val == 'true');
105105
}
106106

107+
$vars['alt_wpts'] = $request->get_parameter('alt_wpts');
108+
if ($vars['alt_wpts'] === null)
109+
$vars['alt_wpts'] = 'false';
110+
elseif (!in_array($vars['alt_wpts'], array('true', 'desc:table', 'false')))
111+
throw new InvalidParam('alt_wpts');
112+
if ($vars['alt_wpts'] != 'false' && (!$vars['ns_ground']))
113+
throw new BadRequest("In order for 'alt_wpts' to work you have to also include 'ns_ground' extensions.");
114+
107115
$vars['latest_logs'] = $request->get_parameter('latest_logs');
108116
if ($vars['latest_logs'] === null)
109117
$vars['latest_logs'] = 'false';
110-
else if (!in_array($vars['latest_logs'], array('true', 'user', 'false')))
118+
elseif (!in_array($vars['latest_logs'], array('true', 'user', 'false')))
111119
throw new InvalidParam('latest_logs');
112120
if ($vars['latest_logs'] != 'false' && (!$vars['ns_ground']))
113121
throw new BadRequest("In order for 'latest_logs' to work you have to also include 'ns_ground' extensions.");
@@ -217,7 +225,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
217225
$fields .= "|trackables";
218226
elseif ($vars['trackables'] == 'desc:count')
219227
$fields .= "|trackables_count";
220-
if ($vars['alt_wpts'] == 'true' || $location_source != 'default-coords')
228+
if ($vars['alt_wpts'] != 'false' || $location_source != 'default-coords')
221229
$fields .= "|alt_wpts";
222230
if ($vars['recommendations'] != 'none')
223231
$fields .= "|recommendations|founds";
@@ -425,7 +433,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
425433
# remove current alt waypoint
426434
unset($cache_ref['alt_wpts'][$alt_wpt_key]);
427435
# add original location as alternate
428-
if ($vars['alt_wpts'])
436+
if ($vars['alt_wpts'] != 'false')
429437
{
430438
$cache_ref['alt_wpts'][] = array(
431439
'name' => $cache_ref['code'].'-DEFAULT-COORDS',
@@ -489,7 +497,7 @@ public static function create_gpx(OkapiRequest $request, $flags = null)
489497
# Additional waypoints. Currently, we're not 100% sure if their entries should
490498
# be included in the GGZ file (the format is undocumented).
491499

492-
if (isset($cache_ref['alt_wpts'])) {
500+
if ($vars['alt_wpts'] == 'true') {
493501
$idx = 1;
494502
foreach ($cache_ref['alt_wpts'] as &$alt_wpt_ref) {
495503
if (!isset($alt_wpt_ref['ggz_entry'])) {

okapi/services/caches/formatters/gpx/docs.xml

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,29 @@
201201
and <b>latest_logs</b> arguments must be set to <b>true</b> in order for the logs to be included.
202202
</opt>
203203
<opt name='alt_wpts' default='false'>
204-
<p>Boolean. If <b>true</b> then we will include additional (alternate) waypoints in the response.
205-
These are all places associated with the cache.</p>
206-
<p>Combine this with <b>ns_gsak</b> if you want the result to include additional references between
207-
waypoints and their geocaches. Please note that not many applications are currently able to
208-
properly understand GSAK metadata.</p>
204+
<p>This argument controls if additional (alternate) waypoints are included
205+
in the response and how they are included. These are all places associated with
206+
the cache.</p>
207+
<ul>
208+
<li>
209+
<p><b>true</b> - include additional waypoints as &lt;wpt&gt; elements.
210+
They will be handled like separate geocaches, but represented -
211+
depending on the application - by special symbols or names.</p>
212+
<p>Combine this with <b>ns_gsak</b> if you want them to be appear as
213+
child waypoints of the geocache instead. Please note that some
214+
applications do not properly understand (and will ignore) GSAK child
215+
waypoint metadata,</p>
216+
</li>
217+
<li>
218+
<b>desc:table</b> - additional waypoints will be listed as a table in
219+
the cache description (<b>ns_ground</b> has to be <b>true</b>).
220+
Developers may customize the table's appearance by overriding CSS
221+
styles for the <i>okapi-alt-wpts</i> class,
222+
</li>
223+
<li>
224+
<p><b>false</b> - do not include additional waypoints.</p>
225+
</li>
226+
</ul>
209227
</opt>
210228
<opt name='mark_found' default='false'>
211229
<p>Boolean. If <b>true</b> then all caches which are already found, will be marked appropriately

okapi/services/caches/formatters/gpx/gpxfile.tpl.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@
114114
&lt;/ul&gt;
115115
<?php } ?>
116116
<?= Okapi::xmlescape($c['description']) ?>
117+
<?php if ($vars['alt_wpts'] == 'desc:table' && count($c['alt_wpts']) > 0) { /* Does user want us to include an additional waypoints table? */ ?>
118+
&lt;p&gt;&lt;b&gt;<?= _("Additional waypoints") ?>:&lt;/b&gt;&lt;/p&gt;
119+
&lt;table class="okapi-alt-wpts" style="magin-top: 0.5em; border-collapse: collapse;"&gt;
120+
<?php foreach ($c['alt_wpts'] as $w) { ?>
121+
&lt;tr&gt;
122+
&lt;td style="border: 1px solid black; padding: 0.5em"&gt;<?= $w['type_name'] ?>&lt;/td&gt;
123+
&lt;td style="border: 1px solid black; padding: 0.5em"&gt;<?= implode('&lt;br /&gt;', Okapi::format_location($w['location'])) ?>&lt;/td&gt;
124+
&lt;td style="border: 1px solid black; padding: 0.5em"&gt;<?= $w['description'] ?>&lt;/td&gt;
125+
&lt;/tr&gt;
126+
<?php } ?>
127+
&lt;/table&gt;
128+
<?php } ?>
117129
<?php if ((strpos($vars['images'], "descrefs:") === 0) && count($c['images']) > 0) { /* Does user want us to include <img> references in cache descriptions? */
118130
if ($vars['images'] == "descrefs:thumblinks") { ?>
119131
&lt;h2&gt;<?= _("Images") ?> (<?= count($c['images']) ?>)&lt;/h2&gt;
@@ -168,7 +180,7 @@
168180
<?php if ((in_array('gc:personal_note', $vars['my_notes'])) && ($c['my_notes'] != null)) { /* Does user want us to include personal notes? -> Issue 294 */ ?>
169181
<groundspeak:personal_note><?= Okapi::xmlescape($c['my_notes']) ?></groundspeak:personal_note>
170182
<?php } ?>
171-
<?php if ($vars['trackables'] == 'gc:travelbugs') { /* Does user want us to geokrets as GC trackables? */ ?>
183+
<?php if ($vars['trackables'] == 'gc:travelbugs') { /* Does user want us to include geokrets as GC trackables? */ ?>
172184
<groundspeak:travelbugs>
173185
<?php foreach ($c['trackables'] as $trackable) { ?>
174186
<groundspeak:travelbug id="<?= $trackable['id'] ?>" ref="<?= $trackable['code'] ?>">
@@ -249,7 +261,7 @@
249261
$cache_ref['ggz_entry']['file_len'] = ob_get_length() - $cache_ref['ggz_entry']['file_pos'];
250262
}
251263
?>
252-
<?php if ($vars['alt_wpts']) { ?>
264+
<?php if ($vars['alt_wpts'] == 'true') { ?>
253265
<?php foreach ($cache_ref['alt_wpts'] as &$wpt_ref) { ?>
254266
<?php
255267
if (isset($wpt_ref['ggz_entry'])) {

0 commit comments

Comments
 (0)