shaarli-plugin-clickat/clickat.php

28 lines
922 B
PHP
Raw Normal View History

2020-10-14 00:12:16 +02:00
<?php
/**
2020-10-14 12:47:42 +02:00
* ClickAt
2020-10-14 00:12:16 +02:00
*
* This plugin makes microblogging social networks (Twitter/X, Threads, Bluesky and Fediverse) addresses clickable.
2020-10-14 00:12:16 +02:00
*/
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Render\TemplatePage;
function hook_clickat_render_linklist($data)
{
2024-01-27 17:43:56 +01:00
$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>'
2024-02-11 21:50:03 +01:00
);
foreach ($data['links'] as &$value) {
if (strpos($value['description'], ' @') !== false) {
foreach($patterns as $nic => $link) {
$value['description'] = preg_replace($nic, $link, $value['description']);
2024-02-11 21:50:03 +01:00
}
}
}
2020-10-14 00:12:16 +02:00
return $data;
}