@@ -34,7 +34,7 @@ public static function options()
34
34
'is_ignored ' , 'willattends ' , 'country ' , 'state ' , 'preview_image ' ,
35
35
'trip_time ' , 'trip_distance ' , 'attribution_note ' ,'gc_code ' , 'hint2 ' , 'hints2 ' ,
36
36
'protection_areas ' , 'short_description ' , 'short_descriptions ' , 'needs_maintenance ' ,
37
- 'watchers ' , 'is_rated ' , 'is_recommended ' );
37
+ 'watchers ' , 'is_rated ' , 'is_recommended ' , ' oc_team_annotation ' );
38
38
39
39
public static function call (OkapiRequest $ request )
40
40
{
@@ -66,17 +66,17 @@ public static function call(OkapiRequest $request)
66
66
if (!in_array ($ field , self ::$ valid_field_names ))
67
67
throw new InvalidParam ('fields ' , "' $ field' is not a valid field code. " );
68
68
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.
72
72
73
- $ fields_to_remove_later = array (' empty_descriptions ' );
73
+ $ fields_to_remove_later = array ();
74
74
if (
75
75
in_array ('description ' , $ fields ) || in_array ('descriptions ' , $ fields )
76
76
|| in_array ('short_description ' , $ fields ) || in_array ('short_descriptions ' , $ fields )
77
77
|| in_array ('hint ' , $ fields ) || in_array ('hints ' , $ fields )
78
78
|| 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 )
80
80
)
81
81
{
82
82
if (!in_array ('owner ' , $ fields ))
@@ -96,6 +96,13 @@ public static function call(OkapiRequest $request)
96
96
if (!in_array ($ attribution_append , array ('none ' , 'static ' , 'full ' )))
97
97
throw new InvalidParam ('attribution_append ' );
98
98
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
+
99
106
$ user_uuid = $ request ->get_parameter ('user_uuid ' );
100
107
if ($ user_uuid != null )
101
108
{
@@ -350,6 +357,7 @@ public static function call(OkapiRequest $request)
350
357
case 'alt_wpts ' : /* handled separately */ break ;
351
358
case 'country ' : /* handled separately */ break ;
352
359
case 'state ' : /* handled separately */ break ;
360
+ case 'oc_team_annotation ' : /* handled separately */ break ;
353
361
case 'last_found ' : $ entry ['last_found ' ] = ($ row ['last_found ' ] > '1980 ' ) ? date ('c ' , strtotime ($ row ['last_found ' ])) : null ; break ;
354
362
case 'last_modified ' : $ entry ['last_modified ' ] = date ('c ' , strtotime ($ row ['last_modified ' ])); break ;
355
363
case 'date_created ' : $ entry ['date_created ' ] = date ('c ' , strtotime ($ row ['date_created ' ])); break ;
@@ -555,7 +563,8 @@ public static function call(OkapiRequest $request)
555
563
if (in_array ('description ' , $ fields ) || in_array ('descriptions ' , $ fields )
556
564
|| in_array ('short_description ' , $ fields ) || in_array ('short_descriptions ' , $ fields )
557
565
|| 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 ))
559
568
{
560
569
# At first, we will fill all those fields, even if user requested just one
561
570
# of them. We will chop off the unwanted ones at the end.
@@ -567,12 +576,21 @@ public static function call(OkapiRequest $request)
567
576
$ result_ref ['empty_descriptions ' ] = [];
568
577
$ result_ref ['hints ' ] = new ArrayObject ();
569
578
$ result_ref ['hints2 ' ] = new ArrayObject ();
579
+ $ result_ref ['oc_team_annotations ' ] = new ArrayObject ();
570
580
}
581
+ $ fields_to_remove_later [] = 'empty_descriptions ' ;
582
+ $ fields_to_remove_later [] = 'oc_team_annotations ' ;
571
583
572
584
# Get cache descriptions and hints.
573
585
586
+ if (Settings::get ('OC_BRANCH ' ) == 'oc.pl ' )
587
+ $ oc_team_annotation_SQL = 'rr_comment ' ;
588
+ else
589
+ $ oc_team_annotation_SQL = "null " ;
574
590
$ 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
576
594
from cache_desc
577
595
where cache_id in (' " .implode ("',' " , array_map ('\okapi\core\Db::escape_string ' , array_keys ($ cacheid2wptcode )))."')
578
596
" );
@@ -588,7 +606,8 @@ public static function call(OkapiRequest $request)
588
606
$ language = strtolower ($ row ['language ' ]);
589
607
590
608
$ 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 )
592
611
{
593
612
/* Note, that the "owner" and "internal_id" fields are automatically included,
594
613
* whenever the cache description is included. */
@@ -610,6 +629,24 @@ public static function call(OkapiRequest $request)
610
629
);
611
630
Okapi::gettext_domain_restore ();
612
631
}
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
+ }
613
650
if ($ row ['desc ' ] && $ attribution_append != 'none ' )
614
651
{
615
652
$ tmp .= "\n<p><em> " .
@@ -635,9 +672,14 @@ public static function call(OkapiRequest $request)
635
672
$ results [$ cache_code ]['hints2 ' ][$ language ]
636
673
= htmlspecialchars_decode (mb_ereg_replace ("<br /> " , "" , $ row ['hint ' ]), ENT_COMPAT );
637
674
}
675
+ if ($ row ['oc_team_annotation ' ])
676
+ {
677
+ $ results [$ cache_code ]['oc_team_annotations ' ][$ language ] = $ row ['oc_team_annotation ' ];
678
+ }
638
679
}
639
680
unset($ listing_is_outdated );
640
681
unset($ language );
682
+ unset($ include_team_annotation );
641
683
642
684
foreach ($ results as &$ result_ref )
643
685
{
@@ -653,13 +695,19 @@ public static function call(OkapiRequest $request)
653
695
$ result_ref ['description ' ] = Okapi::pick_best_language ($ result_ref ['descriptions ' ], $ langprefs );
654
696
$ result_ref ['hint ' ] = Okapi::pick_best_language ($ result_ref ['hints ' ], $ langprefs );
655
697
$ 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 );
656
704
}
657
705
658
706
# Remove unwanted fields.
659
707
660
708
foreach (array (
661
709
'short_description ' , 'short_descriptions ' , 'description ' , 'descriptions ' ,
662
- 'hint ' , 'hints ' , 'hint2 ' , 'hints2 '
710
+ 'hint ' , 'hints ' , 'hint2 ' , 'hints2 ' , ' oc_team_annotation ' ,
663
711
) as $ field )
664
712
if (!in_array ($ field , $ fields ))
665
713
foreach ($ results as &$ result_ref )
0 commit comments