* on n'utilise plus spip_blocklogs_liens * on ajoute à la place id_objet / objet à spip_blocklogs * on passe en cle primaire : id_blocklog, id_objet, objet => comme cela, c'est restrictif mais c'est comme ca que cela doit fonctionner
58 lines
1.1 KiB
PHP
Executable file
58 lines
1.1 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 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);
|
|
|
|
|
|
if (! defined("_BLOCKLOG_ALGO")) {
|
|
define("_BLOCKLOG_ALGO", 'sha256');
|
|
}
|
|
$blockchaine .= "|" . $r['chaine'];
|
|
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
|
|
|
return $blockchaine === $r['blockchaine'];
|
|
}
|
|
}
|