[SPIP] ~v3.0.17-->v3.0.19
[ptitvelo/web/www.git] / www / ecrire / iterateur / data.php
index c4c623a..4ccaa43 100644 (file)
@@ -3,7 +3,7 @@
 /***************************************************************************\
  *  SPIP, Systeme de publication pour l'internet                           *
  *                                                                         *
- *  Copyright (c) 2001-2012                                                *
+ *  Copyright (c) 2001-2014                                                *
  *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
  *                                                                         *
  *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
@@ -125,7 +125,7 @@ class IterateurDATA implements Iterator {
        }
 
        /**
-        * Srtocker en cache si possible
+        * Stocker en cache si possible
         * @param  $cle
         * @param  $ttl
         * @return
@@ -145,8 +145,8 @@ class IterateurDATA implements Iterator {
                                'ttl' => $ttl
                        ),
                        3600 + $ttl);
-                       # conserver le cache 1h deplus que la validite demandee,
-                       # pour le cas ou le serveur distant ne repond plus
+                       # conserver le cache 1h de plus que la validite demandee,
+                       # pour le cas ou le serveur distant ne reponde plus
        }
 
        /**
@@ -168,7 +168,7 @@ class IterateurDATA implements Iterator {
                        $this->command['sourcemode'] = $this->command['from'][0];
                }
 
-               // cherchons defferents moyens de creer le tableau de donnees
+               // cherchons differents moyens de creer le tableau de donnees
                // les commandes connues pour l'iterateur DATA
                // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...}
                
@@ -386,7 +386,7 @@ class IterateurDATA implements Iterator {
                        if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) {
                                // tri par cle
                                if ($r[1] == 'cle'){
-                                       if (isset($r2) and $r[2])
+                                       if (isset($r[2]) and $r[2])
                                                krsort($this->tableau);
                                        else
                                                ksort($this->tableau);
@@ -411,7 +411,7 @@ class IterateurDATA implements Iterator {
                                        $a = '.sprintf($tv,'$aa').';
                                        $b = '.sprintf($tv,'$bb').';
                                        if ($a <> $b)
-                                               return ($a ' . ($r[2] ? '>' : '<').' $b) ? -1 : 1;';
+                                               return ($a ' . ((isset($r[2]) and $r[2]) ? '>' : '<').' $b) ? -1 : 1;';
                                }
                        }
                }
@@ -426,7 +426,7 @@ class IterateurDATA implements Iterator {
 
 
        /**
-        * Grouper les resurltats
+        * Grouper les resultats
         * {fusion /x/y/z}
         * 
        **/
@@ -518,7 +518,25 @@ function inc_plugins_to_array_dist() {
  * @return array
  */
 function inc_xml_to_array_dist($u) {
-       return @ObjectToArray(new SimpleXmlIterator($u));
+       return @XMLObjectToArray(new SimpleXmlIterator($u));
+}
+
+/**
+ *
+ * object -> tableau
+ *
+ * @param    object  $object The object to convert
+ * @return   array
+ *
+ */
+function inc_object_to_array( $object ) {
+    if( !is_object( $object ) && !is_array( $object ) ) {
+        return $object;
+    }
+    if( is_object( $object ) ) {
+        $object = get_object_vars( $object );
+    }
+    return array_map( 'inc_object_to_array', $object );
 }
 
 /**
@@ -535,7 +553,7 @@ function inc_yql_to_array_dist($u) {
                throw new Exception('YQL: r&#233;ponse vide ou mal form&#233;e');
                return false;
        }
-       return (array) $w;
+       return inc_object_to_array($w);
 }
 
 /**
@@ -679,7 +697,7 @@ function inc_ls_to_array_dist($u) {
  * @param Object $object
  * @return array|bool
  */
-function ObjectToArray($object){
+function XMLObjectToArray($object){
        $xml_array = array();
        for( $object->rewind(); $object->valid(); $object->next() ) {
                if(array_key_exists($key = $object->key(), $xml_array)){
@@ -690,7 +708,7 @@ function ObjectToArray($object){
                        foreach($vars['@attributes'] as $k => $v)
                        $xml_array[$key][$k] = $v;
                if($object->hasChildren()){
-                       $xml_array[$key][] = ObjectToArray(
+                       $xml_array[$key][] = XMLObjectToArray(
                                $object->current());
                }
                else{