@@ -59,6 +59,10 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | // http://code.spip.net/@argumenter_inclure |
| 62 | +/** |
|
| 63 | + * @param boolean $rejet_filtres |
|
| 64 | + * @param string $id_boucle |
|
| 65 | + */ |
|
| 62 | 66 | function argumenter_inclure( |
| 63 | 67 | $params, |
| 64 | 68 | $rejet_filtres, |
@@ -751,7 +755,7 @@ discard block |
||
| 751 | 755 | * Nom de la commande |
| 752 | 756 | * @param string $val |
| 753 | 757 | * Code PHP décrivant la valeur à affecter |
| 754 | - * @return array |
|
| 758 | + * @return string[] |
|
| 755 | 759 | * |
| 756 | 760 | * - index 0 : Code pour une affectation statique. Si non rempli, la propriété devra |
| 757 | 761 | * être ré-affectée à chaque appel de la boucle. |
@@ -859,6 +863,9 @@ discard block |
||
| 859 | 863 | } |
| 860 | 864 | |
| 861 | 865 | // http://code.spip.net/@calculer_order |
| 866 | +/** |
|
| 867 | + * @param Boucle $boucle |
|
| 868 | + */ |
|
| 862 | 869 | function calculer_order(&$boucle) { |
| 863 | 870 | if (!$order = $boucle->order |
| 864 | 871 | and !$order = $boucle->default_order |
@@ -944,6 +951,9 @@ discard block |
||
| 944 | 951 | define('_REGEXP_CONCAT_NON_VIDE', "/^(.*)[.]\s*'[^']+'\s*$/"); |
| 945 | 952 | |
| 946 | 953 | // http://code.spip.net/@compile_cas |
| 954 | +/** |
|
| 955 | + * @param string $id_boucle |
|
| 956 | + */ |
|
| 947 | 957 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 948 | 958 | |
| 949 | 959 | $codes = array(); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -60,91 +60,91 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // http://code.spip.net/@argumenter_inclure |
| 62 | 62 | function argumenter_inclure( |
| 63 | - $params, |
|
| 64 | - $rejet_filtres, |
|
| 65 | - $p, |
|
| 66 | - &$boucles, |
|
| 67 | - $id_boucle, |
|
| 68 | - $echap = true, |
|
| 69 | - $lang = '', |
|
| 70 | - $fond1 = false |
|
| 63 | + $params, |
|
| 64 | + $rejet_filtres, |
|
| 65 | + $p, |
|
| 66 | + &$boucles, |
|
| 67 | + $id_boucle, |
|
| 68 | + $echap = true, |
|
| 69 | + $lang = '', |
|
| 70 | + $fond1 = false |
|
| 71 | 71 | ) { |
| 72 | - $l = array(); |
|
| 73 | - $erreur_p_i_i = ''; |
|
| 74 | - if (!is_array($params)) { |
|
| 75 | - return $l; |
|
| 76 | - } |
|
| 77 | - foreach ($params as $k => $couple) { |
|
| 78 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | - $filtre = array_shift($couple); |
|
| 80 | - if ($filtre) { |
|
| 81 | - break; |
|
| 82 | - } |
|
| 83 | - foreach ($couple as $n => $val) { |
|
| 84 | - $var = $val[0]; |
|
| 85 | - if ($var->type != 'texte') { |
|
| 86 | - if ($n or $k or $fond1) { |
|
| 87 | - $erreur_p_i_i = array( |
|
| 88 | - 'zbug_parametres_inclus_incorrects', |
|
| 89 | - array('param' => $var->nom_champ) |
|
| 90 | - ); |
|
| 91 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | - break; |
|
| 93 | - } else { |
|
| 94 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | - } |
|
| 96 | - } else { |
|
| 97 | - preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | - $m = array_pad($m, 3, null); |
|
| 99 | - $var = $m[1]; |
|
| 100 | - $auto = false;; |
|
| 101 | - if ($m[2]) { |
|
| 102 | - $v = $m[3]; |
|
| 103 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | - $v = $m[1]; |
|
| 105 | - } |
|
| 106 | - $val[0] = new Texte; |
|
| 107 | - $val[0]->texte = $v; |
|
| 108 | - } elseif ($k or $n or $fond1) { |
|
| 109 | - $auto = true; |
|
| 110 | - } else { |
|
| 111 | - $var = 1; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ($var == 'lang') { |
|
| 115 | - $lang = !$auto |
|
| 116 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | - : '$GLOBALS["spip_lang"]'; |
|
| 118 | - } else { |
|
| 119 | - $val = $auto |
|
| 120 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | - if ($var !== 1) { |
|
| 123 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | - . $val . ($echap ? ") . '" : " "); |
|
| 125 | - } else { |
|
| 126 | - $val = $echap ? "'.$val.'" : $val; |
|
| 127 | - } |
|
| 128 | - $l[$var] = $val; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if ($erreur_p_i_i) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | - // sauf si on n'en veut pas |
|
| 139 | - if ($lang === false) { |
|
| 140 | - return $l; |
|
| 141 | - } |
|
| 142 | - if (!$lang) { |
|
| 143 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | - } |
|
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : " "); |
|
| 146 | - |
|
| 147 | - return $l; |
|
| 72 | + $l = array(); |
|
| 73 | + $erreur_p_i_i = ''; |
|
| 74 | + if (!is_array($params)) { |
|
| 75 | + return $l; |
|
| 76 | + } |
|
| 77 | + foreach ($params as $k => $couple) { |
|
| 78 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 79 | + $filtre = array_shift($couple); |
|
| 80 | + if ($filtre) { |
|
| 81 | + break; |
|
| 82 | + } |
|
| 83 | + foreach ($couple as $n => $val) { |
|
| 84 | + $var = $val[0]; |
|
| 85 | + if ($var->type != 'texte') { |
|
| 86 | + if ($n or $k or $fond1) { |
|
| 87 | + $erreur_p_i_i = array( |
|
| 88 | + 'zbug_parametres_inclus_incorrects', |
|
| 89 | + array('param' => $var->nom_champ) |
|
| 90 | + ); |
|
| 91 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 92 | + break; |
|
| 93 | + } else { |
|
| 94 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 95 | + } |
|
| 96 | + } else { |
|
| 97 | + preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
|
| 98 | + $m = array_pad($m, 3, null); |
|
| 99 | + $var = $m[1]; |
|
| 100 | + $auto = false;; |
|
| 101 | + if ($m[2]) { |
|
| 102 | + $v = $m[3]; |
|
| 103 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 104 | + $v = $m[1]; |
|
| 105 | + } |
|
| 106 | + $val[0] = new Texte; |
|
| 107 | + $val[0]->texte = $v; |
|
| 108 | + } elseif ($k or $n or $fond1) { |
|
| 109 | + $auto = true; |
|
| 110 | + } else { |
|
| 111 | + $var = 1; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ($var == 'lang') { |
|
| 115 | + $lang = !$auto |
|
| 116 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 117 | + : '$GLOBALS["spip_lang"]'; |
|
| 118 | + } else { |
|
| 119 | + $val = $auto |
|
| 120 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 121 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 122 | + if ($var !== 1) { |
|
| 123 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 124 | + . $val . ($echap ? ") . '" : " "); |
|
| 125 | + } else { |
|
| 126 | + $val = $echap ? "'.$val.'" : $val; |
|
| 127 | + } |
|
| 128 | + $l[$var] = $val; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if ($erreur_p_i_i) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 137 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 138 | + // sauf si on n'en veut pas |
|
| 139 | + if ($lang === false) { |
|
| 140 | + return $l; |
|
| 141 | + } |
|
| 142 | + if (!$lang) { |
|
| 143 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 144 | + } |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : " "); |
|
| 146 | + |
|
| 147 | + return $l; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -168,71 +168,71 @@ discard block |
||
| 168 | 168 | **/ |
| 169 | 169 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 170 | 170 | |
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 175 | - |
|
| 176 | - } else { |
|
| 177 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | - $fichier = $r[1]; |
|
| 180 | - } else { |
|
| 181 | - $fichier = ''; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - if (!$code or $code === '""') { |
|
| 185 | - $erreur_p_i_i = array( |
|
| 186 | - 'zbug_parametres_inclus_incorrects', |
|
| 187 | - array('param' => $code) |
|
| 188 | - ); |
|
| 189 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | - |
|
| 191 | - return false; |
|
| 192 | - } |
|
| 193 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | - |
|
| 195 | - if (is_array($_contexte)) { |
|
| 196 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | - unset($_contexte['env']); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // noter les doublons dans l'appel a public.php |
|
| 202 | - if (isset($_contexte['doublons'])) { |
|
| 203 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | - $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | - unset($_contexte['ajax']); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $_contexte = join(",\n\t", $_contexte); |
|
| 212 | - } else { |
|
| 213 | - return false; |
|
| 214 | - } // j'aurais voulu toucher le fond ... |
|
| 215 | - |
|
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | - |
|
| 218 | - if ($env) { |
|
| 219 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | - } else { |
|
| 226 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | - if ($ajax) { |
|
| 228 | - $_options[] = $ajax; |
|
| 229 | - } |
|
| 230 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 175 | + |
|
| 176 | + } else { |
|
| 177 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 178 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 179 | + $fichier = $r[1]; |
|
| 180 | + } else { |
|
| 181 | + $fichier = ''; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + if (!$code or $code === '""') { |
|
| 185 | + $erreur_p_i_i = array( |
|
| 186 | + 'zbug_parametres_inclus_incorrects', |
|
| 187 | + array('param' => $code) |
|
| 188 | + ); |
|
| 189 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | + } |
|
| 193 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 194 | + |
|
| 195 | + if (is_array($_contexte)) { |
|
| 196 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 197 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 198 | + unset($_contexte['env']); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // noter les doublons dans l'appel a public.php |
|
| 202 | + if (isset($_contexte['doublons'])) { |
|
| 203 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 207 | + $ajax = preg_replace(",=>(.*)$,ims", '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 208 | + unset($_contexte['ajax']); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $_contexte = join(",\n\t", $_contexte); |
|
| 212 | + } else { |
|
| 213 | + return false; |
|
| 214 | + } // j'aurais voulu toucher le fond ... |
|
| 215 | + |
|
| 216 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 217 | + |
|
| 218 | + if ($env) { |
|
| 219 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 223 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 224 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 225 | + } else { |
|
| 226 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 227 | + if ($ajax) { |
|
| 228 | + $_options[] = $ajax; |
|
| 229 | + } |
|
| 230 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 231 | + $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")") . ';'; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 251 | 251 | */ |
| 252 | 252 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 253 | - /* |
|
| 253 | + /* |
|
| 254 | 254 | $show['statut'][] = array( |
| 255 | 255 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 256 | 256 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -274,71 +274,71 @@ discard block |
||
| 274 | 274 | champstatut est alors le champ statut sur la tablen |
| 275 | 275 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 276 | 276 | */ |
| 277 | - $id_table = $boucle->id_table; |
|
| 278 | - $show = $boucle->show; |
|
| 279 | - if (isset($show['statut']) and $show['statut']) { |
|
| 280 | - foreach ($show['statut'] as $k => $s) { |
|
| 281 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | - $filtrer = true; |
|
| 283 | - if (isset($s['exception'])) { |
|
| 284 | - foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | - $filtrer = false; |
|
| 287 | - break; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($filtrer) { |
|
| 293 | - if (is_array($s['champ'])) { |
|
| 294 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | - $jointures = array(); |
|
| 296 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | - foreach ($s['champ'] as $j) { |
|
| 300 | - $id = reset($j); |
|
| 301 | - $def = $trouver_table($id); |
|
| 302 | - $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | - } |
|
| 304 | - $jointures[0][0] = $id_table; |
|
| 305 | - if (!array_search($id, $boucle->from)) { |
|
| 306 | - include_spip('public/jointures'); |
|
| 307 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | - } |
|
| 309 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | - $id = array_search($id, $boucle->from); |
|
| 311 | - } else { |
|
| 312 | - $id = $id_table; |
|
| 313 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | - } |
|
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 316 | - |
|
| 317 | - $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | - include_spip('public/quete'); |
|
| 319 | - if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | - and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | - ) { |
|
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | - array_unshift($boucle->where, |
|
| 324 | - $echapper ? |
|
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | - : |
|
| 327 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - array_unshift($boucle->where, |
|
| 331 | - $echapper ? |
|
| 332 | - "\nquete_condition_statut('$mstatut'," |
|
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | - : |
|
| 337 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 277 | + $id_table = $boucle->id_table; |
|
| 278 | + $show = $boucle->show; |
|
| 279 | + if (isset($show['statut']) and $show['statut']) { |
|
| 280 | + foreach ($show['statut'] as $k => $s) { |
|
| 281 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 282 | + $filtrer = true; |
|
| 283 | + if (isset($s['exception'])) { |
|
| 284 | + foreach (is_array($s['exception']) ? $s['exception'] : array($s['exception']) as $m) { |
|
| 285 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 286 | + $filtrer = false; |
|
| 287 | + break; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($filtrer) { |
|
| 293 | + if (is_array($s['champ'])) { |
|
| 294 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 295 | + $jointures = array(); |
|
| 296 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 297 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 298 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 299 | + foreach ($s['champ'] as $j) { |
|
| 300 | + $id = reset($j); |
|
| 301 | + $def = $trouver_table($id); |
|
| 302 | + $jointures[] = array('', array($id, $def), end($j)); |
|
| 303 | + } |
|
| 304 | + $jointures[0][0] = $id_table; |
|
| 305 | + if (!array_search($id, $boucle->from)) { |
|
| 306 | + include_spip('public/jointures'); |
|
| 307 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 308 | + } |
|
| 309 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 310 | + $id = array_search($id, $boucle->from); |
|
| 311 | + } else { |
|
| 312 | + $id = $id_table; |
|
| 313 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 314 | + } |
|
| 315 | + $mstatut = $id . '.' . $statut; |
|
| 316 | + |
|
| 317 | + $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
|
| 318 | + include_spip('public/quete'); |
|
| 319 | + if (isset($s['post_date']) and $s['post_date'] |
|
| 320 | + and $GLOBALS['meta']["post_dates"] == 'non' |
|
| 321 | + ) { |
|
| 322 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | + array_unshift($boucle->where, |
|
| 324 | + $echapper ? |
|
| 325 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 326 | + : |
|
| 327 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + array_unshift($boucle->where, |
|
| 331 | + $echapper ? |
|
| 332 | + "\nquete_condition_statut('$mstatut'," |
|
| 333 | + . _q($s['previsu']) . "," |
|
| 334 | + . _q($s['publie']) . "," |
|
| 335 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 336 | + : |
|
| 337 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -357,29 +357,29 @@ discard block |
||
| 357 | 357 | */ |
| 358 | 358 | function calculer_boucle($id_boucle, &$boucles) { |
| 359 | 359 | |
| 360 | - $boucle = &$boucles[$id_boucle]; |
|
| 361 | - instituer_boucle($boucle); |
|
| 362 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | - |
|
| 364 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | - // mais pas tous, sinon ca pete. |
|
| 366 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | - $trace = ''; |
|
| 368 | - } else { |
|
| 369 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 371 | - $trace = " |
|
| 360 | + $boucle = &$boucles[$id_boucle]; |
|
| 361 | + instituer_boucle($boucle); |
|
| 362 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 363 | + |
|
| 364 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 365 | + // mais pas tous, sinon ca pete. |
|
| 366 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 367 | + $trace = ''; |
|
| 368 | + } else { |
|
| 369 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 370 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 371 | + $trace = " |
|
| 372 | 372 | if (empty($_trace)) { |
| 373 | 373 | $_trace = []; |
| 374 | 374 | } |
| 375 | 375 | if (count($_trace) < 3) { |
| 376 | 376 | $_trace" . "[] = \$t0; |
| 377 | 377 | }"; |
| 378 | - } |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 381 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 382 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 380 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 381 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 382 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | |
@@ -402,15 +402,15 @@ discard block |
||
| 402 | 402 | * Code PHP compilé de la boucle récursive |
| 403 | 403 | **/ |
| 404 | 404 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 405 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 406 | - |
|
| 407 | - return |
|
| 408 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 409 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 410 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 411 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 412 | - . $trace |
|
| 413 | - . "\n\treturn \$t0;"; |
|
| 405 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 406 | + |
|
| 407 | + return |
|
| 408 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 409 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 410 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 411 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 412 | + . $trace |
|
| 413 | + . "\n\treturn \$t0;"; |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | /** |
@@ -464,169 +464,169 @@ discard block |
||
| 464 | 464 | **/ |
| 465 | 465 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 466 | 466 | |
| 467 | - $boucle = &$boucles[$id_boucle]; |
|
| 468 | - $return = $boucle->return; |
|
| 469 | - $type_boucle = $boucle->type_requete; |
|
| 470 | - $primary = $boucle->primary; |
|
| 471 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 472 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 473 | - $corps = ''; |
|
| 474 | - |
|
| 475 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 476 | - // et puis faire un [] plutot qu'un "','." |
|
| 477 | - if ($boucle->doublons) { |
|
| 478 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 479 | - index_pile($id_boucle, $primary, $boucles) |
|
| 480 | - . "; // doublons\n"; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - // La boucle doit-elle selectionner la langue ? |
|
| 484 | - // - par defaut, les boucles suivantes le font |
|
| 485 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 486 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 487 | - if (!$constant && $boucle->lang_select != 'non' && |
|
| 488 | - (($boucle->lang_select == 'oui') || |
|
| 489 | - in_array($type_boucle, array( |
|
| 490 | - 'articles', |
|
| 491 | - 'rubriques', |
|
| 492 | - 'hierarchie', |
|
| 493 | - 'breves' |
|
| 494 | - ))) |
|
| 495 | - ) { |
|
| 496 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 497 | - // afin que le corps de boucle affecte la globale directement |
|
| 498 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 499 | - $fin_lang = "lang_select();\n\t"; |
|
| 500 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 501 | - |
|
| 502 | - $corps .= |
|
| 503 | - "\n\t\tlang_select_public(" |
|
| 504 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 505 | - . ", '" . $boucle->lang_select . "'" |
|
| 506 | - . (in_array($type_boucle, array( |
|
| 507 | - 'articles', |
|
| 508 | - 'rubriques', |
|
| 509 | - 'hierarchie', |
|
| 510 | - 'breves' |
|
| 511 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 512 | - . ');'; |
|
| 513 | - } else { |
|
| 514 | - $init_lang = ''; |
|
| 515 | - $fin_lang = ''; |
|
| 516 | - $fin_lang_select_public = ''; |
|
| 517 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 518 | - if (strpos($return, '?php') === false |
|
| 519 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 520 | - ) { |
|
| 521 | - $i = 1; |
|
| 522 | - foreach ($r[1] as $t) { |
|
| 523 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 524 | - $return = str_replace($t, "\$l$i", $return); |
|
| 525 | - $i++; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - // gestion optimale des separateurs et des boucles constantes |
|
| 531 | - if (count($boucle->separateur)) { |
|
| 532 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - $corps .= |
|
| 536 | - ((!$boucle->separateur) ? |
|
| 537 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 538 | - (($return === "''") ? '' : |
|
| 539 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 540 | - ("\n\t\t\$t1 " . |
|
| 541 | - ((strpos($return, '$t1.') === 0) ? |
|
| 542 | - (".=" . substr($return, 4)) : |
|
| 543 | - ('= ' . $return)) . |
|
| 544 | - ";\n\t\t" . |
|
| 545 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 546 | - |
|
| 547 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 548 | - // souhaite invalider ces elements |
|
| 549 | - if (!$constant and $primary) { |
|
| 550 | - include_spip('inc/invalideur'); |
|
| 551 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - // gerer le compteur de boucle |
|
| 555 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 556 | - |
|
| 557 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 558 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 559 | - . $boucle->partie |
|
| 560 | - . $corps; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - // depiler la lang de la boucle si besoin |
|
| 564 | - $corps .= $fin_lang_select_public; |
|
| 565 | - |
|
| 566 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 567 | - |
|
| 568 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 569 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 570 | - if (!$boucle->numrows) { |
|
| 571 | - return "\n\t\$t0 = '';"; |
|
| 572 | - } else { |
|
| 573 | - $corps = ""; |
|
| 574 | - } |
|
| 575 | - } else { |
|
| 576 | - $boucle->numrows = true; |
|
| 577 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 578 | - } |
|
| 579 | - } else { |
|
| 580 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - $count = ''; |
|
| 584 | - if (!$boucle->select) { |
|
| 585 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 586 | - $count = '1'; |
|
| 587 | - } else { |
|
| 588 | - $count = 'count(*)'; |
|
| 589 | - } |
|
| 590 | - $boucles[$id_boucle]->select[] = $count; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - if ($flag_cpt) { |
|
| 594 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 595 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 596 | - } else { |
|
| 597 | - $nums = ''; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 601 | - $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 602 | - . $boucle->mode_partie |
|
| 603 | - . "\n\t"; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - // Ne calculer la requete que maintenant |
|
| 607 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 608 | - |
|
| 609 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 610 | - ? ("\n\t$init = array();") : '') |
|
| 611 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 612 | - |
|
| 613 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 614 | - |
|
| 615 | - $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 616 | - $init, |
|
| 617 | - $boucle->iterateur, |
|
| 618 | - "\$command", |
|
| 619 | - $contexte, |
|
| 620 | - $nums, |
|
| 621 | - $init_lang, |
|
| 622 | - $corps, |
|
| 623 | - $fin_lang, |
|
| 624 | - $trace, |
|
| 625 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 626 | - ); |
|
| 467 | + $boucle = &$boucles[$id_boucle]; |
|
| 468 | + $return = $boucle->return; |
|
| 469 | + $type_boucle = $boucle->type_requete; |
|
| 470 | + $primary = $boucle->primary; |
|
| 471 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 472 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 473 | + $corps = ''; |
|
| 474 | + |
|
| 475 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 476 | + // et puis faire un [] plutot qu'un "','." |
|
| 477 | + if ($boucle->doublons) { |
|
| 478 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 479 | + index_pile($id_boucle, $primary, $boucles) |
|
| 480 | + . "; // doublons\n"; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + // La boucle doit-elle selectionner la langue ? |
|
| 484 | + // - par defaut, les boucles suivantes le font |
|
| 485 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 486 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 487 | + if (!$constant && $boucle->lang_select != 'non' && |
|
| 488 | + (($boucle->lang_select == 'oui') || |
|
| 489 | + in_array($type_boucle, array( |
|
| 490 | + 'articles', |
|
| 491 | + 'rubriques', |
|
| 492 | + 'hierarchie', |
|
| 493 | + 'breves' |
|
| 494 | + ))) |
|
| 495 | + ) { |
|
| 496 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 497 | + // afin que le corps de boucle affecte la globale directement |
|
| 498 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 499 | + $fin_lang = "lang_select();\n\t"; |
|
| 500 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 501 | + |
|
| 502 | + $corps .= |
|
| 503 | + "\n\t\tlang_select_public(" |
|
| 504 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 505 | + . ", '" . $boucle->lang_select . "'" |
|
| 506 | + . (in_array($type_boucle, array( |
|
| 507 | + 'articles', |
|
| 508 | + 'rubriques', |
|
| 509 | + 'hierarchie', |
|
| 510 | + 'breves' |
|
| 511 | + )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 512 | + . ');'; |
|
| 513 | + } else { |
|
| 514 | + $init_lang = ''; |
|
| 515 | + $fin_lang = ''; |
|
| 516 | + $fin_lang_select_public = ''; |
|
| 517 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 518 | + if (strpos($return, '?php') === false |
|
| 519 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 520 | + ) { |
|
| 521 | + $i = 1; |
|
| 522 | + foreach ($r[1] as $t) { |
|
| 523 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 524 | + $return = str_replace($t, "\$l$i", $return); |
|
| 525 | + $i++; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + // gestion optimale des separateurs et des boucles constantes |
|
| 531 | + if (count($boucle->separateur)) { |
|
| 532 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + $corps .= |
|
| 536 | + ((!$boucle->separateur) ? |
|
| 537 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 538 | + (($return === "''") ? '' : |
|
| 539 | + ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 540 | + ("\n\t\t\$t1 " . |
|
| 541 | + ((strpos($return, '$t1.') === 0) ? |
|
| 542 | + (".=" . substr($return, 4)) : |
|
| 543 | + ('= ' . $return)) . |
|
| 544 | + ";\n\t\t" . |
|
| 545 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 546 | + |
|
| 547 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 548 | + // souhaite invalider ces elements |
|
| 549 | + if (!$constant and $primary) { |
|
| 550 | + include_spip('inc/invalideur'); |
|
| 551 | + $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + // gerer le compteur de boucle |
|
| 555 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 556 | + |
|
| 557 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 558 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 559 | + . $boucle->partie |
|
| 560 | + . $corps; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + // depiler la lang de la boucle si besoin |
|
| 564 | + $corps .= $fin_lang_select_public; |
|
| 565 | + |
|
| 566 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 567 | + |
|
| 568 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 569 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 570 | + if (!$boucle->numrows) { |
|
| 571 | + return "\n\t\$t0 = '';"; |
|
| 572 | + } else { |
|
| 573 | + $corps = ""; |
|
| 574 | + } |
|
| 575 | + } else { |
|
| 576 | + $boucle->numrows = true; |
|
| 577 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 578 | + } |
|
| 579 | + } else { |
|
| 580 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + $count = ''; |
|
| 584 | + if (!$boucle->select) { |
|
| 585 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 586 | + $count = '1'; |
|
| 587 | + } else { |
|
| 588 | + $count = 'count(*)'; |
|
| 589 | + } |
|
| 590 | + $boucles[$id_boucle]->select[] = $count; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + if ($flag_cpt) { |
|
| 594 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 595 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 596 | + } else { |
|
| 597 | + $nums = ''; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 601 | + $nums .= "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 602 | + . $boucle->mode_partie |
|
| 603 | + . "\n\t"; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + // Ne calculer la requete que maintenant |
|
| 607 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 608 | + |
|
| 609 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 610 | + ? ("\n\t$init = array();") : '') |
|
| 611 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 612 | + |
|
| 613 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 614 | + |
|
| 615 | + $a = sprintf(CODE_CORPS_BOUCLE, |
|
| 616 | + $init, |
|
| 617 | + $boucle->iterateur, |
|
| 618 | + "\$command", |
|
| 619 | + $contexte, |
|
| 620 | + $nums, |
|
| 621 | + $init_lang, |
|
| 622 | + $corps, |
|
| 623 | + $fin_lang, |
|
| 624 | + $trace, |
|
| 625 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 626 | + ); |
|
| 627 | 627 | |
| 628 | 628 | # var_dump($a);exit; |
| 629 | - return $a; |
|
| 629 | + return $a; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | |
@@ -642,43 +642,43 @@ discard block |
||
| 642 | 642 | * Code PHP compilé définissant les informations de requête |
| 643 | 643 | **/ |
| 644 | 644 | function calculer_requete_sql($boucle) { |
| 645 | - $init = array(); |
|
| 646 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 647 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 648 | - # En absence de champ c'est un decompte : |
|
| 649 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 650 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 651 | - $init[] = calculer_dec('groupby', |
|
| 652 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 653 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 654 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 655 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 656 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 657 | - $init[] = calculer_dec('limit', |
|
| 658 | - (strpos($boucle->limit, 'intval') === false ? |
|
| 659 | - "'" . $boucle->limit . "'" |
|
| 660 | - : |
|
| 661 | - $boucle->limit)); |
|
| 662 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 663 | - $s = $d = ""; |
|
| 664 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 665 | - // ou recalculée à chaque passage (vide) |
|
| 666 | - foreach ($init as $i) { |
|
| 667 | - if (reset($i)) { |
|
| 668 | - $s .= "\n\t\t" . end($i); |
|
| 669 | - } # statique |
|
| 670 | - else { |
|
| 671 | - $d .= "\n\t" . end($i); |
|
| 672 | - } # dynamique |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 676 | - . $boucle->in |
|
| 677 | - . $boucle->hash |
|
| 678 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 679 | - . $s |
|
| 680 | - . "\n\t}" |
|
| 681 | - . $d; |
|
| 645 | + $init = array(); |
|
| 646 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 647 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 648 | + # En absence de champ c'est un decompte : |
|
| 649 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 650 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 651 | + $init[] = calculer_dec('groupby', |
|
| 652 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 653 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 654 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 655 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 656 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 657 | + $init[] = calculer_dec('limit', |
|
| 658 | + (strpos($boucle->limit, 'intval') === false ? |
|
| 659 | + "'" . $boucle->limit . "'" |
|
| 660 | + : |
|
| 661 | + $boucle->limit)); |
|
| 662 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 663 | + $s = $d = ""; |
|
| 664 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 665 | + // ou recalculée à chaque passage (vide) |
|
| 666 | + foreach ($init as $i) { |
|
| 667 | + if (reset($i)) { |
|
| 668 | + $s .= "\n\t\t" . end($i); |
|
| 669 | + } # statique |
|
| 670 | + else { |
|
| 671 | + $d .= "\n\t" . end($i); |
|
| 672 | + } # dynamique |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 676 | + . $boucle->in |
|
| 677 | + . $boucle->hash |
|
| 678 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 679 | + . $s |
|
| 680 | + . "\n\t}" |
|
| 681 | + . $d; |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | /** |
@@ -696,13 +696,13 @@ discard block |
||
| 696 | 696 | * qui peut être utilisé pour la production d'un tableau array() |
| 697 | 697 | **/ |
| 698 | 698 | function memoriser_contexte_compil($p) { |
| 699 | - return join(',', array( |
|
| 700 | - _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 701 | - _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 702 | - _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 703 | - intval($p->ligne), |
|
| 704 | - '$GLOBALS[\'spip_lang\']' |
|
| 705 | - )); |
|
| 699 | + return join(',', array( |
|
| 700 | + _q(isset($p->descr['sourcefile']) ? $p->descr['sourcefile'] : ''), |
|
| 701 | + _q(isset($p->descr['nom']) ? $p->descr['nom'] : ''), |
|
| 702 | + _q(isset($p->id_boucle) ? $p->id_boucle : null), |
|
| 703 | + intval($p->ligne), |
|
| 704 | + '$GLOBALS[\'spip_lang\']' |
|
| 705 | + )); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -720,19 +720,19 @@ discard block |
||
| 720 | 720 | * Objet Contexte |
| 721 | 721 | **/ |
| 722 | 722 | function reconstruire_contexte_compil($context_compil) { |
| 723 | - if (!is_array($context_compil)) { |
|
| 724 | - return $context_compil; |
|
| 725 | - } |
|
| 726 | - $p = new Contexte; |
|
| 727 | - $p->descr = array( |
|
| 728 | - 'sourcefile' => $context_compil[0], |
|
| 729 | - 'nom' => $context_compil[1] |
|
| 730 | - ); |
|
| 731 | - $p->id_boucle = $context_compil[2]; |
|
| 732 | - $p->ligne = $context_compil[3]; |
|
| 733 | - $p->lang = $context_compil[4]; |
|
| 734 | - |
|
| 735 | - return $p; |
|
| 723 | + if (!is_array($context_compil)) { |
|
| 724 | + return $context_compil; |
|
| 725 | + } |
|
| 726 | + $p = new Contexte; |
|
| 727 | + $p->descr = array( |
|
| 728 | + 'sourcefile' => $context_compil[0], |
|
| 729 | + 'nom' => $context_compil[1] |
|
| 730 | + ); |
|
| 731 | + $p->id_boucle = $context_compil[2]; |
|
| 732 | + $p->ligne = $context_compil[3]; |
|
| 733 | + $p->lang = $context_compil[4]; |
|
| 734 | + |
|
| 735 | + return $p; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -758,12 +758,12 @@ discard block |
||
| 758 | 758 | * - index 1 : Code de l'affectation |
| 759 | 759 | **/ |
| 760 | 760 | function calculer_dec($nom, $val) { |
| 761 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 762 | - // si une variable apparait dans le calcul de la clause |
|
| 763 | - // il faut la re-evaluer a chaque passage |
|
| 764 | - if ( |
|
| 765 | - strpos($val, '$') !== false |
|
| 766 | - /* |
|
| 761 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 762 | + // si une variable apparait dans le calcul de la clause |
|
| 763 | + // il faut la re-evaluer a chaque passage |
|
| 764 | + if ( |
|
| 765 | + strpos($val, '$') !== false |
|
| 766 | + /* |
|
| 767 | 767 | OR strpos($val, 'sql_') !== false |
| 768 | 768 | OR ( |
| 769 | 769 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -771,11 +771,11 @@ discard block |
||
| 771 | 771 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 772 | 772 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 773 | 773 | )*/ |
| 774 | - ) { |
|
| 775 | - $static = ""; |
|
| 776 | - } |
|
| 774 | + ) { |
|
| 775 | + $static = ""; |
|
| 776 | + } |
|
| 777 | 777 | |
| 778 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 778 | + return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | /** |
@@ -795,32 +795,32 @@ discard block |
||
| 795 | 795 | * Expression PHP décrivant un texte ou un tableau |
| 796 | 796 | **/ |
| 797 | 797 | function calculer_dump_array($a) { |
| 798 | - if (!is_array($a)) { |
|
| 799 | - return $a; |
|
| 800 | - } |
|
| 801 | - $res = ""; |
|
| 802 | - if ($a and $a[0] == "'?'") { |
|
| 803 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 804 | - " ? " . calculer_dump_array($a[2]) . |
|
| 805 | - " : " . calculer_dump_array($a[3]) . |
|
| 806 | - ")"); |
|
| 807 | - } else { |
|
| 808 | - foreach ($a as $v) { |
|
| 809 | - $res .= ", " . calculer_dump_array($v); |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 813 | - } |
|
| 798 | + if (!is_array($a)) { |
|
| 799 | + return $a; |
|
| 800 | + } |
|
| 801 | + $res = ""; |
|
| 802 | + if ($a and $a[0] == "'?'") { |
|
| 803 | + return ("(" . calculer_dump_array($a[1]) . |
|
| 804 | + " ? " . calculer_dump_array($a[2]) . |
|
| 805 | + " : " . calculer_dump_array($a[3]) . |
|
| 806 | + ")"); |
|
| 807 | + } else { |
|
| 808 | + foreach ($a as $v) { |
|
| 809 | + $res .= ", " . calculer_dump_array($v); |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 813 | + } |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | // http://code.spip.net/@calculer_dump_join |
| 817 | 817 | function calculer_dump_join($a) { |
| 818 | - $res = ""; |
|
| 819 | - foreach ($a as $k => $v) { |
|
| 820 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 821 | - } |
|
| 818 | + $res = ""; |
|
| 819 | + foreach ($a as $k => $v) { |
|
| 820 | + $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 821 | + } |
|
| 822 | 822 | |
| 823 | - return 'array(' . substr($res, 2) . ')'; |
|
| 823 | + return 'array(' . substr($res, 2) . ')'; |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
@@ -832,12 +832,12 @@ discard block |
||
| 832 | 832 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 833 | 833 | **/ |
| 834 | 834 | function calculer_from(&$boucle) { |
| 835 | - $res = ""; |
|
| 836 | - foreach ($boucle->from as $k => $v) { |
|
| 837 | - $res .= ",'$k' => '$v'"; |
|
| 838 | - } |
|
| 835 | + $res = ""; |
|
| 836 | + foreach ($boucle->from as $k => $v) { |
|
| 837 | + $res .= ",'$k' => '$v'"; |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - return 'array(' . substr($res, 1) . ')'; |
|
| 840 | + return 'array(' . substr($res, 1) . ')'; |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | /** |
@@ -850,30 +850,30 @@ discard block |
||
| 850 | 850 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 851 | 851 | **/ |
| 852 | 852 | function calculer_from_type(&$boucle) { |
| 853 | - $res = ""; |
|
| 854 | - foreach ($boucle->from_type as $k => $v) { |
|
| 855 | - $res .= ",'$k' => '$v'"; |
|
| 856 | - } |
|
| 853 | + $res = ""; |
|
| 854 | + foreach ($boucle->from_type as $k => $v) { |
|
| 855 | + $res .= ",'$k' => '$v'"; |
|
| 856 | + } |
|
| 857 | 857 | |
| 858 | - return 'array(' . substr($res, 1) . ')'; |
|
| 858 | + return 'array(' . substr($res, 1) . ')'; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | // http://code.spip.net/@calculer_order |
| 862 | 862 | function calculer_order(&$boucle) { |
| 863 | - if (!$order = $boucle->order |
|
| 864 | - and !$order = $boucle->default_order |
|
| 865 | - ) { |
|
| 866 | - $order = array(); |
|
| 867 | - } |
|
| 863 | + if (!$order = $boucle->order |
|
| 864 | + and !$order = $boucle->default_order |
|
| 865 | + ) { |
|
| 866 | + $order = array(); |
|
| 867 | + } |
|
| 868 | 868 | |
| 869 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 869 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 870 | 870 | $col = "." . $boucle->modificateur['collate']; |
| 871 | 871 | foreach($order as $k=>$o) |
| 872 | 872 | if (strpos($order[$k],'COLLATE')===false) |
| 873 | 873 | $order[$k].= $col; |
| 874 | 874 | }*/ |
| 875 | 875 | |
| 876 | - return join(', ', $order); |
|
| 876 | + return join(', ', $order); |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -883,59 +883,59 @@ discard block |
||
| 883 | 883 | |
| 884 | 884 | // http://code.spip.net/@calculer_liste |
| 885 | 885 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 886 | - if (!$tableau) { |
|
| 887 | - return "''"; |
|
| 888 | - } |
|
| 889 | - if (is_string($descr)) { |
|
| 890 | - if (isset($boucles[$descr])) { |
|
| 891 | - $idb = $descr; |
|
| 892 | - $descr = []; |
|
| 893 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 894 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 895 | - } |
|
| 896 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 897 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - else { |
|
| 901 | - $descr = array(); |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - if (!isset($descr['niv'])) { |
|
| 905 | - $descr['niv'] = 0; |
|
| 906 | - } |
|
| 907 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 908 | - if ($codes === false) { |
|
| 909 | - return false; |
|
| 910 | - } |
|
| 911 | - $n = count($codes); |
|
| 912 | - if (!$n) { |
|
| 913 | - return "''"; |
|
| 914 | - } |
|
| 915 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 916 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 917 | - if ($n == 1) { |
|
| 918 | - return $codes[0]; |
|
| 919 | - } else { |
|
| 920 | - $res = ''; |
|
| 921 | - foreach ($codes as $code) { |
|
| 922 | - if (!preg_match("/^'[^']*'$/", $code) |
|
| 923 | - or substr($res, -1, 1) !== "'" |
|
| 924 | - ) { |
|
| 925 | - $res .= " .\n$tab$code"; |
|
| 926 | - } else { |
|
| 927 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 932 | - } |
|
| 933 | - } else { |
|
| 934 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 935 | - |
|
| 936 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 937 | - $codes) . ")))"; |
|
| 938 | - } |
|
| 886 | + if (!$tableau) { |
|
| 887 | + return "''"; |
|
| 888 | + } |
|
| 889 | + if (is_string($descr)) { |
|
| 890 | + if (isset($boucles[$descr])) { |
|
| 891 | + $idb = $descr; |
|
| 892 | + $descr = []; |
|
| 893 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 894 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 895 | + } |
|
| 896 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 897 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + else { |
|
| 901 | + $descr = array(); |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + if (!isset($descr['niv'])) { |
|
| 905 | + $descr['niv'] = 0; |
|
| 906 | + } |
|
| 907 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 908 | + if ($codes === false) { |
|
| 909 | + return false; |
|
| 910 | + } |
|
| 911 | + $n = count($codes); |
|
| 912 | + if (!$n) { |
|
| 913 | + return "''"; |
|
| 914 | + } |
|
| 915 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 916 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 917 | + if ($n == 1) { |
|
| 918 | + return $codes[0]; |
|
| 919 | + } else { |
|
| 920 | + $res = ''; |
|
| 921 | + foreach ($codes as $code) { |
|
| 922 | + if (!preg_match("/^'[^']*'$/", $code) |
|
| 923 | + or substr($res, -1, 1) !== "'" |
|
| 924 | + ) { |
|
| 925 | + $res .= " .\n$tab$code"; |
|
| 926 | + } else { |
|
| 927 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 932 | + } |
|
| 933 | + } else { |
|
| 934 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 935 | + |
|
| 936 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 937 | + $codes) . ")))"; |
|
| 938 | + } |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | |
@@ -946,203 +946,203 @@ discard block |
||
| 946 | 946 | // http://code.spip.net/@compile_cas |
| 947 | 947 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 948 | 948 | |
| 949 | - $codes = array(); |
|
| 950 | - // cas de la boucle recursive |
|
| 951 | - if (is_array($id_boucle)) { |
|
| 952 | - $id_boucle = $id_boucle[0]; |
|
| 953 | - } |
|
| 954 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 955 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 956 | - $mode = _request('var_mode_affiche'); |
|
| 957 | - $err_e_c = ''; |
|
| 958 | - // chaque commentaire introduit dans le code doit commencer |
|
| 959 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 960 | - foreach ($tableau as $p) { |
|
| 961 | - |
|
| 962 | - switch ($p->type) { |
|
| 963 | - // texte seul |
|
| 964 | - case 'texte': |
|
| 965 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 966 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 967 | - $avant = ''; |
|
| 968 | - $apres = ''; |
|
| 969 | - $altern = "''"; |
|
| 970 | - break; |
|
| 971 | - |
|
| 972 | - case 'polyglotte': |
|
| 973 | - $code = ""; |
|
| 974 | - foreach ($p->traductions as $k => $v) { |
|
| 975 | - $code .= ",'" . |
|
| 976 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 977 | - "' => '" . |
|
| 978 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 979 | - "'"; |
|
| 980 | - } |
|
| 981 | - $code = "choisir_traduction(array(" . |
|
| 982 | - substr($code, 1) . |
|
| 983 | - "))"; |
|
| 984 | - $commentaire = '&'; |
|
| 985 | - $avant = ''; |
|
| 986 | - $apres = ''; |
|
| 987 | - $altern = "''"; |
|
| 988 | - break; |
|
| 989 | - |
|
| 990 | - // inclure |
|
| 991 | - case 'include': |
|
| 992 | - $p->descr = $descr; |
|
| 993 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 994 | - if ($code === false) { |
|
| 995 | - $err_e_c = true; |
|
| 996 | - $code = "''"; |
|
| 997 | - } else { |
|
| 998 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 999 | - $avant = ''; |
|
| 1000 | - $apres = ''; |
|
| 1001 | - $altern = "''"; |
|
| 1002 | - } |
|
| 1003 | - break; |
|
| 1004 | - |
|
| 1005 | - // boucle |
|
| 1006 | - case TYPE_RECURSIF: |
|
| 1007 | - $nom = $p->id_boucle; |
|
| 1008 | - $newdescr = $descr; |
|
| 1009 | - $newdescr['id_mere'] = $nom; |
|
| 1010 | - $newdescr['niv']++; |
|
| 1011 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1012 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1013 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1014 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1015 | - $newdescr['niv']--; |
|
| 1016 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1017 | - if ($preaff === false |
|
| 1018 | - or $avant === false |
|
| 1019 | - or $apres === false |
|
| 1020 | - or $altern === false |
|
| 1021 | - or $postaff === false) { |
|
| 1022 | - $err_e_c = true; |
|
| 1023 | - $code = "''"; |
|
| 1024 | - } else { |
|
| 1025 | - $code = 'BOUCLE' . |
|
| 1026 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1027 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1028 | - $commentaire = "?$nom"; |
|
| 1029 | - if (!$boucles[$nom]->milieu |
|
| 1030 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1031 | - ) { |
|
| 1032 | - if ($preaff != "''") { |
|
| 1033 | - $code .= "\n. $preaff"; |
|
| 1034 | - } |
|
| 1035 | - if ($altern != "''") { |
|
| 1036 | - $code .= "\n. $altern"; |
|
| 1037 | - } |
|
| 1038 | - if ($postaff != "''") { |
|
| 1039 | - $code .= "\n. $postaff"; |
|
| 1040 | - } |
|
| 1041 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1042 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1043 | - } |
|
| 1044 | - $avant = $apres = $altern = "''"; |
|
| 1045 | - } else { |
|
| 1046 | - if ($preaff != "''") { |
|
| 1047 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1048 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1049 | - } |
|
| 1050 | - if ($postaff != "''") { |
|
| 1051 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1052 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1053 | - } |
|
| 1054 | - if ($altern != "''") { |
|
| 1055 | - $altern = "($altern)"; |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - break; |
|
| 1060 | - |
|
| 1061 | - case 'idiome': |
|
| 1062 | - $l = array(); |
|
| 1063 | - $code = ''; |
|
| 1064 | - foreach ($p->arg as $k => $v) { |
|
| 1065 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1066 | - if ($k) { |
|
| 1067 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1068 | - } else { |
|
| 1069 | - $code = $_v; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1073 | - if ($p->module) { |
|
| 1074 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1075 | - } elseif ($p->nom_champ) { |
|
| 1076 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1077 | - } else { |
|
| 1078 | - $m = ''; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - $code = (!$code ? "'$m'" : |
|
| 1082 | - ($m ? "'$m' . $code" : |
|
| 1083 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1084 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1085 | - $code = "_T($code)"; |
|
| 1086 | - if ($p->param) { |
|
| 1087 | - $p->id_boucle = $id_boucle; |
|
| 1088 | - $p->boucles = &$boucles; |
|
| 1089 | - $code = compose_filtres($p, $code); |
|
| 1090 | - } |
|
| 1091 | - $commentaire = ":"; |
|
| 1092 | - $avant = ''; |
|
| 1093 | - $apres = ''; |
|
| 1094 | - $altern = "''"; |
|
| 1095 | - break; |
|
| 1096 | - |
|
| 1097 | - case 'champ': |
|
| 1098 | - |
|
| 1099 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1100 | - $p->id_boucle = $id_boucle; |
|
| 1101 | - $p->boucles = &$boucles; |
|
| 1102 | - $p->descr = $descr; |
|
| 1103 | - #$p->interdire_scripts = true; |
|
| 1104 | - $p->type_requete = $type; |
|
| 1105 | - |
|
| 1106 | - $code = calculer_champ($p); |
|
| 1107 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1108 | - $avant = calculer_liste($p->avant, |
|
| 1109 | - $descr, $boucles, $id_boucle); |
|
| 1110 | - $apres = calculer_liste($p->apres, |
|
| 1111 | - $descr, $boucles, $id_boucle); |
|
| 1112 | - $altern = "''"; |
|
| 1113 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1114 | - // forcer la conversion en une chaine par strval |
|
| 1115 | - // si ca peut etre autre chose qu'une chaine |
|
| 1116 | - if (($avant != "''" or $apres != "''") |
|
| 1117 | - and $code[0] != "'" |
|
| 949 | + $codes = array(); |
|
| 950 | + // cas de la boucle recursive |
|
| 951 | + if (is_array($id_boucle)) { |
|
| 952 | + $id_boucle = $id_boucle[0]; |
|
| 953 | + } |
|
| 954 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 955 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 956 | + $mode = _request('var_mode_affiche'); |
|
| 957 | + $err_e_c = ''; |
|
| 958 | + // chaque commentaire introduit dans le code doit commencer |
|
| 959 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 960 | + foreach ($tableau as $p) { |
|
| 961 | + |
|
| 962 | + switch ($p->type) { |
|
| 963 | + // texte seul |
|
| 964 | + case 'texte': |
|
| 965 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 966 | + $commentaire = strlen($p->texte) . " signes"; |
|
| 967 | + $avant = ''; |
|
| 968 | + $apres = ''; |
|
| 969 | + $altern = "''"; |
|
| 970 | + break; |
|
| 971 | + |
|
| 972 | + case 'polyglotte': |
|
| 973 | + $code = ""; |
|
| 974 | + foreach ($p->traductions as $k => $v) { |
|
| 975 | + $code .= ",'" . |
|
| 976 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 977 | + "' => '" . |
|
| 978 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 979 | + "'"; |
|
| 980 | + } |
|
| 981 | + $code = "choisir_traduction(array(" . |
|
| 982 | + substr($code, 1) . |
|
| 983 | + "))"; |
|
| 984 | + $commentaire = '&'; |
|
| 985 | + $avant = ''; |
|
| 986 | + $apres = ''; |
|
| 987 | + $altern = "''"; |
|
| 988 | + break; |
|
| 989 | + |
|
| 990 | + // inclure |
|
| 991 | + case 'include': |
|
| 992 | + $p->descr = $descr; |
|
| 993 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 994 | + if ($code === false) { |
|
| 995 | + $err_e_c = true; |
|
| 996 | + $code = "''"; |
|
| 997 | + } else { |
|
| 998 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 999 | + $avant = ''; |
|
| 1000 | + $apres = ''; |
|
| 1001 | + $altern = "''"; |
|
| 1002 | + } |
|
| 1003 | + break; |
|
| 1004 | + |
|
| 1005 | + // boucle |
|
| 1006 | + case TYPE_RECURSIF: |
|
| 1007 | + $nom = $p->id_boucle; |
|
| 1008 | + $newdescr = $descr; |
|
| 1009 | + $newdescr['id_mere'] = $nom; |
|
| 1010 | + $newdescr['niv']++; |
|
| 1011 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1012 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1013 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1014 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1015 | + $newdescr['niv']--; |
|
| 1016 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1017 | + if ($preaff === false |
|
| 1018 | + or $avant === false |
|
| 1019 | + or $apres === false |
|
| 1020 | + or $altern === false |
|
| 1021 | + or $postaff === false) { |
|
| 1022 | + $err_e_c = true; |
|
| 1023 | + $code = "''"; |
|
| 1024 | + } else { |
|
| 1025 | + $code = 'BOUCLE' . |
|
| 1026 | + str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1027 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1028 | + $commentaire = "?$nom"; |
|
| 1029 | + if (!$boucles[$nom]->milieu |
|
| 1030 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1031 | + ) { |
|
| 1032 | + if ($preaff != "''") { |
|
| 1033 | + $code .= "\n. $preaff"; |
|
| 1034 | + } |
|
| 1035 | + if ($altern != "''") { |
|
| 1036 | + $code .= "\n. $altern"; |
|
| 1037 | + } |
|
| 1038 | + if ($postaff != "''") { |
|
| 1039 | + $code .= "\n. $postaff"; |
|
| 1040 | + } |
|
| 1041 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1042 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1043 | + } |
|
| 1044 | + $avant = $apres = $altern = "''"; |
|
| 1045 | + } else { |
|
| 1046 | + if ($preaff != "''") { |
|
| 1047 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1048 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1049 | + } |
|
| 1050 | + if ($postaff != "''") { |
|
| 1051 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1052 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1053 | + } |
|
| 1054 | + if ($altern != "''") { |
|
| 1055 | + $altern = "($altern)"; |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + break; |
|
| 1060 | + |
|
| 1061 | + case 'idiome': |
|
| 1062 | + $l = array(); |
|
| 1063 | + $code = ''; |
|
| 1064 | + foreach ($p->arg as $k => $v) { |
|
| 1065 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1066 | + if ($k) { |
|
| 1067 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1068 | + } else { |
|
| 1069 | + $code = $_v; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1073 | + if ($p->module) { |
|
| 1074 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1075 | + } elseif ($p->nom_champ) { |
|
| 1076 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1077 | + } else { |
|
| 1078 | + $m = ''; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + $code = (!$code ? "'$m'" : |
|
| 1082 | + ($m ? "'$m' . $code" : |
|
| 1083 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1084 | + . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1085 | + $code = "_T($code)"; |
|
| 1086 | + if ($p->param) { |
|
| 1087 | + $p->id_boucle = $id_boucle; |
|
| 1088 | + $p->boucles = &$boucles; |
|
| 1089 | + $code = compose_filtres($p, $code); |
|
| 1090 | + } |
|
| 1091 | + $commentaire = ":"; |
|
| 1092 | + $avant = ''; |
|
| 1093 | + $apres = ''; |
|
| 1094 | + $altern = "''"; |
|
| 1095 | + break; |
|
| 1096 | + |
|
| 1097 | + case 'champ': |
|
| 1098 | + |
|
| 1099 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1100 | + $p->id_boucle = $id_boucle; |
|
| 1101 | + $p->boucles = &$boucles; |
|
| 1102 | + $p->descr = $descr; |
|
| 1103 | + #$p->interdire_scripts = true; |
|
| 1104 | + $p->type_requete = $type; |
|
| 1105 | + |
|
| 1106 | + $code = calculer_champ($p); |
|
| 1107 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1108 | + $avant = calculer_liste($p->avant, |
|
| 1109 | + $descr, $boucles, $id_boucle); |
|
| 1110 | + $apres = calculer_liste($p->apres, |
|
| 1111 | + $descr, $boucles, $id_boucle); |
|
| 1112 | + $altern = "''"; |
|
| 1113 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1114 | + // forcer la conversion en une chaine par strval |
|
| 1115 | + // si ca peut etre autre chose qu'une chaine |
|
| 1116 | + if (($avant != "''" or $apres != "''") |
|
| 1117 | + and $code[0] != "'" |
|
| 1118 | 1118 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1119 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1120 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1121 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1122 | - ) { |
|
| 1123 | - $code = "strval($code)"; |
|
| 1124 | - } |
|
| 1125 | - break; |
|
| 1126 | - |
|
| 1127 | - default: |
|
| 1128 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1129 | - $code = "''"; |
|
| 1130 | - $p->descr = $descr; |
|
| 1131 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1132 | - erreur_squelette($err_e_c, $p); |
|
| 1133 | - } // switch |
|
| 1134 | - |
|
| 1135 | - if ($code != "''") { |
|
| 1136 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1137 | - $codes[] = (($mode == 'validation') ? |
|
| 1138 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1139 | - : (($mode == 'code') ? |
|
| 1140 | - "\n// $commentaire\n$code" : |
|
| 1141 | - $code)); |
|
| 1142 | - } |
|
| 1143 | - } // foreach |
|
| 1144 | - |
|
| 1145 | - return $err_e_c ? false : $codes; |
|
| 1119 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1120 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1121 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1122 | + ) { |
|
| 1123 | + $code = "strval($code)"; |
|
| 1124 | + } |
|
| 1125 | + break; |
|
| 1126 | + |
|
| 1127 | + default: |
|
| 1128 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1129 | + $code = "''"; |
|
| 1130 | + $p->descr = $descr; |
|
| 1131 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1132 | + erreur_squelette($err_e_c, $p); |
|
| 1133 | + } // switch |
|
| 1134 | + |
|
| 1135 | + if ($code != "''") { |
|
| 1136 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1137 | + $codes[] = (($mode == 'validation') ? |
|
| 1138 | + "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1139 | + : (($mode == 'code') ? |
|
| 1140 | + "\n// $commentaire\n$code" : |
|
| 1141 | + $code)); |
|
| 1142 | + } |
|
| 1143 | + } // foreach |
|
| 1144 | + |
|
| 1145 | + return $err_e_c ? false : $codes; |
|
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | /** |
@@ -1152,13 +1152,13 @@ discard block |
||
| 1152 | 1152 | * @return string |
| 1153 | 1153 | */ |
| 1154 | 1154 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1155 | - if ($partie1 === "''") { |
|
| 1156 | - return $partie2; |
|
| 1157 | - } |
|
| 1158 | - if ($partie2 === "''") { |
|
| 1159 | - return $partie1; |
|
| 1160 | - } |
|
| 1161 | - return "$partie1\n. $partie2"; |
|
| 1155 | + if ($partie1 === "''") { |
|
| 1156 | + return $partie2; |
|
| 1157 | + } |
|
| 1158 | + if ($partie2 === "''") { |
|
| 1159 | + return $partie1; |
|
| 1160 | + } |
|
| 1161 | + return "$partie1\n. $partie2"; |
|
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | |
@@ -1183,57 +1183,57 @@ discard block |
||
| 1183 | 1183 | * @return mixed|string |
| 1184 | 1184 | */ |
| 1185 | 1185 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1186 | - if ($avant === "''") { |
|
| 1187 | - $avant = ''; |
|
| 1188 | - } |
|
| 1189 | - if ($apres === "''") { |
|
| 1190 | - $apres = ''; |
|
| 1191 | - } |
|
| 1192 | - if ($avant or $apres or ($altern !== "''")){ |
|
| 1193 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)){ |
|
| 1194 | - $t = $code; |
|
| 1195 | - $cond = ''; |
|
| 1196 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1197 | - $t = $r[2]; |
|
| 1198 | - $cond = '!' . $r[1]; |
|
| 1199 | - } else { |
|
| 1200 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)){ |
|
| 1201 | - $t = $r[2]; |
|
| 1202 | - $cond = $r[1]; |
|
| 1203 | - } else { |
|
| 1204 | - $t = '$t' . $n; |
|
| 1205 | - $cond = "($t = $code)!==''"; |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1210 | - $t . |
|
| 1211 | - (!$apres ? "" : " . $apres"); |
|
| 1212 | - |
|
| 1213 | - if ($res!==$t){ |
|
| 1214 | - $res = "($res)"; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - return $code; |
|
| 1186 | + if ($avant === "''") { |
|
| 1187 | + $avant = ''; |
|
| 1188 | + } |
|
| 1189 | + if ($apres === "''") { |
|
| 1190 | + $apres = ''; |
|
| 1191 | + } |
|
| 1192 | + if ($avant or $apres or ($altern !== "''")){ |
|
| 1193 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)){ |
|
| 1194 | + $t = $code; |
|
| 1195 | + $cond = ''; |
|
| 1196 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1197 | + $t = $r[2]; |
|
| 1198 | + $cond = '!' . $r[1]; |
|
| 1199 | + } else { |
|
| 1200 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)){ |
|
| 1201 | + $t = $r[2]; |
|
| 1202 | + $cond = $r[1]; |
|
| 1203 | + } else { |
|
| 1204 | + $t = '$t' . $n; |
|
| 1205 | + $cond = "($t = $code)!==''"; |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $res = (!$avant ? "" : "$avant . ") . |
|
| 1210 | + $t . |
|
| 1211 | + (!$apres ? "" : " . $apres"); |
|
| 1212 | + |
|
| 1213 | + if ($res!==$t){ |
|
| 1214 | + $res = "($res)"; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + return $code; |
|
| 1221 | 1221 | |
| 1222 | 1222 | } |
| 1223 | 1223 | |
| 1224 | 1224 | |
| 1225 | 1225 | function compile_inclure_doublons($lexemes) { |
| 1226 | - foreach ($lexemes as $v) { |
|
| 1227 | - if ($v->type === 'include' and $v->param) { |
|
| 1228 | - foreach ($v->param as $r) { |
|
| 1229 | - if (trim($r[0]) === 'doublons') { |
|
| 1230 | - return true; |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - return false; |
|
| 1226 | + foreach ($lexemes as $v) { |
|
| 1227 | + if ($v->type === 'include' and $v->param) { |
|
| 1228 | + foreach ($v->param as $r) { |
|
| 1229 | + if (trim($r[0]) === 'doublons') { |
|
| 1230 | + return true; |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + return false; |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1253,348 +1253,348 @@ discard block |
||
| 1253 | 1253 | |
| 1254 | 1254 | // http://code.spip.net/@public_compiler_dist |
| 1255 | 1255 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, $connect = '') { |
| 1256 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1257 | - // Bonus : supprime le BOM |
|
| 1258 | - include_spip('inc/charsets'); |
|
| 1259 | - $squelette = transcoder_page($squelette); |
|
| 1260 | - |
|
| 1261 | - // rendre inertes les echappements de #[](){}<> |
|
| 1262 | - $i = 0; |
|
| 1263 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1264 | - $i++; |
|
| 1265 | - } |
|
| 1266 | - $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1267 | - function($a) use ($inerte) { |
|
| 1268 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1269 | - }, |
|
| 1270 | - $squelette, |
|
| 1271 | - -1, |
|
| 1272 | - $esc |
|
| 1273 | - ); |
|
| 1274 | - |
|
| 1275 | - $descr = array( |
|
| 1276 | - 'nom' => $nom, |
|
| 1277 | - 'gram' => $gram, |
|
| 1278 | - 'sourcefile' => $sourcefile, |
|
| 1279 | - 'squelette' => $squelette |
|
| 1280 | - ); |
|
| 1281 | - |
|
| 1282 | - // Phraser le squelette, selon sa grammaire |
|
| 1283 | - |
|
| 1284 | - $boucles = array(); |
|
| 1285 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1286 | - |
|
| 1287 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1288 | - |
|
| 1289 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1290 | - |
|
| 1291 | - // restituer les echappements |
|
| 1292 | - if ($esc) { |
|
| 1293 | - foreach ($boucles as $i => $boucle) { |
|
| 1294 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1295 | - ",$inerte-(\d+)-,", |
|
| 1296 | - function($a) { |
|
| 1297 | - return chr($a[1]); |
|
| 1298 | - }, |
|
| 1299 | - $boucle->return |
|
| 1300 | - ); |
|
| 1301 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1302 | - ",$inerte-(\d+)-,", |
|
| 1303 | - function($a) { |
|
| 1304 | - return "\\\\" . chr($a[1]); |
|
| 1305 | - }, |
|
| 1306 | - $boucle->descr['squelette'] |
|
| 1307 | - ); |
|
| 1308 | - } |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1312 | - if ($debug) { |
|
| 1313 | - include_spip('public/decompiler'); |
|
| 1314 | - foreach ($boucles as $id => $boucle) { |
|
| 1315 | - if ($id) { |
|
| 1316 | - $decomp = "\n/* BOUCLE " . |
|
| 1317 | - $boucle->type_requete . |
|
| 1318 | - " " . |
|
| 1319 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1320 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1321 | - " */\n"; |
|
| 1322 | - } else { |
|
| 1323 | - $decomp = ("\n/*\n" . |
|
| 1324 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1325 | - . "\n*/"); |
|
| 1326 | - } |
|
| 1327 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1328 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1329 | - } |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - return $boucles; |
|
| 1256 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1257 | + // Bonus : supprime le BOM |
|
| 1258 | + include_spip('inc/charsets'); |
|
| 1259 | + $squelette = transcoder_page($squelette); |
|
| 1260 | + |
|
| 1261 | + // rendre inertes les echappements de #[](){}<> |
|
| 1262 | + $i = 0; |
|
| 1263 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1264 | + $i++; |
|
| 1265 | + } |
|
| 1266 | + $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
|
| 1267 | + function($a) use ($inerte) { |
|
| 1268 | + return "$inerte-" . ord($a[1]) . '-'; |
|
| 1269 | + }, |
|
| 1270 | + $squelette, |
|
| 1271 | + -1, |
|
| 1272 | + $esc |
|
| 1273 | + ); |
|
| 1274 | + |
|
| 1275 | + $descr = array( |
|
| 1276 | + 'nom' => $nom, |
|
| 1277 | + 'gram' => $gram, |
|
| 1278 | + 'sourcefile' => $sourcefile, |
|
| 1279 | + 'squelette' => $squelette |
|
| 1280 | + ); |
|
| 1281 | + |
|
| 1282 | + // Phraser le squelette, selon sa grammaire |
|
| 1283 | + |
|
| 1284 | + $boucles = array(); |
|
| 1285 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1286 | + |
|
| 1287 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1288 | + |
|
| 1289 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1290 | + |
|
| 1291 | + // restituer les echappements |
|
| 1292 | + if ($esc) { |
|
| 1293 | + foreach ($boucles as $i => $boucle) { |
|
| 1294 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1295 | + ",$inerte-(\d+)-,", |
|
| 1296 | + function($a) { |
|
| 1297 | + return chr($a[1]); |
|
| 1298 | + }, |
|
| 1299 | + $boucle->return |
|
| 1300 | + ); |
|
| 1301 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1302 | + ",$inerte-(\d+)-,", |
|
| 1303 | + function($a) { |
|
| 1304 | + return "\\\\" . chr($a[1]); |
|
| 1305 | + }, |
|
| 1306 | + $boucle->descr['squelette'] |
|
| 1307 | + ); |
|
| 1308 | + } |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1312 | + if ($debug) { |
|
| 1313 | + include_spip('public/decompiler'); |
|
| 1314 | + foreach ($boucles as $id => $boucle) { |
|
| 1315 | + if ($id) { |
|
| 1316 | + $decomp = "\n/* BOUCLE " . |
|
| 1317 | + $boucle->type_requete . |
|
| 1318 | + " " . |
|
| 1319 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1320 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1321 | + " */\n"; |
|
| 1322 | + } else { |
|
| 1323 | + $decomp = ("\n/*\n" . |
|
| 1324 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1325 | + . "\n*/"); |
|
| 1326 | + } |
|
| 1327 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1328 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1329 | + } |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + return $boucles; |
|
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | 1335 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1336 | 1336 | // Autres specifications comme ci-dessus |
| 1337 | 1337 | |
| 1338 | 1338 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect = '') { |
| 1339 | - static $trouver_table; |
|
| 1340 | - spip_timer('calcul_skel'); |
|
| 1341 | - |
|
| 1342 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1343 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1344 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1345 | - |
|
| 1346 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1347 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1348 | - } |
|
| 1349 | - } |
|
| 1350 | - foreach ($boucles as $id => $boucle) { |
|
| 1351 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1352 | - } |
|
| 1353 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1354 | - |
|
| 1355 | - // Demander la description des tables une fois pour toutes |
|
| 1356 | - if (!$trouver_table) { |
|
| 1357 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - // reperer si les doublons sont demandes |
|
| 1361 | - // pour un inclure ou une boucle document |
|
| 1362 | - // c'est utile a la fonction champs_traitements |
|
| 1363 | - foreach ($boucles as $id => $boucle) { |
|
| 1364 | - if (!($type = $boucle->type_requete)) { |
|
| 1365 | - continue; |
|
| 1366 | - } |
|
| 1367 | - if (!$descr['documents'] and ( |
|
| 1368 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1369 | - compile_inclure_doublons($boucle->avant) or |
|
| 1370 | - compile_inclure_doublons($boucle->apres) or |
|
| 1371 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1372 | - compile_inclure_doublons($boucle->altern)) |
|
| 1373 | - ) { |
|
| 1374 | - $descr['documents'] = true; |
|
| 1375 | - } |
|
| 1376 | - if ($type != TYPE_RECURSIF) { |
|
| 1377 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1378 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1379 | - } |
|
| 1380 | - |
|
| 1381 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1382 | - if ($g = charger_fonction( |
|
| 1383 | - preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1384 | - ) { |
|
| 1385 | - $boucles[$id] = $g($boucle); |
|
| 1386 | - |
|
| 1387 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1388 | - // utiliser les informations donnees par le requeteur |
|
| 1389 | - // cas "php:xx" et "data:xx". |
|
| 1390 | - } else { |
|
| 1391 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1392 | - $requeteur($boucles, $boucle, $id); |
|
| 1393 | - |
|
| 1394 | - // utiliser la description des champs transmis |
|
| 1395 | - } else { |
|
| 1396 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1397 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1398 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1399 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1400 | - if (!$show |
|
| 1401 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1402 | - ) { |
|
| 1403 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1404 | - } |
|
| 1405 | - if ($show) { |
|
| 1406 | - $boucles[$id]->show = $show; |
|
| 1407 | - // recopie les infos les plus importantes |
|
| 1408 | - $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1409 | - $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1410 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1411 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1412 | - |
|
| 1413 | - if (empty($boucles[$id]->descr)) { |
|
| 1414 | - $boucles[$id]->descr = &$descr; |
|
| 1415 | - } |
|
| 1416 | - if ((!$boucles[$id]->jointures) |
|
| 1417 | - and is_array($show['tables_jointures']) |
|
| 1418 | - and count($x = $show['tables_jointures']) |
|
| 1419 | - ) { |
|
| 1420 | - $boucles[$id]->jointures = $x; |
|
| 1421 | - } |
|
| 1422 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1423 | - $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1424 | - while ($j = array_pop($jointures)) { |
|
| 1425 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1426 | - } |
|
| 1427 | - } |
|
| 1428 | - } else { |
|
| 1429 | - // Pas une erreur si la table est optionnelle |
|
| 1430 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1431 | - $boucles[$id]->type_requete = ''; |
|
| 1432 | - } else { |
|
| 1433 | - $boucles[$id]->type_requete = false; |
|
| 1434 | - $boucle = $boucles[$id]; |
|
| 1435 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1436 | - ($boucle->sql_serveur . ":")) . |
|
| 1437 | - $type; |
|
| 1438 | - $msg = array( |
|
| 1439 | - 'zbug_table_inconnue', |
|
| 1440 | - array('table' => $x) |
|
| 1441 | - ); |
|
| 1442 | - erreur_squelette($msg, $boucle); |
|
| 1443 | - } |
|
| 1444 | - } |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1451 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1452 | - foreach ($boucles as $id => $boucle) { |
|
| 1453 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1454 | - $boucles[$id]->descr = &$descr; |
|
| 1455 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1456 | - if (!$rec) { |
|
| 1457 | - $msg = array( |
|
| 1458 | - 'zbug_boucle_recursive_undef', |
|
| 1459 | - array('nom' => $boucle->param[0]) |
|
| 1460 | - ); |
|
| 1461 | - erreur_squelette($msg, $boucle); |
|
| 1462 | - $boucles[$id]->type_requete = false; |
|
| 1463 | - } else { |
|
| 1464 | - $rec->externe = $id; |
|
| 1465 | - $descr['id_mere'] = $id; |
|
| 1466 | - $boucles[$id]->return = |
|
| 1467 | - calculer_liste(array($rec), |
|
| 1468 | - $descr, |
|
| 1469 | - $boucles, |
|
| 1470 | - $boucle->param); |
|
| 1471 | - } |
|
| 1472 | - } |
|
| 1473 | - } |
|
| 1474 | - foreach ($boucles as $id => $boucle) { |
|
| 1475 | - $id = strval($id); // attention au type dans index_pile |
|
| 1476 | - $type = $boucle->type_requete; |
|
| 1477 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1478 | - $res = ''; |
|
| 1479 | - if ($boucle->param) { |
|
| 1480 | - // retourne un tableau en cas d'erreur |
|
| 1481 | - $res = calculer_criteres($id, $boucles); |
|
| 1482 | - } |
|
| 1483 | - $descr['id_mere'] = $id; |
|
| 1484 | - $boucles[$id]->return = |
|
| 1485 | - calculer_liste($boucle->milieu, |
|
| 1486 | - $descr, |
|
| 1487 | - $boucles, |
|
| 1488 | - $id); |
|
| 1489 | - // Si les criteres se sont mal compiles |
|
| 1490 | - // ne pas tenter d'assembler le code final |
|
| 1491 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1492 | - if (is_array($res)) { |
|
| 1493 | - $boucles[$id]->type_requete = false; |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - // idem pour la racine |
|
| 1499 | - $descr['id_mere'] = ''; |
|
| 1500 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1504 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1505 | - // de'terminables seulement maintenant |
|
| 1506 | - |
|
| 1507 | - foreach ($boucles as $id => $boucle) { |
|
| 1508 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1509 | - if ($boucle->return === false) { |
|
| 1510 | - $corps = false; |
|
| 1511 | - continue; |
|
| 1512 | - } |
|
| 1513 | - // appeler la fonction de definition de la boucle |
|
| 1514 | - |
|
| 1515 | - if ($req = $boucle->type_requete) { |
|
| 1516 | - // boucle personnalisée ? |
|
| 1517 | - $table = strtoupper($boucle->type_requete); |
|
| 1518 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1519 | - if ( |
|
| 1520 | - // fonction de boucle avec serveur & table |
|
| 1521 | - (!$serveur or |
|
| 1522 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1523 | - and (!function_exists($f = $f . "_dist")) |
|
| 1524 | - ) |
|
| 1525 | - ) |
|
| 1526 | - // fonction de boucle avec table |
|
| 1527 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1528 | - and (!function_exists($f = $f . "_dist")) |
|
| 1529 | - ) { |
|
| 1530 | - // fonction de boucle standard |
|
| 1531 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1532 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1537 | - "static \$connect;\n\t" . |
|
| 1538 | - "\$command['connect'] = \$connect = " . |
|
| 1539 | - _q($boucle->sql_serveur) . |
|
| 1540 | - ";" . |
|
| 1541 | - $f($id, $boucles); |
|
| 1542 | - } else { |
|
| 1543 | - $req = ("\n\treturn '';"); |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - $boucles[$id]->return = |
|
| 1547 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1548 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1549 | - $req . |
|
| 1550 | - "\n}\n"; |
|
| 1551 | - } |
|
| 1552 | - |
|
| 1553 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1554 | - // retourner False, sinon inserer leur decompilation |
|
| 1555 | - if (is_bool($corps)) { |
|
| 1556 | - return false; |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1339 | + static $trouver_table; |
|
| 1340 | + spip_timer('calcul_skel'); |
|
| 1341 | + |
|
| 1342 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1343 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1344 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1345 | + |
|
| 1346 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1347 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1348 | + } |
|
| 1349 | + } |
|
| 1350 | + foreach ($boucles as $id => $boucle) { |
|
| 1351 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1352 | + } |
|
| 1353 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1354 | + |
|
| 1355 | + // Demander la description des tables une fois pour toutes |
|
| 1356 | + if (!$trouver_table) { |
|
| 1357 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + // reperer si les doublons sont demandes |
|
| 1361 | + // pour un inclure ou une boucle document |
|
| 1362 | + // c'est utile a la fonction champs_traitements |
|
| 1363 | + foreach ($boucles as $id => $boucle) { |
|
| 1364 | + if (!($type = $boucle->type_requete)) { |
|
| 1365 | + continue; |
|
| 1366 | + } |
|
| 1367 | + if (!$descr['documents'] and ( |
|
| 1368 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1369 | + compile_inclure_doublons($boucle->avant) or |
|
| 1370 | + compile_inclure_doublons($boucle->apres) or |
|
| 1371 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1372 | + compile_inclure_doublons($boucle->altern)) |
|
| 1373 | + ) { |
|
| 1374 | + $descr['documents'] = true; |
|
| 1375 | + } |
|
| 1376 | + if ($type != TYPE_RECURSIF) { |
|
| 1377 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1378 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1379 | + } |
|
| 1380 | + |
|
| 1381 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1382 | + if ($g = charger_fonction( |
|
| 1383 | + preg_replace('/\W/', '_', $boucle->type_requete), 'iterateur', true) |
|
| 1384 | + ) { |
|
| 1385 | + $boucles[$id] = $g($boucle); |
|
| 1386 | + |
|
| 1387 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1388 | + // utiliser les informations donnees par le requeteur |
|
| 1389 | + // cas "php:xx" et "data:xx". |
|
| 1390 | + } else { |
|
| 1391 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1392 | + $requeteur($boucles, $boucle, $id); |
|
| 1393 | + |
|
| 1394 | + // utiliser la description des champs transmis |
|
| 1395 | + } else { |
|
| 1396 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1397 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1398 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1399 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1400 | + if (!$show |
|
| 1401 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1402 | + ) { |
|
| 1403 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1404 | + } |
|
| 1405 | + if ($show) { |
|
| 1406 | + $boucles[$id]->show = $show; |
|
| 1407 | + // recopie les infos les plus importantes |
|
| 1408 | + $boucles[$id]->primary = isset($show['key']["PRIMARY KEY"]) ? $show['key']["PRIMARY KEY"] : ''; |
|
| 1409 | + $boucles[$id]->id_table = $x = preg_replace(",^spip_,", "", $show['id_table']); |
|
| 1410 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1411 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1412 | + |
|
| 1413 | + if (empty($boucles[$id]->descr)) { |
|
| 1414 | + $boucles[$id]->descr = &$descr; |
|
| 1415 | + } |
|
| 1416 | + if ((!$boucles[$id]->jointures) |
|
| 1417 | + and is_array($show['tables_jointures']) |
|
| 1418 | + and count($x = $show['tables_jointures']) |
|
| 1419 | + ) { |
|
| 1420 | + $boucles[$id]->jointures = $x; |
|
| 1421 | + } |
|
| 1422 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1423 | + $jointures = preg_split("/\s+/", $boucles[$id]->jointures_explicites); |
|
| 1424 | + while ($j = array_pop($jointures)) { |
|
| 1425 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1426 | + } |
|
| 1427 | + } |
|
| 1428 | + } else { |
|
| 1429 | + // Pas une erreur si la table est optionnelle |
|
| 1430 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1431 | + $boucles[$id]->type_requete = ''; |
|
| 1432 | + } else { |
|
| 1433 | + $boucles[$id]->type_requete = false; |
|
| 1434 | + $boucle = $boucles[$id]; |
|
| 1435 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1436 | + ($boucle->sql_serveur . ":")) . |
|
| 1437 | + $type; |
|
| 1438 | + $msg = array( |
|
| 1439 | + 'zbug_table_inconnue', |
|
| 1440 | + array('table' => $x) |
|
| 1441 | + ); |
|
| 1442 | + erreur_squelette($msg, $boucle); |
|
| 1443 | + } |
|
| 1444 | + } |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1451 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1452 | + foreach ($boucles as $id => $boucle) { |
|
| 1453 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1454 | + $boucles[$id]->descr = &$descr; |
|
| 1455 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1456 | + if (!$rec) { |
|
| 1457 | + $msg = array( |
|
| 1458 | + 'zbug_boucle_recursive_undef', |
|
| 1459 | + array('nom' => $boucle->param[0]) |
|
| 1460 | + ); |
|
| 1461 | + erreur_squelette($msg, $boucle); |
|
| 1462 | + $boucles[$id]->type_requete = false; |
|
| 1463 | + } else { |
|
| 1464 | + $rec->externe = $id; |
|
| 1465 | + $descr['id_mere'] = $id; |
|
| 1466 | + $boucles[$id]->return = |
|
| 1467 | + calculer_liste(array($rec), |
|
| 1468 | + $descr, |
|
| 1469 | + $boucles, |
|
| 1470 | + $boucle->param); |
|
| 1471 | + } |
|
| 1472 | + } |
|
| 1473 | + } |
|
| 1474 | + foreach ($boucles as $id => $boucle) { |
|
| 1475 | + $id = strval($id); // attention au type dans index_pile |
|
| 1476 | + $type = $boucle->type_requete; |
|
| 1477 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1478 | + $res = ''; |
|
| 1479 | + if ($boucle->param) { |
|
| 1480 | + // retourne un tableau en cas d'erreur |
|
| 1481 | + $res = calculer_criteres($id, $boucles); |
|
| 1482 | + } |
|
| 1483 | + $descr['id_mere'] = $id; |
|
| 1484 | + $boucles[$id]->return = |
|
| 1485 | + calculer_liste($boucle->milieu, |
|
| 1486 | + $descr, |
|
| 1487 | + $boucles, |
|
| 1488 | + $id); |
|
| 1489 | + // Si les criteres se sont mal compiles |
|
| 1490 | + // ne pas tenter d'assembler le code final |
|
| 1491 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1492 | + if (is_array($res)) { |
|
| 1493 | + $boucles[$id]->type_requete = false; |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + // idem pour la racine |
|
| 1499 | + $descr['id_mere'] = ''; |
|
| 1500 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1504 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1505 | + // de'terminables seulement maintenant |
|
| 1506 | + |
|
| 1507 | + foreach ($boucles as $id => $boucle) { |
|
| 1508 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1509 | + if ($boucle->return === false) { |
|
| 1510 | + $corps = false; |
|
| 1511 | + continue; |
|
| 1512 | + } |
|
| 1513 | + // appeler la fonction de definition de la boucle |
|
| 1514 | + |
|
| 1515 | + if ($req = $boucle->type_requete) { |
|
| 1516 | + // boucle personnalisée ? |
|
| 1517 | + $table = strtoupper($boucle->type_requete); |
|
| 1518 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1519 | + if ( |
|
| 1520 | + // fonction de boucle avec serveur & table |
|
| 1521 | + (!$serveur or |
|
| 1522 | + ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1523 | + and (!function_exists($f = $f . "_dist")) |
|
| 1524 | + ) |
|
| 1525 | + ) |
|
| 1526 | + // fonction de boucle avec table |
|
| 1527 | + and (!function_exists($f = "boucle_" . $table)) |
|
| 1528 | + and (!function_exists($f = $f . "_dist")) |
|
| 1529 | + ) { |
|
| 1530 | + // fonction de boucle standard |
|
| 1531 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1532 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1537 | + "static \$connect;\n\t" . |
|
| 1538 | + "\$command['connect'] = \$connect = " . |
|
| 1539 | + _q($boucle->sql_serveur) . |
|
| 1540 | + ";" . |
|
| 1541 | + $f($id, $boucles); |
|
| 1542 | + } else { |
|
| 1543 | + $req = ("\n\treturn '';"); |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + $boucles[$id]->return = |
|
| 1547 | + "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1548 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1549 | + $req . |
|
| 1550 | + "\n}\n"; |
|
| 1551 | + } |
|
| 1552 | + |
|
| 1553 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1554 | + // retourner False, sinon inserer leur decompilation |
|
| 1555 | + if (is_bool($corps)) { |
|
| 1556 | + return false; |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1560 | 1560 | ' |
| 1561 | - // reporter de maniere securisee les doublons inclus |
|
| 1562 | - . ' |
|
| 1561 | + // reporter de maniere securisee les doublons inclus |
|
| 1562 | + . ' |
|
| 1563 | 1563 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1564 | 1564 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1565 | 1565 | |
| 1566 | 1566 | $connect = ' . |
| 1567 | - _q($connect) . '; |
|
| 1567 | + _q($connect) . '; |
|
| 1568 | 1568 | $page = ' . |
| 1569 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1570 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1571 | - // avant de referencer $Cache |
|
| 1572 | - $corps . "; |
|
| 1569 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1570 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1571 | + // avant de referencer $Cache |
|
| 1572 | + $corps . "; |
|
| 1573 | 1573 | |
| 1574 | 1574 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1575 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1575 | + . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1576 | 1576 | }"; |
| 1577 | 1577 | |
| 1578 | - $secondes = spip_timer('calcul_skel'); |
|
| 1579 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1580 | - // $connect n'est pas sûr : on nettoie |
|
| 1581 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1578 | + $secondes = spip_timer('calcul_skel'); |
|
| 1579 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1580 | + // $connect n'est pas sûr : on nettoie |
|
| 1581 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1582 | 1582 | |
| 1583 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1584 | - $code = new Boucle; |
|
| 1585 | - $code->descr = $descr; |
|
| 1586 | - $code->return = ' |
|
| 1583 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1584 | + $code = new Boucle; |
|
| 1585 | + $code->descr = $descr; |
|
| 1586 | + $code->return = ' |
|
| 1587 | 1587 | // |
| 1588 | 1588 | // Fonction principale du squelette ' . |
| 1589 | - $sourcefile . |
|
| 1590 | - ($connect ? " pour $connect" : '') . |
|
| 1591 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1592 | - "\n//\n" . |
|
| 1593 | - $principal; |
|
| 1589 | + $sourcefile . |
|
| 1590 | + ($connect ? " pour $connect" : '') . |
|
| 1591 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1592 | + "\n//\n" . |
|
| 1593 | + $principal; |
|
| 1594 | 1594 | |
| 1595 | - $boucles[''] = $code; |
|
| 1595 | + $boucles[''] = $code; |
|
| 1596 | 1596 | |
| 1597 | - return $boucles; |
|
| 1597 | + return $boucles; |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | |
@@ -1611,18 +1611,18 @@ discard block |
||
| 1611 | 1611 | * |
| 1612 | 1612 | **/ |
| 1613 | 1613 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1614 | - if (class_exists($boucle->type_requete)) { |
|
| 1615 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1616 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1617 | - } else { |
|
| 1618 | - $x = $boucle->type_requete; |
|
| 1619 | - $boucle->type_requete = false; |
|
| 1620 | - $msg = array( |
|
| 1621 | - 'zbug_iterateur_inconnu', |
|
| 1622 | - array('iterateur' => $x) |
|
| 1623 | - ); |
|
| 1624 | - erreur_squelette($msg, $boucle); |
|
| 1625 | - } |
|
| 1614 | + if (class_exists($boucle->type_requete)) { |
|
| 1615 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1616 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1617 | + } else { |
|
| 1618 | + $x = $boucle->type_requete; |
|
| 1619 | + $boucle->type_requete = false; |
|
| 1620 | + $msg = array( |
|
| 1621 | + 'zbug_iterateur_inconnu', |
|
| 1622 | + array('iterateur' => $x) |
|
| 1623 | + ); |
|
| 1624 | + erreur_squelette($msg, $boucle); |
|
| 1625 | + } |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | |
@@ -1640,23 +1640,23 @@ discard block |
||
| 1640 | 1640 | * |
| 1641 | 1641 | **/ |
| 1642 | 1642 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1643 | - include_spip('iterateur/data'); |
|
| 1644 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1645 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1646 | - $boucles[$id] = $g($boucle); |
|
| 1647 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1648 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1649 | - |
|
| 1650 | - } else { |
|
| 1651 | - $x = $boucle->type_requete; |
|
| 1652 | - $boucle->type_requete = false; |
|
| 1653 | - $msg = array( |
|
| 1654 | - 'zbug_requeteur_inconnu', |
|
| 1655 | - array( |
|
| 1656 | - 'requeteur' => 'data', |
|
| 1657 | - 'type' => $x |
|
| 1658 | - ) |
|
| 1659 | - ); |
|
| 1660 | - erreur_squelette($msg, $boucle); |
|
| 1661 | - } |
|
| 1643 | + include_spip('iterateur/data'); |
|
| 1644 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1645 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1646 | + $boucles[$id] = $g($boucle); |
|
| 1647 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1648 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1649 | + |
|
| 1650 | + } else { |
|
| 1651 | + $x = $boucle->type_requete; |
|
| 1652 | + $boucle->type_requete = false; |
|
| 1653 | + $msg = array( |
|
| 1654 | + 'zbug_requeteur_inconnu', |
|
| 1655 | + array( |
|
| 1656 | + 'requeteur' => 'data', |
|
| 1657 | + 'type' => $x |
|
| 1658 | + ) |
|
| 1659 | + ); |
|
| 1660 | + erreur_squelette($msg, $boucle); |
|
| 1661 | + } |
|
| 1662 | 1662 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | preg_match(",^([^=]*)(=?)(.*)$,m", $var->texte, $m); |
| 98 | 98 | $m = array_pad($m, 3, null); |
| 99 | 99 | $var = $m[1]; |
| 100 | - $auto = false;; |
|
| 100 | + $auto = false; ; |
|
| 101 | 101 | if ($m[2]) { |
| 102 | 102 | $v = $m[3]; |
| 103 | 103 | if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
| 122 | 122 | if ($var !== 1) { |
| 123 | 123 | $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
| 124 | - . $val . ($echap ? ") . '" : " "); |
|
| 124 | + . $val.($echap ? ") . '" : " "); |
|
| 125 | 125 | } else { |
| 126 | 126 | $val = $echap ? "'.$val.'" : $val; |
| 127 | 127 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (!$lang) { |
| 143 | 143 | $lang = '$GLOBALS["spip_lang"]'; |
| 144 | 144 | } |
| 145 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : " "); |
|
| 145 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ").$lang.($echap ? ") . '" : " "); |
|
| 146 | 146 | |
| 147 | 147 | return $l; |
| 148 | 148 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
| 172 | 172 | if (is_string($p->texte)) { |
| 173 | 173 | $fichier = $p->texte; |
| 174 | - $code = "\"".str_replace('"','\"',$fichier)."\""; |
|
| 174 | + $code = "\"".str_replace('"', '\"', $fichier)."\""; |
|
| 175 | 175 | |
| 176 | 176 | } else { |
| 177 | 177 | $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | return false; |
| 214 | 214 | } // j'aurais voulu toucher le fond ... |
| 215 | 215 | |
| 216 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 216 | + $contexte = 'array('.$_contexte.')'; |
|
| 217 | 217 | |
| 218 | 218 | if ($env) { |
| 219 | 219 | $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | $_options[] = $ajax; |
| 229 | 229 | } |
| 230 | 230 | $code = " ' . argumenter_squelette($code) . '"; |
| 231 | - $code = "echo " . sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | - "_request(\"connect\")") . ';'; |
|
| 231 | + $code = "echo ".sprintf(CODE_RECUPERER_FOND, $code, $contexte, implode(',', $_options), |
|
| 232 | + "_request(\"connect\")").';'; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return "\n'<'.'" . "?php " . $code . "\n?'." . "'>'"; |
|
| 235 | + return "\n'<'.'"."?php ".$code."\n?'."."'>'"; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -312,17 +312,17 @@ discard block |
||
| 312 | 312 | $id = $id_table; |
| 313 | 313 | $statut = preg_replace(',\W,', '', $s['champ']); // securite |
| 314 | 314 | } |
| 315 | - $mstatut = $id . '.' . $statut; |
|
| 315 | + $mstatut = $id.'.'.$statut; |
|
| 316 | 316 | |
| 317 | 317 | $arg_ignore_previsu = ($ignore_previsu ? ",true" : ''); |
| 318 | 318 | include_spip('public/quete'); |
| 319 | 319 | if (isset($s['post_date']) and $s['post_date'] |
| 320 | 320 | and $GLOBALS['meta']["post_dates"] == 'non' |
| 321 | 321 | ) { |
| 322 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 322 | + $date = $id.'.'.preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 323 | 323 | array_unshift($boucle->where, |
| 324 | 324 | $echapper ? |
| 325 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 325 | + "\nquete_condition_postdates('$date',"._q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 326 | 326 | : |
| 327 | 327 | quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
| 328 | 328 | ); |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | array_unshift($boucle->where, |
| 331 | 331 | $echapper ? |
| 332 | 332 | "\nquete_condition_statut('$mstatut'," |
| 333 | - . _q($s['previsu']) . "," |
|
| 334 | - . _q($s['publie']) . "," |
|
| 335 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 333 | + . _q($s['previsu'])."," |
|
| 334 | + . _q($s['publie'])."," |
|
| 335 | + . _q($boucle->sql_serveur)."$arg_ignore_previsu)" |
|
| 336 | 336 | : |
| 337 | 337 | quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
| 338 | 338 | ); |
@@ -366,14 +366,14 @@ discard block |
||
| 366 | 366 | if (_request('var_mode_affiche') != 'resultat') { |
| 367 | 367 | $trace = ''; |
| 368 | 368 | } else { |
| 369 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 369 | + $_trace = $boucles[$id_boucle]->descr['nom'].$id_boucle; |
|
| 370 | 370 | $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
| 371 | 371 | $trace = " |
| 372 | 372 | if (empty($_trace)) { |
| 373 | 373 | $_trace = []; |
| 374 | 374 | } |
| 375 | 375 | if (count($_trace) < 3) { |
| 376 | - $_trace" . "[] = \$t0; |
|
| 376 | + $_trace"."[] = \$t0; |
|
| 377 | 377 | }"; |
| 378 | 378 | } |
| 379 | 379 | |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | return |
| 408 | 408 | // Numrows[$nom] peut ne pas être encore defini |
| 409 | 409 | "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
| 410 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ";" |
|
| 410 | + . "\n\t\$t0 = ".$boucles[$id_boucle]->return.";" |
|
| 411 | 411 | . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
| 412 | 412 | . $trace |
| 413 | 413 | . "\n\treturn \$t0;"; |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
| 476 | 476 | // et puis faire un [] plutot qu'un "','." |
| 477 | 477 | if ($boucle->doublons) { |
| 478 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 478 | + $corps .= "\n\t\t\tforeach(".$boucle->doublons.' as $k) $doublons[$k] .= "," . '. |
|
| 479 | 479 | index_pile($id_boucle, $primary, $boucles) |
| 480 | 480 | . "; // doublons\n"; |
| 481 | 481 | } |
@@ -502,13 +502,13 @@ discard block |
||
| 502 | 502 | $corps .= |
| 503 | 503 | "\n\t\tlang_select_public(" |
| 504 | 504 | . index_pile($id_boucle, 'lang', $boucles) |
| 505 | - . ", '" . $boucle->lang_select . "'" |
|
| 505 | + . ", '".$boucle->lang_select."'" |
|
| 506 | 506 | . (in_array($type_boucle, array( |
| 507 | 507 | 'articles', |
| 508 | 508 | 'rubriques', |
| 509 | 509 | 'hierarchie', |
| 510 | 510 | 'breves' |
| 511 | - )) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 511 | + )) ? ', '.index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 512 | 512 | . ');'; |
| 513 | 513 | } else { |
| 514 | 514 | $init_lang = ''; |
@@ -529,26 +529,22 @@ discard block |
||
| 529 | 529 | |
| 530 | 530 | // gestion optimale des separateurs et des boucles constantes |
| 531 | 531 | if (count($boucle->separateur)) { |
| 532 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 532 | + $code_sep = ("'".str_replace("'", "\'", join('', $boucle->separateur))."'"); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | $corps .= |
| 536 | 536 | ((!$boucle->separateur) ? |
| 537 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 538 | - (($return === "''") ? '' : |
|
| 539 | - ("\n\t\t" . '$t0 .= ' . $return . ";"))) : |
|
| 540 | - ("\n\t\t\$t1 " . |
|
| 537 | + (($constant && !$corps && !$flag_cpt) ? $return : (($return === "''") ? '' : ("\n\t\t".'$t0 .= '.$return.";"))) : ("\n\t\t\$t1 ". |
|
| 541 | 538 | ((strpos($return, '$t1.') === 0) ? |
| 542 | - (".=" . substr($return, 4)) : |
|
| 543 | - ('= ' . $return)) . |
|
| 544 | - ";\n\t\t" . |
|
| 545 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 539 | + (".=".substr($return, 4)) : ('= '.$return)). |
|
| 540 | + ";\n\t\t". |
|
| 541 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? '.$code_sep." : '') . \$t1;")); |
|
| 546 | 542 | |
| 547 | 543 | // Calculer les invalideurs si c'est une boucle non constante et si on |
| 548 | 544 | // souhaite invalider ces elements |
| 549 | 545 | if (!$constant and $primary) { |
| 550 | 546 | include_spip('inc/invalideur'); |
| 551 | - $corps = calcul_invalideurs($corps, $primary,$boucles, $id_boucle); |
|
| 547 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 552 | 548 | } |
| 553 | 549 | |
| 554 | 550 | // gerer le compteur de boucle |
@@ -622,7 +618,7 @@ discard block |
||
| 622 | 618 | $corps, |
| 623 | 619 | $fin_lang, |
| 624 | 620 | $trace, |
| 625 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 621 | + 'BOUCLE'.$id_boucle.' @ '.($boucle->descr['sourcefile']) |
|
| 626 | 622 | ); |
| 627 | 623 | |
| 628 | 624 | # var_dump($a);exit; |
@@ -643,20 +639,20 @@ discard block |
||
| 643 | 639 | **/ |
| 644 | 640 | function calculer_requete_sql($boucle) { |
| 645 | 641 | $init = array(); |
| 646 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 647 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 642 | + $init[] = calculer_dec('table', "'".$boucle->id_table."'"); |
|
| 643 | + $init[] = calculer_dec('id', "'".$boucle->id_boucle."'"); |
|
| 648 | 644 | # En absence de champ c'est un decompte : |
| 649 | 645 | $init[] = calculer_dec('from', calculer_from($boucle)); |
| 650 | 646 | $init[] = calculer_dec('type', calculer_from_type($boucle)); |
| 651 | 647 | $init[] = calculer_dec('groupby', |
| 652 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ")"); |
|
| 653 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . "\")"); |
|
| 654 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ")"); |
|
| 648 | + 'array('.(($g = join("\",\n\t\t\"", $boucle->group)) ? '"'.$g.'"' : '').")"); |
|
| 649 | + $init[] = calculer_dec('select', 'array("'.join("\",\n\t\t\"", $boucle->select)."\")"); |
|
| 650 | + $init[] = calculer_dec('orderby', 'array('.calculer_order($boucle).")"); |
|
| 655 | 651 | $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
| 656 | 652 | $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
| 657 | 653 | $init[] = calculer_dec('limit', |
| 658 | 654 | (strpos($boucle->limit, 'intval') === false ? |
| 659 | - "'" . $boucle->limit . "'" |
|
| 655 | + "'".$boucle->limit."'" |
|
| 660 | 656 | : |
| 661 | 657 | $boucle->limit)); |
| 662 | 658 | $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
@@ -665,17 +661,17 @@ discard block |
||
| 665 | 661 | // ou recalculée à chaque passage (vide) |
| 666 | 662 | foreach ($init as $i) { |
| 667 | 663 | if (reset($i)) { |
| 668 | - $s .= "\n\t\t" . end($i); |
|
| 664 | + $s .= "\n\t\t".end($i); |
|
| 669 | 665 | } # statique |
| 670 | 666 | else { |
| 671 | - $d .= "\n\t" . end($i); |
|
| 667 | + $d .= "\n\t".end($i); |
|
| 672 | 668 | } # dynamique |
| 673 | 669 | } |
| 674 | 670 | |
| 675 | 671 | return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
| 676 | 672 | . $boucle->in |
| 677 | 673 | . $boucle->hash |
| 678 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 674 | + . "\n\t".'if (!isset($command[\'table\'])) {' |
|
| 679 | 675 | . $s |
| 680 | 676 | . "\n\t}" |
| 681 | 677 | . $d; |
@@ -758,7 +754,7 @@ discard block |
||
| 758 | 754 | * - index 1 : Code de l'affectation |
| 759 | 755 | **/ |
| 760 | 756 | function calculer_dec($nom, $val) { |
| 761 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 757 | + $static = 'if (!isset($command[\''.$nom.'\'])) '; |
|
| 762 | 758 | // si une variable apparait dans le calcul de la clause |
| 763 | 759 | // il faut la re-evaluer a chaque passage |
| 764 | 760 | if ( |
@@ -775,7 +771,7 @@ discard block |
||
| 775 | 771 | $static = ""; |
| 776 | 772 | } |
| 777 | 773 | |
| 778 | - return array($static, '$command[\'' . $nom . '\'] = ' . $val . ';'); |
|
| 774 | + return array($static, '$command[\''.$nom.'\'] = '.$val.';'); |
|
| 779 | 775 | } |
| 780 | 776 | |
| 781 | 777 | /** |
@@ -800,16 +796,16 @@ discard block |
||
| 800 | 796 | } |
| 801 | 797 | $res = ""; |
| 802 | 798 | if ($a and $a[0] == "'?'") { |
| 803 | - return ("(" . calculer_dump_array($a[1]) . |
|
| 804 | - " ? " . calculer_dump_array($a[2]) . |
|
| 805 | - " : " . calculer_dump_array($a[3]) . |
|
| 799 | + return ("(".calculer_dump_array($a[1]). |
|
| 800 | + " ? ".calculer_dump_array($a[2]). |
|
| 801 | + " : ".calculer_dump_array($a[3]). |
|
| 806 | 802 | ")"); |
| 807 | 803 | } else { |
| 808 | 804 | foreach ($a as $v) { |
| 809 | - $res .= ", " . calculer_dump_array($v); |
|
| 805 | + $res .= ", ".calculer_dump_array($v); |
|
| 810 | 806 | } |
| 811 | 807 | |
| 812 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 808 | + return "\n\t\t\tarray(".substr($res, 2).')'; |
|
| 813 | 809 | } |
| 814 | 810 | } |
| 815 | 811 | |
@@ -817,10 +813,10 @@ discard block |
||
| 817 | 813 | function calculer_dump_join($a) { |
| 818 | 814 | $res = ""; |
| 819 | 815 | foreach ($a as $k => $v) { |
| 820 | - $res .= ", '$k' => array(" . implode(',', $v) . ")"; |
|
| 816 | + $res .= ", '$k' => array(".implode(',', $v).")"; |
|
| 821 | 817 | } |
| 822 | 818 | |
| 823 | - return 'array(' . substr($res, 2) . ')'; |
|
| 819 | + return 'array('.substr($res, 2).')'; |
|
| 824 | 820 | } |
| 825 | 821 | |
| 826 | 822 | /** |
@@ -837,7 +833,7 @@ discard block |
||
| 837 | 833 | $res .= ",'$k' => '$v'"; |
| 838 | 834 | } |
| 839 | 835 | |
| 840 | - return 'array(' . substr($res, 1) . ')'; |
|
| 836 | + return 'array('.substr($res, 1).')'; |
|
| 841 | 837 | } |
| 842 | 838 | |
| 843 | 839 | /** |
@@ -855,7 +851,7 @@ discard block |
||
| 855 | 851 | $res .= ",'$k' => '$v'"; |
| 856 | 852 | } |
| 857 | 853 | |
| 858 | - return 'array(' . substr($res, 1) . ')'; |
|
| 854 | + return 'array('.substr($res, 1).')'; |
|
| 859 | 855 | } |
| 860 | 856 | |
| 861 | 857 | // http://code.spip.net/@calculer_order |
@@ -924,17 +920,17 @@ discard block |
||
| 924 | 920 | ) { |
| 925 | 921 | $res .= " .\n$tab$code"; |
| 926 | 922 | } else { |
| 927 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 923 | + $res = substr($res, 0, -1).substr($code, 1); |
|
| 928 | 924 | } |
| 929 | 925 | } |
| 930 | 926 | |
| 931 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 927 | + return '('.substr($res, 2 + $descr['niv']).')'; |
|
| 932 | 928 | } |
| 933 | 929 | } else { |
| 934 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ? $descr['niv'] : ''); |
|
| 930 | + $nom = $descr['nom'].$id_boucle.($descr['niv'] ? $descr['niv'] : ''); |
|
| 935 | 931 | |
| 936 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join(" ,\n$tab", |
|
| 937 | - $codes) . ")))"; |
|
| 932 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(".join(" ,\n$tab", |
|
| 933 | + $codes).")))"; |
|
| 938 | 934 | } |
| 939 | 935 | } |
| 940 | 936 | |
@@ -963,7 +959,7 @@ discard block |
||
| 963 | 959 | // texte seul |
| 964 | 960 | case 'texte': |
| 965 | 961 | $code = sandbox_composer_texte($p->texte, $p); |
| 966 | - $commentaire = strlen($p->texte) . " signes"; |
|
| 962 | + $commentaire = strlen($p->texte)." signes"; |
|
| 967 | 963 | $avant = ''; |
| 968 | 964 | $apres = ''; |
| 969 | 965 | $altern = "''"; |
@@ -972,14 +968,14 @@ discard block |
||
| 972 | 968 | case 'polyglotte': |
| 973 | 969 | $code = ""; |
| 974 | 970 | foreach ($p->traductions as $k => $v) { |
| 975 | - $code .= ",'" . |
|
| 976 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $k) . |
|
| 977 | - "' => '" . |
|
| 978 | - str_replace(array("\\", "'"), array("\\\\", "\\'"), $v) . |
|
| 971 | + $code .= ",'". |
|
| 972 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $k). |
|
| 973 | + "' => '". |
|
| 974 | + str_replace(array("\\", "'"), array("\\\\", "\\'"), $v). |
|
| 979 | 975 | "'"; |
| 980 | 976 | } |
| 981 | - $code = "choisir_traduction(array(" . |
|
| 982 | - substr($code, 1) . |
|
| 977 | + $code = "choisir_traduction(array(". |
|
| 978 | + substr($code, 1). |
|
| 983 | 979 | "))"; |
| 984 | 980 | $commentaire = '&'; |
| 985 | 981 | $avant = ''; |
@@ -995,7 +991,7 @@ discard block |
||
| 995 | 991 | $err_e_c = true; |
| 996 | 992 | $code = "''"; |
| 997 | 993 | } else { |
| 998 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 994 | + $commentaire = '<INCLURE '.addslashes(str_replace("\n", ' ', $code)).'>'; |
|
| 999 | 995 | $avant = ''; |
| 1000 | 996 | $apres = ''; |
| 1001 | 997 | $altern = "''"; |
@@ -1022,8 +1018,8 @@ discard block |
||
| 1022 | 1018 | $err_e_c = true; |
| 1023 | 1019 | $code = "''"; |
| 1024 | 1020 | } else { |
| 1025 | - $code = 'BOUCLE' . |
|
| 1026 | - str_replace("-", "_", $nom) . $descr['nom'] . |
|
| 1021 | + $code = 'BOUCLE'. |
|
| 1022 | + str_replace("-", "_", $nom).$descr['nom']. |
|
| 1027 | 1023 | '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
| 1028 | 1024 | $commentaire = "?$nom"; |
| 1029 | 1025 | if (!$boucles[$nom]->milieu |
@@ -1064,24 +1060,22 @@ discard block |
||
| 1064 | 1060 | foreach ($p->arg as $k => $v) { |
| 1065 | 1061 | $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
| 1066 | 1062 | if ($k) { |
| 1067 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1063 | + $l[] = _q($k).' => '.$_v; |
|
| 1068 | 1064 | } else { |
| 1069 | 1065 | $code = $_v; |
| 1070 | 1066 | } |
| 1071 | 1067 | } |
| 1072 | 1068 | // Si le module n'est pas fourni, l'expliciter sauf si calculé |
| 1073 | 1069 | if ($p->module) { |
| 1074 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1070 | + $m = $p->module.':'.$p->nom_champ; |
|
| 1075 | 1071 | } elseif ($p->nom_champ) { |
| 1076 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1072 | + $m = MODULES_IDIOMES.':'.$p->nom_champ; |
|
| 1077 | 1073 | } else { |
| 1078 | 1074 | $m = ''; |
| 1079 | 1075 | } |
| 1080 | 1076 | |
| 1081 | - $code = (!$code ? "'$m'" : |
|
| 1082 | - ($m ? "'$m' . $code" : |
|
| 1083 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1084 | - . (!$l ? '' : (", array(" . implode(",\n", $l) . ")")); |
|
| 1077 | + $code = (!$code ? "'$m'" : ($m ? "'$m' . $code" : ("(strpos(\$x=$code, ':') ? \$x : ('".MODULES_IDIOMES.":' . \$x))"))) |
|
| 1078 | + . (!$l ? '' : (", array(".implode(",\n", $l).")")); |
|
| 1085 | 1079 | $code = "_T($code)"; |
| 1086 | 1080 | if ($p->param) { |
| 1087 | 1081 | $p->id_boucle = $id_boucle; |
@@ -1104,7 +1098,7 @@ discard block |
||
| 1104 | 1098 | $p->type_requete = $type; |
| 1105 | 1099 | |
| 1106 | 1100 | $code = calculer_champ($p); |
| 1107 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1101 | + $commentaire = '#'.$p->nom_champ.$p->etoile; |
|
| 1108 | 1102 | $avant = calculer_liste($p->avant, |
| 1109 | 1103 | $descr, $boucles, $id_boucle); |
| 1110 | 1104 | $apres = calculer_liste($p->apres, |
@@ -1135,10 +1129,9 @@ discard block |
||
| 1135 | 1129 | if ($code != "''") { |
| 1136 | 1130 | $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
| 1137 | 1131 | $codes[] = (($mode == 'validation') ? |
| 1138 | - "array($code, '$commentaire', " . $p->ligne . ")" |
|
| 1132 | + "array($code, '$commentaire', ".$p->ligne.")" |
|
| 1139 | 1133 | : (($mode == 'code') ? |
| 1140 | - "\n// $commentaire\n$code" : |
|
| 1141 | - $code)); |
|
| 1134 | + "\n// $commentaire\n$code" : $code)); |
|
| 1142 | 1135 | } |
| 1143 | 1136 | } // foreach |
| 1144 | 1137 | |
@@ -1189,28 +1182,28 @@ discard block |
||
| 1189 | 1182 | if ($apres === "''") { |
| 1190 | 1183 | $apres = ''; |
| 1191 | 1184 | } |
| 1192 | - if ($avant or $apres or ($altern !== "''")){ |
|
| 1193 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)){ |
|
| 1185 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1186 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1194 | 1187 | $t = $code; |
| 1195 | 1188 | $cond = ''; |
| 1196 | 1189 | } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
| 1197 | 1190 | $t = $r[2]; |
| 1198 | - $cond = '!' . $r[1]; |
|
| 1191 | + $cond = '!'.$r[1]; |
|
| 1199 | 1192 | } else { |
| 1200 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)){ |
|
| 1193 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1201 | 1194 | $t = $r[2]; |
| 1202 | 1195 | $cond = $r[1]; |
| 1203 | 1196 | } else { |
| 1204 | - $t = '$t' . $n; |
|
| 1197 | + $t = '$t'.$n; |
|
| 1205 | 1198 | $cond = "($t = $code)!==''"; |
| 1206 | 1199 | } |
| 1207 | 1200 | } |
| 1208 | 1201 | |
| 1209 | - $res = (!$avant ? "" : "$avant . ") . |
|
| 1210 | - $t . |
|
| 1202 | + $res = (!$avant ? "" : "$avant . "). |
|
| 1203 | + $t. |
|
| 1211 | 1204 | (!$apres ? "" : " . $apres"); |
| 1212 | 1205 | |
| 1213 | - if ($res!==$t){ |
|
| 1206 | + if ($res !== $t) { |
|
| 1214 | 1207 | $res = "($res)"; |
| 1215 | 1208 | } |
| 1216 | 1209 | |
@@ -1260,12 +1253,12 @@ discard block |
||
| 1260 | 1253 | |
| 1261 | 1254 | // rendre inertes les echappements de #[](){}<> |
| 1262 | 1255 | $i = 0; |
| 1263 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1256 | + while (false !== strpos($squelette, $inerte = '-INERTE'.$i)) { |
|
| 1264 | 1257 | $i++; |
| 1265 | 1258 | } |
| 1266 | 1259 | $squelette = preg_replace_callback(',\\\\([#[()\]{}<>]),', |
| 1267 | 1260 | function($a) use ($inerte) { |
| 1268 | - return "$inerte-" . ord($a[1]) . '-'; |
|
| 1261 | + return "$inerte-".ord($a[1]).'-'; |
|
| 1269 | 1262 | }, |
| 1270 | 1263 | $squelette, |
| 1271 | 1264 | -1, |
@@ -1282,7 +1275,7 @@ discard block |
||
| 1282 | 1275 | // Phraser le squelette, selon sa grammaire |
| 1283 | 1276 | |
| 1284 | 1277 | $boucles = array(); |
| 1285 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1278 | + $f = charger_fonction('phraser_'.$gram, 'public'); |
|
| 1286 | 1279 | |
| 1287 | 1280 | $squelette = $f($squelette, '', $boucles, $descr); |
| 1288 | 1281 | |
@@ -1301,7 +1294,7 @@ discard block |
||
| 1301 | 1294 | $boucles[$i]->descr['squelette'] = preg_replace_callback( |
| 1302 | 1295 | ",$inerte-(\d+)-,", |
| 1303 | 1296 | function($a) { |
| 1304 | - return "\\\\" . chr($a[1]); |
|
| 1297 | + return "\\\\".chr($a[1]); |
|
| 1305 | 1298 | }, |
| 1306 | 1299 | $boucle->descr['squelette'] |
| 1307 | 1300 | ); |
@@ -1313,19 +1306,19 @@ discard block |
||
| 1313 | 1306 | include_spip('public/decompiler'); |
| 1314 | 1307 | foreach ($boucles as $id => $boucle) { |
| 1315 | 1308 | if ($id) { |
| 1316 | - $decomp = "\n/* BOUCLE " . |
|
| 1317 | - $boucle->type_requete . |
|
| 1318 | - " " . |
|
| 1319 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1320 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1309 | + $decomp = "\n/* BOUCLE ". |
|
| 1310 | + $boucle->type_requete. |
|
| 1311 | + " ". |
|
| 1312 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')). |
|
| 1313 | + ($boucle->debug ? "\n *\n * ".implode("\n * ", $boucle->debug)."\n" : ''). |
|
| 1321 | 1314 | " */\n"; |
| 1322 | 1315 | } else { |
| 1323 | - $decomp = ("\n/*\n" . |
|
| 1316 | + $decomp = ("\n/*\n". |
|
| 1324 | 1317 | str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
| 1325 | 1318 | . "\n*/"); |
| 1326 | 1319 | } |
| 1327 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1328 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1320 | + $boucles[$id]->return = $decomp.$boucle->return; |
|
| 1321 | + $GLOBALS['debug_objets']['code'][$nom.$id] = $boucle->return; |
|
| 1329 | 1322 | } |
| 1330 | 1323 | } |
| 1331 | 1324 | |
@@ -1348,7 +1341,7 @@ discard block |
||
| 1348 | 1341 | } |
| 1349 | 1342 | } |
| 1350 | 1343 | foreach ($boucles as $id => $boucle) { |
| 1351 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1344 | + $GLOBALS['debug_objets']['boucle'][$nom.$id] = $boucle; |
|
| 1352 | 1345 | } |
| 1353 | 1346 | $descr['documents'] = compile_inclure_doublons($squelette); |
| 1354 | 1347 | |
@@ -1432,8 +1425,7 @@ discard block |
||
| 1432 | 1425 | } else { |
| 1433 | 1426 | $boucles[$id]->type_requete = false; |
| 1434 | 1427 | $boucle = $boucles[$id]; |
| 1435 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1436 | - ($boucle->sql_serveur . ":")) . |
|
| 1428 | + $x = (!$boucle->sql_serveur ? '' : ($boucle->sql_serveur.":")). |
|
| 1437 | 1429 | $type; |
| 1438 | 1430 | $msg = array( |
| 1439 | 1431 | 'zbug_table_inconnue', |
@@ -1519,13 +1511,13 @@ discard block |
||
| 1519 | 1511 | if ( |
| 1520 | 1512 | // fonction de boucle avec serveur & table |
| 1521 | 1513 | (!$serveur or |
| 1522 | - ((!function_exists($f = "boucle_" . $serveur . "_" . $table)) |
|
| 1523 | - and (!function_exists($f = $f . "_dist")) |
|
| 1514 | + ((!function_exists($f = "boucle_".$serveur."_".$table)) |
|
| 1515 | + and (!function_exists($f = $f."_dist")) |
|
| 1524 | 1516 | ) |
| 1525 | 1517 | ) |
| 1526 | 1518 | // fonction de boucle avec table |
| 1527 | - and (!function_exists($f = "boucle_" . $table)) |
|
| 1528 | - and (!function_exists($f = $f . "_dist")) |
|
| 1519 | + and (!function_exists($f = "boucle_".$table)) |
|
| 1520 | + and (!function_exists($f = $f."_dist")) |
|
| 1529 | 1521 | ) { |
| 1530 | 1522 | // fonction de boucle standard |
| 1531 | 1523 | if (!function_exists($f = 'boucle_DEFAUT')) { |
@@ -1533,20 +1525,20 @@ discard block |
||
| 1533 | 1525 | } |
| 1534 | 1526 | } |
| 1535 | 1527 | |
| 1536 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1537 | - "static \$connect;\n\t" . |
|
| 1538 | - "\$command['connect'] = \$connect = " . |
|
| 1539 | - _q($boucle->sql_serveur) . |
|
| 1540 | - ";" . |
|
| 1528 | + $req = "\n\n\tstatic \$command = array();\n\t". |
|
| 1529 | + "static \$connect;\n\t". |
|
| 1530 | + "\$command['connect'] = \$connect = ". |
|
| 1531 | + _q($boucle->sql_serveur). |
|
| 1532 | + ";". |
|
| 1541 | 1533 | $f($id, $boucles); |
| 1542 | 1534 | } else { |
| 1543 | 1535 | $req = ("\n\treturn '';"); |
| 1544 | 1536 | } |
| 1545 | 1537 | |
| 1546 | 1538 | $boucles[$id]->return = |
| 1547 | - "\n\nfunction BOUCLE" . strtr($id, "-", "_") . $nom . |
|
| 1548 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1549 | - $req . |
|
| 1539 | + "\n\nfunction BOUCLE".strtr($id, "-", "_").$nom. |
|
| 1540 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {'. |
|
| 1541 | + $req. |
|
| 1550 | 1542 | "\n}\n"; |
| 1551 | 1543 | } |
| 1552 | 1544 | |
@@ -1556,7 +1548,7 @@ discard block |
||
| 1556 | 1548 | return false; |
| 1557 | 1549 | } |
| 1558 | 1550 | |
| 1559 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1551 | + $principal = "\nfunction ".$nom.'($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1560 | 1552 | ' |
| 1561 | 1553 | // reporter de maniere securisee les doublons inclus |
| 1562 | 1554 | . ' |
@@ -1564,15 +1556,15 @@ discard block |
||
| 1564 | 1556 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1565 | 1557 | |
| 1566 | 1558 | $connect = ' . |
| 1567 | - _q($connect) . '; |
|
| 1559 | + _q($connect).'; |
|
| 1568 | 1560 | $page = ' . |
| 1569 | 1561 | // ATTENTION, le calcul de l'expression $corps affectera $Cache |
| 1570 | 1562 | // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
| 1571 | 1563 | // avant de referencer $Cache |
| 1572 | - $corps . "; |
|
| 1564 | + $corps."; |
|
| 1573 | 1565 | |
| 1574 | 1566 | return analyse_resultat_skel(" . var_export($nom, true) |
| 1575 | - . ", \$Cache, \$page, " . var_export($sourcefile, true) . "); |
|
| 1567 | + . ", \$Cache, \$page, ".var_export($sourcefile, true)."); |
|
| 1576 | 1568 | }"; |
| 1577 | 1569 | |
| 1578 | 1570 | $secondes = spip_timer('calcul_skel'); |
@@ -1586,10 +1578,10 @@ discard block |
||
| 1586 | 1578 | $code->return = ' |
| 1587 | 1579 | // |
| 1588 | 1580 | // Fonction principale du squelette ' . |
| 1589 | - $sourcefile . |
|
| 1590 | - ($connect ? " pour $connect" : '') . |
|
| 1591 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1592 | - "\n//\n" . |
|
| 1581 | + $sourcefile. |
|
| 1582 | + ($connect ? " pour $connect" : ''). |
|
| 1583 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes"). |
|
| 1584 | + "\n//\n". |
|
| 1593 | 1585 | $principal; |
| 1594 | 1586 | |
| 1595 | 1587 | $boucles[''] = $code; |
@@ -1641,7 +1633,7 @@ discard block |
||
| 1641 | 1633 | **/ |
| 1642 | 1634 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1643 | 1635 | include_spip('iterateur/data'); |
| 1644 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1636 | + if ($h = charger_fonction($boucle->type_requete.'_to_array', 'inc', true)) { |
|
| 1645 | 1637 | $g = charger_fonction('data', 'iterateur'); |
| 1646 | 1638 | $boucles[$id] = $g($boucle); |
| 1647 | 1639 | // from[0] stocke le type de data (rss, yql, ...) |
@@ -102,6 +102,10 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // http://code.spip.net/@phraser_polyglotte |
| 105 | +/** |
|
| 106 | + * @param string $texte |
|
| 107 | + * @param integer $ligne |
|
| 108 | + */ |
|
| 105 | 109 | function phraser_polyglotte($texte, $ligne, $result) { |
| 106 | 110 | |
| 107 | 111 | if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
@@ -264,6 +268,9 @@ discard block |
||
| 264 | 268 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 265 | 269 | |
| 266 | 270 | // http://code.spip.net/@phraser_champs_etendus |
| 271 | +/** |
|
| 272 | + * @param integer $ligne |
|
| 273 | + */ |
|
| 267 | 274 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 268 | 275 | if ($texte === "") { |
| 269 | 276 | return $result; |
@@ -286,7 +293,7 @@ discard block |
||
| 286 | 293 | * http://code.spip.net/@phraser_args |
| 287 | 294 | * |
| 288 | 295 | * @param $texte |
| 289 | - * @param $fin |
|
| 296 | + * @param string $fin |
|
| 290 | 297 | * @param $sep |
| 291 | 298 | * @param $result |
| 292 | 299 | * @param $pointeur_champ |
@@ -306,6 +313,9 @@ discard block |
||
| 306 | 313 | } |
| 307 | 314 | |
| 308 | 315 | // http://code.spip.net/@phraser_arg |
| 316 | +/** |
|
| 317 | + * @param string $texte |
|
| 318 | + */ |
|
| 309 | 319 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 310 | 320 | preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
| 311 | 321 | $suite = ltrim($match[2]); |
@@ -443,6 +453,9 @@ discard block |
||
| 443 | 453 | |
| 444 | 454 | |
| 445 | 455 | // http://code.spip.net/@phraser_champs_exterieurs |
| 456 | +/** |
|
| 457 | + * @param string $texte |
|
| 458 | + */ |
|
| 446 | 459 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 447 | 460 | $res = array(); |
| 448 | 461 | while (($p = strpos($texte, "%$sep")) !== false) { |
@@ -462,6 +475,9 @@ discard block |
||
| 462 | 475 | } |
| 463 | 476 | |
| 464 | 477 | // http://code.spip.net/@phraser_champs_interieurs |
| 478 | +/** |
|
| 479 | + * @param string $sep |
|
| 480 | + */ |
|
| 465 | 481 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 466 | 482 | $i = 0; // en fait count($result) |
| 467 | 483 | $x = ""; |
@@ -755,6 +771,10 @@ discard block |
||
| 755 | 771 | } |
| 756 | 772 | |
| 757 | 773 | // http://code.spip.net/@phraser_critere_infixe |
| 774 | +/** |
|
| 775 | + * @param string $arg1 |
|
| 776 | + * @param string $arg2 |
|
| 777 | + */ |
|
| 758 | 778 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 759 | 779 | $args[0] = new Texte; |
| 760 | 780 | $args[0]->texte = $arg1; |
@@ -795,7 +815,7 @@ discard block |
||
| 795 | 815 | * @param $texte |
| 796 | 816 | * @param $id_parent |
| 797 | 817 | * @param $descr |
| 798 | - * @return array|null |
|
| 818 | + * @return string |
|
| 799 | 819 | */ |
| 800 | 820 | function public_trouver_premiere_boucle($texte, $id_parent, $descr) { |
| 801 | 821 | $premiere_boucle = null; |
@@ -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 */ |
@@ -65,83 +65,83 @@ discard block |
||
| 65 | 65 | // http://code.spip.net/@phraser_inclure |
| 66 | 66 | function phraser_inclure($texte, $ligne, $result) { |
| 67 | 67 | |
| 68 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | - $match = array_pad($match, 3, null); |
|
| 70 | - $p = strpos($texte, $match[0]); |
|
| 71 | - $debut = substr($texte, 0, $p); |
|
| 72 | - if ($p) { |
|
| 73 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | - } |
|
| 75 | - $ligne += substr_count($debut, "\n"); |
|
| 76 | - $champ = new Inclure; |
|
| 77 | - $champ->ligne = $ligne; |
|
| 78 | - $ligne += substr_count($match[0], "\n"); |
|
| 79 | - $fichier = $match[2]; |
|
| 80 | - # assurer ici la migration .php3 => .php |
|
| 81 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | - $fichier = $r[1]; |
|
| 84 | - } |
|
| 85 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | - phraser_args($texte, "/>", "", $result, $champ); |
|
| 89 | - if (!$champ->texte or count($champ->param) > 1) { |
|
| 90 | - if (!function_exists('normaliser_inclure')) { |
|
| 91 | - include_spip('public/normaliser'); |
|
| 92 | - } |
|
| 93 | - normaliser_inclure($champ); |
|
| 94 | - } |
|
| 95 | - $texte = substr($champ->apres, strpos($champ->apres, '>') + 1); |
|
| 96 | - $champ->apres = ""; |
|
| 97 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | - $result[] = $champ; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return (($texte === "") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 68 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 69 | + $match = array_pad($match, 3, null); |
|
| 70 | + $p = strpos($texte, $match[0]); |
|
| 71 | + $debut = substr($texte, 0, $p); |
|
| 72 | + if ($p) { |
|
| 73 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 74 | + } |
|
| 75 | + $ligne += substr_count($debut, "\n"); |
|
| 76 | + $champ = new Inclure; |
|
| 77 | + $champ->ligne = $ligne; |
|
| 78 | + $ligne += substr_count($match[0], "\n"); |
|
| 79 | + $fichier = $match[2]; |
|
| 80 | + # assurer ici la migration .php3 => .php |
|
| 81 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 82 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 83 | + $fichier = $r[1]; |
|
| 84 | + } |
|
| 85 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 86 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 87 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 88 | + phraser_args($texte, "/>", "", $result, $champ); |
|
| 89 | + if (!$champ->texte or count($champ->param) > 1) { |
|
| 90 | + if (!function_exists('normaliser_inclure')) { |
|
| 91 | + include_spip('public/normaliser'); |
|
| 92 | + } |
|
| 93 | + normaliser_inclure($champ); |
|
| 94 | + } |
|
| 95 | + $texte = substr($champ->apres, strpos($champ->apres, '>') + 1); |
|
| 96 | + $champ->apres = ""; |
|
| 97 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 98 | + $result[] = $champ; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return (($texte === "") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // http://code.spip.net/@phraser_polyglotte |
| 105 | 105 | function phraser_polyglotte($texte, $ligne, $result) { |
| 106 | 106 | |
| 107 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | - foreach ($m as $match) { |
|
| 109 | - $p = strpos($texte, $match[0]); |
|
| 110 | - $debut = substr($texte, 0, $p); |
|
| 111 | - if ($p) { |
|
| 112 | - $champ = new Texte; |
|
| 113 | - $champ->texte = $debut; |
|
| 114 | - $champ->ligne = $ligne; |
|
| 115 | - $result[] = $champ; |
|
| 116 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $champ = new Polyglotte; |
|
| 120 | - $champ->ligne = $ligne; |
|
| 121 | - $ligne += substr_count($match[0], "\n"); |
|
| 122 | - $lang = ''; |
|
| 123 | - $bloc = $match[1]; |
|
| 124 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | - while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)) { |
|
| 126 | - $trad = $regs[1]; |
|
| 127 | - if ($trad or $lang) { |
|
| 128 | - $champ->traductions[$lang] = $trad; |
|
| 129 | - } |
|
| 130 | - $lang = $regs[2]; |
|
| 131 | - $bloc = $regs[3]; |
|
| 132 | - } |
|
| 133 | - $champ->traductions[$lang] = $bloc; |
|
| 134 | - $result[] = $champ; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - if ($texte !== "") { |
|
| 138 | - $champ = new Texte; |
|
| 139 | - $champ->texte = $texte; |
|
| 140 | - $champ->ligne = $ligne; |
|
| 141 | - $result[] = $champ; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $result; |
|
| 107 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 108 | + foreach ($m as $match) { |
|
| 109 | + $p = strpos($texte, $match[0]); |
|
| 110 | + $debut = substr($texte, 0, $p); |
|
| 111 | + if ($p) { |
|
| 112 | + $champ = new Texte; |
|
| 113 | + $champ->texte = $debut; |
|
| 114 | + $champ->ligne = $ligne; |
|
| 115 | + $result[] = $champ; |
|
| 116 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $champ = new Polyglotte; |
|
| 120 | + $champ->ligne = $ligne; |
|
| 121 | + $ligne += substr_count($match[0], "\n"); |
|
| 122 | + $lang = ''; |
|
| 123 | + $bloc = $match[1]; |
|
| 124 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 125 | + while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)) { |
|
| 126 | + $trad = $regs[1]; |
|
| 127 | + if ($trad or $lang) { |
|
| 128 | + $champ->traductions[$lang] = $trad; |
|
| 129 | + } |
|
| 130 | + $lang = $regs[2]; |
|
| 131 | + $bloc = $regs[3]; |
|
| 132 | + } |
|
| 133 | + $champ->traductions[$lang] = $bloc; |
|
| 134 | + $result[] = $champ; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + if ($texte !== "") { |
|
| 138 | + $champ = new Texte; |
|
| 139 | + $champ->texte = $texte; |
|
| 140 | + $champ->ligne = $ligne; |
|
| 141 | + $result[] = $champ; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $result; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -163,41 +163,41 @@ discard block |
||
| 163 | 163 | * @return array |
| 164 | 164 | **/ |
| 165 | 165 | function phraser_idiomes($texte, $ligne, $result) { |
| 166 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | - $match = array_pad($match, 8, null); |
|
| 168 | - $p = strpos($texte, $match[0]); |
|
| 169 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | - if ($debut) { |
|
| 172 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | - } |
|
| 174 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | - $ligne += substr_count($debut, "\n"); |
|
| 176 | - if ($ko) { |
|
| 177 | - continue; |
|
| 178 | - } // faux idiome |
|
| 179 | - $champ = new Idiome; |
|
| 180 | - $champ->ligne = $ligne; |
|
| 181 | - $ligne += substr_count($match[0], "\n"); |
|
| 182 | - // Stocker les arguments de la balise de traduction |
|
| 183 | - $args = array(); |
|
| 184 | - $largs = $match[5]; |
|
| 185 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | - $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 187 | - $largs = substr($largs, strlen($r[0])); |
|
| 188 | - } |
|
| 189 | - $champ->arg = $args; |
|
| 190 | - $champ->nom_champ = strtolower($match[3]); |
|
| 191 | - $champ->module = $match[2]; |
|
| 192 | - // pas d'imbrication pour les filtres sur langue |
|
| 193 | - phraser_args($match[7], ":", '', array(), $champ); |
|
| 194 | - $result[] = $champ; |
|
| 195 | - } |
|
| 196 | - if ($texte !== "") { |
|
| 197 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $result; |
|
| 166 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 167 | + $match = array_pad($match, 8, null); |
|
| 168 | + $p = strpos($texte, $match[0]); |
|
| 169 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 170 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 171 | + if ($debut) { |
|
| 172 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 173 | + } |
|
| 174 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 175 | + $ligne += substr_count($debut, "\n"); |
|
| 176 | + if ($ko) { |
|
| 177 | + continue; |
|
| 178 | + } // faux idiome |
|
| 179 | + $champ = new Idiome; |
|
| 180 | + $champ->ligne = $ligne; |
|
| 181 | + $ligne += substr_count($match[0], "\n"); |
|
| 182 | + // Stocker les arguments de la balise de traduction |
|
| 183 | + $args = array(); |
|
| 184 | + $largs = $match[5]; |
|
| 185 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | + $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 187 | + $largs = substr($largs, strlen($r[0])); |
|
| 188 | + } |
|
| 189 | + $champ->arg = $args; |
|
| 190 | + $champ->nom_champ = strtolower($match[3]); |
|
| 191 | + $champ->module = $match[2]; |
|
| 192 | + // pas d'imbrication pour les filtres sur langue |
|
| 193 | + phraser_args($match[7], ":", '', array(), $champ); |
|
| 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, $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, '', array(), $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, $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, '', array(), $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: |
@@ -265,15 +265,15 @@ discard block |
||
| 265 | 265 | |
| 266 | 266 | // http://code.spip.net/@phraser_champs_etendus |
| 267 | 267 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 268 | - if ($texte === "") { |
|
| 269 | - return $result; |
|
| 270 | - } |
|
| 271 | - $sep = '##'; |
|
| 272 | - while (strpos($texte, $sep) !== false) { |
|
| 273 | - $sep .= '#'; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 268 | + if ($texte === "") { |
|
| 269 | + return $result; |
|
| 270 | + } |
|
| 271 | + $sep = '##'; |
|
| 272 | + while (strpos($texte, $sep) !== false) { |
|
| 273 | + $sep .= '#'; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -293,270 +293,270 @@ discard block |
||
| 293 | 293 | * @return array |
| 294 | 294 | */ |
| 295 | 295 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ) { |
| 296 | - $texte = ltrim($texte); |
|
| 297 | - while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
|
| 298 | - $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 299 | - $texte = ltrim($texte); |
|
| 300 | - } |
|
| 296 | + $texte = ltrim($texte); |
|
| 297 | + while (($texte !== "") && strpos($fin, $texte[0]) === false) { |
|
| 298 | + $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 299 | + $texte = ltrim($texte); |
|
| 300 | + } |
|
| 301 | 301 | # mettre ici la suite du texte, |
| 302 | 302 | # notamment pour que l'appelant vire le caractere fermant si besoin |
| 303 | - $pointeur_champ->apres = $texte; |
|
| 303 | + $pointeur_champ->apres = $texte; |
|
| 304 | 304 | |
| 305 | - return $result; |
|
| 305 | + return $result; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | // http://code.spip.net/@phraser_arg |
| 309 | 309 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 310 | - preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 311 | - $suite = ltrim($match[2]); |
|
| 312 | - $fonc = trim($match[1]); |
|
| 313 | - if ($fonc && $fonc[0] == "|") { |
|
| 314 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 315 | - } |
|
| 316 | - $res = array($fonc); |
|
| 317 | - $err_f = ''; |
|
| 318 | - // cas du filtre sans argument ou du critere / |
|
| 319 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 320 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 321 | - if (!$match[1]) { |
|
| 322 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 323 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 324 | - $texte = ''; |
|
| 325 | - } else { |
|
| 326 | - $texte = $suite; |
|
| 327 | - } |
|
| 328 | - if ($err_f) { |
|
| 329 | - $pointeur_champ->param = false; |
|
| 330 | - } elseif ($fonc !== '') { |
|
| 331 | - $pointeur_champ->param[] = $res; |
|
| 332 | - } |
|
| 333 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 334 | - $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 335 | - |
|
| 336 | - return $result; |
|
| 337 | - } |
|
| 338 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 339 | - $collecte = array(); |
|
| 340 | - while ($args && $args[0] != '}') { |
|
| 341 | - if ($args[0] == '"') { |
|
| 342 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 343 | - } elseif ($args[0] == "'") { |
|
| 344 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 345 | - } else { |
|
| 346 | - preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 347 | - if (!strlen($regs[2])) { |
|
| 348 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 349 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 350 | - $champ = new Texte; |
|
| 351 | - $champ->apres = $champ->avant = $args = ""; |
|
| 352 | - break; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - $arg = $regs[2]; |
|
| 356 | - if (trim($regs[1])) { |
|
| 357 | - $champ = new Texte; |
|
| 358 | - $champ->texte = $arg; |
|
| 359 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 360 | - $result[] = $champ; |
|
| 361 | - $collecte[] = $champ; |
|
| 362 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 363 | - } else { |
|
| 364 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 365 | - // 0 est un aveu d'impuissance. A completer |
|
| 366 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 367 | - |
|
| 368 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 369 | - $collecte = array_merge($collecte, $arg); |
|
| 370 | - $result = array_merge($result, $arg); |
|
| 371 | - } else { |
|
| 372 | - $n = strpos($args, $r[0]); |
|
| 373 | - $pred = substr($args, 0, $n); |
|
| 374 | - $par = ',}'; |
|
| 375 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 376 | - $pred = $m[1]; |
|
| 377 | - $par = ')'; |
|
| 378 | - } |
|
| 379 | - if ($pred) { |
|
| 380 | - $champ = new Texte; |
|
| 381 | - $champ->texte = $pred; |
|
| 382 | - $champ->apres = $champ->avant = ""; |
|
| 383 | - $result[] = $champ; |
|
| 384 | - $collecte[] = $champ; |
|
| 385 | - } |
|
| 386 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 387 | - $champ = new Champ; |
|
| 388 | - $champ->nom_boucle = $r[2]; |
|
| 389 | - $champ->nom_champ = $r[3]; |
|
| 390 | - $champ->etoile = $r[5]; |
|
| 391 | - $next = $r[6]; |
|
| 392 | - while ($next == '{') { |
|
| 393 | - phraser_arg($rec, $sep, array(), $champ); |
|
| 394 | - $args = ltrim($rec); |
|
| 395 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 396 | - } |
|
| 397 | - while ($next == '|') { |
|
| 398 | - phraser_args($rec, $par, $sep, array(), $champ); |
|
| 399 | - $args = $champ->apres; |
|
| 400 | - $champ->apres = ''; |
|
| 401 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 402 | - } |
|
| 403 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 404 | - if ($champ->param === false) { |
|
| 405 | - $err_f = true; |
|
| 406 | - } else { |
|
| 407 | - phraser_vieux($champ); |
|
| 408 | - } |
|
| 409 | - if ($par == ')') { |
|
| 410 | - $args = substr($args, 1); |
|
| 411 | - } |
|
| 412 | - $collecte[] = $champ; |
|
| 413 | - $result[] = $champ; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 417 | - $args = ltrim(substr($args, 1)); |
|
| 418 | - if ($collecte) { |
|
| 419 | - $res[] = $collecte; |
|
| 420 | - $collecte = array(); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - if ($collecte) { |
|
| 425 | - $res[] = $collecte; |
|
| 426 | - $collecte = array(); |
|
| 427 | - } |
|
| 428 | - $texte = substr($args, 1); |
|
| 429 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 430 | - // propager les erreurs, et ignorer les param vides |
|
| 431 | - if ($pointeur_champ->param !== false) { |
|
| 432 | - if ($err_f) { |
|
| 433 | - $pointeur_champ->param = false; |
|
| 434 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 435 | - $pointeur_champ->param[] = $res; |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 439 | - $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 440 | - |
|
| 441 | - return $result; |
|
| 310 | + preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 311 | + $suite = ltrim($match[2]); |
|
| 312 | + $fonc = trim($match[1]); |
|
| 313 | + if ($fonc && $fonc[0] == "|") { |
|
| 314 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 315 | + } |
|
| 316 | + $res = array($fonc); |
|
| 317 | + $err_f = ''; |
|
| 318 | + // cas du filtre sans argument ou du critere / |
|
| 319 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 320 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 321 | + if (!$match[1]) { |
|
| 322 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 323 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 324 | + $texte = ''; |
|
| 325 | + } else { |
|
| 326 | + $texte = $suite; |
|
| 327 | + } |
|
| 328 | + if ($err_f) { |
|
| 329 | + $pointeur_champ->param = false; |
|
| 330 | + } elseif ($fonc !== '') { |
|
| 331 | + $pointeur_champ->param[] = $res; |
|
| 332 | + } |
|
| 333 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 334 | + $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 335 | + |
|
| 336 | + return $result; |
|
| 337 | + } |
|
| 338 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 339 | + $collecte = array(); |
|
| 340 | + while ($args && $args[0] != '}') { |
|
| 341 | + if ($args[0] == '"') { |
|
| 342 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 343 | + } elseif ($args[0] == "'") { |
|
| 344 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 345 | + } else { |
|
| 346 | + preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 347 | + if (!strlen($regs[2])) { |
|
| 348 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 349 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 350 | + $champ = new Texte; |
|
| 351 | + $champ->apres = $champ->avant = $args = ""; |
|
| 352 | + break; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + $arg = $regs[2]; |
|
| 356 | + if (trim($regs[1])) { |
|
| 357 | + $champ = new Texte; |
|
| 358 | + $champ->texte = $arg; |
|
| 359 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 360 | + $result[] = $champ; |
|
| 361 | + $collecte[] = $champ; |
|
| 362 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 363 | + } else { |
|
| 364 | + if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 365 | + // 0 est un aveu d'impuissance. A completer |
|
| 366 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 367 | + |
|
| 368 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 369 | + $collecte = array_merge($collecte, $arg); |
|
| 370 | + $result = array_merge($result, $arg); |
|
| 371 | + } else { |
|
| 372 | + $n = strpos($args, $r[0]); |
|
| 373 | + $pred = substr($args, 0, $n); |
|
| 374 | + $par = ',}'; |
|
| 375 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 376 | + $pred = $m[1]; |
|
| 377 | + $par = ')'; |
|
| 378 | + } |
|
| 379 | + if ($pred) { |
|
| 380 | + $champ = new Texte; |
|
| 381 | + $champ->texte = $pred; |
|
| 382 | + $champ->apres = $champ->avant = ""; |
|
| 383 | + $result[] = $champ; |
|
| 384 | + $collecte[] = $champ; |
|
| 385 | + } |
|
| 386 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 387 | + $champ = new Champ; |
|
| 388 | + $champ->nom_boucle = $r[2]; |
|
| 389 | + $champ->nom_champ = $r[3]; |
|
| 390 | + $champ->etoile = $r[5]; |
|
| 391 | + $next = $r[6]; |
|
| 392 | + while ($next == '{') { |
|
| 393 | + phraser_arg($rec, $sep, array(), $champ); |
|
| 394 | + $args = ltrim($rec); |
|
| 395 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 396 | + } |
|
| 397 | + while ($next == '|') { |
|
| 398 | + phraser_args($rec, $par, $sep, array(), $champ); |
|
| 399 | + $args = $champ->apres; |
|
| 400 | + $champ->apres = ''; |
|
| 401 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 402 | + } |
|
| 403 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 404 | + if ($champ->param === false) { |
|
| 405 | + $err_f = true; |
|
| 406 | + } else { |
|
| 407 | + phraser_vieux($champ); |
|
| 408 | + } |
|
| 409 | + if ($par == ')') { |
|
| 410 | + $args = substr($args, 1); |
|
| 411 | + } |
|
| 412 | + $collecte[] = $champ; |
|
| 413 | + $result[] = $champ; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 417 | + $args = ltrim(substr($args, 1)); |
|
| 418 | + if ($collecte) { |
|
| 419 | + $res[] = $collecte; |
|
| 420 | + $collecte = array(); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + if ($collecte) { |
|
| 425 | + $res[] = $collecte; |
|
| 426 | + $collecte = array(); |
|
| 427 | + } |
|
| 428 | + $texte = substr($args, 1); |
|
| 429 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 430 | + // propager les erreurs, et ignorer les param vides |
|
| 431 | + if ($pointeur_champ->param !== false) { |
|
| 432 | + if ($err_f) { |
|
| 433 | + $pointeur_champ->param = false; |
|
| 434 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 435 | + $pointeur_champ->param[] = $res; |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 439 | + $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 440 | + |
|
| 441 | + return $result; |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | |
| 445 | 445 | // http://code.spip.net/@phraser_champs_exterieurs |
| 446 | 446 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 447 | - $res = array(); |
|
| 448 | - while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 449 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | - break; |
|
| 451 | - } |
|
| 452 | - $debut = substr($texte, 0, $p); |
|
| 453 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 454 | - if ($p) { |
|
| 455 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 456 | - } |
|
| 457 | - $ligne += substr_count($debut, "\n"); |
|
| 458 | - $res[] = $nested[$m[1]]; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 447 | + $res = array(); |
|
| 448 | + while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 449 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | + break; |
|
| 451 | + } |
|
| 452 | + $debut = substr($texte, 0, $p); |
|
| 453 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 454 | + if ($p) { |
|
| 455 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 456 | + } |
|
| 457 | + $ligne += substr_count($debut, "\n"); |
|
| 458 | + $res[] = $nested[$m[1]]; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // http://code.spip.net/@phraser_champs_interieurs |
| 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, $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 | - $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 488 | - phraser_vieux($champ); |
|
| 489 | - $champ->avant = |
|
| 490 | - phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | - $debut = substr($champ->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 | - $result[$i] = $champ; |
|
| 498 | - $i++; |
|
| 499 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 500 | - } |
|
| 501 | - if ($texte !== "") { |
|
| 502 | - $result[$i] = $texte; |
|
| 503 | - $i++; |
|
| 504 | - } |
|
| 505 | - $x = ''; |
|
| 506 | - |
|
| 507 | - while ($j < $i) { |
|
| 508 | - $z = $result[$j]; |
|
| 509 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 510 | - if (is_object($z)) { |
|
| 511 | - $x .= "%$sep$j@"; |
|
| 512 | - } else { |
|
| 513 | - $x .= $z; |
|
| 514 | - } |
|
| 515 | - $j++; |
|
| 516 | - } |
|
| 517 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 518 | - $texte = $x; |
|
| 519 | - } else { |
|
| 520 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 521 | - } |
|
| 522 | - } |
|
| 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, $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 | + $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 488 | + phraser_vieux($champ); |
|
| 489 | + $champ->avant = |
|
| 490 | + phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | + $debut = substr($champ->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 | + $result[$i] = $champ; |
|
| 498 | + $i++; |
|
| 499 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 500 | + } |
|
| 501 | + if ($texte !== "") { |
|
| 502 | + $result[$i] = $texte; |
|
| 503 | + $i++; |
|
| 504 | + } |
|
| 505 | + $x = ''; |
|
| 506 | + |
|
| 507 | + while ($j < $i) { |
|
| 508 | + $z = $result[$j]; |
|
| 509 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 510 | + if (is_object($z)) { |
|
| 511 | + $x .= "%$sep$j@"; |
|
| 512 | + } else { |
|
| 513 | + $x .= $z; |
|
| 514 | + } |
|
| 515 | + $j++; |
|
| 516 | + } |
|
| 517 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 518 | + $texte = $x; |
|
| 519 | + } else { |
|
| 520 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | function phraser_vieux(&$champ) { |
| 526 | - $nom = $champ->nom_champ; |
|
| 527 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 528 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 529 | - include_spip('public/normaliser'); |
|
| 530 | - } |
|
| 531 | - phraser_vieux_emb($champ); |
|
| 532 | - } elseif ($nom == 'EXPOSER') { |
|
| 533 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 534 | - include_spip('public/normaliser'); |
|
| 535 | - } |
|
| 536 | - phraser_vieux_exposer($champ); |
|
| 537 | - } elseif ($champ->param) { |
|
| 538 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 539 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_recherche($champ); |
|
| 543 | - } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 544 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_logos($champ); |
|
| 548 | - } elseif ($nom == 'MODELE') { |
|
| 549 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 550 | - include_spip('public/normaliser'); |
|
| 551 | - } |
|
| 552 | - phraser_vieux_modele($champ); |
|
| 553 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 554 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 555 | - include_spip('public/normaliser'); |
|
| 556 | - } |
|
| 557 | - phraser_vieux_inclu($champ); |
|
| 558 | - } |
|
| 559 | - } |
|
| 526 | + $nom = $champ->nom_champ; |
|
| 527 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 528 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 529 | + include_spip('public/normaliser'); |
|
| 530 | + } |
|
| 531 | + phraser_vieux_emb($champ); |
|
| 532 | + } elseif ($nom == 'EXPOSER') { |
|
| 533 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 534 | + include_spip('public/normaliser'); |
|
| 535 | + } |
|
| 536 | + phraser_vieux_exposer($champ); |
|
| 537 | + } elseif ($champ->param) { |
|
| 538 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 539 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_recherche($champ); |
|
| 543 | + } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 544 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_logos($champ); |
|
| 548 | + } elseif ($nom == 'MODELE') { |
|
| 549 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 550 | + include_spip('public/normaliser'); |
|
| 551 | + } |
|
| 552 | + phraser_vieux_modele($champ); |
|
| 553 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 554 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 555 | + include_spip('public/normaliser'); |
|
| 556 | + } |
|
| 557 | + phraser_vieux_inclu($champ); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | |
@@ -584,190 +584,190 @@ discard block |
||
| 584 | 584 | **/ |
| 585 | 585 | function phraser_criteres($params, &$result) { |
| 586 | 586 | |
| 587 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 588 | - $args = array(); |
|
| 589 | - $type = $result->type_requete; |
|
| 590 | - $doublons = array(); |
|
| 591 | - foreach ($params as $v) { |
|
| 592 | - $var = $v[1][0]; |
|
| 593 | - $param = ($var->type != 'texte') ? "" : $var->texte; |
|
| 594 | - if ((count($v) > 2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))) { |
|
| 595 | - // plus d'un argument et pas le critere IN: |
|
| 596 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 597 | - if ($var->type != 'texte' |
|
| 598 | - or preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 599 | - ) { |
|
| 600 | - $op = ','; |
|
| 601 | - $not = ""; |
|
| 602 | - $cond = false; |
|
| 603 | - } else { |
|
| 604 | - // Le debut du premier argument est l'operateur |
|
| 605 | - preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 606 | - $op = $m[2]; |
|
| 607 | - $not = $m[1]; |
|
| 608 | - $cond = $m[3]; |
|
| 609 | - // virer le premier argument, |
|
| 610 | - // et mettre son reliquat eventuel |
|
| 611 | - // Recopier pour ne pas alterer le texte source |
|
| 612 | - // utile au debusqueur |
|
| 613 | - if ($m[4]) { |
|
| 614 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 615 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 616 | - $c = null; |
|
| 617 | - eval('$c = ' . $m[4] . ';'); |
|
| 618 | - if (isset($c)) { |
|
| 619 | - $m[4] = $c; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - $texte = new Texte; |
|
| 623 | - $texte->texte = $m[4]; |
|
| 624 | - $v[1][0] = $texte; |
|
| 625 | - } else { |
|
| 626 | - array_shift($v[1]); |
|
| 627 | - } |
|
| 628 | - } |
|
| 629 | - array_shift($v); // $v[O] est vide |
|
| 630 | - $crit = new Critere; |
|
| 631 | - $crit->op = $op; |
|
| 632 | - $crit->not = $not; |
|
| 633 | - $crit->cond = $cond; |
|
| 634 | - $crit->exclus = ""; |
|
| 635 | - $crit->param = $v; |
|
| 636 | - $args[] = $crit; |
|
| 637 | - } else { |
|
| 638 | - if ($var->type != 'texte') { |
|
| 639 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 640 | - // erreur ou critere infixe "/" |
|
| 641 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 642 | - $err_ci = array( |
|
| 643 | - 'zbug_critere_inconnu', |
|
| 644 | - array('critere' => $var->nom_champ) |
|
| 645 | - ); |
|
| 646 | - erreur_squelette($err_ci, $result); |
|
| 647 | - } else { |
|
| 648 | - $crit = new Critere; |
|
| 649 | - $crit->op = '/'; |
|
| 650 | - $crit->not = ""; |
|
| 651 | - $crit->exclus = ""; |
|
| 652 | - $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 653 | - $args[] = $crit; |
|
| 654 | - } |
|
| 655 | - } else { |
|
| 656 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 657 | - // les separateurs |
|
| 658 | - if ($var->apres) { |
|
| 659 | - $result->separateur[] = $param; |
|
| 660 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 661 | - $result->modificateur['tout'] = true; |
|
| 662 | - } elseif ($param == 'plat') { |
|
| 663 | - $result->modificateur['plat'] = true; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 667 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 668 | - // ceux-ci pour avoir la rubrique mere... |
|
| 669 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 670 | - // traités normalement. |
|
| 671 | - elseif (strcasecmp($type, 'hierarchie') == 0 |
|
| 672 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 673 | - and preg_match(",^id_\w+\s*$,", $param) |
|
| 674 | - ) { |
|
| 675 | - $result->modificateur['tout'] = true; |
|
| 676 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == "id_rubrique") { |
|
| 677 | - // rien a faire sur {id_rubrique} tout seul |
|
| 678 | - } else { |
|
| 679 | - // pas d'emplacement statique, faut un dynamique |
|
| 680 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 681 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 682 | - // cette variable sera inseree dans le code |
|
| 683 | - // et son nom sert d'indicateur des maintenant |
|
| 684 | - $result->doublons = '$doublons_index'; |
|
| 685 | - if ($param == 'unique') { |
|
| 686 | - $param = 'doublons'; |
|
| 687 | - } |
|
| 688 | - } elseif ($param == 'recherche') { |
|
| 689 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 690 | - $result->hash = ' '; |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 694 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 695 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 696 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 697 | - $a2 = trim($m[8]); |
|
| 698 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 699 | - $a2 = substr($a2, 1, -1); |
|
| 700 | - } |
|
| 701 | - $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 702 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 703 | - $m[6], $m[5]); |
|
| 704 | - $crit->exclus = $m[1]; |
|
| 705 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 706 | - CHAMP_SQL_PLUS_FONC . |
|
| 707 | - ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 708 | - // contient aussi les comparaisons implicites ! |
|
| 709 | - // Comme ci-dessus: |
|
| 710 | - // le premier arg contient l'operateur |
|
| 711 | - array_shift($v); |
|
| 712 | - if ($m[6]) { |
|
| 713 | - $v[0][0] = new Texte; |
|
| 714 | - $v[0][0]->texte = $m[6]; |
|
| 715 | - } else { |
|
| 716 | - array_shift($v[0]); |
|
| 717 | - if (!$v[0]) { |
|
| 718 | - array_shift($v); |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - $crit = new Critere; |
|
| 722 | - $crit->op = $m[2]; |
|
| 723 | - $crit->param = $v; |
|
| 724 | - $crit->not = $m[1]; |
|
| 725 | - $crit->cond = $m[5]; |
|
| 726 | - } else { |
|
| 727 | - $err_ci = array( |
|
| 728 | - 'zbug_critere_inconnu', |
|
| 729 | - array('critere' => $param) |
|
| 730 | - ); |
|
| 731 | - erreur_squelette($err_ci, $result); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 735 | - $args[] = $crit; |
|
| 736 | - } else { |
|
| 737 | - $doublons[] = $crit; |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - // les doublons non nies doivent etre le dernier critere |
|
| 745 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 746 | - // cf critere_doublon |
|
| 747 | - if ($doublons) { |
|
| 748 | - $args = array_merge($args, $doublons); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 752 | - if (!$err_ci) { |
|
| 753 | - $result->criteres = $args; |
|
| 754 | - } |
|
| 587 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 588 | + $args = array(); |
|
| 589 | + $type = $result->type_requete; |
|
| 590 | + $doublons = array(); |
|
| 591 | + foreach ($params as $v) { |
|
| 592 | + $var = $v[1][0]; |
|
| 593 | + $param = ($var->type != 'texte') ? "" : $var->texte; |
|
| 594 | + if ((count($v) > 2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))) { |
|
| 595 | + // plus d'un argument et pas le critere IN: |
|
| 596 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 597 | + if ($var->type != 'texte' |
|
| 598 | + or preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 599 | + ) { |
|
| 600 | + $op = ','; |
|
| 601 | + $not = ""; |
|
| 602 | + $cond = false; |
|
| 603 | + } else { |
|
| 604 | + // Le debut du premier argument est l'operateur |
|
| 605 | + preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 606 | + $op = $m[2]; |
|
| 607 | + $not = $m[1]; |
|
| 608 | + $cond = $m[3]; |
|
| 609 | + // virer le premier argument, |
|
| 610 | + // et mettre son reliquat eventuel |
|
| 611 | + // Recopier pour ne pas alterer le texte source |
|
| 612 | + // utile au debusqueur |
|
| 613 | + if ($m[4]) { |
|
| 614 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 615 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 616 | + $c = null; |
|
| 617 | + eval('$c = ' . $m[4] . ';'); |
|
| 618 | + if (isset($c)) { |
|
| 619 | + $m[4] = $c; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + $texte = new Texte; |
|
| 623 | + $texte->texte = $m[4]; |
|
| 624 | + $v[1][0] = $texte; |
|
| 625 | + } else { |
|
| 626 | + array_shift($v[1]); |
|
| 627 | + } |
|
| 628 | + } |
|
| 629 | + array_shift($v); // $v[O] est vide |
|
| 630 | + $crit = new Critere; |
|
| 631 | + $crit->op = $op; |
|
| 632 | + $crit->not = $not; |
|
| 633 | + $crit->cond = $cond; |
|
| 634 | + $crit->exclus = ""; |
|
| 635 | + $crit->param = $v; |
|
| 636 | + $args[] = $crit; |
|
| 637 | + } else { |
|
| 638 | + if ($var->type != 'texte') { |
|
| 639 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 640 | + // erreur ou critere infixe "/" |
|
| 641 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 642 | + $err_ci = array( |
|
| 643 | + 'zbug_critere_inconnu', |
|
| 644 | + array('critere' => $var->nom_champ) |
|
| 645 | + ); |
|
| 646 | + erreur_squelette($err_ci, $result); |
|
| 647 | + } else { |
|
| 648 | + $crit = new Critere; |
|
| 649 | + $crit->op = '/'; |
|
| 650 | + $crit->not = ""; |
|
| 651 | + $crit->exclus = ""; |
|
| 652 | + $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 653 | + $args[] = $crit; |
|
| 654 | + } |
|
| 655 | + } else { |
|
| 656 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 657 | + // les separateurs |
|
| 658 | + if ($var->apres) { |
|
| 659 | + $result->separateur[] = $param; |
|
| 660 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 661 | + $result->modificateur['tout'] = true; |
|
| 662 | + } elseif ($param == 'plat') { |
|
| 663 | + $result->modificateur['plat'] = true; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 667 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 668 | + // ceux-ci pour avoir la rubrique mere... |
|
| 669 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 670 | + // traités normalement. |
|
| 671 | + elseif (strcasecmp($type, 'hierarchie') == 0 |
|
| 672 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 673 | + and preg_match(",^id_\w+\s*$,", $param) |
|
| 674 | + ) { |
|
| 675 | + $result->modificateur['tout'] = true; |
|
| 676 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == "id_rubrique") { |
|
| 677 | + // rien a faire sur {id_rubrique} tout seul |
|
| 678 | + } else { |
|
| 679 | + // pas d'emplacement statique, faut un dynamique |
|
| 680 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 681 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 682 | + // cette variable sera inseree dans le code |
|
| 683 | + // et son nom sert d'indicateur des maintenant |
|
| 684 | + $result->doublons = '$doublons_index'; |
|
| 685 | + if ($param == 'unique') { |
|
| 686 | + $param = 'doublons'; |
|
| 687 | + } |
|
| 688 | + } elseif ($param == 'recherche') { |
|
| 689 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 690 | + $result->hash = ' '; |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 694 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 695 | + } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 696 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 697 | + $a2 = trim($m[8]); |
|
| 698 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 699 | + $a2 = substr($a2, 1, -1); |
|
| 700 | + } |
|
| 701 | + $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 702 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 703 | + $m[6], $m[5]); |
|
| 704 | + $crit->exclus = $m[1]; |
|
| 705 | + } elseif (preg_match("/^([!]?)\s*(" . |
|
| 706 | + CHAMP_SQL_PLUS_FONC . |
|
| 707 | + ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 708 | + // contient aussi les comparaisons implicites ! |
|
| 709 | + // Comme ci-dessus: |
|
| 710 | + // le premier arg contient l'operateur |
|
| 711 | + array_shift($v); |
|
| 712 | + if ($m[6]) { |
|
| 713 | + $v[0][0] = new Texte; |
|
| 714 | + $v[0][0]->texte = $m[6]; |
|
| 715 | + } else { |
|
| 716 | + array_shift($v[0]); |
|
| 717 | + if (!$v[0]) { |
|
| 718 | + array_shift($v); |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + $crit = new Critere; |
|
| 722 | + $crit->op = $m[2]; |
|
| 723 | + $crit->param = $v; |
|
| 724 | + $crit->not = $m[1]; |
|
| 725 | + $crit->cond = $m[5]; |
|
| 726 | + } else { |
|
| 727 | + $err_ci = array( |
|
| 728 | + 'zbug_critere_inconnu', |
|
| 729 | + array('critere' => $param) |
|
| 730 | + ); |
|
| 731 | + erreur_squelette($err_ci, $result); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 735 | + $args[] = $crit; |
|
| 736 | + } else { |
|
| 737 | + $doublons[] = $crit; |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + // les doublons non nies doivent etre le dernier critere |
|
| 745 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 746 | + // cf critere_doublon |
|
| 747 | + if ($doublons) { |
|
| 748 | + $args = array_merge($args, $doublons); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 752 | + if (!$err_ci) { |
|
| 753 | + $result->criteres = $args; |
|
| 754 | + } |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | // http://code.spip.net/@phraser_critere_infixe |
| 758 | 758 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 759 | - $args[0] = new Texte; |
|
| 760 | - $args[0]->texte = $arg1; |
|
| 761 | - $args[0] = array($args[0]); |
|
| 762 | - $args[1][0] = new Texte; |
|
| 763 | - $args[1][0]->texte = $arg2; |
|
| 764 | - $crit = new Critere; |
|
| 765 | - $crit->op = $op; |
|
| 766 | - $crit->not = $not; |
|
| 767 | - $crit->cond = $cond; |
|
| 768 | - $crit->param = $args; |
|
| 769 | - |
|
| 770 | - return $crit; |
|
| 759 | + $args[0] = new Texte; |
|
| 760 | + $args[0]->texte = $arg1; |
|
| 761 | + $args[0] = array($args[0]); |
|
| 762 | + $args[1][0] = new Texte; |
|
| 763 | + $args[1][0]->texte = $arg2; |
|
| 764 | + $crit = new Critere; |
|
| 765 | + $crit->op = $op; |
|
| 766 | + $crit->not = $not; |
|
| 767 | + $crit->cond = $cond; |
|
| 768 | + $crit->param = $args; |
|
| 769 | + |
|
| 770 | + return $crit; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | /** |
@@ -778,12 +778,12 @@ discard block |
||
| 778 | 778 | * @return int |
| 779 | 779 | */ |
| 780 | 780 | function public_compte_ligne($texte, $debut = 0, $longueur = null) { |
| 781 | - if (is_null($longueur)) { |
|
| 782 | - return substr_count($texte, "\n", $debut); |
|
| 783 | - } |
|
| 784 | - else { |
|
| 785 | - return substr_count($texte, "\n", $debut, $longueur); |
|
| 786 | - } |
|
| 781 | + if (is_null($longueur)) { |
|
| 782 | + return substr_count($texte, "\n", $debut); |
|
| 783 | + } |
|
| 784 | + else { |
|
| 785 | + return substr_count($texte, "\n", $debut, $longueur); |
|
| 786 | + } |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | |
@@ -798,284 +798,284 @@ discard block |
||
| 798 | 798 | * @return array|null |
| 799 | 799 | */ |
| 800 | 800 | function public_trouver_premiere_boucle($texte, $id_parent, $descr) { |
| 801 | - $premiere_boucle = null; |
|
| 802 | - $current_pos = 0; |
|
| 803 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 804 | - $current_pos = $pos_boucle + 1; |
|
| 805 | - $pos_parent = strpos($texte,'(', $pos_boucle); |
|
| 806 | - if ($pos_parent === false |
|
| 807 | - or !$id_boucle = trim(substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 808 | - or !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) { |
|
| 809 | - |
|
| 810 | - $result = new Boucle; |
|
| 811 | - $result->id_parent = $id_parent; |
|
| 812 | - $result->descr = $descr; |
|
| 813 | - |
|
| 814 | - // un id_boucle pour l'affichage de l'erreur |
|
| 815 | - if (!$id_boucle) { |
|
| 816 | - $id_boucle = substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 817 | - } |
|
| 818 | - $result->id_boucle = $id_boucle; |
|
| 819 | - $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 820 | - erreur_squelette($err_b, $result); |
|
| 821 | - |
|
| 822 | - continue; |
|
| 823 | - } |
|
| 824 | - else { |
|
| 825 | - $boucle = [ |
|
| 826 | - 'id_boucle' => $id_boucle, |
|
| 827 | - 'debut_boucle' => $pos_boucle, |
|
| 828 | - 'pos_boucle' => $pos_boucle, |
|
| 829 | - 'pos_parent' => $pos_parent, |
|
| 830 | - 'pos_precond' => false, |
|
| 831 | - 'pos_precond_inside' => false, |
|
| 832 | - 'pos_preaff' => false, |
|
| 833 | - 'pos_preaff_inside' => false, |
|
| 834 | - ]; |
|
| 835 | - |
|
| 836 | - // trouver sa position de depart reelle : au <B_ ou au <BB_ |
|
| 837 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 838 | - $pos_precond = strpos($texte, $precond_boucle); |
|
| 839 | - if ($pos_precond !== false and $pos_precond < $boucle['debut_boucle']) { |
|
| 840 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 841 | - $boucle['pos_precond'] = $pos_precond; |
|
| 842 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 846 | - $pos_preaff = strpos($texte, $preaff_boucle); |
|
| 847 | - if ($pos_preaff !== false and $pos_preaff < $boucle['debut_boucle']) { |
|
| 848 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 849 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 850 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 854 | - $premiere_boucle = $boucle; |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - return $premiere_boucle; |
|
| 801 | + $premiere_boucle = null; |
|
| 802 | + $current_pos = 0; |
|
| 803 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 804 | + $current_pos = $pos_boucle + 1; |
|
| 805 | + $pos_parent = strpos($texte,'(', $pos_boucle); |
|
| 806 | + if ($pos_parent === false |
|
| 807 | + or !$id_boucle = trim(substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 808 | + or !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) { |
|
| 809 | + |
|
| 810 | + $result = new Boucle; |
|
| 811 | + $result->id_parent = $id_parent; |
|
| 812 | + $result->descr = $descr; |
|
| 813 | + |
|
| 814 | + // un id_boucle pour l'affichage de l'erreur |
|
| 815 | + if (!$id_boucle) { |
|
| 816 | + $id_boucle = substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 817 | + } |
|
| 818 | + $result->id_boucle = $id_boucle; |
|
| 819 | + $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 820 | + erreur_squelette($err_b, $result); |
|
| 821 | + |
|
| 822 | + continue; |
|
| 823 | + } |
|
| 824 | + else { |
|
| 825 | + $boucle = [ |
|
| 826 | + 'id_boucle' => $id_boucle, |
|
| 827 | + 'debut_boucle' => $pos_boucle, |
|
| 828 | + 'pos_boucle' => $pos_boucle, |
|
| 829 | + 'pos_parent' => $pos_parent, |
|
| 830 | + 'pos_precond' => false, |
|
| 831 | + 'pos_precond_inside' => false, |
|
| 832 | + 'pos_preaff' => false, |
|
| 833 | + 'pos_preaff_inside' => false, |
|
| 834 | + ]; |
|
| 835 | + |
|
| 836 | + // trouver sa position de depart reelle : au <B_ ou au <BB_ |
|
| 837 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 838 | + $pos_precond = strpos($texte, $precond_boucle); |
|
| 839 | + if ($pos_precond !== false and $pos_precond < $boucle['debut_boucle']) { |
|
| 840 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 841 | + $boucle['pos_precond'] = $pos_precond; |
|
| 842 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 846 | + $pos_preaff = strpos($texte, $preaff_boucle); |
|
| 847 | + if ($pos_preaff !== false and $pos_preaff < $boucle['debut_boucle']) { |
|
| 848 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 849 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 850 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 854 | + $premiere_boucle = $boucle; |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + return $premiere_boucle; |
|
| 860 | 860 | } |
| 861 | 861 | |
| 862 | 862 | |
| 863 | 863 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne = 1) { |
| 864 | 864 | |
| 865 | - $all_res = array(); |
|
| 866 | - |
|
| 867 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr)) { |
|
| 868 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 869 | - $result = new Boucle; |
|
| 870 | - $result->id_parent = $id_parent; |
|
| 871 | - $result->descr = $descr; |
|
| 872 | - |
|
| 873 | - $pos_boucle = $boucle['pos_boucle']; |
|
| 874 | - $id_boucle = $boucle['id_boucle']; |
|
| 875 | - $pos_parent = $boucle['pos_parent']; |
|
| 876 | - |
|
| 877 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne + public_compte_ligne($texte, 0, $pos_parent); |
|
| 878 | - $pos_debut_boucle = $pos_boucle; |
|
| 879 | - $milieu = substr($texte, $pos_parent); |
|
| 880 | - |
|
| 881 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 882 | - if ($boucle['pos_precond'] !== false) { |
|
| 883 | - |
|
| 884 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 885 | - |
|
| 886 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 887 | - $result->avant = substr($texte, $pos_avant, $pos_boucle - $pos_avant); |
|
| 888 | - $ligne_avant = $ligne + public_compte_ligne($texte,0, $pos_avant); |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 892 | - if ($boucle['pos_preaff'] !== false) { |
|
| 893 | - |
|
| 894 | - $end_preaff = $pos_debut_boucle; |
|
| 895 | - |
|
| 896 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 897 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 898 | - $ligne_preaff = $ligne + public_compte_ligne($texte,0, $pos_preaff); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - $debut = substr($texte, 0, $boucle['debut_boucle']); |
|
| 902 | - |
|
| 903 | - $result->id_boucle = $id_boucle; |
|
| 904 | - |
|
| 905 | - if (!preg_match(SPEC_BOUCLE, $milieu, $match)) { |
|
| 906 | - $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 907 | - erreur_squelette($err_b, $result); |
|
| 908 | - |
|
| 909 | - $ligne += public_compte_ligne($texte, 0, $pos_boucle + 1); |
|
| 910 | - $texte = substr($texte, $pos_boucle + 1); |
|
| 911 | - continue; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - $result->type_requete = $match[0]; |
|
| 915 | - $milieu = substr($milieu, strlen($match[0])); |
|
| 916 | - $pos_boucle = $pos_parent + strlen($match[0]); // on s'en sert pour compter les lignes plus precisemment |
|
| 917 | - |
|
| 918 | - $type = $match[1]; |
|
| 919 | - $jointures = trim($match[2]); |
|
| 920 | - $table_optionnelle = ($match[3]); |
|
| 921 | - if ($jointures) { |
|
| 922 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 923 | - // ou elles seront completees des jointures declarees |
|
| 924 | - $result->jointures_explicites = $jointures; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - if ($table_optionnelle) { |
|
| 928 | - $result->table_optionnelle = $type; |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 932 | - // Resultat mis dans result->param |
|
| 933 | - phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 934 | - |
|
| 935 | - // En 2e passe result->criteres contiendra un tableau |
|
| 936 | - // pour l'instant on met le source (chaine) : |
|
| 937 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 938 | - $pos_fin_criteres = strpos($milieu, $result->apres); |
|
| 939 | - $pos_boucle += $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 940 | - $result->criteres = substr($milieu, 0, $pos_fin_criteres); |
|
| 941 | - $milieu = $result->apres; |
|
| 942 | - $result->apres = ""; |
|
| 943 | - |
|
| 944 | - // |
|
| 945 | - // Recuperer la fin : |
|
| 946 | - // |
|
| 947 | - if ($milieu[0] === '/') { |
|
| 948 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 949 | - $suite = substr($milieu, 2); |
|
| 950 | - $pos_boucle += 2; |
|
| 951 | - $milieu = ''; |
|
| 952 | - } else { |
|
| 953 | - $milieu = substr($milieu, 1); |
|
| 954 | - $pos_boucle += 1; |
|
| 955 | - |
|
| 956 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 957 | - $pos_fin = strpos($milieu, $fin_boucle); |
|
| 958 | - if ($pos_fin === false) { |
|
| 959 | - $err_b = array( |
|
| 960 | - 'zbug_erreur_boucle_fermant', |
|
| 961 | - array('id' => $id_boucle) |
|
| 962 | - ); |
|
| 963 | - erreur_squelette($err_b, $result); |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - $pos_boucle += $pos_fin + strlen($fin_boucle); |
|
| 967 | - $suite = substr($milieu, $pos_fin + strlen($fin_boucle)); |
|
| 968 | - $milieu = substr($milieu, 0, $pos_fin); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - $result->milieu = $milieu; |
|
| 972 | - $ligne_suite = $ligne_apres = $ligne + public_compte_ligne($texte, 0, $pos_boucle); |
|
| 973 | - |
|
| 974 | - // |
|
| 975 | - // 1. Recuperer la partie conditionnelle apres |
|
| 976 | - // |
|
| 977 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . ">"; |
|
| 978 | - $pos_apres = strpos($suite, $apres_boucle); |
|
| 979 | - if ($pos_apres !== false) { |
|
| 980 | - $result->apres = substr($suite, 0, $pos_apres); |
|
| 981 | - $pos_apres += strlen($apres_boucle); |
|
| 982 | - $suite = substr($suite, $pos_apres); |
|
| 983 | - $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_apres); |
|
| 984 | - $pos_boucle += $pos_apres ; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - // |
|
| 989 | - // 2. Recuperer la partie alternative |
|
| 990 | - // |
|
| 991 | - $ligne_altern = $ligne_suite; |
|
| 992 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 993 | - $pos_altern = strpos($suite, $altern_boucle); |
|
| 994 | - if ($pos_altern !== false) { |
|
| 995 | - $result->altern = substr($suite, 0, $pos_altern); |
|
| 996 | - $pos_altern += strlen($altern_boucle); |
|
| 997 | - $suite = substr($suite, $pos_altern); |
|
| 998 | - $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_altern); |
|
| 999 | - $pos_boucle += $pos_altern; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - // |
|
| 1003 | - // 3. Recuperer la partie footer non alternative |
|
| 1004 | - // |
|
| 1005 | - $ligne_postaff = $ligne_suite; |
|
| 1006 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . ">"; |
|
| 1007 | - $pos_postaff = strpos($suite, $postaff_boucle); |
|
| 1008 | - if ($pos_postaff !== false) { |
|
| 1009 | - $result->postaff = substr($suite, 0, $pos_postaff); |
|
| 1010 | - $pos_postaff += strlen($postaff_boucle); |
|
| 1011 | - $suite = substr($suite, $pos_postaff); |
|
| 1012 | - $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_postaff); |
|
| 1013 | - $pos_boucle += $pos_postaff ; |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - $result->ligne = $ligne_preaff; |
|
| 1017 | - |
|
| 1018 | - if ($p = strpos($type, ':')) { |
|
| 1019 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1020 | - $type = substr($type, $p + 1); |
|
| 1021 | - } |
|
| 1022 | - $soustype = strtolower($type); |
|
| 1023 | - |
|
| 1024 | - if (!isset($GLOBALS["table_des_tables"][$soustype])) { |
|
| 1025 | - $soustype = $type; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - $result->type_requete = $soustype; |
|
| 1029 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1030 | - if (!is_array($result->param)) { |
|
| 1031 | - $err_b = true; |
|
| 1032 | - } else { |
|
| 1033 | - phraser_criteres($result->param, $result); |
|
| 1034 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1035 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1036 | - $args = $result->param; |
|
| 1037 | - array_unshift($args, |
|
| 1038 | - substr($type, strlen(TYPE_RECURSIF))); |
|
| 1039 | - $result->param = $args; |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1044 | - $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $ligne_milieu); |
|
| 1045 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1046 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1047 | - $boucles[$id_boucle] = null; |
|
| 1048 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff); |
|
| 1049 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant); |
|
| 1050 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres); |
|
| 1051 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern); |
|
| 1052 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff); |
|
| 1053 | - |
|
| 1054 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1055 | - if ($err_b) { |
|
| 1056 | - $result->type_requete = false; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - // Verifier qu'il n'y a pas double definition |
|
| 1060 | - // apres analyse des sous-parties (pas avant). |
|
| 1061 | - |
|
| 1062 | - if (!empty($boucles[$id_boucle])) { |
|
| 1063 | - $err_b_d = array( |
|
| 1064 | - 'zbug_erreur_boucle_double', |
|
| 1065 | - array('id' => $id_boucle) |
|
| 1066 | - ); |
|
| 1067 | - erreur_squelette($err_b_d, $result); |
|
| 1068 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1069 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1070 | - } else { |
|
| 1071 | - $boucles[$id_boucle] = $result; |
|
| 1072 | - } |
|
| 1073 | - $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 1074 | - $all_res[] = &$boucles[$id_boucle]; |
|
| 1075 | - |
|
| 1076 | - $ligne = $ligne_suite; |
|
| 1077 | - $texte = $suite; |
|
| 1078 | - } |
|
| 1079 | - |
|
| 1080 | - return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 865 | + $all_res = array(); |
|
| 866 | + |
|
| 867 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr)) { |
|
| 868 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 869 | + $result = new Boucle; |
|
| 870 | + $result->id_parent = $id_parent; |
|
| 871 | + $result->descr = $descr; |
|
| 872 | + |
|
| 873 | + $pos_boucle = $boucle['pos_boucle']; |
|
| 874 | + $id_boucle = $boucle['id_boucle']; |
|
| 875 | + $pos_parent = $boucle['pos_parent']; |
|
| 876 | + |
|
| 877 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne + public_compte_ligne($texte, 0, $pos_parent); |
|
| 878 | + $pos_debut_boucle = $pos_boucle; |
|
| 879 | + $milieu = substr($texte, $pos_parent); |
|
| 880 | + |
|
| 881 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 882 | + if ($boucle['pos_precond'] !== false) { |
|
| 883 | + |
|
| 884 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 885 | + |
|
| 886 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 887 | + $result->avant = substr($texte, $pos_avant, $pos_boucle - $pos_avant); |
|
| 888 | + $ligne_avant = $ligne + public_compte_ligne($texte,0, $pos_avant); |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 892 | + if ($boucle['pos_preaff'] !== false) { |
|
| 893 | + |
|
| 894 | + $end_preaff = $pos_debut_boucle; |
|
| 895 | + |
|
| 896 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 897 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 898 | + $ligne_preaff = $ligne + public_compte_ligne($texte,0, $pos_preaff); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + $debut = substr($texte, 0, $boucle['debut_boucle']); |
|
| 902 | + |
|
| 903 | + $result->id_boucle = $id_boucle; |
|
| 904 | + |
|
| 905 | + if (!preg_match(SPEC_BOUCLE, $milieu, $match)) { |
|
| 906 | + $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 907 | + erreur_squelette($err_b, $result); |
|
| 908 | + |
|
| 909 | + $ligne += public_compte_ligne($texte, 0, $pos_boucle + 1); |
|
| 910 | + $texte = substr($texte, $pos_boucle + 1); |
|
| 911 | + continue; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + $result->type_requete = $match[0]; |
|
| 915 | + $milieu = substr($milieu, strlen($match[0])); |
|
| 916 | + $pos_boucle = $pos_parent + strlen($match[0]); // on s'en sert pour compter les lignes plus precisemment |
|
| 917 | + |
|
| 918 | + $type = $match[1]; |
|
| 919 | + $jointures = trim($match[2]); |
|
| 920 | + $table_optionnelle = ($match[3]); |
|
| 921 | + if ($jointures) { |
|
| 922 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 923 | + // ou elles seront completees des jointures declarees |
|
| 924 | + $result->jointures_explicites = $jointures; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + if ($table_optionnelle) { |
|
| 928 | + $result->table_optionnelle = $type; |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 932 | + // Resultat mis dans result->param |
|
| 933 | + phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 934 | + |
|
| 935 | + // En 2e passe result->criteres contiendra un tableau |
|
| 936 | + // pour l'instant on met le source (chaine) : |
|
| 937 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 938 | + $pos_fin_criteres = strpos($milieu, $result->apres); |
|
| 939 | + $pos_boucle += $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 940 | + $result->criteres = substr($milieu, 0, $pos_fin_criteres); |
|
| 941 | + $milieu = $result->apres; |
|
| 942 | + $result->apres = ""; |
|
| 943 | + |
|
| 944 | + // |
|
| 945 | + // Recuperer la fin : |
|
| 946 | + // |
|
| 947 | + if ($milieu[0] === '/') { |
|
| 948 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 949 | + $suite = substr($milieu, 2); |
|
| 950 | + $pos_boucle += 2; |
|
| 951 | + $milieu = ''; |
|
| 952 | + } else { |
|
| 953 | + $milieu = substr($milieu, 1); |
|
| 954 | + $pos_boucle += 1; |
|
| 955 | + |
|
| 956 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 957 | + $pos_fin = strpos($milieu, $fin_boucle); |
|
| 958 | + if ($pos_fin === false) { |
|
| 959 | + $err_b = array( |
|
| 960 | + 'zbug_erreur_boucle_fermant', |
|
| 961 | + array('id' => $id_boucle) |
|
| 962 | + ); |
|
| 963 | + erreur_squelette($err_b, $result); |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + $pos_boucle += $pos_fin + strlen($fin_boucle); |
|
| 967 | + $suite = substr($milieu, $pos_fin + strlen($fin_boucle)); |
|
| 968 | + $milieu = substr($milieu, 0, $pos_fin); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + $result->milieu = $milieu; |
|
| 972 | + $ligne_suite = $ligne_apres = $ligne + public_compte_ligne($texte, 0, $pos_boucle); |
|
| 973 | + |
|
| 974 | + // |
|
| 975 | + // 1. Recuperer la partie conditionnelle apres |
|
| 976 | + // |
|
| 977 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . ">"; |
|
| 978 | + $pos_apres = strpos($suite, $apres_boucle); |
|
| 979 | + if ($pos_apres !== false) { |
|
| 980 | + $result->apres = substr($suite, 0, $pos_apres); |
|
| 981 | + $pos_apres += strlen($apres_boucle); |
|
| 982 | + $suite = substr($suite, $pos_apres); |
|
| 983 | + $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_apres); |
|
| 984 | + $pos_boucle += $pos_apres ; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + // |
|
| 989 | + // 2. Recuperer la partie alternative |
|
| 990 | + // |
|
| 991 | + $ligne_altern = $ligne_suite; |
|
| 992 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 993 | + $pos_altern = strpos($suite, $altern_boucle); |
|
| 994 | + if ($pos_altern !== false) { |
|
| 995 | + $result->altern = substr($suite, 0, $pos_altern); |
|
| 996 | + $pos_altern += strlen($altern_boucle); |
|
| 997 | + $suite = substr($suite, $pos_altern); |
|
| 998 | + $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_altern); |
|
| 999 | + $pos_boucle += $pos_altern; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + // |
|
| 1003 | + // 3. Recuperer la partie footer non alternative |
|
| 1004 | + // |
|
| 1005 | + $ligne_postaff = $ligne_suite; |
|
| 1006 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . ">"; |
|
| 1007 | + $pos_postaff = strpos($suite, $postaff_boucle); |
|
| 1008 | + if ($pos_postaff !== false) { |
|
| 1009 | + $result->postaff = substr($suite, 0, $pos_postaff); |
|
| 1010 | + $pos_postaff += strlen($postaff_boucle); |
|
| 1011 | + $suite = substr($suite, $pos_postaff); |
|
| 1012 | + $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_postaff); |
|
| 1013 | + $pos_boucle += $pos_postaff ; |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + $result->ligne = $ligne_preaff; |
|
| 1017 | + |
|
| 1018 | + if ($p = strpos($type, ':')) { |
|
| 1019 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1020 | + $type = substr($type, $p + 1); |
|
| 1021 | + } |
|
| 1022 | + $soustype = strtolower($type); |
|
| 1023 | + |
|
| 1024 | + if (!isset($GLOBALS["table_des_tables"][$soustype])) { |
|
| 1025 | + $soustype = $type; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + $result->type_requete = $soustype; |
|
| 1029 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1030 | + if (!is_array($result->param)) { |
|
| 1031 | + $err_b = true; |
|
| 1032 | + } else { |
|
| 1033 | + phraser_criteres($result->param, $result); |
|
| 1034 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1035 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1036 | + $args = $result->param; |
|
| 1037 | + array_unshift($args, |
|
| 1038 | + substr($type, strlen(TYPE_RECURSIF))); |
|
| 1039 | + $result->param = $args; |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1044 | + $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $ligne_milieu); |
|
| 1045 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1046 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1047 | + $boucles[$id_boucle] = null; |
|
| 1048 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff); |
|
| 1049 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant); |
|
| 1050 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres); |
|
| 1051 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern); |
|
| 1052 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff); |
|
| 1053 | + |
|
| 1054 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1055 | + if ($err_b) { |
|
| 1056 | + $result->type_requete = false; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + // Verifier qu'il n'y a pas double definition |
|
| 1060 | + // apres analyse des sous-parties (pas avant). |
|
| 1061 | + |
|
| 1062 | + if (!empty($boucles[$id_boucle])) { |
|
| 1063 | + $err_b_d = array( |
|
| 1064 | + 'zbug_erreur_boucle_double', |
|
| 1065 | + array('id' => $id_boucle) |
|
| 1066 | + ); |
|
| 1067 | + erreur_squelette($err_b_d, $result); |
|
| 1068 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1069 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1070 | + } else { |
|
| 1071 | + $boucles[$id_boucle] = $result; |
|
| 1072 | + } |
|
| 1073 | + $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 1074 | + $all_res[] = &$boucles[$id_boucle]; |
|
| 1075 | + |
|
| 1076 | + $ligne = $ligne_suite; |
|
| 1077 | + $texte = $suite; |
|
| 1078 | + } |
|
| 1079 | + |
|
| 1080 | + return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 1081 | 1081 | } |
@@ -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 | // http://code.spip.net/@phraser_inclure |
| 66 | 66 | function phraser_inclure($texte, $ligne, $result) { |
@@ -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, $match[0]); |
| 220 | 220 | // texte après la balise |
| 221 | 221 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | $collecte[] = $champ; |
| 362 | 362 | $args = ltrim($regs[count($regs) - 1]); |
| 363 | 363 | } else { |
| 364 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) { |
|
| 364 | + if (!preg_match("/".NOM_DE_CHAMP."([{|])/", $arg, $r)) { |
|
| 365 | 365 | // 0 est un aveu d'impuissance. A completer |
| 366 | 366 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 367 | 367 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 447 | 447 | $res = array(); |
| 448 | 448 | while (($p = strpos($texte, "%$sep")) !== false) { |
| 449 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 449 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | 450 | break; |
| 451 | 451 | } |
| 452 | 452 | $debut = substr($texte, 0, $p); |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 615 | 615 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 616 | 616 | $c = null; |
| 617 | - eval('$c = ' . $m[4] . ';'); |
|
| 617 | + eval('$c = '.$m[4].';'); |
|
| 618 | 618 | if (isset($c)) { |
| 619 | 619 | $m[4] = $c; |
| 620 | 620 | } |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | |
| 693 | 693 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 694 | 694 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 695 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 695 | + } elseif (preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 696 | 696 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
| 697 | 697 | $a2 = trim($m[8]); |
| 698 | 698 | if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
@@ -702,8 +702,8 @@ discard block |
||
| 702 | 702 | (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
| 703 | 703 | $m[6], $m[5]); |
| 704 | 704 | $crit->exclus = $m[1]; |
| 705 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 706 | - CHAMP_SQL_PLUS_FONC . |
|
| 705 | + } elseif (preg_match("/^([!]?)\s*(". |
|
| 706 | + CHAMP_SQL_PLUS_FONC. |
|
| 707 | 707 | ")\s*(\??)(.*)$/is", $param, $m)) { |
| 708 | 708 | // contient aussi les comparaisons implicites ! |
| 709 | 709 | // Comme ci-dessus: |
@@ -802,9 +802,9 @@ discard block |
||
| 802 | 802 | $current_pos = 0; |
| 803 | 803 | while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
| 804 | 804 | $current_pos = $pos_boucle + 1; |
| 805 | - $pos_parent = strpos($texte,'(', $pos_boucle); |
|
| 805 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 806 | 806 | if ($pos_parent === false |
| 807 | - or !$id_boucle = trim(substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 807 | + or !$id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))) |
|
| 808 | 808 | or !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) { |
| 809 | 809 | |
| 810 | 810 | $result = new Boucle; |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | |
| 814 | 814 | // un id_boucle pour l'affichage de l'erreur |
| 815 | 815 | if (!$id_boucle) { |
| 816 | - $id_boucle = substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 816 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 817 | 817 | } |
| 818 | 818 | $result->id_boucle = $id_boucle; |
| 819 | 819 | $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | ]; |
| 835 | 835 | |
| 836 | 836 | // trouver sa position de depart reelle : au <B_ ou au <BB_ |
| 837 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 837 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 838 | 838 | $pos_precond = strpos($texte, $precond_boucle); |
| 839 | 839 | if ($pos_precond !== false and $pos_precond < $boucle['debut_boucle']) { |
| 840 | 840 | $boucle['debut_boucle'] = $pos_precond; |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 843 | 843 | } |
| 844 | 844 | |
| 845 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 845 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 846 | 846 | $pos_preaff = strpos($texte, $preaff_boucle); |
| 847 | 847 | if ($pos_preaff !== false and $pos_preaff < $boucle['debut_boucle']) { |
| 848 | 848 | $boucle['debut_boucle'] = $pos_preaff; |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | |
| 886 | 886 | $pos_avant = $boucle['pos_precond_inside']; |
| 887 | 887 | $result->avant = substr($texte, $pos_avant, $pos_boucle - $pos_avant); |
| 888 | - $ligne_avant = $ligne + public_compte_ligne($texte,0, $pos_avant); |
|
| 888 | + $ligne_avant = $ligne + public_compte_ligne($texte, 0, $pos_avant); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | |
| 896 | 896 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 897 | 897 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 898 | - $ligne_preaff = $ligne + public_compte_ligne($texte,0, $pos_preaff); |
|
| 898 | + $ligne_preaff = $ligne + public_compte_ligne($texte, 0, $pos_preaff); |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | $debut = substr($texte, 0, $boucle['debut_boucle']); |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | $milieu = substr($milieu, 1); |
| 954 | 954 | $pos_boucle += 1; |
| 955 | 955 | |
| 956 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 956 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle.">"; |
|
| 957 | 957 | $pos_fin = strpos($milieu, $fin_boucle); |
| 958 | 958 | if ($pos_fin === false) { |
| 959 | 959 | $err_b = array( |
@@ -974,14 +974,14 @@ discard block |
||
| 974 | 974 | // |
| 975 | 975 | // 1. Recuperer la partie conditionnelle apres |
| 976 | 976 | // |
| 977 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . ">"; |
|
| 977 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.">"; |
|
| 978 | 978 | $pos_apres = strpos($suite, $apres_boucle); |
| 979 | 979 | if ($pos_apres !== false) { |
| 980 | 980 | $result->apres = substr($suite, 0, $pos_apres); |
| 981 | 981 | $pos_apres += strlen($apres_boucle); |
| 982 | 982 | $suite = substr($suite, $pos_apres); |
| 983 | 983 | $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_apres); |
| 984 | - $pos_boucle += $pos_apres ; |
|
| 984 | + $pos_boucle += $pos_apres; |
|
| 985 | 985 | } |
| 986 | 986 | |
| 987 | 987 | |
@@ -989,7 +989,7 @@ discard block |
||
| 989 | 989 | // 2. Recuperer la partie alternative |
| 990 | 990 | // |
| 991 | 991 | $ligne_altern = $ligne_suite; |
| 992 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 992 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.">"; |
|
| 993 | 993 | $pos_altern = strpos($suite, $altern_boucle); |
| 994 | 994 | if ($pos_altern !== false) { |
| 995 | 995 | $result->altern = substr($suite, 0, $pos_altern); |
@@ -1003,14 +1003,14 @@ discard block |
||
| 1003 | 1003 | // 3. Recuperer la partie footer non alternative |
| 1004 | 1004 | // |
| 1005 | 1005 | $ligne_postaff = $ligne_suite; |
| 1006 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . ">"; |
|
| 1006 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.">"; |
|
| 1007 | 1007 | $pos_postaff = strpos($suite, $postaff_boucle); |
| 1008 | 1008 | if ($pos_postaff !== false) { |
| 1009 | 1009 | $result->postaff = substr($suite, 0, $pos_postaff); |
| 1010 | 1010 | $pos_postaff += strlen($postaff_boucle); |
| 1011 | 1011 | $suite = substr($suite, $pos_postaff); |
| 1012 | 1012 | $ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_postaff); |
| 1013 | - $pos_boucle += $pos_postaff ; |
|
| 1013 | + $pos_boucle += $pos_postaff; |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | $result->ligne = $ligne_preaff; |
@@ -780,8 +780,7 @@ discard block |
||
| 780 | 780 | function public_compte_ligne($texte, $debut = 0, $longueur = null) { |
| 781 | 781 | if (is_null($longueur)) { |
| 782 | 782 | return substr_count($texte, "\n", $debut); |
| 783 | - } |
|
| 784 | - else { |
|
| 783 | + } else { |
|
| 785 | 784 | return substr_count($texte, "\n", $debut, $longueur); |
| 786 | 785 | } |
| 787 | 786 | } |
@@ -820,8 +819,7 @@ discard block |
||
| 820 | 819 | erreur_squelette($err_b, $result); |
| 821 | 820 | |
| 822 | 821 | continue; |
| 823 | - } |
|
| 824 | - else { |
|
| 822 | + } else { |
|
| 825 | 823 | $boucle = [ |
| 826 | 824 | 'id_boucle' => $id_boucle, |
| 827 | 825 | 'debut_boucle' => $pos_boucle, |
@@ -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 | |
@@ -34,53 +34,53 @@ discard block |
||
| 34 | 34 | * @package SPIP\Core\Compilateur\AST |
| 35 | 35 | */ |
| 36 | 36 | class Contexte { |
| 37 | - /** |
|
| 38 | - * Description du squelette |
|
| 39 | - * |
|
| 40 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | - * |
|
| 42 | - * Peut contenir les index : |
|
| 43 | - * |
|
| 44 | - * - nom : Nom du fichier de cache |
|
| 45 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | - * - sourcefile : Chemin du squelette |
|
| 47 | - * - squelette : Code du squelette |
|
| 48 | - * - id_mere : Identifiant de la boucle parente |
|
| 49 | - * - documents : Pour embed et img dans les textes |
|
| 50 | - * - session : Pour un cache sessionné par auteur |
|
| 51 | - * - niv : Niveau de tabulation |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $descr = array(); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Identifiant de la boucle |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - public $id_boucle = ''; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Numéro de ligne dans le code source du squelette |
|
| 66 | - * |
|
| 67 | - * @var int |
|
| 68 | - */ |
|
| 69 | - public $ligne = 0; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Langue d'exécution |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $lang = ''; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Résultat de la compilation: toujours une expression PHP |
|
| 80 | - * |
|
| 81 | - * @var string |
|
| 82 | - */ |
|
| 83 | - public $code = ''; |
|
| 37 | + /** |
|
| 38 | + * Description du squelette |
|
| 39 | + * |
|
| 40 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | + * |
|
| 42 | + * Peut contenir les index : |
|
| 43 | + * |
|
| 44 | + * - nom : Nom du fichier de cache |
|
| 45 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | + * - sourcefile : Chemin du squelette |
|
| 47 | + * - squelette : Code du squelette |
|
| 48 | + * - id_mere : Identifiant de la boucle parente |
|
| 49 | + * - documents : Pour embed et img dans les textes |
|
| 50 | + * - session : Pour un cache sessionné par auteur |
|
| 51 | + * - niv : Niveau de tabulation |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $descr = array(); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Identifiant de la boucle |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + public $id_boucle = ''; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Numéro de ligne dans le code source du squelette |
|
| 66 | + * |
|
| 67 | + * @var int |
|
| 68 | + */ |
|
| 69 | + public $ligne = 0; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Langue d'exécution |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $lang = ''; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Résultat de la compilation: toujours une expression PHP |
|
| 80 | + * |
|
| 81 | + * @var string |
|
| 82 | + */ |
|
| 83 | + public $code = ''; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -90,44 +90,44 @@ discard block |
||
| 90 | 90 | * @package SPIP\Core\Compilateur\AST |
| 91 | 91 | **/ |
| 92 | 92 | class Texte { |
| 93 | - /** |
|
| 94 | - * Type de noeud |
|
| 95 | - * |
|
| 96 | - * @var string |
|
| 97 | - */ |
|
| 98 | - public $type = 'texte'; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Le texte |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $texte; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Contenu avant le texte. |
|
| 109 | - * |
|
| 110 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | - * |
|
| 112 | - * @var string|array |
|
| 113 | - */ |
|
| 114 | - public $avant = ""; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Contenu après le texte. |
|
| 118 | - * |
|
| 119 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | - * |
|
| 121 | - * @var string|array |
|
| 122 | - */ |
|
| 123 | - public $apres = ""; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Numéro de ligne dans le code source du squelette |
|
| 127 | - * |
|
| 128 | - * @var int |
|
| 129 | - */ |
|
| 130 | - public $ligne = 0; |
|
| 93 | + /** |
|
| 94 | + * Type de noeud |
|
| 95 | + * |
|
| 96 | + * @var string |
|
| 97 | + */ |
|
| 98 | + public $type = 'texte'; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Le texte |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $texte; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Contenu avant le texte. |
|
| 109 | + * |
|
| 110 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | + * |
|
| 112 | + * @var string|array |
|
| 113 | + */ |
|
| 114 | + public $avant = ""; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Contenu après le texte. |
|
| 118 | + * |
|
| 119 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | + * |
|
| 121 | + * @var string|array |
|
| 122 | + */ |
|
| 123 | + public $apres = ""; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Numéro de ligne dans le code source du squelette |
|
| 127 | + * |
|
| 128 | + * @var int |
|
| 129 | + */ |
|
| 130 | + public $ligne = 0; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -136,50 +136,50 @@ discard block |
||
| 136 | 136 | * @package SPIP\Core\Compilateur\AST |
| 137 | 137 | **/ |
| 138 | 138 | class Inclure { |
| 139 | - /** |
|
| 140 | - * Type de noeud |
|
| 141 | - * |
|
| 142 | - * @var string |
|
| 143 | - */ |
|
| 144 | - public $type = 'include'; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Nom d'un fichier inclu |
|
| 148 | - * |
|
| 149 | - * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | - * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | - * |
|
| 152 | - * @var string|Texte |
|
| 153 | - */ |
|
| 154 | - public $texte; |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Inutilisé, propriété générique de l'AST |
|
| 158 | - * |
|
| 159 | - * @var string|array |
|
| 160 | - */ |
|
| 161 | - public $avant = ''; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Inutilisé, propriété générique de l'AST |
|
| 165 | - * |
|
| 166 | - * @var string|array |
|
| 167 | - */ |
|
| 168 | - public $apres = ''; |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Numéro de ligne dans le code source du squelette |
|
| 172 | - * |
|
| 173 | - * @var int |
|
| 174 | - */ |
|
| 175 | - public $ligne = 0; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Valeurs des paramètres |
|
| 179 | - * |
|
| 180 | - * @var array |
|
| 181 | - */ |
|
| 182 | - public $param = array(); |
|
| 139 | + /** |
|
| 140 | + * Type de noeud |
|
| 141 | + * |
|
| 142 | + * @var string |
|
| 143 | + */ |
|
| 144 | + public $type = 'include'; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Nom d'un fichier inclu |
|
| 148 | + * |
|
| 149 | + * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | + * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | + * |
|
| 152 | + * @var string|Texte |
|
| 153 | + */ |
|
| 154 | + public $texte; |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Inutilisé, propriété générique de l'AST |
|
| 158 | + * |
|
| 159 | + * @var string|array |
|
| 160 | + */ |
|
| 161 | + public $avant = ''; |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Inutilisé, propriété générique de l'AST |
|
| 165 | + * |
|
| 166 | + * @var string|array |
|
| 167 | + */ |
|
| 168 | + public $apres = ''; |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Numéro de ligne dans le code source du squelette |
|
| 172 | + * |
|
| 173 | + * @var int |
|
| 174 | + */ |
|
| 175 | + public $ligne = 0; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Valeurs des paramètres |
|
| 179 | + * |
|
| 180 | + * @var array |
|
| 181 | + */ |
|
| 182 | + public $param = array(); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -189,384 +189,384 @@ discard block |
||
| 189 | 189 | * @package SPIP\Core\Compilateur\AST |
| 190 | 190 | **/ |
| 191 | 191 | class Boucle { |
| 192 | - /** |
|
| 193 | - * Type de noeud |
|
| 194 | - * |
|
| 195 | - * @var string |
|
| 196 | - */ |
|
| 197 | - public $type = 'boucle'; |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Identifiant de la boucle |
|
| 201 | - * |
|
| 202 | - * @var string |
|
| 203 | - */ |
|
| 204 | - public $id_boucle; |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Identifiant de la boucle parente |
|
| 208 | - * |
|
| 209 | - * @var string |
|
| 210 | - */ |
|
| 211 | - public $id_parent = ''; |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Partie avant toujours affichee |
|
| 215 | - * |
|
| 216 | - * @var string|array |
|
| 217 | - */ |
|
| 218 | - public $preaff = ''; |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Partie optionnelle avant |
|
| 222 | - * |
|
| 223 | - * @var string|array |
|
| 224 | - */ |
|
| 225 | - public $avant = ''; |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Pour chaque élément |
|
| 229 | - * |
|
| 230 | - * @var string|array |
|
| 231 | - */ |
|
| 232 | - public $milieu = ''; |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Partie optionnelle après |
|
| 236 | - * |
|
| 237 | - * @var string|array |
|
| 238 | - */ |
|
| 239 | - public $apres = ''; |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | - * |
|
| 244 | - * @var string|array |
|
| 245 | - */ |
|
| 246 | - public $altern = ''; |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Partie apres toujours affichee |
|
| 250 | - * |
|
| 251 | - * @var string|array |
|
| 252 | - */ |
|
| 253 | - public $postaff = ''; |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * La boucle doit-elle sélectionner la langue ? |
|
| 258 | - * |
|
| 259 | - * @var string|null |
|
| 260 | - */ |
|
| 261 | - public $lang_select; |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | - * |
|
| 266 | - * @var string|null |
|
| 267 | - */ |
|
| 268 | - public $type_requete; |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * La table est elle optionnelle ? |
|
| 272 | - * |
|
| 273 | - * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | - * |
|
| 275 | - * @var bool |
|
| 276 | - */ |
|
| 277 | - public $table_optionnelle = false; |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Nom du fichier de connexion |
|
| 281 | - * |
|
| 282 | - * @var string |
|
| 283 | - */ |
|
| 284 | - public $sql_serveur = ''; |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Paramètres de la boucle |
|
| 288 | - * |
|
| 289 | - * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | - * au calcul des critères |
|
| 291 | - * |
|
| 292 | - * @var array |
|
| 293 | - */ |
|
| 294 | - public $param = array(); |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Critères de la boucle |
|
| 298 | - * |
|
| 299 | - * @var Critere[] |
|
| 300 | - */ |
|
| 301 | - public $criteres = array(); |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | - * |
|
| 306 | - * @var string[] |
|
| 307 | - */ |
|
| 308 | - public $separateur = array(); |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Liste des jointures possibles avec cette table |
|
| 312 | - * |
|
| 313 | - * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | - * des jointures déclarées explicitement sur la boucle |
|
| 315 | - * |
|
| 316 | - * @see base_trouver_table_dist() |
|
| 317 | - * @var array |
|
| 318 | - */ |
|
| 319 | - public $jointures = array(); |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Jointures explicites avec cette table |
|
| 323 | - * |
|
| 324 | - * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | - * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | - * à la boucle. |
|
| 327 | - * |
|
| 328 | - * @var string|bool |
|
| 329 | - */ |
|
| 330 | - public $jointures_explicites = false; |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | - * |
|
| 335 | - * @var string|null |
|
| 336 | - */ |
|
| 337 | - public $doublons; |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | - * |
|
| 342 | - * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | - * |
|
| 344 | - * @var string |
|
| 345 | - */ |
|
| 346 | - public $partie = ""; |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | - * ou de soustractions d'éléments à faire |
|
| 351 | - * |
|
| 352 | - * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | - * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | - * |
|
| 355 | - * @var string |
|
| 356 | - */ |
|
| 357 | - public $total_parties = ""; |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | - * |
|
| 362 | - * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | - * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | - * |
|
| 365 | - * @var string |
|
| 366 | - */ |
|
| 367 | - public $mode_partie = ''; |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | - * |
|
| 372 | - * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | - * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | - * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | - * de l'appelant (rec) |
|
| 376 | - * |
|
| 377 | - * @var string |
|
| 378 | - */ |
|
| 379 | - public $externe = ''; |
|
| 380 | - |
|
| 381 | - // champs pour la construction de la requete SQL |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Liste des champs à récupérer par la boucle |
|
| 385 | - * |
|
| 386 | - * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | - * |
|
| 388 | - * @var string[] |
|
| 389 | - */ |
|
| 390 | - public $select = array(); |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | - * |
|
| 395 | - * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | - * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | - * |
|
| 398 | - * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | - * |
|
| 400 | - * @var string[] |
|
| 401 | - */ |
|
| 402 | - public $from = array(); |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | - * |
|
| 407 | - * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | - * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | - * |
|
| 410 | - * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | - * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | - * |
|
| 413 | - * @var string[] |
|
| 414 | - */ |
|
| 415 | - public $from_type = array(); |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Liste des conditions WHERE de la boucle |
|
| 419 | - * |
|
| 420 | - * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | - * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | - * |
|
| 423 | - * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | - * |
|
| 425 | - * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | - * chaque élément ajouté directement au where par |
|
| 427 | - * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | - * est une condition AND en plus. |
|
| 429 | - * |
|
| 430 | - * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | - * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | - * $expr = array(operateur, val1, val2) |
|
| 433 | - * |
|
| 434 | - * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | - * à réaliser tel que : |
|
| 436 | - * |
|
| 437 | - * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | - * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | - * suivant cet ordre : "val1 operateur val2". |
|
| 440 | - * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | - * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | - * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | - * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | - * Exemples : |
|
| 445 | - * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | - * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | - * |
|
| 448 | - * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | - * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | - * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | - * |
|
| 452 | - * @var array |
|
| 453 | - */ |
|
| 454 | - public $where = array(); |
|
| 455 | - |
|
| 456 | - public $join = array(); |
|
| 457 | - public $having = array(); |
|
| 458 | - public $limit; |
|
| 459 | - public $group = array(); |
|
| 460 | - public $order = array(); |
|
| 461 | - public $default_order = array(); |
|
| 462 | - public $date = 'date'; |
|
| 463 | - public $hash = ""; |
|
| 464 | - public $in = ""; |
|
| 465 | - public $sous_requete = false; |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | - * |
|
| 470 | - * Il sert à insérer le code calculant une hierarchie |
|
| 471 | - * |
|
| 472 | - * @var string |
|
| 473 | - */ |
|
| 474 | - public $hierarchie = ''; |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * Indique la présence d'un critère sur le statut |
|
| 478 | - * |
|
| 479 | - * @deprecated Remplacé par $boucle->modificateur['criteres']['statut'] |
|
| 480 | - * @var bool |
|
| 481 | - */ |
|
| 482 | - public $statut = false; |
|
| 483 | - |
|
| 484 | - // champs pour la construction du corps PHP |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Description des sources de données de la boucle |
|
| 488 | - * |
|
| 489 | - * Description des données de la boucle issu de trouver_table |
|
| 490 | - * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 491 | - * |
|
| 492 | - * @see base_trouver_table_dist() |
|
| 493 | - * @var array |
|
| 494 | - */ |
|
| 495 | - public $show = array(); |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 499 | - * |
|
| 500 | - * @var string |
|
| 501 | - */ |
|
| 502 | - public $id_table; |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 506 | - * |
|
| 507 | - * @var string |
|
| 508 | - */ |
|
| 509 | - public $primary; |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Code PHP compilé de la boucle |
|
| 513 | - * |
|
| 514 | - * @var string |
|
| 515 | - */ |
|
| 516 | - public $return; |
|
| 517 | - |
|
| 518 | - public $numrows = false; |
|
| 519 | - public $cptrows = false; |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Description du squelette |
|
| 523 | - * |
|
| 524 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 525 | - * |
|
| 526 | - * Peut contenir les index : |
|
| 527 | - * |
|
| 528 | - * - nom : Nom du fichier de cache |
|
| 529 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 530 | - * - sourcefile : Chemin du squelette |
|
| 531 | - * - squelette : Code du squelette |
|
| 532 | - * - id_mere : Identifiant de la boucle parente |
|
| 533 | - * - documents : Pour embed et img dans les textes |
|
| 534 | - * - session : Pour un cache sessionné par auteur |
|
| 535 | - * - niv : Niveau de tabulation |
|
| 536 | - * |
|
| 537 | - * @var array |
|
| 538 | - */ |
|
| 539 | - public $descr = array(); |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Numéro de ligne dans le code source du squelette |
|
| 543 | - * |
|
| 544 | - * @var int |
|
| 545 | - */ |
|
| 546 | - public $ligne = 0; |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - public $modificateur = array(); // table pour stocker les modificateurs de boucle tels que tout, plat ..., utilisable par les plugins egalement |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Type d'itérateur utilisé pour cette boucle |
|
| 553 | - * |
|
| 554 | - * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 555 | - * - 'DATA' pour l'itérateur DATA, ... |
|
| 556 | - * |
|
| 557 | - * @var string |
|
| 558 | - */ |
|
| 559 | - public $iterateur = ''; // type d'iterateur |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 563 | - */ |
|
| 564 | - public $debug = []; |
|
| 565 | - |
|
| 566 | - // obsoletes, conserves provisoirement pour compatibilite |
|
| 567 | - public $tout = false; |
|
| 568 | - public $plat = false; |
|
| 569 | - public $lien = false; |
|
| 192 | + /** |
|
| 193 | + * Type de noeud |
|
| 194 | + * |
|
| 195 | + * @var string |
|
| 196 | + */ |
|
| 197 | + public $type = 'boucle'; |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Identifiant de la boucle |
|
| 201 | + * |
|
| 202 | + * @var string |
|
| 203 | + */ |
|
| 204 | + public $id_boucle; |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Identifiant de la boucle parente |
|
| 208 | + * |
|
| 209 | + * @var string |
|
| 210 | + */ |
|
| 211 | + public $id_parent = ''; |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Partie avant toujours affichee |
|
| 215 | + * |
|
| 216 | + * @var string|array |
|
| 217 | + */ |
|
| 218 | + public $preaff = ''; |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Partie optionnelle avant |
|
| 222 | + * |
|
| 223 | + * @var string|array |
|
| 224 | + */ |
|
| 225 | + public $avant = ''; |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Pour chaque élément |
|
| 229 | + * |
|
| 230 | + * @var string|array |
|
| 231 | + */ |
|
| 232 | + public $milieu = ''; |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Partie optionnelle après |
|
| 236 | + * |
|
| 237 | + * @var string|array |
|
| 238 | + */ |
|
| 239 | + public $apres = ''; |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | + * |
|
| 244 | + * @var string|array |
|
| 245 | + */ |
|
| 246 | + public $altern = ''; |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Partie apres toujours affichee |
|
| 250 | + * |
|
| 251 | + * @var string|array |
|
| 252 | + */ |
|
| 253 | + public $postaff = ''; |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * La boucle doit-elle sélectionner la langue ? |
|
| 258 | + * |
|
| 259 | + * @var string|null |
|
| 260 | + */ |
|
| 261 | + public $lang_select; |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | + * |
|
| 266 | + * @var string|null |
|
| 267 | + */ |
|
| 268 | + public $type_requete; |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * La table est elle optionnelle ? |
|
| 272 | + * |
|
| 273 | + * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | + * |
|
| 275 | + * @var bool |
|
| 276 | + */ |
|
| 277 | + public $table_optionnelle = false; |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Nom du fichier de connexion |
|
| 281 | + * |
|
| 282 | + * @var string |
|
| 283 | + */ |
|
| 284 | + public $sql_serveur = ''; |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Paramètres de la boucle |
|
| 288 | + * |
|
| 289 | + * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | + * au calcul des critères |
|
| 291 | + * |
|
| 292 | + * @var array |
|
| 293 | + */ |
|
| 294 | + public $param = array(); |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Critères de la boucle |
|
| 298 | + * |
|
| 299 | + * @var Critere[] |
|
| 300 | + */ |
|
| 301 | + public $criteres = array(); |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | + * |
|
| 306 | + * @var string[] |
|
| 307 | + */ |
|
| 308 | + public $separateur = array(); |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Liste des jointures possibles avec cette table |
|
| 312 | + * |
|
| 313 | + * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | + * des jointures déclarées explicitement sur la boucle |
|
| 315 | + * |
|
| 316 | + * @see base_trouver_table_dist() |
|
| 317 | + * @var array |
|
| 318 | + */ |
|
| 319 | + public $jointures = array(); |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Jointures explicites avec cette table |
|
| 323 | + * |
|
| 324 | + * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | + * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | + * à la boucle. |
|
| 327 | + * |
|
| 328 | + * @var string|bool |
|
| 329 | + */ |
|
| 330 | + public $jointures_explicites = false; |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | + * |
|
| 335 | + * @var string|null |
|
| 336 | + */ |
|
| 337 | + public $doublons; |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | + * |
|
| 342 | + * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | + * |
|
| 344 | + * @var string |
|
| 345 | + */ |
|
| 346 | + public $partie = ""; |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | + * ou de soustractions d'éléments à faire |
|
| 351 | + * |
|
| 352 | + * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | + * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | + * |
|
| 355 | + * @var string |
|
| 356 | + */ |
|
| 357 | + public $total_parties = ""; |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | + * |
|
| 362 | + * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | + * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | + * |
|
| 365 | + * @var string |
|
| 366 | + */ |
|
| 367 | + public $mode_partie = ''; |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | + * |
|
| 372 | + * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | + * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | + * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | + * de l'appelant (rec) |
|
| 376 | + * |
|
| 377 | + * @var string |
|
| 378 | + */ |
|
| 379 | + public $externe = ''; |
|
| 380 | + |
|
| 381 | + // champs pour la construction de la requete SQL |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Liste des champs à récupérer par la boucle |
|
| 385 | + * |
|
| 386 | + * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | + * |
|
| 388 | + * @var string[] |
|
| 389 | + */ |
|
| 390 | + public $select = array(); |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | + * |
|
| 395 | + * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | + * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | + * |
|
| 398 | + * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | + * |
|
| 400 | + * @var string[] |
|
| 401 | + */ |
|
| 402 | + public $from = array(); |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | + * |
|
| 407 | + * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | + * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | + * |
|
| 410 | + * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | + * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | + * |
|
| 413 | + * @var string[] |
|
| 414 | + */ |
|
| 415 | + public $from_type = array(); |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Liste des conditions WHERE de la boucle |
|
| 419 | + * |
|
| 420 | + * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | + * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | + * |
|
| 423 | + * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | + * |
|
| 425 | + * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | + * chaque élément ajouté directement au where par |
|
| 427 | + * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | + * est une condition AND en plus. |
|
| 429 | + * |
|
| 430 | + * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | + * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | + * $expr = array(operateur, val1, val2) |
|
| 433 | + * |
|
| 434 | + * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | + * à réaliser tel que : |
|
| 436 | + * |
|
| 437 | + * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | + * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | + * suivant cet ordre : "val1 operateur val2". |
|
| 440 | + * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | + * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | + * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | + * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | + * Exemples : |
|
| 445 | + * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | + * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | + * |
|
| 448 | + * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | + * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | + * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | + * |
|
| 452 | + * @var array |
|
| 453 | + */ |
|
| 454 | + public $where = array(); |
|
| 455 | + |
|
| 456 | + public $join = array(); |
|
| 457 | + public $having = array(); |
|
| 458 | + public $limit; |
|
| 459 | + public $group = array(); |
|
| 460 | + public $order = array(); |
|
| 461 | + public $default_order = array(); |
|
| 462 | + public $date = 'date'; |
|
| 463 | + public $hash = ""; |
|
| 464 | + public $in = ""; |
|
| 465 | + public $sous_requete = false; |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | + * |
|
| 470 | + * Il sert à insérer le code calculant une hierarchie |
|
| 471 | + * |
|
| 472 | + * @var string |
|
| 473 | + */ |
|
| 474 | + public $hierarchie = ''; |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * Indique la présence d'un critère sur le statut |
|
| 478 | + * |
|
| 479 | + * @deprecated Remplacé par $boucle->modificateur['criteres']['statut'] |
|
| 480 | + * @var bool |
|
| 481 | + */ |
|
| 482 | + public $statut = false; |
|
| 483 | + |
|
| 484 | + // champs pour la construction du corps PHP |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Description des sources de données de la boucle |
|
| 488 | + * |
|
| 489 | + * Description des données de la boucle issu de trouver_table |
|
| 490 | + * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 491 | + * |
|
| 492 | + * @see base_trouver_table_dist() |
|
| 493 | + * @var array |
|
| 494 | + */ |
|
| 495 | + public $show = array(); |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 499 | + * |
|
| 500 | + * @var string |
|
| 501 | + */ |
|
| 502 | + public $id_table; |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 506 | + * |
|
| 507 | + * @var string |
|
| 508 | + */ |
|
| 509 | + public $primary; |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Code PHP compilé de la boucle |
|
| 513 | + * |
|
| 514 | + * @var string |
|
| 515 | + */ |
|
| 516 | + public $return; |
|
| 517 | + |
|
| 518 | + public $numrows = false; |
|
| 519 | + public $cptrows = false; |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Description du squelette |
|
| 523 | + * |
|
| 524 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 525 | + * |
|
| 526 | + * Peut contenir les index : |
|
| 527 | + * |
|
| 528 | + * - nom : Nom du fichier de cache |
|
| 529 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 530 | + * - sourcefile : Chemin du squelette |
|
| 531 | + * - squelette : Code du squelette |
|
| 532 | + * - id_mere : Identifiant de la boucle parente |
|
| 533 | + * - documents : Pour embed et img dans les textes |
|
| 534 | + * - session : Pour un cache sessionné par auteur |
|
| 535 | + * - niv : Niveau de tabulation |
|
| 536 | + * |
|
| 537 | + * @var array |
|
| 538 | + */ |
|
| 539 | + public $descr = array(); |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Numéro de ligne dans le code source du squelette |
|
| 543 | + * |
|
| 544 | + * @var int |
|
| 545 | + */ |
|
| 546 | + public $ligne = 0; |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + public $modificateur = array(); // table pour stocker les modificateurs de boucle tels que tout, plat ..., utilisable par les plugins egalement |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Type d'itérateur utilisé pour cette boucle |
|
| 553 | + * |
|
| 554 | + * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 555 | + * - 'DATA' pour l'itérateur DATA, ... |
|
| 556 | + * |
|
| 557 | + * @var string |
|
| 558 | + */ |
|
| 559 | + public $iterateur = ''; // type d'iterateur |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 563 | + */ |
|
| 564 | + public $debug = []; |
|
| 565 | + |
|
| 566 | + // obsoletes, conserves provisoirement pour compatibilite |
|
| 567 | + public $tout = false; |
|
| 568 | + public $plat = false; |
|
| 569 | + public $lien = false; |
|
| 570 | 570 | } |
| 571 | 571 | |
| 572 | 572 | /** |
@@ -577,56 +577,56 @@ discard block |
||
| 577 | 577 | * @package SPIP\Core\Compilateur\AST |
| 578 | 578 | **/ |
| 579 | 579 | class Critere { |
| 580 | - /** |
|
| 581 | - * Type de noeud |
|
| 582 | - * |
|
| 583 | - * @var string |
|
| 584 | - */ |
|
| 585 | - public $type = 'critere'; |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Opérateur (>, <, >=, IN, ...) |
|
| 589 | - * |
|
| 590 | - * @var null|string |
|
| 591 | - */ |
|
| 592 | - public $op; |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * Présence d'une négation (truc !op valeur) |
|
| 596 | - * |
|
| 597 | - * @var null|string |
|
| 598 | - */ |
|
| 599 | - public $not; |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * Présence d'une exclusion (!truc op valeur) |
|
| 603 | - * |
|
| 604 | - * @var null|string |
|
| 605 | - */ |
|
| 606 | - public $exclus; |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * Présence d'une condition dans le critère (truc ?) |
|
| 610 | - * |
|
| 611 | - * @var bool |
|
| 612 | - */ |
|
| 613 | - public $cond = false; |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Paramètres du critère |
|
| 617 | - * - $param[0] : élément avant l'opérateur |
|
| 618 | - * - $param[1..n] : éléments après l'opérateur |
|
| 619 | - * |
|
| 620 | - * @var array |
|
| 621 | - */ |
|
| 622 | - public $param = array(); |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Numéro de ligne dans le code source du squelette |
|
| 626 | - * |
|
| 627 | - * @var int |
|
| 628 | - */ |
|
| 629 | - public $ligne = 0; |
|
| 580 | + /** |
|
| 581 | + * Type de noeud |
|
| 582 | + * |
|
| 583 | + * @var string |
|
| 584 | + */ |
|
| 585 | + public $type = 'critere'; |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Opérateur (>, <, >=, IN, ...) |
|
| 589 | + * |
|
| 590 | + * @var null|string |
|
| 591 | + */ |
|
| 592 | + public $op; |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * Présence d'une négation (truc !op valeur) |
|
| 596 | + * |
|
| 597 | + * @var null|string |
|
| 598 | + */ |
|
| 599 | + public $not; |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * Présence d'une exclusion (!truc op valeur) |
|
| 603 | + * |
|
| 604 | + * @var null|string |
|
| 605 | + */ |
|
| 606 | + public $exclus; |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * Présence d'une condition dans le critère (truc ?) |
|
| 610 | + * |
|
| 611 | + * @var bool |
|
| 612 | + */ |
|
| 613 | + public $cond = false; |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Paramètres du critère |
|
| 617 | + * - $param[0] : élément avant l'opérateur |
|
| 618 | + * - $param[1..n] : éléments après l'opérateur |
|
| 619 | + * |
|
| 620 | + * @var array |
|
| 621 | + */ |
|
| 622 | + public $param = array(); |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * Numéro de ligne dans le code source du squelette |
|
| 626 | + * |
|
| 627 | + * @var int |
|
| 628 | + */ |
|
| 629 | + public $ligne = 0; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -635,139 +635,139 @@ discard block |
||
| 635 | 635 | * @package SPIP\Core\Compilateur\AST |
| 636 | 636 | **/ |
| 637 | 637 | class Champ { |
| 638 | - /** |
|
| 639 | - * Type de noeud |
|
| 640 | - * |
|
| 641 | - * @var string |
|
| 642 | - */ |
|
| 643 | - public $type = 'champ'; |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 647 | - * |
|
| 648 | - * @var string|null |
|
| 649 | - */ |
|
| 650 | - public $nom_champ; |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Identifiant de la boucle parente si explicité |
|
| 654 | - * |
|
| 655 | - * @var string|null |
|
| 656 | - */ |
|
| 657 | - public $nom_boucle = ''; |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Partie optionnelle avant |
|
| 661 | - * |
|
| 662 | - * @var null|string|array |
|
| 663 | - */ |
|
| 664 | - public $avant; |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Partie optionnelle après |
|
| 668 | - * |
|
| 669 | - * @var null|string|array |
|
| 670 | - */ |
|
| 671 | - public $apres; |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Étoiles : annuler des automatismes |
|
| 675 | - * |
|
| 676 | - * - '*' annule les filtres automatiques |
|
| 677 | - * - '**' annule en plus les protections de scripts |
|
| 678 | - * |
|
| 679 | - * @var null|string |
|
| 680 | - */ |
|
| 681 | - public $etoile; |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Arguments et filtres explicites sur la balise |
|
| 685 | - * |
|
| 686 | - * - $param[0] contient les arguments de la balise |
|
| 687 | - * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 688 | - * |
|
| 689 | - * @var array |
|
| 690 | - */ |
|
| 691 | - public $param = array(); |
|
| 692 | - |
|
| 693 | - /** |
|
| 694 | - * Source des filtres (compatibilité) (?) |
|
| 695 | - * |
|
| 696 | - * @var array|null |
|
| 697 | - */ |
|
| 698 | - public $fonctions = array(); |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * Identifiant de la boucle |
|
| 702 | - * |
|
| 703 | - * @var string |
|
| 704 | - */ |
|
| 705 | - public $id_boucle = ''; |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * AST du squelette, liste de toutes les boucles |
|
| 709 | - * |
|
| 710 | - * @var Boucles[] |
|
| 711 | - */ |
|
| 712 | - public $boucles; |
|
| 713 | - |
|
| 714 | - /** |
|
| 715 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 716 | - * |
|
| 717 | - * @var string|null |
|
| 718 | - */ |
|
| 719 | - public $type_requete; |
|
| 720 | - |
|
| 721 | - /** |
|
| 722 | - * Résultat de la compilation: toujours une expression PHP |
|
| 723 | - * |
|
| 724 | - * @var string |
|
| 725 | - */ |
|
| 726 | - public $code = ''; |
|
| 727 | - |
|
| 728 | - /** |
|
| 729 | - * Interdire les scripts |
|
| 730 | - * |
|
| 731 | - * false si on est sûr de cette balise |
|
| 732 | - * |
|
| 733 | - * @see interdire_scripts() |
|
| 734 | - * @var bool |
|
| 735 | - */ |
|
| 736 | - public $interdire_scripts = true; |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * Description du squelette |
|
| 740 | - * |
|
| 741 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 742 | - * |
|
| 743 | - * Peut contenir les index : |
|
| 744 | - * |
|
| 745 | - * - nom : Nom du fichier de cache |
|
| 746 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 747 | - * - sourcefile : Chemin du squelette |
|
| 748 | - * - squelette : Code du squelette |
|
| 749 | - * - id_mere : Identifiant de la boucle parente |
|
| 750 | - * - documents : Pour embed et img dans les textes |
|
| 751 | - * - session : Pour un cache sessionné par auteur |
|
| 752 | - * - niv : Niveau de tabulation |
|
| 753 | - * |
|
| 754 | - * @var array |
|
| 755 | - */ |
|
| 756 | - public $descr = array(); |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * Numéro de ligne dans le code source du squelette |
|
| 760 | - * |
|
| 761 | - * @var int |
|
| 762 | - */ |
|
| 763 | - public $ligne = 0; |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 767 | - * |
|
| 768 | - * @var bool |
|
| 769 | - */ |
|
| 770 | - public $balise_calculee = false; |
|
| 638 | + /** |
|
| 639 | + * Type de noeud |
|
| 640 | + * |
|
| 641 | + * @var string |
|
| 642 | + */ |
|
| 643 | + public $type = 'champ'; |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 647 | + * |
|
| 648 | + * @var string|null |
|
| 649 | + */ |
|
| 650 | + public $nom_champ; |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Identifiant de la boucle parente si explicité |
|
| 654 | + * |
|
| 655 | + * @var string|null |
|
| 656 | + */ |
|
| 657 | + public $nom_boucle = ''; |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Partie optionnelle avant |
|
| 661 | + * |
|
| 662 | + * @var null|string|array |
|
| 663 | + */ |
|
| 664 | + public $avant; |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Partie optionnelle après |
|
| 668 | + * |
|
| 669 | + * @var null|string|array |
|
| 670 | + */ |
|
| 671 | + public $apres; |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * Étoiles : annuler des automatismes |
|
| 675 | + * |
|
| 676 | + * - '*' annule les filtres automatiques |
|
| 677 | + * - '**' annule en plus les protections de scripts |
|
| 678 | + * |
|
| 679 | + * @var null|string |
|
| 680 | + */ |
|
| 681 | + public $etoile; |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Arguments et filtres explicites sur la balise |
|
| 685 | + * |
|
| 686 | + * - $param[0] contient les arguments de la balise |
|
| 687 | + * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 688 | + * |
|
| 689 | + * @var array |
|
| 690 | + */ |
|
| 691 | + public $param = array(); |
|
| 692 | + |
|
| 693 | + /** |
|
| 694 | + * Source des filtres (compatibilité) (?) |
|
| 695 | + * |
|
| 696 | + * @var array|null |
|
| 697 | + */ |
|
| 698 | + public $fonctions = array(); |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * Identifiant de la boucle |
|
| 702 | + * |
|
| 703 | + * @var string |
|
| 704 | + */ |
|
| 705 | + public $id_boucle = ''; |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * AST du squelette, liste de toutes les boucles |
|
| 709 | + * |
|
| 710 | + * @var Boucles[] |
|
| 711 | + */ |
|
| 712 | + public $boucles; |
|
| 713 | + |
|
| 714 | + /** |
|
| 715 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 716 | + * |
|
| 717 | + * @var string|null |
|
| 718 | + */ |
|
| 719 | + public $type_requete; |
|
| 720 | + |
|
| 721 | + /** |
|
| 722 | + * Résultat de la compilation: toujours une expression PHP |
|
| 723 | + * |
|
| 724 | + * @var string |
|
| 725 | + */ |
|
| 726 | + public $code = ''; |
|
| 727 | + |
|
| 728 | + /** |
|
| 729 | + * Interdire les scripts |
|
| 730 | + * |
|
| 731 | + * false si on est sûr de cette balise |
|
| 732 | + * |
|
| 733 | + * @see interdire_scripts() |
|
| 734 | + * @var bool |
|
| 735 | + */ |
|
| 736 | + public $interdire_scripts = true; |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * Description du squelette |
|
| 740 | + * |
|
| 741 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 742 | + * |
|
| 743 | + * Peut contenir les index : |
|
| 744 | + * |
|
| 745 | + * - nom : Nom du fichier de cache |
|
| 746 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 747 | + * - sourcefile : Chemin du squelette |
|
| 748 | + * - squelette : Code du squelette |
|
| 749 | + * - id_mere : Identifiant de la boucle parente |
|
| 750 | + * - documents : Pour embed et img dans les textes |
|
| 751 | + * - session : Pour un cache sessionné par auteur |
|
| 752 | + * - niv : Niveau de tabulation |
|
| 753 | + * |
|
| 754 | + * @var array |
|
| 755 | + */ |
|
| 756 | + public $descr = array(); |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * Numéro de ligne dans le code source du squelette |
|
| 760 | + * |
|
| 761 | + * @var int |
|
| 762 | + */ |
|
| 763 | + public $ligne = 0; |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 767 | + * |
|
| 768 | + * @var bool |
|
| 769 | + */ |
|
| 770 | + public $balise_calculee = false; |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | |
@@ -775,123 +775,123 @@ discard block |
||
| 775 | 775 | * Description d'une chaîne de langue |
| 776 | 776 | **/ |
| 777 | 777 | class Idiome { |
| 778 | - /** |
|
| 779 | - * Type de noeud |
|
| 780 | - * |
|
| 781 | - * @var string |
|
| 782 | - */ |
|
| 783 | - public $type = 'idiome'; |
|
| 784 | - |
|
| 785 | - /** |
|
| 786 | - * Clé de traduction demandée. Exemple 'item_oui' |
|
| 787 | - * |
|
| 788 | - * @var string |
|
| 789 | - */ |
|
| 790 | - public $nom_champ = ""; |
|
| 791 | - |
|
| 792 | - /** |
|
| 793 | - * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 794 | - * |
|
| 795 | - * @var string |
|
| 796 | - */ |
|
| 797 | - public $module = ""; |
|
| 798 | - |
|
| 799 | - /** |
|
| 800 | - * Arguments à passer à la chaîne |
|
| 801 | - * |
|
| 802 | - * @var array |
|
| 803 | - */ |
|
| 804 | - public $arg = array(); |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * Filtres à appliquer au résultat |
|
| 808 | - * |
|
| 809 | - * @var array |
|
| 810 | - */ |
|
| 811 | - public $param = array(); |
|
| 812 | - |
|
| 813 | - /** |
|
| 814 | - * Source des filtres (compatibilité) (?) |
|
| 815 | - * |
|
| 816 | - * @var array|null |
|
| 817 | - */ |
|
| 818 | - public $fonctions = array(); |
|
| 819 | - |
|
| 820 | - /** |
|
| 821 | - * Inutilisé, propriété générique de l'AST |
|
| 822 | - * |
|
| 823 | - * @var string|array |
|
| 824 | - */ |
|
| 825 | - public $avant = ''; |
|
| 826 | - |
|
| 827 | - /** |
|
| 828 | - * Inutilisé, propriété générique de l'AST |
|
| 829 | - * |
|
| 830 | - * @var string|array |
|
| 831 | - */ |
|
| 832 | - public $apres = ''; |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * Identifiant de la boucle |
|
| 836 | - * |
|
| 837 | - * @var string |
|
| 838 | - */ |
|
| 839 | - public $id_boucle = ''; |
|
| 840 | - |
|
| 841 | - /** |
|
| 842 | - * AST du squelette, liste de toutes les boucles |
|
| 843 | - * |
|
| 844 | - * @var Boucles[] |
|
| 845 | - */ |
|
| 846 | - public $boucles; |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 850 | - * |
|
| 851 | - * @var string|null |
|
| 852 | - */ |
|
| 853 | - public $type_requete; |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * Résultat de la compilation: toujours une expression PHP |
|
| 857 | - * |
|
| 858 | - * @var string |
|
| 859 | - */ |
|
| 860 | - public $code = ''; |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * Interdire les scripts |
|
| 864 | - * |
|
| 865 | - * @see interdire_scripts() |
|
| 866 | - * @var bool |
|
| 867 | - */ |
|
| 868 | - public $interdire_scripts = false; |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Description du squelette |
|
| 872 | - * |
|
| 873 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 874 | - * |
|
| 875 | - * Peut contenir les index : |
|
| 876 | - * - nom : Nom du fichier de cache |
|
| 877 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 878 | - * - sourcefile : Chemin du squelette |
|
| 879 | - * - squelette : Code du squelette |
|
| 880 | - * - id_mere : Identifiant de la boucle parente |
|
| 881 | - * - documents : Pour embed et img dans les textes |
|
| 882 | - * - session : Pour un cache sessionné par auteur |
|
| 883 | - * - niv : Niveau de tabulation |
|
| 884 | - * |
|
| 885 | - * @var array |
|
| 886 | - */ |
|
| 887 | - public $descr = array(); |
|
| 888 | - |
|
| 889 | - /** |
|
| 890 | - * Numéro de ligne dans le code source du squelette |
|
| 891 | - * |
|
| 892 | - * @var int |
|
| 893 | - */ |
|
| 894 | - public $ligne = 0; |
|
| 778 | + /** |
|
| 779 | + * Type de noeud |
|
| 780 | + * |
|
| 781 | + * @var string |
|
| 782 | + */ |
|
| 783 | + public $type = 'idiome'; |
|
| 784 | + |
|
| 785 | + /** |
|
| 786 | + * Clé de traduction demandée. Exemple 'item_oui' |
|
| 787 | + * |
|
| 788 | + * @var string |
|
| 789 | + */ |
|
| 790 | + public $nom_champ = ""; |
|
| 791 | + |
|
| 792 | + /** |
|
| 793 | + * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 794 | + * |
|
| 795 | + * @var string |
|
| 796 | + */ |
|
| 797 | + public $module = ""; |
|
| 798 | + |
|
| 799 | + /** |
|
| 800 | + * Arguments à passer à la chaîne |
|
| 801 | + * |
|
| 802 | + * @var array |
|
| 803 | + */ |
|
| 804 | + public $arg = array(); |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * Filtres à appliquer au résultat |
|
| 808 | + * |
|
| 809 | + * @var array |
|
| 810 | + */ |
|
| 811 | + public $param = array(); |
|
| 812 | + |
|
| 813 | + /** |
|
| 814 | + * Source des filtres (compatibilité) (?) |
|
| 815 | + * |
|
| 816 | + * @var array|null |
|
| 817 | + */ |
|
| 818 | + public $fonctions = array(); |
|
| 819 | + |
|
| 820 | + /** |
|
| 821 | + * Inutilisé, propriété générique de l'AST |
|
| 822 | + * |
|
| 823 | + * @var string|array |
|
| 824 | + */ |
|
| 825 | + public $avant = ''; |
|
| 826 | + |
|
| 827 | + /** |
|
| 828 | + * Inutilisé, propriété générique de l'AST |
|
| 829 | + * |
|
| 830 | + * @var string|array |
|
| 831 | + */ |
|
| 832 | + public $apres = ''; |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * Identifiant de la boucle |
|
| 836 | + * |
|
| 837 | + * @var string |
|
| 838 | + */ |
|
| 839 | + public $id_boucle = ''; |
|
| 840 | + |
|
| 841 | + /** |
|
| 842 | + * AST du squelette, liste de toutes les boucles |
|
| 843 | + * |
|
| 844 | + * @var Boucles[] |
|
| 845 | + */ |
|
| 846 | + public $boucles; |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 850 | + * |
|
| 851 | + * @var string|null |
|
| 852 | + */ |
|
| 853 | + public $type_requete; |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * Résultat de la compilation: toujours une expression PHP |
|
| 857 | + * |
|
| 858 | + * @var string |
|
| 859 | + */ |
|
| 860 | + public $code = ''; |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * Interdire les scripts |
|
| 864 | + * |
|
| 865 | + * @see interdire_scripts() |
|
| 866 | + * @var bool |
|
| 867 | + */ |
|
| 868 | + public $interdire_scripts = false; |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Description du squelette |
|
| 872 | + * |
|
| 873 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 874 | + * |
|
| 875 | + * Peut contenir les index : |
|
| 876 | + * - nom : Nom du fichier de cache |
|
| 877 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 878 | + * - sourcefile : Chemin du squelette |
|
| 879 | + * - squelette : Code du squelette |
|
| 880 | + * - id_mere : Identifiant de la boucle parente |
|
| 881 | + * - documents : Pour embed et img dans les textes |
|
| 882 | + * - session : Pour un cache sessionné par auteur |
|
| 883 | + * - niv : Niveau de tabulation |
|
| 884 | + * |
|
| 885 | + * @var array |
|
| 886 | + */ |
|
| 887 | + public $descr = array(); |
|
| 888 | + |
|
| 889 | + /** |
|
| 890 | + * Numéro de ligne dans le code source du squelette |
|
| 891 | + * |
|
| 892 | + * @var int |
|
| 893 | + */ |
|
| 894 | + public $ligne = 0; |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | /** |
@@ -900,28 +900,28 @@ discard block |
||
| 900 | 900 | * @package SPIP\Core\Compilateur\AST |
| 901 | 901 | **/ |
| 902 | 902 | class Polyglotte { |
| 903 | - /** |
|
| 904 | - * Type de noeud |
|
| 905 | - * |
|
| 906 | - * @var string |
|
| 907 | - */ |
|
| 908 | - public $type = 'polyglotte'; |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * Tableau des traductions possibles classées par langue |
|
| 912 | - * |
|
| 913 | - * Tableau code de langue => texte |
|
| 914 | - * |
|
| 915 | - * @var array |
|
| 916 | - */ |
|
| 917 | - public $traductions = array(); |
|
| 918 | - |
|
| 919 | - /** |
|
| 920 | - * Numéro de ligne dans le code source du squelette |
|
| 921 | - * |
|
| 922 | - * @var int |
|
| 923 | - */ |
|
| 924 | - public $ligne = 0; |
|
| 903 | + /** |
|
| 904 | + * Type de noeud |
|
| 905 | + * |
|
| 906 | + * @var string |
|
| 907 | + */ |
|
| 908 | + public $type = 'polyglotte'; |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * Tableau des traductions possibles classées par langue |
|
| 912 | + * |
|
| 913 | + * Tableau code de langue => texte |
|
| 914 | + * |
|
| 915 | + * @var array |
|
| 916 | + */ |
|
| 917 | + public $traductions = array(); |
|
| 918 | + |
|
| 919 | + /** |
|
| 920 | + * Numéro de ligne dans le code source du squelette |
|
| 921 | + * |
|
| 922 | + * @var int |
|
| 923 | + */ |
|
| 924 | + public $ligne = 0; |
|
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | |
@@ -946,80 +946,80 @@ discard block |
||
| 946 | 946 | */ |
| 947 | 947 | function declarer_interfaces() { |
| 948 | 948 | |
| 949 | - $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 950 | - $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 951 | - $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 952 | - $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 953 | - |
|
| 954 | - // definition des statuts de publication |
|
| 955 | - $GLOBALS['table_statut'] = array(); |
|
| 956 | - |
|
| 957 | - // |
|
| 958 | - // tableau des tables de jointures |
|
| 959 | - // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 960 | - $GLOBALS['tables_jointures'] = array(); |
|
| 961 | - $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 962 | - |
|
| 963 | - // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 964 | - $GLOBALS['exceptions_des_jointures']['profondeur'] = array('spip_rubriques', 'profondeur'); |
|
| 965 | - |
|
| 966 | - define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 967 | - define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 968 | - define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s), "TYPO", $connect, $Pile[0])'); |
|
| 969 | - |
|
| 970 | - $GLOBALS['table_des_traitements']['BIO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 971 | - $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 972 | - $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 973 | - $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 974 | - $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 975 | - $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 976 | - $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 977 | - $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 978 | - $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 979 | - $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 980 | - $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 981 | - $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 982 | - $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 983 | - $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 984 | - $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 985 | - $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 986 | - $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 987 | - $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 988 | - $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 989 | - $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 990 | - $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 991 | - $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 992 | - |
|
| 993 | - // valeur par defaut pour les balises non listees ci-dessus |
|
| 994 | - $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 995 | - // toujours securiser les DATA |
|
| 996 | - $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 997 | - // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 998 | - $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1002 | - $interfaces = pipeline('declarer_tables_interfaces', |
|
| 1003 | - array( |
|
| 1004 | - 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1005 | - 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1006 | - 'table_date' => $GLOBALS['table_date'], |
|
| 1007 | - 'table_titre' => $GLOBALS['table_titre'], |
|
| 1008 | - 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1009 | - 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1010 | - 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1011 | - 'table_statut' => $GLOBALS['table_statut'], |
|
| 1012 | - )); |
|
| 1013 | - if ($interfaces) { |
|
| 1014 | - $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1015 | - $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1016 | - $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1017 | - $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1018 | - $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1019 | - $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1020 | - $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1021 | - $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1022 | - } |
|
| 949 | + $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 950 | + $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 951 | + $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 952 | + $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 953 | + |
|
| 954 | + // definition des statuts de publication |
|
| 955 | + $GLOBALS['table_statut'] = array(); |
|
| 956 | + |
|
| 957 | + // |
|
| 958 | + // tableau des tables de jointures |
|
| 959 | + // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 960 | + $GLOBALS['tables_jointures'] = array(); |
|
| 961 | + $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 962 | + |
|
| 963 | + // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 964 | + $GLOBALS['exceptions_des_jointures']['profondeur'] = array('spip_rubriques', 'profondeur'); |
|
| 965 | + |
|
| 966 | + define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 967 | + define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 968 | + define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s), "TYPO", $connect, $Pile[0])'); |
|
| 969 | + |
|
| 970 | + $GLOBALS['table_des_traitements']['BIO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 971 | + $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 972 | + $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 973 | + $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 974 | + $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 975 | + $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 976 | + $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 977 | + $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 978 | + $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 979 | + $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 980 | + $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 981 | + $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 982 | + $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 983 | + $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 984 | + $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 985 | + $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 986 | + $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 987 | + $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 988 | + $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 989 | + $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 990 | + $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 991 | + $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 992 | + |
|
| 993 | + // valeur par defaut pour les balises non listees ci-dessus |
|
| 994 | + $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 995 | + // toujours securiser les DATA |
|
| 996 | + $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 997 | + // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 998 | + $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1002 | + $interfaces = pipeline('declarer_tables_interfaces', |
|
| 1003 | + array( |
|
| 1004 | + 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1005 | + 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1006 | + 'table_date' => $GLOBALS['table_date'], |
|
| 1007 | + 'table_titre' => $GLOBALS['table_titre'], |
|
| 1008 | + 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1009 | + 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1010 | + 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1011 | + 'table_statut' => $GLOBALS['table_statut'], |
|
| 1012 | + )); |
|
| 1013 | + if ($interfaces) { |
|
| 1014 | + $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1015 | + $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1016 | + $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1017 | + $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1018 | + $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1019 | + $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1020 | + $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1021 | + $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1022 | + } |
|
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | 1025 | declarer_interfaces(); |
@@ -11,126 +11,126 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ""; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ""; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = " />"; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ""; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ""; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ""; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ""; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ""; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = " />"; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ("(" . $file . ")") : ""; |
|
| 35 | - } else { |
|
| 36 | - $t = "{fond=" . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ("{" . join(", ", $args) . "}"); |
|
| 39 | - |
|
| 40 | - return ("<INCLURE" . $t . $args . ">"); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ("(" . $file . ")") : ""; |
|
| 35 | + } else { |
|
| 36 | + $t = "{fond=" . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ("{" . join(", ", $args) . "}"); |
|
| 39 | + |
|
| 40 | + return ("<INCLURE" . $t . $args . ">"); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = array(); |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = array(); |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 49 | + return ("<multi>" . join(" ", $contenu) . "</multi>"); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 58 | + return ("<:" . ($module ? "$module:" : "") . $nom . $args . $filtres . ":>"); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = "#" |
|
| 63 | - . ($boucle ? ($boucle . ":") : "") |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = "#" |
|
| 63 | + . ($boucle ? ($boucle . ":") : "") |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - list($type, $valeur) = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + list($type, $valeur) = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? "" : ("{" . join(",", $critere) . "}")); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? "" : ("{" . join(",", $args) . "}"))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | - list($texte, $type) = $args[$i]; |
|
| 105 | - list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 124 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 125 | - ) { |
|
| 126 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return join("", array_map('array_shift', $args)); |
|
| 103 | + for ($i = 0; $i < count($args) - 1; $i++) { |
|
| 104 | + list($texte, $type) = $args[$i]; |
|
| 105 | + list($texte2, $type2) = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if (($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 124 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 125 | + ) { |
|
| 126 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return join("", array_map('array_shift', $args)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | function format_texte_html($texte) { |
| 135 | - return $texte; |
|
| 135 | + return $texte; |
|
| 136 | 136 | } |
@@ -11,129 +11,129 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | - $struct->table_optionnelle); |
|
| 31 | - |
|
| 32 | - if ($struct->jointures_explicites) { |
|
| 33 | - $type .= " " . $struct->jointures_explicites; |
|
| 34 | - } |
|
| 35 | - if ($struct->table_optionnelle) { |
|
| 36 | - $type .= "?"; |
|
| 37 | - } |
|
| 38 | - // Revoir le cas de la boucle recursive |
|
| 39 | - |
|
| 40 | - $crit = $struct->param; |
|
| 41 | - if ($crit and !is_array($crit[0])) { |
|
| 42 | - $type = strtolower($type) . array_shift($crit); |
|
| 43 | - } |
|
| 44 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | - |
|
| 46 | - $f = 'format_boucle_' . $fmt; |
|
| 47 | - |
|
| 48 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | + $struct->table_optionnelle); |
|
| 31 | + |
|
| 32 | + if ($struct->jointures_explicites) { |
|
| 33 | + $type .= " " . $struct->jointures_explicites; |
|
| 34 | + } |
|
| 35 | + if ($struct->table_optionnelle) { |
|
| 36 | + $type .= "?"; |
|
| 37 | + } |
|
| 38 | + // Revoir le cas de la boucle recursive |
|
| 39 | + |
|
| 40 | + $crit = $struct->param; |
|
| 41 | + if ($crit and !is_array($crit[0])) { |
|
| 42 | + $type = strtolower($type) . array_shift($crit); |
|
| 43 | + } |
|
| 44 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 45 | + |
|
| 46 | + $f = 'format_boucle_' . $fmt; |
|
| 47 | + |
|
| 48 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 52 | - $res = array(); |
|
| 53 | - foreach ($struct->param ? $struct->param : array() as $couple) { |
|
| 54 | - array_shift($couple); |
|
| 55 | - foreach ($couple as $v) { |
|
| 56 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | - $f = 'format_inclure_' . $fmt; |
|
| 62 | - |
|
| 63 | - return $f($file, $res, $prof); |
|
| 52 | + $res = array(); |
|
| 53 | + foreach ($struct->param ? $struct->param : array() as $couple) { |
|
| 54 | + array_shift($couple); |
|
| 55 | + foreach ($couple as $v) { |
|
| 56 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | + $f = 'format_inclure_' . $fmt; |
|
| 62 | + |
|
| 63 | + return $f($file, $res, $prof); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 67 | - $f = 'format_texte_' . $fmt; |
|
| 67 | + $f = 'format_texte_' . $fmt; |
|
| 68 | 68 | |
| 69 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 73 | - $f = 'format_polyglotte_' . $fmt; |
|
| 73 | + $f = 'format_polyglotte_' . $fmt; |
|
| 74 | 74 | |
| 75 | - return $f($struct->traductions, $prof); |
|
| 75 | + return $f($struct->traductions, $prof); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 79 | - $args = array(); |
|
| 80 | - foreach ($struct->arg as $k => $v) { |
|
| 81 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | - } |
|
| 79 | + $args = array(); |
|
| 80 | + foreach ($struct->arg as $k => $v) { |
|
| 81 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 85 | 85 | |
| 86 | - $f = 'format_idiome_' . $fmt; |
|
| 86 | + $f = 'format_idiome_' . $fmt; |
|
| 87 | 87 | |
| 88 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 92 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | - $args = $filtres = ''; |
|
| 95 | - if ($p = $struct->param) { |
|
| 96 | - if ($p[0][0] === '') { |
|
| 97 | - $args = decompiler_liste(array(array_shift($p)), $fmt, $prof); |
|
| 98 | - } |
|
| 99 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | - } |
|
| 101 | - $f = 'format_champ_' . $fmt; |
|
| 102 | - |
|
| 103 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 92 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 93 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 94 | + $args = $filtres = ''; |
|
| 95 | + if ($p = $struct->param) { |
|
| 96 | + if ($p[0][0] === '') { |
|
| 97 | + $args = decompiler_liste(array(array_shift($p)), $fmt, $prof); |
|
| 98 | + } |
|
| 99 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 100 | + } |
|
| 101 | + $f = 'format_champ_' . $fmt; |
|
| 102 | + |
|
| 103 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 107 | - if (!is_array($sources)) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - $f = 'format_liste_' . $fmt; |
|
| 111 | - $res = ''; |
|
| 112 | - foreach ($sources as $arg) { |
|
| 113 | - if (!is_array($arg)) { |
|
| 114 | - continue; // ne devrait pas arriver. |
|
| 115 | - } else { |
|
| 116 | - $r = array_shift($arg); |
|
| 117 | - } |
|
| 118 | - $args = array(); |
|
| 119 | - foreach ($arg as $v) { |
|
| 120 | - // cas des arguments entoures de ' ou " |
|
| 121 | - if ((count($v) == 1) |
|
| 122 | - and $v[0]->type == 'texte' |
|
| 123 | - and (strlen($v[0]->apres) == 1) |
|
| 124 | - and $v[0]->apres == $v[0]->avant |
|
| 125 | - ) { |
|
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | - } else { |
|
| 128 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (($r !== '') or $args) { |
|
| 132 | - $res .= $f($r, $args, $prof); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $res; |
|
| 107 | + if (!is_array($sources)) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + $f = 'format_liste_' . $fmt; |
|
| 111 | + $res = ''; |
|
| 112 | + foreach ($sources as $arg) { |
|
| 113 | + if (!is_array($arg)) { |
|
| 114 | + continue; // ne devrait pas arriver. |
|
| 115 | + } else { |
|
| 116 | + $r = array_shift($arg); |
|
| 117 | + } |
|
| 118 | + $args = array(); |
|
| 119 | + foreach ($arg as $v) { |
|
| 120 | + // cas des arguments entoures de ' ou " |
|
| 121 | + if ((count($v) == 1) |
|
| 122 | + and $v[0]->type == 'texte' |
|
| 123 | + and (strlen($v[0]->apres) == 1) |
|
| 124 | + and $v[0]->apres == $v[0]->avant |
|
| 125 | + ) { |
|
| 126 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | + } else { |
|
| 128 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (($r !== '') or $args) { |
|
| 132 | + $res .= $f($r, $args, $prof); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $res; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Decompilation des criteres: on triche et on deroge: |
@@ -141,91 +141,91 @@ discard block |
||
| 141 | 141 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 142 | 142 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 143 | 143 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 144 | - $sources = $boucle->param; |
|
| 145 | - if (!is_array($sources)) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $res = ''; |
|
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 150 | - foreach ($sources as $crit) { |
|
| 151 | - if (!is_array($crit)) { |
|
| 152 | - continue; |
|
| 153 | - } // boucle recursive |
|
| 154 | - array_shift($crit); |
|
| 155 | - $args = array(); |
|
| 156 | - foreach ($crit as $i => $v) { |
|
| 157 | - if ((count($v) == 1) |
|
| 158 | - and $v[0]->type == 'texte' |
|
| 159 | - and $v[0]->apres |
|
| 160 | - ) { |
|
| 161 | - $args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 162 | - } else { |
|
| 163 | - $res2 = array(); |
|
| 164 | - foreach ($v as $k => $p) { |
|
| 165 | - if (isset($p->type) |
|
| 166 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | - ) { |
|
| 168 | - $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 169 | - $res2[] = array($p->type, $r); |
|
| 170 | - } else { |
|
| 171 | - spip_log("critere $i / $k mal forme"); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - $args[] = $res2; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - $res .= $f($args); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $res; |
|
| 144 | + $sources = $boucle->param; |
|
| 145 | + if (!is_array($sources)) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $res = ''; |
|
| 149 | + $f = 'format_critere_' . $fmt; |
|
| 150 | + foreach ($sources as $crit) { |
|
| 151 | + if (!is_array($crit)) { |
|
| 152 | + continue; |
|
| 153 | + } // boucle recursive |
|
| 154 | + array_shift($crit); |
|
| 155 | + $args = array(); |
|
| 156 | + foreach ($crit as $i => $v) { |
|
| 157 | + if ((count($v) == 1) |
|
| 158 | + and $v[0]->type == 'texte' |
|
| 159 | + and $v[0]->apres |
|
| 160 | + ) { |
|
| 161 | + $args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 162 | + } else { |
|
| 163 | + $res2 = array(); |
|
| 164 | + foreach ($v as $k => $p) { |
|
| 165 | + if (isset($p->type) |
|
| 166 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | + ) { |
|
| 168 | + $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
|
| 169 | + $res2[] = array($p->type, $r); |
|
| 170 | + } else { |
|
| 171 | + spip_log("critere $i / $k mal forme"); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + $args[] = $res2; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + $res .= $f($args); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $res; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 185 | - if (!is_array($liste)) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 189 | - $contenu = array(); |
|
| 190 | - foreach ($liste as $k => $p) { |
|
| 191 | - if (!isset($p->type)) { |
|
| 192 | - continue; |
|
| 193 | - } #?????? |
|
| 194 | - $d = 'decompiler_' . $p->type; |
|
| 195 | - $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 196 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 197 | - // contenait des args et s'il est suivi d'espaces, |
|
| 198 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 199 | - |
|
| 200 | - if ($next |
|
| 201 | - and ($next->type == 'texte') |
|
| 202 | - and $p->type == 'champ' |
|
| 203 | - and !$p->apres |
|
| 204 | - and !$p->avant |
|
| 205 | - and $p->fonctions |
|
| 206 | - ) { |
|
| 207 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 208 | - if ($n) { |
|
| 209 | - $champ = new Texte; |
|
| 210 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 211 | - $champ->ligne = $p->ligne; |
|
| 212 | - $p->apres = array($champ); |
|
| 213 | - $next->texte = substr($next->texte, $n); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
|
| 217 | - |
|
| 218 | - } |
|
| 219 | - $f = 'format_suite_' . $fmt; |
|
| 220 | - |
|
| 221 | - return $f($contenu); |
|
| 185 | + if (!is_array($liste)) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 189 | + $contenu = array(); |
|
| 190 | + foreach ($liste as $k => $p) { |
|
| 191 | + if (!isset($p->type)) { |
|
| 192 | + continue; |
|
| 193 | + } #?????? |
|
| 194 | + $d = 'decompiler_' . $p->type; |
|
| 195 | + $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
|
| 196 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 197 | + // contenait des args et s'il est suivi d'espaces, |
|
| 198 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 199 | + |
|
| 200 | + if ($next |
|
| 201 | + and ($next->type == 'texte') |
|
| 202 | + and $p->type == 'champ' |
|
| 203 | + and !$p->apres |
|
| 204 | + and !$p->avant |
|
| 205 | + and $p->fonctions |
|
| 206 | + ) { |
|
| 207 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 208 | + if ($n) { |
|
| 209 | + $champ = new Texte; |
|
| 210 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 211 | + $champ->ligne = $p->ligne; |
|
| 212 | + $p->apres = array($champ); |
|
| 213 | + $next->texte = substr($next->texte, $n); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
|
| 217 | + |
|
| 218 | + } |
|
| 219 | + $f = 'format_suite_' . $fmt; |
|
| 220 | + |
|
| 221 | + return $f($contenu); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 225 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | - return "'$fmt'?"; |
|
| 227 | - } |
|
| 228 | - $f = 'decompiler_' . $quoi; |
|
| 225 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | + return "'$fmt'?"; |
|
| 227 | + } |
|
| 228 | + $f = 'decompiler_' . $quoi; |
|
| 229 | 229 | |
| 230 | - return $f($liste, $fmt, $prof); |
|
| 230 | + return $f($liste, $fmt, $prof); |
|
| 231 | 231 | } |
@@ -26,11 +26,10 @@ discard block |
||
| 26 | 26 | $postaff = decompiler_($struct->postaff, $fmt, $prof); |
| 27 | 27 | |
| 28 | 28 | $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
| 29 | - $type .= ($struct->type_requete ? $struct->type_requete : |
|
| 30 | - $struct->table_optionnelle); |
|
| 29 | + $type .= ($struct->type_requete ? $struct->type_requete : $struct->table_optionnelle); |
|
| 31 | 30 | |
| 32 | 31 | if ($struct->jointures_explicites) { |
| 33 | - $type .= " " . $struct->jointures_explicites; |
|
| 32 | + $type .= " ".$struct->jointures_explicites; |
|
| 34 | 33 | } |
| 35 | 34 | if ($struct->table_optionnelle) { |
| 36 | 35 | $type .= "?"; |
@@ -39,11 +38,11 @@ discard block |
||
| 39 | 38 | |
| 40 | 39 | $crit = $struct->param; |
| 41 | 40 | if ($crit and !is_array($crit[0])) { |
| 42 | - $type = strtolower($type) . array_shift($crit); |
|
| 41 | + $type = strtolower($type).array_shift($crit); |
|
| 43 | 42 | } |
| 44 | 43 | $crit = decompiler_criteres($struct, $fmt, $prof); |
| 45 | 44 | |
| 46 | - $f = 'format_boucle_' . $fmt; |
|
| 45 | + $f = 'format_boucle_'.$fmt; |
|
| 47 | 46 | |
| 48 | 47 | return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
| 49 | 48 | } |
@@ -56,21 +55,20 @@ discard block |
||
| 56 | 55 | $res[] = decompiler_($v, $fmt, $prof); |
| 57 | 56 | } |
| 58 | 57 | } |
| 59 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 60 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 61 | - $f = 'format_inclure_' . $fmt; |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : decompiler_($struct->texte, $fmt, $prof); |
|
| 59 | + $f = 'format_inclure_'.$fmt; |
|
| 62 | 60 | |
| 63 | 61 | return $f($file, $res, $prof); |
| 64 | 62 | } |
| 65 | 63 | |
| 66 | 64 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 67 | - $f = 'format_texte_' . $fmt; |
|
| 65 | + $f = 'format_texte_'.$fmt; |
|
| 68 | 66 | |
| 69 | 67 | return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
| 70 | 68 | } |
| 71 | 69 | |
| 72 | 70 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 73 | - $f = 'format_polyglotte_' . $fmt; |
|
| 71 | + $f = 'format_polyglotte_'.$fmt; |
|
| 74 | 72 | |
| 75 | 73 | return $f($struct->traductions, $prof); |
| 76 | 74 | } |
@@ -83,7 +81,7 @@ discard block |
||
| 83 | 81 | |
| 84 | 82 | $filtres = decompiler_liste($struct->param, $fmt, $prof); |
| 85 | 83 | |
| 86 | - $f = 'format_idiome_' . $fmt; |
|
| 84 | + $f = 'format_idiome_'.$fmt; |
|
| 87 | 85 | |
| 88 | 86 | return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
| 89 | 87 | } |
@@ -98,7 +96,7 @@ discard block |
||
| 98 | 96 | } |
| 99 | 97 | $filtres = decompiler_liste($p, $fmt, $prof); |
| 100 | 98 | } |
| 101 | - $f = 'format_champ_' . $fmt; |
|
| 99 | + $f = 'format_champ_'.$fmt; |
|
| 102 | 100 | |
| 103 | 101 | return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
| 104 | 102 | } |
@@ -107,7 +105,7 @@ discard block |
||
| 107 | 105 | if (!is_array($sources)) { |
| 108 | 106 | return ''; |
| 109 | 107 | } |
| 110 | - $f = 'format_liste_' . $fmt; |
|
| 108 | + $f = 'format_liste_'.$fmt; |
|
| 111 | 109 | $res = ''; |
| 112 | 110 | foreach ($sources as $arg) { |
| 113 | 111 | if (!is_array($arg)) { |
@@ -123,7 +121,7 @@ discard block |
||
| 123 | 121 | and (strlen($v[0]->apres) == 1) |
| 124 | 122 | and $v[0]->apres == $v[0]->avant |
| 125 | 123 | ) { |
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 124 | + $args[] = $v[0]->avant.$v[0]->texte.$v[0]->apres; |
|
| 127 | 125 | } else { |
| 128 | 126 | $args[] = decompiler_($v, $fmt, 0 - $prof); |
| 129 | 127 | } |
@@ -146,7 +144,7 @@ discard block |
||
| 146 | 144 | return ''; |
| 147 | 145 | } |
| 148 | 146 | $res = ''; |
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 147 | + $f = 'format_critere_'.$fmt; |
|
| 150 | 148 | foreach ($sources as $crit) { |
| 151 | 149 | if (!is_array($crit)) { |
| 152 | 150 | continue; |
@@ -158,12 +156,12 @@ discard block |
||
| 158 | 156 | and $v[0]->type == 'texte' |
| 159 | 157 | and $v[0]->apres |
| 160 | 158 | ) { |
| 161 | - $args[] = array(array('texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres))); |
|
| 159 | + $args[] = array(array('texte', ($v[0]->apres.$v[0]->texte.$v[0]->apres))); |
|
| 162 | 160 | } else { |
| 163 | 161 | $res2 = array(); |
| 164 | 162 | foreach ($v as $k => $p) { |
| 165 | 163 | if (isset($p->type) |
| 166 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 164 | + and function_exists($d = 'decompiler_'.$p->type) |
|
| 167 | 165 | ) { |
| 168 | 166 | $r = $d($p, $fmt, (0 - $prof), @$v[$k + 1]); |
| 169 | 167 | $res2[] = array($p->type, $r); |
@@ -191,7 +189,7 @@ discard block |
||
| 191 | 189 | if (!isset($p->type)) { |
| 192 | 190 | continue; |
| 193 | 191 | } #?????? |
| 194 | - $d = 'decompiler_' . $p->type; |
|
| 192 | + $d = 'decompiler_'.$p->type; |
|
| 195 | 193 | $next = isset($liste[$k + 1]) ? $liste[$k + 1] : false; |
| 196 | 194 | // Forcer le champ etendu si son source (pas les reecritures) |
| 197 | 195 | // contenait des args et s'il est suivi d'espaces, |
@@ -216,16 +214,16 @@ discard block |
||
| 216 | 214 | $contenu[] = array($d($p, $fmt, $prof2), $p->type); |
| 217 | 215 | |
| 218 | 216 | } |
| 219 | - $f = 'format_suite_' . $fmt; |
|
| 217 | + $f = 'format_suite_'.$fmt; |
|
| 220 | 218 | |
| 221 | 219 | return $f($contenu); |
| 222 | 220 | } |
| 223 | 221 | |
| 224 | 222 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 225 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 223 | + if (!include_spip('public/format_'.$fmt)) { |
|
| 226 | 224 | return "'$fmt'?"; |
| 227 | 225 | } |
| 228 | - $f = 'decompiler_' . $quoi; |
|
| 226 | + $f = 'decompiler_'.$quoi; |
|
| 229 | 227 | |
| 230 | 228 | return $f($liste, $fmt, $prof); |
| 231 | 229 | } |