@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | /** |
| 32 | 32 | * Raccourcis dépendant du sens de la langue |
| 33 | 33 | * |
| 34 | - * @return array Tablea ('','') |
|
| 34 | + * @return string[] Tablea ('','') |
|
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | 37 | return array('', ''); |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | * Ne fait rien ici. Voir plugin Textwheel |
| 355 | 355 | * |
| 356 | 356 | * @param string $letexte |
| 357 | - * @param null $forcer |
|
| 357 | + * @param boolean|null $forcer |
|
| 358 | 358 | * @return string |
| 359 | 359 | */ |
| 360 | 360 | function paragrapher($letexte, $forcer = true) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return array('', ''); |
|
| 37 | + return array('', ''); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,19 +102,19 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (array('script', 'iframe') as $tag) { |
|
| 106 | - if (stripos($t, "<$tag") !== false |
|
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | - ) { |
|
| 109 | - foreach ($r as $regs) { |
|
| 110 | - $t = str_replace($regs[0], |
|
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | - $t); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return $t; |
|
| 105 | + foreach (array('script', 'iframe') as $tag) { |
|
| 106 | + if (stripos($t, "<$tag") !== false |
|
| 107 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | + ) { |
|
| 109 | + foreach ($r as $regs) { |
|
| 110 | + $t = str_replace($regs[0], |
|
| 111 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 112 | + $t); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return $t; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -143,55 +143,55 @@ discard block |
||
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | 145 | function interdire_scripts($arg, $mode_filtre=null) { |
| 146 | - // on memorise le resultat sur les arguments non triviaux |
|
| 147 | - static $dejavu = array(); |
|
| 148 | - |
|
| 149 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | - return $arg; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | - return $dejavu[$mode_filtre][$arg]; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // echapper les tags asp/php |
|
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | - |
|
| 165 | - // echapper le php |
|
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | - |
|
| 168 | - // echapper le < script language=php > |
|
| 169 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | - |
|
| 171 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | - switch ($mode_filtre) { |
|
| 173 | - case 0: |
|
| 174 | - if (!_DIR_RESTREINT) { |
|
| 175 | - $t = echappe_js($t); |
|
| 176 | - } |
|
| 177 | - break; |
|
| 178 | - case -1: |
|
| 179 | - $t = echappe_js($t); |
|
| 180 | - break; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // pas de <base href /> svp ! |
|
| 184 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | - |
|
| 186 | - // Reinserer les echappements des modeles |
|
| 187 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | - } |
|
| 190 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 146 | + // on memorise le resultat sur les arguments non triviaux |
|
| 147 | + static $dejavu = array(); |
|
| 148 | + |
|
| 149 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 150 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 151 | + return $arg; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) { |
|
| 155 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 159 | + return $dejavu[$mode_filtre][$arg]; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // echapper les tags asp/php |
|
| 163 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 164 | + |
|
| 165 | + // echapper le php |
|
| 166 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 167 | + |
|
| 168 | + // echapper le < script language=php > |
|
| 169 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 170 | + |
|
| 171 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 172 | + switch ($mode_filtre) { |
|
| 173 | + case 0: |
|
| 174 | + if (!_DIR_RESTREINT) { |
|
| 175 | + $t = echappe_js($t); |
|
| 176 | + } |
|
| 177 | + break; |
|
| 178 | + case -1: |
|
| 179 | + $t = echappe_js($t); |
|
| 180 | + break; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // pas de <base href /> svp ! |
|
| 184 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 185 | + |
|
| 186 | + // Reinserer les echappements des modeles |
|
| 187 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 188 | + $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 189 | + } |
|
| 190 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -220,64 +220,64 @@ discard block |
||
| 220 | 220 | * Texte transformé |
| 221 | 221 | **/ |
| 222 | 222 | function typo($letexte, $echapper = true, $connect = null, $env = array()) { |
| 223 | - // Plus vite ! |
|
| 224 | - if (!$letexte) { |
|
| 225 | - return $letexte; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | - // prive etant historiquement ecrit sans argment $connect |
|
| 230 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | - // ou il faut passer interdire_script explicitement |
|
| 232 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | - // ne seront pas perturbes |
|
| 234 | - $interdire_script = false; |
|
| 235 | - if (is_null($connect)) { |
|
| 236 | - $connect = ''; |
|
| 237 | - $interdire_script = true; |
|
| 238 | - $env['espace_prive'] = test_espace_prive(); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - // Echapper les codes <html> etc |
|
| 242 | - if ($echapper) { |
|
| 243 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // |
|
| 247 | - // Installer les modeles, notamment images et documents ; |
|
| 248 | - // |
|
| 249 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | - // cf. inc/lien |
|
| 251 | - |
|
| 252 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | - if ($letexte != $mem) { |
|
| 254 | - $echapper = true; |
|
| 255 | - } |
|
| 256 | - unset($mem); |
|
| 257 | - |
|
| 258 | - $letexte = corriger_typo($letexte); |
|
| 259 | - $letexte = echapper_faux_tags($letexte); |
|
| 260 | - |
|
| 261 | - // reintegrer les echappements |
|
| 262 | - if ($echapper) { |
|
| 263 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | - if ($interdire_script) { |
|
| 268 | - $letexte = interdire_scripts($letexte); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | - // https://core.spip.net/issues/3371 |
|
| 273 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | - // https://core.spip.net/issues/4166 |
|
| 275 | - if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | - $letexte = echapper_html_suspect($letexte); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $letexte; |
|
| 223 | + // Plus vite ! |
|
| 224 | + if (!$letexte) { |
|
| 225 | + return $letexte; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 229 | + // prive etant historiquement ecrit sans argment $connect |
|
| 230 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 231 | + // ou il faut passer interdire_script explicitement |
|
| 232 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 233 | + // ne seront pas perturbes |
|
| 234 | + $interdire_script = false; |
|
| 235 | + if (is_null($connect)) { |
|
| 236 | + $connect = ''; |
|
| 237 | + $interdire_script = true; |
|
| 238 | + $env['espace_prive'] = test_espace_prive(); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + // Echapper les codes <html> etc |
|
| 242 | + if ($echapper) { |
|
| 243 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // |
|
| 247 | + // Installer les modeles, notamment images et documents ; |
|
| 248 | + // |
|
| 249 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 250 | + // cf. inc/lien |
|
| 251 | + |
|
| 252 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 253 | + if ($letexte != $mem) { |
|
| 254 | + $echapper = true; |
|
| 255 | + } |
|
| 256 | + unset($mem); |
|
| 257 | + |
|
| 258 | + $letexte = corriger_typo($letexte); |
|
| 259 | + $letexte = echapper_faux_tags($letexte); |
|
| 260 | + |
|
| 261 | + // reintegrer les echappements |
|
| 262 | + if ($echapper) { |
|
| 263 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 267 | + if ($interdire_script) { |
|
| 268 | + $letexte = interdire_scripts($letexte); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 272 | + // https://core.spip.net/issues/3371 |
|
| 273 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 274 | + // https://core.spip.net/issues/4166 |
|
| 275 | + if ($GLOBALS['filtrer_javascript'] == -1 |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 277 | + $letexte = echapper_html_suspect($letexte); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $letexte; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // Correcteur typographique |
@@ -302,57 +302,57 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | function corriger_typo($letexte, $lang = '') { |
| 304 | 304 | |
| 305 | - // Plus vite ! |
|
| 306 | - if (!$letexte) { |
|
| 307 | - return $letexte; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | - |
|
| 312 | - // Caracteres de controle "illegaux" |
|
| 313 | - $letexte = corriger_caracteres($letexte); |
|
| 314 | - |
|
| 315 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | - foreach ($regs as $reg) { |
|
| 318 | - $insert = $reg[0]; |
|
| 319 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // trouver les blocs idiomes et les traiter à part |
|
| 327 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | - $ei = ($ei !== $letexte); |
|
| 329 | - |
|
| 330 | - // trouver les blocs multi et les traiter a part |
|
| 331 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | - $em = ($em !== $letexte); |
|
| 333 | - |
|
| 334 | - // Charger & appliquer les fonctions de typographie |
|
| 335 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | - $letexte = $typographie($letexte); |
|
| 337 | - |
|
| 338 | - // Les citations en une autre langue, s'il y a lieu |
|
| 339 | - if ($em) { |
|
| 340 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | - } |
|
| 342 | - if ($ei) { |
|
| 343 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Retablir les caracteres proteges |
|
| 347 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | - |
|
| 349 | - // pipeline |
|
| 350 | - $letexte = pipeline('post_typo', $letexte); |
|
| 351 | - |
|
| 352 | - # un message pour abs_url - on est passe en mode texte |
|
| 353 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | - |
|
| 355 | - return $letexte; |
|
| 305 | + // Plus vite ! |
|
| 306 | + if (!$letexte) { |
|
| 307 | + return $letexte; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 311 | + |
|
| 312 | + // Caracteres de controle "illegaux" |
|
| 313 | + $letexte = corriger_caracteres($letexte); |
|
| 314 | + |
|
| 315 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 316 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 317 | + foreach ($regs as $reg) { |
|
| 318 | + $insert = $reg[0]; |
|
| 319 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 320 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 321 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 322 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // trouver les blocs idiomes et les traiter à part |
|
| 327 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 328 | + $ei = ($ei !== $letexte); |
|
| 329 | + |
|
| 330 | + // trouver les blocs multi et les traiter a part |
|
| 331 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 332 | + $em = ($em !== $letexte); |
|
| 333 | + |
|
| 334 | + // Charger & appliquer les fonctions de typographie |
|
| 335 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 336 | + $letexte = $typographie($letexte); |
|
| 337 | + |
|
| 338 | + // Les citations en une autre langue, s'il y a lieu |
|
| 339 | + if ($em) { |
|
| 340 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 341 | + } |
|
| 342 | + if ($ei) { |
|
| 343 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Retablir les caracteres proteges |
|
| 347 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 348 | + |
|
| 349 | + // pipeline |
|
| 350 | + $letexte = pipeline('post_typo', $letexte); |
|
| 351 | + |
|
| 352 | + # un message pour abs_url - on est passe en mode texte |
|
| 353 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 354 | + |
|
| 355 | + return $letexte; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function paragrapher($letexte, $forcer = true) { |
| 371 | - return $letexte; |
|
| 371 | + return $letexte; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -380,11 +380,11 @@ discard block |
||
| 380 | 380 | * @return string Texte |
| 381 | 381 | **/ |
| 382 | 382 | function traiter_retours_chariots($letexte) { |
| 383 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | - $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | - $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 383 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 384 | + $letexte = preg_replace(",<p[>[:space:]],iS", "\n\n\\0", $letexte); |
|
| 385 | + $letexte = preg_replace(",</p[>[:space:]],iS", "\\0\n\n", $letexte); |
|
| 386 | 386 | |
| 387 | - return $letexte; |
|
| 387 | + return $letexte; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -410,37 +410,37 @@ discard block |
||
| 410 | 410 | * Texte transformé |
| 411 | 411 | **/ |
| 412 | 412 | function propre($t, $connect = null, $env = array()) { |
| 413 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | - // prive etant historiquement ecrits sans argment $connect |
|
| 415 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | - // ou il faut passer interdire_script explicitement |
|
| 417 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | - // ne seront pas perturbes |
|
| 419 | - $interdire_script = false; |
|
| 420 | - if (is_null($connect)) { |
|
| 421 | - $connect = ''; |
|
| 422 | - $interdire_script = true; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if (!$t) { |
|
| 426 | - return strval($t); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | - // avant echappement des balises <html> |
|
| 431 | - // https://core.spip.net/issues/3371 |
|
| 432 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | - // https://core.spip.net/issues/4166 |
|
| 434 | - if ($interdire_script |
|
| 435 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | - $t = echapper_html_suspect($t, false); |
|
| 439 | - } |
|
| 440 | - $t = echappe_html($t); |
|
| 441 | - $t = expanser_liens($t, $connect, $env); |
|
| 442 | - $t = traiter_raccourcis($t); |
|
| 443 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | - |
|
| 445 | - return $t; |
|
| 413 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 414 | + // prive etant historiquement ecrits sans argment $connect |
|
| 415 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 416 | + // ou il faut passer interdire_script explicitement |
|
| 417 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 418 | + // ne seront pas perturbes |
|
| 419 | + $interdire_script = false; |
|
| 420 | + if (is_null($connect)) { |
|
| 421 | + $connect = ''; |
|
| 422 | + $interdire_script = true; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if (!$t) { |
|
| 426 | + return strval($t); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 430 | + // avant echappement des balises <html> |
|
| 431 | + // https://core.spip.net/issues/3371 |
|
| 432 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 433 | + // https://core.spip.net/issues/4166 |
|
| 434 | + if ($interdire_script |
|
| 435 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 438 | + $t = echapper_html_suspect($t, false); |
|
| 439 | + } |
|
| 440 | + $t = echappe_html($t); |
|
| 441 | + $t = expanser_liens($t, $connect, $env); |
|
| 442 | + $t = traiter_raccourcis($t); |
|
| 443 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 444 | + |
|
| 445 | + return $t; |
|
| 446 | 446 | } |
@@ -104,11 +104,11 @@ discard block |
||
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | 105 | foreach (array('script', 'iframe') as $tag) { |
| 106 | 106 | if (stripos($t, "<$tag") !== false |
| 107 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 107 | + and preg_match_all(',<'.$tag.'.*?($|</'.$tag.'.),isS', $t, $r, PREG_SET_ORDER) |
|
| 108 | 108 | ) { |
| 109 | 109 | foreach ($r as $regs) { |
| 110 | 110 | $t = str_replace($regs[0], |
| 111 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 111 | + "<code$class>".nl2br(spip_htmlspecialchars($regs[0])).'</code>', |
|
| 112 | 112 | $t); |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @return string |
| 143 | 143 | * Code protégé |
| 144 | 144 | **/ |
| 145 | -function interdire_scripts($arg, $mode_filtre=null) { |
|
| 145 | +function interdire_scripts($arg, $mode_filtre = null) { |
|
| 146 | 146 | // on memorise le resultat sur les arguments non triviaux |
| 147 | 147 | static $dejavu = array(); |
| 148 | 148 | |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // echapper les tags asp/php |
| 163 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 163 | + $t = str_replace('<'.'%', '<%', $arg); |
|
| 164 | 164 | |
| 165 | 165 | // echapper le php |
| 166 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 166 | + $t = str_replace('<'.'?', '<?', $t); |
|
| 167 | 167 | |
| 168 | 168 | // echapper le < script language=php > |
| 169 | 169 | $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | // Reinserer les echappements des modeles |
| 187 | 187 | if (defined('_PROTEGE_JS_MODELES')) { |
| 188 | - $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES); |
|
| 188 | + $t = echappe_retour($t, "javascript"._PROTEGE_JS_MODELES); |
|
| 189 | 189 | } |
| 190 | 190 | if (defined('_PROTEGE_PHP_MODELES')) { |
| 191 | - $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES); |
|
| 191 | + $t = echappe_retour($t, "php"._PROTEGE_PHP_MODELES); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $dejavu[$mode_filtre][$arg] = $t; |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
| 274 | 274 | // https://core.spip.net/issues/4166 |
| 275 | 275 | if ($GLOBALS['filtrer_javascript'] == -1 |
| 276 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 276 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 277 | 277 | $letexte = echapper_html_suspect($letexte); |
| 278 | 278 | } |
| 279 | 279 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | define('_TYPO_PROTEGER', "!':;?~%-"); |
| 285 | 285 | define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8"); |
| 286 | 286 | |
| 287 | -define('_TYPO_BALISE', ",</?[a-z!][^<>]*[" . preg_quote(_TYPO_PROTEGER) . "][^<>]*>,imsS"); |
|
| 287 | +define('_TYPO_BALISE', ",</?[a-z!][^<>]*[".preg_quote(_TYPO_PROTEGER)."][^<>]*>,imsS"); |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * Corrige la typographie |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | // https://core.spip.net/issues/4166 |
| 434 | 434 | if ($interdire_script |
| 435 | 435 | or $GLOBALS['filtrer_javascript'] == -1 |
| 436 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0) |
|
| 437 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) { |
|
| 436 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 437 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)) { |
|
| 438 | 438 | $t = echapper_html_suspect($t, false); |
| 439 | 439 | } |
| 440 | 440 | $t = echappe_html($t); |
@@ -245,7 +245,7 @@ |
||
| 245 | 245 | * @param array $matches |
| 246 | 246 | * Branches de l'arbre validant la rexgep |
| 247 | 247 | * @param bool $init ? |
| 248 | - * @return bool |
|
| 248 | + * @return integer |
|
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -47,23 +47,23 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1048576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ""; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | - } else { |
|
| 55 | - lire_fichier($fichier, $contenu); |
|
| 56 | - } |
|
| 57 | - $arbre = array(); |
|
| 58 | - if ($contenu) { |
|
| 59 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | - } |
|
| 50 | + $contenu = ""; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_page($fichier, false, false, $taille_max, $datas); |
|
| 54 | + } else { |
|
| 55 | + lire_fichier($fichier, $contenu); |
|
| 56 | + } |
|
| 57 | + $arbre = array(); |
|
| 58 | + if ($contenu) { |
|
| 59 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return count($arbre) ? $arbre : false; |
|
| 62 | + return count($arbre) ? $arbre : false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 66 | - define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 66 | + define('_SPIP_XML_TAG_SPLIT', "{<([^:>][^>]*?)>}sS"); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,151 +82,151 @@ discard block |
||
| 82 | 82 | * - false si l'arbre xml ne peut être créé ou est vide |
| 83 | 83 | **/ |
| 84 | 84 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 85 | - $out = array(); |
|
| 86 | - // enlever les commentaires |
|
| 87 | - $charset = 'AUTO'; |
|
| 88 | - if ($clean === true) { |
|
| 89 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | - $charset = $regs[2]; |
|
| 91 | - } |
|
| 92 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | - include_spip('inc/charsets'); |
|
| 95 | - $clean = $charset; |
|
| 96 | - //$texte = importer_charset($texte,$charset); |
|
| 97 | - } |
|
| 98 | - if (is_string($clean)) { |
|
| 99 | - $charset = $clean; |
|
| 100 | - } |
|
| 101 | - $txt = $texte; |
|
| 85 | + $out = array(); |
|
| 86 | + // enlever les commentaires |
|
| 87 | + $charset = 'AUTO'; |
|
| 88 | + if ($clean === true) { |
|
| 89 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | + $charset = $regs[2]; |
|
| 91 | + } |
|
| 92 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | + include_spip('inc/charsets'); |
|
| 95 | + $clean = $charset; |
|
| 96 | + //$texte = importer_charset($texte,$charset); |
|
| 97 | + } |
|
| 98 | + if (is_string($clean)) { |
|
| 99 | + $charset = $clean; |
|
| 100 | + } |
|
| 101 | + $txt = $texte; |
|
| 102 | 102 | |
| 103 | - // tant qu'il y a des tags |
|
| 104 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | - while (count($chars) >= 2) { |
|
| 106 | - // tag ouvrant |
|
| 107 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 103 | + // tant qu'il y a des tags |
|
| 104 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | + while (count($chars) >= 2) { |
|
| 106 | + // tag ouvrant |
|
| 107 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 108 | 108 | |
| 109 | - // $before doit etre vide ou des espaces uniquements! |
|
| 110 | - $before = trim($chars[0]); |
|
| 109 | + // $before doit etre vide ou des espaces uniquements! |
|
| 110 | + $before = trim($chars[0]); |
|
| 111 | 111 | |
| 112 | - if (strlen($before) > 0) { |
|
| 113 | - return importer_charset($texte, $charset); |
|
| 114 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 112 | + if (strlen($before) > 0) { |
|
| 113 | + return importer_charset($texte, $charset); |
|
| 114 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 115 | 115 | |
| 116 | - $tag = rtrim($chars[1]); |
|
| 117 | - $txt = $chars[2]; |
|
| 116 | + $tag = rtrim($chars[1]); |
|
| 117 | + $txt = $chars[2]; |
|
| 118 | 118 | |
| 119 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | - return importer_charset($texte, $charset); |
|
| 121 | - }//$texte; |
|
| 122 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | - $out[$tag][] = ""; |
|
| 125 | - } else { |
|
| 126 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | - $closing_tag = reset($closing_tag); |
|
| 128 | - // tag fermant |
|
| 129 | - $ncclos = strlen("</$closing_tag>"); |
|
| 130 | - $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | - if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | - $nclose = 0; |
|
| 133 | - $nopen = 0; |
|
| 134 | - $d = 0; |
|
| 135 | - while ( |
|
| 136 | - $p !== false |
|
| 137 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | - $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | - ) { |
|
| 141 | - $nclose++; |
|
| 142 | - $d = $p + $ncclos; |
|
| 143 | - $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - if ($p === false) { |
|
| 147 | - if ($strict) { |
|
| 148 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 119 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 120 | + return importer_charset($texte, $charset); |
|
| 121 | + }//$texte; |
|
| 122 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 123 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | + $out[$tag][] = ""; |
|
| 125 | + } else { |
|
| 126 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | + $closing_tag = reset($closing_tag); |
|
| 128 | + // tag fermant |
|
| 129 | + $ncclos = strlen("</$closing_tag>"); |
|
| 130 | + $p = strpos($txt, "</$closing_tag>"); |
|
| 131 | + if ($p !== false and (strpos($txt, "<") < $p)) { |
|
| 132 | + $nclose = 0; |
|
| 133 | + $nopen = 0; |
|
| 134 | + $d = 0; |
|
| 135 | + while ( |
|
| 136 | + $p !== false |
|
| 137 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | + and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | + $matches, PREG_SET_ORDER)) > $nclose) |
|
| 140 | + ) { |
|
| 141 | + $nclose++; |
|
| 142 | + $d = $p + $ncclos; |
|
| 143 | + $p = strpos($txt, "</$closing_tag>", $d); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + if ($p === false) { |
|
| 147 | + if ($strict) { |
|
| 148 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 149 | 149 | |
| 150 | - return $out; |
|
| 151 | - } else { |
|
| 152 | - return importer_charset($texte, $charset); |
|
| 153 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | - } |
|
| 155 | - $content = substr($txt, 0, $p); |
|
| 156 | - $txt = substr($txt, $p + $ncclos); |
|
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | - { |
|
| 159 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | - }//$content; |
|
| 161 | - else { |
|
| 162 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | - } |
|
| 167 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | - return $out; |
|
| 169 | - } else { |
|
| 170 | - return importer_charset($texte, $charset); |
|
| 171 | - }//$texte; |
|
| 150 | + return $out; |
|
| 151 | + } else { |
|
| 152 | + return importer_charset($texte, $charset); |
|
| 153 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 154 | + } |
|
| 155 | + $content = substr($txt, 0, $p); |
|
| 156 | + $txt = substr($txt, $p + $ncclos); |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 158 | + { |
|
| 159 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 160 | + }//$content; |
|
| 161 | + else { |
|
| 162 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 166 | + } |
|
| 167 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 168 | + return $out; |
|
| 169 | + } else { |
|
| 170 | + return importer_charset($texte, $charset); |
|
| 171 | + }//$texte; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // http://code.spip.net/@spip_xml_aplatit |
| 175 | 175 | function spip_xml_aplatit($arbre, $separateur = " ") { |
| 176 | - $s = ""; |
|
| 177 | - if (is_array($arbre)) { |
|
| 178 | - foreach ($arbre as $tag => $feuille) { |
|
| 179 | - if (is_array($feuille)) { |
|
| 180 | - if ($tag !== intval($tag)) { |
|
| 181 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | - if (strlen($f)) { |
|
| 183 | - $tagf = explode(" ", $tag); |
|
| 184 | - $tagf = $tagf[0]; |
|
| 185 | - $s .= "<$tag>$f</$tagf>"; |
|
| 186 | - } else { |
|
| 187 | - $s .= "<$tag />"; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - $s .= spip_xml_aplatit($feuille); |
|
| 191 | - } |
|
| 192 | - $s .= $separateur; |
|
| 193 | - } else { |
|
| 194 | - $s .= "$feuille$separateur"; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 176 | + $s = ""; |
|
| 177 | + if (is_array($arbre)) { |
|
| 178 | + foreach ($arbre as $tag => $feuille) { |
|
| 179 | + if (is_array($feuille)) { |
|
| 180 | + if ($tag !== intval($tag)) { |
|
| 181 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 182 | + if (strlen($f)) { |
|
| 183 | + $tagf = explode(" ", $tag); |
|
| 184 | + $tagf = $tagf[0]; |
|
| 185 | + $s .= "<$tag>$f</$tagf>"; |
|
| 186 | + } else { |
|
| 187 | + $s .= "<$tag />"; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + $s .= spip_xml_aplatit($feuille); |
|
| 191 | + } |
|
| 192 | + $s .= $separateur; |
|
| 193 | + } else { |
|
| 194 | + $s .= "$feuille$separateur"; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 199 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // http://code.spip.net/@spip_xml_tagname |
| 203 | 203 | function spip_xml_tagname($tag) { |
| 204 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | - return $reg[1]; |
|
| 206 | - } |
|
| 204 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 205 | + return $reg[1]; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return ""; |
|
| 208 | + return ""; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // http://code.spip.net/@spip_xml_decompose_tag |
| 212 | 212 | function spip_xml_decompose_tag($tag) { |
| 213 | - $tagname = spip_xml_tagname($tag); |
|
| 214 | - $liste = array(); |
|
| 215 | - $p = strpos($tag, ' '); |
|
| 216 | - $tag = substr($tag, $p); |
|
| 217 | - $p = strpos($tag, '='); |
|
| 218 | - while ($p !== false) { |
|
| 219 | - $attr = trim(substr($tag, 0, $p)); |
|
| 220 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | - $quote = $tag{0}; |
|
| 222 | - $p = strpos($tag, $quote, 1); |
|
| 223 | - $cont = substr($tag, 1, $p - 1); |
|
| 224 | - $liste[$attr] = $cont; |
|
| 225 | - $tag = substr($tag, $p + 1); |
|
| 226 | - $p = strpos($tag, '='); |
|
| 227 | - } |
|
| 213 | + $tagname = spip_xml_tagname($tag); |
|
| 214 | + $liste = array(); |
|
| 215 | + $p = strpos($tag, ' '); |
|
| 216 | + $tag = substr($tag, $p); |
|
| 217 | + $p = strpos($tag, '='); |
|
| 218 | + while ($p !== false) { |
|
| 219 | + $attr = trim(substr($tag, 0, $p)); |
|
| 220 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | + $quote = $tag{0}; |
|
| 222 | + $p = strpos($tag, $quote, 1); |
|
| 223 | + $cont = substr($tag, 1, $p - 1); |
|
| 224 | + $liste[$attr] = $cont; |
|
| 225 | + $tag = substr($tag, $p + 1); |
|
| 226 | + $p = strpos($tag, '='); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return array($tagname, $liste); |
|
| 229 | + return array($tagname, $liste); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 252 | - if ($init) { |
|
| 253 | - $matches = array(); |
|
| 254 | - } |
|
| 255 | - if (is_array($arbre) && count($arbre)) { |
|
| 256 | - foreach (array_keys($arbre) as $tag) { |
|
| 257 | - if (preg_match($regexp, $tag)) { |
|
| 258 | - $matches[$tag] = &$arbre[$tag]; |
|
| 259 | - } |
|
| 260 | - if (is_array($arbre[$tag])) { |
|
| 261 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 252 | + if ($init) { |
|
| 253 | + $matches = array(); |
|
| 254 | + } |
|
| 255 | + if (is_array($arbre) && count($arbre)) { |
|
| 256 | + foreach (array_keys($arbre) as $tag) { |
|
| 257 | + if (preg_match($regexp, $tag)) { |
|
| 258 | + $matches[$tag] = &$arbre[$tag]; |
|
| 259 | + } |
|
| 260 | + if (is_array($arbre[$tag])) { |
|
| 261 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return (count($matches)); |
|
| 268 | + return (count($matches)); |
|
| 269 | 269 | } |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | while ( |
| 136 | 136 | $p !== false |
| 137 | 137 | and ($morceau = substr($txt, $d, $p - $d)) |
| 138 | - and (($nopen += preg_match_all("{<" . preg_quote($closing_tag) . "(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 138 | + and (($nopen += preg_match_all("{<".preg_quote($closing_tag)."(\s*>|\s[^>]*[^/>]>)}is", $morceau, |
|
| 139 | 139 | $matches, PREG_SET_ORDER)) > $nclose) |
| 140 | 140 | ) { |
| 141 | 141 | $nclose++; |
@@ -154,9 +154,11 @@ |
||
| 154 | 154 | } |
| 155 | 155 | $content = substr($txt, 0, $p); |
| 156 | 156 | $txt = substr($txt, $p + $ncclos); |
| 157 | - if ($profondeur == 0 or strpos($content, "<") === false) // eviter une recursion si pas utile |
|
| 157 | + if ($profondeur == 0 or strpos($content, "<") === false) { |
|
| 158 | + // eviter une recursion si pas utile |
|
| 158 | 159 | { |
| 159 | 160 | $out[$tag][] = importer_charset($content, $charset); |
| 161 | + } |
|
| 160 | 162 | }//$content; |
| 161 | 163 | else { |
| 162 | 164 | $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
@@ -235,6 +235,9 @@ |
||
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@install_premier_auteur |
| 238 | +/** |
|
| 239 | + * @param string $hidden |
|
| 240 | + */ |
|
| 238 | 241 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 239 | 242 | return info_progression_etape(3, 'etape_', 'install/') . |
| 240 | 243 | info_etape( |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
| 48 | 48 | |
| 49 | 49 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 50 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 50 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 51 | 51 | |
| 52 | 52 | $fquery = sql_serveur('query', $server_db); |
| 53 | 53 | if ($choix_db == 'new_spip') { |
@@ -57,13 +57,13 @@ discard block |
||
| 57 | 57 | if (!$ok) { |
| 58 | 58 | $re = "Impossible de creer la base $re"; |
| 59 | 59 | spip_log($re); |
| 60 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 60 | + return '<p>'._T('avis_connexion_erreur_creer_base')."</p><!--\n$re\n-->"; |
|
| 61 | 61 | } |
| 62 | 62 | } else { |
| 63 | 63 | $re = "Le nom de la base doit correspondre a $re"; |
| 64 | 64 | spip_log($re); |
| 65 | 65 | |
| 66 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 66 | + return '<p>'._T('avis_connexion_erreur_nom_base')."</p><!--\n$re\n-->"; |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
| 75 | 75 | |
| 76 | 76 | $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
| 77 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 77 | + = $GLOBALS['spip_'.$server_db.'_functions_'.$GLOBALS['spip_sql_version']]; |
|
| 78 | 78 | |
| 79 | 79 | // Completer le tableau decrivant la connexion |
| 80 | 80 | |
| 81 | 81 | $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
| 82 | 82 | $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
| 83 | 83 | |
| 84 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 84 | + $old = sql_showbase($table_prefix.'_meta', $server_db); |
|
| 85 | 85 | if ($old) { |
| 86 | 86 | $old = sql_fetch($old, $server_db); |
| 87 | 87 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $charset['charset']; |
| 101 | 101 | $charsetbase = $charset['charset']; |
| 102 | 102 | } else { |
| 103 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 103 | + spip_log(_DEFAULT_CHARSET.' inconnu du serveur SQL'); |
|
| 104 | 104 | $charsetbase = 'standard'; |
| 105 | 105 | } |
| 106 | 106 | spip_log("Creation des tables. Codage $charsetbase"); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | if ($r) { |
| 151 | 151 | $r = sql_fetch($r, $server_db); |
| 152 | 152 | } |
| 153 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 153 | + $version_installee = !$r ? 0 : (double) $r['valeur']; |
|
| 154 | 154 | if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
| 155 | 155 | $fupdateq( |
| 156 | 156 | 'spip_meta', |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | '', |
| 160 | 160 | $server_db |
| 161 | 161 | ); |
| 162 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 162 | + spip_log('nouvelle version installee: '.$GLOBALS['spip_version_base']); |
|
| 163 | 163 | } |
| 164 | 164 | // eliminer la derniere operation d'admin mal terminee |
| 165 | 165 | // notamment la mise a jour |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | if ($chmod_db) { |
| 187 | 187 | install_fichier_connexion( |
| 188 | 188 | _FILE_CHMOD_TMP, |
| 189 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 189 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', ".sprintf('0%3o', $chmod_db).");\n" |
|
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -236,16 +236,16 @@ discard block |
||
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@install_premier_auteur |
| 238 | 238 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 239 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 239 | + return info_progression_etape(3, 'etape_', 'install/'). |
|
| 240 | 240 | info_etape( |
| 241 | 241 | _T('info_informations_personnelles'), |
| 242 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 243 | - aider('install5', true) . |
|
| 244 | - '<p>' . |
|
| 242 | + '<b>'._T('texte_informations_personnelles_1').'</b>'. |
|
| 243 | + aider('install5', true). |
|
| 244 | + '<p>'. |
|
| 245 | 245 | ($auteur_obligatoire ? |
| 246 | 246 | '' |
| 247 | 247 | : |
| 248 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 248 | + _T('texte_informations_personnelles_2').' '._T('info_laisser_champs_vides') |
|
| 249 | 249 | ) |
| 250 | 250 | ) |
| 251 | 251 | . generer_form_ecrire('install', ( |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | _T('info_identification_publique'), |
| 256 | 256 | array( |
| 257 | 257 | 'nom' => array( |
| 258 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 258 | + 'label' => '<b>'._T('entree_signature')."</b><br />\n"._T('entree_nom_pseudo_1')."\n", |
|
| 259 | 259 | 'valeur' => $nom, |
| 260 | 260 | 'required' => $auteur_obligatoire, |
| 261 | 261 | ), |
| 262 | 262 | 'email' => array( |
| 263 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 263 | + 'label' => '<b>'._T('entree_adresse_email')."</b>\n", |
|
| 264 | 264 | 'valeur' => $email, |
| 265 | 265 | ) |
| 266 | 266 | ) |
@@ -270,23 +270,23 @@ discard block |
||
| 270 | 270 | _T('entree_identifiants_connexion'), |
| 271 | 271 | array( |
| 272 | 272 | 'login' => array( |
| 273 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 273 | + 'label' => '<b>'._T('entree_login')."</b><br />\n"._T( |
|
| 274 | 274 | 'info_login_trop_court_car_pluriel', |
| 275 | 275 | array('nb' => _LOGIN_TROP_COURT) |
| 276 | - ) . "\n", |
|
| 276 | + )."\n", |
|
| 277 | 277 | 'valeur' => $login, |
| 278 | 278 | 'required' => $auteur_obligatoire, |
| 279 | 279 | ), |
| 280 | 280 | 'pass' => array( |
| 281 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 281 | + 'label' => '<b>'._T('entree_mot_passe')."</b><br />\n"._T( |
|
| 282 | 282 | 'info_passe_trop_court_car_pluriel', |
| 283 | 283 | array('nb' => _PASS_LONGUEUR_MINI) |
| 284 | - ) . "\n", |
|
| 284 | + )."\n", |
|
| 285 | 285 | 'valeur' => $pass, |
| 286 | 286 | 'required' => $auteur_obligatoire, |
| 287 | 287 | ), |
| 288 | 288 | 'pass_verif' => array( |
| 289 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 289 | + 'label' => '<b>'._T('info_confirmer_passe')."</b><br />\n", |
|
| 290 | 290 | 'valeur' => $pass, |
| 291 | 291 | 'required' => $auteur_obligatoire, |
| 292 | 292 | ) |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | if ($res) { |
| 333 | 333 | $res = info_progression_etape(2, 'etape_', 'install/', true) |
| 334 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 334 | + . "<div class='error'><h3>"._T('avis_operation_echec').'</h3>' |
|
| 335 | 335 | . $res |
| 336 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 336 | + . '<p>'._T('texte_operation_echec').'</p>' |
|
| 337 | 337 | . '</div>'; |
| 338 | 338 | } |
| 339 | 339 | } else { |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/headers'); |
@@ -20,199 +20,199 @@ discard block |
||
| 20 | 20 | // http://code.spip.net/@install_bases |
| 21 | 21 | function install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db) { |
| 22 | 22 | |
| 23 | - // Prefix des tables : |
|
| 24 | - // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | - // a partir de ce qui est envoye a l'installation |
|
| 26 | - if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | - $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | - ? $GLOBALS['table_prefix'] |
|
| 29 | - : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | - // S'il est vide on remet spip |
|
| 31 | - if (!$table_prefix) { |
|
| 32 | - $table_prefix = 'spip'; |
|
| 33 | - } |
|
| 34 | - } else { |
|
| 35 | - $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 39 | - list(, $adresse_db, $port) = $r; |
|
| 40 | - } else { |
|
| 41 | - $port = ''; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $GLOBALS['connexions'][$server_db] |
|
| 45 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | - |
|
| 47 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | - |
|
| 50 | - $fquery = sql_serveur('query', $server_db); |
|
| 51 | - if ($choix_db == 'new_spip') { |
|
| 52 | - $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | - if (preg_match($re, $sel_db)) { |
|
| 54 | - $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | - if (!$ok) { |
|
| 56 | - $re = "Impossible de creer la base $re"; |
|
| 57 | - spip_log($re); |
|
| 58 | - return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | - } |
|
| 60 | - } else { |
|
| 61 | - $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | - spip_log($re); |
|
| 63 | - |
|
| 64 | - return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | - // un sql_mode |
|
| 70 | - install_mode_appel($server_db, false); |
|
| 71 | - $GLOBALS['connexions'][$server_db] |
|
| 72 | - = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | - |
|
| 74 | - $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | - = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | - |
|
| 77 | - // Completer le tableau decrivant la connexion |
|
| 78 | - |
|
| 79 | - $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | - $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | - |
|
| 82 | - $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | - if ($old) { |
|
| 84 | - $old = sql_fetch($old, $server_db); |
|
| 85 | - } |
|
| 86 | - if (!$old) { |
|
| 87 | - // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | - // dans le codage std de SPIP, |
|
| 89 | - $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | - |
|
| 91 | - if ($charset) { |
|
| 92 | - sql_set_charset($charset['charset'], $server_db); |
|
| 93 | - $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | - $charset['charset']; |
|
| 95 | - $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | - $charset['collation']; |
|
| 97 | - $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | - $charset['charset']; |
|
| 99 | - $charsetbase = $charset['charset']; |
|
| 100 | - } else { |
|
| 101 | - spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | - $charsetbase = 'standard'; |
|
| 103 | - } |
|
| 104 | - spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | - creer_base($server_db); // AT LAST |
|
| 106 | - // memoriser avec quel charset on l'a creee |
|
| 107 | - |
|
| 108 | - if ($charset) { |
|
| 109 | - $t = array( |
|
| 110 | - 'nom' => 'charset_sql_base', |
|
| 111 | - 'valeur' => $charset['charset'], |
|
| 112 | - 'impt' => 'non' |
|
| 113 | - ); |
|
| 114 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 115 | - $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | - $t['valeur'] = $charset['collation']; |
|
| 117 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 118 | - $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | - $t['valeur'] = $charset['charset']; |
|
| 120 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 121 | - } |
|
| 122 | - $t = array( |
|
| 123 | - 'nom' => 'version_installee', |
|
| 124 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | - 'impt' => 'non' |
|
| 126 | - ); |
|
| 127 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 128 | - $t['nom'] = 'nouvelle_install'; |
|
| 129 | - $t['valeur'] = 1; |
|
| 130 | - @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 131 | - // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | - @sql_insertq( |
|
| 134 | - 'spip_meta', |
|
| 135 | - array('nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']), |
|
| 136 | - '', |
|
| 137 | - $server_db |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - // pour recreer les tables disparues au besoin |
|
| 142 | - spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | - creer_base($server_db); |
|
| 144 | - $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | - |
|
| 146 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | - |
|
| 148 | - if ($r) { |
|
| 149 | - $r = sql_fetch($r, $server_db); |
|
| 150 | - } |
|
| 151 | - $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 152 | - if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 153 | - $fupdateq( |
|
| 154 | - 'spip_meta', |
|
| 155 | - array('valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'), |
|
| 156 | - "nom='version_installee'", |
|
| 157 | - '', |
|
| 158 | - $server_db |
|
| 159 | - ); |
|
| 160 | - spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | - } |
|
| 162 | - // eliminer la derniere operation d'admin mal terminee |
|
| 163 | - // notamment la mise a jour |
|
| 164 | - @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // recuperer le charset de la connexion dans les meta |
|
| 168 | - $charset = ''; |
|
| 169 | - $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | - if ($r) { |
|
| 171 | - $r = sql_fetch($r, $server_db); |
|
| 172 | - } |
|
| 173 | - if ($r) { |
|
| 174 | - $charset = $r['valeur']; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | - |
|
| 179 | - $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | - if (!$result_ok) { |
|
| 181 | - return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($chmod_db) { |
|
| 185 | - install_fichier_connexion( |
|
| 186 | - _FILE_CHMOD_TMP, |
|
| 187 | - "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | - // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | - // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | - |
|
| 195 | - if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 196 | - spip_unlink(_FILE_CONNECT); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - install_fichier_connexion( |
|
| 200 | - _FILE_CONNECT_TMP, |
|
| 201 | - $ligne_rappel |
|
| 202 | - . install_connexion( |
|
| 203 | - $adresse_db, |
|
| 204 | - $port, |
|
| 205 | - $login_db, |
|
| 206 | - $pass_db, |
|
| 207 | - $sel_db, |
|
| 208 | - $server_db, |
|
| 209 | - $table_prefix, |
|
| 210 | - '', |
|
| 211 | - $charset |
|
| 212 | - ) |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - return ''; |
|
| 23 | + // Prefix des tables : |
|
| 24 | + // S'il n'est pas defini par mes_options/inc/mutualiser, on va le creer |
|
| 25 | + // a partir de ce qui est envoye a l'installation |
|
| 26 | + if (!defined('_INSTALL_TABLE_PREFIX')) { |
|
| 27 | + $table_prefix = ($GLOBALS['table_prefix'] != 'spip') |
|
| 28 | + ? $GLOBALS['table_prefix'] |
|
| 29 | + : preparer_prefixe_tables(_request('tprefix')); |
|
| 30 | + // S'il est vide on remet spip |
|
| 31 | + if (!$table_prefix) { |
|
| 32 | + $table_prefix = 'spip'; |
|
| 33 | + } |
|
| 34 | + } else { |
|
| 35 | + $table_prefix = _INSTALL_TABLE_PREFIX; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (preg_match(',(.*):(.*),', $adresse_db, $r)) { |
|
| 39 | + list(, $adresse_db, $port) = $r; |
|
| 40 | + } else { |
|
| 41 | + $port = ''; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $GLOBALS['connexions'][$server_db] |
|
| 45 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, '', $server_db); |
|
| 46 | + |
|
| 47 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 48 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 49 | + |
|
| 50 | + $fquery = sql_serveur('query', $server_db); |
|
| 51 | + if ($choix_db == 'new_spip') { |
|
| 52 | + $re = ',^[a-z_][a-z_0-9-]*$,i'; |
|
| 53 | + if (preg_match($re, $sel_db)) { |
|
| 54 | + $ok = sql_create_base($sel_db, $server_db); |
|
| 55 | + if (!$ok) { |
|
| 56 | + $re = "Impossible de creer la base $re"; |
|
| 57 | + spip_log($re); |
|
| 58 | + return '<p>' . _T('avis_connexion_erreur_creer_base') . "</p><!--\n$re\n-->"; |
|
| 59 | + } |
|
| 60 | + } else { |
|
| 61 | + $re = "Le nom de la base doit correspondre a $re"; |
|
| 62 | + spip_log($re); |
|
| 63 | + |
|
| 64 | + return '<p>' . _T('avis_connexion_erreur_nom_base') . "</p><!--\n$re\n-->"; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // on rejoue la connexion apres avoir teste si il faut lui indiquer |
|
| 69 | + // un sql_mode |
|
| 70 | + install_mode_appel($server_db, false); |
|
| 71 | + $GLOBALS['connexions'][$server_db] |
|
| 72 | + = spip_connect_db($adresse_db, $port, $login_db, $pass_db, $sel_db, $server_db); |
|
| 73 | + |
|
| 74 | + $GLOBALS['connexions'][$server_db][$GLOBALS['spip_sql_version']] |
|
| 75 | + = $GLOBALS['spip_' . $server_db . '_functions_' . $GLOBALS['spip_sql_version']]; |
|
| 76 | + |
|
| 77 | + // Completer le tableau decrivant la connexion |
|
| 78 | + |
|
| 79 | + $GLOBALS['connexions'][$server_db]['prefixe'] = $table_prefix; |
|
| 80 | + $GLOBALS['connexions'][$server_db]['db'] = $sel_db; |
|
| 81 | + |
|
| 82 | + $old = sql_showbase($table_prefix . '_meta', $server_db); |
|
| 83 | + if ($old) { |
|
| 84 | + $old = sql_fetch($old, $server_db); |
|
| 85 | + } |
|
| 86 | + if (!$old) { |
|
| 87 | + // Si possible, demander au serveur d'envoyer les textes |
|
| 88 | + // dans le codage std de SPIP, |
|
| 89 | + $charset = sql_get_charset(_DEFAULT_CHARSET, $server_db); |
|
| 90 | + |
|
| 91 | + if ($charset) { |
|
| 92 | + sql_set_charset($charset['charset'], $server_db); |
|
| 93 | + $GLOBALS['meta']['charset_sql_base'] = |
|
| 94 | + $charset['charset']; |
|
| 95 | + $GLOBALS['meta']['charset_collation_sql_base'] = |
|
| 96 | + $charset['collation']; |
|
| 97 | + $GLOBALS['meta']['charset_sql_connexion'] = |
|
| 98 | + $charset['charset']; |
|
| 99 | + $charsetbase = $charset['charset']; |
|
| 100 | + } else { |
|
| 101 | + spip_log(_DEFAULT_CHARSET . ' inconnu du serveur SQL'); |
|
| 102 | + $charsetbase = 'standard'; |
|
| 103 | + } |
|
| 104 | + spip_log("Creation des tables. Codage $charsetbase"); |
|
| 105 | + creer_base($server_db); // AT LAST |
|
| 106 | + // memoriser avec quel charset on l'a creee |
|
| 107 | + |
|
| 108 | + if ($charset) { |
|
| 109 | + $t = array( |
|
| 110 | + 'nom' => 'charset_sql_base', |
|
| 111 | + 'valeur' => $charset['charset'], |
|
| 112 | + 'impt' => 'non' |
|
| 113 | + ); |
|
| 114 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 115 | + $t['nom'] = 'charset_collation_sql_base'; |
|
| 116 | + $t['valeur'] = $charset['collation']; |
|
| 117 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 118 | + $t['nom'] = 'charset_sql_connexion'; |
|
| 119 | + $t['valeur'] = $charset['charset']; |
|
| 120 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 121 | + } |
|
| 122 | + $t = array( |
|
| 123 | + 'nom' => 'version_installee', |
|
| 124 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 125 | + 'impt' => 'non' |
|
| 126 | + ); |
|
| 127 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 128 | + $t['nom'] = 'nouvelle_install'; |
|
| 129 | + $t['valeur'] = 1; |
|
| 130 | + @sql_insertq('spip_meta', $t, '', $server_db); |
|
| 131 | + // positionner la langue par defaut du site si un cookie de lang a ete mis |
|
| 132 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 133 | + @sql_insertq( |
|
| 134 | + 'spip_meta', |
|
| 135 | + array('nom' => 'langue_site', 'valeur' => $_COOKIE['spip_lang_ecrire']), |
|
| 136 | + '', |
|
| 137 | + $server_db |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + // pour recreer les tables disparues au besoin |
|
| 142 | + spip_log('Table des Meta deja la. Verification des autres.'); |
|
| 143 | + creer_base($server_db); |
|
| 144 | + $fupdateq = sql_serveur('updateq', $server_db); |
|
| 145 | + |
|
| 146 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='version_installee'", $server_db); |
|
| 147 | + |
|
| 148 | + if ($r) { |
|
| 149 | + $r = sql_fetch($r, $server_db); |
|
| 150 | + } |
|
| 151 | + $version_installee = !$r ? 0 : (double)$r['valeur']; |
|
| 152 | + if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 153 | + $fupdateq( |
|
| 154 | + 'spip_meta', |
|
| 155 | + array('valeur' => $GLOBALS['spip_version_base'], 'impt' => 'non'), |
|
| 156 | + "nom='version_installee'", |
|
| 157 | + '', |
|
| 158 | + $server_db |
|
| 159 | + ); |
|
| 160 | + spip_log('nouvelle version installee: ' . $GLOBALS['spip_version_base']); |
|
| 161 | + } |
|
| 162 | + // eliminer la derniere operation d'admin mal terminee |
|
| 163 | + // notamment la mise a jour |
|
| 164 | + @$fquery("DELETE FROM spip_meta WHERE nom='import_all' OR nom='admin'", $server_db); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // recuperer le charset de la connexion dans les meta |
|
| 168 | + $charset = ''; |
|
| 169 | + $r = $fquery("SELECT valeur FROM spip_meta WHERE nom='charset_sql_connexion'", $server_db); |
|
| 170 | + if ($r) { |
|
| 171 | + $r = sql_fetch($r, $server_db); |
|
| 172 | + } |
|
| 173 | + if ($r) { |
|
| 174 | + $charset = $r['valeur']; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $ligne_rappel = install_mode_appel($server_db); |
|
| 178 | + |
|
| 179 | + $result_ok = @$fquery('SELECT COUNT(*) FROM spip_meta', $server_db); |
|
| 180 | + if (!$result_ok) { |
|
| 181 | + return "<!--\nvielle = $old rappel= $ligne_rappel\n-->"; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($chmod_db) { |
|
| 185 | + install_fichier_connexion( |
|
| 186 | + _FILE_CHMOD_TMP, |
|
| 187 | + "if (!defined('_SPIP_CHMOD')) define('_SPIP_CHMOD', " . sprintf('0%3o', $chmod_db) . ");\n" |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // si ce fichier existe a cette etape c'est qu'il provient |
|
| 192 | + // d'une installation qui ne l'a pas cree correctement. |
|
| 193 | + // Le supprimer pour que _FILE_CONNECT_TMP prime. |
|
| 194 | + |
|
| 195 | + if (_FILE_CONNECT and file_exists(_FILE_CONNECT)) { |
|
| 196 | + spip_unlink(_FILE_CONNECT); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + install_fichier_connexion( |
|
| 200 | + _FILE_CONNECT_TMP, |
|
| 201 | + $ligne_rappel |
|
| 202 | + . install_connexion( |
|
| 203 | + $adresse_db, |
|
| 204 | + $port, |
|
| 205 | + $login_db, |
|
| 206 | + $pass_db, |
|
| 207 | + $sel_db, |
|
| 208 | + $server_db, |
|
| 209 | + $table_prefix, |
|
| 210 | + '', |
|
| 211 | + $charset |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + return ''; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,169 +227,169 @@ discard block |
||
| 227 | 227 | * @return string Le préfixe corrigé |
| 228 | 228 | */ |
| 229 | 229 | function preparer_prefixe_tables($prefixe) { |
| 230 | - return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 230 | + return trim(preg_replace(',^[0-9]+,', '', preg_replace(',[^a-z0-9],', '', strtolower($prefixe)))); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // http://code.spip.net/@install_propose_ldap |
| 234 | 234 | function install_propose_ldap() { |
| 235 | - return generer_form_ecrire('install', ( |
|
| 236 | - fieldset( |
|
| 237 | - _T('info_authentification_externe'), |
|
| 238 | - array( |
|
| 239 | - 'etape' => array( |
|
| 240 | - 'label' => _T('texte_annuaire_ldap_1'), |
|
| 241 | - 'valeur' => 'ldap1', |
|
| 242 | - 'hidden' => true |
|
| 243 | - ) |
|
| 244 | - ), |
|
| 245 | - bouton_suivant(_T('bouton_acces_ldap')) |
|
| 246 | - ))); |
|
| 235 | + return generer_form_ecrire('install', ( |
|
| 236 | + fieldset( |
|
| 237 | + _T('info_authentification_externe'), |
|
| 238 | + array( |
|
| 239 | + 'etape' => array( |
|
| 240 | + 'label' => _T('texte_annuaire_ldap_1'), |
|
| 241 | + 'valeur' => 'ldap1', |
|
| 242 | + 'hidden' => true |
|
| 243 | + ) |
|
| 244 | + ), |
|
| 245 | + bouton_suivant(_T('bouton_acces_ldap')) |
|
| 246 | + ))); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
| 250 | 250 | // http://code.spip.net/@install_premier_auteur |
| 251 | 251 | function install_premier_auteur($email, $login, $nom, $pass, $hidden, $auteur_obligatoire) { |
| 252 | - return info_progression_etape(3, 'etape_', 'install/') . |
|
| 253 | - info_etape( |
|
| 254 | - _T('info_informations_personnelles'), |
|
| 255 | - '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 256 | - aider('install5', true) . |
|
| 257 | - '<p>' . |
|
| 258 | - ($auteur_obligatoire ? |
|
| 259 | - '' |
|
| 260 | - : |
|
| 261 | - _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 262 | - ) |
|
| 263 | - ) |
|
| 264 | - . generer_form_ecrire('install', ( |
|
| 265 | - "\n<input type='hidden' name='etape' value='3b' />" |
|
| 266 | - . $hidden |
|
| 267 | - . fieldset( |
|
| 268 | - _T('info_identification_publique'), |
|
| 269 | - array( |
|
| 270 | - 'nom' => array( |
|
| 271 | - 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 272 | - 'valeur' => $nom, |
|
| 273 | - 'required' => $auteur_obligatoire, |
|
| 274 | - ), |
|
| 275 | - 'email' => array( |
|
| 276 | - 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 277 | - 'valeur' => $email, |
|
| 278 | - ) |
|
| 279 | - ) |
|
| 280 | - ) |
|
| 281 | - |
|
| 282 | - . fieldset( |
|
| 283 | - _T('entree_identifiants_connexion'), |
|
| 284 | - array( |
|
| 285 | - 'login' => array( |
|
| 286 | - 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 287 | - 'info_login_trop_court_car_pluriel', |
|
| 288 | - array('nb' => _LOGIN_TROP_COURT) |
|
| 289 | - ) . "\n", |
|
| 290 | - 'valeur' => $login, |
|
| 291 | - 'required' => $auteur_obligatoire, |
|
| 292 | - ), |
|
| 293 | - 'pass' => array( |
|
| 294 | - 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 295 | - 'info_passe_trop_court_car_pluriel', |
|
| 296 | - array('nb' => _PASS_LONGUEUR_MINI) |
|
| 297 | - ) . "\n", |
|
| 298 | - 'valeur' => $pass, |
|
| 299 | - 'required' => $auteur_obligatoire, |
|
| 300 | - ), |
|
| 301 | - 'pass_verif' => array( |
|
| 302 | - 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 303 | - 'valeur' => $pass, |
|
| 304 | - 'required' => $auteur_obligatoire, |
|
| 305 | - ) |
|
| 306 | - ) |
|
| 307 | - ) |
|
| 308 | - . bouton_suivant())); |
|
| 252 | + return info_progression_etape(3, 'etape_', 'install/') . |
|
| 253 | + info_etape( |
|
| 254 | + _T('info_informations_personnelles'), |
|
| 255 | + '<b>' . _T('texte_informations_personnelles_1') . '</b>' . |
|
| 256 | + aider('install5', true) . |
|
| 257 | + '<p>' . |
|
| 258 | + ($auteur_obligatoire ? |
|
| 259 | + '' |
|
| 260 | + : |
|
| 261 | + _T('texte_informations_personnelles_2') . ' ' . _T('info_laisser_champs_vides') |
|
| 262 | + ) |
|
| 263 | + ) |
|
| 264 | + . generer_form_ecrire('install', ( |
|
| 265 | + "\n<input type='hidden' name='etape' value='3b' />" |
|
| 266 | + . $hidden |
|
| 267 | + . fieldset( |
|
| 268 | + _T('info_identification_publique'), |
|
| 269 | + array( |
|
| 270 | + 'nom' => array( |
|
| 271 | + 'label' => '<b>' . _T('entree_signature') . "</b><br />\n" . _T('entree_nom_pseudo_1') . "\n", |
|
| 272 | + 'valeur' => $nom, |
|
| 273 | + 'required' => $auteur_obligatoire, |
|
| 274 | + ), |
|
| 275 | + 'email' => array( |
|
| 276 | + 'label' => '<b>' . _T('entree_adresse_email') . "</b>\n", |
|
| 277 | + 'valeur' => $email, |
|
| 278 | + ) |
|
| 279 | + ) |
|
| 280 | + ) |
|
| 281 | + |
|
| 282 | + . fieldset( |
|
| 283 | + _T('entree_identifiants_connexion'), |
|
| 284 | + array( |
|
| 285 | + 'login' => array( |
|
| 286 | + 'label' => '<b>' . _T('entree_login') . "</b><br />\n" . _T( |
|
| 287 | + 'info_login_trop_court_car_pluriel', |
|
| 288 | + array('nb' => _LOGIN_TROP_COURT) |
|
| 289 | + ) . "\n", |
|
| 290 | + 'valeur' => $login, |
|
| 291 | + 'required' => $auteur_obligatoire, |
|
| 292 | + ), |
|
| 293 | + 'pass' => array( |
|
| 294 | + 'label' => '<b>' . _T('entree_mot_passe') . "</b><br />\n" . _T( |
|
| 295 | + 'info_passe_trop_court_car_pluriel', |
|
| 296 | + array('nb' => _PASS_LONGUEUR_MINI) |
|
| 297 | + ) . "\n", |
|
| 298 | + 'valeur' => $pass, |
|
| 299 | + 'required' => $auteur_obligatoire, |
|
| 300 | + ), |
|
| 301 | + 'pass_verif' => array( |
|
| 302 | + 'label' => '<b>' . _T('info_confirmer_passe') . "</b><br />\n", |
|
| 303 | + 'valeur' => $pass, |
|
| 304 | + 'required' => $auteur_obligatoire, |
|
| 305 | + ) |
|
| 306 | + ) |
|
| 307 | + ) |
|
| 308 | + . bouton_suivant())); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // http://code.spip.net/@install_etape_3_dist |
| 312 | 312 | function install_etape_3_dist() { |
| 313 | - $ldap_present = _request('ldap_present'); |
|
| 314 | - |
|
| 315 | - if (!$ldap_present) { |
|
| 316 | - $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 317 | - ? _INSTALL_HOST_DB |
|
| 318 | - : _request('adresse_db'); |
|
| 319 | - |
|
| 320 | - $login_db = defined('_INSTALL_USER_DB') |
|
| 321 | - ? _INSTALL_USER_DB |
|
| 322 | - : _request('login_db'); |
|
| 323 | - |
|
| 324 | - $pass_db = defined('_INSTALL_PASS_DB') |
|
| 325 | - ? _INSTALL_PASS_DB |
|
| 326 | - : _request('pass_db'); |
|
| 327 | - |
|
| 328 | - $server_db = defined('_INSTALL_SERVER_DB') |
|
| 329 | - ? _INSTALL_SERVER_DB |
|
| 330 | - : _request('server_db'); |
|
| 331 | - |
|
| 332 | - $chmod_db = defined('_SPIP_CHMOD') |
|
| 333 | - ? _SPIP_CHMOD |
|
| 334 | - : _request('chmod'); |
|
| 335 | - |
|
| 336 | - $choix_db = defined('_INSTALL_NAME_DB') |
|
| 337 | - ? _INSTALL_NAME_DB |
|
| 338 | - : _request('choix_db'); |
|
| 339 | - |
|
| 340 | - $sel_db = ($choix_db == 'new_spip') |
|
| 341 | - ? _request('table_new') : $choix_db; |
|
| 342 | - |
|
| 343 | - $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 344 | - |
|
| 345 | - if ($res) { |
|
| 346 | - $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 347 | - . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 348 | - . $res |
|
| 349 | - . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 350 | - . '</div>'; |
|
| 351 | - } |
|
| 352 | - } else { |
|
| 353 | - $res = ''; |
|
| 354 | - list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 355 | - $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - if (!$res) { |
|
| 359 | - if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 360 | - include(_FILE_CONNECT_TMP); |
|
| 361 | - } else { |
|
| 362 | - redirige_url_ecrire('install'); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 366 | - include(_FILE_CHMOD_TMP); |
|
| 367 | - } else { |
|
| 368 | - redirige_url_ecrire('install'); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 372 | - . (defined('_INSTALL_NAME_DB') ? '' |
|
| 373 | - : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 374 | - |
|
| 375 | - $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 376 | - |
|
| 377 | - $res = "<div class='success'><b>" |
|
| 378 | - . _T('info_base_installee') |
|
| 379 | - . '</b></div>' |
|
| 380 | - . install_premier_auteur( |
|
| 381 | - _request('email'), |
|
| 382 | - _request('login'), |
|
| 383 | - _request('nom'), |
|
| 384 | - _request('pass'), |
|
| 385 | - $hidden, |
|
| 386 | - $auteur_obligatoire |
|
| 387 | - ) |
|
| 388 | - . (($ldap_present or !function_exists('ldap_connect')) |
|
| 389 | - ? '' : install_propose_ldap()); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - echo install_debut_html(); |
|
| 393 | - echo $res; |
|
| 394 | - echo install_fin_html(); |
|
| 313 | + $ldap_present = _request('ldap_present'); |
|
| 314 | + |
|
| 315 | + if (!$ldap_present) { |
|
| 316 | + $adresse_db = defined('_INSTALL_HOST_DB') |
|
| 317 | + ? _INSTALL_HOST_DB |
|
| 318 | + : _request('adresse_db'); |
|
| 319 | + |
|
| 320 | + $login_db = defined('_INSTALL_USER_DB') |
|
| 321 | + ? _INSTALL_USER_DB |
|
| 322 | + : _request('login_db'); |
|
| 323 | + |
|
| 324 | + $pass_db = defined('_INSTALL_PASS_DB') |
|
| 325 | + ? _INSTALL_PASS_DB |
|
| 326 | + : _request('pass_db'); |
|
| 327 | + |
|
| 328 | + $server_db = defined('_INSTALL_SERVER_DB') |
|
| 329 | + ? _INSTALL_SERVER_DB |
|
| 330 | + : _request('server_db'); |
|
| 331 | + |
|
| 332 | + $chmod_db = defined('_SPIP_CHMOD') |
|
| 333 | + ? _SPIP_CHMOD |
|
| 334 | + : _request('chmod'); |
|
| 335 | + |
|
| 336 | + $choix_db = defined('_INSTALL_NAME_DB') |
|
| 337 | + ? _INSTALL_NAME_DB |
|
| 338 | + : _request('choix_db'); |
|
| 339 | + |
|
| 340 | + $sel_db = ($choix_db == 'new_spip') |
|
| 341 | + ? _request('table_new') : $choix_db; |
|
| 342 | + |
|
| 343 | + $res = install_bases($adresse_db, $login_db, $pass_db, $server_db, $choix_db, $sel_db, $chmod_db); |
|
| 344 | + |
|
| 345 | + if ($res) { |
|
| 346 | + $res = info_progression_etape(2, 'etape_', 'install/', true) |
|
| 347 | + . "<div class='error'><h3>" . _T('avis_operation_echec') . '</h3>' |
|
| 348 | + . $res |
|
| 349 | + . '<p>' . _T('texte_operation_echec') . '</p>' |
|
| 350 | + . '</div>'; |
|
| 351 | + } |
|
| 352 | + } else { |
|
| 353 | + $res = ''; |
|
| 354 | + list($adresse_db, $login_db, $pass_db, $sel_db, $server_db) = analyse_fichier_connection(_FILE_CONNECT_TMP); |
|
| 355 | + $GLOBALS['connexions'][$server_db] = spip_connect_db($adresse_db, $sel_db, $login_db, $pass_db, $sel_db, $server_db); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + if (!$res) { |
|
| 359 | + if (file_exists(_FILE_CONNECT_TMP)) { |
|
| 360 | + include(_FILE_CONNECT_TMP); |
|
| 361 | + } else { |
|
| 362 | + redirige_url_ecrire('install'); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + if (file_exists(_FILE_CHMOD_TMP)) { |
|
| 366 | + include(_FILE_CHMOD_TMP); |
|
| 367 | + } else { |
|
| 368 | + redirige_url_ecrire('install'); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $hidden = predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) |
|
| 372 | + . (defined('_INSTALL_NAME_DB') ? '' |
|
| 373 | + : "\n<input type='hidden' name='sel_db' value='$sel_db' />"); |
|
| 374 | + |
|
| 375 | + $auteur_obligatoire = ($ldap_present ? 0 : !sql_countsel('spip_auteurs', '', '', '', $server_db)); |
|
| 376 | + |
|
| 377 | + $res = "<div class='success'><b>" |
|
| 378 | + . _T('info_base_installee') |
|
| 379 | + . '</b></div>' |
|
| 380 | + . install_premier_auteur( |
|
| 381 | + _request('email'), |
|
| 382 | + _request('login'), |
|
| 383 | + _request('nom'), |
|
| 384 | + _request('pass'), |
|
| 385 | + $hidden, |
|
| 386 | + $auteur_obligatoire |
|
| 387 | + ) |
|
| 388 | + . (($ldap_present or !function_exists('ldap_connect')) |
|
| 389 | + ? '' : install_propose_ldap()); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + echo install_debut_html(); |
|
| 393 | + echo $res; |
|
| 394 | + echo install_fin_html(); |
|
| 395 | 395 | } |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | /** |
| 134 | 134 | * Déclarer les critères exceptions |
| 135 | 135 | * |
| 136 | - * @return array |
|
| 136 | + * @return string[] |
|
| 137 | 137 | */ |
| 138 | 138 | public function exception_des_criteres() { |
| 139 | 139 | return array('tableau'); |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | * pour la syntaxe cf la fonction spip preg_files |
| 788 | 788 | * |
| 789 | 789 | * @param string $dir |
| 790 | - * @param string $regexp |
|
| 790 | + * @param integer $regexp |
|
| 791 | 791 | * @param int $limit |
| 792 | 792 | * @return array|bool |
| 793 | 793 | */ |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | /** |
| 827 | 827 | * Object -> tableau |
| 828 | 828 | * |
| 829 | - * @param Object $object |
|
| 829 | + * @param SimpleXMLIterator $object |
|
| 830 | 830 | * @return array|bool |
| 831 | 831 | */ |
| 832 | 832 | function XMLObjectToArray($object) { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // Si a ce stade on n'a pas de table, il y a un bug |
| 232 | 232 | if (!is_array($this->tableau)) { |
| 233 | 233 | $this->err = true; |
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 234 | + spip_log("erreur datasource ".var_export($command, true)); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | // {datapath query.results} |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | if (isset($this->command['sourcemode']) |
| 272 | 272 | and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
| 273 | 273 | ) { |
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 274 | + charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | # le premier argument peut etre un array, une URL etc. |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | # avons-nous un cache dispo ? |
| 281 | 281 | $cle = null; |
| 282 | 282 | if (is_string($src)) { |
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 283 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'], true)); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | $cache = $this->cache_get($cle); |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | } |
| 348 | 348 | } |
| 349 | 349 | if (!$this->err |
| 350 | - and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 350 | + and $g = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 351 | 351 | ) { |
| 352 | 352 | $args = $this->command['source']; |
| 353 | 353 | $args[0] = $u; |
@@ -482,13 +482,13 @@ discard block |
||
| 482 | 482 | $tv = '%s'; |
| 483 | 483 | } # {par valeur/xx/yy} ?? |
| 484 | 484 | else { |
| 485 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 485 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 486 | 486 | } |
| 487 | 487 | $sortfunc .= ' |
| 488 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 489 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 488 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 489 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 490 | 490 | if ($a <> $b) |
| 491 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 491 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | */ |
| 642 | 642 | function inc_yql_to_array_dist($u) { |
| 643 | 643 | define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
| 644 | - $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 644 | + $v = recuperer_url($url = _YQL_ENDPOINT.urlencode($u).'&format=json'); |
|
| 645 | 645 | if (!$v['page'] |
| 646 | 646 | or !$w = json_decode($v['page'], true) |
| 647 | 647 | ) { |
@@ -663,7 +663,7 @@ discard block |
||
| 663 | 663 | function inc_sql_to_array_dist($u) { |
| 664 | 664 | # sortir le connecteur de $u |
| 665 | 665 | preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
| 666 | - $serveur = (string)$v[1]; |
|
| 666 | + $serveur = (string) $v[1]; |
|
| 667 | 667 | $req = trim($v[2]); |
| 668 | 668 | if ($s = sql_query($req, $serveur)) { |
| 669 | 669 | $r = array(); |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | if (is_array($json = json_decode($u)) |
| 688 | 688 | or is_object($json) |
| 689 | 689 | ) { |
| 690 | - return (array)$json; |
|
| 690 | + return (array) $json; |
|
| 691 | 691 | } |
| 692 | 692 | } |
| 693 | 693 | |
@@ -706,13 +706,13 @@ discard block |
||
| 706 | 706 | $i = 1; |
| 707 | 707 | foreach ($entete as $k => $v) { |
| 708 | 708 | if (trim($v) == "") { |
| 709 | - $v = "col" . $i; |
|
| 709 | + $v = "col".$i; |
|
| 710 | 710 | } // reperer des eventuelles cases vides |
| 711 | 711 | if (is_numeric($v) and $v < 0) { |
| 712 | - $v = "__" . $v; |
|
| 712 | + $v = "__".$v; |
|
| 713 | 713 | } // ne pas risquer d'ecraser une cle numerique |
| 714 | 714 | if (is_numeric($v)) { |
| 715 | - $v = "_" . $v; |
|
| 715 | + $v = "_".$v; |
|
| 716 | 716 | } // ne pas risquer d'ecraser une cle numerique |
| 717 | 717 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 718 | 718 | foreach ($csv as &$item) { |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @return array|bool |
| 797 | 797 | */ |
| 798 | 798 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 799 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 799 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -811,13 +811,13 @@ discard block |
||
| 811 | 811 | $glob = charger_fonction('glob_to_array', 'inc'); |
| 812 | 812 | $a = $glob($u); |
| 813 | 813 | foreach ($a as &$v) { |
| 814 | - $b = (array)@stat($v); |
|
| 814 | + $b = (array) @stat($v); |
|
| 815 | 815 | foreach ($b as $k => $ignore) { |
| 816 | 816 | if (is_numeric($k)) { |
| 817 | 817 | unset($b[$k]); |
| 818 | 818 | } |
| 819 | 819 | } |
| 820 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 820 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 821 | 821 | $v = array_merge( |
| 822 | 822 | pathinfo($v), |
| 823 | 823 | $b |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | $xml_array = array(); |
| 838 | 838 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 839 | 839 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 840 | - $key .= '-' . uniqid(); |
|
| 840 | + $key .= '-'.uniqid(); |
|
| 841 | 841 | } |
| 842 | 842 | $vars = get_object_vars($object->current()); |
| 843 | 843 | if (isset($vars['@attributes'])) { |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = array( |
|
| 47 | - 'field' => array( |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = array( |
|
| 47 | + 'field' => array( |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,520 +62,520 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = array(); |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = array(); |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = array()) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind() { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = key($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return array('tableau'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set($cle, |
|
| 183 | - array( |
|
| 184 | - 'data' => $valeur, |
|
| 185 | - 'time' => time(), |
|
| 186 | - 'ttl' => $ttl |
|
| 187 | - ), |
|
| 188 | - 3600 + $ttl); |
|
| 189 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Aller chercher les données de la boucle DATA |
|
| 195 | - * |
|
| 196 | - * @throws Exception |
|
| 197 | - * @param array $command |
|
| 198 | - * @return void |
|
| 199 | - */ |
|
| 200 | - protected function select($command) { |
|
| 201 | - |
|
| 202 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | - // le type se retrouve dans la commande 'from' |
|
| 204 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | - if (isset($this->command['from'][0])) { |
|
| 206 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | - } |
|
| 209 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | - // les commandes connues pour l'iterateur DATA |
|
| 214 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | - |
|
| 216 | - // {source format, [URL], [arg2]...} |
|
| 217 | - if (isset($this->command['source']) |
|
| 218 | - and isset($this->command['sourcemode']) |
|
| 219 | - ) { |
|
| 220 | - $this->select_source(); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - // Critere {liste X1, X2, X3} |
|
| 224 | - if (isset($this->command['liste'])) { |
|
| 225 | - $this->select_liste(); |
|
| 226 | - } |
|
| 227 | - if (isset($this->command['enum'])) { |
|
| 228 | - $this->select_enum(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | - if (!is_array($this->tableau)) { |
|
| 233 | - $this->err = true; |
|
| 234 | - spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // {datapath query.results} |
|
| 238 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | - if (!$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if (isset($this->command['sourcemode']) |
|
| 272 | - and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | - ) { |
|
| 274 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - # le premier argument peut etre un array, une URL etc. |
|
| 278 | - $src = $this->command['source'][0]; |
|
| 279 | - |
|
| 280 | - # avons-nous un cache dispo ? |
|
| 281 | - $cle = null; |
|
| 282 | - if (is_string($src)) { |
|
| 283 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $cache = $this->cache_get($cle); |
|
| 287 | - if (isset($this->command['datacache'])) { |
|
| 288 | - $ttl = intval($this->command['datacache']); |
|
| 289 | - } |
|
| 290 | - if ($cache |
|
| 291 | - and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | - > time()) |
|
| 293 | - and !(_request('var_mode') === 'recalcul' |
|
| 294 | - and include_spip('inc/autoriser') |
|
| 295 | - and autoriser('recalcul') |
|
| 296 | - ) |
|
| 297 | - ) { |
|
| 298 | - $this->tableau = $cache['data']; |
|
| 299 | - } else { |
|
| 300 | - try { |
|
| 301 | - # dommage que ca ne soit pas une option de yql_to_array... |
|
| 302 | - if ($this->command['sourcemode'] == 'yql') { |
|
| 303 | - if (!isset($ttl)) { |
|
| 304 | - $ttl = 3600; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - if (isset($this->command['sourcemode']) |
|
| 309 | - and in_array($this->command['sourcemode'], |
|
| 310 | - array('table', 'array', 'tableau')) |
|
| 311 | - ) { |
|
| 312 | - if (is_array($a = $src) |
|
| 313 | - or (is_string($a) |
|
| 314 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 315 | - and is_array($a = @unserialize($a))) |
|
| 316 | - ) { |
|
| 317 | - $this->tableau = $a; |
|
| 318 | - } |
|
| 319 | - } else { |
|
| 320 | - if (tester_url_absolue($src)) { |
|
| 321 | - include_spip('inc/distant'); |
|
| 322 | - $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 323 | - if (!$u) { |
|
| 324 | - throw new Exception("404"); |
|
| 325 | - } |
|
| 326 | - if (!isset($ttl)) { |
|
| 327 | - $ttl = 24 * 3600; |
|
| 328 | - } |
|
| 329 | - } else { |
|
| 330 | - if (@is_dir($src)) { |
|
| 331 | - $u = $src; |
|
| 332 | - if (!isset($ttl)) { |
|
| 333 | - $ttl = 10; |
|
| 334 | - } |
|
| 335 | - } else { |
|
| 336 | - if (@is_readable($src) && @is_file($src)) { |
|
| 337 | - $u = spip_file_get_contents($src); |
|
| 338 | - if (!isset($ttl)) { |
|
| 339 | - $ttl = 10; |
|
| 340 | - } |
|
| 341 | - } else { |
|
| 342 | - $u = $src; |
|
| 343 | - if (!isset($ttl)) { |
|
| 344 | - $ttl = 10; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - if (!$this->err |
|
| 350 | - and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 351 | - ) { |
|
| 352 | - $args = $this->command['source']; |
|
| 353 | - $args[0] = $u; |
|
| 354 | - if (is_array($a = call_user_func_array($g, $args))) { |
|
| 355 | - $this->tableau = $a; |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - if (!is_array($this->tableau)) { |
|
| 361 | - $this->err = true; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 365 | - $this->cache_set($cle, $ttl); |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - } catch (Exception $e) { |
|
| 369 | - $e = $e->getMessage(); |
|
| 370 | - $err = sprintf("[%s, %s] $e", |
|
| 371 | - $src, |
|
| 372 | - $this->command['sourcemode']); |
|
| 373 | - erreur_squelette(array($err, array())); |
|
| 374 | - $this->err = true; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 379 | - if ($this->err |
|
| 380 | - and $cache |
|
| 381 | - ) { |
|
| 382 | - $this->tableau = $cache['data']; |
|
| 383 | - $this->err = false; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Retourne un tableau donne depuis un critère liste |
|
| 390 | - * |
|
| 391 | - * Critère `{liste X1, X2, X3}` |
|
| 392 | - * |
|
| 393 | - * @see critere_DATA_liste_dist() |
|
| 394 | - * |
|
| 395 | - **/ |
|
| 396 | - protected function select_liste() { |
|
| 397 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 398 | - if (!isset($this->command['liste'][1])) { |
|
| 399 | - if (!is_array($this->command['liste'][0])) { |
|
| 400 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 401 | - } else { |
|
| 402 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - $this->tableau = $this->command['liste']; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Retourne un tableau donne depuis un critere liste |
|
| 410 | - * Critere {enum Xmin, Xmax} |
|
| 411 | - * |
|
| 412 | - **/ |
|
| 413 | - protected function select_enum() { |
|
| 414 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 415 | - if (!isset($this->command['enum'][1])) { |
|
| 416 | - if (!is_array($this->command['enum'][0])) { |
|
| 417 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 418 | - } else { |
|
| 419 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - if (count($this->command['enum']) >= 3) { |
|
| 423 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 424 | - array_shift($this->command['enum'])); |
|
| 425 | - } else { |
|
| 426 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 427 | - } |
|
| 428 | - $this->tableau = $enum; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - /** |
|
| 433 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 434 | - * {datapath query.results} |
|
| 435 | - * |
|
| 436 | - **/ |
|
| 437 | - protected function select_datapath() { |
|
| 438 | - $base = reset($this->command['datapath']); |
|
| 439 | - if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 440 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 441 | - if (!is_array($this->tableau)) { |
|
| 442 | - $this->tableau = array(); |
|
| 443 | - $this->err = true; |
|
| 444 | - spip_log("datapath '$base' absent"); |
|
| 445 | - } |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Ordonner les resultats |
|
| 451 | - * {par x} |
|
| 452 | - * |
|
| 453 | - **/ |
|
| 454 | - protected function select_orderby() { |
|
| 455 | - $sortfunc = ''; |
|
| 456 | - $aleas = 0; |
|
| 457 | - foreach ($this->command['orderby'] as $tri) { |
|
| 458 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 459 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 460 | - $r = array_pad($r, 3, null); |
|
| 461 | - |
|
| 462 | - // tri par cle |
|
| 463 | - if ($r[1] == 'cle') { |
|
| 464 | - if (isset($r[2]) and $r[2]) { |
|
| 465 | - krsort($this->tableau); |
|
| 466 | - } else { |
|
| 467 | - ksort($this->tableau); |
|
| 468 | - } |
|
| 469 | - } # {par hasard} |
|
| 470 | - else { |
|
| 471 | - if ($r[1] == 'hasard') { |
|
| 472 | - $k = array_keys($this->tableau); |
|
| 473 | - shuffle($k); |
|
| 474 | - $v = array(); |
|
| 475 | - foreach ($k as $cle) { |
|
| 476 | - $v[$cle] = $this->tableau[$cle]; |
|
| 477 | - } |
|
| 478 | - $this->tableau = $v; |
|
| 479 | - } else { |
|
| 480 | - # {par valeur} |
|
| 481 | - if ($r[1] == 'valeur') { |
|
| 482 | - $tv = '%s'; |
|
| 483 | - } # {par valeur/xx/yy} ?? |
|
| 484 | - else { |
|
| 485 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 486 | - } |
|
| 487 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = array(); |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = array(); |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = array()) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind() { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = key($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return array('tableau'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set($cle, |
|
| 183 | + array( |
|
| 184 | + 'data' => $valeur, |
|
| 185 | + 'time' => time(), |
|
| 186 | + 'ttl' => $ttl |
|
| 187 | + ), |
|
| 188 | + 3600 + $ttl); |
|
| 189 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 190 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Aller chercher les données de la boucle DATA |
|
| 195 | + * |
|
| 196 | + * @throws Exception |
|
| 197 | + * @param array $command |
|
| 198 | + * @return void |
|
| 199 | + */ |
|
| 200 | + protected function select($command) { |
|
| 201 | + |
|
| 202 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 203 | + // le type se retrouve dans la commande 'from' |
|
| 204 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 205 | + if (isset($this->command['from'][0])) { |
|
| 206 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 207 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 208 | + } |
|
| 209 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 213 | + // les commandes connues pour l'iterateur DATA |
|
| 214 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 215 | + |
|
| 216 | + // {source format, [URL], [arg2]...} |
|
| 217 | + if (isset($this->command['source']) |
|
| 218 | + and isset($this->command['sourcemode']) |
|
| 219 | + ) { |
|
| 220 | + $this->select_source(); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + // Critere {liste X1, X2, X3} |
|
| 224 | + if (isset($this->command['liste'])) { |
|
| 225 | + $this->select_liste(); |
|
| 226 | + } |
|
| 227 | + if (isset($this->command['enum'])) { |
|
| 228 | + $this->select_enum(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 232 | + if (!is_array($this->tableau)) { |
|
| 233 | + $this->err = true; |
|
| 234 | + spip_log("erreur datasource " . var_export($command, true)); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // {datapath query.results} |
|
| 238 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 239 | + if (!$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if (isset($this->command['sourcemode']) |
|
| 272 | + and !in_array($this->command['sourcemode'], array('table', 'array', 'tableau')) |
|
| 273 | + ) { |
|
| 274 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + # le premier argument peut etre un array, une URL etc. |
|
| 278 | + $src = $this->command['source'][0]; |
|
| 279 | + |
|
| 280 | + # avons-nous un cache dispo ? |
|
| 281 | + $cle = null; |
|
| 282 | + if (is_string($src)) { |
|
| 283 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $cache = $this->cache_get($cle); |
|
| 287 | + if (isset($this->command['datacache'])) { |
|
| 288 | + $ttl = intval($this->command['datacache']); |
|
| 289 | + } |
|
| 290 | + if ($cache |
|
| 291 | + and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 292 | + > time()) |
|
| 293 | + and !(_request('var_mode') === 'recalcul' |
|
| 294 | + and include_spip('inc/autoriser') |
|
| 295 | + and autoriser('recalcul') |
|
| 296 | + ) |
|
| 297 | + ) { |
|
| 298 | + $this->tableau = $cache['data']; |
|
| 299 | + } else { |
|
| 300 | + try { |
|
| 301 | + # dommage que ca ne soit pas une option de yql_to_array... |
|
| 302 | + if ($this->command['sourcemode'] == 'yql') { |
|
| 303 | + if (!isset($ttl)) { |
|
| 304 | + $ttl = 3600; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + if (isset($this->command['sourcemode']) |
|
| 309 | + and in_array($this->command['sourcemode'], |
|
| 310 | + array('table', 'array', 'tableau')) |
|
| 311 | + ) { |
|
| 312 | + if (is_array($a = $src) |
|
| 313 | + or (is_string($a) |
|
| 314 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 315 | + and is_array($a = @unserialize($a))) |
|
| 316 | + ) { |
|
| 317 | + $this->tableau = $a; |
|
| 318 | + } |
|
| 319 | + } else { |
|
| 320 | + if (tester_url_absolue($src)) { |
|
| 321 | + include_spip('inc/distant'); |
|
| 322 | + $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 323 | + if (!$u) { |
|
| 324 | + throw new Exception("404"); |
|
| 325 | + } |
|
| 326 | + if (!isset($ttl)) { |
|
| 327 | + $ttl = 24 * 3600; |
|
| 328 | + } |
|
| 329 | + } else { |
|
| 330 | + if (@is_dir($src)) { |
|
| 331 | + $u = $src; |
|
| 332 | + if (!isset($ttl)) { |
|
| 333 | + $ttl = 10; |
|
| 334 | + } |
|
| 335 | + } else { |
|
| 336 | + if (@is_readable($src) && @is_file($src)) { |
|
| 337 | + $u = spip_file_get_contents($src); |
|
| 338 | + if (!isset($ttl)) { |
|
| 339 | + $ttl = 10; |
|
| 340 | + } |
|
| 341 | + } else { |
|
| 342 | + $u = $src; |
|
| 343 | + if (!isset($ttl)) { |
|
| 344 | + $ttl = 10; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + if (!$this->err |
|
| 350 | + and $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 351 | + ) { |
|
| 352 | + $args = $this->command['source']; |
|
| 353 | + $args[0] = $u; |
|
| 354 | + if (is_array($a = call_user_func_array($g, $args))) { |
|
| 355 | + $this->tableau = $a; |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + if (!is_array($this->tableau)) { |
|
| 361 | + $this->err = true; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 365 | + $this->cache_set($cle, $ttl); |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + } catch (Exception $e) { |
|
| 369 | + $e = $e->getMessage(); |
|
| 370 | + $err = sprintf("[%s, %s] $e", |
|
| 371 | + $src, |
|
| 372 | + $this->command['sourcemode']); |
|
| 373 | + erreur_squelette(array($err, array())); |
|
| 374 | + $this->err = true; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 379 | + if ($this->err |
|
| 380 | + and $cache |
|
| 381 | + ) { |
|
| 382 | + $this->tableau = $cache['data']; |
|
| 383 | + $this->err = false; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Retourne un tableau donne depuis un critère liste |
|
| 390 | + * |
|
| 391 | + * Critère `{liste X1, X2, X3}` |
|
| 392 | + * |
|
| 393 | + * @see critere_DATA_liste_dist() |
|
| 394 | + * |
|
| 395 | + **/ |
|
| 396 | + protected function select_liste() { |
|
| 397 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 398 | + if (!isset($this->command['liste'][1])) { |
|
| 399 | + if (!is_array($this->command['liste'][0])) { |
|
| 400 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 401 | + } else { |
|
| 402 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + $this->tableau = $this->command['liste']; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Retourne un tableau donne depuis un critere liste |
|
| 410 | + * Critere {enum Xmin, Xmax} |
|
| 411 | + * |
|
| 412 | + **/ |
|
| 413 | + protected function select_enum() { |
|
| 414 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 415 | + if (!isset($this->command['enum'][1])) { |
|
| 416 | + if (!is_array($this->command['enum'][0])) { |
|
| 417 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 418 | + } else { |
|
| 419 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + if (count($this->command['enum']) >= 3) { |
|
| 423 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 424 | + array_shift($this->command['enum'])); |
|
| 425 | + } else { |
|
| 426 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 427 | + } |
|
| 428 | + $this->tableau = $enum; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + /** |
|
| 433 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 434 | + * {datapath query.results} |
|
| 435 | + * |
|
| 436 | + **/ |
|
| 437 | + protected function select_datapath() { |
|
| 438 | + $base = reset($this->command['datapath']); |
|
| 439 | + if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 440 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 441 | + if (!is_array($this->tableau)) { |
|
| 442 | + $this->tableau = array(); |
|
| 443 | + $this->err = true; |
|
| 444 | + spip_log("datapath '$base' absent"); |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Ordonner les resultats |
|
| 451 | + * {par x} |
|
| 452 | + * |
|
| 453 | + **/ |
|
| 454 | + protected function select_orderby() { |
|
| 455 | + $sortfunc = ''; |
|
| 456 | + $aleas = 0; |
|
| 457 | + foreach ($this->command['orderby'] as $tri) { |
|
| 458 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 459 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 460 | + $r = array_pad($r, 3, null); |
|
| 461 | + |
|
| 462 | + // tri par cle |
|
| 463 | + if ($r[1] == 'cle') { |
|
| 464 | + if (isset($r[2]) and $r[2]) { |
|
| 465 | + krsort($this->tableau); |
|
| 466 | + } else { |
|
| 467 | + ksort($this->tableau); |
|
| 468 | + } |
|
| 469 | + } # {par hasard} |
|
| 470 | + else { |
|
| 471 | + if ($r[1] == 'hasard') { |
|
| 472 | + $k = array_keys($this->tableau); |
|
| 473 | + shuffle($k); |
|
| 474 | + $v = array(); |
|
| 475 | + foreach ($k as $cle) { |
|
| 476 | + $v[$cle] = $this->tableau[$cle]; |
|
| 477 | + } |
|
| 478 | + $this->tableau = $v; |
|
| 479 | + } else { |
|
| 480 | + # {par valeur} |
|
| 481 | + if ($r[1] == 'valeur') { |
|
| 482 | + $tv = '%s'; |
|
| 483 | + } # {par valeur/xx/yy} ?? |
|
| 484 | + else { |
|
| 485 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 486 | + } |
|
| 487 | + $sortfunc .= ' |
|
| 488 | 488 | $a = ' . sprintf($tv, '$aa') . '; |
| 489 | 489 | $b = ' . sprintf($tv, '$bb') . '; |
| 490 | 490 | if ($a <> $b) |
| 491 | 491 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 492 | - } |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if ($sortfunc) { |
|
| 498 | - $sortfunc .= "\n return 0;"; |
|
| 499 | - uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 500 | - return eval($sortfunc); |
|
| 501 | - }); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Grouper les resultats |
|
| 508 | - * {fusion /x/y/z} |
|
| 509 | - * |
|
| 510 | - **/ |
|
| 511 | - protected function select_groupby() { |
|
| 512 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | - $vu = array(); |
|
| 515 | - foreach ($this->tableau as $k => $v) { |
|
| 516 | - $val = table_valeur($v, $fusion); |
|
| 517 | - if (isset($vu[$val])) { |
|
| 518 | - unset($this->tableau[$k]); |
|
| 519 | - } else { |
|
| 520 | - $vu[$val] = true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * L'iterateur est-il encore valide ? |
|
| 529 | - * |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function valid() { |
|
| 533 | - return !is_null($this->cle); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Retourner la valeur |
|
| 538 | - * |
|
| 539 | - * @return null |
|
| 540 | - */ |
|
| 541 | - public function current() { |
|
| 542 | - return $this->valeur; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Retourner la cle |
|
| 547 | - * |
|
| 548 | - * @return null |
|
| 549 | - */ |
|
| 550 | - public function key() { |
|
| 551 | - return $this->cle; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Passer a la valeur suivante |
|
| 556 | - * |
|
| 557 | - * @return void |
|
| 558 | - */ |
|
| 559 | - public function next() { |
|
| 560 | - if ($this->valid()) { |
|
| 561 | - $this->cle = key($this->tableau); |
|
| 562 | - $this->valeur = current($this->tableau); |
|
| 563 | - next($this->tableau); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Compter le nombre total de resultats |
|
| 569 | - * |
|
| 570 | - * @return int |
|
| 571 | - */ |
|
| 572 | - public function count() { |
|
| 573 | - if (is_null($this->total)) { |
|
| 574 | - $this->total = count($this->tableau); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return $this->total; |
|
| 578 | - } |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if ($sortfunc) { |
|
| 498 | + $sortfunc .= "\n return 0;"; |
|
| 499 | + uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 500 | + return eval($sortfunc); |
|
| 501 | + }); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Grouper les resultats |
|
| 508 | + * {fusion /x/y/z} |
|
| 509 | + * |
|
| 510 | + **/ |
|
| 511 | + protected function select_groupby() { |
|
| 512 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | + $vu = array(); |
|
| 515 | + foreach ($this->tableau as $k => $v) { |
|
| 516 | + $val = table_valeur($v, $fusion); |
|
| 517 | + if (isset($vu[$val])) { |
|
| 518 | + unset($this->tableau[$k]); |
|
| 519 | + } else { |
|
| 520 | + $vu[$val] = true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * L'iterateur est-il encore valide ? |
|
| 529 | + * |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function valid() { |
|
| 533 | + return !is_null($this->cle); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Retourner la valeur |
|
| 538 | + * |
|
| 539 | + * @return null |
|
| 540 | + */ |
|
| 541 | + public function current() { |
|
| 542 | + return $this->valeur; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Retourner la cle |
|
| 547 | + * |
|
| 548 | + * @return null |
|
| 549 | + */ |
|
| 550 | + public function key() { |
|
| 551 | + return $this->cle; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Passer a la valeur suivante |
|
| 556 | + * |
|
| 557 | + * @return void |
|
| 558 | + */ |
|
| 559 | + public function next() { |
|
| 560 | + if ($this->valid()) { |
|
| 561 | + $this->cle = key($this->tableau); |
|
| 562 | + $this->valeur = current($this->tableau); |
|
| 563 | + next($this->tableau); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Compter le nombre total de resultats |
|
| 569 | + * |
|
| 570 | + * @return int |
|
| 571 | + */ |
|
| 572 | + public function count() { |
|
| 573 | + if (is_null($this->total)) { |
|
| 574 | + $this->total = count($this->tableau); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return $this->total; |
|
| 578 | + } |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | /* |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | * @return array |
| 590 | 590 | */ |
| 591 | 591 | function inc_file_to_array_dist($u) { |
| 592 | - return preg_split('/\r?\n/', $u); |
|
| 592 | + return preg_split('/\r?\n/', $u); |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | /** |
@@ -598,9 +598,9 @@ discard block |
||
| 598 | 598 | * @return unknown |
| 599 | 599 | */ |
| 600 | 600 | function inc_plugins_to_array_dist() { |
| 601 | - include_spip('inc/plugin'); |
|
| 601 | + include_spip('inc/plugin'); |
|
| 602 | 602 | |
| 603 | - return liste_chemin_plugin_actifs(); |
|
| 603 | + return liste_chemin_plugin_actifs(); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | /** |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | * @return array |
| 611 | 611 | */ |
| 612 | 612 | function inc_xml_to_array_dist($u) { |
| 613 | - return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 613 | + return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -622,14 +622,14 @@ discard block |
||
| 622 | 622 | * |
| 623 | 623 | */ |
| 624 | 624 | function inc_object_to_array($object) { |
| 625 | - if (!is_object($object) && !is_array($object)) { |
|
| 626 | - return $object; |
|
| 627 | - } |
|
| 628 | - if (is_object($object)) { |
|
| 629 | - $object = get_object_vars($object); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - return array_map('inc_object_to_array', $object); |
|
| 625 | + if (!is_object($object) && !is_array($object)) { |
|
| 626 | + return $object; |
|
| 627 | + } |
|
| 628 | + if (is_object($object)) { |
|
| 629 | + $object = get_object_vars($object); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + return array_map('inc_object_to_array', $object); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -640,18 +640,18 @@ discard block |
||
| 640 | 640 | * @return array|bool |
| 641 | 641 | */ |
| 642 | 642 | function inc_yql_to_array_dist($u) { |
| 643 | - define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 644 | - $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 645 | - if (!$v['page'] |
|
| 646 | - or !$w = json_decode($v['page'], true) |
|
| 647 | - ) { |
|
| 648 | - throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 649 | - } |
|
| 650 | - if (isset($w['error'])) { |
|
| 651 | - throw new Exception($w['error']['description']); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return inc_object_to_array($w); |
|
| 643 | + define('_YQL_ENDPOINT', 'https://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 644 | + $v = recuperer_url($url = _YQL_ENDPOINT . urlencode($u) . '&format=json'); |
|
| 645 | + if (!$v['page'] |
|
| 646 | + or !$w = json_decode($v['page'], true) |
|
| 647 | + ) { |
|
| 648 | + throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 649 | + } |
|
| 650 | + if (isset($w['error'])) { |
|
| 651 | + throw new Exception($w['error']['description']); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return inc_object_to_array($w); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -661,20 +661,20 @@ discard block |
||
| 661 | 661 | * @return array|bool |
| 662 | 662 | */ |
| 663 | 663 | function inc_sql_to_array_dist($u) { |
| 664 | - # sortir le connecteur de $u |
|
| 665 | - preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 666 | - $serveur = (string)$v[1]; |
|
| 667 | - $req = trim($v[2]); |
|
| 668 | - if ($s = sql_query($req, $serveur)) { |
|
| 669 | - $r = array(); |
|
| 670 | - while ($t = sql_fetch($s)) { |
|
| 671 | - $r[] = $t; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - return $r; |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - return false; |
|
| 664 | + # sortir le connecteur de $u |
|
| 665 | + preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 666 | + $serveur = (string)$v[1]; |
|
| 667 | + $req = trim($v[2]); |
|
| 668 | + if ($s = sql_query($req, $serveur)) { |
|
| 669 | + $r = array(); |
|
| 670 | + while ($t = sql_fetch($s)) { |
|
| 671 | + $r[] = $t; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + return $r; |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + return false; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -684,11 +684,11 @@ discard block |
||
| 684 | 684 | * @return array|bool |
| 685 | 685 | */ |
| 686 | 686 | function inc_json_to_array_dist($u) { |
| 687 | - if (is_array($json = json_decode($u)) |
|
| 688 | - or is_object($json) |
|
| 689 | - ) { |
|
| 690 | - return (array)$json; |
|
| 691 | - } |
|
| 687 | + if (is_array($json = json_decode($u)) |
|
| 688 | + or is_object($json) |
|
| 689 | + ) { |
|
| 690 | + return (array)$json; |
|
| 691 | + } |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | /** |
@@ -698,30 +698,30 @@ discard block |
||
| 698 | 698 | * @return array|bool |
| 699 | 699 | */ |
| 700 | 700 | function inc_csv_to_array_dist($u) { |
| 701 | - include_spip('inc/csv'); |
|
| 702 | - list($entete, $csv) = analyse_csv($u); |
|
| 703 | - array_unshift($csv, $entete); |
|
| 704 | - |
|
| 705 | - include_spip('inc/charsets'); |
|
| 706 | - $i = 1; |
|
| 707 | - foreach ($entete as $k => $v) { |
|
| 708 | - if (trim($v) == "") { |
|
| 709 | - $v = "col" . $i; |
|
| 710 | - } // reperer des eventuelles cases vides |
|
| 711 | - if (is_numeric($v) and $v < 0) { |
|
| 712 | - $v = "__" . $v; |
|
| 713 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 714 | - if (is_numeric($v)) { |
|
| 715 | - $v = "_" . $v; |
|
| 716 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 717 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 718 | - foreach ($csv as &$item) { |
|
| 719 | - $item[$v] = &$item[$k]; |
|
| 720 | - } |
|
| 721 | - $i++; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - return $csv; |
|
| 701 | + include_spip('inc/csv'); |
|
| 702 | + list($entete, $csv) = analyse_csv($u); |
|
| 703 | + array_unshift($csv, $entete); |
|
| 704 | + |
|
| 705 | + include_spip('inc/charsets'); |
|
| 706 | + $i = 1; |
|
| 707 | + foreach ($entete as $k => $v) { |
|
| 708 | + if (trim($v) == "") { |
|
| 709 | + $v = "col" . $i; |
|
| 710 | + } // reperer des eventuelles cases vides |
|
| 711 | + if (is_numeric($v) and $v < 0) { |
|
| 712 | + $v = "__" . $v; |
|
| 713 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 714 | + if (is_numeric($v)) { |
|
| 715 | + $v = "_" . $v; |
|
| 716 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 717 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 718 | + foreach ($csv as &$item) { |
|
| 719 | + $item[$v] = &$item[$k]; |
|
| 720 | + } |
|
| 721 | + $i++; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + return $csv; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
@@ -731,12 +731,12 @@ discard block |
||
| 731 | 731 | * @return array|bool |
| 732 | 732 | */ |
| 733 | 733 | function inc_rss_to_array_dist($u) { |
| 734 | - include_spip('inc/syndic'); |
|
| 735 | - if (is_array($rss = analyser_backend($u))) { |
|
| 736 | - $tableau = $rss; |
|
| 737 | - } |
|
| 734 | + include_spip('inc/syndic'); |
|
| 735 | + if (is_array($rss = analyser_backend($u))) { |
|
| 736 | + $tableau = $rss; |
|
| 737 | + } |
|
| 738 | 738 | |
| 739 | - return $tableau; |
|
| 739 | + return $tableau; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -746,9 +746,9 @@ discard block |
||
| 746 | 746 | * @return array|bool |
| 747 | 747 | */ |
| 748 | 748 | function inc_atom_to_array_dist($u) { |
| 749 | - $g = charger_fonction('rss_to_array', 'inc'); |
|
| 749 | + $g = charger_fonction('rss_to_array', 'inc'); |
|
| 750 | 750 | |
| 751 | - return $g($u); |
|
| 751 | + return $g($u); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -759,11 +759,11 @@ discard block |
||
| 759 | 759 | * @return array|bool |
| 760 | 760 | */ |
| 761 | 761 | function inc_glob_to_array_dist($u) { |
| 762 | - $a = glob($u, |
|
| 763 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 764 | - ); |
|
| 762 | + $a = glob($u, |
|
| 763 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 764 | + ); |
|
| 765 | 765 | |
| 766 | - return $a ? $a : array(); |
|
| 766 | + return $a ? $a : array(); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | /** |
@@ -774,14 +774,14 @@ discard block |
||
| 774 | 774 | * @throws Exception |
| 775 | 775 | */ |
| 776 | 776 | function inc_yaml_to_array_dist($u) { |
| 777 | - include_spip('inc/yaml-mini'); |
|
| 778 | - if (!function_exists("yaml_decode")) { |
|
| 779 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 777 | + include_spip('inc/yaml-mini'); |
|
| 778 | + if (!function_exists("yaml_decode")) { |
|
| 779 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 780 | 780 | |
| 781 | - return false; |
|
| 782 | - } |
|
| 781 | + return false; |
|
| 782 | + } |
|
| 783 | 783 | |
| 784 | - return yaml_decode($u); |
|
| 784 | + return yaml_decode($u); |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @return array|bool |
| 797 | 797 | */ |
| 798 | 798 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 799 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 799 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -808,23 +808,23 @@ discard block |
||
| 808 | 808 | * @return array|bool |
| 809 | 809 | */ |
| 810 | 810 | function inc_ls_to_array_dist($u) { |
| 811 | - $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 812 | - $a = $glob($u); |
|
| 813 | - foreach ($a as &$v) { |
|
| 814 | - $b = (array)@stat($v); |
|
| 815 | - foreach ($b as $k => $ignore) { |
|
| 816 | - if (is_numeric($k)) { |
|
| 817 | - unset($b[$k]); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 821 | - $v = array_merge( |
|
| 822 | - pathinfo($v), |
|
| 823 | - $b |
|
| 824 | - ); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - return $a; |
|
| 811 | + $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 812 | + $a = $glob($u); |
|
| 813 | + foreach ($a as &$v) { |
|
| 814 | + $b = (array)@stat($v); |
|
| 815 | + foreach ($b as $k => $ignore) { |
|
| 816 | + if (is_numeric($k)) { |
|
| 817 | + unset($b[$k]); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 821 | + $v = array_merge( |
|
| 822 | + pathinfo($v), |
|
| 823 | + $b |
|
| 824 | + ); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + return $a; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -834,24 +834,24 @@ discard block |
||
| 834 | 834 | * @return array|bool |
| 835 | 835 | */ |
| 836 | 836 | function XMLObjectToArray($object) { |
| 837 | - $xml_array = array(); |
|
| 838 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 839 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 840 | - $key .= '-' . uniqid(); |
|
| 841 | - } |
|
| 842 | - $vars = get_object_vars($object->current()); |
|
| 843 | - if (isset($vars['@attributes'])) { |
|
| 844 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 845 | - $xml_array[$key][$k] = $v; |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - if ($object->hasChildren()) { |
|
| 849 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 850 | - $object->current()); |
|
| 851 | - } else { |
|
| 852 | - $xml_array[$key][] = strval($object->current()); |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $xml_array; |
|
| 837 | + $xml_array = array(); |
|
| 838 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 839 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 840 | + $key .= '-' . uniqid(); |
|
| 841 | + } |
|
| 842 | + $vars = get_object_vars($object->current()); |
|
| 843 | + if (isset($vars['@attributes'])) { |
|
| 844 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 845 | + $xml_array[$key][$k] = $v; |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + if ($object->hasChildren()) { |
|
| 849 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 850 | + $object->current()); |
|
| 851 | + } else { |
|
| 852 | + $xml_array[$key][] = strval($object->current()); |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $xml_array; |
|
| 857 | 857 | } |
@@ -121,6 +121,10 @@ discard block |
||
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | +/** |
|
| 125 | + * @param integer $id_input |
|
| 126 | + * @param string $file |
|
| 127 | + */ |
|
| 124 | 128 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | 129 | $name = substr(md5($file), 0, 16); |
| 126 | 130 | |
@@ -185,6 +189,9 @@ discard block |
||
| 185 | 189 | . "</div>"; |
| 186 | 190 | } |
| 187 | 191 | |
| 192 | +/** |
|
| 193 | + * @param string $nom |
|
| 194 | + */ |
|
| 188 | 195 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 189 | 196 | if (!$dir_plugins) { |
| 190 | 197 | $dir_plugins = _DIR_PLUGINS; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/charsets'); |
| 23 | 23 | include_spip('inc/texte'); |
@@ -25,181 +25,181 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | // http://code.spip.net/@ligne_plug |
| 27 | 27 | function plugins_afficher_plugin_dist( |
| 28 | - $url_page, |
|
| 29 | - $plug_file, |
|
| 30 | - $checked, |
|
| 31 | - $actif, |
|
| 32 | - $expose = false, |
|
| 33 | - $class_li = "item", |
|
| 34 | - $dir_plugins = _DIR_PLUGINS |
|
| 28 | + $url_page, |
|
| 29 | + $plug_file, |
|
| 30 | + $checked, |
|
| 31 | + $actif, |
|
| 32 | + $expose = false, |
|
| 33 | + $class_li = "item", |
|
| 34 | + $dir_plugins = _DIR_PLUGINS |
|
| 35 | 35 | ) { |
| 36 | 36 | |
| 37 | - static $id_input = 0; |
|
| 38 | - static $versions = array(); |
|
| 39 | - |
|
| 40 | - $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | - $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | - $prefix = $info['prefix']; |
|
| 44 | - $cfg = ""; |
|
| 45 | - $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | - $erreur = ""; |
|
| 48 | - |
|
| 49 | - if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | - $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | - $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | - _T('plugin_info_non_compatible_spip')); |
|
| 53 | - $class_li .= " disabled"; |
|
| 54 | - $checkable = false; |
|
| 55 | - } elseif (isset($info['erreur'])) { |
|
| 56 | - $class_li .= " error"; |
|
| 57 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | - _T('plugin_info_erreur_xml')) |
|
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | - $checkable = false; |
|
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | - $class_li .= " error"; |
|
| 63 | - $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | - " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | - } else { |
|
| 68 | - $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // numerotons les occurrences d'un meme prefix |
|
| 72 | - $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
|
| 73 | - |
|
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | - |
|
| 76 | - return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | - . ((!$checkable and !$checked) |
|
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | - . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | - . $cfg |
|
| 81 | - . $erreur |
|
| 82 | - . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | - ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | - . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | - . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | - . "</div>" |
|
| 87 | - . "</li>"; |
|
| 37 | + static $id_input = 0; |
|
| 38 | + static $versions = array(); |
|
| 39 | + |
|
| 40 | + $force_reload = (_request('var_mode') == 'recalcul'); |
|
| 41 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 42 | + $info = $get_infos($plug_file, $force_reload, $dir_plugins); |
|
| 43 | + $prefix = $info['prefix']; |
|
| 44 | + $cfg = ""; |
|
| 45 | + $checkable = ($dir_plugins !== _DIR_PLUGINS_DIST); |
|
| 46 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 47 | + $erreur = ""; |
|
| 48 | + |
|
| 49 | + if (!plugin_version_compatible($info['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 50 | + $info['slogan'] = _T('plugin_info_non_compatible_spip'); |
|
| 51 | + $erreur = http_img_pack("plugin-dis-32.png", _T('plugin_info_non_compatible_spip'), " class='picto_err'", |
|
| 52 | + _T('plugin_info_non_compatible_spip')); |
|
| 53 | + $class_li .= " disabled"; |
|
| 54 | + $checkable = false; |
|
| 55 | + } elseif (isset($info['erreur'])) { |
|
| 56 | + $class_li .= " error"; |
|
| 57 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
|
| 58 | + _T('plugin_info_erreur_xml')) |
|
| 59 | + . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 60 | + $checkable = false; |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 62 | + $class_li .= " error"; |
|
| 63 | + $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
|
| 64 | + " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
|
| 65 | + . "<div class='erreur'>" . implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 67 | + } else { |
|
| 68 | + $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // numerotons les occurrences d'un meme prefix |
|
| 72 | + $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
|
| 73 | + |
|
| 74 | + $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 75 | + |
|
| 76 | + return "<li id='$prefix$id' class='$class_li'>" |
|
| 77 | + . ((!$checkable and !$checked) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 79 | + . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
|
| 80 | + . $cfg |
|
| 81 | + . $erreur |
|
| 82 | + . (($dir_plugins !== _DIR_PLUGINS_DIST and plugin_est_installe($plug_file)) |
|
| 83 | + ? plugin_desintalle($plug_file, $nom, $dir_plugins) : '') |
|
| 84 | + . "<div class='details'>" // pour l'ajax de exec/info_plugin |
|
| 85 | + . (!$expose ? '' : affiche_bloc_plugin($plug_file, $info, $dir_plugins)) |
|
| 86 | + . "</div>" |
|
| 87 | + . "</li>"; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function plugin_bouton_config($nom, $infos, $dir) { |
| 91 | - // la verification se base sur le filesystem |
|
| 92 | - // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | - $prefix = strtolower($infos['prefix']); |
|
| 94 | - // si plugin.xml fournit un squelette, le prendre |
|
| 95 | - if (isset($infos['config']) and $infos['config']) { |
|
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | - array( |
|
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 99 | - 'nom' => $nom |
|
| 100 | - )); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // si le plugin CFG est la, l'essayer |
|
| 104 | - if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | - { |
|
| 107 | - if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | - return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // sinon prendre le squelette std sur le nom std |
|
| 114 | - return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | - array( |
|
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 117 | - 'nom' => $nom |
|
| 118 | - )); |
|
| 91 | + // la verification se base sur le filesystem |
|
| 92 | + // il faut donc n'utiliser que des minuscules, par convention |
|
| 93 | + $prefix = strtolower($infos['prefix']); |
|
| 94 | + // si plugin.xml fournit un squelette, le prendre |
|
| 95 | + if (isset($infos['config']) and $infos['config']) { |
|
| 96 | + return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 97 | + array( |
|
| 98 | + 'script' => 'configurer_' . $prefix, |
|
| 99 | + 'nom' => $nom |
|
| 100 | + )); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // si le plugin CFG est la, l'essayer |
|
| 104 | + if (defined('_DIR_PLUGIN_CFG')) { |
|
| 105 | + if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 106 | + { |
|
| 107 | + if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
|
| 108 | + return "<div class='cfg_link'>$cfg</div>"; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // sinon prendre le squelette std sur le nom std |
|
| 114 | + return recuperer_fond("prive/squelettes/inclure/cfg", |
|
| 115 | + array( |
|
| 116 | + 'script' => 'configurer_' . $prefix, |
|
| 117 | + 'nom' => $nom |
|
| 118 | + )); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // checkbox pour activer ou desactiver |
| 122 | 122 | // si ce n'est pas une extension |
| 123 | 123 | |
| 124 | 124 | function plugin_checkbox($id_input, $file, $actif) { |
| 125 | - $name = substr(md5($file), 0, 16); |
|
| 126 | - |
|
| 127 | - return "<div class='check'>\n" |
|
| 128 | - . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | - . ($actif ? " checked='checked'" : "") |
|
| 130 | - . " class='checkbox' value='O' />" |
|
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | - . "</div>"; |
|
| 125 | + $name = substr(md5($file), 0, 16); |
|
| 126 | + |
|
| 127 | + return "<div class='check'>\n" |
|
| 128 | + . "<input type='checkbox' name='s$name' id='label_$id_input'" |
|
| 129 | + . ($actif ? " checked='checked'" : "") |
|
| 130 | + . " class='checkbox' value='O' />" |
|
| 131 | + . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 132 | + . "</div>"; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function plugin_nom($info, $dir_plugins, $plug_file) { |
| 136 | - $prefix = $info['prefix']; |
|
| 137 | - $dir = "$dir_plugins$plug_file"; |
|
| 138 | - // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | - if ($info['dtd'] == "paquet") { |
|
| 140 | - $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 141 | - if (!$nom) { |
|
| 142 | - $nom = PtoBR(propre($info['nom'])); |
|
| 143 | - } |
|
| 144 | - } else { |
|
| 145 | - $nom = typo(attribut_html($info['nom'])); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return trim($nom); |
|
| 136 | + $prefix = $info['prefix']; |
|
| 137 | + $dir = "$dir_plugins$plug_file"; |
|
| 138 | + // Si dtd paquet, on traite le nom soit par son item de langue soit par sa valeur immediate a l'index "nom" |
|
| 139 | + if ($info['dtd'] == "paquet") { |
|
| 140 | + $nom = PtoBR(plugin_propre("{$prefix}_nom", "$dir/lang/paquet-$prefix")); |
|
| 141 | + if (!$nom) { |
|
| 142 | + $nom = PtoBR(propre($info['nom'])); |
|
| 143 | + } |
|
| 144 | + } else { |
|
| 145 | + $nom = typo(attribut_html($info['nom'])); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return trim($nom); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Cartouche Resume |
| 152 | 152 | function plugin_resume($info, $dir_plugins, $plug_file, $url_page) { |
| 153 | - $prefix = $info['prefix']; |
|
| 154 | - $dir = "$dir_plugins$plug_file"; |
|
| 155 | - $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | - // une seule ligne dans le slogan : couper si besoin |
|
| 157 | - if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | - $slogan = substr($slogan, 0, $p); |
|
| 159 | - } |
|
| 160 | - // couper par securite |
|
| 161 | - $slogan = couper($slogan, 80); |
|
| 162 | - |
|
| 163 | - $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | - |
|
| 165 | - $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | - |
|
| 167 | - if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 168 | - include_spip("inc/filtres_images_mini"); |
|
| 169 | - $i = inserer_attribut(image_reduire("$dir/$i", 32), 'alt', ''); |
|
| 170 | - $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 171 | - } else { |
|
| 172 | - $i = ''; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return "<div class='resume'>" |
|
| 176 | - . "<h3><a href='$url' rel='info'>" |
|
| 177 | - . $nom |
|
| 178 | - . "</a></h3>" |
|
| 179 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 180 | - . " <span class='etat'> - " |
|
| 181 | - . plugin_etat_en_clair($info['etat']) |
|
| 182 | - . "</span>" |
|
| 183 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 184 | - . $i |
|
| 185 | - . "</div>"; |
|
| 153 | + $prefix = $info['prefix']; |
|
| 154 | + $dir = "$dir_plugins$plug_file"; |
|
| 155 | + $slogan = PtoBR(plugin_propre($info['slogan'], "$dir/lang/paquet-$prefix")); |
|
| 156 | + // une seule ligne dans le slogan : couper si besoin |
|
| 157 | + if (($p = strpos($slogan, "<br />")) !== false) { |
|
| 158 | + $slogan = substr($slogan, 0, $p); |
|
| 159 | + } |
|
| 160 | + // couper par securite |
|
| 161 | + $slogan = couper($slogan, 80); |
|
| 162 | + |
|
| 163 | + $nom = plugin_nom($info, $dir_plugins, $plug_file); |
|
| 164 | + |
|
| 165 | + $url = parametre_url($url_page, "plugin", substr($dir, strlen(_DIR_RACINE))); |
|
| 166 | + |
|
| 167 | + if (isset($info['logo']) and $i = trim($info['logo'])) { |
|
| 168 | + include_spip("inc/filtres_images_mini"); |
|
| 169 | + $i = inserer_attribut(image_reduire("$dir/$i", 32), 'alt', ''); |
|
| 170 | + $i = "<div class='icon'><a href='$url' rel='info'>$i</a></div>"; |
|
| 171 | + } else { |
|
| 172 | + $i = ''; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return "<div class='resume'>" |
|
| 176 | + . "<h3><a href='$url' rel='info'>" |
|
| 177 | + . $nom |
|
| 178 | + . "</a></h3>" |
|
| 179 | + . " <span class='version'>" . $info['version'] . "</span>" |
|
| 180 | + . " <span class='etat'> - " |
|
| 181 | + . plugin_etat_en_clair($info['etat']) |
|
| 182 | + . "</span>" |
|
| 183 | + . "<div class='short'>" . $slogan . "</div>" |
|
| 184 | + . $i |
|
| 185 | + . "</div>"; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | function plugin_desintalle($plug_file, $nom, $dir_plugins = null) { |
| 189 | - if (!$dir_plugins) { |
|
| 190 | - $dir_plugins = _DIR_PLUGINS; |
|
| 191 | - } |
|
| 189 | + if (!$dir_plugins) { |
|
| 190 | + $dir_plugins = _DIR_PLUGINS; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 194 | - $text = _T('bouton_desinstaller'); |
|
| 195 | - $text2 = _T('info_desinstaller_plugin'); |
|
| 196 | - $file = basename($plug_file); |
|
| 193 | + $action = redirige_action_auteur('desinstaller_plugin', "$dir_plugins::$plug_file", 'admin_plugin'); |
|
| 194 | + $text = _T('bouton_desinstaller'); |
|
| 195 | + $text2 = _T('info_desinstaller_plugin'); |
|
| 196 | + $file = basename($plug_file); |
|
| 197 | 197 | |
| 198 | - return "<div class='actions'>[" . |
|
| 199 | - "<a href='$action' |
|
| 198 | + return "<div class='actions'>[" . |
|
| 199 | + "<a href='$action' |
|
| 200 | 200 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 201 | - . $text |
|
| 202 | - . "</a>]</div>"; |
|
| 201 | + . $text |
|
| 202 | + . "</a>]</div>"; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -213,132 +213,132 @@ discard block |
||
| 213 | 213 | * Traduction de l'état dans la langue en cours |
| 214 | 214 | **/ |
| 215 | 215 | function plugin_etat_en_clair($etat) { |
| 216 | - if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 217 | - $etat = 'developpement'; |
|
| 218 | - } |
|
| 216 | + if (!in_array($etat, array('stable', 'test', 'experimental'))) { |
|
| 217 | + $etat = 'developpement'; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - return _T('plugin_etat_' . $etat); |
|
| 220 | + return _T('plugin_etat_' . $etat); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // http://code.spip.net/@plugin_propre |
| 224 | 224 | function plugin_propre($texte, $module = '') { |
| 225 | - // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 226 | - if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 227 | - $module = substr($module, strlen(_DIR_RACINE)); |
|
| 228 | - } |
|
| 229 | - if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 230 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return propre($texte); |
|
| 225 | + // retirer le retour a la racine du module, car le find_in_path se fait depuis la racine |
|
| 226 | + if (_DIR_RACINE and strncmp($module, _DIR_RACINE, strlen(_DIR_RACINE)) == 0) { |
|
| 227 | + $module = substr($module, strlen(_DIR_RACINE)); |
|
| 228 | + } |
|
| 229 | + if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
|
| 230 | + $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return propre($texte); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
| 237 | 237 | // http://code.spip.net/@affiche_bloc_plugin |
| 238 | 238 | function affiche_bloc_plugin($plug_file, $info, $dir_plugins = null) { |
| 239 | - if (!$dir_plugins) { |
|
| 240 | - $dir_plugins = _DIR_PLUGINS; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $prefix = $info['prefix']; |
|
| 244 | - $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 245 | - |
|
| 246 | - $s = ""; |
|
| 247 | - // TODO: le traiter_multi ici n'est pas beau |
|
| 248 | - // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 249 | - $description = ""; |
|
| 250 | - if (isset($info['description'])) { |
|
| 251 | - $description = plugin_propre($info['description'], $dir); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if (isset($info['documentation']) |
|
| 255 | - and $lien = $info['documentation'] |
|
| 256 | - ) { |
|
| 257 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 258 | - } |
|
| 259 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 260 | - |
|
| 261 | - if (isset($info['auteur'])) { |
|
| 262 | - if (is_array($info['auteur'])) { |
|
| 263 | - $a = formater_credits($info['auteur'], ', '); |
|
| 264 | - } // pour compat mais ne doit plus arriver |
|
| 265 | - else { |
|
| 266 | - $a = trim($info['auteur']); |
|
| 267 | - } |
|
| 268 | - if ($a) { |
|
| 269 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 270 | - $dir)) . "</dd>\n"; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - if (isset($info['credit'])) { |
|
| 275 | - if ($a = formater_credits($info['credit'], ', ')) { |
|
| 276 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 277 | - $dir)) . "</dd>\n"; |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - if (isset($info['licence'])) { |
|
| 282 | - if (is_array($info['licence'])) { |
|
| 283 | - $a = formater_credits($info['licence'], ', '); |
|
| 284 | - } // pour compat mais ne doit plus arriver |
|
| 285 | - else { |
|
| 286 | - $a = trim($info['licence']); |
|
| 287 | - } |
|
| 288 | - if ($a) { |
|
| 289 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 290 | - $dir)) . "</dd>\n"; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $s = "<dl class='description'>$s</dl>"; |
|
| 295 | - |
|
| 296 | - // |
|
| 297 | - // Ajouter les infos techniques |
|
| 298 | - // |
|
| 299 | - $infotech = array(); |
|
| 300 | - |
|
| 301 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 302 | - // Version SVN |
|
| 303 | - if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 304 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 305 | - } |
|
| 306 | - $version .= "</dd>"; |
|
| 307 | - $infotech[] = $version; |
|
| 308 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 309 | - // source zip le cas echeant |
|
| 310 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 311 | - and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 312 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 313 | - : ''; |
|
| 314 | - |
|
| 315 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 316 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 317 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 318 | - |
|
| 319 | - $s .= "<dl class='tech'>" |
|
| 320 | - . join('', $infotech) |
|
| 321 | - . "</dl>"; |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - return $s; |
|
| 239 | + if (!$dir_plugins) { |
|
| 240 | + $dir_plugins = _DIR_PLUGINS; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $prefix = $info['prefix']; |
|
| 244 | + $dir = "$dir_plugins$plug_file/lang/paquet-$prefix"; |
|
| 245 | + |
|
| 246 | + $s = ""; |
|
| 247 | + // TODO: le traiter_multi ici n'est pas beau |
|
| 248 | + // cf. description du plugin/_stable_/ortho/plugin.xml |
|
| 249 | + $description = ""; |
|
| 250 | + if (isset($info['description'])) { |
|
| 251 | + $description = plugin_propre($info['description'], $dir); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if (isset($info['documentation']) |
|
| 255 | + and $lien = $info['documentation'] |
|
| 256 | + ) { |
|
| 257 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 258 | + } |
|
| 259 | + $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 260 | + |
|
| 261 | + if (isset($info['auteur'])) { |
|
| 262 | + if (is_array($info['auteur'])) { |
|
| 263 | + $a = formater_credits($info['auteur'], ', '); |
|
| 264 | + } // pour compat mais ne doit plus arriver |
|
| 265 | + else { |
|
| 266 | + $a = trim($info['auteur']); |
|
| 267 | + } |
|
| 268 | + if ($a) { |
|
| 269 | + $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 270 | + $dir)) . "</dd>\n"; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + if (isset($info['credit'])) { |
|
| 275 | + if ($a = formater_credits($info['credit'], ', ')) { |
|
| 276 | + $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 277 | + $dir)) . "</dd>\n"; |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + if (isset($info['licence'])) { |
|
| 282 | + if (is_array($info['licence'])) { |
|
| 283 | + $a = formater_credits($info['licence'], ', '); |
|
| 284 | + } // pour compat mais ne doit plus arriver |
|
| 285 | + else { |
|
| 286 | + $a = trim($info['licence']); |
|
| 287 | + } |
|
| 288 | + if ($a) { |
|
| 289 | + $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 290 | + $dir)) . "</dd>\n"; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $s = "<dl class='description'>$s</dl>"; |
|
| 295 | + |
|
| 296 | + // |
|
| 297 | + // Ajouter les infos techniques |
|
| 298 | + // |
|
| 299 | + $infotech = array(); |
|
| 300 | + |
|
| 301 | + $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 302 | + // Version SVN |
|
| 303 | + if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 304 | + $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 305 | + } |
|
| 306 | + $version .= "</dd>"; |
|
| 307 | + $infotech[] = $version; |
|
| 308 | + $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 309 | + // source zip le cas echeant |
|
| 310 | + $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 311 | + and preg_match(',^source:(.*)$,m', $log, $r)) |
|
| 312 | + ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 313 | + : ''; |
|
| 314 | + |
|
| 315 | + $infotech[] = !$info['necessite'] ? '' : |
|
| 316 | + ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 317 | + array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 318 | + |
|
| 319 | + $s .= "<dl class='tech'>" |
|
| 320 | + . join('', $infotech) |
|
| 321 | + . "</dl>"; |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + return $s; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | function formater_credits($infos, $sep = ', ') { |
| 328 | - $texte = ''; |
|
| 329 | - |
|
| 330 | - foreach ($infos as $_credit) { |
|
| 331 | - if ($texte) { |
|
| 332 | - $texte .= $sep; |
|
| 333 | - } |
|
| 334 | - // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 335 | - $texte .= |
|
| 336 | - (!is_array($_credit)) |
|
| 337 | - ? PtoBR(propre($_credit)) |
|
| 338 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 339 | - $_credit['nom'] . |
|
| 340 | - ($_credit['url'] ? '</a>' : ''); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $texte; |
|
| 328 | + $texte = ''; |
|
| 329 | + |
|
| 330 | + foreach ($infos as $_credit) { |
|
| 331 | + if ($texte) { |
|
| 332 | + $texte .= $sep; |
|
| 333 | + } |
|
| 334 | + // Si le credit en cours n'est pas un array c'est donc un copyright |
|
| 335 | + $texte .= |
|
| 336 | + (!is_array($_credit)) |
|
| 337 | + ? PtoBR(propre($_credit)) |
|
| 338 | + : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 339 | + $_credit['nom'] . |
|
| 340 | + ($_credit['url'] ? '</a>' : ''); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $texte; |
|
| 344 | 344 | } |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | $class_li .= " error"; |
| 57 | 57 | $erreur = http_img_pack("plugin-err-32.png", _T('plugin_info_erreur_xml'), " class='picto_err'", |
| 58 | 58 | _T('plugin_info_erreur_xml')) |
| 59 | - . "<div class='erreur'>" . join('<br >', $info['erreur']) . "</div>"; |
|
| 59 | + . "<div class='erreur'>".join('<br >', $info['erreur'])."</div>"; |
|
| 60 | 60 | $checkable = false; |
| 61 | - } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file])) { |
|
| 61 | + } elseif (isset($GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])) { |
|
| 62 | 62 | $class_li .= " error"; |
| 63 | 63 | $erreur = http_img_pack("plugin-err-32.png", _T('plugin_impossible_activer', array('plugin' => $nom)), |
| 64 | 64 | " class='picto_err'", _T('plugin_impossible_activer', array('plugin' => $nom))) |
| 65 | - . "<div class='erreur'>" . implode("<br />", |
|
| 66 | - $GLOBALS['erreurs_activation_raw'][$dir_plugins . $plug_file]) . "</div>"; |
|
| 65 | + . "<div class='erreur'>".implode("<br />", |
|
| 66 | + $GLOBALS['erreurs_activation_raw'][$dir_plugins.$plug_file])."</div>"; |
|
| 67 | 67 | } else { |
| 68 | 68 | $cfg = $actif ? plugin_bouton_config($plug_file, $info, $dir_plugins) : ""; |
| 69 | 69 | } |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | // numerotons les occurrences d'un meme prefix |
| 72 | 72 | $versions[$prefix] = $id = isset($versions[$prefix]) ? $versions[$prefix] + 1 : ''; |
| 73 | 73 | |
| 74 | - $class_li .= ($actif ? " actif" : "") . ($expose ? " on" : ""); |
|
| 74 | + $class_li .= ($actif ? " actif" : "").($expose ? " on" : ""); |
|
| 75 | 75 | |
| 76 | 76 | return "<li id='$prefix$id' class='$class_li'>" |
| 77 | 77 | . ((!$checkable and !$checked) |
| 78 | - ? '' : plugin_checkbox(++$id_input, $dir_plugins . $plug_file, $checked)) |
|
| 78 | + ? '' : plugin_checkbox(++$id_input, $dir_plugins.$plug_file, $checked)) |
|
| 79 | 79 | . plugin_resume($info, $dir_plugins, $plug_file, $url_page) |
| 80 | 80 | . $cfg |
| 81 | 81 | . $erreur |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | $prefix = strtolower($infos['prefix']); |
| 94 | 94 | // si plugin.xml fournit un squelette, le prendre |
| 95 | 95 | if (isset($infos['config']) and $infos['config']) { |
| 96 | - return recuperer_fond("$dir$nom/" . $infos['config'], |
|
| 96 | + return recuperer_fond("$dir$nom/".$infos['config'], |
|
| 97 | 97 | array( |
| 98 | - 'script' => 'configurer_' . $prefix, |
|
| 98 | + 'script' => 'configurer_'.$prefix, |
|
| 99 | 99 | 'nom' => $nom |
| 100 | 100 | )); |
| 101 | 101 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | // sinon prendre le squelette std sur le nom std |
| 114 | 114 | return recuperer_fond("prive/squelettes/inclure/cfg", |
| 115 | 115 | array( |
| 116 | - 'script' => 'configurer_' . $prefix, |
|
| 116 | + 'script' => 'configurer_'.$prefix, |
|
| 117 | 117 | 'nom' => $nom |
| 118 | 118 | )); |
| 119 | 119 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | . "<input type='checkbox' name='s$name' id='label_$id_input'" |
| 129 | 129 | . ($actif ? " checked='checked'" : "") |
| 130 | 130 | . " class='checkbox' value='O' />" |
| 131 | - . "\n<label for='label_$id_input'>" . _T('activer_plugin') . "</label>" |
|
| 131 | + . "\n<label for='label_$id_input'>"._T('activer_plugin')."</label>" |
|
| 132 | 132 | . "</div>"; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | . "<h3><a href='$url' rel='info'>" |
| 177 | 177 | . $nom |
| 178 | 178 | . "</a></h3>" |
| 179 | - . " <span class='version'>" . $info['version'] . "</span>" |
|
| 179 | + . " <span class='version'>".$info['version']."</span>" |
|
| 180 | 180 | . " <span class='etat'> - " |
| 181 | 181 | . plugin_etat_en_clair($info['etat']) |
| 182 | 182 | . "</span>" |
| 183 | - . "<div class='short'>" . $slogan . "</div>" |
|
| 183 | + . "<div class='short'>".$slogan."</div>" |
|
| 184 | 184 | . $i |
| 185 | 185 | . "</div>"; |
| 186 | 186 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | $text2 = _T('info_desinstaller_plugin'); |
| 196 | 196 | $file = basename($plug_file); |
| 197 | 197 | |
| 198 | - return "<div class='actions'>[" . |
|
| 198 | + return "<div class='actions'>[". |
|
| 199 | 199 | "<a href='$action' |
| 200 | 200 | onclick='return confirm(\"$text $nom ?\\n$text2\")'>" |
| 201 | 201 | . $text |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $etat = 'developpement'; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - return _T('plugin_etat_' . $etat); |
|
| 220 | + return _T('plugin_etat_'.$etat); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // http://code.spip.net/@plugin_propre |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $module = substr($module, strlen(_DIR_RACINE)); |
| 228 | 228 | } |
| 229 | 229 | if (preg_match("|^\w+_[\w_]+$|", $texte)) { |
| 230 | - $texte = _T(($module ? "$module:" : '') . $texte, array(), array('force' => false)); |
|
| 230 | + $texte = _T(($module ? "$module:" : '').$texte, array(), array('force' => false)); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | return propre($texte); |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | if (isset($info['documentation']) |
| 255 | 255 | and $lien = $info['documentation'] |
| 256 | 256 | ) { |
| 257 | - $description .= "<p><em class='site'><a href='$lien' class='spip_out'>" . _T('en_savoir_plus') . '</a></em></p>'; |
|
| 257 | + $description .= "<p><em class='site'><a href='$lien' class='spip_out'>"._T('en_savoir_plus').'</a></em></p>'; |
|
| 258 | 258 | } |
| 259 | - $s .= "<dd class='desc'>" . $description . "</dd>\n"; |
|
| 259 | + $s .= "<dd class='desc'>".$description."</dd>\n"; |
|
| 260 | 260 | |
| 261 | 261 | if (isset($info['auteur'])) { |
| 262 | 262 | if (is_array($info['auteur'])) { |
@@ -266,15 +266,15 @@ discard block |
||
| 266 | 266 | $a = trim($info['auteur']); |
| 267 | 267 | } |
| 268 | 268 | if ($a) { |
| 269 | - $s .= "<dt class='auteurs'>" . _T('public:par_auteur') . "</dt><dd class='auteurs'>" . PtoBR(propre($a, |
|
| 270 | - $dir)) . "</dd>\n"; |
|
| 269 | + $s .= "<dt class='auteurs'>"._T('public:par_auteur')."</dt><dd class='auteurs'>".PtoBR(propre($a, |
|
| 270 | + $dir))."</dd>\n"; |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | if (isset($info['credit'])) { |
| 275 | 275 | if ($a = formater_credits($info['credit'], ', ')) { |
| 276 | - $s .= "<dt class='credits'>" . _T('plugin_info_credit') . "</dt><dd class='credits'>" . PtoBR(propre($a, |
|
| 277 | - $dir)) . "</dd>\n"; |
|
| 276 | + $s .= "<dt class='credits'>"._T('plugin_info_credit')."</dt><dd class='credits'>".PtoBR(propre($a, |
|
| 277 | + $dir))."</dd>\n"; |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -286,8 +286,8 @@ discard block |
||
| 286 | 286 | $a = trim($info['licence']); |
| 287 | 287 | } |
| 288 | 288 | if ($a) { |
| 289 | - $s .= "<dt class='licence'>" . _T('intitule_licence') . "</dt><dd class='licence'>" . PtoBR(propre($a, |
|
| 290 | - $dir)) . "</dd>\n"; |
|
| 289 | + $s .= "<dt class='licence'>"._T('intitule_licence')."</dt><dd class='licence'>".PtoBR(propre($a, |
|
| 290 | + $dir))."</dd>\n"; |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -298,23 +298,22 @@ discard block |
||
| 298 | 298 | // |
| 299 | 299 | $infotech = array(); |
| 300 | 300 | |
| 301 | - $version = "<dt>" . _T('version') . "</dt><dd>" . $info['version']; |
|
| 301 | + $version = "<dt>"._T('version')."</dt><dd>".$info['version']; |
|
| 302 | 302 | // Version SVN |
| 303 | - if ($svn_revision = version_svn_courante($dir_plugins . $plug_file)) { |
|
| 304 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 303 | + if ($svn_revision = version_svn_courante($dir_plugins.$plug_file)) { |
|
| 304 | + $version .= ($svn_revision < 0 ? ' SVN' : '').' ['.abs($svn_revision).']'; |
|
| 305 | 305 | } |
| 306 | 306 | $version .= "</dd>"; |
| 307 | 307 | $infotech[] = $version; |
| 308 | - $infotech[] = "<dt>" . _T('repertoire_plugins') . "</dt><dd>" . joli_repertoire("$dir_plugins$plug_file") . "</dd>"; |
|
| 308 | + $infotech[] = "<dt>"._T('repertoire_plugins')."</dt><dd>".joli_repertoire("$dir_plugins$plug_file")."</dd>"; |
|
| 309 | 309 | // source zip le cas echeant |
| 310 | - $infotech[] = (lire_fichier($dir_plugins . $plug_file . '/install.log', $log) |
|
| 310 | + $infotech[] = (lire_fichier($dir_plugins.$plug_file.'/install.log', $log) |
|
| 311 | 311 | and preg_match(',^source:(.*)$,m', $log, $r)) |
| 312 | - ? '<dt>' . _T('plugin_source') . '</dt><dd>' . trim($r[1]) . "</dd>" |
|
| 312 | + ? '<dt>'._T('plugin_source').'</dt><dd>'.trim($r[1])."</dd>" |
|
| 313 | 313 | : ''; |
| 314 | 314 | |
| 315 | - $infotech[] = !$info['necessite'] ? '' : |
|
| 316 | - ('<dt>' . _T('plugin_info_necessite') . '</dt><dd>' . join(' ', |
|
| 317 | - array_map('array_shift', $info['necessite'])) . '</dd>'); |
|
| 315 | + $infotech[] = !$info['necessite'] ? '' : ('<dt>'._T('plugin_info_necessite').'</dt><dd>'.join(' ', |
|
| 316 | + array_map('array_shift', $info['necessite'])).'</dd>'); |
|
| 318 | 317 | |
| 319 | 318 | $s .= "<dl class='tech'>" |
| 320 | 319 | . join('', $infotech) |
@@ -335,8 +334,8 @@ discard block |
||
| 335 | 334 | $texte .= |
| 336 | 335 | (!is_array($_credit)) |
| 337 | 336 | ? PtoBR(propre($_credit)) |
| 338 | - : ($_credit['url'] ? '<a href="' . $_credit['url'] . '">' : '') . |
|
| 339 | - $_credit['nom'] . |
|
| 337 | + : ($_credit['url'] ? '<a href="'.$_credit['url'].'">' : ''). |
|
| 338 | + $_credit['nom']. |
|
| 340 | 339 | ($_credit['url'] ? '</a>' : ''); |
| 341 | 340 | } |
| 342 | 341 | |
@@ -102,10 +102,12 @@ |
||
| 102 | 102 | |
| 103 | 103 | // si le plugin CFG est la, l'essayer |
| 104 | 104 | if (defined('_DIR_PLUGIN_CFG')) { |
| 105 | - if (include_spip('inc/cfg')) // test CFG version >= 1.0.5 |
|
| 105 | + if (include_spip('inc/cfg')) { |
|
| 106 | + // test CFG version >= 1.0.5 |
|
| 106 | 107 | { |
| 107 | 108 | if ($cfg = icone_lien_cfg("$dir$nom", "cfg")) { |
| 108 | 109 | return "<div class='cfg_link'>$cfg</div>"; |
| 110 | + } |
|
| 109 | 111 | } |
| 110 | 112 | } |
| 111 | 113 | } |
@@ -75,11 +75,19 @@ |
||
| 75 | 75 | // vraiment n'importe quoi la gestion des chemins des plugins |
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // http://code.spip.net/@chemin_plug |
| 78 | +/** |
|
| 79 | + * @param string $racine |
|
| 80 | + * |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 78 | 83 | function chemin_plug($racine, $plug) { |
| 79 | 84 | return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | // http://code.spip.net/@tree_open_close_dir |
| 88 | +/** |
|
| 89 | + * @param string $target |
|
| 90 | + */ |
|
| 83 | 91 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | 92 | if ($current == $target) { |
| 85 | 93 | return ""; |
@@ -11,64 +11,64 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // http://code.spip.net/@affiche_arbre_plugins |
| 18 | 18 | function plugins_afficher_repertoires_dist($url_page, $liste_plugins, $liste_plugins_actifs) { |
| 19 | - $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | - $racine = basename(_DIR_PLUGINS); |
|
| 21 | - $init_dir = $current_dir = ""; |
|
| 22 | - // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | - // des qu'un path est deja note deplie on s'arrete |
|
| 24 | - $deplie = array($racine => true); |
|
| 25 | - $fast_liste_plugins_actifs = array(); |
|
| 26 | - foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | - $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | - $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | - $dir = dirname($chemin_plug); |
|
| 30 | - $maxiter = 100; |
|
| 31 | - while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | - $deplie[$dir] = true; |
|
| 33 | - $dir = dirname($dir); |
|
| 34 | - } |
|
| 35 | - } |
|
| 19 | + $ligne_plug = charger_fonction('afficher_plugin', 'plugins'); |
|
| 20 | + $racine = basename(_DIR_PLUGINS); |
|
| 21 | + $init_dir = $current_dir = ""; |
|
| 22 | + // liste des repertoires deplies : construit en remontant l'arbo de chaque plugin actif |
|
| 23 | + // des qu'un path est deja note deplie on s'arrete |
|
| 24 | + $deplie = array($racine => true); |
|
| 25 | + $fast_liste_plugins_actifs = array(); |
|
| 26 | + foreach ($liste_plugins_actifs as $key => $plug) { |
|
| 27 | + $chemin_plug = chemin_plug($racine, $plug); |
|
| 28 | + $fast_liste_plugins_actifs[$chemin_plug] = true; |
|
| 29 | + $dir = dirname($chemin_plug); |
|
| 30 | + $maxiter = 100; |
|
| 31 | + while (strlen($dir) && !isset($deplie[$dir]) && $dir != $racine && $maxiter-- > 0) { |
|
| 32 | + $deplie[$dir] = true; |
|
| 33 | + $dir = dirname($dir); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - // index repertoires --> plugin |
|
| 38 | - $dir_index = array(); |
|
| 39 | - foreach ($liste_plugins as $key => $plug) { |
|
| 40 | - $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | - $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | - } |
|
| 37 | + // index repertoires --> plugin |
|
| 38 | + $dir_index = array(); |
|
| 39 | + foreach ($liste_plugins as $key => $plug) { |
|
| 40 | + $liste_plugins[$key] = chemin_plug($racine, $plug); |
|
| 41 | + $dir_index[dirname($liste_plugins[$key])][] = $key; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - $visible = @isset($deplie[$current_dir]); |
|
| 45 | - $maxiter = 1000; |
|
| 44 | + $visible = @isset($deplie[$current_dir]); |
|
| 45 | + $maxiter = 1000; |
|
| 46 | 46 | |
| 47 | - $res = ''; |
|
| 48 | - while (count($liste_plugins) && $maxiter--) { |
|
| 49 | - // le rep suivant |
|
| 50 | - $dir = dirname(reset($liste_plugins)); |
|
| 51 | - if ($dir != $current_dir) { |
|
| 52 | - $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | - } |
|
| 47 | + $res = ''; |
|
| 48 | + while (count($liste_plugins) && $maxiter--) { |
|
| 49 | + // le rep suivant |
|
| 50 | + $dir = dirname(reset($liste_plugins)); |
|
| 51 | + if ($dir != $current_dir) { |
|
| 52 | + $res .= tree_open_close_dir($current_dir, $dir, $deplie); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // d'abord tous les plugins du rep courant |
|
| 56 | - if (isset($dir_index[$current_dir])) { |
|
| 57 | - foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | - $plug = $liste_plugins[$key]; |
|
| 59 | - $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | - $id = substr(md5($plug), 0, 16); |
|
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 63 | - unset($liste_plugins[$key]); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 55 | + // d'abord tous les plugins du rep courant |
|
| 56 | + if (isset($dir_index[$current_dir])) { |
|
| 57 | + foreach ($dir_index[$current_dir] as $key) { |
|
| 58 | + $plug = $liste_plugins[$key]; |
|
| 59 | + $actif = @isset($fast_liste_plugins_actifs[$plug]); |
|
| 60 | + $id = substr(md5($plug), 0, 16); |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | + 'menu-entree') . "\n"; |
|
| 63 | + unset($liste_plugins[$key]); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $res .= tree_open_close_dir($current_dir, $init_dir, true); |
|
| 68 | 68 | |
| 69 | - return "<ul class='menu-liste plugins'>" |
|
| 70 | - . $res |
|
| 71 | - . "</ul>"; |
|
| 69 | + return "<ul class='menu-liste plugins'>" |
|
| 70 | + . $res |
|
| 71 | + . "</ul>"; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -76,44 +76,44 @@ discard block |
||
| 76 | 76 | // une fonction pour aider... |
| 77 | 77 | // http://code.spip.net/@chemin_plug |
| 78 | 78 | function chemin_plug($racine, $plug) { |
| 79 | - return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 79 | + return preg_replace(',[^/]+/\.\./,', '', "$racine/$plug"); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // http://code.spip.net/@tree_open_close_dir |
| 83 | 83 | function tree_open_close_dir(&$current, $target, $deplie = array()) { |
| 84 | - if ($current == $target) { |
|
| 85 | - return ""; |
|
| 86 | - } |
|
| 87 | - $tcur = explode("/", $current); |
|
| 88 | - $ttarg = explode("/", $target); |
|
| 89 | - $tcom = array(); |
|
| 90 | - $output = ""; |
|
| 91 | - // la partie commune |
|
| 92 | - while (reset($tcur) == reset($ttarg)) { |
|
| 93 | - $tcom[] = array_shift($tcur); |
|
| 94 | - array_shift($ttarg); |
|
| 95 | - } |
|
| 96 | - // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | - while ($close = array_pop($tcur)) { |
|
| 98 | - $output .= "</ul>\n"; |
|
| 99 | - $output .= fin_block(); |
|
| 100 | - $output .= "</li>\n"; |
|
| 101 | - } |
|
| 102 | - $chemin = ""; |
|
| 103 | - if (count($tcom)) { |
|
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | - } |
|
| 106 | - // ouvrir les repertoires jusqu'a la cible |
|
| 107 | - while ($open = array_shift($ttarg)) { |
|
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 110 | - $output .= "<li>"; |
|
| 111 | - $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | - $output .= debut_block_depliable($visible); |
|
| 84 | + if ($current == $target) { |
|
| 85 | + return ""; |
|
| 86 | + } |
|
| 87 | + $tcur = explode("/", $current); |
|
| 88 | + $ttarg = explode("/", $target); |
|
| 89 | + $tcom = array(); |
|
| 90 | + $output = ""; |
|
| 91 | + // la partie commune |
|
| 92 | + while (reset($tcur) == reset($ttarg)) { |
|
| 93 | + $tcom[] = array_shift($tcur); |
|
| 94 | + array_shift($ttarg); |
|
| 95 | + } |
|
| 96 | + // fermer les repertoires courant jusqu'au point de fork |
|
| 97 | + while ($close = array_pop($tcur)) { |
|
| 98 | + $output .= "</ul>\n"; |
|
| 99 | + $output .= fin_block(); |
|
| 100 | + $output .= "</li>\n"; |
|
| 101 | + } |
|
| 102 | + $chemin = ""; |
|
| 103 | + if (count($tcom)) { |
|
| 104 | + $chemin .= implode("/", $tcom) . "/"; |
|
| 105 | + } |
|
| 106 | + // ouvrir les repertoires jusqu'a la cible |
|
| 107 | + while ($open = array_shift($ttarg)) { |
|
| 108 | + $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | + $chemin .= $open . "/"; |
|
| 110 | + $output .= "<li>"; |
|
| 111 | + $output .= bouton_block_depliable($chemin, $visible); |
|
| 112 | + $output .= debut_block_depliable($visible); |
|
| 113 | 113 | |
| 114 | - $output .= "<ul>\n"; |
|
| 115 | - } |
|
| 116 | - $current = $target; |
|
| 114 | + $output .= "<ul>\n"; |
|
| 115 | + } |
|
| 116 | + $current = $target; |
|
| 117 | 117 | |
| 118 | - return $output; |
|
| 118 | + return $output; |
|
| 119 | 119 | } |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | $plug = $liste_plugins[$key]; |
| 59 | 59 | $actif = @isset($fast_liste_plugins_actifs[$plug]); |
| 60 | 60 | $id = substr(md5($plug), 0, 16); |
| 61 | - $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE . $plug), $actif, |
|
| 62 | - 'menu-entree') . "\n"; |
|
| 61 | + $res .= $ligne_plug($url_page, str_replace(_DIR_PLUGINS, '', _DIR_RACINE.$plug), $actif, |
|
| 62 | + 'menu-entree')."\n"; |
|
| 63 | 63 | unset($liste_plugins[$key]); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -101,12 +101,12 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | $chemin = ""; |
| 103 | 103 | if (count($tcom)) { |
| 104 | - $chemin .= implode("/", $tcom) . "/"; |
|
| 104 | + $chemin .= implode("/", $tcom)."/"; |
|
| 105 | 105 | } |
| 106 | 106 | // ouvrir les repertoires jusqu'a la cible |
| 107 | 107 | while ($open = array_shift($ttarg)) { |
| 108 | - $visible = @isset($deplie[$chemin . $open]); |
|
| 109 | - $chemin .= $open . "/"; |
|
| 108 | + $visible = @isset($deplie[$chemin.$open]); |
|
| 109 | + $chemin .= $open."/"; |
|
| 110 | 110 | $output .= "<li>"; |
| 111 | 111 | $output .= bouton_block_depliable($chemin, $visible); |
| 112 | 112 | $output .= debut_block_depliable($visible); |
@@ -14,6 +14,9 @@ |
||
| 14 | 14 | return; |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | +/** |
|
| 18 | + * @return string|null |
|
| 19 | + */ |
|
| 17 | 20 | function securiser_redirect_action($redirect) { |
| 18 | 21 | if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
| 19 | 22 | and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
@@ -11,146 +11,146 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function securiser_redirect_action($redirect) { |
| 18 | - if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 19 | - and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
|
| 20 | - // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 21 | - // c'est encore le plus simple |
|
| 22 | - $base = $GLOBALS['meta']['adresse_site'] . "/"; |
|
| 23 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 24 | - return $redirect; |
|
| 25 | - } |
|
| 26 | - $base = url_de_base(); |
|
| 27 | - if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 28 | - return $redirect; |
|
| 29 | - } |
|
| 18 | + if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 19 | + and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
|
| 20 | + // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 21 | + // c'est encore le plus simple |
|
| 22 | + $base = $GLOBALS['meta']['adresse_site'] . "/"; |
|
| 23 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 24 | + return $redirect; |
|
| 25 | + } |
|
| 26 | + $base = url_de_base(); |
|
| 27 | + if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
|
| 28 | + return $redirect; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return ""; |
|
| 32 | - } |
|
| 31 | + return ""; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return $redirect; |
|
| 34 | + return $redirect; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // http://code.spip.net/@traiter_appels_actions |
| 38 | 38 | function traiter_appels_actions() { |
| 39 | - // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 40 | - if ($action = _request('action')) { |
|
| 41 | - include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 42 | - include_spip('inc/autoriser'); |
|
| 43 | - include_spip('inc/headers'); |
|
| 44 | - include_spip('inc/actions'); |
|
| 45 | - // des actions peuvent appeler _T |
|
| 46 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 47 | - include_spip('inc/lang'); |
|
| 48 | - utiliser_langue_visiteur(); |
|
| 49 | - } |
|
| 50 | - // si l'action est provoque par un hit {ajax} |
|
| 51 | - // il faut transmettre l'env ajax au redirect |
|
| 52 | - // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 53 | - if (($v = _request('var_ajax')) |
|
| 54 | - and ($v !== 'form') |
|
| 55 | - and ($args = _request('var_ajax_env')) |
|
| 56 | - and ($url = _request('redirect')) |
|
| 57 | - ) { |
|
| 58 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 59 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 60 | - set_request('redirect', $url); |
|
| 61 | - } else { |
|
| 62 | - if (_request('redirect')) { |
|
| 63 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $var_f = charger_fonction($action, 'action'); |
|
| 67 | - $var_f(); |
|
| 68 | - if (!isset($GLOBALS['redirect'])) { |
|
| 69 | - $GLOBALS['redirect'] = _request('redirect'); |
|
| 70 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 71 | - $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 72 | - } |
|
| 73 | - $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 74 | - } |
|
| 75 | - if ($url = $GLOBALS['redirect']) { |
|
| 76 | - // si l'action est provoque par un hit {ajax} |
|
| 77 | - // il faut transmettre l'env ajax au redirect |
|
| 78 | - // qui a pu etre defini par l'action |
|
| 79 | - if (($v = _request('var_ajax')) |
|
| 80 | - and ($v !== 'form') |
|
| 81 | - and ($args = _request('var_ajax_env')) |
|
| 82 | - ) { |
|
| 83 | - $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 84 | - $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 85 | - // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 86 | - $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 87 | - } |
|
| 88 | - $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 89 | - redirige_par_entete($url); |
|
| 90 | - } |
|
| 91 | - if (!headers_sent() |
|
| 92 | - and !ob_get_length() |
|
| 93 | - ) { |
|
| 94 | - http_status(204); |
|
| 95 | - } // No Content |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 39 | + // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 40 | + if ($action = _request('action')) { |
|
| 41 | + include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 42 | + include_spip('inc/autoriser'); |
|
| 43 | + include_spip('inc/headers'); |
|
| 44 | + include_spip('inc/actions'); |
|
| 45 | + // des actions peuvent appeler _T |
|
| 46 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 47 | + include_spip('inc/lang'); |
|
| 48 | + utiliser_langue_visiteur(); |
|
| 49 | + } |
|
| 50 | + // si l'action est provoque par un hit {ajax} |
|
| 51 | + // il faut transmettre l'env ajax au redirect |
|
| 52 | + // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 53 | + if (($v = _request('var_ajax')) |
|
| 54 | + and ($v !== 'form') |
|
| 55 | + and ($args = _request('var_ajax_env')) |
|
| 56 | + and ($url = _request('redirect')) |
|
| 57 | + ) { |
|
| 58 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 59 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 60 | + set_request('redirect', $url); |
|
| 61 | + } else { |
|
| 62 | + if (_request('redirect')) { |
|
| 63 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $var_f = charger_fonction($action, 'action'); |
|
| 67 | + $var_f(); |
|
| 68 | + if (!isset($GLOBALS['redirect'])) { |
|
| 69 | + $GLOBALS['redirect'] = _request('redirect'); |
|
| 70 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 71 | + $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 72 | + } |
|
| 73 | + $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 74 | + } |
|
| 75 | + if ($url = $GLOBALS['redirect']) { |
|
| 76 | + // si l'action est provoque par un hit {ajax} |
|
| 77 | + // il faut transmettre l'env ajax au redirect |
|
| 78 | + // qui a pu etre defini par l'action |
|
| 79 | + if (($v = _request('var_ajax')) |
|
| 80 | + and ($v !== 'form') |
|
| 81 | + and ($args = _request('var_ajax_env')) |
|
| 82 | + ) { |
|
| 83 | + $url = parametre_url($url, 'var_ajax', $v, '&'); |
|
| 84 | + $url = parametre_url($url, 'var_ajax_env', $args, '&'); |
|
| 85 | + // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 86 | + $url = preg_replace(',#([^#&?]+)$,', "&var_ajax_ancre=\\1", $url); |
|
| 87 | + } |
|
| 88 | + $url = str_replace('&', '&', $url); // les redirections se font en &, pas en en & |
|
| 89 | + redirige_par_entete($url); |
|
| 90 | + } |
|
| 91 | + if (!headers_sent() |
|
| 92 | + and !ob_get_length() |
|
| 93 | + ) { |
|
| 94 | + http_status(204); |
|
| 95 | + } // No Content |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - return false; |
|
| 99 | + return false; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | // http://code.spip.net/@refuser_traiter_formulaire_ajax |
| 104 | 104 | function refuser_traiter_formulaire_ajax() { |
| 105 | - if ($v = _request('var_ajax') |
|
| 106 | - and $v == 'form' |
|
| 107 | - and $form = _request('formulaire_action') |
|
| 108 | - and $args = _request('formulaire_action_args') |
|
| 109 | - and decoder_contexte_ajax($args, $form) !== false |
|
| 110 | - ) { |
|
| 111 | - // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 112 | - // mais traiter ne veut pas |
|
| 113 | - // on le dit a la page qui va resumbit |
|
| 114 | - // sans ajax |
|
| 115 | - include_spip('inc/actions'); |
|
| 116 | - ajax_retour('noajax', false); |
|
| 117 | - exit; |
|
| 118 | - } |
|
| 105 | + if ($v = _request('var_ajax') |
|
| 106 | + and $v == 'form' |
|
| 107 | + and $form = _request('formulaire_action') |
|
| 108 | + and $args = _request('formulaire_action_args') |
|
| 109 | + and decoder_contexte_ajax($args, $form) !== false |
|
| 110 | + ) { |
|
| 111 | + // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 112 | + // mais traiter ne veut pas |
|
| 113 | + // on le dit a la page qui va resumbit |
|
| 114 | + // sans ajax |
|
| 115 | + include_spip('inc/actions'); |
|
| 116 | + ajax_retour('noajax', false); |
|
| 117 | + exit; |
|
| 118 | + } |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // http://code.spip.net/@traiter_appels_inclusions_ajax |
| 122 | 122 | function traiter_appels_inclusions_ajax() { |
| 123 | - // traiter les appels de bloc ajax (ex: pagination) |
|
| 124 | - if ($v = _request('var_ajax') |
|
| 125 | - and $v !== 'form' |
|
| 126 | - and $args = _request('var_ajax_env') |
|
| 127 | - ) { |
|
| 128 | - include_spip('inc/filtres'); |
|
| 129 | - include_spip('inc/actions'); |
|
| 130 | - if ($args = decoder_contexte_ajax($args) |
|
| 131 | - and $fond = $args['fond'] |
|
| 132 | - ) { |
|
| 133 | - include_spip('public/assembler'); |
|
| 134 | - $contexte = calculer_contexte(); |
|
| 135 | - $contexte = array_merge($args, $contexte); |
|
| 136 | - $page = recuperer_fond($fond, $contexte, array('trim' => false)); |
|
| 137 | - $texte = $page; |
|
| 138 | - if ($ancre = _request('var_ajax_ancre')) { |
|
| 139 | - // pas n'importe quoi quand meme dans la variable ! |
|
| 140 | - $ancre = str_replace(array('<', '"', "'"), array('<', '"', ''), $ancre); |
|
| 141 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 142 | - } |
|
| 143 | - } else { |
|
| 144 | - include_spip('inc/headers'); |
|
| 145 | - http_status(403); |
|
| 146 | - $texte = _L('signature ajax bloc incorrecte'); |
|
| 147 | - } |
|
| 148 | - ajax_retour($texte, false); |
|
| 123 | + // traiter les appels de bloc ajax (ex: pagination) |
|
| 124 | + if ($v = _request('var_ajax') |
|
| 125 | + and $v !== 'form' |
|
| 126 | + and $args = _request('var_ajax_env') |
|
| 127 | + ) { |
|
| 128 | + include_spip('inc/filtres'); |
|
| 129 | + include_spip('inc/actions'); |
|
| 130 | + if ($args = decoder_contexte_ajax($args) |
|
| 131 | + and $fond = $args['fond'] |
|
| 132 | + ) { |
|
| 133 | + include_spip('public/assembler'); |
|
| 134 | + $contexte = calculer_contexte(); |
|
| 135 | + $contexte = array_merge($args, $contexte); |
|
| 136 | + $page = recuperer_fond($fond, $contexte, array('trim' => false)); |
|
| 137 | + $texte = $page; |
|
| 138 | + if ($ancre = _request('var_ajax_ancre')) { |
|
| 139 | + // pas n'importe quoi quand meme dans la variable ! |
|
| 140 | + $ancre = str_replace(array('<', '"', "'"), array('<', '"', ''), $ancre); |
|
| 141 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 142 | + } |
|
| 143 | + } else { |
|
| 144 | + include_spip('inc/headers'); |
|
| 145 | + http_status(403); |
|
| 146 | + $texte = _L('signature ajax bloc incorrecte'); |
|
| 147 | + } |
|
| 148 | + ajax_retour($texte, false); |
|
| 149 | 149 | |
| 150 | - return true; // on a fini le hit |
|
| 151 | - } |
|
| 150 | + return true; // on a fini le hit |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return false; |
|
| 153 | + return false; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // au 1er appel, traite les formulaires dynamiques charger/verifier/traiter |
@@ -159,148 +159,148 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | // http://code.spip.net/@traiter_formulaires_dynamiques |
| 161 | 161 | function traiter_formulaires_dynamiques($get = false) { |
| 162 | - static $post = array(); |
|
| 163 | - static $done = false; |
|
| 162 | + static $post = array(); |
|
| 163 | + static $done = false; |
|
| 164 | 164 | |
| 165 | - if ($get) { |
|
| 166 | - return $post; |
|
| 167 | - } |
|
| 168 | - if ($done) { |
|
| 169 | - return false; |
|
| 170 | - } |
|
| 171 | - $done = true; |
|
| 165 | + if ($get) { |
|
| 166 | + return $post; |
|
| 167 | + } |
|
| 168 | + if ($done) { |
|
| 169 | + return false; |
|
| 170 | + } |
|
| 171 | + $done = true; |
|
| 172 | 172 | |
| 173 | - if (!($form = _request('formulaire_action') |
|
| 174 | - and $args = _request('formulaire_action_args')) |
|
| 175 | - ) { |
|
| 176 | - return false; |
|
| 177 | - } // le hit peut continuer normalement |
|
| 173 | + if (!($form = _request('formulaire_action') |
|
| 174 | + and $args = _request('formulaire_action_args')) |
|
| 175 | + ) { |
|
| 176 | + return false; |
|
| 177 | + } // le hit peut continuer normalement |
|
| 178 | 178 | |
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 181 | - spip_log("signature ajax form incorrecte : $form"); |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (($args = decoder_contexte_ajax($args, $form)) === false) { |
|
| 181 | + spip_log("signature ajax form incorrecte : $form"); |
|
| 182 | 182 | |
| 183 | - return false; // continuons le hit comme si de rien etait |
|
| 184 | - } else { |
|
| 185 | - include_spip('inc/lang'); |
|
| 186 | - // sauvegarder la lang en cours |
|
| 187 | - $old_lang = $GLOBALS['spip_lang']; |
|
| 188 | - // changer la langue avec celle qui a cours dans le formulaire |
|
| 189 | - // on la depile de $args car c'est un argument implicite masque |
|
| 190 | - changer_langue(array_shift($args)); |
|
| 183 | + return false; // continuons le hit comme si de rien etait |
|
| 184 | + } else { |
|
| 185 | + include_spip('inc/lang'); |
|
| 186 | + // sauvegarder la lang en cours |
|
| 187 | + $old_lang = $GLOBALS['spip_lang']; |
|
| 188 | + // changer la langue avec celle qui a cours dans le formulaire |
|
| 189 | + // on la depile de $args car c'est un argument implicite masque |
|
| 190 | + changer_langue(array_shift($args)); |
|
| 191 | 191 | |
| 192 | 192 | |
| 193 | - // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 194 | - include_spip('public/parametrer'); |
|
| 195 | - // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 196 | - include_spip('base/abstract_sql'); |
|
| 193 | + // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 194 | + include_spip('public/parametrer'); |
|
| 195 | + // ainsi que l'API SQL bien utile dans verifier/traiter |
|
| 196 | + include_spip('base/abstract_sql'); |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 200 | - * mais avant l'appel de la fonction de vérification. |
|
| 201 | - */ |
|
| 202 | - pipeline( |
|
| 203 | - 'formulaire_receptionner', |
|
| 204 | - array( |
|
| 205 | - 'args' => array('form' => $form, 'args' => $args), |
|
| 206 | - 'data' => null, |
|
| 207 | - ) |
|
| 208 | - ); |
|
| 198 | + /** |
|
| 199 | + * Pipeline exécuté lors de la soumission d'un formulaire, |
|
| 200 | + * mais avant l'appel de la fonction de vérification. |
|
| 201 | + */ |
|
| 202 | + pipeline( |
|
| 203 | + 'formulaire_receptionner', |
|
| 204 | + array( |
|
| 205 | + 'args' => array('form' => $form, 'args' => $args), |
|
| 206 | + 'data' => null, |
|
| 207 | + ) |
|
| 208 | + ); |
|
| 209 | 209 | |
| 210 | - $verifier = charger_fonction("verifier", "formulaires/$form/", true); |
|
| 211 | - $post["erreurs_$form"] = pipeline( |
|
| 212 | - 'formulaire_verifier', |
|
| 213 | - array( |
|
| 214 | - 'args' => array('form' => $form, 'args' => $args), |
|
| 215 | - 'data' => $verifier ? call_user_func_array($verifier, $args) : array() |
|
| 216 | - ) |
|
| 217 | - ); |
|
| 218 | - // prise en charge CVT multi etape si besoin |
|
| 219 | - if (_request('cvtm_prev_post')) { |
|
| 220 | - include_spip('inc/cvt_multietapes'); |
|
| 221 | - $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 222 | - array('form' => $form, 'args' => $args), |
|
| 223 | - $post["erreurs_$form"] |
|
| 224 | - ); |
|
| 225 | - } |
|
| 210 | + $verifier = charger_fonction("verifier", "formulaires/$form/", true); |
|
| 211 | + $post["erreurs_$form"] = pipeline( |
|
| 212 | + 'formulaire_verifier', |
|
| 213 | + array( |
|
| 214 | + 'args' => array('form' => $form, 'args' => $args), |
|
| 215 | + 'data' => $verifier ? call_user_func_array($verifier, $args) : array() |
|
| 216 | + ) |
|
| 217 | + ); |
|
| 218 | + // prise en charge CVT multi etape si besoin |
|
| 219 | + if (_request('cvtm_prev_post')) { |
|
| 220 | + include_spip('inc/cvt_multietapes'); |
|
| 221 | + $post["erreurs_$form"] = cvtmulti_formulaire_verifier_etapes( |
|
| 222 | + array('form' => $form, 'args' => $args), |
|
| 223 | + $post["erreurs_$form"] |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 228 | - if (count($post["erreurs_$form"]) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 229 | - $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(count($post["erreurs_$form"]), |
|
| 230 | - 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 231 | - } |
|
| 227 | + // accessibilite : si des erreurs mais pas de message general l'ajouter |
|
| 228 | + if (count($post["erreurs_$form"]) and !isset($post["erreurs_$form"]['message_erreur'])) { |
|
| 229 | + $post["erreurs_$form"]['message_erreur'] = singulier_ou_pluriel(count($post["erreurs_$form"]), |
|
| 230 | + 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // si on ne demandait qu'une verif json |
|
| 234 | - if (_request('formulaire_action_verifier_json')) { |
|
| 235 | - include_spip('inc/json'); |
|
| 236 | - include_spip('inc/actions'); |
|
| 237 | - ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain'); |
|
| 233 | + // si on ne demandait qu'une verif json |
|
| 234 | + if (_request('formulaire_action_verifier_json')) { |
|
| 235 | + include_spip('inc/json'); |
|
| 236 | + include_spip('inc/actions'); |
|
| 237 | + ajax_retour(json_encode($post["erreurs_$form"]), 'text/plain'); |
|
| 238 | 238 | |
| 239 | - return true; // on a fini le hit |
|
| 240 | - } |
|
| 241 | - $retour = ""; |
|
| 242 | - if ((count($post["erreurs_$form"]) == 0)) { |
|
| 243 | - $rev = ""; |
|
| 244 | - if ($traiter = charger_fonction("traiter", "formulaires/$form/", true)) { |
|
| 245 | - $rev = call_user_func_array($traiter, $args); |
|
| 246 | - } |
|
| 239 | + return true; // on a fini le hit |
|
| 240 | + } |
|
| 241 | + $retour = ""; |
|
| 242 | + if ((count($post["erreurs_$form"]) == 0)) { |
|
| 243 | + $rev = ""; |
|
| 244 | + if ($traiter = charger_fonction("traiter", "formulaires/$form/", true)) { |
|
| 245 | + $rev = call_user_func_array($traiter, $args); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - $rev = pipeline( |
|
| 249 | - 'formulaire_traiter', |
|
| 250 | - array( |
|
| 251 | - 'args' => array('form' => $form, 'args' => $args), |
|
| 252 | - 'data' => $rev |
|
| 253 | - ) |
|
| 254 | - ); |
|
| 255 | - // le retour de traiter est |
|
| 256 | - // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 257 | - // il permet le pipelinage, en particulier |
|
| 258 | - // en y passant l'id de l'objet cree/modifie |
|
| 259 | - // si message_erreur est present, on considere que le traitement a echoue |
|
| 260 | - $post["message_ok_$form"] = ''; |
|
| 261 | - // on peut avoir message_ok et message_erreur |
|
| 262 | - if (isset($rev['message_ok'])) { |
|
| 263 | - $post["message_ok_$form"] = $rev['message_ok']; |
|
| 264 | - } |
|
| 248 | + $rev = pipeline( |
|
| 249 | + 'formulaire_traiter', |
|
| 250 | + array( |
|
| 251 | + 'args' => array('form' => $form, 'args' => $args), |
|
| 252 | + 'data' => $rev |
|
| 253 | + ) |
|
| 254 | + ); |
|
| 255 | + // le retour de traiter est |
|
| 256 | + // un tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 257 | + // il permet le pipelinage, en particulier |
|
| 258 | + // en y passant l'id de l'objet cree/modifie |
|
| 259 | + // si message_erreur est present, on considere que le traitement a echoue |
|
| 260 | + $post["message_ok_$form"] = ''; |
|
| 261 | + // on peut avoir message_ok et message_erreur |
|
| 262 | + if (isset($rev['message_ok'])) { |
|
| 263 | + $post["message_ok_$form"] = $rev['message_ok']; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - // verifier si traiter n'a pas echoue avec une erreur : |
|
| 267 | - if (isset($rev['message_erreur'])) { |
|
| 268 | - $post["erreurs_$form"]["message_erreur"] = $rev['message_erreur']; |
|
| 269 | - // si il y a une erreur on ne redirige pas |
|
| 270 | - } else { |
|
| 271 | - // sinon faire ce qu'il faut : |
|
| 272 | - if (isset($rev['editable'])) { |
|
| 273 | - $post["editable_$form"] = $rev['editable']; |
|
| 274 | - } |
|
| 275 | - // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 276 | - // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 277 | - if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 278 | - include_spip('inc/headers'); |
|
| 279 | - list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 280 | - $post["message_ok_$form"] .= $message; |
|
| 281 | - $retour .= $masque; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 286 | - if (_request('var_ajax')) { |
|
| 287 | - if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 288 | - include_spip('inc/actions'); |
|
| 289 | - include_spip('public/assembler'); |
|
| 290 | - array_unshift($args, $form); |
|
| 291 | - $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 292 | - // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 293 | - // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 294 | - // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 295 | - $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 296 | - ajax_retour($retour, false); |
|
| 266 | + // verifier si traiter n'a pas echoue avec une erreur : |
|
| 267 | + if (isset($rev['message_erreur'])) { |
|
| 268 | + $post["erreurs_$form"]["message_erreur"] = $rev['message_erreur']; |
|
| 269 | + // si il y a une erreur on ne redirige pas |
|
| 270 | + } else { |
|
| 271 | + // sinon faire ce qu'il faut : |
|
| 272 | + if (isset($rev['editable'])) { |
|
| 273 | + $post["editable_$form"] = $rev['editable']; |
|
| 274 | + } |
|
| 275 | + // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 276 | + // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 277 | + if (isset($rev['redirect']) and $rev['redirect']) { |
|
| 278 | + include_spip('inc/headers'); |
|
| 279 | + list($masque, $message) = redirige_formulaire($rev['redirect'], '', 'ajaxform'); |
|
| 280 | + $post["message_ok_$form"] .= $message; |
|
| 281 | + $retour .= $masque; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 286 | + if (_request('var_ajax')) { |
|
| 287 | + if (find_in_path('formulaire_.php', 'balise/', true)) { |
|
| 288 | + include_spip('inc/actions'); |
|
| 289 | + include_spip('public/assembler'); |
|
| 290 | + array_unshift($args, $form); |
|
| 291 | + $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn', $args), false); |
|
| 292 | + // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 293 | + // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 294 | + // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
|
| 295 | + $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 296 | + ajax_retour($retour, false); |
|
| 297 | 297 | |
| 298 | - return true; // on a fini le hit |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - // restaurer la lang en cours |
|
| 302 | - changer_langue($old_lang); |
|
| 303 | - } |
|
| 298 | + return true; // on a fini le hit |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + // restaurer la lang en cours |
|
| 302 | + changer_langue($old_lang); |
|
| 303 | + } |
|
| 304 | 304 | |
| 305 | - return false; // le hit peut continuer normalement |
|
| 305 | + return false; // le hit peut continuer normalement |
|
| 306 | 306 | } |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function securiser_redirect_action($redirect) { |
| 18 | - if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 18 | + if ((tester_url_absolue($redirect) or preg_match(',^\w+:,', trim($redirect))) |
|
| 19 | 19 | and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
| 20 | 20 | // si l'url est une url du site, on la laisse passer sans rien faire |
| 21 | 21 | // c'est encore le plus simple |
| 22 | - $base = $GLOBALS['meta']['adresse_site'] . "/"; |
|
| 22 | + $base = $GLOBALS['meta']['adresse_site']."/"; |
|
| 23 | 23 | if (strlen($base) and strncmp($redirect, $base, strlen($base)) == 0) { |
| 24 | 24 | return $redirect; |
| 25 | 25 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | if ($ancre = _request('var_ajax_ancre')) { |
| 139 | 139 | // pas n'importe quoi quand meme dans la variable ! |
| 140 | 140 | $ancre = str_replace(array('<', '"', "'"), array('<', '"', ''), $ancre); |
| 141 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>" . $texte; |
|
| 141 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>".$texte; |
|
| 142 | 142 | } |
| 143 | 143 | } else { |
| 144 | 144 | include_spip('inc/headers'); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
| 293 | 293 | // sans cela le formulaire n'est pas actif apres le hit ajax |
| 294 | 294 | // la classe ajax-form-is-ok sert a s'assurer que le retour ajax s'est bien passe |
| 295 | - $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>" . $retour; |
|
| 295 | + $retour = "<br class='bugajaxie ajax-form-is-ok' style='display:none;'/>".$retour; |
|
| 296 | 296 | ajax_retour($retour, false); |
| 297 | 297 | |
| 298 | 298 | return true; // on a fini le hit |
@@ -59,6 +59,10 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | // http://code.spip.net/@argumenter_inclure |
| 62 | +/** |
|
| 63 | + * @param boolean $rejet_filtres |
|
| 64 | + * @param string $id_boucle |
|
| 65 | + */ |
|
| 62 | 66 | function argumenter_inclure( |
| 63 | 67 | $params, |
| 64 | 68 | $rejet_filtres, |
@@ -747,7 +751,7 @@ discard block |
||
| 747 | 751 | * Nom de la commande |
| 748 | 752 | * @param string $val |
| 749 | 753 | * Code PHP décrivant la valeur à affecter |
| 750 | - * @return array |
|
| 754 | + * @return string[] |
|
| 751 | 755 | * |
| 752 | 756 | * - index 0 : Code pour une affectation statique. Si non rempli, la propriété devra |
| 753 | 757 | * être ré-affectée à chaque appel de la boucle. |
@@ -855,6 +859,9 @@ discard block |
||
| 855 | 859 | } |
| 856 | 860 | |
| 857 | 861 | // http://code.spip.net/@calculer_order |
| 862 | +/** |
|
| 863 | + * @param Boucle $boucle |
|
| 864 | + */ |
|
| 858 | 865 | function calculer_order(&$boucle) { |
| 859 | 866 | if (!$order = $boucle->order |
| 860 | 867 | and !$order = $boucle->default_order |
@@ -924,6 +931,9 @@ discard block |
||
| 924 | 931 | define('_REGEXP_CONCAT_NON_VIDE', "/^(.*)[.]\s*'[^']+'\s*$/"); |
| 925 | 932 | |
| 926 | 933 | // http://code.spip.net/@compile_cas |
| 934 | +/** |
|
| 935 | + * @param string $id_boucle |
|
| 936 | + */ |
|
| 927 | 937 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 928 | 938 | |
| 929 | 939 | $codes = array(); |
@@ -1113,6 +1123,9 @@ discard block |
||
| 1113 | 1123 | // de meme si EXP est de la forme (t ? '' : 'C') |
| 1114 | 1124 | |
| 1115 | 1125 | // http://code.spip.net/@compile_retour |
| 1126 | +/** |
|
| 1127 | + * @param string $tab |
|
| 1128 | + */ |
|
| 1116 | 1129 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1117 | 1130 | if ($avant == "''") { |
| 1118 | 1131 | $avant = ''; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -60,91 +60,91 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // http://code.spip.net/@argumenter_inclure |
| 62 | 62 | function argumenter_inclure( |
| 63 | - $params, |
|
| 64 | - $rejet_filtres, |
|
| 65 | - $p, |
|
| 66 | - &$boucles, |
|
| 67 | - $id_boucle, |
|
| 68 | - $echap = true, |
|
| 69 | - $lang = '', |
|
| 70 | - $fond1 = false |
|
| 63 | + $params, |
|
| 64 | + $rejet_filtres, |
|
| 65 | + $p, |
|
| 66 | + &$boucles, |
|
| 67 | + $id_boucle, |
|
| 68 | + $echap = true, |
|
| 69 | + $lang = '', |
|
| 70 | + $fond1 = false |
|
| 71 | 71 | ) { |
| 72 | - $l = array(); |
|
| 73 | - $erreur_p_i_i = ''; |
|
| 74 | - if (!is_array($params)) { |
|
| 75 | - return $l; |
|
| 76 | - } |
|
| 77 | - foreach ($params as $k => $couple) { |
|
| 78 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | - $filtre = array_shift($couple); |
|
| 80 | - if ($filtre) { |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - foreach ($couple as $n => $val) { |
|
| 84 | - $var = $val[0]; |
|
| 85 | - if ($var->type != 'texte') { |
|
| 86 | - if ($n or $k or $fond1) { |
|
| 87 | - $erreur_p_i_i = array( |
|
| 88 | - 'zbug_parametres_inclus_incorrects', |
|
| 89 | - array('param' => $var->nom_champ) |
|
| 90 | - ); |
|
| 91 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | - break; |
|
| 93 | - } else { |
|
| 94 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | - } |
|
| 96 | - } else { |
|
| 97 | - preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | - $m = array_pad($m, 3, null); |
|
| 99 | - $var = $m[1]; |
|
| 100 | - $auto = false;; |
|
| 101 | - if ($m[2]) { |
|
| 102 | - $v = $m[3]; |
|
| 103 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | - $v = $m[1]; |
|
| 105 | - } |
|
| 106 | - $val[0] = new Texte; |
|
| 107 | - $val[0]->texte = $v; |
|
| 108 | - } elseif ($k or $n or $fond1) { |
|
| 109 | - $auto = true; |
|
| 110 | - } else { |
|
| 111 | - $var = 1; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ($var == 'lang') { |
|
| 115 | - $lang = !$auto |
|
| 116 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | - : '$GLOBALS["spip_lang"]'; |
|
| 118 | - } else { |
|
| 119 | - $val = $auto |
|
| 120 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | - if ($var !== 1) { |
|
| 123 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | - . $val . ($echap ? ") . '" : " "); |
|
| 125 | - } else { |
|
| 126 | - $val = $echap ? "'.$val.'" : $val; |
|
| 127 | - } |
|
| 128 | - $l[$var] = $val; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if ($erreur_p_i_i) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | - // sauf si on n'en veut pas |
|
| 139 | - if ($lang === false) { |
|
| 140 | - return $l; |
|
| 141 | - } |
|
| 142 | - if (!$lang) { |
|
| 143 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | - } |
|
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : " "); |
|
| 146 | - |
|
| 147 | - return $l; |
|
| 72 | + $l = array(); |
|
| 73 | + $erreur_p_i_i = ''; |
|
| 74 | + if (!is_array($params)) { |
|
| 75 | + return $l; |
|
| 76 | + } |
|
| 77 | + foreach ($params as $k => $couple) { |
|
| 78 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | + $filtre = array_shift($couple); |
|
| 80 | + if ($filtre) { |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + foreach ($couple as $n => $val) { |
|
| 84 | + $var = $val[0]; |
|
| 85 | + if ($var->type != 'texte') { |
|
| 86 | + if ($n or $k or $fond1) { |
|
| 87 | + $erreur_p_i_i = array( |
|
| 88 | + 'zbug_parametres_inclus_incorrects', |
|
| 89 | + array('param' => $var->nom_champ) |
|
| 90 | + ); |
|
| 91 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | + break; |
|
| 93 | + } else { |
|
| 94 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | + $m = array_pad($m, 3, null); |
|
| 99 | + $var = $m[1]; |
|
| 100 | + $auto = false;; |
|
| 101 | + if ($m[2]) { |
|
| 102 | + $v = $m[3]; |
|
| 103 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | + $v = $m[1]; |
|
| 105 | + } |
|
| 106 | + $val[0] = new Texte; |
|
| 107 | + $val[0]->texte = $v; |
|
| 108 | + } elseif ($k or $n or $fond1) { |
|
| 109 | + $auto = true; |
|
| 110 | + } else { |
|
| 111 | + $var = 1; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ($var == 'lang') { |
|
| 115 | + $lang = !$auto |
|
| 116 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | + : '$GLOBALS["spip_lang"]'; |
|
| 118 | + } else { |
|
| 119 | + $val = $auto |
|
| 120 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | + if ($var !== 1) { |
|
| 123 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | + . $val . ($echap ? ") . '" : " "); |
|
| 125 | + } else { |
|
| 126 | + $val = $echap ? "'.$val.'" : $val; |
|
| 127 | + } |
|
| 128 | + $l[$var] = $val; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if ($erreur_p_i_i) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | + // sauf si on n'en veut pas |
|
| 139 | + if ($lang === false) { |
|
| 140 | + return $l; |
|
| 141 | + } |
|
| 142 | + if (!$lang) { |
|
| 143 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | + } |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : " "); |
|
| 146 | + |
|
| 147 | + return $l; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -168,71 +168,71 @@ discard block |
||
| 168 | 168 | **/ |
| 169 | 169 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 170 | 170 | |
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 175 | - |
|
| 176 | - } else { |
|
| 177 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | - $fichier = $r[1]; |
|
| 180 | - } else { |
|
| 181 | - $fichier = ''; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - if (!$code or $code === '""') { |
|
| 185 | - $erreur_p_i_i = array( |
|
| 186 | - 'zbug_parametres_inclus_incorrects', |
|
| 187 | - array('param' => $code) |
|
| 188 | - ); |
|
| 189 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | - |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | - |
|
| 195 | - if (is_array($_contexte)) { |
|
| 196 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | - unset($_contexte['env']); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // noter les doublons dans l'appel a public.php |
|
| 202 | - if (isset($_contexte['doublons'])) { |
|
| 203 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | - $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | - unset($_contexte['ajax']); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $_contexte = join(",\n\t", $_contexte); |
|
| 212 | - } else { |
|
| 213 | - return false; |
|
| 214 | - } // j'aurais voulu toucher le fond ... |
|
| 215 | - |
|
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | - |
|
| 218 | - if ($env) { |
|
| 219 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | - } else { |
|
| 226 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | - if ($ajax) { |
|
| 228 | - $_options[] = $ajax; |
|
| 229 | - } |
|
| 230 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 175 | + |
|
| 176 | + } else { |
|
| 177 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | + $fichier = $r[1]; |
|
| 180 | + } else { |
|
| 181 | + $fichier = ''; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + if (!$code or $code === '""') { |
|
| 185 | + $erreur_p_i_i = array( |
|
| 186 | + 'zbug_parametres_inclus_incorrects', |
|
| 187 | + array('param' => $code) |
|
| 188 | + ); |
|
| 189 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | + |
|
| 195 | + if (is_array($_contexte)) { |
|
| 196 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | + unset($_contexte['env']); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // noter les doublons dans l'appel a public.php |
|
| 202 | + if (isset($_contexte['doublons'])) { |
|
| 203 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | + $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | + unset($_contexte['ajax']); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $_contexte = join(",\n\t", $_contexte); |
|
| 212 | + } else { |
|
| 213 | + return false; |
|
| 214 | + } // j'aurais voulu toucher le fond ... |
|
| 215 | + |
|
| 216 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | + |
|
| 218 | + if ($env) { |
|
| 219 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | + } else { |
|
| 226 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | + if ($ajax) { |
|
| 228 | + $_options[] = $ajax; |
|
| 229 | + } |
|
| 230 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | + $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")") . ';'; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 251 | 251 | */ |
| 252 | 252 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 253 | - /* |
|
| 253 | + /* |
|
| 254 | 254 | $show['statut'][] = array( |
| 255 | 255 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 256 | 256 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -274,71 +274,71 @@ discard block |
||
| 274 | 274 | champstatut est alors le champ statut sur la tablen |
| 275 | 275 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 276 | 276 | */ |
| 277 | - $id_table = $boucle->id_table; |
|
| 278 | - $show = $boucle->show; |
|
| 279 | - if (isset($show['statut']) and $show['statut']) { |
|
| 280 | - foreach ($show['statut'] as $k => $s) { |
|
| 281 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | - $filtrer = true; |
|
| 283 | - if (isset($s['exception'])) { |
|
| 284 | - foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | - $filtrer = false; |
|
| 287 | - break; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($filtrer) { |
|
| 293 | - if (is_array($s['champ'])) { |
|
| 294 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | - $jointures = array(); |
|
| 296 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | - foreach ($s['champ'] as $j) { |
|
| 300 | - $id = reset($j); |
|
| 301 | - $def = $trouver_table($id); |
|
| 302 | - $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | - } |
|
| 304 | - $jointures[0][0] = $id_table; |
|
| 305 | - if (!array_search($id, $boucle->from)) { |
|
| 306 | - include_spip('public/jointures'); |
|
| 307 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | - } |
|
| 309 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | - $id = array_search($id, $boucle->from); |
|
| 311 | - } else { |
|
| 312 | - $id = $id_table; |
|
| 313 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | - } |
|
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 316 | - |
|
| 317 | - $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | - include_spip('public/quete'); |
|
| 319 | - if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | - and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | - ) { |
|
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | - array_unshift($boucle->where, |
|
| 324 | - $echapper ? |
|
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | - : |
|
| 327 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - array_unshift($boucle->where, |
|
| 331 | - $echapper ? |
|
| 332 | - "\nquete_condition_statut('$mstatut'," |
|
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | - : |
|
| 337 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 277 | + $id_table = $boucle->id_table; |
|
| 278 | + $show = $boucle->show; |
|
| 279 | + if (isset($show['statut']) and $show['statut']) { |
|
| 280 | + foreach ($show['statut'] as $k => $s) { |
|
| 281 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | + $filtrer = true; |
|
| 283 | + if (isset($s['exception'])) { |
|
| 284 | + foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | + $filtrer = false; |
|
| 287 | + break; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($filtrer) { |
|
| 293 | + if (is_array($s['champ'])) { |
|
| 294 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | + $jointures = array(); |
|
| 296 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | + foreach ($s['champ'] as $j) { |
|
| 300 | + $id = reset($j); |
|
| 301 | + $def = $trouver_table($id); |
|
| 302 | + $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | + } |
|
| 304 | + $jointures[0][0] = $id_table; |
|
| 305 | + if (!array_search($id, $boucle->from)) { |
|
| 306 | + include_spip('public/jointures'); |
|
| 307 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | + } |
|
| 309 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | + $id = array_search($id, $boucle->from); |
|
| 311 | + } else { |
|
| 312 | + $id = $id_table; |
|
| 313 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | + } |
|
| 315 | + $mstatut = $id . '.' . $statut; |
|
| 316 | + |
|
| 317 | + $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | + include_spip('public/quete'); |
|
| 319 | + if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | + and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | + ) { |
|
| 322 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | + array_unshift($boucle->where, |
|
| 324 | + $echapper ? |
|
| 325 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | + : |
|
| 327 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + array_unshift($boucle->where, |
|
| 331 | + $echapper ? |
|
| 332 | + "\nquete_condition_statut('$mstatut'," |
|
| 333 | + . _q($s['previsu']) . "," |
|
| 334 | + . _q($s['publie']) . "," |
|
| 335 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | + : |
|
| 337 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -357,23 +357,23 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | function calculer_boucle($id_boucle, &$boucles) { |
| 359 | 359 | |
| 360 | - $boucle = &$boucles[$id_boucle]; |
|
| 361 | - instituer_boucle($boucle); |
|
| 362 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | - |
|
| 364 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | - // mais pas tous, sinon ca pete. |
|
| 366 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | - $trace = ''; |
|
| 368 | - } else { |
|
| 369 | - $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | - $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 360 | + $boucle = &$boucles[$id_boucle]; |
|
| 361 | + instituer_boucle($boucle); |
|
| 362 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | + |
|
| 364 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | + // mais pas tous, sinon ca pete. |
|
| 366 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | + $trace = ''; |
|
| 368 | + } else { |
|
| 369 | + $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | + $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
|
| 371 | 371 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
| 372 | - } |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 375 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 376 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 374 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 375 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 376 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | |
@@ -396,15 +396,15 @@ discard block |
||
| 396 | 396 | * Code PHP compilé de la boucle récursive |
| 397 | 397 | **/ |
| 398 | 398 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 399 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 400 | - |
|
| 401 | - return |
|
| 402 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 403 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 404 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 405 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 406 | - . $trace |
|
| 407 | - . "\n\treturn \$t0;"; |
|
| 399 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 400 | + |
|
| 401 | + return |
|
| 402 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 403 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 404 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 405 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 406 | + . $trace |
|
| 407 | + . "\n\treturn \$t0;"; |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -458,169 +458,169 @@ discard block |
||
| 458 | 458 | **/ |
| 459 | 459 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 460 | 460 | |
| 461 | - $boucle = &$boucles[$id_boucle]; |
|
| 462 | - $return = $boucle->return; |
|
| 463 | - $type_boucle = $boucle->type_requete; |
|
| 464 | - $primary = $boucle->primary; |
|
| 465 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 466 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 467 | - $corps = ''; |
|
| 468 | - |
|
| 469 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 470 | - // et puis faire un [] plutot qu'un "','." |
|
| 471 | - if ($boucle->doublons) { |
|
| 472 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 473 | - index_pile($id_boucle, $primary, $boucles) |
|
| 474 | - . "; // doublons\n"; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - // La boucle doit-elle selectionner la langue ? |
|
| 478 | - // - par defaut, les boucles suivantes le font |
|
| 479 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 480 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 481 | - if (!$constant && $boucle->lang_select != 'non' && |
|
| 482 | - (($boucle->lang_select == 'oui') || |
|
| 483 | - in_array($type_boucle, array( |
|
| 484 | - 'articles', |
|
| 485 | - 'rubriques', |
|
| 486 | - 'hierarchie', |
|
| 487 | - 'breves' |
|
| 488 | - ))) |
|
| 489 | - ) { |
|
| 490 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 491 | - // afin que le corps de boucle affecte la globale directement |
|
| 492 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 493 | - $fin_lang = "lang_select();\n\t"; |
|
| 494 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 495 | - |
|
| 496 | - $corps .= |
|
| 497 | - "\n\t\tlang_select_public(" |
|
| 498 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 499 | - . ", '" . $boucle->lang_select . "'" |
|
| 500 | - . (in_array($type_boucle, array( |
|
| 501 | - 'articles', |
|
| 502 | - 'rubriques', |
|
| 503 | - 'hierarchie', |
|
| 504 | - 'breves' |
|
| 505 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 506 | - . ');'; |
|
| 507 | - } else { |
|
| 508 | - $init_lang = ''; |
|
| 509 | - $fin_lang = ''; |
|
| 510 | - $fin_lang_select_public = ''; |
|
| 511 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 512 | - if (strpos($return, '?php') === false |
|
| 513 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 514 | - ) { |
|
| 515 | - $i = 1; |
|
| 516 | - foreach ($r[1] as $t) { |
|
| 517 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 518 | - $return = str_replace($t, "\$l$i", $return); |
|
| 519 | - $i++; |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - // gestion optimale des separateurs et des boucles constantes |
|
| 525 | - if (count($boucle->separateur)) { |
|
| 526 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - $corps .= |
|
| 530 | - ((!$boucle->separateur) ? |
|
| 531 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 532 | - (($return === "''") ? '' : |
|
| 533 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 534 | - ("\n\t\t\$t1 " . |
|
| 535 | - ((strpos($return, '$t1.') === 0) ? |
|
| 536 | - (".=" . substr($return, 4)) : |
|
| 537 | - ('= ' . $return)) . |
|
| 538 | - ";\n\t\t" . |
|
| 539 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 540 | - |
|
| 541 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 542 | - // souhaite invalider ces elements |
|
| 543 | - if (!$constant and $primary) { |
|
| 544 | - include_spip('inc/invalideur'); |
|
| 545 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // gerer le compteur de boucle |
|
| 549 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 550 | - |
|
| 551 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 552 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 553 | - . $boucle->partie |
|
| 554 | - . $corps; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - // depiler la lang de la boucle si besoin |
|
| 558 | - $corps .= $fin_lang_select_public; |
|
| 559 | - |
|
| 560 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 561 | - |
|
| 562 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 563 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 564 | - if (!$boucle->numrows) { |
|
| 565 | - return "\n\t\$t0 = '';"; |
|
| 566 | - } else { |
|
| 567 | - $corps = ""; |
|
| 568 | - } |
|
| 569 | - } else { |
|
| 570 | - $boucle->numrows = true; |
|
| 571 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 572 | - } |
|
| 573 | - } else { |
|
| 574 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - $count = ''; |
|
| 578 | - if (!$boucle->select) { |
|
| 579 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 580 | - $count = '1'; |
|
| 581 | - } else { |
|
| 582 | - $count = 'count(*)'; |
|
| 583 | - } |
|
| 584 | - $boucles[$id_boucle]->select[] = $count; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - if ($flag_cpt) { |
|
| 588 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 589 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 590 | - } else { |
|
| 591 | - $nums = ''; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 595 | - $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 596 | - . $boucle->mode_partie |
|
| 597 | - . "\n\t"; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - // Ne calculer la requete que maintenant |
|
| 601 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 602 | - |
|
| 603 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 604 | - ? ("\n\t$init = array();") : '') |
|
| 605 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 606 | - |
|
| 607 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 608 | - |
|
| 609 | - $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 610 | - $init, |
|
| 611 | - $boucle->iterateur, |
|
| 612 | - "\$command", |
|
| 613 | - $contexte, |
|
| 614 | - $nums, |
|
| 615 | - $init_lang, |
|
| 616 | - $corps, |
|
| 617 | - $fin_lang, |
|
| 618 | - $trace, |
|
| 619 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 620 | - ); |
|
| 461 | + $boucle = &$boucles[$id_boucle]; |
|
| 462 | + $return = $boucle->return; |
|
| 463 | + $type_boucle = $boucle->type_requete; |
|
| 464 | + $primary = $boucle->primary; |
|
| 465 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 466 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 467 | + $corps = ''; |
|
| 468 | + |
|
| 469 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 470 | + // et puis faire un [] plutot qu'un "','." |
|
| 471 | + if ($boucle->doublons) { |
|
| 472 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 473 | + index_pile($id_boucle, $primary, $boucles) |
|
| 474 | + . "; // doublons\n"; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + // La boucle doit-elle selectionner la langue ? |
|
| 478 | + // - par defaut, les boucles suivantes le font |
|
| 479 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 480 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 481 | + if (!$constant && $boucle->lang_select != 'non' && |
|
| 482 | + (($boucle->lang_select == 'oui') || |
|
| 483 | + in_array($type_boucle, array( |
|
| 484 | + 'articles', |
|
| 485 | + 'rubriques', |
|
| 486 | + 'hierarchie', |
|
| 487 | + 'breves' |
|
| 488 | + ))) |
|
| 489 | + ) { |
|
| 490 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 491 | + // afin que le corps de boucle affecte la globale directement |
|
| 492 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 493 | + $fin_lang = "lang_select();\n\t"; |
|
| 494 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 495 | + |
|
| 496 | + $corps .= |
|
| 497 | + "\n\t\tlang_select_public(" |
|
| 498 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 499 | + . ", '" . $boucle->lang_select . "'" |
|
| 500 | + . (in_array($type_boucle, array( |
|
| 501 | + 'articles', |
|
| 502 | + 'rubriques', |
|
| 503 | + 'hierarchie', |
|
| 504 | + 'breves' |
|
| 505 | + )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 506 | + . ');'; |
|
| 507 | + } else { |
|
| 508 | + $init_lang = ''; |
|
| 509 | + $fin_lang = ''; |
|
| 510 | + $fin_lang_select_public = ''; |
|
| 511 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 512 | + if (strpos($return, '?php') === false |
|
| 513 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 514 | + ) { |
|
| 515 | + $i = 1; |
|
| 516 | + foreach ($r[1] as $t) { |
|
| 517 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 518 | + $return = str_replace($t, "\$l$i", $return); |
|
| 519 | + $i++; |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + // gestion optimale des separateurs et des boucles constantes |
|
| 525 | + if (count($boucle->separateur)) { |
|
| 526 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + $corps .= |
|
| 530 | + ((!$boucle->separateur) ? |
|
| 531 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 532 | + (($return === "''") ? '' : |
|
| 533 | + ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 534 | + ("\n\t\t\$t1 " . |
|
| 535 | + ((strpos($return, '$t1.') === 0) ? |
|
| 536 | + (".=" . substr($return, 4)) : |
|
| 537 | + ('= ' . $return)) . |
|
| 538 | + ";\n\t\t" . |
|
| 539 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 540 | + |
|
| 541 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 542 | + // souhaite invalider ces elements |
|
| 543 | + if (!$constant and $primary) { |
|
| 544 | + include_spip('inc/invalideur'); |
|
| 545 | + $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // gerer le compteur de boucle |
|
| 549 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 550 | + |
|
| 551 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 552 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 553 | + . $boucle->partie |
|
| 554 | + . $corps; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // depiler la lang de la boucle si besoin |
|
| 558 | + $corps .= $fin_lang_select_public; |
|
| 559 | + |
|
| 560 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 561 | + |
|
| 562 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 563 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 564 | + if (!$boucle->numrows) { |
|
| 565 | + return "\n\t\$t0 = '';"; |
|
| 566 | + } else { |
|
| 567 | + $corps = ""; |
|
| 568 | + } |
|
| 569 | + } else { |
|
| 570 | + $boucle->numrows = true; |
|
| 571 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 572 | + } |
|
| 573 | + } else { |
|
| 574 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + $count = ''; |
|
| 578 | + if (!$boucle->select) { |
|
| 579 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 580 | + $count = '1'; |
|
| 581 | + } else { |
|
| 582 | + $count = 'count(*)'; |
|
| 583 | + } |
|
| 584 | + $boucles[$id_boucle]->select[] = $count; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + if ($flag_cpt) { |
|
| 588 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 589 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 590 | + } else { |
|
| 591 | + $nums = ''; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 595 | + $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 596 | + . $boucle->mode_partie |
|
| 597 | + . "\n\t"; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + // Ne calculer la requete que maintenant |
|
| 601 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 602 | + |
|
| 603 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 604 | + ? ("\n\t$init = array();") : '') |
|
| 605 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 606 | + |
|
| 607 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 608 | + |
|
| 609 | + $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 610 | + $init, |
|
| 611 | + $boucle->iterateur, |
|
| 612 | + "\$command", |
|
| 613 | + $contexte, |
|
| 614 | + $nums, |
|
| 615 | + $init_lang, |
|
| 616 | + $corps, |
|
| 617 | + $fin_lang, |
|
| 618 | + $trace, |
|
| 619 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 620 | + ); |
|
| 621 | 621 | |
| 622 | 622 | # var_dump($a);exit; |
| 623 | - return $a; |
|
| 623 | + return $a; |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | |
@@ -636,43 +636,43 @@ discard block |
||
| 636 | 636 | * Code PHP compilé définissant les informations de requête |
| 637 | 637 | **/ |
| 638 | 638 | function calculer_requete_sql($boucle) { |
| 639 | - $init = array(); |
|
| 640 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 641 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 642 | - # En absence de champ c'est un decompte : |
|
| 643 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 644 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 645 | - $init[] = calculer_dec('groupby', |
|
| 646 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 647 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 648 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 649 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 650 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 651 | - $init[] = calculer_dec('limit', |
|
| 652 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 653 | - "'" . $boucle->limit . "'" |
|
| 654 | - : |
|
| 655 | - $boucle->limit)); |
|
| 656 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 657 | - $s = $d = ""; |
|
| 658 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 659 | - // ou recalculée à chaque passage (vide) |
|
| 660 | - foreach ($init as $i) { |
|
| 661 | - if (reset($i)) { |
|
| 662 | - $s .= "\n\t\t" . end($i); |
|
| 663 | - } # statique |
|
| 664 | - else { |
|
| 665 | - $d .= "\n\t" . end($i); |
|
| 666 | - } # dynamique |
|
| 667 | - } |
|
| 668 | - |
|
| 669 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 670 | - . $boucle->in |
|
| 671 | - . $boucle->hash |
|
| 672 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 673 | - . $s |
|
| 674 | - . "\n\t}" |
|
| 675 | - . $d; |
|
| 639 | + $init = array(); |
|
| 640 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 641 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 642 | + # En absence de champ c'est un decompte : |
|
| 643 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 644 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 645 | + $init[] = calculer_dec('groupby', |
|
| 646 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 647 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 648 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 649 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 650 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 651 | + $init[] = calculer_dec('limit', |
|
| 652 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 653 | + "'" . $boucle->limit . "'" |
|
| 654 | + : |
|
| 655 | + $boucle->limit)); |
|
| 656 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 657 | + $s = $d = ""; |
|
| 658 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 659 | + // ou recalculée à chaque passage (vide) |
|
| 660 | + foreach ($init as $i) { |
|
| 661 | + if (reset($i)) { |
|
| 662 | + $s .= "\n\t\t" . end($i); |
|
| 663 | + } # statique |
|
| 664 | + else { |
|
| 665 | + $d .= "\n\t" . end($i); |
|
| 666 | + } # dynamique |
|
| 667 | + } |
|
| 668 | + |
|
| 669 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 670 | + . $boucle->in |
|
| 671 | + . $boucle->hash |
|
| 672 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 673 | + . $s |
|
| 674 | + . "\n\t}" |
|
| 675 | + . $d; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -690,13 +690,13 @@ discard block |
||
| 690 | 690 | * qui peut être utilisé pour la production d'un tableau array() |
| 691 | 691 | **/ |
| 692 | 692 | function memoriser_contexte_compil($p) { |
| 693 | - return join(',', array( |
|
| 694 | - _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 695 | - _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 696 | - _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 697 | - intval($p->ligne), |
|
| 698 | - '$GLOBALS[\'spip_lang\']' |
|
| 699 | - )); |
|
| 693 | + return join(',', array( |
|
| 694 | + _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 695 | + _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 696 | + _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 697 | + intval($p->ligne), |
|
| 698 | + '$GLOBALS[\'spip_lang\']' |
|
| 699 | + )); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -714,19 +714,19 @@ discard block |
||
| 714 | 714 | * Objet Contexte |
| 715 | 715 | **/ |
| 716 | 716 | function reconstruire_contexte_compil($context_compil) { |
| 717 | - if (!is_array($context_compil)) { |
|
| 718 | - return $context_compil; |
|
| 719 | - } |
|
| 720 | - $p = new Contexte; |
|
| 721 | - $p->descr = array( |
|
| 722 | - 'sourcefile' => $context_compil[0], |
|
| 723 | - 'nom' => $context_compil[1] |
|
| 724 | - ); |
|
| 725 | - $p->id_boucle = $context_compil[2]; |
|
| 726 | - $p->ligne = $context_compil[3]; |
|
| 727 | - $p->lang = $context_compil[4]; |
|
| 728 | - |
|
| 729 | - return $p; |
|
| 717 | + if (!is_array($context_compil)) { |
|
| 718 | + return $context_compil; |
|
| 719 | + } |
|
| 720 | + $p = new Contexte; |
|
| 721 | + $p->descr = array( |
|
| 722 | + 'sourcefile' => $context_compil[0], |
|
| 723 | + 'nom' => $context_compil[1] |
|
| 724 | + ); |
|
| 725 | + $p->id_boucle = $context_compil[2]; |
|
| 726 | + $p->ligne = $context_compil[3]; |
|
| 727 | + $p->lang = $context_compil[4]; |
|
| 728 | + |
|
| 729 | + return $p; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -752,12 +752,12 @@ discard block |
||
| 752 | 752 | * - index 1 : Code de l'affectation |
| 753 | 753 | **/ |
| 754 | 754 | function calculer_dec($nom, $val) { |
| 755 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 756 | - // si une variable apparait dans le calcul de la clause |
|
| 757 | - // il faut la re-evaluer a chaque passage |
|
| 758 | - if ( |
|
| 759 | - strpos($val, '$') !== false |
|
| 760 | - /* |
|
| 755 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 756 | + // si une variable apparait dans le calcul de la clause |
|
| 757 | + // il faut la re-evaluer a chaque passage |
|
| 758 | + if ( |
|
| 759 | + strpos($val, '$') !== false |
|
| 760 | + /* |
|
| 761 | 761 | OR strpos($val, 'sql_') !== false |
| 762 | 762 | OR ( |
| 763 | 763 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -765,11 +765,11 @@ discard block |
||
| 765 | 765 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 766 | 766 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 767 | 767 | )*/ |
| 768 | - ) { |
|
| 769 | - $static = ""; |
|
| 770 | - } |
|
| 768 | + ) { |
|
| 769 | + $static = ""; |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 772 | + return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /** |
@@ -789,32 +789,32 @@ discard block |
||
| 789 | 789 | * Expression PHP décrivant un texte ou un tableau |
| 790 | 790 | **/ |
| 791 | 791 | function calculer_dump_array($a) { |
| 792 | - if (!is_array($a)) { |
|
| 793 | - return $a; |
|
| 794 | - } |
|
| 795 | - $res = ""; |
|
| 796 | - if ($a and $a[0] == "'?'") { |
|
| 797 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 798 | - " ? " . calculer_dump_array($a[2]) . |
|
| 799 | - " : " . calculer_dump_array($a[3]) . |
|
| 800 | - ")"); |
|
| 801 | - } else { |
|
| 802 | - foreach ($a as $v) { |
|
| 803 | - $res .= ", " . calculer_dump_array($v); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 807 | - } |
|
| 792 | + if (!is_array($a)) { |
|
| 793 | + return $a; |
|
| 794 | + } |
|
| 795 | + $res = ""; |
|
| 796 | + if ($a and $a[0] == "'?'") { |
|
| 797 | + return ("(" . calculer_dump_array($a[1]) . |
|
| 798 | + " ? " . calculer_dump_array($a[2]) . |
|
| 799 | + " : " . calculer_dump_array($a[3]) . |
|
| 800 | + ")"); |
|
| 801 | + } else { |
|
| 802 | + foreach ($a as $v) { |
|
| 803 | + $res .= ", " . calculer_dump_array($v); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 807 | + } |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | // http://code.spip.net/@calculer_dump_join |
| 811 | 811 | function calculer_dump_join($a) { |
| 812 | - $res = ""; |
|
| 813 | - foreach ($a as $k => $v) { |
|
| 814 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 815 | - } |
|
| 812 | + $res = ""; |
|
| 813 | + foreach ($a as $k => $v) { |
|
| 814 | + $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 815 | + } |
|
| 816 | 816 | |
| 817 | - return 'array(' . substr($res, 2) . ')'; |
|
| 817 | + return 'array(' . substr($res, 2) . ')'; |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
@@ -826,12 +826,12 @@ discard block |
||
| 826 | 826 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 827 | 827 | **/ |
| 828 | 828 | function calculer_from(&$boucle) { |
| 829 | - $res = ""; |
|
| 830 | - foreach ($boucle->from as $k => $v) { |
|
| 831 | - $res .= ",'$k' => '$v'"; |
|
| 832 | - } |
|
| 829 | + $res = ""; |
|
| 830 | + foreach ($boucle->from as $k => $v) { |
|
| 831 | + $res .= ",'$k' => '$v'"; |
|
| 832 | + } |
|
| 833 | 833 | |
| 834 | - return 'array(' . substr($res, 1) . ')'; |
|
| 834 | + return 'array(' . substr($res, 1) . ')'; |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | /** |
@@ -844,30 +844,30 @@ discard block |
||
| 844 | 844 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 845 | 845 | **/ |
| 846 | 846 | function calculer_from_type(&$boucle) { |
| 847 | - $res = ""; |
|
| 848 | - foreach ($boucle->from_type as $k => $v) { |
|
| 849 | - $res .= ",'$k' => '$v'"; |
|
| 850 | - } |
|
| 847 | + $res = ""; |
|
| 848 | + foreach ($boucle->from_type as $k => $v) { |
|
| 849 | + $res .= ",'$k' => '$v'"; |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | - return 'array(' . substr($res, 1) . ')'; |
|
| 852 | + return 'array(' . substr($res, 1) . ')'; |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | // http://code.spip.net/@calculer_order |
| 856 | 856 | function calculer_order(&$boucle) { |
| 857 | - if (!$order = $boucle->order |
|
| 858 | - and !$order = $boucle->default_order |
|
| 859 | - ) { |
|
| 860 | - $order = array(); |
|
| 861 | - } |
|
| 857 | + if (!$order = $boucle->order |
|
| 858 | + and !$order = $boucle->default_order |
|
| 859 | + ) { |
|
| 860 | + $order = array(); |
|
| 861 | + } |
|
| 862 | 862 | |
| 863 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 863 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 864 | 864 | $col = "." . $boucle->modificateur['collate']; |
| 865 | 865 | foreach($order as $k=>$o) |
| 866 | 866 | if (strpos($order[$k],'COLLATE')===false) |
| 867 | 867 | $order[$k].= $col; |
| 868 | 868 | }*/ |
| 869 | 869 | |
| 870 | - return join(', ', $order); |
|
| 870 | + return join(', ', $order); |
|
| 871 | 871 | } |
| 872 | 872 | |
| 873 | 873 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -877,44 +877,44 @@ discard block |
||
| 877 | 877 | |
| 878 | 878 | // http://code.spip.net/@calculer_liste |
| 879 | 879 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 880 | - if (!$tableau) { |
|
| 881 | - return "''"; |
|
| 882 | - } |
|
| 883 | - if (!isset($descr['niv'])) { |
|
| 884 | - $descr['niv'] = 0; |
|
| 885 | - } |
|
| 886 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 887 | - if ($codes === false) { |
|
| 888 | - return false; |
|
| 889 | - } |
|
| 890 | - $n = count($codes); |
|
| 891 | - if (!$n) { |
|
| 892 | - return "''"; |
|
| 893 | - } |
|
| 894 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 895 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 896 | - if ($n == 1) { |
|
| 897 | - return $codes[0]; |
|
| 898 | - } else { |
|
| 899 | - $res = ''; |
|
| 900 | - foreach ($codes as $code) { |
|
| 901 | - if (!preg_match("/^'[^']*'$/", $code) |
|
| 902 | - or substr($res, -1, 1) !== "'" |
|
| 903 | - ) { |
|
| 904 | - $res .= " .\n$tab$code"; |
|
| 905 | - } else { |
|
| 906 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 911 | - } |
|
| 912 | - } else { |
|
| 913 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 914 | - |
|
| 915 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 916 | - $codes) . ")))"; |
|
| 917 | - } |
|
| 880 | + if (!$tableau) { |
|
| 881 | + return "''"; |
|
| 882 | + } |
|
| 883 | + if (!isset($descr['niv'])) { |
|
| 884 | + $descr['niv'] = 0; |
|
| 885 | + } |
|
| 886 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 887 | + if ($codes === false) { |
|
| 888 | + return false; |
|
| 889 | + } |
|
| 890 | + $n = count($codes); |
|
| 891 | + if (!$n) { |
|
| 892 | + return "''"; |
|
| 893 | + } |
|
| 894 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 895 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 896 | + if ($n == 1) { |
|
| 897 | + return $codes[0]; |
|
| 898 | + } else { |
|
| 899 | + $res = ''; |
|
| 900 | + foreach ($codes as $code) { |
|
| 901 | + if (!preg_match("/^'[^']*'$/", $code) |
|
| 902 | + or substr($res, -1, 1) !== "'" |
|
| 903 | + ) { |
|
| 904 | + $res .= " .\n$tab$code"; |
|
| 905 | + } else { |
|
| 906 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 911 | + } |
|
| 912 | + } else { |
|
| 913 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 914 | + |
|
| 915 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 916 | + $codes) . ")))"; |
|
| 917 | + } |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | define('_REGEXP_COND_VIDE_NONVIDE', "/^[(](.*)[?]\s*''\s*:\s*('[^']+')\s*[)]$/"); |
@@ -924,186 +924,186 @@ discard block |
||
| 924 | 924 | // http://code.spip.net/@compile_cas |
| 925 | 925 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 926 | 926 | |
| 927 | - $codes = array(); |
|
| 928 | - // cas de la boucle recursive |
|
| 929 | - if (is_array($id_boucle)) { |
|
| 930 | - $id_boucle = $id_boucle[0]; |
|
| 931 | - } |
|
| 932 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 933 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 934 | - $mode = _request('var_mode_affiche'); |
|
| 935 | - $err_e_c = ''; |
|
| 936 | - // chaque commentaire introduit dans le code doit commencer |
|
| 937 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 938 | - foreach ($tableau as $p) { |
|
| 939 | - |
|
| 940 | - switch ($p->type) { |
|
| 941 | - // texte seul |
|
| 942 | - case 'texte': |
|
| 943 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 944 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 945 | - $avant = ''; |
|
| 946 | - $apres = ''; |
|
| 947 | - $altern = "''"; |
|
| 948 | - break; |
|
| 949 | - |
|
| 950 | - case 'polyglotte': |
|
| 951 | - $code = ""; |
|
| 952 | - foreach ($p->traductions as $k => $v) { |
|
| 953 | - $code .= ",'" . |
|
| 954 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 955 | - "' => '" . |
|
| 956 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 957 | - "'"; |
|
| 958 | - } |
|
| 959 | - $code = "choisir_traduction(array(" . |
|
| 960 | - substr($code, 1) . |
|
| 961 | - "))"; |
|
| 962 | - $commentaire = '&'; |
|
| 963 | - $avant = ''; |
|
| 964 | - $apres = ''; |
|
| 965 | - $altern = "''"; |
|
| 966 | - break; |
|
| 967 | - |
|
| 968 | - // inclure |
|
| 969 | - case 'include': |
|
| 970 | - $p->descr = $descr; |
|
| 971 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 972 | - if ($code === false) { |
|
| 973 | - $err_e_c = true; |
|
| 974 | - $code = "''"; |
|
| 975 | - } else { |
|
| 976 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 977 | - $avant = ''; |
|
| 978 | - $apres = ''; |
|
| 979 | - $altern = "''"; |
|
| 980 | - } |
|
| 981 | - break; |
|
| 982 | - |
|
| 983 | - // boucle |
|
| 984 | - case TYPE_RECURSIF: |
|
| 985 | - $nom = $p->id_boucle; |
|
| 986 | - $newdescr = $descr; |
|
| 987 | - $newdescr['id_mere'] = $nom; |
|
| 988 | - $newdescr['niv']++; |
|
| 989 | - $avant = calculer_liste($p->avant, |
|
| 990 | - $newdescr, $boucles, $id_boucle); |
|
| 991 | - $apres = calculer_liste($p->apres, |
|
| 992 | - $newdescr, $boucles, $id_boucle); |
|
| 993 | - $newdescr['niv']--; |
|
| 994 | - $altern = calculer_liste($p->altern, |
|
| 995 | - $newdescr, $boucles, $id_boucle); |
|
| 996 | - if (($avant === false) or ($apres === false) or ($altern === false)) { |
|
| 997 | - $err_e_c = true; |
|
| 998 | - $code = "''"; |
|
| 999 | - } else { |
|
| 1000 | - $code = 'BOUCLE' . |
|
| 1001 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1002 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1003 | - $commentaire = "?$nom"; |
|
| 1004 | - if (!$boucles[$nom]->milieu |
|
| 1005 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1006 | - ) { |
|
| 1007 | - if ($altern != "''") { |
|
| 1008 | - $code .= "\n. $altern"; |
|
| 1009 | - } |
|
| 1010 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1011 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1012 | - } |
|
| 1013 | - $avant = $apres = $altern = "''"; |
|
| 1014 | - } else { |
|
| 1015 | - if ($altern != "''") { |
|
| 1016 | - $altern = "($altern)"; |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - break; |
|
| 1021 | - |
|
| 1022 | - case 'idiome': |
|
| 1023 | - $l = array(); |
|
| 1024 | - $code = ''; |
|
| 1025 | - foreach ($p->arg as $k => $v) { |
|
| 1026 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1027 | - if ($k) { |
|
| 1028 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1029 | - } else { |
|
| 1030 | - $code = $_v; |
|
| 1031 | - } |
|
| 1032 | - } |
|
| 1033 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1034 | - if ($p->module) { |
|
| 1035 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1036 | - } elseif ($p->nom_champ) { |
|
| 1037 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1038 | - } else { |
|
| 1039 | - $m = ''; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - $code = (!$code ? "'$m'" : |
|
| 1043 | - ($m ? "'$m' . $code" : |
|
| 1044 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1045 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1046 | - $code = "_T($code)"; |
|
| 1047 | - if ($p->param) { |
|
| 1048 | - $p->id_boucle = $id_boucle; |
|
| 1049 | - $p->boucles = &$boucles; |
|
| 1050 | - $code = compose_filtres($p, $code); |
|
| 1051 | - } |
|
| 1052 | - $commentaire = ":"; |
|
| 1053 | - $avant = ''; |
|
| 1054 | - $apres = ''; |
|
| 1055 | - $altern = "''"; |
|
| 1056 | - break; |
|
| 1057 | - |
|
| 1058 | - case 'champ': |
|
| 1059 | - |
|
| 1060 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1061 | - $p->id_boucle = $id_boucle; |
|
| 1062 | - $p->boucles = &$boucles; |
|
| 1063 | - $p->descr = $descr; |
|
| 1064 | - #$p->interdire_scripts = true; |
|
| 1065 | - $p->type_requete = $type; |
|
| 1066 | - |
|
| 1067 | - $code = calculer_champ($p); |
|
| 1068 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1069 | - $avant = calculer_liste($p->avant, |
|
| 1070 | - $descr, $boucles, $id_boucle); |
|
| 1071 | - $apres = calculer_liste($p->apres, |
|
| 1072 | - $descr, $boucles, $id_boucle); |
|
| 1073 | - $altern = "''"; |
|
| 1074 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1075 | - // forcer la conversion en une chaine par strval |
|
| 1076 | - // si ca peut etre autre chose qu'une chaine |
|
| 1077 | - if (($avant != "''" or $apres != "''") |
|
| 1078 | - and $code[0] != "'" |
|
| 927 | + $codes = array(); |
|
| 928 | + // cas de la boucle recursive |
|
| 929 | + if (is_array($id_boucle)) { |
|
| 930 | + $id_boucle = $id_boucle[0]; |
|
| 931 | + } |
|
| 932 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 933 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 934 | + $mode = _request('var_mode_affiche'); |
|
| 935 | + $err_e_c = ''; |
|
| 936 | + // chaque commentaire introduit dans le code doit commencer |
|
| 937 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 938 | + foreach ($tableau as $p) { |
|
| 939 | + |
|
| 940 | + switch ($p->type) { |
|
| 941 | + // texte seul |
|
| 942 | + case 'texte': |
|
| 943 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 944 | + $commentaire = strlen($p->texte) . " signes"; |
|
| 945 | + $avant = ''; |
|
| 946 | + $apres = ''; |
|
| 947 | + $altern = "''"; |
|
| 948 | + break; |
|
| 949 | + |
|
| 950 | + case 'polyglotte': |
|
| 951 | + $code = ""; |
|
| 952 | + foreach ($p->traductions as $k => $v) { |
|
| 953 | + $code .= ",'" . |
|
| 954 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 955 | + "' => '" . |
|
| 956 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 957 | + "'"; |
|
| 958 | + } |
|
| 959 | + $code = "choisir_traduction(array(" . |
|
| 960 | + substr($code, 1) . |
|
| 961 | + "))"; |
|
| 962 | + $commentaire = '&'; |
|
| 963 | + $avant = ''; |
|
| 964 | + $apres = ''; |
|
| 965 | + $altern = "''"; |
|
| 966 | + break; |
|
| 967 | + |
|
| 968 | + // inclure |
|
| 969 | + case 'include': |
|
| 970 | + $p->descr = $descr; |
|
| 971 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 972 | + if ($code === false) { |
|
| 973 | + $err_e_c = true; |
|
| 974 | + $code = "''"; |
|
| 975 | + } else { |
|
| 976 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 977 | + $avant = ''; |
|
| 978 | + $apres = ''; |
|
| 979 | + $altern = "''"; |
|
| 980 | + } |
|
| 981 | + break; |
|
| 982 | + |
|
| 983 | + // boucle |
|
| 984 | + case TYPE_RECURSIF: |
|
| 985 | + $nom = $p->id_boucle; |
|
| 986 | + $newdescr = $descr; |
|
| 987 | + $newdescr['id_mere'] = $nom; |
|
| 988 | + $newdescr['niv']++; |
|
| 989 | + $avant = calculer_liste($p->avant, |
|
| 990 | + $newdescr, $boucles, $id_boucle); |
|
| 991 | + $apres = calculer_liste($p->apres, |
|
| 992 | + $newdescr, $boucles, $id_boucle); |
|
| 993 | + $newdescr['niv']--; |
|
| 994 | + $altern = calculer_liste($p->altern, |
|
| 995 | + $newdescr, $boucles, $id_boucle); |
|
| 996 | + if (($avant === false) or ($apres === false) or ($altern === false)) { |
|
| 997 | + $err_e_c = true; |
|
| 998 | + $code = "''"; |
|
| 999 | + } else { |
|
| 1000 | + $code = 'BOUCLE' . |
|
| 1001 | + str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1002 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1003 | + $commentaire = "?$nom"; |
|
| 1004 | + if (!$boucles[$nom]->milieu |
|
| 1005 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1006 | + ) { |
|
| 1007 | + if ($altern != "''") { |
|
| 1008 | + $code .= "\n. $altern"; |
|
| 1009 | + } |
|
| 1010 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1011 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1012 | + } |
|
| 1013 | + $avant = $apres = $altern = "''"; |
|
| 1014 | + } else { |
|
| 1015 | + if ($altern != "''") { |
|
| 1016 | + $altern = "($altern)"; |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + break; |
|
| 1021 | + |
|
| 1022 | + case 'idiome': |
|
| 1023 | + $l = array(); |
|
| 1024 | + $code = ''; |
|
| 1025 | + foreach ($p->arg as $k => $v) { |
|
| 1026 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1027 | + if ($k) { |
|
| 1028 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1029 | + } else { |
|
| 1030 | + $code = $_v; |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 1033 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1034 | + if ($p->module) { |
|
| 1035 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1036 | + } elseif ($p->nom_champ) { |
|
| 1037 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1038 | + } else { |
|
| 1039 | + $m = ''; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + $code = (!$code ? "'$m'" : |
|
| 1043 | + ($m ? "'$m' . $code" : |
|
| 1044 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1045 | + . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1046 | + $code = "_T($code)"; |
|
| 1047 | + if ($p->param) { |
|
| 1048 | + $p->id_boucle = $id_boucle; |
|
| 1049 | + $p->boucles = &$boucles; |
|
| 1050 | + $code = compose_filtres($p, $code); |
|
| 1051 | + } |
|
| 1052 | + $commentaire = ":"; |
|
| 1053 | + $avant = ''; |
|
| 1054 | + $apres = ''; |
|
| 1055 | + $altern = "''"; |
|
| 1056 | + break; |
|
| 1057 | + |
|
| 1058 | + case 'champ': |
|
| 1059 | + |
|
| 1060 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1061 | + $p->id_boucle = $id_boucle; |
|
| 1062 | + $p->boucles = &$boucles; |
|
| 1063 | + $p->descr = $descr; |
|
| 1064 | + #$p->interdire_scripts = true; |
|
| 1065 | + $p->type_requete = $type; |
|
| 1066 | + |
|
| 1067 | + $code = calculer_champ($p); |
|
| 1068 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1069 | + $avant = calculer_liste($p->avant, |
|
| 1070 | + $descr, $boucles, $id_boucle); |
|
| 1071 | + $apres = calculer_liste($p->apres, |
|
| 1072 | + $descr, $boucles, $id_boucle); |
|
| 1073 | + $altern = "''"; |
|
| 1074 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1075 | + // forcer la conversion en une chaine par strval |
|
| 1076 | + // si ca peut etre autre chose qu'une chaine |
|
| 1077 | + if (($avant != "''" or $apres != "''") |
|
| 1078 | + and $code[0] != "'" |
|
| 1079 | 1079 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1080 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1081 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1082 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1083 | - ) { |
|
| 1084 | - $code = "strval($code)"; |
|
| 1085 | - } |
|
| 1086 | - break; |
|
| 1087 | - |
|
| 1088 | - default: |
|
| 1089 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1090 | - $code = "''"; |
|
| 1091 | - $p->descr = $descr; |
|
| 1092 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1093 | - erreur_squelette($err_e_c, $p); |
|
| 1094 | - } // switch |
|
| 1095 | - |
|
| 1096 | - if ($code != "''") { |
|
| 1097 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1098 | - $codes[] = (($mode == 'validation') ? |
|
| 1099 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1100 | - : (($mode == 'code') ? |
|
| 1101 | - "\n// $commentaire\n$code" : |
|
| 1102 | - $code)); |
|
| 1103 | - } |
|
| 1104 | - } // foreach |
|
| 1105 | - |
|
| 1106 | - return $err_e_c ? false : $codes; |
|
| 1080 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1081 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1082 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1083 | + ) { |
|
| 1084 | + $code = "strval($code)"; |
|
| 1085 | + } |
|
| 1086 | + break; |
|
| 1087 | + |
|
| 1088 | + default: |
|
| 1089 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1090 | + $code = "''"; |
|
| 1091 | + $p->descr = $descr; |
|
| 1092 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1093 | + erreur_squelette($err_e_c, $p); |
|
| 1094 | + } // switch |
|
| 1095 | + |
|
| 1096 | + if ($code != "''") { |
|
| 1097 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1098 | + $codes[] = (($mode == 'validation') ? |
|
| 1099 | + "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1100 | + : (($mode == 'code') ? |
|
| 1101 | + "\n// $commentaire\n$code" : |
|
| 1102 | + $code)); |
|
| 1103 | + } |
|
| 1104 | + } // foreach |
|
| 1105 | + |
|
| 1106 | + return $err_e_c ? false : $codes; |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | // production d'une expression conditionnelle ((v=EXP) ? (p . v .s) : a) |
@@ -1112,56 +1112,56 @@ discard block |
||
| 1112 | 1112 | |
| 1113 | 1113 | // http://code.spip.net/@compile_retour |
| 1114 | 1114 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1115 | - if ($avant == "''") { |
|
| 1116 | - $avant = ''; |
|
| 1117 | - } |
|
| 1118 | - if ($apres == "''") { |
|
| 1119 | - $apres = ''; |
|
| 1120 | - } |
|
| 1121 | - if (!$avant and !$apres and ($altern === "''")) { |
|
| 1122 | - return $code; |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1126 | - $t = $code; |
|
| 1127 | - $cond = ''; |
|
| 1128 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1129 | - $t = $r[2]; |
|
| 1130 | - $cond = '!' . $r[1]; |
|
| 1131 | - } else { |
|
| 1132 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1133 | - $t = $r[2]; |
|
| 1134 | - $cond = $r[1]; |
|
| 1135 | - } else { |
|
| 1136 | - $t = '$t' . $n; |
|
| 1137 | - $cond = "($t = $code)!==''"; |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1142 | - $t . |
|
| 1143 | - (!$apres ? "" : " . $apres"); |
|
| 1144 | - |
|
| 1145 | - if ($res !== $t) { |
|
| 1146 | - $res = "($res)"; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 1115 | + if ($avant == "''") { |
|
| 1116 | + $avant = ''; |
|
| 1117 | + } |
|
| 1118 | + if ($apres == "''") { |
|
| 1119 | + $apres = ''; |
|
| 1120 | + } |
|
| 1121 | + if (!$avant and !$apres and ($altern === "''")) { |
|
| 1122 | + return $code; |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1126 | + $t = $code; |
|
| 1127 | + $cond = ''; |
|
| 1128 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1129 | + $t = $r[2]; |
|
| 1130 | + $cond = '!' . $r[1]; |
|
| 1131 | + } else { |
|
| 1132 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1133 | + $t = $r[2]; |
|
| 1134 | + $cond = $r[1]; |
|
| 1135 | + } else { |
|
| 1136 | + $t = '$t' . $n; |
|
| 1137 | + $cond = "($t = $code)!==''"; |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + $res = (!$avant ? "" : "$avant . ") . |
|
| 1142 | + $t . |
|
| 1143 | + (!$apres ? "" : " . $apres"); |
|
| 1144 | + |
|
| 1145 | + if ($res !== $t) { |
|
| 1146 | + $res = "($res)"; |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + return !$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | |
| 1153 | 1153 | function compile_inclure_doublons($lexemes) { |
| 1154 | - foreach ($lexemes as $v) { |
|
| 1155 | - if ($v->type === 'include' and $v->param) { |
|
| 1156 | - foreach ($v->param as $r) { |
|
| 1157 | - if (trim($r[0]) === 'doublons') { |
|
| 1158 | - return true; |
|
| 1159 | - } |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - return false; |
|
| 1154 | + foreach ($lexemes as $v) { |
|
| 1155 | + if ($v->type === 'include' and $v->param) { |
|
| 1156 | + foreach ($v->param as $r) { |
|
| 1157 | + if (trim($r[0]) === 'doublons') { |
|
| 1158 | + return true; |
|
| 1159 | + } |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + return false; |
|
| 1165 | 1165 | } |
| 1166 | 1166 | |
| 1167 | 1167 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1181,346 +1181,346 @@ discard block |
||
| 1181 | 1181 | |
| 1182 | 1182 | // http://code.spip.net/@public_compiler_dist |
| 1183 | 1183 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect = '') { |
| 1184 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1185 | - // Bonus : supprime le BOM |
|
| 1186 | - include_spip('inc/charsets'); |
|
| 1187 | - $squelette = transcoder_page($squelette); |
|
| 1188 | - |
|
| 1189 | - // rendre inertes les echappements de #[](){}<> |
|
| 1190 | - $i = 0; |
|
| 1191 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1192 | - $i++; |
|
| 1193 | - } |
|
| 1194 | - $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1195 | - function($a) use ($inerte) { |
|
| 1196 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1197 | - }, |
|
| 1198 | - $squelette, |
|
| 1199 | - -1, |
|
| 1200 | - $esc |
|
| 1201 | - ); |
|
| 1202 | - |
|
| 1203 | - $descr = array( |
|
| 1204 | - 'nom' => $nom, |
|
| 1205 | - 'gram' => $gram, |
|
| 1206 | - 'sourcefile' => $sourcefile, |
|
| 1207 | - 'squelette' => $squelette |
|
| 1208 | - ); |
|
| 1209 | - |
|
| 1210 | - // Phraser le squelette, selon sa grammaire |
|
| 1211 | - |
|
| 1212 | - $boucles = array(); |
|
| 1213 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1214 | - |
|
| 1215 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1216 | - |
|
| 1217 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1218 | - |
|
| 1219 | - // restituer les echappements |
|
| 1220 | - if ($esc) { |
|
| 1221 | - foreach ($boucles as $i => $boucle) { |
|
| 1222 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1223 | - ",$inerte-(\d+)-,", |
|
| 1224 | - function($a) { |
|
| 1225 | - return chr($a[1]); |
|
| 1226 | - }, |
|
| 1227 | - $boucle->return |
|
| 1228 | - ); |
|
| 1229 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1230 | - ",$inerte-(\d+)-,", |
|
| 1231 | - function($a) { |
|
| 1232 | - return "\\\\" . chr($a[1]); |
|
| 1233 | - }, |
|
| 1234 | - $boucle->descr['squelette'] |
|
| 1235 | - ); |
|
| 1236 | - } |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1240 | - if ($debug) { |
|
| 1241 | - include_spip('public/decompiler'); |
|
| 1242 | - foreach ($boucles as $id => $boucle) { |
|
| 1243 | - if ($id) { |
|
| 1244 | - $decomp = "\n/* BOUCLE " . |
|
| 1245 | - $boucle->type_requete . |
|
| 1246 | - " " . |
|
| 1247 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1248 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1249 | - " */\n"; |
|
| 1250 | - } else { |
|
| 1251 | - $decomp = ("\n/*\n" . |
|
| 1252 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1253 | - . "\n*/"); |
|
| 1254 | - } |
|
| 1255 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1256 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - |
|
| 1260 | - return $boucles; |
|
| 1184 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1185 | + // Bonus : supprime le BOM |
|
| 1186 | + include_spip('inc/charsets'); |
|
| 1187 | + $squelette = transcoder_page($squelette); |
|
| 1188 | + |
|
| 1189 | + // rendre inertes les echappements de #[](){}<> |
|
| 1190 | + $i = 0; |
|
| 1191 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1192 | + $i++; |
|
| 1193 | + } |
|
| 1194 | + $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1195 | + function($a) use ($inerte) { |
|
| 1196 | + return "$inerte-" . ord($a[1]) . '-'; |
|
| 1197 | + }, |
|
| 1198 | + $squelette, |
|
| 1199 | + -1, |
|
| 1200 | + $esc |
|
| 1201 | + ); |
|
| 1202 | + |
|
| 1203 | + $descr = array( |
|
| 1204 | + 'nom' => $nom, |
|
| 1205 | + 'gram' => $gram, |
|
| 1206 | + 'sourcefile' => $sourcefile, |
|
| 1207 | + 'squelette' => $squelette |
|
| 1208 | + ); |
|
| 1209 | + |
|
| 1210 | + // Phraser le squelette, selon sa grammaire |
|
| 1211 | + |
|
| 1212 | + $boucles = array(); |
|
| 1213 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1214 | + |
|
| 1215 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1216 | + |
|
| 1217 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1218 | + |
|
| 1219 | + // restituer les echappements |
|
| 1220 | + if ($esc) { |
|
| 1221 | + foreach ($boucles as $i => $boucle) { |
|
| 1222 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1223 | + ",$inerte-(\d+)-,", |
|
| 1224 | + function($a) { |
|
| 1225 | + return chr($a[1]); |
|
| 1226 | + }, |
|
| 1227 | + $boucle->return |
|
| 1228 | + ); |
|
| 1229 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1230 | + ",$inerte-(\d+)-,", |
|
| 1231 | + function($a) { |
|
| 1232 | + return "\\\\" . chr($a[1]); |
|
| 1233 | + }, |
|
| 1234 | + $boucle->descr['squelette'] |
|
| 1235 | + ); |
|
| 1236 | + } |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1240 | + if ($debug) { |
|
| 1241 | + include_spip('public/decompiler'); |
|
| 1242 | + foreach ($boucles as $id => $boucle) { |
|
| 1243 | + if ($id) { |
|
| 1244 | + $decomp = "\n/* BOUCLE " . |
|
| 1245 | + $boucle->type_requete . |
|
| 1246 | + " " . |
|
| 1247 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1248 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1249 | + " */\n"; |
|
| 1250 | + } else { |
|
| 1251 | + $decomp = ("\n/*\n" . |
|
| 1252 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1253 | + . "\n*/"); |
|
| 1254 | + } |
|
| 1255 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1256 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + |
|
| 1260 | + return $boucles; |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | 1263 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1264 | 1264 | // Autres specifications comme ci-dessus |
| 1265 | 1265 | |
| 1266 | 1266 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect = '') { |
| 1267 | - static $trouver_table; |
|
| 1268 | - spip_timer('calcul_skel'); |
|
| 1269 | - |
|
| 1270 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1271 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1272 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1273 | - |
|
| 1274 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1275 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - foreach ($boucles as $id => $boucle) { |
|
| 1279 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1280 | - } |
|
| 1281 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1282 | - |
|
| 1283 | - // Demander la description des tables une fois pour toutes |
|
| 1284 | - if (!$trouver_table) { |
|
| 1285 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - // reperer si les doublons sont demandes |
|
| 1289 | - // pour un inclure ou une boucle document |
|
| 1290 | - // c'est utile a la fonction champs_traitements |
|
| 1291 | - foreach ($boucles as $id => $boucle) { |
|
| 1292 | - if (!($type = $boucle->type_requete)) { |
|
| 1293 | - continue; |
|
| 1294 | - } |
|
| 1295 | - if (!$descr['documents'] and ( |
|
| 1296 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1297 | - compile_inclure_doublons($boucle->avant) or |
|
| 1298 | - compile_inclure_doublons($boucle->apres) or |
|
| 1299 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1300 | - compile_inclure_doublons($boucle->altern)) |
|
| 1301 | - ) { |
|
| 1302 | - $descr['documents'] = true; |
|
| 1303 | - } |
|
| 1304 | - if ($type != TYPE_RECURSIF) { |
|
| 1305 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1306 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1310 | - if ($g = charger_fonction( |
|
| 1311 | - preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1312 | - ) { |
|
| 1313 | - $boucles[$id] = $g($boucle); |
|
| 1314 | - |
|
| 1315 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1316 | - // utiliser les informations donnees par le requeteur |
|
| 1317 | - // cas "php:xx" et "data:xx". |
|
| 1318 | - } else { |
|
| 1319 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1320 | - $requeteur($boucles, $boucle, $id); |
|
| 1321 | - |
|
| 1322 | - // utiliser la description des champs transmis |
|
| 1323 | - } else { |
|
| 1324 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1325 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1326 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1327 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1328 | - if (!$show |
|
| 1329 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1330 | - ) { |
|
| 1331 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1332 | - } |
|
| 1333 | - if ($show) { |
|
| 1334 | - $boucles[$id]->show = $show; |
|
| 1335 | - // recopie les infos les plus importantes |
|
| 1336 | - $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1337 | - $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1338 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1339 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1340 | - |
|
| 1341 | - $boucles[$id]->descr = &$descr; |
|
| 1342 | - if ((!$boucles[$id]->jointures) |
|
| 1343 | - and is_array($show['tables_jointures']) |
|
| 1344 | - and count($x = $show['tables_jointures']) |
|
| 1345 | - ) { |
|
| 1346 | - $boucles[$id]->jointures = $x; |
|
| 1347 | - } |
|
| 1348 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1349 | - $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1350 | - while ($j = array_pop($jointures)) { |
|
| 1351 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1352 | - } |
|
| 1353 | - } |
|
| 1354 | - } else { |
|
| 1355 | - // Pas une erreur si la table est optionnelle |
|
| 1356 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1357 | - $boucles[$id]->type_requete = ''; |
|
| 1358 | - } else { |
|
| 1359 | - $boucles[$id]->type_requete = false; |
|
| 1360 | - $boucle = $boucles[$id]; |
|
| 1361 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1362 | - ($boucle->sql_serveur . ":")) . |
|
| 1363 | - $type; |
|
| 1364 | - $msg = array( |
|
| 1365 | - 'zbug_table_inconnue', |
|
| 1366 | - array('table' => $x) |
|
| 1367 | - ); |
|
| 1368 | - erreur_squelette($msg, $boucle); |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - } |
|
| 1375 | - |
|
| 1376 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1377 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1378 | - foreach ($boucles as $id => $boucle) { |
|
| 1379 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1380 | - $boucles[$id]->descr = &$descr; |
|
| 1381 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1382 | - if (!$rec) { |
|
| 1383 | - $msg = array( |
|
| 1384 | - 'zbug_boucle_recursive_undef', |
|
| 1385 | - array('nom' => $boucle->param[0]) |
|
| 1386 | - ); |
|
| 1387 | - erreur_squelette($msg, $boucle); |
|
| 1388 | - $boucles[$id]->type_requete = false; |
|
| 1389 | - } else { |
|
| 1390 | - $rec->externe = $id; |
|
| 1391 | - $descr['id_mere'] = $id; |
|
| 1392 | - $boucles[$id]->return = |
|
| 1393 | - calculer_liste(array($rec), |
|
| 1394 | - $descr, |
|
| 1395 | - $boucles, |
|
| 1396 | - $boucle->param); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1400 | - foreach ($boucles as $id => $boucle) { |
|
| 1401 | - $id = strval($id); // attention au type dans index_pile |
|
| 1402 | - $type = $boucle->type_requete; |
|
| 1403 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1404 | - $res = ''; |
|
| 1405 | - if ($boucle->param) { |
|
| 1406 | - // retourne un tableau en cas d'erreur |
|
| 1407 | - $res = calculer_criteres($id, $boucles); |
|
| 1408 | - } |
|
| 1409 | - $descr['id_mere'] = $id; |
|
| 1410 | - $boucles[$id]->return = |
|
| 1411 | - calculer_liste($boucle->milieu, |
|
| 1412 | - $descr, |
|
| 1413 | - $boucles, |
|
| 1414 | - $id); |
|
| 1415 | - // Si les criteres se sont mal compiles |
|
| 1416 | - // ne pas tenter d'assembler le code final |
|
| 1417 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1418 | - if (is_array($res)) { |
|
| 1419 | - $boucles[$id]->type_requete = false; |
|
| 1420 | - } |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - |
|
| 1424 | - // idem pour la racine |
|
| 1425 | - $descr['id_mere'] = ''; |
|
| 1426 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1427 | - |
|
| 1428 | - |
|
| 1429 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1430 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1431 | - // de'terminables seulement maintenant |
|
| 1432 | - |
|
| 1433 | - foreach ($boucles as $id => $boucle) { |
|
| 1434 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1435 | - if ($boucle->return === false) { |
|
| 1436 | - $corps = false; |
|
| 1437 | - continue; |
|
| 1438 | - } |
|
| 1439 | - // appeler la fonction de definition de la boucle |
|
| 1440 | - |
|
| 1441 | - if ($req = $boucle->type_requete) { |
|
| 1442 | - // boucle personnalisée ? |
|
| 1443 | - $table = strtoupper($boucle->type_requete); |
|
| 1444 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1445 | - if ( |
|
| 1446 | - // fonction de boucle avec serveur & table |
|
| 1447 | - (!$serveur or |
|
| 1448 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1449 | - and (!function_exists($f = $f . "_dist")) |
|
| 1450 | - ) |
|
| 1451 | - ) |
|
| 1452 | - // fonction de boucle avec table |
|
| 1453 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1454 | - and (!function_exists($f = $f . "_dist")) |
|
| 1455 | - ) { |
|
| 1456 | - // fonction de boucle standard |
|
| 1457 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1458 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1459 | - } |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1463 | - "static \$connect;\n\t" . |
|
| 1464 | - "\$command['connect'] = \$connect = " . |
|
| 1465 | - _q($boucle->sql_serveur) . |
|
| 1466 | - ";" . |
|
| 1467 | - $f($id, $boucles); |
|
| 1468 | - } else { |
|
| 1469 | - $req = ("\n\treturn '';"); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - $boucles[$id]->return = |
|
| 1473 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1474 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1475 | - $req . |
|
| 1476 | - "\n}\n"; |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1480 | - // retourner False, sinon inserer leur decompilation |
|
| 1481 | - if (is_bool($corps)) { |
|
| 1482 | - return false; |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1267 | + static $trouver_table; |
|
| 1268 | + spip_timer('calcul_skel'); |
|
| 1269 | + |
|
| 1270 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1271 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1272 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1273 | + |
|
| 1274 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1275 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + foreach ($boucles as $id => $boucle) { |
|
| 1279 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1280 | + } |
|
| 1281 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1282 | + |
|
| 1283 | + // Demander la description des tables une fois pour toutes |
|
| 1284 | + if (!$trouver_table) { |
|
| 1285 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + // reperer si les doublons sont demandes |
|
| 1289 | + // pour un inclure ou une boucle document |
|
| 1290 | + // c'est utile a la fonction champs_traitements |
|
| 1291 | + foreach ($boucles as $id => $boucle) { |
|
| 1292 | + if (!($type = $boucle->type_requete)) { |
|
| 1293 | + continue; |
|
| 1294 | + } |
|
| 1295 | + if (!$descr['documents'] and ( |
|
| 1296 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1297 | + compile_inclure_doublons($boucle->avant) or |
|
| 1298 | + compile_inclure_doublons($boucle->apres) or |
|
| 1299 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1300 | + compile_inclure_doublons($boucle->altern)) |
|
| 1301 | + ) { |
|
| 1302 | + $descr['documents'] = true; |
|
| 1303 | + } |
|
| 1304 | + if ($type != TYPE_RECURSIF) { |
|
| 1305 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1306 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1310 | + if ($g = charger_fonction( |
|
| 1311 | + preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1312 | + ) { |
|
| 1313 | + $boucles[$id] = $g($boucle); |
|
| 1314 | + |
|
| 1315 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1316 | + // utiliser les informations donnees par le requeteur |
|
| 1317 | + // cas "php:xx" et "data:xx". |
|
| 1318 | + } else { |
|
| 1319 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1320 | + $requeteur($boucles, $boucle, $id); |
|
| 1321 | + |
|
| 1322 | + // utiliser la description des champs transmis |
|
| 1323 | + } else { |
|
| 1324 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1325 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1326 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1327 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1328 | + if (!$show |
|
| 1329 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1330 | + ) { |
|
| 1331 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1332 | + } |
|
| 1333 | + if ($show) { |
|
| 1334 | + $boucles[$id]->show = $show; |
|
| 1335 | + // recopie les infos les plus importantes |
|
| 1336 | + $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1337 | + $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1338 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1339 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1340 | + |
|
| 1341 | + $boucles[$id]->descr = &$descr; |
|
| 1342 | + if ((!$boucles[$id]->jointures) |
|
| 1343 | + and is_array($show['tables_jointures']) |
|
| 1344 | + and count($x = $show['tables_jointures']) |
|
| 1345 | + ) { |
|
| 1346 | + $boucles[$id]->jointures = $x; |
|
| 1347 | + } |
|
| 1348 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1349 | + $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1350 | + while ($j = array_pop($jointures)) { |
|
| 1351 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1352 | + } |
|
| 1353 | + } |
|
| 1354 | + } else { |
|
| 1355 | + // Pas une erreur si la table est optionnelle |
|
| 1356 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1357 | + $boucles[$id]->type_requete = ''; |
|
| 1358 | + } else { |
|
| 1359 | + $boucles[$id]->type_requete = false; |
|
| 1360 | + $boucle = $boucles[$id]; |
|
| 1361 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1362 | + ($boucle->sql_serveur . ":")) . |
|
| 1363 | + $type; |
|
| 1364 | + $msg = array( |
|
| 1365 | + 'zbug_table_inconnue', |
|
| 1366 | + array('table' => $x) |
|
| 1367 | + ); |
|
| 1368 | + erreur_squelette($msg, $boucle); |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + |
|
| 1376 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1377 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1378 | + foreach ($boucles as $id => $boucle) { |
|
| 1379 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1380 | + $boucles[$id]->descr = &$descr; |
|
| 1381 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1382 | + if (!$rec) { |
|
| 1383 | + $msg = array( |
|
| 1384 | + 'zbug_boucle_recursive_undef', |
|
| 1385 | + array('nom' => $boucle->param[0]) |
|
| 1386 | + ); |
|
| 1387 | + erreur_squelette($msg, $boucle); |
|
| 1388 | + $boucles[$id]->type_requete = false; |
|
| 1389 | + } else { |
|
| 1390 | + $rec->externe = $id; |
|
| 1391 | + $descr['id_mere'] = $id; |
|
| 1392 | + $boucles[$id]->return = |
|
| 1393 | + calculer_liste(array($rec), |
|
| 1394 | + $descr, |
|
| 1395 | + $boucles, |
|
| 1396 | + $boucle->param); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | + foreach ($boucles as $id => $boucle) { |
|
| 1401 | + $id = strval($id); // attention au type dans index_pile |
|
| 1402 | + $type = $boucle->type_requete; |
|
| 1403 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1404 | + $res = ''; |
|
| 1405 | + if ($boucle->param) { |
|
| 1406 | + // retourne un tableau en cas d'erreur |
|
| 1407 | + $res = calculer_criteres($id, $boucles); |
|
| 1408 | + } |
|
| 1409 | + $descr['id_mere'] = $id; |
|
| 1410 | + $boucles[$id]->return = |
|
| 1411 | + calculer_liste($boucle->milieu, |
|
| 1412 | + $descr, |
|
| 1413 | + $boucles, |
|
| 1414 | + $id); |
|
| 1415 | + // Si les criteres se sont mal compiles |
|
| 1416 | + // ne pas tenter d'assembler le code final |
|
| 1417 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1418 | + if (is_array($res)) { |
|
| 1419 | + $boucles[$id]->type_requete = false; |
|
| 1420 | + } |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + |
|
| 1424 | + // idem pour la racine |
|
| 1425 | + $descr['id_mere'] = ''; |
|
| 1426 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1427 | + |
|
| 1428 | + |
|
| 1429 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1430 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1431 | + // de'terminables seulement maintenant |
|
| 1432 | + |
|
| 1433 | + foreach ($boucles as $id => $boucle) { |
|
| 1434 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1435 | + if ($boucle->return === false) { |
|
| 1436 | + $corps = false; |
|
| 1437 | + continue; |
|
| 1438 | + } |
|
| 1439 | + // appeler la fonction de definition de la boucle |
|
| 1440 | + |
|
| 1441 | + if ($req = $boucle->type_requete) { |
|
| 1442 | + // boucle personnalisée ? |
|
| 1443 | + $table = strtoupper($boucle->type_requete); |
|
| 1444 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1445 | + if ( |
|
| 1446 | + // fonction de boucle avec serveur & table |
|
| 1447 | + (!$serveur or |
|
| 1448 | + ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1449 | + and (!function_exists($f = $f . "_dist")) |
|
| 1450 | + ) |
|
| 1451 | + ) |
|
| 1452 | + // fonction de boucle avec table |
|
| 1453 | + and (!function_exists($f = "boucle_" . $table)) |
|
| 1454 | + and (!function_exists($f = $f . "_dist")) |
|
| 1455 | + ) { |
|
| 1456 | + // fonction de boucle standard |
|
| 1457 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1458 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1459 | + } |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1463 | + "static \$connect;\n\t" . |
|
| 1464 | + "\$command['connect'] = \$connect = " . |
|
| 1465 | + _q($boucle->sql_serveur) . |
|
| 1466 | + ";" . |
|
| 1467 | + $f($id, $boucles); |
|
| 1468 | + } else { |
|
| 1469 | + $req = ("\n\treturn '';"); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + $boucles[$id]->return = |
|
| 1473 | + "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1474 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1475 | + $req . |
|
| 1476 | + "\n}\n"; |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1480 | + // retourner False, sinon inserer leur decompilation |
|
| 1481 | + if (is_bool($corps)) { |
|
| 1482 | + return false; |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1486 | 1486 | ' |
| 1487 | - // reporter de maniere securisee les doublons inclus |
|
| 1488 | - . ' |
|
| 1487 | + // reporter de maniere securisee les doublons inclus |
|
| 1488 | + . ' |
|
| 1489 | 1489 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1490 | 1490 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1491 | 1491 | |
| 1492 | 1492 | $connect = ' . |
| 1493 | - _q($connect) . '; |
|
| 1493 | + _q($connect) . '; |
|
| 1494 | 1494 | $page = ' . |
| 1495 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1496 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1497 | - // avant de referencer $Cache |
|
| 1498 | - $corps . "; |
|
| 1495 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1496 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1497 | + // avant de referencer $Cache |
|
| 1498 | + $corps . "; |
|
| 1499 | 1499 | |
| 1500 | 1500 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1501 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1501 | + . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1502 | 1502 | }"; |
| 1503 | 1503 | |
| 1504 | - $secondes = spip_timer('calcul_skel'); |
|
| 1505 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1506 | - // $connect n'est pas sûr : on nettoie |
|
| 1507 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1504 | + $secondes = spip_timer('calcul_skel'); |
|
| 1505 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1506 | + // $connect n'est pas sûr : on nettoie |
|
| 1507 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1508 | 1508 | |
| 1509 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1510 | - $code = new Boucle; |
|
| 1511 | - $code->descr = $descr; |
|
| 1512 | - $code->return = ' |
|
| 1509 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1510 | + $code = new Boucle; |
|
| 1511 | + $code->descr = $descr; |
|
| 1512 | + $code->return = ' |
|
| 1513 | 1513 | // |
| 1514 | 1514 | // Fonction principale du squelette ' . |
| 1515 | - $sourcefile . |
|
| 1516 | - ($connect ? " pour $connect" : '') . |
|
| 1517 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1518 | - "\n//\n" . |
|
| 1519 | - $principal; |
|
| 1515 | + $sourcefile . |
|
| 1516 | + ($connect ? " pour $connect" : '') . |
|
| 1517 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1518 | + "\n//\n" . |
|
| 1519 | + $principal; |
|
| 1520 | 1520 | |
| 1521 | - $boucles[''] = $code; |
|
| 1521 | + $boucles[''] = $code; |
|
| 1522 | 1522 | |
| 1523 | - return $boucles; |
|
| 1523 | + return $boucles; |
|
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | 1526 | |
@@ -1537,18 +1537,18 @@ discard block |
||
| 1537 | 1537 | * |
| 1538 | 1538 | **/ |
| 1539 | 1539 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1540 | - if (class_exists($boucle->type_requete)) { |
|
| 1541 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1542 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1543 | - } else { |
|
| 1544 | - $x = $boucle->type_requete; |
|
| 1545 | - $boucle->type_requete = false; |
|
| 1546 | - $msg = array( |
|
| 1547 | - 'zbug_iterateur_inconnu', |
|
| 1548 | - array('iterateur' => $x) |
|
| 1549 | - ); |
|
| 1550 | - erreur_squelette($msg, $boucle); |
|
| 1551 | - } |
|
| 1540 | + if (class_exists($boucle->type_requete)) { |
|
| 1541 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1542 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1543 | + } else { |
|
| 1544 | + $x = $boucle->type_requete; |
|
| 1545 | + $boucle->type_requete = false; |
|
| 1546 | + $msg = array( |
|
| 1547 | + 'zbug_iterateur_inconnu', |
|
| 1548 | + array('iterateur' => $x) |
|
| 1549 | + ); |
|
| 1550 | + erreur_squelette($msg, $boucle); |
|
| 1551 | + } |
|
| 1552 | 1552 | } |
| 1553 | 1553 | |
| 1554 | 1554 | |
@@ -1566,23 +1566,23 @@ discard block |
||
| 1566 | 1566 | * |
| 1567 | 1567 | **/ |
| 1568 | 1568 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1569 | - include_spip('iterateur/data'); |
|
| 1570 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1571 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1572 | - $boucles[$id] = $g($boucle); |
|
| 1573 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1574 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1575 | - |
|
| 1576 | - } else { |
|
| 1577 | - $x = $boucle->type_requete; |
|
| 1578 | - $boucle->type_requete = false; |
|
| 1579 | - $msg = array( |
|
| 1580 | - 'zbug_requeteur_inconnu', |
|
| 1581 | - array( |
|
| 1582 | - 'requeteur' => 'data', |
|
| 1583 | - 'type' => $x |
|
| 1584 | - ) |
|
| 1585 | - ); |
|
| 1586 | - erreur_squelette($msg, $boucle); |
|
| 1587 | - } |
|
| 1569 | + include_spip('iterateur/data'); |
|
| 1570 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1571 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1572 | + $boucles[$id] = $g($boucle); |
|
| 1573 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1574 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1575 | + |
|
| 1576 | + } else { |
|
| 1577 | + $x = $boucle->type_requete; |
|
| 1578 | + $boucle->type_requete = false; |
|
| 1579 | + $msg = array( |
|
| 1580 | + 'zbug_requeteur_inconnu', |
|
| 1581 | + array( |
|
| 1582 | + 'requeteur' => 'data', |
|
| 1583 | + 'type' => $x |
|
| 1584 | + ) |
|
| 1585 | + ); |
|
| 1586 | + erreur_squelette($msg, $boucle); |
|
| 1587 | + } |
|
| 1588 | 1588 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
| 98 | 98 | $m = array_pad($m, 3, null); |
| 99 | 99 | $var = $m[1]; |
| 100 | - $auto = false;; |
|
| 100 | + $auto = false; ; |
|
| 101 | 101 | if ($m[2]) { |
| 102 | 102 | $v = $m[3]; |
| 103 | 103 | if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 122 | 122 | if ($var !== 1) { |
| 123 | 123 | $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
| 124 | - . $val . ($echap ? ") . '" : " "); |
|
| 124 | + . $val.($echap ? ") . '" : " "); |
|
| 125 | 125 | } else { |
| 126 | 126 | $val = $echap ? "'.$val.'" : $val; |
| 127 | 127 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (!$lang) { |
| 143 | 143 | $lang = '$GLOBALS["spip_lang"]'; |
| 144 | 144 | } |
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : " "); |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ").$lang.($echap ? ") . '" : " "); |
|
| 146 | 146 | |
| 147 | 147 | return $l; |
| 148 | 148 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
| 172 | 172 | if (is_string($p->texte)) { |
| 173 | 173 | $fichier = $p->texte; |
| 174 | - $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 174 | + $code = "\"".str_replace('"', '\"', $fichier)."\""; |
|
| 175 | 175 | |
| 176 | 176 | } else { |
| 177 | 177 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | return false; |
| 214 | 214 | } // j'aurais voulu toucher le fond ... |
| 215 | 215 | |
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 216 | + $contexte = 'array('.$_contexte.')'; |
|
| 217 | 217 | |
| 218 | 218 | if ($env) { |
| 219 | 219 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | $_options[] = $ajax; |
| 229 | 229 | } |
| 230 | 230 | $code = " ' . argumenter_squelette($code) . '"; |
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 231 | + $code = "echo ".sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")").';'; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 235 | + return "\n'<'.'"."?php ".$code."\n?'."."'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -312,17 +312,17 @@ discard block |
||
| 312 | 312 | $id = $id_table; |
| 313 | 313 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 314 | 314 | } |
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 315 | + $mstatut = $id.'.'.$statut; |
|
| 316 | 316 | |
| 317 | 317 | $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
| 318 | 318 | include_spip('public/quete'); |
| 319 | 319 | if (isset($s['post_date']) and $s['post_date'] |
| 320 | 320 | and $GLOBALS['meta']["post_dates"] == 'non' |
| 321 | 321 | ) { |
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 322 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | 323 | array_unshift($boucle->where, |
| 324 | 324 | $echapper ? |
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 325 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 326 | 326 | : |
| 327 | 327 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 328 | 328 | ); |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | array_unshift($boucle->where, |
| 331 | 331 | $echapper ? |
| 332 | 332 | "\nquete_condition_statut('$mstatut'," |
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 333 | + . _q($s['previsu'])."," |
|
| 334 | + . _q($s['publie'])."," |
|
| 335 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 336 | 336 | : |
| 337 | 337 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 338 | 338 | ); |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | if (_request('var_mode_affiche') != 'resultat') { |
| 367 | 367 | $trace = ''; |
| 368 | 368 | } else { |
| 369 | - $trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 369 | + $trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 370 | 370 | $trace = "if (count(@\$GLOBALS['debug_objets']['resultat']['$trace'])<3) |
| 371 | 371 | \$GLOBALS['debug_objets']['resultat']['$trace'][] = \$t0;"; |
| 372 | 372 | } |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | return |
| 402 | 402 | // Numrows[$nom] peut ne pas être encore defini |
| 403 | 403 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 404 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 404 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.";" |
|
| 405 | 405 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 406 | 406 | . $trace |
| 407 | 407 | . "\n\treturn \$t0;"; |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 470 | 470 | // et puis faire un [] plutot qu'un "','." |
| 471 | 471 | if ($boucle->doublons) { |
| 472 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 472 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 473 | 473 | index_pile($id_boucle, $primary, $boucles) |
| 474 | 474 | . "; // doublons\n"; |
| 475 | 475 | } |
@@ -496,13 +496,13 @@ discard block |
||
| 496 | 496 | $corps .= |
| 497 | 497 | "\n\t\tlang_select_public(" |
| 498 | 498 | . index_pile($id_boucle, 'lang', $boucles) |
| 499 | - . ", '" . $boucle->lang_select . "'" |
|
| 499 | + . ", '".$boucle->lang_select."'" |
|
| 500 | 500 | . (in_array($type_boucle, array( |
| 501 | 501 | 'articles', |
| 502 | 502 | 'rubriques', |
| 503 | 503 | 'hierarchie', |
| 504 | 504 | 'breves' |
| 505 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 505 | + )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 506 | 506 | . ');'; |
| 507 | 507 | } else { |
| 508 | 508 | $init_lang = ''; |
@@ -523,26 +523,22 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | // gestion optimale des separateurs et des boucles constantes |
| 525 | 525 | if (count($boucle->separateur)) { |
| 526 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 526 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | $corps .= |
| 530 | 530 | ((!$boucle->separateur) ? |
| 531 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 532 | - (($return === "''") ? '' : |
|
| 533 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 534 | - ("\n\t\t\$t1 " . |
|
| 531 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.";"))) : ("\n\t\t\$t1 ". |
|
| 535 | 532 | ((strpos($return, '$t1.') === 0) ? |
| 536 | - (".=" . substr($return, 4)) : |
|
| 537 | - ('= ' . $return)) . |
|
| 538 | - ";\n\t\t" . |
|
| 539 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 533 | + (".=".substr($return, 4)) : ('= '.$return)). |
|
| 534 | + ";\n\t\t". |
|
| 535 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 540 | 536 | |
| 541 | 537 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 542 | 538 | // souhaite invalider ces elements |
| 543 | 539 | if (!$constant and $primary) { |
| 544 | 540 | include_spip('inc/invalideur'); |
| 545 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 541 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 546 | 542 | } |
| 547 | 543 | |
| 548 | 544 | // gerer le compteur de boucle |
@@ -616,7 +612,7 @@ discard block |
||
| 616 | 612 | $corps, |
| 617 | 613 | $fin_lang, |
| 618 | 614 | $trace, |
| 619 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 615 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 620 | 616 | ); |
| 621 | 617 | |
| 622 | 618 | # var_dump($a);exit; |
@@ -637,20 +633,20 @@ discard block |
||
| 637 | 633 | **/ |
| 638 | 634 | function calculer_requete_sql($boucle) { |
| 639 | 635 | $init = array(); |
| 640 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 641 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 636 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 637 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 642 | 638 | # En absence de champ c'est un decompte : |
| 643 | 639 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 644 | 640 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 645 | 641 | $init[] = calculer_dec('groupby', |
| 646 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 647 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 648 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 642 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').")"); |
|
| 643 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select)."\")"); |
|
| 644 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).")"); |
|
| 649 | 645 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 650 | 646 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 651 | 647 | $init[] = calculer_dec('limit', |
| 652 | 648 | (strpos($boucle->limit, 'intval') === false ? |
| 653 | - "'" . $boucle->limit . "'" |
|
| 649 | + "'".$boucle->limit."'" |
|
| 654 | 650 | : |
| 655 | 651 | $boucle->limit)); |
| 656 | 652 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
@@ -659,17 +655,17 @@ discard block |
||
| 659 | 655 | // ou recalculée à chaque passage (vide) |
| 660 | 656 | foreach ($init as $i) { |
| 661 | 657 | if (reset($i)) { |
| 662 | - $s .= "\n\t\t" . end($i); |
|
| 658 | + $s .= "\n\t\t".end($i); |
|
| 663 | 659 | } # statique |
| 664 | 660 | else { |
| 665 | - $d .= "\n\t" . end($i); |
|
| 661 | + $d .= "\n\t".end($i); |
|
| 666 | 662 | } # dynamique |
| 667 | 663 | } |
| 668 | 664 | |
| 669 | 665 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 670 | 666 | . $boucle->in |
| 671 | 667 | . $boucle->hash |
| 672 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 668 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 673 | 669 | . $s |
| 674 | 670 | . "\n\t}" |
| 675 | 671 | . $d; |
@@ -752,7 +748,7 @@ discard block |
||
| 752 | 748 | * - index 1 : Code de l'affectation |
| 753 | 749 | **/ |
| 754 | 750 | function calculer_dec($nom, $val) { |
| 755 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 751 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 756 | 752 | // si une variable apparait dans le calcul de la clause |
| 757 | 753 | // il faut la re-evaluer a chaque passage |
| 758 | 754 | if ( |
@@ -769,7 +765,7 @@ discard block |
||
| 769 | 765 | $static = ""; |
| 770 | 766 | } |
| 771 | 767 | |
| 772 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 768 | + return array($static, '$command[\''.$nom.'\'] = '.$val.';'); |
|
| 773 | 769 | } |
| 774 | 770 | |
| 775 | 771 | /** |
@@ -794,16 +790,16 @@ discard block |
||
| 794 | 790 | } |
| 795 | 791 | $res = ""; |
| 796 | 792 | if ($a and $a[0] == "'?'") { |
| 797 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 798 | - " ? " . calculer_dump_array($a[2]) . |
|
| 799 | - " : " . calculer_dump_array($a[3]) . |
|
| 793 | + return ("(".calculer_dump_array($a[1]). |
|
| 794 | + " ? ".calculer_dump_array($a[2]). |
|
| 795 | + " : ".calculer_dump_array($a[3]). |
|
| 800 | 796 | ")"); |
| 801 | 797 | } else { |
| 802 | 798 | foreach ($a as $v) { |
| 803 | - $res .= ", " . calculer_dump_array($v); |
|
| 799 | + $res .= ", ".calculer_dump_array($v); |
|
| 804 | 800 | } |
| 805 | 801 | |
| 806 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 802 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 807 | 803 | } |
| 808 | 804 | } |
| 809 | 805 | |
@@ -811,10 +807,10 @@ discard block |
||
| 811 | 807 | function calculer_dump_join($a) { |
| 812 | 808 | $res = ""; |
| 813 | 809 | foreach ($a as $k => $v) { |
| 814 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 810 | + $res .= ", '$k' => array(".implode(',', $v).")"; |
|
| 815 | 811 | } |
| 816 | 812 | |
| 817 | - return 'array(' . substr($res, 2) . ')'; |
|
| 813 | + return 'array('.substr($res, 2).')'; |
|
| 818 | 814 | } |
| 819 | 815 | |
| 820 | 816 | /** |
@@ -831,7 +827,7 @@ discard block |
||
| 831 | 827 | $res .= ",'$k' => '$v'"; |
| 832 | 828 | } |
| 833 | 829 | |
| 834 | - return 'array(' . substr($res, 1) . ')'; |
|
| 830 | + return 'array('.substr($res, 1).')'; |
|
| 835 | 831 | } |
| 836 | 832 | |
| 837 | 833 | /** |
@@ -849,7 +845,7 @@ discard block |
||
| 849 | 845 | $res .= ",'$k' => '$v'"; |
| 850 | 846 | } |
| 851 | 847 | |
| 852 | - return 'array(' . substr($res, 1) . ')'; |
|
| 848 | + return 'array('.substr($res, 1).')'; |
|
| 853 | 849 | } |
| 854 | 850 | |
| 855 | 851 | // http://code.spip.net/@calculer_order |
@@ -903,17 +899,17 @@ discard block |
||
| 903 | 899 | ) { |
| 904 | 900 | $res .= " .\n$tab$code"; |
| 905 | 901 | } else { |
| 906 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 902 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 907 | 903 | } |
| 908 | 904 | } |
| 909 | 905 | |
| 910 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 906 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 911 | 907 | } |
| 912 | 908 | } else { |
| 913 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 909 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 914 | 910 | |
| 915 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 916 | - $codes) . ")))"; |
|
| 911 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join(" ,\n$tab", |
|
| 912 | + $codes).")))"; |
|
| 917 | 913 | } |
| 918 | 914 | } |
| 919 | 915 | |
@@ -941,7 +937,7 @@ discard block |
||
| 941 | 937 | // texte seul |
| 942 | 938 | case 'texte': |
| 943 | 939 | $code = sandbox_composer_texte($p->texte, $p); |
| 944 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 940 | + $commentaire = strlen($p->texte)." signes"; |
|
| 945 | 941 | $avant = ''; |
| 946 | 942 | $apres = ''; |
| 947 | 943 | $altern = "''"; |
@@ -950,14 +946,14 @@ discard block |
||
| 950 | 946 | case 'polyglotte': |
| 951 | 947 | $code = ""; |
| 952 | 948 | foreach ($p->traductions as $k => $v) { |
| 953 | - $code .= ",'" . |
|
| 954 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 955 | - "' => '" . |
|
| 956 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 949 | + $code .= ",'". |
|
| 950 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k). |
|
| 951 | + "' => '". |
|
| 952 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v). |
|
| 957 | 953 | "'"; |
| 958 | 954 | } |
| 959 | - $code = "choisir_traduction(array(" . |
|
| 960 | - substr($code, 1) . |
|
| 955 | + $code = "choisir_traduction(array(". |
|
| 956 | + substr($code, 1). |
|
| 961 | 957 | "))"; |
| 962 | 958 | $commentaire = '&'; |
| 963 | 959 | $avant = ''; |
@@ -973,7 +969,7 @@ discard block |
||
| 973 | 969 | $err_e_c = true; |
| 974 | 970 | $code = "''"; |
| 975 | 971 | } else { |
| 976 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 972 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 977 | 973 | $avant = ''; |
| 978 | 974 | $apres = ''; |
| 979 | 975 | $altern = "''"; |
@@ -997,8 +993,8 @@ discard block |
||
| 997 | 993 | $err_e_c = true; |
| 998 | 994 | $code = "''"; |
| 999 | 995 | } else { |
| 1000 | - $code = 'BOUCLE' . |
|
| 1001 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 996 | + $code = 'BOUCLE'. |
|
| 997 | + str_replace("-", "_", $nom).$descr['nom']. |
|
| 1002 | 998 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1003 | 999 | $commentaire = "?$nom"; |
| 1004 | 1000 | if (!$boucles[$nom]->milieu |
@@ -1025,24 +1021,22 @@ discard block |
||
| 1025 | 1021 | foreach ($p->arg as $k => $v) { |
| 1026 | 1022 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1027 | 1023 | if ($k) { |
| 1028 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1024 | + $l[] = _q($k).' => '.$_v; |
|
| 1029 | 1025 | } else { |
| 1030 | 1026 | $code = $_v; |
| 1031 | 1027 | } |
| 1032 | 1028 | } |
| 1033 | 1029 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1034 | 1030 | if ($p->module) { |
| 1035 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1031 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1036 | 1032 | } elseif ($p->nom_champ) { |
| 1037 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1033 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1038 | 1034 | } else { |
| 1039 | 1035 | $m = ''; |
| 1040 | 1036 | } |
| 1041 | 1037 | |
| 1042 | - $code = (!$code ? "'$m'" : |
|
| 1043 | - ($m ? "'$m' . $code" : |
|
| 1044 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1045 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1038 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1039 | + . (!$l ? '' : (", array(".implode(",\n", $l).")")); |
|
| 1046 | 1040 | $code = "_T($code)"; |
| 1047 | 1041 | if ($p->param) { |
| 1048 | 1042 | $p->id_boucle = $id_boucle; |
@@ -1065,7 +1059,7 @@ discard block |
||
| 1065 | 1059 | $p->type_requete = $type; |
| 1066 | 1060 | |
| 1067 | 1061 | $code = calculer_champ($p); |
| 1068 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1062 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1069 | 1063 | $avant = calculer_liste($p->avant, |
| 1070 | 1064 | $descr, $boucles, $id_boucle); |
| 1071 | 1065 | $apres = calculer_liste($p->apres, |
@@ -1096,10 +1090,9 @@ discard block |
||
| 1096 | 1090 | if ($code != "''") { |
| 1097 | 1091 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1098 | 1092 | $codes[] = (($mode == 'validation') ? |
| 1099 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1093 | + "array($code, '$commentaire', ".$p->ligne.")" |
|
| 1100 | 1094 | : (($mode == 'code') ? |
| 1101 | - "\n// $commentaire\n$code" : |
|
| 1102 | - $code)); |
|
| 1095 | + "\n// $commentaire\n$code" : $code)); |
|
| 1103 | 1096 | } |
| 1104 | 1097 | } // foreach |
| 1105 | 1098 | |
@@ -1127,19 +1120,19 @@ discard block |
||
| 1127 | 1120 | $cond = ''; |
| 1128 | 1121 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1129 | 1122 | $t = $r[2]; |
| 1130 | - $cond = '!' . $r[1]; |
|
| 1123 | + $cond = '!'.$r[1]; |
|
| 1131 | 1124 | } else { |
| 1132 | 1125 | if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
| 1133 | 1126 | $t = $r[2]; |
| 1134 | 1127 | $cond = $r[1]; |
| 1135 | 1128 | } else { |
| 1136 | - $t = '$t' . $n; |
|
| 1129 | + $t = '$t'.$n; |
|
| 1137 | 1130 | $cond = "($t = $code)!==''"; |
| 1138 | 1131 | } |
| 1139 | 1132 | } |
| 1140 | 1133 | |
| 1141 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1142 | - $t . |
|
| 1134 | + $res = (!$avant ? "" : "$avant . "). |
|
| 1135 | + $t. |
|
| 1143 | 1136 | (!$apres ? "" : " . $apres"); |
| 1144 | 1137 | |
| 1145 | 1138 | if ($res !== $t) { |
@@ -1188,12 +1181,12 @@ discard block |
||
| 1188 | 1181 | |
| 1189 | 1182 | // rendre inertes les echappements de #[](){}<> |
| 1190 | 1183 | $i = 0; |
| 1191 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1184 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1192 | 1185 | $i++; |
| 1193 | 1186 | } |
| 1194 | 1187 | $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
| 1195 | 1188 | function($a) use ($inerte) { |
| 1196 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1189 | + return "$inerte-".ord($a[1]).'-'; |
|
| 1197 | 1190 | }, |
| 1198 | 1191 | $squelette, |
| 1199 | 1192 | -1, |
@@ -1210,7 +1203,7 @@ discard block |
||
| 1210 | 1203 | // Phraser le squelette, selon sa grammaire |
| 1211 | 1204 | |
| 1212 | 1205 | $boucles = array(); |
| 1213 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1206 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1214 | 1207 | |
| 1215 | 1208 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1216 | 1209 | |
@@ -1229,7 +1222,7 @@ discard block |
||
| 1229 | 1222 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1230 | 1223 | ",$inerte-(\d+)-,", |
| 1231 | 1224 | function($a) { |
| 1232 | - return "\\\\" . chr($a[1]); |
|
| 1225 | + return "\\\\".chr($a[1]); |
|
| 1233 | 1226 | }, |
| 1234 | 1227 | $boucle->descr['squelette'] |
| 1235 | 1228 | ); |
@@ -1241,19 +1234,19 @@ discard block |
||
| 1241 | 1234 | include_spip('public/decompiler'); |
| 1242 | 1235 | foreach ($boucles as $id => $boucle) { |
| 1243 | 1236 | if ($id) { |
| 1244 | - $decomp = "\n/* BOUCLE " . |
|
| 1245 | - $boucle->type_requete . |
|
| 1246 | - " " . |
|
| 1247 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1248 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1237 | + $decomp = "\n/* BOUCLE ". |
|
| 1238 | + $boucle->type_requete. |
|
| 1239 | + " ". |
|
| 1240 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1241 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1249 | 1242 | " */\n"; |
| 1250 | 1243 | } else { |
| 1251 | - $decomp = ("\n/*\n" . |
|
| 1244 | + $decomp = ("\n/*\n". |
|
| 1252 | 1245 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1253 | 1246 | . "\n*/"); |
| 1254 | 1247 | } |
| 1255 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1256 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1248 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1249 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1257 | 1250 | } |
| 1258 | 1251 | } |
| 1259 | 1252 | |
@@ -1276,7 +1269,7 @@ discard block |
||
| 1276 | 1269 | } |
| 1277 | 1270 | } |
| 1278 | 1271 | foreach ($boucles as $id => $boucle) { |
| 1279 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1272 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1280 | 1273 | } |
| 1281 | 1274 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1282 | 1275 | |
@@ -1358,8 +1351,7 @@ discard block |
||
| 1358 | 1351 | } else { |
| 1359 | 1352 | $boucles[$id]->type_requete = false; |
| 1360 | 1353 | $boucle = $boucles[$id]; |
| 1361 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1362 | - ($boucle->sql_serveur . ":")) . |
|
| 1354 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.":")). |
|
| 1363 | 1355 | $type; |
| 1364 | 1356 | $msg = array( |
| 1365 | 1357 | 'zbug_table_inconnue', |
@@ -1445,13 +1437,13 @@ discard block |
||
| 1445 | 1437 | if ( |
| 1446 | 1438 | // fonction de boucle avec serveur & table |
| 1447 | 1439 | (!$serveur or |
| 1448 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1449 | - and (!function_exists($f = $f . "_dist")) |
|
| 1440 | + ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1441 | + and (!function_exists($f = $f."_dist")) |
|
| 1450 | 1442 | ) |
| 1451 | 1443 | ) |
| 1452 | 1444 | // fonction de boucle avec table |
| 1453 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1454 | - and (!function_exists($f = $f . "_dist")) |
|
| 1445 | + and (!function_exists($f = "boucle_".$table)) |
|
| 1446 | + and (!function_exists($f = $f."_dist")) |
|
| 1455 | 1447 | ) { |
| 1456 | 1448 | // fonction de boucle standard |
| 1457 | 1449 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1459,20 +1451,20 @@ discard block |
||
| 1459 | 1451 | } |
| 1460 | 1452 | } |
| 1461 | 1453 | |
| 1462 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1463 | - "static \$connect;\n\t" . |
|
| 1464 | - "\$command['connect'] = \$connect = " . |
|
| 1465 | - _q($boucle->sql_serveur) . |
|
| 1466 | - ";" . |
|
| 1454 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1455 | + "static \$connect;\n\t". |
|
| 1456 | + "\$command['connect'] = \$connect = ". |
|
| 1457 | + _q($boucle->sql_serveur). |
|
| 1458 | + ";". |
|
| 1467 | 1459 | $f($id, $boucles); |
| 1468 | 1460 | } else { |
| 1469 | 1461 | $req = ("\n\treturn '';"); |
| 1470 | 1462 | } |
| 1471 | 1463 | |
| 1472 | 1464 | $boucles[$id]->return = |
| 1473 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1474 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1475 | - $req . |
|
| 1465 | + "\n\nfunction BOUCLE".strtr($id, "-", "_").$nom. |
|
| 1466 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1467 | + $req. |
|
| 1476 | 1468 | "\n}\n"; |
| 1477 | 1469 | } |
| 1478 | 1470 | |
@@ -1482,7 +1474,7 @@ discard block |
||
| 1482 | 1474 | return false; |
| 1483 | 1475 | } |
| 1484 | 1476 | |
| 1485 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1477 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1486 | 1478 | ' |
| 1487 | 1479 | // reporter de maniere securisee les doublons inclus |
| 1488 | 1480 | . ' |
@@ -1490,15 +1482,15 @@ discard block |
||
| 1490 | 1482 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1491 | 1483 | |
| 1492 | 1484 | $connect = ' . |
| 1493 | - _q($connect) . '; |
|
| 1485 | + _q($connect).'; |
|
| 1494 | 1486 | $page = ' . |
| 1495 | 1487 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1496 | 1488 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1497 | 1489 | // avant de referencer $Cache |
| 1498 | - $corps . "; |
|
| 1490 | + $corps."; |
|
| 1499 | 1491 | |
| 1500 | 1492 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1501 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1493 | + . ", \$Cache, \$page, ".var_export($sourcefile, true)."); |
|
| 1502 | 1494 | }"; |
| 1503 | 1495 | |
| 1504 | 1496 | $secondes = spip_timer('calcul_skel'); |
@@ -1512,10 +1504,10 @@ discard block |
||
| 1512 | 1504 | $code->return = ' |
| 1513 | 1505 | // |
| 1514 | 1506 | // Fonction principale du squelette ' . |
| 1515 | - $sourcefile . |
|
| 1516 | - ($connect ? " pour $connect" : '') . |
|
| 1517 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1518 | - "\n//\n" . |
|
| 1507 | + $sourcefile. |
|
| 1508 | + ($connect ? " pour $connect" : ''). |
|
| 1509 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1510 | + "\n//\n". |
|
| 1519 | 1511 | $principal; |
| 1520 | 1512 | |
| 1521 | 1513 | $boucles[''] = $code; |
@@ -1567,7 +1559,7 @@ discard block |
||
| 1567 | 1559 | **/ |
| 1568 | 1560 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1569 | 1561 | include_spip('iterateur/data'); |
| 1570 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1562 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1571 | 1563 | $g = charger_fonction('data', 'iterateur'); |
| 1572 | 1564 | $boucles[$id] = $g($boucle); |
| 1573 | 1565 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -133,6 +133,10 @@ discard block |
||
| 133 | 133 | return $nom ? $nom : false; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | +/** |
|
| 137 | + * @param string $squelette |
|
| 138 | + * @param string $phpfile |
|
| 139 | + */ |
|
| 136 | 140 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 137 | 141 | |
| 138 | 142 | // Le dernier index est '' (fonction principale) |
@@ -157,6 +161,9 @@ discard block |
||
| 157 | 161 | |
| 158 | 162 | // Le squelette compile est-il trop vieux ? |
| 159 | 163 | // http://code.spip.net/@squelette_obsolete |
| 164 | +/** |
|
| 165 | + * @param string $skel |
|
| 166 | + */ |
|
| 160 | 167 | function squelette_obsolete($skel, $squelette) { |
| 161 | 168 | static $date_change = null; |
| 162 | 169 | // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
@@ -357,10 +357,12 @@ |
||
| 357 | 357 | |
| 358 | 358 | // et reparagrapher si necessaire (coherence avec le cas descriptif) |
| 359 | 359 | // une introduction a tojours un <p> |
| 360 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 360 | + if ($GLOBALS['toujours_paragrapher']) { |
|
| 361 | + // Fermer les paragraphes |
|
| 361 | 362 | { |
| 362 | 363 | $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
| 363 | 364 | } |
| 365 | + } |
|
| 364 | 366 | |
| 365 | 367 | return $texte; |
| 366 | 368 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 56 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 57 | 57 | |
| 58 | 58 | // si squelette est deja compile et perenne, le charger |
| 59 | 59 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | #} |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 69 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 70 | 70 | include_once $lib; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 120 | 120 | |
| 121 | 121 | // Tracer ce qui vient d'etre compile |
| 122 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 122 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 123 | 123 | |
| 124 | 124 | // si c'est ce que demande le debusqueur, lui passer la main |
| 125 | 125 | if ($GLOBALS['debug_objets']['sourcefile'] |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | $code = " |
| 142 | 142 | /* |
| 143 | 143 | * Squelette : $sourcefile |
| 144 | - * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
|
| 145 | - * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
|
| 146 | - * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
|
| 144 | + * Date : ".gmdate("D, d M Y H:i:s", @filemtime($sourcefile))." GMT |
|
| 145 | + * Compile : " . gmdate("D, d M Y H:i:s", time())." GMT |
|
| 146 | + * " . (!$boucles ? "Pas de boucle" : ("Boucles : ".$noms))." |
|
| 147 | 147 | */ "; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 150 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 151 | 151 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 152 | 152 | ecrire_fichier($phpfile, $code); |
| 153 | 153 | } |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 208 | 208 | |
| 209 | 209 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 210 | - $headers[$j] .= "|" . $r[3]; |
|
| 210 | + $headers[$j] .= "|".$r[3]; |
|
| 211 | 211 | } else { |
| 212 | 212 | $headers[$j] = $r[3]; |
| 213 | 213 | } |
@@ -215,10 +215,10 @@ discard block |
||
| 215 | 215 | } |
| 216 | 216 | // S'agit-il d'un resultat constant ou contenant du code php |
| 217 | 217 | $process_ins = ( |
| 218 | - strpos($corps, '<' . '?') === false |
|
| 218 | + strpos($corps, '<'.'?') === false |
|
| 219 | 219 | or |
| 220 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 221 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 220 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 221 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 222 | 222 | ) |
| 223 | 223 | ? 'html' |
| 224 | 224 | : 'php'; |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | if ($process_ins == 'html') { |
| 246 | 246 | $skel['process_ins'] = ( |
| 247 | - strpos($corps, '<' . '?') === false |
|
| 247 | + strpos($corps, '<'.'?') === false |
|
| 248 | 248 | or |
| 249 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 250 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 249 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 250 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 251 | 251 | ) |
| 252 | 252 | ? 'html' |
| 253 | 253 | : 'php'; |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | if (strlen($intro)) { |
| 326 | 326 | $texte = $intro; |
| 327 | 327 | } else { |
| 328 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 328 | + if (strpos("\n".$texte, "\n|") === false |
|
| 329 | 329 | and strlen($texte) > 2.5 * $longueur |
| 330 | 330 | ) { |
| 331 | 331 | if (strpos($texte, "<multi") !== false) { |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | // |
| 371 | 371 | |
| 372 | 372 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 373 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 373 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 374 | 374 | include_once("%s"); |
| 375 | 375 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 376 | 376 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | **/ |
| 398 | 398 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 399 | 399 | if (strncmp($file, "/", 1) !== 0) { |
| 400 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 400 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 401 | 401 | } |
| 402 | 402 | $r = sprintf(CODE_INCLURE_BALISE, |
| 403 | 403 | $file, |
@@ -425,14 +425,14 @@ discard block |
||
| 425 | 425 | function argumenter_squelette($v) { |
| 426 | 426 | |
| 427 | 427 | if (!is_array($v)) { |
| 428 | - return "'" . texte_script($v) . "'"; |
|
| 428 | + return "'".texte_script($v)."'"; |
|
| 429 | 429 | } else { |
| 430 | 430 | $out = array(); |
| 431 | 431 | foreach ($v as $k => $val) { |
| 432 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 432 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - return 'array(' . join(", ", $out) . ')'; |
|
| 435 | + return 'array('.join(", ", $out).')'; |
|
| 436 | 436 | } |
| 437 | 437 | } |
| 438 | 438 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // Y a-t-il une fonction de traitement des arguments ? |
| 500 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 500 | + $f = 'balise_'.$nomfonction.'_stat'; |
|
| 501 | 501 | |
| 502 | 502 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 503 | 503 | |
@@ -507,16 +507,16 @@ discard block |
||
| 507 | 507 | |
| 508 | 508 | // verifier que la fonction dyn est la, |
| 509 | 509 | // sinon se replier sur la generique si elle existe |
| 510 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 510 | + if (!function_exists('balise_'.$nomfonction.'_dyn')) { |
|
| 511 | 511 | if ($nomfonction_generique |
| 512 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 513 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 512 | + and $file = include_spip("balise/".strtolower($nomfonction_generique)) |
|
| 513 | + and function_exists('balise_'.$nomfonction_generique.'_dyn') |
|
| 514 | 514 | ) { |
| 515 | 515 | // et lui injecter en premier arg le nom de la balise |
| 516 | 516 | array_unshift($r, $nom); |
| 517 | 517 | $nomfonction = $nomfonction_generique; |
| 518 | 518 | if (!_DIR_RESTREINT) { |
| 519 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 519 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 520 | 520 | } |
| 521 | 521 | } else { |
| 522 | 522 | $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
@@ -637,7 +637,7 @@ discard block |
||
| 637 | 637 | $n = ''; |
| 638 | 638 | foreach (explode(',', $liste) as $val) { |
| 639 | 639 | if ($a = intval($val) and $val === strval($a)) { |
| 640 | - $n .= ',' . $val; |
|
| 640 | + $n .= ','.$val; |
|
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | if (strlen($n)) { |
@@ -816,14 +816,14 @@ discard block |
||
| 816 | 816 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 817 | 817 | $i = 0; |
| 818 | 818 | do { |
| 819 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 820 | - array($sous[1] . " AS id"), |
|
| 819 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 820 | + array($sous[1]." AS id"), |
|
| 821 | 821 | $from, |
| 822 | 822 | $from_type, |
| 823 | 823 | $wheresub, |
| 824 | 824 | $jsub, |
| 825 | 825 | array(), array(), '', |
| 826 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 826 | + $having, $table, $id, $serveur, false).")"); |
|
| 827 | 827 | if (!$i) { |
| 828 | 828 | $i = 1; |
| 829 | 829 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | if ($sous[0] == 'SUBSELECT') { |
| 843 | 843 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 844 | 844 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 845 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 845 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 846 | 846 | $sous[1], # select |
| 847 | 847 | $sous[2], #from |
| 848 | 848 | array(), #from_type |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | $sous[6], #limit |
| 855 | 855 | $sous[7] ? $sous[7] : array(), #having |
| 856 | 856 | $table, $id, $serveur, false |
| 857 | - ) . ")"); |
|
| 857 | + ).")"); |
|
| 858 | 858 | } |
| 859 | 859 | array_pop($where_simples); |
| 860 | 860 | } |
@@ -915,15 +915,15 @@ discard block |
||
| 915 | 915 | // sans recours a preg_match |
| 916 | 916 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 917 | 917 | $afrom[$t][$cle] = array( |
| 918 | - "\n" . |
|
| 919 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 918 | + "\n". |
|
| 919 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER")." JOIN", |
|
| 920 | 920 | $from[$cle], |
| 921 | 921 | "AS $cle", |
| 922 | 922 | "ON (", |
| 923 | 923 | "$cle.$c", |
| 924 | 924 | "=", |
| 925 | 925 | "$t.$carr", |
| 926 | - ($and ? "AND " . $and : "") . |
|
| 926 | + ($and ? "AND ".$and : ""). |
|
| 927 | 927 | ")" |
| 928 | 928 | ); |
| 929 | 929 | if (isset($afrom[$cle])) { |
@@ -957,7 +957,7 @@ discard block |
||
| 957 | 957 | $t = key($from); |
| 958 | 958 | $c = current($from); |
| 959 | 959 | reset($from); |
| 960 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 960 | + $e = '/\b('."$t\\.".join("|".$t.'\.', $equiv).')\b/'; |
|
| 961 | 961 | if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 962 | 962 | calculer_jointnul($t, $select, $e) or |
| 963 | 963 | calculer_jointnul($t, $join, $e) or |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | unset($afrom[$t][$nt]); |
| 975 | 975 | $afrom[$nt] = $afrom[$t]; |
| 976 | 976 | unset($afrom[$t]); |
| 977 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 977 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 978 | 978 | $t = $nfrom[4]; |
| 979 | 979 | $alias = ""; |
| 980 | 980 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -985,14 +985,14 @@ discard block |
||
| 985 | 985 | if ($newcle != $oldcle) { |
| 986 | 986 | // si l'ancienne cle etait deja dans le select avec un AS |
| 987 | 987 | // reprendre simplement ce AS |
| 988 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 988 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 989 | 989 | if (preg_match($as, implode(',', $select), $m)) { |
| 990 | 990 | $alias = ""; |
| 991 | 991 | } else { |
| 992 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 992 | + $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 993 | 993 | } |
| 994 | 994 | } |
| 995 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 995 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 996 | 996 | $join = remplacer_jointnul($t, $join, $e); |
| 997 | 997 | $where = remplacer_jointnul($t, $where, $e); |
| 998 | 998 | $having = remplacer_jointnul($t, $having, $e); |
@@ -1026,9 +1026,9 @@ discard block |
||
| 1026 | 1026 | } else { |
| 1027 | 1027 | $exp = ""; |
| 1028 | 1028 | if (strtoupper($join) === 'AND') { |
| 1029 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1029 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1030 | 1030 | } else { |
| 1031 | - return $exp . join($join, $v); |
|
| 1031 | + return $exp.join($join, $v); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | } |
| 1034 | 1034 | } |
@@ -1094,6 +1094,6 @@ discard block |
||
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | 1096 | return $mime_type |
| 1097 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1098 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1097 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)).'_' |
|
| 1098 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1099 | 1099 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -42,223 +42,223 @@ discard block |
||
| 42 | 42 | // http://code.spip.net/@public_composer_dist |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 44 | 44 | |
| 45 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | - |
|
| 47 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | - if (function_exists($nom)) { |
|
| 49 | - return $nom; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | - |
|
| 58 | - // si squelette est deja compile et perenne, le charger |
|
| 59 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | - include_once $phpfile; |
|
| 61 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | - ## eval('?'.'>'.$skel_code); |
|
| 65 | - # spip_log($skel_code, 'comp') |
|
| 66 | - #} |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | - include_once $lib; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | - |
|
| 75 | - if (function_exists($nom)) { |
|
| 76 | - return $nom; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // charger le source, si possible, et compiler |
|
| 80 | - $skel_code = ''; |
|
| 81 | - if (lire_fichier($source, $skel)) { |
|
| 82 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 83 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 87 | - if (!$skel_code) { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - foreach ($skel_code as $id => $boucle) { |
|
| 92 | - $f = $boucle->return; |
|
| 93 | - if (@eval("return true; $f ;") === false) { |
|
| 94 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 95 | - $msg = _T('zbug_erreur_compilation'); |
|
| 96 | - erreur_squelette($msg, $boucle); |
|
| 97 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 98 | - // mais prevenir que c'est mort |
|
| 99 | - $nom = ''; |
|
| 100 | - } |
|
| 101 | - // Contexte de compil inutile a present |
|
| 102 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 103 | - $skel_code[$id] = $f; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $code = ''; |
|
| 107 | - if ($nom) { |
|
| 108 | - // Si le code est bon, concatener et mettre en cache |
|
| 109 | - if (function_exists($nom)) { |
|
| 110 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 111 | - } else { |
|
| 112 | - // code semantiquement faux: bug du compilateur |
|
| 113 | - // $boucle est en fait ici la fct principale du squelette |
|
| 114 | - $msg = _T('zbug_erreur_compilation'); |
|
| 115 | - erreur_squelette($msg, $boucle); |
|
| 116 | - $nom = ''; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 121 | - |
|
| 122 | - // Tracer ce qui vient d'etre compile |
|
| 123 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 124 | - |
|
| 125 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 126 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 127 | - and (_request('var_mode_objet') == $nom) |
|
| 128 | - and (_request('var_mode_affiche') == 'code') |
|
| 129 | - ) { |
|
| 130 | - erreur_squelette(); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $nom ? $nom : false; |
|
| 45 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | + |
|
| 47 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | + if (function_exists($nom)) { |
|
| 49 | + return $nom; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + |
|
| 58 | + // si squelette est deja compile et perenne, le charger |
|
| 59 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | + include_once $phpfile; |
|
| 61 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | + ## eval('?'.'>'.$skel_code); |
|
| 65 | + # spip_log($skel_code, 'comp') |
|
| 66 | + #} |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + include_once $lib; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | + |
|
| 75 | + if (function_exists($nom)) { |
|
| 76 | + return $nom; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // charger le source, si possible, et compiler |
|
| 80 | + $skel_code = ''; |
|
| 81 | + if (lire_fichier($source, $skel)) { |
|
| 82 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 83 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 87 | + if (!$skel_code) { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + foreach ($skel_code as $id => $boucle) { |
|
| 92 | + $f = $boucle->return; |
|
| 93 | + if (@eval("return true; $f ;") === false) { |
|
| 94 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 95 | + $msg = _T('zbug_erreur_compilation'); |
|
| 96 | + erreur_squelette($msg, $boucle); |
|
| 97 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 98 | + // mais prevenir que c'est mort |
|
| 99 | + $nom = ''; |
|
| 100 | + } |
|
| 101 | + // Contexte de compil inutile a present |
|
| 102 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 103 | + $skel_code[$id] = $f; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $code = ''; |
|
| 107 | + if ($nom) { |
|
| 108 | + // Si le code est bon, concatener et mettre en cache |
|
| 109 | + if (function_exists($nom)) { |
|
| 110 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 111 | + } else { |
|
| 112 | + // code semantiquement faux: bug du compilateur |
|
| 113 | + // $boucle est en fait ici la fct principale du squelette |
|
| 114 | + $msg = _T('zbug_erreur_compilation'); |
|
| 115 | + erreur_squelette($msg, $boucle); |
|
| 116 | + $nom = ''; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 121 | + |
|
| 122 | + // Tracer ce qui vient d'etre compile |
|
| 123 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 124 | + |
|
| 125 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 126 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 127 | + and (_request('var_mode_objet') == $nom) |
|
| 128 | + and (_request('var_mode_affiche') == 'code') |
|
| 129 | + ) { |
|
| 130 | + erreur_squelette(); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $nom ? $nom : false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 138 | 138 | |
| 139 | - // Le dernier index est '' (fonction principale) |
|
| 140 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 141 | - if (CODE_COMMENTE) { |
|
| 142 | - $code = " |
|
| 139 | + // Le dernier index est '' (fonction principale) |
|
| 140 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 141 | + if (CODE_COMMENTE) { |
|
| 142 | + $code = " |
|
| 143 | 143 | /* |
| 144 | 144 | * Squelette : $sourcefile |
| 145 | 145 | * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
| 146 | 146 | * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
| 147 | 147 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
| 148 | 148 | */ "; |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 152 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 153 | - ecrire_fichier($phpfile, $code); |
|
| 154 | - } |
|
| 151 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 152 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 153 | + ecrire_fichier($phpfile, $code); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - return $code; |
|
| 156 | + return $code; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Le squelette compile est-il trop vieux ? |
| 160 | 160 | // http://code.spip.net/@squelette_obsolete |
| 161 | 161 | function squelette_obsolete($skel, $squelette) { |
| 162 | - static $date_change = null; |
|
| 163 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 164 | - // par hit |
|
| 165 | - if (is_null($date_change)) { |
|
| 166 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 167 | - $date_change = @filemtime($fonc); |
|
| 168 | - } # compatibilite |
|
| 169 | - if (defined('_FILE_OPTIONS')) { |
|
| 170 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return ( |
|
| 175 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 176 | - or !@file_exists($skel) |
|
| 177 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 178 | - > ($date = @filemtime($skel))) |
|
| 179 | - or ($date_change > $date) |
|
| 180 | - ); |
|
| 162 | + static $date_change = null; |
|
| 163 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 164 | + // par hit |
|
| 165 | + if (is_null($date_change)) { |
|
| 166 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 167 | + $date_change = @filemtime($fonc); |
|
| 168 | + } # compatibilite |
|
| 169 | + if (defined('_FILE_OPTIONS')) { |
|
| 170 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return ( |
|
| 175 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 176 | + or !@file_exists($skel) |
|
| 177 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 178 | + > ($date = @filemtime($skel))) |
|
| 179 | + or ($date_change > $date) |
|
| 180 | + ); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Activer l'invalideur de session |
| 184 | 184 | // http://code.spip.net/@invalideur_session |
| 185 | 185 | function invalideur_session(&$Cache, $code = null) { |
| 186 | - $Cache['session'] = spip_session(); |
|
| 186 | + $Cache['session'] = spip_session(); |
|
| 187 | 187 | |
| 188 | - return $code; |
|
| 188 | + return $code; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
| 192 | 192 | // http://code.spip.net/@analyse_resultat_skel |
| 193 | 193 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 194 | - static $filtres = array(); |
|
| 195 | - $headers = array(); |
|
| 196 | - |
|
| 197 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 198 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 199 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 200 | - if (stripos($corps, 'header') !== false |
|
| 201 | - and preg_match_all( |
|
| 202 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 203 | - $corps, $regs, PREG_SET_ORDER) |
|
| 204 | - ) { |
|
| 205 | - foreach ($regs as $r) { |
|
| 206 | - $corps = str_replace($r[0], '', $corps); |
|
| 207 | - # $j = Content-Type, et pas content-TYPE. |
|
| 208 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 209 | - |
|
| 210 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 211 | - $headers[$j] .= "|" . $r[3]; |
|
| 212 | - } else { |
|
| 213 | - $headers[$j] = $r[3]; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 218 | - $process_ins = ( |
|
| 219 | - strpos($corps, '<' . '?') === false |
|
| 220 | - or |
|
| 221 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 222 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 223 | - ) |
|
| 224 | - ? 'html' |
|
| 225 | - : 'php'; |
|
| 226 | - |
|
| 227 | - $skel = array( |
|
| 228 | - 'squelette' => $nom, |
|
| 229 | - 'source' => $source, |
|
| 230 | - 'process_ins' => $process_ins, |
|
| 231 | - 'invalideurs' => $cache, |
|
| 232 | - 'entetes' => $headers, |
|
| 233 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 234 | - ); |
|
| 235 | - |
|
| 236 | - // traiter #FILTRE{} et filtres |
|
| 237 | - if (!isset($filtres[$nom])) { |
|
| 238 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 239 | - } |
|
| 240 | - if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 241 | - include_spip('public/sandbox'); |
|
| 242 | - $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 243 | - strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 244 | - unset($headers['X-Spip-Filtre']); |
|
| 245 | - |
|
| 246 | - if ($process_ins == 'html') { |
|
| 247 | - $skel['process_ins'] = ( |
|
| 248 | - strpos($corps, '<' . '?') === false |
|
| 249 | - or |
|
| 250 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 251 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 252 | - ) |
|
| 253 | - ? 'html' |
|
| 254 | - : 'php'; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $skel['entetes'] = $headers; |
|
| 259 | - $skel['texte'] = $corps; |
|
| 260 | - |
|
| 261 | - return $skel; |
|
| 194 | + static $filtres = array(); |
|
| 195 | + $headers = array(); |
|
| 196 | + |
|
| 197 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 198 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 199 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 200 | + if (stripos($corps, 'header') !== false |
|
| 201 | + and preg_match_all( |
|
| 202 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 203 | + $corps, $regs, PREG_SET_ORDER) |
|
| 204 | + ) { |
|
| 205 | + foreach ($regs as $r) { |
|
| 206 | + $corps = str_replace($r[0], '', $corps); |
|
| 207 | + # $j = Content-Type, et pas content-TYPE. |
|
| 208 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 209 | + |
|
| 210 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 211 | + $headers[$j] .= "|" . $r[3]; |
|
| 212 | + } else { |
|
| 213 | + $headers[$j] = $r[3]; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 218 | + $process_ins = ( |
|
| 219 | + strpos($corps, '<' . '?') === false |
|
| 220 | + or |
|
| 221 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 222 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 223 | + ) |
|
| 224 | + ? 'html' |
|
| 225 | + : 'php'; |
|
| 226 | + |
|
| 227 | + $skel = array( |
|
| 228 | + 'squelette' => $nom, |
|
| 229 | + 'source' => $source, |
|
| 230 | + 'process_ins' => $process_ins, |
|
| 231 | + 'invalideurs' => $cache, |
|
| 232 | + 'entetes' => $headers, |
|
| 233 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 234 | + ); |
|
| 235 | + |
|
| 236 | + // traiter #FILTRE{} et filtres |
|
| 237 | + if (!isset($filtres[$nom])) { |
|
| 238 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 239 | + } |
|
| 240 | + if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 241 | + include_spip('public/sandbox'); |
|
| 242 | + $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 243 | + strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 244 | + unset($headers['X-Spip-Filtre']); |
|
| 245 | + |
|
| 246 | + if ($process_ins == 'html') { |
|
| 247 | + $skel['process_ins'] = ( |
|
| 248 | + strpos($corps, '<' . '?') === false |
|
| 249 | + or |
|
| 250 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 251 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 252 | + ) |
|
| 253 | + ? 'html' |
|
| 254 | + : 'php'; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $skel['entetes'] = $headers; |
|
| 259 | + $skel['texte'] = $corps; |
|
| 260 | + |
|
| 261 | + return $skel; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // |
@@ -295,75 +295,75 @@ discard block |
||
| 295 | 295 | * Introduction calculée |
| 296 | 296 | **/ |
| 297 | 297 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 298 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 299 | - if (strlen($descriptif)) { |
|
| 300 | - return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // De preference ce qui est marque <intro>...</intro> |
|
| 304 | - $intro = ''; |
|
| 305 | - $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 306 | - while ($fin = strpos($texte, "</intro>")) { |
|
| 307 | - $zone = substr($texte, 0, $fin); |
|
| 308 | - $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 309 | - if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 310 | - $zone = substr($zone, $deb + 7); |
|
| 311 | - } |
|
| 312 | - $intro .= $zone; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 316 | - // qui inclus raccourcis et modeles |
|
| 317 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 318 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 319 | - // des surcharges et enrichissement de propre |
|
| 320 | - // couper doit se faire apres propre |
|
| 321 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 322 | - |
|
| 323 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 324 | - // large et en se mefiant des tableaux #1323 |
|
| 325 | - |
|
| 326 | - if (strlen($intro)) { |
|
| 327 | - $texte = $intro; |
|
| 328 | - } else { |
|
| 329 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 330 | - and strlen($texte) > 2.5 * $longueur |
|
| 331 | - ) { |
|
| 332 | - if (strpos($texte, "<multi") !== false) { |
|
| 333 | - $texte = extraire_multi($texte); |
|
| 334 | - } |
|
| 335 | - $texte = couper($texte, 2 * $longueur); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // ne pas tenir compte des notes |
|
| 340 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 341 | - $notes('', 'empiler'); |
|
| 342 | - } |
|
| 343 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 344 | - // dans l'introduction. |
|
| 345 | - $texte = supprime_img($texte, ''); |
|
| 346 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 347 | - |
|
| 348 | - if ($notes) { |
|
| 349 | - $notes('', 'depiler'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 353 | - $suite = _INTRODUCTION_SUITE; |
|
| 354 | - } |
|
| 355 | - $texte = couper($texte, $longueur, $suite); |
|
| 356 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 357 | - $texte = typo($texte, true, $connect, array()); |
|
| 358 | - |
|
| 359 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 360 | - // une introduction a tojours un <p> |
|
| 361 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 362 | - { |
|
| 363 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return $texte; |
|
| 298 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 299 | + if (strlen($descriptif)) { |
|
| 300 | + return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // De preference ce qui est marque <intro>...</intro> |
|
| 304 | + $intro = ''; |
|
| 305 | + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 306 | + while ($fin = strpos($texte, "</intro>")) { |
|
| 307 | + $zone = substr($texte, 0, $fin); |
|
| 308 | + $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 309 | + if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 310 | + $zone = substr($zone, $deb + 7); |
|
| 311 | + } |
|
| 312 | + $intro .= $zone; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 316 | + // qui inclus raccourcis et modeles |
|
| 317 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 318 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 319 | + // des surcharges et enrichissement de propre |
|
| 320 | + // couper doit se faire apres propre |
|
| 321 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 322 | + |
|
| 323 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 324 | + // large et en se mefiant des tableaux #1323 |
|
| 325 | + |
|
| 326 | + if (strlen($intro)) { |
|
| 327 | + $texte = $intro; |
|
| 328 | + } else { |
|
| 329 | + if (strpos("\n" . $texte, "\n|") === false |
|
| 330 | + and strlen($texte) > 2.5 * $longueur |
|
| 331 | + ) { |
|
| 332 | + if (strpos($texte, "<multi") !== false) { |
|
| 333 | + $texte = extraire_multi($texte); |
|
| 334 | + } |
|
| 335 | + $texte = couper($texte, 2 * $longueur); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // ne pas tenir compte des notes |
|
| 340 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 341 | + $notes('', 'empiler'); |
|
| 342 | + } |
|
| 343 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 344 | + // dans l'introduction. |
|
| 345 | + $texte = supprime_img($texte, ''); |
|
| 346 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 347 | + |
|
| 348 | + if ($notes) { |
|
| 349 | + $notes('', 'depiler'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 353 | + $suite = _INTRODUCTION_SUITE; |
|
| 354 | + } |
|
| 355 | + $texte = couper($texte, $longueur, $suite); |
|
| 356 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 357 | + $texte = typo($texte, true, $connect, array()); |
|
| 358 | + |
|
| 359 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 360 | + // une introduction a tojours un <p> |
|
| 361 | + if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 362 | + { |
|
| 363 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return $texte; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 378 | 378 | if ($lang_select) lang_select(); |
| 379 | 379 | ?' |
| 380 | - . '>'); |
|
| 380 | + . '>'); |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -397,17 +397,17 @@ discard block |
||
| 397 | 397 | * Code PHP pour inclure le squelette de la balise dynamique |
| 398 | 398 | **/ |
| 399 | 399 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 400 | - if (strncmp($file, "/", 1) !== 0) { |
|
| 401 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 402 | - } |
|
| 403 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 404 | - $file, |
|
| 405 | - $context_compil[4] ? $context_compil[4] : '', |
|
| 406 | - $nom, |
|
| 407 | - join(', ', array_map('argumenter_squelette', $args)), |
|
| 408 | - join(', ', array_map('_q', $context_compil))); |
|
| 409 | - |
|
| 410 | - return $r; |
|
| 400 | + if (strncmp($file, "/", 1) !== 0) { |
|
| 401 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 402 | + } |
|
| 403 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 404 | + $file, |
|
| 405 | + $context_compil[4] ? $context_compil[4] : '', |
|
| 406 | + $nom, |
|
| 407 | + join(', ', array_map('argumenter_squelette', $args)), |
|
| 408 | + join(', ', array_map('_q', $context_compil))); |
|
| 409 | + |
|
| 410 | + return $r; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -425,16 +425,16 @@ discard block |
||
| 425 | 425 | **/ |
| 426 | 426 | function argumenter_squelette($v) { |
| 427 | 427 | |
| 428 | - if (!is_array($v)) { |
|
| 429 | - return "'" . texte_script($v) . "'"; |
|
| 430 | - } else { |
|
| 431 | - $out = array(); |
|
| 432 | - foreach ($v as $k => $val) { |
|
| 433 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 434 | - } |
|
| 428 | + if (!is_array($v)) { |
|
| 429 | + return "'" . texte_script($v) . "'"; |
|
| 430 | + } else { |
|
| 431 | + $out = array(); |
|
| 432 | + foreach ($v as $k => $val) { |
|
| 433 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - return 'array(' . join(", ", $out) . ')'; |
|
| 437 | - } |
|
| 436 | + return 'array(' . join(", ", $out) . ')'; |
|
| 437 | + } |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
@@ -465,69 +465,69 @@ discard block |
||
| 465 | 465 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 466 | 466 | **/ |
| 467 | 467 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 468 | - $nomfonction = $nom; |
|
| 469 | - $nomfonction_generique = ""; |
|
| 470 | - |
|
| 471 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 472 | - if (false !== ($p = strpos($nom, "_"))) { |
|
| 473 | - $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 477 | - if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 478 | - // et injecter en premier arg le nom de la balise |
|
| 479 | - array_unshift($args, $nom); |
|
| 480 | - $nomfonction = $nomfonction_generique; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if (!$fonction_balise) { |
|
| 485 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 486 | - erreur_squelette($msg, $context_compil); |
|
| 487 | - |
|
| 488 | - return ''; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - // retrouver le fichier qui a déclaré la fonction |
|
| 492 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 493 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 494 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 495 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 496 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 497 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 501 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 502 | - |
|
| 503 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 504 | - |
|
| 505 | - if (!is_array($r)) { |
|
| 506 | - return $r; |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - // verifier que la fonction dyn est la, |
|
| 510 | - // sinon se replier sur la generique si elle existe |
|
| 511 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 512 | - if ($nomfonction_generique |
|
| 513 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 514 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 515 | - ) { |
|
| 516 | - // et lui injecter en premier arg le nom de la balise |
|
| 517 | - array_unshift($r, $nom); |
|
| 518 | - $nomfonction = $nomfonction_generique; |
|
| 519 | - if (!_DIR_RESTREINT) { |
|
| 520 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 521 | - } |
|
| 522 | - } else { |
|
| 523 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 524 | - erreur_squelette($msg, $context_compil); |
|
| 525 | - |
|
| 526 | - return ''; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 468 | + $nomfonction = $nom; |
|
| 469 | + $nomfonction_generique = ""; |
|
| 470 | + |
|
| 471 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 472 | + if (false !== ($p = strpos($nom, "_"))) { |
|
| 473 | + $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 477 | + if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 478 | + // et injecter en premier arg le nom de la balise |
|
| 479 | + array_unshift($args, $nom); |
|
| 480 | + $nomfonction = $nomfonction_generique; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if (!$fonction_balise) { |
|
| 485 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 486 | + erreur_squelette($msg, $context_compil); |
|
| 487 | + |
|
| 488 | + return ''; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + // retrouver le fichier qui a déclaré la fonction |
|
| 492 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 493 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 494 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 495 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 496 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 497 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 501 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 502 | + |
|
| 503 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 504 | + |
|
| 505 | + if (!is_array($r)) { |
|
| 506 | + return $r; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + // verifier que la fonction dyn est la, |
|
| 510 | + // sinon se replier sur la generique si elle existe |
|
| 511 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 512 | + if ($nomfonction_generique |
|
| 513 | + and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 514 | + and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 515 | + ) { |
|
| 516 | + // et lui injecter en premier arg le nom de la balise |
|
| 517 | + array_unshift($r, $nom); |
|
| 518 | + $nomfonction = $nomfonction_generique; |
|
| 519 | + if (!_DIR_RESTREINT) { |
|
| 520 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 521 | + } |
|
| 522 | + } else { |
|
| 523 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 524 | + erreur_squelette($msg, $context_compil); |
|
| 525 | + |
|
| 526 | + return ''; |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 531 | 531 | |
| 532 | 532 | } |
| 533 | 533 | |
@@ -543,24 +543,24 @@ discard block |
||
| 543 | 543 | **/ |
| 544 | 544 | function lister_objets_avec_logos($type) { |
| 545 | 545 | |
| 546 | - $logos = array(); |
|
| 547 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 548 | - $type = '/' |
|
| 549 | - . type_du_logo($type) |
|
| 550 | - . "on(\d+)\.(" |
|
| 551 | - . join('|', $GLOBALS['formats_logos']) |
|
| 552 | - . ")$/"; |
|
| 553 | - |
|
| 554 | - if ($d = opendir(_DIR_LOGOS)) { |
|
| 555 | - while (($f = readdir($d)) !== false) { |
|
| 556 | - if (preg_match($type, $f, $r)) { |
|
| 557 | - $logos[] = $r[1]; |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - @closedir($d); |
|
| 562 | - |
|
| 563 | - return join(',', $logos); |
|
| 546 | + $logos = array(); |
|
| 547 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 548 | + $type = '/' |
|
| 549 | + . type_du_logo($type) |
|
| 550 | + . "on(\d+)\.(" |
|
| 551 | + . join('|', $GLOBALS['formats_logos']) |
|
| 552 | + . ")$/"; |
|
| 553 | + |
|
| 554 | + if ($d = opendir(_DIR_LOGOS)) { |
|
| 555 | + while (($f = readdir($d)) !== false) { |
|
| 556 | + if (preg_match($type, $f, $r)) { |
|
| 557 | + $logos[] = $r[1]; |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + @closedir($d); |
|
| 562 | + |
|
| 563 | + return join(',', $logos); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | |
@@ -576,14 +576,14 @@ discard block |
||
| 576 | 576 | * Code HTML des notes |
| 577 | 577 | **/ |
| 578 | 578 | function calculer_notes() { |
| 579 | - $r = ''; |
|
| 580 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 581 | - $r = $notes(array()); |
|
| 582 | - $notes('', 'depiler'); |
|
| 583 | - $notes('', 'empiler'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - return $r; |
|
| 579 | + $r = ''; |
|
| 580 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 581 | + $r = $notes(array()); |
|
| 582 | + $notes('', 'depiler'); |
|
| 583 | + $notes('', 'empiler'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + return $r; |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -606,27 +606,27 @@ discard block |
||
| 606 | 606 | * @return null; |
| 607 | 607 | **/ |
| 608 | 608 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 609 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 610 | - if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 611 | - and $lang_select !== 'oui' |
|
| 612 | - ) { |
|
| 613 | - $lang = $GLOBALS['spip_lang']; |
|
| 614 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 615 | - elseif (!strlen($lang)) { |
|
| 616 | - $lang = $GLOBALS['spip_lang']; |
|
| 617 | - } // Cas 3. l'objet est multilingue ! |
|
| 618 | - elseif ($lang_select !== 'oui' |
|
| 619 | - and strlen($titre) > 10 |
|
| 620 | - and strpos($titre, '<multi>') !== false |
|
| 621 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 622 | - ) { |
|
| 623 | - $lang = $GLOBALS['spip_lang']; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 627 | - lang_select($lang); |
|
| 628 | - |
|
| 629 | - return; |
|
| 609 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 610 | + if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 611 | + and $lang_select !== 'oui' |
|
| 612 | + ) { |
|
| 613 | + $lang = $GLOBALS['spip_lang']; |
|
| 614 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 615 | + elseif (!strlen($lang)) { |
|
| 616 | + $lang = $GLOBALS['spip_lang']; |
|
| 617 | + } // Cas 3. l'objet est multilingue ! |
|
| 618 | + elseif ($lang_select !== 'oui' |
|
| 619 | + and strlen($titre) > 10 |
|
| 620 | + and strpos($titre, '<multi>') !== false |
|
| 621 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 622 | + ) { |
|
| 623 | + $lang = $GLOBALS['spip_lang']; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 627 | + lang_select($lang); |
|
| 628 | + |
|
| 629 | + return; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | |
@@ -634,21 +634,21 @@ discard block |
||
| 634 | 634 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 635 | 635 | // http://code.spip.net/@nettoyer_env_doublons |
| 636 | 636 | function nettoyer_env_doublons($envd) { |
| 637 | - foreach ($envd as $table => $liste) { |
|
| 638 | - $n = ''; |
|
| 639 | - foreach (explode(',', $liste) as $val) { |
|
| 640 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 641 | - $n .= ',' . $val; |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - if (strlen($n)) { |
|
| 645 | - $envd[$table] = $n; |
|
| 646 | - } else { |
|
| 647 | - unset($envd[$table]); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $envd; |
|
| 637 | + foreach ($envd as $table => $liste) { |
|
| 638 | + $n = ''; |
|
| 639 | + foreach (explode(',', $liste) as $val) { |
|
| 640 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 641 | + $n .= ',' . $val; |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + if (strlen($n)) { |
|
| 645 | + $envd[$table] = $n; |
|
| 646 | + } else { |
|
| 647 | + unset($envd[$table]); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $envd; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -667,21 +667,21 @@ discard block |
||
| 667 | 667 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 668 | 668 | **/ |
| 669 | 669 | function match_self($w) { |
| 670 | - if (is_string($w)) { |
|
| 671 | - return false; |
|
| 672 | - } |
|
| 673 | - if (is_array($w)) { |
|
| 674 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 675 | - return $w; |
|
| 676 | - } |
|
| 677 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 678 | - if ($m = match_self($sw)) { |
|
| 679 | - return $m; |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - return false; |
|
| 670 | + if (is_string($w)) { |
|
| 671 | + return false; |
|
| 672 | + } |
|
| 673 | + if (is_array($w)) { |
|
| 674 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 675 | + return $w; |
|
| 676 | + } |
|
| 677 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 678 | + if ($m = match_self($sw)) { |
|
| 679 | + return $m; |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + return false; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -697,16 +697,16 @@ discard block |
||
| 697 | 697 | * est remplacée par son code. |
| 698 | 698 | **/ |
| 699 | 699 | function remplace_sous_requete($w, $sousrequete) { |
| 700 | - if (is_array($w)) { |
|
| 701 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 702 | - return $sousrequete; |
|
| 703 | - } |
|
| 704 | - foreach ($w as $k => $sw) { |
|
| 705 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - return $w; |
|
| 700 | + if (is_array($w)) { |
|
| 701 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 702 | + return $sousrequete; |
|
| 703 | + } |
|
| 704 | + foreach ($w as $k => $sw) { |
|
| 705 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + return $w; |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -720,17 +720,17 @@ discard block |
||
| 720 | 720 | * - Conditions avec des sous requêtes |
| 721 | 721 | **/ |
| 722 | 722 | function trouver_sous_requetes($where) { |
| 723 | - $where_simples = array(); |
|
| 724 | - $where_sous = array(); |
|
| 725 | - foreach ($where as $k => $w) { |
|
| 726 | - if (match_self($w)) { |
|
| 727 | - $where_sous[$k] = $w; |
|
| 728 | - } else { |
|
| 729 | - $where_simples[$k] = $w; |
|
| 730 | - } |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - return array($where_simples, $where_sous); |
|
| 723 | + $where_simples = array(); |
|
| 724 | + $where_sous = array(); |
|
| 725 | + foreach ($where as $k => $w) { |
|
| 726 | + if (match_self($w)) { |
|
| 727 | + $where_sous[$k] = $w; |
|
| 728 | + } else { |
|
| 729 | + $where_simples[$k] = $w; |
|
| 730 | + } |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + return array($where_simples, $where_sous); |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | |
@@ -756,258 +756,258 @@ discard block |
||
| 756 | 756 | * @return resource |
| 757 | 757 | */ |
| 758 | 758 | function calculer_select( |
| 759 | - $select = array(), |
|
| 760 | - $from = array(), |
|
| 761 | - $from_type = array(), |
|
| 762 | - $where = array(), |
|
| 763 | - $join = array(), |
|
| 764 | - $groupby = array(), |
|
| 765 | - $orderby = array(), |
|
| 766 | - $limit = '', |
|
| 767 | - $having = array(), |
|
| 768 | - $table = '', |
|
| 769 | - $id = '', |
|
| 770 | - $serveur = '', |
|
| 771 | - $requeter = true |
|
| 759 | + $select = array(), |
|
| 760 | + $from = array(), |
|
| 761 | + $from_type = array(), |
|
| 762 | + $where = array(), |
|
| 763 | + $join = array(), |
|
| 764 | + $groupby = array(), |
|
| 765 | + $orderby = array(), |
|
| 766 | + $limit = '', |
|
| 767 | + $having = array(), |
|
| 768 | + $table = '', |
|
| 769 | + $id = '', |
|
| 770 | + $serveur = '', |
|
| 771 | + $requeter = true |
|
| 772 | 772 | ) { |
| 773 | 773 | |
| 774 | - // retirer les criteres vides: |
|
| 775 | - // {X ?} avec X absent de l'URL |
|
| 776 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 777 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 778 | - $menage = false; |
|
| 779 | - foreach ($where as $k => $v) { |
|
| 780 | - if (is_array($v)) { |
|
| 781 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 782 | - $op = false; |
|
| 783 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 784 | - $op = false; |
|
| 785 | - } else { |
|
| 786 | - $op = $v[0] ? $v[0] : $v; |
|
| 787 | - } |
|
| 788 | - } else { |
|
| 789 | - $op = $v; |
|
| 790 | - } |
|
| 791 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 792 | - unset($where[$k]); |
|
| 793 | - $menage = true; |
|
| 794 | - } |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 798 | - $groupby = array_diff($groupby, array('')); |
|
| 799 | - |
|
| 800 | - // remplacer les sous requetes recursives au calcul |
|
| 801 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 802 | - foreach ($where_sous as $k => $w) { |
|
| 803 | - $menage = true; |
|
| 804 | - // on recupere la sous requete |
|
| 805 | - $sous = match_self($w); |
|
| 806 | - if ($sous[0] == 'SELF') { |
|
| 807 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 808 | - array_push($where_simples, $sous[2]); |
|
| 809 | - $wheresub = array( |
|
| 810 | - $sous[2], |
|
| 811 | - '0=0' |
|
| 812 | - ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 813 | - $jsub = $join; |
|
| 814 | - // trouver les jointures utiles a |
|
| 815 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 816 | - // ie L1.objet='article' |
|
| 817 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 818 | - $i = 0; |
|
| 819 | - do { |
|
| 820 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 821 | - array($sous[1] . " AS id"), |
|
| 822 | - $from, |
|
| 823 | - $from_type, |
|
| 824 | - $wheresub, |
|
| 825 | - $jsub, |
|
| 826 | - array(), array(), '', |
|
| 827 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 828 | - if (!$i) { |
|
| 829 | - $i = 1; |
|
| 830 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 831 | - foreach ($join as $cle => $wj) { |
|
| 832 | - if (count($wj) == 4 |
|
| 833 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 834 | - ) { |
|
| 835 | - $i = 0; |
|
| 836 | - $wheresub[] = $wj[3]; |
|
| 837 | - unset($jsub[$cle][3]); |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - } while ($i++ < 1); |
|
| 842 | - } |
|
| 843 | - if ($sous[0] == 'SUBSELECT') { |
|
| 844 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 845 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 846 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 847 | - $sous[1], # select |
|
| 848 | - $sous[2], #from |
|
| 849 | - array(), #from_type |
|
| 850 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 851 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 852 | - array(), #join |
|
| 853 | - $sous[4] ? $sous[4] : array(), #groupby |
|
| 854 | - $sous[5] ? $sous[5] : array(), #orderby |
|
| 855 | - $sous[6], #limit |
|
| 856 | - $sous[7] ? $sous[7] : array(), #having |
|
| 857 | - $table, $id, $serveur, false |
|
| 858 | - ) . ")"); |
|
| 859 | - } |
|
| 860 | - array_pop($where_simples); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - foreach ($having as $k => $v) { |
|
| 864 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 865 | - unset($having[$k]); |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - // Installer les jointures. |
|
| 870 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 871 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 872 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 873 | - |
|
| 874 | - $afrom = array(); |
|
| 875 | - $equiv = array(); |
|
| 876 | - $k = count($join); |
|
| 877 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 878 | - $cle = $cledef; |
|
| 879 | - // le format de join est : |
|
| 880 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 881 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 882 | - if (count($join[$cle]) == 2) { |
|
| 883 | - $join[$cle][] = $join[$cle][1]; |
|
| 884 | - } |
|
| 885 | - if (count($join[$cle]) == 3) { |
|
| 886 | - $join[$cle][] = ''; |
|
| 887 | - } |
|
| 888 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 889 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 890 | - // pour compat avec ancienne convention |
|
| 891 | - if (is_numeric($cle)) { |
|
| 892 | - $cle = "L$k"; |
|
| 893 | - } |
|
| 894 | - if (!$menage |
|
| 895 | - or isset($afrom[$cle]) |
|
| 896 | - or calculer_jointnul($cle, $select) |
|
| 897 | - or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 898 | - or calculer_jointnul($cle, $having) |
|
| 899 | - or calculer_jointnul($cle, $where_simples) |
|
| 900 | - ) { |
|
| 901 | - // corriger les references non explicites dans select |
|
| 902 | - // ou groupby |
|
| 903 | - foreach ($select as $i => $s) { |
|
| 904 | - if ($s == $c) { |
|
| 905 | - $select[$i] = "$cle.$c AS $c"; |
|
| 906 | - break; |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - foreach ($groupby as $i => $g) { |
|
| 910 | - if ($g == $c) { |
|
| 911 | - $groupby[$i] = "$cle.$c"; |
|
| 912 | - break; |
|
| 913 | - } |
|
| 914 | - } |
|
| 915 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 916 | - // sans recours a preg_match |
|
| 917 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 918 | - $afrom[$t][$cle] = array( |
|
| 919 | - "\n" . |
|
| 920 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 921 | - $from[$cle], |
|
| 922 | - "AS $cle", |
|
| 923 | - "ON (", |
|
| 924 | - "$cle.$c", |
|
| 925 | - "=", |
|
| 926 | - "$t.$carr", |
|
| 927 | - ($and ? "AND " . $and : "") . |
|
| 928 | - ")" |
|
| 929 | - ); |
|
| 930 | - if (isset($afrom[$cle])) { |
|
| 931 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 932 | - unset($afrom[$cle]); |
|
| 933 | - } |
|
| 934 | - $equiv[] = $carr; |
|
| 935 | - } else { |
|
| 936 | - unset($join[$cledef]); |
|
| 937 | - } |
|
| 938 | - unset($from[$cle]); |
|
| 939 | - $k--; |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - if (count($afrom)) { |
|
| 943 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 944 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 945 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 946 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 947 | - // ou dans |
|
| 948 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 949 | - // qui comporte plusieurs jointures |
|
| 950 | - // ou dans |
|
| 951 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 952 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 953 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 954 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 955 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 956 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 957 | - |
|
| 958 | - $t = key($from); |
|
| 959 | - $c = current($from); |
|
| 960 | - reset($from); |
|
| 961 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 962 | - if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 963 | - calculer_jointnul($t, $select, $e) or |
|
| 964 | - calculer_jointnul($t, $join, $e) or |
|
| 965 | - calculer_jointnul($t, $where, $e) or |
|
| 966 | - calculer_jointnul($t, $orderby, $e) or |
|
| 967 | - calculer_jointnul($t, $groupby, $e) or |
|
| 968 | - calculer_jointnul($t, $having, $e)) |
|
| 969 | - && count($afrom[$t]) |
|
| 970 | - ) { |
|
| 971 | - $nfrom = reset($afrom[$t]); |
|
| 972 | - $nt = key($afrom[$t]); |
|
| 973 | - unset($from[$t]); |
|
| 974 | - $from[$nt] = $nfrom[1]; |
|
| 975 | - unset($afrom[$t][$nt]); |
|
| 976 | - $afrom[$nt] = $afrom[$t]; |
|
| 977 | - unset($afrom[$t]); |
|
| 978 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 979 | - $t = $nfrom[4]; |
|
| 980 | - $alias = ""; |
|
| 981 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 982 | - $oldcle = explode('.', $nfrom[6]); |
|
| 983 | - $oldcle = end($oldcle); |
|
| 984 | - $newcle = explode('.', $nfrom[4]); |
|
| 985 | - $newcle = end($newcle); |
|
| 986 | - if ($newcle != $oldcle) { |
|
| 987 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 988 | - // reprendre simplement ce AS |
|
| 989 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 990 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 991 | - $alias = ""; |
|
| 992 | - } else { |
|
| 993 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 997 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 998 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 999 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 1000 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 1001 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 1002 | - } |
|
| 1003 | - $from = reinjecte_joint($afrom, $from); |
|
| 1004 | - } |
|
| 1005 | - $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 1006 | - $r = sql_select($select, $from, $where, |
|
| 1007 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 1008 | - unset($GLOBALS['debug']['aucasou']); |
|
| 1009 | - |
|
| 1010 | - return $r; |
|
| 774 | + // retirer les criteres vides: |
|
| 775 | + // {X ?} avec X absent de l'URL |
|
| 776 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 777 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 778 | + $menage = false; |
|
| 779 | + foreach ($where as $k => $v) { |
|
| 780 | + if (is_array($v)) { |
|
| 781 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 782 | + $op = false; |
|
| 783 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 784 | + $op = false; |
|
| 785 | + } else { |
|
| 786 | + $op = $v[0] ? $v[0] : $v; |
|
| 787 | + } |
|
| 788 | + } else { |
|
| 789 | + $op = $v; |
|
| 790 | + } |
|
| 791 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 792 | + unset($where[$k]); |
|
| 793 | + $menage = true; |
|
| 794 | + } |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 798 | + $groupby = array_diff($groupby, array('')); |
|
| 799 | + |
|
| 800 | + // remplacer les sous requetes recursives au calcul |
|
| 801 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 802 | + foreach ($where_sous as $k => $w) { |
|
| 803 | + $menage = true; |
|
| 804 | + // on recupere la sous requete |
|
| 805 | + $sous = match_self($w); |
|
| 806 | + if ($sous[0] == 'SELF') { |
|
| 807 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 808 | + array_push($where_simples, $sous[2]); |
|
| 809 | + $wheresub = array( |
|
| 810 | + $sous[2], |
|
| 811 | + '0=0' |
|
| 812 | + ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 813 | + $jsub = $join; |
|
| 814 | + // trouver les jointures utiles a |
|
| 815 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 816 | + // ie L1.objet='article' |
|
| 817 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 818 | + $i = 0; |
|
| 819 | + do { |
|
| 820 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 821 | + array($sous[1] . " AS id"), |
|
| 822 | + $from, |
|
| 823 | + $from_type, |
|
| 824 | + $wheresub, |
|
| 825 | + $jsub, |
|
| 826 | + array(), array(), '', |
|
| 827 | + $having, $table, $id, $serveur, false) . ")"); |
|
| 828 | + if (!$i) { |
|
| 829 | + $i = 1; |
|
| 830 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 831 | + foreach ($join as $cle => $wj) { |
|
| 832 | + if (count($wj) == 4 |
|
| 833 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 834 | + ) { |
|
| 835 | + $i = 0; |
|
| 836 | + $wheresub[] = $wj[3]; |
|
| 837 | + unset($jsub[$cle][3]); |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + } while ($i++ < 1); |
|
| 842 | + } |
|
| 843 | + if ($sous[0] == 'SUBSELECT') { |
|
| 844 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 845 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 846 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 847 | + $sous[1], # select |
|
| 848 | + $sous[2], #from |
|
| 849 | + array(), #from_type |
|
| 850 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 851 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 852 | + array(), #join |
|
| 853 | + $sous[4] ? $sous[4] : array(), #groupby |
|
| 854 | + $sous[5] ? $sous[5] : array(), #orderby |
|
| 855 | + $sous[6], #limit |
|
| 856 | + $sous[7] ? $sous[7] : array(), #having |
|
| 857 | + $table, $id, $serveur, false |
|
| 858 | + ) . ")"); |
|
| 859 | + } |
|
| 860 | + array_pop($where_simples); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + foreach ($having as $k => $v) { |
|
| 864 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 865 | + unset($having[$k]); |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + // Installer les jointures. |
|
| 870 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 871 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 872 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 873 | + |
|
| 874 | + $afrom = array(); |
|
| 875 | + $equiv = array(); |
|
| 876 | + $k = count($join); |
|
| 877 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 878 | + $cle = $cledef; |
|
| 879 | + // le format de join est : |
|
| 880 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 881 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 882 | + if (count($join[$cle]) == 2) { |
|
| 883 | + $join[$cle][] = $join[$cle][1]; |
|
| 884 | + } |
|
| 885 | + if (count($join[$cle]) == 3) { |
|
| 886 | + $join[$cle][] = ''; |
|
| 887 | + } |
|
| 888 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 889 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 890 | + // pour compat avec ancienne convention |
|
| 891 | + if (is_numeric($cle)) { |
|
| 892 | + $cle = "L$k"; |
|
| 893 | + } |
|
| 894 | + if (!$menage |
|
| 895 | + or isset($afrom[$cle]) |
|
| 896 | + or calculer_jointnul($cle, $select) |
|
| 897 | + or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 898 | + or calculer_jointnul($cle, $having) |
|
| 899 | + or calculer_jointnul($cle, $where_simples) |
|
| 900 | + ) { |
|
| 901 | + // corriger les references non explicites dans select |
|
| 902 | + // ou groupby |
|
| 903 | + foreach ($select as $i => $s) { |
|
| 904 | + if ($s == $c) { |
|
| 905 | + $select[$i] = "$cle.$c AS $c"; |
|
| 906 | + break; |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + foreach ($groupby as $i => $g) { |
|
| 910 | + if ($g == $c) { |
|
| 911 | + $groupby[$i] = "$cle.$c"; |
|
| 912 | + break; |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 916 | + // sans recours a preg_match |
|
| 917 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 918 | + $afrom[$t][$cle] = array( |
|
| 919 | + "\n" . |
|
| 920 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 921 | + $from[$cle], |
|
| 922 | + "AS $cle", |
|
| 923 | + "ON (", |
|
| 924 | + "$cle.$c", |
|
| 925 | + "=", |
|
| 926 | + "$t.$carr", |
|
| 927 | + ($and ? "AND " . $and : "") . |
|
| 928 | + ")" |
|
| 929 | + ); |
|
| 930 | + if (isset($afrom[$cle])) { |
|
| 931 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 932 | + unset($afrom[$cle]); |
|
| 933 | + } |
|
| 934 | + $equiv[] = $carr; |
|
| 935 | + } else { |
|
| 936 | + unset($join[$cledef]); |
|
| 937 | + } |
|
| 938 | + unset($from[$cle]); |
|
| 939 | + $k--; |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + if (count($afrom)) { |
|
| 943 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 944 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 945 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 946 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 947 | + // ou dans |
|
| 948 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 949 | + // qui comporte plusieurs jointures |
|
| 950 | + // ou dans |
|
| 951 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 952 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 953 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 954 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 955 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 956 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 957 | + |
|
| 958 | + $t = key($from); |
|
| 959 | + $c = current($from); |
|
| 960 | + reset($from); |
|
| 961 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 962 | + if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 963 | + calculer_jointnul($t, $select, $e) or |
|
| 964 | + calculer_jointnul($t, $join, $e) or |
|
| 965 | + calculer_jointnul($t, $where, $e) or |
|
| 966 | + calculer_jointnul($t, $orderby, $e) or |
|
| 967 | + calculer_jointnul($t, $groupby, $e) or |
|
| 968 | + calculer_jointnul($t, $having, $e)) |
|
| 969 | + && count($afrom[$t]) |
|
| 970 | + ) { |
|
| 971 | + $nfrom = reset($afrom[$t]); |
|
| 972 | + $nt = key($afrom[$t]); |
|
| 973 | + unset($from[$t]); |
|
| 974 | + $from[$nt] = $nfrom[1]; |
|
| 975 | + unset($afrom[$t][$nt]); |
|
| 976 | + $afrom[$nt] = $afrom[$t]; |
|
| 977 | + unset($afrom[$t]); |
|
| 978 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 979 | + $t = $nfrom[4]; |
|
| 980 | + $alias = ""; |
|
| 981 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 982 | + $oldcle = explode('.', $nfrom[6]); |
|
| 983 | + $oldcle = end($oldcle); |
|
| 984 | + $newcle = explode('.', $nfrom[4]); |
|
| 985 | + $newcle = end($newcle); |
|
| 986 | + if ($newcle != $oldcle) { |
|
| 987 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 988 | + // reprendre simplement ce AS |
|
| 989 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 990 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 991 | + $alias = ""; |
|
| 992 | + } else { |
|
| 993 | + $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 997 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 998 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 999 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 1000 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 1001 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 1002 | + } |
|
| 1003 | + $from = reinjecte_joint($afrom, $from); |
|
| 1004 | + } |
|
| 1005 | + $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 1006 | + $r = sql_select($select, $from, $where, |
|
| 1007 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 1008 | + unset($GLOBALS['debug']['aucasou']); |
|
| 1009 | + |
|
| 1010 | + return $r; |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | /** |
@@ -1018,20 +1018,20 @@ discard block |
||
| 1018 | 1018 | * @return string |
| 1019 | 1019 | */ |
| 1020 | 1020 | function calculer_where_to_string($v, $join = 'AND') { |
| 1021 | - if (empty($v)) { |
|
| 1022 | - return ''; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - if (!is_array($v)) { |
|
| 1026 | - return $v; |
|
| 1027 | - } else { |
|
| 1028 | - $exp = ""; |
|
| 1029 | - if (strtoupper($join) === 'AND') { |
|
| 1030 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1031 | - } else { |
|
| 1032 | - return $exp . join($join, $v); |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1021 | + if (empty($v)) { |
|
| 1022 | + return ''; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + if (!is_array($v)) { |
|
| 1026 | + return $v; |
|
| 1027 | + } else { |
|
| 1028 | + $exp = ""; |
|
| 1029 | + if (strtoupper($join) === 'AND') { |
|
| 1030 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1031 | + } else { |
|
| 1032 | + return $exp . join($join, $v); |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | |
@@ -1039,62 +1039,62 @@ discard block |
||
| 1039 | 1039 | |
| 1040 | 1040 | // http://code.spip.net/@calculer_jointnul |
| 1041 | 1041 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1042 | - if (!is_array($exp)) { |
|
| 1043 | - if ($equiv) { |
|
| 1044 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1045 | - } |
|
| 1046 | - |
|
| 1047 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1048 | - } else { |
|
| 1049 | - foreach ($exp as $v) { |
|
| 1050 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1051 | - return true; |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - return false; |
|
| 1056 | - } |
|
| 1042 | + if (!is_array($exp)) { |
|
| 1043 | + if ($equiv) { |
|
| 1044 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1045 | + } |
|
| 1046 | + |
|
| 1047 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1048 | + } else { |
|
| 1049 | + foreach ($exp as $v) { |
|
| 1050 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1051 | + return true; |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + return false; |
|
| 1056 | + } |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | // http://code.spip.net/@reinjecte_joint |
| 1060 | 1060 | function reinjecte_joint($afrom, $from) { |
| 1061 | - $from_synth = array(); |
|
| 1062 | - foreach ($from as $k => $v) { |
|
| 1063 | - $from_synth[$k] = $from[$k]; |
|
| 1064 | - if (isset($afrom[$k])) { |
|
| 1065 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1066 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1067 | - } |
|
| 1068 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1069 | - unset($afrom[$k]); |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return $from_synth; |
|
| 1061 | + $from_synth = array(); |
|
| 1062 | + foreach ($from as $k => $v) { |
|
| 1063 | + $from_synth[$k] = $from[$k]; |
|
| 1064 | + if (isset($afrom[$k])) { |
|
| 1065 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1066 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1067 | + } |
|
| 1068 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1069 | + unset($afrom[$k]); |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return $from_synth; |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | // http://code.spip.net/@remplacer_jointnul |
| 1077 | 1077 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1078 | - if (!is_array($exp)) { |
|
| 1079 | - return preg_replace($equiv, $cle, $exp); |
|
| 1080 | - } else { |
|
| 1081 | - foreach ($exp as $k => $v) { |
|
| 1082 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - return $exp; |
|
| 1086 | - } |
|
| 1078 | + if (!is_array($exp)) { |
|
| 1079 | + return preg_replace($equiv, $cle, $exp); |
|
| 1080 | + } else { |
|
| 1081 | + foreach ($exp as $k => $v) { |
|
| 1082 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + return $exp; |
|
| 1086 | + } |
|
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | // calcul du nom du squelette |
| 1090 | 1090 | // http://code.spip.net/@calculer_nom_fonction_squel |
| 1091 | 1091 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 1092 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1093 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1094 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - return $mime_type |
|
| 1098 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1099 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1092 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1093 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1094 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + return $mime_type |
|
| 1098 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1099 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1100 | 1100 | } |