Skip to content

Commit 34e67ab

Browse files
committed
Merged team-annotations
2 parents 0d171bd + 9802600 commit 34e67ab

File tree

3 files changed

+88
-10
lines changed

3 files changed

+88
-10
lines changed

okapi/services/caches/geocache/WebService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ public static function call(OkapiRequest $request)
3636
if ($user_logs_only === null) $user_logs_only = 'false';
3737
$attribution_append = $request->get_parameter('attribution_append');
3838
if (!$attribution_append) $attribution_append = 'full';
39+
$oc_team_annotation = $request->get_parameter('oc_team_annotation');
40+
if (!$oc_team_annotation) $oc_team_annotation = 'description';
3941
$params = array(
4042
'cache_codes' => $cache_code,
4143
'langpref' => $langpref,
4244
'fields' => $fields,
4345
'attribution_append' => $attribution_append,
46+
'oc_team_annotation' => $oc_team_annotation,
4447
'lpc' => $lpc,
4548
'log_fields' => $log_fields,
4649
'user_logs_only' => $user_logs_only,

okapi/services/caches/geocache/docs.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,23 @@
5151
</li>
5252
</ul>
5353
</opt>
54+
<opt name='oc_team_annotation' default='description' infotags='ocpl-specific'>
55+
<p>Opencaching team members may directly annotate geocache listings.
56+
This parameter controls how to retrieve those annotations:</p>
57+
<ul>
58+
<li><b>description</b> - inserts the OC team annotations into the
59+
description texts,</li>
60+
<li><b>separate</b> (recommended) - includes the <b>oc_team_annotation</b> field
61+
instead.</li>
62+
</ul>
63+
<p>Please note that you are REQUIRED to display OC team annotations
64+
alongside with the owner's cache listing. In this they differ from
65+
<i>OC team
66+
<a href="%OKAPI:methodargref:services/logs/entry%">log entries</a></i>,
67+
which will only be visible when logs are displayed.</p>
68+
<p>OC team annotations so far are only in use at OCPL-based sites.
69+
OCDE installations will ignore this parameter.</p>
70+
</opt>
5471
<opt name='lpc' default='10'>
5572
Log-entries per cache - the number of logs returned in the <b>latest_logs</b> field.
5673
This should be an integer or a special "all" value. Please note, that you must include
@@ -401,6 +418,16 @@
401418
names of the attributes with which the cache was tagged; the language will be
402419
selected based on the <b>langpref</b> parameter.
403420
</li>
421+
<li>
422+
<p>%OKAPI:infotag:ocpl-specific% <b>oc_team_annotation</b> - HTML text containing OC team annotations
423+
to the geocache listing. See the <b>oc_team_annotation</b> parameter for
424+
more information.</p>
425+
<p>Notices: The content of this field is not properly localized.
426+
It will only partially respond to the <b>langpref</b> parameter and may
427+
contain an arbitrary mixture of languages and differently localized data
428+
(<a href='https://github.com/opencaching/okapi/issues/533'>why?</a>).
429+
OCDE installations currently will always return an empty string.</p>
430+
</li>
404431
<li>
405432
<p><b>attribution_note</b> - the proper attribution note for the cache listing according
406433
to the local OC site's Data License. By default, this note is also appended to geocache

okapi/services/caches/geocaches/WebService.php

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function options()
3434
'is_ignored', 'willattends', 'country', 'state', 'preview_image',
3535
'trip_time', 'trip_distance', 'attribution_note','gc_code', 'hint2', 'hints2',
3636
'protection_areas', 'short_description', 'short_descriptions', 'needs_maintenance',
37-
'watchers', 'is_rated', 'is_recommended');
37+
'watchers', 'is_rated', 'is_recommended', 'oc_team_annotation');
3838

3939
public static function call(OkapiRequest $request)
4040
{
@@ -66,17 +66,17 @@ public static function call(OkapiRequest $request)
6666
if (!in_array($field, self::$valid_field_names))
6767
throw new InvalidParam('fields', "'$field' is not a valid field code.");
6868

69-
# Some fields need to be temporarily included whenever the "description"
70-
# or "attribution_note" field are included. That's a little ugly, but
71-
# helps performance and conforms to the DRY rule.
69+
# Some fields need to be temporarily included whenever a description-
70+
# related field is included. That's a little ugly, but helps performance
71+
# and conforms to the DRY rule.
7272

73-
$fields_to_remove_later = array('empty_descriptions');
73+
$fields_to_remove_later = array();
7474
if (
7575
in_array('description', $fields) || in_array('descriptions', $fields)
7676
|| in_array('short_description', $fields) || in_array('short_descriptions', $fields)
7777
|| in_array('hint', $fields) || in_array('hints', $fields)
7878
|| in_array('hint2', $fields) || in_array('hints2', $fields)
79-
|| in_array('attribution_note', $fields)
79+
|| in_array('attribution_note', $fields) || in_array('oc_team_annotation', $fields)
8080
)
8181
{
8282
if (!in_array('owner', $fields))
@@ -96,6 +96,13 @@ public static function call(OkapiRequest $request)
9696
if (!in_array($attribution_append, array('none', 'static', 'full')))
9797
throw new InvalidParam('attribution_append');
9898

99+
$oc_team_annotation = $request->get_parameter('oc_team_annotation');
100+
if (!$oc_team_annotation) $oc_team_annotation = 'description';
101+
if (!in_array($oc_team_annotation, array('description', 'separate')))
102+
throw new InvalidParam('oc_team_annotation');
103+
if ($oc_team_annotation == 'separate' && !in_array('oc_team_annotation', $fields))
104+
$fields[] = 'oc_team_annotation';
105+
99106
$user_uuid = $request->get_parameter('user_uuid');
100107
if ($user_uuid != null)
101108
{
@@ -350,6 +357,7 @@ public static function call(OkapiRequest $request)
350357
case 'alt_wpts': /* handled separately */ break;
351358
case 'country': /* handled separately */ break;
352359
case 'state': /* handled separately */ break;
360+
case 'oc_team_annotation': /* handled separately */ break;
353361
case 'last_found': $entry['last_found'] = ($row['last_found'] > '1980') ? date('c', strtotime($row['last_found'])) : null; break;
354362
case 'last_modified': $entry['last_modified'] = date('c', strtotime($row['last_modified'])); break;
355363
case 'date_created': $entry['date_created'] = date('c', strtotime($row['date_created'])); break;
@@ -555,7 +563,8 @@ public static function call(OkapiRequest $request)
555563
if (in_array('description', $fields) || in_array('descriptions', $fields)
556564
|| in_array('short_description', $fields) || in_array('short_descriptions', $fields)
557565
|| in_array('hint', $fields) || in_array('hints', $fields)
558-
|| in_array('hint2', $fields) || in_array('hints2', $fields))
566+
|| in_array('hint2', $fields) || in_array('hints2', $fields)
567+
|| in_array('oc_team_annotation', $fields))
559568
{
560569
# At first, we will fill all those fields, even if user requested just one
561570
# of them. We will chop off the unwanted ones at the end.
@@ -567,12 +576,21 @@ public static function call(OkapiRequest $request)
567576
$result_ref['empty_descriptions'] = [];
568577
$result_ref['hints'] = new ArrayObject();
569578
$result_ref['hints2'] = new ArrayObject();
579+
$result_ref['oc_team_annotations'] = new ArrayObject();
570580
}
581+
$fields_to_remove_later[] = 'empty_descriptions';
582+
$fields_to_remove_later[] = 'oc_team_annotations';
571583

572584
# Get cache descriptions and hints.
573585

586+
if (Settings::get('OC_BRANCH') == 'oc.pl')
587+
$oc_team_annotation_SQL = 'rr_comment';
588+
else
589+
$oc_team_annotation_SQL = "null";
574590
$rs = Db::query("
575-
select cache_id, language, `desc`, short_desc, hint
591+
select
592+
cache_id, language, `desc`, short_desc, hint,
593+
".$oc_team_annotation_SQL." as oc_team_annotation
576594
from cache_desc
577595
where cache_id in ('".implode("','", array_map('\okapi\core\Db::escape_string', array_keys($cacheid2wptcode)))."')
578596
");
@@ -588,7 +606,8 @@ public static function call(OkapiRequest $request)
588606
$language = strtolower($row['language']);
589607

590608
$listing_is_outdated = in_array($cache_code, $outdated_listings);
591-
if ($row['desc'] || $listing_is_outdated)
609+
$include_team_annotation = ($row['oc_team_annotation'] && $oc_team_annotation == 'description');
610+
if ($row['desc'] || $listing_is_outdated || $include_team_annotation)
592611
{
593612
/* Note, that the "owner" and "internal_id" fields are automatically included,
594613
* whenever the cache description is included. */
@@ -610,6 +629,24 @@ public static function call(OkapiRequest $request)
610629
);
611630
Okapi::gettext_domain_restore();
612631
}
632+
if ($include_team_annotation)
633+
{
634+
# Do some ugly hack so that annotations are readble without OC CSS:
635+
636+
$formatted_team_annotation = str_replace(
637+
'class="ocTeamCommentHeader"',
638+
'class="ocTeamCommentHeader" style="display: block; padding-top: 0.5em;"',
639+
$row['oc_team_annotation']
640+
);
641+
$tmp = (
642+
'<div class="ocTeamCommentSection">'.
643+
"<b>"._("Annotations by the Opencaching team:")."</b><br />\n".
644+
$formatted_team_annotation.
645+
"<span style='display: block; padding-top: 0.5em'>("._("End of annotations").")</span>".
646+
"<hr /></div>\n" .
647+
$tmp
648+
);
649+
}
613650
if ($row['desc'] && $attribution_append != 'none')
614651
{
615652
$tmp .= "\n<p><em>".
@@ -635,9 +672,14 @@ public static function call(OkapiRequest $request)
635672
$results[$cache_code]['hints2'][$language]
636673
= htmlspecialchars_decode(mb_ereg_replace("<br />", "" , $row['hint']), ENT_COMPAT);
637674
}
675+
if ($row['oc_team_annotation'])
676+
{
677+
$results[$cache_code]['oc_team_annotations'][$language] = $row['oc_team_annotation'];
678+
}
638679
}
639680
unset($listing_is_outdated);
640681
unset($language);
682+
unset($include_team_annotation);
641683

642684
foreach ($results as &$result_ref)
643685
{
@@ -653,13 +695,19 @@ public static function call(OkapiRequest $request)
653695
$result_ref['description'] = Okapi::pick_best_language($result_ref['descriptions'], $langprefs);
654696
$result_ref['hint'] = Okapi::pick_best_language($result_ref['hints'], $langprefs);
655697
$result_ref['hint2'] = Okapi::pick_best_language($result_ref['hints2'], $langprefs);
698+
699+
# OCPL currently stores the same team comments redundantly in all
700+
# descriptions of the geocache. We might pick any of them. Probably
701+
# they will be moved to the 'caches' table later (see issue #533).
702+
703+
$result_ref['oc_team_annotation'] = Okapi::pick_best_language($result_ref['oc_team_annotations'], $langprefs);
656704
}
657705

658706
# Remove unwanted fields.
659707

660708
foreach (array(
661709
'short_description', 'short_descriptions', 'description', 'descriptions',
662-
'hint', 'hints', 'hint2', 'hints2'
710+
'hint', 'hints', 'hint2', 'hints2', 'oc_team_annotation',
663711
) as $field)
664712
if (!in_array($field, $fields))
665713
foreach ($results as &$result_ref)

0 commit comments

Comments
 (0)