champ.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /***************************************************************************\
  3. * SPIP, Systeme de publication pour l'internet *
  4. * *
  5. * Copyright (c) 2001-2014 *
  6. * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
  7. * *
  8. * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
  9. * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
  10. \***************************************************************************/
  11. if (!defined("_ECRIRE_INC_VERSION")) return;
  12. include_spip('inc/diff');
  13. /**
  14. * Afficher le diff d'un champ texte generique
  15. * @param string $champ
  16. * @param string $old
  17. * @param string $new
  18. * @param string $format
  19. * apercu, diff ou complet
  20. * @return string
  21. */
  22. function afficher_diff_champ_dist($champ,$old,$new,$format='diff'){
  23. // ne pas se compliquer la vie !
  24. if ($old==$new)
  25. $out = ($format!='complet'?'':$new);
  26. else {
  27. if($f = charger_fonction($champ,'afficher_diff', true)){
  28. return $f($champ, $old, $new, $format);
  29. }
  30. $diff = new Diff(new DiffTexte);
  31. $n = preparer_diff($new);
  32. $o = preparer_diff($old);
  33. $out = afficher_diff($diff->comparer($n,$o));
  34. if ($format == 'diff' OR $format == 'apercu')
  35. $out = afficher_para_modifies($out, ($format == 'apercu'));
  36. }
  37. return $out;
  38. }
  39. /**
  40. * http://code.spip.net/@afficher_para_modifies
  41. *
  42. * @param string $texte
  43. * @param bool $court
  44. * @return string
  45. */
  46. function afficher_para_modifies ($texte, $court = false) {
  47. // Limiter la taille de l'affichage
  48. if ($court) $max = 200;
  49. else $max = 2000;
  50. $texte_ret = "";
  51. $paras = explode ("\n",$texte);
  52. for ($i = 0; $i < count($paras) AND strlen($texte_ret) < $max; $i++) {
  53. if (strpos($paras[$i], '"diff-')) $texte_ret .= $paras[$i]."\n\n";
  54. # if (strlen($texte_ret) > $max) $texte_ret .= '(...)';
  55. }
  56. $texte = $texte_ret;
  57. return $texte;
  58. }