diff --git a/blocklog_fonctions.php b/blocklog_fonctions.php index 1daf182..2283439 100755 --- a/blocklog_fonctions.php +++ b/blocklog_fonctions.php @@ -13,7 +13,7 @@ if (!defined('_ECRIRE_INC_VERSION')) { return; } -function trouver_blocklog($id_objet, $objet, $id = false){ +function trouver_blocklog($id_objet, $objet, $all = false){ static $r; if ($r == null) { @@ -24,17 +24,23 @@ function trouver_blocklog($id_objet, $objet, $id = false){ 'id_objet='.intval($id_objet), 'objet='.sql_quote($objet), ); - $r = sql_fetsel('id_blocklog, blockchaine, chaine', $from, $where); - + $r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', $from, $where); } - if ($id) { + if ($all) { return $r; } return $r['blockchaine']; } +function blockchaine_sur_pdf(){ + if (!defined('_BLOCKLOG_CACHER_PDF') or _BLOCKLOG_CACHER_PDF !== true){ + return true; + } + return false; +} + function afficher_blocklog($texte, $id_dossier, $objet){ $objet = trim($objet); @@ -58,68 +64,43 @@ function afficher_blocklog($texte, $id_dossier, $objet){ return $texte; } -function blocklog_verifier_blockchaine($id_objet, $objet){ - if (intval($id_objet) and $objet) { - $r = trouver_blocklog($id_objet, $objet, true); +function blocklog_verifier_blockchaine($num, $objet){ + if (intval($num) and $objet) { + $where = array( + 'num='.intval($num), + 'objet='.sql_quote($objet), + ); + $r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where); $where = array( 'objet='.sql_quote($objet), 'id_blocklog<'.intval($r['id_blocklog']) ); - $blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where, 'id_blocklog DESC', 1); + $blockchaine_prec = sql_getfetsel('blockchaine', 'spip_blocklogs', $where, 'id_blocklog DESC', 1); - $blockchaine .= "|" . $r['chaine']; + $blockchaine = $blockchaine_prec . $r['chaine']; $blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine); return $blockchaine === $r['blockchaine']; } } -function blocklog_verifier_blockchaines($objet, $date_debut = '', $date_fin = ''){ +function blocklog_verifier_chaine($num, $objet){ - if (empty($objet)) { - return []; + if (intval($num) and $objet) { + $where = array( + 'num='.intval($num), + 'objet='.sql_quote($objet), + ); + $r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where); + + $chaine_bdd = $r['chaine']; + $chaine_dynamique = blocklog_creer_chaine($r['requete']); + + return $chaine_bdd === $chaine_dynamique; } - - if (empty($date_debut)) { - $date_debut = date_create() -> modify('-1 year')->format('Y-m-d H:i:s'); - } else { - $date_debut = date_create($date_debut)->format('Y-m-d H:i:s'); - } - if (empty($date_fin)) { - $date_fin = date_create()->format('Y-m-d H:i:s'); - } else { - $date_fin = date_create($date_fin)->format('Y-m-d 23:59:59'); - } - - $from = 'spip_blocklogs'; - $where = array( - 'objet='.sql_quote($objet), - 'maj>='.sql_quote($date_debut), - 'maj<='.sql_quote($date_fin), - ); - - $res = sql_allfetsel('*', $from, $where); - $retour = []; - if (count($res)) { - $blockchaine = ""; - foreach ($res as $r) { - $blockchaine .= "|" . $r['chaine']; - $blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine); - if ($blockchaine === $r['blockchaine']){ - $r['v'] = 'ok'; - $retour[] = $r; - } else { - $r['v'] = 'error'; - $retour[] = $r; - break; - } - } - } - - return $retour; } function blocklog_creer_chaine($requete = ""){ @@ -142,7 +123,6 @@ function blocklog_creer_chaine($requete = ""){ spip_log($chaine, 'blocklog'); } - $chaine .= "|"; $chaine = hash(_BLOCKLOG_ALGO, $chaine); return $chaine; @@ -154,8 +134,54 @@ function blocklog_creer_blockchaine($chaine, $objet){ ); $blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where,'', 'id_blocklog DESC', '1'); - $blockchaine .= "|" . $chaine; + $blockchaine .= $chaine; $blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine); return $blockchaine; } + +//function blocklog_verifier_blockchaines($objet, $date_debut = '', $date_fin = ''){ + + //if (empty($objet)) { + //return []; + //} + + //if (empty($date_debut)) { + //$date_debut = date_create() -> modify('-1 year')->format('Y-m-d H:i:s'); + //} else { + //$date_debut = date_create($date_debut)->format('Y-m-d H:i:s'); + //} + //if (empty($date_fin)) { + //$date_fin = date_create()->format('Y-m-d H:i:s'); + //} else { + //$date_fin = date_create($date_fin)->format('Y-m-d 23:59:59'); + //} + + //$from = 'spip_blocklogs'; + //$where = array( + //'objet='.sql_quote($objet), + //'maj>='.sql_quote($date_debut), + //'maj<='.sql_quote($date_fin), + //); + + //$res = sql_allfetsel('*', $from, $where); + + //$retour = []; + //if (count($res)) { + //$blockchaine = ""; + //foreach ($res as $r) { + //$blockchaine .= $r['chaine']; + //$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine); + //if ($blockchaine === $r['blockchaine']){ + //$r['v'] = 'ok'; + //$retour[] = $r; + //} else { + //$r['v'] = 'error'; + //$retour[] = $r; + //break; + //} + //} + //} + + //return $retour; +//} diff --git a/inclure/inc-tableau_blockchaines.html b/inclure/inc-tableau_blockchaines.html index 39ba455..2aa8eba 100644 --- a/inclure/inc-tableau_blockchaines.html +++ b/inclure/inc-tableau_blockchaines.html @@ -1,26 +1,47 @@ #CACHE{0} -[(#ENV{objet}|blocklog_verifier_blockchaines{#ENV{date_debut}, #ENV{date_fin}}|set{mesLogs})] +
id | -numéro | -Blockchaine | -Date | -Validité | -
---|---|---|---|---|
[(#VALEUR{id_blocklog})] | -[(#VALEUR{num})] | -[(#VALEUR{blockchaine})] | -[(#VALEUR{maj}|affdate{d/M/Y})] | -[(#VALEUR{v})] | -