3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) {
17 include_spip('inc/diff');
20 * Afficher le diff d'un champ texte generique
22 * @param string $champ
25 * @param string $format
26 * apercu, diff ou complet
29 function afficher_diff_champ_dist($champ, $old, $new, $format = 'diff') {
30 // ne pas se compliquer la vie !
32 $out = ($format != 'complet' ?
'' : $new);
34 if ($f = charger_fonction($champ, 'afficher_diff', true)) {
35 return $f($champ, $old, $new, $format);
38 $diff = new Diff(new DiffTexte
);
39 $n = preparer_diff($new);
40 $o = preparer_diff($old);
42 $out = afficher_diff($diff->comparer($n, $o));
43 if ($format == 'diff' or $format == 'apercu') {
44 $out = afficher_para_modifies($out, ($format == 'apercu'));
53 * https://code.spip.net/@afficher_para_modifies
55 * @param string $texte
59 function afficher_para_modifies($texte, $court = false) {
60 // Limiter la taille de l'affichage
68 $paras = explode("\n", $texte);
69 for ($i = 0; $i < count($paras) and strlen($texte_ret) < $max; $i++
) {
70 if (strpos($paras[$i], '"diff-')) {
71 $texte_ret .= $paras[$i] . "\n\n";
73 # if (strlen($texte_ret) > $max) $texte_ret .= '(...)';