spip-paragrapher.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. if (!defined('_ECRIRE_INC_VERSION')) return;
  3. /**
  4. * callback fermer-para-mano
  5. * on refait le preg, a la main
  6. */
  7. function fermer_para_mano(&$t) {
  8. # match: ",<p (.*)<(/?)(STOP P|div|pre|ul|ol|li|blockquote|h[1-6r]|t(able|[rdh]|head|body|foot|extarea)|form|object|center|marquee|address|applet|iframe|d[ltd]|script|noscript|map|button|fieldset|style)\b,UimsS"
  9. # replace: "\n<p "+trim($1)+"</p>\n<$2$3"
  10. foreach (explode('<p ', $t) as $c => $p) {
  11. if ($c == 0)
  12. $t = $p;
  13. else {
  14. $pi = strtolower($p);
  15. if (preg_match(
  16. ",</?(?:stop p|div|pre|ul|ol|li|blockquote|h[1-6r]|t(able|[rdh]|head|body|foot|extarea)|form|object|center|marquee|address|applet|iframe|d[ltd]|script|noscript|map|button|fieldset|style)\b,S",
  17. $pi, $r)) {
  18. $pos = strpos($pi, $r[0]);
  19. $t .= "<p ".str_replace("\n", _AUTOBR."\n", rtrim(substr($p,0,$pos)))."</p>\n".substr($p,$pos);
  20. } else {
  21. $t .= '<p '.$p;
  22. }
  23. }
  24. }
  25. if (_AUTOBR) {
  26. $t = str_replace(_AUTOBR."\n"."<br", "<br", $t); #manque /i
  27. $reg = ',(<br\b[^>]*>\s*)'.preg_quote(_AUTOBR."\n", ',').",iS";
  28. $t = preg_replace($reg, '\1', $t);
  29. }
  30. return $t;
  31. }