Compare commits

..

1 commit
master ... v1

Author SHA1 Message Date
b7ba4b523d maj php doc 2021-11-23 22:09:22 +01:00
5 changed files with 269 additions and 65 deletions

View file

@ -3,9 +3,14 @@
## Utilisation
> Génération du blocklog
```php
$requete = sql_allfetsel($s, $f, $w,'','','','','', false);
$blocklog = charger_fonction('blocklog', 'inc');
$blocklog($objet, $id_objet, $numero_facture, $requete);
// $chaine : string ou array
$blocklog("monObjet", $id_objet, $num_dossier, $chaine);
```
## Page html de generation d'un bloclog
```
?page=sha256sum
```
## options :
@ -16,16 +21,4 @@ define("_BLOCKLOG_ALGO", 'sha256');
//activer les log : blocklog.log
define("_DEBUG_BLOCKLOG", true);
// garder le calcul de la chaine simple, requete avec sql_fetch et non sql_fetch_all
// utiliser sur lcdp
// l'autre solution est de rester en version 1 du plugin
define("_BLOCKLOG_CHAINE_SIMPLE", true);
```
## Page html de generation d'un bloclog
```
?page=sha256sum
```

View file

@ -15,28 +15,33 @@ if (!defined('_ECRIRE_INC_VERSION')) {
function trouver_blocklog($id_objet, $objet, $all = false){
static $r;
if (is_null($r)) {
$where = [
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, requete', 'spip_blocklogs', $where);
);
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', $from, $where);
}
if ($all) {
return $r;
}
return $r['blockchaine'] ?? '';
return $r['blockchaine'];
}
function blockchaine_sur_pdf(){
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){
return true;
}
return false;
}
function afficher_blocklog($texte = '', $id_objet = 0, $objet = '', $type = 'chaine'){
function afficher_blocklog($texte, $id_dossier, $objet, $type = 'chaine'){
$objet = trim($objet);
$blockchaine = '<span class="affichage_blockchaine">';
@ -46,16 +51,12 @@ function afficher_blocklog($texte = '', $id_objet = 0, $objet = '', $type = 'cha
$img .= "&nbsp;";
}
if (!defined('_BLOCKLOG_CACHER_PDF') or _BLOCKLOG_CACHER_PDF !== true){
if (intval($id_objet) and $objet) {
$recup_bl = trouver_blocklog($id_objet, $objet, true);
if (intval($id_dossier) and $objet) {
$blockchaine .= $img;
$blockchaine .= $recup_bl[$type] ?? '';
$blockchaine .= trouver_blocklog($id_dossier, $objet, true)[$type];
$blockchaine .= '</span>';
}
}
if (empty($texte)) {
return $blockchaine;
}
$texte = str_replace('@@blockchaine@@', $blockchaine, $texte);
$texte = str_replace('@@blocklog@@', $blockchaine, $texte);
@ -71,23 +72,23 @@ function blocklog_verifier_blockchaine($num, $objet){
);
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where);
if (is_array($r)) {
$where = array(
'objet='.sql_quote($objet),
'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 = hash(_BLOCKLOG_ALGO, $blockchaine);
return $blockchaine === $r['blockchaine'];
}
}
return false;
}
function blocklog_verifier_chaine($num, $objet){
if (intval($num) and $objet) {
$where = array(
'num='.intval($num),
@ -95,14 +96,11 @@ function blocklog_verifier_chaine($num, $objet){
);
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where);
if (isset($r['chaine']) and isset($r['requete'])) {
$chaine_bdd = $r['chaine'];
$chaine_dynamique = blocklog_creer_chaine($r['requete']);
return $chaine_bdd === $chaine_dynamique;
}
}
return false;
}
function blocklog_creer_chaine($requete = ""){
@ -110,13 +108,9 @@ function blocklog_creer_chaine($requete = ""){
return '';
}
$get_infos = charger_fonction('get_infos', 'plugins');
$version = $get_infos('blocklog');
$r = sql_query($requete);
if (intval($version) < 2 or defined('_BLOCKLOG_CHAINE_SIMPLE')) {
$chaine = sql_fetch($r);
if (is_array($chaine)) {
$c = [];
foreach ($chaine as $i => $v) {
@ -124,12 +118,6 @@ function blocklog_creer_chaine($requete = ""){
}
$chaine = implode('|', $c);
}
} else {
$chaine = sql_fetch_all($r);
if (is_array($chaine)) {
$chaine = serialize($chaine);
}
}
$chaine = hash(_BLOCKLOG_ALGO, $chaine);
@ -137,10 +125,10 @@ function blocklog_creer_chaine($requete = ""){
}
function blocklog_creer_blockchaine($chaine, $objet){
$where = [
$where = array(
'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 = hash(_BLOCKLOG_ALGO, $blockchaine);

222
fabrique_blocklog.php Executable file

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,9 @@
<paquet
prefix="blocklog"
categorie="outil"
version="2.0.2"
version="1.1.5"
etat="dev"
compatibilite="[3.2.0;4.*.*]"
compatibilite="[3.2.0;3.3.*]"
logo="prive/themes/spip/images/blocklog-64.png"
documentation=""
schema="1.0.7"

View file

@ -115,6 +115,7 @@
let c3 = document.querySelector('#c3').value;
let chaine = c1 + c2 +c3;
chaine = sha256(chaine);
console.log(chaine);
document.querySelector('#sha').value = chaine;
});