From a3e350313d5332ebe6ee40b544e34900daeeb004 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Wed, 23 Oct 2019 00:20:44 +0200 Subject: [PATCH] Move redir_private_images to Item::addRedirLinkToImageLinks() --- include/text.php | 24 ------------------------ src/Model/Item.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/text.php b/include/text.php index cc4b8e128e..1b06819570 100644 --- a/include/text.php +++ b/include/text.php @@ -104,30 +104,6 @@ function qp($s) { return str_replace("%", "=", rawurlencode($s)); } -/** - * @brief Find any non-embedded images in private items and add redir links to them - * - * @param App $a - * @param array &$item The field array of an item row - */ -function redir_private_images($a, &$item) -{ - $matches = []; - $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER); - if ($cnt) { - foreach ($matches as $mtch) { - if (strpos($mtch[1], '/redir') !== false) { - continue; - } - - if ((local_user() == $item['uid']) && ($item['private'] == 1) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == Protocol::DFRN)) { - $img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]); - $item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']); - } - } - } -} - /** * @brief Given a text string, convert from bbcode to html and add smilie icons. * diff --git a/src/Model/Item.php b/src/Model/Item.php index ff0f46676f..650390e529 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3342,8 +3342,7 @@ class Item extends BaseObject || $rendered_hash != hash("md5", $item["body"]) || Config::get("system", "ignore_cache") ) { - $a = self::getApp(); - redir_private_images($a, $item); + self::addRedirLinkToImageLinks($item); $item["rendered-html"] = prepare_text($item["body"]); $item["rendered-hash"] = hash("md5", $item["body"]); @@ -3378,6 +3377,31 @@ class Item extends BaseObject $item["body"] = $body; } + /** + * @brief Find any non-embedded images in private items and add redir links to them + * + * @param array &$item The field array of an item row + */ + private static function addRedirLinkToImageLinks(array &$item) + { + $app = self::getApp(); + + $matches = []; + $cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER); + if ($cnt) { + foreach ($matches as $mtch) { + if (strpos($mtch[1], '/redir') !== false) { + continue; + } + + if ((local_user() == $item['uid']) && ($item['private'] == 1) && ($item['contact-id'] != $app->contact['id']) && ($item['network'] == Protocol::DFRN)) { + $img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]); + $item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']); + } + } + } + } + /** * @brief Given an item array, convert the body element from bbcode to html and add smilie icons. * If attach is true, also add icons for item attachments.