/***************************************************************************\
* SPIP, Systeme de publication pour l'internet *
* *
- * Copyright (c) 2001-2016 *
+ * Copyright (c) 2001-2017 *
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
* *
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
-if (!defined('_ECRIRE_INC_VERSION')) return;
-
-
+if (!defined('_ECRIRE_INC_VERSION')) {
+ return;
+}
/**
* Transforme un texte XML en tableau PHP
+ *
* @param string|object $u
* @param bool $utiliser_namespace
* @return array
*/
-function inc_simplexml_to_array_dist($u, $utiliser_namespace=false){
+function inc_simplexml_to_array_dist($u, $utiliser_namespace = false) {
// decoder la chaine en SimpleXML si pas deja fait
- if (is_string($u))
+ if (is_string($u)) {
$u = simplexml_load_string($u);
- return array('root'=>@xmlObjToArr($u, $utiliser_namespace));
+ }
+
+ return array('root' => @xmlObjToArr($u, $utiliser_namespace));
}
* @param object $obj
* @param bool $utiliser_namespace
* @return array
-**/
-function xmlObjToArr($obj, $utiliser_namespace=false) {
+ **/
+function xmlObjToArr($obj, $utiliser_namespace = false) {
$tableau = array();
// Cette fonction getDocNamespaces() est longue sur de gros xml. On permet donc
// de l'activer ou pas suivant le contenu supposé du XML
if (is_object($obj)) {
- if (is_array($utiliser_namespace)){
+ if (is_array($utiliser_namespace)) {
$namespace = $utiliser_namespace;
- }
- else {
- if ($utiliser_namespace)
+ } else {
+ if ($utiliser_namespace) {
$namespace = $obj->getDocNamespaces(true);
- $namespace[NULL] = NULL;
+ }
+ $namespace[null] = null;
}
$name = strtolower((string)$obj->getName());
$text = trim((string)$obj);
if (strlen($text) <= 0) {
- $text = NULL;
+ $text = null;
}
$children = array();
$attributes = array();
// get info for all namespaces
- foreach( $namespace as $ns=>$nsUrl ) {
+ foreach ($namespace as $ns => $nsUrl) {
// attributes
$objAttributes = $obj->attributes($ns, true);
- foreach( $objAttributes as $attributeName => $attributeValue ) {
+ foreach ($objAttributes as $attributeName => $attributeValue) {
$attribName = strtolower(trim((string)$attributeName));
$attribVal = trim((string)$attributeValue);
if (!empty($ns)) {
// children
$objChildren = $obj->children($ns, true);
- foreach( $objChildren as $childName=>$child ) {
+ foreach ($objChildren as $childName => $child) {
$childName = strtolower((string)$childName);
- if( !empty($ns) ) {
- $childName = $ns.':'.$childName;
+ if (!empty($ns)) {
+ $childName = $ns . ':' . $childName;
}
$children[$childName][] = xmlObjToArr($child, $namespace);
}
}
$tableau = array(
- 'name'=>$name,
+ 'name' => $name,
);
- if ($text)
+ if ($text) {
$tableau['text'] = $text;
- if ($attributes)
+ }
+ if ($attributes) {
$tableau['attributes'] = $attributes;
- if ($children)
+ }
+ if ($children) {
$tableau['children'] = $children;
+ }
}
return $tableau;
}
-
-?>