Add origin plugin
This commit is contained in:
parent
e37a7ab9ec
commit
0e94b7b7f8
4 changed files with 90 additions and 0 deletions
2
plugins/origin/field.html
Normal file
2
plugins/origin/field.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<label for="lf_stuff"><i>Demo Stuff</i></label><br>
|
||||
<input type="text" name="lf_stuff" id="lf_stuff" value="%s" class="lf_input"><br>
|
1
plugins/origin/origin.meta
Normal file
1
plugins/origin/origin.meta
Normal file
|
@ -0,0 +1 @@
|
|||
description="For each link, add new field for origin of shaare"
|
84
plugins/origin/origin.php
Normal file
84
plugins/origin/origin.php
Normal file
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Plugin origin
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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 .'/demo_plugin/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);
|
||||
return trim($parts['host']);
|
||||
}
|
3
plugins/origin/render.html
Normal file
3
plugins/origin/render.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div class="origin clear">
|
||||
Origin -> <a href="%s">%s</a>
|
||||
</div>
|
Loading…
Reference in a new issue