Move redir_private_images to Item::addRedirLinkToImageLinks()

This commit is contained in:
Philipp Holzer 2019-10-23 00:20:44 +02:00
parent 4704bf6394
commit a3e350313d
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
2 changed files with 26 additions and 26 deletions

View file

@ -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.
*

View file

@ -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.