|
|
|
@ -1,11 +1,12 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Plugin Thumbsite
|
|
|
|
|
* Licence GPL
|
|
|
|
|
* 2008-2021
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!defined('_ECRIRE_INC_VERSION')){
|
|
|
|
|
if (!defined('_ECRIRE_INC_VERSION')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -30,7 +31,7 @@ function balise_THUMBSHOT_dist($p) {
|
|
|
|
|
$_defaut = interprete_argument_balise(3, $p);
|
|
|
|
|
$_defaut = ($_defaut ?: "''");
|
|
|
|
|
|
|
|
|
|
$p->code = "((\$f = chercher_filtre('balise_img')) ? \$f(sinon(thumbsites_fichier_thumbshot($_url), $_defaut), ''" . ($_taille ? ", is_numeric($_taille) ? $_taille . 'x*' : $_taille" : '') .") : '')";
|
|
|
|
|
$p->code = "((\$f = chercher_filtre('balise_img')) ? \$f(sinon(thumbsites_fichier_thumbshot($_url), $_defaut), ''" . ($_taille ? ", is_numeric($_taille) ? $_taille . 'x*' : $_taille" : '') . ") : '')";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $p;
|
|
|
|
@ -43,7 +44,7 @@ function balise_THUMBSHOT_dist($p) {
|
|
|
|
|
*/
|
|
|
|
|
function thumbsites_fonction_thumbshot($service) {
|
|
|
|
|
include_spip('serveurs/' . $service);
|
|
|
|
|
if ($fonction_url_thumbshot = charger_fonction("{$service}_url_thumbshot", "serveurs", true)) {
|
|
|
|
|
if ($fonction_url_thumbshot = charger_fonction("{$service}_url_thumbshot", 'serveurs', true)) {
|
|
|
|
|
return $fonction_url_thumbshot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -54,14 +55,14 @@ function thumbsites_fonction_thumbshot($service) {
|
|
|
|
|
* @param string $url_site
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function thumbsites_url_thumbshot($url_site){
|
|
|
|
|
function thumbsites_url_thumbshot($url_site) {
|
|
|
|
|
if (!$url_site) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$url_thumbshot = '';
|
|
|
|
|
|
|
|
|
|
//determine le serveur de vignettes a utiliser, defaut apercite.fr
|
|
|
|
|
include_spip("inc/config");
|
|
|
|
|
include_spip('inc/config');
|
|
|
|
|
$service = lire_config('thumbsites/serveur', 'apercite');
|
|
|
|
|
if ($fonction_url_thumbshot = thumbsites_fonction_thumbshot($service)) {
|
|
|
|
|
$url_thumbshot = $fonction_url_thumbshot($url_site);
|
|
|
|
@ -83,8 +84,10 @@ function thumbsites_detecter_services_disponibles($dummy = '') {
|
|
|
|
|
foreach ($services_candidats as $basename => $file) {
|
|
|
|
|
$service = basename($basename, '.php');
|
|
|
|
|
$path = dirname($file) . '/';
|
|
|
|
|
if (file_exists($path . 'inc-configurer-thumbsites-'.$service.'.html')
|
|
|
|
|
and thumbsites_fonction_thumbshot($service)) {
|
|
|
|
|
if (
|
|
|
|
|
file_exists($path . 'inc-configurer-thumbsites-' . $service . '.html')
|
|
|
|
|
and thumbsites_fonction_thumbshot($service)
|
|
|
|
|
) {
|
|
|
|
|
$services[$service] = $service;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -98,18 +101,17 @@ function thumbsites_detecter_services_disponibles($dummy = '') {
|
|
|
|
|
* Generer un index des thumbshots de site
|
|
|
|
|
* @param string $dir
|
|
|
|
|
*/
|
|
|
|
|
function thumbsites_creer_index_thumbshots($dir){
|
|
|
|
|
function thumbsites_creer_index_thumbshots($dir) {
|
|
|
|
|
static $done = false;
|
|
|
|
|
if ($done){
|
|
|
|
|
if ($done) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$done = true;
|
|
|
|
|
if (!file_exists($dir . 'index.php')){
|
|
|
|
|
if (!file_exists($dir . 'index.php')) {
|
|
|
|
|
ecrire_fichier($dir . 'index.php', '<?php
|
|
|
|
|
foreach(glob(\'./*.jpg\') as $i)
|
|
|
|
|
echo "<img src=\'$i\' />\n";
|
|
|
|
|
?>'
|
|
|
|
|
);
|
|
|
|
|
?>');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -119,10 +121,10 @@ function thumbsites_creer_index_thumbshots($dir){
|
|
|
|
|
* @param bool $refresh
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function thumbsites_fichier_thumbshot($url_site, $refresh = false){
|
|
|
|
|
function thumbsites_fichier_thumbshot($url_site, $refresh = false) {
|
|
|
|
|
static $nb = 5; // ne pas en charger plus de 5 anciens par tour
|
|
|
|
|
|
|
|
|
|
if (!strlen($url_site) or !parse_url($url_site)){
|
|
|
|
|
if (!strlen($url_site) or !parse_url($url_site)) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -130,34 +132,35 @@ function thumbsites_fichier_thumbshot($url_site, $refresh = false){
|
|
|
|
|
$md5_url = md5(strtolower($url_site));
|
|
|
|
|
$thumb_cache = $dir_tmp . $md5_url . '.jpg';
|
|
|
|
|
|
|
|
|
|
if ($refresh and file_exists($thumb_cache)){
|
|
|
|
|
if ($refresh and file_exists($thumb_cache)) {
|
|
|
|
|
$ret = supprimer_fichier($thumb_cache);
|
|
|
|
|
spip_log("thumbshot demande de rafraichissement url $url_site file $thumb_cache suppression reussie ? $ret");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
include_spip("inc/filtres");
|
|
|
|
|
include_spip('inc/filtres');
|
|
|
|
|
include_spip('inc/config');
|
|
|
|
|
$duree = intval(lire_config('thumbsites/duree_cache', 30));
|
|
|
|
|
|
|
|
|
|
if ($refresh
|
|
|
|
|
or !file_exists($thumb_cache)
|
|
|
|
|
or ((time()-3600*24*$duree>filemtime($thumb_cache)) and $nb>0)){
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
$refresh
|
|
|
|
|
or !file_exists($thumb_cache)
|
|
|
|
|
or ((time() - 3600 * 24 * $duree > filemtime($thumb_cache)) and $nb > 0)
|
|
|
|
|
) {
|
|
|
|
|
spip_log("thumbshot refresh url $url_site file $thumb_cache", 'thumbsites' . _LOG_DEBUG);
|
|
|
|
|
|
|
|
|
|
$nb--;
|
|
|
|
|
include_spip("inc/distant");
|
|
|
|
|
include_spip('inc/distant');
|
|
|
|
|
$url_thumb = thumbsites_url_thumbshot($url_site);
|
|
|
|
|
|
|
|
|
|
$filetmp = $thumb_cache . '.tmp';
|
|
|
|
|
$res = recuperer_url($url_thumb, array('file' => $filetmp));
|
|
|
|
|
$res = recuperer_url($url_thumb, ['file' => $filetmp]);
|
|
|
|
|
|
|
|
|
|
if ($res and !empty($res['file'])){
|
|
|
|
|
if ($res and !empty($res['file'])) {
|
|
|
|
|
spip_log('thumbshot ok pour ' . $url_site . " dans $filetmp", 'thumbsites' . _LOG_DEBUG);
|
|
|
|
|
|
|
|
|
|
// si c'est un png, le convertir en jpg
|
|
|
|
|
$a = @getimagesize($thumb_cache);
|
|
|
|
|
if ($a[2]==3) {
|
|
|
|
|
if ($a[2] == 3) {
|
|
|
|
|
include_spip('inc/filtres_images_lib_mini');
|
|
|
|
|
$img = _imagecreatefrompng($filetmp);
|
|
|
|
|
_image_imagejpg($img, $thumb_cache);
|
|
|
|
@ -175,7 +178,7 @@ function thumbsites_fichier_thumbshot($url_site, $refresh = false){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// On verifie si le thumbshot existe en controlant la taille du fichier
|
|
|
|
|
if (@filesize($thumb_cache)){
|
|
|
|
|
if (@filesize($thumb_cache)) {
|
|
|
|
|
return $thumb_cache;
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
@ -188,13 +191,17 @@ function thumbsites_fichier_thumbshot($url_site, $refresh = false){
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function thumbsites_quete_logo_objet($flux) {
|
|
|
|
|
if (empty($flux['data'])
|
|
|
|
|
and $flux['args']['mode'] === 'on'
|
|
|
|
|
and $flux['args']['objet'] === 'site'
|
|
|
|
|
and $id_syndic = $flux['args']['id_objet']) {
|
|
|
|
|
$url_site = sql_getfetsel('url_site', 'spip_syndic', 'id_syndic='.intval($id_syndic));
|
|
|
|
|
if ($url_site = vider_url($url_site, false)
|
|
|
|
|
and $thumb_file = thumbsites_fichier_thumbshot($url_site)) {
|
|
|
|
|
if (
|
|
|
|
|
empty($flux['data'])
|
|
|
|
|
and $flux['args']['mode'] === 'on'
|
|
|
|
|
and $flux['args']['objet'] === 'site'
|
|
|
|
|
and $id_syndic = $flux['args']['id_objet']
|
|
|
|
|
) {
|
|
|
|
|
$url_site = sql_getfetsel('url_site', 'spip_syndic', 'id_syndic=' . intval($id_syndic));
|
|
|
|
|
if (
|
|
|
|
|
$url_site = vider_url($url_site, false)
|
|
|
|
|
and $thumb_file = thumbsites_fichier_thumbshot($url_site)
|
|
|
|
|
) {
|
|
|
|
|
$flux['data'] = [
|
|
|
|
|
'chemin' => $thumb_file,
|
|
|
|
|
'timestamp' => filemtime($thumb_file),
|
|
|
|
@ -211,23 +218,27 @@ function thumbsites_quete_logo_objet($flux) {
|
|
|
|
|
* @param array $flux
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
function thumbsites_afficher_config_objet($flux){
|
|
|
|
|
function thumbsites_afficher_config_objet($flux) {
|
|
|
|
|
$type = $flux['args']['type'];
|
|
|
|
|
if (($type=='site')
|
|
|
|
|
if (
|
|
|
|
|
($type == 'site')
|
|
|
|
|
and ($id = intval($flux['args']['id']))
|
|
|
|
|
and ($url = sql_getfetsel('url_site', 'spip_syndic', 'id_syndic=' . sql_quote($id)))){
|
|
|
|
|
and ($url = sql_getfetsel('url_site', 'spip_syndic', 'id_syndic=' . sql_quote($id)))
|
|
|
|
|
) {
|
|
|
|
|
include_spip('inc/thumbsites_filtres');
|
|
|
|
|
if ($thumbshot_cache = thumbsites_fichier_thumbshot($url)){
|
|
|
|
|
if ($taille = @getimagesize($thumbshot_cache)){
|
|
|
|
|
$flux['data'] .= recuperer_fond('prive/squelettes/navigation/thumbshot',
|
|
|
|
|
array(
|
|
|
|
|
if ($thumbshot_cache = thumbsites_fichier_thumbshot($url)) {
|
|
|
|
|
if ($taille = @getimagesize($thumbshot_cache)) {
|
|
|
|
|
$flux['data'] .= recuperer_fond(
|
|
|
|
|
'prive/squelettes/navigation/thumbshot',
|
|
|
|
|
[
|
|
|
|
|
'id_objet' => $id,
|
|
|
|
|
'objet' => objet_type($type),
|
|
|
|
|
'thumbshot_cache' => $thumbshot_cache,
|
|
|
|
|
'largeur' => $taille[0],
|
|
|
|
|
'hauteur' => $taille[1],
|
|
|
|
|
'url' => $url,
|
|
|
|
|
));
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -239,13 +250,17 @@ if (!function_exists('url_thumbsite')) {
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
function url_thumbsite($url_site) { return thumbsites_url_thumbshot($url_site);}
|
|
|
|
|
function url_thumbsite($url_site) {
|
|
|
|
|
return thumbsites_url_thumbshot($url_site);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!function_exists('thumbshot')) {
|
|
|
|
|
/**
|
|
|
|
|
* @deprecated
|
|
|
|
|
*/
|
|
|
|
|
function thumbshot($url_site, $refresh=false) { return thumbsites_fichier_thumbshot($url_site, $refresh);}
|
|
|
|
|
function thumbshot($url_site, $refresh = false) {
|
|
|
|
|
return thumbsites_fichier_thumbshot($url_site, $refresh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function thumbsites_crediter($item = 'thumbsites:credit_1_thumbshot') {
|
|
|
|
@ -254,7 +269,7 @@ function thumbsites_crediter($item = 'thumbsites:credit_1_thumbshot') {
|
|
|
|
|
|
|
|
|
|
$service = lire_config('thumbsites/serveur', 'apercite');
|
|
|
|
|
include_spip('serveurs/' . $service);
|
|
|
|
|
if ($fonction_url_credit = charger_fonction("{$service}_url_credit", "serveurs", true)) {
|
|
|
|
|
if ($fonction_url_credit = charger_fonction("{$service}_url_credit", 'serveurs', true)) {
|
|
|
|
|
// On acquiert l'url de crédit du serveur
|
|
|
|
|
$url = $fonction_url_credit();
|
|
|
|
|
// On détermine le nom affché pour le serveur
|
|
|
|
@ -265,8 +280,8 @@ function thumbsites_crediter($item = 'thumbsites:credit_1_thumbshot') {
|
|
|
|
|
$item = 'thumbsites:credit_1_thumbshot';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$credit = _T($item, array('lien' => $lien));
|
|
|
|
|
$credit = _T($item, ['lien' => $lien]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $credit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|