etre capable de recalculer la chaine. on passe en fonction la creation d'une chaine et d'une blochaine
161 lines
3.4 KiB
PHP
Executable file
161 lines
3.4 KiB
PHP
Executable file
<?php
|
|
/**
|
|
* Fonctions utiles au plugin Block Log
|
|
*
|
|
* @plugin Block Log
|
|
* @copyright 2019
|
|
* @author tofulm
|
|
* @licence GNU/GPL
|
|
* @package SPIP\Blocklog\Fonctions
|
|
*/
|
|
|
|
if (!defined('_ECRIRE_INC_VERSION')) {
|
|
return;
|
|
}
|
|
|
|
function trouver_blocklog($id_objet, $objet, $id = false){
|
|
static $r;
|
|
|
|
if ($r == null) {
|
|
$from = array(
|
|
'spip_blocklogs',
|
|
);
|
|
$where = array(
|
|
'id_objet='.intval($id_objet),
|
|
'objet='.sql_quote($objet),
|
|
);
|
|
$r = sql_fetsel('id_blocklog, blockchaine, chaine', $from, $where);
|
|
|
|
}
|
|
|
|
if ($id) {
|
|
return $r;
|
|
}
|
|
|
|
return $r['blockchaine'];
|
|
}
|
|
|
|
function afficher_blocklog($texte, $id_dossier, $objet){
|
|
$objet = trim($objet);
|
|
|
|
$blockchaine = '<span class="affichage_blockchaine">';
|
|
$img = find_in_path('img/icone_blockchaine.svg');
|
|
if ($img) {
|
|
$img = '<img class="icone_blockchaine" src="'.$img.'" style="height:1em;width: 1em;">';
|
|
$img .= " ";
|
|
}
|
|
if (!defined('_BLOCKLOG_CACHER_PDF') or _BLOCKLOG_CACHER_PDF !== true){
|
|
if (intval($id_dossier) and $objet) {
|
|
$blockchaine .= $img;
|
|
$blockchaine .= trouver_blocklog($id_dossier, $objet);
|
|
$blockchaine .= '</span>';
|
|
}
|
|
}
|
|
|
|
$texte = str_replace('@@blockchaine@@', $blockchaine, $texte);
|
|
$texte = str_replace('@@blocklog@@', $blockchaine, $texte);
|
|
|
|
return $texte;
|
|
}
|
|
|
|
function blocklog_verifier_blockchaine($id_objet, $objet){
|
|
if (intval($id_objet) and $objet) {
|
|
$r = trouver_blocklog($id_objet, $objet, true);
|
|
|
|
$where = array(
|
|
'objet='.sql_quote($objet),
|
|
'id_blocklog<'.intval($r['id_blocklog'])
|
|
);
|
|
|
|
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where, 'id_blocklog DESC', 1);
|
|
|
|
|
|
$blockchaine .= "|" . $r['chaine'];
|
|
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
|
|
|
return $blockchaine === $r['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;
|
|
}
|
|
|
|
function blocklog_creer_chaine($requete = ""){
|
|
if ( strlen($requete) < 5 ) {
|
|
return '';
|
|
}
|
|
|
|
$r = sql_query($requete);
|
|
$chaine = sql_fetch($r);
|
|
|
|
if (is_array($chaine)) {
|
|
$c = [];
|
|
foreach ($chaine as $i => $v) {
|
|
$c[] = $v;
|
|
}
|
|
$chaine = implode('|', $c);
|
|
}
|
|
|
|
if (defined('_DEBUG_BLOCKLOG')) {
|
|
spip_log($chaine, 'blocklog');
|
|
}
|
|
|
|
$chaine .= "|";
|
|
$chaine = hash(_BLOCKLOG_ALGO, $chaine);
|
|
|
|
return $chaine;
|
|
}
|
|
|
|
function blocklog_creer_blockchaine($chaine, $objet){
|
|
$where = array(
|
|
'objet='.sql_quote($objet)
|
|
);
|
|
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where,'', 'id_blocklog DESC', '1');
|
|
|
|
$blockchaine .= "|" . $chaine;
|
|
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
|
|
|
return $blockchaine;
|
|
}
|