2018-01-04 14:49:09 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin externalThumbshot
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init function, return an error if the server is not set.
|
|
|
|
*
|
|
|
|
* @param $conf ConfigManager instance.
|
|
|
|
*
|
|
|
|
* @return array Eventual error.
|
|
|
|
*/
|
|
|
|
function myShaarli_init($conf)
|
|
|
|
{
|
|
|
|
if (empty($conf->get('plugins.ExternalThumbshot_URL'))) {
|
|
|
|
$error = 'myShaarli plugin error: '.
|
|
|
|
'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') {
|
|
|
|
$error = 'myShaarli plugin: '.
|
|
|
|
'This plugin need modification of template. Use myShaarli theme for test.';
|
|
|
|
return array($error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add externalThumbshot icon to link_plugin when rendering linklist.
|
|
|
|
*
|
|
|
|
* @param mixed $data - linklist data.
|
|
|
|
*
|
|
|
|
* @return mixed - linklist data with readityourself plugin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function hook_myShaarli_render_linklist($data,$conf)
|
|
|
|
{
|
|
|
|
$thumUrl = $conf->get('plugins.ExternalThumbshot_URL');
|
2018-02-13 11:41:56 +01:00
|
|
|
if(!empty($conf->get('plugins.ExternalThumbshot_KEY'))){
|
|
|
|
$key = $conf->get('plugins.ExternalThumbshot_KEY');
|
|
|
|
}
|
2018-01-04 14:49:09 +01:00
|
|
|
if (!isset($thumUrl)) {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($data['links'] as &$value) {
|
|
|
|
$thumb = computeThumbnail($conf, $value['url']);
|
|
|
|
if(empty($thumb)){
|
2018-02-13 11:41:56 +01:00
|
|
|
if(!empty($key)){
|
|
|
|
$hmac = '&hm='.hash_hmac('sha1', $value['url'], $key).'&url=';
|
|
|
|
} else {
|
|
|
|
$hmac = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$value['thumbnail'] = '<img class="b-lazy" src="#" data-src="'.$thumUrl.$hmac.urlencode($value['url']).'" alt="Thumbnail" width="120" height="90">';
|
2018-01-04 14:49:09 +01:00
|
|
|
} else {
|
2018-02-09 15:56:22 +01:00
|
|
|
$value['thumbnail'] = '<img class="b-lazy" src="#" data-src="'.$thumb['src'].'" alt="Thumbnail" width="120" height="90">';
|
2018-01-04 14:49:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NOT WORKING
|
|
|
|
* To poor performance
|
|
|
|
* Need fix
|
|
|
|
*/
|
|
|
|
|
|
|
|
function returnFavicon($url)
|
|
|
|
{
|
|
|
|
$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 (file_exists('cache/'.$path.'/'.$faviconHash)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
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).'"/>';
|
|
|
|
}
|