Merge pull request #4598 from MrPetovan/spoiler-cache
Fix for CW: Items weren't cached (alt)
This commit is contained in:
commit
fc6576fd83
1 changed files with 19 additions and 10 deletions
|
@ -1169,17 +1169,18 @@ 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" and "rendered-hash"
|
||||||
|
*/
|
||||||
function put_item_in_cache(&$item, $update = false)
|
function put_item_in_cache(&$item, $update = false)
|
||||||
{
|
{
|
||||||
$rendered_hash = defaults($item, 'rendered-hash', '');
|
|
||||||
|
|
||||||
if ($rendered_hash == ''
|
|
||||||
|| $item["rendered-html"] == ""
|
|
||||||
|| $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"];
|
$body = $item["body"];
|
||||||
|
|
||||||
// Add the content warning
|
// Add the content warning
|
||||||
|
@ -1187,18 +1188,26 @@ function put_item_in_cache(&$item, $update = false)
|
||||||
$item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]';
|
$item["body"] = $item['content-warning'] . '[spoiler]' . $item["body"] . '[/spoiler]';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rendered_hash = defaults($item, 'rendered-hash', '');
|
||||||
|
|
||||||
|
if ($rendered_hash == ''
|
||||||
|
|| $item["rendered-html"] == ""
|
||||||
|
|| $rendered_hash != hash("md5", $item["body"])
|
||||||
|
|| Config::get("system", "ignore_cache")
|
||||||
|
) {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
redir_private_images($a, $item);
|
redir_private_images($a, $item);
|
||||||
|
|
||||||
$item["rendered-html"] = prepare_text($item["body"]);
|
$item["rendered-html"] = prepare_text($item["body"]);
|
||||||
$item["rendered-hash"] = hash("md5", $item["body"]);
|
$item["rendered-hash"] = hash("md5", $item["body"]);
|
||||||
$item["body"] = $body;
|
|
||||||
|
|
||||||
if ($update && ($item["id"] > 0)) {
|
if ($update && ($item["id"] > 0)) {
|
||||||
dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]],
|
dba::update('item', ['rendered-html' => $item["rendered-html"], 'rendered-hash' => $item["rendered-hash"]],
|
||||||
['id' => $item["id"]], false);
|
['id' => $item["id"]], false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$item["body"] = $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue