mirror of
https://github.com/friendica/friendica
synced 2024-12-23 03:20:15 +00:00
Add BBCode versioning
- This will trigger the re-conversion of displayed items on version update
This commit is contained in:
parent
a382798999
commit
e712706302
2 changed files with 18 additions and 14 deletions
|
@ -49,6 +49,9 @@ use Friendica\Util\XML;
|
|||
|
||||
class BBCode
|
||||
{
|
||||
// Update this value to the current date whenever changes are made to BBCode::convert
|
||||
const VERSION = '2020-12-03';
|
||||
|
||||
const INTERNAL = 0;
|
||||
const API = 2;
|
||||
const DIASPORA = 3;
|
||||
|
|
|
@ -3529,49 +3529,50 @@ class Item
|
|||
*/
|
||||
public static function putInCache(&$item, $update = false)
|
||||
{
|
||||
$body = $item["body"];
|
||||
// Save original body to prevent addons to modify it
|
||||
$body = $item['body'];
|
||||
|
||||
$rendered_hash = $item['rendered-hash'] ?? '';
|
||||
$rendered_html = $item['rendered-html'] ?? '';
|
||||
|
||||
if ($rendered_hash == ''
|
||||
|| $rendered_html == ""
|
||||
|| $rendered_hash != hash("md5", $item["body"])
|
||||
|| DI::config()->get("system", "ignore_cache")
|
||||
|| $rendered_html == ''
|
||||
|| $rendered_hash != BBCode::VERSION . '::' . hash('md5', $body)
|
||||
|| DI::config()->get('system', 'ignore_cache')
|
||||
) {
|
||||
self::addRedirToImageTags($item);
|
||||
|
||||
$item["rendered-html"] = BBCode::convert($item["body"]);
|
||||
$item["rendered-hash"] = hash("md5", $item["body"]);
|
||||
$item['rendered-html'] = BBCode::convert($item['body']);
|
||||
$item['rendered-hash'] = hash('md5', $body);
|
||||
|
||||
$hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']];
|
||||
Hook::callAll('put_item_in_cache', $hook_data);
|
||||
$item['rendered-html'] = $hook_data['rendered-html'];
|
||||
$item['rendered-hash'] = $hook_data['rendered-hash'];
|
||||
$item['rendered-hash'] = BBCode::VERSION . '::' . $hook_data['rendered-hash'];
|
||||
unset($hook_data);
|
||||
|
||||
// Force an update if the generated values differ from the existing ones
|
||||
if ($rendered_hash != $item["rendered-hash"]) {
|
||||
if ($rendered_hash != $item['rendered-hash']) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
// Only compare the HTML when we forcefully ignore the cache
|
||||
if (DI::config()->get("system", "ignore_cache") && ($rendered_html != $item["rendered-html"])) {
|
||||
if (DI::config()->get('system', 'ignore_cache') && ($rendered_html != $item['rendered-html'])) {
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($update && !empty($item["id"])) {
|
||||
if ($update && !empty($item['id'])) {
|
||||
self::update(
|
||||
[
|
||||
'rendered-html' => $item["rendered-html"],
|
||||
'rendered-hash' => $item["rendered-hash"]
|
||||
'rendered-html' => $item['rendered-html'],
|
||||
'rendered-hash' => $item['rendered-hash']
|
||||
],
|
||||
['id' => $item["id"]]
|
||||
['id' => $item['id']]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$item["body"] = $body;
|
||||
$item['body'] = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue