Compare commits
12 commits
Author | SHA1 | Date | |
---|---|---|---|
2dcf098153 | |||
|
2441f22fc3 | ||
2caf2f808e | |||
f191e4ce8e | |||
02e8f50bed | |||
|
4521675196 | ||
0186c57aa6 | |||
a0349698f0 | |||
9fac6e1c66 | |||
25544d1588 | |||
b6710055e7 | |||
0ae0147a1c |
6 changed files with 67 additions and 271 deletions
21
README.md
21
README.md
|
@ -3,14 +3,9 @@
|
|||
## Utilisation
|
||||
> Génération du blocklog
|
||||
```php
|
||||
$requete = sql_allfetsel($s, $f, $w,'','','','','', false);
|
||||
$blocklog = charger_fonction('blocklog', 'inc');
|
||||
// $chaine : string ou array
|
||||
$blocklog("monObjet", $id_objet, $num_dossier, $chaine);
|
||||
```
|
||||
|
||||
## Page html de generation d'un bloclog
|
||||
```
|
||||
?page=sha256sum
|
||||
$blocklog($objet, $id_objet, $numero_facture, $requete);
|
||||
```
|
||||
|
||||
## options :
|
||||
|
@ -21,4 +16,16 @@ 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
|
||||
```
|
||||
|
||||
|
|
|
@ -15,33 +15,28 @@ if (!defined('_ECRIRE_INC_VERSION')) {
|
|||
|
||||
function trouver_blocklog($id_objet, $objet, $all = false){
|
||||
static $r;
|
||||
|
||||
if ($r == null) {
|
||||
$from = array(
|
||||
'spip_blocklogs',
|
||||
);
|
||||
$where = array(
|
||||
if (is_null($r)) {
|
||||
$where = [
|
||||
'id_objet='.intval($id_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) {
|
||||
return $r;
|
||||
}
|
||||
|
||||
return $r['blockchaine'];
|
||||
return $r['blockchaine'] ?? '';
|
||||
}
|
||||
|
||||
function blockchaine_sur_pdf(){
|
||||
if (!defined('_BLOCKLOG_CACHER_PDF') or _BLOCKLOG_CACHER_PDF !== true){
|
||||
if (!defined('_BLOCKLOG_CACHER_PDF') or (defined('_BLOCKLOG_CACHER_PDF') and _BLOCKLOG_CACHER_PDF !== true)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function afficher_blocklog($texte, $id_dossier, $objet, $type = 'chaine'){
|
||||
function afficher_blocklog($texte = '', $id_objet = 0, $objet = '', $type = 'chaine'){
|
||||
$objet = trim($objet);
|
||||
|
||||
$blockchaine = '<span class="affichage_blockchaine">';
|
||||
|
@ -51,12 +46,16 @@ function afficher_blocklog($texte, $id_dossier, $objet, $type = 'chaine'){
|
|||
$img .= " ";
|
||||
}
|
||||
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 .= trouver_blocklog($id_dossier, $objet, true)[$type];
|
||||
$blockchaine .= $recup_bl[$type] ?? '';
|
||||
$blockchaine .= '</span>';
|
||||
}
|
||||
}
|
||||
if (empty($texte)) {
|
||||
return $blockchaine;
|
||||
}
|
||||
|
||||
$texte = str_replace('@@blockchaine@@', $blockchaine, $texte);
|
||||
$texte = str_replace('@@blocklog@@', $blockchaine, $texte);
|
||||
|
@ -72,23 +71,23 @@ function blocklog_verifier_blockchaine($num, $objet){
|
|||
);
|
||||
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where);
|
||||
|
||||
$where = array(
|
||||
'objet='.sql_quote($objet),
|
||||
'id_blocklog<'.intval($r['id_blocklog'])
|
||||
);
|
||||
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);
|
||||
|
||||
|
||||
$blockchaine = $blockchaine_prec . $r['chaine'];
|
||||
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
||||
|
||||
return $blockchaine === $r['blockchaine'];
|
||||
return $blockchaine === $r['blockchaine'];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function blocklog_verifier_chaine($num, $objet){
|
||||
|
||||
if (intval($num) and $objet) {
|
||||
$where = array(
|
||||
'num='.intval($num),
|
||||
|
@ -96,11 +95,14 @@ function blocklog_verifier_chaine($num, $objet){
|
|||
);
|
||||
$r = sql_fetsel('id_blocklog, blockchaine, chaine, requete', 'spip_blocklogs', $where);
|
||||
|
||||
$chaine_bdd = $r['chaine'];
|
||||
$chaine_dynamique = blocklog_creer_chaine($r['requete']);
|
||||
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 $chaine_bdd === $chaine_dynamique;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function blocklog_creer_chaine($requete = ""){
|
||||
|
@ -108,15 +110,25 @@ function blocklog_creer_chaine($requete = ""){
|
|||
return '';
|
||||
}
|
||||
|
||||
$r = sql_query($requete);
|
||||
$chaine = sql_fetch($r);
|
||||
$get_infos = charger_fonction('get_infos', 'plugins');
|
||||
$version = $get_infos('blocklog');
|
||||
|
||||
if (is_array($chaine)) {
|
||||
$c = [];
|
||||
foreach ($chaine as $i => $v) {
|
||||
$c[] = $v;
|
||||
$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) {
|
||||
$c[] = $v;
|
||||
}
|
||||
$chaine = implode('|', $c);
|
||||
}
|
||||
} else {
|
||||
$chaine = sql_fetch_all($r);
|
||||
if (is_array($chaine)) {
|
||||
$chaine = serialize($chaine);
|
||||
}
|
||||
$chaine = implode('|', $c);
|
||||
}
|
||||
|
||||
$chaine = hash(_BLOCKLOG_ALGO, $chaine);
|
||||
|
@ -125,10 +137,10 @@ function blocklog_creer_chaine($requete = ""){
|
|||
}
|
||||
|
||||
function blocklog_creer_blockchaine($chaine, $objet){
|
||||
$where = array(
|
||||
$where = [
|
||||
'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);
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ if (!defined('_ECRIRE_INC_VERSION')){
|
|||
*
|
||||
* @param string $objet
|
||||
* @param int $id_objet
|
||||
* @param string | array $chaine : ensemble des valeurs utilisées pour creer la chaine
|
||||
* @param string : requete sql pour recuperer les valeurs a intergrer dans la blockchaine
|
||||
* @return array [id_blocklog, chaine, blockchaine]
|
||||
*/
|
||||
function inc_blocklog_dist($objet, $id_objet = 0, $num = 0, $requete = '') {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<paquet
|
||||
prefix="blocklog"
|
||||
categorie="outil"
|
||||
version="1.1.5"
|
||||
version="2.0.2"
|
||||
etat="dev"
|
||||
compatibilite="[3.2.0;3.3.*]"
|
||||
compatibilite="[3.2.0;4.*.*]"
|
||||
logo="prive/themes/spip/images/blocklog-64.png"
|
||||
documentation=""
|
||||
schema="1.0.7"
|
||||
|
|
|
@ -115,7 +115,6 @@
|
|||
let c3 = document.querySelector('#c3').value;
|
||||
let chaine = c1 + c2 +c3;
|
||||
chaine = sha256(chaine);
|
||||
console.log(chaine);
|
||||
document.querySelector('#sha').value = chaine;
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue