[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / cfg / depots / meta.php
1 <?php
2
3 /**
4 * Plugin générique de configuration pour SPIP
5 *
6 * @license GNU/GPL
7 * @package plugins
8 * @subpackage cfg
9 * @category outils
10 * @copyright (c) toggg, marcimat 2007-2008
11 * @link http://www.spip-contrib.net/
12 * @version $Id: meta.php 36744 2010-03-29 02:31:19Z gilles.vincent@gmail.com $
13 */
14
15 if (!defined("_ECRIRE_INC_VERSION")) return;
16
17 /**
18 * Retrouve et met a jour les donnees a plat dans spip_meta
19 * @package plugins
20 * @subpackage cfg
21 */
22 class cfg_depot_meta
23 {
24 /**
25 * Les champs manipulés
26 * @var Array
27 */
28 var $champs = array();
29
30 /**
31 * Si on passe par cfg_id, ça fait..
32 * Heu.. Quelque chose d'utile ?
33 * @var Array
34 */
35 var $champs_id = array();
36
37 /**
38 * Les valeurs en dépôt
39 * @var Array
40 */
41 var $val = array();
42
43 /**
44 * Les différents paramètres : Tables, Colonnes, cfg_id, et Casier
45 * @var Array
46 */
47 var $param = array();
48
49 /**
50 * Pour gestion de l'affichage en succès ou échec
51 * @var Array
52 */
53 var $messages = array('message_ok'=>array(), 'message_erreur'=>array(), 'erreurs'=>array());
54
55 /**
56 * version du depot
57 * @var int
58 */
59 var $version = 2;
60
61 /**
62 *
63 * @param Array $params
64 */
65 function cfg_depot_meta($params=array())
66 {
67 foreach ($params as $o=>$v) {
68 $this->$o = $v;
69 }
70 }
71
72
73 /**
74 * recuperer les valeurs.
75 *
76 * unserialize : si la valeur est deserialisable, elle est retournee deserialisee
77 * permet a #CONFIG d'obtenir une valeur non deserialisee...
78 *
79 * @param boolean $unserialize
80 * @return Array
81 */
82 function lire($unserialize=true)
83 {
84 $val = array();
85 if ($this->champs) {
86 foreach ($this->champs as $name => $def) {
87 // pour compat cfg, si la meta est deserialisable, la retourner deserialisee
88 if ($unserialize && ($a = @unserialize($GLOBALS['meta'][$name])))
89 $val[$name] = $a;
90 else {
91 $val[$name] = $GLOBALS['meta'][$name];
92 }
93 }
94 // si pas d'argument, retourner comme le core serialize($GLOBALS['meta'])
95 } else {
96 $val = serialize($GLOBALS['meta']);
97 }
98 return array(true, $val);
99 }
100
101
102 /**
103 * ecrit chaque enregistrement de meta pour chaque champ
104 *
105 * @return Array
106 */
107 function ecrire()
108 {
109 foreach ($this->champs as $name => $def) {
110 ecrire_meta($name, $this->val[$name]);
111 }
112 if (defined('_COMPAT_CFG_192')) ecrire_metas();
113 return array(true, $this->val);
114 }
115
116
117 /**
118 * supprime chaque enregistrement de meta pour chaque champ
119 *
120 * @return Array
121 */
122 function effacer(){
123 foreach ($this->champs as $name => $def) {
124 if (!$this->val[$name]) {
125 effacer_meta($name);
126 }
127 }
128 if (defined('_COMPAT_CFG_192')) ecrire_metas();
129 return array(true, $this->val);
130 }
131
132
133 /**
134 * charger les arguments de lire_config(meta::nom)
135 *
136 * @param string $args # $args = 'nom'; ici
137 * @return boolean
138 */
139 function charger_args($args){
140 if ($args) $this->champs = array($args=>true);
141 return true;
142 }
143 }
144 ?>