X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;ds=sidebyside;f=www%2Fplugins%2Fauto%2Fcfg%2Fcfg_fonctions.php;fp=www%2Fplugins%2Fauto%2Fcfg%2Fcfg_fonctions.php;h=d9502ef22304d0717bd918ed63b3d3de2fc16ce1;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hp=0000000000000000000000000000000000000000;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c;p=velocampus%2Fweb%2Fwww.git diff --git a/www/plugins/auto/cfg/cfg_fonctions.php b/www/plugins/auto/cfg/cfg_fonctions.php new file mode 100644 index 0000000..d9502ef --- /dev/null +++ b/www/plugins/auto/cfg/cfg_fonctions.php @@ -0,0 +1,317 @@ +code = 'lire_config(' . $arg . ',' . + ($sinon && $sinon != "''" ? $sinon : 'null') . ',' . $unserialize . ')'; + + return $p; +} +} + +# CFG_CHEMIN + +/** + * La balise CFG_CHEMIN retourne le chemin d'une image stockee + * par cfg. + * + * cfg stocke : 'config/vue/champ.ext' (ce qu'affiche #CONFIG)
+ * #cfg_chemin retourne l'adresse complete : 'IMG/config/vue/champ.ext' + * + * @param Object $p Arbre syntaxique du compilo + * @return Object + */ +function balise_CFG_CHEMIN_dist($p) { + if (!$arg = interprete_argument_balise(1,$p)) { + $arg = "''"; + } + $sinon = interprete_argument_balise(2,$p); + + $p->code = '($l = lire_config(' . $arg . ',' . + ($sinon && $sinon != "''" ? $sinon : 'null') . ')) ? _DIR_IMG . $l : null'; + + return $p; +} + + +/** + * #EDIT_CONFIG : Pour jouer avec les Crayons et les configurations + * + * + *
+ * #CONFIG{plugin/casier/cle} + *
+ *
+ * + * @param $p + * @return + */ +function balise_EDIT_CONFIG_dist($p) { + $config = interprete_argument_balise(1,$p); + $instance = interprete_argument_balise(2,$p); + $instance = $instance ? $instance : "'0'"; + $p->code = 'classe_config_crayon('.$config.', '.$instance.')'; + $p->statut = 'php'; + $p->interdire_scripts = false; + return $p; +} + +/** + * Classe qui sera utilisé pour CFG dans le bloc éditable par Crayon + * + * @param string $config + * @param string $instance + * @return string + */ +function classe_config_crayon($config, $instance) { + // pour n'avoir que des caracteres alphanumeriques, + // on transforme "depot::plugin/casier/cle" en "depot___plugin__casier__cle" + $config = cfg_config2crayon($config); + // return 'crayon composant-'.$composant.'-'.$instance.' type_pinceau'; + return 'crayon config-'.$config.'-'.$instance . ' type_config'; +} + +/** + * Outil de manipulation des classes + * + * @param string $config classe pour CFG + * @return string classe pour Crayon + */ +function cfg_config2crayon($config) {return str_replace(array('::','/'), array('___','__'), $config);} + +/** + * Outil de manipulation des classes + * + * @param string $crayon classe pour Crayon + * @return string classe pour CFG + */ +function cfg_crayon2config($crayon) {return str_replace(array('___','__'), array('::','/'), $crayon);} + +/** + * autorisation de configurer + * + * @param string $faire + * @param string $type + * @param string $id + * @param string $qui + * @param string $opt + * @return boolean + */ +function autoriser_config_crayonner_dist($faire, $type, $id, $qui, $opt) { + return autoriser('configurer', $type, $id, $qui, $opt); +} + +/** + * autorisation de crayonner + * + * @param string $faire + * @param string $type + * @param string $id + * @param string $qui + * @param string $opt + * @return boolean + */ +function autoriser_config_modifier_dist($faire, $type, $id, $qui, $opt) { + return autoriser('crayonner', $type, $id, $qui, $opt); +} + + +# CFG_ARBO + +/** + * Affiche une arborescence du contenu d'un #CONFIG + * + * - #CFG_ARBO, + * - #CFG_ARBO{ma_meta}, + * - #CFG_ARBO{~toto}, + * - #CFG_ARBO{ma_meta/mon_casier}, + * - #CFG_ARBO{ma_table:mon_id/mon_champ} + * + * @param Object $p + * @return Object + */ +function balise_CFG_ARBO_dist($p) { + if (!$arg = interprete_argument_balise(1,$p)) { + $arg = "''"; + } + $p->interdire_scripts = false; + $p->code = 'cfg_affiche_arborescence(' . $arg . ')'; + return $p; +} + +/** + * Fonction utilisée par le compilo pour {@see balise_CFG_ARBO_dist} : + * affiche l'arborescence qui est calculée par {@see cfg_affiche_sous_arborescence} + * + * @param string $cfg nom de la table meta + * @return string code html en sortie + */ +function cfg_affiche_arborescence($cfg='') { + + $sortie = ''; + $hash = substr(md5(rand()*rand()),0,6); + + // integration du css + // Suppression de cette inclusion des css arbo au profit d'une inclusion d'un fichier cfg.css dans le header prive +// $sortie .= "\n"; + + // integration du js + $sortie .= "\n"; + + $tableau = lire_config($cfg); + if ($c = @unserialize($tableau)) $tableau = $c; + + if (empty($cfg)) $cfg = 'spip_meta'; + // parcours des donnees + $sortie .= + "
\n" . + cfg_affiche_sous_arborescence($cfg, $tableau) . + "\n
\n"; + + + return $sortie; +} + +/** + * Calcul récursif de l'arborescence des configurations + * + * @param string $nom nom de la table meta + * @param Array $tableau configuration + * @return string code html en sortie + */ +function cfg_affiche_sous_arborescence($nom, $tableau){ + $sortie = "\n
$nom
\n"; + $sortie .= "\n\n"; + return $sortie; +} + + + + +if (!function_exists('filtre_cle_dist')) { +/** + * Cette fonction retourne une valeur dans un tableau arborescent + * en indiquant la cle souhaitee. On descend dans la profondeur de + * l'arborescence du tableau par des slash. + * Si on donne un chaine serialisee en entree a la place d'un tableau, + * la fonction tente de la deserialiser. + * + * Exemples : + * $x = array("a1"=>array("b1"=>array("c1"=>3), "b2"=>4), "a2"=>8); + * filtre_cle_dist($x, "a2") = 8 + * filtre_cle_dist($x, "a1") = array("b1"=>array("c1"=>3), "b2"=>4) + * filtre_cle_dist($x, "a1/b2") = 4 + * filtre_cle_dist($x, "a1/b1/c1") = 3 + * + * Depuis un squelette SPIP : [(#TABLEAU|cle{a1/b1/c1})] + * + * @param array/string $tab : tableau ou tableau serialise + * @param string $chemin : chemin d'acces a une valeur du tableau tel que "cleA/cleB/cleC" + * @param string $defaut : valeur a retourner par defaut, si la cle n'est pas trouvee + * + * @return la valeur correspondant a la cle demandee, $defaut sinon +**/ +function filtre_cle_dist($tab, $chemin, $defaut=null) { + if (!$tab) { + return $defaut; + } + if (!is_array($tab)) { + if (!is_string($tab) + or !$tab = @unserialize($tab) + or !is_array($tab) + ) { + return $defaut; + } + } + $position = &$tab; + $chemins = explode('/', $chemin); + foreach ($chemins as $cle) { + if (!isset($position[$cle])) { + return $defaut; + } + $position = $position[$cle]; + } + return $position; +} +} + + + + +?>