[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / yaml / inc / yaml.php
index 0e12ea0..59f8974 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
-if (!defined("_ECRIRE_INC_VERSION")) return;
+if (!defined('_ECRIRE_INC_VERSION')) {
+       return;
+}
 
 # textwheel fournit yaml_decode() aussi...
 # include_spip('inc/yaml-mini');
@@ -13,13 +15,14 @@ if (!defined("_ECRIRE_INC_VERSION")) return;
 # Regle de dev: ne pas se rendre dependant de la lib sous-jacente
 
 // Si on est en PHP4
- if (version_compare(PHP_VERSION, '5.0.0', '<'))
-       define('_LIB_YAML','spyc-php4'); 
- else {
+if (version_compare(PHP_VERSION, '5.0.0', '<')) {
+       define('_LIB_YAML', 'spyc-php4');
+} else {
        // temporaire le temps de tester spyc
-       define('_LIB_YAML','sfyaml'); 
-       #define('_LIB_YAML','spyc'); 
+       define('_LIB_YAML', 'sfyaml');
+       #define('_LIB_YAML','spyc');
 }
+
 /*
  * Encode n'importe quelle structure en yaml
  * @param $struct
@@ -47,7 +50,7 @@ function yaml_encode($struct, $opt = array()) {
  *        boolean $show_error  true: arrete le parsing et retourne erreur en cas d'echec  - false: retourne un simple false en cas d'erreur de parsing
  */
 if (!function_exists('yaml_decode')) {
-function yaml_decode($input,$show_error=true) {
+function yaml_decode($input, $show_error = true) {
        // Si PHP4
        if (_LIB_YAML == 'spyc-php4') {
                require_once _DIR_PLUGIN_YAML.'spyc/spyc-php4.php';
@@ -60,24 +63,24 @@ function yaml_decode($input,$show_error=true) {
        }
 
        require_once _DIR_PLUGIN_YAML.'inc/yaml_sfyaml.php';
-       return yaml_sfyaml_decode($input,$show_error);
+       return yaml_sfyaml_decode($input, $show_error);
 }
 }
 
 /*
  * Decode un fichier en utilisant yaml_decode
- * @param string $fichier 
+ * @param string $fichier
  */
-function yaml_decode_file($fichier){
+function yaml_decode_file($fichier) {
        $yaml = '';
        $retour = false;
-       
+
        lire_fichier($fichier, $yaml);
        // Si on recupere bien quelque chose
-       if ($yaml){
+       if ($yaml) {
                $retour = yaml_decode($yaml);
        }
-       
+
        return $retour;
 }
 
@@ -87,24 +90,22 @@ function yaml_decode_file($fichier){
  * On passe donc par find_in_path() pour trouver le fichier
  * @param array $tableau
  */
-
-function yaml_charger_inclusions($tableau){
-       if (is_array($tableau)){
+function yaml_charger_inclusions($tableau) {
+       if (is_array($tableau)) {
                $retour = array();
-               foreach($tableau as $cle => $valeur) {
-                       if (is_string($valeur) && substr($valeur,0,8)=='inclure:' && substr($valeur,-5)=='.yaml')
-                               $retour = array_merge($retour,yaml_charger_inclusions(yaml_decode_file(find_in_path(substr($valeur,8)))));
-                       elseif (is_array($valeur))
-                               $retour = array_merge($retour,array($cle => yaml_charger_inclusions($valeur)));
-                       else
-                               $retour = array_merge($retour,array($cle => $valeur));
+               foreach ($tableau as $cle => $valeur) {
+                       if (is_string($valeur) && substr($valeur, 0, 8) == 'inclure:' && substr($valeur, -5) == '.yaml') {
+                               $retour = array_merge($retour, yaml_charger_inclusions(yaml_decode_file(find_in_path(substr($valeur, 8)))));
+                       } elseif (is_array($valeur)) {
+                               $retour = array_merge($retour, array($cle => yaml_charger_inclusions($valeur)));
+                       } else {
+                               $retour = array_merge($retour, array($cle => $valeur));
+                       }
                }
                return $retour;
-       }
-       elseif (is_string($tableau) && substr($tableau,0,8)=='inclure:' && substr($tableau,-5)=='.yaml')
-               return yaml_charger_inclusions(yaml_decode_file(find_in_path(substr($tableau,8))));
-       else
+       } elseif (is_string($tableau) && substr($tableau, 0, 8) == 'inclure:' && substr($tableau, -5) == '.yaml') {
+               return yaml_charger_inclusions(yaml_decode_file(find_in_path(substr($tableau, 8))));
+       } else {
                return $tableau;
+       }
 }
-
-?>