@@ -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) { |
@@ -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); |
@@ -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 | // https://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 | // https://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 | // https://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 | } |
@@ -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) { |
@@ -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,505 +62,505 @@ 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 | - if (isset($this->command['sourcemode']) |
|
| 302 | - and in_array($this->command['sourcemode'], |
|
| 303 | - array('table', 'array', 'tableau')) |
|
| 304 | - ) { |
|
| 305 | - if (is_array($a = $src) |
|
| 306 | - or (is_string($a) |
|
| 307 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 308 | - and is_array($a = @unserialize($a))) |
|
| 309 | - ) { |
|
| 310 | - $this->tableau = $a; |
|
| 311 | - } |
|
| 312 | - } else { |
|
| 313 | - $data = $src; |
|
| 314 | - if (is_string($src)) { |
|
| 315 | - if (tester_url_absolue($src)) { |
|
| 316 | - include_spip('inc/distant'); |
|
| 317 | - $data = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 318 | - if (!$data) { |
|
| 319 | - throw new Exception("404"); |
|
| 320 | - } |
|
| 321 | - if (!isset($ttl)) { |
|
| 322 | - $ttl = 24 * 3600; |
|
| 323 | - } |
|
| 324 | - } elseif (@is_dir($src)) { |
|
| 325 | - $data = $src; |
|
| 326 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 327 | - $data = spip_file_get_contents($src); |
|
| 328 | - } |
|
| 329 | - if (!isset($ttl)) { |
|
| 330 | - $ttl = 10; |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if (!$this->err |
|
| 335 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 336 | - ) { |
|
| 337 | - $args = $this->command['source']; |
|
| 338 | - $args[0] = $data; |
|
| 339 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 340 | - $this->tableau = $a; |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if (!is_array($this->tableau)) { |
|
| 346 | - $this->err = true; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 350 | - $this->cache_set($cle, $ttl); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - } catch (Exception $e) { |
|
| 354 | - $e = $e->getMessage(); |
|
| 355 | - $err = sprintf("[%s, %s] $e", |
|
| 356 | - $src, |
|
| 357 | - $this->command['sourcemode']); |
|
| 358 | - erreur_squelette(array($err, array())); |
|
| 359 | - $this->err = true; |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 364 | - if ($this->err |
|
| 365 | - and $cache |
|
| 366 | - ) { |
|
| 367 | - $this->tableau = $cache['data']; |
|
| 368 | - $this->err = false; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Retourne un tableau donne depuis un critère liste |
|
| 375 | - * |
|
| 376 | - * Critère `{liste X1, X2, X3}` |
|
| 377 | - * |
|
| 378 | - * @see critere_DATA_liste_dist() |
|
| 379 | - * |
|
| 380 | - **/ |
|
| 381 | - protected function select_liste() { |
|
| 382 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 383 | - if (!isset($this->command['liste'][1])) { |
|
| 384 | - if (!is_array($this->command['liste'][0])) { |
|
| 385 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 386 | - } else { |
|
| 387 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - $this->tableau = $this->command['liste']; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Retourne un tableau donne depuis un critere liste |
|
| 395 | - * Critere {enum Xmin, Xmax} |
|
| 396 | - * |
|
| 397 | - **/ |
|
| 398 | - protected function select_enum() { |
|
| 399 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 400 | - if (!isset($this->command['enum'][1])) { |
|
| 401 | - if (!is_array($this->command['enum'][0])) { |
|
| 402 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 403 | - } else { |
|
| 404 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - if (count($this->command['enum']) >= 3) { |
|
| 408 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 409 | - array_shift($this->command['enum'])); |
|
| 410 | - } else { |
|
| 411 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 412 | - } |
|
| 413 | - $this->tableau = $enum; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 419 | - * {datapath query.results} |
|
| 420 | - * |
|
| 421 | - **/ |
|
| 422 | - protected function select_datapath() { |
|
| 423 | - $base = reset($this->command['datapath']); |
|
| 424 | - if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 425 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 426 | - if (!is_array($this->tableau)) { |
|
| 427 | - $this->tableau = array(); |
|
| 428 | - $this->err = true; |
|
| 429 | - spip_log("datapath '$base' absent"); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Ordonner les resultats |
|
| 436 | - * {par x} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_orderby() { |
|
| 440 | - $sortfunc = ''; |
|
| 441 | - $aleas = 0; |
|
| 442 | - foreach ($this->command['orderby'] as $tri) { |
|
| 443 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 444 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 445 | - $r = array_pad($r, 3, null); |
|
| 446 | - |
|
| 447 | - // tri par cle |
|
| 448 | - if ($r[1] == 'cle') { |
|
| 449 | - if (isset($r[2]) and $r[2]) { |
|
| 450 | - krsort($this->tableau); |
|
| 451 | - } else { |
|
| 452 | - ksort($this->tableau); |
|
| 453 | - } |
|
| 454 | - } # {par hasard} |
|
| 455 | - else { |
|
| 456 | - if ($r[1] == 'hasard') { |
|
| 457 | - $k = array_keys($this->tableau); |
|
| 458 | - shuffle($k); |
|
| 459 | - $v = array(); |
|
| 460 | - foreach ($k as $cle) { |
|
| 461 | - $v[$cle] = $this->tableau[$cle]; |
|
| 462 | - } |
|
| 463 | - $this->tableau = $v; |
|
| 464 | - } else { |
|
| 465 | - # {par valeur} |
|
| 466 | - if ($r[1] == 'valeur') { |
|
| 467 | - $tv = '%s'; |
|
| 468 | - } # {par valeur/xx/yy} ?? |
|
| 469 | - else { |
|
| 470 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 471 | - } |
|
| 472 | - $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 | + if (isset($this->command['sourcemode']) |
|
| 302 | + and in_array($this->command['sourcemode'], |
|
| 303 | + array('table', 'array', 'tableau')) |
|
| 304 | + ) { |
|
| 305 | + if (is_array($a = $src) |
|
| 306 | + or (is_string($a) |
|
| 307 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 308 | + and is_array($a = @unserialize($a))) |
|
| 309 | + ) { |
|
| 310 | + $this->tableau = $a; |
|
| 311 | + } |
|
| 312 | + } else { |
|
| 313 | + $data = $src; |
|
| 314 | + if (is_string($src)) { |
|
| 315 | + if (tester_url_absolue($src)) { |
|
| 316 | + include_spip('inc/distant'); |
|
| 317 | + $data = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 318 | + if (!$data) { |
|
| 319 | + throw new Exception("404"); |
|
| 320 | + } |
|
| 321 | + if (!isset($ttl)) { |
|
| 322 | + $ttl = 24 * 3600; |
|
| 323 | + } |
|
| 324 | + } elseif (@is_dir($src)) { |
|
| 325 | + $data = $src; |
|
| 326 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 327 | + $data = spip_file_get_contents($src); |
|
| 328 | + } |
|
| 329 | + if (!isset($ttl)) { |
|
| 330 | + $ttl = 10; |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if (!$this->err |
|
| 335 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 336 | + ) { |
|
| 337 | + $args = $this->command['source']; |
|
| 338 | + $args[0] = $data; |
|
| 339 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 340 | + $this->tableau = $a; |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if (!is_array($this->tableau)) { |
|
| 346 | + $this->err = true; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 350 | + $this->cache_set($cle, $ttl); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + } catch (Exception $e) { |
|
| 354 | + $e = $e->getMessage(); |
|
| 355 | + $err = sprintf("[%s, %s] $e", |
|
| 356 | + $src, |
|
| 357 | + $this->command['sourcemode']); |
|
| 358 | + erreur_squelette(array($err, array())); |
|
| 359 | + $this->err = true; |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 364 | + if ($this->err |
|
| 365 | + and $cache |
|
| 366 | + ) { |
|
| 367 | + $this->tableau = $cache['data']; |
|
| 368 | + $this->err = false; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Retourne un tableau donne depuis un critère liste |
|
| 375 | + * |
|
| 376 | + * Critère `{liste X1, X2, X3}` |
|
| 377 | + * |
|
| 378 | + * @see critere_DATA_liste_dist() |
|
| 379 | + * |
|
| 380 | + **/ |
|
| 381 | + protected function select_liste() { |
|
| 382 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 383 | + if (!isset($this->command['liste'][1])) { |
|
| 384 | + if (!is_array($this->command['liste'][0])) { |
|
| 385 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 386 | + } else { |
|
| 387 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + $this->tableau = $this->command['liste']; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Retourne un tableau donne depuis un critere liste |
|
| 395 | + * Critere {enum Xmin, Xmax} |
|
| 396 | + * |
|
| 397 | + **/ |
|
| 398 | + protected function select_enum() { |
|
| 399 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 400 | + if (!isset($this->command['enum'][1])) { |
|
| 401 | + if (!is_array($this->command['enum'][0])) { |
|
| 402 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 403 | + } else { |
|
| 404 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + if (count($this->command['enum']) >= 3) { |
|
| 408 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum']), |
|
| 409 | + array_shift($this->command['enum'])); |
|
| 410 | + } else { |
|
| 411 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 412 | + } |
|
| 413 | + $this->tableau = $enum; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 419 | + * {datapath query.results} |
|
| 420 | + * |
|
| 421 | + **/ |
|
| 422 | + protected function select_datapath() { |
|
| 423 | + $base = reset($this->command['datapath']); |
|
| 424 | + if (strlen($base = ltrim(trim($base), "/"))) { |
|
| 425 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 426 | + if (!is_array($this->tableau)) { |
|
| 427 | + $this->tableau = array(); |
|
| 428 | + $this->err = true; |
|
| 429 | + spip_log("datapath '$base' absent"); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Ordonner les resultats |
|
| 436 | + * {par x} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_orderby() { |
|
| 440 | + $sortfunc = ''; |
|
| 441 | + $aleas = 0; |
|
| 442 | + foreach ($this->command['orderby'] as $tri) { |
|
| 443 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 444 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 445 | + $r = array_pad($r, 3, null); |
|
| 446 | + |
|
| 447 | + // tri par cle |
|
| 448 | + if ($r[1] == 'cle') { |
|
| 449 | + if (isset($r[2]) and $r[2]) { |
|
| 450 | + krsort($this->tableau); |
|
| 451 | + } else { |
|
| 452 | + ksort($this->tableau); |
|
| 453 | + } |
|
| 454 | + } # {par hasard} |
|
| 455 | + else { |
|
| 456 | + if ($r[1] == 'hasard') { |
|
| 457 | + $k = array_keys($this->tableau); |
|
| 458 | + shuffle($k); |
|
| 459 | + $v = array(); |
|
| 460 | + foreach ($k as $cle) { |
|
| 461 | + $v[$cle] = $this->tableau[$cle]; |
|
| 462 | + } |
|
| 463 | + $this->tableau = $v; |
|
| 464 | + } else { |
|
| 465 | + # {par valeur} |
|
| 466 | + if ($r[1] == 'valeur') { |
|
| 467 | + $tv = '%s'; |
|
| 468 | + } # {par valeur/xx/yy} ?? |
|
| 469 | + else { |
|
| 470 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 471 | + } |
|
| 472 | + $sortfunc .= ' |
|
| 473 | 473 | $a = ' . sprintf($tv, '$aa') . '; |
| 474 | 474 | $b = ' . sprintf($tv, '$bb') . '; |
| 475 | 475 | if ($a <> $b) |
| 476 | 476 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if ($sortfunc) { |
|
| 483 | - $sortfunc .= "\n return 0;"; |
|
| 484 | - uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 485 | - return eval($sortfunc); |
|
| 486 | - }); |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Grouper les resultats |
|
| 493 | - * {fusion /x/y/z} |
|
| 494 | - * |
|
| 495 | - **/ |
|
| 496 | - protected function select_groupby() { |
|
| 497 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 498 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 499 | - $vu = array(); |
|
| 500 | - foreach ($this->tableau as $k => $v) { |
|
| 501 | - $val = table_valeur($v, $fusion); |
|
| 502 | - if (isset($vu[$val])) { |
|
| 503 | - unset($this->tableau[$k]); |
|
| 504 | - } else { |
|
| 505 | - $vu[$val] = true; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * L'iterateur est-il encore valide ? |
|
| 514 | - * |
|
| 515 | - * @return bool |
|
| 516 | - */ |
|
| 517 | - public function valid() { |
|
| 518 | - return !is_null($this->cle); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Retourner la valeur |
|
| 523 | - * |
|
| 524 | - * @return null |
|
| 525 | - */ |
|
| 526 | - public function current() { |
|
| 527 | - return $this->valeur; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Retourner la cle |
|
| 532 | - * |
|
| 533 | - * @return null |
|
| 534 | - */ |
|
| 535 | - public function key() { |
|
| 536 | - return $this->cle; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Passer a la valeur suivante |
|
| 541 | - * |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - public function next() { |
|
| 545 | - if ($this->valid()) { |
|
| 546 | - $this->cle = key($this->tableau); |
|
| 547 | - $this->valeur = current($this->tableau); |
|
| 548 | - next($this->tableau); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Compter le nombre total de resultats |
|
| 554 | - * |
|
| 555 | - * @return int |
|
| 556 | - */ |
|
| 557 | - public function count() { |
|
| 558 | - if (is_null($this->total)) { |
|
| 559 | - $this->total = count($this->tableau); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $this->total; |
|
| 563 | - } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if ($sortfunc) { |
|
| 483 | + $sortfunc .= "\n return 0;"; |
|
| 484 | + uasort($this->tableau, function($aa, $bb) use ($sortfunc) { |
|
| 485 | + return eval($sortfunc); |
|
| 486 | + }); |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Grouper les resultats |
|
| 493 | + * {fusion /x/y/z} |
|
| 494 | + * |
|
| 495 | + **/ |
|
| 496 | + protected function select_groupby() { |
|
| 497 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 498 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 499 | + $vu = array(); |
|
| 500 | + foreach ($this->tableau as $k => $v) { |
|
| 501 | + $val = table_valeur($v, $fusion); |
|
| 502 | + if (isset($vu[$val])) { |
|
| 503 | + unset($this->tableau[$k]); |
|
| 504 | + } else { |
|
| 505 | + $vu[$val] = true; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * L'iterateur est-il encore valide ? |
|
| 514 | + * |
|
| 515 | + * @return bool |
|
| 516 | + */ |
|
| 517 | + public function valid() { |
|
| 518 | + return !is_null($this->cle); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Retourner la valeur |
|
| 523 | + * |
|
| 524 | + * @return null |
|
| 525 | + */ |
|
| 526 | + public function current() { |
|
| 527 | + return $this->valeur; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Retourner la cle |
|
| 532 | + * |
|
| 533 | + * @return null |
|
| 534 | + */ |
|
| 535 | + public function key() { |
|
| 536 | + return $this->cle; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Passer a la valeur suivante |
|
| 541 | + * |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + public function next() { |
|
| 545 | + if ($this->valid()) { |
|
| 546 | + $this->cle = key($this->tableau); |
|
| 547 | + $this->valeur = current($this->tableau); |
|
| 548 | + next($this->tableau); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Compter le nombre total de resultats |
|
| 554 | + * |
|
| 555 | + * @return int |
|
| 556 | + */ |
|
| 557 | + public function count() { |
|
| 558 | + if (is_null($this->total)) { |
|
| 559 | + $this->total = count($this->tableau); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $this->total; |
|
| 563 | + } |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /* |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @return array |
| 575 | 575 | */ |
| 576 | 576 | function inc_file_to_array_dist($data) { |
| 577 | - return preg_split('/\r?\n/', $data); |
|
| 577 | + return preg_split('/\r?\n/', $data); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -583,9 +583,9 @@ discard block |
||
| 583 | 583 | * @return array |
| 584 | 584 | */ |
| 585 | 585 | function inc_plugins_to_array_dist() { |
| 586 | - include_spip('inc/plugin'); |
|
| 586 | + include_spip('inc/plugin'); |
|
| 587 | 587 | |
| 588 | - return liste_chemin_plugin_actifs(); |
|
| 588 | + return liste_chemin_plugin_actifs(); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | /** |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * @return array |
| 596 | 596 | */ |
| 597 | 597 | function inc_xml_to_array_dist($data) { |
| 598 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 598 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -607,14 +607,14 @@ discard block |
||
| 607 | 607 | * |
| 608 | 608 | */ |
| 609 | 609 | function inc_object_to_array($object) { |
| 610 | - if (!is_object($object) && !is_array($object)) { |
|
| 611 | - return $object; |
|
| 612 | - } |
|
| 613 | - if (is_object($object)) { |
|
| 614 | - $object = get_object_vars($object); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return array_map('inc_object_to_array', $object); |
|
| 610 | + if (!is_object($object) && !is_array($object)) { |
|
| 611 | + return $object; |
|
| 612 | + } |
|
| 613 | + if (is_object($object)) { |
|
| 614 | + $object = get_object_vars($object); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return array_map('inc_object_to_array', $object); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -624,20 +624,20 @@ discard block |
||
| 624 | 624 | * @return array|bool |
| 625 | 625 | */ |
| 626 | 626 | function inc_sql_to_array_dist($data) { |
| 627 | - # sortir le connecteur de $data |
|
| 628 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 629 | - $serveur = (string)$v[1]; |
|
| 630 | - $req = trim($v[2]); |
|
| 631 | - if ($s = sql_query($req, $serveur)) { |
|
| 632 | - $r = array(); |
|
| 633 | - while ($t = sql_fetch($s)) { |
|
| 634 | - $r[] = $t; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - return $r; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return false; |
|
| 627 | + # sortir le connecteur de $data |
|
| 628 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 629 | + $serveur = (string)$v[1]; |
|
| 630 | + $req = trim($v[2]); |
|
| 631 | + if ($s = sql_query($req, $serveur)) { |
|
| 632 | + $r = array(); |
|
| 633 | + while ($t = sql_fetch($s)) { |
|
| 634 | + $r[] = $t; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + return $r; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return false; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -647,9 +647,9 @@ discard block |
||
| 647 | 647 | * @return array|bool |
| 648 | 648 | */ |
| 649 | 649 | function inc_json_to_array_dist($data) { |
| 650 | - if (is_array($json = json_decode($data, true))) { |
|
| 651 | - return (array)$json; |
|
| 652 | - } |
|
| 650 | + if (is_array($json = json_decode($data, true))) { |
|
| 651 | + return (array)$json; |
|
| 652 | + } |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -659,30 +659,30 @@ discard block |
||
| 659 | 659 | * @return array|bool |
| 660 | 660 | */ |
| 661 | 661 | function inc_csv_to_array_dist($data) { |
| 662 | - include_spip('inc/csv'); |
|
| 663 | - list($entete, $csv) = analyse_csv($data); |
|
| 664 | - array_unshift($csv, $entete); |
|
| 665 | - |
|
| 666 | - include_spip('inc/charsets'); |
|
| 667 | - $i = 1; |
|
| 668 | - foreach ($entete as $k => $v) { |
|
| 669 | - if (trim($v) == "") { |
|
| 670 | - $v = "col" . $i; |
|
| 671 | - } // reperer des eventuelles cases vides |
|
| 672 | - if (is_numeric($v) and $v < 0) { |
|
| 673 | - $v = "__" . $v; |
|
| 674 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 675 | - if (is_numeric($v)) { |
|
| 676 | - $v = "_" . $v; |
|
| 677 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 678 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 679 | - foreach ($csv as &$item) { |
|
| 680 | - $item[$v] = &$item[$k]; |
|
| 681 | - } |
|
| 682 | - $i++; |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $csv; |
|
| 662 | + include_spip('inc/csv'); |
|
| 663 | + list($entete, $csv) = analyse_csv($data); |
|
| 664 | + array_unshift($csv, $entete); |
|
| 665 | + |
|
| 666 | + include_spip('inc/charsets'); |
|
| 667 | + $i = 1; |
|
| 668 | + foreach ($entete as $k => $v) { |
|
| 669 | + if (trim($v) == "") { |
|
| 670 | + $v = "col" . $i; |
|
| 671 | + } // reperer des eventuelles cases vides |
|
| 672 | + if (is_numeric($v) and $v < 0) { |
|
| 673 | + $v = "__" . $v; |
|
| 674 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 675 | + if (is_numeric($v)) { |
|
| 676 | + $v = "_" . $v; |
|
| 677 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 678 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 679 | + foreach ($csv as &$item) { |
|
| 680 | + $item[$v] = &$item[$k]; |
|
| 681 | + } |
|
| 682 | + $i++; |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $csv; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | /** |
@@ -692,12 +692,12 @@ discard block |
||
| 692 | 692 | * @return array|bool |
| 693 | 693 | */ |
| 694 | 694 | function inc_rss_to_array_dist($data) { |
| 695 | - include_spip('inc/syndic'); |
|
| 696 | - if (is_array($rss = analyser_backend($data))) { |
|
| 697 | - $tableau = $rss; |
|
| 698 | - } |
|
| 695 | + include_spip('inc/syndic'); |
|
| 696 | + if (is_array($rss = analyser_backend($data))) { |
|
| 697 | + $tableau = $rss; |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - return $tableau; |
|
| 700 | + return $tableau; |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | /** |
@@ -707,9 +707,9 @@ discard block |
||
| 707 | 707 | * @return array|bool |
| 708 | 708 | */ |
| 709 | 709 | function inc_atom_to_array_dist($data) { |
| 710 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 710 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 711 | 711 | |
| 712 | - return $rss_to_array($data); |
|
| 712 | + return $rss_to_array($data); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /** |
@@ -720,11 +720,11 @@ discard block |
||
| 720 | 720 | * @return array|bool |
| 721 | 721 | */ |
| 722 | 722 | function inc_glob_to_array_dist($data) { |
| 723 | - $a = glob($data, |
|
| 724 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 725 | - ); |
|
| 723 | + $a = glob($data, |
|
| 724 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 725 | + ); |
|
| 726 | 726 | |
| 727 | - return $a ? $a : array(); |
|
| 727 | + return $a ? $a : array(); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -735,14 +735,14 @@ discard block |
||
| 735 | 735 | * @throws Exception |
| 736 | 736 | */ |
| 737 | 737 | function inc_yaml_to_array_dist($data) { |
| 738 | - include_spip('inc/yaml-mini'); |
|
| 739 | - if (!function_exists("yaml_decode")) { |
|
| 740 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 738 | + include_spip('inc/yaml-mini'); |
|
| 739 | + if (!function_exists("yaml_decode")) { |
|
| 740 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 741 | 741 | |
| 742 | - return false; |
|
| 743 | - } |
|
| 742 | + return false; |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - return yaml_decode($data); |
|
| 745 | + return yaml_decode($data); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * @return array|bool |
| 758 | 758 | */ |
| 759 | 759 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 760 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 760 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -769,23 +769,23 @@ discard block |
||
| 769 | 769 | * @return array|bool |
| 770 | 770 | */ |
| 771 | 771 | function inc_ls_to_array_dist($data) { |
| 772 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 773 | - $a = $glob_to_array($data); |
|
| 774 | - foreach ($a as &$v) { |
|
| 775 | - $b = (array)@stat($v); |
|
| 776 | - foreach ($b as $k => $ignore) { |
|
| 777 | - if (is_numeric($k)) { |
|
| 778 | - unset($b[$k]); |
|
| 779 | - } |
|
| 780 | - } |
|
| 781 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 782 | - $v = array_merge( |
|
| 783 | - pathinfo($v), |
|
| 784 | - $b |
|
| 785 | - ); |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - return $a; |
|
| 772 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 773 | + $a = $glob_to_array($data); |
|
| 774 | + foreach ($a as &$v) { |
|
| 775 | + $b = (array)@stat($v); |
|
| 776 | + foreach ($b as $k => $ignore) { |
|
| 777 | + if (is_numeric($k)) { |
|
| 778 | + unset($b[$k]); |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | + $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 782 | + $v = array_merge( |
|
| 783 | + pathinfo($v), |
|
| 784 | + $b |
|
| 785 | + ); |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + return $a; |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -795,24 +795,24 @@ discard block |
||
| 795 | 795 | * @return array|bool |
| 796 | 796 | */ |
| 797 | 797 | function XMLObjectToArray($object) { |
| 798 | - $xml_array = array(); |
|
| 799 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 800 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 801 | - $key .= '-' . uniqid(); |
|
| 802 | - } |
|
| 803 | - $vars = get_object_vars($object->current()); |
|
| 804 | - if (isset($vars['@attributes'])) { |
|
| 805 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 806 | - $xml_array[$key][$k] = $v; |
|
| 807 | - } |
|
| 808 | - } |
|
| 809 | - if ($object->hasChildren()) { |
|
| 810 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 811 | - $object->current()); |
|
| 812 | - } else { |
|
| 813 | - $xml_array[$key][] = strval($object->current()); |
|
| 814 | - } |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - return $xml_array; |
|
| 798 | + $xml_array = array(); |
|
| 799 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 800 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 801 | + $key .= '-' . uniqid(); |
|
| 802 | + } |
|
| 803 | + $vars = get_object_vars($object->current()); |
|
| 804 | + if (isset($vars['@attributes'])) { |
|
| 805 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 806 | + $xml_array[$key][$k] = $v; |
|
| 807 | + } |
|
| 808 | + } |
|
| 809 | + if ($object->hasChildren()) { |
|
| 810 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 811 | + $object->current()); |
|
| 812 | + } else { |
|
| 813 | + $xml_array[$key][] = strval($object->current()); |
|
| 814 | + } |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + return $xml_array; |
|
| 818 | 818 | } |
@@ -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); |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | if (!$this->err |
| 335 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 335 | + and $data_to_array = charger_fonction($this->command['sourcemode'].'_to_array', 'inc', true) |
|
| 336 | 336 | ) { |
| 337 | 337 | $args = $this->command['source']; |
| 338 | 338 | $args[0] = $data; |
@@ -467,13 +467,13 @@ discard block |
||
| 467 | 467 | $tv = '%s'; |
| 468 | 468 | } # {par valeur/xx/yy} ?? |
| 469 | 469 | else { |
| 470 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 470 | + $tv = 'table_valeur(%s, '.var_export($r[1], true).')'; |
|
| 471 | 471 | } |
| 472 | 472 | $sortfunc .= ' |
| 473 | - $a = ' . sprintf($tv, '$aa') . '; |
|
| 474 | - $b = ' . sprintf($tv, '$bb') . '; |
|
| 473 | + $a = ' . sprintf($tv, '$aa').'; |
|
| 474 | + $b = ' . sprintf($tv, '$bb').'; |
|
| 475 | 475 | if ($a <> $b) |
| 476 | - return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
|
| 476 | + return ($a ' . (!empty($r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
|
| 477 | 477 | } |
| 478 | 478 | } |
| 479 | 479 | } |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | function inc_sql_to_array_dist($data) { |
| 627 | 627 | # sortir le connecteur de $data |
| 628 | 628 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 629 | - $serveur = (string)$v[1]; |
|
| 629 | + $serveur = (string) $v[1]; |
|
| 630 | 630 | $req = trim($v[2]); |
| 631 | 631 | if ($s = sql_query($req, $serveur)) { |
| 632 | 632 | $r = array(); |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | */ |
| 649 | 649 | function inc_json_to_array_dist($data) { |
| 650 | 650 | if (is_array($json = json_decode($data, true))) { |
| 651 | - return (array)$json; |
|
| 651 | + return (array) $json; |
|
| 652 | 652 | } |
| 653 | 653 | } |
| 654 | 654 | |
@@ -667,13 +667,13 @@ discard block |
||
| 667 | 667 | $i = 1; |
| 668 | 668 | foreach ($entete as $k => $v) { |
| 669 | 669 | if (trim($v) == "") { |
| 670 | - $v = "col" . $i; |
|
| 670 | + $v = "col".$i; |
|
| 671 | 671 | } // reperer des eventuelles cases vides |
| 672 | 672 | if (is_numeric($v) and $v < 0) { |
| 673 | - $v = "__" . $v; |
|
| 673 | + $v = "__".$v; |
|
| 674 | 674 | } // ne pas risquer d'ecraser une cle numerique |
| 675 | 675 | if (is_numeric($v)) { |
| 676 | - $v = "_" . $v; |
|
| 676 | + $v = "_".$v; |
|
| 677 | 677 | } // ne pas risquer d'ecraser une cle numerique |
| 678 | 678 | $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
| 679 | 679 | foreach ($csv as &$item) { |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * @return array|bool |
| 758 | 758 | */ |
| 759 | 759 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 760 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 760 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -772,13 +772,13 @@ discard block |
||
| 772 | 772 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 773 | 773 | $a = $glob_to_array($data); |
| 774 | 774 | foreach ($a as &$v) { |
| 775 | - $b = (array)@stat($v); |
|
| 775 | + $b = (array) @stat($v); |
|
| 776 | 776 | foreach ($b as $k => $ignore) { |
| 777 | 777 | if (is_numeric($k)) { |
| 778 | 778 | unset($b[$k]); |
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | - $b['file'] = preg_replace('`/$`','',$v) ; |
|
| 781 | + $b['file'] = preg_replace('`/$`', '', $v); |
|
| 782 | 782 | $v = array_merge( |
| 783 | 783 | pathinfo($v), |
| 784 | 784 | $b |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | $xml_array = array(); |
| 799 | 799 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 800 | 800 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 801 | - $key .= '-' . uniqid(); |
|
| 801 | + $key .= '-'.uniqid(); |
|
| 802 | 802 | } |
| 803 | 803 | $vars = get_object_vars($object->current()); |
| 804 | 804 | if (isset($vars['@attributes'])) { |
@@ -457,6 +457,10 @@ |
||
| 457 | 457 | * aller a la position $n en parcourant |
| 458 | 458 | * un par un tous les elements |
| 459 | 459 | */ |
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @param integer $n |
|
| 463 | + */ |
|
| 460 | 464 | private function seek_loop($n) { |
| 461 | 465 | if ($this->pos > $n) { |
| 462 | 466 | $this->rewind(); |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -22,578 +22,578 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | 24 | class IterFactory { |
| 25 | - public static function create($iterateur, $command, $info = null) { |
|
| 26 | - |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (count($a)) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | - or !class_exists($class) |
|
| 86 | - ) { |
|
| 87 | - die("Iterateur $iterateur non trouvé"); |
|
| 88 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | - # $iter = new EmptyIterator(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - $iter = new $class($command, $info); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return new IterDecorator($iter, $command, $info); |
|
| 96 | - } |
|
| 25 | + public static function create($iterateur, $command, $info = null) { |
|
| 26 | + |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (count($a)) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = "Iterateur" . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | + or !class_exists($class) |
|
| 86 | + ) { |
|
| 87 | + die("Iterateur $iterateur non trouvé"); |
|
| 88 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | + # $iter = new EmptyIterator(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + $iter = new $class($command, $info); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return new IterDecorator($iter, $command, $info); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | class IterDecorator extends FilterIterator { |
| 101 | - private $iter; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Conditions de filtrage |
|
| 105 | - * ie criteres de selection |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - */ |
|
| 109 | - protected $filtre = array(); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | - * |
|
| 114 | - * @var string |
|
| 115 | - */ |
|
| 116 | - protected $func_filtre = null; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Critere {offset, limit} |
|
| 120 | - * |
|
| 121 | - * @var int |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - protected $offset = null; |
|
| 125 | - protected $limit = null; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * nombre d'elements recuperes depuis la position 0, |
|
| 129 | - * en tenant compte des filtres |
|
| 130 | - * |
|
| 131 | - * @var int |
|
| 132 | - */ |
|
| 133 | - protected $fetched = 0; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Y a t'il une erreur ? |
|
| 137 | - * |
|
| 138 | - * @var bool |
|
| 139 | - **/ |
|
| 140 | - protected $err = false; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Drapeau a activer en cas d'echec |
|
| 144 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | - */ |
|
| 146 | - public function err() { |
|
| 147 | - if (method_exists($this->iter, 'err')) { |
|
| 148 | - return $this->iter->err(); |
|
| 149 | - } |
|
| 150 | - if (property_exists($this->iter, 'err')) { |
|
| 151 | - return $this->iter->err; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | - parent::__construct($iter); |
|
| 159 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | - |
|
| 161 | - // recuperer l'iterateur transmis |
|
| 162 | - $this->iter = $this->getInnerIterator(); |
|
| 163 | - $this->command = $command; |
|
| 164 | - $this->info = $info; |
|
| 165 | - $this->pos = 0; |
|
| 166 | - $this->fetched = 0; |
|
| 167 | - |
|
| 168 | - // chercher la liste des champs a retourner par |
|
| 169 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | - $this->calculer_select(); |
|
| 172 | - $this->calculer_filtres(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | - if (isset($this->iter->err)) { |
|
| 177 | - $this->err = $this->iter->err; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | - //$this->total = $this->count(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - // calcule les elements a retournes par fetch() |
|
| 186 | - // enleve les elements inutiles du select() |
|
| 187 | - // |
|
| 188 | - private function calculer_select() { |
|
| 189 | - if ($select = &$this->command['select']) { |
|
| 190 | - foreach ($select as $s) { |
|
| 191 | - // /!\ $s = '.nom' |
|
| 192 | - if ($s[0] == '.') { |
|
| 193 | - $s = substr($s, 1); |
|
| 194 | - } |
|
| 195 | - $this->select[] = $s; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // recuperer la valeur d'une balise #X |
|
| 201 | - // en fonction des methodes |
|
| 202 | - // et proprietes disponibles |
|
| 203 | - public function get_select($nom) { |
|
| 204 | - if (is_object($this->iter) |
|
| 205 | - and method_exists($this->iter, $nom) |
|
| 206 | - ) { |
|
| 207 | - try { |
|
| 208 | - return $this->iter->$nom(); |
|
| 209 | - } catch (Exception $e) { |
|
| 210 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | - |
|
| 214 | - return ''; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - /* |
|
| 101 | + private $iter; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Conditions de filtrage |
|
| 105 | + * ie criteres de selection |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + */ |
|
| 109 | + protected $filtre = array(); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | + * |
|
| 114 | + * @var string |
|
| 115 | + */ |
|
| 116 | + protected $func_filtre = null; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Critere {offset, limit} |
|
| 120 | + * |
|
| 121 | + * @var int |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + protected $offset = null; |
|
| 125 | + protected $limit = null; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * nombre d'elements recuperes depuis la position 0, |
|
| 129 | + * en tenant compte des filtres |
|
| 130 | + * |
|
| 131 | + * @var int |
|
| 132 | + */ |
|
| 133 | + protected $fetched = 0; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Y a t'il une erreur ? |
|
| 137 | + * |
|
| 138 | + * @var bool |
|
| 139 | + **/ |
|
| 140 | + protected $err = false; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Drapeau a activer en cas d'echec |
|
| 144 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | + */ |
|
| 146 | + public function err() { |
|
| 147 | + if (method_exists($this->iter, 'err')) { |
|
| 148 | + return $this->iter->err(); |
|
| 149 | + } |
|
| 150 | + if (property_exists($this->iter, 'err')) { |
|
| 151 | + return $this->iter->err; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | + parent::__construct($iter); |
|
| 159 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | + |
|
| 161 | + // recuperer l'iterateur transmis |
|
| 162 | + $this->iter = $this->getInnerIterator(); |
|
| 163 | + $this->command = $command; |
|
| 164 | + $this->info = $info; |
|
| 165 | + $this->pos = 0; |
|
| 166 | + $this->fetched = 0; |
|
| 167 | + |
|
| 168 | + // chercher la liste des champs a retourner par |
|
| 169 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | + $this->calculer_select(); |
|
| 172 | + $this->calculer_filtres(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | + if (isset($this->iter->err)) { |
|
| 177 | + $this->err = $this->iter->err; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | + //$this->total = $this->count(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + // calcule les elements a retournes par fetch() |
|
| 186 | + // enleve les elements inutiles du select() |
|
| 187 | + // |
|
| 188 | + private function calculer_select() { |
|
| 189 | + if ($select = &$this->command['select']) { |
|
| 190 | + foreach ($select as $s) { |
|
| 191 | + // /!\ $s = '.nom' |
|
| 192 | + if ($s[0] == '.') { |
|
| 193 | + $s = substr($s, 1); |
|
| 194 | + } |
|
| 195 | + $this->select[] = $s; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // recuperer la valeur d'une balise #X |
|
| 201 | + // en fonction des methodes |
|
| 202 | + // et proprietes disponibles |
|
| 203 | + public function get_select($nom) { |
|
| 204 | + if (is_object($this->iter) |
|
| 205 | + and method_exists($this->iter, $nom) |
|
| 206 | + ) { |
|
| 207 | + try { |
|
| 208 | + return $this->iter->$nom(); |
|
| 209 | + } catch (Exception $e) { |
|
| 210 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | + |
|
| 214 | + return ''; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + /* |
|
| 218 | 218 | if (property_exists($this->iter, $nom)) { |
| 219 | 219 | return $this->iter->$nom; |
| 220 | 220 | }*/ |
| 221 | - // cle et valeur par defaut |
|
| 222 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | - if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | - and method_exists($this, $nom) |
|
| 225 | - ) { |
|
| 226 | - return $this->$nom(); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Par defaut chercher en xpath dans la valeur() |
|
| 230 | - return table_valeur($this->valeur(), $nom, null); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - private function calculer_filtres() { |
|
| 235 | - |
|
| 236 | - // Issu de calculer_select() de public/composer L.519 |
|
| 237 | - // TODO: externaliser... |
|
| 238 | - // |
|
| 239 | - // retirer les criteres vides: |
|
| 240 | - // {X ?} avec X absent de l'URL |
|
| 241 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | - if ($where = &$this->command['where']) { |
|
| 244 | - foreach ($where as $k => $v) { |
|
| 245 | - if (is_array($v)) { |
|
| 246 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | - $op = false; |
|
| 248 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | - $op = false; |
|
| 250 | - } else { |
|
| 251 | - $op = $v[0] ? $v[0] : $v; |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - $op = $v; |
|
| 255 | - } |
|
| 256 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | - unset($where[$k]); |
|
| 258 | - } |
|
| 259 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 261 | - $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 262 | - unset($op, $where[$k]); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - foreach ($where as $k => $v) { |
|
| 266 | - // 3 possibilites : count($v) = |
|
| 267 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 268 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 269 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 270 | - |
|
| 271 | - // 1 : forcement traite par un critere, on passe |
|
| 272 | - if (count($v) == 1) { |
|
| 273 | - continue; |
|
| 274 | - } |
|
| 275 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 276 | - $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 277 | - } |
|
| 278 | - if (count($v) == 3) { |
|
| 279 | - $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // critere {2,7} |
|
| 285 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 286 | - $limit = explode(',', $this->command['limit']); |
|
| 287 | - $this->offset = $limit[0]; |
|
| 288 | - $this->limit = $limit[1]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // Creer la fonction de filtrage sur $this |
|
| 292 | - if ($this->filtre) { |
|
| 293 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | - $this->func_filtre = function () use ($filtres) { |
|
| 295 | - return eval($filtres); |
|
| 296 | - }; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 302 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 303 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 304 | - return; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 308 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 309 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 310 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 311 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 312 | - |
|
| 313 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 314 | - # return; |
|
| 315 | - |
|
| 316 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 317 | - |
|
| 318 | - $filtre = ''; |
|
| 319 | - |
|
| 320 | - if ($op == 'REGEXP') { |
|
| 321 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 322 | - $op = ''; |
|
| 323 | - } else { |
|
| 324 | - if ($op == 'LIKE') { |
|
| 325 | - $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 326 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 327 | - $op = ''; |
|
| 328 | - } else { |
|
| 329 | - if ($op == '=') { |
|
| 330 | - $op = '=='; |
|
| 331 | - } else { |
|
| 332 | - if ($op == 'IN') { |
|
| 333 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 334 | - $op = ''; |
|
| 335 | - } else { |
|
| 336 | - if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 337 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 338 | - $op = ''; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ($op) { |
|
| 346 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if ($not) { |
|
| 350 | - $filtre = "!($filtre)"; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if ($filtre) { |
|
| 354 | - $this->filtre[] = $filtre; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - public function next() { |
|
| 360 | - $this->pos++; |
|
| 361 | - parent::next(); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * revient au depart |
|
| 366 | - * |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - public function rewind() { |
|
| 370 | - $this->pos = 0; |
|
| 371 | - $this->fetched = 0; |
|
| 372 | - parent::rewind(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - # Extension SPIP des iterateurs PHP |
|
| 377 | - /** |
|
| 378 | - * type de l'iterateur |
|
| 379 | - * |
|
| 380 | - * @var string |
|
| 381 | - */ |
|
| 382 | - protected $type; |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * parametres de l'iterateur |
|
| 386 | - * |
|
| 387 | - * @var array |
|
| 388 | - */ |
|
| 389 | - protected $command; |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * infos de compilateur |
|
| 393 | - * |
|
| 394 | - * @var array |
|
| 395 | - */ |
|
| 396 | - protected $info; |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * position courante de l'iterateur |
|
| 400 | - * |
|
| 401 | - * @var int |
|
| 402 | - */ |
|
| 403 | - protected $pos = null; |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * nombre total resultats dans l'iterateur |
|
| 407 | - * |
|
| 408 | - * @var int |
|
| 409 | - */ |
|
| 410 | - protected $total = null; |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * nombre maximal de recherche pour $total |
|
| 414 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 415 | - */ |
|
| 416 | - protected $max = 100000; |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Liste des champs a inserer dans les $row |
|
| 421 | - * retournes par ->fetch() |
|
| 422 | - */ |
|
| 423 | - protected $select = array(); |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * aller a la position absolue n, |
|
| 428 | - * comptee depuis le debut |
|
| 429 | - * |
|
| 430 | - * @param int $n |
|
| 431 | - * absolute pos |
|
| 432 | - * @param string $continue |
|
| 433 | - * param for sql_ api |
|
| 434 | - * @return bool |
|
| 435 | - * success or fail if not implemented |
|
| 436 | - */ |
|
| 437 | - public function seek($n = 0, $continue = null) { |
|
| 438 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 439 | - $this->seek_loop($n); |
|
| 440 | - } |
|
| 441 | - $this->pos = $n; |
|
| 442 | - $this->fetched = $n; |
|
| 443 | - |
|
| 444 | - return true; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /* |
|
| 221 | + // cle et valeur par defaut |
|
| 222 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | + if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | + and method_exists($this, $nom) |
|
| 225 | + ) { |
|
| 226 | + return $this->$nom(); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Par defaut chercher en xpath dans la valeur() |
|
| 230 | + return table_valeur($this->valeur(), $nom, null); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + private function calculer_filtres() { |
|
| 235 | + |
|
| 236 | + // Issu de calculer_select() de public/composer L.519 |
|
| 237 | + // TODO: externaliser... |
|
| 238 | + // |
|
| 239 | + // retirer les criteres vides: |
|
| 240 | + // {X ?} avec X absent de l'URL |
|
| 241 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | + if ($where = &$this->command['where']) { |
|
| 244 | + foreach ($where as $k => $v) { |
|
| 245 | + if (is_array($v)) { |
|
| 246 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | + $op = false; |
|
| 248 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | + $op = false; |
|
| 250 | + } else { |
|
| 251 | + $op = $v[0] ? $v[0] : $v; |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + $op = $v; |
|
| 255 | + } |
|
| 256 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | + unset($where[$k]); |
|
| 258 | + } |
|
| 259 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 261 | + $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 262 | + unset($op, $where[$k]); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + foreach ($where as $k => $v) { |
|
| 266 | + // 3 possibilites : count($v) = |
|
| 267 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 268 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 269 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 270 | + |
|
| 271 | + // 1 : forcement traite par un critere, on passe |
|
| 272 | + if (count($v) == 1) { |
|
| 273 | + continue; |
|
| 274 | + } |
|
| 275 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 276 | + $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 277 | + } |
|
| 278 | + if (count($v) == 3) { |
|
| 279 | + $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // critere {2,7} |
|
| 285 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 286 | + $limit = explode(',', $this->command['limit']); |
|
| 287 | + $this->offset = $limit[0]; |
|
| 288 | + $this->limit = $limit[1]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // Creer la fonction de filtrage sur $this |
|
| 292 | + if ($this->filtre) { |
|
| 293 | + $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | + $this->func_filtre = function () use ($filtres) { |
|
| 295 | + return eval($filtres); |
|
| 296 | + }; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 302 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 303 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 304 | + return; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 308 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 309 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 310 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 311 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 312 | + |
|
| 313 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 314 | + # return; |
|
| 315 | + |
|
| 316 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 317 | + |
|
| 318 | + $filtre = ''; |
|
| 319 | + |
|
| 320 | + if ($op == 'REGEXP') { |
|
| 321 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 322 | + $op = ''; |
|
| 323 | + } else { |
|
| 324 | + if ($op == 'LIKE') { |
|
| 325 | + $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 326 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 327 | + $op = ''; |
|
| 328 | + } else { |
|
| 329 | + if ($op == '=') { |
|
| 330 | + $op = '=='; |
|
| 331 | + } else { |
|
| 332 | + if ($op == 'IN') { |
|
| 333 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 334 | + $op = ''; |
|
| 335 | + } else { |
|
| 336 | + if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 337 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 338 | + $op = ''; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ($op) { |
|
| 346 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if ($not) { |
|
| 350 | + $filtre = "!($filtre)"; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if ($filtre) { |
|
| 354 | + $this->filtre[] = $filtre; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + public function next() { |
|
| 360 | + $this->pos++; |
|
| 361 | + parent::next(); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * revient au depart |
|
| 366 | + * |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + public function rewind() { |
|
| 370 | + $this->pos = 0; |
|
| 371 | + $this->fetched = 0; |
|
| 372 | + parent::rewind(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + # Extension SPIP des iterateurs PHP |
|
| 377 | + /** |
|
| 378 | + * type de l'iterateur |
|
| 379 | + * |
|
| 380 | + * @var string |
|
| 381 | + */ |
|
| 382 | + protected $type; |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * parametres de l'iterateur |
|
| 386 | + * |
|
| 387 | + * @var array |
|
| 388 | + */ |
|
| 389 | + protected $command; |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * infos de compilateur |
|
| 393 | + * |
|
| 394 | + * @var array |
|
| 395 | + */ |
|
| 396 | + protected $info; |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * position courante de l'iterateur |
|
| 400 | + * |
|
| 401 | + * @var int |
|
| 402 | + */ |
|
| 403 | + protected $pos = null; |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * nombre total resultats dans l'iterateur |
|
| 407 | + * |
|
| 408 | + * @var int |
|
| 409 | + */ |
|
| 410 | + protected $total = null; |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * nombre maximal de recherche pour $total |
|
| 414 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 415 | + */ |
|
| 416 | + protected $max = 100000; |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Liste des champs a inserer dans les $row |
|
| 421 | + * retournes par ->fetch() |
|
| 422 | + */ |
|
| 423 | + protected $select = array(); |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * aller a la position absolue n, |
|
| 428 | + * comptee depuis le debut |
|
| 429 | + * |
|
| 430 | + * @param int $n |
|
| 431 | + * absolute pos |
|
| 432 | + * @param string $continue |
|
| 433 | + * param for sql_ api |
|
| 434 | + * @return bool |
|
| 435 | + * success or fail if not implemented |
|
| 436 | + */ |
|
| 437 | + public function seek($n = 0, $continue = null) { |
|
| 438 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 439 | + $this->seek_loop($n); |
|
| 440 | + } |
|
| 441 | + $this->pos = $n; |
|
| 442 | + $this->fetched = $n; |
|
| 443 | + |
|
| 444 | + return true; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /* |
|
| 448 | 448 | * aller a la position $n en parcourant |
| 449 | 449 | * un par un tous les elements |
| 450 | 450 | */ |
| 451 | - private function seek_loop($n) { |
|
| 452 | - if ($this->pos > $n) { |
|
| 453 | - $this->rewind(); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - while ($this->pos < $n and $this->valid()) { |
|
| 457 | - $this->next(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - return true; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Avancer de $saut pas |
|
| 465 | - * |
|
| 466 | - * @param $saut |
|
| 467 | - * @param $max |
|
| 468 | - * @return int |
|
| 469 | - */ |
|
| 470 | - public function skip($saut, $max = null) { |
|
| 471 | - // pas de saut en arriere autorise pour cette fonction |
|
| 472 | - if (($saut = intval($saut)) <= 0) { |
|
| 473 | - return $this->pos; |
|
| 474 | - } |
|
| 475 | - $seek = $this->pos + $saut; |
|
| 476 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 477 | - // et on sort |
|
| 478 | - if (is_null($max)) { |
|
| 479 | - $max = $this->count(); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 483 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 484 | - $this->free(); |
|
| 485 | - |
|
| 486 | - return $max; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $this->seek($seek); |
|
| 490 | - |
|
| 491 | - return $this->pos; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Renvoyer un tableau des donnees correspondantes |
|
| 496 | - * a la position courante de l'iterateur |
|
| 497 | - * en controlant si on respecte le filtre |
|
| 498 | - * Appliquer aussi le critere {offset,limit} |
|
| 499 | - * |
|
| 500 | - * @return array|bool |
|
| 501 | - */ |
|
| 502 | - public function fetch() { |
|
| 503 | - if (method_exists($this->iter, 'fetch')) { |
|
| 504 | - return $this->iter->fetch(); |
|
| 505 | - } else { |
|
| 506 | - |
|
| 507 | - while ($this->valid() |
|
| 508 | - and ( |
|
| 509 | - !$this->accept() |
|
| 510 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 511 | - )) { |
|
| 512 | - $this->next(); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - if (!$this->valid()) { |
|
| 516 | - return false; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - if (isset($this->limit) |
|
| 520 | - and $this->fetched > $this->offset + $this->limit |
|
| 521 | - ) { |
|
| 522 | - return false; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $r = array(); |
|
| 526 | - foreach ($this->select as $nom) { |
|
| 527 | - $r[$nom] = $this->get_select($nom); |
|
| 528 | - } |
|
| 529 | - $this->next(); |
|
| 530 | - |
|
| 531 | - return $r; |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - // retourner la cle pour #CLE |
|
| 536 | - public function cle() { |
|
| 537 | - return $this->key(); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // retourner la valeur pour #VALEUR |
|
| 541 | - public function valeur() { |
|
| 542 | - return $this->current(); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Accepte-t-on l'entree courante lue ? |
|
| 547 | - * On execute les filtres pour le savoir. |
|
| 548 | - **/ |
|
| 549 | - public function accept() { |
|
| 550 | - if ($f = $this->func_filtre) { |
|
| 551 | - return $f(); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - return true; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * liberer la ressource |
|
| 559 | - * |
|
| 560 | - * @return bool |
|
| 561 | - */ |
|
| 562 | - public function free() { |
|
| 563 | - if (method_exists($this->iter, 'free')) { |
|
| 564 | - $this->iter->free(); |
|
| 565 | - } |
|
| 566 | - $this->pos = $this->total = 0; |
|
| 567 | - |
|
| 568 | - return true; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Compter le nombre total de resultats |
|
| 573 | - * pour #TOTAL_BOUCLE |
|
| 574 | - * |
|
| 575 | - * @return int |
|
| 576 | - */ |
|
| 577 | - public function count() { |
|
| 578 | - if (is_null($this->total)) { |
|
| 579 | - if (method_exists($this->iter, 'count') |
|
| 580 | - and !$this->func_filtre |
|
| 581 | - ) { |
|
| 582 | - return $this->total = $this->iter->count(); |
|
| 583 | - } else { |
|
| 584 | - // compter les lignes et rembobiner |
|
| 585 | - $total = 0; |
|
| 586 | - $pos = $this->pos; // sauver la position |
|
| 587 | - $this->rewind(); |
|
| 588 | - while ($this->fetch() and $total < $this->max) { |
|
| 589 | - $total++; |
|
| 590 | - } |
|
| 591 | - $this->seek($pos); |
|
| 592 | - $this->total = $total; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $this->total; |
|
| 597 | - } |
|
| 451 | + private function seek_loop($n) { |
|
| 452 | + if ($this->pos > $n) { |
|
| 453 | + $this->rewind(); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + while ($this->pos < $n and $this->valid()) { |
|
| 457 | + $this->next(); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + return true; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Avancer de $saut pas |
|
| 465 | + * |
|
| 466 | + * @param $saut |
|
| 467 | + * @param $max |
|
| 468 | + * @return int |
|
| 469 | + */ |
|
| 470 | + public function skip($saut, $max = null) { |
|
| 471 | + // pas de saut en arriere autorise pour cette fonction |
|
| 472 | + if (($saut = intval($saut)) <= 0) { |
|
| 473 | + return $this->pos; |
|
| 474 | + } |
|
| 475 | + $seek = $this->pos + $saut; |
|
| 476 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 477 | + // et on sort |
|
| 478 | + if (is_null($max)) { |
|
| 479 | + $max = $this->count(); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 483 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 484 | + $this->free(); |
|
| 485 | + |
|
| 486 | + return $max; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $this->seek($seek); |
|
| 490 | + |
|
| 491 | + return $this->pos; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Renvoyer un tableau des donnees correspondantes |
|
| 496 | + * a la position courante de l'iterateur |
|
| 497 | + * en controlant si on respecte le filtre |
|
| 498 | + * Appliquer aussi le critere {offset,limit} |
|
| 499 | + * |
|
| 500 | + * @return array|bool |
|
| 501 | + */ |
|
| 502 | + public function fetch() { |
|
| 503 | + if (method_exists($this->iter, 'fetch')) { |
|
| 504 | + return $this->iter->fetch(); |
|
| 505 | + } else { |
|
| 506 | + |
|
| 507 | + while ($this->valid() |
|
| 508 | + and ( |
|
| 509 | + !$this->accept() |
|
| 510 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 511 | + )) { |
|
| 512 | + $this->next(); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + if (!$this->valid()) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + if (isset($this->limit) |
|
| 520 | + and $this->fetched > $this->offset + $this->limit |
|
| 521 | + ) { |
|
| 522 | + return false; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $r = array(); |
|
| 526 | + foreach ($this->select as $nom) { |
|
| 527 | + $r[$nom] = $this->get_select($nom); |
|
| 528 | + } |
|
| 529 | + $this->next(); |
|
| 530 | + |
|
| 531 | + return $r; |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + // retourner la cle pour #CLE |
|
| 536 | + public function cle() { |
|
| 537 | + return $this->key(); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // retourner la valeur pour #VALEUR |
|
| 541 | + public function valeur() { |
|
| 542 | + return $this->current(); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Accepte-t-on l'entree courante lue ? |
|
| 547 | + * On execute les filtres pour le savoir. |
|
| 548 | + **/ |
|
| 549 | + public function accept() { |
|
| 550 | + if ($f = $this->func_filtre) { |
|
| 551 | + return $f(); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + return true; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * liberer la ressource |
|
| 559 | + * |
|
| 560 | + * @return bool |
|
| 561 | + */ |
|
| 562 | + public function free() { |
|
| 563 | + if (method_exists($this->iter, 'free')) { |
|
| 564 | + $this->iter->free(); |
|
| 565 | + } |
|
| 566 | + $this->pos = $this->total = 0; |
|
| 567 | + |
|
| 568 | + return true; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Compter le nombre total de resultats |
|
| 573 | + * pour #TOTAL_BOUCLE |
|
| 574 | + * |
|
| 575 | + * @return int |
|
| 576 | + */ |
|
| 577 | + public function count() { |
|
| 578 | + if (is_null($this->total)) { |
|
| 579 | + if (method_exists($this->iter, 'count') |
|
| 580 | + and !$this->func_filtre |
|
| 581 | + ) { |
|
| 582 | + return $this->total = $this->iter->count(); |
|
| 583 | + } else { |
|
| 584 | + // compter les lignes et rembobiner |
|
| 585 | + $total = 0; |
|
| 586 | + $pos = $this->pos; // sauver la position |
|
| 587 | + $this->rewind(); |
|
| 588 | + while ($this->fetch() and $total < $this->max) { |
|
| 589 | + $total++; |
|
| 590 | + } |
|
| 591 | + $this->seek($pos); |
|
| 592 | + $this->total = $total; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $this->total; |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | 599 | } |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | // chercher la classe d'iterateur |
| 80 | 80 | // IterateurXXX |
| 81 | 81 | // definie dans le fichier iterateurs/xxx.php |
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 82 | + $class = "Iterateur".$iterateur; |
|
| 83 | 83 | if (!class_exists($class)) { |
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 84 | + if (!include_spip("iterateur/".strtolower($iterateur)) |
|
| 85 | 85 | or !class_exists($class) |
| 86 | 86 | ) { |
| 87 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | return $this->iter->$nom(); |
| 209 | 209 | } catch (Exception $e) { |
| 210 | 210 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 211 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 212 | 212 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 213 | 213 | |
| 214 | 214 | return ''; |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | // Creer la fonction de filtrage sur $this |
| 292 | 292 | if ($this->filtre) { |
| 293 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | - $this->func_filtre = function () use ($filtres) { |
|
| 293 | + $filtres = 'return ('.join(') AND (', $this->filtre).');'; |
|
| 294 | + $this->func_filtre = function() use ($filtres) { |
|
| 295 | 295 | return eval($filtres); |
| 296 | 296 | }; |
| 297 | 297 | } |
@@ -313,28 +313,28 @@ discard block |
||
| 313 | 313 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 314 | 314 | # return; |
| 315 | 315 | |
| 316 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 316 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 317 | 317 | |
| 318 | 318 | $filtre = ''; |
| 319 | 319 | |
| 320 | 320 | if ($op == 'REGEXP') { |
| 321 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 321 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 322 | 322 | $op = ''; |
| 323 | 323 | } else { |
| 324 | 324 | if ($op == 'LIKE') { |
| 325 | 325 | $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
| 326 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 326 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 327 | 327 | $op = ''; |
| 328 | 328 | } else { |
| 329 | 329 | if ($op == '=') { |
| 330 | 330 | $op = '=='; |
| 331 | 331 | } else { |
| 332 | 332 | if ($op == 'IN') { |
| 333 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 333 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 334 | 334 | $op = ''; |
| 335 | 335 | } else { |
| 336 | 336 | if (!in_array($op, array('<', '<=', '>', '>='))) { |
| 337 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 337 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 338 | 338 | $op = ''; |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | if ($op) { |
| 346 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 346 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | if ($not) { |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @param array $depart |
| 233 | 233 | * @param array $arrivee |
| 234 | - * @param string|array $col |
|
| 234 | + * @param string $col |
|
| 235 | 235 | * @return bool |
| 236 | 236 | */ |
| 237 | 237 | function nogroupby_if($depart, $arrivee, $col) { |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $echap ? |
| 179 | 179 | array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
| 180 | 180 | : |
| 181 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 181 | + array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 182 | 182 | } else { |
| 183 | 183 | $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
| 184 | 184 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $groups = liste_champs_jointures($nom, $desc, true); |
| 212 | 212 | if (!$pk) { |
| 213 | 213 | foreach ($groups as $id_prim) { |
| 214 | - $id_field = $nom . '.' . $id_prim; |
|
| 214 | + $id_field = $nom.'.'.$id_prim; |
|
| 215 | 215 | if (!in_array($id_field, $boucle->group)) { |
| 216 | 216 | $boucle->group[] = $id_field; |
| 217 | 217 | } |
@@ -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 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,20 +56,20 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | - or array_key_exists($champ, $desc['field']) |
|
| 61 | - ) { |
|
| 62 | - return array($champ); |
|
| 63 | - } |
|
| 64 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | - array_pop($decompose); |
|
| 67 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | - return $decompose; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return array($champ); |
|
| 59 | + if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | + or array_key_exists($champ, $desc['field']) |
|
| 61 | + ) { |
|
| 62 | + return array($champ); |
|
| 63 | + } |
|
| 64 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | + array_pop($decompose); |
|
| 67 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | + return $decompose; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return array($champ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | * Alias de la table de jointure (Lx) |
| 100 | 100 | */ |
| 101 | 101 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 102 | - // les jointures minimales sont optimales : |
|
| 103 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | - $max = 1; |
|
| 106 | - $res = false; |
|
| 107 | - $milieu_exclus = ($col ? $col : array()); |
|
| 108 | - while ($max <= $max_liens and !$res) { |
|
| 109 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | - $max++; |
|
| 111 | - } |
|
| 112 | - if (!$res) { |
|
| 113 | - return ""; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - list($nom, $desc) = $depart; |
|
| 117 | - |
|
| 118 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 102 | + // les jointures minimales sont optimales : |
|
| 103 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | + $max = 1; |
|
| 106 | + $res = false; |
|
| 107 | + $milieu_exclus = ($col ? $col : array()); |
|
| 108 | + while ($max <= $max_liens and !$res) { |
|
| 109 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | + $max++; |
|
| 111 | + } |
|
| 112 | + if (!$res) { |
|
| 113 | + return ""; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + list($nom, $desc) = $depart; |
|
| 117 | + |
|
| 118 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -154,73 +154,73 @@ discard block |
||
| 154 | 154 | * Alias de la table de jointure (Lx) |
| 155 | 155 | */ |
| 156 | 156 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true) { |
| 157 | - static $num = array(); |
|
| 158 | - $id_table = ""; |
|
| 159 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | - foreach ($res as $cle => $r) { |
|
| 161 | - list($d, $a, $j) = $r; |
|
| 162 | - if (!$id_table) { |
|
| 163 | - $id_table = $d; |
|
| 164 | - } |
|
| 165 | - $n = ++$cpt; |
|
| 166 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | - list($j1, $j2, $obj, $type) = $j; |
|
| 168 | - // trouver de quel cote est (id_objet,objet) |
|
| 169 | - if ($j1 == "id_$obj") { |
|
| 170 | - $obj = "$id_table.$obj"; |
|
| 171 | - } else { |
|
| 172 | - $obj = "L$n.$obj"; |
|
| 173 | - } |
|
| 174 | - // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 175 | - // en cas d'optimisation |
|
| 176 | - //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 177 | - $boucle->join["L$n"] = |
|
| 178 | - $echap ? |
|
| 179 | - array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 180 | - : |
|
| 181 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 182 | - } else { |
|
| 183 | - $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 184 | - } |
|
| 185 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - // pas besoin de group by |
|
| 190 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 191 | - // si une seule jointure et sur une table avec primary key formee |
|
| 192 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 193 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 194 | - |
|
| 195 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 196 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // pas de group by |
|
| 200 | - // si une seule jointure |
|
| 201 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 202 | - if (!$pk |
|
| 203 | - and (count($boucle->from) == 2) |
|
| 204 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 205 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 206 | - ) { |
|
| 207 | - $pk = true; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 211 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 212 | - if (!$pk) { |
|
| 213 | - foreach ($groups as $id_prim) { |
|
| 214 | - $id_field = $nom . '.' . $id_prim; |
|
| 215 | - if (!in_array($id_field, $boucle->group)) { |
|
| 216 | - $boucle->group[] = $id_field; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $boucle->modificateur['lien'] = true; |
|
| 222 | - |
|
| 223 | - return "L$n"; |
|
| 157 | + static $num = array(); |
|
| 158 | + $id_table = ""; |
|
| 159 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | + foreach ($res as $cle => $r) { |
|
| 161 | + list($d, $a, $j) = $r; |
|
| 162 | + if (!$id_table) { |
|
| 163 | + $id_table = $d; |
|
| 164 | + } |
|
| 165 | + $n = ++$cpt; |
|
| 166 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | + list($j1, $j2, $obj, $type) = $j; |
|
| 168 | + // trouver de quel cote est (id_objet,objet) |
|
| 169 | + if ($j1 == "id_$obj") { |
|
| 170 | + $obj = "$id_table.$obj"; |
|
| 171 | + } else { |
|
| 172 | + $obj = "L$n.$obj"; |
|
| 173 | + } |
|
| 174 | + // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 175 | + // en cas d'optimisation |
|
| 176 | + //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 177 | + $boucle->join["L$n"] = |
|
| 178 | + $echap ? |
|
| 179 | + array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 180 | + : |
|
| 181 | + array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 182 | + } else { |
|
| 183 | + $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 184 | + } |
|
| 185 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + // pas besoin de group by |
|
| 190 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 191 | + // si une seule jointure et sur une table avec primary key formee |
|
| 192 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 193 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 194 | + |
|
| 195 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 196 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // pas de group by |
|
| 200 | + // si une seule jointure |
|
| 201 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 202 | + if (!$pk |
|
| 203 | + and (count($boucle->from) == 2) |
|
| 204 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 205 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 206 | + ) { |
|
| 207 | + $pk = true; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 211 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 212 | + if (!$pk) { |
|
| 213 | + foreach ($groups as $id_prim) { |
|
| 214 | + $id_field = $nom . '.' . $id_prim; |
|
| 215 | + if (!in_array($id_field, $boucle->group)) { |
|
| 216 | + $boucle->group[] = $id_field; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $boucle->modificateur['lien'] = true; |
|
| 222 | + |
|
| 223 | + return "L$n"; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | * @return bool |
| 236 | 236 | */ |
| 237 | 237 | function nogroupby_if($depart, $arrivee, $col) { |
| 238 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 239 | - if (!$pk) { |
|
| 240 | - return false; |
|
| 241 | - } |
|
| 242 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 243 | - if (is_array($col)) { |
|
| 244 | - $col = implode(', *', $col); |
|
| 245 | - } // cas id_objet, objet |
|
| 246 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 247 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 238 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 239 | + if (!$pk) { |
|
| 240 | + return false; |
|
| 241 | + } |
|
| 242 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 243 | + if (is_array($col)) { |
|
| 244 | + $col = implode(', *', $col); |
|
| 245 | + } // cas id_objet, objet |
|
| 246 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 247 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -262,46 +262,46 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 264 | 264 | |
| 265 | - static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 265 | + static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 266 | 266 | |
| 267 | - // si cle primaire demandee, la privilegier |
|
| 268 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 269 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 270 | - } |
|
| 267 | + // si cle primaire demandee, la privilegier |
|
| 268 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 269 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - // les champs declares explicitement pour les jointures |
|
| 273 | - if (isset($desc['join'])) { |
|
| 274 | - return $desc['join']; |
|
| 275 | - } |
|
| 276 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 272 | + // les champs declares explicitement pour les jointures |
|
| 273 | + if (isset($desc['join'])) { |
|
| 274 | + return $desc['join']; |
|
| 275 | + } |
|
| 276 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 277 | 277 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 278 | 278 | |
| 279 | - // si pas de cle, c'est fichu |
|
| 280 | - if (!isset($desc['key'])) { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // si cle primaire |
|
| 285 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 286 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // ici on se rabat sur les cles secondaires, |
|
| 290 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 291 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 292 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 293 | - |
|
| 294 | - $join = array(); |
|
| 295 | - foreach ($desc['key'] as $v) { |
|
| 296 | - $join = split_key($v, $join); |
|
| 297 | - } |
|
| 298 | - foreach ($join as $k) { |
|
| 299 | - if (in_array($k, $nojoin)) { |
|
| 300 | - unset($join[$k]); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return $join; |
|
| 279 | + // si pas de cle, c'est fichu |
|
| 280 | + if (!isset($desc['key'])) { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // si cle primaire |
|
| 285 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 286 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // ici on se rabat sur les cles secondaires, |
|
| 290 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 291 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 292 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 293 | + |
|
| 294 | + $join = array(); |
|
| 295 | + foreach ($desc['key'] as $v) { |
|
| 296 | + $join = split_key($v, $join); |
|
| 297 | + } |
|
| 298 | + foreach ($join as $k) { |
|
| 299 | + if (in_array($k, $nojoin)) { |
|
| 300 | + unset($join[$k]); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return $join; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -312,14 +312,14 @@ discard block |
||
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | 314 | function split_key($v, $join = array()) { |
| 315 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 316 | - if (strpos($k, '(') !== false) { |
|
| 317 | - $k = explode('(', $k); |
|
| 318 | - $k = trim(reset($k)); |
|
| 319 | - } |
|
| 320 | - $join[$k] = $k; |
|
| 321 | - } |
|
| 322 | - return $join; |
|
| 315 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 316 | + if (strpos($k, '(') !== false) { |
|
| 317 | + $k = explode('(', $k); |
|
| 318 | + $k = trim(reset($k)); |
|
| 319 | + } |
|
| 320 | + $join[$k] = $k; |
|
| 321 | + } |
|
| 322 | + return $join; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -342,126 +342,126 @@ discard block |
||
| 342 | 342 | * @return array |
| 343 | 343 | */ |
| 344 | 344 | function calculer_chaine_jointures( |
| 345 | - &$boucle, |
|
| 346 | - $depart, |
|
| 347 | - $arrivee, |
|
| 348 | - $vu = array(), |
|
| 349 | - $milieu_exclus = array(), |
|
| 350 | - $max_liens = 5 |
|
| 345 | + &$boucle, |
|
| 346 | + $depart, |
|
| 347 | + $arrivee, |
|
| 348 | + $vu = array(), |
|
| 349 | + $milieu_exclus = array(), |
|
| 350 | + $max_liens = 5 |
|
| 351 | 351 | ) { |
| 352 | - static $trouver_table; |
|
| 353 | - if (!$trouver_table) { |
|
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (is_string($milieu_exclus)) { |
|
| 358 | - $milieu_exclus = array($milieu_exclus); |
|
| 359 | - } |
|
| 360 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 361 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 362 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 363 | - $milieu_exclus[] = 'objet'; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - list($dnom, $ddesc) = $depart; |
|
| 367 | - list($anom, $adesc) = $arrivee; |
|
| 368 | - if (!count($vu)) { |
|
| 369 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 370 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $akeys = array(); |
|
| 374 | - foreach ($adesc['key'] as $k) { |
|
| 375 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 376 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 380 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 381 | - |
|
| 382 | - // cles candidates au depart |
|
| 383 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 384 | - // enlever les cles dde depart exclues par l'appel |
|
| 385 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 386 | - |
|
| 387 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 388 | - |
|
| 389 | - if ($v) { |
|
| 390 | - return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 394 | - if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 395 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 396 | - // id_objet,objet |
|
| 397 | - // si oui on la prend |
|
| 398 | - foreach ($akeys as $key) { |
|
| 399 | - $v = decompose_champ_id_objet($key); |
|
| 400 | - if (is_array($v)) { |
|
| 401 | - $objet = array_shift($v); // objet,'article' |
|
| 402 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 403 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 404 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } else { |
|
| 408 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 409 | - // id_objet,objet a l'arrivee |
|
| 410 | - // si oui on la prend |
|
| 411 | - foreach ($keys as $key) { |
|
| 412 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 413 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 414 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 415 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 416 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 422 | - if ($max_liens <= 1) { |
|
| 423 | - return array(); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // sinon essayer de passer par une autre table |
|
| 427 | - $new = $vu; |
|
| 428 | - foreach ($boucle->jointures as $v) { |
|
| 429 | - if ($v |
|
| 430 | - and !in_array($v, $vu) |
|
| 431 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 432 | - and !in_array($def['table_sql'], $vu) |
|
| 433 | - ) { |
|
| 434 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 435 | - // ie la cle de la jointure precedente |
|
| 436 | - $test_cles = $milieu_exclus; |
|
| 437 | - $new[] = $v; |
|
| 438 | - $max_iter = 50; // securite |
|
| 439 | - while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 440 | - $test_cles, 1)) |
|
| 441 | - and $max_iter--) { |
|
| 442 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 443 | - $milieu = end($jointure_directe_possible); |
|
| 444 | - $exclure_fin = $milieu_exclus; |
|
| 445 | - if (is_string($milieu)) { |
|
| 446 | - $exclure_fin[] = $milieu; |
|
| 447 | - $test_cles[] = $milieu; |
|
| 448 | - } else { |
|
| 449 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 450 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 451 | - } |
|
| 452 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 453 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 454 | - $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 455 | - if ($r) { |
|
| 456 | - array_unshift($r, $jointure_directe_possible); |
|
| 457 | - |
|
| 458 | - return $r; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return array(); |
|
| 352 | + static $trouver_table; |
|
| 353 | + if (!$trouver_table) { |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (is_string($milieu_exclus)) { |
|
| 358 | + $milieu_exclus = array($milieu_exclus); |
|
| 359 | + } |
|
| 360 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 361 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 362 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 363 | + $milieu_exclus[] = 'objet'; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + list($dnom, $ddesc) = $depart; |
|
| 367 | + list($anom, $adesc) = $arrivee; |
|
| 368 | + if (!count($vu)) { |
|
| 369 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 370 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $akeys = array(); |
|
| 374 | + foreach ($adesc['key'] as $k) { |
|
| 375 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 376 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 380 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 381 | + |
|
| 382 | + // cles candidates au depart |
|
| 383 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 384 | + // enlever les cles dde depart exclues par l'appel |
|
| 385 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 386 | + |
|
| 387 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 388 | + |
|
| 389 | + if ($v) { |
|
| 390 | + return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 394 | + if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 395 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 396 | + // id_objet,objet |
|
| 397 | + // si oui on la prend |
|
| 398 | + foreach ($akeys as $key) { |
|
| 399 | + $v = decompose_champ_id_objet($key); |
|
| 400 | + if (is_array($v)) { |
|
| 401 | + $objet = array_shift($v); // objet,'article' |
|
| 402 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 403 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 404 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } else { |
|
| 408 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 409 | + // id_objet,objet a l'arrivee |
|
| 410 | + // si oui on la prend |
|
| 411 | + foreach ($keys as $key) { |
|
| 412 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 413 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 414 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 415 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 416 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 422 | + if ($max_liens <= 1) { |
|
| 423 | + return array(); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // sinon essayer de passer par une autre table |
|
| 427 | + $new = $vu; |
|
| 428 | + foreach ($boucle->jointures as $v) { |
|
| 429 | + if ($v |
|
| 430 | + and !in_array($v, $vu) |
|
| 431 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 432 | + and !in_array($def['table_sql'], $vu) |
|
| 433 | + ) { |
|
| 434 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 435 | + // ie la cle de la jointure precedente |
|
| 436 | + $test_cles = $milieu_exclus; |
|
| 437 | + $new[] = $v; |
|
| 438 | + $max_iter = 50; // securite |
|
| 439 | + while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 440 | + $test_cles, 1)) |
|
| 441 | + and $max_iter--) { |
|
| 442 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 443 | + $milieu = end($jointure_directe_possible); |
|
| 444 | + $exclure_fin = $milieu_exclus; |
|
| 445 | + if (is_string($milieu)) { |
|
| 446 | + $exclure_fin[] = $milieu; |
|
| 447 | + $test_cles[] = $milieu; |
|
| 448 | + } else { |
|
| 449 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 450 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 451 | + } |
|
| 452 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 453 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 454 | + $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 455 | + if ($r) { |
|
| 456 | + array_unshift($r, $jointure_directe_possible); |
|
| 457 | + |
|
| 458 | + return $r; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return array(); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -472,18 +472,18 @@ discard block |
||
| 472 | 472 | * @return array |
| 473 | 473 | */ |
| 474 | 474 | function trouver_cles_table($keys) { |
| 475 | - $res = array(); |
|
| 476 | - foreach ($keys as $v) { |
|
| 477 | - if (!strpos($v, ",")) { |
|
| 478 | - $res[$v] = 1; |
|
| 479 | - } else { |
|
| 480 | - foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 481 | - $res[$k] = 1; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return array_keys($res); |
|
| 475 | + $res = array(); |
|
| 476 | + foreach ($keys as $v) { |
|
| 477 | + if (!strpos($v, ",")) { |
|
| 478 | + $res[$v] = 1; |
|
| 479 | + } else { |
|
| 480 | + foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 481 | + $res[$k] = 1; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return array_keys($res); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -510,33 +510,33 @@ discard block |
||
| 510 | 510 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 511 | 511 | */ |
| 512 | 512 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 513 | - static $trouver_table = ''; |
|
| 514 | - if (!$trouver_table) { |
|
| 515 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - if (!is_array($cle)) { |
|
| 519 | - $cle = array($cle); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - foreach ($tables as $k => $table) { |
|
| 523 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 524 | - if (isset($desc['field']) |
|
| 525 | - // verifier que toutes les cles cherchees sont la |
|
| 526 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 527 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 528 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 529 | - ) { |
|
| 530 | - return array( |
|
| 531 | - 'desc' => $desc, |
|
| 532 | - 'table' => $desc['table'], |
|
| 533 | - 'alias' => $k, |
|
| 534 | - ); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - return false; |
|
| 513 | + static $trouver_table = ''; |
|
| 514 | + if (!$trouver_table) { |
|
| 515 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + if (!is_array($cle)) { |
|
| 519 | + $cle = array($cle); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + foreach ($tables as $k => $table) { |
|
| 523 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 524 | + if (isset($desc['field']) |
|
| 525 | + // verifier que toutes les cles cherchees sont la |
|
| 526 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 527 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 528 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 529 | + ) { |
|
| 530 | + return array( |
|
| 531 | + 'desc' => $desc, |
|
| 532 | + 'table' => $desc['table'], |
|
| 533 | + 'alias' => $k, |
|
| 534 | + ); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + return false; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
@@ -562,52 +562,52 @@ discard block |
||
| 562 | 562 | */ |
| 563 | 563 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 564 | 564 | |
| 565 | - // support de la recherche multi champ : |
|
| 566 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 567 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 568 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 569 | - if (!is_array($cle)) { |
|
| 570 | - $cle = array($cle); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 574 | - return array($infos['table'], $infos['desc'], $cle); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - // au premier coup, on essaye de decomposer, si possible |
|
| 578 | - if (count($cle) == 1 |
|
| 579 | - and $c = reset($cle) |
|
| 580 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 581 | - ) { |
|
| 582 | - |
|
| 583 | - $desc = $boucle->show; |
|
| 584 | - |
|
| 585 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 586 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 587 | - if (isset($desc['field'][$c])) { |
|
| 588 | - $cle = array(); |
|
| 589 | - $cle[] = array_shift($decompose); // id_objet |
|
| 590 | - $cle[] = array_shift($decompose); // objet |
|
| 591 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 592 | - } |
|
| 593 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 594 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 595 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 596 | - else { |
|
| 597 | - $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 598 | - foreach ($depart as $d) { |
|
| 599 | - $cle = array(); |
|
| 600 | - $cle[] = array_shift($decompose); // id_objet |
|
| 601 | - $cle[] = array_shift($decompose); // objet |
|
| 602 | - $cle[] = $d; |
|
| 603 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 604 | - return $ext; |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - return ""; |
|
| 565 | + // support de la recherche multi champ : |
|
| 566 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 567 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 568 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 569 | + if (!is_array($cle)) { |
|
| 570 | + $cle = array($cle); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 574 | + return array($infos['table'], $infos['desc'], $cle); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // au premier coup, on essaye de decomposer, si possible |
|
| 578 | + if (count($cle) == 1 |
|
| 579 | + and $c = reset($cle) |
|
| 580 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 581 | + ) { |
|
| 582 | + |
|
| 583 | + $desc = $boucle->show; |
|
| 584 | + |
|
| 585 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 586 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 587 | + if (isset($desc['field'][$c])) { |
|
| 588 | + $cle = array(); |
|
| 589 | + $cle[] = array_shift($decompose); // id_objet |
|
| 590 | + $cle[] = array_shift($decompose); // objet |
|
| 591 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 592 | + } |
|
| 593 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 594 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 595 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 596 | + else { |
|
| 597 | + $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 598 | + foreach ($depart as $d) { |
|
| 599 | + $cle = array(); |
|
| 600 | + $cle[] = array_shift($decompose); // id_objet |
|
| 601 | + $cle[] = array_shift($decompose); // objet |
|
| 602 | + $cle[] = $d; |
|
| 603 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 604 | + return $ext; |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + return ""; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -639,21 +639,21 @@ discard block |
||
| 639 | 639 | * @return string |
| 640 | 640 | */ |
| 641 | 641 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 642 | - if ($jointures === false) { |
|
| 643 | - $jointures = $boucle->jointures; |
|
| 644 | - } |
|
| 645 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 646 | - // mais pas poour construire la jointure ensuite |
|
| 647 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 648 | - if ($arrivee) { |
|
| 649 | - $desc = $boucle->show; |
|
| 650 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 651 | - $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 652 | - if ($cle) { |
|
| 653 | - return $cle; |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 657 | - |
|
| 658 | - return ''; |
|
| 642 | + if ($jointures === false) { |
|
| 643 | + $jointures = $boucle->jointures; |
|
| 644 | + } |
|
| 645 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 646 | + // mais pas poour construire la jointure ensuite |
|
| 647 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 648 | + if ($arrivee) { |
|
| 649 | + $desc = $boucle->show; |
|
| 650 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 651 | + $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 652 | + if ($cle) { |
|
| 653 | + return $cle; |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 657 | + |
|
| 658 | + return ''; |
|
| 659 | 659 | } |
@@ -75,6 +75,9 @@ |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | +/** |
|
| 79 | + * @param string $nom |
|
| 80 | + */ |
|
| 78 | 81 | function phraser_logo_faux_filtres($nom) { |
| 79 | 82 | switch ($nom) { |
| 80 | 83 | case 'top': |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | 55 | |
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + } elseif (preg_match("/^".NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 57 | 57 | $champ = new Champ(); |
| 58 | 58 | $champ->nom_boucle = $m[2]; |
| 59 | 59 | $champ->nom_champ = $m[3]; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $p->param[0][1] = array($c); |
| 132 | 132 | $p->param[0][0] = ''; |
| 133 | 133 | $p->fonctions = array(); |
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -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 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,135 +25,135 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = array(''); |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte; |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = array($c); |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - |
|
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | - $champ = new Champ(); |
|
| 58 | - $champ->nom_boucle = $m[2]; |
|
| 59 | - $champ->nom_champ = $m[3]; |
|
| 60 | - $champ->etoile = $m[5]; |
|
| 61 | - $champ = array($champ); |
|
| 62 | - if ($m[6]) { |
|
| 63 | - $r = new Texte; |
|
| 64 | - $r->texte = $m[6]; |
|
| 65 | - $champ[] = $r; |
|
| 66 | - } |
|
| 67 | - $args[] = $champ; |
|
| 68 | - array_shift($p->param); |
|
| 69 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | - |
|
| 71 | - } // le cas else est la seule incompatibilite |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = array(''); |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte; |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = array($c); |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + |
|
| 56 | + } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | + $champ = new Champ(); |
|
| 58 | + $champ->nom_boucle = $m[2]; |
|
| 59 | + $champ->nom_champ = $m[3]; |
|
| 60 | + $champ->etoile = $m[5]; |
|
| 61 | + $champ = array($champ); |
|
| 62 | + if ($m[6]) { |
|
| 63 | + $r = new Texte; |
|
| 64 | + $r->texte = $m[6]; |
|
| 65 | + $champ[] = $r; |
|
| 66 | + } |
|
| 67 | + $args[] = $champ; |
|
| 68 | + array_shift($p->param); |
|
| 69 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | + |
|
| 71 | + } // le cas else est la seule incompatibilite |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + array_unshift($p->param, $args); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | function phraser_logo_faux_filtres($nom) { |
| 79 | - switch ($nom) { |
|
| 80 | - case 'top': |
|
| 81 | - case 'left': |
|
| 82 | - case 'right': |
|
| 83 | - case 'center': |
|
| 84 | - case 'bottom': |
|
| 85 | - return 0; |
|
| 86 | - case 'lien': |
|
| 87 | - return 1; |
|
| 88 | - case 'fichier': |
|
| 89 | - return 2; |
|
| 90 | - default: |
|
| 91 | - return $nom; |
|
| 92 | - } |
|
| 79 | + switch ($nom) { |
|
| 80 | + case 'top': |
|
| 81 | + case 'left': |
|
| 82 | + case 'right': |
|
| 83 | + case 'center': |
|
| 84 | + case 'bottom': |
|
| 85 | + return 0; |
|
| 86 | + case 'lien': |
|
| 87 | + return 1; |
|
| 88 | + case 'fichier': |
|
| 89 | + return 2; |
|
| 90 | + default: |
|
| 91 | + return $nom; |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
| 96 | 96 | // La balise embed_document est a present le modele emb |
| 97 | 97 | |
| 98 | 98 | function phraser_vieux_emb(&$p) { |
| 99 | - if (!is_array($p->param)) { |
|
| 100 | - $p->param = array(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Produire le premier argument {emb} |
|
| 104 | - $texte = new Texte; |
|
| 105 | - $texte->texte = 'emb'; |
|
| 106 | - $param = array('', array($texte)); |
|
| 107 | - |
|
| 108 | - // Transformer les filtres en arguments |
|
| 109 | - for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | - if ($p->param[$i][0]) { |
|
| 111 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | - break; |
|
| 113 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | - $texte = new Texte; |
|
| 115 | - $texte->texte = $p->param[$i][0]; |
|
| 116 | - $param[] = array($texte); |
|
| 117 | - } |
|
| 118 | - array_shift($p->param); |
|
| 119 | - } |
|
| 120 | - array_unshift($p->param, $param); |
|
| 121 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | - $p->nom_champ = 'MODELE'; |
|
| 99 | + if (!is_array($p->param)) { |
|
| 100 | + $p->param = array(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Produire le premier argument {emb} |
|
| 104 | + $texte = new Texte; |
|
| 105 | + $texte->texte = 'emb'; |
|
| 106 | + $param = array('', array($texte)); |
|
| 107 | + |
|
| 108 | + // Transformer les filtres en arguments |
|
| 109 | + for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | + if ($p->param[$i][0]) { |
|
| 111 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | + break; |
|
| 113 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | + $texte = new Texte; |
|
| 115 | + $texte->texte = $p->param[$i][0]; |
|
| 116 | + $param[] = array($texte); |
|
| 117 | + } |
|
| 118 | + array_shift($p->param); |
|
| 119 | + } |
|
| 120 | + array_unshift($p->param, $param); |
|
| 121 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | + $p->nom_champ = 'MODELE'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Vieux formulaire de recherch |
| 126 | 126 | |
| 127 | 127 | function phraser_vieux_recherche($p) { |
| 128 | - if ($p->param[0][0]) { |
|
| 129 | - $c = new Texte; |
|
| 130 | - $c->texte = $p->param[0][0]; |
|
| 131 | - $p->param[0][1] = array($c); |
|
| 132 | - $p->param[0][0] = ''; |
|
| 133 | - $p->fonctions = array(); |
|
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | - } |
|
| 128 | + if ($p->param[0][0]) { |
|
| 129 | + $c = new Texte; |
|
| 130 | + $c->texte = $p->param[0][0]; |
|
| 131 | + $p->param[0][1] = array($c); |
|
| 132 | + $p->param[0][0] = ''; |
|
| 133 | + $p->fonctions = array(); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Gerer la notation [(#EXPOSER|on,off)] |
| 139 | 139 | function phraser_vieux_exposer($p) { |
| 140 | - if ($a = $p->fonctions) { |
|
| 141 | - preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | - $args = array(); |
|
| 143 | - if ($regs[1]) { |
|
| 144 | - $a = new Texte; |
|
| 145 | - $a->texte = $regs[1]; |
|
| 146 | - $args = array('', array($a)); |
|
| 147 | - if ($regs[3]) { |
|
| 148 | - $a = new Texte; |
|
| 149 | - $a->texte = $regs[3]; |
|
| 150 | - $args[] = array($a); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $p->param[0] = $args; |
|
| 154 | - $p->fonctions = array(); |
|
| 155 | - $p->nom_champ = 'EXPOSE'; |
|
| 156 | - } |
|
| 140 | + if ($a = $p->fonctions) { |
|
| 141 | + preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | + $args = array(); |
|
| 143 | + if ($regs[1]) { |
|
| 144 | + $a = new Texte; |
|
| 145 | + $a->texte = $regs[1]; |
|
| 146 | + $args = array('', array($a)); |
|
| 147 | + if ($regs[3]) { |
|
| 148 | + $a = new Texte; |
|
| 149 | + $a->texte = $regs[3]; |
|
| 150 | + $args[] = array($a); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $p->param[0] = $args; |
|
| 154 | + $p->fonctions = array(); |
|
| 155 | + $p->nom_champ = 'EXPOSE'; |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | function phraser_vieux_modele($p) { normaliser_args_inclumodel($p); } |
@@ -161,55 +161,55 @@ discard block |
||
| 161 | 161 | function phraser_vieux_inclu($p) { normaliser_args_inclumodel($p); } |
| 162 | 162 | |
| 163 | 163 | function normaliser_args_inclumodel($p) { |
| 164 | - $params = $p->param; |
|
| 165 | - if (!$params) { |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - $args = $params[0]; |
|
| 169 | - if ($args[0]) { |
|
| 170 | - return; |
|
| 171 | - } // filtre immediat |
|
| 172 | - array_shift($p->param); |
|
| 173 | - foreach ($p->param as $l) { |
|
| 174 | - if (!array_shift($l)) { |
|
| 175 | - $args = array_merge($args, $l); |
|
| 176 | - array_shift($p->param); |
|
| 177 | - } else { |
|
| 178 | - break; |
|
| 179 | - } // filtre |
|
| 180 | - } |
|
| 181 | - array_unshift($p->param, $args); |
|
| 164 | + $params = $p->param; |
|
| 165 | + if (!$params) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + $args = $params[0]; |
|
| 169 | + if ($args[0]) { |
|
| 170 | + return; |
|
| 171 | + } // filtre immediat |
|
| 172 | + array_shift($p->param); |
|
| 173 | + foreach ($p->param as $l) { |
|
| 174 | + if (!array_shift($l)) { |
|
| 175 | + $args = array_merge($args, $l); |
|
| 176 | + array_shift($p->param); |
|
| 177 | + } else { |
|
| 178 | + break; |
|
| 179 | + } // filtre |
|
| 180 | + } |
|
| 181 | + array_unshift($p->param, $args); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function normaliser_inclure($champ) { |
| 185 | - normaliser_args_inclumodel($champ); |
|
| 186 | - $l = $champ->param[0]; |
|
| 187 | - if (is_array($l) and !$l[0]) { |
|
| 188 | - foreach ($l as $k => $p) { |
|
| 189 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | - $p[0]->texte = trim($p[0]->texte); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - foreach ($l as $k => $p) { |
|
| 194 | - if (!$p or $p[0]->type != 'texte' or |
|
| 195 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | - ) { |
|
| 197 | - continue; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($r[1]) { |
|
| 201 | - $p[0]->texte = $r[1]; |
|
| 202 | - } else { |
|
| 203 | - unset($p[0]); |
|
| 204 | - } |
|
| 205 | - $champ->texte = $p; |
|
| 206 | - unset($champ->param[0][$k]); |
|
| 207 | - if (count($champ->param[0]) == 1) { |
|
| 208 | - array_shift($champ->param); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - spip_log("inclure sans fond ni fichier"); |
|
| 185 | + normaliser_args_inclumodel($champ); |
|
| 186 | + $l = $champ->param[0]; |
|
| 187 | + if (is_array($l) and !$l[0]) { |
|
| 188 | + foreach ($l as $k => $p) { |
|
| 189 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | + $p[0]->texte = trim($p[0]->texte); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + foreach ($l as $k => $p) { |
|
| 194 | + if (!$p or $p[0]->type != 'texte' or |
|
| 195 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | + ) { |
|
| 197 | + continue; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($r[1]) { |
|
| 201 | + $p[0]->texte = $r[1]; |
|
| 202 | + } else { |
|
| 203 | + unset($p[0]); |
|
| 204 | + } |
|
| 205 | + $champ->texte = $p; |
|
| 206 | + unset($champ->param[0][$k]); |
|
| 207 | + if (count($champ->param[0]) == 1) { |
|
| 208 | + array_shift($champ->param); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + spip_log("inclure sans fond ni fichier"); |
|
| 215 | 215 | } |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @uses public_tester_redirection_dist() |
| 233 | 233 | * @param string $fond |
| 234 | - * @param array $contexte |
|
| 234 | + * @param string $contexte |
|
| 235 | 235 | * @param string $connect |
| 236 | 236 | * @return array|bool |
| 237 | 237 | */ |
@@ -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_fichiers_fonctions(); |
@@ -31,167 +31,167 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // https://code.spip.net/@public_parametrer_dist |
| 33 | 33 | function public_parametrer_dist($fond, $contexte = '', $cache = '', $connect = '') { |
| 34 | - static $composer, $styliser, $notes = null; |
|
| 35 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | - if ($page) { |
|
| 37 | - return $page; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (isset($contexte['lang'])) { |
|
| 41 | - $lang = $contexte['lang']; |
|
| 42 | - } elseif (!isset($lang)) { |
|
| 43 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | - if ($select) { |
|
| 48 | - $select = lang_select($lang); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | - |
|
| 53 | - if (!$styliser) { |
|
| 54 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | - } |
|
| 56 | - list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | - |
|
| 59 | - if ($skel) { |
|
| 60 | - |
|
| 61 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 62 | - // (recursion possible a cause des modeles) |
|
| 63 | - if ($debug) { |
|
| 64 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 65 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // charger le squelette en specifiant les langages cibles et source |
|
| 69 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 70 | - |
|
| 71 | - if (!$composer) { |
|
| 72 | - $composer = charger_fonction('composer', 'public'); |
|
| 73 | - } |
|
| 74 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 75 | - } else { |
|
| 76 | - $fonc = ''; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 80 | - $page = $fonc; |
|
| 81 | - } else { |
|
| 82 | - // Preparer l'appel de la fonction principale du squelette |
|
| 83 | - |
|
| 84 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 85 | - |
|
| 86 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 87 | - // et on enregistre l'etat courant des globales de notes... |
|
| 88 | - if (is_null($notes)) { |
|
| 89 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 90 | - } |
|
| 91 | - if ($notes) { |
|
| 92 | - $notes('', 'empiler'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Rajouter d'office ces deux parametres |
|
| 96 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 97 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 98 | - if (!isset($contexte['date'])) { |
|
| 99 | - $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 100 | - $contexte['date_default'] = true; |
|
| 101 | - } else { |
|
| 102 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - if (!isset($contexte['date_redac'])) { |
|
| 106 | - $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 107 | - $contexte['date_redac_default'] = true; |
|
| 108 | - } else { |
|
| 109 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | - $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 114 | - |
|
| 115 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 116 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 117 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 118 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 119 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 120 | - if ($notes) { |
|
| 121 | - $notes('', 'depiler'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // reinjecter en dynamique la pile des notes |
|
| 125 | - // si il y a des inclure dynamiques |
|
| 126 | - // si la pile n'est pas vide |
|
| 127 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 128 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 129 | - if ($notes) { |
|
| 130 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // spip_log: un joli contexte |
|
| 134 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 135 | - |
|
| 136 | - $profile = spip_timer($a); |
|
| 137 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 138 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 139 | - |
|
| 140 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 141 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 142 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if ($debug) { |
|
| 146 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 147 | - $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 148 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 149 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 150 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 151 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 152 | - and (_request('var_mode_objet') == $fonc) |
|
| 153 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 154 | - ) { |
|
| 155 | - erreur_squelette(); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 159 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 160 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 161 | - // si aucun #CACHE{} spécifié |
|
| 162 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 163 | - // entre public et prive |
|
| 164 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 165 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 166 | - } else { |
|
| 167 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $page['contexte'] = $contexte; |
|
| 172 | - |
|
| 173 | - // faire remonter le fichier source |
|
| 174 | - static $js_inclus = false; |
|
| 175 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 176 | - $page['sourcefile'] = $sourcefile; |
|
| 177 | - $page['texte'] = |
|
| 178 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 179 | - . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 180 | - $js_inclus = true; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 184 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 185 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 186 | - unset($GLOBALS['cache_utilise_session']); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if ($select) { |
|
| 191 | - lang_select(); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $page; |
|
| 34 | + static $composer, $styliser, $notes = null; |
|
| 35 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | + if ($page) { |
|
| 37 | + return $page; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (isset($contexte['lang'])) { |
|
| 41 | + $lang = $contexte['lang']; |
|
| 42 | + } elseif (!isset($lang)) { |
|
| 43 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | + if ($select) { |
|
| 48 | + $select = lang_select($lang); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | + |
|
| 53 | + if (!$styliser) { |
|
| 54 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | + } |
|
| 56 | + list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | + |
|
| 59 | + if ($skel) { |
|
| 60 | + |
|
| 61 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 62 | + // (recursion possible a cause des modeles) |
|
| 63 | + if ($debug) { |
|
| 64 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 65 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // charger le squelette en specifiant les langages cibles et source |
|
| 69 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 70 | + |
|
| 71 | + if (!$composer) { |
|
| 72 | + $composer = charger_fonction('composer', 'public'); |
|
| 73 | + } |
|
| 74 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 75 | + } else { |
|
| 76 | + $fonc = ''; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 80 | + $page = $fonc; |
|
| 81 | + } else { |
|
| 82 | + // Preparer l'appel de la fonction principale du squelette |
|
| 83 | + |
|
| 84 | + spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 85 | + |
|
| 86 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 87 | + // et on enregistre l'etat courant des globales de notes... |
|
| 88 | + if (is_null($notes)) { |
|
| 89 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 90 | + } |
|
| 91 | + if ($notes) { |
|
| 92 | + $notes('', 'empiler'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Rajouter d'office ces deux parametres |
|
| 96 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 97 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 98 | + if (!isset($contexte['date'])) { |
|
| 99 | + $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 100 | + $contexte['date_default'] = true; |
|
| 101 | + } else { |
|
| 102 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if (!isset($contexte['date_redac'])) { |
|
| 106 | + $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 107 | + $contexte['date_redac_default'] = true; |
|
| 108 | + } else { |
|
| 109 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | + $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 114 | + |
|
| 115 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 116 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 117 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 118 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 119 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 120 | + if ($notes) { |
|
| 121 | + $notes('', 'depiler'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // reinjecter en dynamique la pile des notes |
|
| 125 | + // si il y a des inclure dynamiques |
|
| 126 | + // si la pile n'est pas vide |
|
| 127 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 128 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 129 | + if ($notes) { |
|
| 130 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // spip_log: un joli contexte |
|
| 134 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 135 | + |
|
| 136 | + $profile = spip_timer($a); |
|
| 137 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 138 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 139 | + |
|
| 140 | + if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 141 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 142 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if ($debug) { |
|
| 146 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 147 | + $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 148 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 149 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 150 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 151 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 152 | + and (_request('var_mode_objet') == $fonc) |
|
| 153 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 154 | + ) { |
|
| 155 | + erreur_squelette(); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 159 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 160 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 161 | + // si aucun #CACHE{} spécifié |
|
| 162 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 163 | + // entre public et prive |
|
| 164 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 165 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 166 | + } else { |
|
| 167 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $page['contexte'] = $contexte; |
|
| 172 | + |
|
| 173 | + // faire remonter le fichier source |
|
| 174 | + static $js_inclus = false; |
|
| 175 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 176 | + $page['sourcefile'] = $sourcefile; |
|
| 177 | + $page['texte'] = |
|
| 178 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 179 | + . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 180 | + $js_inclus = true; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 184 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 185 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 186 | + unset($GLOBALS['cache_utilise_session']); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if ($select) { |
|
| 191 | + lang_select(); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $page; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -200,33 +200,33 @@ discard block |
||
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | 202 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 203 | - $infos = array(); |
|
| 204 | - $line = 0; |
|
| 205 | - foreach ($contexte as $var => $val) { |
|
| 206 | - $line++; |
|
| 207 | - if ($max_lines and $max_lines < $line) { |
|
| 208 | - $infos[] = '…'; |
|
| 209 | - break; |
|
| 210 | - } |
|
| 211 | - if (is_array($val)) { |
|
| 212 | - if ($profondeur_max > 0) { |
|
| 213 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 214 | - } else { |
|
| 215 | - $val = 'array:' . count($val); |
|
| 216 | - } |
|
| 217 | - } elseif (is_object($val)) { |
|
| 218 | - $val = get_class($val); |
|
| 219 | - } elseif (strlen("$val") > 30) { |
|
| 220 | - $val = substr("$val", 0, 29) . '…'; |
|
| 221 | - if (strstr($val, ' ')) { |
|
| 222 | - $val = "'$val'"; |
|
| 223 | - } |
|
| 224 | - } elseif (strstr($val, ' ')) { |
|
| 225 | - $val = "'$val'"; |
|
| 226 | - } |
|
| 227 | - $infos[] = $var . '=' . $val; |
|
| 228 | - } |
|
| 229 | - return join(', ', $infos); |
|
| 203 | + $infos = array(); |
|
| 204 | + $line = 0; |
|
| 205 | + foreach ($contexte as $var => $val) { |
|
| 206 | + $line++; |
|
| 207 | + if ($max_lines and $max_lines < $line) { |
|
| 208 | + $infos[] = '…'; |
|
| 209 | + break; |
|
| 210 | + } |
|
| 211 | + if (is_array($val)) { |
|
| 212 | + if ($profondeur_max > 0) { |
|
| 213 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 214 | + } else { |
|
| 215 | + $val = 'array:' . count($val); |
|
| 216 | + } |
|
| 217 | + } elseif (is_object($val)) { |
|
| 218 | + $val = get_class($val); |
|
| 219 | + } elseif (strlen("$val") > 30) { |
|
| 220 | + $val = substr("$val", 0, 29) . '…'; |
|
| 221 | + if (strstr($val, ' ')) { |
|
| 222 | + $val = "'$val'"; |
|
| 223 | + } |
|
| 224 | + } elseif (strstr($val, ' ')) { |
|
| 225 | + $val = "'$val'"; |
|
| 226 | + } |
|
| 227 | + $infos[] = $var . '=' . $val; |
|
| 228 | + } |
|
| 229 | + return join(', ', $infos); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | * @return array|bool |
| 244 | 244 | */ |
| 245 | 245 | function tester_redirection($fond, $contexte, $connect) { |
| 246 | - static $tester_redirection = null; |
|
| 247 | - if (is_null($tester_redirection)) { |
|
| 248 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 249 | - } |
|
| 250 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 246 | + static $tester_redirection = null; |
|
| 247 | + if (is_null($tester_redirection)) { |
|
| 248 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 249 | + } |
|
| 250 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -263,40 +263,40 @@ discard block |
||
| 263 | 263 | * @return array|bool |
| 264 | 264 | */ |
| 265 | 265 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 266 | - if ($fond == 'article' |
|
| 267 | - and $id_article = intval($contexte['id_article']) |
|
| 268 | - ) { |
|
| 269 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 270 | - $m = quete_virtuel($id_article, $connect); |
|
| 271 | - if (strlen($m)) { |
|
| 272 | - include_spip('inc/texte'); |
|
| 273 | - // les navigateurs pataugent si l'URL est vide |
|
| 274 | - if ($url = virtuel_redirige($m, true)) { |
|
| 275 | - // passer en url absolue car cette redirection pourra |
|
| 276 | - // etre utilisee dans un contexte d'url qui change |
|
| 277 | - // y compris url arbo |
|
| 278 | - $status = 302; |
|
| 279 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 280 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 281 | - } |
|
| 282 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 283 | - include_spip('inc/filtres_mini'); |
|
| 284 | - $url = url_absolue($url); |
|
| 285 | - } |
|
| 286 | - $url = str_replace('&', '&', $url); |
|
| 287 | - |
|
| 288 | - return array( |
|
| 289 | - 'texte' => "<" |
|
| 290 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 291 | - . texte_script($url) |
|
| 292 | - . "','',$status);" |
|
| 293 | - . "?" . ">", |
|
| 294 | - 'process_ins' => 'php', |
|
| 295 | - 'status' => $status |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - return false; |
|
| 266 | + if ($fond == 'article' |
|
| 267 | + and $id_article = intval($contexte['id_article']) |
|
| 268 | + ) { |
|
| 269 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 270 | + $m = quete_virtuel($id_article, $connect); |
|
| 271 | + if (strlen($m)) { |
|
| 272 | + include_spip('inc/texte'); |
|
| 273 | + // les navigateurs pataugent si l'URL est vide |
|
| 274 | + if ($url = virtuel_redirige($m, true)) { |
|
| 275 | + // passer en url absolue car cette redirection pourra |
|
| 276 | + // etre utilisee dans un contexte d'url qui change |
|
| 277 | + // y compris url arbo |
|
| 278 | + $status = 302; |
|
| 279 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 280 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 281 | + } |
|
| 282 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 283 | + include_spip('inc/filtres_mini'); |
|
| 284 | + $url = url_absolue($url); |
|
| 285 | + } |
|
| 286 | + $url = str_replace('&', '&', $url); |
|
| 287 | + |
|
| 288 | + return array( |
|
| 289 | + 'texte' => "<" |
|
| 290 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 291 | + . texte_script($url) |
|
| 292 | + . "','',$status);" |
|
| 293 | + . "?" . ">", |
|
| 294 | + 'process_ins' => 'php', |
|
| 295 | + 'status' => $status |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + return false; |
|
| 302 | 302 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | } else { |
| 82 | 82 | // Preparer l'appel de la fonction principale du squelette |
| 83 | 83 | |
| 84 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | + spip_timer($a = 'calcul page '.rand(0, 1000)); |
|
| 85 | 85 | |
| 86 | 86 | // On cree un marqueur de notes unique lie a cette composition |
| 87 | 87 | // et on enregistre l'etat courant des globales de notes... |
@@ -135,17 +135,17 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | $profile = spip_timer($a); |
| 137 | 137 | spip_log("calcul ($profile) [$skel] $infos" |
| 138 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 138 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 139 | 139 | |
| 140 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 140 | + if (defined('_CALCUL_PROFILER') AND intval($profile) > _CALCUL_PROFILER) { |
|
| 141 | 141 | spip_log("calcul ($profile) [$skel] $infos" |
| 142 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 142 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], "profiler"._LOG_AVERTISSEMENT); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | if ($debug) { |
| 146 | 146 | // si c'est ce que demande le debusqueur, lui passer la main |
| 147 | 147 | $t = strlen($page['texte']) ? $page['texte'] : " "; |
| 148 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 148 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 149 | 149 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 150 | 150 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 151 | 151 | if ($GLOBALS['debug_objets']['sourcefile'] |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 176 | 176 | $page['sourcefile'] = $sourcefile; |
| 177 | 177 | $page['texte'] = |
| 178 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 178 | + "<div class='inclure_blocs'><h6>".$page['sourcefile']."</h6>".$page['texte']."</div>" |
|
| 179 | 179 | . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 180 | 180 | $js_inclus = true; |
| 181 | 181 | } |
@@ -210,21 +210,21 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | if (is_array($val)) { |
| 212 | 212 | if ($profondeur_max > 0) { |
| 213 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 213 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 214 | 214 | } else { |
| 215 | - $val = 'array:' . count($val); |
|
| 215 | + $val = 'array:'.count($val); |
|
| 216 | 216 | } |
| 217 | 217 | } elseif (is_object($val)) { |
| 218 | 218 | $val = get_class($val); |
| 219 | 219 | } elseif (strlen("$val") > 30) { |
| 220 | - $val = substr("$val", 0, 29) . '…'; |
|
| 220 | + $val = substr("$val", 0, 29).'…'; |
|
| 221 | 221 | if (strstr($val, ' ')) { |
| 222 | 222 | $val = "'$val'"; |
| 223 | 223 | } |
| 224 | 224 | } elseif (strstr($val, ' ')) { |
| 225 | 225 | $val = "'$val'"; |
| 226 | 226 | } |
| 227 | - $infos[] = $var . '=' . $val; |
|
| 227 | + $infos[] = $var.'='.$val; |
|
| 228 | 228 | } |
| 229 | 229 | return join(', ', $infos); |
| 230 | 230 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 291 | 291 | . texte_script($url) |
| 292 | 292 | . "','',$status);" |
| 293 | - . "?" . ">", |
|
| 293 | + . "?".">", |
|
| 294 | 294 | 'process_ins' => 'php', |
| 295 | 295 | 'status' => $status |
| 296 | 296 | ); |
@@ -158,7 +158,7 @@ |
||
| 158 | 158 | * @param string $corps |
| 159 | 159 | * @param array $filtres |
| 160 | 160 | * Tableau de filtres à appliquer. |
| 161 | - * @return mixed|string |
|
| 161 | + * @return string |
|
| 162 | 162 | */ |
| 163 | 163 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 164 | 164 | $series_filtres = func_get_args(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -58,35 +58,35 @@ discard block |
||
| 58 | 58 | * @return string |
| 59 | 59 | */ |
| 60 | 60 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p) { |
| 61 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 62 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 66 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 67 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 68 | - |
|
| 69 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | - if (strpbrk($f, ':')) { // Class::method |
|
| 72 | - $refl = new ReflectionMethod($f); |
|
| 73 | - } else { |
|
| 74 | - $refl = new ReflectionFunction($f); |
|
| 75 | - } |
|
| 76 | - $refs = $refl->getParameters(); |
|
| 77 | - if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | - } else { |
|
| 80 | - $code = "$f($code$arglist)"; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - // le filtre n'existe pas, |
|
| 84 | - // on le notifie |
|
| 85 | - else { |
|
| 86 | - erreur_squelette(array('zbug_erreur_filtre', array('filtre' => texte_script($fonc))), $p); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $code; |
|
| 61 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 62 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 66 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 67 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 68 | + |
|
| 69 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | + if (strpbrk($f, ':')) { // Class::method |
|
| 72 | + $refl = new ReflectionMethod($f); |
|
| 73 | + } else { |
|
| 74 | + $refl = new ReflectionFunction($f); |
|
| 75 | + } |
|
| 76 | + $refs = $refl->getParameters(); |
|
| 77 | + if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | + } else { |
|
| 80 | + $code = "$f($code$arglist)"; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + // le filtre n'existe pas, |
|
| 84 | + // on le notifie |
|
| 85 | + else { |
|
| 86 | + erreur_squelette(array('zbug_erreur_filtre', array('filtre' => texte_script($fonc))), $p); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $code; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Calculer un <INCLURE(xx.php)> |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 113 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | - // si inexistant, on essaiera a l'execution |
|
| 115 | - if ($path = find_in_path($fichier)) { |
|
| 116 | - $path = "\"$path\""; |
|
| 117 | - } else { |
|
| 118 | - $path = "find_in_path(\"$fichier\")"; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 113 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | + // si inexistant, on essaiera a l'execution |
|
| 115 | + if ($path = find_in_path($fichier)) { |
|
| 116 | + $path = "\"$path\""; |
|
| 117 | + } else { |
|
| 118 | + $path = "find_in_path(\"$fichier\")"; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -130,19 +130,19 @@ discard block |
||
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | 132 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 133 | - // Securite |
|
| 134 | - if ($p->interdire_scripts |
|
| 135 | - and $p->etoile != '**' |
|
| 136 | - ) { |
|
| 137 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 138 | - $code = "interdire_scripts($code)"; |
|
| 139 | - } else { |
|
| 140 | - $code = interdire_scripts($r[2]); |
|
| 141 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $code; |
|
| 133 | + // Securite |
|
| 134 | + if ($p->interdire_scripts |
|
| 135 | + and $p->etoile != '**' |
|
| 136 | + ) { |
|
| 137 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 138 | + $code = "interdire_scripts($code)"; |
|
| 139 | + } else { |
|
| 140 | + $code = interdire_scripts($r[2]); |
|
| 141 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $code; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
@@ -161,30 +161,30 @@ discard block |
||
| 161 | 161 | * @return mixed|string |
| 162 | 162 | */ |
| 163 | 163 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 164 | - $series_filtres = func_get_args(); |
|
| 165 | - array_shift($series_filtres);// skel |
|
| 166 | - array_shift($series_filtres);// corps |
|
| 167 | - |
|
| 168 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 169 | - if ($skel['process_ins'] == 'php') { |
|
| 170 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // recuperer les couples de remplacement |
|
| 174 | - $replace = echapper_php_callback(); |
|
| 175 | - |
|
| 176 | - foreach ($series_filtres as $filtres) { |
|
| 177 | - if (count($filtres)) { |
|
| 178 | - foreach ($filtres as $filtre) { |
|
| 179 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 180 | - $corps = $f($corps); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // restaurer les echappements |
|
| 187 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 164 | + $series_filtres = func_get_args(); |
|
| 165 | + array_shift($series_filtres);// skel |
|
| 166 | + array_shift($series_filtres);// corps |
|
| 167 | + |
|
| 168 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 169 | + if ($skel['process_ins'] == 'php') { |
|
| 170 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // recuperer les couples de remplacement |
|
| 174 | + $replace = echapper_php_callback(); |
|
| 175 | + |
|
| 176 | + foreach ($series_filtres as $filtres) { |
|
| 177 | + if (count($filtres)) { |
|
| 178 | + foreach ($filtres as $filtre) { |
|
| 179 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 180 | + $corps = $f($corps); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // restaurer les echappements |
|
| 187 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
@@ -203,21 +203,21 @@ discard block |
||
| 203 | 203 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 204 | 204 | **/ |
| 205 | 205 | function echapper_php_callback($r = null) { |
| 206 | - static $src = array(); |
|
| 207 | - static $dst = array(); |
|
| 206 | + static $src = array(); |
|
| 207 | + static $dst = array(); |
|
| 208 | 208 | |
| 209 | - // si on recoit un tableau, on est en mode echappement |
|
| 210 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 211 | - if (is_array($r)) { |
|
| 212 | - $dst[] = $r[0]; |
|
| 209 | + // si on recoit un tableau, on est en mode echappement |
|
| 210 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 211 | + if (is_array($r)) { |
|
| 212 | + $dst[] = $r[0]; |
|
| 213 | 213 | |
| 214 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 215 | - } |
|
| 214 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 218 | - // et on RAZ les remplacements |
|
| 219 | - $r = array($src, $dst); |
|
| 220 | - $src = $dst = array(); |
|
| 217 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 218 | + // et on RAZ les remplacements |
|
| 219 | + $r = array($src, $dst); |
|
| 220 | + $src = $dst = array(); |
|
| 221 | 221 | |
| 222 | - return $r; |
|
| 222 | + return $r; |
|
| 223 | 223 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 44 | + $code = "'".str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte)."'"; |
|
| 45 | 45 | |
| 46 | 46 | return $code; |
| 47 | 47 | } |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 164 | 164 | $series_filtres = func_get_args(); |
| 165 | - array_shift($series_filtres);// skel |
|
| 166 | - array_shift($series_filtres);// corps |
|
| 165 | + array_shift($series_filtres); // skel |
|
| 166 | + array_shift($series_filtres); // corps |
|
| 167 | 167 | |
| 168 | 168 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 169 | 169 | if ($skel['process_ins'] == 'php') { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | if (is_array($r)) { |
| 212 | 212 | $dst[] = $r[0]; |
| 213 | 213 | |
| 214 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 214 | + return $src[] = '___'.md5($r[0]).'___'; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | // si on recoit pas un tableau, on renvoit les couples de substitution |
@@ -236,7 +236,7 @@ |
||
| 236 | 236 | * @param string $type |
| 237 | 237 | * @param string $ext |
| 238 | 238 | * @param bool $echafauder |
| 239 | - * @return mixed |
|
| 239 | + * @return string|boolean |
|
| 240 | 240 | */ |
| 241 | 241 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 242 | 242 | if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\Public\Styliser |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined("_ECRIRE_INC_VERSION")) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -29,181 +29,181 @@ discard block |
||
| 29 | 29 | * @return array Données modifiées du pipeline |
| 30 | 30 | */ |
| 31 | 31 | function public_styliser_par_z_dist($flux) { |
| 32 | - static $prefix_path = null; |
|
| 33 | - static $prefix_length; |
|
| 34 | - static $z_blocs; |
|
| 35 | - static $apl_constant; |
|
| 36 | - static $page; |
|
| 37 | - static $disponible = array(); |
|
| 38 | - static $echafauder; |
|
| 39 | - static $prepend = ""; |
|
| 40 | - |
|
| 41 | - if (!isset($prefix_path)) { |
|
| 42 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | - if (test_espace_prive()) { |
|
| 44 | - $prefix_path = "prive/squelettes/"; |
|
| 45 | - $prefix_length = strlen($prefix_path); |
|
| 46 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | - $page = 'exec'; |
|
| 48 | - $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | - define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | - } else { |
|
| 51 | - $prefix_path = ""; |
|
| 52 | - $prefix_length = 0; |
|
| 53 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | - $page = _SPIP_PAGE; |
|
| 55 | - $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(_DIR_PLUGIN_DIST, |
|
| 57 | - '/') : '')); |
|
| 58 | - } |
|
| 59 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ""); |
|
| 60 | - } |
|
| 61 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 62 | - |
|
| 63 | - $fond = $flux['args']['fond']; |
|
| 64 | - |
|
| 65 | - if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 66 | - $fond = substr($fond, $prefix_length); |
|
| 67 | - $squelette = $flux['data']; |
|
| 68 | - $ext = $flux['args']['ext']; |
|
| 69 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 70 | - if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 71 | - and $dir = explode('/', $fond) |
|
| 72 | - and count($dir) == 2 // pas un sous repertoire |
|
| 73 | - and $dir = reset($dir) |
|
| 74 | - and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 75 | - and defined($apl_constant) |
|
| 76 | - and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 77 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 78 | - ) { |
|
| 79 | - $flux['data'] = $pipe; |
|
| 80 | - |
|
| 81 | - return $flux; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 85 | - if ($squelette and !z_fond_valide($squelette)) { |
|
| 86 | - $squelette = ""; |
|
| 87 | - $echafauder = ""; |
|
| 88 | - } |
|
| 89 | - if ($prepend) { |
|
| 90 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 91 | - if ($squelette) { |
|
| 92 | - $flux['data'] = $squelette; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // gerer les squelettes non trouves |
|
| 97 | - // -> router vers les /dist.html |
|
| 98 | - // ou scaffolding ou page automatique les contenus |
|
| 99 | - if (!$squelette) { |
|
| 100 | - |
|
| 101 | - // si on est sur un ?page=XX non trouve |
|
| 102 | - if ((isset($flux['args']['contexte'][$page]) |
|
| 103 | - and $flux['args']['contexte'][$page] == $fond) |
|
| 104 | - or (isset($flux['args']['contexte']['type-page']) |
|
| 105 | - and $flux['args']['contexte']['type-page'] == $fond) |
|
| 106 | - or ($fond == 'sommaire' |
|
| 107 | - and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 108 | - ) { |
|
| 109 | - |
|
| 110 | - // si on est sur un ?page=XX non trouve |
|
| 111 | - // se brancher sur contenu/xx si il existe |
|
| 112 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 113 | - if (!isset($disponible[$fond])) { |
|
| 114 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if ($disponible[$fond]) { |
|
| 118 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // echafaudage : |
|
| 123 | - // si c'est un fond de contenu d'un objet en base |
|
| 124 | - // generer un fond automatique a la volee pour les webmestres |
|
| 125 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 126 | - $type = substr($fond, strlen($z_contenu) + 1); |
|
| 127 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 128 | - $type = $flux['args']['contexte'][$page]; |
|
| 129 | - } |
|
| 130 | - if (!isset($disponible[$type])) { |
|
| 131 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 132 | - } |
|
| 133 | - if (is_string($disponible[$type])) { |
|
| 134 | - $flux['data'] = $disponible[$type]; |
|
| 135 | - } elseif ($echafauder |
|
| 136 | - and include_spip('inc/autoriser') |
|
| 137 | - and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 138 | - and autoriser('echafauder', $type) |
|
| 139 | - and $is = $disponible[$type] |
|
| 140 | - and is_array($is) |
|
| 141 | - ) { |
|
| 142 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 143 | - } else { |
|
| 144 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, '404', $ext, |
|
| 145 | - $echafauder)); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 150 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 151 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 152 | - else { |
|
| 153 | - if ($dir = explode('/', $fond) |
|
| 154 | - and $dir = reset($dir) |
|
| 155 | - and $dir !== $z_contenu |
|
| 156 | - and in_array($dir, $z_blocs) |
|
| 157 | - ) { |
|
| 158 | - $type = substr($fond, strlen("$dir/")); |
|
| 159 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 160 | - $type = $flux['args']['contexte'][$page]; |
|
| 161 | - } |
|
| 162 | - if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 163 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 164 | - } |
|
| 165 | - if ($type == 'page' or $disponible[$type]) { |
|
| 166 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - $squelette = $flux['data']; |
|
| 171 | - } |
|
| 172 | - // layout specifiques par type et compositions : |
|
| 173 | - // body-article.html |
|
| 174 | - // body-sommaire.html |
|
| 175 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 176 | - // meme dossier que body.html |
|
| 177 | - if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 178 | - if (isset($flux['args']['contexte']['type-page']) |
|
| 179 | - and ( |
|
| 180 | - (isset($flux['args']['contexte']['composition']) |
|
| 181 | - and file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page'] . "-" . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 182 | - or |
|
| 183 | - file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 184 | - ) |
|
| 185 | - ) { |
|
| 186 | - $flux['data'] = $f; |
|
| 187 | - } |
|
| 188 | - } elseif ($fond == 'structure' |
|
| 189 | - and z_sanitize_var_zajax() |
|
| 190 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 191 | - ) { |
|
| 192 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 193 | - } // chercher le fond correspondant a la composition |
|
| 194 | - elseif (isset($flux['args']['contexte']['composition']) |
|
| 195 | - and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 196 | - and $dir = substr($fond, $prefix_length) |
|
| 197 | - and $dir = explode('/', $dir) |
|
| 198 | - and $dir = reset($dir) |
|
| 199 | - and in_array($dir, $z_blocs) |
|
| 200 | - and $f = find_in_path($prefix_path . $prepend . $fond . "-" . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 201 | - ) { |
|
| 202 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $flux; |
|
| 32 | + static $prefix_path = null; |
|
| 33 | + static $prefix_length; |
|
| 34 | + static $z_blocs; |
|
| 35 | + static $apl_constant; |
|
| 36 | + static $page; |
|
| 37 | + static $disponible = array(); |
|
| 38 | + static $echafauder; |
|
| 39 | + static $prepend = ""; |
|
| 40 | + |
|
| 41 | + if (!isset($prefix_path)) { |
|
| 42 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | + if (test_espace_prive()) { |
|
| 44 | + $prefix_path = "prive/squelettes/"; |
|
| 45 | + $prefix_length = strlen($prefix_path); |
|
| 46 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | + $page = 'exec'; |
|
| 48 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | + } else { |
|
| 51 | + $prefix_path = ""; |
|
| 52 | + $prefix_length = 0; |
|
| 53 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | + $page = _SPIP_PAGE; |
|
| 55 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(_DIR_PLUGIN_DIST, |
|
| 57 | + '/') : '')); |
|
| 58 | + } |
|
| 59 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ""); |
|
| 60 | + } |
|
| 61 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 62 | + |
|
| 63 | + $fond = $flux['args']['fond']; |
|
| 64 | + |
|
| 65 | + if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 66 | + $fond = substr($fond, $prefix_length); |
|
| 67 | + $squelette = $flux['data']; |
|
| 68 | + $ext = $flux['args']['ext']; |
|
| 69 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 70 | + if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 71 | + and $dir = explode('/', $fond) |
|
| 72 | + and count($dir) == 2 // pas un sous repertoire |
|
| 73 | + and $dir = reset($dir) |
|
| 74 | + and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 75 | + and defined($apl_constant) |
|
| 76 | + and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 77 | + and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 78 | + ) { |
|
| 79 | + $flux['data'] = $pipe; |
|
| 80 | + |
|
| 81 | + return $flux; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 85 | + if ($squelette and !z_fond_valide($squelette)) { |
|
| 86 | + $squelette = ""; |
|
| 87 | + $echafauder = ""; |
|
| 88 | + } |
|
| 89 | + if ($prepend) { |
|
| 90 | + $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 91 | + if ($squelette) { |
|
| 92 | + $flux['data'] = $squelette; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // gerer les squelettes non trouves |
|
| 97 | + // -> router vers les /dist.html |
|
| 98 | + // ou scaffolding ou page automatique les contenus |
|
| 99 | + if (!$squelette) { |
|
| 100 | + |
|
| 101 | + // si on est sur un ?page=XX non trouve |
|
| 102 | + if ((isset($flux['args']['contexte'][$page]) |
|
| 103 | + and $flux['args']['contexte'][$page] == $fond) |
|
| 104 | + or (isset($flux['args']['contexte']['type-page']) |
|
| 105 | + and $flux['args']['contexte']['type-page'] == $fond) |
|
| 106 | + or ($fond == 'sommaire' |
|
| 107 | + and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 108 | + ) { |
|
| 109 | + |
|
| 110 | + // si on est sur un ?page=XX non trouve |
|
| 111 | + // se brancher sur contenu/xx si il existe |
|
| 112 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 113 | + if (!isset($disponible[$fond])) { |
|
| 114 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if ($disponible[$fond]) { |
|
| 118 | + $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // echafaudage : |
|
| 123 | + // si c'est un fond de contenu d'un objet en base |
|
| 124 | + // generer un fond automatique a la volee pour les webmestres |
|
| 125 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 126 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 127 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 128 | + $type = $flux['args']['contexte'][$page]; |
|
| 129 | + } |
|
| 130 | + if (!isset($disponible[$type])) { |
|
| 131 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 132 | + } |
|
| 133 | + if (is_string($disponible[$type])) { |
|
| 134 | + $flux['data'] = $disponible[$type]; |
|
| 135 | + } elseif ($echafauder |
|
| 136 | + and include_spip('inc/autoriser') |
|
| 137 | + and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 138 | + and autoriser('echafauder', $type) |
|
| 139 | + and $is = $disponible[$type] |
|
| 140 | + and is_array($is) |
|
| 141 | + ) { |
|
| 142 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 143 | + } else { |
|
| 144 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, '404', $ext, |
|
| 145 | + $echafauder)); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 150 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 151 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 152 | + else { |
|
| 153 | + if ($dir = explode('/', $fond) |
|
| 154 | + and $dir = reset($dir) |
|
| 155 | + and $dir !== $z_contenu |
|
| 156 | + and in_array($dir, $z_blocs) |
|
| 157 | + ) { |
|
| 158 | + $type = substr($fond, strlen("$dir/")); |
|
| 159 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 160 | + $type = $flux['args']['contexte'][$page]; |
|
| 161 | + } |
|
| 162 | + if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 163 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 164 | + } |
|
| 165 | + if ($type == 'page' or $disponible[$type]) { |
|
| 166 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + $squelette = $flux['data']; |
|
| 171 | + } |
|
| 172 | + // layout specifiques par type et compositions : |
|
| 173 | + // body-article.html |
|
| 174 | + // body-sommaire.html |
|
| 175 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 176 | + // meme dossier que body.html |
|
| 177 | + if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 178 | + if (isset($flux['args']['contexte']['type-page']) |
|
| 179 | + and ( |
|
| 180 | + (isset($flux['args']['contexte']['composition']) |
|
| 181 | + and file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page'] . "-" . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 182 | + or |
|
| 183 | + file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 184 | + ) |
|
| 185 | + ) { |
|
| 186 | + $flux['data'] = $f; |
|
| 187 | + } |
|
| 188 | + } elseif ($fond == 'structure' |
|
| 189 | + and z_sanitize_var_zajax() |
|
| 190 | + and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 191 | + ) { |
|
| 192 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 193 | + } // chercher le fond correspondant a la composition |
|
| 194 | + elseif (isset($flux['args']['contexte']['composition']) |
|
| 195 | + and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 196 | + and $dir = substr($fond, $prefix_length) |
|
| 197 | + and $dir = explode('/', $dir) |
|
| 198 | + and $dir = reset($dir) |
|
| 199 | + and in_array($dir, $z_blocs) |
|
| 200 | + and $f = find_in_path($prefix_path . $prepend . $fond . "-" . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 201 | + ) { |
|
| 202 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $flux; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -213,18 +213,18 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function z_blocs($espace_prive = false) { |
| 216 | - if ($espace_prive) { |
|
| 217 | - return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : array( |
|
| 218 | - 'contenu', |
|
| 219 | - 'navigation', |
|
| 220 | - 'extra', |
|
| 221 | - 'head', |
|
| 222 | - 'hierarchie', |
|
| 223 | - 'top' |
|
| 224 | - )); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : array('contenu')); |
|
| 216 | + if ($espace_prive) { |
|
| 217 | + return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : array( |
|
| 218 | + 'contenu', |
|
| 219 | + 'navigation', |
|
| 220 | + 'extra', |
|
| 221 | + 'head', |
|
| 222 | + 'hierarchie', |
|
| 223 | + 'top' |
|
| 224 | + )); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : array('contenu')); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | * @return mixed |
| 240 | 240 | */ |
| 241 | 241 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 242 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 243 | - return $d; |
|
| 244 | - } |
|
| 242 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 243 | + return $d; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 246 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -257,13 +257,13 @@ discard block |
||
| 257 | 257 | * `true` si on peut l'utiliser, `false` sinon. |
| 258 | 258 | **/ |
| 259 | 259 | function z_fond_valide($squelette) { |
| 260 | - if (!_ZCORE_EXCLURE_PATH |
|
| 261 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 262 | - ) { |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 260 | + if (!_ZCORE_EXCLURE_PATH |
|
| 261 | + or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 262 | + ) { |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - return false; |
|
| 266 | + return false; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -281,14 +281,14 @@ discard block |
||
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | 283 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 284 | - if ( |
|
| 285 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 286 | - or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 287 | - ) { |
|
| 288 | - return substr($f, 0, -strlen(".$ext")); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return ""; |
|
| 284 | + if ( |
|
| 285 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 286 | + or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 287 | + ) { |
|
| 288 | + return substr($f, 0, -strlen(".$ext")); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return ""; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -300,51 +300,51 @@ discard block |
||
| 300 | 300 | * @return bool |
| 301 | 301 | */ |
| 302 | 302 | function z_echafaudable($type) { |
| 303 | - static $pages = null; |
|
| 304 | - static $echafaudable = array(); |
|
| 305 | - if (isset($echafaudable[$type])) { |
|
| 306 | - return $echafaudable[$type]; |
|
| 307 | - } |
|
| 308 | - if (preg_match(',[^\w],', $type)) { |
|
| 309 | - return $echafaudable[$type] = false; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if (test_espace_prive()) { |
|
| 313 | - if (!function_exists('trouver_objet_exec')) { |
|
| 314 | - include_spip('inc/pipelines_ecrire'); |
|
| 315 | - } |
|
| 316 | - if ($e = trouver_objet_exec($type)) { |
|
| 317 | - return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $e); |
|
| 318 | - } else { |
|
| 319 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 320 | - if (($t = objet_type($type, false)) !== $type |
|
| 321 | - and $e = trouver_objet_exec($t) |
|
| 322 | - ) { |
|
| 323 | - return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $t); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - } else { |
|
| 327 | - if (is_null($pages)) { |
|
| 328 | - $pages = array(); |
|
| 329 | - $liste = lister_tables_objets_sql(); |
|
| 330 | - foreach ($liste as $t => $d) { |
|
| 331 | - if ($d['page']) { |
|
| 332 | - $pages[$d['page']] = array($d['table_objet'], $t); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - if (!isset($pages[$type])) { |
|
| 337 | - return $echafaudable[$type] = false; |
|
| 338 | - } |
|
| 339 | - if (count($pages[$type]) == 2) { |
|
| 340 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - return $echafaudable[$type] = $pages[$type]; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $echafaudable[$type] = false; |
|
| 303 | + static $pages = null; |
|
| 304 | + static $echafaudable = array(); |
|
| 305 | + if (isset($echafaudable[$type])) { |
|
| 306 | + return $echafaudable[$type]; |
|
| 307 | + } |
|
| 308 | + if (preg_match(',[^\w],', $type)) { |
|
| 309 | + return $echafaudable[$type] = false; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if (test_espace_prive()) { |
|
| 313 | + if (!function_exists('trouver_objet_exec')) { |
|
| 314 | + include_spip('inc/pipelines_ecrire'); |
|
| 315 | + } |
|
| 316 | + if ($e = trouver_objet_exec($type)) { |
|
| 317 | + return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $e); |
|
| 318 | + } else { |
|
| 319 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 320 | + if (($t = objet_type($type, false)) !== $type |
|
| 321 | + and $e = trouver_objet_exec($t) |
|
| 322 | + ) { |
|
| 323 | + return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $t); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + } else { |
|
| 327 | + if (is_null($pages)) { |
|
| 328 | + $pages = array(); |
|
| 329 | + $liste = lister_tables_objets_sql(); |
|
| 330 | + foreach ($liste as $t => $d) { |
|
| 331 | + if ($d['page']) { |
|
| 332 | + $pages[$d['page']] = array($d['table_objet'], $t); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + if (!isset($pages[$type])) { |
|
| 337 | + return $echafaudable[$type] = false; |
|
| 338 | + } |
|
| 339 | + if (count($pages[$type]) == 2) { |
|
| 340 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + return $echafaudable[$type] = $pages[$type]; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $echafaudable[$type] = false; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -361,46 +361,46 @@ discard block |
||
| 361 | 361 | * @return string |
| 362 | 362 | */ |
| 363 | 363 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 364 | - $scaffold = ""; |
|
| 365 | - |
|
| 366 | - // page objet ou objet_edit |
|
| 367 | - if (is_array($desc_exec)) { |
|
| 368 | - $type = $desc_exec['type']; |
|
| 369 | - $primary = $desc_exec['id_table_objet']; |
|
| 370 | - |
|
| 371 | - if ($desc_exec['edition'] === false) { |
|
| 372 | - $fond = "objet"; |
|
| 373 | - } else { |
|
| 374 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 375 | - $desc = $trouver_table($table_sql); |
|
| 376 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 377 | - $fond = 'objet_edit'; |
|
| 378 | - } else { |
|
| 379 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - $dir = z_blocs(test_espace_prive()); |
|
| 383 | - $dir = reset($dir); |
|
| 384 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ",objet=" . $type . ",id_objet=#" . strtoupper($primary) . ",env}>"; |
|
| 385 | - } // page objets |
|
| 386 | - elseif ($type = $desc_exec and strpos($type, "/") === false) { |
|
| 387 | - $dir = z_blocs(test_espace_prive()); |
|
| 388 | - $dir = reset($dir); |
|
| 389 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ",env} />"; |
|
| 390 | - } |
|
| 391 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 392 | - // et objet et tire de $table |
|
| 393 | - elseif ($fond = $desc_exec) { |
|
| 394 | - $dir = md5(dirname($fond)); |
|
| 395 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ",env} />"; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - $base_dir = sous_repertoire(_DIR_CACHE, "scaffold", false); |
|
| 399 | - $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 400 | - $f = $base_dir . "$exec"; |
|
| 401 | - ecrire_fichier("$f.$ext", $scaffold); |
|
| 402 | - |
|
| 403 | - return $f; |
|
| 364 | + $scaffold = ""; |
|
| 365 | + |
|
| 366 | + // page objet ou objet_edit |
|
| 367 | + if (is_array($desc_exec)) { |
|
| 368 | + $type = $desc_exec['type']; |
|
| 369 | + $primary = $desc_exec['id_table_objet']; |
|
| 370 | + |
|
| 371 | + if ($desc_exec['edition'] === false) { |
|
| 372 | + $fond = "objet"; |
|
| 373 | + } else { |
|
| 374 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 375 | + $desc = $trouver_table($table_sql); |
|
| 376 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 377 | + $fond = 'objet_edit'; |
|
| 378 | + } else { |
|
| 379 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + $dir = z_blocs(test_espace_prive()); |
|
| 383 | + $dir = reset($dir); |
|
| 384 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ",objet=" . $type . ",id_objet=#" . strtoupper($primary) . ",env}>"; |
|
| 385 | + } // page objets |
|
| 386 | + elseif ($type = $desc_exec and strpos($type, "/") === false) { |
|
| 387 | + $dir = z_blocs(test_espace_prive()); |
|
| 388 | + $dir = reset($dir); |
|
| 389 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ",env} />"; |
|
| 390 | + } |
|
| 391 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 392 | + // et objet et tire de $table |
|
| 393 | + elseif ($fond = $desc_exec) { |
|
| 394 | + $dir = md5(dirname($fond)); |
|
| 395 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ",env} />"; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + $base_dir = sous_repertoire(_DIR_CACHE, "scaffold", false); |
|
| 399 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 400 | + $f = $base_dir . "$exec"; |
|
| 401 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 402 | + |
|
| 403 | + return $f; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -409,16 +409,16 @@ discard block |
||
| 409 | 409 | * @return bool|string |
| 410 | 410 | */ |
| 411 | 411 | function z_sanitize_var_zajax() { |
| 412 | - $z_ajax = _request('var_zajax'); |
|
| 413 | - if (!$z_ajax) { |
|
| 414 | - return false; |
|
| 415 | - } |
|
| 416 | - if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 417 | - or !in_array($z_ajax, $z_blocs) |
|
| 418 | - ) { |
|
| 419 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 420 | - $z_ajax = false; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $z_ajax; |
|
| 412 | + $z_ajax = _request('var_zajax'); |
|
| 413 | + if (!$z_ajax) { |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 416 | + if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 417 | + or !in_array($z_ajax, $z_blocs) |
|
| 418 | + ) { |
|
| 419 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 420 | + $z_ajax = false; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $z_ajax; |
|
| 424 | 424 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
| 54 | 54 | $page = _SPIP_PAGE; |
| 55 | 55 | $echafauder = charger_fonction('echafauder', 'public', true); |
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(_DIR_PLUGIN_DIST, |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim(_DIR_PLUGIN_DIST, |
|
| 57 | 57 | '/') : '')); |
| 58 | 58 | } |
| 59 | 59 | $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ""); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
| 75 | 75 | and defined($apl_constant) |
| 76 | 76 | and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
| 77 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 77 | + and $pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 78 | 78 | ) { |
| 79 | 79 | $flux['data'] = $pipe; |
| 80 | 80 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $echafauder = ""; |
| 88 | 88 | } |
| 89 | 89 | if ($prepend) { |
| 90 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 90 | + $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext")); |
|
| 91 | 91 | if ($squelette) { |
| 92 | 92 | $flux['data'] = $squelette; |
| 93 | 93 | } |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | // se brancher sur contenu/xx si il existe |
| 112 | 112 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 113 | 113 | if (!isset($disponible[$fond])) { |
| 114 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 114 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if ($disponible[$fond]) { |
| 118 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 118 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext")); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $type = $flux['args']['contexte'][$page]; |
| 129 | 129 | } |
| 130 | 130 | if (!isset($disponible[$type])) { |
| 131 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 131 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 132 | 132 | } |
| 133 | 133 | if (is_string($disponible[$type])) { |
| 134 | 134 | $flux['data'] = $disponible[$type]; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | ) { |
| 142 | 142 | $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
| 143 | 143 | } else { |
| 144 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, '404', $ext, |
|
| 144 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, '404', $ext, |
|
| 145 | 145 | $echafauder)); |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | $type = $flux['args']['contexte'][$page]; |
| 161 | 161 | } |
| 162 | 162 | if ($type !== 'page' and !isset($disponible[$type])) { |
| 163 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 163 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 164 | 164 | } |
| 165 | 165 | if ($type == 'page' or $disponible[$type]) { |
| 166 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 166 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | if (isset($flux['args']['contexte']['type-page']) |
| 179 | 179 | and ( |
| 180 | 180 | (isset($flux['args']['contexte']['composition']) |
| 181 | - and file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page'] . "-" . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 181 | + and file_exists(($f = $squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 182 | 182 | or |
| 183 | - file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 183 | + file_exists(($f = $squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 184 | 184 | ) |
| 185 | 185 | ) { |
| 186 | 186 | $flux['data'] = $f; |
| 187 | 187 | } |
| 188 | 188 | } elseif ($fond == 'structure' |
| 189 | 189 | and z_sanitize_var_zajax() |
| 190 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 190 | + and $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext") |
|
| 191 | 191 | ) { |
| 192 | 192 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 193 | 193 | } // chercher le fond correspondant a la composition |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | and $dir = explode('/', $dir) |
| 198 | 198 | and $dir = reset($dir) |
| 199 | 199 | and in_array($dir, $z_blocs) |
| 200 | - and $f = find_in_path($prefix_path . $prepend . $fond . "-" . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 200 | + and $f = find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext") |
|
| 201 | 201 | ) { |
| 202 | 202 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 203 | 203 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | **/ |
| 259 | 259 | function z_fond_valide($squelette) { |
| 260 | 260 | if (!_ZCORE_EXCLURE_PATH |
| 261 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 261 | + or !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette) |
|
| 262 | 262 | ) { |
| 263 | 263 | return true; |
| 264 | 264 | } |
@@ -381,23 +381,23 @@ discard block |
||
| 381 | 381 | } |
| 382 | 382 | $dir = z_blocs(test_espace_prive()); |
| 383 | 383 | $dir = reset($dir); |
| 384 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ",objet=" . $type . ",id_objet=#" . strtoupper($primary) . ",env}>"; |
|
| 384 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.",objet=".$type.",id_objet=#".strtoupper($primary).",env}>"; |
|
| 385 | 385 | } // page objets |
| 386 | 386 | elseif ($type = $desc_exec and strpos($type, "/") === false) { |
| 387 | 387 | $dir = z_blocs(test_espace_prive()); |
| 388 | 388 | $dir = reset($dir); |
| 389 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ",env} />"; |
|
| 389 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.",env} />"; |
|
| 390 | 390 | } |
| 391 | 391 | // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
| 392 | 392 | // et objet et tire de $table |
| 393 | 393 | elseif ($fond = $desc_exec) { |
| 394 | 394 | $dir = md5(dirname($fond)); |
| 395 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ",env} />"; |
|
| 395 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).",env} />"; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | $base_dir = sous_repertoire(_DIR_CACHE, "scaffold", false); |
| 399 | 399 | $base_dir = sous_repertoire($base_dir, $dir, false); |
| 400 | - $f = $base_dir . "$exec"; |
|
| 400 | + $f = $base_dir."$exec"; |
|
| 401 | 401 | ecrire_fichier("$f.$ext", $scaffold); |
| 402 | 402 | |
| 403 | 403 | return $f; |