Add filter for note

This commit is contained in:
Knah Tsaeb 2018-10-05 15:32:27 +02:00
parent ee610d4505
commit 71071f144a
1 changed files with 88 additions and 74 deletions

View File

@ -4,28 +4,27 @@
* Plugin externalThumbshot * Plugin externalThumbshot
*/ */
/** /**
* Init function, return an error if the server is not set. * Init function, return an error if the server is not set.
* *
* @param $conf ConfigManager instance. * @param $conf ConfigManager instance.
* *
* @return array Eventual error. * @return array Eventual error.
*/ */
function myShaarli_init($conf) function myShaarli_init($conf)
{ {
if (empty($conf->get('plugins.ExternalThumbshot_URL'))) { if (empty($conf->get('plugins.ExternalThumbshot_URL'))) {
$error = 'myShaarli plugin error: '. $error = 'myShaarli plugin error: ' .
'Please define the "ExternalThumbshot_URL" setting in the plugin administration page.'; 'Please define the "ExternalThumbshot_URL" setting in the plugin administration page.';
return array($error); return array($error);
} }
if ($conf->get('resource.theme') !== 'myShaarli' AND $conf->get('resource.theme') !== 'myShaarli_Columns') { if ($conf->get('resource.theme') !== 'myShaarli' and $conf->get('resource.theme') !== 'myShaarli_Columns') {
$error = 'myShaarli plugin: '. $error = 'myShaarli plugin: ' .
'This plugin need modification of template. Use myShaarli theme for test.'; 'This plugin need modification of template. Use myShaarli theme for test.';
return array($error); return array($error);
} }
$conf->set('thumbnails.mode', 'none'); $conf->set('thumbnails.mode', 'none');
} }
/** /**
* Add externalThumbshot icon to link_plugin when rendering linklist. * Add externalThumbshot icon to link_plugin when rendering linklist.
@ -35,10 +34,23 @@
* @return mixed - linklist data with readityourself plugin. * @return mixed - linklist data with readityourself plugin.
*/ */
function hook_myShaarli_render_linklist($data,$conf) function hook_myShaarli_render_linklist($data, $conf)
{ {
$thumUrl = $conf->get('plugins.ExternalThumbshot_URL'); $action = array(
if(!empty($conf->get('plugins.ExternalThumbshot_KEY'))){ 'attr' => array(
'href' => '?searchtags=note',
'title' => 'Note',
),
'html' => '<i class="fa fa-sticky-note"> </i>',
);
if (isset($_GET['searchtags']) && $_GET['searchtags'] === 'note') {
$action['on'] = true;
} else {
$action['off'] = true;
}
$data['action_plugin'][] = $action;
$thumUrl = $conf->get('plugins.ExternalThumbshot_URL');
if (!empty($conf->get('plugins.ExternalThumbshot_KEY'))) {
$key = $conf->get('plugins.ExternalThumbshot_KEY'); $key = $conf->get('plugins.ExternalThumbshot_KEY');
} }
if (!isset($thumUrl)) { if (!isset($thumUrl)) {
@ -47,28 +59,28 @@ function hook_myShaarli_render_linklist($data,$conf)
foreach ($data['links'] as &$value) { foreach ($data['links'] as &$value) {
//$thumb = computeThumbnail($conf, $value['url']); //$thumb = computeThumbnail($conf, $value['url']);
if(empty($thumb)){ if (empty($thumb)) {
if(!empty($key)){ if (!empty($key)) {
$hmac = '&amp;hm='.hash_hmac('sha1', $value['url'], $key).'&amp;url='; $hmac = '&amp;hm=' . hash_hmac('sha1', $value['url'], $key) . '&amp;url=';
} else { } else {
$hmac = null; $hmac = null;
} }
$value['thumbnail'] = $thumUrl.$hmac.urlencode($value['url']); $value['thumbnail'] = $thumUrl . $hmac . urlencode($value['url']);
} else { } else {
$value['thumbnail'] = $thumb['src']; $value['thumbnail'] = $thumb['src'];
} }
if(empty($value['favicon'])){ if (empty($value['favicon'])) {
if(!empty($key)){ if (!empty($key)) {
$hmac = '&amp;t=fav&amp;hm='.hash_hmac('sha1', $value['url'], $key).'&amp;url='; $hmac = '&amp;t=fav&amp;hm=' . hash_hmac('sha1', $value['url'], $key) . '&amp;url=';
} else { } else {
$hmac = null; $hmac = null;
} }
$value['favicon'] = $thumUrl.$hmac.urlencode($value['url']); $value['favicon'] = $thumUrl . $hmac . urlencode($value['url']);
} else { } else {
$value['favicon'] = $thumb['src']; $value['favicon'] = $thumb['src'];
} }
} }
return $data; return $data;
@ -82,10 +94,10 @@ function hook_myShaarli_render_linklist($data,$conf)
* @return mixed - linklist data with readityourself plugin. * @return mixed - linklist data with readityourself plugin.
*/ */
function hook_myShaarli_render_daily($data,$conf) function hook_myShaarli_render_daily($data, $conf)
{ {
$thumUrl = $conf->get('plugins.ExternalThumbshot_URL'); $thumUrl = $conf->get('plugins.ExternalThumbshot_URL');
if(!empty($conf->get('plugins.ExternalThumbshot_KEY'))){ if (!empty($conf->get('plugins.ExternalThumbshot_KEY'))) {
$key = $conf->get('plugins.ExternalThumbshot_KEY'); $key = $conf->get('plugins.ExternalThumbshot_KEY');
} }
if (!isset($thumUrl)) { if (!isset($thumUrl)) {
@ -94,16 +106,16 @@ function hook_myShaarli_render_daily($data,$conf)
foreach ($data['linksToDisplay'] as &$value) { foreach ($data['linksToDisplay'] as &$value) {
//$thumb = computeThumbnail($conf, $value['url']); //$thumb = computeThumbnail($conf, $value['url']);
if(empty($thumb)){ if (empty($thumb)) {
if(!empty($key)){ if (!empty($key)) {
$hmac = '&amp;hm='.hash_hmac('sha1', $value['url'], $key).'&amp;url='; $hmac = '&amp;hm=' . hash_hmac('sha1', $value['url'], $key) . '&amp;url=';
} else { } else {
$hmac = null; $hmac = null;
} }
$value['thumbnail'] = $thumUrl.$hmac.urlencode($value['url']); $value['thumbnail'] = $thumUrl . $hmac . urlencode($value['url']);
} else { } else {
$value['thumbnail'] = $thumb['src']; $value['thumbnail'] = $thumb['src'];
} }
} }
return $data; return $data;
@ -114,44 +126,46 @@ function hook_myShaarli_render_daily($data,$conf)
*/ */
function hook_myShaarli_render_footer($data) function hook_myShaarli_render_footer($data)
{ {
if(file_exists('contact.php')){ if (file_exists('contact.php')) {
$data['text'][] = '<br><a href="https://forge.leslibres.org/Knah-Tsaeb/MyShaarli">MyShaarli</a> is a fork of Shaarli.<a href="contact.php">Contact</a>'; $data['text'][] = '<br><a href="https://forge.leslibres.org/Knah-Tsaeb/MyShaarli">MyShaarli</a> is a fork of Shaarli.<a href="contact.php">Contact</a>';
} }
return $data; return $data;
} }
/** /**
* NOT WORKING * Hook render_editlink.
* To poor performance *
* Need fix * Template placeholders:
*/ * - field_plugin: add link fields after tags.
*
function returnFavicon($url) * @param array $data data passed to plugin
*
* @return array altered $data.
*/
function hook_myShaarli_render_editlink($data)
{ {
$faviconHash = md5($url); if ((int) $data['link_is_new'] === 1 && $data['link']['url'][0] === '?' && strlen($data['link']['url']) === 7) {
$path = substr($faviconHash, 0, 2).'/'.substr($faviconHash, 2, 2); $data['link']['tags'] = 'note ';
$faviconPath = 'cache/'.$path.'/'.$faviconHash.'.ico';
if (file_exists($faviconPath)) {
$content = file_get_contents($faviconPath);
return '<img class="favicon" alt="favicon" src="data:image/ico;base64,'.base64_encode($content).'"/>';
} }
if (file_exists('cache/'.$path.'/'.$faviconHash)) { return $data;
return; }
}
require_once 'plugins/myShaarli/favicon/DataAccess.php'; /**
require_once 'plugins/myShaarli/favicon/Favicon.php';
$favicon = new \Favicon\Favicon(); Améliore la sortie print
$favicon->cache(array('dir' => 'cache')); @author Tatane http://www.tatane.info/index.php/print_rn
$urlOfFavicon = $favicon->get($url); @author http://www.blog.cactuscrew.com/77-print_rn.html
if (!$urlOfFavicon) { @param $data (array) tableau ou variable à examiner
mkdir('cache/'.$path, 0777, true); @param $name (string) nom a afficher
touch('cache/'.$path.'/'.$faviconHash); @return false affiche les clef valeur du tableau $data
return; @example n_print($array, 'Tableau de valeur');
} */
if (!is_dir('cache/'.$path.'/')) { function n_print($data, $name = '')
mkdir('cache/'.$path, 0777, true); {
} $aBackTrace = debug_backtrace();
$content = file_get_contents($urlOfFavicon); echo '<h2>', $name, '</h2>';
file_put_contents($faviconPath, $content); echo '<fieldset style="border: 1px solid orange; padding: 5px;color: <a href="?addtag=333" title="Hashtag 333">#333</a>; background-color: <a href="?addtag=fff" title="Hashtag fff">#fff</a>;">';
return '<img class="favicon" alt="favicon" src="data:image/ico;base64,'.base64_encode($content).'"/>'; echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />';
} }