76 lines
1.7 KiB
PHP
Executable file
76 lines
1.7 KiB
PHP
Executable file
<?php
|
|
if (!defined('_ECRIRE_INC_VERSION')){
|
|
return;
|
|
}
|
|
|
|
|
|
/**
|
|
* creation de la blockchaine
|
|
*
|
|
* @param string $objet
|
|
* @param int $id_objet
|
|
* @param string | array $chaine : ensemble des valeurs utilisées pour creer la chaine
|
|
* @return array [id_blocklog, chaine, blockchaine]
|
|
*/
|
|
function inc_blocklog_dist($objet, $id_objet = 0, $num = 0, $chaine = '') {
|
|
if (!$objet or !$id_objet or !$chaine) {
|
|
return false;
|
|
}
|
|
|
|
if (defined('_DEBUG_BLOCKLOG')) {
|
|
spip_log('objet = '.$objet, 'blocklog');
|
|
spip_log('id_objet = '.$id_objet, 'blocklog');
|
|
spip_log('num = '.$num, 'blocklog');
|
|
spip_log('----------------', 'blocklog');
|
|
}
|
|
|
|
if (! defined("_BLOCKLOG_ALGO")) {
|
|
define("_BLOCKLOG_ALGO", 'sha256');
|
|
}
|
|
|
|
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);
|
|
|
|
|
|
$where = array(
|
|
'objet='.sql_quote($objet)
|
|
);
|
|
$blockchaine = sql_getfetsel('blockchaine', 'spip_blocklogs', $where,'', 'id_blocklog DESC', '1');
|
|
|
|
$blockchaine .= "|" . $chaine;
|
|
$blockchaine = hash(_BLOCKLOG_ALGO, $blockchaine);
|
|
|
|
|
|
$set = array (
|
|
'objet' => $objet,
|
|
'id_objet' => intval($id_objet),
|
|
'blockchaine' => $blockchaine,
|
|
'chaine' => $chaine,
|
|
'num' => intval($num)
|
|
);
|
|
|
|
if (defined('_DEBUG_BLOCKLOG')) {
|
|
spip_log($set, 'blocklog');
|
|
spip_log('================', 'blocklog');
|
|
}
|
|
|
|
include_spip('action/editer_objet');
|
|
set_request('id_auteur', null);
|
|
$r = objet_inserer("blocklog", null, $set);
|
|
if (!intval($r)) {
|
|
spip_log("la blockchaine pour $objet / $id_objet ne pas pas etre inserer en bdd", 'blocklog'._LOG_ERREUR);
|
|
}
|
|
|
|
return $r;
|
|
}
|