From 3ae87dd5f19679596b23465dcfddbe46a13aae1c Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Sun, 16 Jul 2006 11:48:40 +0000
Subject: [PATCH] prendre en charge les tag autofermant (<.../>) dans le parser
 xml

---
 ecrire/inc/plugin.php | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/ecrire/inc/plugin.php b/ecrire/inc/plugin.php
index ef96b40e5d..360c893b11 100644
--- a/ecrire/inc/plugin.php
+++ b/ecrire/inc/plugin.php
@@ -265,18 +265,26 @@ function parse_plugin_xml($texte){
 		if (strlen($before)>0)
 			return $texte; // before non vide, donc on est dans du texte
 	
-		$tag = $chars[1];$closing_tag = explode(" ",trim($tag));$closing_tag=reset($closing_tag);
+		$tag = $chars[1];
+		$closing_tag = explode(" ",trim($tag));$closing_tag=reset($closing_tag);
 		$txt = $chars[2];
 	
-		// tag fermant
-		$chars = preg_split("{(</".preg_quote($closing_tag).">)}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
-		if (!isset($chars[1])) { // tag fermant manquant
-			$out[$tag][]="erreur : tag fermant $tag manquant::$txt"; 
-			return $out;
+		if(substr($tag,-1)=='/'){ // self closing tag
+			$tag = substr($tag,0,strlen($tag)-1);
+			$out[$tag][]="";
+			$txt = trim($txt);
+		}
+		else{
+			// tag fermant
+			$chars = preg_split("{(</".preg_quote($closing_tag).">)}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE);
+			if (!isset($chars[1])) { // tag fermant manquant
+				$out[$tag][]="erreur : tag fermant $tag manquant::$txt"; 
+				return $out;
+			}
+			$content = $chars[0];
+			$txt = trim($chars[2]);
+			$out[$tag][]=parse_plugin_xml($content);
 		}
-		$content = $chars[0];
-		$txt = trim($chars[2]);
-		$out[$tag][]=parse_plugin_xml($content);
 	}
 	if (count($out)&&(strlen($txt)==0))
 		return $out;
@@ -289,8 +297,11 @@ function applatit_arbre($arbre,$separateur = " "){
 	if (is_array($arbre))
 		foreach($arbre as $tag=>$feuille){
 			if (is_array($feuille)){
-				if ($tag!==intval($tag))
-					$s.="<$tag>".applatit_arbre($feuille)."</$tag>";
+				if ($tag!==intval($tag)){
+					$f = applatit_arbre($feuille);
+					if (strlen($f))	$s.="<$tag>$f</$tag>";
+					else $s.="<$tag/>";
+				}
 				else
 					$s.=applatit_arbre($feuille);
 				$s .= $separateur;
-- 
GitLab