MyShaarli/plugins/origin/origin.php
Knah Tsaeb 984073a980 Release v0.11.0
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEWe5LuNiFNDXAgI8BOzJIyqqwgW4FAl08H7AACgkQOzJIyqqw
 gW4dEw/9F55N9HMK1xTByxsnrMihjzBaKKc1lBBNJizAXrX2QchgnhE15ATRnQNy
 /7GUU8hCRukBsffMp7Ve1tbPkVvQwWgyQn2Hpp+ayGNWgQYrU1jNSaCQcbyxybyP
 6e+8DFAdDsleHiYCSZBPUHMpiJyQWsVBDV1wQPRrqvm+JYE3+9IwHzm+9/y4sk55
 7bp5Mj7fYyts5AJfLj9gxg2juGRnnhKXGWj2WI4Yk1mpwQLFSf43wC8lFf0ASY1J
 PfhjwOOFCRv/7LOL66nIPp74+pKcyO/S8p2m/pFNgrHL2bJXaAmFMPmYQjyoFmaA
 83iM5Jv3fBXMSf/iHnPvQlD0nmIvXUeu5ftBUIE/C4Uwu8LZTlOsPelW1dH5ygGa
 TVaA3/vlRhDWATe9mRNrHPHQT3VoxHg8U3qIv3p3cakj1uRFaFvkKhI7dEoqFSJY
 zsmISLbPMbmvJkMMNT4sI2q3ioyGDiU0OSayKocJziiu/H9+c2Pdty3YOSvJp/SX
 sjgqSX/hwtNmpQnS63dweDLoBGWjj01MYgedI9r64kmfW3QoSYsdVfykEMHIfofw
 /g8hRMBmuzK0VuDrla6DIBl7s58w0Uepr+e/lFMI4pzwHzxzUCZ5lc6wG0yCxuq2
 R+wTbpLqeXghKIaprmxq9i1TnAiCIl+lmw9zKj3M3fXwBGQ8e4I=
 =c7Xq
 -----END PGP SIGNATURE-----

Merge tag 'v0.11.0' into myShaarli_commu

Release v0.11.0
2019-08-12 14:16:22 +02:00

118 lines
2.7 KiB
PHP

<?php
/**
* Plugin origin
*/
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Router;
/**
* Hook render_editlink.
*
* Template placeholders:
* - field_plugin: add link fields after tags.
*
* @param array $data data passed to plugin
*
* @return array altered $data.
*/
function hook_origin_render_editlink($data)
{
// Load HTML into a string
$html = file_get_contents(PluginManager::$PLUGINS_PATH .'/origin/field.html');
// replace value in HTML if it exists in $data
if (!empty($data['link']['via'])) {
$html = sprintf($html, $data['link']['via']);
} else {
$html = sprintf($html, '');
}
// field_plugin
$data['edit_link_plugin'][] = $html;
return $data;
}
/**
* Hook savelink.
*
* Triggered when a link is save (new or edit).
*
* @param array $data contains the new link data.
*
* @return array altered $data.
*/
function hook_origin_save_link($data)
{
// Save link added in editlink field
if (!empty($_POST['lf_origin'])) {
$data['via'] = escape($_POST['lf_origin']);
}
return $data;
}
/**
* Add externalThumbshot icon to link_plugin when rendering linklist.
*
* @param mixed $data - linklist data.
*
* @return mixed - linklist data with readityourself plugin.
*/
function hook_origin_render_linklist($data,$conf)
{
$origin_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/origin/render.html');
foreach ($data['links'] as &$value) {
if(!empty($value['via'])){
$host = getJustDomain($value['via']);
$origin = sprintf($origin_html, $value['via'], $host);
$value['description'] = $value['description'].$origin;
}
}
return $data;
}
// Try to get just domain for @via
function getJustDomain($url) {
$parts = parse_url($url);
if(!empty($parts['host'])){
return trim($parts['host']);
} else {
return false;
}
}
/**
* Execute render_feed hook.
* Called with ATOM and RSS feed.
*
* Special data keys:
* - _PAGE_: current page
* - _LOGGEDIN_: true/false
*
* @param array $data data passed to plugin
*
* @return array altered $data.
*/
function hook_origin_render_feed($data)
{
$origin_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/origin/render.html');
foreach ($data['links'] as &$value) {
if(!empty($value['via'])){
$host = getJustDomain($value['via']);
$origin = sprintf($origin_html, $value['via'], $host);
$value['description'] = $value['description'].$origin;
}
}
return $data;
}