initial import

This commit is contained in:
n 2020-10-14 00:12:16 +02:00
commit c769184c4f
3 changed files with 124 additions and 0 deletions

8
README.md Normal file
View file

@ -0,0 +1,8 @@
## ClickAt
[Shaarli](https://github.com/shaarli/Shaarli/) plugin to make Twitter and Fediverse addresses clickable.
# Manual
1. Activate plugin.
2. Quote users from Twitter with their @nic, and users from the Fediverse with @nic@server.

1
clickat.meta Normal file
View file

@ -0,0 +1 @@
description="Make Twitter and Fediverse addresses clickable."

115
clickat.php Normal file
View file

@ -0,0 +1,115 @@
<?php
/**
* Demo Plugin.
*
* This plugin tries to completely cover Shaarli's plugin API.
* Can be used by plugin developers to make their own plugin.
*/
/*
* RENDER HEADER, INCLUDES, FOOTER
*
* Those hooks are called at every page rendering.
* You can filter its execution by checking _PAGE_ value
* and check user status with _LOGGEDIN_.
*/
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Render\TemplatePage;
/**
* In the footer hook, there is a working example of a translation extension for Shaarli.
*
* The extension must be attached to a new translation domain (i.e. NOT 'shaarli').
* Use case: any custom theme or non official plugin can use the translation system.
*
* See the documentation for more information.
*/
const EXT_TRANSLATION_DOMAIN = 'clickat';
/*
* This is not necessary, but it's easier if you don't want Poedit to mix up your translations.
*/
function clickat_t($text, $nText = '', $nb = 1)
{
return t($text, $nText, $nb, EXT_TRANSLATION_DOMAIN);
}
/**
* Initialization function.
* It will be called when the plugin is loaded.
* This function can be used to return a list of initialization errors.
*
* @param $conf ConfigManager instance.
*
* @return array List of errors (optional).
*/
function clickat_init($conf)
{
return $errors;
}
/*
* SPECIFIC PAGES
*/
/**
* Hook render_linklist.
*
* Template placeholders:
* - action_plugin: next to 'private only' button.
* - plugin_start_zone: page start
* - plugin_end_zone: page end
* - link_plugin: icons below each links.
*
* Data:
* - _LOGGEDIN_: true/false
*
* @param array $data data passed to plugin
*
* @return array altered $data.
*/
function hook_clickat_render_linklist($data)
{
/*
* Action links (action_plugin):
* A link is an array of its attributes (key="value"),
* and a mandatory `html` key, which contains its value.
* It's also recommended to add key 'on' or 'off' for theme rendering.
*/
return clickify($data);
}
/**
* Hook render_daily.
*
* Template placeholders:
* - plugin_start_zone: page start.
* - plugin_end_zone: page end.
*
* Data:
* - _LOGGEDIN_: true/false
*
* @param array $data data passed to plugin
*
* @return array altered $data.
*/
function hook_clickat_render_daily($data)
{
return clickify($data);
}
function clickify($data)
{
foreach ($data['links'] as &$value) {
$value['description'] = preg_replace('/@([\w\d]+)@([\w\d_\.]+)/','<a href="https://\2/users/\1">&commat;\1</a>',$value['description']);
$value['description'] = preg_replace('/@([\w\d]+)/','<a href="https://twitter.com/\1">&commat;\1</a>',$value['description']);
}
return $data;
}