From e28020c68ab6bfadffd87eec3bff9e1f2e0fe439 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 15 Mar 2018 01:32:04 -0400 Subject: [PATCH 1/3] Fix for CW: Items weren't cached --- include/text.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/text.php b/include/text.php index 0aeaa7203b..00d401cfb3 100644 --- a/include/text.php +++ b/include/text.php @@ -1171,6 +1171,11 @@ function redir_private_images($a, &$item) function put_item_in_cache(&$item, $update = false) { + // Add the content warning + if (!empty($item['content-warning'])) { + $item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]'; + } + $rendered_hash = defaults($item, 'rendered-hash', ''); if ($rendered_hash == '' @@ -1182,11 +1187,6 @@ function put_item_in_cache(&$item, $update = false) // I'm not sure if we should store it permanently, so we save the old value. $body = $item["body"]; - // Add the content warning - if (!empty($item['content-warning'])) { - $item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]'; - } - $a = get_app(); redir_private_images($a, $item); From 644767519e8e8e39c0e138c6cce4ca8490753e39 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 15 Mar 2018 02:13:00 -0400 Subject: [PATCH 2/3] Ensure the item body stays the same in put_item_in_cache() - Add documentation --- include/text.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/include/text.php b/include/text.php index 00d401cfb3..cc7a985393 100644 --- a/include/text.php +++ b/include/text.php @@ -1169,8 +1169,20 @@ function redir_private_images($a, &$item) } } +/** + * Sets the "rendered-html" field of the provided item + * + * Body is preserved to avoid side-effects as we modify it just-in-time for spoilers and private image links + * + * @param array $item + * @param bool $update + * + * @todo Remove reference, simply return "rendered-html" + */ function put_item_in_cache(&$item, $update = false) { + $body = $item["body"]; + // Add the content warning if (!empty($item['content-warning'])) { $item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]'; @@ -1183,22 +1195,19 @@ function put_item_in_cache(&$item, $update = false) || $rendered_hash != hash("md5", $item["body"]) || Config::get("system", "ignore_cache") ) { - // The function "redir_private_images" changes the body. - // I'm not sure if we should store it permanently, so we save the old value. - $body = $item["body"]; - $a = get_app(); redir_private_images($a, $item); $item["rendered-html"] = prepare_text($item["body"]); $item["rendered-hash"] = hash("md5", $item["body"]); - $item["body"] = $body; if ($update && ($item["id"] > 0)) { dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]], ['id' => $item["id"]], false); } } + + $item["body"] = $body; } /** From c53c00ba4e51cc89ab8260cb64ba4dfb72427aea Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 15 Mar 2018 03:23:11 -0400 Subject: [PATCH 3/3] Add rendred-hash to put_item_in_cache todo --- include/text.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/text.php b/include/text.php index cc7a985393..a67527311f 100644 --- a/include/text.php +++ b/include/text.php @@ -1177,7 +1177,7 @@ function redir_private_images($a, &$item) * @param array $item * @param bool $update * - * @todo Remove reference, simply return "rendered-html" + * @todo Remove reference, simply return "rendered-html" and "rendered-hash" */ function put_item_in_cache(&$item, $update = false) {