@@ -258,41 +258,57 @@ private static function _call(OkapiRequest $request)
258
258
# Prepare our comment to be inserted into the database. This may require
259
259
# some reformatting which depends on the current OC installation.
260
260
261
- if (Settings::get ('OC_BRANCH ' ) == 'oc.de ' )
261
+ # OC sites store all comments in HTML format, while the 'text_html' field
262
+ # indicates their *original* format as delivered by the user. This
263
+ # allows processing the 'text' field contents without caring about the
264
+ # original format, while still being able to re-create the comment in
265
+ # its original form.
266
+
267
+ if ($ comment_format == 'plaintext ' )
262
268
{
263
- # OCDE stores all comments in HTML format, while the 'text_html' field
264
- # indicates their *original* format as delivered by the user. This
265
- # allows processing the 'text' field contents without caring about the
266
- # original format, while still being able to re-create the comment in
267
- # its original form. It requires us to HTML-encode plaintext comments
268
- # and to indicate this by setting 'html_text' to FALSE.
269
- #
270
- # For user-supplied HTML comments, OCDE requires us to do additional
271
- # HTML purification prior to the insertion into the database.
272
-
273
- if ($ comment_format == 'plaintext ' )
274
- {
275
- # This code is identical to the plaintext processing in OCDE code,
276
- # including a space handling bug: Multiple consecutive spaces will
277
- # get semantically lost in the generated HTML.
269
+ # This code is identical to the plaintext processing in OC code,
270
+ # including a space handling bug: Multiple consecutive spaces will
271
+ # get semantically lost in the generated HTML.
278
272
279
- $ formatted_comment = htmlspecialchars ($ comment , ENT_COMPAT );
280
- $ formatted_comment = nl2br ($ formatted_comment );
273
+ $ formatted_comment = htmlspecialchars ($ comment , ENT_COMPAT );
274
+ $ formatted_comment = nl2br ($ formatted_comment );
275
+
276
+ if (Settings::get ('OC_BRANCH ' ) == 'oc.de ' )
277
+ {
281
278
$ value_for_text_html_field = 0 ;
282
279
}
283
280
else
284
281
{
285
- if ($ comment_format == 'auto ' )
286
- {
287
- # 'Auto' is for backward compatibility. Before the "comment_format"
288
- # was introduced, OKAPI used a weird format in between (it allowed
289
- # HTML, but applied nl2br too).
282
+ # 'text_html' = 0 (false) is broken in OCPL code and has been
283
+ # deprecated; OCPL code was changed to always set it to 1 (true).
284
+ # For OKAPI, the value has been changed from 0 to 1 with commit
285
+ # cb7d222, after an email discussion with Harrie Klomp. This is
286
+ # an ID of the appropriate email thread:
287
+ #
288
+ # Message-ID: <22b643093838b151b300f969f699aa04@harrieklomp.be>
290
289
291
- $ formatted_comment = nl2br ($ comment );
292
- }
293
- else
294
- $ formatted_comment = $ comment ;
290
+ $ value_for_text_html_field = 1 ;
291
+ }
292
+ }
293
+ elseif ($ comment_format == 'auto ' )
294
+ {
295
+ # 'Auto' is for backward compatibility. Before the "comment_format"
296
+ # was introduced, OKAPI used a weird format in between (it allowed
297
+ # HTML, but applied nl2br too).
298
+
299
+ $ formatted_comment = nl2br ($ comment );
300
+ $ value_for_text_html_field = 1 ;
301
+ }
302
+ else
303
+ {
304
+ $ formatted_comment = $ comment ;
305
+
306
+ # For user-supplied HTML comments, OC sites require us to do
307
+ # additional HTML purification prior to the insertion into the
308
+ # database.
295
309
310
+ if (Settings::get ('OC_BRANCH ' ) == 'oc.de ' )
311
+ {
296
312
# NOTICE: We are including EXTERNAL OCDE library here! This
297
313
# code does not belong to OKAPI!
298
314
@@ -302,48 +318,35 @@ private static function _call(OkapiRequest $request)
302
318
303
319
$ purifier = new \OcHTMLPurifier ($ opt );
304
320
$ formatted_comment = $ purifier ->purify ($ formatted_comment );
305
- $ value_for_text_html_field = 1 ;
306
- }
307
- }
308
- else
309
- {
310
- # OCPL is even weirder. It also stores HTML-lized comments in the database
311
- # (it doesn't really matter if 'text_html' field is set to FALSE). OKAPI must
312
- # save it in HTML either way. However, escaping plain-text doesn't work!
313
- # If we put "<b>" in, it still gets converted to "<b>" before display!
314
- # NONE of this process is documented within OCPL code. OKAPI uses a dirty
315
- # "hack" to save PLAINTEXT comments (let us hope the hack will remain valid).
316
- #
317
- # OCPL doesn't require HTML purification prior to the database insertion.
318
- # HTML seems to be purified dynamically, before it is displayed.
319
-
320
- if ($ comment_format == 'plaintext ' )
321
- {
322
- $ formatted_comment = htmlspecialchars ($ comment , ENT_QUOTES );
323
- $ formatted_comment = nl2br ($ formatted_comment );
324
- $ formatted_comment = str_replace ("& " , "&#38; " , $ formatted_comment );
325
- $ formatted_comment = str_replace ("< " , "&#60; " , $ formatted_comment );
326
- $ formatted_comment = str_replace ("> " , "&#62; " , $ formatted_comment );
327
- #
328
- # The following was changed from 0 to 1 by Harrie Klomp. The discussion
329
- # regarding this change was exchanged via emails. This is an ID of the
330
- # appropriate email thread:
331
- #
332
- # Message-ID: <22b643093838b151b300f969f699aa04@harrieklomp.be>
333
- #
334
- $ value_for_text_html_field = 1 ;
335
- }
336
- elseif ($ comment_format == 'auto ' )
337
- {
338
- $ formatted_comment = nl2br ($ comment );
339
- $ value_for_text_html_field = 1 ;
340
321
}
341
322
else
342
323
{
343
- $ formatted_comment = $ comment ;
344
- $ value_for_text_html_field = 1 ;
324
+ # TODO: Add OCPL HTML filtering. The OCPL code for this is:
325
+
326
+ # require_once($rootpath . 'lib/class.inputfilter.php');
327
+ # $myFilter = new InputFilter($allowedtags, $allowedattr, 0, 0, 1);
328
+ # $log_text = $myFilter->process($log_text);
345
329
}
330
+
331
+ $ value_for_text_html_field = 1 ;
332
+ }
333
+
334
+ if (Settings::get ('OC_BRANCH ' ) == 'oc.pl ' )
335
+ {
336
+ # The HTML processing in OCPL code is broken. Effectively, it
337
+ # will decode < > and & (and maybe other things?)
338
+ # before display so that text contents may be interpreted as HTML.
339
+ # We work around this by applying a double-encoding for & < >:
340
+
341
+ $ formatted_comment = str_replace ("& " , "&#38; " , $ formatted_comment );
342
+ $ formatted_comment = str_replace ("< " , "&#60; " , $ formatted_comment );
343
+ $ formatted_comment = str_replace ("> " , "&#62; " , $ formatted_comment );
344
+
345
+ # Note: This problem also exists when submitting logs on OCPL websites.
346
+ # If you e.g. enter "<text>" in the editor, it will get lost.
347
+ # See https://github.com/opencaching/opencaching-pl/issues/469.
346
348
}
349
+
347
350
unset($ comment );
348
351
349
352
# Prevent bug #367. Start the transaction and lock all the rows of this
0 commit comments