@@ -11,37 +11,37 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // rien sauf les "~" et "-," |
| 18 | 18 | |
| 19 | 19 | function typographie_en_dist($letexte) { |
| 20 | 20 | |
| 21 | - // zouli apostrophe |
|
| 22 | - $letexte = str_replace("'", '’', $letexte); |
|
| 21 | + // zouli apostrophe |
|
| 22 | + $letexte = str_replace("'", '’', $letexte); |
|
| 23 | 23 | |
| 24 | - $cherche1 = [ |
|
| 25 | - '/ --?,/S' |
|
| 26 | - ]; |
|
| 27 | - $remplace1 = [ |
|
| 28 | - '~\0' |
|
| 29 | - ]; |
|
| 30 | - $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 24 | + $cherche1 = [ |
|
| 25 | + '/ --?,/S' |
|
| 26 | + ]; |
|
| 27 | + $remplace1 = [ |
|
| 28 | + '~\0' |
|
| 29 | + ]; |
|
| 30 | + $letexte = preg_replace($cherche1, $remplace1, $letexte); |
|
| 31 | 31 | |
| 32 | - $letexte = str_replace(' ', '~', $letexte); |
|
| 33 | - $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 32 | + $letexte = str_replace(' ', '~', $letexte); |
|
| 33 | + $letexte = preg_replace('/ *~+ */', '~', $letexte); |
|
| 34 | 34 | |
| 35 | - $cherche2 = [ |
|
| 36 | - '/([^-\n]|^)--([^-]|$)/', |
|
| 37 | - '/~/' |
|
| 38 | - ]; |
|
| 39 | - $remplace2 = [ |
|
| 40 | - '\1—\2', |
|
| 41 | - ' ' |
|
| 42 | - ]; |
|
| 35 | + $cherche2 = [ |
|
| 36 | + '/([^-\n]|^)--([^-]|$)/', |
|
| 37 | + '/~/' |
|
| 38 | + ]; |
|
| 39 | + $remplace2 = [ |
|
| 40 | + '\1—\2', |
|
| 41 | + ' ' |
|
| 42 | + ]; |
|
| 43 | 43 | |
| 44 | - $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 44 | + $letexte = preg_replace($cherche2, $remplace2, $letexte); |
|
| 45 | 45 | |
| 46 | - return $letexte; |
|
| 46 | + return $letexte; |
|
| 47 | 47 | } |
@@ -177,14 +177,14 @@ discard block |
||
| 177 | 177 | // sache qu'il peut enlever ce where si il enleve la jointure |
| 178 | 178 | $boucle->where["JOIN-L$n"] = |
| 179 | 179 | $echap ? |
| 180 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 180 | + ["'='", "'$obj'", "sql_quote('$type')"] |
|
| 181 | 181 | : |
| 182 | - ['=',"$obj",sql_quote($type)]; |
|
| 182 | + ['=', "$obj", sql_quote($type)]; |
|
| 183 | 183 | $boucle->join["L$n"] = |
| 184 | 184 | $echap ? |
| 185 | 185 | ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
| 186 | 186 | : |
| 187 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 187 | + [$id_table, $j2, $j1, "$obj=".sql_quote($type)]; |
|
| 188 | 188 | } else { |
| 189 | 189 | $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
| 190 | 190 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $groups = liste_champs_jointures($nom, $desc, true); |
| 219 | 219 | if (!$pk) { |
| 220 | 220 | foreach ($groups as $id_prim) { |
| 221 | - $id_field = $nom . '.' . $id_prim; |
|
| 221 | + $id_field = $nom.'.'.$id_prim; |
|
| 222 | 222 | if (!in_array($id_field, $boucle->group)) { |
| 223 | 223 | $boucle->group[] = $id_field; |
| 224 | 224 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return ['id_objet', 'objet', objet_type($champ)]; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,21 +56,21 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if ( |
|
| 60 | - !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | - or array_key_exists($champ, $desc['field']) |
|
| 62 | - ) { |
|
| 63 | - return [$champ]; |
|
| 64 | - } |
|
| 65 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | - array_pop($decompose); |
|
| 68 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | - return $decompose; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return [$champ]; |
|
| 59 | + if ( |
|
| 60 | + !is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 61 | + or array_key_exists($champ, $desc['field']) |
|
| 62 | + ) { |
|
| 63 | + return [$champ]; |
|
| 64 | + } |
|
| 65 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 66 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 67 | + array_pop($decompose); |
|
| 68 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 69 | + return $decompose; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return [$champ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | |
@@ -100,23 +100,23 @@ discard block |
||
| 100 | 100 | * Alias de la table de jointure (Lx) |
| 101 | 101 | */ |
| 102 | 102 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 103 | - // les jointures minimales sont optimales : |
|
| 104 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | - $max = 1; |
|
| 107 | - $res = false; |
|
| 108 | - $milieu_exclus = ($col ?: []); |
|
| 109 | - while ($max <= $max_liens and !$res) { |
|
| 110 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | - $max++; |
|
| 112 | - } |
|
| 113 | - if (!$res) { |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - [$nom, $desc] = $depart; |
|
| 118 | - |
|
| 119 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 103 | + // les jointures minimales sont optimales : |
|
| 104 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 105 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 106 | + $max = 1; |
|
| 107 | + $res = false; |
|
| 108 | + $milieu_exclus = ($col ?: []); |
|
| 109 | + while ($max <= $max_liens and !$res) { |
|
| 110 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, [], $milieu_exclus, $max); |
|
| 111 | + $max++; |
|
| 112 | + } |
|
| 113 | + if (!$res) { |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + [$nom, $desc] = $depart; |
|
| 118 | + |
|
| 119 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -155,82 +155,82 @@ discard block |
||
| 155 | 155 | * Alias de la table de jointure (Lx) |
| 156 | 156 | */ |
| 157 | 157 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = [], $nom = '', $col = '', $echap = true) { |
| 158 | - $a = []; |
|
| 159 | - $j = null; |
|
| 160 | - $n = null; |
|
| 161 | - static $num = []; |
|
| 162 | - $id_table = ''; |
|
| 163 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 164 | - foreach ($res as $cle => $r) { |
|
| 165 | - [$d, $a, $j] = $r; |
|
| 166 | - if (!$id_table) { |
|
| 167 | - $id_table = $d; |
|
| 168 | - } |
|
| 169 | - $n = ++$cpt; |
|
| 170 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 171 | - [$j1, $j2, $obj, $type] = $j; |
|
| 172 | - // trouver de quel cote est (id_objet,objet) |
|
| 173 | - if ($j1 == "id_$obj") { |
|
| 174 | - $obj = "$id_table.$obj"; |
|
| 175 | - } else { |
|
| 176 | - $obj = "L$n.$obj"; |
|
| 177 | - } |
|
| 178 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 179 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 180 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 181 | - $boucle->where["JOIN-L$n"] = |
|
| 182 | - $echap ? |
|
| 183 | - ["'='","'$obj'","sql_quote('$type')"] |
|
| 184 | - : |
|
| 185 | - ['=',"$obj",sql_quote($type)]; |
|
| 186 | - $boucle->join["L$n"] = |
|
| 187 | - $echap ? |
|
| 188 | - ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 189 | - : |
|
| 190 | - [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 191 | - } else { |
|
| 192 | - $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 193 | - } |
|
| 194 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - // pas besoin de group by |
|
| 199 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 200 | - // si une seule jointure et sur une table avec primary key formee |
|
| 201 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 202 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 203 | - |
|
| 204 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 205 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // pas de group by |
|
| 209 | - // si une seule jointure |
|
| 210 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 211 | - if ( |
|
| 212 | - !$pk |
|
| 213 | - and (count($boucle->from) == 2) |
|
| 214 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 215 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 216 | - ) { |
|
| 217 | - $pk = true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 221 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 222 | - if (!$pk) { |
|
| 223 | - foreach ($groups as $id_prim) { |
|
| 224 | - $id_field = $nom . '.' . $id_prim; |
|
| 225 | - if (!in_array($id_field, $boucle->group)) { |
|
| 226 | - $boucle->group[] = $id_field; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $boucle->modificateur['lien'] = true; |
|
| 232 | - |
|
| 233 | - return "L$n"; |
|
| 158 | + $a = []; |
|
| 159 | + $j = null; |
|
| 160 | + $n = null; |
|
| 161 | + static $num = []; |
|
| 162 | + $id_table = ''; |
|
| 163 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 164 | + foreach ($res as $cle => $r) { |
|
| 165 | + [$d, $a, $j] = $r; |
|
| 166 | + if (!$id_table) { |
|
| 167 | + $id_table = $d; |
|
| 168 | + } |
|
| 169 | + $n = ++$cpt; |
|
| 170 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 171 | + [$j1, $j2, $obj, $type] = $j; |
|
| 172 | + // trouver de quel cote est (id_objet,objet) |
|
| 173 | + if ($j1 == "id_$obj") { |
|
| 174 | + $obj = "$id_table.$obj"; |
|
| 175 | + } else { |
|
| 176 | + $obj = "L$n.$obj"; |
|
| 177 | + } |
|
| 178 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 179 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 180 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 181 | + $boucle->where["JOIN-L$n"] = |
|
| 182 | + $echap ? |
|
| 183 | + ["'='","'$obj'","sql_quote('$type')"] |
|
| 184 | + : |
|
| 185 | + ['=',"$obj",sql_quote($type)]; |
|
| 186 | + $boucle->join["L$n"] = |
|
| 187 | + $echap ? |
|
| 188 | + ["'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')"] |
|
| 189 | + : |
|
| 190 | + [$id_table, $j2, $j1, "$obj=" . sql_quote($type)]; |
|
| 191 | + } else { |
|
| 192 | + $boucle->join["L$n"] = $echap ? ["'$id_table'", "'$j'"] : [$id_table, $j]; |
|
| 193 | + } |
|
| 194 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + // pas besoin de group by |
|
| 199 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 200 | + // si une seule jointure et sur une table avec primary key formee |
|
| 201 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 202 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 203 | + |
|
| 204 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 205 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // pas de group by |
|
| 209 | + // si une seule jointure |
|
| 210 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 211 | + if ( |
|
| 212 | + !$pk |
|
| 213 | + and (count($boucle->from) == 2) |
|
| 214 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 215 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 216 | + ) { |
|
| 217 | + $pk = true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 221 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 222 | + if (!$pk) { |
|
| 223 | + foreach ($groups as $id_prim) { |
|
| 224 | + $id_field = $nom . '.' . $id_prim; |
|
| 225 | + if (!in_array($id_field, $boucle->group)) { |
|
| 226 | + $boucle->group[] = $id_field; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $boucle->modificateur['lien'] = true; |
|
| 232 | + |
|
| 233 | + return "L$n"; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -245,19 +245,19 @@ discard block |
||
| 245 | 245 | * @return bool |
| 246 | 246 | */ |
| 247 | 247 | function nogroupby_if($depart, $arrivee, $col) { |
| 248 | - if ( |
|
| 249 | - empty($arrivee['key']['PRIMARY KEY']) |
|
| 250 | - or !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 251 | - or empty($depart['key']['PRIMARY KEY']) |
|
| 252 | - ) { |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 255 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 256 | - if (is_array($col)) { |
|
| 257 | - $col = implode(', *', $col); |
|
| 258 | - } // cas id_objet, objet |
|
| 259 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 260 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 248 | + if ( |
|
| 249 | + empty($arrivee['key']['PRIMARY KEY']) |
|
| 250 | + or !($pk = $arrivee['key']['PRIMARY KEY']) |
|
| 251 | + or empty($depart['key']['PRIMARY KEY']) |
|
| 252 | + ) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 256 | + if (is_array($col)) { |
|
| 257 | + $col = implode(', *', $col); |
|
| 258 | + } // cas id_objet, objet |
|
| 259 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 260 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -275,46 +275,46 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 277 | 277 | |
| 278 | - static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 278 | + static $nojoin = ['idx', 'maj', 'date', 'statut']; |
|
| 279 | 279 | |
| 280 | - // si cle primaire demandee, la privilegier |
|
| 281 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 282 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 283 | - } |
|
| 280 | + // si cle primaire demandee, la privilegier |
|
| 281 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 282 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - // les champs declares explicitement pour les jointures |
|
| 286 | - if (isset($desc['join'])) { |
|
| 287 | - return $desc['join']; |
|
| 288 | - } |
|
| 289 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 285 | + // les champs declares explicitement pour les jointures |
|
| 286 | + if (isset($desc['join'])) { |
|
| 287 | + return $desc['join']; |
|
| 288 | + } |
|
| 289 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 290 | 290 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 291 | 291 | |
| 292 | - // si pas de cle, c'est fichu |
|
| 293 | - if (!isset($desc['key'])) { |
|
| 294 | - return []; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // si cle primaire |
|
| 298 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 299 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // ici on se rabat sur les cles secondaires, |
|
| 303 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 304 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 305 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 306 | - |
|
| 307 | - $join = []; |
|
| 308 | - foreach ($desc['key'] as $v) { |
|
| 309 | - $join = split_key($v, $join); |
|
| 310 | - } |
|
| 311 | - foreach ($join as $k) { |
|
| 312 | - if (in_array($k, $nojoin)) { |
|
| 313 | - unset($join[$k]); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - return $join; |
|
| 292 | + // si pas de cle, c'est fichu |
|
| 293 | + if (!isset($desc['key'])) { |
|
| 294 | + return []; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // si cle primaire |
|
| 298 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 299 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // ici on se rabat sur les cles secondaires, |
|
| 303 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 304 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 305 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 306 | + |
|
| 307 | + $join = []; |
|
| 308 | + foreach ($desc['key'] as $v) { |
|
| 309 | + $join = split_key($v, $join); |
|
| 310 | + } |
|
| 311 | + foreach ($join as $k) { |
|
| 312 | + if (in_array($k, $nojoin)) { |
|
| 313 | + unset($join[$k]); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + return $join; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -325,14 +325,14 @@ discard block |
||
| 325 | 325 | * @return array |
| 326 | 326 | */ |
| 327 | 327 | function split_key($v, $join = []) { |
| 328 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 329 | - if (strpos($k, '(') !== false) { |
|
| 330 | - $k = explode('(', $k); |
|
| 331 | - $k = trim(reset($k)); |
|
| 332 | - } |
|
| 333 | - $join[$k] = $k; |
|
| 334 | - } |
|
| 335 | - return $join; |
|
| 328 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 329 | + if (strpos($k, '(') !== false) { |
|
| 330 | + $k = explode('(', $k); |
|
| 331 | + $k = trim(reset($k)); |
|
| 332 | + } |
|
| 333 | + $join[$k] = $k; |
|
| 334 | + } |
|
| 335 | + return $join; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -355,135 +355,135 @@ discard block |
||
| 355 | 355 | * @return array |
| 356 | 356 | */ |
| 357 | 357 | function calculer_chaine_jointures( |
| 358 | - &$boucle, |
|
| 359 | - $depart, |
|
| 360 | - $arrivee, |
|
| 361 | - $vu = [], |
|
| 362 | - $milieu_exclus = [], |
|
| 363 | - $max_liens = 5 |
|
| 358 | + &$boucle, |
|
| 359 | + $depart, |
|
| 360 | + $arrivee, |
|
| 361 | + $vu = [], |
|
| 362 | + $milieu_exclus = [], |
|
| 363 | + $max_liens = 5 |
|
| 364 | 364 | ) { |
| 365 | - static $trouver_table; |
|
| 366 | - if (!$trouver_table) { |
|
| 367 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - if (is_string($milieu_exclus)) { |
|
| 371 | - $milieu_exclus = [$milieu_exclus]; |
|
| 372 | - } |
|
| 373 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 374 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 375 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 376 | - $milieu_exclus[] = 'objet'; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - [$dnom, $ddesc] = $depart; |
|
| 380 | - [$anom, $adesc] = $arrivee; |
|
| 381 | - if (!count($vu)) { |
|
| 382 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 383 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $akeys = []; |
|
| 387 | - foreach ($adesc['key'] as $k) { |
|
| 388 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 389 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 393 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 394 | - |
|
| 395 | - // cles candidates au depart |
|
| 396 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 397 | - // enlever les cles dde depart exclues par l'appel |
|
| 398 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 399 | - |
|
| 400 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 401 | - |
|
| 402 | - if ($v) { |
|
| 403 | - return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 407 | - if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 408 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 409 | - // id_objet,objet |
|
| 410 | - // si oui on la prend |
|
| 411 | - foreach ($akeys as $key) { |
|
| 412 | - $v = decompose_champ_id_objet($key); |
|
| 413 | - if (is_array($v)) { |
|
| 414 | - $objet = array_shift($v); // objet,'article' |
|
| 415 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 416 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 417 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } else { |
|
| 421 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 422 | - // id_objet,objet a l'arrivee |
|
| 423 | - // si oui on la prend |
|
| 424 | - foreach ($keys as $key) { |
|
| 425 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 426 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 427 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 428 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 429 | - return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 435 | - if ($max_liens <= 1) { |
|
| 436 | - return []; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // sinon essayer de passer par une autre table |
|
| 440 | - $new = $vu; |
|
| 441 | - foreach ($boucle->jointures as $v) { |
|
| 442 | - if ( |
|
| 443 | - $v |
|
| 444 | - and !in_array($v, $vu) |
|
| 445 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 446 | - and !in_array($def['table_sql'], $vu) |
|
| 447 | - ) { |
|
| 448 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 449 | - // ie la cle de la jointure precedente |
|
| 450 | - $test_cles = $milieu_exclus; |
|
| 451 | - $new[] = $v; |
|
| 452 | - $max_iter = 50; // securite |
|
| 453 | - while ( |
|
| 454 | - count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 455 | - $boucle, |
|
| 456 | - $depart, |
|
| 457 | - [$v, $def], |
|
| 458 | - $vu, |
|
| 459 | - $test_cles, |
|
| 460 | - 1 |
|
| 461 | - )) |
|
| 462 | - and $max_iter-- |
|
| 463 | - ) { |
|
| 464 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 465 | - $milieu = end($jointure_directe_possible); |
|
| 466 | - $exclure_fin = $milieu_exclus; |
|
| 467 | - if (is_string($milieu)) { |
|
| 468 | - $exclure_fin[] = $milieu; |
|
| 469 | - $test_cles[] = $milieu; |
|
| 470 | - } else { |
|
| 471 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 472 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 473 | - } |
|
| 474 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 475 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 476 | - $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 477 | - if ($r) { |
|
| 478 | - array_unshift($r, $jointure_directe_possible); |
|
| 479 | - |
|
| 480 | - return $r; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return []; |
|
| 365 | + static $trouver_table; |
|
| 366 | + if (!$trouver_table) { |
|
| 367 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + if (is_string($milieu_exclus)) { |
|
| 371 | + $milieu_exclus = [$milieu_exclus]; |
|
| 372 | + } |
|
| 373 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 374 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 375 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 376 | + $milieu_exclus[] = 'objet'; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + [$dnom, $ddesc] = $depart; |
|
| 380 | + [$anom, $adesc] = $arrivee; |
|
| 381 | + if (!count($vu)) { |
|
| 382 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 383 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $akeys = []; |
|
| 387 | + foreach ($adesc['key'] as $k) { |
|
| 388 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 389 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 393 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 394 | + |
|
| 395 | + // cles candidates au depart |
|
| 396 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 397 | + // enlever les cles dde depart exclues par l'appel |
|
| 398 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 399 | + |
|
| 400 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 401 | + |
|
| 402 | + if ($v) { |
|
| 403 | + return [[$dnom, [$adesc['table'], $adesc], array_shift($v)]]; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 407 | + if (count(array_intersect(['id_objet', 'objet'], $keys)) == 2) { |
|
| 408 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 409 | + // id_objet,objet |
|
| 410 | + // si oui on la prend |
|
| 411 | + foreach ($akeys as $key) { |
|
| 412 | + $v = decompose_champ_id_objet($key); |
|
| 413 | + if (is_array($v)) { |
|
| 414 | + $objet = array_shift($v); // objet,'article' |
|
| 415 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 416 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 417 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } else { |
|
| 421 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 422 | + // id_objet,objet a l'arrivee |
|
| 423 | + // si oui on la prend |
|
| 424 | + foreach ($keys as $key) { |
|
| 425 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 426 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 427 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 428 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 429 | + return [[$dnom, [$adesc['table'], $adesc], $v]]; |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 435 | + if ($max_liens <= 1) { |
|
| 436 | + return []; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // sinon essayer de passer par une autre table |
|
| 440 | + $new = $vu; |
|
| 441 | + foreach ($boucle->jointures as $v) { |
|
| 442 | + if ( |
|
| 443 | + $v |
|
| 444 | + and !in_array($v, $vu) |
|
| 445 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 446 | + and !in_array($def['table_sql'], $vu) |
|
| 447 | + ) { |
|
| 448 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 449 | + // ie la cle de la jointure precedente |
|
| 450 | + $test_cles = $milieu_exclus; |
|
| 451 | + $new[] = $v; |
|
| 452 | + $max_iter = 50; // securite |
|
| 453 | + while ( |
|
| 454 | + count($jointure_directe_possible = calculer_chaine_jointures( |
|
| 455 | + $boucle, |
|
| 456 | + $depart, |
|
| 457 | + [$v, $def], |
|
| 458 | + $vu, |
|
| 459 | + $test_cles, |
|
| 460 | + 1 |
|
| 461 | + )) |
|
| 462 | + and $max_iter-- |
|
| 463 | + ) { |
|
| 464 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 465 | + $milieu = end($jointure_directe_possible); |
|
| 466 | + $exclure_fin = $milieu_exclus; |
|
| 467 | + if (is_string($milieu)) { |
|
| 468 | + $exclure_fin[] = $milieu; |
|
| 469 | + $test_cles[] = $milieu; |
|
| 470 | + } else { |
|
| 471 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 472 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 473 | + } |
|
| 474 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 475 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 476 | + $r = calculer_chaine_jointures($boucle, [$v, $def], $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 477 | + if ($r) { |
|
| 478 | + array_unshift($r, $jointure_directe_possible); |
|
| 479 | + |
|
| 480 | + return $r; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return []; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -494,18 +494,18 @@ discard block |
||
| 494 | 494 | * @return array |
| 495 | 495 | */ |
| 496 | 496 | function trouver_cles_table($keys) { |
| 497 | - $res = []; |
|
| 498 | - foreach ($keys as $v) { |
|
| 499 | - if (!strpos($v, ',')) { |
|
| 500 | - $res[$v] = 1; |
|
| 501 | - } else { |
|
| 502 | - foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 503 | - $res[$k] = 1; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - return array_keys($res); |
|
| 497 | + $res = []; |
|
| 498 | + foreach ($keys as $v) { |
|
| 499 | + if (!strpos($v, ',')) { |
|
| 500 | + $res[$v] = 1; |
|
| 501 | + } else { |
|
| 502 | + foreach (preg_split('/\s*,\s*/', $v) as $k) { |
|
| 503 | + $res[$k] = 1; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + return array_keys($res); |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | |
@@ -532,34 +532,34 @@ discard block |
||
| 532 | 532 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 533 | 533 | */ |
| 534 | 534 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 535 | - static $trouver_table = ''; |
|
| 536 | - if (!$trouver_table) { |
|
| 537 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - if (!is_array($cle)) { |
|
| 541 | - $cle = [$cle]; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - foreach ($tables as $k => $table) { |
|
| 545 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 546 | - if ( |
|
| 547 | - isset($desc['field']) |
|
| 548 | - // verifier que toutes les cles cherchees sont la |
|
| 549 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 550 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 551 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 552 | - ) { |
|
| 553 | - return [ |
|
| 554 | - 'desc' => $desc, |
|
| 555 | - 'table' => $desc['table'], |
|
| 556 | - 'alias' => $k, |
|
| 557 | - ]; |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return false; |
|
| 535 | + static $trouver_table = ''; |
|
| 536 | + if (!$trouver_table) { |
|
| 537 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + if (!is_array($cle)) { |
|
| 541 | + $cle = [$cle]; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + foreach ($tables as $k => $table) { |
|
| 545 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 546 | + if ( |
|
| 547 | + isset($desc['field']) |
|
| 548 | + // verifier que toutes les cles cherchees sont la |
|
| 549 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 550 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 551 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 552 | + ) { |
|
| 553 | + return [ |
|
| 554 | + 'desc' => $desc, |
|
| 555 | + 'table' => $desc['table'], |
|
| 556 | + 'alias' => $k, |
|
| 557 | + ]; |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return false; |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
@@ -585,52 +585,52 @@ discard block |
||
| 585 | 585 | */ |
| 586 | 586 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 587 | 587 | |
| 588 | - // support de la recherche multi champ : |
|
| 589 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 590 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 591 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 592 | - if (!is_array($cle)) { |
|
| 593 | - $cle = [$cle]; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 597 | - return [$infos['table'], $infos['desc'], $cle]; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - // au premier coup, on essaye de decomposer, si possible |
|
| 601 | - if ( |
|
| 602 | - count($cle) == 1 |
|
| 603 | - and $c = reset($cle) |
|
| 604 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 605 | - ) { |
|
| 606 | - $desc = $boucle->show; |
|
| 607 | - |
|
| 608 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 609 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 610 | - if (isset($desc['field'][$c])) { |
|
| 611 | - $cle = []; |
|
| 612 | - $cle[] = array_shift($decompose); // id_objet |
|
| 613 | - $cle[] = array_shift($decompose); // objet |
|
| 614 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 615 | - } |
|
| 616 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 617 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 618 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 619 | - else { |
|
| 620 | - $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 621 | - foreach ($depart as $d) { |
|
| 622 | - $cle = []; |
|
| 623 | - $cle[] = array_shift($decompose); // id_objet |
|
| 624 | - $cle[] = array_shift($decompose); // objet |
|
| 625 | - $cle[] = $d; |
|
| 626 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 627 | - return $ext; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - return ''; |
|
| 588 | + // support de la recherche multi champ : |
|
| 589 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 590 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 591 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 592 | + if (!is_array($cle)) { |
|
| 593 | + $cle = [$cle]; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 597 | + return [$infos['table'], $infos['desc'], $cle]; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + // au premier coup, on essaye de decomposer, si possible |
|
| 601 | + if ( |
|
| 602 | + count($cle) == 1 |
|
| 603 | + and $c = reset($cle) |
|
| 604 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 605 | + ) { |
|
| 606 | + $desc = $boucle->show; |
|
| 607 | + |
|
| 608 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 609 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 610 | + if (isset($desc['field'][$c])) { |
|
| 611 | + $cle = []; |
|
| 612 | + $cle[] = array_shift($decompose); // id_objet |
|
| 613 | + $cle[] = array_shift($decompose); // objet |
|
| 614 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 615 | + } |
|
| 616 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 617 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 618 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 619 | + else { |
|
| 620 | + $depart = liste_champs_jointures(($desc['table'] ?? ''), $desc); |
|
| 621 | + foreach ($depart as $d) { |
|
| 622 | + $cle = []; |
|
| 623 | + $cle[] = array_shift($decompose); // id_objet |
|
| 624 | + $cle[] = array_shift($decompose); // objet |
|
| 625 | + $cle[] = $d; |
|
| 626 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 627 | + return $ext; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + return ''; |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | /** |
@@ -662,21 +662,21 @@ discard block |
||
| 662 | 662 | * @return string |
| 663 | 663 | */ |
| 664 | 664 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 665 | - if ($jointures === false) { |
|
| 666 | - $jointures = $boucle->jointures; |
|
| 667 | - } |
|
| 668 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 669 | - // mais pas poour construire la jointure ensuite |
|
| 670 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 671 | - if ($arrivee) { |
|
| 672 | - $desc = $boucle->show; |
|
| 673 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 674 | - $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 675 | - if ($cle) { |
|
| 676 | - return $cle; |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 680 | - |
|
| 681 | - return ''; |
|
| 665 | + if ($jointures === false) { |
|
| 666 | + $jointures = $boucle->jointures; |
|
| 667 | + } |
|
| 668 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 669 | + // mais pas poour construire la jointure ensuite |
|
| 670 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 671 | + if ($arrivee) { |
|
| 672 | + $desc = $boucle->show; |
|
| 673 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 674 | + $cle = calculer_jointure($boucle, [$desc['id_table'], $desc], $arrivee, '', $cond); |
|
| 675 | + if ($cle) { |
|
| 676 | + return $cle; |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 680 | + |
|
| 681 | + return ''; |
|
| 682 | 682 | } |
@@ -920,8 +920,7 @@ |
||
| 920 | 920 | if (isset($boucles[$idb]->descr['sourcefile'])) { |
| 921 | 921 | $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
| 922 | 922 | } |
| 923 | - } |
|
| 924 | - else { |
|
| 923 | + } else { |
|
| 925 | 924 | $descr = []; |
| 926 | 925 | } |
| 927 | 926 | } |
@@ -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 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -58,92 +58,92 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | function argumenter_inclure( |
| 61 | - $params, |
|
| 62 | - $rejet_filtres, |
|
| 63 | - $p, |
|
| 64 | - &$boucles, |
|
| 65 | - $id_boucle, |
|
| 66 | - $echap = true, |
|
| 67 | - $lang = '', |
|
| 68 | - $fond1 = false |
|
| 61 | + $params, |
|
| 62 | + $rejet_filtres, |
|
| 63 | + $p, |
|
| 64 | + &$boucles, |
|
| 65 | + $id_boucle, |
|
| 66 | + $echap = true, |
|
| 67 | + $lang = '', |
|
| 68 | + $fond1 = false |
|
| 69 | 69 | ) { |
| 70 | - $l = []; |
|
| 71 | - $erreur_p_i_i = ''; |
|
| 72 | - if (!is_array($params)) { |
|
| 73 | - return $l; |
|
| 74 | - } |
|
| 75 | - foreach ($params as $k => $couple) { |
|
| 76 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 77 | - $filtre = array_shift($couple); |
|
| 78 | - if ($filtre) { |
|
| 79 | - break; |
|
| 80 | - } |
|
| 81 | - foreach ($couple as $n => $val) { |
|
| 82 | - $var = $val[0]; |
|
| 83 | - if ($var->type != 'texte') { |
|
| 84 | - if ($n or $k or $fond1) { |
|
| 85 | - $erreur_p_i_i = [ |
|
| 86 | - 'zbug_parametres_inclus_incorrects', |
|
| 87 | - ['param' => $var->nom_champ] |
|
| 88 | - ]; |
|
| 89 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 90 | - break; |
|
| 91 | - } else { |
|
| 92 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 93 | - } |
|
| 94 | - } else { |
|
| 95 | - preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 96 | - $m = array_pad($m, 3, null); |
|
| 97 | - $var = $m[1]; |
|
| 98 | - $auto = false; |
|
| 70 | + $l = []; |
|
| 71 | + $erreur_p_i_i = ''; |
|
| 72 | + if (!is_array($params)) { |
|
| 73 | + return $l; |
|
| 74 | + } |
|
| 75 | + foreach ($params as $k => $couple) { |
|
| 76 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 77 | + $filtre = array_shift($couple); |
|
| 78 | + if ($filtre) { |
|
| 79 | + break; |
|
| 80 | + } |
|
| 81 | + foreach ($couple as $n => $val) { |
|
| 82 | + $var = $val[0]; |
|
| 83 | + if ($var->type != 'texte') { |
|
| 84 | + if ($n or $k or $fond1) { |
|
| 85 | + $erreur_p_i_i = [ |
|
| 86 | + 'zbug_parametres_inclus_incorrects', |
|
| 87 | + ['param' => $var->nom_champ] |
|
| 88 | + ]; |
|
| 89 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 90 | + break; |
|
| 91 | + } else { |
|
| 92 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 93 | + } |
|
| 94 | + } else { |
|
| 95 | + preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 96 | + $m = array_pad($m, 3, null); |
|
| 97 | + $var = $m[1]; |
|
| 98 | + $auto = false; |
|
| 99 | 99 | ; |
| 100 | - if ($m[2]) { |
|
| 101 | - $v = $m[3]; |
|
| 102 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 103 | - $v = $m[1]; |
|
| 104 | - } |
|
| 105 | - $val[0] = new Texte(); |
|
| 106 | - $val[0]->texte = $v; |
|
| 107 | - } elseif ($k or $n or $fond1) { |
|
| 108 | - $auto = true; |
|
| 109 | - } else { |
|
| 110 | - $var = 1; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if ($var == 'lang') { |
|
| 114 | - $lang = !$auto |
|
| 115 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 116 | - : '$GLOBALS["spip_lang"]'; |
|
| 117 | - } else { |
|
| 118 | - $val = $auto |
|
| 119 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 120 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 121 | - if ($var !== 1) { |
|
| 122 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 123 | - . $val . ($echap ? ") . '" : ' '); |
|
| 124 | - } else { |
|
| 125 | - $val = $echap ? "'.$val.'" : $val; |
|
| 126 | - } |
|
| 127 | - $l[$var] = $val; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - if ($erreur_p_i_i) { |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 135 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 136 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 137 | - // sauf si on n'en veut pas |
|
| 138 | - if ($lang === false) { |
|
| 139 | - return $l; |
|
| 140 | - } |
|
| 141 | - if (!$lang) { |
|
| 142 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 143 | - } |
|
| 144 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | - |
|
| 146 | - return $l; |
|
| 100 | + if ($m[2]) { |
|
| 101 | + $v = $m[3]; |
|
| 102 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 103 | + $v = $m[1]; |
|
| 104 | + } |
|
| 105 | + $val[0] = new Texte(); |
|
| 106 | + $val[0]->texte = $v; |
|
| 107 | + } elseif ($k or $n or $fond1) { |
|
| 108 | + $auto = true; |
|
| 109 | + } else { |
|
| 110 | + $var = 1; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if ($var == 'lang') { |
|
| 114 | + $lang = !$auto |
|
| 115 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 116 | + : '$GLOBALS["spip_lang"]'; |
|
| 117 | + } else { |
|
| 118 | + $val = $auto |
|
| 119 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 120 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 121 | + if ($var !== 1) { |
|
| 122 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 123 | + . $val . ($echap ? ") . '" : ' '); |
|
| 124 | + } else { |
|
| 125 | + $val = $echap ? "'.$val.'" : $val; |
|
| 126 | + } |
|
| 127 | + $l[$var] = $val; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + if ($erreur_p_i_i) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 136 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 137 | + // sauf si on n'en veut pas |
|
| 138 | + if ($lang === false) { |
|
| 139 | + return $l; |
|
| 140 | + } |
|
| 141 | + if (!$lang) { |
|
| 142 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 143 | + } |
|
| 144 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | + |
|
| 146 | + return $l; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -167,84 +167,84 @@ discard block |
||
| 167 | 167 | **/ |
| 168 | 168 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 169 | 169 | |
| 170 | - $_options = []; |
|
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | - } else { |
|
| 176 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | - $fichier = $r[1]; |
|
| 179 | - } else { |
|
| 180 | - $fichier = ''; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - if (!$code or $code === '""' or $code === "''") { |
|
| 184 | - $trace = $p->fonctions; |
|
| 185 | - while ( |
|
| 186 | - is_array($trace) |
|
| 187 | - and $trace = array_filter($trace) |
|
| 188 | - and count($trace) == 1 |
|
| 189 | - ) { |
|
| 190 | - $trace = reset($trace); |
|
| 191 | - } |
|
| 192 | - $erreur_p_i_i = [ |
|
| 193 | - 'zbug_parametres_inclus_incorrects', |
|
| 194 | - ['param' => print_r($trace, true)] |
|
| 195 | - ]; |
|
| 196 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | - |
|
| 198 | - return "''"; |
|
| 199 | - } |
|
| 200 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | - |
|
| 202 | - if (is_array($_contexte)) { |
|
| 203 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | - unset($_contexte['env']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // noter les doublons dans l'appel a public.php |
|
| 209 | - if (isset($_contexte['doublons'])) { |
|
| 210 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | - $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | - unset($_contexte['ajax']); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $_contexte = join(",\n\t", $_contexte); |
|
| 219 | - } else { |
|
| 220 | - return false; |
|
| 221 | - } // j'aurais voulu toucher le fond ... |
|
| 222 | - |
|
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | - |
|
| 225 | - if ($env) { |
|
| 226 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | - } else { |
|
| 233 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | - if ($ajax) { |
|
| 235 | - $_options[] = $ajax; |
|
| 236 | - } |
|
| 237 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | - $code = 'echo ' . sprintf( |
|
| 239 | - CODE_RECUPERER_FOND, |
|
| 240 | - $code, |
|
| 241 | - $contexte, |
|
| 242 | - implode(',', $_options), |
|
| 243 | - "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | - ) . ';'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 170 | + $_options = []; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | + } else { |
|
| 176 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | + $fichier = $r[1]; |
|
| 179 | + } else { |
|
| 180 | + $fichier = ''; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + if (!$code or $code === '""' or $code === "''") { |
|
| 184 | + $trace = $p->fonctions; |
|
| 185 | + while ( |
|
| 186 | + is_array($trace) |
|
| 187 | + and $trace = array_filter($trace) |
|
| 188 | + and count($trace) == 1 |
|
| 189 | + ) { |
|
| 190 | + $trace = reset($trace); |
|
| 191 | + } |
|
| 192 | + $erreur_p_i_i = [ |
|
| 193 | + 'zbug_parametres_inclus_incorrects', |
|
| 194 | + ['param' => print_r($trace, true)] |
|
| 195 | + ]; |
|
| 196 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | + |
|
| 198 | + return "''"; |
|
| 199 | + } |
|
| 200 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | + |
|
| 202 | + if (is_array($_contexte)) { |
|
| 203 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | + unset($_contexte['env']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // noter les doublons dans l'appel a public.php |
|
| 209 | + if (isset($_contexte['doublons'])) { |
|
| 210 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | + $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | + unset($_contexte['ajax']); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $_contexte = join(",\n\t", $_contexte); |
|
| 219 | + } else { |
|
| 220 | + return false; |
|
| 221 | + } // j'aurais voulu toucher le fond ... |
|
| 222 | + |
|
| 223 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | + |
|
| 225 | + if ($env) { |
|
| 226 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | + } else { |
|
| 233 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | + if ($ajax) { |
|
| 235 | + $_options[] = $ajax; |
|
| 236 | + } |
|
| 237 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | + $code = 'echo ' . sprintf( |
|
| 239 | + CODE_RECUPERER_FOND, |
|
| 240 | + $code, |
|
| 241 | + $contexte, |
|
| 242 | + implode(',', $_options), |
|
| 243 | + "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | + ) . ';'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 263 | 263 | */ |
| 264 | 264 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 265 | - /* |
|
| 265 | + /* |
|
| 266 | 266 | $show['statut'][] = array( |
| 267 | 267 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 268 | 268 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -286,74 +286,74 @@ discard block |
||
| 286 | 286 | champstatut est alors le champ statut sur la tablen |
| 287 | 287 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 288 | 288 | */ |
| 289 | - $id_table = $boucle->id_table; |
|
| 290 | - $show = $boucle->show; |
|
| 291 | - if (isset($show['statut']) and $show['statut']) { |
|
| 292 | - foreach ($show['statut'] as $k => $s) { |
|
| 293 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | - $filtrer = true; |
|
| 295 | - if (isset($s['exception'])) { |
|
| 296 | - foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | - $filtrer = false; |
|
| 299 | - break; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($filtrer) { |
|
| 305 | - if (is_array($s['champ'])) { |
|
| 306 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | - $jointures = []; |
|
| 308 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | - foreach ($s['champ'] as $j) { |
|
| 312 | - $id = reset($j); |
|
| 313 | - $def = $trouver_table($id); |
|
| 314 | - $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | - } |
|
| 316 | - $jointures[0][0] = $id_table; |
|
| 317 | - if (!array_search($id, $boucle->from)) { |
|
| 318 | - include_spip('public/jointures'); |
|
| 319 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | - } |
|
| 321 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | - $id = array_search($id, $boucle->from); |
|
| 323 | - } else { |
|
| 324 | - $id = $id_table; |
|
| 325 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | - } |
|
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 328 | - |
|
| 329 | - $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | - include_spip('public/quete'); |
|
| 331 | - if ( |
|
| 332 | - isset($s['post_date']) and $s['post_date'] |
|
| 333 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | - ) { |
|
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | - array_unshift( |
|
| 337 | - $boucle->where, |
|
| 338 | - $echapper ? |
|
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | - : |
|
| 341 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - array_unshift( |
|
| 345 | - $boucle->where, |
|
| 346 | - $echapper ? |
|
| 347 | - "\nquete_condition_statut('$mstatut'," |
|
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | - : |
|
| 352 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 289 | + $id_table = $boucle->id_table; |
|
| 290 | + $show = $boucle->show; |
|
| 291 | + if (isset($show['statut']) and $show['statut']) { |
|
| 292 | + foreach ($show['statut'] as $k => $s) { |
|
| 293 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | + $filtrer = true; |
|
| 295 | + if (isset($s['exception'])) { |
|
| 296 | + foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | + $filtrer = false; |
|
| 299 | + break; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($filtrer) { |
|
| 305 | + if (is_array($s['champ'])) { |
|
| 306 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | + $jointures = []; |
|
| 308 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | + foreach ($s['champ'] as $j) { |
|
| 312 | + $id = reset($j); |
|
| 313 | + $def = $trouver_table($id); |
|
| 314 | + $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | + } |
|
| 316 | + $jointures[0][0] = $id_table; |
|
| 317 | + if (!array_search($id, $boucle->from)) { |
|
| 318 | + include_spip('public/jointures'); |
|
| 319 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | + } |
|
| 321 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | + $id = array_search($id, $boucle->from); |
|
| 323 | + } else { |
|
| 324 | + $id = $id_table; |
|
| 325 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | + } |
|
| 327 | + $mstatut = $id . '.' . $statut; |
|
| 328 | + |
|
| 329 | + $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | + include_spip('public/quete'); |
|
| 331 | + if ( |
|
| 332 | + isset($s['post_date']) and $s['post_date'] |
|
| 333 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | + ) { |
|
| 335 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | + array_unshift( |
|
| 337 | + $boucle->where, |
|
| 338 | + $echapper ? |
|
| 339 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | + : |
|
| 341 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + array_unshift( |
|
| 345 | + $boucle->where, |
|
| 346 | + $echapper ? |
|
| 347 | + "\nquete_condition_statut('$mstatut'," |
|
| 348 | + . _q($s['previsu']) . ',' |
|
| 349 | + . _q($s['publie']) . ',' |
|
| 350 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | + : |
|
| 352 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,29 +372,29 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | function calculer_boucle($id_boucle, &$boucles) { |
| 374 | 374 | |
| 375 | - $boucle = &$boucles[$id_boucle]; |
|
| 376 | - instituer_boucle($boucle); |
|
| 377 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | - |
|
| 379 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | - // mais pas tous, sinon ca pete. |
|
| 381 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | - $trace = ''; |
|
| 383 | - } else { |
|
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | - $trace = " |
|
| 375 | + $boucle = &$boucles[$id_boucle]; |
|
| 376 | + instituer_boucle($boucle); |
|
| 377 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | + |
|
| 379 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | + // mais pas tous, sinon ca pete. |
|
| 381 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | + $trace = ''; |
|
| 383 | + } else { |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | + $trace = " |
|
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | 391 | $_trace" . '[] = $t0; |
| 392 | 392 | }'; |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 395 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | * Code PHP compilé de la boucle récursive |
| 418 | 418 | **/ |
| 419 | 419 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 420 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | - |
|
| 422 | - return |
|
| 423 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | - . $trace |
|
| 428 | - . "\n\treturn \$t0;"; |
|
| 420 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | + |
|
| 422 | + return |
|
| 423 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | + . $trace |
|
| 428 | + . "\n\treturn \$t0;"; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -478,174 +478,174 @@ discard block |
||
| 478 | 478 | **/ |
| 479 | 479 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 480 | 480 | |
| 481 | - $code_sep = null; |
|
| 482 | - $boucle = &$boucles[$id_boucle]; |
|
| 483 | - $return = $boucle->return; |
|
| 484 | - $type_boucle = $boucle->type_requete; |
|
| 485 | - $primary = $boucle->primary; |
|
| 486 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 487 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 488 | - $corps = ''; |
|
| 489 | - |
|
| 490 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 491 | - // et puis faire un [] plutot qu'un "','." |
|
| 492 | - if ($boucle->doublons) { |
|
| 493 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 494 | - index_pile($id_boucle, $primary, $boucles) |
|
| 495 | - . "; // doublons\n"; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // La boucle doit-elle selectionner la langue ? |
|
| 499 | - // - par defaut, les boucles suivantes le font |
|
| 500 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 501 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 502 | - if ( |
|
| 503 | - !$constant && $boucle->lang_select != 'non' && |
|
| 504 | - (($boucle->lang_select == 'oui') || |
|
| 505 | - in_array($type_boucle, [ |
|
| 506 | - 'articles', |
|
| 507 | - 'rubriques', |
|
| 508 | - 'hierarchie', |
|
| 509 | - 'breves' |
|
| 510 | - ])) |
|
| 511 | - ) { |
|
| 512 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 513 | - // afin que le corps de boucle affecte la globale directement |
|
| 514 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 515 | - $fin_lang = "lang_select();\n\t"; |
|
| 516 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 517 | - |
|
| 518 | - $corps .= |
|
| 519 | - "\n\t\tlang_select_public(" |
|
| 520 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 521 | - . ", '" . $boucle->lang_select . "'" |
|
| 522 | - . (in_array($type_boucle, [ |
|
| 523 | - 'articles', |
|
| 524 | - 'rubriques', |
|
| 525 | - 'hierarchie', |
|
| 526 | - 'breves' |
|
| 527 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 528 | - . ');'; |
|
| 529 | - } else { |
|
| 530 | - $init_lang = ''; |
|
| 531 | - $fin_lang = ''; |
|
| 532 | - $fin_lang_select_public = ''; |
|
| 533 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 534 | - if ( |
|
| 535 | - strpos($return, '?php') === false |
|
| 536 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 537 | - ) { |
|
| 538 | - $i = 1; |
|
| 539 | - foreach ($r[1] as $t) { |
|
| 540 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 541 | - $return = str_replace($t, "\$l$i", $return); |
|
| 542 | - $i++; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // gestion optimale des separateurs et des boucles constantes |
|
| 548 | - if (is_countable($boucle->separateur) ? count($boucle->separateur) : 0) { |
|
| 549 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - $corps .= |
|
| 553 | - ((!$boucle->separateur) ? |
|
| 554 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 555 | - (($return === "''") ? '' : |
|
| 556 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 557 | - ("\n\t\t\$t1 " . |
|
| 558 | - ((strpos($return, '$t1.') === 0) ? |
|
| 559 | - ('.=' . substr($return, 4)) : |
|
| 560 | - ('= ' . $return)) . |
|
| 561 | - ";\n\t\t" . |
|
| 562 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 563 | - |
|
| 564 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 565 | - // souhaite invalider ces elements |
|
| 566 | - if (!$constant and $primary) { |
|
| 567 | - include_spip('inc/invalideur'); |
|
| 568 | - $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // gerer le compteur de boucle |
|
| 572 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 573 | - |
|
| 574 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 575 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 576 | - . $boucle->partie |
|
| 577 | - . $corps; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - // depiler la lang de la boucle si besoin |
|
| 581 | - $corps .= $fin_lang_select_public; |
|
| 582 | - |
|
| 583 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 584 | - |
|
| 585 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 586 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 587 | - if (!$boucle->numrows) { |
|
| 588 | - return "\n\t\$t0 = '';"; |
|
| 589 | - } else { |
|
| 590 | - $corps = ''; |
|
| 591 | - } |
|
| 592 | - } else { |
|
| 593 | - $boucle->numrows = true; |
|
| 594 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 595 | - } |
|
| 596 | - } else { |
|
| 597 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $count = ''; |
|
| 601 | - if (!$boucle->select) { |
|
| 602 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 603 | - $count = '1'; |
|
| 604 | - } else { |
|
| 605 | - $count = 'count(*)'; |
|
| 606 | - } |
|
| 607 | - $boucles[$id_boucle]->select[] = $count; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - if ($flag_cpt) { |
|
| 611 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 612 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 613 | - } else { |
|
| 614 | - $nums = ''; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 618 | - $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 619 | - . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 620 | - . $boucle->mode_partie |
|
| 621 | - . "\n\t"; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // Ne calculer la requete que maintenant |
|
| 625 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 626 | - |
|
| 627 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 628 | - ? ("\n\t$init = array();") : '') |
|
| 629 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 630 | - |
|
| 631 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 632 | - |
|
| 633 | - $a = sprintf( |
|
| 634 | - CODE_CORPS_BOUCLE, |
|
| 635 | - $init, |
|
| 636 | - $boucle->iterateur, |
|
| 637 | - '$command', |
|
| 638 | - $contexte, |
|
| 639 | - $nums, |
|
| 640 | - $init_lang, |
|
| 641 | - $corps, |
|
| 642 | - $fin_lang, |
|
| 643 | - $trace, |
|
| 644 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 645 | - ); |
|
| 481 | + $code_sep = null; |
|
| 482 | + $boucle = &$boucles[$id_boucle]; |
|
| 483 | + $return = $boucle->return; |
|
| 484 | + $type_boucle = $boucle->type_requete; |
|
| 485 | + $primary = $boucle->primary; |
|
| 486 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 487 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 488 | + $corps = ''; |
|
| 489 | + |
|
| 490 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 491 | + // et puis faire un [] plutot qu'un "','." |
|
| 492 | + if ($boucle->doublons) { |
|
| 493 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 494 | + index_pile($id_boucle, $primary, $boucles) |
|
| 495 | + . "; // doublons\n"; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + // La boucle doit-elle selectionner la langue ? |
|
| 499 | + // - par defaut, les boucles suivantes le font |
|
| 500 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 501 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 502 | + if ( |
|
| 503 | + !$constant && $boucle->lang_select != 'non' && |
|
| 504 | + (($boucle->lang_select == 'oui') || |
|
| 505 | + in_array($type_boucle, [ |
|
| 506 | + 'articles', |
|
| 507 | + 'rubriques', |
|
| 508 | + 'hierarchie', |
|
| 509 | + 'breves' |
|
| 510 | + ])) |
|
| 511 | + ) { |
|
| 512 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 513 | + // afin que le corps de boucle affecte la globale directement |
|
| 514 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 515 | + $fin_lang = "lang_select();\n\t"; |
|
| 516 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 517 | + |
|
| 518 | + $corps .= |
|
| 519 | + "\n\t\tlang_select_public(" |
|
| 520 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 521 | + . ", '" . $boucle->lang_select . "'" |
|
| 522 | + . (in_array($type_boucle, [ |
|
| 523 | + 'articles', |
|
| 524 | + 'rubriques', |
|
| 525 | + 'hierarchie', |
|
| 526 | + 'breves' |
|
| 527 | + ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 528 | + . ');'; |
|
| 529 | + } else { |
|
| 530 | + $init_lang = ''; |
|
| 531 | + $fin_lang = ''; |
|
| 532 | + $fin_lang_select_public = ''; |
|
| 533 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 534 | + if ( |
|
| 535 | + strpos($return, '?php') === false |
|
| 536 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 537 | + ) { |
|
| 538 | + $i = 1; |
|
| 539 | + foreach ($r[1] as $t) { |
|
| 540 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 541 | + $return = str_replace($t, "\$l$i", $return); |
|
| 542 | + $i++; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // gestion optimale des separateurs et des boucles constantes |
|
| 548 | + if (is_countable($boucle->separateur) ? count($boucle->separateur) : 0) { |
|
| 549 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + $corps .= |
|
| 553 | + ((!$boucle->separateur) ? |
|
| 554 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 555 | + (($return === "''") ? '' : |
|
| 556 | + ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 557 | + ("\n\t\t\$t1 " . |
|
| 558 | + ((strpos($return, '$t1.') === 0) ? |
|
| 559 | + ('.=' . substr($return, 4)) : |
|
| 560 | + ('= ' . $return)) . |
|
| 561 | + ";\n\t\t" . |
|
| 562 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 563 | + |
|
| 564 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 565 | + // souhaite invalider ces elements |
|
| 566 | + if (!$constant and $primary) { |
|
| 567 | + include_spip('inc/invalideur'); |
|
| 568 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // gerer le compteur de boucle |
|
| 572 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 573 | + |
|
| 574 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 575 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 576 | + . $boucle->partie |
|
| 577 | + . $corps; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + // depiler la lang de la boucle si besoin |
|
| 581 | + $corps .= $fin_lang_select_public; |
|
| 582 | + |
|
| 583 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 584 | + |
|
| 585 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 586 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 587 | + if (!$boucle->numrows) { |
|
| 588 | + return "\n\t\$t0 = '';"; |
|
| 589 | + } else { |
|
| 590 | + $corps = ''; |
|
| 591 | + } |
|
| 592 | + } else { |
|
| 593 | + $boucle->numrows = true; |
|
| 594 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 595 | + } |
|
| 596 | + } else { |
|
| 597 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $count = ''; |
|
| 601 | + if (!$boucle->select) { |
|
| 602 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 603 | + $count = '1'; |
|
| 604 | + } else { |
|
| 605 | + $count = 'count(*)'; |
|
| 606 | + } |
|
| 607 | + $boucles[$id_boucle]->select[] = $count; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + if ($flag_cpt) { |
|
| 611 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 612 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 613 | + } else { |
|
| 614 | + $nums = ''; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 618 | + $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 619 | + . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 620 | + . $boucle->mode_partie |
|
| 621 | + . "\n\t"; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // Ne calculer la requete que maintenant |
|
| 625 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 626 | + |
|
| 627 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 628 | + ? ("\n\t$init = array();") : '') |
|
| 629 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 630 | + |
|
| 631 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 632 | + |
|
| 633 | + $a = sprintf( |
|
| 634 | + CODE_CORPS_BOUCLE, |
|
| 635 | + $init, |
|
| 636 | + $boucle->iterateur, |
|
| 637 | + '$command', |
|
| 638 | + $contexte, |
|
| 639 | + $nums, |
|
| 640 | + $init_lang, |
|
| 641 | + $corps, |
|
| 642 | + $fin_lang, |
|
| 643 | + $trace, |
|
| 644 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 645 | + ); |
|
| 646 | 646 | |
| 647 | 647 | # var_dump($a);exit; |
| 648 | - return $a; |
|
| 648 | + return $a; |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -661,48 +661,48 @@ discard block |
||
| 661 | 661 | * Code PHP compilé définissant les informations de requête |
| 662 | 662 | **/ |
| 663 | 663 | function calculer_requete_sql($boucle) { |
| 664 | - $init = []; |
|
| 665 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 666 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 667 | - # En absence de champ c'est un decompte : |
|
| 668 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 669 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 670 | - $init[] = calculer_dec( |
|
| 671 | - 'groupby', |
|
| 672 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 673 | - ); |
|
| 674 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 675 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 676 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 677 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 678 | - $init[] = calculer_dec( |
|
| 679 | - 'limit', |
|
| 680 | - ( |
|
| 681 | - strpos($boucle->limit, 'intval') === false ? |
|
| 682 | - "'" . ($boucle->limit) . "'" : |
|
| 683 | - $boucle->limit |
|
| 684 | - ) |
|
| 685 | - ); |
|
| 686 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 687 | - $s = $d = ''; |
|
| 688 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 689 | - // ou recalculée à chaque passage (vide) |
|
| 690 | - foreach ($init as $i) { |
|
| 691 | - if (reset($i)) { |
|
| 692 | - $s .= "\n\t\t" . end($i); |
|
| 693 | - } # statique |
|
| 694 | - else { |
|
| 695 | - $d .= "\n\t" . end($i); |
|
| 696 | - } # dynamique |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 700 | - . $boucle->in |
|
| 701 | - . $boucle->hash |
|
| 702 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 703 | - . $s |
|
| 704 | - . "\n\t}" |
|
| 705 | - . $d; |
|
| 664 | + $init = []; |
|
| 665 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 666 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 667 | + # En absence de champ c'est un decompte : |
|
| 668 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 669 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 670 | + $init[] = calculer_dec( |
|
| 671 | + 'groupby', |
|
| 672 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 673 | + ); |
|
| 674 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 675 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 676 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 677 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 678 | + $init[] = calculer_dec( |
|
| 679 | + 'limit', |
|
| 680 | + ( |
|
| 681 | + strpos($boucle->limit, 'intval') === false ? |
|
| 682 | + "'" . ($boucle->limit) . "'" : |
|
| 683 | + $boucle->limit |
|
| 684 | + ) |
|
| 685 | + ); |
|
| 686 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 687 | + $s = $d = ''; |
|
| 688 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 689 | + // ou recalculée à chaque passage (vide) |
|
| 690 | + foreach ($init as $i) { |
|
| 691 | + if (reset($i)) { |
|
| 692 | + $s .= "\n\t\t" . end($i); |
|
| 693 | + } # statique |
|
| 694 | + else { |
|
| 695 | + $d .= "\n\t" . end($i); |
|
| 696 | + } # dynamique |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 700 | + . $boucle->in |
|
| 701 | + . $boucle->hash |
|
| 702 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 703 | + . $s |
|
| 704 | + . "\n\t}" |
|
| 705 | + . $d; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -720,13 +720,13 @@ discard block |
||
| 720 | 720 | * qui peut être utilisé pour la production d'un tableau array() |
| 721 | 721 | **/ |
| 722 | 722 | function memoriser_contexte_compil($p) { |
| 723 | - return join(',', [ |
|
| 724 | - _q($p->descr['sourcefile'] ?? ''), |
|
| 725 | - _q($p->descr['nom'] ?? ''), |
|
| 726 | - _q($p->id_boucle ?? ''), |
|
| 727 | - intval($p->ligne), |
|
| 728 | - '$GLOBALS[\'spip_lang\']' |
|
| 729 | - ]); |
|
| 723 | + return join(',', [ |
|
| 724 | + _q($p->descr['sourcefile'] ?? ''), |
|
| 725 | + _q($p->descr['nom'] ?? ''), |
|
| 726 | + _q($p->id_boucle ?? ''), |
|
| 727 | + intval($p->ligne), |
|
| 728 | + '$GLOBALS[\'spip_lang\']' |
|
| 729 | + ]); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -744,20 +744,20 @@ discard block |
||
| 744 | 744 | * Objet Contexte |
| 745 | 745 | **/ |
| 746 | 746 | function reconstruire_contexte_compil($context_compil) { |
| 747 | - if (!is_array($context_compil)) { |
|
| 748 | - return $context_compil; |
|
| 749 | - } |
|
| 750 | - $p = new Contexte(); |
|
| 751 | - $p->descr = [ |
|
| 752 | - 'sourcefile' => $context_compil[0] ?? '', |
|
| 753 | - 'nom' => $context_compil[1] ?? '', |
|
| 754 | - ]; |
|
| 755 | - |
|
| 756 | - $p->id_boucle = $context_compil[2] ?? ''; |
|
| 757 | - $p->ligne = (int)($context_compil[3] ?? 0); |
|
| 758 | - $p->lang = $context_compil[4] ?? ''; |
|
| 759 | - |
|
| 760 | - return $p; |
|
| 747 | + if (!is_array($context_compil)) { |
|
| 748 | + return $context_compil; |
|
| 749 | + } |
|
| 750 | + $p = new Contexte(); |
|
| 751 | + $p->descr = [ |
|
| 752 | + 'sourcefile' => $context_compil[0] ?? '', |
|
| 753 | + 'nom' => $context_compil[1] ?? '', |
|
| 754 | + ]; |
|
| 755 | + |
|
| 756 | + $p->id_boucle = $context_compil[2] ?? ''; |
|
| 757 | + $p->ligne = (int)($context_compil[3] ?? 0); |
|
| 758 | + $p->lang = $context_compil[4] ?? ''; |
|
| 759 | + |
|
| 760 | + return $p; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -783,12 +783,12 @@ discard block |
||
| 783 | 783 | * - index 1 : Code de l'affectation |
| 784 | 784 | **/ |
| 785 | 785 | function calculer_dec($nom, $val) { |
| 786 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 787 | - // si une variable apparait dans le calcul de la clause |
|
| 788 | - // il faut la re-evaluer a chaque passage |
|
| 789 | - if ( |
|
| 790 | - strpos($val, '$') !== false |
|
| 791 | - /* |
|
| 786 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 787 | + // si une variable apparait dans le calcul de la clause |
|
| 788 | + // il faut la re-evaluer a chaque passage |
|
| 789 | + if ( |
|
| 790 | + strpos($val, '$') !== false |
|
| 791 | + /* |
|
| 792 | 792 | OR strpos($val, 'sql_') !== false |
| 793 | 793 | OR ( |
| 794 | 794 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -796,11 +796,11 @@ discard block |
||
| 796 | 796 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 797 | 797 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 798 | 798 | )*/ |
| 799 | - ) { |
|
| 800 | - $static = ''; |
|
| 801 | - } |
|
| 799 | + ) { |
|
| 800 | + $static = ''; |
|
| 801 | + } |
|
| 802 | 802 | |
| 803 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 803 | + return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -820,32 +820,32 @@ discard block |
||
| 820 | 820 | * Expression PHP décrivant un texte ou un tableau |
| 821 | 821 | **/ |
| 822 | 822 | function calculer_dump_array($a) { |
| 823 | - if (!is_array($a)) { |
|
| 824 | - return $a; |
|
| 825 | - } |
|
| 826 | - $res = ''; |
|
| 827 | - if ($a and $a[0] == "'?'") { |
|
| 828 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 829 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 830 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 831 | - ')'); |
|
| 832 | - } else { |
|
| 833 | - foreach ($a as $k => $v) { |
|
| 834 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 835 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 839 | - } |
|
| 823 | + if (!is_array($a)) { |
|
| 824 | + return $a; |
|
| 825 | + } |
|
| 826 | + $res = ''; |
|
| 827 | + if ($a and $a[0] == "'?'") { |
|
| 828 | + return ('(' . calculer_dump_array($a[1]) . |
|
| 829 | + ' ? ' . calculer_dump_array($a[2]) . |
|
| 830 | + ' : ' . calculer_dump_array($a[3]) . |
|
| 831 | + ')'); |
|
| 832 | + } else { |
|
| 833 | + foreach ($a as $k => $v) { |
|
| 834 | + $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 835 | + $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 839 | + } |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | function calculer_dump_join($a) { |
| 843 | - $res = ''; |
|
| 844 | - foreach ($a as $k => $v) { |
|
| 845 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 846 | - } |
|
| 843 | + $res = ''; |
|
| 844 | + foreach ($a as $k => $v) { |
|
| 845 | + $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 846 | + } |
|
| 847 | 847 | |
| 848 | - return 'array(' . substr($res, 2) . ')'; |
|
| 848 | + return 'array(' . substr($res, 2) . ')'; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -857,12 +857,12 @@ discard block |
||
| 857 | 857 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 858 | 858 | **/ |
| 859 | 859 | function calculer_from(&$boucle) { |
| 860 | - $res = ''; |
|
| 861 | - foreach ($boucle->from as $k => $v) { |
|
| 862 | - $res .= ",'$k' => '$v'"; |
|
| 863 | - } |
|
| 860 | + $res = ''; |
|
| 861 | + foreach ($boucle->from as $k => $v) { |
|
| 862 | + $res .= ",'$k' => '$v'"; |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - return 'array(' . substr($res, 1) . ')'; |
|
| 865 | + return 'array(' . substr($res, 1) . ')'; |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | /** |
@@ -875,30 +875,30 @@ discard block |
||
| 875 | 875 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 876 | 876 | **/ |
| 877 | 877 | function calculer_from_type(&$boucle) { |
| 878 | - $res = ''; |
|
| 879 | - foreach ($boucle->from_type as $k => $v) { |
|
| 880 | - $res .= ",'$k' => '$v'"; |
|
| 881 | - } |
|
| 878 | + $res = ''; |
|
| 879 | + foreach ($boucle->from_type as $k => $v) { |
|
| 880 | + $res .= ",'$k' => '$v'"; |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - return 'array(' . substr($res, 1) . ')'; |
|
| 883 | + return 'array(' . substr($res, 1) . ')'; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | function calculer_order(&$boucle) { |
| 887 | - if ( |
|
| 888 | - !$order = $boucle->order |
|
| 889 | - and !$order = $boucle->default_order |
|
| 890 | - ) { |
|
| 891 | - $order = []; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 887 | + if ( |
|
| 888 | + !$order = $boucle->order |
|
| 889 | + and !$order = $boucle->default_order |
|
| 890 | + ) { |
|
| 891 | + $order = []; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 895 | 895 | $col = "." . $boucle->modificateur['collate']; |
| 896 | 896 | foreach($order as $k=>$o) |
| 897 | 897 | if (strpos($order[$k],'COLLATE')===false) |
| 898 | 898 | $order[$k].= $col; |
| 899 | 899 | }*/ |
| 900 | 900 | |
| 901 | - return join(', ', $order); |
|
| 901 | + return join(', ', $order); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -907,62 +907,62 @@ discard block |
||
| 907 | 907 | // (qui sera argument d'un Return ou la partie droite d'une affectation). |
| 908 | 908 | |
| 909 | 909 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 910 | - if (!$tableau) { |
|
| 911 | - return "''"; |
|
| 912 | - } |
|
| 913 | - if (is_string($descr)) { |
|
| 914 | - if (isset($boucles[$descr])) { |
|
| 915 | - $idb = $descr; |
|
| 916 | - $descr = []; |
|
| 917 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | - } |
|
| 920 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - else { |
|
| 925 | - $descr = []; |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - if (!isset($descr['niv'])) { |
|
| 929 | - $descr['niv'] = 0; |
|
| 930 | - } |
|
| 931 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | - if ($codes === false) { |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - $n = is_countable($codes) ? count($codes) : 0; |
|
| 936 | - if (!$n) { |
|
| 937 | - return "''"; |
|
| 938 | - } |
|
| 939 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | - if ($n == 1) { |
|
| 942 | - return $codes[0]; |
|
| 943 | - } else { |
|
| 944 | - $res = ''; |
|
| 945 | - foreach ($codes as $code) { |
|
| 946 | - if ( |
|
| 947 | - !preg_match("/^'[^']*'$/", $code) |
|
| 948 | - or substr($res, -1, 1) !== "'" |
|
| 949 | - ) { |
|
| 950 | - $res .= " .\n$tab$code"; |
|
| 951 | - } else { |
|
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | - } |
|
| 958 | - } else { |
|
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ?: ''); |
|
| 960 | - |
|
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | - " ,\n$tab", |
|
| 963 | - $codes |
|
| 964 | - ) . ')))'; |
|
| 965 | - } |
|
| 910 | + if (!$tableau) { |
|
| 911 | + return "''"; |
|
| 912 | + } |
|
| 913 | + if (is_string($descr)) { |
|
| 914 | + if (isset($boucles[$descr])) { |
|
| 915 | + $idb = $descr; |
|
| 916 | + $descr = []; |
|
| 917 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | + } |
|
| 920 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + else { |
|
| 925 | + $descr = []; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + if (!isset($descr['niv'])) { |
|
| 929 | + $descr['niv'] = 0; |
|
| 930 | + } |
|
| 931 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | + if ($codes === false) { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + $n = is_countable($codes) ? count($codes) : 0; |
|
| 936 | + if (!$n) { |
|
| 937 | + return "''"; |
|
| 938 | + } |
|
| 939 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | + if ($n == 1) { |
|
| 942 | + return $codes[0]; |
|
| 943 | + } else { |
|
| 944 | + $res = ''; |
|
| 945 | + foreach ($codes as $code) { |
|
| 946 | + if ( |
|
| 947 | + !preg_match("/^'[^']*'$/", $code) |
|
| 948 | + or substr($res, -1, 1) !== "'" |
|
| 949 | + ) { |
|
| 950 | + $res .= " .\n$tab$code"; |
|
| 951 | + } else { |
|
| 952 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | + } |
|
| 958 | + } else { |
|
| 959 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ?: ''); |
|
| 960 | + |
|
| 961 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | + " ,\n$tab", |
|
| 963 | + $codes |
|
| 964 | + ) . ')))'; |
|
| 965 | + } |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | |
@@ -972,213 +972,213 @@ discard block |
||
| 972 | 972 | |
| 973 | 973 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 974 | 974 | |
| 975 | - $codes = []; |
|
| 976 | - // cas de la boucle recursive |
|
| 977 | - if (is_array($id_boucle)) { |
|
| 978 | - $id_boucle = $id_boucle[0]; |
|
| 979 | - } |
|
| 980 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 981 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 982 | - $mode = _request('var_mode_affiche'); |
|
| 983 | - $err_e_c = ''; |
|
| 984 | - // chaque commentaire introduit dans le code doit commencer |
|
| 985 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 986 | - foreach ($tableau as $p) { |
|
| 987 | - switch ($p->type) { |
|
| 988 | - // texte seul |
|
| 989 | - case 'texte': |
|
| 990 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 991 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 992 | - $avant = ''; |
|
| 993 | - $apres = ''; |
|
| 994 | - $altern = "''"; |
|
| 995 | - break; |
|
| 996 | - |
|
| 997 | - case 'polyglotte': |
|
| 998 | - $code = ''; |
|
| 999 | - foreach ($p->traductions as $k => $v) { |
|
| 1000 | - $code .= ",'" . |
|
| 1001 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1002 | - "' => '" . |
|
| 1003 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1004 | - "'"; |
|
| 1005 | - } |
|
| 1006 | - $code = 'choisir_traduction(array(' . |
|
| 1007 | - substr($code, 1) . |
|
| 1008 | - '))'; |
|
| 1009 | - $commentaire = '&'; |
|
| 1010 | - $avant = ''; |
|
| 1011 | - $apres = ''; |
|
| 1012 | - $altern = "''"; |
|
| 1013 | - break; |
|
| 1014 | - |
|
| 1015 | - // inclure |
|
| 1016 | - case 'include': |
|
| 1017 | - $p->descr = $descr; |
|
| 1018 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1019 | - if ($code === false) { |
|
| 1020 | - $err_e_c = true; |
|
| 1021 | - $code = "''"; |
|
| 1022 | - } else { |
|
| 1023 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1024 | - $avant = ''; |
|
| 1025 | - $apres = ''; |
|
| 1026 | - $altern = "''"; |
|
| 1027 | - } |
|
| 1028 | - break; |
|
| 1029 | - |
|
| 1030 | - // boucle |
|
| 1031 | - case TYPE_RECURSIF: |
|
| 1032 | - $nom = $p->id_boucle; |
|
| 1033 | - $newdescr = $descr; |
|
| 1034 | - $newdescr['id_mere'] = $nom; |
|
| 1035 | - $newdescr['niv']++; |
|
| 1036 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1037 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1038 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1039 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1040 | - $newdescr['niv']--; |
|
| 1041 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1042 | - if ( |
|
| 1043 | - $preaff === false |
|
| 1044 | - or $avant === false |
|
| 1045 | - or $apres === false |
|
| 1046 | - or $altern === false |
|
| 1047 | - or $postaff === false |
|
| 1048 | - ) { |
|
| 1049 | - $err_e_c = true; |
|
| 1050 | - $code = "''"; |
|
| 1051 | - } else { |
|
| 1052 | - $code = 'BOUCLE' . |
|
| 1053 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1054 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1055 | - $commentaire = "?$nom"; |
|
| 1056 | - if ( |
|
| 1057 | - !$boucles[$nom]->milieu |
|
| 1058 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1059 | - ) { |
|
| 1060 | - if ($preaff != "''") { |
|
| 1061 | - $code .= "\n. $preaff"; |
|
| 1062 | - } |
|
| 1063 | - if ($altern != "''") { |
|
| 1064 | - $code .= "\n. $altern"; |
|
| 1065 | - } |
|
| 1066 | - if ($postaff != "''") { |
|
| 1067 | - $code .= "\n. $postaff"; |
|
| 1068 | - } |
|
| 1069 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1070 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1071 | - } |
|
| 1072 | - $avant = $apres = $altern = "''"; |
|
| 1073 | - } else { |
|
| 1074 | - if ($preaff != "''") { |
|
| 1075 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1076 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1077 | - } |
|
| 1078 | - if ($postaff != "''") { |
|
| 1079 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1080 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1081 | - } |
|
| 1082 | - if ($altern != "''") { |
|
| 1083 | - $altern = "($altern)"; |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - break; |
|
| 1088 | - |
|
| 1089 | - case 'idiome': |
|
| 1090 | - $l = []; |
|
| 1091 | - $code = ''; |
|
| 1092 | - foreach ($p->arg as $k => $v) { |
|
| 1093 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1094 | - if ($k) { |
|
| 1095 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1096 | - } else { |
|
| 1097 | - $code = $_v; |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1101 | - if ($p->module) { |
|
| 1102 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1103 | - } elseif ($p->nom_champ) { |
|
| 1104 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1105 | - } else { |
|
| 1106 | - $m = ''; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - $code = (!$code ? "'$m'" : |
|
| 1110 | - ($m ? "'$m' . $code" : |
|
| 1111 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1112 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1113 | - $code = "_T($code)"; |
|
| 1114 | - if ($p->param) { |
|
| 1115 | - $p->id_boucle = $id_boucle; |
|
| 1116 | - $p->boucles = &$boucles; |
|
| 1117 | - $code = compose_filtres($p, $code); |
|
| 1118 | - } |
|
| 1119 | - $commentaire = ':'; |
|
| 1120 | - $avant = ''; |
|
| 1121 | - $apres = ''; |
|
| 1122 | - $altern = "''"; |
|
| 1123 | - break; |
|
| 1124 | - |
|
| 1125 | - case 'champ': |
|
| 1126 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1127 | - $p->id_boucle = $id_boucle; |
|
| 1128 | - $p->boucles = &$boucles; |
|
| 1129 | - $p->descr = $descr; |
|
| 1130 | - #$p->interdire_scripts = true; |
|
| 1131 | - $p->type_requete = $type; |
|
| 1132 | - |
|
| 1133 | - $code = calculer_champ($p); |
|
| 1134 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1135 | - $avant = calculer_liste( |
|
| 1136 | - $p->avant, |
|
| 1137 | - $descr, |
|
| 1138 | - $boucles, |
|
| 1139 | - $id_boucle |
|
| 1140 | - ); |
|
| 1141 | - $apres = calculer_liste( |
|
| 1142 | - $p->apres, |
|
| 1143 | - $descr, |
|
| 1144 | - $boucles, |
|
| 1145 | - $id_boucle |
|
| 1146 | - ); |
|
| 1147 | - $altern = "''"; |
|
| 1148 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1149 | - // forcer la conversion en une chaine par strval |
|
| 1150 | - // si ca peut etre autre chose qu'une chaine |
|
| 1151 | - if ( |
|
| 1152 | - ($avant != "''" or $apres != "''") |
|
| 1153 | - and $code[0] != "'" |
|
| 975 | + $codes = []; |
|
| 976 | + // cas de la boucle recursive |
|
| 977 | + if (is_array($id_boucle)) { |
|
| 978 | + $id_boucle = $id_boucle[0]; |
|
| 979 | + } |
|
| 980 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 981 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 982 | + $mode = _request('var_mode_affiche'); |
|
| 983 | + $err_e_c = ''; |
|
| 984 | + // chaque commentaire introduit dans le code doit commencer |
|
| 985 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 986 | + foreach ($tableau as $p) { |
|
| 987 | + switch ($p->type) { |
|
| 988 | + // texte seul |
|
| 989 | + case 'texte': |
|
| 990 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 991 | + $commentaire = strlen($p->texte) . ' signes'; |
|
| 992 | + $avant = ''; |
|
| 993 | + $apres = ''; |
|
| 994 | + $altern = "''"; |
|
| 995 | + break; |
|
| 996 | + |
|
| 997 | + case 'polyglotte': |
|
| 998 | + $code = ''; |
|
| 999 | + foreach ($p->traductions as $k => $v) { |
|
| 1000 | + $code .= ",'" . |
|
| 1001 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1002 | + "' => '" . |
|
| 1003 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1004 | + "'"; |
|
| 1005 | + } |
|
| 1006 | + $code = 'choisir_traduction(array(' . |
|
| 1007 | + substr($code, 1) . |
|
| 1008 | + '))'; |
|
| 1009 | + $commentaire = '&'; |
|
| 1010 | + $avant = ''; |
|
| 1011 | + $apres = ''; |
|
| 1012 | + $altern = "''"; |
|
| 1013 | + break; |
|
| 1014 | + |
|
| 1015 | + // inclure |
|
| 1016 | + case 'include': |
|
| 1017 | + $p->descr = $descr; |
|
| 1018 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1019 | + if ($code === false) { |
|
| 1020 | + $err_e_c = true; |
|
| 1021 | + $code = "''"; |
|
| 1022 | + } else { |
|
| 1023 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1024 | + $avant = ''; |
|
| 1025 | + $apres = ''; |
|
| 1026 | + $altern = "''"; |
|
| 1027 | + } |
|
| 1028 | + break; |
|
| 1029 | + |
|
| 1030 | + // boucle |
|
| 1031 | + case TYPE_RECURSIF: |
|
| 1032 | + $nom = $p->id_boucle; |
|
| 1033 | + $newdescr = $descr; |
|
| 1034 | + $newdescr['id_mere'] = $nom; |
|
| 1035 | + $newdescr['niv']++; |
|
| 1036 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1037 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1038 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1039 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1040 | + $newdescr['niv']--; |
|
| 1041 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1042 | + if ( |
|
| 1043 | + $preaff === false |
|
| 1044 | + or $avant === false |
|
| 1045 | + or $apres === false |
|
| 1046 | + or $altern === false |
|
| 1047 | + or $postaff === false |
|
| 1048 | + ) { |
|
| 1049 | + $err_e_c = true; |
|
| 1050 | + $code = "''"; |
|
| 1051 | + } else { |
|
| 1052 | + $code = 'BOUCLE' . |
|
| 1053 | + str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1054 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1055 | + $commentaire = "?$nom"; |
|
| 1056 | + if ( |
|
| 1057 | + !$boucles[$nom]->milieu |
|
| 1058 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1059 | + ) { |
|
| 1060 | + if ($preaff != "''") { |
|
| 1061 | + $code .= "\n. $preaff"; |
|
| 1062 | + } |
|
| 1063 | + if ($altern != "''") { |
|
| 1064 | + $code .= "\n. $altern"; |
|
| 1065 | + } |
|
| 1066 | + if ($postaff != "''") { |
|
| 1067 | + $code .= "\n. $postaff"; |
|
| 1068 | + } |
|
| 1069 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1070 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1071 | + } |
|
| 1072 | + $avant = $apres = $altern = "''"; |
|
| 1073 | + } else { |
|
| 1074 | + if ($preaff != "''") { |
|
| 1075 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1076 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1077 | + } |
|
| 1078 | + if ($postaff != "''") { |
|
| 1079 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1080 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1081 | + } |
|
| 1082 | + if ($altern != "''") { |
|
| 1083 | + $altern = "($altern)"; |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + break; |
|
| 1088 | + |
|
| 1089 | + case 'idiome': |
|
| 1090 | + $l = []; |
|
| 1091 | + $code = ''; |
|
| 1092 | + foreach ($p->arg as $k => $v) { |
|
| 1093 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1094 | + if ($k) { |
|
| 1095 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1096 | + } else { |
|
| 1097 | + $code = $_v; |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1101 | + if ($p->module) { |
|
| 1102 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1103 | + } elseif ($p->nom_champ) { |
|
| 1104 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1105 | + } else { |
|
| 1106 | + $m = ''; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + $code = (!$code ? "'$m'" : |
|
| 1110 | + ($m ? "'$m' . $code" : |
|
| 1111 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1112 | + . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1113 | + $code = "_T($code)"; |
|
| 1114 | + if ($p->param) { |
|
| 1115 | + $p->id_boucle = $id_boucle; |
|
| 1116 | + $p->boucles = &$boucles; |
|
| 1117 | + $code = compose_filtres($p, $code); |
|
| 1118 | + } |
|
| 1119 | + $commentaire = ':'; |
|
| 1120 | + $avant = ''; |
|
| 1121 | + $apres = ''; |
|
| 1122 | + $altern = "''"; |
|
| 1123 | + break; |
|
| 1124 | + |
|
| 1125 | + case 'champ': |
|
| 1126 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1127 | + $p->id_boucle = $id_boucle; |
|
| 1128 | + $p->boucles = &$boucles; |
|
| 1129 | + $p->descr = $descr; |
|
| 1130 | + #$p->interdire_scripts = true; |
|
| 1131 | + $p->type_requete = $type; |
|
| 1132 | + |
|
| 1133 | + $code = calculer_champ($p); |
|
| 1134 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1135 | + $avant = calculer_liste( |
|
| 1136 | + $p->avant, |
|
| 1137 | + $descr, |
|
| 1138 | + $boucles, |
|
| 1139 | + $id_boucle |
|
| 1140 | + ); |
|
| 1141 | + $apres = calculer_liste( |
|
| 1142 | + $p->apres, |
|
| 1143 | + $descr, |
|
| 1144 | + $boucles, |
|
| 1145 | + $id_boucle |
|
| 1146 | + ); |
|
| 1147 | + $altern = "''"; |
|
| 1148 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1149 | + // forcer la conversion en une chaine par strval |
|
| 1150 | + // si ca peut etre autre chose qu'une chaine |
|
| 1151 | + if ( |
|
| 1152 | + ($avant != "''" or $apres != "''") |
|
| 1153 | + and $code[0] != "'" |
|
| 1154 | 1154 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1155 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1156 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1157 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1158 | - ) { |
|
| 1159 | - $code = "strval($code)"; |
|
| 1160 | - } |
|
| 1161 | - break; |
|
| 1162 | - |
|
| 1163 | - default: |
|
| 1164 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1165 | - $code = "''"; |
|
| 1166 | - $p->descr = $descr; |
|
| 1167 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1168 | - erreur_squelette($err_e_c, $p); |
|
| 1169 | - } // switch |
|
| 1170 | - |
|
| 1171 | - if ($code != "''") { |
|
| 1172 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1173 | - $codes[] = (($mode == 'validation') ? |
|
| 1174 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1175 | - : (($mode == 'code') ? |
|
| 1176 | - "\n// $commentaire\n$code" : |
|
| 1177 | - $code)); |
|
| 1178 | - } |
|
| 1179 | - } // foreach |
|
| 1180 | - |
|
| 1181 | - return $err_e_c ? false : $codes; |
|
| 1155 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1156 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1157 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1158 | + ) { |
|
| 1159 | + $code = "strval($code)"; |
|
| 1160 | + } |
|
| 1161 | + break; |
|
| 1162 | + |
|
| 1163 | + default: |
|
| 1164 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1165 | + $code = "''"; |
|
| 1166 | + $p->descr = $descr; |
|
| 1167 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1168 | + erreur_squelette($err_e_c, $p); |
|
| 1169 | + } // switch |
|
| 1170 | + |
|
| 1171 | + if ($code != "''") { |
|
| 1172 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1173 | + $codes[] = (($mode == 'validation') ? |
|
| 1174 | + "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1175 | + : (($mode == 'code') ? |
|
| 1176 | + "\n// $commentaire\n$code" : |
|
| 1177 | + $code)); |
|
| 1178 | + } |
|
| 1179 | + } // foreach |
|
| 1180 | + |
|
| 1181 | + return $err_e_c ? false : $codes; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1188,13 +1188,13 @@ discard block |
||
| 1188 | 1188 | * @return string |
| 1189 | 1189 | */ |
| 1190 | 1190 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1191 | - if ($partie1 === "''") { |
|
| 1192 | - return $partie2; |
|
| 1193 | - } |
|
| 1194 | - if ($partie2 === "''") { |
|
| 1195 | - return $partie1; |
|
| 1196 | - } |
|
| 1197 | - return "$partie1\n. $partie2"; |
|
| 1191 | + if ($partie1 === "''") { |
|
| 1192 | + return $partie2; |
|
| 1193 | + } |
|
| 1194 | + if ($partie2 === "''") { |
|
| 1195 | + return $partie1; |
|
| 1196 | + } |
|
| 1197 | + return "$partie1\n. $partie2"; |
|
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | 1200 | |
@@ -1218,56 +1218,56 @@ discard block |
||
| 1218 | 1218 | * @return mixed|string |
| 1219 | 1219 | */ |
| 1220 | 1220 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1221 | - if ($avant === "''") { |
|
| 1222 | - $avant = ''; |
|
| 1223 | - } |
|
| 1224 | - if ($apres === "''") { |
|
| 1225 | - $apres = ''; |
|
| 1226 | - } |
|
| 1227 | - if ($avant or $apres or ($altern !== "''")) { |
|
| 1228 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1229 | - $t = $code; |
|
| 1230 | - $cond = ''; |
|
| 1231 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1232 | - $t = $r[2]; |
|
| 1233 | - $cond = '!' . $r[1]; |
|
| 1234 | - } else { |
|
| 1235 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1236 | - $t = $r[2]; |
|
| 1237 | - $cond = $r[1]; |
|
| 1238 | - } else { |
|
| 1239 | - $t = '$t' . $n; |
|
| 1240 | - $cond = "($t = $code)!==''"; |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1245 | - $t . |
|
| 1246 | - (!$apres ? '' : " . $apres"); |
|
| 1247 | - |
|
| 1248 | - if ($res !== $t) { |
|
| 1249 | - $res = "($res)"; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - return $code; |
|
| 1221 | + if ($avant === "''") { |
|
| 1222 | + $avant = ''; |
|
| 1223 | + } |
|
| 1224 | + if ($apres === "''") { |
|
| 1225 | + $apres = ''; |
|
| 1226 | + } |
|
| 1227 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1228 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1229 | + $t = $code; |
|
| 1230 | + $cond = ''; |
|
| 1231 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1232 | + $t = $r[2]; |
|
| 1233 | + $cond = '!' . $r[1]; |
|
| 1234 | + } else { |
|
| 1235 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1236 | + $t = $r[2]; |
|
| 1237 | + $cond = $r[1]; |
|
| 1238 | + } else { |
|
| 1239 | + $t = '$t' . $n; |
|
| 1240 | + $cond = "($t = $code)!==''"; |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + $res = (!$avant ? '' : "$avant . ") . |
|
| 1245 | + $t . |
|
| 1246 | + (!$apres ? '' : " . $apres"); |
|
| 1247 | + |
|
| 1248 | + if ($res !== $t) { |
|
| 1249 | + $res = "($res)"; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + return $code; |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | |
| 1259 | 1259 | function compile_inclure_doublons($lexemes) { |
| 1260 | - foreach ($lexemes as $v) { |
|
| 1261 | - if ($v->type === 'include' and $v->param) { |
|
| 1262 | - foreach ($v->param as $r) { |
|
| 1263 | - if (trim($r[0]) === 'doublons') { |
|
| 1264 | - return true; |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - return false; |
|
| 1260 | + foreach ($lexemes as $v) { |
|
| 1261 | + if ($v->type === 'include' and $v->param) { |
|
| 1262 | + foreach ($v->param as $r) { |
|
| 1263 | + if (trim($r[0]) === 'doublons') { |
|
| 1264 | + return true; |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + return false; |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1286,354 +1286,354 @@ discard block |
||
| 1286 | 1286 | // En cas d'erreur, elle retournera un tableau des 2 premiers elements seulement |
| 1287 | 1287 | |
| 1288 | 1288 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, string $connect = '') { |
| 1289 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1290 | - // Bonus : supprime le BOM |
|
| 1291 | - include_spip('inc/charsets'); |
|
| 1292 | - $squelette = transcoder_page($squelette); |
|
| 1293 | - |
|
| 1294 | - // rendre inertes les echappements de #[](){}<> |
|
| 1295 | - $i = 0; |
|
| 1296 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1297 | - $i++; |
|
| 1298 | - } |
|
| 1299 | - $squelette = preg_replace_callback( |
|
| 1300 | - ',\\\\([#[()\]{}<>]),', |
|
| 1301 | - fn($a) => "$inerte-" . ord($a[1]) . '-', |
|
| 1302 | - $squelette, |
|
| 1303 | - -1, |
|
| 1304 | - $esc |
|
| 1305 | - ); |
|
| 1306 | - |
|
| 1307 | - $descr = [ |
|
| 1308 | - 'nom' => $nom, |
|
| 1309 | - 'gram' => $gram, |
|
| 1310 | - 'sourcefile' => $sourcefile, |
|
| 1311 | - 'squelette' => $squelette |
|
| 1312 | - ]; |
|
| 1313 | - |
|
| 1314 | - // Phraser le squelette, selon sa grammaire |
|
| 1315 | - |
|
| 1316 | - $boucles = []; |
|
| 1317 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1318 | - |
|
| 1319 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1320 | - |
|
| 1321 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1322 | - |
|
| 1323 | - // restituer les echappements |
|
| 1324 | - if ($esc) { |
|
| 1325 | - foreach ($boucles as $i => $boucle) { |
|
| 1326 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1327 | - ",$inerte-(\d+)-,", |
|
| 1328 | - fn($a) => chr($a[1]), |
|
| 1329 | - $boucle->return |
|
| 1330 | - ); |
|
| 1331 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1332 | - ",$inerte-(\d+)-,", |
|
| 1333 | - fn($a) => '\\\\' . chr($a[1]), |
|
| 1334 | - $boucle->descr['squelette'] |
|
| 1335 | - ); |
|
| 1336 | - } |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1340 | - if ($debug) { |
|
| 1341 | - include_spip('public/decompiler'); |
|
| 1342 | - foreach ($boucles as $id => $boucle) { |
|
| 1343 | - if ($id) { |
|
| 1344 | - $decomp = "\n/* BOUCLE " . |
|
| 1345 | - $boucle->type_requete . |
|
| 1346 | - ' ' . |
|
| 1347 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1348 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1349 | - " */\n"; |
|
| 1350 | - } else { |
|
| 1351 | - $decomp = ("\n/*\n" . |
|
| 1352 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1353 | - . "\n*/"); |
|
| 1354 | - } |
|
| 1355 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1356 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - return $boucles; |
|
| 1289 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1290 | + // Bonus : supprime le BOM |
|
| 1291 | + include_spip('inc/charsets'); |
|
| 1292 | + $squelette = transcoder_page($squelette); |
|
| 1293 | + |
|
| 1294 | + // rendre inertes les echappements de #[](){}<> |
|
| 1295 | + $i = 0; |
|
| 1296 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1297 | + $i++; |
|
| 1298 | + } |
|
| 1299 | + $squelette = preg_replace_callback( |
|
| 1300 | + ',\\\\([#[()\]{}<>]),', |
|
| 1301 | + fn($a) => "$inerte-" . ord($a[1]) . '-', |
|
| 1302 | + $squelette, |
|
| 1303 | + -1, |
|
| 1304 | + $esc |
|
| 1305 | + ); |
|
| 1306 | + |
|
| 1307 | + $descr = [ |
|
| 1308 | + 'nom' => $nom, |
|
| 1309 | + 'gram' => $gram, |
|
| 1310 | + 'sourcefile' => $sourcefile, |
|
| 1311 | + 'squelette' => $squelette |
|
| 1312 | + ]; |
|
| 1313 | + |
|
| 1314 | + // Phraser le squelette, selon sa grammaire |
|
| 1315 | + |
|
| 1316 | + $boucles = []; |
|
| 1317 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1318 | + |
|
| 1319 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1320 | + |
|
| 1321 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1322 | + |
|
| 1323 | + // restituer les echappements |
|
| 1324 | + if ($esc) { |
|
| 1325 | + foreach ($boucles as $i => $boucle) { |
|
| 1326 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1327 | + ",$inerte-(\d+)-,", |
|
| 1328 | + fn($a) => chr($a[1]), |
|
| 1329 | + $boucle->return |
|
| 1330 | + ); |
|
| 1331 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1332 | + ",$inerte-(\d+)-,", |
|
| 1333 | + fn($a) => '\\\\' . chr($a[1]), |
|
| 1334 | + $boucle->descr['squelette'] |
|
| 1335 | + ); |
|
| 1336 | + } |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1340 | + if ($debug) { |
|
| 1341 | + include_spip('public/decompiler'); |
|
| 1342 | + foreach ($boucles as $id => $boucle) { |
|
| 1343 | + if ($id) { |
|
| 1344 | + $decomp = "\n/* BOUCLE " . |
|
| 1345 | + $boucle->type_requete . |
|
| 1346 | + ' ' . |
|
| 1347 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1348 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1349 | + " */\n"; |
|
| 1350 | + } else { |
|
| 1351 | + $decomp = ("\n/*\n" . |
|
| 1352 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1353 | + . "\n*/"); |
|
| 1354 | + } |
|
| 1355 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1356 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + return $boucles; |
|
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | 1363 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1364 | 1364 | // Autres specifications comme ci-dessus |
| 1365 | 1365 | |
| 1366 | 1366 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, string $connect = '') { |
| 1367 | - static $trouver_table; |
|
| 1368 | - spip_timer('calcul_skel'); |
|
| 1369 | - |
|
| 1370 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1371 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1372 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1373 | - |
|
| 1374 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1375 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1376 | - } |
|
| 1377 | - } |
|
| 1378 | - foreach ($boucles as $id => $boucle) { |
|
| 1379 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1380 | - } |
|
| 1381 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1382 | - |
|
| 1383 | - // Demander la description des tables une fois pour toutes |
|
| 1384 | - if (!$trouver_table) { |
|
| 1385 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - // reperer si les doublons sont demandes |
|
| 1389 | - // pour un inclure ou une boucle document |
|
| 1390 | - // c'est utile a la fonction champs_traitements |
|
| 1391 | - foreach ($boucles as $id => $boucle) { |
|
| 1392 | - if (!($type = $boucle->type_requete)) { |
|
| 1393 | - continue; |
|
| 1394 | - } |
|
| 1395 | - if ( |
|
| 1396 | - !$descr['documents'] and ( |
|
| 1397 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1398 | - compile_inclure_doublons($boucle->avant) or |
|
| 1399 | - compile_inclure_doublons($boucle->apres) or |
|
| 1400 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1401 | - compile_inclure_doublons($boucle->altern)) |
|
| 1402 | - ) { |
|
| 1403 | - $descr['documents'] = true; |
|
| 1404 | - } |
|
| 1405 | - if ($type != TYPE_RECURSIF) { |
|
| 1406 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1407 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1408 | - } |
|
| 1409 | - |
|
| 1410 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1411 | - if ( |
|
| 1412 | - $g = charger_fonction( |
|
| 1413 | - preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1414 | - 'iterateur', |
|
| 1415 | - true |
|
| 1416 | - ) |
|
| 1417 | - ) { |
|
| 1418 | - $boucles[$id] = $g($boucle); |
|
| 1419 | - |
|
| 1420 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1421 | - // utiliser les informations donnees par le requeteur |
|
| 1422 | - // cas "php:xx" et "data:xx". |
|
| 1423 | - } else { |
|
| 1424 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1425 | - $requeteur($boucles, $boucle, $id); |
|
| 1426 | - |
|
| 1427 | - // utiliser la description des champs transmis |
|
| 1428 | - } else { |
|
| 1429 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1430 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1431 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1432 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1433 | - if ( |
|
| 1434 | - !$show |
|
| 1435 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1436 | - ) { |
|
| 1437 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1438 | - } |
|
| 1439 | - if ($show) { |
|
| 1440 | - $boucles[$id]->show = $show; |
|
| 1441 | - // recopie les infos les plus importantes |
|
| 1442 | - $boucles[$id]->primary = $show['key']['PRIMARY KEY'] ?? ''; |
|
| 1443 | - $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1444 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1445 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1446 | - |
|
| 1447 | - if (empty($boucles[$id]->descr)) { |
|
| 1448 | - $boucles[$id]->descr = &$descr; |
|
| 1449 | - } |
|
| 1450 | - if ( |
|
| 1451 | - (!$boucles[$id]->jointures) |
|
| 1452 | - and is_array($show['tables_jointures']) |
|
| 1453 | - and count($x = $show['tables_jointures']) |
|
| 1454 | - ) { |
|
| 1455 | - $boucles[$id]->jointures = $x; |
|
| 1456 | - } |
|
| 1457 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1458 | - $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1459 | - while ($j = array_pop($jointures)) { |
|
| 1460 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1461 | - } |
|
| 1462 | - } |
|
| 1463 | - } else { |
|
| 1464 | - // Pas une erreur si la table est optionnelle |
|
| 1465 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1466 | - $boucles[$id]->type_requete = ''; |
|
| 1467 | - } else { |
|
| 1468 | - $boucles[$id]->type_requete = false; |
|
| 1469 | - $boucle = $boucles[$id]; |
|
| 1470 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1471 | - ($boucle->sql_serveur . ':')) . |
|
| 1472 | - $type; |
|
| 1473 | - $msg = [ |
|
| 1474 | - 'zbug_table_inconnue', |
|
| 1475 | - ['table' => $x] |
|
| 1476 | - ]; |
|
| 1477 | - erreur_squelette($msg, $boucle); |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - } |
|
| 1481 | - } |
|
| 1482 | - } |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1486 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1487 | - foreach ($boucles as $id => $boucle) { |
|
| 1488 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1489 | - $boucles[$id]->descr = &$descr; |
|
| 1490 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1491 | - if (!$rec) { |
|
| 1492 | - $msg = [ |
|
| 1493 | - 'zbug_boucle_recursive_undef', |
|
| 1494 | - ['nom' => $boucle->param[0]] |
|
| 1495 | - ]; |
|
| 1496 | - erreur_squelette($msg, $boucle); |
|
| 1497 | - $boucles[$id]->type_requete = false; |
|
| 1498 | - } else { |
|
| 1499 | - $rec->externe = $id; |
|
| 1500 | - $descr['id_mere'] = $id; |
|
| 1501 | - $boucles[$id]->return = |
|
| 1502 | - calculer_liste( |
|
| 1503 | - [$rec], |
|
| 1504 | - $descr, |
|
| 1505 | - $boucles, |
|
| 1506 | - $boucle->param |
|
| 1507 | - ); |
|
| 1508 | - } |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - foreach ($boucles as $id => $boucle) { |
|
| 1512 | - $id = strval($id); // attention au type dans index_pile |
|
| 1513 | - $type = $boucle->type_requete; |
|
| 1514 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1515 | - $res = ''; |
|
| 1516 | - if ($boucle->param) { |
|
| 1517 | - // retourne un tableau en cas d'erreur |
|
| 1518 | - $res = calculer_criteres($id, $boucles); |
|
| 1519 | - } |
|
| 1520 | - $descr['id_mere'] = $id; |
|
| 1521 | - $boucles[$id]->return = |
|
| 1522 | - calculer_liste( |
|
| 1523 | - $boucle->milieu, |
|
| 1524 | - $descr, |
|
| 1525 | - $boucles, |
|
| 1526 | - $id |
|
| 1527 | - ); |
|
| 1528 | - // Si les criteres se sont mal compiles |
|
| 1529 | - // ne pas tenter d'assembler le code final |
|
| 1530 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1531 | - if (is_array($res)) { |
|
| 1532 | - $boucles[$id]->type_requete = false; |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - // idem pour la racine |
|
| 1538 | - $descr['id_mere'] = ''; |
|
| 1539 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1540 | - |
|
| 1541 | - |
|
| 1542 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1543 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1544 | - // de'terminables seulement maintenant |
|
| 1545 | - |
|
| 1546 | - foreach ($boucles as $id => $boucle) { |
|
| 1547 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1548 | - if ($boucle->return === false) { |
|
| 1549 | - $corps = false; |
|
| 1550 | - continue; |
|
| 1551 | - } |
|
| 1552 | - // appeler la fonction de definition de la boucle |
|
| 1553 | - |
|
| 1554 | - if ($req = $boucle->type_requete) { |
|
| 1555 | - // boucle personnalisée ? |
|
| 1556 | - $table = strtoupper($boucle->type_requete); |
|
| 1557 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1558 | - if ( |
|
| 1559 | - // fonction de boucle avec serveur & table |
|
| 1560 | - (!$serveur or |
|
| 1561 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1562 | - and (!function_exists($f = $f . '_dist')) |
|
| 1563 | - ) |
|
| 1564 | - ) |
|
| 1565 | - // fonction de boucle avec table |
|
| 1566 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1567 | - and (!function_exists($f = $f . '_dist')) |
|
| 1568 | - ) { |
|
| 1569 | - // fonction de boucle standard |
|
| 1570 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1571 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1572 | - } |
|
| 1573 | - } |
|
| 1574 | - |
|
| 1575 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1576 | - "static \$connect;\n\t" . |
|
| 1577 | - "\$command['connect'] = \$connect = " . |
|
| 1578 | - _q($boucle->sql_serveur) . |
|
| 1579 | - ';' . |
|
| 1580 | - $f($id, $boucles); |
|
| 1581 | - } else { |
|
| 1582 | - $req = ("\n\treturn '';"); |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - $boucles[$id]->return = |
|
| 1586 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1587 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1588 | - $req . |
|
| 1589 | - "\n}\n"; |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1593 | - // retourner False, sinon inserer leur decompilation |
|
| 1594 | - if (is_bool($corps)) { |
|
| 1595 | - return false; |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1367 | + static $trouver_table; |
|
| 1368 | + spip_timer('calcul_skel'); |
|
| 1369 | + |
|
| 1370 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1371 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1372 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1373 | + |
|
| 1374 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1375 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1376 | + } |
|
| 1377 | + } |
|
| 1378 | + foreach ($boucles as $id => $boucle) { |
|
| 1379 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1380 | + } |
|
| 1381 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1382 | + |
|
| 1383 | + // Demander la description des tables une fois pour toutes |
|
| 1384 | + if (!$trouver_table) { |
|
| 1385 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + // reperer si les doublons sont demandes |
|
| 1389 | + // pour un inclure ou une boucle document |
|
| 1390 | + // c'est utile a la fonction champs_traitements |
|
| 1391 | + foreach ($boucles as $id => $boucle) { |
|
| 1392 | + if (!($type = $boucle->type_requete)) { |
|
| 1393 | + continue; |
|
| 1394 | + } |
|
| 1395 | + if ( |
|
| 1396 | + !$descr['documents'] and ( |
|
| 1397 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1398 | + compile_inclure_doublons($boucle->avant) or |
|
| 1399 | + compile_inclure_doublons($boucle->apres) or |
|
| 1400 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1401 | + compile_inclure_doublons($boucle->altern)) |
|
| 1402 | + ) { |
|
| 1403 | + $descr['documents'] = true; |
|
| 1404 | + } |
|
| 1405 | + if ($type != TYPE_RECURSIF) { |
|
| 1406 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1407 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1408 | + } |
|
| 1409 | + |
|
| 1410 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1411 | + if ( |
|
| 1412 | + $g = charger_fonction( |
|
| 1413 | + preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1414 | + 'iterateur', |
|
| 1415 | + true |
|
| 1416 | + ) |
|
| 1417 | + ) { |
|
| 1418 | + $boucles[$id] = $g($boucle); |
|
| 1419 | + |
|
| 1420 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1421 | + // utiliser les informations donnees par le requeteur |
|
| 1422 | + // cas "php:xx" et "data:xx". |
|
| 1423 | + } else { |
|
| 1424 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1425 | + $requeteur($boucles, $boucle, $id); |
|
| 1426 | + |
|
| 1427 | + // utiliser la description des champs transmis |
|
| 1428 | + } else { |
|
| 1429 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1430 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1431 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1432 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1433 | + if ( |
|
| 1434 | + !$show |
|
| 1435 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1436 | + ) { |
|
| 1437 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1438 | + } |
|
| 1439 | + if ($show) { |
|
| 1440 | + $boucles[$id]->show = $show; |
|
| 1441 | + // recopie les infos les plus importantes |
|
| 1442 | + $boucles[$id]->primary = $show['key']['PRIMARY KEY'] ?? ''; |
|
| 1443 | + $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1444 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1445 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1446 | + |
|
| 1447 | + if (empty($boucles[$id]->descr)) { |
|
| 1448 | + $boucles[$id]->descr = &$descr; |
|
| 1449 | + } |
|
| 1450 | + if ( |
|
| 1451 | + (!$boucles[$id]->jointures) |
|
| 1452 | + and is_array($show['tables_jointures']) |
|
| 1453 | + and count($x = $show['tables_jointures']) |
|
| 1454 | + ) { |
|
| 1455 | + $boucles[$id]->jointures = $x; |
|
| 1456 | + } |
|
| 1457 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1458 | + $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1459 | + while ($j = array_pop($jointures)) { |
|
| 1460 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1461 | + } |
|
| 1462 | + } |
|
| 1463 | + } else { |
|
| 1464 | + // Pas une erreur si la table est optionnelle |
|
| 1465 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1466 | + $boucles[$id]->type_requete = ''; |
|
| 1467 | + } else { |
|
| 1468 | + $boucles[$id]->type_requete = false; |
|
| 1469 | + $boucle = $boucles[$id]; |
|
| 1470 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1471 | + ($boucle->sql_serveur . ':')) . |
|
| 1472 | + $type; |
|
| 1473 | + $msg = [ |
|
| 1474 | + 'zbug_table_inconnue', |
|
| 1475 | + ['table' => $x] |
|
| 1476 | + ]; |
|
| 1477 | + erreur_squelette($msg, $boucle); |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + } |
|
| 1481 | + } |
|
| 1482 | + } |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1486 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1487 | + foreach ($boucles as $id => $boucle) { |
|
| 1488 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1489 | + $boucles[$id]->descr = &$descr; |
|
| 1490 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1491 | + if (!$rec) { |
|
| 1492 | + $msg = [ |
|
| 1493 | + 'zbug_boucle_recursive_undef', |
|
| 1494 | + ['nom' => $boucle->param[0]] |
|
| 1495 | + ]; |
|
| 1496 | + erreur_squelette($msg, $boucle); |
|
| 1497 | + $boucles[$id]->type_requete = false; |
|
| 1498 | + } else { |
|
| 1499 | + $rec->externe = $id; |
|
| 1500 | + $descr['id_mere'] = $id; |
|
| 1501 | + $boucles[$id]->return = |
|
| 1502 | + calculer_liste( |
|
| 1503 | + [$rec], |
|
| 1504 | + $descr, |
|
| 1505 | + $boucles, |
|
| 1506 | + $boucle->param |
|
| 1507 | + ); |
|
| 1508 | + } |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + foreach ($boucles as $id => $boucle) { |
|
| 1512 | + $id = strval($id); // attention au type dans index_pile |
|
| 1513 | + $type = $boucle->type_requete; |
|
| 1514 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1515 | + $res = ''; |
|
| 1516 | + if ($boucle->param) { |
|
| 1517 | + // retourne un tableau en cas d'erreur |
|
| 1518 | + $res = calculer_criteres($id, $boucles); |
|
| 1519 | + } |
|
| 1520 | + $descr['id_mere'] = $id; |
|
| 1521 | + $boucles[$id]->return = |
|
| 1522 | + calculer_liste( |
|
| 1523 | + $boucle->milieu, |
|
| 1524 | + $descr, |
|
| 1525 | + $boucles, |
|
| 1526 | + $id |
|
| 1527 | + ); |
|
| 1528 | + // Si les criteres se sont mal compiles |
|
| 1529 | + // ne pas tenter d'assembler le code final |
|
| 1530 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1531 | + if (is_array($res)) { |
|
| 1532 | + $boucles[$id]->type_requete = false; |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + // idem pour la racine |
|
| 1538 | + $descr['id_mere'] = ''; |
|
| 1539 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1540 | + |
|
| 1541 | + |
|
| 1542 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1543 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1544 | + // de'terminables seulement maintenant |
|
| 1545 | + |
|
| 1546 | + foreach ($boucles as $id => $boucle) { |
|
| 1547 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1548 | + if ($boucle->return === false) { |
|
| 1549 | + $corps = false; |
|
| 1550 | + continue; |
|
| 1551 | + } |
|
| 1552 | + // appeler la fonction de definition de la boucle |
|
| 1553 | + |
|
| 1554 | + if ($req = $boucle->type_requete) { |
|
| 1555 | + // boucle personnalisée ? |
|
| 1556 | + $table = strtoupper($boucle->type_requete); |
|
| 1557 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1558 | + if ( |
|
| 1559 | + // fonction de boucle avec serveur & table |
|
| 1560 | + (!$serveur or |
|
| 1561 | + ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1562 | + and (!function_exists($f = $f . '_dist')) |
|
| 1563 | + ) |
|
| 1564 | + ) |
|
| 1565 | + // fonction de boucle avec table |
|
| 1566 | + and (!function_exists($f = 'boucle_' . $table)) |
|
| 1567 | + and (!function_exists($f = $f . '_dist')) |
|
| 1568 | + ) { |
|
| 1569 | + // fonction de boucle standard |
|
| 1570 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1571 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1572 | + } |
|
| 1573 | + } |
|
| 1574 | + |
|
| 1575 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1576 | + "static \$connect;\n\t" . |
|
| 1577 | + "\$command['connect'] = \$connect = " . |
|
| 1578 | + _q($boucle->sql_serveur) . |
|
| 1579 | + ';' . |
|
| 1580 | + $f($id, $boucles); |
|
| 1581 | + } else { |
|
| 1582 | + $req = ("\n\treturn '';"); |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + $boucles[$id]->return = |
|
| 1586 | + "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1587 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1588 | + $req . |
|
| 1589 | + "\n}\n"; |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1593 | + // retourner False, sinon inserer leur decompilation |
|
| 1594 | + if (is_bool($corps)) { |
|
| 1595 | + return false; |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1599 | 1599 | ' |
| 1600 | - // reporter de maniere securisee les doublons inclus |
|
| 1601 | - . ' |
|
| 1600 | + // reporter de maniere securisee les doublons inclus |
|
| 1601 | + . ' |
|
| 1602 | 1602 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1603 | 1603 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1604 | 1604 | |
| 1605 | 1605 | $connect = ' . |
| 1606 | - _q($connect) . '; |
|
| 1606 | + _q($connect) . '; |
|
| 1607 | 1607 | $page = ' . |
| 1608 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1609 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1610 | - // avant de referencer $Cache |
|
| 1611 | - $corps . '; |
|
| 1608 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1609 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1610 | + // avant de referencer $Cache |
|
| 1611 | + $corps . '; |
|
| 1612 | 1612 | |
| 1613 | 1613 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1614 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1614 | + . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1615 | 1615 | }'; |
| 1616 | 1616 | |
| 1617 | - $secondes = spip_timer('calcul_skel'); |
|
| 1618 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1619 | - // $connect n'est pas sûr : on nettoie |
|
| 1620 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1617 | + $secondes = spip_timer('calcul_skel'); |
|
| 1618 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1619 | + // $connect n'est pas sûr : on nettoie |
|
| 1620 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1621 | 1621 | |
| 1622 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1623 | - $code = new Boucle(); |
|
| 1624 | - $code->descr = $descr; |
|
| 1625 | - $code->return = ' |
|
| 1622 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1623 | + $code = new Boucle(); |
|
| 1624 | + $code->descr = $descr; |
|
| 1625 | + $code->return = ' |
|
| 1626 | 1626 | // |
| 1627 | 1627 | // Fonction principale du squelette ' . |
| 1628 | - $sourcefile . |
|
| 1629 | - ($connect ? " pour $connect" : '') . |
|
| 1630 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1631 | - "\n//\n" . |
|
| 1632 | - $principal; |
|
| 1628 | + $sourcefile . |
|
| 1629 | + ($connect ? " pour $connect" : '') . |
|
| 1630 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1631 | + "\n//\n" . |
|
| 1632 | + $principal; |
|
| 1633 | 1633 | |
| 1634 | - $boucles[''] = $code; |
|
| 1634 | + $boucles[''] = $code; |
|
| 1635 | 1635 | |
| 1636 | - return $boucles; |
|
| 1636 | + return $boucles; |
|
| 1637 | 1637 | } |
| 1638 | 1638 | |
| 1639 | 1639 | |
@@ -1650,18 +1650,18 @@ discard block |
||
| 1650 | 1650 | * |
| 1651 | 1651 | **/ |
| 1652 | 1652 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1653 | - if (class_exists($boucle->type_requete)) { |
|
| 1654 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1655 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1656 | - } else { |
|
| 1657 | - $x = $boucle->type_requete; |
|
| 1658 | - $boucle->type_requete = false; |
|
| 1659 | - $msg = [ |
|
| 1660 | - 'zbug_iterateur_inconnu', |
|
| 1661 | - ['iterateur' => $x] |
|
| 1662 | - ]; |
|
| 1663 | - erreur_squelette($msg, $boucle); |
|
| 1664 | - } |
|
| 1653 | + if (class_exists($boucle->type_requete)) { |
|
| 1654 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1655 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1656 | + } else { |
|
| 1657 | + $x = $boucle->type_requete; |
|
| 1658 | + $boucle->type_requete = false; |
|
| 1659 | + $msg = [ |
|
| 1660 | + 'zbug_iterateur_inconnu', |
|
| 1661 | + ['iterateur' => $x] |
|
| 1662 | + ]; |
|
| 1663 | + erreur_squelette($msg, $boucle); |
|
| 1664 | + } |
|
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | 1667 | |
@@ -1679,22 +1679,22 @@ discard block |
||
| 1679 | 1679 | * |
| 1680 | 1680 | **/ |
| 1681 | 1681 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1682 | - include_spip('iterateur/data'); |
|
| 1683 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1684 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1685 | - $boucles[$id] = $g($boucle); |
|
| 1686 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1687 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1688 | - } else { |
|
| 1689 | - $x = $boucle->type_requete; |
|
| 1690 | - $boucle->type_requete = false; |
|
| 1691 | - $msg = [ |
|
| 1692 | - 'zbug_requeteur_inconnu', |
|
| 1693 | - [ |
|
| 1694 | - 'requeteur' => 'data', |
|
| 1695 | - 'type' => $x |
|
| 1696 | - ] |
|
| 1697 | - ]; |
|
| 1698 | - erreur_squelette($msg, $boucle); |
|
| 1699 | - } |
|
| 1682 | + include_spip('iterateur/data'); |
|
| 1683 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1684 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1685 | + $boucles[$id] = $g($boucle); |
|
| 1686 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1687 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1688 | + } else { |
|
| 1689 | + $x = $boucle->type_requete; |
|
| 1690 | + $boucle->type_requete = false; |
|
| 1691 | + $msg = [ |
|
| 1692 | + 'zbug_requeteur_inconnu', |
|
| 1693 | + [ |
|
| 1694 | + 'requeteur' => 'data', |
|
| 1695 | + 'type' => $x |
|
| 1696 | + ] |
|
| 1697 | + ]; |
|
| 1698 | + erreur_squelette($msg, $boucle); |
|
| 1699 | + } |
|
| 1700 | 1700 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 121 | 121 | if ($var !== 1) { |
| 122 | 122 | $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
| 123 | - . $val . ($echap ? ") . '" : ' '); |
|
| 123 | + . $val.($echap ? ") . '" : ' '); |
|
| 124 | 124 | } else { |
| 125 | 125 | $val = $echap ? "'.$val.'" : $val; |
| 126 | 126 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | if (!$lang) { |
| 142 | 142 | $lang = '$GLOBALS["spip_lang"]'; |
| 143 | 143 | } |
| 144 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 144 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ").$lang.($echap ? ") . '" : ' '); |
|
| 145 | 145 | |
| 146 | 146 | return $l; |
| 147 | 147 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
| 172 | 172 | if (is_string($p->texte)) { |
| 173 | 173 | $fichier = $p->texte; |
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 174 | + $code = '"'.str_replace('"', '\"', $fichier).'"'; |
|
| 175 | 175 | } else { |
| 176 | 176 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
| 177 | 177 | if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | return false; |
| 221 | 221 | } // j'aurais voulu toucher le fond ... |
| 222 | 222 | |
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 223 | + $contexte = 'array('.$_contexte.')'; |
|
| 224 | 224 | |
| 225 | 225 | if ($env) { |
| 226 | 226 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | $_options[] = $ajax; |
| 236 | 236 | } |
| 237 | 237 | $code = " ' . argumenter_squelette($code) . '"; |
| 238 | - $code = 'echo ' . sprintf( |
|
| 238 | + $code = 'echo '.sprintf( |
|
| 239 | 239 | CODE_RECUPERER_FOND, |
| 240 | 240 | $code, |
| 241 | 241 | $contexte, |
| 242 | 242 | implode(',', $_options), |
| 243 | 243 | "_request(\\'connect\\') ?? \\'\\'" |
| 244 | - ) . ';'; |
|
| 244 | + ).';'; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 247 | + return "\n'<'.'".'?php '.$code."\n?'."."'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $id = $id_table; |
| 325 | 325 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 326 | 326 | } |
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 327 | + $mstatut = $id.'.'.$statut; |
|
| 328 | 328 | |
| 329 | 329 | $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
| 330 | 330 | include_spip('public/quete'); |
@@ -332,11 +332,11 @@ discard block |
||
| 332 | 332 | isset($s['post_date']) and $s['post_date'] |
| 333 | 333 | and $GLOBALS['meta']['post_dates'] == 'non' |
| 334 | 334 | ) { |
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 335 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | 336 | array_unshift( |
| 337 | 337 | $boucle->where, |
| 338 | 338 | $echapper ? |
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 339 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 340 | 340 | : |
| 341 | 341 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 342 | 342 | ); |
@@ -345,9 +345,9 @@ discard block |
||
| 345 | 345 | $boucle->where, |
| 346 | 346 | $echapper ? |
| 347 | 347 | "\nquete_condition_statut('$mstatut'," |
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 348 | + . _q($s['previsu']).',' |
|
| 349 | + . _q($s['publie']).',' |
|
| 350 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 351 | 351 | : |
| 352 | 352 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 353 | 353 | ); |
@@ -381,14 +381,14 @@ discard block |
||
| 381 | 381 | if (_request('var_mode_affiche') != 'resultat') { |
| 382 | 382 | $trace = ''; |
| 383 | 383 | } else { |
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 385 | 385 | $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
| 386 | 386 | $trace = " |
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | - $_trace" . '[] = $t0; |
|
| 391 | + $_trace".'[] = $t0; |
|
| 392 | 392 | }'; |
| 393 | 393 | } |
| 394 | 394 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | return |
| 423 | 423 | // Numrows[$nom] peut ne pas être encore defini |
| 424 | 424 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 425 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.';' |
|
| 426 | 426 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 427 | 427 | . $trace |
| 428 | 428 | . "\n\treturn \$t0;"; |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 491 | 491 | // et puis faire un [] plutot qu'un "','." |
| 492 | 492 | if ($boucle->doublons) { |
| 493 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 493 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 494 | 494 | index_pile($id_boucle, $primary, $boucles) |
| 495 | 495 | . "; // doublons\n"; |
| 496 | 496 | } |
@@ -518,13 +518,13 @@ discard block |
||
| 518 | 518 | $corps .= |
| 519 | 519 | "\n\t\tlang_select_public(" |
| 520 | 520 | . index_pile($id_boucle, 'lang', $boucles) |
| 521 | - . ", '" . $boucle->lang_select . "'" |
|
| 521 | + . ", '".$boucle->lang_select."'" |
|
| 522 | 522 | . (in_array($type_boucle, [ |
| 523 | 523 | 'articles', |
| 524 | 524 | 'rubriques', |
| 525 | 525 | 'hierarchie', |
| 526 | 526 | 'breves' |
| 527 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 527 | + ]) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 528 | 528 | . ');'; |
| 529 | 529 | } else { |
| 530 | 530 | $init_lang = ''; |
@@ -546,20 +546,16 @@ discard block |
||
| 546 | 546 | |
| 547 | 547 | // gestion optimale des separateurs et des boucles constantes |
| 548 | 548 | if (is_countable($boucle->separateur) ? count($boucle->separateur) : 0) { |
| 549 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 549 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | $corps .= |
| 553 | 553 | ((!$boucle->separateur) ? |
| 554 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 555 | - (($return === "''") ? '' : |
|
| 556 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 557 | - ("\n\t\t\$t1 " . |
|
| 554 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.';'))) : ("\n\t\t\$t1 ". |
|
| 558 | 555 | ((strpos($return, '$t1.') === 0) ? |
| 559 | - ('.=' . substr($return, 4)) : |
|
| 560 | - ('= ' . $return)) . |
|
| 561 | - ";\n\t\t" . |
|
| 562 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 556 | + ('.='.substr($return, 4)) : ('= '.$return)). |
|
| 557 | + ";\n\t\t". |
|
| 558 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 563 | 559 | |
| 564 | 560 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 565 | 561 | // souhaite invalider ces elements |
@@ -641,7 +637,7 @@ discard block |
||
| 641 | 637 | $corps, |
| 642 | 638 | $fin_lang, |
| 643 | 639 | $trace, |
| 644 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 640 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 645 | 641 | ); |
| 646 | 642 | |
| 647 | 643 | # var_dump($a);exit; |
@@ -662,25 +658,24 @@ discard block |
||
| 662 | 658 | **/ |
| 663 | 659 | function calculer_requete_sql($boucle) { |
| 664 | 660 | $init = []; |
| 665 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 666 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 661 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 662 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 667 | 663 | # En absence de champ c'est un decompte : |
| 668 | 664 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 669 | 665 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 670 | 666 | $init[] = calculer_dec( |
| 671 | 667 | 'groupby', |
| 672 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 668 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').')' |
|
| 673 | 669 | ); |
| 674 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 675 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 670 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select).'")'); |
|
| 671 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).')'); |
|
| 676 | 672 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 677 | 673 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 678 | 674 | $init[] = calculer_dec( |
| 679 | 675 | 'limit', |
| 680 | 676 | ( |
| 681 | 677 | strpos($boucle->limit, 'intval') === false ? |
| 682 | - "'" . ($boucle->limit) . "'" : |
|
| 683 | - $boucle->limit |
|
| 678 | + "'".($boucle->limit)."'" : $boucle->limit |
|
| 684 | 679 | ) |
| 685 | 680 | ); |
| 686 | 681 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
@@ -689,17 +684,17 @@ discard block |
||
| 689 | 684 | // ou recalculée à chaque passage (vide) |
| 690 | 685 | foreach ($init as $i) { |
| 691 | 686 | if (reset($i)) { |
| 692 | - $s .= "\n\t\t" . end($i); |
|
| 687 | + $s .= "\n\t\t".end($i); |
|
| 693 | 688 | } # statique |
| 694 | 689 | else { |
| 695 | - $d .= "\n\t" . end($i); |
|
| 690 | + $d .= "\n\t".end($i); |
|
| 696 | 691 | } # dynamique |
| 697 | 692 | } |
| 698 | 693 | |
| 699 | 694 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 700 | 695 | . $boucle->in |
| 701 | 696 | . $boucle->hash |
| 702 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 697 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 703 | 698 | . $s |
| 704 | 699 | . "\n\t}" |
| 705 | 700 | . $d; |
@@ -754,7 +749,7 @@ discard block |
||
| 754 | 749 | ]; |
| 755 | 750 | |
| 756 | 751 | $p->id_boucle = $context_compil[2] ?? ''; |
| 757 | - $p->ligne = (int)($context_compil[3] ?? 0); |
|
| 752 | + $p->ligne = (int) ($context_compil[3] ?? 0); |
|
| 758 | 753 | $p->lang = $context_compil[4] ?? ''; |
| 759 | 754 | |
| 760 | 755 | return $p; |
@@ -783,7 +778,7 @@ discard block |
||
| 783 | 778 | * - index 1 : Code de l'affectation |
| 784 | 779 | **/ |
| 785 | 780 | function calculer_dec($nom, $val) { |
| 786 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 781 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 787 | 782 | // si une variable apparait dans le calcul de la clause |
| 788 | 783 | // il faut la re-evaluer a chaque passage |
| 789 | 784 | if ( |
@@ -800,7 +795,7 @@ discard block |
||
| 800 | 795 | $static = ''; |
| 801 | 796 | } |
| 802 | 797 | |
| 803 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 798 | + return [$static, '$command[\''.$nom.'\'] = '.$val.';']; |
|
| 804 | 799 | } |
| 805 | 800 | |
| 806 | 801 | /** |
@@ -825,27 +820,27 @@ discard block |
||
| 825 | 820 | } |
| 826 | 821 | $res = ''; |
| 827 | 822 | if ($a and $a[0] == "'?'") { |
| 828 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 829 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 830 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 823 | + return ('('.calculer_dump_array($a[1]). |
|
| 824 | + ' ? '.calculer_dump_array($a[2]). |
|
| 825 | + ' : '.calculer_dump_array($a[3]). |
|
| 831 | 826 | ')'); |
| 832 | 827 | } else { |
| 833 | 828 | foreach ($a as $k => $v) { |
| 834 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 835 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 829 | + $showk = (is_numeric($k) ? '' : sql_quote($k).' => '); |
|
| 830 | + $res .= ', '.$showk.calculer_dump_array($v); |
|
| 836 | 831 | } |
| 837 | 832 | |
| 838 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 833 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 839 | 834 | } |
| 840 | 835 | } |
| 841 | 836 | |
| 842 | 837 | function calculer_dump_join($a) { |
| 843 | 838 | $res = ''; |
| 844 | 839 | foreach ($a as $k => $v) { |
| 845 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 840 | + $res .= ", '$k' => array(".implode(',', $v).')'; |
|
| 846 | 841 | } |
| 847 | 842 | |
| 848 | - return 'array(' . substr($res, 2) . ')'; |
|
| 843 | + return 'array('.substr($res, 2).')'; |
|
| 849 | 844 | } |
| 850 | 845 | |
| 851 | 846 | /** |
@@ -862,7 +857,7 @@ discard block |
||
| 862 | 857 | $res .= ",'$k' => '$v'"; |
| 863 | 858 | } |
| 864 | 859 | |
| 865 | - return 'array(' . substr($res, 1) . ')'; |
|
| 860 | + return 'array('.substr($res, 1).')'; |
|
| 866 | 861 | } |
| 867 | 862 | |
| 868 | 863 | /** |
@@ -880,7 +875,7 @@ discard block |
||
| 880 | 875 | $res .= ",'$k' => '$v'"; |
| 881 | 876 | } |
| 882 | 877 | |
| 883 | - return 'array(' . substr($res, 1) . ')'; |
|
| 878 | + return 'array('.substr($res, 1).')'; |
|
| 884 | 879 | } |
| 885 | 880 | |
| 886 | 881 | function calculer_order(&$boucle) { |
@@ -949,19 +944,19 @@ discard block |
||
| 949 | 944 | ) { |
| 950 | 945 | $res .= " .\n$tab$code"; |
| 951 | 946 | } else { |
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 947 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 953 | 948 | } |
| 954 | 949 | } |
| 955 | 950 | |
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 951 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 957 | 952 | } |
| 958 | 953 | } else { |
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ?: ''); |
|
| 954 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ?: ''); |
|
| 960 | 955 | |
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 956 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join( |
|
| 962 | 957 | " ,\n$tab", |
| 963 | 958 | $codes |
| 964 | - ) . ')))'; |
|
| 959 | + ).')))'; |
|
| 965 | 960 | } |
| 966 | 961 | } |
| 967 | 962 | |
@@ -988,7 +983,7 @@ discard block |
||
| 988 | 983 | // texte seul |
| 989 | 984 | case 'texte': |
| 990 | 985 | $code = sandbox_composer_texte($p->texte, $p); |
| 991 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 986 | + $commentaire = strlen($p->texte).' signes'; |
|
| 992 | 987 | $avant = ''; |
| 993 | 988 | $apres = ''; |
| 994 | 989 | $altern = "''"; |
@@ -997,14 +992,14 @@ discard block |
||
| 997 | 992 | case 'polyglotte': |
| 998 | 993 | $code = ''; |
| 999 | 994 | foreach ($p->traductions as $k => $v) { |
| 1000 | - $code .= ",'" . |
|
| 1001 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1002 | - "' => '" . |
|
| 1003 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 995 | + $code .= ",'". |
|
| 996 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k). |
|
| 997 | + "' => '". |
|
| 998 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v). |
|
| 1004 | 999 | "'"; |
| 1005 | 1000 | } |
| 1006 | - $code = 'choisir_traduction(array(' . |
|
| 1007 | - substr($code, 1) . |
|
| 1001 | + $code = 'choisir_traduction(array('. |
|
| 1002 | + substr($code, 1). |
|
| 1008 | 1003 | '))'; |
| 1009 | 1004 | $commentaire = '&'; |
| 1010 | 1005 | $avant = ''; |
@@ -1020,7 +1015,7 @@ discard block |
||
| 1020 | 1015 | $err_e_c = true; |
| 1021 | 1016 | $code = "''"; |
| 1022 | 1017 | } else { |
| 1023 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1018 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 1024 | 1019 | $avant = ''; |
| 1025 | 1020 | $apres = ''; |
| 1026 | 1021 | $altern = "''"; |
@@ -1049,8 +1044,8 @@ discard block |
||
| 1049 | 1044 | $err_e_c = true; |
| 1050 | 1045 | $code = "''"; |
| 1051 | 1046 | } else { |
| 1052 | - $code = 'BOUCLE' . |
|
| 1053 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1047 | + $code = 'BOUCLE'. |
|
| 1048 | + str_replace('-', '_', $nom).$descr['nom']. |
|
| 1054 | 1049 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1055 | 1050 | $commentaire = "?$nom"; |
| 1056 | 1051 | if ( |
@@ -1092,24 +1087,22 @@ discard block |
||
| 1092 | 1087 | foreach ($p->arg as $k => $v) { |
| 1093 | 1088 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1094 | 1089 | if ($k) { |
| 1095 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1090 | + $l[] = _q($k).' => '.$_v; |
|
| 1096 | 1091 | } else { |
| 1097 | 1092 | $code = $_v; |
| 1098 | 1093 | } |
| 1099 | 1094 | } |
| 1100 | 1095 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1101 | 1096 | if ($p->module) { |
| 1102 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1097 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1103 | 1098 | } elseif ($p->nom_champ) { |
| 1104 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1099 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1105 | 1100 | } else { |
| 1106 | 1101 | $m = ''; |
| 1107 | 1102 | } |
| 1108 | 1103 | |
| 1109 | - $code = (!$code ? "'$m'" : |
|
| 1110 | - ($m ? "'$m' . $code" : |
|
| 1111 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1112 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1104 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1105 | + . (!$l ? '' : (', array('.implode(",\n", $l).')')); |
|
| 1113 | 1106 | $code = "_T($code)"; |
| 1114 | 1107 | if ($p->param) { |
| 1115 | 1108 | $p->id_boucle = $id_boucle; |
@@ -1131,7 +1124,7 @@ discard block |
||
| 1131 | 1124 | $p->type_requete = $type; |
| 1132 | 1125 | |
| 1133 | 1126 | $code = calculer_champ($p); |
| 1134 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1127 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1135 | 1128 | $avant = calculer_liste( |
| 1136 | 1129 | $p->avant, |
| 1137 | 1130 | $descr, |
@@ -1171,10 +1164,9 @@ discard block |
||
| 1171 | 1164 | if ($code != "''") { |
| 1172 | 1165 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1173 | 1166 | $codes[] = (($mode == 'validation') ? |
| 1174 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1167 | + "array($code, '$commentaire', ".$p->ligne.')' |
|
| 1175 | 1168 | : (($mode == 'code') ? |
| 1176 | - "\n// $commentaire\n$code" : |
|
| 1177 | - $code)); |
|
| 1169 | + "\n// $commentaire\n$code" : $code)); |
|
| 1178 | 1170 | } |
| 1179 | 1171 | } // foreach |
| 1180 | 1172 | |
@@ -1230,19 +1222,19 @@ discard block |
||
| 1230 | 1222 | $cond = ''; |
| 1231 | 1223 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1232 | 1224 | $t = $r[2]; |
| 1233 | - $cond = '!' . $r[1]; |
|
| 1225 | + $cond = '!'.$r[1]; |
|
| 1234 | 1226 | } else { |
| 1235 | 1227 | if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
| 1236 | 1228 | $t = $r[2]; |
| 1237 | 1229 | $cond = $r[1]; |
| 1238 | 1230 | } else { |
| 1239 | - $t = '$t' . $n; |
|
| 1231 | + $t = '$t'.$n; |
|
| 1240 | 1232 | $cond = "($t = $code)!==''"; |
| 1241 | 1233 | } |
| 1242 | 1234 | } |
| 1243 | 1235 | |
| 1244 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1245 | - $t . |
|
| 1236 | + $res = (!$avant ? '' : "$avant . "). |
|
| 1237 | + $t. |
|
| 1246 | 1238 | (!$apres ? '' : " . $apres"); |
| 1247 | 1239 | |
| 1248 | 1240 | if ($res !== $t) { |
@@ -1293,12 +1285,12 @@ discard block |
||
| 1293 | 1285 | |
| 1294 | 1286 | // rendre inertes les echappements de #[](){}<> |
| 1295 | 1287 | $i = 0; |
| 1296 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1288 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1297 | 1289 | $i++; |
| 1298 | 1290 | } |
| 1299 | 1291 | $squelette = preg_replace_callback( |
| 1300 | 1292 | ',\\\\([#[()\]{}<>]),', |
| 1301 | - fn($a) => "$inerte-" . ord($a[1]) . '-', |
|
| 1293 | + fn($a) => "$inerte-".ord($a[1]).'-', |
|
| 1302 | 1294 | $squelette, |
| 1303 | 1295 | -1, |
| 1304 | 1296 | $esc |
@@ -1314,7 +1306,7 @@ discard block |
||
| 1314 | 1306 | // Phraser le squelette, selon sa grammaire |
| 1315 | 1307 | |
| 1316 | 1308 | $boucles = []; |
| 1317 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1309 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1318 | 1310 | |
| 1319 | 1311 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1320 | 1312 | |
@@ -1330,7 +1322,7 @@ discard block |
||
| 1330 | 1322 | ); |
| 1331 | 1323 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1332 | 1324 | ",$inerte-(\d+)-,", |
| 1333 | - fn($a) => '\\\\' . chr($a[1]), |
|
| 1325 | + fn($a) => '\\\\'.chr($a[1]), |
|
| 1334 | 1326 | $boucle->descr['squelette'] |
| 1335 | 1327 | ); |
| 1336 | 1328 | } |
@@ -1341,19 +1333,19 @@ discard block |
||
| 1341 | 1333 | include_spip('public/decompiler'); |
| 1342 | 1334 | foreach ($boucles as $id => $boucle) { |
| 1343 | 1335 | if ($id) { |
| 1344 | - $decomp = "\n/* BOUCLE " . |
|
| 1345 | - $boucle->type_requete . |
|
| 1346 | - ' ' . |
|
| 1347 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1348 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1336 | + $decomp = "\n/* BOUCLE ". |
|
| 1337 | + $boucle->type_requete. |
|
| 1338 | + ' '. |
|
| 1339 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1340 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1349 | 1341 | " */\n"; |
| 1350 | 1342 | } else { |
| 1351 | - $decomp = ("\n/*\n" . |
|
| 1343 | + $decomp = ("\n/*\n". |
|
| 1352 | 1344 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1353 | 1345 | . "\n*/"); |
| 1354 | 1346 | } |
| 1355 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1356 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1347 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1348 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1357 | 1349 | } |
| 1358 | 1350 | } |
| 1359 | 1351 | |
@@ -1376,7 +1368,7 @@ discard block |
||
| 1376 | 1368 | } |
| 1377 | 1369 | } |
| 1378 | 1370 | foreach ($boucles as $id => $boucle) { |
| 1379 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1371 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1380 | 1372 | } |
| 1381 | 1373 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1382 | 1374 | |
@@ -1467,8 +1459,7 @@ discard block |
||
| 1467 | 1459 | } else { |
| 1468 | 1460 | $boucles[$id]->type_requete = false; |
| 1469 | 1461 | $boucle = $boucles[$id]; |
| 1470 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1471 | - ($boucle->sql_serveur . ':')) . |
|
| 1462 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.':')). |
|
| 1472 | 1463 | $type; |
| 1473 | 1464 | $msg = [ |
| 1474 | 1465 | 'zbug_table_inconnue', |
@@ -1558,13 +1549,13 @@ discard block |
||
| 1558 | 1549 | if ( |
| 1559 | 1550 | // fonction de boucle avec serveur & table |
| 1560 | 1551 | (!$serveur or |
| 1561 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1562 | - and (!function_exists($f = $f . '_dist')) |
|
| 1552 | + ((!function_exists($f = 'boucle_'.$serveur.'_'.$table)) |
|
| 1553 | + and (!function_exists($f = $f.'_dist')) |
|
| 1563 | 1554 | ) |
| 1564 | 1555 | ) |
| 1565 | 1556 | // fonction de boucle avec table |
| 1566 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1567 | - and (!function_exists($f = $f . '_dist')) |
|
| 1557 | + and (!function_exists($f = 'boucle_'.$table)) |
|
| 1558 | + and (!function_exists($f = $f.'_dist')) |
|
| 1568 | 1559 | ) { |
| 1569 | 1560 | // fonction de boucle standard |
| 1570 | 1561 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1572,20 +1563,20 @@ discard block |
||
| 1572 | 1563 | } |
| 1573 | 1564 | } |
| 1574 | 1565 | |
| 1575 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1576 | - "static \$connect;\n\t" . |
|
| 1577 | - "\$command['connect'] = \$connect = " . |
|
| 1578 | - _q($boucle->sql_serveur) . |
|
| 1579 | - ';' . |
|
| 1566 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1567 | + "static \$connect;\n\t". |
|
| 1568 | + "\$command['connect'] = \$connect = ". |
|
| 1569 | + _q($boucle->sql_serveur). |
|
| 1570 | + ';'. |
|
| 1580 | 1571 | $f($id, $boucles); |
| 1581 | 1572 | } else { |
| 1582 | 1573 | $req = ("\n\treturn '';"); |
| 1583 | 1574 | } |
| 1584 | 1575 | |
| 1585 | 1576 | $boucles[$id]->return = |
| 1586 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1587 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1588 | - $req . |
|
| 1577 | + "\n\nfunction BOUCLE".strtr($id, '-', '_').$nom. |
|
| 1578 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1579 | + $req. |
|
| 1589 | 1580 | "\n}\n"; |
| 1590 | 1581 | } |
| 1591 | 1582 | |
@@ -1595,7 +1586,7 @@ discard block |
||
| 1595 | 1586 | return false; |
| 1596 | 1587 | } |
| 1597 | 1588 | |
| 1598 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1589 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1599 | 1590 | ' |
| 1600 | 1591 | // reporter de maniere securisee les doublons inclus |
| 1601 | 1592 | . ' |
@@ -1603,15 +1594,15 @@ discard block |
||
| 1603 | 1594 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1604 | 1595 | |
| 1605 | 1596 | $connect = ' . |
| 1606 | - _q($connect) . '; |
|
| 1597 | + _q($connect).'; |
|
| 1607 | 1598 | $page = ' . |
| 1608 | 1599 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1609 | 1600 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1610 | 1601 | // avant de referencer $Cache |
| 1611 | - $corps . '; |
|
| 1602 | + $corps.'; |
|
| 1612 | 1603 | |
| 1613 | 1604 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1614 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1605 | + . ', $Cache, $page, '.var_export($sourcefile, true).'); |
|
| 1615 | 1606 | }'; |
| 1616 | 1607 | |
| 1617 | 1608 | $secondes = spip_timer('calcul_skel'); |
@@ -1625,10 +1616,10 @@ discard block |
||
| 1625 | 1616 | $code->return = ' |
| 1626 | 1617 | // |
| 1627 | 1618 | // Fonction principale du squelette ' . |
| 1628 | - $sourcefile . |
|
| 1629 | - ($connect ? " pour $connect" : '') . |
|
| 1630 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1631 | - "\n//\n" . |
|
| 1619 | + $sourcefile. |
|
| 1620 | + ($connect ? " pour $connect" : ''). |
|
| 1621 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1622 | + "\n//\n". |
|
| 1632 | 1623 | $principal; |
| 1633 | 1624 | |
| 1634 | 1625 | $boucles[''] = $code; |
@@ -1680,7 +1671,7 @@ discard block |
||
| 1680 | 1671 | **/ |
| 1681 | 1672 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1682 | 1673 | include_spip('iterateur/data'); |
| 1683 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1674 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1684 | 1675 | $g = charger_fonction('data', 'iterateur'); |
| 1685 | 1676 | $boucles[$id] = $g($boucle); |
| 1686 | 1677 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -802,8 +802,7 @@ discard block |
||
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | 803 | if (is_null($fin)) { |
| 804 | 804 | return substr_count($texte, "\n", $debut); |
| 805 | - } |
|
| 806 | - else { |
|
| 805 | + } else { |
|
| 807 | 806 | return substr_count($texte, "\n", $debut, $fin - $debut); |
| 808 | 807 | } |
| 809 | 808 | } |
@@ -850,8 +849,7 @@ discard block |
||
| 850 | 849 | erreur_squelette($err_b, $result); |
| 851 | 850 | |
| 852 | 851 | continue; |
| 853 | - } |
|
| 854 | - else { |
|
| 852 | + } else { |
|
| 855 | 853 | $boucle = [ |
| 856 | 854 | 'id_boucle' => $id_boucle, |
| 857 | 855 | 'id_boucle_err' => $id_boucle, |
@@ -991,8 +989,7 @@ discard block |
||
| 991 | 989 | // si c'est un appel pour memoriser une boucle, memorisons la |
| 992 | 990 | if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
| 993 | 991 | $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
| 994 | - } |
|
| 995 | - else { |
|
| 992 | + } else { |
|
| 996 | 993 | if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
| 997 | 994 | $placeholder = $champ->nom_champ; |
| 998 | 995 | $id = reset($champ->param[0][1]); |
@@ -1135,8 +1132,7 @@ discard block |
||
| 1135 | 1132 | ]; |
| 1136 | 1133 | erreur_squelette($err_b, $result); |
| 1137 | 1134 | $pos_courante += strlen($fin_boucle); |
| 1138 | - } |
|
| 1139 | - else { |
|
| 1135 | + } else { |
|
| 1140 | 1136 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1141 | 1137 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1142 | 1138 | $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
@@ -48,19 +48,19 @@ discard block |
||
| 48 | 48 | * Nom d'une balise #TOTO |
| 49 | 49 | * |
| 50 | 50 | * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */ |
| 51 | -define('NOM_DE_CHAMP', '#((' . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 51 | +define('NOM_DE_CHAMP', '#(('.NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 52 | 52 | /** Balise complète [...(#TOTO) ... ] */ |
| 53 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 53 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 54 | 54 | |
| 55 | 55 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 56 | 56 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 57 | 57 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS'); |
| 58 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 58 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 59 | 59 | |
| 60 | 60 | /** Champ sql dans parenthèse ex: (id_article) */ |
| 61 | 61 | define('SQL_ARGS', '(\([^)]*\))'); |
| 62 | 62 | /** Fonction SQL sur un champ ex: SUM(visites) */ |
| 63 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 63 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 64 | 64 | |
| 65 | 65 | function phraser_inclure($texte, $ligne, $result) { |
| 66 | 66 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 218 | + while (preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match)) { |
|
| 219 | 219 | $p = strpos($texte, (string) $match[0]); |
| 220 | 220 | // texte après la balise |
| 221 | 221 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | $collecte[] = $champ; |
| 364 | 364 | $args = ltrim($regs[count($regs) - 1]); |
| 365 | 365 | } else { |
| 366 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 366 | + if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) { |
|
| 367 | 367 | // 0 est un aveu d'impuissance. A completer |
| 368 | 368 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 369 | 369 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 448 | 448 | $res = []; |
| 449 | 449 | while (($p = strpos($texte, (string) "%$sep")) !== false) { |
| 450 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | 451 | break; |
| 452 | 452 | } |
| 453 | 453 | $debut = substr($texte, 0, $p); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | $pos_apres = 0; |
| 488 | 488 | $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
| 489 | 489 | phraser_vieux($champ); |
| 490 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 490 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | 491 | $debut = substr($match[7], $pos_apres + 1); |
| 492 | 492 | if (!empty($debut)) { |
| 493 | 493 | $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 619 | 619 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 620 | 620 | $c = null; |
| 621 | - eval('$c = ' . $m[4] . ';'); |
|
| 621 | + eval('$c = '.$m[4].';'); |
|
| 622 | 622 | if (isset($c)) { |
| 623 | 623 | $m[4] = $c; |
| 624 | 624 | } |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 699 | 699 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 700 | 700 | } elseif ( |
| 701 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 701 | + preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 702 | 702 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
| 703 | 703 | ) { |
| 704 | 704 | $a2 = trim($m[8]); |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | ); |
| 716 | 716 | $crit->exclus = $m[1]; |
| 717 | 717 | } elseif ( |
| 718 | - preg_match('/^([!]?)\s*(' . |
|
| 719 | - CHAMP_SQL_PLUS_FONC . |
|
| 718 | + preg_match('/^([!]?)\s*('. |
|
| 719 | + CHAMP_SQL_PLUS_FONC. |
|
| 720 | 720 | ')\s*(\??)(.*)$/is', $param, $m) |
| 721 | 721 | ) { |
| 722 | 722 | // contient aussi les comparaisons implicites ! |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
| 864 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 864 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 865 | 865 | $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 866 | 866 | if ( |
| 867 | 867 | $pos_precond !== false |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 875 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 876 | 876 | $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 877 | 877 | if ( |
| 878 | 878 | $pos_preaff !== false |
@@ -920,13 +920,13 @@ discard block |
||
| 920 | 920 | $pos_anonyme_next = null; |
| 921 | 921 | // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
| 922 | 922 | if (!strlen($id_boucle)) { |
| 923 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 923 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE.'(', $pos_courante); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | // |
| 927 | 927 | // 1. Recuperer la partie conditionnelle apres |
| 928 | 928 | // |
| 929 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 929 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>'; |
|
| 930 | 930 | $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
| 931 | 931 | if ( |
| 932 | 932 | $pos_apres !== false |
@@ -935,13 +935,13 @@ discard block |
||
| 935 | 935 | $boucle['pos_postcond'] = $pos_apres; |
| 936 | 936 | $pos_apres += strlen($apres_boucle); |
| 937 | 937 | $boucle['pos_postcond_inside'] = $pos_apres; |
| 938 | - $pos_courante = $pos_apres ; |
|
| 938 | + $pos_courante = $pos_apres; |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | // |
| 942 | 942 | // 2. Récuperer la partie alternative apres |
| 943 | 943 | // |
| 944 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 944 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>'; |
|
| 945 | 945 | $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
| 946 | 946 | if ( |
| 947 | 947 | $pos_altern !== false |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | // |
| 957 | 957 | // 3. Recuperer la partie footer non alternative |
| 958 | 958 | // |
| 959 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 959 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>'; |
|
| 960 | 960 | $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
| 961 | 961 | if ( |
| 962 | 962 | $pos_postaff !== false |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | $boucle['pos_postaff'] = $pos_postaff; |
| 966 | 966 | $pos_postaff += strlen($postaff_boucle); |
| 967 | 967 | $boucle['pos_postaff_inside'] = $pos_postaff; |
| 968 | - $pos_courante = $pos_postaff ; |
|
| 968 | + $pos_courante = $pos_postaff; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | return $boucle; |
@@ -1005,7 +1005,7 @@ discard block |
||
| 1005 | 1005 | * @return string |
| 1006 | 1006 | */ |
| 1007 | 1007 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1008 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1008 | + $placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']'; |
|
| 1009 | 1009 | //memoriser la boucle a reinjecter |
| 1010 | 1010 | $id_boucle = "$id_boucle"; |
| 1011 | 1011 | phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
| 1019 | 1019 | if (is_null($boucle_placeholder)) { |
| 1020 | 1020 | do { |
| 1021 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1021 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid())); |
|
| 1022 | 1022 | } while (strpos($texte, $boucle_placeholder) !== false); |
| 1023 | 1023 | } |
| 1024 | 1024 | |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | |
| 1039 | 1039 | // boucle anonyme ? |
| 1040 | 1040 | if (!strlen($id_boucle)) { |
| 1041 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1041 | + $id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | $pos_debut_boucle = $pos_courante; |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | |
| 1052 | 1052 | $pos_avant = $boucle['pos_precond_inside']; |
| 1053 | 1053 | $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
| 1054 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1054 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | |
| 1061 | 1061 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 1062 | 1062 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 1063 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1063 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | $result->id_boucle = $id_boucle; |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | } else { |
| 1118 | 1118 | $pos_milieu += 1; |
| 1119 | 1119 | |
| 1120 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1120 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>'; |
|
| 1121 | 1121 | $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
| 1122 | 1122 | if ($pos_fin === false) { |
| 1123 | 1123 | $err_b = [ |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | else { |
| 1131 | 1131 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1132 | 1132 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1133 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1133 | + $search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'('; |
|
| 1134 | 1134 | $search_from = $pos_milieu; |
| 1135 | 1135 | $nb_open = 1; |
| 1136 | 1136 | $nb_close = 1; |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | if ($boucle['pos_postcond']) { |
| 1171 | 1171 | $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
| 1172 | 1172 | $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
| 1173 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1173 | + $pos_courante = $boucle['pos_postcond_inside']; |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | |
@@ -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 | /** Début de la partie principale d'une boucle */ |
@@ -64,82 +64,82 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function phraser_inclure($texte, $ligne, $result) { |
| 66 | 66 | |
| 67 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | - $match = array_pad($match, 3, null); |
|
| 69 | - $p = strpos($texte, (string) $match[0]); |
|
| 70 | - $debut = substr($texte, 0, $p); |
|
| 71 | - if ($p) { |
|
| 72 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | - } |
|
| 74 | - $ligne += substr_count($debut, "\n"); |
|
| 75 | - $champ = new Inclure(); |
|
| 76 | - $champ->ligne = $ligne; |
|
| 77 | - $ligne += substr_count($match[0], "\n"); |
|
| 78 | - $fichier = $match[2]; |
|
| 79 | - # assurer ici la migration .php3 => .php |
|
| 80 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | - $fichier = $r[1]; |
|
| 83 | - } |
|
| 84 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | - $pos_apres = 0; |
|
| 88 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | - if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | - if (!function_exists('normaliser_inclure')) { |
|
| 91 | - include_spip('public/normaliser'); |
|
| 92 | - } |
|
| 93 | - normaliser_inclure($champ); |
|
| 94 | - } |
|
| 95 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | - $result[] = $champ; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 67 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | + $match = array_pad($match, 3, null); |
|
| 69 | + $p = strpos($texte, (string) $match[0]); |
|
| 70 | + $debut = substr($texte, 0, $p); |
|
| 71 | + if ($p) { |
|
| 72 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | + } |
|
| 74 | + $ligne += substr_count($debut, "\n"); |
|
| 75 | + $champ = new Inclure(); |
|
| 76 | + $champ->ligne = $ligne; |
|
| 77 | + $ligne += substr_count($match[0], "\n"); |
|
| 78 | + $fichier = $match[2]; |
|
| 79 | + # assurer ici la migration .php3 => .php |
|
| 80 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | + $fichier = $r[1]; |
|
| 83 | + } |
|
| 84 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | + $pos_apres = 0; |
|
| 88 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | + if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | + if (!function_exists('normaliser_inclure')) { |
|
| 91 | + include_spip('public/normaliser'); |
|
| 92 | + } |
|
| 93 | + normaliser_inclure($champ); |
|
| 94 | + } |
|
| 95 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | + $result[] = $champ; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function phraser_polyglotte($texte, $ligne, $result) { |
| 104 | 104 | |
| 105 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | - foreach ($m as $match) { |
|
| 107 | - $p = strpos($texte, (string) $match[0]); |
|
| 108 | - $debut = substr($texte, 0, $p); |
|
| 109 | - if ($p) { |
|
| 110 | - $champ = new Texte(); |
|
| 111 | - $champ->texte = $debut; |
|
| 112 | - $champ->ligne = $ligne; |
|
| 113 | - $result[] = $champ; |
|
| 114 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $champ = new Polyglotte(); |
|
| 118 | - $champ->ligne = $ligne; |
|
| 119 | - $ligne += substr_count($match[0], "\n"); |
|
| 120 | - $lang = ''; |
|
| 121 | - $bloc = $match[1]; |
|
| 122 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | - $trad = $regs[1]; |
|
| 125 | - if ($trad or $lang) { |
|
| 126 | - $champ->traductions[$lang] = $trad; |
|
| 127 | - } |
|
| 128 | - $lang = $regs[2]; |
|
| 129 | - $bloc = $regs[3]; |
|
| 130 | - } |
|
| 131 | - $champ->traductions[$lang] = $bloc; |
|
| 132 | - $result[] = $champ; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if ($texte !== '') { |
|
| 136 | - $champ = new Texte(); |
|
| 137 | - $champ->texte = $texte; |
|
| 138 | - $champ->ligne = $ligne; |
|
| 139 | - $result[] = $champ; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $result; |
|
| 105 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | + foreach ($m as $match) { |
|
| 107 | + $p = strpos($texte, (string) $match[0]); |
|
| 108 | + $debut = substr($texte, 0, $p); |
|
| 109 | + if ($p) { |
|
| 110 | + $champ = new Texte(); |
|
| 111 | + $champ->texte = $debut; |
|
| 112 | + $champ->ligne = $ligne; |
|
| 113 | + $result[] = $champ; |
|
| 114 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $champ = new Polyglotte(); |
|
| 118 | + $champ->ligne = $ligne; |
|
| 119 | + $ligne += substr_count($match[0], "\n"); |
|
| 120 | + $lang = ''; |
|
| 121 | + $bloc = $match[1]; |
|
| 122 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | + $trad = $regs[1]; |
|
| 125 | + if ($trad or $lang) { |
|
| 126 | + $champ->traductions[$lang] = $trad; |
|
| 127 | + } |
|
| 128 | + $lang = $regs[2]; |
|
| 129 | + $bloc = $regs[3]; |
|
| 130 | + } |
|
| 131 | + $champ->traductions[$lang] = $bloc; |
|
| 132 | + $result[] = $champ; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if ($texte !== '') { |
|
| 136 | + $champ = new Texte(); |
|
| 137 | + $champ->texte = $texte; |
|
| 138 | + $champ->ligne = $ligne; |
|
| 139 | + $result[] = $champ; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $result; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -161,43 +161,43 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | **/ |
| 163 | 163 | function phraser_idiomes($texte, $ligne, $result) { |
| 164 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | - $match = array_pad($match, 8, null); |
|
| 166 | - $p = strpos($texte, (string) $match[0]); |
|
| 167 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | - if ($debut) { |
|
| 170 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | - } |
|
| 172 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | - $ligne += substr_count($debut, "\n"); |
|
| 174 | - if ($ko) { |
|
| 175 | - continue; |
|
| 176 | - } // faux idiome |
|
| 177 | - $champ = new Idiome(); |
|
| 178 | - $champ->ligne = $ligne; |
|
| 179 | - $ligne += substr_count($match[0], "\n"); |
|
| 180 | - // Stocker les arguments de la balise de traduction |
|
| 181 | - $args = []; |
|
| 182 | - $largs = $match[5]; |
|
| 183 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | - $largs = substr($largs, strlen($r[0])); |
|
| 186 | - } |
|
| 187 | - $champ->arg = $args; |
|
| 188 | - $champ->nom_champ = strtolower($match[3]); |
|
| 189 | - $champ->module = $match[2]; |
|
| 190 | - // pas d'imbrication pour les filtres sur langue |
|
| 191 | - $pos_apres = 0; |
|
| 192 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | - $result[] = $champ; |
|
| 195 | - } |
|
| 196 | - if ($texte !== '') { |
|
| 197 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $result; |
|
| 164 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | + $match = array_pad($match, 8, null); |
|
| 166 | + $p = strpos($texte, (string) $match[0]); |
|
| 167 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | + if ($debut) { |
|
| 170 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | + } |
|
| 172 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | + $ligne += substr_count($debut, "\n"); |
|
| 174 | + if ($ko) { |
|
| 175 | + continue; |
|
| 176 | + } // faux idiome |
|
| 177 | + $champ = new Idiome(); |
|
| 178 | + $champ->ligne = $ligne; |
|
| 179 | + $ligne += substr_count($match[0], "\n"); |
|
| 180 | + // Stocker les arguments de la balise de traduction |
|
| 181 | + $args = []; |
|
| 182 | + $largs = $match[5]; |
|
| 183 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | + $largs = substr($largs, strlen($r[0])); |
|
| 186 | + } |
|
| 187 | + $champ->arg = $args; |
|
| 188 | + $champ->nom_champ = strtolower($match[3]); |
|
| 189 | + $champ->module = $match[2]; |
|
| 190 | + // pas d'imbrication pour les filtres sur langue |
|
| 191 | + $pos_apres = 0; |
|
| 192 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | + $result[] = $champ; |
|
| 195 | + } |
|
| 196 | + if ($texte !== '') { |
|
| 197 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $result; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -215,47 +215,47 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | - $p = strpos($texte, (string) $match[0]); |
|
| 220 | - // texte après la balise |
|
| 221 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | - |
|
| 223 | - $debut = substr($texte, 0, $p); |
|
| 224 | - if ($p) { |
|
| 225 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | - } |
|
| 227 | - $ligne += substr_count($debut, "\n"); |
|
| 228 | - $champ = new Champ(); |
|
| 229 | - $champ->ligne = $ligne; |
|
| 230 | - $ligne += substr_count($match[0], "\n"); |
|
| 231 | - $champ->nom_boucle = $match[2]; |
|
| 232 | - $champ->nom_champ = $match[3]; |
|
| 233 | - $champ->etoile = $match[5]; |
|
| 234 | - |
|
| 235 | - if ($suite and $suite[0] == '{') { |
|
| 236 | - phraser_arg($suite, '', [], $champ); |
|
| 237 | - // ce ltrim est une ereur de conception |
|
| 238 | - // mais on le conserve par souci de compatibilite |
|
| 239 | - $texte = ltrim($suite); |
|
| 240 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 218 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | + $p = strpos($texte, (string) $match[0]); |
|
| 220 | + // texte après la balise |
|
| 221 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | + |
|
| 223 | + $debut = substr($texte, 0, $p); |
|
| 224 | + if ($p) { |
|
| 225 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | + } |
|
| 227 | + $ligne += substr_count($debut, "\n"); |
|
| 228 | + $champ = new Champ(); |
|
| 229 | + $champ->ligne = $ligne; |
|
| 230 | + $ligne += substr_count($match[0], "\n"); |
|
| 231 | + $champ->nom_boucle = $match[2]; |
|
| 232 | + $champ->nom_champ = $match[3]; |
|
| 233 | + $champ->etoile = $match[5]; |
|
| 234 | + |
|
| 235 | + if ($suite and $suite[0] == '{') { |
|
| 236 | + phraser_arg($suite, '', [], $champ); |
|
| 237 | + // ce ltrim est une ereur de conception |
|
| 238 | + // mais on le conserve par souci de compatibilite |
|
| 239 | + $texte = ltrim($suite); |
|
| 240 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 243 | 243 | if ($n = (strlen($suite) - strlen($texte))) { |
| 244 | 244 | $champ->apres = array(new Texte); |
| 245 | 245 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 246 | 246 | } |
| 247 | 247 | */ |
| 248 | - } else { |
|
| 249 | - $texte = $suite; |
|
| 250 | - } |
|
| 251 | - phraser_vieux($champ); |
|
| 252 | - $result[] = $champ; |
|
| 253 | - } |
|
| 254 | - if ($texte !== '') { |
|
| 255 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $result; |
|
| 248 | + } else { |
|
| 249 | + $texte = $suite; |
|
| 250 | + } |
|
| 251 | + phraser_vieux($champ); |
|
| 252 | + $result[] = $champ; |
|
| 253 | + } |
|
| 254 | + if ($texte !== '') { |
|
| 255 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $result; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Gestion des imbrications: |
@@ -264,15 +264,15 @@ discard block |
||
| 264 | 264 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 265 | 265 | |
| 266 | 266 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 267 | - if ($texte === '') { |
|
| 268 | - return $result; |
|
| 269 | - } |
|
| 270 | - $sep = '##'; |
|
| 271 | - while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | - $sep .= '#'; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 267 | + if ($texte === '') { |
|
| 268 | + return $result; |
|
| 269 | + } |
|
| 270 | + $sep = '##'; |
|
| 271 | + while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | + $sep .= '#'; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -291,275 +291,275 @@ discard block |
||
| 291 | 291 | * @return array |
| 292 | 292 | */ |
| 293 | 293 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 294 | - $length = strlen($texte); |
|
| 295 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | - $pos_debut++; |
|
| 297 | - } |
|
| 298 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | - $st = substr($texte, $pos_debut); |
|
| 301 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | - $pos_debut = $length - strlen($st); |
|
| 303 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | - $pos_debut++; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $result; |
|
| 294 | + $length = strlen($texte); |
|
| 295 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | + $pos_debut++; |
|
| 297 | + } |
|
| 298 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | + $st = substr($texte, $pos_debut); |
|
| 301 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | + $pos_debut = $length - strlen($st); |
|
| 303 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | + $pos_debut++; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $result; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 312 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | - $suite = ltrim($match[2]); |
|
| 314 | - $fonc = trim($match[1]); |
|
| 315 | - if ($fonc && $fonc[0] == '|') { |
|
| 316 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | - } |
|
| 318 | - $res = [$fonc]; |
|
| 319 | - $err_f = ''; |
|
| 320 | - // cas du filtre sans argument ou du critere / |
|
| 321 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | - if (!$match[1]) { |
|
| 324 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | - $texte = ''; |
|
| 327 | - } else { |
|
| 328 | - $texte = $suite; |
|
| 329 | - } |
|
| 330 | - if ($err_f) { |
|
| 331 | - $pointeur_champ->param = false; |
|
| 332 | - } elseif ($fonc !== '') { |
|
| 333 | - $pointeur_champ->param[] = $res; |
|
| 334 | - } |
|
| 335 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | - |
|
| 338 | - return $result; |
|
| 339 | - } |
|
| 340 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | - $collecte = []; |
|
| 342 | - while ($args && $args[0] != '}') { |
|
| 343 | - if ($args[0] == '"') { |
|
| 344 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | - } elseif ($args[0] == "'") { |
|
| 346 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | - } else { |
|
| 348 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | - $champ = new Texte(); |
|
| 353 | - $champ->apres = $champ->avant = $args = ''; |
|
| 354 | - break; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $arg = $regs[2]; |
|
| 358 | - if (trim($regs[1])) { |
|
| 359 | - $champ = new Texte(); |
|
| 360 | - $champ->texte = $arg; |
|
| 361 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | - $result[] = $champ; |
|
| 363 | - $collecte[] = $champ; |
|
| 364 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | - } else { |
|
| 366 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | - // 0 est un aveu d'impuissance. A completer |
|
| 368 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | - |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - $collecte = array_merge($collecte, $arg); |
|
| 372 | - $result = array_merge($result, $arg); |
|
| 373 | - } else { |
|
| 374 | - $n = strpos($args, (string) $r[0]); |
|
| 375 | - $pred = substr($args, 0, $n); |
|
| 376 | - $par = ',}'; |
|
| 377 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | - $pred = $m[1]; |
|
| 379 | - $par = ')'; |
|
| 380 | - } |
|
| 381 | - if ($pred) { |
|
| 382 | - $champ = new Texte(); |
|
| 383 | - $champ->texte = $pred; |
|
| 384 | - $champ->apres = $champ->avant = ''; |
|
| 385 | - $result[] = $champ; |
|
| 386 | - $collecte[] = $champ; |
|
| 387 | - } |
|
| 388 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | - $champ = new Champ(); |
|
| 390 | - $champ->nom_boucle = $r[2]; |
|
| 391 | - $champ->nom_champ = $r[3]; |
|
| 392 | - $champ->etoile = $r[5]; |
|
| 393 | - $next = $r[6]; |
|
| 394 | - while ($next == '{') { |
|
| 395 | - phraser_arg($rec, $sep, [], $champ); |
|
| 396 | - $args = ltrim($rec); |
|
| 397 | - $next = $args[0] ?? ''; |
|
| 398 | - } |
|
| 399 | - while ($next == '|') { |
|
| 400 | - $pos_apres = 0; |
|
| 401 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | - $args = substr($rec, $pos_apres); |
|
| 403 | - $next = $args[0] ?? ''; |
|
| 404 | - } |
|
| 405 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | - if ($champ->param === false) { |
|
| 407 | - $err_f = true; |
|
| 408 | - } else { |
|
| 409 | - phraser_vieux($champ); |
|
| 410 | - } |
|
| 411 | - if ($par == ')') { |
|
| 412 | - $args = substr($args, 1); |
|
| 413 | - } |
|
| 414 | - $collecte[] = $champ; |
|
| 415 | - $result[] = $champ; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | - $args = ltrim(substr($args, 1)); |
|
| 420 | - if ($collecte) { |
|
| 421 | - $res[] = $collecte; |
|
| 422 | - $collecte = []; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - $texte = substr($args, 1); |
|
| 431 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | - // propager les erreurs, et ignorer les param vides |
|
| 433 | - if ($pointeur_champ->param !== false) { |
|
| 434 | - if ($err_f) { |
|
| 435 | - $pointeur_champ->param = false; |
|
| 436 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | - $pointeur_champ->param[] = $res; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | - |
|
| 443 | - return $result; |
|
| 312 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | + $suite = ltrim($match[2]); |
|
| 314 | + $fonc = trim($match[1]); |
|
| 315 | + if ($fonc && $fonc[0] == '|') { |
|
| 316 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | + } |
|
| 318 | + $res = [$fonc]; |
|
| 319 | + $err_f = ''; |
|
| 320 | + // cas du filtre sans argument ou du critere / |
|
| 321 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | + if (!$match[1]) { |
|
| 324 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | + $texte = ''; |
|
| 327 | + } else { |
|
| 328 | + $texte = $suite; |
|
| 329 | + } |
|
| 330 | + if ($err_f) { |
|
| 331 | + $pointeur_champ->param = false; |
|
| 332 | + } elseif ($fonc !== '') { |
|
| 333 | + $pointeur_champ->param[] = $res; |
|
| 334 | + } |
|
| 335 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | + |
|
| 338 | + return $result; |
|
| 339 | + } |
|
| 340 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | + $collecte = []; |
|
| 342 | + while ($args && $args[0] != '}') { |
|
| 343 | + if ($args[0] == '"') { |
|
| 344 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | + } elseif ($args[0] == "'") { |
|
| 346 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | + } else { |
|
| 348 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | + $champ = new Texte(); |
|
| 353 | + $champ->apres = $champ->avant = $args = ''; |
|
| 354 | + break; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $arg = $regs[2]; |
|
| 358 | + if (trim($regs[1])) { |
|
| 359 | + $champ = new Texte(); |
|
| 360 | + $champ->texte = $arg; |
|
| 361 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | + $result[] = $champ; |
|
| 363 | + $collecte[] = $champ; |
|
| 364 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | + } else { |
|
| 366 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | + // 0 est un aveu d'impuissance. A completer |
|
| 368 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | + |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + $collecte = array_merge($collecte, $arg); |
|
| 372 | + $result = array_merge($result, $arg); |
|
| 373 | + } else { |
|
| 374 | + $n = strpos($args, (string) $r[0]); |
|
| 375 | + $pred = substr($args, 0, $n); |
|
| 376 | + $par = ',}'; |
|
| 377 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | + $pred = $m[1]; |
|
| 379 | + $par = ')'; |
|
| 380 | + } |
|
| 381 | + if ($pred) { |
|
| 382 | + $champ = new Texte(); |
|
| 383 | + $champ->texte = $pred; |
|
| 384 | + $champ->apres = $champ->avant = ''; |
|
| 385 | + $result[] = $champ; |
|
| 386 | + $collecte[] = $champ; |
|
| 387 | + } |
|
| 388 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | + $champ = new Champ(); |
|
| 390 | + $champ->nom_boucle = $r[2]; |
|
| 391 | + $champ->nom_champ = $r[3]; |
|
| 392 | + $champ->etoile = $r[5]; |
|
| 393 | + $next = $r[6]; |
|
| 394 | + while ($next == '{') { |
|
| 395 | + phraser_arg($rec, $sep, [], $champ); |
|
| 396 | + $args = ltrim($rec); |
|
| 397 | + $next = $args[0] ?? ''; |
|
| 398 | + } |
|
| 399 | + while ($next == '|') { |
|
| 400 | + $pos_apres = 0; |
|
| 401 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | + $args = substr($rec, $pos_apres); |
|
| 403 | + $next = $args[0] ?? ''; |
|
| 404 | + } |
|
| 405 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | + if ($champ->param === false) { |
|
| 407 | + $err_f = true; |
|
| 408 | + } else { |
|
| 409 | + phraser_vieux($champ); |
|
| 410 | + } |
|
| 411 | + if ($par == ')') { |
|
| 412 | + $args = substr($args, 1); |
|
| 413 | + } |
|
| 414 | + $collecte[] = $champ; |
|
| 415 | + $result[] = $champ; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | + $args = ltrim(substr($args, 1)); |
|
| 420 | + if ($collecte) { |
|
| 421 | + $res[] = $collecte; |
|
| 422 | + $collecte = []; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + $texte = substr($args, 1); |
|
| 431 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | + // propager les erreurs, et ignorer les param vides |
|
| 433 | + if ($pointeur_champ->param !== false) { |
|
| 434 | + if ($err_f) { |
|
| 435 | + $pointeur_champ->param = false; |
|
| 436 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | + $pointeur_champ->param[] = $res; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | + |
|
| 443 | + return $result; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
| 447 | 447 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 448 | - $res = []; |
|
| 449 | - while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | - break; |
|
| 452 | - } |
|
| 453 | - $debut = substr($texte, 0, $p); |
|
| 454 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | - if ($p) { |
|
| 456 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | - } |
|
| 458 | - $ligne += substr_count($debut, "\n"); |
|
| 459 | - $res[] = $nested[$m[1]]; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 448 | + $res = []; |
|
| 449 | + while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | + break; |
|
| 452 | + } |
|
| 453 | + $debut = substr($texte, 0, $p); |
|
| 454 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | + if ($p) { |
|
| 456 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | + } |
|
| 458 | + $ligne += substr_count($debut, "\n"); |
|
| 459 | + $res[] = $nested[$m[1]]; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 466 | - $i = 0; // en fait count($result) |
|
| 467 | - $x = ''; |
|
| 468 | - |
|
| 469 | - while (true) { |
|
| 470 | - $j = $i; |
|
| 471 | - $n = $ligne; |
|
| 472 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | - $p = strpos($texte, (string) $match[0]); |
|
| 474 | - $debut = substr($texte, 0, $p); |
|
| 475 | - if ($p) { |
|
| 476 | - $result[$i] = $debut; |
|
| 477 | - $i++; |
|
| 478 | - } |
|
| 479 | - $nom = $match[4]; |
|
| 480 | - $champ = new Champ(); |
|
| 481 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | - $champ->nom_boucle = $match[3]; |
|
| 484 | - $champ->nom_champ = $nom; |
|
| 485 | - $champ->etoile = $match[6]; |
|
| 486 | - // phraser_args indiquera ou commence apres |
|
| 487 | - $pos_apres = 0; |
|
| 488 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | - phraser_vieux($champ); |
|
| 490 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | - if (!empty($debut)) { |
|
| 493 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | - } |
|
| 495 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | - |
|
| 497 | - // reinjecter la boucle si c'en est une |
|
| 498 | - phraser_boucle_placeholder($champ); |
|
| 499 | - |
|
| 500 | - $result[$i] = $champ; |
|
| 501 | - $i++; |
|
| 502 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | - } |
|
| 504 | - if ($texte !== '') { |
|
| 505 | - $result[$i] = $texte; |
|
| 506 | - $i++; |
|
| 507 | - } |
|
| 508 | - $x = ''; |
|
| 509 | - |
|
| 510 | - while ($j < $i) { |
|
| 511 | - $z = $result[$j]; |
|
| 512 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | - if (is_object($z)) { |
|
| 514 | - $x .= "%$sep$j@"; |
|
| 515 | - } else { |
|
| 516 | - $x .= $z; |
|
| 517 | - } |
|
| 518 | - $j++; |
|
| 519 | - } |
|
| 520 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | - $texte = $x; |
|
| 522 | - } else { |
|
| 523 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | - } |
|
| 525 | - } |
|
| 466 | + $i = 0; // en fait count($result) |
|
| 467 | + $x = ''; |
|
| 468 | + |
|
| 469 | + while (true) { |
|
| 470 | + $j = $i; |
|
| 471 | + $n = $ligne; |
|
| 472 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | + $p = strpos($texte, (string) $match[0]); |
|
| 474 | + $debut = substr($texte, 0, $p); |
|
| 475 | + if ($p) { |
|
| 476 | + $result[$i] = $debut; |
|
| 477 | + $i++; |
|
| 478 | + } |
|
| 479 | + $nom = $match[4]; |
|
| 480 | + $champ = new Champ(); |
|
| 481 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | + $champ->nom_boucle = $match[3]; |
|
| 484 | + $champ->nom_champ = $nom; |
|
| 485 | + $champ->etoile = $match[6]; |
|
| 486 | + // phraser_args indiquera ou commence apres |
|
| 487 | + $pos_apres = 0; |
|
| 488 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | + phraser_vieux($champ); |
|
| 490 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | + if (!empty($debut)) { |
|
| 493 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | + } |
|
| 495 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | + |
|
| 497 | + // reinjecter la boucle si c'en est une |
|
| 498 | + phraser_boucle_placeholder($champ); |
|
| 499 | + |
|
| 500 | + $result[$i] = $champ; |
|
| 501 | + $i++; |
|
| 502 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | + } |
|
| 504 | + if ($texte !== '') { |
|
| 505 | + $result[$i] = $texte; |
|
| 506 | + $i++; |
|
| 507 | + } |
|
| 508 | + $x = ''; |
|
| 509 | + |
|
| 510 | + while ($j < $i) { |
|
| 511 | + $z = $result[$j]; |
|
| 512 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | + if (is_object($z)) { |
|
| 514 | + $x .= "%$sep$j@"; |
|
| 515 | + } else { |
|
| 516 | + $x .= $z; |
|
| 517 | + } |
|
| 518 | + $j++; |
|
| 519 | + } |
|
| 520 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | + $texte = $x; |
|
| 522 | + } else { |
|
| 523 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | function phraser_vieux(&$champ) { |
| 529 | - $nom = $champ->nom_champ; |
|
| 530 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | - include_spip('public/normaliser'); |
|
| 533 | - } |
|
| 534 | - phraser_vieux_emb($champ); |
|
| 535 | - } elseif ($nom == 'EXPOSER') { |
|
| 536 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | - include_spip('public/normaliser'); |
|
| 538 | - } |
|
| 539 | - phraser_vieux_exposer($champ); |
|
| 540 | - } elseif ($champ->param) { |
|
| 541 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | - include_spip('public/normaliser'); |
|
| 544 | - } |
|
| 545 | - phraser_vieux_recherche($champ); |
|
| 546 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | - include_spip('public/normaliser'); |
|
| 549 | - } |
|
| 550 | - phraser_vieux_logos($champ); |
|
| 551 | - } elseif ($nom == 'MODELE') { |
|
| 552 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | - include_spip('public/normaliser'); |
|
| 554 | - } |
|
| 555 | - phraser_vieux_modele($champ); |
|
| 556 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | - include_spip('public/normaliser'); |
|
| 559 | - } |
|
| 560 | - phraser_vieux_inclu($champ); |
|
| 561 | - } |
|
| 562 | - } |
|
| 529 | + $nom = $champ->nom_champ; |
|
| 530 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | + include_spip('public/normaliser'); |
|
| 533 | + } |
|
| 534 | + phraser_vieux_emb($champ); |
|
| 535 | + } elseif ($nom == 'EXPOSER') { |
|
| 536 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | + include_spip('public/normaliser'); |
|
| 538 | + } |
|
| 539 | + phraser_vieux_exposer($champ); |
|
| 540 | + } elseif ($champ->param) { |
|
| 541 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | + include_spip('public/normaliser'); |
|
| 544 | + } |
|
| 545 | + phraser_vieux_recherche($champ); |
|
| 546 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | + include_spip('public/normaliser'); |
|
| 549 | + } |
|
| 550 | + phraser_vieux_logos($champ); |
|
| 551 | + } elseif ($nom == 'MODELE') { |
|
| 552 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | + include_spip('public/normaliser'); |
|
| 554 | + } |
|
| 555 | + phraser_vieux_modele($champ); |
|
| 556 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | + include_spip('public/normaliser'); |
|
| 559 | + } |
|
| 560 | + phraser_vieux_inclu($champ); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | |
@@ -587,200 +587,200 @@ discard block |
||
| 587 | 587 | **/ |
| 588 | 588 | function phraser_criteres($params, &$result) { |
| 589 | 589 | |
| 590 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | - $args = []; |
|
| 592 | - $type = $result->type_requete; |
|
| 593 | - $doublons = []; |
|
| 594 | - foreach ($params as $v) { |
|
| 595 | - $var = $v[1][0]; |
|
| 596 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | - // plus d'un argument et pas le critere IN: |
|
| 599 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | - if ( |
|
| 601 | - $var->type != 'texte' |
|
| 602 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | - ) { |
|
| 604 | - $op = ','; |
|
| 605 | - $not = false; |
|
| 606 | - $cond = false; |
|
| 607 | - } else { |
|
| 608 | - // Le debut du premier argument est l'operateur |
|
| 609 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | - $op = $m[2]; |
|
| 611 | - $not = (bool) $m[1]; |
|
| 612 | - $cond = $m[3]; |
|
| 613 | - // virer le premier argument, |
|
| 614 | - // et mettre son reliquat eventuel |
|
| 615 | - // Recopier pour ne pas alterer le texte source |
|
| 616 | - // utile au debusqueur |
|
| 617 | - if ($m[4]) { |
|
| 618 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | - $c = null; |
|
| 621 | - eval('$c = ' . $m[4] . ';'); |
|
| 622 | - if (isset($c)) { |
|
| 623 | - $m[4] = $c; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - $texte = new Texte(); |
|
| 627 | - $texte->texte = $m[4]; |
|
| 628 | - $v[1][0] = $texte; |
|
| 629 | - } else { |
|
| 630 | - array_shift($v[1]); |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - array_shift($v); // $v[O] est vide |
|
| 634 | - $crit = new Critere(); |
|
| 635 | - $crit->op = $op; |
|
| 636 | - $crit->not = $not; |
|
| 637 | - $crit->cond = $cond; |
|
| 638 | - $crit->exclus = ''; |
|
| 639 | - $crit->param = $v; |
|
| 640 | - $args[] = $crit; |
|
| 641 | - } else { |
|
| 642 | - if ($var->type != 'texte') { |
|
| 643 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | - // erreur ou critere infixe "/" |
|
| 645 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | - $err_ci = [ |
|
| 647 | - 'zbug_critere_inconnu', |
|
| 648 | - ['critere' => $var->nom_champ] |
|
| 649 | - ]; |
|
| 650 | - erreur_squelette($err_ci, $result); |
|
| 651 | - } else { |
|
| 652 | - $crit = new Critere(); |
|
| 653 | - $crit->op = '/'; |
|
| 654 | - $crit->not = false; |
|
| 655 | - $crit->exclus = ''; |
|
| 656 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | - $args[] = $crit; |
|
| 658 | - } |
|
| 659 | - } else { |
|
| 660 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | - // les separateurs |
|
| 662 | - if ($var->apres) { |
|
| 663 | - $result->separateur[] = $param; |
|
| 664 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | - $result->modificateur['tout'] = true; |
|
| 666 | - } elseif ($param == 'plat') { |
|
| 667 | - $result->modificateur['plat'] = true; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | - // ceux-ci pour avoir la rubrique mere... |
|
| 673 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | - // traités normalement. |
|
| 675 | - elseif ( |
|
| 676 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | - ) { |
|
| 680 | - $result->modificateur['tout'] = true; |
|
| 681 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | - // rien a faire sur {id_rubrique} tout seul |
|
| 683 | - } else { |
|
| 684 | - // pas d'emplacement statique, faut un dynamique |
|
| 685 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | - // cette variable sera inseree dans le code |
|
| 688 | - // et son nom sert d'indicateur des maintenant |
|
| 689 | - $result->doublons = '$doublons_index'; |
|
| 690 | - if ($param == 'unique') { |
|
| 691 | - $param = 'doublons'; |
|
| 692 | - } |
|
| 693 | - } elseif ($param == 'recherche') { |
|
| 694 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | - $result->hash = ' '; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | - } elseif ( |
|
| 701 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | - ) { |
|
| 704 | - $a2 = trim($m[8]); |
|
| 705 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | - $a2 = substr($a2, 1, -1); |
|
| 707 | - } |
|
| 708 | - $crit = phraser_critere_infixe( |
|
| 709 | - $m[2], |
|
| 710 | - $a2, |
|
| 711 | - $v, |
|
| 712 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | - $m[6], |
|
| 714 | - $m[5] |
|
| 715 | - ); |
|
| 716 | - $crit->exclus = $m[1]; |
|
| 717 | - } elseif ( |
|
| 718 | - preg_match('/^([!]?)\s*(' . |
|
| 719 | - CHAMP_SQL_PLUS_FONC . |
|
| 720 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | - ) { |
|
| 722 | - // contient aussi les comparaisons implicites ! |
|
| 723 | - // Comme ci-dessus: |
|
| 724 | - // le premier arg contient l'operateur |
|
| 725 | - array_shift($v); |
|
| 726 | - if ($m[6]) { |
|
| 727 | - $v[0][0] = new Texte(); |
|
| 728 | - $v[0][0]->texte = $m[6]; |
|
| 729 | - } else { |
|
| 730 | - array_shift($v[0]); |
|
| 731 | - if (!$v[0]) { |
|
| 732 | - array_shift($v); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - $crit = new Critere(); |
|
| 736 | - $crit->op = $m[2]; |
|
| 737 | - $crit->param = $v; |
|
| 738 | - $crit->not = (bool) $m[1]; |
|
| 739 | - $crit->cond = $m[5]; |
|
| 740 | - } else { |
|
| 741 | - $err_ci = [ |
|
| 742 | - 'zbug_critere_inconnu', |
|
| 743 | - ['critere' => $param] |
|
| 744 | - ]; |
|
| 745 | - erreur_squelette($err_ci, $result); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | - $args[] = $crit; |
|
| 750 | - } else { |
|
| 751 | - $doublons[] = $crit; |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - // les doublons non nies doivent etre le dernier critere |
|
| 759 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | - // cf critere_doublon |
|
| 761 | - if ($doublons) { |
|
| 762 | - $args = [...$args, ...$doublons]; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | - if (!$err_ci) { |
|
| 767 | - $result->criteres = $args; |
|
| 768 | - } |
|
| 590 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | + $args = []; |
|
| 592 | + $type = $result->type_requete; |
|
| 593 | + $doublons = []; |
|
| 594 | + foreach ($params as $v) { |
|
| 595 | + $var = $v[1][0]; |
|
| 596 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | + // plus d'un argument et pas le critere IN: |
|
| 599 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | + if ( |
|
| 601 | + $var->type != 'texte' |
|
| 602 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | + ) { |
|
| 604 | + $op = ','; |
|
| 605 | + $not = false; |
|
| 606 | + $cond = false; |
|
| 607 | + } else { |
|
| 608 | + // Le debut du premier argument est l'operateur |
|
| 609 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | + $op = $m[2]; |
|
| 611 | + $not = (bool) $m[1]; |
|
| 612 | + $cond = $m[3]; |
|
| 613 | + // virer le premier argument, |
|
| 614 | + // et mettre son reliquat eventuel |
|
| 615 | + // Recopier pour ne pas alterer le texte source |
|
| 616 | + // utile au debusqueur |
|
| 617 | + if ($m[4]) { |
|
| 618 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | + $c = null; |
|
| 621 | + eval('$c = ' . $m[4] . ';'); |
|
| 622 | + if (isset($c)) { |
|
| 623 | + $m[4] = $c; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + $texte = new Texte(); |
|
| 627 | + $texte->texte = $m[4]; |
|
| 628 | + $v[1][0] = $texte; |
|
| 629 | + } else { |
|
| 630 | + array_shift($v[1]); |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + array_shift($v); // $v[O] est vide |
|
| 634 | + $crit = new Critere(); |
|
| 635 | + $crit->op = $op; |
|
| 636 | + $crit->not = $not; |
|
| 637 | + $crit->cond = $cond; |
|
| 638 | + $crit->exclus = ''; |
|
| 639 | + $crit->param = $v; |
|
| 640 | + $args[] = $crit; |
|
| 641 | + } else { |
|
| 642 | + if ($var->type != 'texte') { |
|
| 643 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | + // erreur ou critere infixe "/" |
|
| 645 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | + $err_ci = [ |
|
| 647 | + 'zbug_critere_inconnu', |
|
| 648 | + ['critere' => $var->nom_champ] |
|
| 649 | + ]; |
|
| 650 | + erreur_squelette($err_ci, $result); |
|
| 651 | + } else { |
|
| 652 | + $crit = new Critere(); |
|
| 653 | + $crit->op = '/'; |
|
| 654 | + $crit->not = false; |
|
| 655 | + $crit->exclus = ''; |
|
| 656 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | + $args[] = $crit; |
|
| 658 | + } |
|
| 659 | + } else { |
|
| 660 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | + // les separateurs |
|
| 662 | + if ($var->apres) { |
|
| 663 | + $result->separateur[] = $param; |
|
| 664 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | + $result->modificateur['tout'] = true; |
|
| 666 | + } elseif ($param == 'plat') { |
|
| 667 | + $result->modificateur['plat'] = true; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | + // ceux-ci pour avoir la rubrique mere... |
|
| 673 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | + // traités normalement. |
|
| 675 | + elseif ( |
|
| 676 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | + ) { |
|
| 680 | + $result->modificateur['tout'] = true; |
|
| 681 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | + // rien a faire sur {id_rubrique} tout seul |
|
| 683 | + } else { |
|
| 684 | + // pas d'emplacement statique, faut un dynamique |
|
| 685 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | + // cette variable sera inseree dans le code |
|
| 688 | + // et son nom sert d'indicateur des maintenant |
|
| 689 | + $result->doublons = '$doublons_index'; |
|
| 690 | + if ($param == 'unique') { |
|
| 691 | + $param = 'doublons'; |
|
| 692 | + } |
|
| 693 | + } elseif ($param == 'recherche') { |
|
| 694 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | + $result->hash = ' '; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | + } elseif ( |
|
| 701 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | + ) { |
|
| 704 | + $a2 = trim($m[8]); |
|
| 705 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | + $a2 = substr($a2, 1, -1); |
|
| 707 | + } |
|
| 708 | + $crit = phraser_critere_infixe( |
|
| 709 | + $m[2], |
|
| 710 | + $a2, |
|
| 711 | + $v, |
|
| 712 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | + $m[6], |
|
| 714 | + $m[5] |
|
| 715 | + ); |
|
| 716 | + $crit->exclus = $m[1]; |
|
| 717 | + } elseif ( |
|
| 718 | + preg_match('/^([!]?)\s*(' . |
|
| 719 | + CHAMP_SQL_PLUS_FONC . |
|
| 720 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | + ) { |
|
| 722 | + // contient aussi les comparaisons implicites ! |
|
| 723 | + // Comme ci-dessus: |
|
| 724 | + // le premier arg contient l'operateur |
|
| 725 | + array_shift($v); |
|
| 726 | + if ($m[6]) { |
|
| 727 | + $v[0][0] = new Texte(); |
|
| 728 | + $v[0][0]->texte = $m[6]; |
|
| 729 | + } else { |
|
| 730 | + array_shift($v[0]); |
|
| 731 | + if (!$v[0]) { |
|
| 732 | + array_shift($v); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + $crit = new Critere(); |
|
| 736 | + $crit->op = $m[2]; |
|
| 737 | + $crit->param = $v; |
|
| 738 | + $crit->not = (bool) $m[1]; |
|
| 739 | + $crit->cond = $m[5]; |
|
| 740 | + } else { |
|
| 741 | + $err_ci = [ |
|
| 742 | + 'zbug_critere_inconnu', |
|
| 743 | + ['critere' => $param] |
|
| 744 | + ]; |
|
| 745 | + erreur_squelette($err_ci, $result); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | + $args[] = $crit; |
|
| 750 | + } else { |
|
| 751 | + $doublons[] = $crit; |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + // les doublons non nies doivent etre le dernier critere |
|
| 759 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | + // cf critere_doublon |
|
| 761 | + if ($doublons) { |
|
| 762 | + $args = [...$args, ...$doublons]; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | + if (!$err_ci) { |
|
| 767 | + $result->criteres = $args; |
|
| 768 | + } |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 772 | - $args[0] = new Texte(); |
|
| 773 | - $args[0]->texte = $arg1; |
|
| 774 | - $args[0] = [$args[0]]; |
|
| 775 | - $args[1][0] = new Texte(); |
|
| 776 | - $args[1][0]->texte = $arg2; |
|
| 777 | - $crit = new Critere(); |
|
| 778 | - $crit->op = $op; |
|
| 779 | - $crit->not = $not; |
|
| 780 | - $crit->cond = $cond; |
|
| 781 | - $crit->param = $args; |
|
| 782 | - |
|
| 783 | - return $crit; |
|
| 772 | + $args[0] = new Texte(); |
|
| 773 | + $args[0]->texte = $arg1; |
|
| 774 | + $args[0] = [$args[0]]; |
|
| 775 | + $args[1][0] = new Texte(); |
|
| 776 | + $args[1][0]->texte = $arg2; |
|
| 777 | + $crit = new Critere(); |
|
| 778 | + $crit->op = $op; |
|
| 779 | + $crit->not = $not; |
|
| 780 | + $crit->cond = $cond; |
|
| 781 | + $crit->param = $args; |
|
| 782 | + |
|
| 783 | + return $crit; |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -791,12 +791,12 @@ discard block |
||
| 791 | 791 | * @return int |
| 792 | 792 | */ |
| 793 | 793 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 794 | - if (is_null($fin)) { |
|
| 795 | - return substr_count($texte, "\n", $debut); |
|
| 796 | - } |
|
| 797 | - else { |
|
| 798 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | - } |
|
| 794 | + if (is_null($fin)) { |
|
| 795 | + return substr_count($texte, "\n", $debut); |
|
| 796 | + } |
|
| 797 | + else { |
|
| 798 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | + } |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | |
@@ -812,87 +812,87 @@ discard block |
||
| 812 | 812 | * @return array|null |
| 813 | 813 | */ |
| 814 | 814 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 815 | - $premiere_boucle = null; |
|
| 816 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | - |
|
| 818 | - $current_pos = $pos_debut_texte; |
|
| 819 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | - $current_pos = $pos_boucle + 1; |
|
| 821 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | - |
|
| 823 | - $id_boucle = ''; |
|
| 824 | - if ($pos_parent !== false) { |
|
| 825 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | - } |
|
| 827 | - if ( |
|
| 828 | - $pos_parent === false |
|
| 829 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | - ) { |
|
| 831 | - $result = new Boucle(); |
|
| 832 | - $result->id_parent = $id_parent; |
|
| 833 | - $result->descr = $descr; |
|
| 834 | - |
|
| 835 | - // un id_boucle pour l'affichage de l'erreur |
|
| 836 | - if (!strlen($id_boucle)) { |
|
| 837 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | - } |
|
| 839 | - $result->id_boucle = $id_boucle; |
|
| 840 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | - erreur_squelette($err_b, $result); |
|
| 842 | - |
|
| 843 | - continue; |
|
| 844 | - } |
|
| 845 | - else { |
|
| 846 | - $boucle = [ |
|
| 847 | - 'id_boucle' => $id_boucle, |
|
| 848 | - 'id_boucle_err' => $id_boucle, |
|
| 849 | - 'debut_boucle' => $pos_boucle, |
|
| 850 | - 'pos_boucle' => $pos_boucle, |
|
| 851 | - 'pos_parent' => $pos_parent, |
|
| 852 | - 'pos_precond' => false, |
|
| 853 | - 'pos_precond_inside' => false, |
|
| 854 | - 'pos_preaff' => false, |
|
| 855 | - 'pos_preaff_inside' => false, |
|
| 856 | - ]; |
|
| 857 | - |
|
| 858 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | - if (!strlen($id_boucle)) { |
|
| 860 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | - if ( |
|
| 867 | - $pos_precond !== false |
|
| 868 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | - ) { |
|
| 870 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | - $boucle['pos_precond'] = $pos_precond; |
|
| 872 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | - if ( |
|
| 878 | - $pos_preaff !== false |
|
| 879 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | - ) { |
|
| 881 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | - } |
|
| 885 | - if (!strlen($id_boucle)) { |
|
| 886 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | - $premiere_boucle = $boucle; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - return $premiere_boucle; |
|
| 815 | + $premiere_boucle = null; |
|
| 816 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | + |
|
| 818 | + $current_pos = $pos_debut_texte; |
|
| 819 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | + $current_pos = $pos_boucle + 1; |
|
| 821 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | + |
|
| 823 | + $id_boucle = ''; |
|
| 824 | + if ($pos_parent !== false) { |
|
| 825 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | + } |
|
| 827 | + if ( |
|
| 828 | + $pos_parent === false |
|
| 829 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | + ) { |
|
| 831 | + $result = new Boucle(); |
|
| 832 | + $result->id_parent = $id_parent; |
|
| 833 | + $result->descr = $descr; |
|
| 834 | + |
|
| 835 | + // un id_boucle pour l'affichage de l'erreur |
|
| 836 | + if (!strlen($id_boucle)) { |
|
| 837 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | + } |
|
| 839 | + $result->id_boucle = $id_boucle; |
|
| 840 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | + erreur_squelette($err_b, $result); |
|
| 842 | + |
|
| 843 | + continue; |
|
| 844 | + } |
|
| 845 | + else { |
|
| 846 | + $boucle = [ |
|
| 847 | + 'id_boucle' => $id_boucle, |
|
| 848 | + 'id_boucle_err' => $id_boucle, |
|
| 849 | + 'debut_boucle' => $pos_boucle, |
|
| 850 | + 'pos_boucle' => $pos_boucle, |
|
| 851 | + 'pos_parent' => $pos_parent, |
|
| 852 | + 'pos_precond' => false, |
|
| 853 | + 'pos_precond_inside' => false, |
|
| 854 | + 'pos_preaff' => false, |
|
| 855 | + 'pos_preaff_inside' => false, |
|
| 856 | + ]; |
|
| 857 | + |
|
| 858 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | + if (!strlen($id_boucle)) { |
|
| 860 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | + if ( |
|
| 867 | + $pos_precond !== false |
|
| 868 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | + ) { |
|
| 870 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | + $boucle['pos_precond'] = $pos_precond; |
|
| 872 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | + if ( |
|
| 878 | + $pos_preaff !== false |
|
| 879 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | + ) { |
|
| 881 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | + } |
|
| 885 | + if (!strlen($id_boucle)) { |
|
| 886 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | + $premiere_boucle = $boucle; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + return $premiere_boucle; |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -907,68 +907,68 @@ discard block |
||
| 907 | 907 | * @return mixed |
| 908 | 908 | */ |
| 909 | 909 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 910 | - $id_boucle = $boucle['id_boucle']; |
|
| 911 | - $pos_courante = $pos_debut_texte; |
|
| 912 | - |
|
| 913 | - $boucle['pos_postcond'] = false; |
|
| 914 | - $boucle['pos_postcond_inside'] = false; |
|
| 915 | - $boucle['pos_altern'] = false; |
|
| 916 | - $boucle['pos_altern_inside'] = false; |
|
| 917 | - $boucle['pos_postaff'] = false; |
|
| 918 | - $boucle['pos_postaff_inside'] = false; |
|
| 919 | - |
|
| 920 | - $pos_anonyme_next = null; |
|
| 921 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | - if (!strlen($id_boucle)) { |
|
| 923 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - // |
|
| 927 | - // 1. Recuperer la partie conditionnelle apres |
|
| 928 | - // |
|
| 929 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | - if ( |
|
| 932 | - $pos_apres !== false |
|
| 933 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | - ) { |
|
| 935 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | - $pos_apres += strlen($apres_boucle); |
|
| 937 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | - $pos_courante = $pos_apres ; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // |
|
| 942 | - // 2. Récuperer la partie alternative apres |
|
| 943 | - // |
|
| 944 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | - if ( |
|
| 947 | - $pos_altern !== false |
|
| 948 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | - ) { |
|
| 950 | - $boucle['pos_altern'] = $pos_altern; |
|
| 951 | - $pos_altern += strlen($altern_boucle); |
|
| 952 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | - $pos_courante = $pos_altern; |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - // |
|
| 957 | - // 3. Recuperer la partie footer non alternative |
|
| 958 | - // |
|
| 959 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | - if ( |
|
| 962 | - $pos_postaff !== false |
|
| 963 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | - ) { |
|
| 965 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | - $pos_postaff += strlen($postaff_boucle); |
|
| 967 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | - $pos_courante = $pos_postaff ; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - return $boucle; |
|
| 910 | + $id_boucle = $boucle['id_boucle']; |
|
| 911 | + $pos_courante = $pos_debut_texte; |
|
| 912 | + |
|
| 913 | + $boucle['pos_postcond'] = false; |
|
| 914 | + $boucle['pos_postcond_inside'] = false; |
|
| 915 | + $boucle['pos_altern'] = false; |
|
| 916 | + $boucle['pos_altern_inside'] = false; |
|
| 917 | + $boucle['pos_postaff'] = false; |
|
| 918 | + $boucle['pos_postaff_inside'] = false; |
|
| 919 | + |
|
| 920 | + $pos_anonyme_next = null; |
|
| 921 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | + if (!strlen($id_boucle)) { |
|
| 923 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + // |
|
| 927 | + // 1. Recuperer la partie conditionnelle apres |
|
| 928 | + // |
|
| 929 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | + if ( |
|
| 932 | + $pos_apres !== false |
|
| 933 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | + ) { |
|
| 935 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | + $pos_apres += strlen($apres_boucle); |
|
| 937 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | + $pos_courante = $pos_apres ; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // |
|
| 942 | + // 2. Récuperer la partie alternative apres |
|
| 943 | + // |
|
| 944 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | + if ( |
|
| 947 | + $pos_altern !== false |
|
| 948 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | + ) { |
|
| 950 | + $boucle['pos_altern'] = $pos_altern; |
|
| 951 | + $pos_altern += strlen($altern_boucle); |
|
| 952 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | + $pos_courante = $pos_altern; |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + // |
|
| 957 | + // 3. Recuperer la partie footer non alternative |
|
| 958 | + // |
|
| 959 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | + if ( |
|
| 962 | + $pos_postaff !== false |
|
| 963 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | + ) { |
|
| 965 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | + $pos_postaff += strlen($postaff_boucle); |
|
| 967 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | + $pos_courante = $pos_postaff ; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + return $boucle; |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | |
@@ -978,21 +978,21 @@ discard block |
||
| 978 | 978 | * @param null|object $boucle |
| 979 | 979 | */ |
| 980 | 980 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 981 | - static $boucles_connues = []; |
|
| 982 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | - } |
|
| 986 | - else { |
|
| 987 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | - $placeholder = $champ->nom_champ; |
|
| 989 | - $id = reset($champ->param[0][1]); |
|
| 990 | - $id = $id->texte; |
|
| 991 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 981 | + static $boucles_connues = []; |
|
| 982 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | + } |
|
| 986 | + else { |
|
| 987 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | + $placeholder = $champ->nom_champ; |
|
| 989 | + $id = reset($champ->param[0][1]); |
|
| 990 | + $id = $id->texte; |
|
| 991 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | |
@@ -1005,274 +1005,274 @@ discard block |
||
| 1005 | 1005 | * @return string |
| 1006 | 1006 | */ |
| 1007 | 1007 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1008 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | - //memoriser la boucle a reinjecter |
|
| 1010 | - $id_boucle = "$id_boucle"; |
|
| 1011 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | - return $placeholder; |
|
| 1008 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | + //memoriser la boucle a reinjecter |
|
| 1010 | + $id_boucle = "$id_boucle"; |
|
| 1011 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | + return $placeholder; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1016 | 1016 | |
| 1017 | - $all_res = []; |
|
| 1018 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | - if (is_null($boucle_placeholder)) { |
|
| 1020 | - do { |
|
| 1021 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | - $pos_debut_texte = 0; |
|
| 1027 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | - $result = new Boucle(); |
|
| 1030 | - $result->id_parent = $id_parent; |
|
| 1031 | - $result->descr = $descr; |
|
| 1032 | - |
|
| 1033 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | - $pos_parent = $boucle['pos_parent']; |
|
| 1035 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | - |
|
| 1037 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | - |
|
| 1039 | - // boucle anonyme ? |
|
| 1040 | - if (!strlen($id_boucle)) { |
|
| 1041 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - $pos_debut_boucle = $pos_courante; |
|
| 1045 | - |
|
| 1046 | - $pos_milieu = $pos_parent; |
|
| 1047 | - |
|
| 1048 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | - if ($boucle['pos_precond'] !== false) { |
|
| 1050 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | - |
|
| 1052 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | - $end_preaff = $pos_debut_boucle; |
|
| 1060 | - |
|
| 1061 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - $result->id_boucle = $id_boucle; |
|
| 1067 | - |
|
| 1068 | - if ( |
|
| 1069 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | - or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | - or $pos_match > $pos_milieu |
|
| 1072 | - ) { |
|
| 1073 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | - erreur_squelette($err_b, $result); |
|
| 1075 | - |
|
| 1076 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | - continue; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - $result->type_requete = $match[0]; |
|
| 1082 | - $pos_milieu += strlen($match[0]); |
|
| 1083 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | - |
|
| 1085 | - $type = $match[1]; |
|
| 1086 | - $jointures = trim($match[2]); |
|
| 1087 | - $table_optionnelle = ($match[3]); |
|
| 1088 | - if ($jointures) { |
|
| 1089 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | - // ou elles seront completees des jointures declarees |
|
| 1091 | - $result->jointures_explicites = $jointures; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - if ($table_optionnelle) { |
|
| 1095 | - $result->table_optionnelle = $type; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | - // Resultat mis dans result->param |
|
| 1100 | - $pos_fin_criteres = $pos_milieu; |
|
| 1101 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | - |
|
| 1103 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | - // pour l'instant on met le source (chaine) : |
|
| 1105 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | - $pos_milieu = $pos_fin_criteres; |
|
| 1109 | - |
|
| 1110 | - // |
|
| 1111 | - // Recuperer la fin : |
|
| 1112 | - // |
|
| 1113 | - if ($texte[$pos_milieu] === '/') { |
|
| 1114 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | - $pos_courante += 2; |
|
| 1116 | - $result->milieu = ''; |
|
| 1117 | - } else { |
|
| 1118 | - $pos_milieu += 1; |
|
| 1119 | - |
|
| 1120 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | - if ($pos_fin === false) { |
|
| 1123 | - $err_b = [ |
|
| 1124 | - 'zbug_erreur_boucle_fermant', |
|
| 1125 | - ['id' => $id_boucle] |
|
| 1126 | - ]; |
|
| 1127 | - erreur_squelette($err_b, $result); |
|
| 1128 | - $pos_courante += strlen($fin_boucle); |
|
| 1129 | - } |
|
| 1130 | - else { |
|
| 1131 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | - $search_from = $pos_milieu; |
|
| 1135 | - $nb_open = 1; |
|
| 1136 | - $nb_close = 1; |
|
| 1137 | - $maxiter = 0; |
|
| 1138 | - do { |
|
| 1139 | - while ( |
|
| 1140 | - $nb_close < $nb_open |
|
| 1141 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | - ) { |
|
| 1143 | - $nb_close++; |
|
| 1144 | - $pos_fin = $p; |
|
| 1145 | - } |
|
| 1146 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | - if ($nb_close < $nb_open) { |
|
| 1148 | - break; |
|
| 1149 | - } |
|
| 1150 | - while ( |
|
| 1151 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | - and $p < $pos_fin |
|
| 1153 | - ) { |
|
| 1154 | - $nb_open++; |
|
| 1155 | - $search_from = $p + 1; |
|
| 1156 | - } |
|
| 1157 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | - |
|
| 1159 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | - } |
|
| 1161 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | - |
|
| 1167 | - // |
|
| 1168 | - // 1. Partie conditionnelle apres ? |
|
| 1169 | - // |
|
| 1170 | - if ($boucle['pos_postcond']) { |
|
| 1171 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - |
|
| 1177 | - // |
|
| 1178 | - // 2. Partie alternative apres ? |
|
| 1179 | - // |
|
| 1180 | - $ligne_altern = $ligne_suite; |
|
| 1181 | - if ($boucle['pos_altern']) { |
|
| 1182 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - // |
|
| 1188 | - // 3. Partie footer non alternative ? |
|
| 1189 | - // |
|
| 1190 | - $ligne_postaff = $ligne_suite; |
|
| 1191 | - if ($boucle['pos_postaff']) { |
|
| 1192 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - $result->ligne = $ligne_preaff; |
|
| 1198 | - |
|
| 1199 | - if ($p = strpos($type, ':')) { |
|
| 1200 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | - $type = substr($type, $p + 1); |
|
| 1202 | - } |
|
| 1203 | - $soustype = strtolower($type); |
|
| 1204 | - |
|
| 1205 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | - $soustype = $type; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $result->type_requete = $soustype; |
|
| 1210 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | - if (!is_array($result->param)) { |
|
| 1212 | - $err_b = true; |
|
| 1213 | - } else { |
|
| 1214 | - phraser_criteres($result->param, $result); |
|
| 1215 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | - $args = $result->param; |
|
| 1218 | - array_unshift( |
|
| 1219 | - $args, |
|
| 1220 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | - ); |
|
| 1222 | - $result->param = $args; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | - if (empty($boucles[$id_boucle])) { |
|
| 1232 | - $boucles[$id_boucle] = null; |
|
| 1233 | - } |
|
| 1234 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | - |
|
| 1240 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | - if ($err_b) { |
|
| 1242 | - $result->type_requete = false; |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - // Verifier qu'il n'y a pas double definition |
|
| 1246 | - // apres analyse des sous-parties (pas avant). |
|
| 1247 | - if (!empty($boucles[$id_boucle])) { |
|
| 1248 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | - $err_b_d = [ |
|
| 1250 | - 'zbug_erreur_boucle_double', |
|
| 1251 | - ['id' => $id_boucle] |
|
| 1252 | - ]; |
|
| 1253 | - erreur_squelette($err_b_d, $result); |
|
| 1254 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | - } |
|
| 1257 | - } else { |
|
| 1258 | - $boucles[$id_boucle] = $result; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | - |
|
| 1267 | - // phraser la partie avant le debut de la boucle |
|
| 1268 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | - |
|
| 1271 | - $ligne_debut_texte = $ligne_suite; |
|
| 1272 | - $pos_debut_texte = $pos_courante; |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | - |
|
| 1277 | - return $all_res; |
|
| 1017 | + $all_res = []; |
|
| 1018 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | + if (is_null($boucle_placeholder)) { |
|
| 1020 | + do { |
|
| 1021 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | + $pos_debut_texte = 0; |
|
| 1027 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | + $result = new Boucle(); |
|
| 1030 | + $result->id_parent = $id_parent; |
|
| 1031 | + $result->descr = $descr; |
|
| 1032 | + |
|
| 1033 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | + $pos_parent = $boucle['pos_parent']; |
|
| 1035 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | + |
|
| 1037 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | + |
|
| 1039 | + // boucle anonyme ? |
|
| 1040 | + if (!strlen($id_boucle)) { |
|
| 1041 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + $pos_debut_boucle = $pos_courante; |
|
| 1045 | + |
|
| 1046 | + $pos_milieu = $pos_parent; |
|
| 1047 | + |
|
| 1048 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | + if ($boucle['pos_precond'] !== false) { |
|
| 1050 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | + |
|
| 1052 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | + $end_preaff = $pos_debut_boucle; |
|
| 1060 | + |
|
| 1061 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + $result->id_boucle = $id_boucle; |
|
| 1067 | + |
|
| 1068 | + if ( |
|
| 1069 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | + or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | + or $pos_match > $pos_milieu |
|
| 1072 | + ) { |
|
| 1073 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | + erreur_squelette($err_b, $result); |
|
| 1075 | + |
|
| 1076 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | + continue; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + $result->type_requete = $match[0]; |
|
| 1082 | + $pos_milieu += strlen($match[0]); |
|
| 1083 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | + |
|
| 1085 | + $type = $match[1]; |
|
| 1086 | + $jointures = trim($match[2]); |
|
| 1087 | + $table_optionnelle = ($match[3]); |
|
| 1088 | + if ($jointures) { |
|
| 1089 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | + // ou elles seront completees des jointures declarees |
|
| 1091 | + $result->jointures_explicites = $jointures; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + if ($table_optionnelle) { |
|
| 1095 | + $result->table_optionnelle = $type; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | + // Resultat mis dans result->param |
|
| 1100 | + $pos_fin_criteres = $pos_milieu; |
|
| 1101 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | + |
|
| 1103 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | + // pour l'instant on met le source (chaine) : |
|
| 1105 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | + $pos_milieu = $pos_fin_criteres; |
|
| 1109 | + |
|
| 1110 | + // |
|
| 1111 | + // Recuperer la fin : |
|
| 1112 | + // |
|
| 1113 | + if ($texte[$pos_milieu] === '/') { |
|
| 1114 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | + $pos_courante += 2; |
|
| 1116 | + $result->milieu = ''; |
|
| 1117 | + } else { |
|
| 1118 | + $pos_milieu += 1; |
|
| 1119 | + |
|
| 1120 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | + if ($pos_fin === false) { |
|
| 1123 | + $err_b = [ |
|
| 1124 | + 'zbug_erreur_boucle_fermant', |
|
| 1125 | + ['id' => $id_boucle] |
|
| 1126 | + ]; |
|
| 1127 | + erreur_squelette($err_b, $result); |
|
| 1128 | + $pos_courante += strlen($fin_boucle); |
|
| 1129 | + } |
|
| 1130 | + else { |
|
| 1131 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | + $search_from = $pos_milieu; |
|
| 1135 | + $nb_open = 1; |
|
| 1136 | + $nb_close = 1; |
|
| 1137 | + $maxiter = 0; |
|
| 1138 | + do { |
|
| 1139 | + while ( |
|
| 1140 | + $nb_close < $nb_open |
|
| 1141 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | + ) { |
|
| 1143 | + $nb_close++; |
|
| 1144 | + $pos_fin = $p; |
|
| 1145 | + } |
|
| 1146 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | + if ($nb_close < $nb_open) { |
|
| 1148 | + break; |
|
| 1149 | + } |
|
| 1150 | + while ( |
|
| 1151 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | + and $p < $pos_fin |
|
| 1153 | + ) { |
|
| 1154 | + $nb_open++; |
|
| 1155 | + $search_from = $p + 1; |
|
| 1156 | + } |
|
| 1157 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | + |
|
| 1159 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | + } |
|
| 1161 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | + |
|
| 1167 | + // |
|
| 1168 | + // 1. Partie conditionnelle apres ? |
|
| 1169 | + // |
|
| 1170 | + if ($boucle['pos_postcond']) { |
|
| 1171 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + |
|
| 1177 | + // |
|
| 1178 | + // 2. Partie alternative apres ? |
|
| 1179 | + // |
|
| 1180 | + $ligne_altern = $ligne_suite; |
|
| 1181 | + if ($boucle['pos_altern']) { |
|
| 1182 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + // |
|
| 1188 | + // 3. Partie footer non alternative ? |
|
| 1189 | + // |
|
| 1190 | + $ligne_postaff = $ligne_suite; |
|
| 1191 | + if ($boucle['pos_postaff']) { |
|
| 1192 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + $result->ligne = $ligne_preaff; |
|
| 1198 | + |
|
| 1199 | + if ($p = strpos($type, ':')) { |
|
| 1200 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | + $type = substr($type, $p + 1); |
|
| 1202 | + } |
|
| 1203 | + $soustype = strtolower($type); |
|
| 1204 | + |
|
| 1205 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | + $soustype = $type; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $result->type_requete = $soustype; |
|
| 1210 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | + if (!is_array($result->param)) { |
|
| 1212 | + $err_b = true; |
|
| 1213 | + } else { |
|
| 1214 | + phraser_criteres($result->param, $result); |
|
| 1215 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | + $args = $result->param; |
|
| 1218 | + array_unshift( |
|
| 1219 | + $args, |
|
| 1220 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | + ); |
|
| 1222 | + $result->param = $args; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | + if (empty($boucles[$id_boucle])) { |
|
| 1232 | + $boucles[$id_boucle] = null; |
|
| 1233 | + } |
|
| 1234 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | + |
|
| 1240 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | + if ($err_b) { |
|
| 1242 | + $result->type_requete = false; |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + // Verifier qu'il n'y a pas double definition |
|
| 1246 | + // apres analyse des sous-parties (pas avant). |
|
| 1247 | + if (!empty($boucles[$id_boucle])) { |
|
| 1248 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | + $err_b_d = [ |
|
| 1250 | + 'zbug_erreur_boucle_double', |
|
| 1251 | + ['id' => $id_boucle] |
|
| 1252 | + ]; |
|
| 1253 | + erreur_squelette($err_b_d, $result); |
|
| 1254 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | + } |
|
| 1257 | + } else { |
|
| 1258 | + $boucles[$id_boucle] = $result; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | + |
|
| 1267 | + // phraser la partie avant le debut de la boucle |
|
| 1268 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | + |
|
| 1271 | + $ligne_debut_texte = $ligne_suite; |
|
| 1272 | + $pos_debut_texte = $pos_courante; |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | + |
|
| 1277 | + return $all_res; |
|
| 1278 | 1278 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | array_shift($p->param); |
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 55 | + } elseif (preg_match('/^'.NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 56 | 56 | $champ = new Champ(); |
| 57 | 57 | $champ->nom_boucle = $m[2]; |
| 58 | 58 | $champ->nom_champ = $m[3]; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $p->param[0][1] = [$c]; |
| 129 | 129 | $p->param[0][0] = ''; |
| 130 | 130 | $p->fonctions = []; |
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -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 | } |
@@ -41,7 +41,7 @@ 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 | 46 | return $code; |
| 47 | 47 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $min_f = $refl->getNumberOfRequiredParameters(); |
| 86 | 86 | if (($nb_args_f < $min_f)) { |
| 87 | 87 | $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
| 88 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 88 | + erreur_squelette(['zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | // le filtre n'existe pas, |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 172 | 172 | $series_filtres = func_get_args(); |
| 173 | - array_shift($series_filtres);// skel |
|
| 174 | - array_shift($series_filtres);// corps |
|
| 173 | + array_shift($series_filtres); // skel |
|
| 174 | + array_shift($series_filtres); // corps |
|
| 175 | 175 | |
| 176 | 176 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 177 | 177 | if ($skel['process_ins'] == 'php') { |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | if (is_array($r)) { |
| 220 | 220 | $dst[] = $r[0]; |
| 221 | 221 | |
| 222 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 222 | + return $src[] = '___'.md5($r[0]).'___'; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // si on recoit pas un tableau, on renvoit les couples de substitution |
@@ -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 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
| 54 | 54 | $page = _SPIP_PAGE; |
| 55 | 55 | $echafauder = charger_fonction('echafauder', 'public', true); |
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim( |
|
| 57 | 57 | _DIR_PLUGIN_DIST, |
| 58 | 58 | '/' |
| 59 | 59 | ) : '')); |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
| 78 | 78 | and defined($apl_constant) |
| 79 | 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 |
|
| 80 | + and $pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | 81 | ) { |
| 82 | 82 | $flux['data'] = $pipe; |
| 83 | 83 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $echafauder = ''; |
| 91 | 91 | } |
| 92 | 92 | if ($prepend) { |
| 93 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 93 | + $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | 94 | if ($squelette) { |
| 95 | 95 | $flux['data'] = $squelette; |
| 96 | 96 | } |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | // se brancher sur contenu/xx si il existe |
| 114 | 114 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 115 | 115 | if (!isset($disponible[$fond])) { |
| 116 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 116 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | if ($disponible[$fond]) { |
| 120 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 120 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $type = $flux['args']['contexte'][$page]; |
| 131 | 131 | } |
| 132 | 132 | if (!isset($disponible[$type])) { |
| 133 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 133 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | 134 | } |
| 135 | 135 | if (is_string($disponible[$type])) { |
| 136 | 136 | $flux['data'] = $disponible[$type]; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
| 146 | 146 | } else { |
| 147 | 147 | $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
| 148 | - $prefix_path . $prepend, |
|
| 148 | + $prefix_path.$prepend, |
|
| 149 | 149 | $z_contenu, |
| 150 | 150 | '404', |
| 151 | 151 | $ext, |
@@ -169,10 +169,10 @@ discard block |
||
| 169 | 169 | $type = $flux['args']['contexte'][$page]; |
| 170 | 170 | } |
| 171 | 171 | if ($type !== 'page' and !isset($disponible[$type])) { |
| 172 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 172 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | 173 | } |
| 174 | 174 | if ($type == 'page' or $disponible[$type]) { |
| 175 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 175 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | isset($flux['args']['contexte']['type-page']) |
| 189 | 189 | and ( |
| 190 | 190 | (isset($flux['args']['contexte']['composition']) |
| 191 | - and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 191 | + and file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page'].'-'.$flux['args']['contexte']['composition']).".$ext")) |
|
| 192 | 192 | or |
| 193 | - file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 193 | + file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page']).".$ext") |
|
| 194 | 194 | ) |
| 195 | 195 | ) { |
| 196 | 196 | $flux['data'] = $f; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | } elseif ( |
| 199 | 199 | $fond == 'structure' |
| 200 | 200 | and z_sanitize_var_zajax() |
| 201 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 201 | + and $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext") |
|
| 202 | 202 | ) { |
| 203 | 203 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 204 | 204 | } // chercher le fond correspondant a la composition |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | and $dir = explode('/', $dir) |
| 210 | 210 | and $dir = reset($dir) |
| 211 | 211 | and in_array($dir, $z_blocs) |
| 212 | - and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 212 | + and $f = find_in_path($prefix_path.$prepend.$fond.'-'.$flux['args']['contexte']['composition'].".$ext") |
|
| 213 | 213 | ) { |
| 214 | 214 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 215 | 215 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | function z_fond_valide($squelette) { |
| 272 | 272 | if ( |
| 273 | 273 | !_ZCORE_EXCLURE_PATH |
| 274 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 274 | + or !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette) |
|
| 275 | 275 | ) { |
| 276 | 276 | return true; |
| 277 | 277 | } |
@@ -395,23 +395,23 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | $dir = z_blocs(test_espace_prive()); |
| 397 | 397 | $dir = reset($dir); |
| 398 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 398 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.',objet='.$type.',id_objet=#'.strtoupper($primary).',env}>'; |
|
| 399 | 399 | } // page objets |
| 400 | 400 | elseif ($type = $desc_exec and strpos($type, '/') === false) { |
| 401 | 401 | $dir = z_blocs(test_espace_prive()); |
| 402 | 402 | $dir = reset($dir); |
| 403 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 403 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.',env} />'; |
|
| 404 | 404 | } |
| 405 | 405 | // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
| 406 | 406 | // et objet et tire de $table |
| 407 | 407 | elseif ($fond = $desc_exec) { |
| 408 | 408 | $dir = md5(dirname($fond)); |
| 409 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 409 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).',env} />'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
| 413 | 413 | $base_dir = sous_repertoire($base_dir, $dir, false); |
| 414 | - $f = $base_dir . "$exec"; |
|
| 414 | + $f = $base_dir."$exec"; |
|
| 415 | 415 | ecrire_fichier("$f.$ext", $scaffold); |
| 416 | 416 | |
| 417 | 417 | return $f; |
@@ -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 | } |
@@ -207,8 +207,7 @@ discard block |
||
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | 208 | if (trouver_fond('pagination_' . $modele, 'modeles')) { |
| 209 | 209 | $modele = '_' . $modele; |
| 210 | - } |
|
| 211 | - else { |
|
| 210 | + } else { |
|
| 212 | 211 | $modele = ''; |
| 213 | 212 | } |
| 214 | 213 | } |
@@ -295,8 +294,7 @@ discard block |
||
| 295 | 294 | if ($ids) { |
| 296 | 295 | $ids = array_column($ids, 'id_objet'); |
| 297 | 296 | return implode(',', $ids); |
| 298 | - } |
|
| 299 | - else { |
|
| 297 | + } else { |
|
| 300 | 298 | return '0'; |
| 301 | 299 | } |
| 302 | 300 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $texte = $intro; |
| 85 | 85 | } else { |
| 86 | 86 | if ( |
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 87 | + strpos("\n".$texte, "\n|") === false |
|
| 88 | 88 | and strlen($texte) > 2.5 * $longueur |
| 89 | 89 | ) { |
| 90 | 90 | if (strpos($texte, '<multi') !== false) { |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | if ($pas < 1) { |
| 169 | 169 | return ''; |
| 170 | 170 | } |
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 171 | + $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 172 | + $debut = 'debut'.$nom; // 'debut_articles' |
|
| 173 | 173 | |
| 174 | 174 | // n'afficher l'ancre qu'une fois |
| 175 | 175 | if (!isset($ancres[$ancre])) { |
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='".$ancre."' class='pagination_ancre'></a>"; |
|
| 177 | 177 | } else { |
| 178 | 178 | $bloc_ancre = ''; |
| 179 | 179 | } |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | if ($modele) { |
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 208 | + if (trouver_fond('pagination_'.$modele, 'modeles')) { |
|
| 209 | + $modele = '_'.$modele; |
|
| 210 | 210 | } |
| 211 | 211 | else { |
| 212 | 212 | $modele = ''; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | 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)); |
|
| 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 | 295 | if ($ids) { |
| 296 | 296 | $ids = array_column($ids, 'id_objet'); |
| 297 | 297 | return implode(',', $ids); |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | // Classes : on indique le sens de tri et l'item exposé |
| 486 | 486 | if (!$is_sens_fixe) { |
| 487 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 487 | + $classe .= ' item-tri item-tri_'.($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 488 | 488 | } |
| 489 | 489 | if ($champ_ou_sens === $tri_champ) { |
| 490 | 490 | $classe .= ' item-tri_actif'; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | */ |
| 524 | 524 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 525 | 525 | if (strncmp($t, 'multi ', 6) == 0) { |
| 526 | - return 'multi' . $senstri; |
|
| 526 | + return 'multi'.$senstri; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | $champ = $t; |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | case 'sinum ': |
| 558 | 558 | return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
| 559 | 559 | default: |
| 560 | - return $champ . $senstri; |
|
| 560 | + return $champ.$senstri; |
|
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | |
@@ -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 | // public/interfaces definit des traitements sur les champs qui utilisent des fonctions de inc/texte |
@@ -55,75 +55,75 @@ discard block |
||
| 55 | 55 | * Introduction calculée |
| 56 | 56 | **/ |
| 57 | 57 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 58 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 59 | - if (strlen($descriptif)) { |
|
| 60 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // De preference ce qui est marque <intro>...</intro> |
|
| 64 | - $intro = ''; |
|
| 65 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 66 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 67 | - $zone = substr($texte, 0, $fin); |
|
| 68 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 69 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 70 | - $zone = substr($zone, $deb + 7); |
|
| 71 | - } |
|
| 72 | - $intro .= $zone; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 76 | - // qui inclus raccourcis et modeles |
|
| 77 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 78 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 79 | - // des surcharges et enrichissement de propre |
|
| 80 | - // couper doit se faire apres propre |
|
| 81 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 82 | - |
|
| 83 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 84 | - // large et en se mefiant des tableaux #1323 |
|
| 85 | - |
|
| 86 | - if (strlen($intro)) { |
|
| 87 | - $texte = $intro; |
|
| 88 | - } else { |
|
| 89 | - if ( |
|
| 90 | - strpos("\n" . $texte, "\n|") === false |
|
| 91 | - and strlen($texte) > 2.5 * $longueur |
|
| 92 | - ) { |
|
| 93 | - if (strpos($texte, '<multi') !== false) { |
|
| 94 | - $texte = extraire_multi($texte); |
|
| 95 | - } |
|
| 96 | - $texte = couper($texte, 2 * $longueur); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // ne pas tenir compte des notes |
|
| 101 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 102 | - $notes('', 'empiler'); |
|
| 103 | - } |
|
| 104 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 105 | - // dans l'introduction. |
|
| 106 | - $texte = supprime_img($texte, ''); |
|
| 107 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 108 | - |
|
| 109 | - if ($notes) { |
|
| 110 | - $notes('', 'depiler'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 114 | - $suite = _INTRODUCTION_SUITE; |
|
| 115 | - } |
|
| 116 | - $texte = couper($texte, $longueur, $suite); |
|
| 117 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 118 | - $texte = typo($texte, true, $connect, []); |
|
| 119 | - |
|
| 120 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 121 | - // une introduction a tojours un <p> |
|
| 122 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 123 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $texte; |
|
| 58 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 59 | + if (strlen($descriptif)) { |
|
| 60 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // De preference ce qui est marque <intro>...</intro> |
|
| 64 | + $intro = ''; |
|
| 65 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 66 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 67 | + $zone = substr($texte, 0, $fin); |
|
| 68 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 69 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 70 | + $zone = substr($zone, $deb + 7); |
|
| 71 | + } |
|
| 72 | + $intro .= $zone; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 76 | + // qui inclus raccourcis et modeles |
|
| 77 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 78 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 79 | + // des surcharges et enrichissement de propre |
|
| 80 | + // couper doit se faire apres propre |
|
| 81 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 82 | + |
|
| 83 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 84 | + // large et en se mefiant des tableaux #1323 |
|
| 85 | + |
|
| 86 | + if (strlen($intro)) { |
|
| 87 | + $texte = $intro; |
|
| 88 | + } else { |
|
| 89 | + if ( |
|
| 90 | + strpos("\n" . $texte, "\n|") === false |
|
| 91 | + and strlen($texte) > 2.5 * $longueur |
|
| 92 | + ) { |
|
| 93 | + if (strpos($texte, '<multi') !== false) { |
|
| 94 | + $texte = extraire_multi($texte); |
|
| 95 | + } |
|
| 96 | + $texte = couper($texte, 2 * $longueur); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // ne pas tenir compte des notes |
|
| 101 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 102 | + $notes('', 'empiler'); |
|
| 103 | + } |
|
| 104 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 105 | + // dans l'introduction. |
|
| 106 | + $texte = supprime_img($texte, ''); |
|
| 107 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 108 | + |
|
| 109 | + if ($notes) { |
|
| 110 | + $notes('', 'depiler'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 114 | + $suite = _INTRODUCTION_SUITE; |
|
| 115 | + } |
|
| 116 | + $texte = couper($texte, $longueur, $suite); |
|
| 117 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 118 | + $texte = typo($texte, true, $connect, []); |
|
| 119 | + |
|
| 120 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 121 | + // une introduction a tojours un <p> |
|
| 122 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 123 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $texte; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
@@ -158,73 +158,73 @@ discard block |
||
| 158 | 158 | * Code HTML de la pagination |
| 159 | 159 | **/ |
| 160 | 160 | function filtre_pagination_dist( |
| 161 | - $total, |
|
| 162 | - $nom, |
|
| 163 | - $position, |
|
| 164 | - $pas, |
|
| 165 | - $liste = true, |
|
| 166 | - $modele = '', |
|
| 167 | - string $connect = '', |
|
| 168 | - $env = [] |
|
| 161 | + $total, |
|
| 162 | + $nom, |
|
| 163 | + $position, |
|
| 164 | + $pas, |
|
| 165 | + $liste = true, |
|
| 166 | + $modele = '', |
|
| 167 | + string $connect = '', |
|
| 168 | + $env = [] |
|
| 169 | 169 | ) { |
| 170 | - static $ancres = []; |
|
| 171 | - if ($pas < 1) { |
|
| 172 | - return ''; |
|
| 173 | - } |
|
| 174 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 175 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 176 | - |
|
| 177 | - // n'afficher l'ancre qu'une fois |
|
| 178 | - if (!isset($ancres[$ancre])) { |
|
| 179 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 180 | - } else { |
|
| 181 | - $bloc_ancre = ''; |
|
| 182 | - } |
|
| 183 | - // liste = false : on ne veut que l'ancre |
|
| 184 | - if (!$liste) { |
|
| 185 | - return $ancres[$ancre]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 189 | - $pagination = [ |
|
| 190 | - 'debut' => $debut, |
|
| 191 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 192 | - 'total' => $total, |
|
| 193 | - 'position' => intval($position), |
|
| 194 | - 'pas' => $pas, |
|
| 195 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 196 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 197 | - 'ancre' => $ancre, |
|
| 198 | - 'bloc_ancre' => $bloc_ancre |
|
| 199 | - ]; |
|
| 200 | - if (is_array($env)) { |
|
| 201 | - $pagination = array_merge($env, $pagination); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Pas de pagination |
|
| 205 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 206 | - return ''; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ($modele) { |
|
| 210 | - $pagination['type_pagination'] = $modele; |
|
| 211 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 212 | - $modele = '_' . $modele; |
|
| 213 | - } |
|
| 214 | - else { |
|
| 215 | - $modele = ''; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 221 | - } |
|
| 222 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 223 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 170 | + static $ancres = []; |
|
| 171 | + if ($pas < 1) { |
|
| 172 | + return ''; |
|
| 173 | + } |
|
| 174 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 175 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 176 | + |
|
| 177 | + // n'afficher l'ancre qu'une fois |
|
| 178 | + if (!isset($ancres[$ancre])) { |
|
| 179 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 180 | + } else { |
|
| 181 | + $bloc_ancre = ''; |
|
| 182 | + } |
|
| 183 | + // liste = false : on ne veut que l'ancre |
|
| 184 | + if (!$liste) { |
|
| 185 | + return $ancres[$ancre]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 189 | + $pagination = [ |
|
| 190 | + 'debut' => $debut, |
|
| 191 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 192 | + 'total' => $total, |
|
| 193 | + 'position' => intval($position), |
|
| 194 | + 'pas' => $pas, |
|
| 195 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 196 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 197 | + 'ancre' => $ancre, |
|
| 198 | + 'bloc_ancre' => $bloc_ancre |
|
| 199 | + ]; |
|
| 200 | + if (is_array($env)) { |
|
| 201 | + $pagination = array_merge($env, $pagination); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Pas de pagination |
|
| 205 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 206 | + return ''; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ($modele) { |
|
| 210 | + $pagination['type_pagination'] = $modele; |
|
| 211 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 212 | + $modele = '_' . $modele; |
|
| 213 | + } |
|
| 214 | + else { |
|
| 215 | + $modele = ''; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 221 | + } |
|
| 222 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 223 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -243,44 +243,44 @@ discard block |
||
| 243 | 243 | * Liste (première page, dernière page). |
| 244 | 244 | **/ |
| 245 | 245 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 246 | - if ($max <= 0 or $max >= $nombre) { |
|
| 247 | - return [1, $nombre]; |
|
| 248 | - } |
|
| 249 | - if ($max <= 1) { |
|
| 250 | - return [$courante, $courante]; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 254 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 255 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 256 | - |
|
| 257 | - return [$premiere, $derniere]; |
|
| 246 | + if ($max <= 0 or $max >= $nombre) { |
|
| 247 | + return [1, $nombre]; |
|
| 248 | + } |
|
| 249 | + if ($max <= 1) { |
|
| 250 | + return [$courante, $courante]; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 254 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 255 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 256 | + |
|
| 257 | + return [$premiere, $derniere]; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 261 | - if ($numero_page === 'tous') { |
|
| 262 | - return '∞'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'prev') { |
|
| 265 | - return '<'; |
|
| 266 | - } |
|
| 267 | - if ($numero_page === 'next') { |
|
| 268 | - return '>'; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - switch ($type_pagination) { |
|
| 272 | - case 'resultats': |
|
| 273 | - return $rang_item + 1; // 1 11 21 31... |
|
| 274 | - case 'naturel': |
|
| 275 | - return $rang_item ?: 1; // 1 10 20 30... |
|
| 276 | - case 'rang': |
|
| 277 | - return $rang_item; // 0 10 20 30... |
|
| 278 | - |
|
| 279 | - case 'page': |
|
| 280 | - case 'prive': |
|
| 281 | - default: |
|
| 282 | - return $numero_page; // 1 2 3 4 5... |
|
| 283 | - } |
|
| 261 | + if ($numero_page === 'tous') { |
|
| 262 | + return '∞'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'prev') { |
|
| 265 | + return '<'; |
|
| 266 | + } |
|
| 267 | + if ($numero_page === 'next') { |
|
| 268 | + return '>'; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + switch ($type_pagination) { |
|
| 272 | + case 'resultats': |
|
| 273 | + return $rang_item + 1; // 1 11 21 31... |
|
| 274 | + case 'naturel': |
|
| 275 | + return $rang_item ?: 1; // 1 10 20 30... |
|
| 276 | + case 'rang': |
|
| 277 | + return $rang_item; // 0 10 20 30... |
|
| 278 | + |
|
| 279 | + case 'page': |
|
| 280 | + case 'prive': |
|
| 281 | + default: |
|
| 282 | + return $numero_page; // 1 2 3 4 5... |
|
| 283 | + } |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -293,15 +293,15 @@ discard block |
||
| 293 | 293 | **/ |
| 294 | 294 | function lister_objets_avec_logos($type) { |
| 295 | 295 | |
| 296 | - $objet = objet_type($type); |
|
| 297 | - $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)); |
|
| 298 | - if ($ids) { |
|
| 299 | - $ids = array_column($ids, 'id_objet'); |
|
| 300 | - return implode(',', $ids); |
|
| 301 | - } |
|
| 302 | - else { |
|
| 303 | - return '0'; |
|
| 304 | - } |
|
| 296 | + $objet = objet_type($type); |
|
| 297 | + $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)); |
|
| 298 | + if ($ids) { |
|
| 299 | + $ids = array_column($ids, 'id_objet'); |
|
| 300 | + return implode(',', $ids); |
|
| 301 | + } |
|
| 302 | + else { |
|
| 303 | + return '0'; |
|
| 304 | + } |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -317,14 +317,14 @@ discard block |
||
| 317 | 317 | * Code HTML des notes |
| 318 | 318 | **/ |
| 319 | 319 | function calculer_notes() { |
| 320 | - $r = ''; |
|
| 321 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 322 | - $r = $notes([]); |
|
| 323 | - $notes('', 'depiler'); |
|
| 324 | - $notes('', 'empiler'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return $r; |
|
| 320 | + $r = ''; |
|
| 321 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 322 | + $r = $notes([]); |
|
| 323 | + $notes('', 'depiler'); |
|
| 324 | + $notes('', 'empiler'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return $r; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | |
@@ -341,10 +341,10 @@ discard block |
||
| 341 | 341 | * @return string |
| 342 | 342 | */ |
| 343 | 343 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 344 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 345 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 344 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 345 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 346 | 346 | |
| 347 | - return ($res[$ids] ?? ''); |
|
| 347 | + return ($res[$ids] ?? ''); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -361,19 +361,19 @@ discard block |
||
| 361 | 361 | * @private |
| 362 | 362 | */ |
| 363 | 363 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 364 | - static $liens = []; |
|
| 365 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 366 | - include_spip('action/editer_liens'); |
|
| 367 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 368 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 369 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 370 | - } else { |
|
| 371 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 375 | - } |
|
| 376 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 364 | + static $liens = []; |
|
| 365 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 366 | + include_spip('action/editer_liens'); |
|
| 367 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 368 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 369 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 370 | + } else { |
|
| 371 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 375 | + } |
|
| 376 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -387,24 +387,24 @@ discard block |
||
| 387 | 387 | * @return int|string |
| 388 | 388 | */ |
| 389 | 389 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 390 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 391 | - // 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 |
|
| 392 | - if ( |
|
| 393 | - isset($env['form']) and $env['form'] |
|
| 394 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 395 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 396 | - and $r = objet_associable($env['_objet_lien']) |
|
| 397 | - and [$p, $table_lien] = $r |
|
| 398 | - and lien_triables($table_lien) |
|
| 399 | - and isset($env['objet']) and $env['objet'] |
|
| 400 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 401 | - and $objet_source |
|
| 402 | - and $id = intval($id) |
|
| 403 | - ) { |
|
| 404 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 405 | - return ($rang ?: ''); |
|
| 406 | - } |
|
| 407 | - return recuperer_numero($titre); |
|
| 390 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 391 | + // 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 |
|
| 392 | + if ( |
|
| 393 | + isset($env['form']) and $env['form'] |
|
| 394 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 395 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 396 | + and $r = objet_associable($env['_objet_lien']) |
|
| 397 | + and [$p, $table_lien] = $r |
|
| 398 | + and lien_triables($table_lien) |
|
| 399 | + and isset($env['objet']) and $env['objet'] |
|
| 400 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 401 | + and $objet_source |
|
| 402 | + and $id = intval($id) |
|
| 403 | + ) { |
|
| 404 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 405 | + return ($rang ?: ''); |
|
| 406 | + } |
|
| 407 | + return recuperer_numero($titre); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -431,72 +431,72 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | function calculer_balise_tri(string $champ_ou_sens, string $libelle, string $classe, string $tri_nom, string $tri_champ, string $tri_sens, $liste_tri_sens_defaut): string { |
| 433 | 433 | |
| 434 | - $url = self('&'); |
|
| 435 | - $tri_sens = (int) $tri_sens; |
|
| 436 | - $alias_sens = [ |
|
| 437 | - '<' => -1, |
|
| 438 | - '>' => 1, |
|
| 439 | - 'inverse' => -1, |
|
| 440 | - ]; |
|
| 441 | - |
|
| 442 | - // Normaliser la liste des sens de tri par défaut |
|
| 443 | - // On ajoute un jocker pour les champs non présents dans la liste |
|
| 444 | - // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 445 | - if (is_array($liste_tri_sens_defaut)) { |
|
| 446 | - $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 447 | - } else { |
|
| 448 | - $liste_tri_sens_defaut = [ |
|
| 449 | - '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 450 | - ]; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // Les sens de tri actuel et nouveau : |
|
| 454 | - // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 455 | - $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 456 | - if ($is_sens_fixe) { |
|
| 457 | - $tri_sens_actuel = $tri_sens; |
|
| 458 | - $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 459 | - // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 460 | - } elseif ($champ_ou_sens === $tri_champ) { |
|
| 461 | - $tri_sens_actuel = $tri_sens; |
|
| 462 | - $tri_sens_nouveau = $tri_sens * -1; |
|
| 463 | - // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 464 | - } else { |
|
| 465 | - $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // URL : ajouter le champ sur lequel porte le tri |
|
| 469 | - if (!$is_sens_fixe) { |
|
| 470 | - $param_tri = "tri$tri_nom"; |
|
| 471 | - $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 475 | - // c.à .d différent du sens par défaut pour le champ |
|
| 476 | - $param_sens = "sens$tri_nom"; |
|
| 477 | - $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 478 | - if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 479 | - $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 480 | - } else { |
|
| 481 | - $url = parametre_url($url, $param_sens, ''); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // Drapeau pour garder en session ? |
|
| 485 | - $param_memo = (!$is_sens_fixe ? $param_tri : $param_sens); |
|
| 486 | - $url = parametre_url($url, 'var_memotri', strncmp($tri_nom, 'session', 7) == 0 ? $param_memo : ''); |
|
| 487 | - |
|
| 488 | - // Classes : on indique le sens de tri et l'item exposé |
|
| 489 | - if (!$is_sens_fixe) { |
|
| 490 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 491 | - } |
|
| 492 | - if ($champ_ou_sens === $tri_champ) { |
|
| 493 | - $classe .= ' item-tri_actif'; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Lien |
|
| 497 | - $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 498 | - |
|
| 499 | - return $balise; |
|
| 434 | + $url = self('&'); |
|
| 435 | + $tri_sens = (int) $tri_sens; |
|
| 436 | + $alias_sens = [ |
|
| 437 | + '<' => -1, |
|
| 438 | + '>' => 1, |
|
| 439 | + 'inverse' => -1, |
|
| 440 | + ]; |
|
| 441 | + |
|
| 442 | + // Normaliser la liste des sens de tri par défaut |
|
| 443 | + // On ajoute un jocker pour les champs non présents dans la liste |
|
| 444 | + // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 445 | + if (is_array($liste_tri_sens_defaut)) { |
|
| 446 | + $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 447 | + } else { |
|
| 448 | + $liste_tri_sens_defaut = [ |
|
| 449 | + '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 450 | + ]; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // Les sens de tri actuel et nouveau : |
|
| 454 | + // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 455 | + $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 456 | + if ($is_sens_fixe) { |
|
| 457 | + $tri_sens_actuel = $tri_sens; |
|
| 458 | + $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 459 | + // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 460 | + } elseif ($champ_ou_sens === $tri_champ) { |
|
| 461 | + $tri_sens_actuel = $tri_sens; |
|
| 462 | + $tri_sens_nouveau = $tri_sens * -1; |
|
| 463 | + // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 464 | + } else { |
|
| 465 | + $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // URL : ajouter le champ sur lequel porte le tri |
|
| 469 | + if (!$is_sens_fixe) { |
|
| 470 | + $param_tri = "tri$tri_nom"; |
|
| 471 | + $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 475 | + // c.à .d différent du sens par défaut pour le champ |
|
| 476 | + $param_sens = "sens$tri_nom"; |
|
| 477 | + $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 478 | + if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 479 | + $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 480 | + } else { |
|
| 481 | + $url = parametre_url($url, $param_sens, ''); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // Drapeau pour garder en session ? |
|
| 485 | + $param_memo = (!$is_sens_fixe ? $param_tri : $param_sens); |
|
| 486 | + $url = parametre_url($url, 'var_memotri', strncmp($tri_nom, 'session', 7) == 0 ? $param_memo : ''); |
|
| 487 | + |
|
| 488 | + // Classes : on indique le sens de tri et l'item exposé |
|
| 489 | + if (!$is_sens_fixe) { |
|
| 490 | + $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 491 | + } |
|
| 492 | + if ($champ_ou_sens === $tri_champ) { |
|
| 493 | + $classe .= ' item-tri_actif'; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Lien |
|
| 497 | + $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 498 | + |
|
| 499 | + return $balise; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | 514 | function tri_protege_champ($t) { |
| 515 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 515 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -525,43 +525,43 @@ discard block |
||
| 525 | 525 | * @return string |
| 526 | 526 | */ |
| 527 | 527 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 528 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 529 | - return 'multi' . $senstri; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $champ = $t; |
|
| 533 | - |
|
| 534 | - $prefixe = ''; |
|
| 535 | - foreach (['num ', 'sinum '] as $p) { |
|
| 536 | - if (strpos($t, $p) === 0) { |
|
| 537 | - $champ = substr($t, strlen($p)); |
|
| 538 | - $prefixe = $p; |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 543 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 544 | - |
|
| 545 | - if (is_array($from)) { |
|
| 546 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 547 | - foreach ($from as $idt => $table_sql) { |
|
| 548 | - if ( |
|
| 549 | - $desc = $trouver_table($table_sql) |
|
| 550 | - and isset($desc['field'][$champ]) |
|
| 551 | - ) { |
|
| 552 | - $champ = "$idt.$champ"; |
|
| 553 | - break; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - switch ($prefixe) { |
|
| 558 | - case 'num ': |
|
| 559 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 560 | - case 'sinum ': |
|
| 561 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 562 | - default: |
|
| 563 | - return $champ . $senstri; |
|
| 564 | - } |
|
| 528 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 529 | + return 'multi' . $senstri; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $champ = $t; |
|
| 533 | + |
|
| 534 | + $prefixe = ''; |
|
| 535 | + foreach (['num ', 'sinum '] as $p) { |
|
| 536 | + if (strpos($t, $p) === 0) { |
|
| 537 | + $champ = substr($t, strlen($p)); |
|
| 538 | + $prefixe = $p; |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 543 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 544 | + |
|
| 545 | + if (is_array($from)) { |
|
| 546 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 547 | + foreach ($from as $idt => $table_sql) { |
|
| 548 | + if ( |
|
| 549 | + $desc = $trouver_table($table_sql) |
|
| 550 | + and isset($desc['field'][$champ]) |
|
| 551 | + ) { |
|
| 552 | + $champ = "$idt.$champ"; |
|
| 553 | + break; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + switch ($prefixe) { |
|
| 558 | + case 'num ': |
|
| 559 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 560 | + case 'sinum ': |
|
| 561 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 562 | + default: |
|
| 563 | + return $champ . $senstri; |
|
| 564 | + } |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -575,18 +575,18 @@ discard block |
||
| 575 | 575 | * @return string |
| 576 | 576 | */ |
| 577 | 577 | function tri_champ_select($t) { |
| 578 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 579 | - $t = substr($t, 6); |
|
| 580 | - $t = preg_replace(',\s,', '', $t); |
|
| 581 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 582 | - |
|
| 583 | - return $t; |
|
| 584 | - } |
|
| 585 | - if (trim($t) == 'hasard') { |
|
| 586 | - return 'rand() AS hasard'; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return "''"; |
|
| 578 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 579 | + $t = substr($t, 6); |
|
| 580 | + $t = preg_replace(',\s,', '', $t); |
|
| 581 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 582 | + |
|
| 583 | + return $t; |
|
| 584 | + } |
|
| 585 | + if (trim($t) == 'hasard') { |
|
| 586 | + return 'rand() AS hasard'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return "''"; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -598,16 +598,16 @@ discard block |
||
| 598 | 598 | * @return string |
| 599 | 599 | */ |
| 600 | 600 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 601 | - if (!is_array($valeurs)) { |
|
| 602 | - return ''; |
|
| 603 | - } |
|
| 604 | - $f = sql_serveur('quote', $serveur, true); |
|
| 605 | - if (!is_string($f) or !$f) { |
|
| 606 | - return ''; |
|
| 607 | - } |
|
| 608 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 609 | - |
|
| 610 | - return $valeurs; |
|
| 601 | + if (!is_array($valeurs)) { |
|
| 602 | + return ''; |
|
| 603 | + } |
|
| 604 | + $f = sql_serveur('quote', $serveur, true); |
|
| 605 | + if (!is_string($f) or !$f) { |
|
| 606 | + return ''; |
|
| 607 | + } |
|
| 608 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 609 | + |
|
| 610 | + return $valeurs; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -630,20 +630,20 @@ discard block |
||
| 630 | 630 | * Valeur $defaut sinon. |
| 631 | 631 | **/ |
| 632 | 632 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 633 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 634 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 635 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 636 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 637 | - $args[1] = $args[0]; |
|
| 638 | - $args[0] = $filtre; |
|
| 639 | - return image_graver(image_filtrer($args)); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $f = chercher_filtre($filtre); |
|
| 643 | - if (!$f) { |
|
| 644 | - return $defaut; |
|
| 645 | - } |
|
| 646 | - array_shift($args); // enlever $arg |
|
| 647 | - array_shift($args); // enlever $filtre |
|
| 648 | - return $f($arg, ...$args); |
|
| 633 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 634 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 635 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 636 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 637 | + $args[1] = $args[0]; |
|
| 638 | + $args[0] = $filtre; |
|
| 639 | + return image_graver(image_filtrer($args)); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $f = chercher_filtre($filtre); |
|
| 643 | + if (!$f) { |
|
| 644 | + return $defaut; |
|
| 645 | + } |
|
| 646 | + array_shift($args); // enlever $arg |
|
| 647 | + array_shift($args); // enlever $filtre |
|
| 648 | + return $f($arg, ...$args); |
|
| 649 | 649 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | $GLOBALS['contexte'] = calculer_contexte(); |
| 39 | 39 | $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
| 40 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 40 | + $page['contexte_implicite']['cache'] = $fond.preg_replace( |
|
| 41 | 41 | ',\.[a-zA-Z0-9]*$,', |
| 42 | 42 | '', |
| 43 | 43 | preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | if ($page === '') { |
| 139 | 139 | $erreur = _T( |
| 140 | 140 | 'info_erreur_squelette2', |
| 141 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 141 | + ['fichier' => spip_htmlspecialchars($fond).'.'._EXTENSION_SQUELETTES] |
|
| 142 | 142 | ); |
| 143 | 143 | erreur_squelette($erreur); |
| 144 | 144 | // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
| 184 | 184 | and !isset($page['entetes']['Last-Modified']) |
| 185 | 185 | ) { |
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified).' GMT'; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // fermer la connexion apres les headers si requete HEAD |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | 'spip_version_code' => $GLOBALS['spip_version_code'], |
| 249 | 249 | ]; |
| 250 | 250 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 251 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 251 | + $contexte_implicite['host'] .= '|'.$_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | return $contexte_implicite; |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | if (is_null($id)) { |
| 582 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | + $msg = "modeles/$modele : "._T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 583 | 583 | erreur_squelette($msg); |
| 584 | 584 | // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
| 585 | 585 | $id = 0; |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
| 629 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 629 | + if (!trouve_modele($fond = ($type.'_'.$soustype))) { |
|
| 630 | 630 | $fond = ''; |
| 631 | 631 | $class = $soustype; |
| 632 | 632 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | |
| 642 | 642 | return false; |
| 643 | 643 | } |
| 644 | - $fond = 'modeles/' . $fond; |
|
| 644 | + $fond = 'modeles/'.$fond; |
|
| 645 | 645 | // Creer le contexte |
| 646 | 646 | $contexte = $env; |
| 647 | 647 | $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | // sinon, s'il y a un lien, on l'ajoute classiquement |
| 683 | 683 | if ( |
| 684 | 684 | strstr( |
| 685 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 685 | + ' '.($classes = extraire_attribut($retour, 'class')).' ', |
|
| 686 | 686 | 'spip_lien_ok' |
| 687 | 687 | ) |
| 688 | 688 | ) { |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | ); |
| 694 | 694 | } else { |
| 695 | 695 | if ($lien) { |
| 696 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 696 | + $retour = "<a href='".$lien['href']."' class='".$lien['class']."'>".$retour.'</a>'; |
|
| 697 | 697 | } |
| 698 | 698 | } |
| 699 | 699 | |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | return $page; |
| 718 | 718 | } |
| 719 | 719 | // eval $page et affecte $res |
| 720 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 720 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 721 | 721 | |
| 722 | 722 | // Lever un drapeau (global) si le fond utilise #SESSION |
| 723 | 723 | // a destination de public/parametrer |
@@ -785,16 +785,16 @@ discard block |
||
| 785 | 785 | if (($pos = strpos($head, '<head>')) !== false) { |
| 786 | 786 | $head = substr_replace($head, $base, $pos + 6, 0); |
| 787 | 787 | } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
| 788 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 788 | + $head = str_replace($r[0], $r[0].$base, $head); |
|
| 789 | 789 | } |
| 790 | - $texte = $head . substr($texte, $poshead); |
|
| 790 | + $texte = $head.substr($texte, $poshead); |
|
| 791 | 791 | } |
| 792 | 792 | if ($href_base) { |
| 793 | 793 | // gerer les ancres |
| 794 | 794 | $base = $_SERVER['REQUEST_URI']; |
| 795 | 795 | // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
| 796 | 796 | if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
| 797 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 797 | + $base = str_replace(["'", '"', '<'], ['%27', '%22', '%3C'], $base); |
|
| 798 | 798 | } |
| 799 | 799 | if (strpos($texte, "href='#") !== false) { |
| 800 | 800 | $texte = str_replace("href='#", "href='$base#", $texte); |
@@ -20,178 +20,178 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // En cas de modification, il faut aussi actualiser la regexp de nettoyer_uri_var() dans inc/utils.php |
| 27 | 27 | if (!defined('_CONTEXTE_IGNORE_VARIABLES')) { |
| 28 | - define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 28 | + define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | function assembler($fond, string $connect = '') { |
| 32 | 32 | |
| 33 | - $chemin_cache = null; |
|
| 34 | - $lastmodified = null; |
|
| 35 | - $res = null; |
|
| 36 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 37 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 38 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 39 | - |
|
| 40 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 41 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 42 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 43 | - ',\.[a-zA-Z0-9]*$,', |
|
| 44 | - '', |
|
| 45 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 46 | - ); |
|
| 47 | - // Cette fonction est utilisee deux fois |
|
| 48 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 49 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 50 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 51 | - if ($cacher) { |
|
| 52 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 53 | - } else { |
|
| 54 | - $GLOBALS['use_cache'] = -1; |
|
| 55 | - } |
|
| 56 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 57 | - if ($res) { |
|
| 58 | - return ['texte' => $res]; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!$chemin_cache || !$lastmodified) { |
|
| 62 | - $lastmodified = time(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 66 | - $calculer_page = true; |
|
| 67 | - |
|
| 68 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 69 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 70 | - // pages sont dynamiques) |
|
| 71 | - if ( |
|
| 72 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 73 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 74 | - and $chemin_cache |
|
| 75 | - and isset($page['entetes']) |
|
| 76 | - and isset($page['entetes']['Cache-Control']) |
|
| 77 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 78 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 79 | - ) { |
|
| 80 | - $since = preg_replace( |
|
| 81 | - '/;.*/', |
|
| 82 | - '', |
|
| 83 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 84 | - ); |
|
| 85 | - $since = str_replace('GMT', '', $since); |
|
| 86 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 87 | - $page['status'] = 304; |
|
| 88 | - $headers_only = true; |
|
| 89 | - $calculer_page = false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 94 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 95 | - if (!$calculer_page) { |
|
| 96 | - $page['texte'] = ''; |
|
| 97 | - } else { |
|
| 98 | - // si la page est prise dans le cache |
|
| 99 | - if (!$GLOBALS['use_cache']) { |
|
| 100 | - // Informer les boutons d'admin du contexte |
|
| 101 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 102 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 103 | - |
|
| 104 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 105 | - // d'inversion url => objet |
|
| 106 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 107 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 108 | - #unset($_ENV['url_propre']); |
|
| 109 | - } else { |
|
| 110 | - // Compat ascendante : |
|
| 111 | - // 1. $contexte est global |
|
| 112 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 113 | - // et calculer la page |
|
| 114 | - if (!test_espace_prive()) { |
|
| 115 | - include_spip('inc/urls'); |
|
| 116 | - [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 117 | - nettoyer_uri(), |
|
| 118 | - $fond, |
|
| 119 | - $GLOBALS['contexte'], |
|
| 120 | - true |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - // squelette par defaut |
|
| 124 | - if (!strlen($fond ?? '')) { |
|
| 125 | - $fond = 'sommaire'; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // produire la page : peut mettre a jour $lastmodified |
|
| 129 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 130 | - $page = $produire_page( |
|
| 131 | - $fond, |
|
| 132 | - $GLOBALS['contexte'], |
|
| 133 | - $GLOBALS['use_cache'], |
|
| 134 | - $chemin_cache, |
|
| 135 | - null, |
|
| 136 | - $page, |
|
| 137 | - $lastmodified, |
|
| 138 | - $connect |
|
| 139 | - ); |
|
| 140 | - if ($page === '') { |
|
| 141 | - $erreur = _T( |
|
| 142 | - 'info_erreur_squelette2', |
|
| 143 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 144 | - ); |
|
| 145 | - erreur_squelette($erreur); |
|
| 146 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 147 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ($page and $chemin_cache) { |
|
| 152 | - $page['cache'] = $chemin_cache; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - auto_content_type($page); |
|
| 156 | - |
|
| 157 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 158 | - |
|
| 159 | - // Definir les entetes si ce n'est fait |
|
| 160 | - if (!$GLOBALS['flag_preserver']) { |
|
| 161 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 162 | - if ( |
|
| 163 | - trim($page['texte']) === '' |
|
| 164 | - and _VAR_MODE !== 'debug' |
|
| 165 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 166 | - ) { |
|
| 167 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 168 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 169 | - } |
|
| 170 | - // pas de cache client en mode 'observation' |
|
| 171 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 172 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 173 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Entete Last-Modified: |
|
| 179 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | - if ( |
|
| 182 | - $lastmodified |
|
| 183 | - and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | - and !isset($page['entetes']['Last-Modified']) |
|
| 185 | - ) { |
|
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // fermer la connexion apres les headers si requete HEAD |
|
| 190 | - if ($headers_only) { |
|
| 191 | - $page['entetes']['Connection'] = 'close'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $page; |
|
| 33 | + $chemin_cache = null; |
|
| 34 | + $lastmodified = null; |
|
| 35 | + $res = null; |
|
| 36 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 37 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 38 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 39 | + |
|
| 40 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 41 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 42 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 43 | + ',\.[a-zA-Z0-9]*$,', |
|
| 44 | + '', |
|
| 45 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 46 | + ); |
|
| 47 | + // Cette fonction est utilisee deux fois |
|
| 48 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 49 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 50 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 51 | + if ($cacher) { |
|
| 52 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 53 | + } else { |
|
| 54 | + $GLOBALS['use_cache'] = -1; |
|
| 55 | + } |
|
| 56 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 57 | + if ($res) { |
|
| 58 | + return ['texte' => $res]; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!$chemin_cache || !$lastmodified) { |
|
| 62 | + $lastmodified = time(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 66 | + $calculer_page = true; |
|
| 67 | + |
|
| 68 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 69 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 70 | + // pages sont dynamiques) |
|
| 71 | + if ( |
|
| 72 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 73 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 74 | + and $chemin_cache |
|
| 75 | + and isset($page['entetes']) |
|
| 76 | + and isset($page['entetes']['Cache-Control']) |
|
| 77 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 78 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 79 | + ) { |
|
| 80 | + $since = preg_replace( |
|
| 81 | + '/;.*/', |
|
| 82 | + '', |
|
| 83 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 84 | + ); |
|
| 85 | + $since = str_replace('GMT', '', $since); |
|
| 86 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 87 | + $page['status'] = 304; |
|
| 88 | + $headers_only = true; |
|
| 89 | + $calculer_page = false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 94 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 95 | + if (!$calculer_page) { |
|
| 96 | + $page['texte'] = ''; |
|
| 97 | + } else { |
|
| 98 | + // si la page est prise dans le cache |
|
| 99 | + if (!$GLOBALS['use_cache']) { |
|
| 100 | + // Informer les boutons d'admin du contexte |
|
| 101 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 102 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 103 | + |
|
| 104 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 105 | + // d'inversion url => objet |
|
| 106 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 107 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 108 | + #unset($_ENV['url_propre']); |
|
| 109 | + } else { |
|
| 110 | + // Compat ascendante : |
|
| 111 | + // 1. $contexte est global |
|
| 112 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 113 | + // et calculer la page |
|
| 114 | + if (!test_espace_prive()) { |
|
| 115 | + include_spip('inc/urls'); |
|
| 116 | + [$fond, $GLOBALS['contexte'], $url_redirect] = urls_decoder_url( |
|
| 117 | + nettoyer_uri(), |
|
| 118 | + $fond, |
|
| 119 | + $GLOBALS['contexte'], |
|
| 120 | + true |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + // squelette par defaut |
|
| 124 | + if (!strlen($fond ?? '')) { |
|
| 125 | + $fond = 'sommaire'; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // produire la page : peut mettre a jour $lastmodified |
|
| 129 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 130 | + $page = $produire_page( |
|
| 131 | + $fond, |
|
| 132 | + $GLOBALS['contexte'], |
|
| 133 | + $GLOBALS['use_cache'], |
|
| 134 | + $chemin_cache, |
|
| 135 | + null, |
|
| 136 | + $page, |
|
| 137 | + $lastmodified, |
|
| 138 | + $connect |
|
| 139 | + ); |
|
| 140 | + if ($page === '') { |
|
| 141 | + $erreur = _T( |
|
| 142 | + 'info_erreur_squelette2', |
|
| 143 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 144 | + ); |
|
| 145 | + erreur_squelette($erreur); |
|
| 146 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 147 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ($page and $chemin_cache) { |
|
| 152 | + $page['cache'] = $chemin_cache; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + auto_content_type($page); |
|
| 156 | + |
|
| 157 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 158 | + |
|
| 159 | + // Definir les entetes si ce n'est fait |
|
| 160 | + if (!$GLOBALS['flag_preserver']) { |
|
| 161 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 162 | + if ( |
|
| 163 | + trim($page['texte']) === '' |
|
| 164 | + and _VAR_MODE !== 'debug' |
|
| 165 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 166 | + ) { |
|
| 167 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 168 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 169 | + } |
|
| 170 | + // pas de cache client en mode 'observation' |
|
| 171 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 172 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 173 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Entete Last-Modified: |
|
| 179 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | + if ( |
|
| 182 | + $lastmodified |
|
| 183 | + and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | + and !isset($page['entetes']['Last-Modified']) |
|
| 185 | + ) { |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // fermer la connexion apres les headers si requete HEAD |
|
| 190 | + if ($headers_only) { |
|
| 191 | + $page['entetes']['Connection'] = 'close'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $page; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -208,19 +208,19 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function calculer_contexte() { |
| 210 | 210 | |
| 211 | - $contexte = []; |
|
| 212 | - foreach ($_GET as $var => $val) { |
|
| 213 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 214 | - $contexte[$var] = $val; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - foreach ($_POST as $var => $val) { |
|
| 218 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | - $contexte[$var] = $val; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $contexte; |
|
| 211 | + $contexte = []; |
|
| 212 | + foreach ($_GET as $var => $val) { |
|
| 213 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 214 | + $contexte[$var] = $val; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + foreach ($_POST as $var => $val) { |
|
| 218 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 219 | + $contexte[$var] = $val; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $contexte; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -231,25 +231,25 @@ discard block |
||
| 231 | 231 | * @return array |
| 232 | 232 | */ |
| 233 | 233 | function calculer_contexte_implicite() { |
| 234 | - static $notes = null; |
|
| 235 | - if (is_null($notes)) { |
|
| 236 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 237 | - } |
|
| 238 | - $contexte_implicite = [ |
|
| 239 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 240 | - 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 241 | - 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 242 | - 'espace' => test_espace_prive(), |
|
| 243 | - 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 244 | - 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 245 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 246 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 247 | - ]; |
|
| 248 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 249 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - return $contexte_implicite; |
|
| 234 | + static $notes = null; |
|
| 235 | + if (is_null($notes)) { |
|
| 236 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 237 | + } |
|
| 238 | + $contexte_implicite = [ |
|
| 239 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 240 | + 'host' => ($_SERVER['HTTP_HOST'] ?? null), |
|
| 241 | + 'https' => ($_SERVER['HTTPS'] ?? ''), |
|
| 242 | + 'espace' => test_espace_prive(), |
|
| 243 | + 'marqueur' => ($GLOBALS['marqueur'] ?? ''), |
|
| 244 | + 'marqueur_skel' => ($GLOBALS['marqueur_skel'] ?? ''), |
|
| 245 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 246 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 247 | + ]; |
|
| 248 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 249 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + return $contexte_implicite; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // |
@@ -258,55 +258,55 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | function auto_content_type($page) { |
| 260 | 260 | |
| 261 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 262 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 263 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 264 | - $page['texte'] |
|
| 265 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 266 | - } |
|
| 261 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 262 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 263 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 264 | + $page['texte'] |
|
| 265 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 266 | + } |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | function inclure_page($fond, $contexte, string $connect = '') { |
| 270 | - $use_cache = null; |
|
| 271 | - $chemin_cache = null; |
|
| 272 | - $lastinclude = null; |
|
| 273 | - $res = null; |
|
| 274 | - static $cacher, $produire_page; |
|
| 275 | - |
|
| 276 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | - // (cette precaution n'est probablement plus utile) |
|
| 279 | - unset($contexte['fond']); |
|
| 280 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | - if (is_null($cacher)) { |
|
| 283 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | - } |
|
| 285 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | - if ($cacher) { |
|
| 288 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | - } else { |
|
| 290 | - $use_cache = -1; |
|
| 291 | - } |
|
| 292 | - // $res = message d'erreur : on sort de la |
|
| 293 | - if ($res) { |
|
| 294 | - return ['texte' => $res]; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | - // produire la page : peut mettre a jour $lastinclude |
|
| 299 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | - if ($use_cache) { |
|
| 301 | - if (is_null($produire_page)) { |
|
| 302 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | - } |
|
| 304 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | - } |
|
| 306 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | - $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 308 | - |
|
| 309 | - return $page; |
|
| 270 | + $use_cache = null; |
|
| 271 | + $chemin_cache = null; |
|
| 272 | + $lastinclude = null; |
|
| 273 | + $res = null; |
|
| 274 | + static $cacher, $produire_page; |
|
| 275 | + |
|
| 276 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | + // (cette precaution n'est probablement plus utile) |
|
| 279 | + unset($contexte['fond']); |
|
| 280 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | + if (is_null($cacher)) { |
|
| 283 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | + } |
|
| 285 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | + if ($cacher) { |
|
| 288 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | + } else { |
|
| 290 | + $use_cache = -1; |
|
| 291 | + } |
|
| 292 | + // $res = message d'erreur : on sort de la |
|
| 293 | + if ($res) { |
|
| 294 | + return ['texte' => $res]; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | + // produire la page : peut mettre a jour $lastinclude |
|
| 299 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | + if ($use_cache) { |
|
| 301 | + if (is_null($produire_page)) { |
|
| 302 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | + } |
|
| 304 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | + } |
|
| 306 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | + $GLOBALS['lastmodified'] = max(($GLOBALS['lastmodified'] ?? 0), $lastinclude); |
|
| 308 | + |
|
| 309 | + return $page; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -324,41 +324,41 @@ discard block |
||
| 324 | 324 | * @return array |
| 325 | 325 | */ |
| 326 | 326 | function public_produire_page_dist( |
| 327 | - $fond, |
|
| 328 | - $contexte, |
|
| 329 | - $use_cache, |
|
| 330 | - $chemin_cache, |
|
| 331 | - $contexte_cache, |
|
| 332 | - &$page, |
|
| 333 | - &$lastinclude, |
|
| 334 | - $connect = '' |
|
| 327 | + $fond, |
|
| 328 | + $contexte, |
|
| 329 | + $use_cache, |
|
| 330 | + $chemin_cache, |
|
| 331 | + $contexte_cache, |
|
| 332 | + &$page, |
|
| 333 | + &$lastinclude, |
|
| 334 | + $connect = '' |
|
| 335 | 335 | ) { |
| 336 | - static $parametrer, $cacher; |
|
| 337 | - if (!$parametrer) { |
|
| 338 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | - } |
|
| 340 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | - // et on l'enregistre sur le disque |
|
| 342 | - if ( |
|
| 343 | - $chemin_cache |
|
| 344 | - and $use_cache > -1 |
|
| 345 | - and is_array($page) |
|
| 346 | - and count($page) |
|
| 347 | - and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | - and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | - ) { |
|
| 350 | - if (is_null($cacher)) { |
|
| 351 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | - } |
|
| 353 | - $lastinclude = time(); |
|
| 354 | - if ($cacher) { |
|
| 355 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | - } else { |
|
| 357 | - $use_cache = -1; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $page; |
|
| 336 | + static $parametrer, $cacher; |
|
| 337 | + if (!$parametrer) { |
|
| 338 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | + } |
|
| 340 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | + // et on l'enregistre sur le disque |
|
| 342 | + if ( |
|
| 343 | + $chemin_cache |
|
| 344 | + and $use_cache > -1 |
|
| 345 | + and is_array($page) |
|
| 346 | + and count($page) |
|
| 347 | + and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | + and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | + ) { |
|
| 350 | + if (is_null($cacher)) { |
|
| 351 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | + } |
|
| 353 | + $lastinclude = time(); |
|
| 354 | + if ($cacher) { |
|
| 355 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | + } else { |
|
| 357 | + $use_cache = -1; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $page; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Fonction inseree par le compilateur dans le code compile. |
@@ -372,14 +372,14 @@ discard block |
||
| 372 | 372 | // 4: langue |
| 373 | 373 | |
| 374 | 374 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 375 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | - |
|
| 377 | - if (!is_array($contexte_exec)) { |
|
| 378 | - echo $contexte_exec; |
|
| 379 | - } // message d'erreur etc |
|
| 380 | - else { |
|
| 381 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | - } |
|
| 375 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | + |
|
| 377 | + if (!is_array($contexte_exec)) { |
|
| 378 | + echo $contexte_exec; |
|
| 379 | + } // message d'erreur etc |
|
| 380 | + else { |
|
| 381 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -392,101 +392,101 @@ discard block |
||
| 392 | 392 | * @return string |
| 393 | 393 | */ |
| 394 | 394 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 395 | - if (is_array($texte)) { |
|
| 396 | - [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 397 | - |
|
| 398 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 399 | - $d = $GLOBALS['delais'] ?? null; |
|
| 400 | - $GLOBALS['delais'] = $delainc; |
|
| 401 | - |
|
| 402 | - $page = recuperer_fond( |
|
| 403 | - $fond, |
|
| 404 | - $contexte_inclus, |
|
| 405 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 406 | - ); |
|
| 407 | - |
|
| 408 | - $texte = $page['texte']; |
|
| 409 | - |
|
| 410 | - $GLOBALS['delais'] = $d; |
|
| 411 | - // Faire remonter les entetes |
|
| 412 | - if ( |
|
| 413 | - isset($page['entetes']) |
|
| 414 | - and is_array($page['entetes']) |
|
| 415 | - ) { |
|
| 416 | - // mais pas toutes |
|
| 417 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 418 | - unset($page['entetes']['Content-Type']); |
|
| 419 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 420 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 421 | - $GLOBALS['page']['entetes'] = []; |
|
| 422 | - } |
|
| 423 | - $GLOBALS['page']['entetes'] = |
|
| 424 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 428 | - if ( |
|
| 429 | - isset($page['contexte']['_pipelines']) |
|
| 430 | - and is_array($page['contexte']['_pipelines']) |
|
| 431 | - and count($page['contexte']['_pipelines']) |
|
| 432 | - ) { |
|
| 433 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 434 | - $args['contexte'] = $page['contexte']; |
|
| 435 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 436 | - $texte = pipeline( |
|
| 437 | - $pipe, |
|
| 438 | - [ |
|
| 439 | - 'data' => $texte, |
|
| 440 | - 'args' => $args |
|
| 441 | - ] |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | - $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 450 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | - } |
|
| 452 | - if ($echo) { |
|
| 453 | - echo $texte; |
|
| 454 | - } else { |
|
| 455 | - return $texte; |
|
| 456 | - } |
|
| 395 | + if (is_array($texte)) { |
|
| 396 | + [$fond, $delainc, $contexte_inclus] = $texte; |
|
| 397 | + |
|
| 398 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 399 | + $d = $GLOBALS['delais'] ?? null; |
|
| 400 | + $GLOBALS['delais'] = $delainc; |
|
| 401 | + |
|
| 402 | + $page = recuperer_fond( |
|
| 403 | + $fond, |
|
| 404 | + $contexte_inclus, |
|
| 405 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 406 | + ); |
|
| 407 | + |
|
| 408 | + $texte = $page['texte']; |
|
| 409 | + |
|
| 410 | + $GLOBALS['delais'] = $d; |
|
| 411 | + // Faire remonter les entetes |
|
| 412 | + if ( |
|
| 413 | + isset($page['entetes']) |
|
| 414 | + and is_array($page['entetes']) |
|
| 415 | + ) { |
|
| 416 | + // mais pas toutes |
|
| 417 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 418 | + unset($page['entetes']['Content-Type']); |
|
| 419 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 420 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 421 | + $GLOBALS['page']['entetes'] = []; |
|
| 422 | + } |
|
| 423 | + $GLOBALS['page']['entetes'] = |
|
| 424 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 428 | + if ( |
|
| 429 | + isset($page['contexte']['_pipelines']) |
|
| 430 | + and is_array($page['contexte']['_pipelines']) |
|
| 431 | + and count($page['contexte']['_pipelines']) |
|
| 432 | + ) { |
|
| 433 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 434 | + $args['contexte'] = $page['contexte']; |
|
| 435 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 436 | + $texte = pipeline( |
|
| 437 | + $pipe, |
|
| 438 | + [ |
|
| 439 | + 'data' => $texte, |
|
| 440 | + 'args' => $args |
|
| 441 | + ] |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | + $ligne = intval($contexte_compil[3] ?? $contexte_compil); |
|
| 450 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | + } |
|
| 452 | + if ($echo) { |
|
| 453 | + echo $texte; |
|
| 454 | + } else { |
|
| 455 | + return $texte; |
|
| 456 | + } |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | function message_page_indisponible($page, $contexte) { |
| 460 | - static $deja = false; |
|
| 461 | - if ($deja) { |
|
| 462 | - return 'erreur'; |
|
| 463 | - } |
|
| 464 | - $codes = [ |
|
| 465 | - '404' => '404 Not Found', |
|
| 466 | - '503' => '503 Service Unavailable', |
|
| 467 | - ]; |
|
| 468 | - |
|
| 469 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 470 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 471 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 472 | - if (!isset($contexte['lang'])) { |
|
| 473 | - include_spip('inc/lang'); |
|
| 474 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - $deja = true; |
|
| 478 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 479 | - // ex restriction d'acces => 401 |
|
| 480 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 481 | - |
|
| 482 | - // produire la page d'erreur |
|
| 483 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 484 | - if (!$page) { |
|
| 485 | - $page = inclure_page('404', $contexte); |
|
| 486 | - } |
|
| 487 | - $page['status'] = $contexte['status']; |
|
| 488 | - |
|
| 489 | - return $page; |
|
| 460 | + static $deja = false; |
|
| 461 | + if ($deja) { |
|
| 462 | + return 'erreur'; |
|
| 463 | + } |
|
| 464 | + $codes = [ |
|
| 465 | + '404' => '404 Not Found', |
|
| 466 | + '503' => '503 Service Unavailable', |
|
| 467 | + ]; |
|
| 468 | + |
|
| 469 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 470 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 471 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 472 | + if (!isset($contexte['lang'])) { |
|
| 473 | + include_spip('inc/lang'); |
|
| 474 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + $deja = true; |
|
| 478 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 479 | + // ex restriction d'acces => 401 |
|
| 480 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 481 | + |
|
| 482 | + // produire la page d'erreur |
|
| 483 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 484 | + if (!$page) { |
|
| 485 | + $page = inclure_page('404', $contexte); |
|
| 486 | + } |
|
| 487 | + $page['status'] = $contexte['status']; |
|
| 488 | + |
|
| 489 | + return $page; |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -498,44 +498,44 @@ discard block |
||
| 498 | 498 | * @return mixed |
| 499 | 499 | */ |
| 500 | 500 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 501 | - static $balise_dyn_appellee_par_modele = null; |
|
| 502 | - switch ($operation) { |
|
| 503 | - case 'read': |
|
| 504 | - return $balise_dyn_appellee_par_modele; |
|
| 505 | - case 'reset': |
|
| 506 | - $balise_dyn_appellee_par_modele = null; |
|
| 507 | - return null; |
|
| 508 | - case 'set': |
|
| 509 | - default: |
|
| 510 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 511 | - return $arg; |
|
| 512 | - } |
|
| 501 | + static $balise_dyn_appellee_par_modele = null; |
|
| 502 | + switch ($operation) { |
|
| 503 | + case 'read': |
|
| 504 | + return $balise_dyn_appellee_par_modele; |
|
| 505 | + case 'reset': |
|
| 506 | + $balise_dyn_appellee_par_modele = null; |
|
| 507 | + return null; |
|
| 508 | + case 'set': |
|
| 509 | + default: |
|
| 510 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 511 | + return $arg; |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // temporairement ici : a mettre dans le futur inc/modeles |
| 516 | 516 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 517 | 517 | function creer_contexte_de_modele($args) { |
| 518 | - $contexte = []; |
|
| 519 | - foreach ($args as $var => $val) { |
|
| 520 | - if (is_int($var)) { // argument pas formate |
|
| 521 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 522 | - $var = 'align'; |
|
| 523 | - $contexte[$var] = $val; |
|
| 524 | - } else { |
|
| 525 | - $args = explode('=', $val); |
|
| 526 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 527 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 528 | - } else // notation abregee |
|
| 529 | - { |
|
| 530 | - $contexte[trim($val)] = trim($val); |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - } else { |
|
| 534 | - $contexte[$var] = $val; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - return $contexte; |
|
| 518 | + $contexte = []; |
|
| 519 | + foreach ($args as $var => $val) { |
|
| 520 | + if (is_int($var)) { // argument pas formate |
|
| 521 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 522 | + $var = 'align'; |
|
| 523 | + $contexte[$var] = $val; |
|
| 524 | + } else { |
|
| 525 | + $args = explode('=', $val); |
|
| 526 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 527 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 528 | + } else // notation abregee |
|
| 529 | + { |
|
| 530 | + $contexte[trim($val)] = trim($val); |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + } else { |
|
| 534 | + $contexte[$var] = $val; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + return $contexte; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -550,43 +550,43 @@ discard block |
||
| 550 | 550 | * @return string |
| 551 | 551 | */ |
| 552 | 552 | function styliser_modele($modele, $id, $contexte = null) { |
| 553 | - static $styliseurs = null; |
|
| 554 | - if (is_null($styliseurs)) { |
|
| 555 | - $tables_objet = lister_tables_objets_sql(); |
|
| 556 | - foreach ($tables_objet as $table => $desc) { |
|
| 557 | - if ( |
|
| 558 | - isset($desc['modeles']) and $desc['modeles'] |
|
| 559 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 560 | - and function_exists($desc['modeles_styliser']) |
|
| 561 | - ) { |
|
| 562 | - $primary = id_table_objet($table); |
|
| 563 | - foreach ($desc['modeles'] as $m) { |
|
| 564 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - if (isset($styliseurs[$modele])) { |
|
| 571 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 572 | - $primary = $styliseurs[$modele]['primary']; |
|
| 573 | - if (is_null($id) and $contexte) { |
|
| 574 | - if (isset($contexte['id'])) { |
|
| 575 | - $id = $contexte['id']; |
|
| 576 | - } elseif (isset($contexte[$primary])) { |
|
| 577 | - $id = $contexte[$primary]; |
|
| 578 | - } |
|
| 579 | - } |
|
| 580 | - if (is_null($id)) { |
|
| 581 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | - erreur_squelette($msg); |
|
| 583 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 584 | - $id = 0; |
|
| 585 | - } |
|
| 586 | - $modele = $styliseur($modele, $id); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $modele; |
|
| 553 | + static $styliseurs = null; |
|
| 554 | + if (is_null($styliseurs)) { |
|
| 555 | + $tables_objet = lister_tables_objets_sql(); |
|
| 556 | + foreach ($tables_objet as $table => $desc) { |
|
| 557 | + if ( |
|
| 558 | + isset($desc['modeles']) and $desc['modeles'] |
|
| 559 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 560 | + and function_exists($desc['modeles_styliser']) |
|
| 561 | + ) { |
|
| 562 | + $primary = id_table_objet($table); |
|
| 563 | + foreach ($desc['modeles'] as $m) { |
|
| 564 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + if (isset($styliseurs[$modele])) { |
|
| 571 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 572 | + $primary = $styliseurs[$modele]['primary']; |
|
| 573 | + if (is_null($id) and $contexte) { |
|
| 574 | + if (isset($contexte['id'])) { |
|
| 575 | + $id = $contexte['id']; |
|
| 576 | + } elseif (isset($contexte[$primary])) { |
|
| 577 | + $id = $contexte[$primary]; |
|
| 578 | + } |
|
| 579 | + } |
|
| 580 | + if (is_null($id)) { |
|
| 581 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | + erreur_squelette($msg); |
|
| 583 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 584 | + $id = 0; |
|
| 585 | + } |
|
| 586 | + $modele = $styliseur($modele, $id); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $modele; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -603,102 +603,102 @@ discard block |
||
| 603 | 603 | */ |
| 604 | 604 | function inclure_modele($type, $id, $params, $lien, string $connect = '', $env = []) { |
| 605 | 605 | |
| 606 | - static $compteur; |
|
| 607 | - if (++$compteur > 10) { |
|
| 608 | - return ''; |
|
| 609 | - } # ne pas boucler indefiniment |
|
| 610 | - |
|
| 611 | - $type = strtolower($type); |
|
| 612 | - $type = styliser_modele($type, $id); |
|
| 613 | - |
|
| 614 | - $fond = $class = ''; |
|
| 615 | - |
|
| 616 | - $params = array_filter(explode('|', $params)); |
|
| 617 | - if ($params) { |
|
| 618 | - $soustype = current($params); |
|
| 619 | - $soustype = strtolower(trim($soustype)); |
|
| 620 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 621 | - $soustype = next($params); |
|
| 622 | - $soustype = strtolower($soustype); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 626 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 627 | - $fond = ''; |
|
| 628 | - $class = $soustype; |
|
| 629 | - } |
|
| 630 | - // enlever le sous type des params |
|
| 631 | - $params = array_diff($params, [$soustype]); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 636 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 637 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 638 | - |
|
| 639 | - return false; |
|
| 640 | - } |
|
| 641 | - $fond = 'modeles/' . $fond; |
|
| 642 | - // Creer le contexte |
|
| 643 | - $contexte = $env; |
|
| 644 | - $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 645 | - |
|
| 646 | - // Le numero du modele est mis dans l'environnement |
|
| 647 | - // d'une part sous l'identifiant "id" |
|
| 648 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 649 | - // par la fonction id_table_objet, |
|
| 650 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 651 | - $_id = id_table_objet($type); |
|
| 652 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 653 | - |
|
| 654 | - if (isset($class)) { |
|
| 655 | - $contexte['class'] = $class; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 659 | - if ($lien) { |
|
| 660 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 661 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 662 | - $contexte['lien_class'] = $lien['class']; |
|
| 663 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 664 | - $contexte['lien_title'] = $lien['title']; |
|
| 665 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - // Traiter les parametres |
|
| 669 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 670 | - $arg_list = creer_contexte_de_modele($params); |
|
| 671 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 672 | - $contexte = array_merge($contexte, $arg_list); |
|
| 673 | - |
|
| 674 | - // Appliquer le modele avec le contexte |
|
| 675 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 676 | - |
|
| 677 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 678 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 679 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 680 | - if ( |
|
| 681 | - strstr( |
|
| 682 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 683 | - 'spip_lien_ok' |
|
| 684 | - ) |
|
| 685 | - ) { |
|
| 686 | - $retour = inserer_attribut( |
|
| 687 | - $retour, |
|
| 688 | - 'class', |
|
| 689 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 690 | - ); |
|
| 691 | - } else { |
|
| 692 | - if ($lien) { |
|
| 693 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 694 | - } |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - $compteur--; |
|
| 698 | - |
|
| 699 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 700 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 701 | - : $retour; |
|
| 606 | + static $compteur; |
|
| 607 | + if (++$compteur > 10) { |
|
| 608 | + return ''; |
|
| 609 | + } # ne pas boucler indefiniment |
|
| 610 | + |
|
| 611 | + $type = strtolower($type); |
|
| 612 | + $type = styliser_modele($type, $id); |
|
| 613 | + |
|
| 614 | + $fond = $class = ''; |
|
| 615 | + |
|
| 616 | + $params = array_filter(explode('|', $params)); |
|
| 617 | + if ($params) { |
|
| 618 | + $soustype = current($params); |
|
| 619 | + $soustype = strtolower(trim($soustype)); |
|
| 620 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 621 | + $soustype = next($params); |
|
| 622 | + $soustype = strtolower($soustype); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 626 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 627 | + $fond = ''; |
|
| 628 | + $class = $soustype; |
|
| 629 | + } |
|
| 630 | + // enlever le sous type des params |
|
| 631 | + $params = array_diff($params, [$soustype]); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 636 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 637 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 638 | + |
|
| 639 | + return false; |
|
| 640 | + } |
|
| 641 | + $fond = 'modeles/' . $fond; |
|
| 642 | + // Creer le contexte |
|
| 643 | + $contexte = $env; |
|
| 644 | + $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 645 | + |
|
| 646 | + // Le numero du modele est mis dans l'environnement |
|
| 647 | + // d'une part sous l'identifiant "id" |
|
| 648 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 649 | + // par la fonction id_table_objet, |
|
| 650 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 651 | + $_id = id_table_objet($type); |
|
| 652 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 653 | + |
|
| 654 | + if (isset($class)) { |
|
| 655 | + $contexte['class'] = $class; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 659 | + if ($lien) { |
|
| 660 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 661 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 662 | + $contexte['lien_class'] = $lien['class']; |
|
| 663 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 664 | + $contexte['lien_title'] = $lien['title']; |
|
| 665 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + // Traiter les parametres |
|
| 669 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 670 | + $arg_list = creer_contexte_de_modele($params); |
|
| 671 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 672 | + $contexte = array_merge($contexte, $arg_list); |
|
| 673 | + |
|
| 674 | + // Appliquer le modele avec le contexte |
|
| 675 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 676 | + |
|
| 677 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 678 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 679 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 680 | + if ( |
|
| 681 | + strstr( |
|
| 682 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 683 | + 'spip_lien_ok' |
|
| 684 | + ) |
|
| 685 | + ) { |
|
| 686 | + $retour = inserer_attribut( |
|
| 687 | + $retour, |
|
| 688 | + 'class', |
|
| 689 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 690 | + ); |
|
| 691 | + } else { |
|
| 692 | + if ($lien) { |
|
| 693 | + $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 694 | + } |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + $compteur--; |
|
| 698 | + |
|
| 699 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 700 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 701 | + : $retour; |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -707,105 +707,105 @@ discard block |
||
| 707 | 707 | // recuperer_fond($fond,$contexte,array('raw'=>true)) |
| 708 | 708 | function evaluer_fond($fond, $contexte = [], string $connect = '') { |
| 709 | 709 | |
| 710 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 711 | - |
|
| 712 | - if (!$page) { |
|
| 713 | - return $page; |
|
| 714 | - } |
|
| 715 | - // eval $page et affecte $res |
|
| 716 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 717 | - |
|
| 718 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 719 | - // a destination de public/parametrer |
|
| 720 | - // pour remonter vers les inclusions appelantes |
|
| 721 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 722 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 723 | - if ( |
|
| 724 | - isset($page['invalideurs']) |
|
| 725 | - and isset($page['invalideurs']['session']) |
|
| 726 | - ) { |
|
| 727 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - return $page; |
|
| 710 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 711 | + |
|
| 712 | + if (!$page) { |
|
| 713 | + return $page; |
|
| 714 | + } |
|
| 715 | + // eval $page et affecte $res |
|
| 716 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 717 | + |
|
| 718 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 719 | + // a destination de public/parametrer |
|
| 720 | + // pour remonter vers les inclusions appelantes |
|
| 721 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 722 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 723 | + if ( |
|
| 724 | + isset($page['invalideurs']) |
|
| 725 | + and isset($page['invalideurs']['session']) |
|
| 726 | + ) { |
|
| 727 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + return $page; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | |
| 734 | 734 | function page_base_href(&$texte) { |
| 735 | - static $set_html_base = null; |
|
| 736 | - if (is_null($set_html_base)) { |
|
| 737 | - if (!defined('_SET_HTML_BASE')) { |
|
| 738 | - // si la profondeur est superieure a 1 |
|
| 739 | - // est que ce n'est pas une url page ni une url action |
|
| 740 | - // activer par defaut |
|
| 741 | - $set_html_base = (( |
|
| 742 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 743 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 744 | - and !_request('action')) ? true : false); |
|
| 745 | - } else { |
|
| 746 | - $set_html_base = _SET_HTML_BASE; |
|
| 747 | - } |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - if ( |
|
| 751 | - $set_html_base |
|
| 752 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 753 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 754 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 755 | - ) { |
|
| 756 | - $head = substr($texte, 0, $poshead); |
|
| 757 | - $insert = false; |
|
| 758 | - $href_base = false; |
|
| 759 | - if (strpos($head, '<base') === false) { |
|
| 760 | - $insert = true; |
|
| 761 | - } else { |
|
| 762 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 763 | - // sinon juste re-ecrire les ancres si besoin |
|
| 764 | - $insert = true; |
|
| 765 | - include_spip('inc/filtres'); |
|
| 766 | - $bases = extraire_balises($head, 'base'); |
|
| 767 | - foreach ($bases as $base) { |
|
| 768 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 769 | - $insert = false; |
|
| 770 | - break; |
|
| 771 | - } |
|
| 772 | - } |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - if ($insert) { |
|
| 776 | - include_spip('inc/filtres_mini'); |
|
| 777 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 778 | - $href_base = url_absolue('./'); |
|
| 779 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 780 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 781 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 782 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 783 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 784 | - } |
|
| 785 | - $texte = $head . substr($texte, $poshead); |
|
| 786 | - } |
|
| 787 | - if ($href_base) { |
|
| 788 | - // gerer les ancres |
|
| 789 | - $base = $_SERVER['REQUEST_URI']; |
|
| 790 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 791 | - if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 792 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 793 | - } |
|
| 794 | - if (strpos($texte, "href='#") !== false) { |
|
| 795 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 796 | - } |
|
| 797 | - if (strpos($texte, 'href="#') !== false) { |
|
| 798 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - } |
|
| 735 | + static $set_html_base = null; |
|
| 736 | + if (is_null($set_html_base)) { |
|
| 737 | + if (!defined('_SET_HTML_BASE')) { |
|
| 738 | + // si la profondeur est superieure a 1 |
|
| 739 | + // est que ce n'est pas une url page ni une url action |
|
| 740 | + // activer par defaut |
|
| 741 | + $set_html_base = (( |
|
| 742 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 743 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 744 | + and !_request('action')) ? true : false); |
|
| 745 | + } else { |
|
| 746 | + $set_html_base = _SET_HTML_BASE; |
|
| 747 | + } |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + if ( |
|
| 751 | + $set_html_base |
|
| 752 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 753 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 754 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 755 | + ) { |
|
| 756 | + $head = substr($texte, 0, $poshead); |
|
| 757 | + $insert = false; |
|
| 758 | + $href_base = false; |
|
| 759 | + if (strpos($head, '<base') === false) { |
|
| 760 | + $insert = true; |
|
| 761 | + } else { |
|
| 762 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 763 | + // sinon juste re-ecrire les ancres si besoin |
|
| 764 | + $insert = true; |
|
| 765 | + include_spip('inc/filtres'); |
|
| 766 | + $bases = extraire_balises($head, 'base'); |
|
| 767 | + foreach ($bases as $base) { |
|
| 768 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 769 | + $insert = false; |
|
| 770 | + break; |
|
| 771 | + } |
|
| 772 | + } |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + if ($insert) { |
|
| 776 | + include_spip('inc/filtres_mini'); |
|
| 777 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 778 | + $href_base = url_absolue('./'); |
|
| 779 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 780 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 781 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 782 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 783 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 784 | + } |
|
| 785 | + $texte = $head . substr($texte, $poshead); |
|
| 786 | + } |
|
| 787 | + if ($href_base) { |
|
| 788 | + // gerer les ancres |
|
| 789 | + $base = $_SERVER['REQUEST_URI']; |
|
| 790 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 791 | + if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 792 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 793 | + } |
|
| 794 | + if (strpos($texte, "href='#") !== false) { |
|
| 795 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 796 | + } |
|
| 797 | + if (strpos($texte, 'href="#') !== false) { |
|
| 798 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | |
| 805 | 805 | // Envoyer les entetes, en retenant ceux qui sont a usage interne |
| 806 | 806 | // et demarrent par X-Spip-... |
| 807 | 807 | function envoyer_entetes($entetes) { |
| 808 | - foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 809 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 810 | - } |
|
| 808 | + foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 809 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 810 | + } |
|
| 811 | 811 | } |