Preparation für multiple icon styles / improved code

This commit is contained in:
Michael 2024-11-09 14:39:32 +00:00
parent c8a4b67414
commit a4c5d7539c
368 changed files with 1949 additions and 1009 deletions

View file

@ -8,6 +8,7 @@
namespace Friendica\Model;
use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
use Friendica\Content\ContactSelector;
use Friendica\Content\Image;
use Friendica\Content\Post\Collection\PostMedias;
use Friendica\Content\Post\Entity\PostMedia;
@ -3375,7 +3376,7 @@ class Item
$item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
}
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network', 'has-media', 'quote-uri-id', 'post-type'];
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'author-gsid', 'guid', 'created', 'plink', 'network', 'has-media', 'quote-uri-id', 'post-type'];
$shared_uri_id = 0;
$shared_links = [];
@ -3383,7 +3384,7 @@ class Item
$shared = DI::contentItem()->getSharedPost($item, $fields);
if (!empty($shared['post'])) {
$shared_item = $shared['post'];
$shared_item = $shared['post'];
$shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']);
$shared_item['body'] = Post\Media::replaceImage($shared_item['body']);
$quote_uri_id = $shared['post']['uri-id'];
@ -3470,6 +3471,10 @@ class Item
unset($hook_data);
}
if (!empty($shared_item['uri-id'])) {
$s = self::replacePlatformIcon($s, $shared_item, $uid);
}
$hook_data = [
'item' => $item,
'html' => $s,
@ -3533,6 +3538,39 @@ class Item
return $hook_data['html'];
}
/**
* Replace the platform icon with the icon in the style selected by the user
*
* @param string $html
* @param array $item
* @param integer $uid
* @return string
*/
private static function replacePlatformIcon(string $html, array $item, int $uid): string
{
$dom = new \DOMDocument();
if (!@$dom->loadHTML($html)) {
return $html;
}
$svg = ContactSelector::networkToSVG($item['network'], $item['author-gsid'], '', $uid);
if (empty($svg)) {
return $html;
}
$xpath = new \DOMXPath($dom);
/** @var DOMElement $element */
foreach ($xpath->query("//img[@class='network-svg']") as $element) {
$src = $element->getAttributeNode('src')->nodeValue;
if ($src == $svg) {
continue;
}
$element_html = $element->ownerDocument->saveHTML($element);
$html = str_replace($element_html, str_replace($src, $svg, $element_html), $html);
}
return $html;
}
/**
* Modify links to pictures to links for the "Fancybox" gallery
*