shaarli-plugin-clickat/clickat.php
n 1989307a67
All checks were successful
lint / lint (push) Successful in 14s
PHP Coding Standards fixes
2024-02-11 21:53:17 +01:00

27 lines
922 B
PHP

<?php
/**
* ClickAt
*
* This plugin makes microblogging social networks (Twitter/X, Threads, Bluesky and Fediverse) addresses clickable.
*/
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
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) {
if (strpos($value['description'], ' @') !== false) {
foreach($patterns as $nic => $link) {
$value['description'] = preg_replace($nic, $link, $value['description']);
}
}
}
return $data;
}