[SPIP] +2.1.12
[velocampus/web/www.git] / www / plugins / auto / cfg / inc / compat_cfg.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 2007
11 * @link http://www.spip-contrib.net/
12 * @version $Id: compat_cfg.php 36744 2010-03-29 02:31:19Z gilles.vincent@gmail.com $
13 */
14
15 if (!defined("_ECRIRE_INC_VERSION")) return;
16
17 /**
18 * CFG doit-il être compatible SPIP 1.9.2 ?
19 * @ignore
20 */
21 define('_COMPAT_CFG_192', true);
22
23 if (version_compare($GLOBALS['spip_version_code'], '11216', '<')
24 && !function_exists('balise_ACTION_FORMULAIRE_dist')) {
25 function balise_ACTION_FORMULAIRE_dist($p){
26 $p->code="''";
27 $p->interdire_scripts = false;
28 return $p;
29 }
30 }
31
32 /* fichier de compatibilite vers spip 1.9.2 */
33 if (version_compare($GLOBALS['spip_version_code'], '1.9300', '<')
34 AND $f = charger_fonction('compat_cfg', 'inc'))
35 $f();
36
37 /**
38 * Gestion de la compatibilité avec SPIP 1.9.2
39 *
40 * <b>ceci n'est pas l'original du plugin compat mais la copie pour CFG</b>
41 *
42 * En termes de distribution ce fichier PEUT etre recopie dans chaque plugin
43 * qui desire en avoir une version autonome (voire forkee), A CONDITION DE
44 * RENOMMER le fichier et ses deux fonctions ; c'est un peu lourd a maintenir
45 * mais c'est le prix a payer pour l'independance des plugins entre eux :-(
46 *
47 * la version commune a tous est developpee sur
48 * {@link http://zone.spip.org/spip-zone/browser/_dev_/compat/ svn://zone.spip.org/spip-zone/_dev_/compat/}
49 *
50 * @param Array $quoi
51 */
52 function inc_compat_cfg_dist($quoi = NULL) {
53 if (!function_exists($f = 'compat_cfg_defs')) $f .= '_dist';
54 $defs = $f();
55
56 include_spip('base/abstract_sql');
57
58 if (is_string($quoi))
59 $quoi = array($quoi);
60 else if (is_null($quoi))
61 $quoi = array_keys($defs);
62
63 foreach ($quoi as $d) {
64 if (!function_exists($d)
65 AND isset($defs[$d])) {
66 eval ("function $d".$defs[$d]);
67 }
68 }
69 }
70
71 /**
72 * Calcule le tableau de compatibilité des fonctions non définies sous SPIP2.0
73 * (fournit leur arbre syntaxique manipulé par le compilo)
74 *
75 * @return Array
76 */
77 function compat_cfg_defs_dist() {
78 $defs = array(
79 // on fait au plus simple pour le journal
80 'journal' =>
81 '($phrase, $opt = array()) {
82 return spip_log($phrase, \'journal\');
83 }',
84
85 'push' =>
86 '($array, $val) {
87 if($array == \'\' OR !array_push($array, $val)) return \'\';
88 return $array;
89 }',
90
91 'et' =>
92 '($code, $arg) {
93 return ((($code) AND ($arg)) ?\' \' :\'\');
94 }',
95
96 'ou' =>
97 '($code, $arg) {
98 return ((($code) OR ($arg)) ?\' \' :\'\');
99 }',
100
101 'xou' =>
102 '($code, $arg) {
103 return ((($code) XOR ($arg)) ?\' \' :\'\');
104 }',
105
106 'non' =>
107 '($code) {
108 return (($code) ?\'\' :\' \');
109 }',
110
111 'oui' =>
112 '($code) {
113 return (($code) ?\' \' :\'\');
114 }',
115
116 'sql_fetch' =>
117 '(
118 $res,
119 $serveur=\'\'
120 ) {
121 return spip_fetch_array($res);
122 }',
123
124 'sql_query' =>
125 '($res, $serveur=\'\') {
126 return spip_query($res);
127 }',
128
129 // n'existe pas en 1.9.2
130 'sql_alter' =>
131 '($res, $serveur=\'\') {
132 return spip_query(\'ALTER \' . $res);
133 }',
134
135 // n'existe pas en 1.9.2
136 // on cree la requete directement
137 'sql_delete' =>
138 '($table, $where=\'\', $serveur=\'\') {
139 if (!is_array($table)) $table = array($table);
140 if (!is_array($where)) $where = array($where);
141 $query = \'DELETE FROM \'
142 . implode(\',\', $table)
143 . \' WHERE \'
144 . implode(\' AND \', $where);
145 return spip_query($query);
146 }',
147
148 // sql_quote : _q directement
149 'sql_quote' =>
150 '(
151 $val,
152 $serveur=\'\'
153 ) {
154 return _q($val);
155 }',
156
157 'sql_select' =>
158 '(
159 $select = array(),
160 $from = array(),
161 $where = array(),
162 $groupby = array(),
163 $orderby = array(),
164 $limit = \'\',
165 $having = array(),
166 $serveur=\'\'
167 ) {
168 return spip_abstract_select(
169 $select,
170 $from,
171 $where,
172 $groupby,
173 $orderby,
174 $limit,
175 $sousrequete = \'\',
176 $having,
177 $table = \'\',
178 $id = \'\',
179 $serveur);
180 }',
181
182 'sql_fetsel' =>
183 '(
184 $select = array(),
185 $from = array(),
186 $where = array(),
187 $groupby = array(),
188 $orderby = array(),
189 $limit = \'\',
190 $having = array(),
191 $serveur=\'\'
192 ) {
193 return sql_fetch(sql_select(
194 $select,
195 $from,
196 $where,
197 $groupby,
198 $orderby,
199 $limit,
200 $having,
201 $serveur
202 ));
203 }',
204
205 'sql_getfetsel' =>
206 '(
207 $select,
208 $from = array(),
209 $where = array(),
210 $groupby = array(),
211 $orderby = array(),
212 $limit = \'\',
213 $having = array(),
214 $serveur=\'\'
215 ) {
216 $r = sql_fetsel(
217 $select,
218 $from,
219 $where,
220 $groupby,
221 $orderby,
222 $limit,
223 $having,
224 $serveur
225 );
226 return $r ? $r[$select] : NULL;
227 }',
228
229 'sql_allfetsel' =>
230 '(
231 $select,
232 $from = array(),
233 $where = array(),
234 $groupby = array(),
235 $orderby = array(),
236 $limit = \'\',
237 $having = array(),
238 $serveur=\'\'
239 ) {
240 $q = sql_select(
241 $select,
242 $from,
243 $where,
244 $groupby,
245 $orderby,
246 $limit,
247 $having,
248 $serveur
249 );
250 if (!$q) return array();
251 $res = array();
252 while ($r = sql_fetch($q)) $res[] = $r;
253 return $res;
254 }',
255
256 // n'existe pas en 1.9.2
257 // on cree la requete directement
258 'sql_update' =>
259 '(
260 $table,
261 $champs,
262 $where=\'\',
263 $desc=array(),
264 $serveur=\'\'
265 ) {
266 if (!is_array($table)) $table = array($table);
267 if (!is_array($champs)) $champs = array($champs);
268 if (!is_array($where)) $where = array($where);
269
270 $query = $r = \'\';
271 foreach ($champs as $champ => $val)
272 $r .= \',\' . $champ . "=$val";
273 if ($r = substr($r, 1))
274 $query = \'UPDATE \'
275 . implode(\',\', $table)
276 . \' SET \' . $r
277 . (empty($where) ? \'\' :\' WHERE \' . implode(\' AND \', $where));
278 if ($query)
279 return spip_query($query);
280 }',
281
282 'sql_updateq' =>
283 '(
284 $table,
285 $champs,
286 $where=\'\',
287 $desc=array(),
288 $serveur=\'\'
289 ) {
290 if (!is_array($champs)) $exp = array($champs);
291
292 foreach ($champs as $k => $val) {
293 $champs[$k] = sql_quote($val);
294 }
295
296 return sql_update(
297 $table,
298 $champs,
299 $where,
300 $desc,
301 $serveur
302 );
303 }',
304
305
306 // n'existe pas en 1.9.2
307 // on cree la requete directement
308 'sql_insertq' =>
309 '(
310 $table,
311 $champs
312 ) {
313 if (!is_array($champs)) $exp = array($champs);
314
315 foreach ($champs as $k => $val) {
316 $champs[$k] = sql_quote($val);
317 }
318
319 $query = "INSERT INTO $table (".implode(",", array_keys($champs)).") VALUES (".implode(",", $champs).")";
320 return sql_query($query);
321 }',
322
323 'sql_showtable' => '($table, $serveur=\'\') {
324 include_spip("base/abstract_sql");
325 return spip_abstract_showtable($table, \'mysql\', true);
326 }',
327
328
329 'sql_count' =>
330 '(
331 $res,
332 $serveur=\'\'
333 ) {
334 return spip_mysql_count($res);
335 }',
336
337
338 'sql_countsel' =>
339 '(
340 $from = array(),
341 $where = array(),
342 $groupby = array(),
343 $limit = \'\',
344 $having = array(),
345 $serveur=\'\'
346 ) {
347 return(sql_getfetsel(\'COUNT(*)\', $from, $where, $groupby, \'\', $limit, $having, $serveur));
348 }',
349
350 'sql_selectdb' =>
351 '(
352 $res,
353 $serveur=\'\'
354 ) {
355 $GLOBALS[\'spip_mysql_db\'] = mysql_select_db($res);
356 return $GLOBALS[\'spip_mysql_db\'];
357 }'
358
359 );
360 return $defs;
361 }
362
363 ?>