improve networks loop

This commit is contained in:
n 2024-01-27 17:43:56 +01:00
parent 9a5eb1acf6
commit 80f7d336c6
Signed by: n
GPG Key ID: 510227DD6C502CE3
1 changed files with 8 additions and 16 deletions

View File

@ -11,23 +11,15 @@ use Shaarli\Render\TemplatePage;
function hook_clickat_render_linklist($data)
{
$patterns = array(
'/\ @([\w\d]+).bsky.social/' => ' <a href="https://bsky.app/profile/\1.bsky.social">&commat;\1.bsky.social</a>',
'/\ @([\w\d]+)@([\w\d_\-\.]+)/' => ' <a href="https://\2/@\1">&commat;\1</a>',
'/\ @([\w\d]+)/' => ' <a href="https://twitter.com/\1">&commat;\1</a>'
);
foreach ($data['links'] as &$value) {
$value['description'] = preg_replace(
'/\ @([\w\d]+).bsky.social/',
' <a href="https://bsky.app/profile/\1.bsky.social">&commat;\1.bsky.social</a>',
$value['description']
);
$value['description'] = preg_replace(
'/\ @([\w\d]+)@([\w\d_\-\.]+)/',
' <a href="https://\2/@\1">&commat;\1</a>',
$value['description']
);
$value['description'] = preg_replace(
'/\ @([\w\d]+)/',
' <a href="https://twitter.com/\1">&commat;\1</a>',
$value['description']
);
foreach($patterns as $nic => $link) {
$value['description'] = preg_replace($nic, $link, $value['description']);
}
}
return $data;
}