@@ -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(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -59,42 +59,42 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 62 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 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 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | - } else { |
|
| 81 | - $code = "$f($code$arglist)"; |
|
| 82 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | - } |
|
| 84 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | - if (($nb_args_f < $min_f)) { |
|
| 87 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - // le filtre n'existe pas, |
|
| 92 | - // on le notifie |
|
| 93 | - else { |
|
| 94 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $code; |
|
| 62 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 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 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | + } else { |
|
| 81 | + $code = "$f($code$arglist)"; |
|
| 82 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | + } |
|
| 84 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | + if (($nb_args_f < $min_f)) { |
|
| 87 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + // le filtre n'existe pas, |
|
| 92 | + // on le notifie |
|
| 93 | + else { |
|
| 94 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $code; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Calculer un <INCLURE(xx.php)> |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | 119 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 120 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | - // si inexistant, on essaiera a l'execution |
|
| 122 | - if ($path = find_in_path($fichier)) { |
|
| 123 | - $path = "\"$path\""; |
|
| 124 | - } else { |
|
| 125 | - $path = "find_in_path(\"$fichier\")"; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 120 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | + // si inexistant, on essaiera a l'execution |
|
| 122 | + if ($path = find_in_path($fichier)) { |
|
| 123 | + $path = "\"$path\""; |
|
| 124 | + } else { |
|
| 125 | + $path = "find_in_path(\"$fichier\")"; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -137,20 +137,20 @@ discard block |
||
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | 139 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 140 | - // Securite |
|
| 141 | - if ( |
|
| 142 | - $p->interdire_scripts |
|
| 143 | - and $p->etoile != '**' |
|
| 144 | - ) { |
|
| 145 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | - $code = "interdire_scripts($code)"; |
|
| 147 | - } else { |
|
| 148 | - $code = interdire_scripts($r[2]); |
|
| 149 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $code; |
|
| 140 | + // Securite |
|
| 141 | + if ( |
|
| 142 | + $p->interdire_scripts |
|
| 143 | + and $p->etoile != '**' |
|
| 144 | + ) { |
|
| 145 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | + $code = "interdire_scripts($code)"; |
|
| 147 | + } else { |
|
| 148 | + $code = interdire_scripts($r[2]); |
|
| 149 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $code; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -169,30 +169,30 @@ discard block |
||
| 169 | 169 | * @return mixed|string |
| 170 | 170 | */ |
| 171 | 171 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 172 | - $series_filtres = func_get_args(); |
|
| 173 | - array_shift($series_filtres);// skel |
|
| 174 | - array_shift($series_filtres);// corps |
|
| 175 | - |
|
| 176 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | - if ($skel['process_ins'] == 'php') { |
|
| 178 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // recuperer les couples de remplacement |
|
| 182 | - $replace = echapper_php_callback(); |
|
| 183 | - |
|
| 184 | - foreach ($series_filtres as $filtres) { |
|
| 185 | - if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | - foreach ($filtres as $filtre) { |
|
| 187 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | - $corps = $f($corps); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // restaurer les echappements |
|
| 195 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 172 | + $series_filtres = func_get_args(); |
|
| 173 | + array_shift($series_filtres);// skel |
|
| 174 | + array_shift($series_filtres);// corps |
|
| 175 | + |
|
| 176 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | + if ($skel['process_ins'] == 'php') { |
|
| 178 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // recuperer les couples de remplacement |
|
| 182 | + $replace = echapper_php_callback(); |
|
| 183 | + |
|
| 184 | + foreach ($series_filtres as $filtres) { |
|
| 185 | + if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | + foreach ($filtres as $filtre) { |
|
| 187 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | + $corps = $f($corps); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // restaurer les echappements |
|
| 195 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
@@ -211,21 +211,21 @@ discard block |
||
| 211 | 211 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 212 | 212 | **/ |
| 213 | 213 | function echapper_php_callback($r = null) { |
| 214 | - static $src = []; |
|
| 215 | - static $dst = []; |
|
| 214 | + static $src = []; |
|
| 215 | + static $dst = []; |
|
| 216 | 216 | |
| 217 | - // si on recoit un tableau, on est en mode echappement |
|
| 218 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | - if (is_array($r)) { |
|
| 220 | - $dst[] = $r[0]; |
|
| 217 | + // si on recoit un tableau, on est en mode echappement |
|
| 218 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | + if (is_array($r)) { |
|
| 220 | + $dst[] = $r[0]; |
|
| 221 | 221 | |
| 222 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | - } |
|
| 222 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | - // et on RAZ les remplacements |
|
| 227 | - $r = [$src, $dst]; |
|
| 228 | - $src = $dst = []; |
|
| 225 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | + // et on RAZ les remplacements |
|
| 227 | + $r = [$src, $dst]; |
|
| 228 | + $src = $dst = []; |
|
| 229 | 229 | |
| 230 | - return $r; |
|
| 230 | + return $r; |
|
| 231 | 231 | } |
@@ -11,129 +11,129 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | - |
|
| 31 | - if ($struct->jointures_explicites) { |
|
| 32 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | - } |
|
| 34 | - if ($struct->table_optionnelle) { |
|
| 35 | - $type .= '?'; |
|
| 36 | - } |
|
| 37 | - // Revoir le cas de la boucle recursive |
|
| 38 | - |
|
| 39 | - $crit = $struct->param; |
|
| 40 | - if ($crit and !is_array($crit[0])) { |
|
| 41 | - $type = strtolower($type) . array_shift($crit); |
|
| 42 | - } |
|
| 43 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | - |
|
| 45 | - $f = 'format_boucle_' . $fmt; |
|
| 46 | - |
|
| 47 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | + |
|
| 31 | + if ($struct->jointures_explicites) { |
|
| 32 | + $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | + } |
|
| 34 | + if ($struct->table_optionnelle) { |
|
| 35 | + $type .= '?'; |
|
| 36 | + } |
|
| 37 | + // Revoir le cas de la boucle recursive |
|
| 38 | + |
|
| 39 | + $crit = $struct->param; |
|
| 40 | + if ($crit and !is_array($crit[0])) { |
|
| 41 | + $type = strtolower($type) . array_shift($crit); |
|
| 42 | + } |
|
| 43 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | + |
|
| 45 | + $f = 'format_boucle_' . $fmt; |
|
| 46 | + |
|
| 47 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 51 | - $res = []; |
|
| 52 | - foreach ($struct->param ?: [] as $couple) { |
|
| 53 | - array_shift($couple); |
|
| 54 | - foreach ($couple as $v) { |
|
| 55 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | - $f = 'format_inclure_' . $fmt; |
|
| 61 | - |
|
| 62 | - return $f($file, $res, $prof); |
|
| 51 | + $res = []; |
|
| 52 | + foreach ($struct->param ?: [] as $couple) { |
|
| 53 | + array_shift($couple); |
|
| 54 | + foreach ($couple as $v) { |
|
| 55 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | + $f = 'format_inclure_' . $fmt; |
|
| 61 | + |
|
| 62 | + return $f($file, $res, $prof); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 66 | - $f = 'format_texte_' . $fmt; |
|
| 66 | + $f = 'format_texte_' . $fmt; |
|
| 67 | 67 | |
| 68 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 68 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 72 | - $f = 'format_polyglotte_' . $fmt; |
|
| 72 | + $f = 'format_polyglotte_' . $fmt; |
|
| 73 | 73 | |
| 74 | - return $f($struct->traductions, $prof); |
|
| 74 | + return $f($struct->traductions, $prof); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 78 | - $args = []; |
|
| 79 | - foreach ($struct->arg as $k => $v) { |
|
| 80 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | - } |
|
| 78 | + $args = []; |
|
| 79 | + foreach ($struct->arg as $k => $v) { |
|
| 80 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 83 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | 84 | |
| 85 | - $f = 'format_idiome_' . $fmt; |
|
| 85 | + $f = 'format_idiome_' . $fmt; |
|
| 86 | 86 | |
| 87 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 87 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 91 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | - $args = $filtres = ''; |
|
| 94 | - if ($p = $struct->param) { |
|
| 95 | - if ($p[0][0] === '') { |
|
| 96 | - $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | - } |
|
| 98 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | - } |
|
| 100 | - $f = 'format_champ_' . $fmt; |
|
| 101 | - |
|
| 102 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 91 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | + $args = $filtres = ''; |
|
| 94 | + if ($p = $struct->param) { |
|
| 95 | + if ($p[0][0] === '') { |
|
| 96 | + $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | + } |
|
| 98 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | + } |
|
| 100 | + $f = 'format_champ_' . $fmt; |
|
| 101 | + |
|
| 102 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 106 | - if (!is_array($sources)) { |
|
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - $f = 'format_liste_' . $fmt; |
|
| 110 | - $res = ''; |
|
| 111 | - foreach ($sources as $arg) { |
|
| 112 | - if (!is_array($arg)) { |
|
| 113 | - continue; // ne devrait pas arriver. |
|
| 114 | - } else { |
|
| 115 | - $r = array_shift($arg); |
|
| 116 | - } |
|
| 117 | - $args = []; |
|
| 118 | - foreach ($arg as $v) { |
|
| 119 | - // cas des arguments entoures de ' ou " |
|
| 120 | - if ( |
|
| 121 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | - and $v[0]->type == 'texte' |
|
| 123 | - and (strlen($v[0]->apres) == 1) |
|
| 124 | - and $v[0]->apres == $v[0]->avant |
|
| 125 | - ) { |
|
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | - } else { |
|
| 128 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (($r !== '') or $args) { |
|
| 132 | - $res .= $f($r, $args, $prof); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $res; |
|
| 106 | + if (!is_array($sources)) { |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + $f = 'format_liste_' . $fmt; |
|
| 110 | + $res = ''; |
|
| 111 | + foreach ($sources as $arg) { |
|
| 112 | + if (!is_array($arg)) { |
|
| 113 | + continue; // ne devrait pas arriver. |
|
| 114 | + } else { |
|
| 115 | + $r = array_shift($arg); |
|
| 116 | + } |
|
| 117 | + $args = []; |
|
| 118 | + foreach ($arg as $v) { |
|
| 119 | + // cas des arguments entoures de ' ou " |
|
| 120 | + if ( |
|
| 121 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | + and $v[0]->type == 'texte' |
|
| 123 | + and (strlen($v[0]->apres) == 1) |
|
| 124 | + and $v[0]->apres == $v[0]->avant |
|
| 125 | + ) { |
|
| 126 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | + } else { |
|
| 128 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (($r !== '') or $args) { |
|
| 132 | + $res .= $f($r, $args, $prof); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $res; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Decompilation des criteres: on triche et on deroge: |
@@ -141,93 +141,93 @@ discard block |
||
| 141 | 141 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 142 | 142 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 143 | 143 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 144 | - $sources = $boucle->param; |
|
| 145 | - if (!is_array($sources)) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $res = ''; |
|
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 150 | - foreach ($sources as $crit) { |
|
| 151 | - if (!is_array($crit)) { |
|
| 152 | - continue; |
|
| 153 | - } // boucle recursive |
|
| 154 | - array_shift($crit); |
|
| 155 | - $args = []; |
|
| 156 | - foreach ($crit as $i => $v) { |
|
| 157 | - if ( |
|
| 158 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | - and $v[0]->type == 'texte' |
|
| 160 | - and $v[0]->apres |
|
| 161 | - ) { |
|
| 162 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | - } else { |
|
| 164 | - $res2 = []; |
|
| 165 | - foreach ($v as $k => $p) { |
|
| 166 | - if ( |
|
| 167 | - isset($p->type) |
|
| 168 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | - ) { |
|
| 170 | - $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 171 | - $res2[] = [$p->type, $r]; |
|
| 172 | - } else { |
|
| 173 | - spip_log("critere $i / $k mal forme"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - $args[] = $res2; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $res .= $f($args); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return $res; |
|
| 144 | + $sources = $boucle->param; |
|
| 145 | + if (!is_array($sources)) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $res = ''; |
|
| 149 | + $f = 'format_critere_' . $fmt; |
|
| 150 | + foreach ($sources as $crit) { |
|
| 151 | + if (!is_array($crit)) { |
|
| 152 | + continue; |
|
| 153 | + } // boucle recursive |
|
| 154 | + array_shift($crit); |
|
| 155 | + $args = []; |
|
| 156 | + foreach ($crit as $i => $v) { |
|
| 157 | + if ( |
|
| 158 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | + and $v[0]->type == 'texte' |
|
| 160 | + and $v[0]->apres |
|
| 161 | + ) { |
|
| 162 | + $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | + } else { |
|
| 164 | + $res2 = []; |
|
| 165 | + foreach ($v as $k => $p) { |
|
| 166 | + if ( |
|
| 167 | + isset($p->type) |
|
| 168 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | + ) { |
|
| 170 | + $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 171 | + $res2[] = [$p->type, $r]; |
|
| 172 | + } else { |
|
| 173 | + spip_log("critere $i / $k mal forme"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + $args[] = $res2; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $res .= $f($args); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return $res; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 187 | - if (!is_array($liste)) { |
|
| 188 | - return ''; |
|
| 189 | - } |
|
| 190 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | - $contenu = []; |
|
| 192 | - foreach ($liste as $k => $p) { |
|
| 193 | - if (!isset($p->type)) { |
|
| 194 | - continue; |
|
| 195 | - } #?????? |
|
| 196 | - $d = 'decompiler_' . $p->type; |
|
| 197 | - $next = $liste[$k + 1] ?? false; |
|
| 198 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | - // contenait des args et s'il est suivi d'espaces, |
|
| 200 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | - |
|
| 202 | - if ( |
|
| 203 | - $next |
|
| 204 | - and ($next->type == 'texte') |
|
| 205 | - and $p->type == 'champ' |
|
| 206 | - and !$p->apres |
|
| 207 | - and !$p->avant |
|
| 208 | - and $p->fonctions |
|
| 209 | - ) { |
|
| 210 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | - if ($n) { |
|
| 212 | - $champ = new Texte(); |
|
| 213 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | - $champ->ligne = $p->ligne; |
|
| 215 | - $p->apres = [$champ]; |
|
| 216 | - $next->texte = substr($next->texte, $n); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | - } |
|
| 221 | - $f = 'format_suite_' . $fmt; |
|
| 222 | - |
|
| 223 | - return $f($contenu); |
|
| 187 | + if (!is_array($liste)) { |
|
| 188 | + return ''; |
|
| 189 | + } |
|
| 190 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | + $contenu = []; |
|
| 192 | + foreach ($liste as $k => $p) { |
|
| 193 | + if (!isset($p->type)) { |
|
| 194 | + continue; |
|
| 195 | + } #?????? |
|
| 196 | + $d = 'decompiler_' . $p->type; |
|
| 197 | + $next = $liste[$k + 1] ?? false; |
|
| 198 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | + // contenait des args et s'il est suivi d'espaces, |
|
| 200 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | + |
|
| 202 | + if ( |
|
| 203 | + $next |
|
| 204 | + and ($next->type == 'texte') |
|
| 205 | + and $p->type == 'champ' |
|
| 206 | + and !$p->apres |
|
| 207 | + and !$p->avant |
|
| 208 | + and $p->fonctions |
|
| 209 | + ) { |
|
| 210 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | + if ($n) { |
|
| 212 | + $champ = new Texte(); |
|
| 213 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | + $champ->ligne = $p->ligne; |
|
| 215 | + $p->apres = [$champ]; |
|
| 216 | + $next->texte = substr($next->texte, $n); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | + } |
|
| 221 | + $f = 'format_suite_' . $fmt; |
|
| 222 | + |
|
| 223 | + return $f($contenu); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 227 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | - return "'$fmt'?"; |
|
| 229 | - } |
|
| 230 | - $f = 'decompiler_' . $quoi; |
|
| 227 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | + return "'$fmt'?"; |
|
| 229 | + } |
|
| 230 | + $f = 'decompiler_' . $quoi; |
|
| 231 | 231 | |
| 232 | - return $f($liste, $fmt, $prof); |
|
| 232 | + return $f($liste, $fmt, $prof); |
|
| 233 | 233 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - [$id_rubrique, $lang] = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + [$id_rubrique, $lang] = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = $row['lang'] ?? ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = $row['lang'] ?? ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |
@@ -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 | /** |
@@ -21,667 +21,667 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | class IterFactory { |
| 24 | - public static function create($iterateur, $command, $info = null) { |
|
| 25 | - |
|
| 26 | - $iter = null; |
|
| 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(), [], $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 = $command['args'] ?? []; |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 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 (is_countable($a) ? count($a) : 0) { |
|
| 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 ( |
|
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | - or !class_exists($class) |
|
| 87 | - ) { |
|
| 88 | - die("Iterateur $iterateur non trouvé"); |
|
| 89 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | - # $iter = new EmptyIterator(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - $iter = new $class($command, $info); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return new IterDecorator($iter, $command, $info); |
|
| 97 | - } |
|
| 24 | + public static function create($iterateur, $command, $info = null) { |
|
| 25 | + |
|
| 26 | + $iter = null; |
|
| 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(), [], $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 = $command['args'] ?? []; |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 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 (is_countable($a) ? count($a) : 0) { |
|
| 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 ( |
|
| 85 | + !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | + or !class_exists($class) |
|
| 87 | + ) { |
|
| 88 | + die("Iterateur $iterateur non trouvé"); |
|
| 89 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | + # $iter = new EmptyIterator(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + $iter = new $class($command, $info); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return new IterDecorator($iter, $command, $info); |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | class IterDecorator extends FilterIterator { |
| 102 | - private $iter; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Conditions de filtrage |
|
| 106 | - * ie criteres de selection |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $filtre = []; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | - * |
|
| 115 | - * @var string |
|
| 116 | - */ |
|
| 117 | - protected $func_filtre = null; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Critere {offset, limit} |
|
| 121 | - * |
|
| 122 | - * @var int |
|
| 123 | - * @var int |
|
| 124 | - */ |
|
| 125 | - protected $offset = null; |
|
| 126 | - protected $limit = null; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * nombre d'elements recuperes depuis la position 0, |
|
| 130 | - * en tenant compte des filtres |
|
| 131 | - * |
|
| 132 | - * @var int |
|
| 133 | - */ |
|
| 134 | - protected $fetched = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Y a t'il une erreur ? |
|
| 138 | - * |
|
| 139 | - * @var bool |
|
| 140 | - **/ |
|
| 141 | - protected $err = false; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Drapeau a activer en cas d'echec |
|
| 145 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | - */ |
|
| 147 | - public function err() { |
|
| 148 | - if (method_exists($this->iter, 'err')) { |
|
| 149 | - return $this->iter->err(); |
|
| 150 | - } |
|
| 151 | - if (property_exists($this->iter, 'err')) { |
|
| 152 | - return $this->iter->err; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | - parent::__construct($iter); |
|
| 160 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | - |
|
| 162 | - // recuperer l'iterateur transmis |
|
| 163 | - $this->iter = $this->getInnerIterator(); |
|
| 164 | - $this->command = $command; |
|
| 165 | - $this->info = $info; |
|
| 166 | - $this->pos = 0; |
|
| 167 | - $this->fetched = 0; |
|
| 168 | - |
|
| 169 | - // chercher la liste des champs a retourner par |
|
| 170 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | - $this->calculer_select(); |
|
| 173 | - $this->calculer_filtres(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | - if (isset($this->iter->err)) { |
|
| 178 | - $this->err = $this->iter->err; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | - //$this->total = $this->count(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - // calcule les elements a retournes par fetch() |
|
| 187 | - // enleve les elements inutiles du select() |
|
| 188 | - // |
|
| 189 | - private function calculer_select() { |
|
| 190 | - if ($select = &$this->command['select']) { |
|
| 191 | - foreach ($select as $s) { |
|
| 192 | - // /!\ $s = '.nom' |
|
| 193 | - if ($s[0] == '.') { |
|
| 194 | - $s = substr($s, 1); |
|
| 195 | - } |
|
| 196 | - $this->select[] = $s; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // recuperer la valeur d'une balise #X |
|
| 202 | - // en fonction des methodes |
|
| 203 | - // et proprietes disponibles |
|
| 204 | - public function get_select($nom) { |
|
| 205 | - if ( |
|
| 206 | - is_object($this->iter) |
|
| 207 | - and method_exists($this->iter, $nom) |
|
| 208 | - ) { |
|
| 209 | - try { |
|
| 210 | - return $this->iter->$nom(); |
|
| 211 | - } catch (Exception $e) { |
|
| 212 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | - |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - /* |
|
| 102 | + private $iter; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Conditions de filtrage |
|
| 106 | + * ie criteres de selection |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $filtre = []; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | + * |
|
| 115 | + * @var string |
|
| 116 | + */ |
|
| 117 | + protected $func_filtre = null; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Critere {offset, limit} |
|
| 121 | + * |
|
| 122 | + * @var int |
|
| 123 | + * @var int |
|
| 124 | + */ |
|
| 125 | + protected $offset = null; |
|
| 126 | + protected $limit = null; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * nombre d'elements recuperes depuis la position 0, |
|
| 130 | + * en tenant compte des filtres |
|
| 131 | + * |
|
| 132 | + * @var int |
|
| 133 | + */ |
|
| 134 | + protected $fetched = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Y a t'il une erreur ? |
|
| 138 | + * |
|
| 139 | + * @var bool |
|
| 140 | + **/ |
|
| 141 | + protected $err = false; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Drapeau a activer en cas d'echec |
|
| 145 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | + */ |
|
| 147 | + public function err() { |
|
| 148 | + if (method_exists($this->iter, 'err')) { |
|
| 149 | + return $this->iter->err(); |
|
| 150 | + } |
|
| 151 | + if (property_exists($this->iter, 'err')) { |
|
| 152 | + return $this->iter->err; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | + parent::__construct($iter); |
|
| 160 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | + |
|
| 162 | + // recuperer l'iterateur transmis |
|
| 163 | + $this->iter = $this->getInnerIterator(); |
|
| 164 | + $this->command = $command; |
|
| 165 | + $this->info = $info; |
|
| 166 | + $this->pos = 0; |
|
| 167 | + $this->fetched = 0; |
|
| 168 | + |
|
| 169 | + // chercher la liste des champs a retourner par |
|
| 170 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | + $this->calculer_select(); |
|
| 173 | + $this->calculer_filtres(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | + if (isset($this->iter->err)) { |
|
| 178 | + $this->err = $this->iter->err; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | + //$this->total = $this->count(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + // calcule les elements a retournes par fetch() |
|
| 187 | + // enleve les elements inutiles du select() |
|
| 188 | + // |
|
| 189 | + private function calculer_select() { |
|
| 190 | + if ($select = &$this->command['select']) { |
|
| 191 | + foreach ($select as $s) { |
|
| 192 | + // /!\ $s = '.nom' |
|
| 193 | + if ($s[0] == '.') { |
|
| 194 | + $s = substr($s, 1); |
|
| 195 | + } |
|
| 196 | + $this->select[] = $s; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // recuperer la valeur d'une balise #X |
|
| 202 | + // en fonction des methodes |
|
| 203 | + // et proprietes disponibles |
|
| 204 | + public function get_select($nom) { |
|
| 205 | + if ( |
|
| 206 | + is_object($this->iter) |
|
| 207 | + and method_exists($this->iter, $nom) |
|
| 208 | + ) { |
|
| 209 | + try { |
|
| 210 | + return $this->iter->$nom(); |
|
| 211 | + } catch (Exception $e) { |
|
| 212 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | + |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + /* |
|
| 220 | 220 | if (property_exists($this->iter, $nom)) { |
| 221 | 221 | return $this->iter->$nom; |
| 222 | 222 | }*/ |
| 223 | - // cle et valeur par defaut |
|
| 224 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | - if ( |
|
| 226 | - in_array($nom, ['cle', 'valeur']) |
|
| 227 | - and method_exists($this, $nom) |
|
| 228 | - ) { |
|
| 229 | - return $this->$nom(); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Par defaut chercher en xpath dans la valeur() |
|
| 233 | - return table_valeur($this->valeur(), $nom, null); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - private function calculer_filtres() { |
|
| 238 | - |
|
| 239 | - // Issu de calculer_select() de public/composer L.519 |
|
| 240 | - // TODO: externaliser... |
|
| 241 | - // |
|
| 242 | - // retirer les criteres vides: |
|
| 243 | - // {X ?} avec X absent de l'URL |
|
| 244 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | - if ($where = &$this->command['where']) { |
|
| 247 | - foreach ($where as $k => $v) { |
|
| 248 | - $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // critere {2,7} |
|
| 253 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | - $limit = explode(',', $this->command['limit']); |
|
| 255 | - $this->offset = $limit[0]; |
|
| 256 | - $this->limit = $limit[1]; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Creer la fonction de filtrage sur $this |
|
| 260 | - if ($this->filtre) { |
|
| 261 | - if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 263 | - $this->func_filtre = fn() => eval($filtres); |
|
| 264 | - } |
|
| 265 | - else { |
|
| 266 | - $this->func_filtre = null; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | - * les filtres vides ou null sont ignores |
|
| 274 | - * @param $filtres |
|
| 275 | - * @param string $operateur |
|
| 276 | - * @return string|null |
|
| 277 | - */ |
|
| 278 | - protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | - |
|
| 280 | - $filtres_string = []; |
|
| 281 | - foreach ($filtres as $k => $v) { |
|
| 282 | - // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | - if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | - $op = array_shift($v); |
|
| 285 | - $v = $this->assembler_filtres($v, $op); |
|
| 286 | - } |
|
| 287 | - if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | - continue; |
|
| 289 | - } |
|
| 290 | - $filtres_string[] = $v; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (!count($filtres_string)) { |
|
| 294 | - return null; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Traduire un element du tableau where SQL en un filtre |
|
| 302 | - * @param $v |
|
| 303 | - * @return string|array|null |
|
| 304 | - */ |
|
| 305 | - protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | - if (is_array($v)) { |
|
| 307 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | - return 'true'; |
|
| 309 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | - return 'true'; |
|
| 311 | - } else { |
|
| 312 | - $op = $v[0] ?: $v; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $op = $v; |
|
| 316 | - } |
|
| 317 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | - return 'true'; |
|
| 319 | - } |
|
| 320 | - if ($op === '0=1') { |
|
| 321 | - return 'false'; |
|
| 322 | - } |
|
| 323 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | - return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // 3 possibilites : count($v) = |
|
| 329 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | - |
|
| 333 | - // 1 : forcement traite par un critere, on passe |
|
| 334 | - if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | - return null; // sera ignore |
|
| 336 | - } |
|
| 337 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | - return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | - } |
|
| 340 | - if (count($v) == 3) { |
|
| 341 | - // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | - if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | - array_shift($v); |
|
| 344 | - foreach (array_keys($v) as $k) { |
|
| 345 | - $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | - if ($v[$k] === null) { |
|
| 347 | - unset($v[$k]); |
|
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 350 | - if ($op === 'OR') { |
|
| 351 | - return 'true'; |
|
| 352 | - } |
|
| 353 | - if ($op === 'AND') { |
|
| 354 | - unset($v[$k]); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 358 | - if ($op === 'OR') { |
|
| 359 | - unset($v[$k]); |
|
| 360 | - } |
|
| 361 | - if ($op === 'AND') { |
|
| 362 | - return 'false'; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - if (!count($v)) { |
|
| 367 | - return null; |
|
| 368 | - } |
|
| 369 | - if (count($v) === 1) { |
|
| 370 | - return reset($v); |
|
| 371 | - } |
|
| 372 | - array_unshift($v, $op); |
|
| 373 | - return $v; |
|
| 374 | - } |
|
| 375 | - return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return null; // sera ignore |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Calculer un filtre sur un champ du tableau |
|
| 383 | - * @param $cle |
|
| 384 | - * @param $op |
|
| 385 | - * @param $valeur |
|
| 386 | - * @param false $not |
|
| 387 | - * @return string|null |
|
| 388 | - */ |
|
| 389 | - protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | - |
|
| 401 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | - # return; |
|
| 403 | - |
|
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | - |
|
| 406 | - $filtre = ''; |
|
| 407 | - |
|
| 408 | - if ($op == 'REGEXP') { |
|
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | - $op = ''; |
|
| 411 | - } else { |
|
| 412 | - if ($op == 'LIKE') { |
|
| 413 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | - $op = ''; |
|
| 416 | - } else { |
|
| 417 | - if ($op == '=') { |
|
| 418 | - $op = '=='; |
|
| 419 | - } else { |
|
| 420 | - if ($op == 'IN') { |
|
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | - $op = ''; |
|
| 423 | - } else { |
|
| 424 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | - $op = ''; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($op) { |
|
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($not) { |
|
| 438 | - $filtre = "!($filtre)"; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - return $filtre; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - public function next() : void { |
|
| 446 | - $this->pos++; |
|
| 447 | - parent::next(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * revient au depart |
|
| 452 | - * |
|
| 453 | - * @return void |
|
| 454 | - */ |
|
| 455 | - public function rewind() : void { |
|
| 456 | - $this->pos = 0; |
|
| 457 | - $this->fetched = 0; |
|
| 458 | - parent::rewind(); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - # Extension SPIP des iterateurs PHP |
|
| 463 | - /** |
|
| 464 | - * type de l'iterateur |
|
| 465 | - * |
|
| 466 | - * @var string |
|
| 467 | - */ |
|
| 468 | - protected $type; |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * parametres de l'iterateur |
|
| 472 | - * |
|
| 473 | - * @var array |
|
| 474 | - */ |
|
| 475 | - protected $command; |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * infos de compilateur |
|
| 479 | - * |
|
| 480 | - * @var array |
|
| 481 | - */ |
|
| 482 | - protected $info; |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * position courante de l'iterateur |
|
| 486 | - * |
|
| 487 | - * @var int |
|
| 488 | - */ |
|
| 489 | - protected $pos = null; |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * nombre total resultats dans l'iterateur |
|
| 493 | - * |
|
| 494 | - * @var int |
|
| 495 | - */ |
|
| 496 | - protected $total = null; |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * nombre maximal de recherche pour $total |
|
| 500 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | - */ |
|
| 502 | - protected $max = 100000; |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Liste des champs a inserer dans les $row |
|
| 507 | - * retournes par ->fetch() |
|
| 508 | - */ |
|
| 509 | - protected $select = []; |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * aller a la position absolue n, |
|
| 514 | - * comptee depuis le debut |
|
| 515 | - * |
|
| 516 | - * @param int $n |
|
| 517 | - * absolute pos |
|
| 518 | - * @param string $continue |
|
| 519 | - * param for sql_ api |
|
| 520 | - * @return bool |
|
| 521 | - * success or fail if not implemented |
|
| 522 | - */ |
|
| 523 | - public function seek($n = 0, $continue = null) { |
|
| 524 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | - $this->seek_loop($n); |
|
| 526 | - } |
|
| 527 | - $this->pos = $n; |
|
| 528 | - $this->fetched = $n; |
|
| 529 | - |
|
| 530 | - return true; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /* |
|
| 223 | + // cle et valeur par defaut |
|
| 224 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | + if ( |
|
| 226 | + in_array($nom, ['cle', 'valeur']) |
|
| 227 | + and method_exists($this, $nom) |
|
| 228 | + ) { |
|
| 229 | + return $this->$nom(); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Par defaut chercher en xpath dans la valeur() |
|
| 233 | + return table_valeur($this->valeur(), $nom, null); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + private function calculer_filtres() { |
|
| 238 | + |
|
| 239 | + // Issu de calculer_select() de public/composer L.519 |
|
| 240 | + // TODO: externaliser... |
|
| 241 | + // |
|
| 242 | + // retirer les criteres vides: |
|
| 243 | + // {X ?} avec X absent de l'URL |
|
| 244 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | + if ($where = &$this->command['where']) { |
|
| 247 | + foreach ($where as $k => $v) { |
|
| 248 | + $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // critere {2,7} |
|
| 253 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | + $limit = explode(',', $this->command['limit']); |
|
| 255 | + $this->offset = $limit[0]; |
|
| 256 | + $this->limit = $limit[1]; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Creer la fonction de filtrage sur $this |
|
| 260 | + if ($this->filtre) { |
|
| 261 | + if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | + $filtres = 'return ' . $filtres . ';'; |
|
| 263 | + $this->func_filtre = fn() => eval($filtres); |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + $this->func_filtre = null; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | + * les filtres vides ou null sont ignores |
|
| 274 | + * @param $filtres |
|
| 275 | + * @param string $operateur |
|
| 276 | + * @return string|null |
|
| 277 | + */ |
|
| 278 | + protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | + |
|
| 280 | + $filtres_string = []; |
|
| 281 | + foreach ($filtres as $k => $v) { |
|
| 282 | + // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | + if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | + $op = array_shift($v); |
|
| 285 | + $v = $this->assembler_filtres($v, $op); |
|
| 286 | + } |
|
| 287 | + if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | + continue; |
|
| 289 | + } |
|
| 290 | + $filtres_string[] = $v; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (!count($filtres_string)) { |
|
| 294 | + return null; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Traduire un element du tableau where SQL en un filtre |
|
| 302 | + * @param $v |
|
| 303 | + * @return string|array|null |
|
| 304 | + */ |
|
| 305 | + protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | + if (is_array($v)) { |
|
| 307 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | + return 'true'; |
|
| 309 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | + return 'true'; |
|
| 311 | + } else { |
|
| 312 | + $op = $v[0] ?: $v; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $op = $v; |
|
| 316 | + } |
|
| 317 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | + return 'true'; |
|
| 319 | + } |
|
| 320 | + if ($op === '0=1') { |
|
| 321 | + return 'false'; |
|
| 322 | + } |
|
| 323 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | + return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // 3 possibilites : count($v) = |
|
| 329 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | + |
|
| 333 | + // 1 : forcement traite par un critere, on passe |
|
| 334 | + if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | + return null; // sera ignore |
|
| 336 | + } |
|
| 337 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | + return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | + } |
|
| 340 | + if (count($v) == 3) { |
|
| 341 | + // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | + if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | + array_shift($v); |
|
| 344 | + foreach (array_keys($v) as $k) { |
|
| 345 | + $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | + if ($v[$k] === null) { |
|
| 347 | + unset($v[$k]); |
|
| 348 | + } |
|
| 349 | + elseif ($v[$k] === 'true') { |
|
| 350 | + if ($op === 'OR') { |
|
| 351 | + return 'true'; |
|
| 352 | + } |
|
| 353 | + if ($op === 'AND') { |
|
| 354 | + unset($v[$k]); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + elseif ($v[$k] === 'false') { |
|
| 358 | + if ($op === 'OR') { |
|
| 359 | + unset($v[$k]); |
|
| 360 | + } |
|
| 361 | + if ($op === 'AND') { |
|
| 362 | + return 'false'; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + if (!count($v)) { |
|
| 367 | + return null; |
|
| 368 | + } |
|
| 369 | + if (count($v) === 1) { |
|
| 370 | + return reset($v); |
|
| 371 | + } |
|
| 372 | + array_unshift($v, $op); |
|
| 373 | + return $v; |
|
| 374 | + } |
|
| 375 | + return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return null; // sera ignore |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Calculer un filtre sur un champ du tableau |
|
| 383 | + * @param $cle |
|
| 384 | + * @param $op |
|
| 385 | + * @param $valeur |
|
| 386 | + * @param false $not |
|
| 387 | + * @return string|null |
|
| 388 | + */ |
|
| 389 | + protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | + |
|
| 401 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | + # return; |
|
| 403 | + |
|
| 404 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | + |
|
| 406 | + $filtre = ''; |
|
| 407 | + |
|
| 408 | + if ($op == 'REGEXP') { |
|
| 409 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | + $op = ''; |
|
| 411 | + } else { |
|
| 412 | + if ($op == 'LIKE') { |
|
| 413 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | + $op = ''; |
|
| 416 | + } else { |
|
| 417 | + if ($op == '=') { |
|
| 418 | + $op = '=='; |
|
| 419 | + } else { |
|
| 420 | + if ($op == 'IN') { |
|
| 421 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | + $op = ''; |
|
| 423 | + } else { |
|
| 424 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | + $op = ''; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($op) { |
|
| 434 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($not) { |
|
| 438 | + $filtre = "!($filtre)"; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + return $filtre; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + public function next() : void { |
|
| 446 | + $this->pos++; |
|
| 447 | + parent::next(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * revient au depart |
|
| 452 | + * |
|
| 453 | + * @return void |
|
| 454 | + */ |
|
| 455 | + public function rewind() : void { |
|
| 456 | + $this->pos = 0; |
|
| 457 | + $this->fetched = 0; |
|
| 458 | + parent::rewind(); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + # Extension SPIP des iterateurs PHP |
|
| 463 | + /** |
|
| 464 | + * type de l'iterateur |
|
| 465 | + * |
|
| 466 | + * @var string |
|
| 467 | + */ |
|
| 468 | + protected $type; |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * parametres de l'iterateur |
|
| 472 | + * |
|
| 473 | + * @var array |
|
| 474 | + */ |
|
| 475 | + protected $command; |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * infos de compilateur |
|
| 479 | + * |
|
| 480 | + * @var array |
|
| 481 | + */ |
|
| 482 | + protected $info; |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * position courante de l'iterateur |
|
| 486 | + * |
|
| 487 | + * @var int |
|
| 488 | + */ |
|
| 489 | + protected $pos = null; |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * nombre total resultats dans l'iterateur |
|
| 493 | + * |
|
| 494 | + * @var int |
|
| 495 | + */ |
|
| 496 | + protected $total = null; |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * nombre maximal de recherche pour $total |
|
| 500 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | + */ |
|
| 502 | + protected $max = 100000; |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Liste des champs a inserer dans les $row |
|
| 507 | + * retournes par ->fetch() |
|
| 508 | + */ |
|
| 509 | + protected $select = []; |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * aller a la position absolue n, |
|
| 514 | + * comptee depuis le debut |
|
| 515 | + * |
|
| 516 | + * @param int $n |
|
| 517 | + * absolute pos |
|
| 518 | + * @param string $continue |
|
| 519 | + * param for sql_ api |
|
| 520 | + * @return bool |
|
| 521 | + * success or fail if not implemented |
|
| 522 | + */ |
|
| 523 | + public function seek($n = 0, $continue = null) { |
|
| 524 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | + $this->seek_loop($n); |
|
| 526 | + } |
|
| 527 | + $this->pos = $n; |
|
| 528 | + $this->fetched = $n; |
|
| 529 | + |
|
| 530 | + return true; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /* |
|
| 534 | 534 | * aller a la position $n en parcourant |
| 535 | 535 | * un par un tous les elements |
| 536 | 536 | */ |
| 537 | - private function seek_loop($n) { |
|
| 538 | - if ($this->pos > $n) { |
|
| 539 | - $this->rewind(); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - while ($this->pos < $n and $this->valid()) { |
|
| 543 | - $this->next(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return true; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Avancer de $saut pas |
|
| 551 | - * |
|
| 552 | - * @param $saut |
|
| 553 | - * @param $max |
|
| 554 | - * @return int |
|
| 555 | - */ |
|
| 556 | - public function skip($saut, $max = null) { |
|
| 557 | - // pas de saut en arriere autorise pour cette fonction |
|
| 558 | - if (($saut = intval($saut)) <= 0) { |
|
| 559 | - return $this->pos; |
|
| 560 | - } |
|
| 561 | - $seek = $this->pos + $saut; |
|
| 562 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | - // et on sort |
|
| 564 | - if (is_null($max)) { |
|
| 565 | - $max = $this->count(); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | - $this->free(); |
|
| 571 | - |
|
| 572 | - return $max; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - $this->seek($seek); |
|
| 576 | - |
|
| 577 | - return $this->pos; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Renvoyer un tableau des donnees correspondantes |
|
| 582 | - * a la position courante de l'iterateur |
|
| 583 | - * en controlant si on respecte le filtre |
|
| 584 | - * Appliquer aussi le critere {offset,limit} |
|
| 585 | - * |
|
| 586 | - * @return array|bool |
|
| 587 | - */ |
|
| 588 | - public function fetch() { |
|
| 589 | - if (method_exists($this->iter, 'fetch')) { |
|
| 590 | - return $this->iter->fetch(); |
|
| 591 | - } else { |
|
| 592 | - while ( |
|
| 593 | - $this->valid() |
|
| 594 | - and ( |
|
| 595 | - !$this->accept() |
|
| 596 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - $this->next(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - if (!$this->valid()) { |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - if ( |
|
| 607 | - isset($this->limit) |
|
| 608 | - and $this->fetched > $this->offset + $this->limit |
|
| 609 | - ) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $r = []; |
|
| 614 | - foreach ($this->select as $nom) { |
|
| 615 | - $r[$nom] = $this->get_select($nom); |
|
| 616 | - } |
|
| 617 | - $this->next(); |
|
| 618 | - |
|
| 619 | - return $r; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // retourner la cle pour #CLE |
|
| 624 | - public function cle() { |
|
| 625 | - return $this->key(); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // retourner la valeur pour #VALEUR |
|
| 629 | - public function valeur() { |
|
| 630 | - return $this->current(); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Accepte-t-on l'entree courante lue ? |
|
| 635 | - * On execute les filtres pour le savoir. |
|
| 636 | - **/ |
|
| 637 | - public function accept(): bool { |
|
| 638 | - if ($f = $this->func_filtre) { |
|
| 639 | - return $f(); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - return true; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * liberer la ressource |
|
| 647 | - * |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - public function free() { |
|
| 651 | - if (method_exists($this->iter, 'free')) { |
|
| 652 | - $this->iter->free(); |
|
| 653 | - } |
|
| 654 | - $this->pos = $this->total = 0; |
|
| 655 | - |
|
| 656 | - return true; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Compter le nombre total de resultats |
|
| 661 | - * pour #TOTAL_BOUCLE |
|
| 662 | - * |
|
| 663 | - * @return int |
|
| 664 | - */ |
|
| 665 | - public function count() { |
|
| 666 | - if (is_null($this->total)) { |
|
| 667 | - if ( |
|
| 668 | - method_exists($this->iter, 'count') |
|
| 669 | - and !$this->func_filtre |
|
| 670 | - ) { |
|
| 671 | - return $this->total = $this->iter->count(); |
|
| 672 | - } else { |
|
| 673 | - // compter les lignes et rembobiner |
|
| 674 | - $total = 0; |
|
| 675 | - $pos = $this->pos; // sauver la position |
|
| 676 | - $this->rewind(); |
|
| 677 | - while ($this->fetch() and $total < $this->max) { |
|
| 678 | - $total++; |
|
| 679 | - } |
|
| 680 | - $this->seek($pos); |
|
| 681 | - $this->total = $total; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $this->total; |
|
| 686 | - } |
|
| 537 | + private function seek_loop($n) { |
|
| 538 | + if ($this->pos > $n) { |
|
| 539 | + $this->rewind(); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + while ($this->pos < $n and $this->valid()) { |
|
| 543 | + $this->next(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return true; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Avancer de $saut pas |
|
| 551 | + * |
|
| 552 | + * @param $saut |
|
| 553 | + * @param $max |
|
| 554 | + * @return int |
|
| 555 | + */ |
|
| 556 | + public function skip($saut, $max = null) { |
|
| 557 | + // pas de saut en arriere autorise pour cette fonction |
|
| 558 | + if (($saut = intval($saut)) <= 0) { |
|
| 559 | + return $this->pos; |
|
| 560 | + } |
|
| 561 | + $seek = $this->pos + $saut; |
|
| 562 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | + // et on sort |
|
| 564 | + if (is_null($max)) { |
|
| 565 | + $max = $this->count(); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | + $this->free(); |
|
| 571 | + |
|
| 572 | + return $max; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $this->seek($seek); |
|
| 576 | + |
|
| 577 | + return $this->pos; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Renvoyer un tableau des donnees correspondantes |
|
| 582 | + * a la position courante de l'iterateur |
|
| 583 | + * en controlant si on respecte le filtre |
|
| 584 | + * Appliquer aussi le critere {offset,limit} |
|
| 585 | + * |
|
| 586 | + * @return array|bool |
|
| 587 | + */ |
|
| 588 | + public function fetch() { |
|
| 589 | + if (method_exists($this->iter, 'fetch')) { |
|
| 590 | + return $this->iter->fetch(); |
|
| 591 | + } else { |
|
| 592 | + while ( |
|
| 593 | + $this->valid() |
|
| 594 | + and ( |
|
| 595 | + !$this->accept() |
|
| 596 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + $this->next(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + if (!$this->valid()) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + if ( |
|
| 607 | + isset($this->limit) |
|
| 608 | + and $this->fetched > $this->offset + $this->limit |
|
| 609 | + ) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $r = []; |
|
| 614 | + foreach ($this->select as $nom) { |
|
| 615 | + $r[$nom] = $this->get_select($nom); |
|
| 616 | + } |
|
| 617 | + $this->next(); |
|
| 618 | + |
|
| 619 | + return $r; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // retourner la cle pour #CLE |
|
| 624 | + public function cle() { |
|
| 625 | + return $this->key(); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // retourner la valeur pour #VALEUR |
|
| 629 | + public function valeur() { |
|
| 630 | + return $this->current(); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Accepte-t-on l'entree courante lue ? |
|
| 635 | + * On execute les filtres pour le savoir. |
|
| 636 | + **/ |
|
| 637 | + public function accept(): bool { |
|
| 638 | + if ($f = $this->func_filtre) { |
|
| 639 | + return $f(); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + return true; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * liberer la ressource |
|
| 647 | + * |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + public function free() { |
|
| 651 | + if (method_exists($this->iter, 'free')) { |
|
| 652 | + $this->iter->free(); |
|
| 653 | + } |
|
| 654 | + $this->pos = $this->total = 0; |
|
| 655 | + |
|
| 656 | + return true; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Compter le nombre total de resultats |
|
| 661 | + * pour #TOTAL_BOUCLE |
|
| 662 | + * |
|
| 663 | + * @return int |
|
| 664 | + */ |
|
| 665 | + public function count() { |
|
| 666 | + if (is_null($this->total)) { |
|
| 667 | + if ( |
|
| 668 | + method_exists($this->iter, 'count') |
|
| 669 | + and !$this->func_filtre |
|
| 670 | + ) { |
|
| 671 | + return $this->total = $this->iter->count(); |
|
| 672 | + } else { |
|
| 673 | + // compter les lignes et rembobiner |
|
| 674 | + $total = 0; |
|
| 675 | + $pos = $this->pos; // sauver la position |
|
| 676 | + $this->rewind(); |
|
| 677 | + while ($this->fetch() and $total < $this->max) { |
|
| 678 | + $total++; |
|
| 679 | + } |
|
| 680 | + $this->seek($pos); |
|
| 681 | + $this->total = $total; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $this->total; |
|
| 686 | + } |
|
| 687 | 687 | } |
@@ -11,127 +11,127 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = ' />'; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = ' />'; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | - } else { |
|
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | - |
|
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | + } else { |
|
| 36 | + $t = '{fond=' . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | + |
|
| 40 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = []; |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = []; |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = '#' |
|
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = '#' |
|
| 63 | + . ($boucle ? ($boucle . ':') : '') |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - [$type, $valeur] = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + [$type, $valeur] = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | - [$texte, $type] = $args[$i]; |
|
| 105 | - [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if ( |
|
| 124 | - ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | - ) { |
|
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 103 | + for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | + [$texte, $type] = $args[$i]; |
|
| 105 | + [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if ( |
|
| 124 | + ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | + ) { |
|
| 127 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function format_texte_html($texte) { |
| 136 | - return $texte; |
|
| 136 | + return $texte; |
|
| 137 | 137 | } |
@@ -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 | |
@@ -52,75 +52,75 @@ discard block |
||
| 52 | 52 | * Introduction calculée |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 55 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | - if (strlen($descriptif)) { |
|
| 57 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // De preference ce qui est marque <intro>...</intro> |
|
| 61 | - $intro = ''; |
|
| 62 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | - $zone = substr($texte, 0, $fin); |
|
| 65 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | - $zone = substr($zone, $deb + 7); |
|
| 68 | - } |
|
| 69 | - $intro .= $zone; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | - // qui inclus raccourcis et modeles |
|
| 74 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | - // des surcharges et enrichissement de propre |
|
| 77 | - // couper doit se faire apres propre |
|
| 78 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | - |
|
| 80 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | - // large et en se mefiant des tableaux #1323 |
|
| 82 | - |
|
| 83 | - if (strlen($intro)) { |
|
| 84 | - $texte = $intro; |
|
| 85 | - } else { |
|
| 86 | - if ( |
|
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 88 | - and strlen($texte) > 2.5 * $longueur |
|
| 89 | - ) { |
|
| 90 | - if (strpos($texte, '<multi') !== false) { |
|
| 91 | - $texte = extraire_multi($texte); |
|
| 92 | - } |
|
| 93 | - $texte = couper($texte, 2 * $longueur); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // ne pas tenir compte des notes |
|
| 98 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | - $notes('', 'empiler'); |
|
| 100 | - } |
|
| 101 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | - // dans l'introduction. |
|
| 103 | - $texte = supprime_img($texte, ''); |
|
| 104 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | - |
|
| 106 | - if ($notes) { |
|
| 107 | - $notes('', 'depiler'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | - $suite = _INTRODUCTION_SUITE; |
|
| 112 | - } |
|
| 113 | - $texte = couper($texte, $longueur, $suite); |
|
| 114 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | - $texte = typo($texte, true, $connect, []); |
|
| 116 | - |
|
| 117 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | - // une introduction a tojours un <p> |
|
| 119 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $texte; |
|
| 55 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | + if (strlen($descriptif)) { |
|
| 57 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // De preference ce qui est marque <intro>...</intro> |
|
| 61 | + $intro = ''; |
|
| 62 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | + $zone = substr($texte, 0, $fin); |
|
| 65 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | + $zone = substr($zone, $deb + 7); |
|
| 68 | + } |
|
| 69 | + $intro .= $zone; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | + // qui inclus raccourcis et modeles |
|
| 74 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | + // des surcharges et enrichissement de propre |
|
| 77 | + // couper doit se faire apres propre |
|
| 78 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | + |
|
| 80 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | + // large et en se mefiant des tableaux #1323 |
|
| 82 | + |
|
| 83 | + if (strlen($intro)) { |
|
| 84 | + $texte = $intro; |
|
| 85 | + } else { |
|
| 86 | + if ( |
|
| 87 | + strpos("\n" . $texte, "\n|") === false |
|
| 88 | + and strlen($texte) > 2.5 * $longueur |
|
| 89 | + ) { |
|
| 90 | + if (strpos($texte, '<multi') !== false) { |
|
| 91 | + $texte = extraire_multi($texte); |
|
| 92 | + } |
|
| 93 | + $texte = couper($texte, 2 * $longueur); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // ne pas tenir compte des notes |
|
| 98 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | + $notes('', 'empiler'); |
|
| 100 | + } |
|
| 101 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | + // dans l'introduction. |
|
| 103 | + $texte = supprime_img($texte, ''); |
|
| 104 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | + |
|
| 106 | + if ($notes) { |
|
| 107 | + $notes('', 'depiler'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | + $suite = _INTRODUCTION_SUITE; |
|
| 112 | + } |
|
| 113 | + $texte = couper($texte, $longueur, $suite); |
|
| 114 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | + $texte = typo($texte, true, $connect, []); |
|
| 116 | + |
|
| 117 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | + // une introduction a tojours un <p> |
|
| 119 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $texte; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
@@ -155,73 +155,73 @@ discard block |
||
| 155 | 155 | * Code HTML de la pagination |
| 156 | 156 | **/ |
| 157 | 157 | function filtre_pagination_dist( |
| 158 | - $total, |
|
| 159 | - $nom, |
|
| 160 | - $position, |
|
| 161 | - $pas, |
|
| 162 | - $liste = true, |
|
| 163 | - $modele = '', |
|
| 164 | - string $connect = '', |
|
| 165 | - $env = [] |
|
| 158 | + $total, |
|
| 159 | + $nom, |
|
| 160 | + $position, |
|
| 161 | + $pas, |
|
| 162 | + $liste = true, |
|
| 163 | + $modele = '', |
|
| 164 | + string $connect = '', |
|
| 165 | + $env = [] |
|
| 166 | 166 | ) { |
| 167 | - static $ancres = []; |
|
| 168 | - if ($pas < 1) { |
|
| 169 | - return ''; |
|
| 170 | - } |
|
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | - |
|
| 174 | - // n'afficher l'ancre qu'une fois |
|
| 175 | - if (!isset($ancres[$ancre])) { |
|
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | - } else { |
|
| 178 | - $bloc_ancre = ''; |
|
| 179 | - } |
|
| 180 | - // liste = false : on ne veut que l'ancre |
|
| 181 | - if (!$liste) { |
|
| 182 | - return $ancres[$ancre]; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | - $pagination = [ |
|
| 187 | - 'debut' => $debut, |
|
| 188 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | - 'total' => $total, |
|
| 190 | - 'position' => intval($position), |
|
| 191 | - 'pas' => $pas, |
|
| 192 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | - 'ancre' => $ancre, |
|
| 195 | - 'bloc_ancre' => $bloc_ancre |
|
| 196 | - ]; |
|
| 197 | - if (is_array($env)) { |
|
| 198 | - $pagination = array_merge($env, $pagination); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Pas de pagination |
|
| 202 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($modele) { |
|
| 207 | - $pagination['type_pagination'] = $modele; |
|
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - $modele = ''; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | - } |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 167 | + static $ancres = []; |
|
| 168 | + if ($pas < 1) { |
|
| 169 | + return ''; |
|
| 170 | + } |
|
| 171 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | + |
|
| 174 | + // n'afficher l'ancre qu'une fois |
|
| 175 | + if (!isset($ancres[$ancre])) { |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | + } else { |
|
| 178 | + $bloc_ancre = ''; |
|
| 179 | + } |
|
| 180 | + // liste = false : on ne veut que l'ancre |
|
| 181 | + if (!$liste) { |
|
| 182 | + return $ancres[$ancre]; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | + $pagination = [ |
|
| 187 | + 'debut' => $debut, |
|
| 188 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | + 'total' => $total, |
|
| 190 | + 'position' => intval($position), |
|
| 191 | + 'pas' => $pas, |
|
| 192 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | + 'ancre' => $ancre, |
|
| 195 | + 'bloc_ancre' => $bloc_ancre |
|
| 196 | + ]; |
|
| 197 | + if (is_array($env)) { |
|
| 198 | + $pagination = array_merge($env, $pagination); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Pas de pagination |
|
| 202 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($modele) { |
|
| 207 | + $pagination['type_pagination'] = $modele; |
|
| 208 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | + $modele = '_' . $modele; |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + $modele = ''; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | + } |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -240,44 +240,44 @@ discard block |
||
| 240 | 240 | * Liste (première page, dernière page). |
| 241 | 241 | **/ |
| 242 | 242 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 243 | - if ($max <= 0 or $max >= $nombre) { |
|
| 244 | - return [1, $nombre]; |
|
| 245 | - } |
|
| 246 | - if ($max <= 1) { |
|
| 247 | - return [$courante, $courante]; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | - |
|
| 254 | - return [$premiere, $derniere]; |
|
| 243 | + if ($max <= 0 or $max >= $nombre) { |
|
| 244 | + return [1, $nombre]; |
|
| 245 | + } |
|
| 246 | + if ($max <= 1) { |
|
| 247 | + return [$courante, $courante]; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | + |
|
| 254 | + return [$premiere, $derniere]; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 258 | - if ($numero_page === 'tous') { |
|
| 259 | - return '∞'; |
|
| 260 | - } |
|
| 261 | - if ($numero_page === 'prev') { |
|
| 262 | - return '<'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'next') { |
|
| 265 | - return '>'; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - switch ($type_pagination) { |
|
| 269 | - case 'resultats': |
|
| 270 | - return $rang_item + 1; // 1 11 21 31... |
|
| 271 | - case 'naturel': |
|
| 272 | - return $rang_item ?: 1; // 1 10 20 30... |
|
| 273 | - case 'rang': |
|
| 274 | - return $rang_item; // 0 10 20 30... |
|
| 275 | - |
|
| 276 | - case 'page': |
|
| 277 | - case 'prive': |
|
| 278 | - default: |
|
| 279 | - return $numero_page; // 1 2 3 4 5... |
|
| 280 | - } |
|
| 258 | + if ($numero_page === 'tous') { |
|
| 259 | + return '∞'; |
|
| 260 | + } |
|
| 261 | + if ($numero_page === 'prev') { |
|
| 262 | + return '<'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'next') { |
|
| 265 | + return '>'; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + switch ($type_pagination) { |
|
| 269 | + case 'resultats': |
|
| 270 | + return $rang_item + 1; // 1 11 21 31... |
|
| 271 | + case 'naturel': |
|
| 272 | + return $rang_item ?: 1; // 1 10 20 30... |
|
| 273 | + case 'rang': |
|
| 274 | + return $rang_item; // 0 10 20 30... |
|
| 275 | + |
|
| 276 | + case 'page': |
|
| 277 | + case 'prive': |
|
| 278 | + default: |
|
| 279 | + return $numero_page; // 1 2 3 4 5... |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -290,15 +290,15 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | - $objet = objet_type($type); |
|
| 294 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | - if ($ids) { |
|
| 296 | - $ids = array_column($ids, 'id_objet'); |
|
| 297 | - return implode(',', $ids); |
|
| 298 | - } |
|
| 299 | - else { |
|
| 300 | - return '0'; |
|
| 301 | - } |
|
| 293 | + $objet = objet_type($type); |
|
| 294 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | + if ($ids) { |
|
| 296 | + $ids = array_column($ids, 'id_objet'); |
|
| 297 | + return implode(',', $ids); |
|
| 298 | + } |
|
| 299 | + else { |
|
| 300 | + return '0'; |
|
| 301 | + } |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | * Code HTML des notes |
| 315 | 315 | **/ |
| 316 | 316 | function calculer_notes() { |
| 317 | - $r = ''; |
|
| 318 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | - $r = $notes([]); |
|
| 320 | - $notes('', 'depiler'); |
|
| 321 | - $notes('', 'empiler'); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $r; |
|
| 317 | + $r = ''; |
|
| 318 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | + $r = $notes([]); |
|
| 320 | + $notes('', 'depiler'); |
|
| 321 | + $notes('', 'empiler'); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $r; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -338,10 +338,10 @@ discard block |
||
| 338 | 338 | * @return string |
| 339 | 339 | */ |
| 340 | 340 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 341 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 341 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 343 | 343 | |
| 344 | - return ($res[$ids] ?? ''); |
|
| 344 | + return ($res[$ids] ?? ''); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -358,19 +358,19 @@ discard block |
||
| 358 | 358 | * @private |
| 359 | 359 | */ |
| 360 | 360 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 361 | - static $liens = []; |
|
| 362 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | - include_spip('action/editer_liens'); |
|
| 364 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | - } else { |
|
| 368 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | - } |
|
| 373 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 361 | + static $liens = []; |
|
| 362 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | + include_spip('action/editer_liens'); |
|
| 364 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | + } else { |
|
| 368 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | + } |
|
| 373 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -384,24 +384,24 @@ discard block |
||
| 384 | 384 | * @return int|string |
| 385 | 385 | */ |
| 386 | 386 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 387 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | - if ( |
|
| 390 | - isset($env['form']) and $env['form'] |
|
| 391 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | - and $r = objet_associable($env['_objet_lien']) |
|
| 394 | - and [$p, $table_lien] = $r |
|
| 395 | - and lien_triables($table_lien) |
|
| 396 | - and isset($env['objet']) and $env['objet'] |
|
| 397 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | - and $objet_source |
|
| 399 | - and $id = intval($id) |
|
| 400 | - ) { |
|
| 401 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | - return ($rang ?: ''); |
|
| 403 | - } |
|
| 404 | - return recuperer_numero($titre); |
|
| 387 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | + if ( |
|
| 390 | + isset($env['form']) and $env['form'] |
|
| 391 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | + and $r = objet_associable($env['_objet_lien']) |
|
| 394 | + and [$p, $table_lien] = $r |
|
| 395 | + and lien_triables($table_lien) |
|
| 396 | + and isset($env['objet']) and $env['objet'] |
|
| 397 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | + and $objet_source |
|
| 399 | + and $id = intval($id) |
|
| 400 | + ) { |
|
| 401 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | + return ($rang ?: ''); |
|
| 403 | + } |
|
| 404 | + return recuperer_numero($titre); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function tri_protege_champ($t) { |
| 420 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 420 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -430,43 +430,43 @@ discard block |
||
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | 432 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 433 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | - return 'multi'; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $champ = $t; |
|
| 438 | - |
|
| 439 | - $prefixe = ''; |
|
| 440 | - foreach (['num ', 'sinum '] as $p) { |
|
| 441 | - if (strpos($t, $p) === 0) { |
|
| 442 | - $champ = substr($t, strlen($p)); |
|
| 443 | - $prefixe = $p; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | - |
|
| 450 | - if (is_array($from)) { |
|
| 451 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | - foreach ($from as $idt => $table_sql) { |
|
| 453 | - if ( |
|
| 454 | - $desc = $trouver_table($table_sql) |
|
| 455 | - and isset($desc['field'][$champ]) |
|
| 456 | - ) { |
|
| 457 | - $champ = "$idt.$champ"; |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - switch ($prefixe) { |
|
| 463 | - case 'num ': |
|
| 464 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | - case 'sinum ': |
|
| 466 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | - default: |
|
| 468 | - return $champ . $senstri; |
|
| 469 | - } |
|
| 433 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | + return 'multi'; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $champ = $t; |
|
| 438 | + |
|
| 439 | + $prefixe = ''; |
|
| 440 | + foreach (['num ', 'sinum '] as $p) { |
|
| 441 | + if (strpos($t, $p) === 0) { |
|
| 442 | + $champ = substr($t, strlen($p)); |
|
| 443 | + $prefixe = $p; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | + |
|
| 450 | + if (is_array($from)) { |
|
| 451 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | + foreach ($from as $idt => $table_sql) { |
|
| 453 | + if ( |
|
| 454 | + $desc = $trouver_table($table_sql) |
|
| 455 | + and isset($desc['field'][$champ]) |
|
| 456 | + ) { |
|
| 457 | + $champ = "$idt.$champ"; |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + switch ($prefixe) { |
|
| 463 | + case 'num ': |
|
| 464 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | + case 'sinum ': |
|
| 466 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | + default: |
|
| 468 | + return $champ . $senstri; |
|
| 469 | + } |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,18 +480,18 @@ discard block |
||
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | 482 | function tri_champ_select($t) { |
| 483 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | - $t = substr($t, 6); |
|
| 485 | - $t = preg_replace(',\s,', '', $t); |
|
| 486 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | - |
|
| 488 | - return $t; |
|
| 489 | - } |
|
| 490 | - if (trim($t) == 'hasard') { |
|
| 491 | - return 'rand() AS hasard'; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return "''"; |
|
| 483 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | + $t = substr($t, 6); |
|
| 485 | + $t = preg_replace(',\s,', '', $t); |
|
| 486 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | + |
|
| 488 | + return $t; |
|
| 489 | + } |
|
| 490 | + if (trim($t) == 'hasard') { |
|
| 491 | + return 'rand() AS hasard'; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return "''"; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -503,16 +503,16 @@ discard block |
||
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | 505 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 506 | - if (!is_array($valeurs)) { |
|
| 507 | - return ''; |
|
| 508 | - } |
|
| 509 | - $f = sql_serveur('quote', $serveur, true); |
|
| 510 | - if (!is_string($f) or !$f) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | - |
|
| 515 | - return $valeurs; |
|
| 506 | + if (!is_array($valeurs)) { |
|
| 507 | + return ''; |
|
| 508 | + } |
|
| 509 | + $f = sql_serveur('quote', $serveur, true); |
|
| 510 | + if (!is_string($f) or !$f) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | + |
|
| 515 | + return $valeurs; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -535,21 +535,21 @@ discard block |
||
| 535 | 535 | * Valeur $defaut sinon. |
| 536 | 536 | **/ |
| 537 | 537 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 538 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | - $args[1] = $args[0]; |
|
| 543 | - $args[0] = $filtre; |
|
| 544 | - return image_graver(image_filtrer($args)); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - $f = chercher_filtre($filtre); |
|
| 548 | - if (!$f) { |
|
| 549 | - return $defaut; |
|
| 550 | - } |
|
| 551 | - array_shift($args); // enlever $arg |
|
| 552 | - array_shift($args); // enlever $filtre |
|
| 553 | - array_unshift($args, $arg); // remettre $arg |
|
| 554 | - return call_user_func_array($f, $args); |
|
| 538 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | + $args[1] = $args[0]; |
|
| 543 | + $args[0] = $filtre; |
|
| 544 | + return image_graver(image_filtrer($args)); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + $f = chercher_filtre($filtre); |
|
| 548 | + if (!$f) { |
|
| 549 | + return $defaut; |
|
| 550 | + } |
|
| 551 | + array_shift($args); // enlever $arg |
|
| 552 | + array_shift($args); // enlever $filtre |
|
| 553 | + array_unshift($args, $arg); // remettre $arg |
|
| 554 | + return call_user_func_array($f, $args); |
|
| 555 | 555 | } |
@@ -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,193 +29,193 @@ 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 = []; |
|
| 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( |
|
| 57 | - _DIR_PLUGIN_DIST, |
|
| 58 | - '/' |
|
| 59 | - ) : '')); |
|
| 60 | - } |
|
| 61 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | - } |
|
| 63 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | - |
|
| 65 | - $fond = $flux['args']['fond']; |
|
| 66 | - |
|
| 67 | - if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | - $fond = substr($fond, $prefix_length); |
|
| 69 | - $squelette = $flux['data']; |
|
| 70 | - $ext = $flux['args']['ext']; |
|
| 71 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | - if ( |
|
| 73 | - defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | - and $dir = explode('/', $fond) |
|
| 75 | - and count($dir) == 2 // pas un sous repertoire |
|
| 76 | - and $dir = reset($dir) |
|
| 77 | - and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | - and defined($apl_constant) |
|
| 79 | - and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | - ) { |
|
| 82 | - $flux['data'] = $pipe; |
|
| 83 | - |
|
| 84 | - return $flux; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | - if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | - $squelette = ''; |
|
| 90 | - $echafauder = ''; |
|
| 91 | - } |
|
| 92 | - if ($prepend) { |
|
| 93 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | - if ($squelette) { |
|
| 95 | - $flux['data'] = $squelette; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // gerer les squelettes non trouves |
|
| 100 | - // -> router vers les /dist.html |
|
| 101 | - // ou scaffolding ou page automatique les contenus |
|
| 102 | - if (!$squelette) { |
|
| 103 | - // si on est sur un ?page=XX non trouve |
|
| 104 | - if ( |
|
| 105 | - (isset($flux['args']['contexte'][$page]) |
|
| 106 | - and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | - or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | - and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | - or ($fond == 'sommaire' |
|
| 110 | - and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | - ) { |
|
| 112 | - // si on est sur un ?page=XX non trouve |
|
| 113 | - // se brancher sur contenu/xx si il existe |
|
| 114 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | - if (!isset($disponible[$fond])) { |
|
| 116 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($disponible[$fond]) { |
|
| 120 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // echafaudage : |
|
| 125 | - // si c'est un fond de contenu d'un objet en base |
|
| 126 | - // generer un fond automatique a la volee pour les webmestres |
|
| 127 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | - $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | - $type = $flux['args']['contexte'][$page]; |
|
| 131 | - } |
|
| 132 | - if (!isset($disponible[$type])) { |
|
| 133 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | - } |
|
| 135 | - if (is_string($disponible[$type])) { |
|
| 136 | - $flux['data'] = $disponible[$type]; |
|
| 137 | - } elseif ( |
|
| 138 | - $echafauder |
|
| 139 | - and include_spip('inc/autoriser') |
|
| 140 | - and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | - and autoriser('echafauder', $type) |
|
| 142 | - and $is = $disponible[$type] |
|
| 143 | - and is_array($is) |
|
| 144 | - ) { |
|
| 145 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | - } else { |
|
| 147 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | - $prefix_path . $prepend, |
|
| 149 | - $z_contenu, |
|
| 150 | - '404', |
|
| 151 | - $ext, |
|
| 152 | - $echafauder |
|
| 153 | - )); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | - else { |
|
| 161 | - if ( |
|
| 162 | - $dir = explode('/', $fond) |
|
| 163 | - and $dir = reset($dir) |
|
| 164 | - and $dir !== $z_contenu |
|
| 165 | - and in_array($dir, $z_blocs) |
|
| 166 | - ) { |
|
| 167 | - $type = substr($fond, strlen("$dir/")); |
|
| 168 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | - $type = $flux['args']['contexte'][$page]; |
|
| 170 | - } |
|
| 171 | - if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | - } |
|
| 174 | - if ($type == 'page' or $disponible[$type]) { |
|
| 175 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $squelette = $flux['data']; |
|
| 180 | - } |
|
| 181 | - // layout specifiques par type et compositions : |
|
| 182 | - // body-article.html |
|
| 183 | - // body-sommaire.html |
|
| 184 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | - // meme dossier que body.html |
|
| 186 | - if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | - if ( |
|
| 188 | - isset($flux['args']['contexte']['type-page']) |
|
| 189 | - and ( |
|
| 190 | - (isset($flux['args']['contexte']['composition']) |
|
| 191 | - and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | - or |
|
| 193 | - file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | - ) |
|
| 195 | - ) { |
|
| 196 | - $flux['data'] = $f; |
|
| 197 | - } |
|
| 198 | - } elseif ( |
|
| 199 | - $fond == 'structure' |
|
| 200 | - and z_sanitize_var_zajax() |
|
| 201 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | - ) { |
|
| 203 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | - } // chercher le fond correspondant a la composition |
|
| 205 | - elseif ( |
|
| 206 | - isset($flux['args']['contexte']['composition']) |
|
| 207 | - and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | - and $dir = substr($fond, $prefix_length) |
|
| 209 | - and $dir = explode('/', $dir) |
|
| 210 | - and $dir = reset($dir) |
|
| 211 | - and in_array($dir, $z_blocs) |
|
| 212 | - and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | - ) { |
|
| 214 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - 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 = []; |
|
| 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( |
|
| 57 | + _DIR_PLUGIN_DIST, |
|
| 58 | + '/' |
|
| 59 | + ) : '')); |
|
| 60 | + } |
|
| 61 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | + } |
|
| 63 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | + |
|
| 65 | + $fond = $flux['args']['fond']; |
|
| 66 | + |
|
| 67 | + if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | + $fond = substr($fond, $prefix_length); |
|
| 69 | + $squelette = $flux['data']; |
|
| 70 | + $ext = $flux['args']['ext']; |
|
| 71 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | + if ( |
|
| 73 | + defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | + and $dir = explode('/', $fond) |
|
| 75 | + and count($dir) == 2 // pas un sous repertoire |
|
| 76 | + and $dir = reset($dir) |
|
| 77 | + and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | + and defined($apl_constant) |
|
| 79 | + and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | + and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | + ) { |
|
| 82 | + $flux['data'] = $pipe; |
|
| 83 | + |
|
| 84 | + return $flux; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | + if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | + $squelette = ''; |
|
| 90 | + $echafauder = ''; |
|
| 91 | + } |
|
| 92 | + if ($prepend) { |
|
| 93 | + $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | + if ($squelette) { |
|
| 95 | + $flux['data'] = $squelette; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // gerer les squelettes non trouves |
|
| 100 | + // -> router vers les /dist.html |
|
| 101 | + // ou scaffolding ou page automatique les contenus |
|
| 102 | + if (!$squelette) { |
|
| 103 | + // si on est sur un ?page=XX non trouve |
|
| 104 | + if ( |
|
| 105 | + (isset($flux['args']['contexte'][$page]) |
|
| 106 | + and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | + or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | + and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | + or ($fond == 'sommaire' |
|
| 110 | + and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | + ) { |
|
| 112 | + // si on est sur un ?page=XX non trouve |
|
| 113 | + // se brancher sur contenu/xx si il existe |
|
| 114 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | + if (!isset($disponible[$fond])) { |
|
| 116 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($disponible[$fond]) { |
|
| 120 | + $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // echafaudage : |
|
| 125 | + // si c'est un fond de contenu d'un objet en base |
|
| 126 | + // generer un fond automatique a la volee pour les webmestres |
|
| 127 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | + $type = $flux['args']['contexte'][$page]; |
|
| 131 | + } |
|
| 132 | + if (!isset($disponible[$type])) { |
|
| 133 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | + } |
|
| 135 | + if (is_string($disponible[$type])) { |
|
| 136 | + $flux['data'] = $disponible[$type]; |
|
| 137 | + } elseif ( |
|
| 138 | + $echafauder |
|
| 139 | + and include_spip('inc/autoriser') |
|
| 140 | + and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | + and autoriser('echafauder', $type) |
|
| 142 | + and $is = $disponible[$type] |
|
| 143 | + and is_array($is) |
|
| 144 | + ) { |
|
| 145 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | + } else { |
|
| 147 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | + $prefix_path . $prepend, |
|
| 149 | + $z_contenu, |
|
| 150 | + '404', |
|
| 151 | + $ext, |
|
| 152 | + $echafauder |
|
| 153 | + )); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | + else { |
|
| 161 | + if ( |
|
| 162 | + $dir = explode('/', $fond) |
|
| 163 | + and $dir = reset($dir) |
|
| 164 | + and $dir !== $z_contenu |
|
| 165 | + and in_array($dir, $z_blocs) |
|
| 166 | + ) { |
|
| 167 | + $type = substr($fond, strlen("$dir/")); |
|
| 168 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | + $type = $flux['args']['contexte'][$page]; |
|
| 170 | + } |
|
| 171 | + if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | + } |
|
| 174 | + if ($type == 'page' or $disponible[$type]) { |
|
| 175 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $squelette = $flux['data']; |
|
| 180 | + } |
|
| 181 | + // layout specifiques par type et compositions : |
|
| 182 | + // body-article.html |
|
| 183 | + // body-sommaire.html |
|
| 184 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | + // meme dossier que body.html |
|
| 186 | + if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | + if ( |
|
| 188 | + isset($flux['args']['contexte']['type-page']) |
|
| 189 | + and ( |
|
| 190 | + (isset($flux['args']['contexte']['composition']) |
|
| 191 | + and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | + or |
|
| 193 | + file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | + ) |
|
| 195 | + ) { |
|
| 196 | + $flux['data'] = $f; |
|
| 197 | + } |
|
| 198 | + } elseif ( |
|
| 199 | + $fond == 'structure' |
|
| 200 | + and z_sanitize_var_zajax() |
|
| 201 | + and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | + ) { |
|
| 203 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | + } // chercher le fond correspondant a la composition |
|
| 205 | + elseif ( |
|
| 206 | + isset($flux['args']['contexte']['composition']) |
|
| 207 | + and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | + and $dir = substr($fond, $prefix_length) |
|
| 209 | + and $dir = explode('/', $dir) |
|
| 210 | + and $dir = reset($dir) |
|
| 211 | + and in_array($dir, $z_blocs) |
|
| 212 | + and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | + ) { |
|
| 214 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + return $flux; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,18 +225,18 @@ discard block |
||
| 225 | 225 | * @return array |
| 226 | 226 | */ |
| 227 | 227 | function z_blocs($espace_prive = false) { |
| 228 | - if ($espace_prive) { |
|
| 229 | - return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | - 'contenu', |
|
| 231 | - 'navigation', |
|
| 232 | - 'extra', |
|
| 233 | - 'head', |
|
| 234 | - 'hierarchie', |
|
| 235 | - 'top' |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 228 | + if ($espace_prive) { |
|
| 229 | + return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | + 'contenu', |
|
| 231 | + 'navigation', |
|
| 232 | + 'extra', |
|
| 233 | + 'head', |
|
| 234 | + 'hierarchie', |
|
| 235 | + 'top' |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @return mixed |
| 252 | 252 | */ |
| 253 | 253 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 254 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | - return $d; |
|
| 256 | - } |
|
| 254 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | + return $d; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 258 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | * `true` si on peut l'utiliser, `false` sinon. |
| 270 | 270 | **/ |
| 271 | 271 | function z_fond_valide($squelette) { |
| 272 | - if ( |
|
| 273 | - !_ZCORE_EXCLURE_PATH |
|
| 274 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | - ) { |
|
| 276 | - return true; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return false; |
|
| 272 | + if ( |
|
| 273 | + !_ZCORE_EXCLURE_PATH |
|
| 274 | + or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | + ) { |
|
| 276 | + return true; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return false; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | 296 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 297 | - if ( |
|
| 298 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | - or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | - ) { |
|
| 301 | - return substr($f, 0, -strlen(".$ext")); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return ''; |
|
| 297 | + if ( |
|
| 298 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | + or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | + ) { |
|
| 301 | + return substr($f, 0, -strlen(".$ext")); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return ''; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -313,52 +313,52 @@ discard block |
||
| 313 | 313 | * @return bool |
| 314 | 314 | */ |
| 315 | 315 | function z_echafaudable($type) { |
| 316 | - static $pages = null; |
|
| 317 | - static $echafaudable = []; |
|
| 318 | - if (isset($echafaudable[$type])) { |
|
| 319 | - return $echafaudable[$type]; |
|
| 320 | - } |
|
| 321 | - if (preg_match(',[^\w],', $type)) { |
|
| 322 | - return $echafaudable[$type] = false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if (test_espace_prive()) { |
|
| 326 | - if (!function_exists('trouver_objet_exec')) { |
|
| 327 | - include_spip('inc/pipelines_ecrire'); |
|
| 328 | - } |
|
| 329 | - if ($e = trouver_objet_exec($type)) { |
|
| 330 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | - } else { |
|
| 332 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | - if ( |
|
| 334 | - ($t = objet_type($type, false)) !== $type |
|
| 335 | - and $e = trouver_objet_exec($t) |
|
| 336 | - ) { |
|
| 337 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } else { |
|
| 341 | - if (is_null($pages)) { |
|
| 342 | - $pages = []; |
|
| 343 | - $liste = lister_tables_objets_sql(); |
|
| 344 | - foreach ($liste as $t => $d) { |
|
| 345 | - if ($d['page']) { |
|
| 346 | - $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - if (!isset($pages[$type])) { |
|
| 351 | - return $echafaudable[$type] = false; |
|
| 352 | - } |
|
| 353 | - if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $echafaudable[$type] = $pages[$type]; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $echafaudable[$type] = false; |
|
| 316 | + static $pages = null; |
|
| 317 | + static $echafaudable = []; |
|
| 318 | + if (isset($echafaudable[$type])) { |
|
| 319 | + return $echafaudable[$type]; |
|
| 320 | + } |
|
| 321 | + if (preg_match(',[^\w],', $type)) { |
|
| 322 | + return $echafaudable[$type] = false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if (test_espace_prive()) { |
|
| 326 | + if (!function_exists('trouver_objet_exec')) { |
|
| 327 | + include_spip('inc/pipelines_ecrire'); |
|
| 328 | + } |
|
| 329 | + if ($e = trouver_objet_exec($type)) { |
|
| 330 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | + } else { |
|
| 332 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | + if ( |
|
| 334 | + ($t = objet_type($type, false)) !== $type |
|
| 335 | + and $e = trouver_objet_exec($t) |
|
| 336 | + ) { |
|
| 337 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } else { |
|
| 341 | + if (is_null($pages)) { |
|
| 342 | + $pages = []; |
|
| 343 | + $liste = lister_tables_objets_sql(); |
|
| 344 | + foreach ($liste as $t => $d) { |
|
| 345 | + if ($d['page']) { |
|
| 346 | + $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + if (!isset($pages[$type])) { |
|
| 351 | + return $echafaudable[$type] = false; |
|
| 352 | + } |
|
| 353 | + if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $echafaudable[$type] = $pages[$type]; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $echafaudable[$type] = false; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -375,46 +375,46 @@ discard block |
||
| 375 | 375 | * @return string |
| 376 | 376 | */ |
| 377 | 377 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 378 | - $scaffold = ''; |
|
| 379 | - |
|
| 380 | - // page objet ou objet_edit |
|
| 381 | - if (is_array($desc_exec)) { |
|
| 382 | - $type = $desc_exec['type']; |
|
| 383 | - $primary = $desc_exec['id_table_objet']; |
|
| 384 | - |
|
| 385 | - if ($desc_exec['edition'] === false) { |
|
| 386 | - $fond = 'objet'; |
|
| 387 | - } else { |
|
| 388 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | - $desc = $trouver_table($table_sql); |
|
| 390 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | - $fond = 'objet_edit'; |
|
| 392 | - } else { |
|
| 393 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - $dir = z_blocs(test_espace_prive()); |
|
| 397 | - $dir = reset($dir); |
|
| 398 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | - } // page objets |
|
| 400 | - elseif ($type = $desc_exec and strpos($type, '/') === false) { |
|
| 401 | - $dir = z_blocs(test_espace_prive()); |
|
| 402 | - $dir = reset($dir); |
|
| 403 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | - } |
|
| 405 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | - // et objet et tire de $table |
|
| 407 | - elseif ($fond = $desc_exec) { |
|
| 408 | - $dir = md5(dirname($fond)); |
|
| 409 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | - $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | - $f = $base_dir . "$exec"; |
|
| 415 | - ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | - |
|
| 417 | - return $f; |
|
| 378 | + $scaffold = ''; |
|
| 379 | + |
|
| 380 | + // page objet ou objet_edit |
|
| 381 | + if (is_array($desc_exec)) { |
|
| 382 | + $type = $desc_exec['type']; |
|
| 383 | + $primary = $desc_exec['id_table_objet']; |
|
| 384 | + |
|
| 385 | + if ($desc_exec['edition'] === false) { |
|
| 386 | + $fond = 'objet'; |
|
| 387 | + } else { |
|
| 388 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | + $desc = $trouver_table($table_sql); |
|
| 390 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | + $fond = 'objet_edit'; |
|
| 392 | + } else { |
|
| 393 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + $dir = z_blocs(test_espace_prive()); |
|
| 397 | + $dir = reset($dir); |
|
| 398 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | + } // page objets |
|
| 400 | + elseif ($type = $desc_exec and strpos($type, '/') === false) { |
|
| 401 | + $dir = z_blocs(test_espace_prive()); |
|
| 402 | + $dir = reset($dir); |
|
| 403 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | + } |
|
| 405 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | + // et objet et tire de $table |
|
| 407 | + elseif ($fond = $desc_exec) { |
|
| 408 | + $dir = md5(dirname($fond)); |
|
| 409 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | + $f = $base_dir . "$exec"; |
|
| 415 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | + |
|
| 417 | + return $f; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return bool|string |
| 424 | 424 | */ |
| 425 | 425 | function z_sanitize_var_zajax() { |
| 426 | - $z_ajax = _request('var_zajax'); |
|
| 427 | - if (!$z_ajax) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - if ( |
|
| 431 | - !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | - or !in_array($z_ajax, $z_blocs) |
|
| 433 | - ) { |
|
| 434 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | - $z_ajax = false; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $z_ajax; |
|
| 426 | + $z_ajax = _request('var_zajax'); |
|
| 427 | + if (!$z_ajax) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + if ( |
|
| 431 | + !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | + or !in_array($z_ajax, $z_blocs) |
|
| 433 | + ) { |
|
| 434 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | + $z_ajax = false; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $z_ajax; |
|
| 439 | 439 | } |
@@ -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,193 +25,193 @@ 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 = ['']; |
|
| 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[] = [$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 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | - $champ = new Champ(); |
|
| 57 | - $champ->nom_boucle = $m[2]; |
|
| 58 | - $champ->nom_champ = $m[3]; |
|
| 59 | - $champ->etoile = $m[5]; |
|
| 60 | - $champ = [$champ]; |
|
| 61 | - if ($m[6]) { |
|
| 62 | - $r = new Texte(); |
|
| 63 | - $r->texte = $m[6]; |
|
| 64 | - $champ[] = $r; |
|
| 65 | - } |
|
| 66 | - $args[] = $champ; |
|
| 67 | - array_shift($p->param); |
|
| 68 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | - } // le cas else est la seule incompatibilite |
|
| 70 | - } |
|
| 71 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = ['']; |
|
| 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[] = [$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 | + } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + $champ = new Champ(); |
|
| 57 | + $champ->nom_boucle = $m[2]; |
|
| 58 | + $champ->nom_champ = $m[3]; |
|
| 59 | + $champ->etoile = $m[5]; |
|
| 60 | + $champ = [$champ]; |
|
| 61 | + if ($m[6]) { |
|
| 62 | + $r = new Texte(); |
|
| 63 | + $r->texte = $m[6]; |
|
| 64 | + $champ[] = $r; |
|
| 65 | + } |
|
| 66 | + $args[] = $champ; |
|
| 67 | + array_shift($p->param); |
|
| 68 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | + } // le cas else est la seule incompatibilite |
|
| 70 | + } |
|
| 71 | + array_unshift($p->param, $args); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | function phraser_logo_faux_filtres($nom) { |
| 76 | - switch ($nom) { |
|
| 77 | - case 'top': |
|
| 78 | - case 'left': |
|
| 79 | - case 'right': |
|
| 80 | - case 'center': |
|
| 81 | - case 'bottom': |
|
| 82 | - return 0; |
|
| 83 | - case 'lien': |
|
| 84 | - return 1; |
|
| 85 | - case 'fichier': |
|
| 86 | - return 2; |
|
| 87 | - default: |
|
| 88 | - return $nom; |
|
| 89 | - } |
|
| 76 | + switch ($nom) { |
|
| 77 | + case 'top': |
|
| 78 | + case 'left': |
|
| 79 | + case 'right': |
|
| 80 | + case 'center': |
|
| 81 | + case 'bottom': |
|
| 82 | + return 0; |
|
| 83 | + case 'lien': |
|
| 84 | + return 1; |
|
| 85 | + case 'fichier': |
|
| 86 | + return 2; |
|
| 87 | + default: |
|
| 88 | + return $nom; |
|
| 89 | + } |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | // La balise embed_document est a present le modele emb |
| 94 | 94 | |
| 95 | 95 | function phraser_vieux_emb(&$p) { |
| 96 | - if (!is_array($p->param)) { |
|
| 97 | - $p->param = []; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Produire le premier argument {emb} |
|
| 101 | - $texte = new Texte(); |
|
| 102 | - $texte->texte = 'emb'; |
|
| 103 | - $param = ['', [$texte]]; |
|
| 104 | - |
|
| 105 | - // Transformer les filtres en arguments |
|
| 106 | - for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | - if ($p->param[$i][0]) { |
|
| 108 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | - break; |
|
| 110 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | - $texte = new Texte(); |
|
| 112 | - $texte->texte = $p->param[$i][0]; |
|
| 113 | - $param[] = [$texte]; |
|
| 114 | - } |
|
| 115 | - array_shift($p->param); |
|
| 116 | - } |
|
| 117 | - array_unshift($p->param, $param); |
|
| 118 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | - $p->nom_champ = 'MODELE'; |
|
| 96 | + if (!is_array($p->param)) { |
|
| 97 | + $p->param = []; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Produire le premier argument {emb} |
|
| 101 | + $texte = new Texte(); |
|
| 102 | + $texte->texte = 'emb'; |
|
| 103 | + $param = ['', [$texte]]; |
|
| 104 | + |
|
| 105 | + // Transformer les filtres en arguments |
|
| 106 | + for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | + if ($p->param[$i][0]) { |
|
| 108 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | + break; |
|
| 110 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | + $texte = new Texte(); |
|
| 112 | + $texte->texte = $p->param[$i][0]; |
|
| 113 | + $param[] = [$texte]; |
|
| 114 | + } |
|
| 115 | + array_shift($p->param); |
|
| 116 | + } |
|
| 117 | + array_unshift($p->param, $param); |
|
| 118 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | + $p->nom_champ = 'MODELE'; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Vieux formulaire de recherch |
| 123 | 123 | |
| 124 | 124 | function phraser_vieux_recherche($p) { |
| 125 | - if ($p->param[0][0]) { |
|
| 126 | - $c = new Texte(); |
|
| 127 | - $c->texte = $p->param[0][0]; |
|
| 128 | - $p->param[0][1] = [$c]; |
|
| 129 | - $p->param[0][0] = ''; |
|
| 130 | - $p->fonctions = []; |
|
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | - } |
|
| 125 | + if ($p->param[0][0]) { |
|
| 126 | + $c = new Texte(); |
|
| 127 | + $c->texte = $p->param[0][0]; |
|
| 128 | + $p->param[0][1] = [$c]; |
|
| 129 | + $p->param[0][0] = ''; |
|
| 130 | + $p->fonctions = []; |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Gerer la notation [(#EXPOSER|on,off)] |
| 136 | 136 | function phraser_vieux_exposer($p) { |
| 137 | - if ($a = $p->fonctions) { |
|
| 138 | - preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | - $args = []; |
|
| 140 | - if ($regs[1]) { |
|
| 141 | - $a = new Texte(); |
|
| 142 | - $a->texte = $regs[1]; |
|
| 143 | - $args = ['', [$a]]; |
|
| 144 | - if ($regs[3]) { |
|
| 145 | - $a = new Texte(); |
|
| 146 | - $a->texte = $regs[3]; |
|
| 147 | - $args[] = [$a]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $p->param[0] = $args; |
|
| 151 | - $p->fonctions = []; |
|
| 152 | - $p->nom_champ = 'EXPOSE'; |
|
| 153 | - } |
|
| 137 | + if ($a = $p->fonctions) { |
|
| 138 | + preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | + $args = []; |
|
| 140 | + if ($regs[1]) { |
|
| 141 | + $a = new Texte(); |
|
| 142 | + $a->texte = $regs[1]; |
|
| 143 | + $args = ['', [$a]]; |
|
| 144 | + if ($regs[3]) { |
|
| 145 | + $a = new Texte(); |
|
| 146 | + $a->texte = $regs[3]; |
|
| 147 | + $args[] = [$a]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $p->param[0] = $args; |
|
| 151 | + $p->fonctions = []; |
|
| 152 | + $p->nom_champ = 'EXPOSE'; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | function phraser_vieux_modele($p) { |
| 157 | - normaliser_args_inclumodel($p); |
|
| 157 | + normaliser_args_inclumodel($p); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | function phraser_vieux_inclu($p) { |
| 161 | - normaliser_args_inclumodel($p); |
|
| 161 | + normaliser_args_inclumodel($p); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | function normaliser_args_inclumodel($p) { |
| 165 | - $params = $p->param; |
|
| 166 | - if (!$params) { |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - $args = $params[0]; |
|
| 170 | - if ($args[0]) { |
|
| 171 | - return; |
|
| 172 | - } // filtre immediat |
|
| 173 | - array_shift($p->param); |
|
| 174 | - foreach ($p->param as $l) { |
|
| 175 | - if (!array_shift($l)) { |
|
| 176 | - $args = array_merge($args, $l); |
|
| 177 | - array_shift($p->param); |
|
| 178 | - } else { |
|
| 179 | - break; |
|
| 180 | - } // filtre |
|
| 181 | - } |
|
| 182 | - array_unshift($p->param, $args); |
|
| 165 | + $params = $p->param; |
|
| 166 | + if (!$params) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + $args = $params[0]; |
|
| 170 | + if ($args[0]) { |
|
| 171 | + return; |
|
| 172 | + } // filtre immediat |
|
| 173 | + array_shift($p->param); |
|
| 174 | + foreach ($p->param as $l) { |
|
| 175 | + if (!array_shift($l)) { |
|
| 176 | + $args = array_merge($args, $l); |
|
| 177 | + array_shift($p->param); |
|
| 178 | + } else { |
|
| 179 | + break; |
|
| 180 | + } // filtre |
|
| 181 | + } |
|
| 182 | + array_unshift($p->param, $args); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function normaliser_inclure($champ) { |
| 186 | - normaliser_args_inclumodel($champ); |
|
| 187 | - $l = $champ->param[0]; |
|
| 188 | - if (is_array($l) and !$l[0]) { |
|
| 189 | - foreach ($l as $k => $p) { |
|
| 190 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | - $p[0]->texte = trim($p[0]->texte); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - foreach ($l as $k => $p) { |
|
| 195 | - if ( |
|
| 196 | - !$p or $p[0]->type != 'texte' or |
|
| 197 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | - ) { |
|
| 199 | - continue; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($r[1]) { |
|
| 203 | - $p[0]->texte = $r[1]; |
|
| 204 | - } else { |
|
| 205 | - unset($p[0]); |
|
| 206 | - } |
|
| 207 | - $champ->texte = $p; |
|
| 208 | - unset($champ->param[0][$k]); |
|
| 209 | - if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | - array_shift($champ->param); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - spip_log('inclure sans fond ni fichier'); |
|
| 186 | + normaliser_args_inclumodel($champ); |
|
| 187 | + $l = $champ->param[0]; |
|
| 188 | + if (is_array($l) and !$l[0]) { |
|
| 189 | + foreach ($l as $k => $p) { |
|
| 190 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | + $p[0]->texte = trim($p[0]->texte); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + foreach ($l as $k => $p) { |
|
| 195 | + if ( |
|
| 196 | + !$p or $p[0]->type != 'texte' or |
|
| 197 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | + ) { |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($r[1]) { |
|
| 203 | + $p[0]->texte = $r[1]; |
|
| 204 | + } else { |
|
| 205 | + unset($p[0]); |
|
| 206 | + } |
|
| 207 | + $champ->texte = $p; |
|
| 208 | + unset($champ->param[0][$k]); |
|
| 209 | + if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | + array_shift($champ->param); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + spip_log('inclure sans fond ni fichier'); |
|
| 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 | /** |
@@ -36,15 +36,15 @@ discard block |
||
| 36 | 36 | define('_PHP_MIN', '7.4.0'); |
| 37 | 37 | |
| 38 | 38 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 39 | - /** le nom du repertoire ecrire/ */ |
|
| 40 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 39 | + /** le nom du repertoire ecrire/ */ |
|
| 40 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** Chemin relatif pour aller dans ecrire |
| 44 | 44 | * vide si on est dans ecrire, 'ecrire/' sinon */ |
| 45 | 45 | define( |
| 46 | - '_DIR_RESTREINT', |
|
| 47 | - (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 46 | + '_DIR_RESTREINT', |
|
| 47 | + (!is_dir(_DIR_RESTREINT_ABS) ? '' : _DIR_RESTREINT_ABS) |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | 50 | /** Chemin relatif pour aller à la racine */ |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | // Icones |
| 61 | 61 | if (!defined('_NOM_IMG_PACK')) { |
| 62 | - /** Nom du dossier images */ |
|
| 63 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 62 | + /** Nom du dossier images */ |
|
| 63 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 64 | 64 | } |
| 65 | 65 | /** le chemin http (relatif) vers les images standard */ |
| 66 | 66 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | define('_ROOT_IMG_PACK', dirname(__DIR__) . '/prive/' . _NOM_IMG_PACK); |
| 70 | 70 | |
| 71 | 71 | if (!defined('_JAVASCRIPT')) { |
| 72 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 73 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 72 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 73 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 74 | 74 | } // utilisable avec #CHEMIN et find_in_path |
| 75 | 75 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
| 76 | 76 | define('_DIR_JAVASCRIPT', (_DIR_RACINE . 'prive/' . _JAVASCRIPT)); |
@@ -80,47 +80,47 @@ discard block |
||
| 80 | 80 | # mais on peut les mettre ailleurs et changer completement les noms |
| 81 | 81 | |
| 82 | 82 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 83 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 84 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 83 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 84 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 85 | 85 | } |
| 86 | 86 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 87 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 88 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 87 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 88 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 89 | 89 | } |
| 90 | 90 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 91 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 92 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 91 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 92 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 93 | 93 | } |
| 94 | 94 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 95 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 96 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 95 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 96 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /** Le nom du fichier de personnalisation */ |
| 101 | 101 | if (!defined('_NOM_CONFIG')) { |
| 102 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 102 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // Son emplacement absolu si on le trouve |
| 106 | 106 | if ( |
| 107 | - @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 108 | - or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 107 | + @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php') |
|
| 108 | + or (@file_exists($f = _ROOT_RESTREINT . _NOM_CONFIG . '.php')) |
|
| 109 | 109 | ) { |
| 110 | - /** Emplacement absolu du fichier d'option */ |
|
| 111 | - define('_FILE_OPTIONS', $f); |
|
| 110 | + /** Emplacement absolu du fichier d'option */ |
|
| 111 | + define('_FILE_OPTIONS', $f); |
|
| 112 | 112 | } else { |
| 113 | - define('_FILE_OPTIONS', ''); |
|
| 113 | + define('_FILE_OPTIONS', ''); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | if (!defined('MODULES_IDIOMES')) { |
| 117 | - /** |
|
| 118 | - * Modules par défaut pour la traduction. |
|
| 119 | - * |
|
| 120 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 121 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 122 | - */ |
|
| 123 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 117 | + /** |
|
| 118 | + * Modules par défaut pour la traduction. |
|
| 119 | + * |
|
| 120 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 121 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 122 | + */ |
|
| 123 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // *** Fin des define *** // |
@@ -128,10 +128,10 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | // Inclure l'ecran de securite |
| 130 | 130 | if ( |
| 131 | - !defined('_ECRAN_SECURITE') |
|
| 132 | - and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 131 | + !defined('_ECRAN_SECURITE') |
|
| 132 | + and @file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . 'ecran_securite.php') |
|
| 133 | 133 | ) { |
| 134 | - include $f; |
|
| 134 | + include $f; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -139,30 +139,30 @@ discard block |
||
| 139 | 139 | * Détecteur de robot d'indexation |
| 140 | 140 | */ |
| 141 | 141 | if (!defined('_IS_BOT')) { |
| 142 | - define( |
|
| 143 | - '_IS_BOT', |
|
| 144 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | - and preg_match( |
|
| 146 | - // mots generiques |
|
| 147 | - ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | - // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | - . 'MSIE 6\.0|' |
|
| 150 | - // UA plus cibles |
|
| 151 | - . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | - . ',i', |
|
| 153 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 142 | + define( |
|
| 143 | + '_IS_BOT', |
|
| 144 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 145 | + and preg_match( |
|
| 146 | + // mots generiques |
|
| 147 | + ',bot|slurp|crawler|spider|webvac|yandex|' |
|
| 148 | + // MSIE 6.0 est un botnet 99,9% du temps, on traite donc ce USER_AGENT comme un bot |
|
| 149 | + . 'MSIE 6\.0|' |
|
| 150 | + // UA plus cibles |
|
| 151 | + . '80legs|accoona|AltaVista|ASPSeek|Baidu|Charlotte|EC2LinkFinder|eStyle|facebook|flipboard|hootsuite|FunWebProducts|Google|Genieo|INA dlweb|InfegyAtlas|Java VM|LiteFinder|Lycos|MetaURI|Moreover|Rambler|Scooter|ScrubbyBloglines|Yahoo|Yeti' |
|
| 152 | + . ',i', |
|
| 153 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | if (!defined('_IS_CLI')) { |
| 159 | - define( |
|
| 160 | - '_IS_CLI', |
|
| 161 | - !isset($_SERVER['HTTP_HOST']) |
|
| 162 | - and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 163 | - and !empty($_SERVER['argv']) |
|
| 164 | - and empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | - ); |
|
| 159 | + define( |
|
| 160 | + '_IS_CLI', |
|
| 161 | + !isset($_SERVER['HTTP_HOST']) |
|
| 162 | + and !strlen($_SERVER['DOCUMENT_ROOT']) |
|
| 163 | + and !empty($_SERVER['argv']) |
|
| 164 | + and empty($_SERVER['REQUEST_METHOD']) |
|
| 165 | + ); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // *** Parametrage par defaut de SPIP *** |
@@ -174,61 +174,61 @@ discard block |
||
| 174 | 174 | // Ne pas les rendre indefinies. |
| 175 | 175 | |
| 176 | 176 | global |
| 177 | - $nombre_de_logs, |
|
| 178 | - $taille_des_logs, |
|
| 179 | - $table_prefix, |
|
| 180 | - $cookie_prefix, |
|
| 181 | - $dossier_squelettes, |
|
| 182 | - $filtrer_javascript, |
|
| 183 | - $type_urls, |
|
| 184 | - $debut_date_publication, |
|
| 185 | - $ip, |
|
| 186 | - $mysql_rappel_connexion, |
|
| 187 | - $mysql_rappel_nom_base, |
|
| 188 | - $test_i18n, |
|
| 189 | - $ignore_auth_http, |
|
| 190 | - $ignore_remote_user, |
|
| 191 | - $derniere_modif_invalide, |
|
| 192 | - $home_server, |
|
| 193 | - $help_server, |
|
| 194 | - $url_glossaire_externe, |
|
| 195 | - $tex_server, |
|
| 196 | - $traiter_math, |
|
| 197 | - $xhtml, |
|
| 198 | - $xml_indent, |
|
| 199 | - $source_vignettes, |
|
| 200 | - $formats_logos, |
|
| 201 | - $controler_dates_rss, |
|
| 202 | - $spip_pipeline, |
|
| 203 | - $spip_matrice, |
|
| 204 | - $plugins, |
|
| 205 | - $surcharges, |
|
| 206 | - $exceptions_des_tables, |
|
| 207 | - $tables_principales, |
|
| 208 | - $table_des_tables, |
|
| 209 | - $tables_auxiliaires, |
|
| 210 | - $table_primary, |
|
| 211 | - $table_date, |
|
| 212 | - $table_titre, |
|
| 213 | - $tables_jointures, |
|
| 214 | - $liste_des_statuts, |
|
| 215 | - $liste_des_etats, |
|
| 216 | - $liste_des_authentifications, |
|
| 217 | - $spip_version_branche, |
|
| 218 | - $spip_version_code, |
|
| 219 | - $spip_version_base, |
|
| 220 | - $spip_sql_version, |
|
| 221 | - $spip_version_affichee, |
|
| 222 | - $visiteur_session, |
|
| 223 | - $auteur_session, |
|
| 224 | - $connect_statut, |
|
| 225 | - $connect_toutes_rubriques, |
|
| 226 | - $hash_recherche, |
|
| 227 | - $hash_recherche_strict, |
|
| 228 | - $ldap_present, |
|
| 229 | - $meta, |
|
| 230 | - $connect_id_rubrique, |
|
| 231 | - $puce; |
|
| 177 | + $nombre_de_logs, |
|
| 178 | + $taille_des_logs, |
|
| 179 | + $table_prefix, |
|
| 180 | + $cookie_prefix, |
|
| 181 | + $dossier_squelettes, |
|
| 182 | + $filtrer_javascript, |
|
| 183 | + $type_urls, |
|
| 184 | + $debut_date_publication, |
|
| 185 | + $ip, |
|
| 186 | + $mysql_rappel_connexion, |
|
| 187 | + $mysql_rappel_nom_base, |
|
| 188 | + $test_i18n, |
|
| 189 | + $ignore_auth_http, |
|
| 190 | + $ignore_remote_user, |
|
| 191 | + $derniere_modif_invalide, |
|
| 192 | + $home_server, |
|
| 193 | + $help_server, |
|
| 194 | + $url_glossaire_externe, |
|
| 195 | + $tex_server, |
|
| 196 | + $traiter_math, |
|
| 197 | + $xhtml, |
|
| 198 | + $xml_indent, |
|
| 199 | + $source_vignettes, |
|
| 200 | + $formats_logos, |
|
| 201 | + $controler_dates_rss, |
|
| 202 | + $spip_pipeline, |
|
| 203 | + $spip_matrice, |
|
| 204 | + $plugins, |
|
| 205 | + $surcharges, |
|
| 206 | + $exceptions_des_tables, |
|
| 207 | + $tables_principales, |
|
| 208 | + $table_des_tables, |
|
| 209 | + $tables_auxiliaires, |
|
| 210 | + $table_primary, |
|
| 211 | + $table_date, |
|
| 212 | + $table_titre, |
|
| 213 | + $tables_jointures, |
|
| 214 | + $liste_des_statuts, |
|
| 215 | + $liste_des_etats, |
|
| 216 | + $liste_des_authentifications, |
|
| 217 | + $spip_version_branche, |
|
| 218 | + $spip_version_code, |
|
| 219 | + $spip_version_base, |
|
| 220 | + $spip_sql_version, |
|
| 221 | + $spip_version_affichee, |
|
| 222 | + $visiteur_session, |
|
| 223 | + $auteur_session, |
|
| 224 | + $connect_statut, |
|
| 225 | + $connect_toutes_rubriques, |
|
| 226 | + $hash_recherche, |
|
| 227 | + $hash_recherche_strict, |
|
| 228 | + $ldap_present, |
|
| 229 | + $meta, |
|
| 230 | + $connect_id_rubrique, |
|
| 231 | + $puce; |
|
| 232 | 232 | |
| 233 | 233 | # comment on logge, defaut 4 tmp/spip.log de 100k, 0 ou 0 suppriment le log |
| 234 | 234 | $nombre_de_logs = 4; |
@@ -283,48 +283,48 @@ discard block |
||
| 283 | 283 | // Prendre en compte les entetes HTTP_X_FORWARDED_XX |
| 284 | 284 | // |
| 285 | 285 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
| 286 | - if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | - } |
|
| 289 | - if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | - $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | - } |
|
| 286 | + if (empty($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 287 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = $_SERVER['HTTP_HOST']; |
|
| 288 | + } |
|
| 289 | + if (empty($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 290 | + $_SERVER['HTTP_X_FORWARDED_PORT'] = 443; |
|
| 291 | + } |
|
| 292 | 292 | } |
| 293 | 293 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 294 | - if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | - $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | - $_SERVER['HTTPS'] = 'on'; |
|
| 298 | - if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | - $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | - if (strpos($host, ',') !== false) { |
|
| 305 | - $h = explode(',', $host); |
|
| 306 | - $host = trim(reset($h)); |
|
| 307 | - } |
|
| 308 | - // securite sur le contenu de l'entete |
|
| 309 | - $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | - $_SERVER['HTTP_HOST'] = $host; |
|
| 294 | + if (isset($_SERVER['HTTP_X_FORWARDED_PORT']) and is_numeric($_SERVER['HTTP_X_FORWARDED_PORT'])) { |
|
| 295 | + $_SERVER['SERVER_PORT'] = $_SERVER['HTTP_X_FORWARDED_PORT']; |
|
| 296 | + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) and $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { |
|
| 297 | + $_SERVER['HTTPS'] = 'on'; |
|
| 298 | + if (isset($_SERVER['REQUEST_SCHEME'])) { |
|
| 299 | + $_SERVER['REQUEST_SCHEME'] = 'https'; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + $host = $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 304 | + if (strpos($host, ',') !== false) { |
|
| 305 | + $h = explode(',', $host); |
|
| 306 | + $host = trim(reset($h)); |
|
| 307 | + } |
|
| 308 | + // securite sur le contenu de l'entete |
|
| 309 | + $host = strtr($host, "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 310 | + $_SERVER['HTTP_HOST'] = $host; |
|
| 311 | 311 | } |
| 312 | 312 | // |
| 313 | 313 | // On note le numero IP du client dans la variable $ip |
| 314 | 314 | // |
| 315 | 315 | if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
| 316 | - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | - if (strpos($ip, ',') !== false) { |
|
| 318 | - $ip = explode(',', $ip); |
|
| 319 | - $ip = reset($ip); |
|
| 320 | - } |
|
| 321 | - // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | - if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | - $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | - } |
|
| 316 | + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 317 | + if (strpos($ip, ',') !== false) { |
|
| 318 | + $ip = explode(',', $ip); |
|
| 319 | + $ip = reset($ip); |
|
| 320 | + } |
|
| 321 | + // ecraser $_SERVER['REMOTE_ADDR'] si elle est en localhost |
|
| 322 | + if (isset($_SERVER['REMOTE_ADDR']) and $_SERVER['REMOTE_ADDR'] === '127.0.0.1') { |
|
| 323 | + $_SERVER['REMOTE_ADDR'] = $ip; |
|
| 324 | + } |
|
| 325 | 325 | } |
| 326 | 326 | if (isset($_SERVER['REMOTE_ADDR'])) { |
| 327 | - $ip = $_SERVER['REMOTE_ADDR']; |
|
| 327 | + $ip = $_SERVER['REMOTE_ADDR']; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Pour renforcer la privacy, decommentez la ligne ci-dessous (ou recopiez-la |
@@ -409,24 +409,24 @@ discard block |
||
| 409 | 409 | |
| 410 | 410 | // Liste des statuts. |
| 411 | 411 | $liste_des_statuts = [ |
| 412 | - 'info_administrateurs' => '0minirezo', |
|
| 413 | - 'info_redacteurs' => '1comite', |
|
| 414 | - 'info_visiteurs' => '6forum', |
|
| 415 | - 'texte_statut_poubelle' => '5poubelle' |
|
| 412 | + 'info_administrateurs' => '0minirezo', |
|
| 413 | + 'info_redacteurs' => '1comite', |
|
| 414 | + 'info_visiteurs' => '6forum', |
|
| 415 | + 'texte_statut_poubelle' => '5poubelle' |
|
| 416 | 416 | ]; |
| 417 | 417 | |
| 418 | 418 | $liste_des_etats = [ |
| 419 | - 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | - 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | - 'texte_statut_publie' => 'publie', |
|
| 422 | - 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | - 'texte_statut_refuse' => 'refuse' |
|
| 419 | + 'texte_statut_en_cours_redaction' => 'prepa', |
|
| 420 | + 'texte_statut_propose_evaluation' => 'prop', |
|
| 421 | + 'texte_statut_publie' => 'publie', |
|
| 422 | + 'texte_statut_poubelle' => 'poubelle', |
|
| 423 | + 'texte_statut_refuse' => 'refuse' |
|
| 424 | 424 | ]; |
| 425 | 425 | |
| 426 | 426 | // liste des methodes d'authentifications |
| 427 | 427 | $liste_des_authentifications = [ |
| 428 | - 'spip' => 'spip', |
|
| 429 | - 'ldap' => 'ldap' |
|
| 428 | + 'spip' => 'spip', |
|
| 429 | + 'ldap' => 'ldap' |
|
| 430 | 430 | ]; |
| 431 | 431 | |
| 432 | 432 | // Experimental : pour supprimer systematiquement l'affichage des numeros |
@@ -476,12 +476,12 @@ discard block |
||
| 476 | 476 | // Definition personnelles eventuelles |
| 477 | 477 | |
| 478 | 478 | if (_FILE_OPTIONS) { |
| 479 | - include_once _FILE_OPTIONS; |
|
| 479 | + include_once _FILE_OPTIONS; |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | if (!defined('SPIP_ERREUR_REPORT')) { |
| 483 | - /** Masquer les warning */ |
|
| 484 | - define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 483 | + /** Masquer les warning */ |
|
| 484 | + define('SPIP_ERREUR_REPORT', E_ALL ^ E_NOTICE ^ E_DEPRECATED); |
|
| 485 | 485 | } |
| 486 | 486 | error_reporting(SPIP_ERREUR_REPORT); |
| 487 | 487 | |
@@ -494,10 +494,10 @@ discard block |
||
| 494 | 494 | // ===> on execute en neutralisant les messages d'erreur |
| 495 | 495 | |
| 496 | 496 | spip_initialisation_core( |
| 497 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 497 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 498 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 499 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 500 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 501 | 501 | ); |
| 502 | 502 | |
| 503 | 503 | |
@@ -507,70 +507,70 @@ discard block |
||
| 507 | 507 | // donc il faut avoir tout fini ici avant de charger les plugins |
| 508 | 508 | |
| 509 | 509 | if (@is_readable(_CACHE_PLUGINS_OPT) and @is_readable(_CACHE_PLUGINS_PATH)) { |
| 510 | - // chargement optimise precompile |
|
| 511 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 510 | + // chargement optimise precompile |
|
| 511 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 512 | 512 | } else { |
| 513 | - spip_initialisation_suite(); |
|
| 514 | - include_spip('inc/plugin'); |
|
| 515 | - // generer les fichiers php precompiles |
|
| 516 | - // de chargement des plugins et des pipelines |
|
| 517 | - actualise_plugins_actifs(); |
|
| 513 | + spip_initialisation_suite(); |
|
| 514 | + include_spip('inc/plugin'); |
|
| 515 | + // generer les fichiers php precompiles |
|
| 516 | + // de chargement des plugins et des pipelines |
|
| 517 | + actualise_plugins_actifs(); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // Initialisations non critiques surchargeables par les plugins |
| 521 | 521 | spip_initialisation_suite(); |
| 522 | 522 | |
| 523 | 523 | if (!defined('_LOG_FILTRE_GRAVITE')) { |
| 524 | - /** niveau maxi d'enregistrement des logs */ |
|
| 525 | - define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 524 | + /** niveau maxi d'enregistrement des logs */ |
|
| 525 | + define('_LOG_FILTRE_GRAVITE', _LOG_INFO_IMPORTANTE); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | if (!defined('_OUTILS_DEVELOPPEURS')) { |
| 529 | - /** Activer des outils pour développeurs ? */ |
|
| 530 | - define('_OUTILS_DEVELOPPEURS', false); |
|
| 529 | + /** Activer des outils pour développeurs ? */ |
|
| 530 | + define('_OUTILS_DEVELOPPEURS', false); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | // charger systematiquement inc/autoriser dans l'espace restreint |
| 534 | 534 | if (test_espace_prive()) { |
| 535 | - include_spip('inc/autoriser'); |
|
| 535 | + include_spip('inc/autoriser'); |
|
| 536 | 536 | } |
| 537 | 537 | // |
| 538 | 538 | // Installer Spip si pas installe... sauf si justement on est en train |
| 539 | 539 | // |
| 540 | 540 | if ( |
| 541 | - !(_FILE_CONNECT |
|
| 542 | - or autoriser_sans_cookie(_request('exec')) |
|
| 543 | - or _request('action') == 'cookie' |
|
| 544 | - or _request('action') == 'converser' |
|
| 545 | - or _request('action') == 'test_dirs') |
|
| 541 | + !(_FILE_CONNECT |
|
| 542 | + or autoriser_sans_cookie(_request('exec')) |
|
| 543 | + or _request('action') == 'cookie' |
|
| 544 | + or _request('action') == 'converser' |
|
| 545 | + or _request('action') == 'test_dirs') |
|
| 546 | 546 | ) { |
| 547 | - // Si on peut installer, on lance illico |
|
| 548 | - if (test_espace_prive()) { |
|
| 549 | - include_spip('inc/headers'); |
|
| 550 | - redirige_url_ecrire('install'); |
|
| 551 | - } else { |
|
| 552 | - // Si on est dans le site public, dire que qq s'en occupe |
|
| 553 | - include_spip('inc/minipres'); |
|
| 554 | - utiliser_langue_visiteur(); |
|
| 555 | - echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 556 | - exit; |
|
| 557 | - } |
|
| 558 | - // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 547 | + // Si on peut installer, on lance illico |
|
| 548 | + if (test_espace_prive()) { |
|
| 549 | + include_spip('inc/headers'); |
|
| 550 | + redirige_url_ecrire('install'); |
|
| 551 | + } else { |
|
| 552 | + // Si on est dans le site public, dire que qq s'en occupe |
|
| 553 | + include_spip('inc/minipres'); |
|
| 554 | + utiliser_langue_visiteur(); |
|
| 555 | + echo minipres(_T('info_travaux_titre'), "<p style='text-align: center;'>" . _T('info_travaux_texte') . '</p>', ['status' => 503]); |
|
| 556 | + exit; |
|
| 557 | + } |
|
| 558 | + // autrement c'est une install ad hoc (spikini...), on sait pas faire |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | // memoriser un tri sessionne eventuel |
| 562 | 562 | if ( |
| 563 | - isset($_REQUEST['var_memotri']) |
|
| 564 | - and $t = $_REQUEST['var_memotri'] |
|
| 565 | - and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 563 | + isset($_REQUEST['var_memotri']) |
|
| 564 | + and $t = $_REQUEST['var_memotri'] |
|
| 565 | + and (strncmp($t, 'trisession', 10) == 0 or strncmp($t, 'senssession', 11) == 0) |
|
| 566 | 566 | ) { |
| 567 | - if (!function_exists('session_set')) { |
|
| 568 | - include_spip('inc/session'); |
|
| 569 | - } |
|
| 570 | - $t = preg_replace(',\W,', '_', $t); |
|
| 571 | - if ($v = _request($t)) { |
|
| 572 | - session_set($t, $v); |
|
| 573 | - } |
|
| 567 | + if (!function_exists('session_set')) { |
|
| 568 | + include_spip('inc/session'); |
|
| 569 | + } |
|
| 570 | + $t = preg_replace(',\W,', '_', $t); |
|
| 571 | + if ($v = _request($t)) { |
|
| 572 | + session_set($t, $v); |
|
| 573 | + } |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -580,22 +580,22 @@ discard block |
||
| 580 | 580 | * La globale $spip_header_silencieux permet de rendre le header minimal pour raisons de securite |
| 581 | 581 | */ |
| 582 | 582 | if (!defined('_HEADER_COMPOSED_BY')) { |
| 583 | - define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 583 | + define('_HEADER_COMPOSED_BY', 'Composed-By: SPIP'); |
|
| 584 | 584 | } |
| 585 | 585 | if (!headers_sent() and _HEADER_COMPOSED_BY) { |
| 586 | - if (!defined('_HEADER_VARY')) { |
|
| 587 | - define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 588 | - } |
|
| 589 | - if (_HEADER_VARY) { |
|
| 590 | - header(_HEADER_VARY); |
|
| 591 | - } |
|
| 592 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 593 | - include_spip('inc/filtres_mini'); |
|
| 594 | - header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 595 | - } else { |
|
| 596 | - // header minimal |
|
| 597 | - header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 598 | - } |
|
| 586 | + if (!defined('_HEADER_VARY')) { |
|
| 587 | + define('_HEADER_VARY', 'Vary: Cookie, Accept-Encoding'); |
|
| 588 | + } |
|
| 589 | + if (_HEADER_VARY) { |
|
| 590 | + header(_HEADER_VARY); |
|
| 591 | + } |
|
| 592 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 593 | + include_spip('inc/filtres_mini'); |
|
| 594 | + header(_HEADER_COMPOSED_BY . " $spip_version_affichee @ www.spip.net + " . url_absolue(_DIR_VAR . 'config.txt')); |
|
| 595 | + } else { |
|
| 596 | + // header minimal |
|
| 597 | + header(_HEADER_COMPOSED_BY . ' @ www.spip.net'); |
|
| 598 | + } |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | $methode = ($_SERVER['REQUEST_METHOD'] ?? ((php_sapi_name() == 'cli') ? 'cli' : '')); |