diff --git a/README.md b/README.md index 5860a67..e1b41fb 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,17 @@ social networks (Twitter/𝕏, Threads, Bluesky and Fediverse) addresses clickab ## Manual -1. Clone repository in plugin directory. +1. Clone repository in `plugins` directory (plugin directory name must be `clickat`) +``` +$ git clone https://forge.tourmentine.com/n/shaarli-plugin-clickat.git path/to/shaarli/plugins/clickat +``` 2. Activate plugin. 3. Quote users from: - Twitter/𝕏 with their `@nic`, - Threads with `@nic@threads.net`, - Bluesky with `@nic.bsky.social`, - Fediverse with `@nic@instance`. + +## Caveats + +For now addresses need to be proceded by an empty space. diff --git a/clickat.php b/clickat.php index 0175e02..307bd75 100644 --- a/clickat.php +++ b/clickat.php @@ -11,23 +11,15 @@ use Shaarli\Render\TemplatePage; function hook_clickat_render_linklist($data) { - + $patterns = array( + '/\ @([\w\d]+).bsky.social/' => ' @\1.bsky.social', + '/\ @([\w\d]+)@([\w\d_\-\.]+)/' => ' @\1', + '/\ @([\w\d]+)/' => ' @\1' + ); foreach ($data['links'] as &$value) { - $value['description'] = preg_replace( - '/\ @([\w\d]+).bsky.social/', - ' @\1.bsky.social', - $value['description'] - ); - $value['description'] = preg_replace( - '/\ @([\w\d]+)@([\w\d_\-\.]+)/', - ' @\1', - $value['description'] - ); - $value['description'] = preg_replace( - '/\ @([\w\d]+)/', - ' @\1', - $value['description'] - ); + foreach($patterns as $nic => $link) { + $value['description'] = preg_replace($nic, $link, $value['description']); + } } return $data; }