[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / plugins-dist / revisions / afficher_diff / champ.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
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 \***************************************************************************/
12
13 if (!defined("_ECRIRE_INC_VERSION")) return;
14
15 include_spip('inc/diff');
16
17 /**
18 * Afficher le diff d'un champ texte generique
19 * @param string $champ
20 * @param string $old
21 * @param string $new
22 * @param string $format
23 * apercu, diff ou complet
24 * @return string
25 */
26 function afficher_diff_champ_dist($champ,$old,$new,$format='diff'){
27 // ne pas se compliquer la vie !
28 if ($old==$new)
29 $out = ($format!='complet'?'':$new);
30 else {
31 if($f = charger_fonction($champ,'afficher_diff', true)){
32 return $f($champ, $old, $new, $format);
33 }
34
35 $diff = new Diff(new DiffTexte);
36 $n = preparer_diff($new);
37 $o = preparer_diff($old);
38
39 $out = afficher_diff($diff->comparer($n,$o));
40 if ($format == 'diff' OR $format == 'apercu')
41 $out = afficher_para_modifies($out, ($format == 'apercu'));
42 }
43 return $out;
44 }
45
46
47 /**
48 * http://code.spip.net/@afficher_para_modifies
49 *
50 * @param string $texte
51 * @param bool $court
52 * @return string
53 */
54 function afficher_para_modifies ($texte, $court = false) {
55 // Limiter la taille de l'affichage
56 if ($court) $max = 200;
57 else $max = 2000;
58
59 $texte_ret = "";
60 $paras = explode ("\n",$texte);
61 for ($i = 0; $i < count($paras) AND strlen($texte_ret) < $max; $i++) {
62 if (strpos($paras[$i], '"diff-')) $texte_ret .= $paras[$i]."\n\n";
63 # if (strlen($texte_ret) > $max) $texte_ret .= '(...)';
64 }
65 $texte = $texte_ret;
66 return $texte;
67 }