efd968a492054325233ef8112d27ad4f3ece00a1
[lhc/web/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-2013 *
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
32 $diff = new Diff(new DiffTexte);
33 $n = preparer_diff($new);
34 $o = preparer_diff($old);
35
36 $out = afficher_diff($diff->comparer($n,$o));
37 if ($format == 'diff' OR $format == 'apercu')
38 $out = afficher_para_modifies($out, ($format == 'apercu'));
39 }
40 return $out;
41 }
42
43
44 /**
45 * http://doc.spip.org/@afficher_para_modifies
46 *
47 * @param string $texte
48 * @param bool $court
49 * @return string
50 */
51 function afficher_para_modifies ($texte, $court = false) {
52 // Limiter la taille de l'affichage
53 if ($court) $max = 200;
54 else $max = 2000;
55
56 $texte_ret = "";
57 $paras = explode ("\n",$texte);
58 for ($i = 0; $i < count($paras) AND strlen($texte_ret) < $max; $i++) {
59 if (strpos($paras[$i], '"diff-')) $texte_ret .= $paras[$i]."\n\n";
60 # if (strlen($texte_ret) > $max) $texte_ret .= '(...)';
61 }
62 $texte = $texte_ret;
63 return $texte;
64 }