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

@ -18,7 +18,7 @@
'Please define the "ExternalThumbshot_URL" setting in the plugin administration page.';
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: ' .
'This plugin need modification of template. Use myShaarli theme for test.';
return array($error);
@ -26,7 +26,6 @@
$conf->set('thumbnails.mode', 'none');
}
/**
* Add externalThumbshot icon to link_plugin when rendering linklist.
*
@ -37,6 +36,19 @@
function hook_myShaarli_render_linklist($data, $conf)
{
$action = array(
'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');
@ -121,37 +133,39 @@ function hook_myShaarli_render_footer($data)
}
/**
* NOT WORKING
* To poor performance
* Need fix
* Hook render_editlink.
*
* Template placeholders:
* - field_plugin: add link fields after tags.
*
* @param array $data data passed to plugin
*
* @return array altered $data.
*/
function returnFavicon($url)
function hook_myShaarli_render_editlink($data)
{
$faviconHash = md5($url);
$path = substr($faviconHash, 0, 2).'/'.substr($faviconHash, 2, 2);
$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 ((int) $data['link_is_new'] === 1 && $data['link']['url'][0] === '?' && strlen($data['link']['url']) === 7) {
$data['link']['tags'] = 'note ';
}
if (file_exists('cache/'.$path.'/'.$faviconHash)) {
return;
return $data;
}
require_once 'plugins/myShaarli/favicon/DataAccess.php';
require_once 'plugins/myShaarli/favicon/Favicon.php';
$favicon = new \Favicon\Favicon();
$favicon->cache(array('dir' => 'cache'));
$urlOfFavicon = $favicon->get($url);
if (!$urlOfFavicon) {
mkdir('cache/'.$path, 0777, true);
touch('cache/'.$path.'/'.$faviconHash);
return;
}
if (!is_dir('cache/'.$path.'/')) {
mkdir('cache/'.$path, 0777, true);
}
$content = file_get_contents($urlOfFavicon);
file_put_contents($faviconPath, $content);
return '<img class="favicon" alt="favicon" src="data:image/ico;base64,'.base64_encode($content).'"/>';
/**
Améliore la sortie print
@author Tatane http://www.tatane.info/index.php/print_rn
@author http://www.blog.cactuscrew.com/77-print_rn.html
@param $data (array) tableau ou variable à examiner
@param $name (string) nom a afficher
@return false affiche les clef valeur du tableau $data
@example n_print($array, 'Tableau de valeur');
*/
function n_print($data, $name = '')
{
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
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>;">';
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 />';
}