cleanup (sorry Daily Shaarli)

This commit is contained in:
n 2020-10-14 12:47:42 +02:00
parent e25b3350c7
commit ee9d18be7f
1 changed files with 6 additions and 95 deletions

View File

@ -1,115 +1,26 @@
<?php
/**
* Demo Plugin.
* ClickAt
*
* 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_.
* This plugin makes Twitter and Fediverse addresses clickable.
*/
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']);
}
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;
}