source: trunk/spip/esqueleto-redcta/plugins/cfg/cfg_fonctions.php @ 152

Last change on this file since 152 was 152, checked in by guille, 15 years ago

se agregaron svn_update y cfg para el 2.0

File size: 3.6 KB
Line 
1<?php
2
3if (!defined("_ECRIRE_INC_VERSION")) return;
4
5
6# CONFIG
7
8
9// #CONFIG retourne lire_config()
10//
11// Le 3eme argument permet de controler la serialisation du resultat
12// (mais ne sert que pour le depot 'meta') qui doit parfois deserialiser
13// ex: |in_array{#CONFIG{toto,#ARRAY,1}}.
14// Ceci n'affecte pas d'autres depots et |in_array{#CONFIG{toto/,#ARRAY}} sera equivalent
15// car du moment qu'il y a un /, c'est le depot 'metapack' qui est appelle.
16//
17function balise_CONFIG($p) {
18        if (!$arg = interprete_argument_balise(1,$p)) {
19                $arg = "''";
20        }
21        $sinon = interprete_argument_balise(2,$p);
22        $unserialize = sinon(interprete_argument_balise(3,$p),"false");
23
24        $p->code = 'lire_config(' . $arg . ',' . 
25                ($sinon && $sinon != "''" ? $sinon : 'null') . ',' . $unserialize . ')';       
26
27        return $p;
28}
29
30
31
32# CFG_CHEMIN
33
34//
35// La balise CFG_CHEMIN retourne le chemin d'une image stockee
36// par cfg.
37//
38// cfg stocke : 'config/vue/champ.ext' (ce qu'affiche #CONFIG)
39// #cfg_chemin retourne l'adresse complete : 'IMG/config/vue/champ.ext'
40//
41function balise_CFG_CHEMIN_dist($p) {
42        if (!$arg = interprete_argument_balise(1,$p)) {
43                $arg = "''";
44        }
45        $sinon = interprete_argument_balise(2,$p);
46       
47        $p->code = '($l = lire_config(' . $arg . ',' . 
48                ($sinon && $sinon != "''" ? $sinon : 'null') . ')) ? _DIR_IMG . $l : null';             
49       
50        return $p;
51}
52
53
54
55# CFG_ARBO
56
57
58/*
59 * Affiche une arborescence du contenu d'un #CONFIG
60 *
61 * #CFG_ARBO,
62 * #CFG_ARBO{ma_meta},
63 * #CFG_ARBO{~toto},
64 * #CFG_ARBO{ma_meta/mon_casier},
65 * #CFG_ARBO{ma_table:mon_id/mon_champ}
66 *
67 */
68function balise_CFG_ARBO_dist($p) {
69        if (!$arg = interprete_argument_balise(1,$p)) {
70                $arg = "''";
71        }
72        $p->interdire_scripts = false;
73        $p->code = 'cfg_affiche_arborescence(' . $arg . ')';
74        return $p;
75}
76
77function cfg_affiche_arborescence($cfg='') {
78
79        $sortie = '';
80        $hash = substr(md5(rand()*rand()),0,6);
81       
82        // integration du css
83        // Suppression de cette inclusion des css arbo au profit d'une inclusion d'un fichier cfg.css dans le header prive
84//      $sortie .= "<style type='text/css'>\n"
85//                      .  ".cfg_arbo{}\n"
86//                      .  ".cfg_arbo h5{padding:0.2em 0.2em; margin:0.2em 0; cursor:pointer;}\n"
87//                      .  ".cfg_arbo ul{border:1px solid #ccc; margin:0; padding:0.2em 0.5em; list-style-type:none;}\n"
88//                      .  "</style>\n";
89
90        // integration du js   
91        $sortie .= "<script type='text/javascript'><!--
92                               
93                                $(document).ready(function(){
94                                        function cfg_arbo(){
95                                                jQuery('#cfg_arbo_$hash ul').hide();
96                                                jQuery('#cfg_arbo_$hash h5')
97                                                .prepend('<strong>[+] <\/strong>')
98                                                .toggle(
99                                                  function () {
100                                                        $(this).children('strong').text('[-] ');
101                                                        $(this).next('ul').show();
102                                                  },
103                                                  function () {
104                                                        $(this).children('strong').text('[+] ');
105                                                        $(this).next('ul').hide();
106                                                  });                                           
107                                        }
108                                        setTimeout(cfg_arbo,100);
109
110                                });
111                                // --></script>\n";
112                               
113        $tableau = lire_config($cfg);
114        if ($c = @unserialize($tableau)) $tableau = $c;
115       
116        if (empty($cfg)) $cfg = 'spip_meta';
117        // parcours des donnees
118        $sortie .= 
119                "<div class='cfg_arbo' id='cfg_arbo_$hash'>\n" .
120                cfg_affiche_sous_arborescence($cfg, $tableau) .
121                "\n</div>\n";
122
123
124        return $sortie;
125}
126
127function cfg_affiche_sous_arborescence($nom, $tableau){
128        $sortie = "\n<h5>$nom</h5>\n";
129        $sortie .= "\n<ul>";
130        if (is_array($tableau)){
131                ksort($tableau);
132                foreach ($tableau as $tab=>$val){
133                        if (is_array($val)) 
134                                $sortie .= cfg_affiche_sous_arborescence($tab, $val);
135                        elseif (false !== $v = @unserialize($val))
136                                $sortie .= cfg_affiche_sous_arborescence($tab, $v);
137                        else
138                                $sortie .= "<li>$tab = " . htmlentities($val) ."</li>\n";
139                       
140                }
141        } else {
142                $sortie .= "<li>$nom = " . htmlentities($tableau) . "</li>";
143        }
144        $sortie .= "</ul>\n";
145        return $sortie; 
146}
147
148?>
Note: See TracBrowser for help on using the repository browser.