From dc984b7e6f1a638ec162467d5b9a847ef068bfdd Mon Sep 17 00:00:00 2001 From: Fil <fil@rezo.net> Date: Fri, 4 Sep 2009 17:28:12 +0000 Subject: [PATCH] proposition d'API pour journaliser les evenements qui se produisent dans spip --- .gitattributes | 1 + ecrire/inc/journal.php | 51 +++++++++++++++++++++++++++++++++++++++++ ecrire/inc/modifier.php | 11 +++++++++ 3 files changed, 63 insertions(+) create mode 100644 ecrire/inc/journal.php diff --git a/.gitattributes b/.gitattributes index 202d04bbea..11bb473385 100644 --- a/.gitattributes +++ b/.gitattributes @@ -244,6 +244,7 @@ ecrire/inc/instituer_auteur.php -text ecrire/inc/instituer_breve.php -text ecrire/inc/instituer_site.php -text ecrire/inc/joindre.php -text +ecrire/inc/journal.php -text ecrire/inc/json.php -text ecrire/inc/lang_liste.php -text ecrire/inc/legender.php -text diff --git a/ecrire/inc/journal.php b/ecrire/inc/journal.php new file mode 100644 index 0000000000..5545ff7c49 --- /dev/null +++ b/ecrire/inc/journal.php @@ -0,0 +1,51 @@ +<?php + +/***************************************************************************\ + * SPIP, Systeme de publication pour l'internet * + * * + * Copyright (c) 2001-2009 * + * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * + * * + * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * + * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * +\***************************************************************************/ + +if (!defined("_ECRIRE_INC_VERSION")) return; + + +/* + * Consigner une phrase dans le journal de bord du site + * Cette API travaille a minima, mais un plugin pourra stocker + * ces journaux en base et fournir des outils d'affichage, de selection etc + * + * @param string $journal + * @param array $opt + */ +function journal($phrase, $opt = array()) { + if (!strlen($phrase)) + return; + if ($opt) + $phrase .= " :: ".str_replace("\n", ' ', join(', ',$opt)); + spip_log($phrase, 'journal'); +} + +/* Lire le journal de bord en appliquant les criteres de choix + * et le renvoyer sous forme de tableau horodate ; attention a + * limiter a un nombre raisonnable d'items : l'API ne definit + * pas de limite + * + * @param array $criteres + */ +function lire_journal($criteres = null) { + $journal = array(); + foreach (array(_DIR_TMP.'prive_journal.log', _DIR_TMP.'journal.log') as $f) + if (@is_readable($f)) + foreach(file($f) as $l) { + if ($time = strtotime(join(' ', array_slice(explode(' ',$l),0,3)))) + $journal[$time] = join(' ', array_slice(explode(' ',$l),6)); + } + krsort($journal); + return $journal; +} + +?> diff --git a/ecrire/inc/modifier.php b/ecrire/inc/modifier.php index 1f1da0bcea..19638ea929 100644 --- a/ecrire/inc/modifier.php +++ b/ecrire/inc/modifier.php @@ -157,6 +157,17 @@ function modifier_contenu($type, $id, $options, $c=false, $serveur='') { exit; } + // journaliser l'affaire + // message a affiner :-) + include_spip('inc/journal'); + include_spip('inc/filtres_mini'); + $qui = sinon($GLOBALS['visiteur_session']['nom'], $GLOBALS['ip']); + journal(_L($qui.' a édité l’'.$type.' '.$id.' ('.join('+',array_diff(array_keys($champs), array('date_modif'))).')'), array( + 'faire' => 'modifier', + 'quoi' => $type, + 'id' => $id + )); + return true; } -- GitLab