This commit is contained in:
cy_altern 2022-04-27 17:06:44 +02:00
parent 0186c57aa6
commit 4521675196

View file

@ -15,23 +15,18 @@ if (!defined('_ECRIRE_INC_VERSION')) {
function trouver_blocklog($id_objet, $objet, $all = false){ function trouver_blocklog($id_objet, $objet, $all = false){
static $r; static $r;
if (is_null($r)) {
if ($r == null) { $where = [
$from = array(
'spip_blocklogs',
);
$where = array(
'id_objet='.intval($id_objet), 'id_objet='.intval($id_objet),
'objet='.sql_quote($objet), 'objet='.sql_quote($objet),
); ];
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', $from, $where); $r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where);
} }
if ($all) { if ($all) {
return $r; return $r;
} }
return $r['blockchaine']; return $r['blockchaine'] ?? '';
} }
function blockchaine_sur_pdf(){ function blockchaine_sur_pdf(){
@ -41,7 +36,7 @@ function blockchaine_sur_pdf(){
return false; return false;
} }
function afficher_blocklog($texte = '', $id_dossier = 0, $objet = '', $type = 'chaine'){ function afficher_blocklog($texte = '', $id_objet = 0, $objet = '', $type = 'chaine'){
$objet = trim($objet); $objet = trim($objet);
$blockchaine = '<span class="affichage_blockchaine">'; $blockchaine = '<span class="affichage_blockchaine">';
@ -50,10 +45,11 @@ function afficher_blocklog($texte = '', $id_dossier = 0, $objet = '', $type = 'c
$img = '<img class="icone_blockchaine" src="'.$img.'" style="height:1em;width: 1em;">'; $img = '<img class="icone_blockchaine" src="'.$img.'" style="height:1em;width: 1em;">';
$img .= "&nbsp;"; $img .= "&nbsp;";
} }
if (!defined('_BLOCKLOG_CACHER_PDF') or (defined('_BLOCKLOG_CACHER_PDF') and _BLOCKLOG_CACHER_PDF !== true)){ if (!defined('_BLOCKLOG_CACHER_PDF') or _BLOCKLOG_CACHER_PDF !== true){
if (intval($id_dossier) and $objet) { if (intval($id_objet) and $objet) {
$recup_bl = trouver_blocklog($id_objet, $objet, true);
$blockchaine .= $img; $blockchaine .= $img;
$blockchaine .= trouver_blocklog($id_dossier, $objet, true)[$type]; $blockchaine .= $recup_bl[$type] ?? '';
$blockchaine .= '</span>'; $blockchaine .= '</span>';
} }
} }
@ -75,23 +71,23 @@ function blocklog_verifier_blockchaine($num, $objet){
); );
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where); $r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where);
if (is_array($r)) {
$where = array( $where = array(
'objet='.sql_quote($objet), 'objet='.sql_quote($objet),
'id_blocklog<'.intval($r['id_blocklog']) 'id_blocklog<'.intval($r['id_blocklog'])
); );
$blockchaine_prec = sql_getfetsel('blockchaine', 'spip_blocklogs', $where, 'id_blocklog DESC', 1); $blockchaine_prec = sql_getfetsel('blockchaine', 'spip_blocklogs', $where, 'id_blocklog DESC', 1) ?? '';
$blockchaine = $blockchaine_prec . $r['chaine']; $blockchaine = $blockchaine_prec . $r['chaine'];
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine); $blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
return $blockchaine === $r['blockchaine']; return $blockchaine === $r['blockchaine'];
} }
}
return false;
} }
function blocklog_verifier_chaine($num, $objet){ function blocklog_verifier_chaine($num, $objet){
if (intval($num) and $objet) { if (intval($num) and $objet) {
$where = array( $where = array(
'num='.intval($num), 'num='.intval($num),
@ -99,11 +95,14 @@ function blocklog_verifier_chaine($num, $objet){
); );
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where); $r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where);
if (isset($r['chaine']) and isset($r['requete'])) {
$chaine_bdd = $r['chaine']; $chaine_bdd = $r['chaine'];
$chaine_dynamique = blocklog_creer_chaine($r['requete']); $chaine_dynamique = blocklog_creer_chaine($r['requete']);
return $chaine_bdd === $chaine_dynamique; return $chaine_bdd === $chaine_dynamique;
} }
}
return false;
} }
function blocklog_creer_chaine($requete = ""){ function blocklog_creer_chaine($requete = ""){
@ -116,10 +115,7 @@ function blocklog_creer_chaine($requete = ""){
$r = sql_query($requete); $r = sql_query($requete);
if ( if (intval($version) < 2 or defined('_BLOCKLOG_CHAINE_SIMPLE')) {
intval($version) < 2
or defined('_BLOCKLOG_CHAINE_SIMPLE')
) {
$chaine = sql_fetch($r); $chaine = sql_fetch($r);
if (is_array($chaine)) { if (is_array($chaine)) {
$c = []; $c = [];
@ -141,10 +137,10 @@ function blocklog_creer_chaine($requete = ""){
} }
function blocklog_creer_blockchaine($chaine, $objet){ function blocklog_creer_blockchaine($chaine, $objet){
$where = array( $where = [
'objet='.sql_quote($objet) 'objet='.sql_quote($objet)
); ];
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where,'', 'id_blocklog DESC', '1'); $blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where,'', 'id_blocklog DESC', '1') ?? '';
$blockchaine .= $chaine; $blockchaine .= $chaine;
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine); $blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);