2018-01-04 14:49:40 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin origin
|
|
|
|
*/
|
|
|
|
|
2019-08-12 14:16:22 +02:00
|
|
|
use Shaarli\Config\ConfigManager;
|
|
|
|
use Shaarli\Plugin\PluginManager;
|
|
|
|
use Shaarli\Router;
|
|
|
|
|
2018-01-04 14:49:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2018-01-04 15:10:22 +01:00
|
|
|
$html = file_get_contents(PluginManager::$PLUGINS_PATH .'/origin/field.html');
|
2018-01-04 14:49:40 +01:00
|
|
|
|
|
|
|
// 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
|
2018-02-09 15:56:22 +01:00
|
|
|
function getJustDomain($url) {
|
2018-01-04 14:49:40 +01:00
|
|
|
$parts = parse_url($url);
|
2018-02-09 15:56:22 +01:00
|
|
|
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;
|
2018-01-04 14:49:40 +01:00
|
|
|
}
|