@@ -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 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | + 'id_parent'; |
|
| 51 | 51 | |
| 52 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 53 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return void |
| 68 | 68 | **/ |
| 69 | 69 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 70 | - $not = $crit->not; |
|
| 71 | - $boucle = &$boucles[$idb]; |
|
| 72 | - $id = $boucle->primary; |
|
| 73 | - |
|
| 74 | - if ($not or !$id) { |
|
| 75 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 70 | + $not = $crit->not; |
|
| 71 | + $boucle = &$boucles[$idb]; |
|
| 72 | + $id = $boucle->primary; |
|
| 73 | + |
|
| 74 | + if ($not or !$id) { |
|
| 75 | + return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -95,73 +95,73 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | **/ |
| 97 | 97 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 98 | - $boucle = &$boucles[$idb]; |
|
| 99 | - $primary = $boucle->primary; |
|
| 100 | - |
|
| 101 | - // la table nécessite une clé primaire, non composée |
|
| 102 | - if (!$primary or strpos($primary, ',')) { |
|
| 103 | - return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | - |
|
| 108 | - // le doublon s'applique sur un type de boucle (article) |
|
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | - |
|
| 111 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | - // on obtient $nom = "'article' . 'nom'" |
|
| 113 | - if (isset($crit->param[0])) { |
|
| 114 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | - |
|
| 121 | - // on crée un sql_in avec la clé primaire de la table |
|
| 122 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | - // $doublons et son index, ici $nom |
|
| 124 | - |
|
| 125 | - // debut du code "sql_in('articles.id_article', " |
|
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 130 | - |
|
| 131 | - // le debut complet du code des doublons |
|
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | - |
|
| 134 | - // nom du doublon "('article' . 'nom')]" |
|
| 135 | - $fin_doub = "($nom)]"; |
|
| 136 | - |
|
| 137 | - // si on trouve un autre critère doublon, |
|
| 138 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | - foreach ($boucle->where as $k => $w) { |
|
| 140 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | - // fusionner le sql_in (du where) |
|
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | - $x = strpos($boucle->hash, $init_comment); |
|
| 145 | - $len = strlen($init_comment); |
|
| 146 | - $boucle->hash = |
|
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | - |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | - |
|
| 156 | - // déclarer le doublon s'il n'existe pas encore |
|
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | - # {!doublons A}{doublons B} |
|
| 163 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 98 | + $boucle = &$boucles[$idb]; |
|
| 99 | + $primary = $boucle->primary; |
|
| 100 | + |
|
| 101 | + // la table nécessite une clé primaire, non composée |
|
| 102 | + if (!$primary or strpos($primary, ',')) { |
|
| 103 | + return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | + |
|
| 108 | + // le doublon s'applique sur un type de boucle (article) |
|
| 109 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + |
|
| 111 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | + // on obtient $nom = "'article' . 'nom'" |
|
| 113 | + if (isset($crit->param[0])) { |
|
| 114 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | + |
|
| 121 | + // on crée un sql_in avec la clé primaire de la table |
|
| 122 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | + // $doublons et son index, ici $nom |
|
| 124 | + |
|
| 125 | + // debut du code "sql_in('articles.id_article', " |
|
| 126 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 130 | + |
|
| 131 | + // le debut complet du code des doublons |
|
| 132 | + $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + |
|
| 134 | + // nom du doublon "('article' . 'nom')]" |
|
| 135 | + $fin_doub = "($nom)]"; |
|
| 136 | + |
|
| 137 | + // si on trouve un autre critère doublon, |
|
| 138 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | + foreach ($boucle->where as $k => $w) { |
|
| 140 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | + // fusionner le sql_in (du where) |
|
| 142 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | + $x = strpos($boucle->hash, $init_comment); |
|
| 145 | + $len = strlen($init_comment); |
|
| 146 | + $boucle->hash = |
|
| 147 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | + |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 155 | + |
|
| 156 | + // déclarer le doublon s'il n'existe pas encore |
|
| 157 | + $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | + # {!doublons A}{doublons B} |
|
| 163 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @return void |
| 183 | 183 | **/ |
| 184 | 184 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 185 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | - $param = 'oui'; |
|
| 187 | - } |
|
| 188 | - if ($crit->not) { |
|
| 189 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | - } |
|
| 191 | - $boucle = &$boucles[$idb]; |
|
| 192 | - $boucle->lang_select = $param; |
|
| 185 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | + $param = 'oui'; |
|
| 187 | + } |
|
| 188 | + if ($crit->not) { |
|
| 189 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | + } |
|
| 191 | + $boucle = &$boucles[$idb]; |
|
| 192 | + $boucle->lang_select = $param; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -211,15 +211,15 @@ discard block |
||
| 211 | 211 | * @return void |
| 212 | 212 | **/ |
| 213 | 213 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 214 | - list($un, $deux) = $crit->param; |
|
| 215 | - $un = $un[0]->texte; |
|
| 216 | - $deux = $deux[0]->texte; |
|
| 217 | - if ($deux) { |
|
| 218 | - $boucles[$idb]->limit = |
|
| 219 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 220 | - } else { |
|
| 221 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 222 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = |
|
| 219 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 220 | + } else { |
|
| 221 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 222 | + } |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -253,58 +253,58 @@ discard block |
||
| 253 | 253 | **/ |
| 254 | 254 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 255 | 255 | |
| 256 | - $boucle = &$boucles[$idb]; |
|
| 257 | - // definition de la taille de la page |
|
| 258 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 259 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 260 | - |
|
| 261 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 262 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 263 | - } else { |
|
| 264 | - $r = intval($r[2]); |
|
| 265 | - $pas = strval($r ? $r : 10); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - // Calcul du nommage de la pagination si il existe. |
|
| 269 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 270 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 271 | - $type = "'$idb'"; |
|
| 272 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 273 | - // Syntaxe {pagination 20, nom} |
|
| 274 | - if (isset($crit->param[0][1])) { |
|
| 275 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 276 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 277 | - elseif (isset($crit->param[1][0])) { |
|
| 278 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 282 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 283 | - $partie = |
|
| 284 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 285 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 286 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 287 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 288 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 289 | - . "\t}\n" |
|
| 290 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 291 | - |
|
| 292 | - $boucle->hash .= ' |
|
| 256 | + $boucle = &$boucles[$idb]; |
|
| 257 | + // definition de la taille de la page |
|
| 258 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 259 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 260 | + |
|
| 261 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 262 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 263 | + } else { |
|
| 264 | + $r = intval($r[2]); |
|
| 265 | + $pas = strval($r ? $r : 10); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + // Calcul du nommage de la pagination si il existe. |
|
| 269 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 270 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 271 | + $type = "'$idb'"; |
|
| 272 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 273 | + // Syntaxe {pagination 20, nom} |
|
| 274 | + if (isset($crit->param[0][1])) { |
|
| 275 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 276 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 277 | + elseif (isset($crit->param[1][0])) { |
|
| 278 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 282 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 283 | + $partie = |
|
| 284 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 285 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 286 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 287 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 288 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 289 | + . "\t}\n" |
|
| 290 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 291 | + |
|
| 292 | + $boucle->hash .= ' |
|
| 293 | 293 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 294 | 294 | |
| 295 | - $boucle->total_parties = $pas; |
|
| 296 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 297 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 298 | - // sauf si pas de primaire, ou si primaire composee |
|
| 299 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 300 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 301 | - if ( |
|
| 302 | - $boucle->primary |
|
| 303 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 304 | - and !in_array($t, $boucle->select) |
|
| 305 | - ) { |
|
| 306 | - $boucle->select[] = $t; |
|
| 307 | - } |
|
| 295 | + $boucle->total_parties = $pas; |
|
| 296 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 297 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 298 | + // sauf si pas de primaire, ou si primaire composee |
|
| 299 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 300 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 301 | + if ( |
|
| 302 | + $boucle->primary |
|
| 303 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 304 | + and !in_array($t, $boucle->select) |
|
| 305 | + ) { |
|
| 306 | + $boucle->select[] = $t; |
|
| 307 | + } |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | |
@@ -326,24 +326,24 @@ discard block |
||
| 326 | 326 | **/ |
| 327 | 327 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 328 | 328 | |
| 329 | - $boucle = &$boucles[$idb]; |
|
| 329 | + $boucle = &$boucles[$idb]; |
|
| 330 | 330 | |
| 331 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 332 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 331 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 332 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 333 | 333 | |
| 334 | - return; |
|
| 335 | - } |
|
| 334 | + return; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - if (isset($crit->param[0])) { |
|
| 338 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 339 | - } else { |
|
| 340 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 341 | - } |
|
| 337 | + if (isset($crit->param[0])) { |
|
| 338 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 339 | + } else { |
|
| 340 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 344 | - $boucle->hash .= ' |
|
| 343 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 344 | + $boucle->hash .= ' |
|
| 345 | 345 | // RECHERCHE' |
| 346 | - . ($crit->cond ? ' |
|
| 346 | + . ($crit->cond ? ' |
|
| 347 | 347 | if (!strlen(' . $quoi . ')){ |
| 348 | 348 | list($rech_select, $rech_where) = array("0 as points",""); |
| 349 | 349 | } else' : '') . ' |
@@ -354,21 +354,21 @@ discard block |
||
| 354 | 354 | '; |
| 355 | 355 | |
| 356 | 356 | |
| 357 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 358 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 359 | - $boucle->select[] = $t; |
|
| 360 | - } # pour postgres, neuneu ici |
|
| 361 | - // jointure uniquement sur le serveur principal |
|
| 362 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 363 | - if (!$boucle->sql_serveur) { |
|
| 364 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 365 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 366 | - } |
|
| 367 | - $boucle->select[] = '$rech_select'; |
|
| 368 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 369 | - |
|
| 370 | - // et la recherche trouve |
|
| 371 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 357 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 358 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 359 | + $boucle->select[] = $t; |
|
| 360 | + } # pour postgres, neuneu ici |
|
| 361 | + // jointure uniquement sur le serveur principal |
|
| 362 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 363 | + if (!$boucle->sql_serveur) { |
|
| 364 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 365 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 366 | + } |
|
| 367 | + $boucle->select[] = '$rech_select'; |
|
| 368 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 369 | + |
|
| 370 | + // et la recherche trouve |
|
| 371 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -385,25 +385,25 @@ discard block |
||
| 385 | 385 | * @return void |
| 386 | 386 | **/ |
| 387 | 387 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 388 | - $boucle = &$boucles[$idb]; |
|
| 389 | - $prim = $boucle->primary; |
|
| 390 | - $table = $boucle->id_table; |
|
| 391 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 392 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 393 | - $boucle->where[] = |
|
| 394 | - [ |
|
| 395 | - "'OR'", |
|
| 396 | - [ |
|
| 397 | - "'AND'", |
|
| 398 | - ["'='", "'$table.id_trad'", 0], |
|
| 399 | - ["'='", "'$table.$prim'", $dprim] |
|
| 400 | - ], |
|
| 401 | - [ |
|
| 402 | - "'AND'", |
|
| 403 | - ["'>'", "'$table.id_trad'", 0], |
|
| 404 | - ["'='", "'$table.id_trad'", $arg] |
|
| 405 | - ] |
|
| 406 | - ]; |
|
| 388 | + $boucle = &$boucles[$idb]; |
|
| 389 | + $prim = $boucle->primary; |
|
| 390 | + $table = $boucle->id_table; |
|
| 391 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 392 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 393 | + $boucle->where[] = |
|
| 394 | + [ |
|
| 395 | + "'OR'", |
|
| 396 | + [ |
|
| 397 | + "'AND'", |
|
| 398 | + ["'='", "'$table.id_trad'", 0], |
|
| 399 | + ["'='", "'$table.$prim'", $dprim] |
|
| 400 | + ], |
|
| 401 | + [ |
|
| 402 | + "'AND'", |
|
| 403 | + ["'>'", "'$table.id_trad'", 0], |
|
| 404 | + ["'='", "'$table.id_trad'", $arg] |
|
| 405 | + ] |
|
| 406 | + ]; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
@@ -421,17 +421,17 @@ discard block |
||
| 421 | 421 | * @return void |
| 422 | 422 | **/ |
| 423 | 423 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 424 | - $boucle = &$boucles[$idb]; |
|
| 425 | - $prim = $boucle->primary; |
|
| 426 | - $table = $boucle->id_table; |
|
| 427 | - |
|
| 428 | - $c = |
|
| 429 | - [ |
|
| 430 | - "'OR'", |
|
| 431 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 432 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 433 | - ]; |
|
| 434 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 424 | + $boucle = &$boucles[$idb]; |
|
| 425 | + $prim = $boucle->primary; |
|
| 426 | + $table = $boucle->id_table; |
|
| 427 | + |
|
| 428 | + $c = |
|
| 429 | + [ |
|
| 430 | + "'OR'", |
|
| 431 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 432 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 433 | + ]; |
|
| 434 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | |
@@ -448,19 +448,19 @@ discard block |
||
| 448 | 448 | **/ |
| 449 | 449 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 450 | 450 | |
| 451 | - $boucle = &$boucles[$idb]; |
|
| 452 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 453 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 454 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 455 | - 'id_parent'; |
|
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | - |
|
| 458 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | - else { |
|
| 462 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 463 | - } |
|
| 451 | + $boucle = &$boucles[$idb]; |
|
| 452 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 453 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 454 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 455 | + 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | + |
|
| 458 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | + else { |
|
| 462 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 463 | + } |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -491,37 +491,37 @@ discard block |
||
| 491 | 491 | **/ |
| 492 | 492 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 493 | 493 | |
| 494 | - $not = $crit->not; |
|
| 495 | - $boucle = &$boucles[$idb]; |
|
| 496 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | - if (isset($crit->param[0])) { |
|
| 498 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | - // sinon on le prend chez une boucle parente |
|
| 500 | - } else { |
|
| 501 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - //Trouver une jointure |
|
| 505 | - $champ = 'id_rubrique'; |
|
| 506 | - $desc = $boucle->show; |
|
| 507 | - //Seulement si necessaire |
|
| 508 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | - $decompose = decompose_champ_id_objet($champ); |
|
| 514 | - $champ = array_shift($decompose); |
|
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | - } |
|
| 517 | - } else { |
|
| 518 | - $cle = $boucle->id_table; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 524 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 494 | + $not = $crit->not; |
|
| 495 | + $boucle = &$boucles[$idb]; |
|
| 496 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | + if (isset($crit->param[0])) { |
|
| 498 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | + // sinon on le prend chez une boucle parente |
|
| 500 | + } else { |
|
| 501 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + //Trouver une jointure |
|
| 505 | + $champ = 'id_rubrique'; |
|
| 506 | + $desc = $boucle->show; |
|
| 507 | + //Seulement si necessaire |
|
| 508 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | + $decompose = decompose_champ_id_objet($champ); |
|
| 514 | + $champ = array_shift($decompose); |
|
| 515 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 518 | + $cle = $boucle->id_table; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 524 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
@@ -537,15 +537,15 @@ discard block |
||
| 537 | 537 | **/ |
| 538 | 538 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 539 | 539 | |
| 540 | - $boucle = &$boucles[$idb]; |
|
| 541 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 542 | - $serveur = $boucle->sql_serveur; |
|
| 540 | + $boucle = &$boucles[$idb]; |
|
| 541 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 542 | + $serveur = $boucle->sql_serveur; |
|
| 543 | 543 | |
| 544 | - $c = "sql_in('" . |
|
| 545 | - $boucle->id_table . '.' . $boucle->primary |
|
| 546 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 544 | + $c = "sql_in('" . |
|
| 545 | + $boucle->id_table . '.' . $boucle->primary |
|
| 546 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | 547 | |
| 548 | - $boucle->where[] = $c; |
|
| 548 | + $boucle->where[] = $c; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
@@ -567,31 +567,31 @@ discard block |
||
| 567 | 567 | * @return void |
| 568 | 568 | **/ |
| 569 | 569 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 570 | - if ($t = isset($crit->param[0])) { |
|
| 571 | - $t = $crit->param[0]; |
|
| 572 | - if ($t[0]->type == 'texte') { |
|
| 573 | - $t = $t[0]->texte; |
|
| 574 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 575 | - $t = table_objet_sql($r[1]); |
|
| 576 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 577 | - if ($t) { |
|
| 578 | - $t .= '.' . $r[2]; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - } else { |
|
| 582 | - $t = '".' |
|
| 583 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 584 | - . '."'; |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - if ($t) { |
|
| 588 | - $boucles[$idb]->group[] = $t; |
|
| 589 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 590 | - $boucles[$idb]->select[] = $t; |
|
| 591 | - } |
|
| 592 | - } else { |
|
| 593 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 594 | - } |
|
| 570 | + if ($t = isset($crit->param[0])) { |
|
| 571 | + $t = $crit->param[0]; |
|
| 572 | + if ($t[0]->type == 'texte') { |
|
| 573 | + $t = $t[0]->texte; |
|
| 574 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 575 | + $t = table_objet_sql($r[1]); |
|
| 576 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 577 | + if ($t) { |
|
| 578 | + $t .= '.' . $r[2]; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + } else { |
|
| 582 | + $t = '".' |
|
| 583 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 584 | + . '."'; |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + if ($t) { |
|
| 588 | + $boucles[$idb]->group[] = $t; |
|
| 589 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 590 | + $boucles[$idb]->select[] = $t; |
|
| 591 | + } |
|
| 592 | + } else { |
|
| 593 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 594 | + } |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @return void |
| 612 | 612 | **/ |
| 613 | 613 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 614 | - $boucles[$idb]->group = []; |
|
| 614 | + $boucles[$idb]->group = []; |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -648,45 +648,45 @@ discard block |
||
| 648 | 648 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 649 | 649 | */ |
| 650 | 650 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 651 | - if (isset($crit->param[0])) { |
|
| 652 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 653 | - $boucle = $boucles[$idb]; |
|
| 654 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 655 | - $n = count($boucle->order); |
|
| 656 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 657 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 658 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 659 | - if ( |
|
| 660 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 661 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 662 | - ) { |
|
| 663 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | - } else { |
|
| 665 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - } else { |
|
| 669 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 670 | - } |
|
| 651 | + if (isset($crit->param[0])) { |
|
| 652 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 653 | + $boucle = $boucles[$idb]; |
|
| 654 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 655 | + $n = count($boucle->order); |
|
| 656 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 657 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 658 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 659 | + if ( |
|
| 660 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 661 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 662 | + ) { |
|
| 663 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | + } else { |
|
| 665 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + } else { |
|
| 669 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 670 | + } |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 674 | 674 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 675 | - $boucle = $boucles[$idb]; |
|
| 676 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 677 | - $var = '$champs_' . $idb; |
|
| 678 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 679 | - if (!$desc) { |
|
| 680 | - $desc = $boucle->show['field']; |
|
| 681 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 682 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 683 | - } |
|
| 684 | - if ($desc) { |
|
| 685 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 686 | - } |
|
| 687 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 688 | - |
|
| 689 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 675 | + $boucle = $boucles[$idb]; |
|
| 676 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 677 | + $var = '$champs_' . $idb; |
|
| 678 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 679 | + if (!$desc) { |
|
| 680 | + $desc = $boucle->show['field']; |
|
| 681 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 682 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 683 | + } |
|
| 684 | + if ($desc) { |
|
| 685 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 686 | + } |
|
| 687 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 688 | + |
|
| 689 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 726 | 726 | */ |
| 727 | 727 | function critere_par_dist($idb, &$boucles, $crit) { |
| 728 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 728 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -747,93 +747,93 @@ discard block |
||
| 747 | 747 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 748 | 748 | */ |
| 749 | 749 | function critere_parinverse($idb, &$boucles, $crit) { |
| 750 | - $boucle = &$boucles[$idb]; |
|
| 751 | - |
|
| 752 | - $sens = $collecte = ''; |
|
| 753 | - if ($crit->not) { |
|
| 754 | - $sens = " . ' DESC'"; |
|
| 755 | - } |
|
| 756 | - if (isset($boucle->modificateur['collate'])) { |
|
| 757 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - // Pour chaque paramètre du critère |
|
| 761 | - foreach ($crit->param as $tri) { |
|
| 762 | - $order = $fct = ''; |
|
| 763 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 764 | - if ($tri[0]->type != 'texte') { |
|
| 765 | - // calculer le order dynamique qui verifie les champs |
|
| 766 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 767 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 768 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 769 | - } |
|
| 770 | - // tris textuels {par titre} |
|
| 771 | - else { |
|
| 772 | - $par = array_shift($tri); |
|
| 773 | - $par = $par->texte; |
|
| 774 | - |
|
| 775 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 776 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 777 | - $expression = trim($m[1]); |
|
| 778 | - $champ = trim($m[2]); |
|
| 779 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 780 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 781 | - } else { |
|
| 782 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 786 | - } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 787 | - // {par FONCTION(champ)} |
|
| 788 | - if (count($match) > 2) { |
|
| 789 | - $par = substr($match[2], 1, -1); |
|
| 790 | - $fct = $match[1]; |
|
| 791 | - } |
|
| 792 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 793 | - if ($par == 'hasard') { |
|
| 794 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 795 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 796 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 797 | - } else { |
|
| 798 | - // cas général {par champ}, {par table.champ}, ... |
|
| 799 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 800 | - } |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // on ne sait pas traiter… |
|
| 804 | - else { |
|
| 805 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 809 | - if (is_array($order)) { |
|
| 810 | - return $order; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 815 | - $t = $m[1]; |
|
| 816 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 817 | - $boucle->select[] = $t; |
|
| 818 | - } |
|
| 819 | - } else { |
|
| 820 | - $sens = ''; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - if ($fct) { |
|
| 824 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 825 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 826 | - } else { |
|
| 827 | - $order = "'$fct(' . $order . ')'"; |
|
| 828 | - } |
|
| 829 | - } |
|
| 830 | - $t = $order . $collecte . $sens; |
|
| 831 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 832 | - $t = $r[1] . $r[2]; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - $boucle->order[] = $t; |
|
| 836 | - } |
|
| 750 | + $boucle = &$boucles[$idb]; |
|
| 751 | + |
|
| 752 | + $sens = $collecte = ''; |
|
| 753 | + if ($crit->not) { |
|
| 754 | + $sens = " . ' DESC'"; |
|
| 755 | + } |
|
| 756 | + if (isset($boucle->modificateur['collate'])) { |
|
| 757 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + // Pour chaque paramètre du critère |
|
| 761 | + foreach ($crit->param as $tri) { |
|
| 762 | + $order = $fct = ''; |
|
| 763 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 764 | + if ($tri[0]->type != 'texte') { |
|
| 765 | + // calculer le order dynamique qui verifie les champs |
|
| 766 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 767 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 768 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 769 | + } |
|
| 770 | + // tris textuels {par titre} |
|
| 771 | + else { |
|
| 772 | + $par = array_shift($tri); |
|
| 773 | + $par = $par->texte; |
|
| 774 | + |
|
| 775 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 776 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 777 | + $expression = trim($m[1]); |
|
| 778 | + $champ = trim($m[2]); |
|
| 779 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 780 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 781 | + } else { |
|
| 782 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 786 | + } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 787 | + // {par FONCTION(champ)} |
|
| 788 | + if (count($match) > 2) { |
|
| 789 | + $par = substr($match[2], 1, -1); |
|
| 790 | + $fct = $match[1]; |
|
| 791 | + } |
|
| 792 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 793 | + if ($par == 'hasard') { |
|
| 794 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 795 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 796 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 797 | + } else { |
|
| 798 | + // cas général {par champ}, {par table.champ}, ... |
|
| 799 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 800 | + } |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // on ne sait pas traiter… |
|
| 804 | + else { |
|
| 805 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 809 | + if (is_array($order)) { |
|
| 810 | + return $order; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 815 | + $t = $m[1]; |
|
| 816 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 817 | + $boucle->select[] = $t; |
|
| 818 | + } |
|
| 819 | + } else { |
|
| 820 | + $sens = ''; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + if ($fct) { |
|
| 824 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 825 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 826 | + } else { |
|
| 827 | + $order = "'$fct(' . $order . ')'"; |
|
| 828 | + } |
|
| 829 | + } |
|
| 830 | + $t = $order . $collecte . $sens; |
|
| 831 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 832 | + $t = $r[1] . $r[2]; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + $boucle->order[] = $t; |
|
| 836 | + } |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | /** |
@@ -847,13 +847,13 @@ discard block |
||
| 847 | 847 | * @return string Clause pour le Order by |
| 848 | 848 | */ |
| 849 | 849 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 850 | - $boucle = &$boucles[$idb]; |
|
| 851 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 852 | - $parha = 'rand() AS hasard'; |
|
| 853 | - if (!in_array($parha, $boucle->select)) { |
|
| 854 | - $boucle->select[] = $parha; |
|
| 855 | - } |
|
| 856 | - return "'hasard'"; |
|
| 850 | + $boucle = &$boucles[$idb]; |
|
| 851 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 852 | + $parha = 'rand() AS hasard'; |
|
| 853 | + if (!in_array($parha, $boucle->select)) { |
|
| 854 | + $boucle->select[] = $parha; |
|
| 855 | + } |
|
| 856 | + return "'hasard'"; |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -877,24 +877,24 @@ discard block |
||
| 877 | 877 | * @return string Clause pour le Order by |
| 878 | 878 | */ |
| 879 | 879 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 880 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 881 | - if (is_array($_champ)) { |
|
| 882 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 883 | - } |
|
| 884 | - $boucle = &$boucles[$idb]; |
|
| 885 | - $texte = '0+' . $_champ; |
|
| 886 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 887 | - if ($suite !== "''") { |
|
| 888 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 889 | - } |
|
| 890 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 891 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 892 | - |
|
| 893 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 894 | - $orderassinum = trim($orderassinum, "'"); |
|
| 895 | - |
|
| 896 | - $order = "'$orderassinum, $asnum'"; |
|
| 897 | - return $order; |
|
| 880 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 881 | + if (is_array($_champ)) { |
|
| 882 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 883 | + } |
|
| 884 | + $boucle = &$boucles[$idb]; |
|
| 885 | + $texte = '0+' . $_champ; |
|
| 886 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 887 | + if ($suite !== "''") { |
|
| 888 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 889 | + } |
|
| 890 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 891 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 892 | + |
|
| 893 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 894 | + $orderassinum = trim($orderassinum, "'"); |
|
| 895 | + |
|
| 896 | + $order = "'$orderassinum, $asnum'"; |
|
| 897 | + return $order; |
|
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | /** |
@@ -915,35 +915,35 @@ discard block |
||
| 915 | 915 | * @return string Clause pour le Order by |
| 916 | 916 | */ |
| 917 | 917 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 918 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 919 | - if (is_array($_champ)) { |
|
| 920 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 921 | - } |
|
| 922 | - $boucle = &$boucles[$idb]; |
|
| 923 | - $texte = '0+' . $_champ; |
|
| 924 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 925 | - if ($suite !== "''") { |
|
| 926 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - $as = false; |
|
| 930 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 931 | - foreach ($boucle->select as $s) { |
|
| 932 | - if (strpos($s, $select) === 0) { |
|
| 933 | - $as = trim(substr($s, strlen($select))); |
|
| 934 | - if (!preg_match(',\W,', $as)) { |
|
| 935 | - break; |
|
| 936 | - } |
|
| 937 | - $as = false; |
|
| 938 | - } |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - if (!$as) { |
|
| 942 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 943 | - $boucle->select[] = $select . $as; |
|
| 944 | - } |
|
| 945 | - $order = "'$as'"; |
|
| 946 | - return $order; |
|
| 918 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 919 | + if (is_array($_champ)) { |
|
| 920 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 921 | + } |
|
| 922 | + $boucle = &$boucles[$idb]; |
|
| 923 | + $texte = '0+' . $_champ; |
|
| 924 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 925 | + if ($suite !== "''") { |
|
| 926 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + $as = false; |
|
| 930 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 931 | + foreach ($boucle->select as $s) { |
|
| 932 | + if (strpos($s, $select) === 0) { |
|
| 933 | + $as = trim(substr($s, strlen($select))); |
|
| 934 | + if (!preg_match(',\W,', $as)) { |
|
| 935 | + break; |
|
| 936 | + } |
|
| 937 | + $as = false; |
|
| 938 | + } |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + if (!$as) { |
|
| 942 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 943 | + $boucle->select[] = $select . $as; |
|
| 944 | + } |
|
| 945 | + $order = "'$as'"; |
|
| 946 | + return $order; |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | |
@@ -963,14 +963,14 @@ discard block |
||
| 963 | 963 | * @return string Clause pour le Order by |
| 964 | 964 | */ |
| 965 | 965 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 966 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 967 | - if (is_array($_champ)) { |
|
| 968 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 969 | - } |
|
| 970 | - $boucle = &$boucles[$idb]; |
|
| 971 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 972 | - $order = "'multi'"; |
|
| 973 | - return $order; |
|
| 966 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 967 | + if (is_array($_champ)) { |
|
| 968 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 969 | + } |
|
| 970 | + $boucle = &$boucles[$idb]; |
|
| 971 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 972 | + $order = "'multi'"; |
|
| 973 | + return $order; |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
@@ -989,56 +989,56 @@ discard block |
||
| 989 | 989 | * @return array|string |
| 990 | 990 | */ |
| 991 | 991 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 992 | - $boucle = &$boucles[$idb]; |
|
| 993 | - $desc = $boucle->show; |
|
| 994 | - |
|
| 995 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 996 | - if (isset($desc['field'][$par])) { |
|
| 997 | - $par = $boucle->id_table . '.' . $par; |
|
| 998 | - } |
|
| 999 | - // le champ est peut être une jointure |
|
| 1000 | - else { |
|
| 1001 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1002 | - $champ = $par; |
|
| 1003 | - |
|
| 1004 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1005 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1006 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1007 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1008 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1009 | - list(, $table, $champ) = $r; |
|
| 1010 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1011 | - $table = table_objet_sql($table); |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1015 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1016 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1017 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1018 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1019 | - } elseif ( |
|
| 1020 | - $boucle->jointures_explicites |
|
| 1021 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1022 | - ) { |
|
| 1023 | - $par = $alias . '.' . $champ; |
|
| 1024 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1025 | - $par = $alias . '.' . $champ; |
|
| 1026 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1027 | - } elseif ( |
|
| 1028 | - $table_alias |
|
| 1029 | - and isset($boucle->from[$table_alias]) |
|
| 1030 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1031 | - ) { |
|
| 1032 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1033 | - } elseif ($table) { |
|
| 1034 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1035 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1036 | - } else { |
|
| 1037 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1038 | - } |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - return $raw ? $par : "'$par'"; |
|
| 992 | + $boucle = &$boucles[$idb]; |
|
| 993 | + $desc = $boucle->show; |
|
| 994 | + |
|
| 995 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 996 | + if (isset($desc['field'][$par])) { |
|
| 997 | + $par = $boucle->id_table . '.' . $par; |
|
| 998 | + } |
|
| 999 | + // le champ est peut être une jointure |
|
| 1000 | + else { |
|
| 1001 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1002 | + $champ = $par; |
|
| 1003 | + |
|
| 1004 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1005 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1006 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1007 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1008 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1009 | + list(, $table, $champ) = $r; |
|
| 1010 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1011 | + $table = table_objet_sql($table); |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1015 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1016 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1017 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1018 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1019 | + } elseif ( |
|
| 1020 | + $boucle->jointures_explicites |
|
| 1021 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1022 | + ) { |
|
| 1023 | + $par = $alias . '.' . $champ; |
|
| 1024 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1025 | + $par = $alias . '.' . $champ; |
|
| 1026 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1027 | + } elseif ( |
|
| 1028 | + $table_alias |
|
| 1029 | + and isset($boucle->from[$table_alias]) |
|
| 1030 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1031 | + ) { |
|
| 1032 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1033 | + } elseif ($table) { |
|
| 1034 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1035 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1036 | + } else { |
|
| 1037 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1038 | + } |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + return $raw ? $par : "'$par'"; |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | /** |
@@ -1052,11 +1052,11 @@ discard block |
||
| 1052 | 1052 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1053 | 1053 | */ |
| 1054 | 1054 | function critere_par_joint($table, $champ, &$boucle) { |
| 1055 | - $t = array_search($table, $boucle->from); |
|
| 1056 | - if (!$t) { |
|
| 1057 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1058 | - } |
|
| 1059 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1055 | + $t = array_search($table, $boucle->from); |
|
| 1056 | + if (!$t) { |
|
| 1057 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1058 | + } |
|
| 1059 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | /** |
@@ -1081,33 +1081,33 @@ discard block |
||
| 1081 | 1081 | */ |
| 1082 | 1082 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1083 | 1083 | |
| 1084 | - $boucle = &$boucles[$idb]; |
|
| 1085 | - // Classement par ordre inverse |
|
| 1086 | - if ($crit->not) { |
|
| 1087 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1088 | - } else { |
|
| 1089 | - $order = "' DESC'"; |
|
| 1090 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1091 | - if (isset($crit->param[0])) { |
|
| 1092 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1093 | - $order = "(($critere)?' DESC':'')"; |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - $n = count($boucle->order); |
|
| 1097 | - if (!$n) { |
|
| 1098 | - if (isset($boucle->default_order[0])) { |
|
| 1099 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1100 | - } else { |
|
| 1101 | - $boucle->default_order[] = ' DESC'; |
|
| 1102 | - } |
|
| 1103 | - } else { |
|
| 1104 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1105 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1106 | - $t = $r[1] . $r[2]; |
|
| 1107 | - } |
|
| 1108 | - $boucle->order[$n - 1] = $t; |
|
| 1109 | - } |
|
| 1110 | - } |
|
| 1084 | + $boucle = &$boucles[$idb]; |
|
| 1085 | + // Classement par ordre inverse |
|
| 1086 | + if ($crit->not) { |
|
| 1087 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1088 | + } else { |
|
| 1089 | + $order = "' DESC'"; |
|
| 1090 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1091 | + if (isset($crit->param[0])) { |
|
| 1092 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1093 | + $order = "(($critere)?' DESC':'')"; |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + $n = count($boucle->order); |
|
| 1097 | + if (!$n) { |
|
| 1098 | + if (isset($boucle->default_order[0])) { |
|
| 1099 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1100 | + } else { |
|
| 1101 | + $boucle->default_order[] = ' DESC'; |
|
| 1102 | + } |
|
| 1103 | + } else { |
|
| 1104 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1105 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1106 | + $t = $r[1] . $r[2]; |
|
| 1107 | + } |
|
| 1108 | + $boucle->order[$n - 1] = $t; |
|
| 1109 | + } |
|
| 1110 | + } |
|
| 1111 | 1111 | } |
| 1112 | 1112 | |
| 1113 | 1113 | /** |
@@ -1118,138 +1118,138 @@ discard block |
||
| 1118 | 1118 | * @return array|string |
| 1119 | 1119 | */ |
| 1120 | 1120 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1121 | - $boucle = &$boucles[$idb]; |
|
| 1121 | + $boucle = &$boucles[$idb]; |
|
| 1122 | 1122 | |
| 1123 | - $sens = $collecte = ''; |
|
| 1124 | - if ($crit->not) { |
|
| 1125 | - $sens = " . ' DESC'"; |
|
| 1126 | - } |
|
| 1123 | + $sens = $collecte = ''; |
|
| 1124 | + if ($crit->not) { |
|
| 1125 | + $sens = " . ' DESC'"; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - $crit2 = clone $crit; |
|
| 1129 | - $crit2->not = false; |
|
| 1130 | - $crit2->param = [reset($crit->param)]; |
|
| 1131 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1128 | + $crit2 = clone $crit; |
|
| 1129 | + $crit2->not = false; |
|
| 1130 | + $crit2->param = [reset($crit->param)]; |
|
| 1131 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1132 | 1132 | |
| 1133 | - // erreur ? |
|
| 1134 | - if (is_array($res)) { |
|
| 1135 | - return $res; |
|
| 1136 | - } |
|
| 1133 | + // erreur ? |
|
| 1134 | + if (is_array($res)) { |
|
| 1135 | + return $res; |
|
| 1136 | + } |
|
| 1137 | 1137 | |
| 1138 | - $_order = array_pop($boucle->order); |
|
| 1138 | + $_order = array_pop($boucle->order); |
|
| 1139 | 1139 | |
| 1140 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1141 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1140 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1141 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | |
| 1145 | 1145 | // https://code.spip.net/@critere_agenda_dist |
| 1146 | 1146 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1147 | - $params = $crit->param; |
|
| 1148 | - |
|
| 1149 | - if (count($params) < 1) { |
|
| 1150 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - $boucle = &$boucles[$idb]; |
|
| 1154 | - $parent = $boucle->id_parent; |
|
| 1155 | - $fields = $boucle->show['field']; |
|
| 1156 | - |
|
| 1157 | - $date = array_shift($params); |
|
| 1158 | - $type = array_shift($params); |
|
| 1159 | - |
|
| 1160 | - // la valeur $type doit etre connue a la compilation |
|
| 1161 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1162 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1163 | - |
|
| 1164 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1165 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1166 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1167 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1168 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1169 | - $date = $date[0]->texte; |
|
| 1170 | - if (!isset($fields[$date])) { |
|
| 1171 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1172 | - } |
|
| 1173 | - } else { |
|
| 1174 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1175 | - $noms = array_keys($fields); |
|
| 1176 | - $defaut = $noms[0]; |
|
| 1177 | - $noms = join(' ', $noms); |
|
| 1178 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1179 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1180 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1181 | - } |
|
| 1182 | - $annee = $params ? array_shift($params) : ''; |
|
| 1183 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1184 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1185 | - ') ? $x : date("Y"))'; |
|
| 1186 | - |
|
| 1187 | - $mois = $params ? array_shift($params) : ''; |
|
| 1188 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1189 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1190 | - ') ? $x : date("m"))'; |
|
| 1191 | - |
|
| 1192 | - $jour = $params ? array_shift($params) : ''; |
|
| 1193 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1194 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1195 | - ') ? $x : date("d"))'; |
|
| 1196 | - |
|
| 1197 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1198 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1199 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1200 | - ') ? $x : date("Y"))'; |
|
| 1201 | - |
|
| 1202 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1203 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1204 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1205 | - ') ? $x : date("m"))'; |
|
| 1206 | - |
|
| 1207 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1208 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1209 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1210 | - ') ? $x : date("d"))'; |
|
| 1211 | - |
|
| 1212 | - $date = $boucle->id_table . ".$date"; |
|
| 1213 | - |
|
| 1214 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1215 | - if ($type == 'jour') { |
|
| 1216 | - $boucle->where[] = [ |
|
| 1217 | - "'='", |
|
| 1218 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1219 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1220 | - ]; |
|
| 1221 | - } elseif ($type == 'mois') { |
|
| 1222 | - $boucle->where[] = [ |
|
| 1223 | - "'='", |
|
| 1224 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1225 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1226 | - ]; |
|
| 1227 | - } elseif ($type == 'semaine') { |
|
| 1228 | - $boucle->where[] = [ |
|
| 1229 | - "'AND'", |
|
| 1230 | - [ |
|
| 1231 | - "'>='", |
|
| 1232 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1233 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1234 | - ], |
|
| 1235 | - [ |
|
| 1236 | - "'<='", |
|
| 1237 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1238 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1239 | - ] |
|
| 1240 | - ]; |
|
| 1241 | - } elseif (count($crit->param) > 2) { |
|
| 1242 | - $boucle->where[] = [ |
|
| 1243 | - "'AND'", |
|
| 1244 | - [ |
|
| 1245 | - "'>='", |
|
| 1246 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1247 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1248 | - ], |
|
| 1249 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1250 | - ]; |
|
| 1251 | - } |
|
| 1252 | - // sinon on prend tout |
|
| 1147 | + $params = $crit->param; |
|
| 1148 | + |
|
| 1149 | + if (count($params) < 1) { |
|
| 1150 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + $boucle = &$boucles[$idb]; |
|
| 1154 | + $parent = $boucle->id_parent; |
|
| 1155 | + $fields = $boucle->show['field']; |
|
| 1156 | + |
|
| 1157 | + $date = array_shift($params); |
|
| 1158 | + $type = array_shift($params); |
|
| 1159 | + |
|
| 1160 | + // la valeur $type doit etre connue a la compilation |
|
| 1161 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1162 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1163 | + |
|
| 1164 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1165 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1166 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1167 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1168 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1169 | + $date = $date[0]->texte; |
|
| 1170 | + if (!isset($fields[$date])) { |
|
| 1171 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1172 | + } |
|
| 1173 | + } else { |
|
| 1174 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1175 | + $noms = array_keys($fields); |
|
| 1176 | + $defaut = $noms[0]; |
|
| 1177 | + $noms = join(' ', $noms); |
|
| 1178 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1179 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1180 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1181 | + } |
|
| 1182 | + $annee = $params ? array_shift($params) : ''; |
|
| 1183 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1184 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1185 | + ') ? $x : date("Y"))'; |
|
| 1186 | + |
|
| 1187 | + $mois = $params ? array_shift($params) : ''; |
|
| 1188 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1189 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1190 | + ') ? $x : date("m"))'; |
|
| 1191 | + |
|
| 1192 | + $jour = $params ? array_shift($params) : ''; |
|
| 1193 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1194 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1195 | + ') ? $x : date("d"))'; |
|
| 1196 | + |
|
| 1197 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1198 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1199 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1200 | + ') ? $x : date("Y"))'; |
|
| 1201 | + |
|
| 1202 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1203 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1204 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1205 | + ') ? $x : date("m"))'; |
|
| 1206 | + |
|
| 1207 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1208 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1209 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1210 | + ') ? $x : date("d"))'; |
|
| 1211 | + |
|
| 1212 | + $date = $boucle->id_table . ".$date"; |
|
| 1213 | + |
|
| 1214 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1215 | + if ($type == 'jour') { |
|
| 1216 | + $boucle->where[] = [ |
|
| 1217 | + "'='", |
|
| 1218 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1219 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1220 | + ]; |
|
| 1221 | + } elseif ($type == 'mois') { |
|
| 1222 | + $boucle->where[] = [ |
|
| 1223 | + "'='", |
|
| 1224 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1225 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1226 | + ]; |
|
| 1227 | + } elseif ($type == 'semaine') { |
|
| 1228 | + $boucle->where[] = [ |
|
| 1229 | + "'AND'", |
|
| 1230 | + [ |
|
| 1231 | + "'>='", |
|
| 1232 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1233 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1234 | + ], |
|
| 1235 | + [ |
|
| 1236 | + "'<='", |
|
| 1237 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1238 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1239 | + ] |
|
| 1240 | + ]; |
|
| 1241 | + } elseif (count($crit->param) > 2) { |
|
| 1242 | + $boucle->where[] = [ |
|
| 1243 | + "'AND'", |
|
| 1244 | + [ |
|
| 1245 | + "'>='", |
|
| 1246 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1247 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1248 | + ], |
|
| 1249 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1250 | + ]; |
|
| 1251 | + } |
|
| 1252 | + // sinon on prend tout |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | |
@@ -1274,33 +1274,33 @@ discard block |
||
| 1274 | 1274 | * @return void |
| 1275 | 1275 | **/ |
| 1276 | 1276 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1277 | - $boucle = &$boucles[$idb]; |
|
| 1278 | - $a1 = $crit->param[0]; |
|
| 1279 | - $a2 = $crit->param[1]; |
|
| 1280 | - $op = $crit->op; |
|
| 1281 | - |
|
| 1282 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1283 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1284 | - |
|
| 1285 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1286 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1287 | - } else { |
|
| 1288 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1289 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1290 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1291 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1292 | - $mode = (($op == '/') ? '/' : |
|
| 1293 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1294 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1295 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1296 | - $boucle->limit = |
|
| 1297 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1298 | - . ".','." |
|
| 1299 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1300 | - } else { |
|
| 1301 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1277 | + $boucle = &$boucles[$idb]; |
|
| 1278 | + $a1 = $crit->param[0]; |
|
| 1279 | + $a2 = $crit->param[1]; |
|
| 1280 | + $op = $crit->op; |
|
| 1281 | + |
|
| 1282 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1283 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1284 | + |
|
| 1285 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1286 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1287 | + } else { |
|
| 1288 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1289 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1290 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1291 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1292 | + $mode = (($op == '/') ? '/' : |
|
| 1293 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1294 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1295 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1296 | + $boucle->limit = |
|
| 1297 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1298 | + . ".','." |
|
| 1299 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1300 | + } else { |
|
| 1301 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | /** |
@@ -1328,63 +1328,63 @@ discard block |
||
| 1328 | 1328 | * @return void |
| 1329 | 1329 | **/ |
| 1330 | 1330 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1331 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1332 | - |
|
| 1333 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1334 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1335 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1336 | - // {1/3} |
|
| 1337 | - if ($op1 == '/') { |
|
| 1338 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1339 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1340 | - "($total_parties ? $total_parties : 1)"; |
|
| 1341 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1342 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1343 | - } else { |
|
| 1344 | - // cas {n-1,x} |
|
| 1345 | - if ($op1 == '-') { |
|
| 1346 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1347 | - } |
|
| 1348 | - |
|
| 1349 | - // cas {x,n-1} |
|
| 1350 | - if ($op2 == '-') { |
|
| 1351 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1352 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1353 | - ($total_parties . ' - 1')); |
|
| 1354 | - } else { |
|
| 1355 | - // {x,1} ou {pagination} |
|
| 1356 | - $fin = '$debut_boucle' |
|
| 1357 | - . (is_numeric($total_parties) ? |
|
| 1358 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1359 | - ('+' . $total_parties . ' - 1')); |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1363 | - if ($op1 == 'p') { |
|
| 1364 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1365 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1366 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - // Notes : |
|
| 1371 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1372 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1373 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1374 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1375 | - |
|
| 1376 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1377 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1378 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1379 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1380 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1381 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1382 | - . "\n\tif (\$debut_boucle>0" |
|
| 1383 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1384 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1385 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1386 | - |
|
| 1387 | - $boucles[$id_boucle]->partie = " |
|
| 1331 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1332 | + |
|
| 1333 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1334 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1335 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1336 | + // {1/3} |
|
| 1337 | + if ($op1 == '/') { |
|
| 1338 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1339 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1340 | + "($total_parties ? $total_parties : 1)"; |
|
| 1341 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1342 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1343 | + } else { |
|
| 1344 | + // cas {n-1,x} |
|
| 1345 | + if ($op1 == '-') { |
|
| 1346 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1347 | + } |
|
| 1348 | + |
|
| 1349 | + // cas {x,n-1} |
|
| 1350 | + if ($op2 == '-') { |
|
| 1351 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1352 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1353 | + ($total_parties . ' - 1')); |
|
| 1354 | + } else { |
|
| 1355 | + // {x,1} ou {pagination} |
|
| 1356 | + $fin = '$debut_boucle' |
|
| 1357 | + . (is_numeric($total_parties) ? |
|
| 1358 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1359 | + ('+' . $total_parties . ' - 1')); |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1363 | + if ($op1 == 'p') { |
|
| 1364 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1365 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1366 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + // Notes : |
|
| 1371 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1372 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1373 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1374 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1375 | + |
|
| 1376 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1377 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1378 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1379 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1380 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1381 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1382 | + . "\n\tif (\$debut_boucle>0" |
|
| 1383 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1384 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1385 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1386 | + |
|
| 1387 | + $boucles[$id_boucle]->partie = " |
|
| 1388 | 1388 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1389 | 1389 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1390 | 1390 | } |
@@ -1401,26 +1401,26 @@ discard block |
||
| 1401 | 1401 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1402 | 1402 | **/ |
| 1403 | 1403 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1404 | - if ($param[0]->type != 'texte') { |
|
| 1405 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1406 | - if (isset($param[1]->texte)) { |
|
| 1407 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1408 | - |
|
| 1409 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1410 | - } else { |
|
| 1411 | - return ["intval($a1)", 0]; |
|
| 1412 | - } |
|
| 1413 | - } else { |
|
| 1414 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1415 | - $a1 = $m[1]; |
|
| 1416 | - if (empty($m[3])) { |
|
| 1417 | - return [$a1, 0]; |
|
| 1418 | - } elseif (!empty($m[4])) { |
|
| 1419 | - return [$a1, $m[4]]; |
|
| 1420 | - } else { |
|
| 1421 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1422 | - } |
|
| 1423 | - } |
|
| 1404 | + if ($param[0]->type != 'texte') { |
|
| 1405 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1406 | + if (isset($param[1]->texte)) { |
|
| 1407 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1408 | + |
|
| 1409 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1410 | + } else { |
|
| 1411 | + return ["intval($a1)", 0]; |
|
| 1412 | + } |
|
| 1413 | + } else { |
|
| 1414 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1415 | + $a1 = $m[1]; |
|
| 1416 | + if (empty($m[3])) { |
|
| 1417 | + return [$a1, 0]; |
|
| 1418 | + } elseif (!empty($m[4])) { |
|
| 1419 | + return [$a1, $m[4]]; |
|
| 1420 | + } else { |
|
| 1421 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1422 | + } |
|
| 1423 | + } |
|
| 1424 | 1424 | } |
| 1425 | 1425 | |
| 1426 | 1426 | |
@@ -1447,47 +1447,47 @@ discard block |
||
| 1447 | 1447 | * array : Erreur sur un des critères |
| 1448 | 1448 | **/ |
| 1449 | 1449 | function calculer_criteres($idb, &$boucles) { |
| 1450 | - $msg = ''; |
|
| 1451 | - $boucle = $boucles[$idb]; |
|
| 1452 | - $table = strtoupper($boucle->type_requete); |
|
| 1453 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1454 | - |
|
| 1455 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1456 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1457 | - if (!is_array($boucle->criteres)) { |
|
| 1458 | - return []; |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - foreach ($boucle->criteres as $crit) { |
|
| 1462 | - $critere = $crit->op; |
|
| 1463 | - // critere personnalise ? |
|
| 1464 | - if ( |
|
| 1465 | - (!$serveur or |
|
| 1466 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1470 | - ) |
|
| 1471 | - ) |
|
| 1472 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1473 | - and (!function_exists($f = $f . '_dist')) |
|
| 1474 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1475 | - and (!function_exists($f = $f . '_dist')) |
|
| 1476 | - ) { |
|
| 1477 | - // fonction critere standard |
|
| 1478 | - $f = $defaut; |
|
| 1479 | - } |
|
| 1480 | - // compile le critere |
|
| 1481 | - $res = $f($idb, $boucles, $crit); |
|
| 1482 | - |
|
| 1483 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1484 | - if (is_array($res)) { |
|
| 1485 | - $msg = $res; |
|
| 1486 | - erreur_squelette($msg, $boucle); |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - |
|
| 1490 | - return $msg; |
|
| 1450 | + $msg = ''; |
|
| 1451 | + $boucle = $boucles[$idb]; |
|
| 1452 | + $table = strtoupper($boucle->type_requete); |
|
| 1453 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1454 | + |
|
| 1455 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1456 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1457 | + if (!is_array($boucle->criteres)) { |
|
| 1458 | + return []; |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + foreach ($boucle->criteres as $crit) { |
|
| 1462 | + $critere = $crit->op; |
|
| 1463 | + // critere personnalise ? |
|
| 1464 | + if ( |
|
| 1465 | + (!$serveur or |
|
| 1466 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1467 | + and (!function_exists($f = $f . '_dist')) |
|
| 1468 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1469 | + and (!function_exists($f = $f . '_dist')) |
|
| 1470 | + ) |
|
| 1471 | + ) |
|
| 1472 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1473 | + and (!function_exists($f = $f . '_dist')) |
|
| 1474 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1475 | + and (!function_exists($f = $f . '_dist')) |
|
| 1476 | + ) { |
|
| 1477 | + // fonction critere standard |
|
| 1478 | + $f = $defaut; |
|
| 1479 | + } |
|
| 1480 | + // compile le critere |
|
| 1481 | + $res = $f($idb, $boucles, $crit); |
|
| 1482 | + |
|
| 1483 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1484 | + if (is_array($res)) { |
|
| 1485 | + $msg = $res; |
|
| 1486 | + erreur_squelette($msg, $boucle); |
|
| 1487 | + } |
|
| 1488 | + } |
|
| 1489 | + |
|
| 1490 | + return $msg; |
|
| 1491 | 1491 | } |
| 1492 | 1492 | |
| 1493 | 1493 | /** |
@@ -1504,11 +1504,11 @@ discard block |
||
| 1504 | 1504 | * @return string Code compilé rééchappé |
| 1505 | 1505 | */ |
| 1506 | 1506 | function kwote($lisp, $serveur = '', $type = '') { |
| 1507 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1508 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1509 | - } else { |
|
| 1510 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1511 | - } |
|
| 1507 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1508 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1509 | + } else { |
|
| 1510 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1511 | + } |
|
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | |
@@ -1527,82 +1527,82 @@ discard block |
||
| 1527 | 1527 | * @return void |
| 1528 | 1528 | **/ |
| 1529 | 1529 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1530 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1531 | - if (!$r) { |
|
| 1532 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1533 | - } |
|
| 1534 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1535 | - |
|
| 1536 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1537 | - |
|
| 1538 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1539 | - $where = $in; |
|
| 1540 | - if ($crit->cond) { |
|
| 1541 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1542 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1543 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1544 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1545 | - } |
|
| 1546 | - } |
|
| 1547 | - if ($crit->exclus) { |
|
| 1548 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1549 | - $where = ["'NOT'", $where]; |
|
| 1550 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1551 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1552 | - { |
|
| 1553 | - $where = [ |
|
| 1554 | - "'NOT'", |
|
| 1555 | - [ |
|
| 1556 | - "'IN'", |
|
| 1557 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1558 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1559 | - ] |
|
| 1560 | - ]; |
|
| 1561 | - } |
|
| 1562 | - } |
|
| 1563 | - |
|
| 1564 | - $boucles[$idb]->where[] = $where; |
|
| 1565 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1566 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1567 | - } |
|
| 1530 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1531 | + if (!$r) { |
|
| 1532 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1533 | + } |
|
| 1534 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1535 | + |
|
| 1536 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1537 | + |
|
| 1538 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1539 | + $where = $in; |
|
| 1540 | + if ($crit->cond) { |
|
| 1541 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1542 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1543 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1544 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1545 | + } |
|
| 1546 | + } |
|
| 1547 | + if ($crit->exclus) { |
|
| 1548 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1549 | + $where = ["'NOT'", $where]; |
|
| 1550 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1551 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1552 | + { |
|
| 1553 | + $where = [ |
|
| 1554 | + "'NOT'", |
|
| 1555 | + [ |
|
| 1556 | + "'IN'", |
|
| 1557 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1558 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1559 | + ] |
|
| 1560 | + ]; |
|
| 1561 | + } |
|
| 1562 | + } |
|
| 1563 | + |
|
| 1564 | + $boucles[$idb]->where[] = $where; |
|
| 1565 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1566 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1567 | + } |
|
| 1568 | 1568 | } |
| 1569 | 1569 | |
| 1570 | 1570 | // https://code.spip.net/@critere_IN_cas |
| 1571 | 1571 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1572 | - static $num = []; |
|
| 1573 | - $descr = $boucles[$idb]->descr; |
|
| 1574 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1575 | - |
|
| 1576 | - $var = '$in' . $cpt++; |
|
| 1577 | - $x = "\n\t$var = array();"; |
|
| 1578 | - foreach ($val as $k => $v) { |
|
| 1579 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1580 | - // optimiser le traitement des constantes |
|
| 1581 | - if (is_numeric($r[2])) { |
|
| 1582 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1583 | - } else { |
|
| 1584 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1585 | - } |
|
| 1586 | - } else { |
|
| 1587 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1588 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1589 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1590 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1591 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1592 | - } |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - $boucles[$idb]->in .= $x; |
|
| 1596 | - |
|
| 1597 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1598 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1599 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1600 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1601 | - if (!$crit2) { |
|
| 1602 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1572 | + static $num = []; |
|
| 1573 | + $descr = $boucles[$idb]->descr; |
|
| 1574 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1575 | + |
|
| 1576 | + $var = '$in' . $cpt++; |
|
| 1577 | + $x = "\n\t$var = array();"; |
|
| 1578 | + foreach ($val as $k => $v) { |
|
| 1579 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1580 | + // optimiser le traitement des constantes |
|
| 1581 | + if (is_numeric($r[2])) { |
|
| 1582 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1583 | + } else { |
|
| 1584 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1585 | + } |
|
| 1586 | + } else { |
|
| 1587 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1588 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1589 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1590 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1591 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1592 | + } |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + $boucles[$idb]->in .= $x; |
|
| 1596 | + |
|
| 1597 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1598 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1599 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1600 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1601 | + if (!$crit2) { |
|
| 1602 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1603 | + } |
|
| 1604 | + |
|
| 1605 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | 1608 | /** |
@@ -1618,22 +1618,22 @@ discard block |
||
| 1618 | 1618 | * @return void |
| 1619 | 1619 | */ |
| 1620 | 1620 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1621 | - $boucle = &$boucles[$idb]; |
|
| 1622 | - if (isset($crit->param[0])) { |
|
| 1623 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1624 | - } else { |
|
| 1625 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - if ($crit->cond) { |
|
| 1629 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - if ($crit->not) { |
|
| 1633 | - $_where = "array('NOT',$_where)"; |
|
| 1634 | - } |
|
| 1635 | - |
|
| 1636 | - $boucle->where[] = $_where; |
|
| 1621 | + $boucle = &$boucles[$idb]; |
|
| 1622 | + if (isset($crit->param[0])) { |
|
| 1623 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1624 | + } else { |
|
| 1625 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1626 | + } |
|
| 1627 | + |
|
| 1628 | + if ($crit->cond) { |
|
| 1629 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + if ($crit->not) { |
|
| 1633 | + $_where = "array('NOT',$_where)"; |
|
| 1634 | + } |
|
| 1635 | + |
|
| 1636 | + $boucle->where[] = $_where; |
|
| 1637 | 1637 | } |
| 1638 | 1638 | |
| 1639 | 1639 | /** |
@@ -1661,31 +1661,31 @@ discard block |
||
| 1661 | 1661 | * @return void |
| 1662 | 1662 | */ |
| 1663 | 1663 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1664 | - /** @var Boucle $boucle */ |
|
| 1665 | - $boucle = $boucles[$idb]; |
|
| 1666 | - |
|
| 1667 | - $champs = lister_champs_id_conditionnel( |
|
| 1668 | - $boucle->show['table'], |
|
| 1669 | - $boucle->show, |
|
| 1670 | - $boucle->sql_serveur |
|
| 1671 | - ); |
|
| 1672 | - |
|
| 1673 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1674 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1675 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1676 | - } |
|
| 1677 | - // nous aider en mode debug. |
|
| 1678 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1679 | - $boucle->modificateur['id_'] = $champs; |
|
| 1680 | - |
|
| 1681 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1682 | - foreach ($champs as $champ) { |
|
| 1683 | - $critere_id_table = new Critere(); |
|
| 1684 | - $critere_id_table->op = $champ; |
|
| 1685 | - $critere_id_table->cond = '?'; |
|
| 1686 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1687 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1688 | - } |
|
| 1664 | + /** @var Boucle $boucle */ |
|
| 1665 | + $boucle = $boucles[$idb]; |
|
| 1666 | + |
|
| 1667 | + $champs = lister_champs_id_conditionnel( |
|
| 1668 | + $boucle->show['table'], |
|
| 1669 | + $boucle->show, |
|
| 1670 | + $boucle->sql_serveur |
|
| 1671 | + ); |
|
| 1672 | + |
|
| 1673 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1674 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1675 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1676 | + } |
|
| 1677 | + // nous aider en mode debug. |
|
| 1678 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1679 | + $boucle->modificateur['id_'] = $champs; |
|
| 1680 | + |
|
| 1681 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1682 | + foreach ($champs as $champ) { |
|
| 1683 | + $critere_id_table = new Critere(); |
|
| 1684 | + $critere_id_table->op = $champ; |
|
| 1685 | + $critere_id_table->cond = '?'; |
|
| 1686 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1687 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1688 | + } |
|
| 1689 | 1689 | } |
| 1690 | 1690 | |
| 1691 | 1691 | /** |
@@ -1705,79 +1705,79 @@ discard block |
||
| 1705 | 1705 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1706 | 1706 | */ |
| 1707 | 1707 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1708 | - // calculer la description de la table |
|
| 1709 | - if (!is_array($desc)) { |
|
| 1710 | - $desc = description_table($table, $serveur); |
|
| 1711 | - } |
|
| 1712 | - if (!$desc) { |
|
| 1713 | - return []; |
|
| 1714 | - } |
|
| 1715 | - |
|
| 1716 | - // Les champs id_xx de la table demandée |
|
| 1717 | - $champs = array_filter( |
|
| 1718 | - array_keys($desc['field']), |
|
| 1719 | - function ($champ) { |
|
| 1720 | - return |
|
| 1721 | - strpos($champ, 'id_') === 0 |
|
| 1722 | - or (in_array($champ, ['objet'])); |
|
| 1723 | - } |
|
| 1724 | - ); |
|
| 1725 | - |
|
| 1726 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1727 | - if ( |
|
| 1728 | - in_array('id_rubrique', $champs) |
|
| 1729 | - and !in_array('id_secteur', $champs) |
|
| 1730 | - ) { |
|
| 1731 | - $champs[] = 'id_secteur'; |
|
| 1732 | - } |
|
| 1733 | - |
|
| 1734 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1735 | - if ($serveur) { |
|
| 1736 | - return $champs; |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - $primary = false; |
|
| 1740 | - $associable = false; |
|
| 1741 | - include_spip('action/editer_liens'); |
|
| 1742 | - |
|
| 1743 | - if (isset($desc['type'])) { |
|
| 1744 | - $primary = id_table_objet($desc['type']); |
|
| 1745 | - $associable = objet_associable($desc['type']); |
|
| 1746 | - } |
|
| 1747 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1748 | - $associable = true; |
|
| 1749 | - } |
|
| 1750 | - |
|
| 1751 | - // liste de toutes les tables principales, sauf la notre |
|
| 1752 | - $tables = lister_tables_objets_sql(); |
|
| 1753 | - unset($tables[$table]); |
|
| 1754 | - |
|
| 1755 | - foreach ($tables as $_table => $_desc) { |
|
| 1756 | - if ( |
|
| 1757 | - $associable |
|
| 1758 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1759 | - or objet_associable($_desc['type']) |
|
| 1760 | - ) { |
|
| 1761 | - $champs[] = id_table_objet($_table); |
|
| 1762 | - } |
|
| 1763 | - } |
|
| 1764 | - $champs = array_values(array_unique($champs)); |
|
| 1765 | - |
|
| 1766 | - // Exclusions de certains id |
|
| 1767 | - $exclusions = pipeline( |
|
| 1768 | - 'exclure_id_conditionnel', |
|
| 1769 | - [ |
|
| 1770 | - 'args' => [ |
|
| 1771 | - 'table' => $table, |
|
| 1772 | - 'id_table_objet' => $primary, |
|
| 1773 | - 'associable' => $associable, |
|
| 1774 | - ], |
|
| 1775 | - 'data' => [], |
|
| 1776 | - ] |
|
| 1777 | - ); |
|
| 1778 | - $champs = array_diff($champs, $exclusions); |
|
| 1779 | - |
|
| 1780 | - return $champs; |
|
| 1708 | + // calculer la description de la table |
|
| 1709 | + if (!is_array($desc)) { |
|
| 1710 | + $desc = description_table($table, $serveur); |
|
| 1711 | + } |
|
| 1712 | + if (!$desc) { |
|
| 1713 | + return []; |
|
| 1714 | + } |
|
| 1715 | + |
|
| 1716 | + // Les champs id_xx de la table demandée |
|
| 1717 | + $champs = array_filter( |
|
| 1718 | + array_keys($desc['field']), |
|
| 1719 | + function ($champ) { |
|
| 1720 | + return |
|
| 1721 | + strpos($champ, 'id_') === 0 |
|
| 1722 | + or (in_array($champ, ['objet'])); |
|
| 1723 | + } |
|
| 1724 | + ); |
|
| 1725 | + |
|
| 1726 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1727 | + if ( |
|
| 1728 | + in_array('id_rubrique', $champs) |
|
| 1729 | + and !in_array('id_secteur', $champs) |
|
| 1730 | + ) { |
|
| 1731 | + $champs[] = 'id_secteur'; |
|
| 1732 | + } |
|
| 1733 | + |
|
| 1734 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1735 | + if ($serveur) { |
|
| 1736 | + return $champs; |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + $primary = false; |
|
| 1740 | + $associable = false; |
|
| 1741 | + include_spip('action/editer_liens'); |
|
| 1742 | + |
|
| 1743 | + if (isset($desc['type'])) { |
|
| 1744 | + $primary = id_table_objet($desc['type']); |
|
| 1745 | + $associable = objet_associable($desc['type']); |
|
| 1746 | + } |
|
| 1747 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1748 | + $associable = true; |
|
| 1749 | + } |
|
| 1750 | + |
|
| 1751 | + // liste de toutes les tables principales, sauf la notre |
|
| 1752 | + $tables = lister_tables_objets_sql(); |
|
| 1753 | + unset($tables[$table]); |
|
| 1754 | + |
|
| 1755 | + foreach ($tables as $_table => $_desc) { |
|
| 1756 | + if ( |
|
| 1757 | + $associable |
|
| 1758 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1759 | + or objet_associable($_desc['type']) |
|
| 1760 | + ) { |
|
| 1761 | + $champs[] = id_table_objet($_table); |
|
| 1762 | + } |
|
| 1763 | + } |
|
| 1764 | + $champs = array_values(array_unique($champs)); |
|
| 1765 | + |
|
| 1766 | + // Exclusions de certains id |
|
| 1767 | + $exclusions = pipeline( |
|
| 1768 | + 'exclure_id_conditionnel', |
|
| 1769 | + [ |
|
| 1770 | + 'args' => [ |
|
| 1771 | + 'table' => $table, |
|
| 1772 | + 'id_table_objet' => $primary, |
|
| 1773 | + 'associable' => $associable, |
|
| 1774 | + ], |
|
| 1775 | + 'data' => [], |
|
| 1776 | + ] |
|
| 1777 | + ); |
|
| 1778 | + $champs = array_diff($champs, $exclusions); |
|
| 1779 | + |
|
| 1780 | + return $champs; |
|
| 1781 | 1781 | } |
| 1782 | 1782 | |
| 1783 | 1783 | /** |
@@ -1832,27 +1832,27 @@ discard block |
||
| 1832 | 1832 | * @return void |
| 1833 | 1833 | */ |
| 1834 | 1834 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1835 | - $boucle = &$boucles[$idb]; |
|
| 1836 | - |
|
| 1837 | - // definition du champ par defaut |
|
| 1838 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1839 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1840 | - $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1841 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1842 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1843 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1844 | - |
|
| 1845 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1846 | - |
|
| 1847 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1848 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1849 | - |
|
| 1850 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1851 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1852 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1853 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1854 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1855 | - $boucle->hash .= " |
|
| 1835 | + $boucle = &$boucles[$idb]; |
|
| 1836 | + |
|
| 1837 | + // definition du champ par defaut |
|
| 1838 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1839 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1840 | + $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1841 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1842 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1843 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1844 | + |
|
| 1845 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1846 | + |
|
| 1847 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1848 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1849 | + |
|
| 1850 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1851 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1852 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1853 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1854 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1855 | + $boucle->hash .= " |
|
| 1856 | 1856 | \$senstri = ''; |
| 1857 | 1857 | \$tri = $_tri; |
| 1858 | 1858 | if (\$tri){ |
@@ -1860,8 +1860,8 @@ discard block |
||
| 1860 | 1860 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1861 | 1861 | }; |
| 1862 | 1862 | "; |
| 1863 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1864 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1863 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1864 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1865 | 1865 | } |
| 1866 | 1866 | |
| 1867 | 1867 | # Criteres de comparaison |
@@ -1878,20 +1878,20 @@ discard block |
||
| 1878 | 1878 | * @return void |
| 1879 | 1879 | **/ |
| 1880 | 1880 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1881 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1882 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1883 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1887 | - if (!$r) { |
|
| 1888 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1889 | - # if (!$crit->cond) { |
|
| 1890 | - return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1891 | - # } |
|
| 1892 | - } else { |
|
| 1893 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1894 | - } |
|
| 1881 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1882 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1883 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1887 | + if (!$r) { |
|
| 1888 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1889 | + # if (!$crit->cond) { |
|
| 1890 | + return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1891 | + # } |
|
| 1892 | + } else { |
|
| 1893 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1894 | + } |
|
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | 1897 | |
@@ -1911,62 +1911,62 @@ discard block |
||
| 1911 | 1911 | * @return void |
| 1912 | 1912 | **/ |
| 1913 | 1913 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1914 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1915 | - |
|
| 1916 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1917 | - |
|
| 1918 | - // inserer la negation (cf !...) |
|
| 1919 | - |
|
| 1920 | - if ($crit->not) { |
|
| 1921 | - $where = ["'NOT'", $where]; |
|
| 1922 | - } |
|
| 1923 | - if ($crit->exclus) { |
|
| 1924 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1925 | - $where = ["'NOT'", $where]; |
|
| 1926 | - } else { |
|
| 1927 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1928 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1929 | - $where = [ |
|
| 1930 | - "'NOT'", |
|
| 1931 | - [ |
|
| 1932 | - "'IN'", |
|
| 1933 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1934 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1935 | - ] |
|
| 1936 | - ]; |
|
| 1937 | - } |
|
| 1938 | - } |
|
| 1939 | - |
|
| 1940 | - // inserer la condition (cf {lang?}) |
|
| 1941 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1942 | - if ($crit->cond) { |
|
| 1943 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1944 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1945 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1946 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1947 | - } |
|
| 1948 | - } |
|
| 1949 | - |
|
| 1950 | - if ($op === '=' and !$crit->not) { |
|
| 1951 | - $where = [ |
|
| 1952 | - "'?'", |
|
| 1953 | - "(is_array($pred))", |
|
| 1954 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1955 | - $where |
|
| 1956 | - ]; |
|
| 1957 | - } |
|
| 1958 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1959 | - if ($where_complement) { |
|
| 1960 | - // condition annexe du type "AND (objet='article')" |
|
| 1961 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1962 | - } |
|
| 1963 | - } |
|
| 1964 | - |
|
| 1965 | - $boucles[$idb]->where[] = $where; |
|
| 1966 | - if ($where_complement) { |
|
| 1967 | - // condition annexe du type "AND (objet='article')" |
|
| 1968 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1969 | - } |
|
| 1914 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1915 | + |
|
| 1916 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1917 | + |
|
| 1918 | + // inserer la negation (cf !...) |
|
| 1919 | + |
|
| 1920 | + if ($crit->not) { |
|
| 1921 | + $where = ["'NOT'", $where]; |
|
| 1922 | + } |
|
| 1923 | + if ($crit->exclus) { |
|
| 1924 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1925 | + $where = ["'NOT'", $where]; |
|
| 1926 | + } else { |
|
| 1927 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1928 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1929 | + $where = [ |
|
| 1930 | + "'NOT'", |
|
| 1931 | + [ |
|
| 1932 | + "'IN'", |
|
| 1933 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1934 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1935 | + ] |
|
| 1936 | + ]; |
|
| 1937 | + } |
|
| 1938 | + } |
|
| 1939 | + |
|
| 1940 | + // inserer la condition (cf {lang?}) |
|
| 1941 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1942 | + if ($crit->cond) { |
|
| 1943 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1944 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1945 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1946 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1947 | + } |
|
| 1948 | + } |
|
| 1949 | + |
|
| 1950 | + if ($op === '=' and !$crit->not) { |
|
| 1951 | + $where = [ |
|
| 1952 | + "'?'", |
|
| 1953 | + "(is_array($pred))", |
|
| 1954 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1955 | + $where |
|
| 1956 | + ]; |
|
| 1957 | + } |
|
| 1958 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1959 | + if ($where_complement) { |
|
| 1960 | + // condition annexe du type "AND (objet='article')" |
|
| 1961 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1962 | + } |
|
| 1963 | + } |
|
| 1964 | + |
|
| 1965 | + $boucles[$idb]->where[] = $where; |
|
| 1966 | + if ($where_complement) { |
|
| 1967 | + // condition annexe du type "AND (objet='article')" |
|
| 1968 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1969 | + } |
|
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | 1972 | |
@@ -2007,165 +2007,165 @@ discard block |
||
| 2007 | 2007 | **/ |
| 2008 | 2008 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2009 | 2009 | |
| 2010 | - $boucle = &$boucles[$idb]; |
|
| 2011 | - $type = $boucle->type_requete; |
|
| 2012 | - $table = $boucle->id_table ?? ''; |
|
| 2013 | - $desc = $boucle->show; |
|
| 2014 | - $col_vraie = null; |
|
| 2015 | - |
|
| 2016 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 2017 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2018 | - |
|
| 2019 | - $col_alias = $col; |
|
| 2020 | - $where_complement = false; |
|
| 2021 | - |
|
| 2022 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2023 | - if ($col == 'id_enfant') { |
|
| 2024 | - $col = $boucle->primary; |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2028 | - if ( |
|
| 2029 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2030 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2031 | - ) { |
|
| 2032 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2033 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2034 | - else { |
|
| 2035 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2036 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2037 | - } |
|
| 2038 | - |
|
| 2039 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2040 | - // sauf si exception declaree : sauter cette etape |
|
| 2041 | - else { |
|
| 2042 | - if ( |
|
| 2043 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2044 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2045 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2046 | - ) { |
|
| 2047 | - $e = decompose_champ_id_objet($col); |
|
| 2048 | - $col = array_shift($e); |
|
| 2049 | - $where_complement = primary_doublee($e, $table); |
|
| 2050 | - } // Cas particulier : expressions de date |
|
| 2051 | - else { |
|
| 2052 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2053 | - list($col, $col_vraie) = $c; |
|
| 2054 | - $table = ''; |
|
| 2055 | - } // table explicitée {mots.titre} |
|
| 2056 | - else { |
|
| 2057 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2058 | - list(, $table, $col) = $r; |
|
| 2059 | - $col_alias = $col; |
|
| 2060 | - |
|
| 2061 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2062 | - if ( |
|
| 2063 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2064 | - and isset($desc['field'][$col]) |
|
| 2065 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2066 | - ) { |
|
| 2067 | - $table = $cle; |
|
| 2068 | - } else { |
|
| 2069 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2070 | - } |
|
| 2071 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2072 | - if (!$table) { |
|
| 2073 | - return ''; |
|
| 2074 | - } |
|
| 2075 | - } |
|
| 2076 | - // si le champ n'est pas trouvé dans la table, |
|
| 2077 | - // on cherche si une jointure peut l'obtenir |
|
| 2078 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2079 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2080 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2081 | - $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2082 | - } |
|
| 2083 | - else { |
|
| 2084 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2085 | - if (!$r) { |
|
| 2086 | - return ''; |
|
| 2087 | - } |
|
| 2088 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2089 | - } |
|
| 2090 | - } |
|
| 2091 | - } |
|
| 2092 | - } |
|
| 2093 | - } |
|
| 2094 | - } |
|
| 2095 | - |
|
| 2096 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2097 | - // Dans tous les cas, |
|
| 2098 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2099 | - // et passer dans sql_quote avec le type si connu |
|
| 2100 | - // et int sinon si la valeur est numerique |
|
| 2101 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2102 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2103 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2104 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2105 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2106 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2107 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2108 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2109 | - } |
|
| 2110 | - // sinon expliciter les |
|
| 2111 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2112 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2113 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2114 | - // sans toucher aux |
|
| 2115 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2116 | - // sql_quote(truc,'','varchar') |
|
| 2117 | - elseif ( |
|
| 2118 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2119 | - // si pas deja un type |
|
| 2120 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2121 | - ) { |
|
| 2122 | - $r = $r[1] |
|
| 2123 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2124 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2125 | - $val[0] = "sql_quote($r)"; |
|
| 2126 | - } |
|
| 2127 | - elseif ( |
|
| 2128 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2129 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2130 | - ) { |
|
| 2131 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2132 | - } |
|
| 2133 | - } |
|
| 2134 | - |
|
| 2135 | - if ( |
|
| 2136 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2137 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2138 | - ) { |
|
| 2139 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2140 | - } |
|
| 2141 | - |
|
| 2142 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2143 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2144 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2145 | - if ($table === $boucle->id_table) { |
|
| 2146 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2147 | - if ($col_alias != $col_vraie) { |
|
| 2148 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2149 | - } |
|
| 2150 | - } |
|
| 2151 | - |
|
| 2152 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2153 | - if ($table) { |
|
| 2154 | - if ($col[0] == '`') { |
|
| 2155 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2156 | - } else { |
|
| 2157 | - $arg = "$table.$col"; |
|
| 2158 | - } |
|
| 2159 | - } else { |
|
| 2160 | - $arg = $col; |
|
| 2161 | - } |
|
| 2162 | - |
|
| 2163 | - // inserer la fonction SQL |
|
| 2164 | - if ($fct) { |
|
| 2165 | - $arg = "$fct($arg$args_sql)"; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2010 | + $boucle = &$boucles[$idb]; |
|
| 2011 | + $type = $boucle->type_requete; |
|
| 2012 | + $table = $boucle->id_table ?? ''; |
|
| 2013 | + $desc = $boucle->show; |
|
| 2014 | + $col_vraie = null; |
|
| 2015 | + |
|
| 2016 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 2017 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2018 | + |
|
| 2019 | + $col_alias = $col; |
|
| 2020 | + $where_complement = false; |
|
| 2021 | + |
|
| 2022 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2023 | + if ($col == 'id_enfant') { |
|
| 2024 | + $col = $boucle->primary; |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2028 | + if ( |
|
| 2029 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2030 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2031 | + ) { |
|
| 2032 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2033 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2034 | + else { |
|
| 2035 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2036 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2037 | + } |
|
| 2038 | + |
|
| 2039 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2040 | + // sauf si exception declaree : sauter cette etape |
|
| 2041 | + else { |
|
| 2042 | + if ( |
|
| 2043 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2044 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2045 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2046 | + ) { |
|
| 2047 | + $e = decompose_champ_id_objet($col); |
|
| 2048 | + $col = array_shift($e); |
|
| 2049 | + $where_complement = primary_doublee($e, $table); |
|
| 2050 | + } // Cas particulier : expressions de date |
|
| 2051 | + else { |
|
| 2052 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2053 | + list($col, $col_vraie) = $c; |
|
| 2054 | + $table = ''; |
|
| 2055 | + } // table explicitée {mots.titre} |
|
| 2056 | + else { |
|
| 2057 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2058 | + list(, $table, $col) = $r; |
|
| 2059 | + $col_alias = $col; |
|
| 2060 | + |
|
| 2061 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2062 | + if ( |
|
| 2063 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2064 | + and isset($desc['field'][$col]) |
|
| 2065 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2066 | + ) { |
|
| 2067 | + $table = $cle; |
|
| 2068 | + } else { |
|
| 2069 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2070 | + } |
|
| 2071 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2072 | + if (!$table) { |
|
| 2073 | + return ''; |
|
| 2074 | + } |
|
| 2075 | + } |
|
| 2076 | + // si le champ n'est pas trouvé dans la table, |
|
| 2077 | + // on cherche si une jointure peut l'obtenir |
|
| 2078 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2079 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2080 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2081 | + $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2082 | + } |
|
| 2083 | + else { |
|
| 2084 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2085 | + if (!$r) { |
|
| 2086 | + return ''; |
|
| 2087 | + } |
|
| 2088 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2089 | + } |
|
| 2090 | + } |
|
| 2091 | + } |
|
| 2092 | + } |
|
| 2093 | + } |
|
| 2094 | + } |
|
| 2095 | + |
|
| 2096 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2097 | + // Dans tous les cas, |
|
| 2098 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2099 | + // et passer dans sql_quote avec le type si connu |
|
| 2100 | + // et int sinon si la valeur est numerique |
|
| 2101 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2102 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2103 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2104 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2105 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2106 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2107 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2108 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2109 | + } |
|
| 2110 | + // sinon expliciter les |
|
| 2111 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2112 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2113 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2114 | + // sans toucher aux |
|
| 2115 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2116 | + // sql_quote(truc,'','varchar') |
|
| 2117 | + elseif ( |
|
| 2118 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2119 | + // si pas deja un type |
|
| 2120 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2121 | + ) { |
|
| 2122 | + $r = $r[1] |
|
| 2123 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2124 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2125 | + $val[0] = "sql_quote($r)"; |
|
| 2126 | + } |
|
| 2127 | + elseif ( |
|
| 2128 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2129 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2130 | + ) { |
|
| 2131 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2132 | + } |
|
| 2133 | + } |
|
| 2134 | + |
|
| 2135 | + if ( |
|
| 2136 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2137 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2138 | + ) { |
|
| 2139 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2140 | + } |
|
| 2141 | + |
|
| 2142 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2143 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2144 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2145 | + if ($table === $boucle->id_table) { |
|
| 2146 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2147 | + if ($col_alias != $col_vraie) { |
|
| 2148 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2149 | + } |
|
| 2150 | + } |
|
| 2151 | + |
|
| 2152 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2153 | + if ($table) { |
|
| 2154 | + if ($col[0] == '`') { |
|
| 2155 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2156 | + } else { |
|
| 2157 | + $arg = "$table.$col"; |
|
| 2158 | + } |
|
| 2159 | + } else { |
|
| 2160 | + $arg = $col; |
|
| 2161 | + } |
|
| 2162 | + |
|
| 2163 | + // inserer la fonction SQL |
|
| 2164 | + if ($fct) { |
|
| 2165 | + $arg = "$fct($arg$args_sql)"; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2169 | 2169 | } |
| 2170 | 2170 | |
| 2171 | 2171 | |
@@ -2194,78 +2194,78 @@ discard block |
||
| 2194 | 2194 | **/ |
| 2195 | 2195 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2196 | 2196 | |
| 2197 | - $where = ''; |
|
| 2198 | - |
|
| 2199 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2200 | - // gestion par les plugins des jointures tordues |
|
| 2201 | - // pas automatiques mais necessaires |
|
| 2202 | - $table_sql = table_objet_sql($table); |
|
| 2203 | - if ( |
|
| 2204 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2205 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2206 | - and |
|
| 2207 | - ( |
|
| 2208 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2209 | - or |
|
| 2210 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2211 | - ) |
|
| 2212 | - ) { |
|
| 2213 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2214 | - $index = isset($t[$col]) |
|
| 2215 | - ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2216 | - |
|
| 2217 | - if (count($index) == 3) { |
|
| 2218 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2219 | - } elseif (count($index) == 2) { |
|
| 2220 | - list($t, $col) = $t[$col]; |
|
| 2221 | - } elseif (count($index) == 1) { |
|
| 2222 | - list($calculer_critere_externe) = $index; |
|
| 2223 | - $t = $table; |
|
| 2224 | - } else { |
|
| 2225 | - $t = ''; |
|
| 2226 | - } // jointure non declaree. La trouver. |
|
| 2227 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2228 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2229 | - } else { |
|
| 2230 | - $t = ''; |
|
| 2231 | - } // jointure non declaree. La trouver. |
|
| 2232 | - |
|
| 2233 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2234 | - |
|
| 2235 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2236 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2237 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2238 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2239 | - $table = ''; |
|
| 2240 | - if ($boucle->jointures_explicites) { |
|
| 2241 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2242 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2243 | - } |
|
| 2244 | - |
|
| 2245 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2246 | - if (!$table) { |
|
| 2247 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2248 | - } |
|
| 2249 | - |
|
| 2250 | - if (!$table) { |
|
| 2251 | - return ''; |
|
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2255 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2256 | - |
|
| 2257 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2258 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2259 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2260 | - $e = decompose_champ_id_objet($col); |
|
| 2261 | - $col = array_shift($e); |
|
| 2262 | - $where = primary_doublee($e, $table); |
|
| 2263 | - } else { |
|
| 2264 | - $col = reset($cle); |
|
| 2265 | - } |
|
| 2266 | - } |
|
| 2267 | - |
|
| 2268 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2197 | + $where = ''; |
|
| 2198 | + |
|
| 2199 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2200 | + // gestion par les plugins des jointures tordues |
|
| 2201 | + // pas automatiques mais necessaires |
|
| 2202 | + $table_sql = table_objet_sql($table); |
|
| 2203 | + if ( |
|
| 2204 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2205 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2206 | + and |
|
| 2207 | + ( |
|
| 2208 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2209 | + or |
|
| 2210 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2211 | + ) |
|
| 2212 | + ) { |
|
| 2213 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2214 | + $index = isset($t[$col]) |
|
| 2215 | + ? $t[$col] : (isset($t['']) ? $t[''] : []); |
|
| 2216 | + |
|
| 2217 | + if (count($index) == 3) { |
|
| 2218 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2219 | + } elseif (count($index) == 2) { |
|
| 2220 | + list($t, $col) = $t[$col]; |
|
| 2221 | + } elseif (count($index) == 1) { |
|
| 2222 | + list($calculer_critere_externe) = $index; |
|
| 2223 | + $t = $table; |
|
| 2224 | + } else { |
|
| 2225 | + $t = ''; |
|
| 2226 | + } // jointure non declaree. La trouver. |
|
| 2227 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2228 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2229 | + } else { |
|
| 2230 | + $t = ''; |
|
| 2231 | + } // jointure non declaree. La trouver. |
|
| 2232 | + |
|
| 2233 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2234 | + |
|
| 2235 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2236 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2237 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2238 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2239 | + $table = ''; |
|
| 2240 | + if ($boucle->jointures_explicites) { |
|
| 2241 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2242 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2246 | + if (!$table) { |
|
| 2247 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2248 | + } |
|
| 2249 | + |
|
| 2250 | + if (!$table) { |
|
| 2251 | + return ''; |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2255 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2256 | + |
|
| 2257 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2258 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2259 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2260 | + $e = decompose_champ_id_objet($col); |
|
| 2261 | + $col = array_shift($e); |
|
| 2262 | + $where = primary_doublee($e, $table); |
|
| 2263 | + } else { |
|
| 2264 | + $col = reset($cle); |
|
| 2265 | + } |
|
| 2266 | + } |
|
| 2267 | + |
|
| 2268 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2269 | 2269 | } |
| 2270 | 2270 | |
| 2271 | 2271 | |
@@ -2286,10 +2286,10 @@ discard block |
||
| 2286 | 2286 | * - valeur |
| 2287 | 2287 | **/ |
| 2288 | 2288 | function primary_doublee($decompose, $table) { |
| 2289 | - $e1 = reset($decompose); |
|
| 2290 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2289 | + $e1 = reset($decompose); |
|
| 2290 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2291 | 2291 | |
| 2292 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2292 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2293 | 2293 | } |
| 2294 | 2294 | |
| 2295 | 2295 | /** |
@@ -2320,57 +2320,57 @@ discard block |
||
| 2320 | 2320 | * Vide sinon. |
| 2321 | 2321 | */ |
| 2322 | 2322 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2323 | - // si on demande un truc du genre spip_mots |
|
| 2324 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2325 | - // et qu'on est la |
|
| 2326 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2327 | - if ( |
|
| 2328 | - $checkarrivee |
|
| 2329 | - and is_string($checkarrivee) |
|
| 2330 | - and $a = table_objet($checkarrivee) |
|
| 2331 | - and in_array($a . '_liens', $joints) |
|
| 2332 | - ) { |
|
| 2333 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2334 | - return $res; |
|
| 2335 | - } |
|
| 2336 | - } |
|
| 2337 | - foreach ($joints as $joint) { |
|
| 2338 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2339 | - // alias de table dans le from |
|
| 2340 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2341 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2342 | - $cols = $arrivee[2]; |
|
| 2343 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2344 | - if (count($cols) > 2) { |
|
| 2345 | - array_pop($cols); |
|
| 2346 | - } |
|
| 2347 | - if ($t) { |
|
| 2348 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2349 | - $joindre = false; |
|
| 2350 | - foreach ($cols as $col) { |
|
| 2351 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2352 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2353 | - $joindre = true; |
|
| 2354 | - } else { |
|
| 2355 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2356 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2357 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2358 | - $joindre = true; |
|
| 2359 | - } |
|
| 2360 | - } |
|
| 2361 | - } |
|
| 2362 | - if (!$joindre) { |
|
| 2363 | - return $t; |
|
| 2364 | - } |
|
| 2365 | - } |
|
| 2366 | - array_pop($arrivee); |
|
| 2367 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2368 | - return $res; |
|
| 2369 | - } |
|
| 2370 | - } |
|
| 2371 | - } |
|
| 2372 | - |
|
| 2373 | - return ''; |
|
| 2323 | + // si on demande un truc du genre spip_mots |
|
| 2324 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2325 | + // et qu'on est la |
|
| 2326 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2327 | + if ( |
|
| 2328 | + $checkarrivee |
|
| 2329 | + and is_string($checkarrivee) |
|
| 2330 | + and $a = table_objet($checkarrivee) |
|
| 2331 | + and in_array($a . '_liens', $joints) |
|
| 2332 | + ) { |
|
| 2333 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2334 | + return $res; |
|
| 2335 | + } |
|
| 2336 | + } |
|
| 2337 | + foreach ($joints as $joint) { |
|
| 2338 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2339 | + // alias de table dans le from |
|
| 2340 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2341 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2342 | + $cols = $arrivee[2]; |
|
| 2343 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2344 | + if (count($cols) > 2) { |
|
| 2345 | + array_pop($cols); |
|
| 2346 | + } |
|
| 2347 | + if ($t) { |
|
| 2348 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2349 | + $joindre = false; |
|
| 2350 | + foreach ($cols as $col) { |
|
| 2351 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2352 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2353 | + $joindre = true; |
|
| 2354 | + } else { |
|
| 2355 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2356 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2357 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2358 | + $joindre = true; |
|
| 2359 | + } |
|
| 2360 | + } |
|
| 2361 | + } |
|
| 2362 | + if (!$joindre) { |
|
| 2363 | + return $t; |
|
| 2364 | + } |
|
| 2365 | + } |
|
| 2366 | + array_pop($arrivee); |
|
| 2367 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2368 | + return $res; |
|
| 2369 | + } |
|
| 2370 | + } |
|
| 2371 | + } |
|
| 2372 | + |
|
| 2373 | + return ''; |
|
| 2374 | 2374 | } |
| 2375 | 2375 | |
| 2376 | 2376 | /** |
@@ -2396,35 +2396,35 @@ discard block |
||
| 2396 | 2396 | * Alias de la table de jointure (Lx) |
| 2397 | 2397 | */ |
| 2398 | 2398 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2399 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2400 | - |
|
| 2401 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2402 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2403 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2404 | - |
|
| 2405 | - if (!$intermediaire or !$arrivee) { |
|
| 2406 | - return ''; |
|
| 2407 | - } |
|
| 2408 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2409 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2410 | - |
|
| 2411 | - $res = fabrique_jointures( |
|
| 2412 | - $boucle, |
|
| 2413 | - [ |
|
| 2414 | - [ |
|
| 2415 | - $boucle->id_table, |
|
| 2416 | - $intermediaire, |
|
| 2417 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2418 | - ], |
|
| 2419 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2420 | - ], |
|
| 2421 | - $cond, |
|
| 2422 | - $desc, |
|
| 2423 | - $boucle->id_table, |
|
| 2424 | - [$col] |
|
| 2425 | - ); |
|
| 2426 | - |
|
| 2427 | - return $res; |
|
| 2399 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2400 | + |
|
| 2401 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2402 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2403 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2404 | + |
|
| 2405 | + if (!$intermediaire or !$arrivee) { |
|
| 2406 | + return ''; |
|
| 2407 | + } |
|
| 2408 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2409 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2410 | + |
|
| 2411 | + $res = fabrique_jointures( |
|
| 2412 | + $boucle, |
|
| 2413 | + [ |
|
| 2414 | + [ |
|
| 2415 | + $boucle->id_table, |
|
| 2416 | + $intermediaire, |
|
| 2417 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2418 | + ], |
|
| 2419 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2420 | + ], |
|
| 2421 | + $cond, |
|
| 2422 | + $desc, |
|
| 2423 | + $boucle->id_table, |
|
| 2424 | + [$col] |
|
| 2425 | + ); |
|
| 2426 | + |
|
| 2427 | + return $res; |
|
| 2428 | 2428 | } |
| 2429 | 2429 | |
| 2430 | 2430 | |
@@ -2441,17 +2441,17 @@ discard block |
||
| 2441 | 2441 | * false sinon. |
| 2442 | 2442 | **/ |
| 2443 | 2443 | function trouver_champ($champ, $where) { |
| 2444 | - if (!is_array($where)) { |
|
| 2445 | - return preg_match($champ, $where); |
|
| 2446 | - } else { |
|
| 2447 | - foreach ($where as $clause) { |
|
| 2448 | - if (trouver_champ($champ, $clause)) { |
|
| 2449 | - return true; |
|
| 2450 | - } |
|
| 2451 | - } |
|
| 2452 | - |
|
| 2453 | - return false; |
|
| 2454 | - } |
|
| 2444 | + if (!is_array($where)) { |
|
| 2445 | + return preg_match($champ, $where); |
|
| 2446 | + } else { |
|
| 2447 | + foreach ($where as $clause) { |
|
| 2448 | + if (trouver_champ($champ, $clause)) { |
|
| 2449 | + return true; |
|
| 2450 | + } |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + return false; |
|
| 2454 | + } |
|
| 2455 | 2455 | } |
| 2456 | 2456 | |
| 2457 | 2457 | |
@@ -2477,130 +2477,130 @@ discard block |
||
| 2477 | 2477 | * - string $args_sql Suite des arguments du critère. ? |
| 2478 | 2478 | **/ |
| 2479 | 2479 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2480 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2481 | - if (count($crit->param) == 0) { |
|
| 2482 | - $op = '='; |
|
| 2483 | - $col = $val = $crit->op; |
|
| 2484 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2485 | - $val = $r[2]; |
|
| 2486 | - } |
|
| 2487 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2488 | - if ($val == 'lang') { |
|
| 2489 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2490 | - } else { |
|
| 2491 | - $defaut = null; |
|
| 2492 | - if ($val == 'id_parent') { |
|
| 2493 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2494 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2495 | - // pour eviter l'erreur SQL |
|
| 2496 | - $val = $boucles[$idb]->primary; |
|
| 2497 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2498 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2499 | - } elseif ($val == 'id_enfant') { |
|
| 2500 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2501 | - // de la boucle superieure |
|
| 2502 | - $val = 'id_parent'; |
|
| 2503 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2504 | - // un critere conditionnel sur date est traite a part |
|
| 2505 | - // car la date est mise d'office par SPIP, |
|
| 2506 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2507 | - } |
|
| 2508 | - |
|
| 2509 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2510 | - $val = [kwote($val)]; |
|
| 2511 | - } |
|
| 2512 | - } else { |
|
| 2513 | - // comparaison explicite |
|
| 2514 | - // le phraseur impose que le premier param soit du texte |
|
| 2515 | - $params = $crit->param; |
|
| 2516 | - $op = $crit->op; |
|
| 2517 | - if ($op == '==') { |
|
| 2518 | - $op = 'REGEXP'; |
|
| 2519 | - } |
|
| 2520 | - $col = array_shift($params); |
|
| 2521 | - $col = $col[0]->texte; |
|
| 2522 | - |
|
| 2523 | - $val = []; |
|
| 2524 | - $parent = $boucles[$idb]->id_parent; |
|
| 2525 | - |
|
| 2526 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2527 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2528 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2529 | - if ( |
|
| 2530 | - count($params) == 1 |
|
| 2531 | - and count($params[0]) == 3 |
|
| 2532 | - and $params[0][0]->type == 'texte' |
|
| 2533 | - and $params[0][2]->type == 'texte' |
|
| 2534 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2535 | - and (($p == "'") or ($p == '"')) |
|
| 2536 | - and $params[0][1]->type == 'champ' |
|
| 2537 | - ) { |
|
| 2538 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2539 | - } else { |
|
| 2540 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2541 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2542 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2543 | - $val[] = $a; |
|
| 2544 | - } else { |
|
| 2545 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2546 | - } // toujours quoter en char ici |
|
| 2547 | - } |
|
| 2548 | - } |
|
| 2549 | - } |
|
| 2550 | - |
|
| 2551 | - $fct = $args_sql = ''; |
|
| 2552 | - // fonction SQL ? |
|
| 2553 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2554 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2555 | - $fct = $m[1]; |
|
| 2556 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2557 | - $col = $a[1]; |
|
| 2558 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2559 | - $col = $m[1]; |
|
| 2560 | - $args_sql = $m[2]; |
|
| 2561 | - } |
|
| 2562 | - $args_sql .= $a[2]; |
|
| 2563 | - } |
|
| 2564 | - |
|
| 2565 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2480 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2481 | + if (count($crit->param) == 0) { |
|
| 2482 | + $op = '='; |
|
| 2483 | + $col = $val = $crit->op; |
|
| 2484 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2485 | + $val = $r[2]; |
|
| 2486 | + } |
|
| 2487 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2488 | + if ($val == 'lang') { |
|
| 2489 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2490 | + } else { |
|
| 2491 | + $defaut = null; |
|
| 2492 | + if ($val == 'id_parent') { |
|
| 2493 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2494 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2495 | + // pour eviter l'erreur SQL |
|
| 2496 | + $val = $boucles[$idb]->primary; |
|
| 2497 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2498 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2499 | + } elseif ($val == 'id_enfant') { |
|
| 2500 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2501 | + // de la boucle superieure |
|
| 2502 | + $val = 'id_parent'; |
|
| 2503 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2504 | + // un critere conditionnel sur date est traite a part |
|
| 2505 | + // car la date est mise d'office par SPIP, |
|
| 2506 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2507 | + } |
|
| 2508 | + |
|
| 2509 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2510 | + $val = [kwote($val)]; |
|
| 2511 | + } |
|
| 2512 | + } else { |
|
| 2513 | + // comparaison explicite |
|
| 2514 | + // le phraseur impose que le premier param soit du texte |
|
| 2515 | + $params = $crit->param; |
|
| 2516 | + $op = $crit->op; |
|
| 2517 | + if ($op == '==') { |
|
| 2518 | + $op = 'REGEXP'; |
|
| 2519 | + } |
|
| 2520 | + $col = array_shift($params); |
|
| 2521 | + $col = $col[0]->texte; |
|
| 2522 | + |
|
| 2523 | + $val = []; |
|
| 2524 | + $parent = $boucles[$idb]->id_parent; |
|
| 2525 | + |
|
| 2526 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2527 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2528 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2529 | + if ( |
|
| 2530 | + count($params) == 1 |
|
| 2531 | + and count($params[0]) == 3 |
|
| 2532 | + and $params[0][0]->type == 'texte' |
|
| 2533 | + and $params[0][2]->type == 'texte' |
|
| 2534 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2535 | + and (($p == "'") or ($p == '"')) |
|
| 2536 | + and $params[0][1]->type == 'champ' |
|
| 2537 | + ) { |
|
| 2538 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2539 | + } else { |
|
| 2540 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2541 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2542 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2543 | + $val[] = $a; |
|
| 2544 | + } else { |
|
| 2545 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2546 | + } // toujours quoter en char ici |
|
| 2547 | + } |
|
| 2548 | + } |
|
| 2549 | + } |
|
| 2550 | + |
|
| 2551 | + $fct = $args_sql = ''; |
|
| 2552 | + // fonction SQL ? |
|
| 2553 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2554 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2555 | + $fct = $m[1]; |
|
| 2556 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2557 | + $col = $a[1]; |
|
| 2558 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2559 | + $col = $m[1]; |
|
| 2560 | + $args_sql = $m[2]; |
|
| 2561 | + } |
|
| 2562 | + $args_sql .= $a[2]; |
|
| 2563 | + } |
|
| 2564 | + |
|
| 2565 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2566 | 2566 | } |
| 2567 | 2567 | |
| 2568 | 2568 | // compatibilite ancienne version |
| 2569 | 2569 | |
| 2570 | 2570 | // https://code.spip.net/@calculer_vieux_in |
| 2571 | 2571 | function calculer_vieux_in($params) { |
| 2572 | - $deb = $params[0][0]; |
|
| 2573 | - $k = count($params) - 1; |
|
| 2574 | - $last = $params[$k]; |
|
| 2575 | - $j = count($last) - 1; |
|
| 2576 | - $last = $last[$j]; |
|
| 2577 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2578 | - |
|
| 2579 | - if ( |
|
| 2580 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2581 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2582 | - ) { |
|
| 2583 | - return $params; |
|
| 2584 | - } |
|
| 2585 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2586 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2587 | - $last = $params[$k][$j]; |
|
| 2588 | - $n = strlen($last->texte); |
|
| 2589 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2590 | - $newp = []; |
|
| 2591 | - foreach ($params as $v) { |
|
| 2592 | - if ($v[0]->type != 'texte') { |
|
| 2593 | - $newp[] = $v; |
|
| 2594 | - } else { |
|
| 2595 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2596 | - $t = new Texte(); |
|
| 2597 | - $t->texte = $x; |
|
| 2598 | - $newp[] = [$t]; |
|
| 2599 | - } |
|
| 2600 | - } |
|
| 2601 | - } |
|
| 2602 | - |
|
| 2603 | - return $newp; |
|
| 2572 | + $deb = $params[0][0]; |
|
| 2573 | + $k = count($params) - 1; |
|
| 2574 | + $last = $params[$k]; |
|
| 2575 | + $j = count($last) - 1; |
|
| 2576 | + $last = $last[$j]; |
|
| 2577 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2578 | + |
|
| 2579 | + if ( |
|
| 2580 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2581 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2582 | + ) { |
|
| 2583 | + return $params; |
|
| 2584 | + } |
|
| 2585 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2586 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2587 | + $last = $params[$k][$j]; |
|
| 2588 | + $n = strlen($last->texte); |
|
| 2589 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2590 | + $newp = []; |
|
| 2591 | + foreach ($params as $v) { |
|
| 2592 | + if ($v[0]->type != 'texte') { |
|
| 2593 | + $newp[] = $v; |
|
| 2594 | + } else { |
|
| 2595 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2596 | + $t = new Texte(); |
|
| 2597 | + $t->texte = $x; |
|
| 2598 | + $newp[] = [$t]; |
|
| 2599 | + } |
|
| 2600 | + } |
|
| 2601 | + } |
|
| 2602 | + |
|
| 2603 | + return $newp; |
|
| 2604 | 2604 | } |
| 2605 | 2605 | |
| 2606 | 2606 | /** |
@@ -2619,89 +2619,89 @@ discard block |
||
| 2619 | 2619 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2620 | 2620 | **/ |
| 2621 | 2621 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2622 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2623 | - return ''; |
|
| 2624 | - } |
|
| 2625 | - |
|
| 2626 | - $boucle = $boucles[$idb]; |
|
| 2627 | - $table = $boucle->show; |
|
| 2628 | - |
|
| 2629 | - // si c'est une colonne de la table, ne rien faire |
|
| 2630 | - if (isset($table['field'][$col])) { |
|
| 2631 | - return ''; |
|
| 2632 | - } |
|
| 2633 | - |
|
| 2634 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2635 | - return ''; |
|
| 2636 | - } |
|
| 2637 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2638 | - |
|
| 2639 | - $col = $regs[1]; |
|
| 2640 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2641 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2642 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2643 | - |
|
| 2644 | - if (isset($table['field']["date$suite"])) { |
|
| 2645 | - $date_orig = 'date' . $suite; |
|
| 2646 | - } else { |
|
| 2647 | - $date_orig = substr($suite, 1); |
|
| 2648 | - } |
|
| 2649 | - $pred = $date_orig; |
|
| 2650 | - } else { |
|
| 2651 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2652 | - $pred = 'date'; |
|
| 2653 | - } |
|
| 2654 | - } |
|
| 2655 | - |
|
| 2656 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2657 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2658 | - ") . '\""; |
|
| 2659 | - |
|
| 2660 | - $col_vraie = $date_orig; |
|
| 2661 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2662 | - |
|
| 2663 | - switch ($col) { |
|
| 2664 | - case 'date': |
|
| 2665 | - $col = $date_orig; |
|
| 2666 | - break; |
|
| 2667 | - case 'jour': |
|
| 2668 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2669 | - break; |
|
| 2670 | - case 'mois': |
|
| 2671 | - $col = "MONTH($date_orig)"; |
|
| 2672 | - break; |
|
| 2673 | - case 'annee': |
|
| 2674 | - $col = "YEAR($date_orig)"; |
|
| 2675 | - break; |
|
| 2676 | - case 'heure': |
|
| 2677 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2678 | - break; |
|
| 2679 | - case 'age': |
|
| 2680 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2681 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | - break; |
|
| 2683 | - case 'age_relatif': |
|
| 2684 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | - break; |
|
| 2687 | - case 'jour_relatif': |
|
| 2688 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2689 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2690 | - break; |
|
| 2691 | - case 'mois_relatif': |
|
| 2692 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2693 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2694 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | - break; |
|
| 2697 | - case 'annee_relatif': |
|
| 2698 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2699 | - $date_orig . ')'; |
|
| 2700 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2701 | - break; |
|
| 2702 | - } |
|
| 2703 | - |
|
| 2704 | - return [$col, $col_vraie]; |
|
| 2622 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2623 | + return ''; |
|
| 2624 | + } |
|
| 2625 | + |
|
| 2626 | + $boucle = $boucles[$idb]; |
|
| 2627 | + $table = $boucle->show; |
|
| 2628 | + |
|
| 2629 | + // si c'est une colonne de la table, ne rien faire |
|
| 2630 | + if (isset($table['field'][$col])) { |
|
| 2631 | + return ''; |
|
| 2632 | + } |
|
| 2633 | + |
|
| 2634 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2635 | + return ''; |
|
| 2636 | + } |
|
| 2637 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2638 | + |
|
| 2639 | + $col = $regs[1]; |
|
| 2640 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2641 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2642 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2643 | + |
|
| 2644 | + if (isset($table['field']["date$suite"])) { |
|
| 2645 | + $date_orig = 'date' . $suite; |
|
| 2646 | + } else { |
|
| 2647 | + $date_orig = substr($suite, 1); |
|
| 2648 | + } |
|
| 2649 | + $pred = $date_orig; |
|
| 2650 | + } else { |
|
| 2651 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2652 | + $pred = 'date'; |
|
| 2653 | + } |
|
| 2654 | + } |
|
| 2655 | + |
|
| 2656 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2657 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2658 | + ") . '\""; |
|
| 2659 | + |
|
| 2660 | + $col_vraie = $date_orig; |
|
| 2661 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2662 | + |
|
| 2663 | + switch ($col) { |
|
| 2664 | + case 'date': |
|
| 2665 | + $col = $date_orig; |
|
| 2666 | + break; |
|
| 2667 | + case 'jour': |
|
| 2668 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2669 | + break; |
|
| 2670 | + case 'mois': |
|
| 2671 | + $col = "MONTH($date_orig)"; |
|
| 2672 | + break; |
|
| 2673 | + case 'annee': |
|
| 2674 | + $col = "YEAR($date_orig)"; |
|
| 2675 | + break; |
|
| 2676 | + case 'heure': |
|
| 2677 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2678 | + break; |
|
| 2679 | + case 'age': |
|
| 2680 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2681 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + break; |
|
| 2683 | + case 'age_relatif': |
|
| 2684 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2685 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | + break; |
|
| 2687 | + case 'jour_relatif': |
|
| 2688 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2689 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2690 | + break; |
|
| 2691 | + case 'mois_relatif': |
|
| 2692 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2693 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2694 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2695 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | + break; |
|
| 2697 | + case 'annee_relatif': |
|
| 2698 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2699 | + $date_orig . ')'; |
|
| 2700 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2701 | + break; |
|
| 2702 | + } |
|
| 2703 | + |
|
| 2704 | + return [$col, $col_vraie]; |
|
| 2705 | 2705 | } |
| 2706 | 2706 | |
| 2707 | 2707 | /** |
@@ -2720,16 +2720,16 @@ discard block |
||
| 2720 | 2720 | * de colonne SQL et une date. |
| 2721 | 2721 | **/ |
| 2722 | 2722 | function calculer_param_date($date_compare, $date_orig) { |
| 2723 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2724 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2725 | - $date_compare = '\'$x\''; |
|
| 2726 | - } else { |
|
| 2727 | - $init = $date_compare; |
|
| 2728 | - } |
|
| 2729 | - |
|
| 2730 | - return |
|
| 2731 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2732 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2723 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2724 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2725 | + $date_compare = '\'$x\''; |
|
| 2726 | + } else { |
|
| 2727 | + $init = $date_compare; |
|
| 2728 | + } |
|
| 2729 | + |
|
| 2730 | + return |
|
| 2731 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2732 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2733 | 2733 | } |
| 2734 | 2734 | |
| 2735 | 2735 | /** |
@@ -2747,20 +2747,20 @@ discard block |
||
| 2747 | 2747 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2748 | 2748 | */ |
| 2749 | 2749 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2750 | - $boucle = &$boucles[$idb]; |
|
| 2751 | - |
|
| 2752 | - $args = []; |
|
| 2753 | - foreach ($crit->param as &$param) { |
|
| 2754 | - array_push( |
|
| 2755 | - $args, |
|
| 2756 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2757 | - ); |
|
| 2758 | - } |
|
| 2750 | + $boucle = &$boucles[$idb]; |
|
| 2759 | 2751 | |
| 2760 | - $boucle->hash .= ' |
|
| 2752 | + $args = []; |
|
| 2753 | + foreach ($crit->param as &$param) { |
|
| 2754 | + array_push( |
|
| 2755 | + $args, |
|
| 2756 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2757 | + ); |
|
| 2758 | + } |
|
| 2759 | + |
|
| 2760 | + $boucle->hash .= ' |
|
| 2761 | 2761 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2762 | 2762 | |
| 2763 | - $boucle->hash .= ' |
|
| 2763 | + $boucle->hash .= ' |
|
| 2764 | 2764 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2765 | 2765 | } |
| 2766 | 2766 | |
@@ -2778,8 +2778,8 @@ discard block |
||
| 2778 | 2778 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2779 | 2779 | */ |
| 2780 | 2780 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2781 | - $boucle = &$boucles[$idb]; |
|
| 2782 | - $boucle->hash .= ' |
|
| 2781 | + $boucle = &$boucles[$idb]; |
|
| 2782 | + $boucle->hash .= ' |
|
| 2783 | 2783 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2784 | 2784 | } |
| 2785 | 2785 | |
@@ -2795,12 +2795,12 @@ discard block |
||
| 2795 | 2795 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2796 | 2796 | */ |
| 2797 | 2797 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2798 | - $boucle = &$boucles[$idb]; |
|
| 2799 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2800 | - foreach ($crit->param as $param) { |
|
| 2801 | - $boucle->hash .= ' |
|
| 2798 | + $boucle = &$boucles[$idb]; |
|
| 2799 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2800 | + foreach ($crit->param as $param) { |
|
| 2801 | + $boucle->hash .= ' |
|
| 2802 | 2802 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2803 | - } |
|
| 2803 | + } |
|
| 2804 | 2804 | } |
| 2805 | 2805 | |
| 2806 | 2806 | /** |
@@ -2817,16 +2817,16 @@ discard block |
||
| 2817 | 2817 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2818 | 2818 | */ |
| 2819 | 2819 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2820 | - $boucle = &$boucles[$idb]; |
|
| 2821 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2822 | - foreach ($crit->param as $param) { |
|
| 2823 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2824 | - $param, |
|
| 2825 | - $idb, |
|
| 2826 | - $boucles, |
|
| 2827 | - $boucles[$idb]->id_parent |
|
| 2828 | - ) . ";\n"; |
|
| 2829 | - } |
|
| 2820 | + $boucle = &$boucles[$idb]; |
|
| 2821 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2822 | + foreach ($crit->param as $param) { |
|
| 2823 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2824 | + $param, |
|
| 2825 | + $idb, |
|
| 2826 | + $boucles, |
|
| 2827 | + $boucles[$idb]->id_parent |
|
| 2828 | + ) . ";\n"; |
|
| 2829 | + } |
|
| 2830 | 2830 | } |
| 2831 | 2831 | |
| 2832 | 2832 | /** |
@@ -2851,16 +2851,16 @@ discard block |
||
| 2851 | 2851 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2852 | 2852 | */ |
| 2853 | 2853 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2854 | - $boucle = &$boucles[$idb]; |
|
| 2855 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2856 | - foreach ($crit->param as $param) { |
|
| 2857 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2858 | - $param, |
|
| 2859 | - $idb, |
|
| 2860 | - $boucles, |
|
| 2861 | - $boucles[$idb]->id_parent |
|
| 2862 | - ) . ";\n"; |
|
| 2863 | - } |
|
| 2854 | + $boucle = &$boucles[$idb]; |
|
| 2855 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2856 | + foreach ($crit->param as $param) { |
|
| 2857 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2858 | + $param, |
|
| 2859 | + $idb, |
|
| 2860 | + $boucles, |
|
| 2861 | + $boucles[$idb]->id_parent |
|
| 2862 | + ) . ";\n"; |
|
| 2863 | + } |
|
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | 2866 | /** |
@@ -2875,11 +2875,11 @@ discard block |
||
| 2875 | 2875 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2876 | 2876 | */ |
| 2877 | 2877 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2878 | - $boucle = &$boucles[$idb]; |
|
| 2879 | - foreach ($crit->param as $param) { |
|
| 2880 | - $boucle->hash .= ' |
|
| 2878 | + $boucle = &$boucles[$idb]; |
|
| 2879 | + foreach ($crit->param as $param) { |
|
| 2880 | + $boucle->hash .= ' |
|
| 2881 | 2881 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2882 | - } |
|
| 2882 | + } |
|
| 2883 | 2883 | } |
| 2884 | 2884 | |
| 2885 | 2885 | |
@@ -2911,20 +2911,20 @@ discard block |
||
| 2911 | 2911 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2912 | 2912 | */ |
| 2913 | 2913 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2914 | - $boucle = &$boucles[$idb]; |
|
| 2915 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2916 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2917 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2918 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2919 | - if ($crit->param) { |
|
| 2920 | - foreach ($crit->param as $param) { |
|
| 2921 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2922 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2923 | - } |
|
| 2924 | - // interdire {si 0} aussi ! |
|
| 2925 | - } else { |
|
| 2926 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2927 | - } |
|
| 2914 | + $boucle = &$boucles[$idb]; |
|
| 2915 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2916 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2917 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2918 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2919 | + if ($crit->param) { |
|
| 2920 | + foreach ($crit->param as $param) { |
|
| 2921 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2922 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2923 | + } |
|
| 2924 | + // interdire {si 0} aussi ! |
|
| 2925 | + } else { |
|
| 2926 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2927 | + } |
|
| 2928 | 2928 | } |
| 2929 | 2929 | |
| 2930 | 2930 | /** |
@@ -2941,8 +2941,8 @@ discard block |
||
| 2941 | 2941 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2942 | 2942 | */ |
| 2943 | 2943 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2944 | - $boucle = &$boucles[$idb]; |
|
| 2945 | - $boucle->hash .= ' |
|
| 2944 | + $boucle = &$boucles[$idb]; |
|
| 2945 | + $boucle->hash .= ' |
|
| 2946 | 2946 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2947 | 2947 | $command[\'sourcemode\'] = \'table\';'; |
| 2948 | 2948 | } |
@@ -2963,29 +2963,29 @@ discard block |
||
| 2963 | 2963 | */ |
| 2964 | 2964 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2965 | 2965 | |
| 2966 | - $not = $crit->not; |
|
| 2967 | - $boucle = &$boucles[$idb]; |
|
| 2968 | - $primary = $boucle->primary; |
|
| 2966 | + $not = $crit->not; |
|
| 2967 | + $boucle = &$boucles[$idb]; |
|
| 2968 | + $primary = $boucle->primary; |
|
| 2969 | 2969 | |
| 2970 | - if (!$primary or strpos($primary, ',')) { |
|
| 2971 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2970 | + if (!$primary or strpos($primary, ',')) { |
|
| 2971 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2972 | 2972 | |
| 2973 | - return; |
|
| 2974 | - } |
|
| 2975 | - $table = $boucle->type_requete; |
|
| 2976 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2973 | + return; |
|
| 2974 | + } |
|
| 2975 | + $table = $boucle->type_requete; |
|
| 2976 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2977 | 2977 | |
| 2978 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2979 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2980 | - 'id_parent'; |
|
| 2978 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2979 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2980 | + 'id_parent'; |
|
| 2981 | 2981 | |
| 2982 | - $in = 'IN'; |
|
| 2983 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2984 | - if ($not) { |
|
| 2985 | - $where = ["'NOT'", $where]; |
|
| 2986 | - } |
|
| 2982 | + $in = 'IN'; |
|
| 2983 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2984 | + if ($not) { |
|
| 2985 | + $where = ["'NOT'", $where]; |
|
| 2986 | + } |
|
| 2987 | 2987 | |
| 2988 | - $boucle->where[] = $where; |
|
| 2988 | + $boucle->where[] = $where; |
|
| 2989 | 2989 | } |
| 2990 | 2990 | |
| 2991 | 2991 | /** |
@@ -3001,8 +3001,8 @@ discard block |
||
| 3001 | 3001 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 3002 | 3002 | */ |
| 3003 | 3003 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3004 | - $not = $crit->not; |
|
| 3005 | - $crit->not = $not ? false : true; |
|
| 3006 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3007 | - $crit->not = $not; |
|
| 3004 | + $not = $crit->not; |
|
| 3005 | + $crit->not = $not ? false : true; |
|
| 3006 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3007 | + $crit->not = $not; |
|
| 3008 | 3008 | } |
@@ -46,10 +46,9 @@ discard block |
||
| 46 | 46 | $not = $crit->not; |
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 48 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 51 | 50 | |
| 52 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $c = ["'='", "'$boucle->id_table."."$id_parent'", 0]; |
|
| 53 | 52 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
| 54 | 53 | } |
| 55 | 54 | |
@@ -72,10 +71,10 @@ discard block |
||
| 72 | 71 | $id = $boucle->primary; |
| 73 | 72 | |
| 74 | 73 | if ($not or !$id) { |
| 75 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 74 | + return (['zbug_critere_inconnu', ['critere' => $not.$crit->op]]); |
|
| 76 | 75 | } |
| 77 | 76 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 78 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | + $boucle->where[] = ["'!='", "'$boucle->id_table."."$id'", $arg]; |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | |
@@ -106,12 +105,12 @@ discard block |
||
| 106 | 105 | $not = ($crit->not ? '' : 'NOT'); |
| 107 | 106 | |
| 108 | 107 | // le doublon s'applique sur un type de boucle (article) |
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + $nom = "'".$boucle->type_requete."'"; |
|
| 110 | 109 | |
| 111 | 110 | // compléter le nom avec un nom précisé {doublons nom} |
| 112 | 111 | // on obtient $nom = "'article' . 'nom'" |
| 113 | 112 | if (isset($crit->param[0])) { |
| 114 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + $nom .= '.'.calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | // $doublons et son index, ici $nom |
| 124 | 123 | |
| 125 | 124 | // debut du code "sql_in('articles.id_article', " |
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 127 | 126 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 128 | 127 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons.'[]= ')); |
|
| 130 | 129 | |
| 131 | 130 | // le debut complet du code des doublons |
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + $debut_doub = $debut_in.$debut_doub; |
|
| 133 | 132 | |
| 134 | 133 | // nom du doublon "('article' . 'nom')]" |
| 135 | 134 | $fin_doub = "($nom)]"; |
@@ -139,22 +138,22 @@ discard block |
||
| 139 | 138 | foreach ($boucle->where as $k => $w) { |
| 140 | 139 | if (strpos($w[0], $debut_doub) === 0) { |
| 141 | 140 | // fusionner le sql_in (du where) |
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 143 | 142 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 144 | 143 | $x = strpos($boucle->hash, $init_comment); |
| 145 | 144 | $len = strlen($init_comment); |
| 146 | 145 | $boucle->hash = |
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 148 | 147 | |
| 149 | 148 | return; |
| 150 | 149 | } |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | 152 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 154 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + $boucle->where[] = [$debut_doub.$fin_doub.", '".$not."')"]; |
|
| 155 | 154 | |
| 156 | 155 | // déclarer le doublon s'il n'existe pas encore |
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + $boucle->hash .= $init_comment.$init_code; |
|
| 158 | 157 | |
| 159 | 158 | |
| 160 | 159 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -216,7 +215,7 @@ discard block |
||
| 216 | 215 | $deux = $deux[0]->texte; |
| 217 | 216 | if ($deux) { |
| 218 | 217 | $boucles[$idb]->limit = |
| 219 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | + 'intval($Pile[0]["debut'.$un.'"]) . ",'.$deux.'"'; |
|
| 220 | 219 | } else { |
| 221 | 220 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
| 222 | 221 | } |
@@ -278,26 +277,26 @@ discard block |
||
| 278 | 277 | $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
| 279 | 278 | } |
| 280 | 279 | |
| 281 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 282 | 281 | $boucle->modificateur['debut_nom'] = $type; |
| 283 | 282 | $partie = |
| 284 | 283 | // tester si le numero de page demande est de la forme '@yyy' |
| 285 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 286 | 285 | . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
| 287 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 288 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 286 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 287 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 289 | 288 | . "\t}\n" |
| 290 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 291 | 290 | |
| 292 | 291 | $boucle->hash .= ' |
| 293 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 292 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 294 | 293 | |
| 295 | 294 | $boucle->total_parties = $pas; |
| 296 | 295 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 297 | 296 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 298 | 297 | // sauf si pas de primaire, ou si primaire composee |
| 299 | 298 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 300 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 301 | 300 | if ( |
| 302 | 301 | $boucle->primary |
| 303 | 302 | and !preg_match('/[,\s]/', $boucle->primary) |
@@ -344,24 +343,24 @@ discard block |
||
| 344 | 343 | $boucle->hash .= ' |
| 345 | 344 | // RECHERCHE' |
| 346 | 345 | . ($crit->cond ? ' |
| 347 | - if (!strlen(' . $quoi . ')){ |
|
| 346 | + if (!strlen(' . $quoi.')){ |
|
| 348 | 347 | list($rech_select, $rech_where) = array("0 as points",""); |
| 349 | - } else' : '') . ' |
|
| 348 | + } else' : '').' |
|
| 350 | 349 | { |
| 351 | 350 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 352 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 351 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 353 | 352 | } |
| 354 | 353 | '; |
| 355 | 354 | |
| 356 | 355 | |
| 357 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 358 | 357 | if (!in_array($t, $boucles[$idb]->select)) { |
| 359 | 358 | $boucle->select[] = $t; |
| 360 | 359 | } # pour postgres, neuneu ici |
| 361 | 360 | // jointure uniquement sur le serveur principal |
| 362 | 361 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 363 | 362 | if (!$boucle->sql_serveur) { |
| 364 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | + $boucle->join['resultats'] = ["'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"]; |
|
| 365 | 364 | $boucle->from['resultats'] = 'spip_resultats'; |
| 366 | 365 | } |
| 367 | 366 | $boucle->select[] = '$rech_select'; |
@@ -428,7 +427,7 @@ discard block |
||
| 428 | 427 | $c = |
| 429 | 428 | [ |
| 430 | 429 | "'OR'", |
| 431 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | + ["'='", "'$table."."id_trad'", "'$table.$prim'"], |
|
| 432 | 431 | ["'='", "'$table.id_trad'", "'0'"] |
| 433 | 432 | ]; |
| 434 | 433 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
@@ -451,15 +450,14 @@ discard block |
||
| 451 | 450 | $boucle = &$boucles[$idb]; |
| 452 | 451 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 453 | 452 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 454 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 455 | - 'id_parent'; |
|
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 454 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 457 | 455 | |
| 458 | 456 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 459 | 457 | $boucle->where[] = ["'='", "'$mparent'", $arg]; |
| 460 | 458 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 461 | 459 | else { |
| 462 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 460 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.$boucle->type_requete]]); |
|
| 463 | 461 | } |
| 464 | 462 | } |
| 465 | 463 | |
@@ -512,16 +510,15 @@ discard block |
||
| 512 | 510 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 513 | 511 | $decompose = decompose_champ_id_objet($champ); |
| 514 | 512 | $champ = array_shift($decompose); |
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 513 | + $boucle->where[] = ["'='", _q($cle.'.'.reset($decompose)), '"'.sql_quote(end($decompose)).'"']; |
|
| 516 | 514 | } |
| 517 | 515 | } else { |
| 518 | 516 | $cle = $boucle->id_table; |
| 519 | 517 | } |
| 520 | 518 | |
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 524 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 519 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 520 | + . ($not ? ", 'NOT'" : '').')'; |
|
| 521 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 525 | 522 | } |
| 526 | 523 | |
| 527 | 524 | /** |
@@ -541,9 +538,9 @@ discard block |
||
| 541 | 538 | $not = ($crit->not ? 'NOT' : ''); |
| 542 | 539 | $serveur = $boucle->sql_serveur; |
| 543 | 540 | |
| 544 | - $c = "sql_in('" . |
|
| 545 | - $boucle->id_table . '.' . $boucle->primary |
|
| 546 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 541 | + $c = "sql_in('". |
|
| 542 | + $boucle->id_table.'.'.$boucle->primary |
|
| 543 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 547 | 544 | |
| 548 | 545 | $boucle->where[] = $c; |
| 549 | 546 | } |
@@ -575,7 +572,7 @@ discard block |
||
| 575 | 572 | $t = table_objet_sql($r[1]); |
| 576 | 573 | $t = array_search($t, $boucles[$idb]->from); |
| 577 | 574 | if ($t) { |
| 578 | - $t .= '.' . $r[2]; |
|
| 575 | + $t .= '.'.$r[2]; |
|
| 579 | 576 | } |
| 580 | 577 | } |
| 581 | 578 | } else { |
@@ -590,7 +587,7 @@ discard block |
||
| 590 | 587 | $boucles[$idb]->select[] = $t; |
| 591 | 588 | } |
| 592 | 589 | } else { |
| 593 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 590 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]); |
|
| 594 | 591 | } |
| 595 | 592 | } |
| 596 | 593 | |
@@ -660,26 +657,26 @@ discard block |
||
| 660 | 657 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 661 | 658 | or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 662 | 659 | ) { |
| 663 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 664 | 661 | } else { |
| 665 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | + $boucle->order[$n - 1] .= ' . '.$boucle->modificateur['collate']; |
|
| 666 | 663 | } |
| 667 | 664 | } |
| 668 | 665 | } else { |
| 669 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . count($boucles[$idb]->order)]]); |
|
| 666 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.count($boucles[$idb]->order)]]); |
|
| 670 | 667 | } |
| 671 | 668 | } |
| 672 | 669 | |
| 673 | 670 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 674 | 671 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 675 | 672 | $boucle = $boucles[$idb]; |
| 676 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 677 | - $var = '$champs_' . $idb; |
|
| 673 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 674 | + $var = '$champs_'.$idb; |
|
| 678 | 675 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 679 | 676 | if (!$desc) { |
| 680 | 677 | $desc = $boucle->show['field']; |
| 681 | 678 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 682 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 679 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.');'; |
|
| 683 | 680 | } |
| 684 | 681 | if ($desc) { |
| 685 | 682 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -754,7 +751,7 @@ discard block |
||
| 754 | 751 | $sens = " . ' DESC'"; |
| 755 | 752 | } |
| 756 | 753 | if (isset($boucle->modificateur['collate'])) { |
| 757 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 754 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 758 | 755 | } |
| 759 | 756 | |
| 760 | 757 | // Pour chaque paramètre du critère |
@@ -776,14 +773,14 @@ discard block |
||
| 776 | 773 | if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
| 777 | 774 | $expression = trim($m[1]); |
| 778 | 775 | $champ = trim($m[2]); |
| 779 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 776 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 780 | 777 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 781 | 778 | } else { |
| 782 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 779 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 783 | 780 | } |
| 784 | 781 | |
| 785 | 782 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 786 | - } elseif (preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 783 | + } elseif (preg_match(',^'.CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 787 | 784 | // {par FONCTION(champ)} |
| 788 | 785 | if (count($match) > 2) { |
| 789 | 786 | $par = substr($match[2], 1, -1); |
@@ -793,7 +790,7 @@ discard block |
||
| 793 | 790 | if ($par == 'hasard') { |
| 794 | 791 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 795 | 792 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 796 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 793 | + $order = "'".$boucle->id_table.'.'.$boucle->show['date']."'"; |
|
| 797 | 794 | } else { |
| 798 | 795 | // cas général {par champ}, {par table.champ}, ... |
| 799 | 796 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -802,7 +799,7 @@ discard block |
||
| 802 | 799 | |
| 803 | 800 | // on ne sait pas traiter… |
| 804 | 801 | else { |
| 805 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 802 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 806 | 803 | } |
| 807 | 804 | |
| 808 | 805 | // En cas d'erreur de squelette retournée par une fonction |
@@ -822,14 +819,14 @@ discard block |
||
| 822 | 819 | |
| 823 | 820 | if ($fct) { |
| 824 | 821 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 825 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 822 | + $order = "'$fct(".$r[1].")'"; |
|
| 826 | 823 | } else { |
| 827 | 824 | $order = "'$fct(' . $order . ')'"; |
| 828 | 825 | } |
| 829 | 826 | } |
| 830 | - $t = $order . $collecte . $sens; |
|
| 827 | + $t = $order.$collecte.$sens; |
|
| 831 | 828 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 832 | - $t = $r[1] . $r[2]; |
|
| 829 | + $t = $r[1].$r[2]; |
|
| 833 | 830 | } |
| 834 | 831 | |
| 835 | 832 | $boucle->order[] = $t; |
@@ -879,16 +876,16 @@ discard block |
||
| 879 | 876 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 880 | 877 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 881 | 878 | if (is_array($_champ)) { |
| 882 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 879 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." num $champ"]]; |
|
| 883 | 880 | } |
| 884 | 881 | $boucle = &$boucles[$idb]; |
| 885 | - $texte = '0+' . $_champ; |
|
| 882 | + $texte = '0+'.$_champ; |
|
| 886 | 883 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 887 | 884 | if ($suite !== "''") { |
| 888 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 885 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 889 | 886 | } |
| 890 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 891 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | + $asnum = 'num'.($boucle->order ? count($boucle->order) : ''); |
|
| 888 | + $boucle->select[] = $texte." AS $asnum"; |
|
| 892 | 889 | |
| 893 | 890 | $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
| 894 | 891 | $orderassinum = trim($orderassinum, "'"); |
@@ -917,13 +914,13 @@ discard block |
||
| 917 | 914 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 918 | 915 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 919 | 916 | if (is_array($_champ)) { |
| 920 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 917 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." sinum $champ"]]; |
|
| 921 | 918 | } |
| 922 | 919 | $boucle = &$boucles[$idb]; |
| 923 | - $texte = '0+' . $_champ; |
|
| 920 | + $texte = '0+'.$_champ; |
|
| 924 | 921 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 925 | 922 | if ($suite !== "''") { |
| 926 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 923 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 927 | 924 | } |
| 928 | 925 | |
| 929 | 926 | $as = false; |
@@ -939,8 +936,8 @@ discard block |
||
| 939 | 936 | } |
| 940 | 937 | |
| 941 | 938 | if (!$as) { |
| 942 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 943 | - $boucle->select[] = $select . $as; |
|
| 939 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ''); |
|
| 940 | + $boucle->select[] = $select.$as; |
|
| 944 | 941 | } |
| 945 | 942 | $order = "'$as'"; |
| 946 | 943 | return $order; |
@@ -965,10 +962,10 @@ discard block |
||
| 965 | 962 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 966 | 963 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 967 | 964 | if (is_array($_champ)) { |
| 968 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 965 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." multi $champ"]]; |
|
| 969 | 966 | } |
| 970 | 967 | $boucle = &$boucles[$idb]; |
| 971 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 968 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 972 | 969 | $order = "'multi'"; |
| 973 | 970 | return $order; |
| 974 | 971 | } |
@@ -994,7 +991,7 @@ discard block |
||
| 994 | 991 | |
| 995 | 992 | // le champ existe dans la table, pas de souci (le plus commun) |
| 996 | 993 | if (isset($desc['field'][$par])) { |
| 997 | - $par = $boucle->id_table . '.' . $par; |
|
| 994 | + $par = $boucle->id_table.'.'.$par; |
|
| 998 | 995 | } |
| 999 | 996 | // le champ est peut être une jointure |
| 1000 | 997 | else { |
@@ -1015,24 +1012,24 @@ discard block |
||
| 1015 | 1012 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 1016 | 1013 | // Si la table est déjà dans le from, on la réutilise. |
| 1017 | 1014 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 1018 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1015 | + $par = $infos['alias'].'.'.$champ; |
|
| 1019 | 1016 | } elseif ( |
| 1020 | 1017 | $boucle->jointures_explicites |
| 1021 | 1018 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 1022 | 1019 | ) { |
| 1023 | - $par = $alias . '.' . $champ; |
|
| 1020 | + $par = $alias.'.'.$champ; |
|
| 1024 | 1021 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 1025 | - $par = $alias . '.' . $champ; |
|
| 1022 | + $par = $alias.'.'.$champ; |
|
| 1026 | 1023 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 1027 | 1024 | } elseif ( |
| 1028 | 1025 | $table_alias |
| 1029 | 1026 | and isset($boucle->from[$table_alias]) |
| 1030 | 1027 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 1031 | 1028 | ) { |
| 1032 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1029 | + $par = $infos['alias'].'.'.$champ; |
|
| 1033 | 1030 | } elseif ($table) { |
| 1034 | 1031 | // On avait table + champ, mais on ne les a pas trouvés |
| 1035 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1032 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 1036 | 1033 | } else { |
| 1037 | 1034 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1038 | 1035 | } |
@@ -1056,7 +1053,7 @@ discard block |
||
| 1056 | 1053 | if (!$t) { |
| 1057 | 1054 | $t = trouver_jointure_champ($champ, $boucle); |
| 1058 | 1055 | } |
| 1059 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1056 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1060 | 1057 | } |
| 1061 | 1058 | |
| 1062 | 1059 | /** |
@@ -1101,9 +1098,9 @@ discard block |
||
| 1101 | 1098 | $boucle->default_order[] = ' DESC'; |
| 1102 | 1099 | } |
| 1103 | 1100 | } else { |
| 1104 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1101 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1105 | 1102 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1106 | - $t = $r[1] . $r[2]; |
|
| 1103 | + $t = $r[1].$r[2]; |
|
| 1107 | 1104 | } |
| 1108 | 1105 | $boucle->order[$n - 1] = $t; |
| 1109 | 1106 | } |
@@ -1138,7 +1135,7 @@ discard block |
||
| 1138 | 1135 | $_order = array_pop($boucle->order); |
| 1139 | 1136 | |
| 1140 | 1137 | $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
| 1141 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1138 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1142 | 1139 | } |
| 1143 | 1140 | |
| 1144 | 1141 | |
@@ -1147,7 +1144,7 @@ discard block |
||
| 1147 | 1144 | $params = $crit->param; |
| 1148 | 1145 | |
| 1149 | 1146 | if (count($params) < 1) { |
| 1150 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1147 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1151 | 1148 | } |
| 1152 | 1149 | |
| 1153 | 1150 | $boucle = &$boucles[$idb]; |
@@ -1168,7 +1165,7 @@ discard block |
||
| 1168 | 1165 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1169 | 1166 | $date = $date[0]->texte; |
| 1170 | 1167 | if (!isset($fields[$date])) { |
| 1171 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1168 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1172 | 1169 | } |
| 1173 | 1170 | } else { |
| 1174 | 1171 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1180,38 +1177,38 @@ discard block |
||
| 1180 | 1177 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1181 | 1178 | } |
| 1182 | 1179 | $annee = $params ? array_shift($params) : ''; |
| 1183 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1184 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1180 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1181 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1185 | 1182 | ') ? $x : date("Y"))'; |
| 1186 | 1183 | |
| 1187 | 1184 | $mois = $params ? array_shift($params) : ''; |
| 1188 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1189 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1185 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1186 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1190 | 1187 | ') ? $x : date("m"))'; |
| 1191 | 1188 | |
| 1192 | 1189 | $jour = $params ? array_shift($params) : ''; |
| 1193 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1194 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1190 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1191 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1195 | 1192 | ') ? $x : date("d"))'; |
| 1196 | 1193 | |
| 1197 | 1194 | $annee2 = $params ? array_shift($params) : ''; |
| 1198 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1199 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1195 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1196 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1200 | 1197 | ') ? $x : date("Y"))'; |
| 1201 | 1198 | |
| 1202 | 1199 | $mois2 = $params ? array_shift($params) : ''; |
| 1203 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1204 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1200 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1201 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1205 | 1202 | ') ? $x : date("m"))'; |
| 1206 | 1203 | |
| 1207 | 1204 | $jour2 = $params ? array_shift($params) : ''; |
| 1208 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1209 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1205 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1206 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1210 | 1207 | ') ? $x : date("d"))'; |
| 1211 | 1208 | |
| 1212 | - $date = $boucle->id_table . ".$date"; |
|
| 1209 | + $date = $boucle->id_table.".$date"; |
|
| 1213 | 1210 | |
| 1214 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1211 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1215 | 1212 | if ($type == 'jour') { |
| 1216 | 1213 | $boucle->where[] = [ |
| 1217 | 1214 | "'='", |
@@ -1283,14 +1280,13 @@ discard block |
||
| 1283 | 1280 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1284 | 1281 | |
| 1285 | 1282 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1286 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1283 | + $boucle->limit = $a11.','.$a21; |
|
| 1287 | 1284 | } else { |
| 1288 | 1285 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1289 | 1286 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1290 | 1287 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1291 | 1288 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1292 | - $mode = (($op == '/') ? '/' : |
|
| 1293 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1289 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1294 | 1290 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1295 | 1291 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
| 1296 | 1292 | $boucle->limit = |
@@ -1336,8 +1332,7 @@ discard block |
||
| 1336 | 1332 | // {1/3} |
| 1337 | 1333 | if ($op1 == '/') { |
| 1338 | 1334 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1339 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1340 | - "($total_parties ? $total_parties : 1)"; |
|
| 1335 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1341 | 1336 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1342 | 1337 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1343 | 1338 | } else { |
@@ -1348,15 +1343,13 @@ discard block |
||
| 1348 | 1343 | |
| 1349 | 1344 | // cas {x,n-1} |
| 1350 | 1345 | if ($op2 == '-') { |
| 1351 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1352 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1353 | - ($total_parties . ' - 1')); |
|
| 1346 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1347 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1354 | 1348 | } else { |
| 1355 | 1349 | // {x,1} ou {pagination} |
| 1356 | 1350 | $fin = '$debut_boucle' |
| 1357 | 1351 | . (is_numeric($total_parties) ? |
| 1358 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1359 | - ('+' . $total_parties . ' - 1')); |
|
| 1352 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1360 | 1353 | } |
| 1361 | 1354 | |
| 1362 | 1355 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1374,11 +1367,11 @@ discard block |
||
| 1374 | 1367 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1375 | 1368 | |
| 1376 | 1369 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1377 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1370 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1378 | 1371 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1379 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1380 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1381 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1372 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1373 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1374 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1382 | 1375 | . "\n\tif (\$debut_boucle>0" |
| 1383 | 1376 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1384 | 1377 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1463,16 +1456,16 @@ discard block |
||
| 1463 | 1456 | // critere personnalise ? |
| 1464 | 1457 | if ( |
| 1465 | 1458 | (!$serveur or |
| 1466 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1459 | + ((!function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere)) |
|
| 1460 | + and (!function_exists($f = $f.'_dist')) |
|
| 1461 | + and (!function_exists($f = 'critere_'.$serveur.'_'.$critere)) |
|
| 1462 | + and (!function_exists($f = $f.'_dist')) |
|
| 1470 | 1463 | ) |
| 1471 | 1464 | ) |
| 1472 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1473 | - and (!function_exists($f = $f . '_dist')) |
|
| 1474 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1475 | - and (!function_exists($f = $f . '_dist')) |
|
| 1465 | + and (!function_exists($f = 'critere_'.$table.'_'.$critere)) |
|
| 1466 | + and (!function_exists($f = $f.'_dist')) |
|
| 1467 | + and (!function_exists($f = 'critere_'.$critere)) |
|
| 1468 | + and (!function_exists($f = $f.'_dist')) |
|
| 1476 | 1469 | ) { |
| 1477 | 1470 | // fonction critere standard |
| 1478 | 1471 | $f = $defaut; |
@@ -1505,9 +1498,9 @@ discard block |
||
| 1505 | 1498 | */ |
| 1506 | 1499 | function kwote($lisp, $serveur = '', $type = '') { |
| 1507 | 1500 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1508 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1509 | 1502 | } else { |
| 1510 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1511 | 1504 | } |
| 1512 | 1505 | } |
| 1513 | 1506 | |
@@ -1529,7 +1522,7 @@ discard block |
||
| 1529 | 1522 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1530 | 1523 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1531 | 1524 | if (!$r) { |
| 1532 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1525 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]); |
|
| 1533 | 1526 | } |
| 1534 | 1527 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1535 | 1528 | |
@@ -1554,8 +1547,8 @@ discard block |
||
| 1554 | 1547 | "'NOT'", |
| 1555 | 1548 | [ |
| 1556 | 1549 | "'IN'", |
| 1557 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1558 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1550 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1551 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1559 | 1552 | ] |
| 1560 | 1553 | ]; |
| 1561 | 1554 | } |
@@ -1573,22 +1566,22 @@ discard block |
||
| 1573 | 1566 | $descr = $boucles[$idb]->descr; |
| 1574 | 1567 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1575 | 1568 | |
| 1576 | - $var = '$in' . $cpt++; |
|
| 1569 | + $var = '$in'.$cpt++; |
|
| 1577 | 1570 | $x = "\n\t$var = array();"; |
| 1578 | 1571 | foreach ($val as $k => $v) { |
| 1579 | 1572 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1580 | 1573 | // optimiser le traitement des constantes |
| 1581 | 1574 | if (is_numeric($r[2])) { |
| 1582 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1575 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1583 | 1576 | } else { |
| 1584 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1577 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1585 | 1578 | } |
| 1586 | 1579 | } else { |
| 1587 | 1580 | // Pour permettre de passer des tableaux de valeurs |
| 1588 | 1581 | // on repere l'utilisation brute de #ENV**{X}, |
| 1589 | 1582 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1590 | 1583 | // et on deballe mais en rajoutant l'anti XSS |
| 1591 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1584 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1592 | 1585 | } |
| 1593 | 1586 | } |
| 1594 | 1587 | |
@@ -1602,7 +1595,7 @@ discard block |
||
| 1602 | 1595 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1603 | 1596 | } |
| 1604 | 1597 | |
| 1605 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1598 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1606 | 1599 | } |
| 1607 | 1600 | |
| 1608 | 1601 | /** |
@@ -1675,7 +1668,7 @@ discard block |
||
| 1675 | 1668 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1676 | 1669 | } |
| 1677 | 1670 | // nous aider en mode debug. |
| 1678 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1671 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1679 | 1672 | $boucle->modificateur['id_'] = $champs; |
| 1680 | 1673 | |
| 1681 | 1674 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1716,7 +1709,7 @@ discard block |
||
| 1716 | 1709 | // Les champs id_xx de la table demandée |
| 1717 | 1710 | $champs = array_filter( |
| 1718 | 1711 | array_keys($desc['field']), |
| 1719 | - function ($champ) { |
|
| 1712 | + function($champ) { |
|
| 1720 | 1713 | return |
| 1721 | 1714 | strpos($champ, 'id_') === 0 |
| 1722 | 1715 | or (in_array($champ, ['objet'])); |
@@ -1930,8 +1923,8 @@ discard block |
||
| 1930 | 1923 | "'NOT'", |
| 1931 | 1924 | [ |
| 1932 | 1925 | "'IN'", |
| 1933 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1934 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1926 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1927 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1935 | 1928 | ] |
| 1936 | 1929 | ]; |
| 1937 | 1930 | } |
@@ -1942,7 +1935,7 @@ discard block |
||
| 1942 | 1935 | if ($crit->cond) { |
| 1943 | 1936 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1944 | 1937 | if ($col === 'date' or $col === 'date_redac') { |
| 1945 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1938 | + if ($pred === "\$Pile[0]['".$col."']") { |
|
| 1946 | 1939 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1947 | 1940 | } |
| 1948 | 1941 | } |
@@ -2105,7 +2098,7 @@ discard block |
||
| 2105 | 2098 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2106 | 2099 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2107 | 2100 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2108 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2101 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2109 | 2102 | } |
| 2110 | 2103 | // sinon expliciter les |
| 2111 | 2104 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2121,14 +2114,14 @@ discard block |
||
| 2121 | 2114 | ) { |
| 2122 | 2115 | $r = $r[1] |
| 2123 | 2116 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2124 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2117 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2125 | 2118 | $val[0] = "sql_quote($r)"; |
| 2126 | 2119 | } |
| 2127 | 2120 | elseif ( |
| 2128 | 2121 | strpos($val[0], '@@defaultcast@@') !== false |
| 2129 | 2122 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2130 | 2123 | ) { |
| 2131 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2124 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2132 | 2125 | } |
| 2133 | 2126 | } |
| 2134 | 2127 | |
@@ -2136,7 +2129,7 @@ discard block |
||
| 2136 | 2129 | strpos($val[0], '@@defaultcast@@') !== false |
| 2137 | 2130 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2138 | 2131 | ) { |
| 2139 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2132 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2140 | 2133 | } |
| 2141 | 2134 | |
| 2142 | 2135 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2152,7 +2145,7 @@ discard block |
||
| 2152 | 2145 | // inserer le nom de la table SQL devant le nom du champ |
| 2153 | 2146 | if ($table) { |
| 2154 | 2147 | if ($col[0] == '`') { |
| 2155 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2148 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2156 | 2149 | } else { |
| 2157 | 2150 | $arg = "$table.$col"; |
| 2158 | 2151 | } |
@@ -2287,9 +2280,9 @@ discard block |
||
| 2287 | 2280 | **/ |
| 2288 | 2281 | function primary_doublee($decompose, $table) { |
| 2289 | 2282 | $e1 = reset($decompose); |
| 2290 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2283 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2291 | 2284 | |
| 2292 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2285 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2293 | 2286 | } |
| 2294 | 2287 | |
| 2295 | 2288 | /** |
@@ -2328,7 +2321,7 @@ discard block |
||
| 2328 | 2321 | $checkarrivee |
| 2329 | 2322 | and is_string($checkarrivee) |
| 2330 | 2323 | and $a = table_objet($checkarrivee) |
| 2331 | - and in_array($a . '_liens', $joints) |
|
| 2324 | + and in_array($a.'_liens', $joints) |
|
| 2332 | 2325 | ) { |
| 2333 | 2326 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2334 | 2327 | return $res; |
@@ -2348,12 +2341,12 @@ discard block |
||
| 2348 | 2341 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2349 | 2342 | $joindre = false; |
| 2350 | 2343 | foreach ($cols as $col) { |
| 2351 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2344 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2352 | 2345 | if (trouver_champ($c, $boucle->where)) { |
| 2353 | 2346 | $joindre = true; |
| 2354 | 2347 | } else { |
| 2355 | 2348 | // mais ca peut etre dans le FIELD pour le Having |
| 2356 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2349 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2357 | 2350 | if (trouver_champ($c, $boucle->select)) { |
| 2358 | 2351 | $joindre = true; |
| 2359 | 2352 | } |
@@ -2399,7 +2392,7 @@ discard block |
||
| 2399 | 2392 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2400 | 2393 | |
| 2401 | 2394 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2402 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2395 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2403 | 2396 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2404 | 2397 | |
| 2405 | 2398 | if (!$intermediaire or !$arrivee) { |
@@ -2503,7 +2496,7 @@ discard block |
||
| 2503 | 2496 | } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
| 2504 | 2497 | // un critere conditionnel sur date est traite a part |
| 2505 | 2498 | // car la date est mise d'office par SPIP, |
| 2506 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2499 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2507 | 2500 | } |
| 2508 | 2501 | |
| 2509 | 2502 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2535,7 +2528,7 @@ discard block |
||
| 2535 | 2528 | and (($p == "'") or ($p == '"')) |
| 2536 | 2529 | and $params[0][1]->type == 'champ' |
| 2537 | 2530 | ) { |
| 2538 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2531 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2539 | 2532 | } else { |
| 2540 | 2533 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2541 | 2534 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2551,7 +2544,7 @@ discard block |
||
| 2551 | 2544 | $fct = $args_sql = ''; |
| 2552 | 2545 | // fonction SQL ? |
| 2553 | 2546 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2554 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2547 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2555 | 2548 | $fct = $m[1]; |
| 2556 | 2549 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2557 | 2550 | $col = $a[1]; |
@@ -2642,7 +2635,7 @@ discard block |
||
| 2642 | 2635 | # si oui choisir ce champ, sinon choisir xxxx |
| 2643 | 2636 | |
| 2644 | 2637 | if (isset($table['field']["date$suite"])) { |
| 2645 | - $date_orig = 'date' . $suite; |
|
| 2638 | + $date_orig = 'date'.$suite; |
|
| 2646 | 2639 | } else { |
| 2647 | 2640 | $date_orig = substr($suite, 1); |
| 2648 | 2641 | } |
@@ -2653,12 +2646,12 @@ discard block |
||
| 2653 | 2646 | } |
| 2654 | 2647 | } |
| 2655 | 2648 | |
| 2656 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2657 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2649 | + $date_compare = "\"' . normaliser_date(". |
|
| 2650 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2658 | 2651 | ") . '\""; |
| 2659 | 2652 | |
| 2660 | 2653 | $col_vraie = $date_orig; |
| 2661 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2654 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2662 | 2655 | |
| 2663 | 2656 | switch ($col) { |
| 2664 | 2657 | case 'date': |
@@ -2678,26 +2671,26 @@ discard block |
||
| 2678 | 2671 | break; |
| 2679 | 2672 | case 'age': |
| 2680 | 2673 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2681 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2674 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2682 | 2675 | break; |
| 2683 | 2676 | case 'age_relatif': |
| 2684 | 2677 | $col = calculer_param_date($date_compare, $date_orig); |
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2678 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2686 | 2679 | break; |
| 2687 | 2680 | case 'jour_relatif': |
| 2688 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2689 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2682 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2690 | 2683 | break; |
| 2691 | 2684 | case 'mois_relatif': |
| 2692 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2693 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2694 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2685 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2686 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2687 | + ')-YEAR('.$date_orig.'))'; |
|
| 2688 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2696 | 2689 | break; |
| 2697 | 2690 | case 'annee_relatif': |
| 2698 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2699 | - $date_orig . ')'; |
|
| 2700 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2691 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2692 | + $date_orig.')'; |
|
| 2693 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2701 | 2694 | break; |
| 2702 | 2695 | } |
| 2703 | 2696 | |
@@ -2758,10 +2751,10 @@ discard block |
||
| 2758 | 2751 | } |
| 2759 | 2752 | |
| 2760 | 2753 | $boucle->hash .= ' |
| 2761 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2754 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2762 | 2755 | |
| 2763 | 2756 | $boucle->hash .= ' |
| 2764 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2757 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2765 | 2758 | } |
| 2766 | 2759 | |
| 2767 | 2760 | /** |
@@ -2780,7 +2773,7 @@ discard block |
||
| 2780 | 2773 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2781 | 2774 | $boucle = &$boucles[$idb]; |
| 2782 | 2775 | $boucle->hash .= ' |
| 2783 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2776 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2784 | 2777 | } |
| 2785 | 2778 | |
| 2786 | 2779 | |
@@ -2799,7 +2792,7 @@ discard block |
||
| 2799 | 2792 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2800 | 2793 | foreach ($crit->param as $param) { |
| 2801 | 2794 | $boucle->hash .= ' |
| 2802 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2795 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2803 | 2796 | } |
| 2804 | 2797 | } |
| 2805 | 2798 | |
@@ -2818,14 +2811,14 @@ discard block |
||
| 2818 | 2811 | */ |
| 2819 | 2812 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2820 | 2813 | $boucle = &$boucles[$idb]; |
| 2821 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2814 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2822 | 2815 | foreach ($crit->param as $param) { |
| 2823 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2816 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2824 | 2817 | $param, |
| 2825 | 2818 | $idb, |
| 2826 | 2819 | $boucles, |
| 2827 | 2820 | $boucles[$idb]->id_parent |
| 2828 | - ) . ";\n"; |
|
| 2821 | + ).";\n"; |
|
| 2829 | 2822 | } |
| 2830 | 2823 | } |
| 2831 | 2824 | |
@@ -2852,14 +2845,14 @@ discard block |
||
| 2852 | 2845 | */ |
| 2853 | 2846 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2854 | 2847 | $boucle = &$boucles[$idb]; |
| 2855 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2848 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2856 | 2849 | foreach ($crit->param as $param) { |
| 2857 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2850 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2858 | 2851 | $param, |
| 2859 | 2852 | $idb, |
| 2860 | 2853 | $boucles, |
| 2861 | 2854 | $boucles[$idb]->id_parent |
| 2862 | - ) . ";\n"; |
|
| 2855 | + ).";\n"; |
|
| 2863 | 2856 | } |
| 2864 | 2857 | } |
| 2865 | 2858 | |
@@ -2878,7 +2871,7 @@ discard block |
||
| 2878 | 2871 | $boucle = &$boucles[$idb]; |
| 2879 | 2872 | foreach ($crit->param as $param) { |
| 2880 | 2873 | $boucle->hash .= ' |
| 2881 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2874 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2882 | 2875 | } |
| 2883 | 2876 | } |
| 2884 | 2877 | |
@@ -2919,7 +2912,7 @@ discard block |
||
| 2919 | 2912 | if ($crit->param) { |
| 2920 | 2913 | foreach ($crit->param as $param) { |
| 2921 | 2914 | $boucle->hash .= "\t\$command['si'][] = " |
| 2922 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2915 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2923 | 2916 | } |
| 2924 | 2917 | // interdire {si 0} aussi ! |
| 2925 | 2918 | } else { |
@@ -2943,7 +2936,7 @@ discard block |
||
| 2943 | 2936 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2944 | 2937 | $boucle = &$boucles[$idb]; |
| 2945 | 2938 | $boucle->hash .= ' |
| 2946 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2939 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2947 | 2940 | $command[\'sourcemode\'] = \'table\';'; |
| 2948 | 2941 | } |
| 2949 | 2942 | |
@@ -2976,11 +2969,10 @@ discard block |
||
| 2976 | 2969 | $table_sql = table_objet_sql(objet_type($table)); |
| 2977 | 2970 | |
| 2978 | 2971 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2979 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2980 | - 'id_parent'; |
|
| 2972 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2981 | 2973 | |
| 2982 | 2974 | $in = 'IN'; |
| 2983 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2975 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2984 | 2976 | if ($not) { |
| 2985 | 2977 | $where = ["'NOT'", $where]; |
| 2986 | 2978 | } |
@@ -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 | // https://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 | - $pos_apres = 0; |
|
| 89 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | - if (!$champ->texte or count($champ->param) > 1) { |
|
| 91 | - if (!function_exists('normaliser_inclure')) { |
|
| 92 | - include_spip('public/normaliser'); |
|
| 93 | - } |
|
| 94 | - normaliser_inclure($champ); |
|
| 95 | - } |
|
| 96 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 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 | + $pos_apres = 0; |
|
| 89 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 90 | + if (!$champ->texte or count($champ->param) > 1) { |
|
| 91 | + if (!function_exists('normaliser_inclure')) { |
|
| 92 | + include_spip('public/normaliser'); |
|
| 93 | + } |
|
| 94 | + normaliser_inclure($champ); |
|
| 95 | + } |
|
| 96 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 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 | // https://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,43 +163,43 @@ 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 = []; |
|
| 184 | - $largs = $match[5]; |
|
| 185 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 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 | - $pos_apres = 0; |
|
| 194 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 195 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 196 | - $result[] = $champ; |
|
| 197 | - } |
|
| 198 | - if ($texte !== '') { |
|
| 199 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - 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 = []; |
|
| 184 | + $largs = $match[5]; |
|
| 185 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 186 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 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 | + $pos_apres = 0; |
|
| 194 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 195 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 196 | + $result[] = $champ; |
|
| 197 | + } |
|
| 198 | + if ($texte !== '') { |
|
| 199 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $result; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -217,47 +217,47 @@ discard block |
||
| 217 | 217 | * @return array |
| 218 | 218 | **/ |
| 219 | 219 | function phraser_champs($texte, $ligne, $result) { |
| 220 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | - $p = strpos($texte, $match[0]); |
|
| 222 | - // texte après la balise |
|
| 223 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | - |
|
| 225 | - $debut = substr($texte, 0, $p); |
|
| 226 | - if ($p) { |
|
| 227 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | - } |
|
| 229 | - $ligne += substr_count($debut, "\n"); |
|
| 230 | - $champ = new Champ(); |
|
| 231 | - $champ->ligne = $ligne; |
|
| 232 | - $ligne += substr_count($match[0], "\n"); |
|
| 233 | - $champ->nom_boucle = $match[2]; |
|
| 234 | - $champ->nom_champ = $match[3]; |
|
| 235 | - $champ->etoile = $match[5]; |
|
| 236 | - |
|
| 237 | - if ($suite and $suite[0] == '{') { |
|
| 238 | - phraser_arg($suite, '', [], $champ); |
|
| 239 | - // ce ltrim est une ereur de conception |
|
| 240 | - // mais on le conserve par souci de compatibilite |
|
| 241 | - $texte = ltrim($suite); |
|
| 242 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 220 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 221 | + $p = strpos($texte, $match[0]); |
|
| 222 | + // texte après la balise |
|
| 223 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 224 | + |
|
| 225 | + $debut = substr($texte, 0, $p); |
|
| 226 | + if ($p) { |
|
| 227 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 228 | + } |
|
| 229 | + $ligne += substr_count($debut, "\n"); |
|
| 230 | + $champ = new Champ(); |
|
| 231 | + $champ->ligne = $ligne; |
|
| 232 | + $ligne += substr_count($match[0], "\n"); |
|
| 233 | + $champ->nom_boucle = $match[2]; |
|
| 234 | + $champ->nom_champ = $match[3]; |
|
| 235 | + $champ->etoile = $match[5]; |
|
| 236 | + |
|
| 237 | + if ($suite and $suite[0] == '{') { |
|
| 238 | + phraser_arg($suite, '', [], $champ); |
|
| 239 | + // ce ltrim est une ereur de conception |
|
| 240 | + // mais on le conserve par souci de compatibilite |
|
| 241 | + $texte = ltrim($suite); |
|
| 242 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 243 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 244 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 245 | 245 | if ($n = (strlen($suite) - strlen($texte))) { |
| 246 | 246 | $champ->apres = array(new Texte); |
| 247 | 247 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 248 | 248 | } |
| 249 | 249 | */ |
| 250 | - } else { |
|
| 251 | - $texte = $suite; |
|
| 252 | - } |
|
| 253 | - phraser_vieux($champ); |
|
| 254 | - $result[] = $champ; |
|
| 255 | - } |
|
| 256 | - if ($texte !== '') { |
|
| 257 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - return $result; |
|
| 250 | + } else { |
|
| 251 | + $texte = $suite; |
|
| 252 | + } |
|
| 253 | + phraser_vieux($champ); |
|
| 254 | + $result[] = $champ; |
|
| 255 | + } |
|
| 256 | + if ($texte !== '') { |
|
| 257 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + return $result; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // Gestion des imbrications: |
@@ -267,15 +267,15 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // https://code.spip.net/@phraser_champs_etendus |
| 269 | 269 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 270 | - if ($texte === '') { |
|
| 271 | - return $result; |
|
| 272 | - } |
|
| 273 | - $sep = '##'; |
|
| 274 | - while (strpos($texte, $sep) !== false) { |
|
| 275 | - $sep .= '#'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 270 | + if ($texte === '') { |
|
| 271 | + return $result; |
|
| 272 | + } |
|
| 273 | + $sep = '##'; |
|
| 274 | + while (strpos($texte, $sep) !== false) { |
|
| 275 | + $sep .= '#'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -296,278 +296,278 @@ discard block |
||
| 296 | 296 | * @return array |
| 297 | 297 | */ |
| 298 | 298 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 299 | - $length = strlen($texte); |
|
| 300 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | - $pos_debut++; |
|
| 302 | - } |
|
| 303 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | - $st = substr($texte, $pos_debut); |
|
| 306 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | - $pos_debut = $length - strlen($st); |
|
| 308 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | - $pos_debut++; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return $result; |
|
| 299 | + $length = strlen($texte); |
|
| 300 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 301 | + $pos_debut++; |
|
| 302 | + } |
|
| 303 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 304 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 305 | + $st = substr($texte, $pos_debut); |
|
| 306 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 307 | + $pos_debut = $length - strlen($st); |
|
| 308 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 309 | + $pos_debut++; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return $result; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // https://code.spip.net/@phraser_arg |
| 317 | 317 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 318 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | - $suite = ltrim($match[2]); |
|
| 320 | - $fonc = trim($match[1]); |
|
| 321 | - if ($fonc && $fonc[0] == '|') { |
|
| 322 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | - } |
|
| 324 | - $res = [$fonc]; |
|
| 325 | - $err_f = ''; |
|
| 326 | - // cas du filtre sans argument ou du critere / |
|
| 327 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | - if (!$match[1]) { |
|
| 330 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | - $texte = ''; |
|
| 333 | - } else { |
|
| 334 | - $texte = $suite; |
|
| 335 | - } |
|
| 336 | - if ($err_f) { |
|
| 337 | - $pointeur_champ->param = false; |
|
| 338 | - } elseif ($fonc !== '') { |
|
| 339 | - $pointeur_champ->param[] = $res; |
|
| 340 | - } |
|
| 341 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | - |
|
| 344 | - return $result; |
|
| 345 | - } |
|
| 346 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | - $collecte = []; |
|
| 348 | - while ($args && $args[0] != '}') { |
|
| 349 | - if ($args[0] == '"') { |
|
| 350 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | - } elseif ($args[0] == "'") { |
|
| 352 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | - } else { |
|
| 354 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | - $champ = new Texte(); |
|
| 359 | - $champ->apres = $champ->avant = $args = ''; |
|
| 360 | - break; |
|
| 361 | - } |
|
| 362 | - } |
|
| 363 | - $arg = $regs[2]; |
|
| 364 | - if (trim($regs[1])) { |
|
| 365 | - $champ = new Texte(); |
|
| 366 | - $champ->texte = $arg; |
|
| 367 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | - $result[] = $champ; |
|
| 369 | - $collecte[] = $champ; |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - } else { |
|
| 372 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | - // 0 est un aveu d'impuissance. A completer |
|
| 374 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | - |
|
| 376 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | - $collecte = array_merge($collecte, $arg); |
|
| 378 | - $result = array_merge($result, $arg); |
|
| 379 | - } else { |
|
| 380 | - $n = strpos($args, $r[0]); |
|
| 381 | - $pred = substr($args, 0, $n); |
|
| 382 | - $par = ',}'; |
|
| 383 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | - $pred = $m[1]; |
|
| 385 | - $par = ')'; |
|
| 386 | - } |
|
| 387 | - if ($pred) { |
|
| 388 | - $champ = new Texte(); |
|
| 389 | - $champ->texte = $pred; |
|
| 390 | - $champ->apres = $champ->avant = ''; |
|
| 391 | - $result[] = $champ; |
|
| 392 | - $collecte[] = $champ; |
|
| 393 | - } |
|
| 394 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | - $champ = new Champ(); |
|
| 396 | - $champ->nom_boucle = $r[2]; |
|
| 397 | - $champ->nom_champ = $r[3]; |
|
| 398 | - $champ->etoile = $r[5]; |
|
| 399 | - $next = $r[6]; |
|
| 400 | - while ($next == '{') { |
|
| 401 | - phraser_arg($rec, $sep, [], $champ); |
|
| 402 | - $args = ltrim($rec); |
|
| 403 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 404 | - } |
|
| 405 | - while ($next == '|') { |
|
| 406 | - $pos_apres = 0; |
|
| 407 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | - $args = substr($rec, $pos_apres); |
|
| 409 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 410 | - } |
|
| 411 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | - if ($champ->param === false) { |
|
| 413 | - $err_f = true; |
|
| 414 | - } else { |
|
| 415 | - phraser_vieux($champ); |
|
| 416 | - } |
|
| 417 | - if ($par == ')') { |
|
| 418 | - $args = substr($args, 1); |
|
| 419 | - } |
|
| 420 | - $collecte[] = $champ; |
|
| 421 | - $result[] = $champ; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | - $args = ltrim(substr($args, 1)); |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - if ($collecte) { |
|
| 433 | - $res[] = $collecte; |
|
| 434 | - $collecte = []; |
|
| 435 | - } |
|
| 436 | - $texte = substr($args, 1); |
|
| 437 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | - // propager les erreurs, et ignorer les param vides |
|
| 439 | - if ($pointeur_champ->param !== false) { |
|
| 440 | - if ($err_f) { |
|
| 441 | - $pointeur_champ->param = false; |
|
| 442 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | - $pointeur_champ->param[] = $res; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | - |
|
| 449 | - return $result; |
|
| 318 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 319 | + $suite = ltrim($match[2]); |
|
| 320 | + $fonc = trim($match[1]); |
|
| 321 | + if ($fonc && $fonc[0] == '|') { |
|
| 322 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 323 | + } |
|
| 324 | + $res = [$fonc]; |
|
| 325 | + $err_f = ''; |
|
| 326 | + // cas du filtre sans argument ou du critere / |
|
| 327 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 328 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 329 | + if (!$match[1]) { |
|
| 330 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 331 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 332 | + $texte = ''; |
|
| 333 | + } else { |
|
| 334 | + $texte = $suite; |
|
| 335 | + } |
|
| 336 | + if ($err_f) { |
|
| 337 | + $pointeur_champ->param = false; |
|
| 338 | + } elseif ($fonc !== '') { |
|
| 339 | + $pointeur_champ->param[] = $res; |
|
| 340 | + } |
|
| 341 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 342 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 343 | + |
|
| 344 | + return $result; |
|
| 345 | + } |
|
| 346 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 347 | + $collecte = []; |
|
| 348 | + while ($args && $args[0] != '}') { |
|
| 349 | + if ($args[0] == '"') { |
|
| 350 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 351 | + } elseif ($args[0] == "'") { |
|
| 352 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 353 | + } else { |
|
| 354 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 355 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 356 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 357 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 358 | + $champ = new Texte(); |
|
| 359 | + $champ->apres = $champ->avant = $args = ''; |
|
| 360 | + break; |
|
| 361 | + } |
|
| 362 | + } |
|
| 363 | + $arg = $regs[2]; |
|
| 364 | + if (trim($regs[1])) { |
|
| 365 | + $champ = new Texte(); |
|
| 366 | + $champ->texte = $arg; |
|
| 367 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 368 | + $result[] = $champ; |
|
| 369 | + $collecte[] = $champ; |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + } else { |
|
| 372 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 373 | + // 0 est un aveu d'impuissance. A completer |
|
| 374 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 375 | + |
|
| 376 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 377 | + $collecte = array_merge($collecte, $arg); |
|
| 378 | + $result = array_merge($result, $arg); |
|
| 379 | + } else { |
|
| 380 | + $n = strpos($args, $r[0]); |
|
| 381 | + $pred = substr($args, 0, $n); |
|
| 382 | + $par = ',}'; |
|
| 383 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 384 | + $pred = $m[1]; |
|
| 385 | + $par = ')'; |
|
| 386 | + } |
|
| 387 | + if ($pred) { |
|
| 388 | + $champ = new Texte(); |
|
| 389 | + $champ->texte = $pred; |
|
| 390 | + $champ->apres = $champ->avant = ''; |
|
| 391 | + $result[] = $champ; |
|
| 392 | + $collecte[] = $champ; |
|
| 393 | + } |
|
| 394 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 395 | + $champ = new Champ(); |
|
| 396 | + $champ->nom_boucle = $r[2]; |
|
| 397 | + $champ->nom_champ = $r[3]; |
|
| 398 | + $champ->etoile = $r[5]; |
|
| 399 | + $next = $r[6]; |
|
| 400 | + while ($next == '{') { |
|
| 401 | + phraser_arg($rec, $sep, [], $champ); |
|
| 402 | + $args = ltrim($rec); |
|
| 403 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 404 | + } |
|
| 405 | + while ($next == '|') { |
|
| 406 | + $pos_apres = 0; |
|
| 407 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 408 | + $args = substr($rec, $pos_apres); |
|
| 409 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 410 | + } |
|
| 411 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 412 | + if ($champ->param === false) { |
|
| 413 | + $err_f = true; |
|
| 414 | + } else { |
|
| 415 | + phraser_vieux($champ); |
|
| 416 | + } |
|
| 417 | + if ($par == ')') { |
|
| 418 | + $args = substr($args, 1); |
|
| 419 | + } |
|
| 420 | + $collecte[] = $champ; |
|
| 421 | + $result[] = $champ; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 425 | + $args = ltrim(substr($args, 1)); |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + if ($collecte) { |
|
| 433 | + $res[] = $collecte; |
|
| 434 | + $collecte = []; |
|
| 435 | + } |
|
| 436 | + $texte = substr($args, 1); |
|
| 437 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 438 | + // propager les erreurs, et ignorer les param vides |
|
| 439 | + if ($pointeur_champ->param !== false) { |
|
| 440 | + if ($err_f) { |
|
| 441 | + $pointeur_champ->param = false; |
|
| 442 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 443 | + $pointeur_champ->param[] = $res; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 447 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 448 | + |
|
| 449 | + return $result; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
| 453 | 453 | // https://code.spip.net/@phraser_champs_exterieurs |
| 454 | 454 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 455 | - $res = []; |
|
| 456 | - while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 457 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - $debut = substr($texte, 0, $p); |
|
| 461 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | - if ($p) { |
|
| 463 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | - } |
|
| 465 | - $ligne += substr_count($debut, "\n"); |
|
| 466 | - $res[] = $nested[$m[1]]; |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 455 | + $res = []; |
|
| 456 | + while (($p = strpos($texte, "%$sep")) !== false) { |
|
| 457 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + $debut = substr($texte, 0, $p); |
|
| 461 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 462 | + if ($p) { |
|
| 463 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 464 | + } |
|
| 465 | + $ligne += substr_count($debut, "\n"); |
|
| 466 | + $res[] = $nested[$m[1]]; |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | // https://code.spip.net/@phraser_champs_interieurs |
| 473 | 473 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 474 | - $i = 0; // en fait count($result) |
|
| 475 | - $x = ''; |
|
| 476 | - |
|
| 477 | - while (true) { |
|
| 478 | - $j = $i; |
|
| 479 | - $n = $ligne; |
|
| 480 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | - $p = strpos($texte, $match[0]); |
|
| 482 | - $debut = substr($texte, 0, $p); |
|
| 483 | - if ($p) { |
|
| 484 | - $result[$i] = $debut; |
|
| 485 | - $i++; |
|
| 486 | - } |
|
| 487 | - $nom = $match[4]; |
|
| 488 | - $champ = new Champ(); |
|
| 489 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | - $champ->nom_boucle = $match[3]; |
|
| 492 | - $champ->nom_champ = $nom; |
|
| 493 | - $champ->etoile = $match[6]; |
|
| 494 | - // phraser_args indiquera ou commence apres |
|
| 495 | - $pos_apres = 0; |
|
| 496 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | - phraser_vieux($champ); |
|
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | - if (!empty($debut)) { |
|
| 501 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | - } |
|
| 503 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | - |
|
| 505 | - // reinjecter la boucle si c'en est une |
|
| 506 | - phraser_boucle_placeholder($champ); |
|
| 507 | - |
|
| 508 | - $result[$i] = $champ; |
|
| 509 | - $i++; |
|
| 510 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | - } |
|
| 512 | - if ($texte !== '') { |
|
| 513 | - $result[$i] = $texte; |
|
| 514 | - $i++; |
|
| 515 | - } |
|
| 516 | - $x = ''; |
|
| 517 | - |
|
| 518 | - while ($j < $i) { |
|
| 519 | - $z = $result[$j]; |
|
| 520 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | - if (is_object($z)) { |
|
| 522 | - $x .= "%$sep$j@"; |
|
| 523 | - } else { |
|
| 524 | - $x .= $z; |
|
| 525 | - } |
|
| 526 | - $j++; |
|
| 527 | - } |
|
| 528 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | - $texte = $x; |
|
| 530 | - } else { |
|
| 531 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | - } |
|
| 533 | - } |
|
| 474 | + $i = 0; // en fait count($result) |
|
| 475 | + $x = ''; |
|
| 476 | + |
|
| 477 | + while (true) { |
|
| 478 | + $j = $i; |
|
| 479 | + $n = $ligne; |
|
| 480 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | + $p = strpos($texte, $match[0]); |
|
| 482 | + $debut = substr($texte, 0, $p); |
|
| 483 | + if ($p) { |
|
| 484 | + $result[$i] = $debut; |
|
| 485 | + $i++; |
|
| 486 | + } |
|
| 487 | + $nom = $match[4]; |
|
| 488 | + $champ = new Champ(); |
|
| 489 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | + $champ->nom_boucle = $match[3]; |
|
| 492 | + $champ->nom_champ = $nom; |
|
| 493 | + $champ->etoile = $match[6]; |
|
| 494 | + // phraser_args indiquera ou commence apres |
|
| 495 | + $pos_apres = 0; |
|
| 496 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | + phraser_vieux($champ); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | + if (!empty($debut)) { |
|
| 501 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | + } |
|
| 503 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | + |
|
| 505 | + // reinjecter la boucle si c'en est une |
|
| 506 | + phraser_boucle_placeholder($champ); |
|
| 507 | + |
|
| 508 | + $result[$i] = $champ; |
|
| 509 | + $i++; |
|
| 510 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | + } |
|
| 512 | + if ($texte !== '') { |
|
| 513 | + $result[$i] = $texte; |
|
| 514 | + $i++; |
|
| 515 | + } |
|
| 516 | + $x = ''; |
|
| 517 | + |
|
| 518 | + while ($j < $i) { |
|
| 519 | + $z = $result[$j]; |
|
| 520 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | + if (is_object($z)) { |
|
| 522 | + $x .= "%$sep$j@"; |
|
| 523 | + } else { |
|
| 524 | + $x .= $z; |
|
| 525 | + } |
|
| 526 | + $j++; |
|
| 527 | + } |
|
| 528 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | + $texte = $x; |
|
| 530 | + } else { |
|
| 531 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | function phraser_vieux(&$champ) { |
| 537 | - $nom = $champ->nom_champ; |
|
| 538 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_emb($champ); |
|
| 543 | - } elseif ($nom == 'EXPOSER') { |
|
| 544 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_exposer($champ); |
|
| 548 | - } elseif ($champ->param) { |
|
| 549 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | - include_spip('public/normaliser'); |
|
| 552 | - } |
|
| 553 | - phraser_vieux_recherche($champ); |
|
| 554 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | - include_spip('public/normaliser'); |
|
| 557 | - } |
|
| 558 | - phraser_vieux_logos($champ); |
|
| 559 | - } elseif ($nom == 'MODELE') { |
|
| 560 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | - include_spip('public/normaliser'); |
|
| 562 | - } |
|
| 563 | - phraser_vieux_modele($champ); |
|
| 564 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | - include_spip('public/normaliser'); |
|
| 567 | - } |
|
| 568 | - phraser_vieux_inclu($champ); |
|
| 569 | - } |
|
| 570 | - } |
|
| 537 | + $nom = $champ->nom_champ; |
|
| 538 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_emb($champ); |
|
| 543 | + } elseif ($nom == 'EXPOSER') { |
|
| 544 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_exposer($champ); |
|
| 548 | + } elseif ($champ->param) { |
|
| 549 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | + include_spip('public/normaliser'); |
|
| 552 | + } |
|
| 553 | + phraser_vieux_recherche($champ); |
|
| 554 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | + include_spip('public/normaliser'); |
|
| 557 | + } |
|
| 558 | + phraser_vieux_logos($champ); |
|
| 559 | + } elseif ($nom == 'MODELE') { |
|
| 560 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | + include_spip('public/normaliser'); |
|
| 562 | + } |
|
| 563 | + phraser_vieux_modele($champ); |
|
| 564 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | + include_spip('public/normaliser'); |
|
| 567 | + } |
|
| 568 | + phraser_vieux_inclu($champ); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -595,201 +595,201 @@ discard block |
||
| 595 | 595 | **/ |
| 596 | 596 | function phraser_criteres($params, &$result) { |
| 597 | 597 | |
| 598 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | - $args = []; |
|
| 600 | - $type = $result->type_requete; |
|
| 601 | - $doublons = []; |
|
| 602 | - foreach ($params as $v) { |
|
| 603 | - $var = $v[1][0]; |
|
| 604 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | - if ((count($v) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | - // plus d'un argument et pas le critere IN: |
|
| 607 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | - if ( |
|
| 609 | - $var->type != 'texte' |
|
| 610 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | - ) { |
|
| 612 | - $op = ','; |
|
| 613 | - $not = ''; |
|
| 614 | - $cond = false; |
|
| 615 | - } else { |
|
| 616 | - // Le debut du premier argument est l'operateur |
|
| 617 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | - $op = $m[2]; |
|
| 619 | - $not = $m[1]; |
|
| 620 | - $cond = $m[3]; |
|
| 621 | - // virer le premier argument, |
|
| 622 | - // et mettre son reliquat eventuel |
|
| 623 | - // Recopier pour ne pas alterer le texte source |
|
| 624 | - // utile au debusqueur |
|
| 625 | - if ($m[4]) { |
|
| 626 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | - $c = null; |
|
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 630 | - if (isset($c)) { |
|
| 631 | - $m[4] = $c; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - $texte = new Texte(); |
|
| 635 | - $texte->texte = $m[4]; |
|
| 636 | - $v[1][0] = $texte; |
|
| 637 | - } else { |
|
| 638 | - array_shift($v[1]); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - array_shift($v); // $v[O] est vide |
|
| 642 | - $crit = new Critere(); |
|
| 643 | - $crit->op = $op; |
|
| 644 | - $crit->not = $not; |
|
| 645 | - $crit->cond = $cond; |
|
| 646 | - $crit->exclus = ''; |
|
| 647 | - $crit->param = $v; |
|
| 648 | - $args[] = $crit; |
|
| 649 | - } else { |
|
| 650 | - if ($var->type != 'texte') { |
|
| 651 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | - // erreur ou critere infixe "/" |
|
| 653 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | - $err_ci = [ |
|
| 655 | - 'zbug_critere_inconnu', |
|
| 656 | - ['critere' => $var->nom_champ] |
|
| 657 | - ]; |
|
| 658 | - erreur_squelette($err_ci, $result); |
|
| 659 | - } else { |
|
| 660 | - $crit = new Critere(); |
|
| 661 | - $crit->op = '/'; |
|
| 662 | - $crit->not = ''; |
|
| 663 | - $crit->exclus = ''; |
|
| 664 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | - $args[] = $crit; |
|
| 666 | - } |
|
| 667 | - } else { |
|
| 668 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | - // les separateurs |
|
| 670 | - if ($var->apres) { |
|
| 671 | - $result->separateur[] = $param; |
|
| 672 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | - $result->modificateur['tout'] = true; |
|
| 674 | - } elseif ($param == 'plat') { |
|
| 675 | - $result->modificateur['plat'] = true; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | - // ceux-ci pour avoir la rubrique mere... |
|
| 681 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | - // traités normalement. |
|
| 683 | - elseif ( |
|
| 684 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | - ) { |
|
| 688 | - $result->modificateur['tout'] = true; |
|
| 689 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | - // rien a faire sur {id_rubrique} tout seul |
|
| 691 | - } else { |
|
| 692 | - // pas d'emplacement statique, faut un dynamique |
|
| 693 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | - // cette variable sera inseree dans le code |
|
| 696 | - // et son nom sert d'indicateur des maintenant |
|
| 697 | - $result->doublons = '$doublons_index'; |
|
| 698 | - if ($param == 'unique') { |
|
| 699 | - $param = 'doublons'; |
|
| 700 | - } |
|
| 701 | - } elseif ($param == 'recherche') { |
|
| 702 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | - $result->hash = ' '; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | - } elseif ( |
|
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | - ) { |
|
| 712 | - $a2 = trim($m[8]); |
|
| 713 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | - $a2 = substr($a2, 1, -1); |
|
| 715 | - } |
|
| 716 | - $crit = phraser_critere_infixe( |
|
| 717 | - $m[2], |
|
| 718 | - $a2, |
|
| 719 | - $v, |
|
| 720 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | - $m[6], |
|
| 722 | - $m[5] |
|
| 723 | - ); |
|
| 724 | - $crit->exclus = $m[1]; |
|
| 725 | - } elseif ( |
|
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 728 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | - ) { |
|
| 730 | - // contient aussi les comparaisons implicites ! |
|
| 731 | - // Comme ci-dessus: |
|
| 732 | - // le premier arg contient l'operateur |
|
| 733 | - array_shift($v); |
|
| 734 | - if ($m[6]) { |
|
| 735 | - $v[0][0] = new Texte(); |
|
| 736 | - $v[0][0]->texte = $m[6]; |
|
| 737 | - } else { |
|
| 738 | - array_shift($v[0]); |
|
| 739 | - if (!$v[0]) { |
|
| 740 | - array_shift($v); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - $crit = new Critere(); |
|
| 744 | - $crit->op = $m[2]; |
|
| 745 | - $crit->param = $v; |
|
| 746 | - $crit->not = $m[1]; |
|
| 747 | - $crit->cond = $m[5]; |
|
| 748 | - } else { |
|
| 749 | - $err_ci = [ |
|
| 750 | - 'zbug_critere_inconnu', |
|
| 751 | - ['critere' => $param] |
|
| 752 | - ]; |
|
| 753 | - erreur_squelette($err_ci, $result); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | - $args[] = $crit; |
|
| 758 | - } else { |
|
| 759 | - $doublons[] = $crit; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // les doublons non nies doivent etre le dernier critere |
|
| 767 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | - // cf critere_doublon |
|
| 769 | - if ($doublons) { |
|
| 770 | - $args = array_merge($args, $doublons); |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | - if (!$err_ci) { |
|
| 775 | - $result->criteres = $args; |
|
| 776 | - } |
|
| 598 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | + $args = []; |
|
| 600 | + $type = $result->type_requete; |
|
| 601 | + $doublons = []; |
|
| 602 | + foreach ($params as $v) { |
|
| 603 | + $var = $v[1][0]; |
|
| 604 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | + if ((count($v) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | + // plus d'un argument et pas le critere IN: |
|
| 607 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | + if ( |
|
| 609 | + $var->type != 'texte' |
|
| 610 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | + ) { |
|
| 612 | + $op = ','; |
|
| 613 | + $not = ''; |
|
| 614 | + $cond = false; |
|
| 615 | + } else { |
|
| 616 | + // Le debut du premier argument est l'operateur |
|
| 617 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | + $op = $m[2]; |
|
| 619 | + $not = $m[1]; |
|
| 620 | + $cond = $m[3]; |
|
| 621 | + // virer le premier argument, |
|
| 622 | + // et mettre son reliquat eventuel |
|
| 623 | + // Recopier pour ne pas alterer le texte source |
|
| 624 | + // utile au debusqueur |
|
| 625 | + if ($m[4]) { |
|
| 626 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | + $c = null; |
|
| 629 | + eval('$c = ' . $m[4] . ';'); |
|
| 630 | + if (isset($c)) { |
|
| 631 | + $m[4] = $c; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + $texte = new Texte(); |
|
| 635 | + $texte->texte = $m[4]; |
|
| 636 | + $v[1][0] = $texte; |
|
| 637 | + } else { |
|
| 638 | + array_shift($v[1]); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + array_shift($v); // $v[O] est vide |
|
| 642 | + $crit = new Critere(); |
|
| 643 | + $crit->op = $op; |
|
| 644 | + $crit->not = $not; |
|
| 645 | + $crit->cond = $cond; |
|
| 646 | + $crit->exclus = ''; |
|
| 647 | + $crit->param = $v; |
|
| 648 | + $args[] = $crit; |
|
| 649 | + } else { |
|
| 650 | + if ($var->type != 'texte') { |
|
| 651 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | + // erreur ou critere infixe "/" |
|
| 653 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | + $err_ci = [ |
|
| 655 | + 'zbug_critere_inconnu', |
|
| 656 | + ['critere' => $var->nom_champ] |
|
| 657 | + ]; |
|
| 658 | + erreur_squelette($err_ci, $result); |
|
| 659 | + } else { |
|
| 660 | + $crit = new Critere(); |
|
| 661 | + $crit->op = '/'; |
|
| 662 | + $crit->not = ''; |
|
| 663 | + $crit->exclus = ''; |
|
| 664 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | + $args[] = $crit; |
|
| 666 | + } |
|
| 667 | + } else { |
|
| 668 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | + // les separateurs |
|
| 670 | + if ($var->apres) { |
|
| 671 | + $result->separateur[] = $param; |
|
| 672 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | + $result->modificateur['tout'] = true; |
|
| 674 | + } elseif ($param == 'plat') { |
|
| 675 | + $result->modificateur['plat'] = true; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | + // ceux-ci pour avoir la rubrique mere... |
|
| 681 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | + // traités normalement. |
|
| 683 | + elseif ( |
|
| 684 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | + ) { |
|
| 688 | + $result->modificateur['tout'] = true; |
|
| 689 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | + // rien a faire sur {id_rubrique} tout seul |
|
| 691 | + } else { |
|
| 692 | + // pas d'emplacement statique, faut un dynamique |
|
| 693 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | + // cette variable sera inseree dans le code |
|
| 696 | + // et son nom sert d'indicateur des maintenant |
|
| 697 | + $result->doublons = '$doublons_index'; |
|
| 698 | + if ($param == 'unique') { |
|
| 699 | + $param = 'doublons'; |
|
| 700 | + } |
|
| 701 | + } elseif ($param == 'recherche') { |
|
| 702 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | + $result->hash = ' '; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | + } elseif ( |
|
| 709 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | + ) { |
|
| 712 | + $a2 = trim($m[8]); |
|
| 713 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | + $a2 = substr($a2, 1, -1); |
|
| 715 | + } |
|
| 716 | + $crit = phraser_critere_infixe( |
|
| 717 | + $m[2], |
|
| 718 | + $a2, |
|
| 719 | + $v, |
|
| 720 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | + $m[6], |
|
| 722 | + $m[5] |
|
| 723 | + ); |
|
| 724 | + $crit->exclus = $m[1]; |
|
| 725 | + } elseif ( |
|
| 726 | + preg_match('/^([!]?)\s*(' . |
|
| 727 | + CHAMP_SQL_PLUS_FONC . |
|
| 728 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | + ) { |
|
| 730 | + // contient aussi les comparaisons implicites ! |
|
| 731 | + // Comme ci-dessus: |
|
| 732 | + // le premier arg contient l'operateur |
|
| 733 | + array_shift($v); |
|
| 734 | + if ($m[6]) { |
|
| 735 | + $v[0][0] = new Texte(); |
|
| 736 | + $v[0][0]->texte = $m[6]; |
|
| 737 | + } else { |
|
| 738 | + array_shift($v[0]); |
|
| 739 | + if (!$v[0]) { |
|
| 740 | + array_shift($v); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + $crit = new Critere(); |
|
| 744 | + $crit->op = $m[2]; |
|
| 745 | + $crit->param = $v; |
|
| 746 | + $crit->not = $m[1]; |
|
| 747 | + $crit->cond = $m[5]; |
|
| 748 | + } else { |
|
| 749 | + $err_ci = [ |
|
| 750 | + 'zbug_critere_inconnu', |
|
| 751 | + ['critere' => $param] |
|
| 752 | + ]; |
|
| 753 | + erreur_squelette($err_ci, $result); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | + $args[] = $crit; |
|
| 758 | + } else { |
|
| 759 | + $doublons[] = $crit; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // les doublons non nies doivent etre le dernier critere |
|
| 767 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | + // cf critere_doublon |
|
| 769 | + if ($doublons) { |
|
| 770 | + $args = array_merge($args, $doublons); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | + if (!$err_ci) { |
|
| 775 | + $result->criteres = $args; |
|
| 776 | + } |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | // https://code.spip.net/@phraser_critere_infixe |
| 780 | 780 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 781 | - $args[0] = new Texte(); |
|
| 782 | - $args[0]->texte = $arg1; |
|
| 783 | - $args[0] = [$args[0]]; |
|
| 784 | - $args[1][0] = new Texte(); |
|
| 785 | - $args[1][0]->texte = $arg2; |
|
| 786 | - $crit = new Critere(); |
|
| 787 | - $crit->op = $op; |
|
| 788 | - $crit->not = $not; |
|
| 789 | - $crit->cond = $cond; |
|
| 790 | - $crit->param = $args; |
|
| 791 | - |
|
| 792 | - return $crit; |
|
| 781 | + $args[0] = new Texte(); |
|
| 782 | + $args[0]->texte = $arg1; |
|
| 783 | + $args[0] = [$args[0]]; |
|
| 784 | + $args[1][0] = new Texte(); |
|
| 785 | + $args[1][0]->texte = $arg2; |
|
| 786 | + $crit = new Critere(); |
|
| 787 | + $crit->op = $op; |
|
| 788 | + $crit->not = $not; |
|
| 789 | + $crit->cond = $cond; |
|
| 790 | + $crit->param = $args; |
|
| 791 | + |
|
| 792 | + return $crit; |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
@@ -800,12 +800,12 @@ discard block |
||
| 800 | 800 | * @return int |
| 801 | 801 | */ |
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | - if (is_null($fin)) { |
|
| 804 | - return substr_count($texte, "\n", $debut); |
|
| 805 | - } |
|
| 806 | - else { |
|
| 807 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | - } |
|
| 803 | + if (is_null($fin)) { |
|
| 804 | + return substr_count($texte, "\n", $debut); |
|
| 805 | + } |
|
| 806 | + else { |
|
| 807 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 808 | + } |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | |
@@ -821,87 +821,87 @@ discard block |
||
| 821 | 821 | * @return array|null |
| 822 | 822 | */ |
| 823 | 823 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 824 | - $premiere_boucle = null; |
|
| 825 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | - |
|
| 827 | - $current_pos = $pos_debut_texte; |
|
| 828 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | - $current_pos = $pos_boucle + 1; |
|
| 830 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | - |
|
| 832 | - $id_boucle = ''; |
|
| 833 | - if ($pos_parent !== false) { |
|
| 834 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | - } |
|
| 836 | - if ( |
|
| 837 | - $pos_parent === false |
|
| 838 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | - ) { |
|
| 840 | - $result = new Boucle(); |
|
| 841 | - $result->id_parent = $id_parent; |
|
| 842 | - $result->descr = $descr; |
|
| 843 | - |
|
| 844 | - // un id_boucle pour l'affichage de l'erreur |
|
| 845 | - if (!strlen($id_boucle)) { |
|
| 846 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | - } |
|
| 848 | - $result->id_boucle = $id_boucle; |
|
| 849 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | - erreur_squelette($err_b, $result); |
|
| 851 | - |
|
| 852 | - continue; |
|
| 853 | - } |
|
| 854 | - else { |
|
| 855 | - $boucle = [ |
|
| 856 | - 'id_boucle' => $id_boucle, |
|
| 857 | - 'id_boucle_err' => $id_boucle, |
|
| 858 | - 'debut_boucle' => $pos_boucle, |
|
| 859 | - 'pos_boucle' => $pos_boucle, |
|
| 860 | - 'pos_parent' => $pos_parent, |
|
| 861 | - 'pos_precond' => false, |
|
| 862 | - 'pos_precond_inside' => false, |
|
| 863 | - 'pos_preaff' => false, |
|
| 864 | - 'pos_preaff_inside' => false, |
|
| 865 | - ]; |
|
| 866 | - |
|
| 867 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | - if (!strlen($id_boucle)) { |
|
| 869 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | - if ( |
|
| 876 | - $pos_precond !== false |
|
| 877 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | - ) { |
|
| 879 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | - $boucle['pos_precond'] = $pos_precond; |
|
| 881 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | - if ( |
|
| 887 | - $pos_preaff !== false |
|
| 888 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | - ) { |
|
| 890 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | - } |
|
| 894 | - if (!strlen($id_boucle)) { |
|
| 895 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | - $premiere_boucle = $boucle; |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - return $premiere_boucle; |
|
| 824 | + $premiere_boucle = null; |
|
| 825 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 826 | + |
|
| 827 | + $current_pos = $pos_debut_texte; |
|
| 828 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 829 | + $current_pos = $pos_boucle + 1; |
|
| 830 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 831 | + |
|
| 832 | + $id_boucle = ''; |
|
| 833 | + if ($pos_parent !== false) { |
|
| 834 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 835 | + } |
|
| 836 | + if ( |
|
| 837 | + $pos_parent === false |
|
| 838 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 839 | + ) { |
|
| 840 | + $result = new Boucle(); |
|
| 841 | + $result->id_parent = $id_parent; |
|
| 842 | + $result->descr = $descr; |
|
| 843 | + |
|
| 844 | + // un id_boucle pour l'affichage de l'erreur |
|
| 845 | + if (!strlen($id_boucle)) { |
|
| 846 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 847 | + } |
|
| 848 | + $result->id_boucle = $id_boucle; |
|
| 849 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 850 | + erreur_squelette($err_b, $result); |
|
| 851 | + |
|
| 852 | + continue; |
|
| 853 | + } |
|
| 854 | + else { |
|
| 855 | + $boucle = [ |
|
| 856 | + 'id_boucle' => $id_boucle, |
|
| 857 | + 'id_boucle_err' => $id_boucle, |
|
| 858 | + 'debut_boucle' => $pos_boucle, |
|
| 859 | + 'pos_boucle' => $pos_boucle, |
|
| 860 | + 'pos_parent' => $pos_parent, |
|
| 861 | + 'pos_precond' => false, |
|
| 862 | + 'pos_precond_inside' => false, |
|
| 863 | + 'pos_preaff' => false, |
|
| 864 | + 'pos_preaff_inside' => false, |
|
| 865 | + ]; |
|
| 866 | + |
|
| 867 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 868 | + if (!strlen($id_boucle)) { |
|
| 869 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 873 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 874 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 875 | + if ( |
|
| 876 | + $pos_precond !== false |
|
| 877 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 878 | + ) { |
|
| 879 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 880 | + $boucle['pos_precond'] = $pos_precond; |
|
| 881 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 885 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 886 | + if ( |
|
| 887 | + $pos_preaff !== false |
|
| 888 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 889 | + ) { |
|
| 890 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 891 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 892 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 893 | + } |
|
| 894 | + if (!strlen($id_boucle)) { |
|
| 895 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 899 | + $premiere_boucle = $boucle; |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + return $premiere_boucle; |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -916,68 +916,68 @@ discard block |
||
| 916 | 916 | * @return mixed |
| 917 | 917 | */ |
| 918 | 918 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 919 | - $id_boucle = $boucle['id_boucle']; |
|
| 920 | - $pos_courante = $pos_debut_texte; |
|
| 921 | - |
|
| 922 | - $boucle['pos_postcond'] = false; |
|
| 923 | - $boucle['pos_postcond_inside'] = false; |
|
| 924 | - $boucle['pos_altern'] = false; |
|
| 925 | - $boucle['pos_altern_inside'] = false; |
|
| 926 | - $boucle['pos_postaff'] = false; |
|
| 927 | - $boucle['pos_postaff_inside'] = false; |
|
| 928 | - |
|
| 929 | - $pos_anonyme_next = null; |
|
| 930 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | - if (!strlen($id_boucle)) { |
|
| 932 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // |
|
| 936 | - // 1. Recuperer la partie conditionnelle apres |
|
| 937 | - // |
|
| 938 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | - if ( |
|
| 941 | - $pos_apres !== false |
|
| 942 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | - ) { |
|
| 944 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | - $pos_apres += strlen($apres_boucle); |
|
| 946 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | - $pos_courante = $pos_apres ; |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - // |
|
| 951 | - // 2. Récuperer la partie alternative apres |
|
| 952 | - // |
|
| 953 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | - if ( |
|
| 956 | - $pos_altern !== false |
|
| 957 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | - ) { |
|
| 959 | - $boucle['pos_altern'] = $pos_altern; |
|
| 960 | - $pos_altern += strlen($altern_boucle); |
|
| 961 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | - $pos_courante = $pos_altern; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - // |
|
| 966 | - // 3. Recuperer la partie footer non alternative |
|
| 967 | - // |
|
| 968 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | - if ( |
|
| 971 | - $pos_postaff !== false |
|
| 972 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | - ) { |
|
| 974 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | - $pos_postaff += strlen($postaff_boucle); |
|
| 976 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | - $pos_courante = $pos_postaff ; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - return $boucle; |
|
| 919 | + $id_boucle = $boucle['id_boucle']; |
|
| 920 | + $pos_courante = $pos_debut_texte; |
|
| 921 | + |
|
| 922 | + $boucle['pos_postcond'] = false; |
|
| 923 | + $boucle['pos_postcond_inside'] = false; |
|
| 924 | + $boucle['pos_altern'] = false; |
|
| 925 | + $boucle['pos_altern_inside'] = false; |
|
| 926 | + $boucle['pos_postaff'] = false; |
|
| 927 | + $boucle['pos_postaff_inside'] = false; |
|
| 928 | + |
|
| 929 | + $pos_anonyme_next = null; |
|
| 930 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 931 | + if (!strlen($id_boucle)) { |
|
| 932 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // |
|
| 936 | + // 1. Recuperer la partie conditionnelle apres |
|
| 937 | + // |
|
| 938 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 939 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 940 | + if ( |
|
| 941 | + $pos_apres !== false |
|
| 942 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 943 | + ) { |
|
| 944 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 945 | + $pos_apres += strlen($apres_boucle); |
|
| 946 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 947 | + $pos_courante = $pos_apres ; |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + // |
|
| 951 | + // 2. Récuperer la partie alternative apres |
|
| 952 | + // |
|
| 953 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 954 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 955 | + if ( |
|
| 956 | + $pos_altern !== false |
|
| 957 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 958 | + ) { |
|
| 959 | + $boucle['pos_altern'] = $pos_altern; |
|
| 960 | + $pos_altern += strlen($altern_boucle); |
|
| 961 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 962 | + $pos_courante = $pos_altern; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + // |
|
| 966 | + // 3. Recuperer la partie footer non alternative |
|
| 967 | + // |
|
| 968 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 969 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 970 | + if ( |
|
| 971 | + $pos_postaff !== false |
|
| 972 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 973 | + ) { |
|
| 974 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 975 | + $pos_postaff += strlen($postaff_boucle); |
|
| 976 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 977 | + $pos_courante = $pos_postaff ; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + return $boucle; |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | |
@@ -987,21 +987,21 @@ discard block |
||
| 987 | 987 | * @param null|object $boucle |
| 988 | 988 | */ |
| 989 | 989 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 990 | - static $boucles_connues = []; |
|
| 991 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | - } |
|
| 995 | - else { |
|
| 996 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | - $placeholder = $champ->nom_champ; |
|
| 998 | - $id = reset($champ->param[0][1]); |
|
| 999 | - $id = $id->texte; |
|
| 1000 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 990 | + static $boucles_connues = []; |
|
| 991 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 992 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 993 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 994 | + } |
|
| 995 | + else { |
|
| 996 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 997 | + $placeholder = $champ->nom_champ; |
|
| 998 | + $id = reset($champ->param[0][1]); |
|
| 999 | + $id = $id->texte; |
|
| 1000 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1001 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | |
@@ -1014,274 +1014,274 @@ discard block |
||
| 1014 | 1014 | * @return string |
| 1015 | 1015 | */ |
| 1016 | 1016 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1017 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | - //memoriser la boucle a reinjecter |
|
| 1019 | - $id_boucle = "$id_boucle"; |
|
| 1020 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | - return $placeholder; |
|
| 1017 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1018 | + //memoriser la boucle a reinjecter |
|
| 1019 | + $id_boucle = "$id_boucle"; |
|
| 1020 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1021 | + return $placeholder; |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1025 | 1025 | |
| 1026 | - $all_res = []; |
|
| 1027 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | - if (is_null($boucle_placeholder)) { |
|
| 1029 | - do { |
|
| 1030 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | - $pos_debut_texte = 0; |
|
| 1036 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | - $result = new Boucle(); |
|
| 1039 | - $result->id_parent = $id_parent; |
|
| 1040 | - $result->descr = $descr; |
|
| 1041 | - |
|
| 1042 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | - $pos_parent = $boucle['pos_parent']; |
|
| 1044 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | - |
|
| 1046 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | - |
|
| 1048 | - // boucle anonyme ? |
|
| 1049 | - if (!strlen($id_boucle)) { |
|
| 1050 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - $pos_debut_boucle = $pos_courante; |
|
| 1054 | - |
|
| 1055 | - $pos_milieu = $pos_parent; |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | - if ($boucle['pos_precond'] !== false) { |
|
| 1059 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | - |
|
| 1061 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | - $end_preaff = $pos_debut_boucle; |
|
| 1069 | - |
|
| 1070 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - $result->id_boucle = $id_boucle; |
|
| 1076 | - |
|
| 1077 | - if ( |
|
| 1078 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | - or ($pos_match = strpos($texte, $match[0], $pos_milieu)) === false |
|
| 1080 | - or $pos_match > $pos_milieu |
|
| 1081 | - ) { |
|
| 1082 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | - erreur_squelette($err_b, $result); |
|
| 1084 | - |
|
| 1085 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | - continue; |
|
| 1088 | - } |
|
| 1089 | - |
|
| 1090 | - $result->type_requete = $match[0]; |
|
| 1091 | - $pos_milieu += strlen($match[0]); |
|
| 1092 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | - |
|
| 1094 | - $type = $match[1]; |
|
| 1095 | - $jointures = trim($match[2]); |
|
| 1096 | - $table_optionnelle = ($match[3]); |
|
| 1097 | - if ($jointures) { |
|
| 1098 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | - // ou elles seront completees des jointures declarees |
|
| 1100 | - $result->jointures_explicites = $jointures; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - if ($table_optionnelle) { |
|
| 1104 | - $result->table_optionnelle = $type; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | - // Resultat mis dans result->param |
|
| 1109 | - $pos_fin_criteres = $pos_milieu; |
|
| 1110 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | - |
|
| 1112 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | - // pour l'instant on met le source (chaine) : |
|
| 1114 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | - $pos_milieu = $pos_fin_criteres; |
|
| 1118 | - |
|
| 1119 | - // |
|
| 1120 | - // Recuperer la fin : |
|
| 1121 | - // |
|
| 1122 | - if ($texte[$pos_milieu] === '/') { |
|
| 1123 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | - $pos_courante += 2; |
|
| 1125 | - $result->milieu = ''; |
|
| 1126 | - } else { |
|
| 1127 | - $pos_milieu += 1; |
|
| 1128 | - |
|
| 1129 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | - if ($pos_fin === false) { |
|
| 1132 | - $err_b = [ |
|
| 1133 | - 'zbug_erreur_boucle_fermant', |
|
| 1134 | - ['id' => $id_boucle] |
|
| 1135 | - ]; |
|
| 1136 | - erreur_squelette($err_b, $result); |
|
| 1137 | - $pos_courante += strlen($fin_boucle); |
|
| 1138 | - } |
|
| 1139 | - else { |
|
| 1140 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | - $search_from = $pos_milieu; |
|
| 1144 | - $nb_open = 1; |
|
| 1145 | - $nb_close = 1; |
|
| 1146 | - $maxiter = 0; |
|
| 1147 | - do { |
|
| 1148 | - while ( |
|
| 1149 | - $nb_close < $nb_open |
|
| 1150 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | - ) { |
|
| 1152 | - $nb_close++; |
|
| 1153 | - $pos_fin = $p; |
|
| 1154 | - } |
|
| 1155 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | - if ($nb_close < $nb_open) { |
|
| 1157 | - break; |
|
| 1158 | - } |
|
| 1159 | - while ( |
|
| 1160 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | - and $p < $pos_fin |
|
| 1162 | - ) { |
|
| 1163 | - $nb_open++; |
|
| 1164 | - $search_from = $p + 1; |
|
| 1165 | - } |
|
| 1166 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | - |
|
| 1168 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | - } |
|
| 1170 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | - |
|
| 1176 | - // |
|
| 1177 | - // 1. Partie conditionnelle apres ? |
|
| 1178 | - // |
|
| 1179 | - if ($boucle['pos_postcond']) { |
|
| 1180 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - // |
|
| 1187 | - // 2. Partie alternative apres ? |
|
| 1188 | - // |
|
| 1189 | - $ligne_altern = $ligne_suite; |
|
| 1190 | - if ($boucle['pos_altern']) { |
|
| 1191 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - // |
|
| 1197 | - // 3. Partie footer non alternative ? |
|
| 1198 | - // |
|
| 1199 | - $ligne_postaff = $ligne_suite; |
|
| 1200 | - if ($boucle['pos_postaff']) { |
|
| 1201 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $result->ligne = $ligne_preaff; |
|
| 1207 | - |
|
| 1208 | - if ($p = strpos($type, ':')) { |
|
| 1209 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | - $type = substr($type, $p + 1); |
|
| 1211 | - } |
|
| 1212 | - $soustype = strtolower($type); |
|
| 1213 | - |
|
| 1214 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | - $soustype = $type; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - $result->type_requete = $soustype; |
|
| 1219 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | - if (!is_array($result->param)) { |
|
| 1221 | - $err_b = true; |
|
| 1222 | - } else { |
|
| 1223 | - phraser_criteres($result->param, $result); |
|
| 1224 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | - $args = $result->param; |
|
| 1227 | - array_unshift( |
|
| 1228 | - $args, |
|
| 1229 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | - ); |
|
| 1231 | - $result->param = $args; |
|
| 1232 | - } |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | - if (empty($boucles[$id_boucle])) { |
|
| 1241 | - $boucles[$id_boucle] = null; |
|
| 1242 | - } |
|
| 1243 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | - |
|
| 1249 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | - if ($err_b) { |
|
| 1251 | - $result->type_requete = false; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - // Verifier qu'il n'y a pas double definition |
|
| 1255 | - // apres analyse des sous-parties (pas avant). |
|
| 1256 | - if (!empty($boucles[$id_boucle])) { |
|
| 1257 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | - $err_b_d = [ |
|
| 1259 | - 'zbug_erreur_boucle_double', |
|
| 1260 | - ['id' => $id_boucle] |
|
| 1261 | - ]; |
|
| 1262 | - erreur_squelette($err_b_d, $result); |
|
| 1263 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | - } |
|
| 1266 | - } else { |
|
| 1267 | - $boucles[$id_boucle] = $result; |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | - |
|
| 1276 | - // phraser la partie avant le debut de la boucle |
|
| 1277 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | - |
|
| 1280 | - $ligne_debut_texte = $ligne_suite; |
|
| 1281 | - $pos_debut_texte = $pos_courante; |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | - |
|
| 1286 | - return $all_res; |
|
| 1026 | + $all_res = []; |
|
| 1027 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1028 | + if (is_null($boucle_placeholder)) { |
|
| 1029 | + do { |
|
| 1030 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1031 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1035 | + $pos_debut_texte = 0; |
|
| 1036 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1037 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1038 | + $result = new Boucle(); |
|
| 1039 | + $result->id_parent = $id_parent; |
|
| 1040 | + $result->descr = $descr; |
|
| 1041 | + |
|
| 1042 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1043 | + $pos_parent = $boucle['pos_parent']; |
|
| 1044 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1045 | + |
|
| 1046 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1047 | + |
|
| 1048 | + // boucle anonyme ? |
|
| 1049 | + if (!strlen($id_boucle)) { |
|
| 1050 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle)), 0, 8); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + $pos_debut_boucle = $pos_courante; |
|
| 1054 | + |
|
| 1055 | + $pos_milieu = $pos_parent; |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1058 | + if ($boucle['pos_precond'] !== false) { |
|
| 1059 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1060 | + |
|
| 1061 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1062 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1063 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1067 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1068 | + $end_preaff = $pos_debut_boucle; |
|
| 1069 | + |
|
| 1070 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1071 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1072 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + $result->id_boucle = $id_boucle; |
|
| 1076 | + |
|
| 1077 | + if ( |
|
| 1078 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1079 | + or ($pos_match = strpos($texte, $match[0], $pos_milieu)) === false |
|
| 1080 | + or $pos_match > $pos_milieu |
|
| 1081 | + ) { |
|
| 1082 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1083 | + erreur_squelette($err_b, $result); |
|
| 1084 | + |
|
| 1085 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1086 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1087 | + continue; |
|
| 1088 | + } |
|
| 1089 | + |
|
| 1090 | + $result->type_requete = $match[0]; |
|
| 1091 | + $pos_milieu += strlen($match[0]); |
|
| 1092 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1093 | + |
|
| 1094 | + $type = $match[1]; |
|
| 1095 | + $jointures = trim($match[2]); |
|
| 1096 | + $table_optionnelle = ($match[3]); |
|
| 1097 | + if ($jointures) { |
|
| 1098 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1099 | + // ou elles seront completees des jointures declarees |
|
| 1100 | + $result->jointures_explicites = $jointures; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + if ($table_optionnelle) { |
|
| 1104 | + $result->table_optionnelle = $type; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1108 | + // Resultat mis dans result->param |
|
| 1109 | + $pos_fin_criteres = $pos_milieu; |
|
| 1110 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1111 | + |
|
| 1112 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1113 | + // pour l'instant on met le source (chaine) : |
|
| 1114 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1115 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1116 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1117 | + $pos_milieu = $pos_fin_criteres; |
|
| 1118 | + |
|
| 1119 | + // |
|
| 1120 | + // Recuperer la fin : |
|
| 1121 | + // |
|
| 1122 | + if ($texte[$pos_milieu] === '/') { |
|
| 1123 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1124 | + $pos_courante += 2; |
|
| 1125 | + $result->milieu = ''; |
|
| 1126 | + } else { |
|
| 1127 | + $pos_milieu += 1; |
|
| 1128 | + |
|
| 1129 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1130 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1131 | + if ($pos_fin === false) { |
|
| 1132 | + $err_b = [ |
|
| 1133 | + 'zbug_erreur_boucle_fermant', |
|
| 1134 | + ['id' => $id_boucle] |
|
| 1135 | + ]; |
|
| 1136 | + erreur_squelette($err_b, $result); |
|
| 1137 | + $pos_courante += strlen($fin_boucle); |
|
| 1138 | + } |
|
| 1139 | + else { |
|
| 1140 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1141 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1142 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1143 | + $search_from = $pos_milieu; |
|
| 1144 | + $nb_open = 1; |
|
| 1145 | + $nb_close = 1; |
|
| 1146 | + $maxiter = 0; |
|
| 1147 | + do { |
|
| 1148 | + while ( |
|
| 1149 | + $nb_close < $nb_open |
|
| 1150 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1151 | + ) { |
|
| 1152 | + $nb_close++; |
|
| 1153 | + $pos_fin = $p; |
|
| 1154 | + } |
|
| 1155 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1156 | + if ($nb_close < $nb_open) { |
|
| 1157 | + break; |
|
| 1158 | + } |
|
| 1159 | + while ( |
|
| 1160 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1161 | + and $p < $pos_fin |
|
| 1162 | + ) { |
|
| 1163 | + $nb_open++; |
|
| 1164 | + $search_from = $p + 1; |
|
| 1165 | + } |
|
| 1166 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1167 | + |
|
| 1168 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1169 | + } |
|
| 1170 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1174 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1175 | + |
|
| 1176 | + // |
|
| 1177 | + // 1. Partie conditionnelle apres ? |
|
| 1178 | + // |
|
| 1179 | + if ($boucle['pos_postcond']) { |
|
| 1180 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1181 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1182 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + // |
|
| 1187 | + // 2. Partie alternative apres ? |
|
| 1188 | + // |
|
| 1189 | + $ligne_altern = $ligne_suite; |
|
| 1190 | + if ($boucle['pos_altern']) { |
|
| 1191 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1192 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1193 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + // |
|
| 1197 | + // 3. Partie footer non alternative ? |
|
| 1198 | + // |
|
| 1199 | + $ligne_postaff = $ligne_suite; |
|
| 1200 | + if ($boucle['pos_postaff']) { |
|
| 1201 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1202 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1203 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $result->ligne = $ligne_preaff; |
|
| 1207 | + |
|
| 1208 | + if ($p = strpos($type, ':')) { |
|
| 1209 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1210 | + $type = substr($type, $p + 1); |
|
| 1211 | + } |
|
| 1212 | + $soustype = strtolower($type); |
|
| 1213 | + |
|
| 1214 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1215 | + $soustype = $type; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + $result->type_requete = $soustype; |
|
| 1219 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1220 | + if (!is_array($result->param)) { |
|
| 1221 | + $err_b = true; |
|
| 1222 | + } else { |
|
| 1223 | + phraser_criteres($result->param, $result); |
|
| 1224 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1225 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1226 | + $args = $result->param; |
|
| 1227 | + array_unshift( |
|
| 1228 | + $args, |
|
| 1229 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1230 | + ); |
|
| 1231 | + $result->param = $args; |
|
| 1232 | + } |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1236 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1237 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1238 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1239 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1240 | + if (empty($boucles[$id_boucle])) { |
|
| 1241 | + $boucles[$id_boucle] = null; |
|
| 1242 | + } |
|
| 1243 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1244 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1245 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1246 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1247 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1248 | + |
|
| 1249 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1250 | + if ($err_b) { |
|
| 1251 | + $result->type_requete = false; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + // Verifier qu'il n'y a pas double definition |
|
| 1255 | + // apres analyse des sous-parties (pas avant). |
|
| 1256 | + if (!empty($boucles[$id_boucle])) { |
|
| 1257 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1258 | + $err_b_d = [ |
|
| 1259 | + 'zbug_erreur_boucle_double', |
|
| 1260 | + ['id' => $id_boucle] |
|
| 1261 | + ]; |
|
| 1262 | + erreur_squelette($err_b_d, $result); |
|
| 1263 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1264 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1265 | + } |
|
| 1266 | + } else { |
|
| 1267 | + $boucles[$id_boucle] = $result; |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1271 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1272 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1273 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1274 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1275 | + |
|
| 1276 | + // phraser la partie avant le debut de la boucle |
|
| 1277 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1278 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1279 | + |
|
| 1280 | + $ligne_debut_texte = $ligne_suite; |
|
| 1281 | + $pos_debut_texte = $pos_courante; |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1285 | + |
|
| 1286 | + return $all_res; |
|
| 1287 | 1287 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_fichiers_fonctions(); |
@@ -31,177 +31,177 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // https://code.spip.net/@public_parametrer_dist |
| 33 | 33 | function public_parametrer_dist($fond, $contexte = '', $cache = '', string $connect = '') { |
| 34 | - static $composer, $styliser, $notes = null; |
|
| 35 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | - if ($page) { |
|
| 37 | - return $page; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (isset($contexte['lang'])) { |
|
| 41 | - $lang = $contexte['lang']; |
|
| 42 | - } elseif (!isset($lang)) { |
|
| 43 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | - if ($select) { |
|
| 48 | - $select = lang_select($lang); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | - |
|
| 53 | - if (!$styliser) { |
|
| 54 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | - } |
|
| 56 | - list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | - |
|
| 59 | - if ($skel) { |
|
| 60 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | - // (recursion possible a cause des modeles) |
|
| 62 | - if ($debug) { |
|
| 63 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // charger le squelette en specifiant les langages cibles et source |
|
| 68 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | - |
|
| 70 | - if (!$composer) { |
|
| 71 | - $composer = charger_fonction('composer', 'public'); |
|
| 72 | - } |
|
| 73 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | - } else { |
|
| 75 | - $fonc = ''; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | - $page = $fonc; |
|
| 80 | - } else { |
|
| 81 | - // Preparer l'appel de la fonction principale du squelette |
|
| 82 | - |
|
| 83 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | - |
|
| 85 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | - // et on enregistre l'etat courant des globales de notes... |
|
| 87 | - if (is_null($notes)) { |
|
| 88 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | - } |
|
| 90 | - if ($notes) { |
|
| 91 | - $notes('', 'empiler'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // Rajouter d'office ces deux parametres |
|
| 95 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | - if (!isset($contexte['date'])) { |
|
| 98 | - $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | - $contexte['date_default'] = true; |
|
| 100 | - } else { |
|
| 101 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if (!isset($contexte['date_redac'])) { |
|
| 105 | - $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | - $contexte['date_redac_default'] = true; |
|
| 107 | - } else { |
|
| 108 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | - try { |
|
| 113 | - $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | - } catch (Throwable $e) { |
|
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | - $corps = "<pre>$msg</pre>"; |
|
| 119 | - $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | - erreur_squelette($full_msg); |
|
| 121 | - unset($msg, $full_msg, $corps); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | - if ($notes) { |
|
| 130 | - $notes('', 'depiler'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // reinjecter en dynamique la pile des notes |
|
| 134 | - // si il y a des inclure dynamiques |
|
| 135 | - // si la pile n'est pas vide |
|
| 136 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | - if ($notes) { |
|
| 139 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // spip_log: un joli contexte |
|
| 143 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | - |
|
| 145 | - $profile = spip_timer($a); |
|
| 146 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | - |
|
| 149 | - if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if ($debug) { |
|
| 155 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | - $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | - if ( |
|
| 161 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | - and (_request('var_mode_objet') == $fonc) |
|
| 163 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | - ) { |
|
| 165 | - erreur_squelette(); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | - // si aucun #CACHE{} spécifié |
|
| 172 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | - // entre public et prive |
|
| 174 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | - } else { |
|
| 177 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $page['contexte'] = $contexte; |
|
| 182 | - |
|
| 183 | - // faire remonter le fichier source |
|
| 184 | - static $js_inclus = false; |
|
| 185 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | - $page['sourcefile'] = $sourcefile; |
|
| 187 | - $page['texte'] = |
|
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | - . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | - $js_inclus = true; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | - unset($GLOBALS['cache_utilise_session']); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($select) { |
|
| 201 | - lang_select(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $page; |
|
| 34 | + static $composer, $styliser, $notes = null; |
|
| 35 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | + if ($page) { |
|
| 37 | + return $page; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (isset($contexte['lang'])) { |
|
| 41 | + $lang = $contexte['lang']; |
|
| 42 | + } elseif (!isset($lang)) { |
|
| 43 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | + if ($select) { |
|
| 48 | + $select = lang_select($lang); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | + |
|
| 53 | + if (!$styliser) { |
|
| 54 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | + } |
|
| 56 | + list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | + |
|
| 59 | + if ($skel) { |
|
| 60 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 61 | + // (recursion possible a cause des modeles) |
|
| 62 | + if ($debug) { |
|
| 63 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 64 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // charger le squelette en specifiant les langages cibles et source |
|
| 68 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 69 | + |
|
| 70 | + if (!$composer) { |
|
| 71 | + $composer = charger_fonction('composer', 'public'); |
|
| 72 | + } |
|
| 73 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 74 | + } else { |
|
| 75 | + $fonc = ''; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 79 | + $page = $fonc; |
|
| 80 | + } else { |
|
| 81 | + // Preparer l'appel de la fonction principale du squelette |
|
| 82 | + |
|
| 83 | + spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | + |
|
| 85 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 86 | + // et on enregistre l'etat courant des globales de notes... |
|
| 87 | + if (is_null($notes)) { |
|
| 88 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 89 | + } |
|
| 90 | + if ($notes) { |
|
| 91 | + $notes('', 'empiler'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // Rajouter d'office ces deux parametres |
|
| 95 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 96 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 97 | + if (!isset($contexte['date'])) { |
|
| 98 | + $contexte['date'] = date('Y-m-d H:i:s'); |
|
| 99 | + $contexte['date_default'] = true; |
|
| 100 | + } else { |
|
| 101 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if (!isset($contexte['date_redac'])) { |
|
| 105 | + $contexte['date_redac'] = date('Y-m-d H:i:s'); |
|
| 106 | + $contexte['date_redac_default'] = true; |
|
| 107 | + } else { |
|
| 108 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 112 | + try { |
|
| 113 | + $page = $fonc(['cache' => $cache], [$contexte]); |
|
| 114 | + } catch (Throwable $e) { |
|
| 115 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 117 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 118 | + $corps = "<pre>$msg</pre>"; |
|
| 119 | + $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
|
| 120 | + erreur_squelette($full_msg); |
|
| 121 | + unset($msg, $full_msg, $corps); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 125 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 126 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 127 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 128 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 129 | + if ($notes) { |
|
| 130 | + $notes('', 'depiler'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // reinjecter en dynamique la pile des notes |
|
| 134 | + // si il y a des inclure dynamiques |
|
| 135 | + // si la pile n'est pas vide |
|
| 136 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 137 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 138 | + if ($notes) { |
|
| 139 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // spip_log: un joli contexte |
|
| 143 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 144 | + |
|
| 145 | + $profile = spip_timer($a); |
|
| 146 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 147 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | + |
|
| 149 | + if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
|
| 150 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 151 | + . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if ($debug) { |
|
| 155 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 156 | + $t = strlen($page['texte']) ? $page['texte'] : ' '; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 159 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 160 | + if ( |
|
| 161 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | + and (_request('var_mode_objet') == $fonc) |
|
| 163 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | + ) { |
|
| 165 | + erreur_squelette(); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | + // si aucun #CACHE{} spécifié |
|
| 172 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | + // entre public et prive |
|
| 174 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | + } else { |
|
| 177 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $page['contexte'] = $contexte; |
|
| 182 | + |
|
| 183 | + // faire remonter le fichier source |
|
| 184 | + static $js_inclus = false; |
|
| 185 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | + $page['sourcefile'] = $sourcefile; |
|
| 187 | + $page['texte'] = |
|
| 188 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 189 | + . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | + $js_inclus = true; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | + unset($GLOBALS['cache_utilise_session']); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($select) { |
|
| 201 | + lang_select(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $page; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,37 +210,37 @@ discard block |
||
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | 212 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 213 | - $infos = []; |
|
| 214 | - $line = 0; |
|
| 215 | - foreach ($contexte as $var => $val) { |
|
| 216 | - $line++; |
|
| 217 | - if ($max_lines and $max_lines < $line) { |
|
| 218 | - $infos[] = '…'; |
|
| 219 | - break; |
|
| 220 | - } |
|
| 221 | - if ($val === null) { |
|
| 222 | - $val = ''; |
|
| 223 | - } elseif (is_array($val)) { |
|
| 224 | - if ($profondeur_max > 0) { |
|
| 225 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 226 | - } else { |
|
| 227 | - $val = 'array:' . count($val); |
|
| 228 | - } |
|
| 229 | - } elseif (is_object($val)) { |
|
| 230 | - $val = get_class($val); |
|
| 231 | - } elseif (strlen("$val") > 30) { |
|
| 232 | - $val = substr("$val", 0, 29) . '…'; |
|
| 233 | - if (strstr($val, ' ')) { |
|
| 234 | - $val = "'$val'"; |
|
| 235 | - } |
|
| 236 | - } elseif (strstr($val, ' ')) { |
|
| 237 | - $val = "'$val'"; |
|
| 238 | - } elseif (!strlen($val)) { |
|
| 239 | - $val = "''"; |
|
| 240 | - } |
|
| 241 | - $infos[] = $var . '=' . $val; |
|
| 242 | - } |
|
| 243 | - return join(', ', $infos); |
|
| 213 | + $infos = []; |
|
| 214 | + $line = 0; |
|
| 215 | + foreach ($contexte as $var => $val) { |
|
| 216 | + $line++; |
|
| 217 | + if ($max_lines and $max_lines < $line) { |
|
| 218 | + $infos[] = '…'; |
|
| 219 | + break; |
|
| 220 | + } |
|
| 221 | + if ($val === null) { |
|
| 222 | + $val = ''; |
|
| 223 | + } elseif (is_array($val)) { |
|
| 224 | + if ($profondeur_max > 0) { |
|
| 225 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 226 | + } else { |
|
| 227 | + $val = 'array:' . count($val); |
|
| 228 | + } |
|
| 229 | + } elseif (is_object($val)) { |
|
| 230 | + $val = get_class($val); |
|
| 231 | + } elseif (strlen("$val") > 30) { |
|
| 232 | + $val = substr("$val", 0, 29) . '…'; |
|
| 233 | + if (strstr($val, ' ')) { |
|
| 234 | + $val = "'$val'"; |
|
| 235 | + } |
|
| 236 | + } elseif (strstr($val, ' ')) { |
|
| 237 | + $val = "'$val'"; |
|
| 238 | + } elseif (!strlen($val)) { |
|
| 239 | + $val = "''"; |
|
| 240 | + } |
|
| 241 | + $infos[] = $var . '=' . $val; |
|
| 242 | + } |
|
| 243 | + return join(', ', $infos); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -257,11 +257,11 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function tester_redirection($fond, $contexte, $connect) { |
| 260 | - static $tester_redirection = null; |
|
| 261 | - if (is_null($tester_redirection)) { |
|
| 262 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 263 | - } |
|
| 264 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 260 | + static $tester_redirection = null; |
|
| 261 | + if (is_null($tester_redirection)) { |
|
| 262 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 263 | + } |
|
| 264 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -277,42 +277,42 @@ discard block |
||
| 277 | 277 | * @return array|bool |
| 278 | 278 | */ |
| 279 | 279 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 280 | - if ( |
|
| 281 | - $fond == 'article' |
|
| 282 | - and !empty($contexte['id_article']) |
|
| 283 | - and $id_article = intval($contexte['id_article']) |
|
| 284 | - ) { |
|
| 285 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 286 | - $m = quete_virtuel($id_article, $connect); |
|
| 287 | - if (strlen($m)) { |
|
| 288 | - include_spip('inc/texte'); |
|
| 289 | - // les navigateurs pataugent si l'URL est vide |
|
| 290 | - if ($url = virtuel_redirige($m, true)) { |
|
| 291 | - // passer en url absolue car cette redirection pourra |
|
| 292 | - // etre utilisee dans un contexte d'url qui change |
|
| 293 | - // y compris url arbo |
|
| 294 | - $status = 302; |
|
| 295 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 296 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 297 | - } |
|
| 298 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 299 | - include_spip('inc/filtres_mini'); |
|
| 300 | - $url = url_absolue($url); |
|
| 301 | - } |
|
| 302 | - $url = str_replace('&', '&', $url); |
|
| 303 | - |
|
| 304 | - return [ |
|
| 305 | - 'texte' => '<' |
|
| 306 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 307 | - . texte_script($url) |
|
| 308 | - . "','',$status);" |
|
| 309 | - . '?' . '>', |
|
| 310 | - 'process_ins' => 'php', |
|
| 311 | - 'status' => $status |
|
| 312 | - ]; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - return false; |
|
| 280 | + if ( |
|
| 281 | + $fond == 'article' |
|
| 282 | + and !empty($contexte['id_article']) |
|
| 283 | + and $id_article = intval($contexte['id_article']) |
|
| 284 | + ) { |
|
| 285 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 286 | + $m = quete_virtuel($id_article, $connect); |
|
| 287 | + if (strlen($m)) { |
|
| 288 | + include_spip('inc/texte'); |
|
| 289 | + // les navigateurs pataugent si l'URL est vide |
|
| 290 | + if ($url = virtuel_redirige($m, true)) { |
|
| 291 | + // passer en url absolue car cette redirection pourra |
|
| 292 | + // etre utilisee dans un contexte d'url qui change |
|
| 293 | + // y compris url arbo |
|
| 294 | + $status = 302; |
|
| 295 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 296 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 297 | + } |
|
| 298 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 299 | + include_spip('inc/filtres_mini'); |
|
| 300 | + $url = url_absolue($url); |
|
| 301 | + } |
|
| 302 | + $url = str_replace('&', '&', $url); |
|
| 303 | + |
|
| 304 | + return [ |
|
| 305 | + 'texte' => '<' |
|
| 306 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 307 | + . texte_script($url) |
|
| 308 | + . "','',$status);" |
|
| 309 | + . '?' . '>', |
|
| 310 | + 'process_ins' => 'php', |
|
| 311 | + 'status' => $status |
|
| 312 | + ]; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + return false; |
|
| 318 | 318 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | } else { |
| 81 | 81 | // Preparer l'appel de la fonction principale du squelette |
| 82 | 82 | |
| 83 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 83 | + spip_timer($a = 'calcul page '.rand(0, 1000)); |
|
| 84 | 84 | |
| 85 | 85 | // On cree un marqueur de notes unique lie a cette composition |
| 86 | 86 | // et on enregistre l'etat courant des globales de notes... |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | try { |
| 113 | 113 | $page = $fonc(['cache' => $cache], [$contexte]); |
| 114 | 114 | } catch (Throwable $e) { |
| 115 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 116 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 115 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 116 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 117 | 117 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 118 | 118 | $corps = "<pre>$msg</pre>"; |
| 119 | 119 | $page = analyse_resultat_skel($fond, ['cache' => $cache], $corps, $sourcefile); |
@@ -144,17 +144,17 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $profile = spip_timer($a); |
| 146 | 146 | spip_log("calcul ($profile) [$skel] $infos" |
| 147 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 147 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 148 | 148 | |
| 149 | 149 | if (defined('_CALCUL_PROFILER') and intval($profile) > _CALCUL_PROFILER) { |
| 150 | 150 | spip_log("calcul ($profile) [$skel] $infos" |
| 151 | - . ' (' . strlen($page['texte']) . ' octets) | ' . $_SERVER['REQUEST_URI'], 'profiler' . _LOG_AVERTISSEMENT); |
|
| 151 | + . ' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], 'profiler'._LOG_AVERTISSEMENT); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if ($debug) { |
| 155 | 155 | // si c'est ce que demande le debusqueur, lui passer la main |
| 156 | 156 | $t = strlen($page['texte']) ? $page['texte'] : ' '; |
| 157 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 157 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 158 | 158 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 159 | 159 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 160 | 160 | if ( |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 186 | 186 | $page['sourcefile'] = $sourcefile; |
| 187 | 187 | $page['texte'] = |
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . '</h6>' . $page['texte'] . '</div>' |
|
| 188 | + "<div class='inclure_blocs'><h6>".$page['sourcefile'].'</h6>'.$page['texte'].'</div>' |
|
| 189 | 189 | . ($js_inclus ? '' : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 190 | 190 | $js_inclus = true; |
| 191 | 191 | } |
@@ -222,14 +222,14 @@ discard block |
||
| 222 | 222 | $val = ''; |
| 223 | 223 | } elseif (is_array($val)) { |
| 224 | 224 | if ($profondeur_max > 0) { |
| 225 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 225 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 226 | 226 | } else { |
| 227 | - $val = 'array:' . count($val); |
|
| 227 | + $val = 'array:'.count($val); |
|
| 228 | 228 | } |
| 229 | 229 | } elseif (is_object($val)) { |
| 230 | 230 | $val = get_class($val); |
| 231 | 231 | } elseif (strlen("$val") > 30) { |
| 232 | - $val = substr("$val", 0, 29) . '…'; |
|
| 232 | + $val = substr("$val", 0, 29).'…'; |
|
| 233 | 233 | if (strstr($val, ' ')) { |
| 234 | 234 | $val = "'$val'"; |
| 235 | 235 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | } elseif (!strlen($val)) { |
| 239 | 239 | $val = "''"; |
| 240 | 240 | } |
| 241 | - $infos[] = $var . '=' . $val; |
|
| 241 | + $infos[] = $var.'='.$val; |
|
| 242 | 242 | } |
| 243 | 243 | return join(', ', $infos); |
| 244 | 244 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 307 | 307 | . texte_script($url) |
| 308 | 308 | . "','',$status);" |
| 309 | - . '?' . '>', |
|
| 309 | + . '?'.'>', |
|
| 310 | 310 | 'process_ins' => 'php', |
| 311 | 311 | 'status' => $status |
| 312 | 312 | ]; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | **/ |
| 27 | 27 | |
| 28 | 28 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 29 | - return; |
|
| 29 | + return; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | * Code PHP si cet argument est présent, sinon null |
| 49 | 49 | **/ |
| 50 | 50 | function interprete_argument_balise(int $n, Champ $p): ?string { |
| 51 | - if (($p->param) && (!$p->param[0][0]) && (count($p->param[0]) > $n)) { |
|
| 52 | - return calculer_liste( |
|
| 53 | - $p->param[0][$n], |
|
| 54 | - $p->descr, |
|
| 55 | - $p->boucles, |
|
| 56 | - $p->id_boucle |
|
| 57 | - ); |
|
| 58 | - } else { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 51 | + if (($p->param) && (!$p->param[0][0]) && (count($p->param[0]) > $n)) { |
|
| 52 | + return calculer_liste( |
|
| 53 | + $p->param[0][$n], |
|
| 54 | + $p->descr, |
|
| 55 | + $p->boucles, |
|
| 56 | + $p->id_boucle |
|
| 57 | + ); |
|
| 58 | + } else { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | * Pile complétée par le code à générer |
| 78 | 78 | **/ |
| 79 | 79 | function balise_NOM_SITE_SPIP_dist($p) { |
| 80 | - $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 80 | + $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 81 | 81 | |
| 82 | - #$p->interdire_scripts = true; |
|
| 83 | - return $p; |
|
| 82 | + #$p->interdire_scripts = true; |
|
| 83 | + return $p; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | * Pile complétée par le code à générer |
| 97 | 97 | **/ |
| 98 | 98 | function balise_EMAIL_WEBMASTER_dist($p) { |
| 99 | - $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 99 | + $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 100 | 100 | |
| 101 | - #$p->interdire_scripts = true; |
|
| 102 | - return $p; |
|
| 101 | + #$p->interdire_scripts = true; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * Pile complétée par le code à générer |
| 116 | 116 | **/ |
| 117 | 117 | function balise_DESCRIPTIF_SITE_SPIP_dist($p) { |
| 118 | - $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 118 | + $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 119 | 119 | |
| 120 | - #$p->interdire_scripts = true; |
|
| 121 | - return $p; |
|
| 120 | + #$p->interdire_scripts = true; |
|
| 121 | + return $p; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * Pile complétée par le code à générer |
| 140 | 140 | **/ |
| 141 | 141 | function balise_CHARSET_dist($p) { |
| 142 | - $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 142 | + $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 143 | 143 | |
| 144 | - #$p->interdire_scripts = true; |
|
| 145 | - return $p; |
|
| 144 | + #$p->interdire_scripts = true; |
|
| 145 | + return $p; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * Pile complétée par le code à générer |
| 168 | 168 | **/ |
| 169 | 169 | function balise_LANG_LEFT_dist($p) { |
| 170 | - $_lang = champ_sql('lang', $p); |
|
| 171 | - $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | - $p->interdire_scripts = false; |
|
| 170 | + $_lang = champ_sql('lang', $p); |
|
| 171 | + $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | + $p->interdire_scripts = false; |
|
| 173 | 173 | |
| 174 | - return $p; |
|
| 174 | + return $p; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | * Pile complétée par le code à générer |
| 192 | 192 | **/ |
| 193 | 193 | function balise_LANG_RIGHT_dist($p) { |
| 194 | - $_lang = champ_sql('lang', $p); |
|
| 195 | - $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | - $p->interdire_scripts = false; |
|
| 194 | + $_lang = champ_sql('lang', $p); |
|
| 195 | + $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | + $p->interdire_scripts = false; |
|
| 197 | 197 | |
| 198 | - return $p; |
|
| 198 | + return $p; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | * Pile complétée par le code à générer |
| 221 | 221 | **/ |
| 222 | 222 | function balise_LANG_DIR_dist($p) { |
| 223 | - $_lang = champ_sql('lang', $p); |
|
| 224 | - $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | - $p->interdire_scripts = false; |
|
| 223 | + $_lang = champ_sql('lang', $p); |
|
| 224 | + $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | + $p->interdire_scripts = false; |
|
| 226 | 226 | |
| 227 | - return $p; |
|
| 227 | + return $p; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | * Pile complétée par le code à générer |
| 242 | 242 | **/ |
| 243 | 243 | function balise_PUCE_dist($p) { |
| 244 | - $p->code = 'definir_puce()'; |
|
| 245 | - $p->interdire_scripts = false; |
|
| 244 | + $p->code = 'definir_puce()'; |
|
| 245 | + $p->interdire_scripts = false; |
|
| 246 | 246 | |
| 247 | - return $p; |
|
| 247 | + return $p; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * Pile completée du code PHP d'exécution de la balise |
| 269 | 269 | */ |
| 270 | 270 | function balise_DATE_dist($p) { |
| 271 | - $p->code = champ_sql('date', $p); |
|
| 271 | + $p->code = champ_sql('date', $p); |
|
| 272 | 272 | |
| 273 | - return $p; |
|
| 273 | + return $p; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | * Pile completée du code PHP d'exécution de la balise |
| 291 | 291 | */ |
| 292 | 292 | function balise_DATE_REDAC_dist($p) { |
| 293 | - $p->code = champ_sql('date_redac', $p); |
|
| 294 | - $p->interdire_scripts = false; |
|
| 293 | + $p->code = champ_sql('date_redac', $p); |
|
| 294 | + $p->interdire_scripts = false; |
|
| 295 | 295 | |
| 296 | - return $p; |
|
| 296 | + return $p; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -312,10 +312,10 @@ discard block |
||
| 312 | 312 | * Pile completée du code PHP d'exécution de la balise |
| 313 | 313 | */ |
| 314 | 314 | function balise_DATE_MODIF_dist($p) { |
| 315 | - $p->code = champ_sql('date_modif', $p); |
|
| 316 | - $p->interdire_scripts = false; |
|
| 315 | + $p->code = champ_sql('date_modif', $p); |
|
| 316 | + $p->interdire_scripts = false; |
|
| 317 | 317 | |
| 318 | - return $p; |
|
| 318 | + return $p; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -333,13 +333,13 @@ discard block |
||
| 333 | 333 | * Pile completée du code PHP d'exécution de la balise |
| 334 | 334 | */ |
| 335 | 335 | function balise_DATE_NOUVEAUTES_dist($p) { |
| 336 | - $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 336 | + $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 337 | 337 | AND isset(\$GLOBALS['meta']['dernier_envoi_neuf'])) ? |
| 338 | 338 | \$GLOBALS['meta']['dernier_envoi_neuf'] : |
| 339 | 339 | \"'0000-00-00'\")"; |
| 340 | - $p->interdire_scripts = false; |
|
| 340 | + $p->interdire_scripts = false; |
|
| 341 | 341 | |
| 342 | - return $p; |
|
| 342 | + return $p; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | * Pile completée du code PHP d'exécution de la balise |
| 358 | 358 | */ |
| 359 | 359 | function balise_DOSSIER_SQUELETTE_dist($p) { |
| 360 | - $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | - $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | - $p->interdire_scripts = false; |
|
| 360 | + $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | + $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | + $p->interdire_scripts = false; |
|
| 363 | 363 | |
| 364 | - return $p; |
|
| 364 | + return $p; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * Pile completée du code PHP d'exécution de la balise |
| 377 | 377 | */ |
| 378 | 378 | function balise_SQUELETTE_dist($p) { |
| 379 | - $code = addslashes($p->descr['sourcefile']); |
|
| 380 | - $p->code = "'$code'" . |
|
| 381 | - $p->interdire_scripts = false; |
|
| 379 | + $code = addslashes($p->descr['sourcefile']); |
|
| 380 | + $p->code = "'$code'" . |
|
| 381 | + $p->interdire_scripts = false; |
|
| 382 | 382 | |
| 383 | - return $p; |
|
| 383 | + return $p; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -399,10 +399,10 @@ discard block |
||
| 399 | 399 | * Pile completée du code PHP d'exécution de la balise |
| 400 | 400 | */ |
| 401 | 401 | function balise_SPIP_VERSION_dist($p) { |
| 402 | - $p->code = 'spip_version()'; |
|
| 403 | - $p->interdire_scripts = false; |
|
| 402 | + $p->code = 'spip_version()'; |
|
| 403 | + $p->interdire_scripts = false; |
|
| 404 | 404 | |
| 405 | - return $p; |
|
| 405 | + return $p; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -428,18 +428,18 @@ discard block |
||
| 428 | 428 | * Pile complétée par le code à générer |
| 429 | 429 | **/ |
| 430 | 430 | function balise_NOM_SITE_dist($p) { |
| 431 | - if (!$p->etoile) { |
|
| 432 | - $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | - champ_sql('url_site', $p) . ',' . |
|
| 434 | - champ_sql('nom_site', $p) . |
|
| 435 | - ", 'titre', \$connect, false))"; |
|
| 436 | - } else { |
|
| 437 | - $p->code = champ_sql('nom_site', $p); |
|
| 438 | - } |
|
| 431 | + if (!$p->etoile) { |
|
| 432 | + $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | + champ_sql('url_site', $p) . ',' . |
|
| 434 | + champ_sql('nom_site', $p) . |
|
| 435 | + ", 'titre', \$connect, false))"; |
|
| 436 | + } else { |
|
| 437 | + $p->code = champ_sql('nom_site', $p); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $p->interdire_scripts = true; |
|
| 440 | + $p->interdire_scripts = true; |
|
| 441 | 441 | |
| 442 | - return $p; |
|
| 442 | + return $p; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -456,11 +456,11 @@ discard block |
||
| 456 | 456 | * Pile complétée par le code à générer |
| 457 | 457 | **/ |
| 458 | 458 | function balise_NOTES_dist($p) { |
| 459 | - // Recuperer les notes |
|
| 460 | - $p->code = 'calculer_notes()'; |
|
| 459 | + // Recuperer les notes |
|
| 460 | + $p->code = 'calculer_notes()'; |
|
| 461 | 461 | |
| 462 | - #$p->interdire_scripts = true; |
|
| 463 | - return $p; |
|
| 462 | + #$p->interdire_scripts = true; |
|
| 463 | + return $p; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -482,10 +482,10 @@ discard block |
||
| 482 | 482 | * Pile complétée par le code à générer |
| 483 | 483 | **/ |
| 484 | 484 | function balise_RECHERCHE_dist($p) { |
| 485 | - $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | - $p->interdire_scripts = false; |
|
| 485 | + $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | + $p->interdire_scripts = false; |
|
| 487 | 487 | |
| 488 | - return $p; |
|
| 488 | + return $p; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -503,17 +503,17 @@ discard block |
||
| 503 | 503 | * Pile complétée par le code à générer |
| 504 | 504 | **/ |
| 505 | 505 | function balise_COMPTEUR_BOUCLE_dist($p) { |
| 506 | - $b = index_boucle_mere($p); |
|
| 507 | - if ($b === '') { |
|
| 508 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | - erreur_squelette($msg, $p); |
|
| 510 | - } else { |
|
| 511 | - $p->code = "(\$Numrows['$b']['compteur_boucle'] ?? 0)"; |
|
| 512 | - $p->boucles[$b]->cptrows = true; |
|
| 513 | - $p->interdire_scripts = false; |
|
| 506 | + $b = index_boucle_mere($p); |
|
| 507 | + if ($b === '') { |
|
| 508 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | + erreur_squelette($msg, $p); |
|
| 510 | + } else { |
|
| 511 | + $p->code = "(\$Numrows['$b']['compteur_boucle'] ?? 0)"; |
|
| 512 | + $p->boucles[$b]->cptrows = true; |
|
| 513 | + $p->interdire_scripts = false; |
|
| 514 | 514 | |
| 515 | - return $p; |
|
| 516 | - } |
|
| 515 | + return $p; |
|
| 516 | + } |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -531,17 +531,17 @@ discard block |
||
| 531 | 531 | * Pile complétée par le code à générer |
| 532 | 532 | **/ |
| 533 | 533 | function balise_TOTAL_BOUCLE_dist($p) { |
| 534 | - $b = index_boucle_mere($p); |
|
| 535 | - if ($b === '') { |
|
| 536 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | - erreur_squelette($msg, $p); |
|
| 538 | - } else { |
|
| 539 | - $p->code = "(\$Numrows['$b']['total'] ?? 0)"; |
|
| 540 | - $p->boucles[$b]->numrows = true; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 534 | + $b = index_boucle_mere($p); |
|
| 535 | + if ($b === '') { |
|
| 536 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | + erreur_squelette($msg, $p); |
|
| 538 | + } else { |
|
| 539 | + $p->code = "(\$Numrows['$b']['total'] ?? 0)"; |
|
| 540 | + $p->boucles[$b]->numrows = true; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - return $p; |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | * Pile complétée par le code à générer |
| 562 | 562 | **/ |
| 563 | 563 | function balise_POINTS_dist($p) { |
| 564 | - return rindex_pile($p, 'points', 'recherche'); |
|
| 564 | + return rindex_pile($p, 'points', 'recherche'); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -582,12 +582,12 @@ discard block |
||
| 582 | 582 | * Pile complétée par le code à générer |
| 583 | 583 | **/ |
| 584 | 584 | function balise_POPULARITE_ABSOLUE_dist($p) { |
| 585 | - $p->code = 'ceil(' . |
|
| 586 | - champ_sql('popularite', $p) . |
|
| 587 | - ')'; |
|
| 588 | - $p->interdire_scripts = false; |
|
| 585 | + $p->code = 'ceil(' . |
|
| 586 | + champ_sql('popularite', $p) . |
|
| 587 | + ')'; |
|
| 588 | + $p->interdire_scripts = false; |
|
| 589 | 589 | |
| 590 | - return $p; |
|
| 590 | + return $p; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | * Pile complétée par le code à générer |
| 608 | 608 | **/ |
| 609 | 609 | function balise_POPULARITE_SITE_dist($p) { |
| 610 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | - $p->interdire_scripts = false; |
|
| 610 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | + $p->interdire_scripts = false; |
|
| 612 | 612 | |
| 613 | - return $p; |
|
| 613 | + return $p; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -631,10 +631,10 @@ discard block |
||
| 631 | 631 | * Pile complétée par le code à générer |
| 632 | 632 | **/ |
| 633 | 633 | function balise_POPULARITE_MAX_dist($p) { |
| 634 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | - $p->interdire_scripts = false; |
|
| 634 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | + $p->interdire_scripts = false; |
|
| 636 | 636 | |
| 637 | - return $p; |
|
| 637 | + return $p; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | |
@@ -660,15 +660,15 @@ discard block |
||
| 660 | 660 | * Pile complétée par le code à générer |
| 661 | 661 | **/ |
| 662 | 662 | function balise_VALEUR_dist($p) { |
| 663 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 664 | - $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 663 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 664 | + $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 665 | 665 | ; |
| 666 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | - $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | - } |
|
| 669 | - $p->interdire_scripts = true; |
|
| 666 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | + $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | + } |
|
| 669 | + $p->interdire_scripts = true; |
|
| 670 | 670 | |
| 671 | - return $p; |
|
| 671 | + return $p; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -697,16 +697,16 @@ discard block |
||
| 697 | 697 | * Pile complétée par le code à générer |
| 698 | 698 | **/ |
| 699 | 699 | function balise_EXPOSE_dist($p) { |
| 700 | - $on = "'on'"; |
|
| 701 | - $off = "''"; |
|
| 702 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | - $on = $v; |
|
| 704 | - if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | - $off = $v; |
|
| 706 | - } |
|
| 707 | - } |
|
| 700 | + $on = "'on'"; |
|
| 701 | + $off = "''"; |
|
| 702 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | + $on = $v; |
|
| 704 | + if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | + $off = $v; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return calculer_balise_expose($p, $on, $off); |
|
| 709 | + return calculer_balise_expose($p, $on, $off); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -724,35 +724,35 @@ discard block |
||
| 724 | 724 | * Pile complétée par le code à générer |
| 725 | 725 | **/ |
| 726 | 726 | function calculer_balise_expose($p, $on, $off) { |
| 727 | - $b = index_boucle($p); |
|
| 728 | - if (empty($p->boucles[$b]->primary)) { |
|
| 729 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | - erreur_squelette($msg, $p); |
|
| 731 | - } else { |
|
| 732 | - $key = $p->boucles[$b]->primary; |
|
| 733 | - $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | - $desc = $p->boucles[$b]->show; |
|
| 735 | - $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 727 | + $b = index_boucle($p); |
|
| 728 | + if (empty($p->boucles[$b]->primary)) { |
|
| 729 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | + erreur_squelette($msg, $p); |
|
| 731 | + } else { |
|
| 732 | + $key = $p->boucles[$b]->primary; |
|
| 733 | + $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | + $desc = $p->boucles[$b]->show; |
|
| 735 | + $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 736 | 736 | |
| 737 | - // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | - $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 737 | + // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | + $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 739 | 739 | |
| 740 | - if (isset($desc['field']['id_parent'])) { |
|
| 741 | - $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | - } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | - $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | - } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | - $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | - } else { |
|
| 747 | - $parent = "''"; |
|
| 748 | - } |
|
| 740 | + if (isset($desc['field']['id_parent'])) { |
|
| 741 | + $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | + } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | + $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | + } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | + $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | + } else { |
|
| 747 | + $parent = "''"; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | - } |
|
| 750 | + $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | - $p->interdire_scripts = false; |
|
| 753 | + $p->interdire_scripts = false; |
|
| 754 | 754 | |
| 755 | - return $p; |
|
| 755 | + return $p; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | |
@@ -792,46 +792,46 @@ discard block |
||
| 792 | 792 | **/ |
| 793 | 793 | function balise_INTRODUCTION_dist($p) { |
| 794 | 794 | |
| 795 | - $type_objet = $p->type_requete; |
|
| 796 | - $cle_objet = id_table_objet($type_objet); |
|
| 797 | - $_id_objet = champ_sql($cle_objet, $p); |
|
| 798 | - |
|
| 799 | - // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 800 | - // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 801 | - $_introduction_longueur = 'null'; |
|
| 802 | - $_ligne = 'array('; |
|
| 803 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 804 | - if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 805 | - if (isset($desc['field']['descriptif'])) { |
|
| 806 | - $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 807 | - } |
|
| 808 | - if (isset($desc['field']['texte'])) { |
|
| 809 | - $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 810 | - } |
|
| 811 | - if (isset($desc['field']['chapo'])) { |
|
| 812 | - $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 813 | - } |
|
| 814 | - if (isset($desc['introduction_longueur'])) { |
|
| 815 | - $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 816 | - } |
|
| 817 | - } |
|
| 818 | - $_ligne .= ')'; |
|
| 819 | - |
|
| 820 | - // Récupérer la longueur et la suite passés en paramètres |
|
| 821 | - $_longueur_ou_suite = 'null'; |
|
| 822 | - if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 823 | - $_longueur_ou_suite = $v1; |
|
| 824 | - } |
|
| 825 | - $_suite = 'null'; |
|
| 826 | - if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 827 | - $_suite = $v2; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $p->code = "generer_introduction_entite($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 831 | - |
|
| 832 | - #$p->interdire_scripts = true; |
|
| 833 | - $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 834 | - return $p; |
|
| 795 | + $type_objet = $p->type_requete; |
|
| 796 | + $cle_objet = id_table_objet($type_objet); |
|
| 797 | + $_id_objet = champ_sql($cle_objet, $p); |
|
| 798 | + |
|
| 799 | + // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 800 | + // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 801 | + $_introduction_longueur = 'null'; |
|
| 802 | + $_ligne = 'array('; |
|
| 803 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 804 | + if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 805 | + if (isset($desc['field']['descriptif'])) { |
|
| 806 | + $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 807 | + } |
|
| 808 | + if (isset($desc['field']['texte'])) { |
|
| 809 | + $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 810 | + } |
|
| 811 | + if (isset($desc['field']['chapo'])) { |
|
| 812 | + $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 813 | + } |
|
| 814 | + if (isset($desc['introduction_longueur'])) { |
|
| 815 | + $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 816 | + } |
|
| 817 | + } |
|
| 818 | + $_ligne .= ')'; |
|
| 819 | + |
|
| 820 | + // Récupérer la longueur et la suite passés en paramètres |
|
| 821 | + $_longueur_ou_suite = 'null'; |
|
| 822 | + if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 823 | + $_longueur_ou_suite = $v1; |
|
| 824 | + } |
|
| 825 | + $_suite = 'null'; |
|
| 826 | + if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 827 | + $_suite = $v2; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $p->code = "generer_introduction_entite($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 831 | + |
|
| 832 | + #$p->interdire_scripts = true; |
|
| 833 | + $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 834 | + return $p; |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | 837 | |
@@ -851,15 +851,15 @@ discard block |
||
| 851 | 851 | * Pile complétée par le code à générer |
| 852 | 852 | **/ |
| 853 | 853 | function balise_LANG_dist($p) { |
| 854 | - $_lang = champ_sql('lang', $p); |
|
| 855 | - if (!$p->etoile) { |
|
| 856 | - $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 857 | - } else { |
|
| 858 | - $p->code = "spip_htmlentities($_lang)"; |
|
| 859 | - } |
|
| 860 | - $p->interdire_scripts = false; |
|
| 854 | + $_lang = champ_sql('lang', $p); |
|
| 855 | + if (!$p->etoile) { |
|
| 856 | + $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 857 | + } else { |
|
| 858 | + $p->code = "spip_htmlentities($_lang)"; |
|
| 859 | + } |
|
| 860 | + $p->interdire_scripts = false; |
|
| 861 | 861 | |
| 862 | - return $p; |
|
| 862 | + return $p; |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | /** |
@@ -881,48 +881,48 @@ discard block |
||
| 881 | 881 | * Pile complétée par le code à générer |
| 882 | 882 | */ |
| 883 | 883 | function balise_LESAUTEURS_dist($p) { |
| 884 | - // Cherche le champ 'lesauteurs' dans la pile |
|
| 885 | - $_lesauteurs = champ_sql('lesauteurs', $p, false); |
|
| 886 | - |
|
| 887 | - // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 888 | - // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 889 | - // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 890 | - // (cf extension sites/) |
|
| 891 | - if ( |
|
| 892 | - $_lesauteurs |
|
| 893 | - and $_lesauteurs != '@$Pile[0][\'lesauteurs\']' |
|
| 894 | - ) { |
|
| 895 | - $p->code = "safehtml($_lesauteurs)"; |
|
| 896 | - // $p->interdire_scripts = true; |
|
| 897 | - } else { |
|
| 898 | - if (!$p->id_boucle) { |
|
| 899 | - $connect = ''; |
|
| 900 | - $objet = 'article'; |
|
| 901 | - $id_table_objet = 'id_article'; |
|
| 902 | - } else { |
|
| 903 | - $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 904 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 905 | - $type_boucle = $p->boucles[$b]->type_requete; |
|
| 906 | - $objet = objet_type($type_boucle); |
|
| 907 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 908 | - } |
|
| 909 | - $c = memoriser_contexte_compil($p); |
|
| 910 | - |
|
| 911 | - $p->code = sprintf( |
|
| 912 | - CODE_RECUPERER_FOND, |
|
| 913 | - "'modeles/lesauteurs'", |
|
| 914 | - "array('objet'=>'" . $objet . |
|
| 915 | - "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 916 | - ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 917 | - ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 918 | - ')', |
|
| 919 | - "'trim'=>true, 'compil'=>array($c)", |
|
| 920 | - _q($connect) |
|
| 921 | - ); |
|
| 922 | - $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - return $p; |
|
| 884 | + // Cherche le champ 'lesauteurs' dans la pile |
|
| 885 | + $_lesauteurs = champ_sql('lesauteurs', $p, false); |
|
| 886 | + |
|
| 887 | + // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 888 | + // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 889 | + // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 890 | + // (cf extension sites/) |
|
| 891 | + if ( |
|
| 892 | + $_lesauteurs |
|
| 893 | + and $_lesauteurs != '@$Pile[0][\'lesauteurs\']' |
|
| 894 | + ) { |
|
| 895 | + $p->code = "safehtml($_lesauteurs)"; |
|
| 896 | + // $p->interdire_scripts = true; |
|
| 897 | + } else { |
|
| 898 | + if (!$p->id_boucle) { |
|
| 899 | + $connect = ''; |
|
| 900 | + $objet = 'article'; |
|
| 901 | + $id_table_objet = 'id_article'; |
|
| 902 | + } else { |
|
| 903 | + $b = $p->nom_boucle ? $p->nom_boucle : $p->id_boucle; |
|
| 904 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 905 | + $type_boucle = $p->boucles[$b]->type_requete; |
|
| 906 | + $objet = objet_type($type_boucle); |
|
| 907 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 908 | + } |
|
| 909 | + $c = memoriser_contexte_compil($p); |
|
| 910 | + |
|
| 911 | + $p->code = sprintf( |
|
| 912 | + CODE_RECUPERER_FOND, |
|
| 913 | + "'modeles/lesauteurs'", |
|
| 914 | + "array('objet'=>'" . $objet . |
|
| 915 | + "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 916 | + ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 917 | + ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 918 | + ')', |
|
| 919 | + "'trim'=>true, 'compil'=>array($c)", |
|
| 920 | + _q($connect) |
|
| 921 | + ); |
|
| 922 | + $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + return $p; |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | |
@@ -949,76 +949,76 @@ discard block |
||
| 949 | 949 | * Pile complétée par le code à générer |
| 950 | 950 | */ |
| 951 | 951 | function balise_RANG_dist($p) { |
| 952 | - $b = index_boucle($p); |
|
| 953 | - if ($b === '') { |
|
| 954 | - $msg = [ |
|
| 955 | - 'zbug_champ_hors_boucle', |
|
| 956 | - ['champ' => '#RANG'] |
|
| 957 | - ]; |
|
| 958 | - erreur_squelette($msg, $p); |
|
| 959 | - } else { |
|
| 960 | - // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 961 | - // dans la boucle immediatement englobante uniquement |
|
| 962 | - // sinon on compose le champ calcule |
|
| 963 | - $_rang = champ_sql('rang', $p, '', false); |
|
| 964 | - |
|
| 965 | - // si pas trouve de champ sql rang : |
|
| 966 | - if (!$_rang or $_rang == "''") { |
|
| 967 | - $boucle = &$p->boucles[$b]; |
|
| 968 | - |
|
| 969 | - // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 970 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 971 | - $desc = $trouver_table($boucle->id_table); |
|
| 972 | - $_titre = ''; # où extraire le numero ? |
|
| 973 | - |
|
| 974 | - if (isset($desc['titre'])) { |
|
| 975 | - $t = $desc['titre']; |
|
| 976 | - if ( |
|
| 977 | - // Soit on trouve avec la déclaration de la lang AVANT |
|
| 978 | - preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | - // Soit on prend depuis le début |
|
| 980 | - or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 981 | - ) { |
|
| 982 | - $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 983 | - $m = trim($m); |
|
| 984 | - if ($m != "''") { |
|
| 985 | - if (!preg_match(',\W,', $m)) { |
|
| 986 | - $m = $boucle->id_table . ".$m"; |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - $m .= ' AS titre_rang'; |
|
| 990 | - |
|
| 991 | - $boucle->select[] = $m; |
|
| 992 | - $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 998 | - if (!$_titre) { |
|
| 999 | - $_titre = champ_sql('titre', $p); |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1003 | - // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1004 | - $type_boucle = $boucle->type_requete; |
|
| 1005 | - $objet = objet_type($type_boucle); |
|
| 1006 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 1007 | - $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1008 | - $_env = '$Pile[0]'; |
|
| 1009 | - |
|
| 1010 | - if (!$_titre) {$_titre = "''"; |
|
| 1011 | - } |
|
| 1012 | - if (!$_primary) {$_primary = "''"; |
|
| 1013 | - } |
|
| 1014 | - $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - $p->code = $_rang; |
|
| 1018 | - $p->interdire_scripts = false; |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - return $p; |
|
| 952 | + $b = index_boucle($p); |
|
| 953 | + if ($b === '') { |
|
| 954 | + $msg = [ |
|
| 955 | + 'zbug_champ_hors_boucle', |
|
| 956 | + ['champ' => '#RANG'] |
|
| 957 | + ]; |
|
| 958 | + erreur_squelette($msg, $p); |
|
| 959 | + } else { |
|
| 960 | + // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 961 | + // dans la boucle immediatement englobante uniquement |
|
| 962 | + // sinon on compose le champ calcule |
|
| 963 | + $_rang = champ_sql('rang', $p, '', false); |
|
| 964 | + |
|
| 965 | + // si pas trouve de champ sql rang : |
|
| 966 | + if (!$_rang or $_rang == "''") { |
|
| 967 | + $boucle = &$p->boucles[$b]; |
|
| 968 | + |
|
| 969 | + // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 970 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 971 | + $desc = $trouver_table($boucle->id_table); |
|
| 972 | + $_titre = ''; # où extraire le numero ? |
|
| 973 | + |
|
| 974 | + if (isset($desc['titre'])) { |
|
| 975 | + $t = $desc['titre']; |
|
| 976 | + if ( |
|
| 977 | + // Soit on trouve avec la déclaration de la lang AVANT |
|
| 978 | + preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | + // Soit on prend depuis le début |
|
| 980 | + or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 981 | + ) { |
|
| 982 | + $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 983 | + $m = trim($m); |
|
| 984 | + if ($m != "''") { |
|
| 985 | + if (!preg_match(',\W,', $m)) { |
|
| 986 | + $m = $boucle->id_table . ".$m"; |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + $m .= ' AS titre_rang'; |
|
| 990 | + |
|
| 991 | + $boucle->select[] = $m; |
|
| 992 | + $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 998 | + if (!$_titre) { |
|
| 999 | + $_titre = champ_sql('titre', $p); |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1003 | + // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1004 | + $type_boucle = $boucle->type_requete; |
|
| 1005 | + $objet = objet_type($type_boucle); |
|
| 1006 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 1007 | + $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1008 | + $_env = '$Pile[0]'; |
|
| 1009 | + |
|
| 1010 | + if (!$_titre) {$_titre = "''"; |
|
| 1011 | + } |
|
| 1012 | + if (!$_primary) {$_primary = "''"; |
|
| 1013 | + } |
|
| 1014 | + $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + $p->code = $_rang; |
|
| 1018 | + $p->interdire_scripts = false; |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + return $p; |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | |
@@ -1040,12 +1040,12 @@ discard block |
||
| 1040 | 1040 | * Pile complétée par le code à générer |
| 1041 | 1041 | **/ |
| 1042 | 1042 | function balise_POPULARITE_dist($p) { |
| 1043 | - $_popularite = champ_sql('popularite', $p); |
|
| 1044 | - $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1043 | + $_popularite = champ_sql('popularite', $p); |
|
| 1044 | + $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1045 | 1045 | / max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))"; |
| 1046 | - $p->interdire_scripts = false; |
|
| 1046 | + $p->interdire_scripts = false; |
|
| 1047 | 1047 | |
| 1048 | - return $p; |
|
| 1048 | + return $p; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | /** |
@@ -1056,8 +1056,8 @@ discard block |
||
| 1056 | 1056 | * l'absence peut-être due à une faute de frappe dans le contexte inclus. |
| 1057 | 1057 | */ |
| 1058 | 1058 | define( |
| 1059 | - 'CODE_PAGINATION', |
|
| 1060 | - '%s($Numrows["%s"]["grand_total"], |
|
| 1059 | + 'CODE_PAGINATION', |
|
| 1060 | + '%s($Numrows["%s"]["grand_total"], |
|
| 1061 | 1061 | %s, |
| 1062 | 1062 | isset($Pile[0][%4$s])?$Pile[0][%4$s]:intval(_request(%4$s)), |
| 1063 | 1063 | %5$s, %6$s, %7$s, %8$s, array(%9$s))' |
@@ -1094,75 +1094,75 @@ discard block |
||
| 1094 | 1094 | * Pile complétée par le code à générer |
| 1095 | 1095 | */ |
| 1096 | 1096 | function balise_PAGINATION_dist($p, $liste = 'true') { |
| 1097 | - $b = index_boucle_mere($p); |
|
| 1098 | - |
|
| 1099 | - // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1100 | - if ($b === '') { |
|
| 1101 | - $msg = [ |
|
| 1102 | - 'zbug_champ_hors_boucle', |
|
| 1103 | - ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1104 | - ]; |
|
| 1105 | - erreur_squelette($msg, $p); |
|
| 1106 | - |
|
| 1107 | - return $p; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1111 | - // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1112 | - if (!$p->boucles[$b]->mode_partie) { |
|
| 1113 | - if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1114 | - $msg = [ |
|
| 1115 | - 'zbug_pagination_sans_critere', |
|
| 1116 | - ['champ' => '#PAGINATION'] |
|
| 1117 | - ]; |
|
| 1118 | - erreur_squelette($msg, $p); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - return $p; |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - // a priori true |
|
| 1125 | - // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1126 | - // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1127 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1128 | - if (count($_contexte)) { |
|
| 1129 | - $key = key($_contexte); |
|
| 1130 | - if (is_numeric($key)) { |
|
| 1131 | - array_shift($_contexte); |
|
| 1132 | - $__modele = interprete_argument_balise(1, $p); |
|
| 1133 | - } |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - if (count($_contexte)) { |
|
| 1137 | - $code_contexte = implode(',', $_contexte); |
|
| 1138 | - } else { |
|
| 1139 | - $code_contexte = ''; |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 1143 | - $pas = $p->boucles[$b]->total_parties; |
|
| 1144 | - $f_pagination = chercher_filtre('pagination'); |
|
| 1145 | - $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1146 | - $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1147 | - : ("'debut" . substr($type, 1)); |
|
| 1148 | - |
|
| 1149 | - $p->code = sprintf( |
|
| 1150 | - CODE_PAGINATION, |
|
| 1151 | - $f_pagination, |
|
| 1152 | - $b, |
|
| 1153 | - $type, |
|
| 1154 | - $modif, |
|
| 1155 | - $pas, |
|
| 1156 | - $liste, |
|
| 1157 | - ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1158 | - _q($connect), |
|
| 1159 | - $code_contexte |
|
| 1160 | - ); |
|
| 1161 | - |
|
| 1162 | - $p->boucles[$b]->numrows = true; |
|
| 1163 | - $p->interdire_scripts = false; |
|
| 1164 | - |
|
| 1165 | - return $p; |
|
| 1097 | + $b = index_boucle_mere($p); |
|
| 1098 | + |
|
| 1099 | + // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1100 | + if ($b === '') { |
|
| 1101 | + $msg = [ |
|
| 1102 | + 'zbug_champ_hors_boucle', |
|
| 1103 | + ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1104 | + ]; |
|
| 1105 | + erreur_squelette($msg, $p); |
|
| 1106 | + |
|
| 1107 | + return $p; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1111 | + // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1112 | + if (!$p->boucles[$b]->mode_partie) { |
|
| 1113 | + if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1114 | + $msg = [ |
|
| 1115 | + 'zbug_pagination_sans_critere', |
|
| 1116 | + ['champ' => '#PAGINATION'] |
|
| 1117 | + ]; |
|
| 1118 | + erreur_squelette($msg, $p); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + return $p; |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + // a priori true |
|
| 1125 | + // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1126 | + // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1127 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1128 | + if (count($_contexte)) { |
|
| 1129 | + $key = key($_contexte); |
|
| 1130 | + if (is_numeric($key)) { |
|
| 1131 | + array_shift($_contexte); |
|
| 1132 | + $__modele = interprete_argument_balise(1, $p); |
|
| 1133 | + } |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + if (count($_contexte)) { |
|
| 1137 | + $code_contexte = implode(',', $_contexte); |
|
| 1138 | + } else { |
|
| 1139 | + $code_contexte = ''; |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 1143 | + $pas = $p->boucles[$b]->total_parties; |
|
| 1144 | + $f_pagination = chercher_filtre('pagination'); |
|
| 1145 | + $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1146 | + $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1147 | + : ("'debut" . substr($type, 1)); |
|
| 1148 | + |
|
| 1149 | + $p->code = sprintf( |
|
| 1150 | + CODE_PAGINATION, |
|
| 1151 | + $f_pagination, |
|
| 1152 | + $b, |
|
| 1153 | + $type, |
|
| 1154 | + $modif, |
|
| 1155 | + $pas, |
|
| 1156 | + $liste, |
|
| 1157 | + ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1158 | + _q($connect), |
|
| 1159 | + $code_contexte |
|
| 1160 | + ); |
|
| 1161 | + |
|
| 1162 | + $p->boucles[$b]->numrows = true; |
|
| 1163 | + $p->interdire_scripts = false; |
|
| 1164 | + |
|
| 1165 | + return $p; |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | |
@@ -1189,11 +1189,11 @@ discard block |
||
| 1189 | 1189 | * Pile complétée par le code à générer |
| 1190 | 1190 | **/ |
| 1191 | 1191 | function balise_ANCRE_PAGINATION_dist($p) { |
| 1192 | - if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1193 | - return $f($p, $liste = 'false'); |
|
| 1194 | - } else { |
|
| 1195 | - return null; |
|
| 1196 | - } // ou une erreur ? |
|
| 1192 | + if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1193 | + return $f($p, $liste = 'false'); |
|
| 1194 | + } else { |
|
| 1195 | + return null; |
|
| 1196 | + } // ou une erreur ? |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | |
@@ -1214,17 +1214,17 @@ discard block |
||
| 1214 | 1214 | * Pile complétée par le code à générer |
| 1215 | 1215 | **/ |
| 1216 | 1216 | function balise_GRAND_TOTAL_dist($p) { |
| 1217 | - $b = index_boucle_mere($p); |
|
| 1218 | - if ($b === '') { |
|
| 1219 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1220 | - erreur_squelette($msg, $p); |
|
| 1221 | - } else { |
|
| 1222 | - $p->code = "(\$Numrows['$b']['grand_total'] ?? \$Numrows['$b']['total'] ?? 0)"; |
|
| 1223 | - $p->boucles[$b]->numrows = true; |
|
| 1224 | - $p->interdire_scripts = false; |
|
| 1225 | - } |
|
| 1217 | + $b = index_boucle_mere($p); |
|
| 1218 | + if ($b === '') { |
|
| 1219 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1220 | + erreur_squelette($msg, $p); |
|
| 1221 | + } else { |
|
| 1222 | + $p->code = "(\$Numrows['$b']['grand_total'] ?? \$Numrows['$b']['total'] ?? 0)"; |
|
| 1223 | + $p->boucles[$b]->numrows = true; |
|
| 1224 | + $p->interdire_scripts = false; |
|
| 1225 | + } |
|
| 1226 | 1226 | |
| 1227 | - return $p; |
|
| 1227 | + return $p; |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | |
@@ -1252,10 +1252,10 @@ discard block |
||
| 1252 | 1252 | * Pile complétée par le code à générer |
| 1253 | 1253 | **/ |
| 1254 | 1254 | function balise_SELF_dist($p) { |
| 1255 | - $p->code = 'self()'; |
|
| 1256 | - $p->interdire_scripts = false; |
|
| 1255 | + $p->code = 'self()'; |
|
| 1256 | + $p->interdire_scripts = false; |
|
| 1257 | 1257 | |
| 1258 | - return $p; |
|
| 1258 | + return $p; |
|
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | |
@@ -1282,17 +1282,17 @@ discard block |
||
| 1282 | 1282 | * Pile complétée par le code à générer |
| 1283 | 1283 | **/ |
| 1284 | 1284 | function balise_CHEMIN_dist($p) { |
| 1285 | - $arg = interprete_argument_balise(1, $p); |
|
| 1286 | - if (!$arg) { |
|
| 1287 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1288 | - erreur_squelette($msg, $p); |
|
| 1289 | - } else { |
|
| 1290 | - $p->code = 'find_in_path(' . $arg . ')'; |
|
| 1291 | - } |
|
| 1285 | + $arg = interprete_argument_balise(1, $p); |
|
| 1286 | + if (!$arg) { |
|
| 1287 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1288 | + erreur_squelette($msg, $p); |
|
| 1289 | + } else { |
|
| 1290 | + $p->code = 'find_in_path(' . $arg . ')'; |
|
| 1291 | + } |
|
| 1292 | 1292 | |
| 1293 | - $p->interdire_scripts = false; |
|
| 1293 | + $p->interdire_scripts = false; |
|
| 1294 | 1294 | |
| 1295 | - return $p; |
|
| 1295 | + return $p; |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | /** |
@@ -1317,16 +1317,16 @@ discard block |
||
| 1317 | 1317 | * Pile complétée par le code à générer |
| 1318 | 1318 | **/ |
| 1319 | 1319 | function balise_CHEMIN_IMAGE_dist($p) { |
| 1320 | - $arg = interprete_argument_balise(1, $p); |
|
| 1321 | - if (!$arg) { |
|
| 1322 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1323 | - erreur_squelette($msg, $p); |
|
| 1324 | - } else { |
|
| 1325 | - $p->code = 'chemin_image(' . $arg . ')'; |
|
| 1326 | - } |
|
| 1320 | + $arg = interprete_argument_balise(1, $p); |
|
| 1321 | + if (!$arg) { |
|
| 1322 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1323 | + erreur_squelette($msg, $p); |
|
| 1324 | + } else { |
|
| 1325 | + $p->code = 'chemin_image(' . $arg . ')'; |
|
| 1326 | + } |
|
| 1327 | 1327 | |
| 1328 | - $p->interdire_scripts = false; |
|
| 1329 | - return $p; |
|
| 1328 | + $p->interdire_scripts = false; |
|
| 1329 | + return $p; |
|
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | |
@@ -1364,36 +1364,36 @@ discard block |
||
| 1364 | 1364 | **/ |
| 1365 | 1365 | function balise_ENV_dist($p, $src = null) { |
| 1366 | 1366 | |
| 1367 | - // cle du tableau desiree |
|
| 1368 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1369 | - // valeur par defaut |
|
| 1370 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1367 | + // cle du tableau desiree |
|
| 1368 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1369 | + // valeur par defaut |
|
| 1370 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1371 | 1371 | |
| 1372 | - // $src est un tableau de donnees sources eventuellement transmis |
|
| 1373 | - // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1372 | + // $src est un tableau de donnees sources eventuellement transmis |
|
| 1373 | + // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1374 | 1374 | |
| 1375 | - if (!$_nom) { |
|
| 1376 | - // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1377 | - // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1378 | - if ($src) { |
|
| 1379 | - $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1380 | - } else { |
|
| 1381 | - $p->code = 'serialize($Pile[0]??[])'; |
|
| 1382 | - } |
|
| 1383 | - } else { |
|
| 1384 | - if (!$src) { |
|
| 1385 | - $src = '$Pile[0]??[]'; |
|
| 1386 | - } |
|
| 1387 | - if ($_sinon) { |
|
| 1388 | - $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1389 | - } else { |
|
| 1390 | - $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1391 | - } |
|
| 1392 | - } |
|
| 1375 | + if (!$_nom) { |
|
| 1376 | + // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1377 | + // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1378 | + if ($src) { |
|
| 1379 | + $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1380 | + } else { |
|
| 1381 | + $p->code = 'serialize($Pile[0]??[])'; |
|
| 1382 | + } |
|
| 1383 | + } else { |
|
| 1384 | + if (!$src) { |
|
| 1385 | + $src = '$Pile[0]??[]'; |
|
| 1386 | + } |
|
| 1387 | + if ($_sinon) { |
|
| 1388 | + $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1389 | + } else { |
|
| 1390 | + $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1391 | + } |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | - #$p->interdire_scripts = true; |
|
| 1394 | + #$p->interdire_scripts = true; |
|
| 1395 | 1395 | |
| 1396 | - return $p; |
|
| 1396 | + return $p; |
|
| 1397 | 1397 | } |
| 1398 | 1398 | |
| 1399 | 1399 | /** |
@@ -1423,16 +1423,16 @@ discard block |
||
| 1423 | 1423 | * Pile completée du code PHP d'exécution de la balise |
| 1424 | 1424 | */ |
| 1425 | 1425 | function balise_CONFIG_dist($p) { |
| 1426 | - if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1427 | - $arg = "''"; |
|
| 1428 | - } |
|
| 1429 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1430 | - $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1426 | + if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1427 | + $arg = "''"; |
|
| 1428 | + } |
|
| 1429 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1430 | + $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1431 | 1431 | |
| 1432 | - $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1433 | - ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1432 | + $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1433 | + ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1434 | 1434 | |
| 1435 | - return $p; |
|
| 1435 | + return $p; |
|
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | |
@@ -1455,10 +1455,10 @@ discard block |
||
| 1455 | 1455 | * Pile completée du code PHP d'exécution de la balise |
| 1456 | 1456 | */ |
| 1457 | 1457 | function balise_CONNECT_dist($p) { |
| 1458 | - $p->code = '($connect ? $connect : NULL)'; |
|
| 1459 | - $p->interdire_scripts = false; |
|
| 1458 | + $p->code = '($connect ? $connect : NULL)'; |
|
| 1459 | + $p->interdire_scripts = false; |
|
| 1460 | 1460 | |
| 1461 | - return $p; |
|
| 1461 | + return $p; |
|
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | 1464 | |
@@ -1486,15 +1486,15 @@ discard block |
||
| 1486 | 1486 | * Pile completée du code PHP d'exécution de la balise |
| 1487 | 1487 | **/ |
| 1488 | 1488 | function balise_SESSION_dist($p) { |
| 1489 | - $p->descr['session'] = true; |
|
| 1489 | + $p->descr['session'] = true; |
|
| 1490 | 1490 | |
| 1491 | - $f = function_exists('balise_ENV') |
|
| 1492 | - ? 'balise_ENV' |
|
| 1493 | - : 'balise_ENV_dist'; |
|
| 1491 | + $f = function_exists('balise_ENV') |
|
| 1492 | + ? 'balise_ENV' |
|
| 1493 | + : 'balise_ENV_dist'; |
|
| 1494 | 1494 | |
| 1495 | - $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1495 | + $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1496 | 1496 | |
| 1497 | - return $p; |
|
| 1497 | + return $p; |
|
| 1498 | 1498 | } |
| 1499 | 1499 | |
| 1500 | 1500 | |
@@ -1517,18 +1517,18 @@ discard block |
||
| 1517 | 1517 | * Pile completée du code PHP d'exécution de la balise |
| 1518 | 1518 | **/ |
| 1519 | 1519 | function balise_SESSION_SET_dist($p) { |
| 1520 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1521 | - $_val = interprete_argument_balise(2, $p); |
|
| 1522 | - if (!$_nom or !$_val) { |
|
| 1523 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1524 | - erreur_squelette($err_b_s_a, $p); |
|
| 1525 | - } else { |
|
| 1526 | - $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1527 | - } |
|
| 1520 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1521 | + $_val = interprete_argument_balise(2, $p); |
|
| 1522 | + if (!$_nom or !$_val) { |
|
| 1523 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1524 | + erreur_squelette($err_b_s_a, $p); |
|
| 1525 | + } else { |
|
| 1526 | + $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1527 | + } |
|
| 1528 | 1528 | |
| 1529 | - $p->interdire_scripts = false; |
|
| 1529 | + $p->interdire_scripts = false; |
|
| 1530 | 1530 | |
| 1531 | - return $p; |
|
| 1531 | + return $p; |
|
| 1532 | 1532 | } |
| 1533 | 1533 | |
| 1534 | 1534 | |
@@ -1559,30 +1559,30 @@ discard block |
||
| 1559 | 1559 | * Pile completée du code PHP d'exécution de la balise |
| 1560 | 1560 | **/ |
| 1561 | 1561 | function balise_EVAL_dist($p) { |
| 1562 | - $php = interprete_argument_balise(1, $p); |
|
| 1563 | - if ($php) { |
|
| 1564 | - # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1565 | - # attention au commentaire "// x signes" qui precede |
|
| 1566 | - if ( |
|
| 1567 | - preg_match( |
|
| 1568 | - ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1569 | - $php, |
|
| 1570 | - $r |
|
| 1571 | - ) |
|
| 1572 | - ) { |
|
| 1573 | - $p->code = /* $r[1]. */ |
|
| 1574 | - '(' . $r[2] . ')'; |
|
| 1575 | - } else { |
|
| 1576 | - $p->code = "eval('return '.$php.';')"; |
|
| 1577 | - } |
|
| 1578 | - } else { |
|
| 1579 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1580 | - erreur_squelette($msg, $p); |
|
| 1581 | - } |
|
| 1582 | - |
|
| 1583 | - #$p->interdire_scripts = true; |
|
| 1584 | - |
|
| 1585 | - return $p; |
|
| 1562 | + $php = interprete_argument_balise(1, $p); |
|
| 1563 | + if ($php) { |
|
| 1564 | + # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1565 | + # attention au commentaire "// x signes" qui precede |
|
| 1566 | + if ( |
|
| 1567 | + preg_match( |
|
| 1568 | + ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1569 | + $php, |
|
| 1570 | + $r |
|
| 1571 | + ) |
|
| 1572 | + ) { |
|
| 1573 | + $p->code = /* $r[1]. */ |
|
| 1574 | + '(' . $r[2] . ')'; |
|
| 1575 | + } else { |
|
| 1576 | + $p->code = "eval('return '.$php.';')"; |
|
| 1577 | + } |
|
| 1578 | + } else { |
|
| 1579 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1580 | + erreur_squelette($msg, $p); |
|
| 1581 | + } |
|
| 1582 | + |
|
| 1583 | + #$p->interdire_scripts = true; |
|
| 1584 | + |
|
| 1585 | + return $p; |
|
| 1586 | 1586 | } |
| 1587 | 1587 | |
| 1588 | 1588 | |
@@ -1612,19 +1612,19 @@ discard block |
||
| 1612 | 1612 | **/ |
| 1613 | 1613 | function balise_CHAMP_SQL_dist($p) { |
| 1614 | 1614 | |
| 1615 | - if ( |
|
| 1616 | - $p->param |
|
| 1617 | - and isset($p->param[0][1][0]) |
|
| 1618 | - and $champ = ($p->param[0][1][0]->texte) |
|
| 1619 | - ) { |
|
| 1620 | - $p->code = champ_sql($champ, $p); |
|
| 1621 | - } else { |
|
| 1622 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1623 | - erreur_squelette($err_b_s_a, $p); |
|
| 1624 | - } |
|
| 1615 | + if ( |
|
| 1616 | + $p->param |
|
| 1617 | + and isset($p->param[0][1][0]) |
|
| 1618 | + and $champ = ($p->param[0][1][0]->texte) |
|
| 1619 | + ) { |
|
| 1620 | + $p->code = champ_sql($champ, $p); |
|
| 1621 | + } else { |
|
| 1622 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1623 | + erreur_squelette($err_b_s_a, $p); |
|
| 1624 | + } |
|
| 1625 | 1625 | |
| 1626 | - #$p->interdire_scripts = true; |
|
| 1627 | - return $p; |
|
| 1626 | + #$p->interdire_scripts = true; |
|
| 1627 | + return $p; |
|
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | 1630 | /** |
@@ -1650,13 +1650,13 @@ discard block |
||
| 1650 | 1650 | * Pile complétée par le code à générer |
| 1651 | 1651 | **/ |
| 1652 | 1652 | function balise_VAL_dist($p) { |
| 1653 | - $p->code = interprete_argument_balise(1, $p); |
|
| 1654 | - if ($p->code === null || !strlen($p->code)) { |
|
| 1655 | - $p->code = "''"; |
|
| 1656 | - } |
|
| 1657 | - $p->interdire_scripts = false; |
|
| 1653 | + $p->code = interprete_argument_balise(1, $p); |
|
| 1654 | + if ($p->code === null || !strlen($p->code)) { |
|
| 1655 | + $p->code = "''"; |
|
| 1656 | + } |
|
| 1657 | + $p->interdire_scripts = false; |
|
| 1658 | 1658 | |
| 1659 | - return $p; |
|
| 1659 | + return $p; |
|
| 1660 | 1660 | } |
| 1661 | 1661 | |
| 1662 | 1662 | /** |
@@ -1685,10 +1685,10 @@ discard block |
||
| 1685 | 1685 | * Pile complétée par le code à générer |
| 1686 | 1686 | **/ |
| 1687 | 1687 | function balise_REM_dist($p) { |
| 1688 | - $p->code = "''"; |
|
| 1689 | - $p->interdire_scripts = false; |
|
| 1688 | + $p->code = "''"; |
|
| 1689 | + $p->interdire_scripts = false; |
|
| 1690 | 1690 | |
| 1691 | - return $p; |
|
| 1691 | + return $p; |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | /** |
@@ -1698,10 +1698,10 @@ discard block |
||
| 1698 | 1698 | * @return mixed |
| 1699 | 1699 | */ |
| 1700 | 1700 | function balise_NULL_dist($p) { |
| 1701 | - $p->code = 'null'; |
|
| 1702 | - $p->interdire_scripts = false; |
|
| 1701 | + $p->code = 'null'; |
|
| 1702 | + $p->interdire_scripts = false; |
|
| 1703 | 1703 | |
| 1704 | - return $p; |
|
| 1704 | + return $p; |
|
| 1705 | 1705 | } |
| 1706 | 1706 | |
| 1707 | 1707 | |
@@ -1725,18 +1725,18 @@ discard block |
||
| 1725 | 1725 | **/ |
| 1726 | 1726 | function balise_HTTP_HEADER_dist($p) { |
| 1727 | 1727 | |
| 1728 | - $header = interprete_argument_balise(1, $p); |
|
| 1729 | - if (!$header) { |
|
| 1730 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1731 | - erreur_squelette($err_b_s_a, $p); |
|
| 1732 | - } else { |
|
| 1733 | - $p->code = "'<'.'?php header(' . _q(" |
|
| 1734 | - . $header |
|
| 1735 | - . ") . '); ?'.'>'"; |
|
| 1736 | - } |
|
| 1737 | - $p->interdire_scripts = false; |
|
| 1728 | + $header = interprete_argument_balise(1, $p); |
|
| 1729 | + if (!$header) { |
|
| 1730 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1731 | + erreur_squelette($err_b_s_a, $p); |
|
| 1732 | + } else { |
|
| 1733 | + $p->code = "'<'.'?php header(' . _q(" |
|
| 1734 | + . $header |
|
| 1735 | + . ") . '); ?'.'>'"; |
|
| 1736 | + } |
|
| 1737 | + $p->interdire_scripts = false; |
|
| 1738 | 1738 | |
| 1739 | - return $p; |
|
| 1739 | + return $p; |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | |
@@ -1761,20 +1761,20 @@ discard block |
||
| 1761 | 1761 | * Pile complétée par le code à générer |
| 1762 | 1762 | **/ |
| 1763 | 1763 | function balise_FILTRE_dist($p) { |
| 1764 | - if ($p->param) { |
|
| 1765 | - $args = []; |
|
| 1766 | - foreach ($p->param as $i => $ignore) { |
|
| 1767 | - $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1768 | - } |
|
| 1769 | - $p->code = "'<' . '" |
|
| 1770 | - . '?php header("X-Spip-Filtre: \'.' |
|
| 1771 | - . join('.\'|\'.', $args) |
|
| 1772 | - . " . '\"); ?'.'>'"; |
|
| 1764 | + if ($p->param) { |
|
| 1765 | + $args = []; |
|
| 1766 | + foreach ($p->param as $i => $ignore) { |
|
| 1767 | + $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1768 | + } |
|
| 1769 | + $p->code = "'<' . '" |
|
| 1770 | + . '?php header("X-Spip-Filtre: \'.' |
|
| 1771 | + . join('.\'|\'.', $args) |
|
| 1772 | + . " . '\"); ?'.'>'"; |
|
| 1773 | 1773 | |
| 1774 | - $p->interdire_scripts = false; |
|
| 1774 | + $p->interdire_scripts = false; |
|
| 1775 | 1775 | |
| 1776 | - return $p; |
|
| 1777 | - } |
|
| 1776 | + return $p; |
|
| 1777 | + } |
|
| 1778 | 1778 | } |
| 1779 | 1779 | |
| 1780 | 1780 | |
@@ -1810,55 +1810,55 @@ discard block |
||
| 1810 | 1810 | **/ |
| 1811 | 1811 | function balise_CACHE_dist($p) { |
| 1812 | 1812 | |
| 1813 | - if ($p->param) { |
|
| 1814 | - $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1815 | - |
|
| 1816 | - // noter la duree du cache dans un entete proprietaire |
|
| 1817 | - |
|
| 1818 | - $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1819 | - . $duree |
|
| 1820 | - . '"); ?' . "'.'>'"; |
|
| 1821 | - |
|
| 1822 | - // Remplir le header Cache-Control |
|
| 1823 | - // cas #CACHE{0} |
|
| 1824 | - if ($duree == 0) { |
|
| 1825 | - $code .= ".'<'.'" |
|
| 1826 | - . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1827 | - . "'.'><'.'" |
|
| 1828 | - . '?php header("Pragma: no-cache"); ?' |
|
| 1829 | - . "'.'>'"; |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - // recuperer les parametres suivants |
|
| 1833 | - $i = 1; |
|
| 1834 | - while (isset($p->param[0][++$i])) { |
|
| 1835 | - $pa = ($p->param[0][$i][0]->texte); |
|
| 1836 | - |
|
| 1837 | - if ( |
|
| 1838 | - $pa == 'cache-client' |
|
| 1839 | - and $duree > 0 |
|
| 1840 | - ) { |
|
| 1841 | - $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1842 | - . $duree |
|
| 1843 | - . '"); ?' . "'.'>'"; |
|
| 1844 | - // il semble logique, si on cache-client, de ne pas invalider |
|
| 1845 | - $pa = 'statique'; |
|
| 1846 | - } |
|
| 1847 | - |
|
| 1848 | - if ( |
|
| 1849 | - $pa == 'statique' |
|
| 1850 | - and $duree > 0 |
|
| 1851 | - ) { |
|
| 1852 | - $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1853 | - } |
|
| 1854 | - } |
|
| 1855 | - } else { |
|
| 1856 | - $code = "''"; |
|
| 1857 | - } |
|
| 1858 | - $p->code = $code; |
|
| 1859 | - $p->interdire_scripts = false; |
|
| 1860 | - |
|
| 1861 | - return $p; |
|
| 1813 | + if ($p->param) { |
|
| 1814 | + $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1815 | + |
|
| 1816 | + // noter la duree du cache dans un entete proprietaire |
|
| 1817 | + |
|
| 1818 | + $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1819 | + . $duree |
|
| 1820 | + . '"); ?' . "'.'>'"; |
|
| 1821 | + |
|
| 1822 | + // Remplir le header Cache-Control |
|
| 1823 | + // cas #CACHE{0} |
|
| 1824 | + if ($duree == 0) { |
|
| 1825 | + $code .= ".'<'.'" |
|
| 1826 | + . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1827 | + . "'.'><'.'" |
|
| 1828 | + . '?php header("Pragma: no-cache"); ?' |
|
| 1829 | + . "'.'>'"; |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + // recuperer les parametres suivants |
|
| 1833 | + $i = 1; |
|
| 1834 | + while (isset($p->param[0][++$i])) { |
|
| 1835 | + $pa = ($p->param[0][$i][0]->texte); |
|
| 1836 | + |
|
| 1837 | + if ( |
|
| 1838 | + $pa == 'cache-client' |
|
| 1839 | + and $duree > 0 |
|
| 1840 | + ) { |
|
| 1841 | + $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1842 | + . $duree |
|
| 1843 | + . '"); ?' . "'.'>'"; |
|
| 1844 | + // il semble logique, si on cache-client, de ne pas invalider |
|
| 1845 | + $pa = 'statique'; |
|
| 1846 | + } |
|
| 1847 | + |
|
| 1848 | + if ( |
|
| 1849 | + $pa == 'statique' |
|
| 1850 | + and $duree > 0 |
|
| 1851 | + ) { |
|
| 1852 | + $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1853 | + } |
|
| 1854 | + } |
|
| 1855 | + } else { |
|
| 1856 | + $code = "''"; |
|
| 1857 | + } |
|
| 1858 | + $p->code = $code; |
|
| 1859 | + $p->interdire_scripts = false; |
|
| 1860 | + |
|
| 1861 | + return $p; |
|
| 1862 | 1862 | } |
| 1863 | 1863 | |
| 1864 | 1864 | |
@@ -1890,13 +1890,13 @@ discard block |
||
| 1890 | 1890 | * Pile complétée par le code à générer |
| 1891 | 1891 | */ |
| 1892 | 1892 | function balise_INSERT_HEAD_dist($p) { |
| 1893 | - $p->code = "'<'.'" |
|
| 1894 | - . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1895 | - . "'.'>'"; |
|
| 1896 | - $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1897 | - $p->interdire_scripts = false; |
|
| 1893 | + $p->code = "'<'.'" |
|
| 1894 | + . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1895 | + . "'.'>'"; |
|
| 1896 | + $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1897 | + $p->interdire_scripts = false; |
|
| 1898 | 1898 | |
| 1899 | - return $p; |
|
| 1899 | + return $p; |
|
| 1900 | 1900 | } |
| 1901 | 1901 | |
| 1902 | 1902 | /** |
@@ -1914,10 +1914,10 @@ discard block |
||
| 1914 | 1914 | * Pile complétée par le code à générer |
| 1915 | 1915 | */ |
| 1916 | 1916 | function balise_INSERT_HEAD_CSS_dist($p) { |
| 1917 | - $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1918 | - $p->interdire_scripts = false; |
|
| 1917 | + $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1918 | + $p->interdire_scripts = false; |
|
| 1919 | 1919 | |
| 1920 | - return $p; |
|
| 1920 | + return $p; |
|
| 1921 | 1921 | } |
| 1922 | 1922 | |
| 1923 | 1923 | /** |
@@ -1932,11 +1932,11 @@ discard block |
||
| 1932 | 1932 | * Pile complétée par le code à générer |
| 1933 | 1933 | **/ |
| 1934 | 1934 | function balise_INCLUDE_dist($p) { |
| 1935 | - if (function_exists('balise_INCLURE')) { |
|
| 1936 | - return balise_INCLURE($p); |
|
| 1937 | - } else { |
|
| 1938 | - return balise_INCLURE_dist($p); |
|
| 1939 | - } |
|
| 1935 | + if (function_exists('balise_INCLURE')) { |
|
| 1936 | + return balise_INCLURE($p); |
|
| 1937 | + } else { |
|
| 1938 | + return balise_INCLURE_dist($p); |
|
| 1939 | + } |
|
| 1940 | 1940 | } |
| 1941 | 1941 | |
| 1942 | 1942 | /** |
@@ -1970,66 +1970,66 @@ discard block |
||
| 1970 | 1970 | * Pile complétée par le code à générer |
| 1971 | 1971 | **/ |
| 1972 | 1972 | function balise_INCLURE_dist($p) { |
| 1973 | - $id_boucle = $p->id_boucle; |
|
| 1974 | - // la lang n'est pas passe de facon automatique par argumenter |
|
| 1975 | - // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1976 | - // en option |
|
| 1977 | - |
|
| 1978 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1979 | - |
|
| 1980 | - // erreur de syntaxe = fond absent |
|
| 1981 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1982 | - if (!$_contexte) { |
|
| 1983 | - $contexte = []; |
|
| 1984 | - } |
|
| 1985 | - |
|
| 1986 | - if (isset($_contexte['fond'])) { |
|
| 1987 | - $f = $_contexte['fond']; |
|
| 1988 | - // toujours vrai : |
|
| 1989 | - if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1990 | - $f = $r[1]; |
|
| 1991 | - unset($_contexte['fond']); |
|
| 1992 | - } else { |
|
| 1993 | - spip_log('compilation de #INCLURE a revoir'); |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - // #INCLURE{doublons} |
|
| 1997 | - if (isset($_contexte['doublons'])) { |
|
| 1998 | - $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1999 | - } |
|
| 2000 | - |
|
| 2001 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2002 | - $flag_env = false; |
|
| 2003 | - if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2004 | - $flag_env = true; |
|
| 2005 | - unset($_contexte['env']); |
|
| 2006 | - } |
|
| 2007 | - |
|
| 2008 | - $_options = []; |
|
| 2009 | - if (isset($_contexte['ajax'])) { |
|
| 2010 | - $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2011 | - unset($_contexte['ajax']); |
|
| 2012 | - } |
|
| 2013 | - if ($p->etoile) { |
|
| 2014 | - $_options[] = "'etoile'=>true"; |
|
| 2015 | - } |
|
| 2016 | - $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2017 | - |
|
| 2018 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2019 | - if ($flag_env) { |
|
| 2020 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect') ?? ''"); |
|
| 2024 | - } elseif (!isset($_contexte[1])) { |
|
| 2025 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2026 | - erreur_squelette($msg, $p); |
|
| 2027 | - } else { |
|
| 2028 | - $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2029 | - } |
|
| 2030 | - |
|
| 2031 | - $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2032 | - return $p; |
|
| 1973 | + $id_boucle = $p->id_boucle; |
|
| 1974 | + // la lang n'est pas passe de facon automatique par argumenter |
|
| 1975 | + // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1976 | + // en option |
|
| 1977 | + |
|
| 1978 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1979 | + |
|
| 1980 | + // erreur de syntaxe = fond absent |
|
| 1981 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1982 | + if (!$_contexte) { |
|
| 1983 | + $contexte = []; |
|
| 1984 | + } |
|
| 1985 | + |
|
| 1986 | + if (isset($_contexte['fond'])) { |
|
| 1987 | + $f = $_contexte['fond']; |
|
| 1988 | + // toujours vrai : |
|
| 1989 | + if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1990 | + $f = $r[1]; |
|
| 1991 | + unset($_contexte['fond']); |
|
| 1992 | + } else { |
|
| 1993 | + spip_log('compilation de #INCLURE a revoir'); |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + // #INCLURE{doublons} |
|
| 1997 | + if (isset($_contexte['doublons'])) { |
|
| 1998 | + $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1999 | + } |
|
| 2000 | + |
|
| 2001 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2002 | + $flag_env = false; |
|
| 2003 | + if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2004 | + $flag_env = true; |
|
| 2005 | + unset($_contexte['env']); |
|
| 2006 | + } |
|
| 2007 | + |
|
| 2008 | + $_options = []; |
|
| 2009 | + if (isset($_contexte['ajax'])) { |
|
| 2010 | + $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2011 | + unset($_contexte['ajax']); |
|
| 2012 | + } |
|
| 2013 | + if ($p->etoile) { |
|
| 2014 | + $_options[] = "'etoile'=>true"; |
|
| 2015 | + } |
|
| 2016 | + $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2017 | + |
|
| 2018 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2019 | + if ($flag_env) { |
|
| 2020 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect') ?? ''"); |
|
| 2024 | + } elseif (!isset($_contexte[1])) { |
|
| 2025 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2026 | + erreur_squelette($msg, $p); |
|
| 2027 | + } else { |
|
| 2028 | + $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2029 | + } |
|
| 2030 | + |
|
| 2031 | + $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2032 | + return $p; |
|
| 2033 | 2033 | } |
| 2034 | 2034 | |
| 2035 | 2035 | |
@@ -2057,69 +2057,69 @@ discard block |
||
| 2057 | 2057 | **/ |
| 2058 | 2058 | function balise_MODELE_dist($p) { |
| 2059 | 2059 | |
| 2060 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2061 | - |
|
| 2062 | - // erreur de syntaxe = fond absent |
|
| 2063 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2064 | - if (!$_contexte) { |
|
| 2065 | - $_contexte = []; |
|
| 2066 | - } |
|
| 2067 | - |
|
| 2068 | - if (!isset($_contexte[1])) { |
|
| 2069 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2070 | - erreur_squelette($msg, $p); |
|
| 2071 | - } else { |
|
| 2072 | - $nom = $_contexte[1]; |
|
| 2073 | - unset($_contexte[1]); |
|
| 2074 | - |
|
| 2075 | - if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2076 | - $nom = "'modeles/" . substr($nom, 1); |
|
| 2077 | - } else { |
|
| 2078 | - $nom = "'modeles/' . $nom"; |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - $flag_env = false; |
|
| 2082 | - if (isset($_contexte['env'])) { |
|
| 2083 | - $flag_env = true; |
|
| 2084 | - unset($_contexte['env']); |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2088 | - // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2089 | - if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2090 | - $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2091 | - if (!strpos($primary, ',')) { |
|
| 2092 | - $id = champ_sql($primary, $p); |
|
| 2093 | - $_contexte[] = "'$primary'=>" . $id; |
|
| 2094 | - $_contexte[] = "'id'=>" . $id; |
|
| 2095 | - } |
|
| 2096 | - } |
|
| 2097 | - $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2098 | - $connect = ''; |
|
| 2099 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2100 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - $_options = memoriser_contexte_compil($p); |
|
| 2104 | - $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2105 | - if (isset($_contexte['ajax'])) { |
|
| 2106 | - $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2107 | - unset($_contexte['ajax']); |
|
| 2108 | - } |
|
| 2109 | - |
|
| 2110 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2111 | - if ($flag_env) { |
|
| 2112 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2113 | - } |
|
| 2114 | - |
|
| 2115 | - $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2116 | - |
|
| 2117 | - $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2118 | - |
|
| 2119 | - $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - return $p; |
|
| 2060 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2061 | + |
|
| 2062 | + // erreur de syntaxe = fond absent |
|
| 2063 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2064 | + if (!$_contexte) { |
|
| 2065 | + $_contexte = []; |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + if (!isset($_contexte[1])) { |
|
| 2069 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2070 | + erreur_squelette($msg, $p); |
|
| 2071 | + } else { |
|
| 2072 | + $nom = $_contexte[1]; |
|
| 2073 | + unset($_contexte[1]); |
|
| 2074 | + |
|
| 2075 | + if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2076 | + $nom = "'modeles/" . substr($nom, 1); |
|
| 2077 | + } else { |
|
| 2078 | + $nom = "'modeles/' . $nom"; |
|
| 2079 | + } |
|
| 2080 | + |
|
| 2081 | + $flag_env = false; |
|
| 2082 | + if (isset($_contexte['env'])) { |
|
| 2083 | + $flag_env = true; |
|
| 2084 | + unset($_contexte['env']); |
|
| 2085 | + } |
|
| 2086 | + |
|
| 2087 | + // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2088 | + // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2089 | + if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2090 | + $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2091 | + if (!strpos($primary, ',')) { |
|
| 2092 | + $id = champ_sql($primary, $p); |
|
| 2093 | + $_contexte[] = "'$primary'=>" . $id; |
|
| 2094 | + $_contexte[] = "'id'=>" . $id; |
|
| 2095 | + } |
|
| 2096 | + } |
|
| 2097 | + $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2098 | + $connect = ''; |
|
| 2099 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2100 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + $_options = memoriser_contexte_compil($p); |
|
| 2104 | + $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2105 | + if (isset($_contexte['ajax'])) { |
|
| 2106 | + $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2107 | + unset($_contexte['ajax']); |
|
| 2108 | + } |
|
| 2109 | + |
|
| 2110 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2111 | + if ($flag_env) { |
|
| 2112 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2113 | + } |
|
| 2114 | + |
|
| 2115 | + $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2116 | + |
|
| 2117 | + $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2118 | + |
|
| 2119 | + $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + return $p; |
|
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | 2125 | |
@@ -2143,21 +2143,21 @@ discard block |
||
| 2143 | 2143 | * Pile complétée par le code à générer |
| 2144 | 2144 | **/ |
| 2145 | 2145 | function balise_SET_dist($p) { |
| 2146 | - $_nom = interprete_argument_balise(1, $p); |
|
| 2147 | - $_val = interprete_argument_balise(2, $p); |
|
| 2146 | + $_nom = interprete_argument_balise(1, $p); |
|
| 2147 | + $_val = interprete_argument_balise(2, $p); |
|
| 2148 | 2148 | |
| 2149 | - if (!$_nom or !$_val) { |
|
| 2150 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2151 | - erreur_squelette($err_b_s_a, $p); |
|
| 2152 | - } |
|
| 2153 | - // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2154 | - // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2155 | - else { |
|
| 2156 | - $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2157 | - } |
|
| 2149 | + if (!$_nom or !$_val) { |
|
| 2150 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2151 | + erreur_squelette($err_b_s_a, $p); |
|
| 2152 | + } |
|
| 2153 | + // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2154 | + // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2155 | + else { |
|
| 2156 | + $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2157 | + } |
|
| 2158 | 2158 | |
| 2159 | - $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2160 | - return $p; |
|
| 2159 | + $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2160 | + return $p; |
|
| 2161 | 2161 | } |
| 2162 | 2162 | |
| 2163 | 2163 | |
@@ -2187,12 +2187,12 @@ discard block |
||
| 2187 | 2187 | * Pile complétée par le code à générer |
| 2188 | 2188 | **/ |
| 2189 | 2189 | function balise_GET_dist($p) { |
| 2190 | - $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2191 | - if (function_exists('balise_ENV')) { |
|
| 2192 | - return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2193 | - } else { |
|
| 2194 | - return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2195 | - } |
|
| 2190 | + $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2191 | + if (function_exists('balise_ENV')) { |
|
| 2192 | + return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2193 | + } else { |
|
| 2194 | + return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2195 | + } |
|
| 2196 | 2196 | } |
| 2197 | 2197 | |
| 2198 | 2198 | |
@@ -2215,22 +2215,22 @@ discard block |
||
| 2215 | 2215 | * Pile complétée par le code à générer |
| 2216 | 2216 | **/ |
| 2217 | 2217 | function balise_DOUBLONS_dist($p) { |
| 2218 | - if ($type = interprete_argument_balise(1, $p)) { |
|
| 2219 | - if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2220 | - $type .= '.' . $famille; |
|
| 2221 | - } |
|
| 2222 | - $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2223 | - if (!$p->etoile) { |
|
| 2224 | - $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2225 | - . $p->code . ')))'; |
|
| 2226 | - } |
|
| 2227 | - } else { |
|
| 2228 | - $p->code = '$doublons'; |
|
| 2229 | - } |
|
| 2218 | + if ($type = interprete_argument_balise(1, $p)) { |
|
| 2219 | + if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2220 | + $type .= '.' . $famille; |
|
| 2221 | + } |
|
| 2222 | + $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2223 | + if (!$p->etoile) { |
|
| 2224 | + $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2225 | + . $p->code . ')))'; |
|
| 2226 | + } |
|
| 2227 | + } else { |
|
| 2228 | + $p->code = '$doublons'; |
|
| 2229 | + } |
|
| 2230 | 2230 | |
| 2231 | - $p->interdire_scripts = false; |
|
| 2231 | + $p->interdire_scripts = false; |
|
| 2232 | 2232 | |
| 2233 | - return $p; |
|
| 2233 | + return $p; |
|
| 2234 | 2234 | } |
| 2235 | 2235 | |
| 2236 | 2236 | |
@@ -2253,18 +2253,18 @@ discard block |
||
| 2253 | 2253 | * Pile complétée par le code à générer |
| 2254 | 2254 | **/ |
| 2255 | 2255 | function balise_PIPELINE_dist($p) { |
| 2256 | - $_pipe = interprete_argument_balise(1, $p); |
|
| 2257 | - if (!$_pipe) { |
|
| 2258 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2259 | - erreur_squelette($err_b_s_a, $p); |
|
| 2260 | - } else { |
|
| 2261 | - $_flux = interprete_argument_balise(2, $p); |
|
| 2262 | - $_flux = $_flux ? $_flux : "''"; |
|
| 2263 | - $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2264 | - $p->interdire_scripts = false; |
|
| 2265 | - } |
|
| 2256 | + $_pipe = interprete_argument_balise(1, $p); |
|
| 2257 | + if (!$_pipe) { |
|
| 2258 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2259 | + erreur_squelette($err_b_s_a, $p); |
|
| 2260 | + } else { |
|
| 2261 | + $_flux = interprete_argument_balise(2, $p); |
|
| 2262 | + $_flux = $_flux ? $_flux : "''"; |
|
| 2263 | + $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2264 | + $p->interdire_scripts = false; |
|
| 2265 | + } |
|
| 2266 | 2266 | |
| 2267 | - return $p; |
|
| 2267 | + return $p; |
|
| 2268 | 2268 | } |
| 2269 | 2269 | |
| 2270 | 2270 | |
@@ -2289,10 +2289,10 @@ discard block |
||
| 2289 | 2289 | * Pile complétée par le code à générer |
| 2290 | 2290 | **/ |
| 2291 | 2291 | function balise_EDIT_dist($p) { |
| 2292 | - $p->code = "''"; |
|
| 2293 | - $p->interdire_scripts = false; |
|
| 2292 | + $p->code = "''"; |
|
| 2293 | + $p->interdire_scripts = false; |
|
| 2294 | 2294 | |
| 2295 | - return $p; |
|
| 2295 | + return $p; |
|
| 2296 | 2296 | } |
| 2297 | 2297 | |
| 2298 | 2298 | |
@@ -2315,11 +2315,11 @@ discard block |
||
| 2315 | 2315 | * Pile complétée par le code à générer |
| 2316 | 2316 | **/ |
| 2317 | 2317 | function balise_TOTAL_UNIQUE_dist($p) { |
| 2318 | - $_famille = interprete_argument_balise(1, $p); |
|
| 2319 | - $_famille = $_famille ? $_famille : "''"; |
|
| 2320 | - $p->code = "unique('', $_famille, true)"; |
|
| 2318 | + $_famille = interprete_argument_balise(1, $p); |
|
| 2319 | + $_famille = $_famille ? $_famille : "''"; |
|
| 2320 | + $p->code = "unique('', $_famille, true)"; |
|
| 2321 | 2321 | |
| 2322 | - return $p; |
|
| 2322 | + return $p; |
|
| 2323 | 2323 | } |
| 2324 | 2324 | |
| 2325 | 2325 | /** |
@@ -2342,19 +2342,19 @@ discard block |
||
| 2342 | 2342 | * Pile complétée par le code à générer |
| 2343 | 2343 | **/ |
| 2344 | 2344 | function balise_ARRAY_dist($p) { |
| 2345 | - $_code = []; |
|
| 2346 | - $n = 1; |
|
| 2347 | - do { |
|
| 2348 | - $_key = interprete_argument_balise($n++, $p); |
|
| 2349 | - $_val = interprete_argument_balise($n++, $p); |
|
| 2350 | - if ($_key and $_val) { |
|
| 2351 | - $_code[] = "$_key => $_val"; |
|
| 2352 | - } |
|
| 2353 | - } while ($_key && $_val); |
|
| 2354 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2355 | - $p->interdire_scripts = false; |
|
| 2345 | + $_code = []; |
|
| 2346 | + $n = 1; |
|
| 2347 | + do { |
|
| 2348 | + $_key = interprete_argument_balise($n++, $p); |
|
| 2349 | + $_val = interprete_argument_balise($n++, $p); |
|
| 2350 | + if ($_key and $_val) { |
|
| 2351 | + $_code[] = "$_key => $_val"; |
|
| 2352 | + } |
|
| 2353 | + } while ($_key && $_val); |
|
| 2354 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2355 | + $p->interdire_scripts = false; |
|
| 2356 | 2356 | |
| 2357 | - return $p; |
|
| 2357 | + return $p; |
|
| 2358 | 2358 | } |
| 2359 | 2359 | |
| 2360 | 2360 | /** |
@@ -2373,15 +2373,15 @@ discard block |
||
| 2373 | 2373 | * Pile complétée par le code à générer |
| 2374 | 2374 | */ |
| 2375 | 2375 | function balise_LISTE_dist($p) { |
| 2376 | - $_code = []; |
|
| 2377 | - $n = 1; |
|
| 2378 | - while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2379 | - $_code[] = $_val; |
|
| 2380 | - } |
|
| 2381 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2382 | - $p->interdire_scripts = false; |
|
| 2376 | + $_code = []; |
|
| 2377 | + $n = 1; |
|
| 2378 | + while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2379 | + $_code[] = $_val; |
|
| 2380 | + } |
|
| 2381 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2382 | + $p->interdire_scripts = false; |
|
| 2383 | 2383 | |
| 2384 | - return $p; |
|
| 2384 | + return $p; |
|
| 2385 | 2385 | } |
| 2386 | 2386 | |
| 2387 | 2387 | |
@@ -2415,21 +2415,21 @@ discard block |
||
| 2415 | 2415 | * Pile complétée par le code à générer |
| 2416 | 2416 | **/ |
| 2417 | 2417 | function balise_AUTORISER_dist($p) { |
| 2418 | - $_code = []; |
|
| 2419 | - $p->descr['session'] = true; // faire un cache par session |
|
| 2418 | + $_code = []; |
|
| 2419 | + $p->descr['session'] = true; // faire un cache par session |
|
| 2420 | 2420 | |
| 2421 | - $n = 1; |
|
| 2422 | - while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2423 | - $_code[] = $_v; |
|
| 2424 | - } |
|
| 2421 | + $n = 1; |
|
| 2422 | + while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2423 | + $_code[] = $_v; |
|
| 2424 | + } |
|
| 2425 | 2425 | |
| 2426 | - $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2427 | - ', ', |
|
| 2428 | - $_code |
|
| 2429 | - ) . ')?" ":"")'; |
|
| 2430 | - $p->interdire_scripts = false; |
|
| 2426 | + $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2427 | + ', ', |
|
| 2428 | + $_code |
|
| 2429 | + ) . ')?" ":"")'; |
|
| 2430 | + $p->interdire_scripts = false; |
|
| 2431 | 2431 | |
| 2432 | - return $p; |
|
| 2432 | + return $p; |
|
| 2433 | 2433 | } |
| 2434 | 2434 | |
| 2435 | 2435 | |
@@ -2453,15 +2453,15 @@ discard block |
||
| 2453 | 2453 | * Pile complétée par le code à générer |
| 2454 | 2454 | **/ |
| 2455 | 2455 | function balise_PLUGIN_dist($p) { |
| 2456 | - $plugin = interprete_argument_balise(1, $p); |
|
| 2457 | - $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2458 | - $type_info = interprete_argument_balise(2, $p); |
|
| 2459 | - $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2456 | + $plugin = interprete_argument_balise(1, $p); |
|
| 2457 | + $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2458 | + $type_info = interprete_argument_balise(2, $p); |
|
| 2459 | + $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2460 | 2460 | |
| 2461 | - $f = chercher_filtre('info_plugin'); |
|
| 2462 | - $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2461 | + $f = chercher_filtre('info_plugin'); |
|
| 2462 | + $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2463 | 2463 | |
| 2464 | - return $p; |
|
| 2464 | + return $p; |
|
| 2465 | 2465 | } |
| 2466 | 2466 | |
| 2467 | 2467 | /** |
@@ -2482,9 +2482,9 @@ discard block |
||
| 2482 | 2482 | * Pile complétée par le code à générer |
| 2483 | 2483 | **/ |
| 2484 | 2484 | function balise_AIDER_dist($p) { |
| 2485 | - $_motif = interprete_argument_balise(1, $p); |
|
| 2486 | - $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2487 | - return $p; |
|
| 2485 | + $_motif = interprete_argument_balise(1, $p); |
|
| 2486 | + $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2487 | + return $p; |
|
| 2488 | 2488 | } |
| 2489 | 2489 | |
| 2490 | 2490 | /** |
@@ -2510,16 +2510,16 @@ discard block |
||
| 2510 | 2510 | * Pile complétée par le code à générer |
| 2511 | 2511 | **/ |
| 2512 | 2512 | function balise_ACTION_FORMULAIRE($p) { |
| 2513 | - if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2514 | - $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2515 | - } |
|
| 2516 | - if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2517 | - $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - // envoyer le nom du formulaire que l'on traite |
|
| 2521 | - // transmettre les eventuels args de la balise formulaire |
|
| 2522 | - $p->code = " '<span class=\"form-hidden\">' . |
|
| 2513 | + if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2514 | + $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2515 | + } |
|
| 2516 | + if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2517 | + $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + // envoyer le nom du formulaire que l'on traite |
|
| 2521 | + // transmettre les eventuels args de la balise formulaire |
|
| 2522 | + $p->code = " '<span class=\"form-hidden\">' . |
|
| 2523 | 2523 | form_hidden($_url) . |
| 2524 | 2524 | '<input name=\'formulaire_action\' type=\'hidden\' |
| 2525 | 2525 | value=\'' . $_form . '\' />' . |
@@ -2530,9 +2530,9 @@ discard block |
||
| 2530 | 2530 | (\$Pile[0]['_hidden'] ?? '') . |
| 2531 | 2531 | '</span>'"; |
| 2532 | 2532 | |
| 2533 | - $p->interdire_scripts = false; |
|
| 2533 | + $p->interdire_scripts = false; |
|
| 2534 | 2534 | |
| 2535 | - return $p; |
|
| 2535 | + return $p; |
|
| 2536 | 2536 | } |
| 2537 | 2537 | |
| 2538 | 2538 | |
@@ -2573,25 +2573,25 @@ discard block |
||
| 2573 | 2573 | */ |
| 2574 | 2574 | function balise_BOUTON_ACTION_dist($p) { |
| 2575 | 2575 | |
| 2576 | - $args = []; |
|
| 2577 | - for ($k = 1; $k <= 6; $k++) { |
|
| 2578 | - $_a = interprete_argument_balise($k, $p); |
|
| 2579 | - if (!$_a) { |
|
| 2580 | - $_a = "''"; |
|
| 2581 | - } |
|
| 2582 | - $args[] = $_a; |
|
| 2583 | - } |
|
| 2584 | - // supprimer les args vides |
|
| 2585 | - while (end($args) == "''" and count($args) > 2) { |
|
| 2586 | - array_pop($args); |
|
| 2587 | - } |
|
| 2588 | - $args = implode(',', $args); |
|
| 2576 | + $args = []; |
|
| 2577 | + for ($k = 1; $k <= 6; $k++) { |
|
| 2578 | + $_a = interprete_argument_balise($k, $p); |
|
| 2579 | + if (!$_a) { |
|
| 2580 | + $_a = "''"; |
|
| 2581 | + } |
|
| 2582 | + $args[] = $_a; |
|
| 2583 | + } |
|
| 2584 | + // supprimer les args vides |
|
| 2585 | + while (end($args) == "''" and count($args) > 2) { |
|
| 2586 | + array_pop($args); |
|
| 2587 | + } |
|
| 2588 | + $args = implode(',', $args); |
|
| 2589 | 2589 | |
| 2590 | - $bouton_action = chercher_filtre('bouton_action'); |
|
| 2591 | - $p->code = "$bouton_action($args)"; |
|
| 2592 | - $p->interdire_scripts = false; |
|
| 2590 | + $bouton_action = chercher_filtre('bouton_action'); |
|
| 2591 | + $p->code = "$bouton_action($args)"; |
|
| 2592 | + $p->interdire_scripts = false; |
|
| 2593 | 2593 | |
| 2594 | - return $p; |
|
| 2594 | + return $p; |
|
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | |
@@ -2610,10 +2610,10 @@ discard block |
||
| 2610 | 2610 | * Pile complétée par le code à générer |
| 2611 | 2611 | */ |
| 2612 | 2612 | function balise_SLOGAN_SITE_SPIP_dist($p) { |
| 2613 | - $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2613 | + $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2614 | 2614 | |
| 2615 | - #$p->interdire_scripts = true; |
|
| 2616 | - return $p; |
|
| 2615 | + #$p->interdire_scripts = true; |
|
| 2616 | + return $p; |
|
| 2617 | 2617 | } |
| 2618 | 2618 | |
| 2619 | 2619 | |
@@ -2637,10 +2637,10 @@ discard block |
||
| 2637 | 2637 | * Pile complétée par le code à générer |
| 2638 | 2638 | */ |
| 2639 | 2639 | function balise_HTML5_dist($p) { |
| 2640 | - $p->code = html5_permis() ? "' '" : "''"; |
|
| 2641 | - $p->interdire_scripts = false; |
|
| 2640 | + $p->code = html5_permis() ? "' '" : "''"; |
|
| 2641 | + $p->interdire_scripts = false; |
|
| 2642 | 2642 | |
| 2643 | - return $p; |
|
| 2643 | + return $p; |
|
| 2644 | 2644 | } |
| 2645 | 2645 | |
| 2646 | 2646 | |
@@ -2666,61 +2666,61 @@ discard block |
||
| 2666 | 2666 | * Pile complétée par le code à générer |
| 2667 | 2667 | */ |
| 2668 | 2668 | function balise_TRI_dist($p, $liste = 'true') { |
| 2669 | - $b = index_boucle_mere($p); |
|
| 2670 | - // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2671 | - if ($b === '') { |
|
| 2672 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2673 | - erreur_squelette($msg, $p); |
|
| 2674 | - $p->code = "''"; |
|
| 2669 | + $b = index_boucle_mere($p); |
|
| 2670 | + // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2671 | + if ($b === '') { |
|
| 2672 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2673 | + erreur_squelette($msg, $p); |
|
| 2674 | + $p->code = "''"; |
|
| 2675 | 2675 | |
| 2676 | - return $p; |
|
| 2677 | - } |
|
| 2678 | - $boucle = $p->boucles[$b]; |
|
| 2676 | + return $p; |
|
| 2677 | + } |
|
| 2678 | + $boucle = $p->boucles[$b]; |
|
| 2679 | 2679 | |
| 2680 | - // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2681 | - // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2682 | - if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2683 | - $msg = ['zbug_champ_hors_critere', [ |
|
| 2684 | - 'champ' => zbug_presenter_champ($p), |
|
| 2685 | - 'critere' => 'tri' |
|
| 2686 | - ]]; |
|
| 2687 | - erreur_squelette($msg, $p); |
|
| 2688 | - $p->code = "''"; |
|
| 2680 | + // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2681 | + // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2682 | + if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2683 | + $msg = ['zbug_champ_hors_critere', [ |
|
| 2684 | + 'champ' => zbug_presenter_champ($p), |
|
| 2685 | + 'critere' => 'tri' |
|
| 2686 | + ]]; |
|
| 2687 | + erreur_squelette($msg, $p); |
|
| 2688 | + $p->code = "''"; |
|
| 2689 | 2689 | |
| 2690 | - return $p; |
|
| 2691 | - } |
|
| 2690 | + return $p; |
|
| 2691 | + } |
|
| 2692 | 2692 | |
| 2693 | - $_champ = interprete_argument_balise(1, $p); |
|
| 2694 | - // si pas de champ, renvoyer le critere de tri utilise |
|
| 2695 | - if (!$_champ) { |
|
| 2696 | - $p->code = $boucle->modificateur['tri_champ']; |
|
| 2693 | + $_champ = interprete_argument_balise(1, $p); |
|
| 2694 | + // si pas de champ, renvoyer le critere de tri utilise |
|
| 2695 | + if (!$_champ) { |
|
| 2696 | + $p->code = $boucle->modificateur['tri_champ']; |
|
| 2697 | 2697 | |
| 2698 | - return $p; |
|
| 2699 | - } |
|
| 2700 | - // forcer la jointure si besoin, et si le champ est statique |
|
| 2701 | - if (preg_match(",^'([\w.]+)'$,i", $_champ, $m)) { |
|
| 2702 | - index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2703 | - } |
|
| 2698 | + return $p; |
|
| 2699 | + } |
|
| 2700 | + // forcer la jointure si besoin, et si le champ est statique |
|
| 2701 | + if (preg_match(",^'([\w.]+)'$,i", $_champ, $m)) { |
|
| 2702 | + index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2703 | + } |
|
| 2704 | 2704 | |
| 2705 | - $_libelle = interprete_argument_balise(2, $p); |
|
| 2706 | - $_libelle = $_libelle ? $_libelle : $_champ; |
|
| 2705 | + $_libelle = interprete_argument_balise(2, $p); |
|
| 2706 | + $_libelle = $_libelle ? $_libelle : $_champ; |
|
| 2707 | 2707 | |
| 2708 | - $_class = interprete_argument_balise(3, $p); |
|
| 2709 | - // si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1 |
|
| 2710 | - // si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1 |
|
| 2711 | - $_issens = "in_array($_champ,array('>','<'))"; |
|
| 2712 | - $_sens = "(strpos('< >',$_champ)-1)"; |
|
| 2708 | + $_class = interprete_argument_balise(3, $p); |
|
| 2709 | + // si champ = ">" c'est un lien vers le tri croissant : de gauche a droite ==> 1 |
|
| 2710 | + // si champ = "<" c'est un lien vers le tri decroissant : (sens inverse) == -1 |
|
| 2711 | + $_issens = "in_array($_champ,array('>','<'))"; |
|
| 2712 | + $_sens = "(strpos('< >',$_champ)-1)"; |
|
| 2713 | 2713 | |
| 2714 | - $_variable = "((\$s=$_issens)?'sens':'tri')." . $boucle->modificateur['tri_nom']; |
|
| 2715 | - $_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)"; |
|
| 2716 | - $_url = "parametre_url($_url,'var_memotri',strncmp(" . $boucle->modificateur['tri_nom'] . ",'session',7)==0?$_variable:'')"; |
|
| 2717 | - $_on = '$s?(' . $boucle->modificateur['tri_sens'] . "==$_sens" . '):(' . $boucle->modificateur['tri_champ'] . "==$_champ)"; |
|
| 2714 | + $_variable = "((\$s=$_issens)?'sens':'tri')." . $boucle->modificateur['tri_nom']; |
|
| 2715 | + $_url = "parametre_url(self(),$_variable,\$s?$_sens:$_champ)"; |
|
| 2716 | + $_url = "parametre_url($_url,'var_memotri',strncmp(" . $boucle->modificateur['tri_nom'] . ",'session',7)==0?$_variable:'')"; |
|
| 2717 | + $_on = '$s?(' . $boucle->modificateur['tri_sens'] . "==$_sens" . '):(' . $boucle->modificateur['tri_champ'] . "==$_champ)"; |
|
| 2718 | 2718 | |
| 2719 | - $p->code = "lien_ou_expose($_url,$_libelle,$_on" . ($_class ? ",$_class" : '') . ')'; |
|
| 2720 | - //$p->code = "''"; |
|
| 2721 | - $p->interdire_scripts = false; |
|
| 2719 | + $p->code = "lien_ou_expose($_url,$_libelle,$_on" . ($_class ? ",$_class" : '') . ')'; |
|
| 2720 | + //$p->code = "''"; |
|
| 2721 | + $p->interdire_scripts = false; |
|
| 2722 | 2722 | |
| 2723 | - return $p; |
|
| 2723 | + return $p; |
|
| 2724 | 2724 | } |
| 2725 | 2725 | |
| 2726 | 2726 | |
@@ -2741,21 +2741,21 @@ discard block |
||
| 2741 | 2741 | * Pile complétée par le code à générer |
| 2742 | 2742 | */ |
| 2743 | 2743 | function balise_SAUTER_dist($p) { |
| 2744 | - $id_boucle = $p->id_boucle; |
|
| 2744 | + $id_boucle = $p->id_boucle; |
|
| 2745 | 2745 | |
| 2746 | - if (empty($p->boucles[$id_boucle])) { |
|
| 2747 | - $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2748 | - erreur_squelette($msg, $p); |
|
| 2749 | - } else { |
|
| 2750 | - $_saut = interprete_argument_balise(1, $p); |
|
| 2751 | - $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2752 | - $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2746 | + if (empty($p->boucles[$id_boucle])) { |
|
| 2747 | + $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2748 | + erreur_squelette($msg, $p); |
|
| 2749 | + } else { |
|
| 2750 | + $_saut = interprete_argument_balise(1, $p); |
|
| 2751 | + $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2752 | + $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2753 | 2753 | |
| 2754 | - $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2755 | - } |
|
| 2756 | - $p->interdire_scripts = false; |
|
| 2754 | + $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2755 | + } |
|
| 2756 | + $p->interdire_scripts = false; |
|
| 2757 | 2757 | |
| 2758 | - return $p; |
|
| 2758 | + return $p; |
|
| 2759 | 2759 | } |
| 2760 | 2760 | |
| 2761 | 2761 | |
@@ -2777,22 +2777,22 @@ discard block |
||
| 2777 | 2777 | * Pile complétée par le code à générer |
| 2778 | 2778 | */ |
| 2779 | 2779 | function balise_PUBLIE_dist($p) { |
| 2780 | - if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2781 | - $_type = _q($p->type_requete); |
|
| 2782 | - $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2783 | - } else { |
|
| 2784 | - $_id = interprete_argument_balise(2, $p); |
|
| 2785 | - } |
|
| 2780 | + if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2781 | + $_type = _q($p->type_requete); |
|
| 2782 | + $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2783 | + } else { |
|
| 2784 | + $_id = interprete_argument_balise(2, $p); |
|
| 2785 | + } |
|
| 2786 | 2786 | |
| 2787 | - $connect = ''; |
|
| 2788 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2789 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2790 | - } |
|
| 2787 | + $connect = ''; |
|
| 2788 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2789 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2790 | + } |
|
| 2791 | 2791 | |
| 2792 | - $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2793 | - $p->interdire_scripts = false; |
|
| 2792 | + $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2793 | + $p->interdire_scripts = false; |
|
| 2794 | 2794 | |
| 2795 | - return $p; |
|
| 2795 | + return $p; |
|
| 2796 | 2796 | } |
| 2797 | 2797 | |
| 2798 | 2798 | /** |
@@ -2821,12 +2821,12 @@ discard block |
||
| 2821 | 2821 | * Pile complétée par le code à générer |
| 2822 | 2822 | */ |
| 2823 | 2823 | function balise_PRODUIRE_dist($p) { |
| 2824 | - $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2825 | - $p = $balise_inclure($p); |
|
| 2824 | + $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2825 | + $p = $balise_inclure($p); |
|
| 2826 | 2826 | |
| 2827 | - $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2827 | + $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2828 | 2828 | |
| 2829 | - return $p; |
|
| 2829 | + return $p; |
|
| 2830 | 2830 | } |
| 2831 | 2831 | |
| 2832 | 2832 | /** |
@@ -2845,13 +2845,13 @@ discard block |
||
| 2845 | 2845 | * Pile complétée par le code à générer |
| 2846 | 2846 | */ |
| 2847 | 2847 | function balise_LARGEUR_ECRAN_dist($p) { |
| 2848 | - $_class = interprete_argument_balise(1, $p); |
|
| 2849 | - if (!$_class) { |
|
| 2850 | - $_class = 'null'; |
|
| 2851 | - } |
|
| 2852 | - $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2848 | + $_class = interprete_argument_balise(1, $p); |
|
| 2849 | + if (!$_class) { |
|
| 2850 | + $_class = 'null'; |
|
| 2851 | + } |
|
| 2852 | + $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2853 | 2853 | |
| 2854 | - return $p; |
|
| 2854 | + return $p; |
|
| 2855 | 2855 | } |
| 2856 | 2856 | |
| 2857 | 2857 | |
@@ -2867,14 +2867,14 @@ discard block |
||
| 2867 | 2867 | * Pile complétée par le code à générer |
| 2868 | 2868 | **/ |
| 2869 | 2869 | function balise_CONST_dist($p) { |
| 2870 | - $_const = interprete_argument_balise(1, $p); |
|
| 2871 | - if (!strlen($_const)) { |
|
| 2872 | - $p->code = "''"; |
|
| 2873 | - } |
|
| 2874 | - else { |
|
| 2875 | - $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2876 | - } |
|
| 2877 | - $p->interdire_scripts = false; |
|
| 2878 | - |
|
| 2879 | - return $p; |
|
| 2870 | + $_const = interprete_argument_balise(1, $p); |
|
| 2871 | + if (!strlen($_const)) { |
|
| 2872 | + $p->code = "''"; |
|
| 2873 | + } |
|
| 2874 | + else { |
|
| 2875 | + $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2876 | + } |
|
| 2877 | + $p->interdire_scripts = false; |
|
| 2878 | + |
|
| 2879 | + return $p; |
|
| 2880 | 2880 | } |
@@ -20,178 +20,178 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // En cas de modification, il faut aussi actualiser la regexp de nettoyer_uri_var() dans inc/utils.php |
| 27 | 27 | if (!defined('_CONTEXTE_IGNORE_VARIABLES')) { |
| 28 | - define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 28 | + define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // https://code.spip.net/@assembler |
| 32 | 32 | function assembler($fond, string $connect = '') { |
| 33 | 33 | |
| 34 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | - |
|
| 38 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 40 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 41 | - ',\.[a-zA-Z0-9]*$,', |
|
| 42 | - '', |
|
| 43 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 44 | - ); |
|
| 45 | - // Cette fonction est utilisee deux fois |
|
| 46 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 47 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 48 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 49 | - if ($cacher) { |
|
| 50 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 51 | - } else { |
|
| 52 | - $GLOBALS['use_cache'] = -1; |
|
| 53 | - } |
|
| 54 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 55 | - if ($res) { |
|
| 56 | - return ['texte' => $res]; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if (!$chemin_cache || !$lastmodified) { |
|
| 60 | - $lastmodified = time(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 64 | - $calculer_page = true; |
|
| 65 | - |
|
| 66 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 67 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 68 | - // pages sont dynamiques) |
|
| 69 | - if ( |
|
| 70 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 71 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 72 | - and $chemin_cache |
|
| 73 | - and isset($page['entetes']) |
|
| 74 | - and isset($page['entetes']['Cache-Control']) |
|
| 75 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 76 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 77 | - ) { |
|
| 78 | - $since = preg_replace( |
|
| 79 | - '/;.*/', |
|
| 80 | - '', |
|
| 81 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 82 | - ); |
|
| 83 | - $since = str_replace('GMT', '', $since); |
|
| 84 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 85 | - $page['status'] = 304; |
|
| 86 | - $headers_only = true; |
|
| 87 | - $calculer_page = false; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 92 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 93 | - if (!$calculer_page) { |
|
| 94 | - $page['texte'] = ''; |
|
| 95 | - } else { |
|
| 96 | - // si la page est prise dans le cache |
|
| 97 | - if (!$GLOBALS['use_cache']) { |
|
| 98 | - // Informer les boutons d'admin du contexte |
|
| 99 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 100 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 101 | - |
|
| 102 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 103 | - // d'inversion url => objet |
|
| 104 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 105 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 106 | - #unset($_ENV['url_propre']); |
|
| 107 | - } else { |
|
| 108 | - // Compat ascendante : |
|
| 109 | - // 1. $contexte est global |
|
| 110 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 111 | - // et calculer la page |
|
| 112 | - if (!test_espace_prive()) { |
|
| 113 | - include_spip('inc/urls'); |
|
| 114 | - list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url( |
|
| 115 | - nettoyer_uri(), |
|
| 116 | - $fond, |
|
| 117 | - $GLOBALS['contexte'], |
|
| 118 | - true |
|
| 119 | - ); |
|
| 120 | - } |
|
| 121 | - // squelette par defaut |
|
| 122 | - if (!strlen($fond)) { |
|
| 123 | - $fond = 'sommaire'; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // produire la page : peut mettre a jour $lastmodified |
|
| 127 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 128 | - $page = $produire_page( |
|
| 129 | - $fond, |
|
| 130 | - $GLOBALS['contexte'], |
|
| 131 | - $GLOBALS['use_cache'], |
|
| 132 | - $chemin_cache, |
|
| 133 | - null, |
|
| 134 | - $page, |
|
| 135 | - $lastmodified, |
|
| 136 | - $connect |
|
| 137 | - ); |
|
| 138 | - if ($page === '') { |
|
| 139 | - $erreur = _T( |
|
| 140 | - 'info_erreur_squelette2', |
|
| 141 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 142 | - ); |
|
| 143 | - erreur_squelette($erreur); |
|
| 144 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 145 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if ($page and $chemin_cache) { |
|
| 150 | - $page['cache'] = $chemin_cache; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - auto_content_type($page); |
|
| 154 | - |
|
| 155 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 156 | - |
|
| 157 | - // Definir les entetes si ce n'est fait |
|
| 158 | - if (!$GLOBALS['flag_preserver']) { |
|
| 159 | - if ($GLOBALS['flag_ob']) { |
|
| 160 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 161 | - if ( |
|
| 162 | - trim($page['texte']) === '' |
|
| 163 | - and _VAR_MODE != 'debug' |
|
| 164 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 165 | - ) { |
|
| 166 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 167 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 168 | - } |
|
| 169 | - // pas de cache client en mode 'observation' |
|
| 170 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 171 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 172 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Entete Last-Modified: |
|
| 179 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | - if ( |
|
| 182 | - $lastmodified |
|
| 183 | - and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | - and !isset($page['entetes']['Last-Modified']) |
|
| 185 | - ) { |
|
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // fermer la connexion apres les headers si requete HEAD |
|
| 190 | - if ($headers_only) { |
|
| 191 | - $page['entetes']['Connection'] = 'close'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $page; |
|
| 34 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | + |
|
| 38 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 40 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 41 | + ',\.[a-zA-Z0-9]*$,', |
|
| 42 | + '', |
|
| 43 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 44 | + ); |
|
| 45 | + // Cette fonction est utilisee deux fois |
|
| 46 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 47 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 48 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 49 | + if ($cacher) { |
|
| 50 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 51 | + } else { |
|
| 52 | + $GLOBALS['use_cache'] = -1; |
|
| 53 | + } |
|
| 54 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 55 | + if ($res) { |
|
| 56 | + return ['texte' => $res]; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if (!$chemin_cache || !$lastmodified) { |
|
| 60 | + $lastmodified = time(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 64 | + $calculer_page = true; |
|
| 65 | + |
|
| 66 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 67 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 68 | + // pages sont dynamiques) |
|
| 69 | + if ( |
|
| 70 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 71 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 72 | + and $chemin_cache |
|
| 73 | + and isset($page['entetes']) |
|
| 74 | + and isset($page['entetes']['Cache-Control']) |
|
| 75 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 76 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 77 | + ) { |
|
| 78 | + $since = preg_replace( |
|
| 79 | + '/;.*/', |
|
| 80 | + '', |
|
| 81 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 82 | + ); |
|
| 83 | + $since = str_replace('GMT', '', $since); |
|
| 84 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 85 | + $page['status'] = 304; |
|
| 86 | + $headers_only = true; |
|
| 87 | + $calculer_page = false; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 92 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 93 | + if (!$calculer_page) { |
|
| 94 | + $page['texte'] = ''; |
|
| 95 | + } else { |
|
| 96 | + // si la page est prise dans le cache |
|
| 97 | + if (!$GLOBALS['use_cache']) { |
|
| 98 | + // Informer les boutons d'admin du contexte |
|
| 99 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 100 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 101 | + |
|
| 102 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 103 | + // d'inversion url => objet |
|
| 104 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 105 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 106 | + #unset($_ENV['url_propre']); |
|
| 107 | + } else { |
|
| 108 | + // Compat ascendante : |
|
| 109 | + // 1. $contexte est global |
|
| 110 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 111 | + // et calculer la page |
|
| 112 | + if (!test_espace_prive()) { |
|
| 113 | + include_spip('inc/urls'); |
|
| 114 | + list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url( |
|
| 115 | + nettoyer_uri(), |
|
| 116 | + $fond, |
|
| 117 | + $GLOBALS['contexte'], |
|
| 118 | + true |
|
| 119 | + ); |
|
| 120 | + } |
|
| 121 | + // squelette par defaut |
|
| 122 | + if (!strlen($fond)) { |
|
| 123 | + $fond = 'sommaire'; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // produire la page : peut mettre a jour $lastmodified |
|
| 127 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 128 | + $page = $produire_page( |
|
| 129 | + $fond, |
|
| 130 | + $GLOBALS['contexte'], |
|
| 131 | + $GLOBALS['use_cache'], |
|
| 132 | + $chemin_cache, |
|
| 133 | + null, |
|
| 134 | + $page, |
|
| 135 | + $lastmodified, |
|
| 136 | + $connect |
|
| 137 | + ); |
|
| 138 | + if ($page === '') { |
|
| 139 | + $erreur = _T( |
|
| 140 | + 'info_erreur_squelette2', |
|
| 141 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 142 | + ); |
|
| 143 | + erreur_squelette($erreur); |
|
| 144 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 145 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if ($page and $chemin_cache) { |
|
| 150 | + $page['cache'] = $chemin_cache; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + auto_content_type($page); |
|
| 154 | + |
|
| 155 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 156 | + |
|
| 157 | + // Definir les entetes si ce n'est fait |
|
| 158 | + if (!$GLOBALS['flag_preserver']) { |
|
| 159 | + if ($GLOBALS['flag_ob']) { |
|
| 160 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 161 | + if ( |
|
| 162 | + trim($page['texte']) === '' |
|
| 163 | + and _VAR_MODE != 'debug' |
|
| 164 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 165 | + ) { |
|
| 166 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 167 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 168 | + } |
|
| 169 | + // pas de cache client en mode 'observation' |
|
| 170 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 171 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 172 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Entete Last-Modified: |
|
| 179 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | + if ( |
|
| 182 | + $lastmodified |
|
| 183 | + and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | + and !isset($page['entetes']['Last-Modified']) |
|
| 185 | + ) { |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // fermer la connexion apres les headers si requete HEAD |
|
| 190 | + if ($headers_only) { |
|
| 191 | + $page['entetes']['Connection'] = 'close'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $page; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -210,19 +210,19 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | function calculer_contexte() { |
| 212 | 212 | |
| 213 | - $contexte = []; |
|
| 214 | - foreach ($_GET as $var => $val) { |
|
| 215 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 216 | - $contexte[$var] = $val; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - foreach ($_POST as $var => $val) { |
|
| 220 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 221 | - $contexte[$var] = $val; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $contexte; |
|
| 213 | + $contexte = []; |
|
| 214 | + foreach ($_GET as $var => $val) { |
|
| 215 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 216 | + $contexte[$var] = $val; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + foreach ($_POST as $var => $val) { |
|
| 220 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 221 | + $contexte[$var] = $val; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $contexte; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,25 +233,25 @@ discard block |
||
| 233 | 233 | * @return array |
| 234 | 234 | */ |
| 235 | 235 | function calculer_contexte_implicite() { |
| 236 | - static $notes = null; |
|
| 237 | - if (is_null($notes)) { |
|
| 238 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 239 | - } |
|
| 240 | - $contexte_implicite = [ |
|
| 241 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 242 | - 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 243 | - 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 244 | - 'espace' => test_espace_prive(), |
|
| 245 | - 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 246 | - 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 247 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 248 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 249 | - ]; |
|
| 250 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 251 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $contexte_implicite; |
|
| 236 | + static $notes = null; |
|
| 237 | + if (is_null($notes)) { |
|
| 238 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 239 | + } |
|
| 240 | + $contexte_implicite = [ |
|
| 241 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 242 | + 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 243 | + 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 244 | + 'espace' => test_espace_prive(), |
|
| 245 | + 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 246 | + 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 247 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 248 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 249 | + ]; |
|
| 250 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 251 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $contexte_implicite; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // |
@@ -261,52 +261,52 @@ discard block |
||
| 261 | 261 | // https://code.spip.net/@auto_content_type |
| 262 | 262 | function auto_content_type($page) { |
| 263 | 263 | |
| 264 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 265 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 266 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 267 | - $page['texte'] |
|
| 268 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 269 | - } |
|
| 264 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 265 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 266 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 267 | + $page['texte'] |
|
| 268 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | // https://code.spip.net/@inclure_page |
| 273 | 273 | function inclure_page($fond, $contexte, string $connect = '') { |
| 274 | - static $cacher, $produire_page; |
|
| 275 | - |
|
| 276 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | - // (cette precaution n'est probablement plus utile) |
|
| 279 | - unset($contexte['fond']); |
|
| 280 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | - if (is_null($cacher)) { |
|
| 283 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | - } |
|
| 285 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | - if ($cacher) { |
|
| 288 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | - } else { |
|
| 290 | - $use_cache = -1; |
|
| 291 | - } |
|
| 292 | - // $res = message d'erreur : on sort de la |
|
| 293 | - if ($res) { |
|
| 294 | - return ['texte' => $res]; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | - // produire la page : peut mettre a jour $lastinclude |
|
| 299 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | - if ($use_cache) { |
|
| 301 | - if (is_null($produire_page)) { |
|
| 302 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | - } |
|
| 304 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | - } |
|
| 306 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | - $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 308 | - |
|
| 309 | - return $page; |
|
| 274 | + static $cacher, $produire_page; |
|
| 275 | + |
|
| 276 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | + // (cette precaution n'est probablement plus utile) |
|
| 279 | + unset($contexte['fond']); |
|
| 280 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | + if (is_null($cacher)) { |
|
| 283 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | + } |
|
| 285 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | + if ($cacher) { |
|
| 288 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | + } else { |
|
| 290 | + $use_cache = -1; |
|
| 291 | + } |
|
| 292 | + // $res = message d'erreur : on sort de la |
|
| 293 | + if ($res) { |
|
| 294 | + return ['texte' => $res]; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | + // produire la page : peut mettre a jour $lastinclude |
|
| 299 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | + if ($use_cache) { |
|
| 301 | + if (is_null($produire_page)) { |
|
| 302 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | + } |
|
| 304 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | + } |
|
| 306 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | + $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 308 | + |
|
| 309 | + return $page; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -324,41 +324,41 @@ discard block |
||
| 324 | 324 | * @return array |
| 325 | 325 | */ |
| 326 | 326 | function public_produire_page_dist( |
| 327 | - $fond, |
|
| 328 | - $contexte, |
|
| 329 | - $use_cache, |
|
| 330 | - $chemin_cache, |
|
| 331 | - $contexte_cache, |
|
| 332 | - &$page, |
|
| 333 | - &$lastinclude, |
|
| 334 | - $connect = '' |
|
| 327 | + $fond, |
|
| 328 | + $contexte, |
|
| 329 | + $use_cache, |
|
| 330 | + $chemin_cache, |
|
| 331 | + $contexte_cache, |
|
| 332 | + &$page, |
|
| 333 | + &$lastinclude, |
|
| 334 | + $connect = '' |
|
| 335 | 335 | ) { |
| 336 | - static $parametrer, $cacher; |
|
| 337 | - if (!$parametrer) { |
|
| 338 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | - } |
|
| 340 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | - // et on l'enregistre sur le disque |
|
| 342 | - if ( |
|
| 343 | - $chemin_cache |
|
| 344 | - and $use_cache > -1 |
|
| 345 | - and is_array($page) |
|
| 346 | - and count($page) |
|
| 347 | - and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | - and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | - ) { |
|
| 350 | - if (is_null($cacher)) { |
|
| 351 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | - } |
|
| 353 | - $lastinclude = time(); |
|
| 354 | - if ($cacher) { |
|
| 355 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | - } else { |
|
| 357 | - $use_cache = -1; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $page; |
|
| 336 | + static $parametrer, $cacher; |
|
| 337 | + if (!$parametrer) { |
|
| 338 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | + } |
|
| 340 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | + // et on l'enregistre sur le disque |
|
| 342 | + if ( |
|
| 343 | + $chemin_cache |
|
| 344 | + and $use_cache > -1 |
|
| 345 | + and is_array($page) |
|
| 346 | + and count($page) |
|
| 347 | + and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | + and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | + ) { |
|
| 350 | + if (is_null($cacher)) { |
|
| 351 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | + } |
|
| 353 | + $lastinclude = time(); |
|
| 354 | + if ($cacher) { |
|
| 355 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | + } else { |
|
| 357 | + $use_cache = -1; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $page; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Fonction inseree par le compilateur dans le code compile. |
@@ -372,14 +372,14 @@ discard block |
||
| 372 | 372 | // 4: langue |
| 373 | 373 | |
| 374 | 374 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 375 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | - |
|
| 377 | - if (!is_array($contexte_exec)) { |
|
| 378 | - echo $contexte_exec; |
|
| 379 | - } // message d'erreur etc |
|
| 380 | - else { |
|
| 381 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | - } |
|
| 375 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | + |
|
| 377 | + if (!is_array($contexte_exec)) { |
|
| 378 | + echo $contexte_exec; |
|
| 379 | + } // message d'erreur etc |
|
| 380 | + else { |
|
| 381 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -394,100 +394,100 @@ discard block |
||
| 394 | 394 | * @return string |
| 395 | 395 | */ |
| 396 | 396 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 397 | - if (is_array($texte)) { |
|
| 398 | - list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 399 | - |
|
| 400 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | - $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 402 | - $GLOBALS['delais'] = $delainc; |
|
| 403 | - |
|
| 404 | - $page = recuperer_fond( |
|
| 405 | - $fond, |
|
| 406 | - $contexte_inclus, |
|
| 407 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | - ); |
|
| 409 | - |
|
| 410 | - $texte = $page['texte']; |
|
| 411 | - |
|
| 412 | - $GLOBALS['delais'] = $d; |
|
| 413 | - // Faire remonter les entetes |
|
| 414 | - if (is_array($page['entetes'])) { |
|
| 415 | - // mais pas toutes |
|
| 416 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 417 | - unset($page['entetes']['Content-Type']); |
|
| 418 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 419 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 420 | - $GLOBALS['page']['entetes'] = []; |
|
| 421 | - } |
|
| 422 | - $GLOBALS['page']['entetes'] = |
|
| 423 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 427 | - if ( |
|
| 428 | - isset($page['contexte']['_pipelines']) |
|
| 429 | - and is_array($page['contexte']['_pipelines']) |
|
| 430 | - and count($page['contexte']['_pipelines']) |
|
| 431 | - ) { |
|
| 432 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 433 | - $args['contexte'] = $page['contexte']; |
|
| 434 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 435 | - $texte = pipeline( |
|
| 436 | - $pipe, |
|
| 437 | - [ |
|
| 438 | - 'data' => $texte, |
|
| 439 | - 'args' => $args |
|
| 440 | - ], |
|
| 441 | - false |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | - $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 450 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | - } |
|
| 452 | - if ($echo) { |
|
| 453 | - echo $texte; |
|
| 454 | - } else { |
|
| 455 | - return $texte; |
|
| 456 | - } |
|
| 397 | + if (is_array($texte)) { |
|
| 398 | + list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 399 | + |
|
| 400 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | + $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 402 | + $GLOBALS['delais'] = $delainc; |
|
| 403 | + |
|
| 404 | + $page = recuperer_fond( |
|
| 405 | + $fond, |
|
| 406 | + $contexte_inclus, |
|
| 407 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | + ); |
|
| 409 | + |
|
| 410 | + $texte = $page['texte']; |
|
| 411 | + |
|
| 412 | + $GLOBALS['delais'] = $d; |
|
| 413 | + // Faire remonter les entetes |
|
| 414 | + if (is_array($page['entetes'])) { |
|
| 415 | + // mais pas toutes |
|
| 416 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 417 | + unset($page['entetes']['Content-Type']); |
|
| 418 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 419 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 420 | + $GLOBALS['page']['entetes'] = []; |
|
| 421 | + } |
|
| 422 | + $GLOBALS['page']['entetes'] = |
|
| 423 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 427 | + if ( |
|
| 428 | + isset($page['contexte']['_pipelines']) |
|
| 429 | + and is_array($page['contexte']['_pipelines']) |
|
| 430 | + and count($page['contexte']['_pipelines']) |
|
| 431 | + ) { |
|
| 432 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 433 | + $args['contexte'] = $page['contexte']; |
|
| 434 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 435 | + $texte = pipeline( |
|
| 436 | + $pipe, |
|
| 437 | + [ |
|
| 438 | + 'data' => $texte, |
|
| 439 | + 'args' => $args |
|
| 440 | + ], |
|
| 441 | + false |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | + $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 450 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | + } |
|
| 452 | + if ($echo) { |
|
| 453 | + echo $texte; |
|
| 454 | + } else { |
|
| 455 | + return $texte; |
|
| 456 | + } |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // https://code.spip.net/@message_page_indisponible |
| 460 | 460 | function message_page_indisponible($page, $contexte) { |
| 461 | - static $deja = false; |
|
| 462 | - if ($deja) { |
|
| 463 | - return 'erreur'; |
|
| 464 | - } |
|
| 465 | - $codes = [ |
|
| 466 | - '404' => '404 Not Found', |
|
| 467 | - '503' => '503 Service Unavailable', |
|
| 468 | - ]; |
|
| 469 | - |
|
| 470 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 471 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 472 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 473 | - if (!isset($contexte['lang'])) { |
|
| 474 | - include_spip('inc/lang'); |
|
| 475 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $deja = true; |
|
| 479 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 480 | - // ex restriction d'acces => 401 |
|
| 481 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 482 | - |
|
| 483 | - // produire la page d'erreur |
|
| 484 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 485 | - if (!$page) { |
|
| 486 | - $page = inclure_page('404', $contexte); |
|
| 487 | - } |
|
| 488 | - $page['status'] = $contexte['status']; |
|
| 489 | - |
|
| 490 | - return $page; |
|
| 461 | + static $deja = false; |
|
| 462 | + if ($deja) { |
|
| 463 | + return 'erreur'; |
|
| 464 | + } |
|
| 465 | + $codes = [ |
|
| 466 | + '404' => '404 Not Found', |
|
| 467 | + '503' => '503 Service Unavailable', |
|
| 468 | + ]; |
|
| 469 | + |
|
| 470 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 471 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 472 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 473 | + if (!isset($contexte['lang'])) { |
|
| 474 | + include_spip('inc/lang'); |
|
| 475 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $deja = true; |
|
| 479 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 480 | + // ex restriction d'acces => 401 |
|
| 481 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 482 | + |
|
| 483 | + // produire la page d'erreur |
|
| 484 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 485 | + if (!$page) { |
|
| 486 | + $page = inclure_page('404', $contexte); |
|
| 487 | + } |
|
| 488 | + $page['status'] = $contexte['status']; |
|
| 489 | + |
|
| 490 | + return $page; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /** |
@@ -499,45 +499,45 @@ discard block |
||
| 499 | 499 | * @return mixed |
| 500 | 500 | */ |
| 501 | 501 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 502 | - static $balise_dyn_appellee_par_modele = null; |
|
| 503 | - switch ($operation) { |
|
| 504 | - case 'read': |
|
| 505 | - return $balise_dyn_appellee_par_modele; |
|
| 506 | - case 'reset': |
|
| 507 | - $balise_dyn_appellee_par_modele = null; |
|
| 508 | - return null; |
|
| 509 | - case 'set': |
|
| 510 | - default: |
|
| 511 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 512 | - return $arg; |
|
| 513 | - } |
|
| 502 | + static $balise_dyn_appellee_par_modele = null; |
|
| 503 | + switch ($operation) { |
|
| 504 | + case 'read': |
|
| 505 | + return $balise_dyn_appellee_par_modele; |
|
| 506 | + case 'reset': |
|
| 507 | + $balise_dyn_appellee_par_modele = null; |
|
| 508 | + return null; |
|
| 509 | + case 'set': |
|
| 510 | + default: |
|
| 511 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 512 | + return $arg; |
|
| 513 | + } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | // temporairement ici : a mettre dans le futur inc/modeles |
| 517 | 517 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 518 | 518 | // https://code.spip.net/@creer_contexte_de_modele |
| 519 | 519 | function creer_contexte_de_modele($args) { |
| 520 | - $contexte = []; |
|
| 521 | - foreach ($args as $var => $val) { |
|
| 522 | - if (is_int($var)) { // argument pas formate |
|
| 523 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | - $var = 'align'; |
|
| 525 | - $contexte[$var] = $val; |
|
| 526 | - } else { |
|
| 527 | - $args = explode('=', $val); |
|
| 528 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | - } else // notation abregee |
|
| 531 | - { |
|
| 532 | - $contexte[trim($val)] = trim($val); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } else { |
|
| 536 | - $contexte[$var] = $val; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $contexte; |
|
| 520 | + $contexte = []; |
|
| 521 | + foreach ($args as $var => $val) { |
|
| 522 | + if (is_int($var)) { // argument pas formate |
|
| 523 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | + $var = 'align'; |
|
| 525 | + $contexte[$var] = $val; |
|
| 526 | + } else { |
|
| 527 | + $args = explode('=', $val); |
|
| 528 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | + } else // notation abregee |
|
| 531 | + { |
|
| 532 | + $contexte[trim($val)] = trim($val); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } else { |
|
| 536 | + $contexte[$var] = $val; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $contexte; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -552,43 +552,43 @@ discard block |
||
| 552 | 552 | * @return string |
| 553 | 553 | */ |
| 554 | 554 | function styliser_modele($modele, $id, $contexte = null) { |
| 555 | - static $styliseurs = null; |
|
| 556 | - if (is_null($styliseurs)) { |
|
| 557 | - $tables_objet = lister_tables_objets_sql(); |
|
| 558 | - foreach ($tables_objet as $table => $desc) { |
|
| 559 | - if ( |
|
| 560 | - isset($desc['modeles']) and $desc['modeles'] |
|
| 561 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 562 | - and function_exists($desc['modeles_styliser']) |
|
| 563 | - ) { |
|
| 564 | - $primary = id_table_objet($table); |
|
| 565 | - foreach ($desc['modeles'] as $m) { |
|
| 566 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - if (isset($styliseurs[$modele])) { |
|
| 573 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 574 | - $primary = $styliseurs[$modele]['primary']; |
|
| 575 | - if (is_null($id) and $contexte) { |
|
| 576 | - if (isset($contexte['id'])) { |
|
| 577 | - $id = $contexte['id']; |
|
| 578 | - } elseif (isset($contexte[$primary])) { |
|
| 579 | - $id = $contexte[$primary]; |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - if (is_null($id)) { |
|
| 583 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 584 | - erreur_squelette($msg); |
|
| 585 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 586 | - $id = 0; |
|
| 587 | - } |
|
| 588 | - $modele = $styliseur($modele, $id); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - return $modele; |
|
| 555 | + static $styliseurs = null; |
|
| 556 | + if (is_null($styliseurs)) { |
|
| 557 | + $tables_objet = lister_tables_objets_sql(); |
|
| 558 | + foreach ($tables_objet as $table => $desc) { |
|
| 559 | + if ( |
|
| 560 | + isset($desc['modeles']) and $desc['modeles'] |
|
| 561 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 562 | + and function_exists($desc['modeles_styliser']) |
|
| 563 | + ) { |
|
| 564 | + $primary = id_table_objet($table); |
|
| 565 | + foreach ($desc['modeles'] as $m) { |
|
| 566 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + if (isset($styliseurs[$modele])) { |
|
| 573 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 574 | + $primary = $styliseurs[$modele]['primary']; |
|
| 575 | + if (is_null($id) and $contexte) { |
|
| 576 | + if (isset($contexte['id'])) { |
|
| 577 | + $id = $contexte['id']; |
|
| 578 | + } elseif (isset($contexte[$primary])) { |
|
| 579 | + $id = $contexte[$primary]; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + if (is_null($id)) { |
|
| 583 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 584 | + erreur_squelette($msg); |
|
| 585 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 586 | + $id = 0; |
|
| 587 | + } |
|
| 588 | + $modele = $styliseur($modele, $id); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + return $modele; |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -607,102 +607,102 @@ discard block |
||
| 607 | 607 | */ |
| 608 | 608 | function inclure_modele($type, $id, $params, $lien, string $connect = '', $env = []) { |
| 609 | 609 | |
| 610 | - static $compteur; |
|
| 611 | - if (++$compteur > 10) { |
|
| 612 | - return ''; |
|
| 613 | - } # ne pas boucler indefiniment |
|
| 614 | - |
|
| 615 | - $type = strtolower($type); |
|
| 616 | - $type = styliser_modele($type, $id); |
|
| 617 | - |
|
| 618 | - $fond = $class = ''; |
|
| 619 | - |
|
| 620 | - $params = array_filter(explode('|', $params)); |
|
| 621 | - if ($params) { |
|
| 622 | - $soustype = current($params); |
|
| 623 | - $soustype = strtolower(trim($soustype)); |
|
| 624 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 625 | - $soustype = next($params); |
|
| 626 | - $soustype = strtolower($soustype); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 630 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 631 | - $fond = ''; |
|
| 632 | - $class = $soustype; |
|
| 633 | - } |
|
| 634 | - // enlever le sous type des params |
|
| 635 | - $params = array_diff($params, [$soustype]); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 640 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 641 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 642 | - |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - $fond = 'modeles/' . $fond; |
|
| 646 | - // Creer le contexte |
|
| 647 | - $contexte = $env; |
|
| 648 | - $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 649 | - |
|
| 650 | - // Le numero du modele est mis dans l'environnement |
|
| 651 | - // d'une part sous l'identifiant "id" |
|
| 652 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 653 | - // par la fonction id_table_objet, |
|
| 654 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 655 | - $_id = id_table_objet($type); |
|
| 656 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 657 | - |
|
| 658 | - if (isset($class)) { |
|
| 659 | - $contexte['class'] = $class; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 663 | - if ($lien) { |
|
| 664 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 665 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 666 | - $contexte['lien_class'] = $lien['class']; |
|
| 667 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 668 | - $contexte['lien_title'] = $lien['title']; |
|
| 669 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - // Traiter les parametres |
|
| 673 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 674 | - $arg_list = creer_contexte_de_modele($params); |
|
| 675 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 676 | - $contexte = array_merge($contexte, $arg_list); |
|
| 677 | - |
|
| 678 | - // Appliquer le modele avec le contexte |
|
| 679 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 680 | - |
|
| 681 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 682 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 683 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 684 | - if ( |
|
| 685 | - strstr( |
|
| 686 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 687 | - 'spip_lien_ok' |
|
| 688 | - ) |
|
| 689 | - ) { |
|
| 690 | - $retour = inserer_attribut( |
|
| 691 | - $retour, |
|
| 692 | - 'class', |
|
| 693 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 694 | - ); |
|
| 695 | - } else { |
|
| 696 | - if ($lien) { |
|
| 697 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - $compteur--; |
|
| 702 | - |
|
| 703 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 704 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 705 | - : $retour; |
|
| 610 | + static $compteur; |
|
| 611 | + if (++$compteur > 10) { |
|
| 612 | + return ''; |
|
| 613 | + } # ne pas boucler indefiniment |
|
| 614 | + |
|
| 615 | + $type = strtolower($type); |
|
| 616 | + $type = styliser_modele($type, $id); |
|
| 617 | + |
|
| 618 | + $fond = $class = ''; |
|
| 619 | + |
|
| 620 | + $params = array_filter(explode('|', $params)); |
|
| 621 | + if ($params) { |
|
| 622 | + $soustype = current($params); |
|
| 623 | + $soustype = strtolower(trim($soustype)); |
|
| 624 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 625 | + $soustype = next($params); |
|
| 626 | + $soustype = strtolower($soustype); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 630 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 631 | + $fond = ''; |
|
| 632 | + $class = $soustype; |
|
| 633 | + } |
|
| 634 | + // enlever le sous type des params |
|
| 635 | + $params = array_diff($params, [$soustype]); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 640 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 641 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 642 | + |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + $fond = 'modeles/' . $fond; |
|
| 646 | + // Creer le contexte |
|
| 647 | + $contexte = $env; |
|
| 648 | + $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 649 | + |
|
| 650 | + // Le numero du modele est mis dans l'environnement |
|
| 651 | + // d'une part sous l'identifiant "id" |
|
| 652 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 653 | + // par la fonction id_table_objet, |
|
| 654 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 655 | + $_id = id_table_objet($type); |
|
| 656 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 657 | + |
|
| 658 | + if (isset($class)) { |
|
| 659 | + $contexte['class'] = $class; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 663 | + if ($lien) { |
|
| 664 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 665 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 666 | + $contexte['lien_class'] = $lien['class']; |
|
| 667 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 668 | + $contexte['lien_title'] = $lien['title']; |
|
| 669 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + // Traiter les parametres |
|
| 673 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 674 | + $arg_list = creer_contexte_de_modele($params); |
|
| 675 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 676 | + $contexte = array_merge($contexte, $arg_list); |
|
| 677 | + |
|
| 678 | + // Appliquer le modele avec le contexte |
|
| 679 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 680 | + |
|
| 681 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 682 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 683 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 684 | + if ( |
|
| 685 | + strstr( |
|
| 686 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 687 | + 'spip_lien_ok' |
|
| 688 | + ) |
|
| 689 | + ) { |
|
| 690 | + $retour = inserer_attribut( |
|
| 691 | + $retour, |
|
| 692 | + 'class', |
|
| 693 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 694 | + ); |
|
| 695 | + } else { |
|
| 696 | + if ($lien) { |
|
| 697 | + $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + $compteur--; |
|
| 702 | + |
|
| 703 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 704 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 705 | + : $retour; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -712,99 +712,99 @@ discard block |
||
| 712 | 712 | // https://code.spip.net/@evaluer_fond |
| 713 | 713 | function evaluer_fond($fond, $contexte = [], string $connect = '') { |
| 714 | 714 | |
| 715 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 716 | - |
|
| 717 | - if (!$page) { |
|
| 718 | - return $page; |
|
| 719 | - } |
|
| 720 | - // eval $page et affecte $res |
|
| 721 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 722 | - |
|
| 723 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 724 | - // a destination de public/parametrer |
|
| 725 | - // pour remonter vers les inclusions appelantes |
|
| 726 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 727 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 728 | - if ( |
|
| 729 | - isset($page['invalideurs']) |
|
| 730 | - and isset($page['invalideurs']['session']) |
|
| 731 | - ) { |
|
| 732 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - return $page; |
|
| 715 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 716 | + |
|
| 717 | + if (!$page) { |
|
| 718 | + return $page; |
|
| 719 | + } |
|
| 720 | + // eval $page et affecte $res |
|
| 721 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 722 | + |
|
| 723 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 724 | + // a destination de public/parametrer |
|
| 725 | + // pour remonter vers les inclusions appelantes |
|
| 726 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 727 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 728 | + if ( |
|
| 729 | + isset($page['invalideurs']) |
|
| 730 | + and isset($page['invalideurs']['session']) |
|
| 731 | + ) { |
|
| 732 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + return $page; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | // https://code.spip.net/@page_base_href |
| 740 | 740 | function page_base_href(&$texte) { |
| 741 | - static $set_html_base = null; |
|
| 742 | - if (is_null($set_html_base)) { |
|
| 743 | - if (!defined('_SET_HTML_BASE')) { |
|
| 744 | - // si la profondeur est superieure a 1 |
|
| 745 | - // est que ce n'est pas une url page ni une url action |
|
| 746 | - // activer par defaut |
|
| 747 | - $set_html_base = (( |
|
| 748 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 749 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 750 | - and !_request('action')) ? true : false); |
|
| 751 | - } else { |
|
| 752 | - $set_html_base = _SET_HTML_BASE; |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ( |
|
| 757 | - $set_html_base |
|
| 758 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 759 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 760 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 761 | - ) { |
|
| 762 | - $head = substr($texte, 0, $poshead); |
|
| 763 | - $insert = false; |
|
| 764 | - $href_base = false; |
|
| 765 | - if (strpos($head, '<base') === false) { |
|
| 766 | - $insert = true; |
|
| 767 | - } else { |
|
| 768 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 769 | - // sinon juste re-ecrire les ancres si besoin |
|
| 770 | - $insert = true; |
|
| 771 | - include_spip('inc/filtres'); |
|
| 772 | - $bases = extraire_balises($head, 'base'); |
|
| 773 | - foreach ($bases as $base) { |
|
| 774 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 775 | - $insert = false; |
|
| 776 | - break; |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - if ($insert) { |
|
| 782 | - include_spip('inc/filtres_mini'); |
|
| 783 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 784 | - $href_base = url_absolue('./'); |
|
| 785 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 786 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 787 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 788 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 789 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 790 | - } |
|
| 791 | - $texte = $head . substr($texte, $poshead); |
|
| 792 | - } |
|
| 793 | - if ($href_base) { |
|
| 794 | - // gerer les ancres |
|
| 795 | - $base = $_SERVER['REQUEST_URI']; |
|
| 796 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 797 | - if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 798 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 799 | - } |
|
| 800 | - if (strpos($texte, "href='#") !== false) { |
|
| 801 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 802 | - } |
|
| 803 | - if (strpos($texte, 'href="#') !== false) { |
|
| 804 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - } |
|
| 741 | + static $set_html_base = null; |
|
| 742 | + if (is_null($set_html_base)) { |
|
| 743 | + if (!defined('_SET_HTML_BASE')) { |
|
| 744 | + // si la profondeur est superieure a 1 |
|
| 745 | + // est que ce n'est pas une url page ni une url action |
|
| 746 | + // activer par defaut |
|
| 747 | + $set_html_base = (( |
|
| 748 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 749 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 750 | + and !_request('action')) ? true : false); |
|
| 751 | + } else { |
|
| 752 | + $set_html_base = _SET_HTML_BASE; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ( |
|
| 757 | + $set_html_base |
|
| 758 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 759 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 760 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 761 | + ) { |
|
| 762 | + $head = substr($texte, 0, $poshead); |
|
| 763 | + $insert = false; |
|
| 764 | + $href_base = false; |
|
| 765 | + if (strpos($head, '<base') === false) { |
|
| 766 | + $insert = true; |
|
| 767 | + } else { |
|
| 768 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 769 | + // sinon juste re-ecrire les ancres si besoin |
|
| 770 | + $insert = true; |
|
| 771 | + include_spip('inc/filtres'); |
|
| 772 | + $bases = extraire_balises($head, 'base'); |
|
| 773 | + foreach ($bases as $base) { |
|
| 774 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 775 | + $insert = false; |
|
| 776 | + break; |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + if ($insert) { |
|
| 782 | + include_spip('inc/filtres_mini'); |
|
| 783 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 784 | + $href_base = url_absolue('./'); |
|
| 785 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 786 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 787 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 788 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 789 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 790 | + } |
|
| 791 | + $texte = $head . substr($texte, $poshead); |
|
| 792 | + } |
|
| 793 | + if ($href_base) { |
|
| 794 | + // gerer les ancres |
|
| 795 | + $base = $_SERVER['REQUEST_URI']; |
|
| 796 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 797 | + if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 798 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 799 | + } |
|
| 800 | + if (strpos($texte, "href='#") !== false) { |
|
| 801 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 802 | + } |
|
| 803 | + if (strpos($texte, 'href="#') !== false) { |
|
| 804 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | // et demarrent par X-Spip-... |
| 813 | 813 | // https://code.spip.net/@envoyer_entetes |
| 814 | 814 | function envoyer_entetes($entetes) { |
| 815 | - foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 816 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 817 | - } |
|
| 815 | + foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 816 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 817 | + } |
|
| 818 | 818 | } |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1048576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = [ |
|
| 47 | - 'field' => [ |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ] |
|
| 52 | - ]; |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = [ |
|
| 47 | + 'field' => [ |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ] |
|
| 52 | + ]; |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,524 +62,524 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = []; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = []; |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = []) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind() : void { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = key($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return ['tableau']; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set( |
|
| 183 | - $cle, |
|
| 184 | - [ |
|
| 185 | - 'data' => $valeur, |
|
| 186 | - 'time' => time(), |
|
| 187 | - 'ttl' => $ttl |
|
| 188 | - ], |
|
| 189 | - 3600 + $ttl |
|
| 190 | - ); |
|
| 191 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Aller chercher les données de la boucle DATA |
|
| 197 | - * |
|
| 198 | - * @throws Exception |
|
| 199 | - * @param array $command |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - protected function select($command) { |
|
| 203 | - |
|
| 204 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | - // le type se retrouve dans la commande 'from' |
|
| 206 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | - if (isset($this->command['from'][0])) { |
|
| 208 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | - } |
|
| 211 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | - // les commandes connues pour l'iterateur DATA |
|
| 216 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | - |
|
| 218 | - // {source format, [URL], [arg2]...} |
|
| 219 | - if ( |
|
| 220 | - isset($this->command['source']) |
|
| 221 | - and isset($this->command['sourcemode']) |
|
| 222 | - ) { |
|
| 223 | - $this->select_source(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Critere {liste X1, X2, X3} |
|
| 227 | - if (isset($this->command['liste'])) { |
|
| 228 | - $this->select_liste(); |
|
| 229 | - } |
|
| 230 | - if (isset($this->command['enum'])) { |
|
| 231 | - $this->select_enum(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | - if (!is_array($this->tableau)) { |
|
| 236 | - $this->err = true; |
|
| 237 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // {datapath query.results} |
|
| 241 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | - if ( |
|
| 243 | - !$this->err |
|
| 244 | - and isset($this->command['datapath']) |
|
| 245 | - and is_array($this->command['datapath']) |
|
| 246 | - ) { |
|
| 247 | - $this->select_datapath(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // tri {par x} |
|
| 251 | - if ($this->command['orderby']) { |
|
| 252 | - $this->select_orderby(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | - if ($this->command['groupby']) { |
|
| 257 | - $this->select_groupby(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $this->rewind(); |
|
| 261 | - #var_dump($this->tableau); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Aller chercher les donnees de la boucle DATA |
|
| 267 | - * depuis une source |
|
| 268 | - * {source format, [URL], [arg2]...} |
|
| 269 | - */ |
|
| 270 | - protected function select_source() { |
|
| 271 | - # un peu crado : avant de charger le cache il faut charger |
|
| 272 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | - # l'objet en cache ; cf plugins/icalendar |
|
| 274 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | - if ( |
|
| 276 | - isset($this->command['sourcemode']) |
|
| 277 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | - ) { |
|
| 279 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - # le premier argument peut etre un array, une URL etc. |
|
| 283 | - $src = $this->command['source'][0]; |
|
| 284 | - |
|
| 285 | - # avons-nous un cache dispo ? |
|
| 286 | - $cle = null; |
|
| 287 | - if (is_string($src)) { |
|
| 288 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - $cache = $this->cache_get($cle); |
|
| 292 | - if (isset($this->command['datacache'])) { |
|
| 293 | - $ttl = intval($this->command['datacache']); |
|
| 294 | - } |
|
| 295 | - if ( |
|
| 296 | - $cache |
|
| 297 | - and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 298 | - > time()) |
|
| 299 | - and !(_request('var_mode') === 'recalcul' |
|
| 300 | - and include_spip('inc/autoriser') |
|
| 301 | - and autoriser('recalcul') |
|
| 302 | - ) |
|
| 303 | - ) { |
|
| 304 | - $this->tableau = $cache['data']; |
|
| 305 | - } else { |
|
| 306 | - try { |
|
| 307 | - if ( |
|
| 308 | - isset($this->command['sourcemode']) |
|
| 309 | - and in_array( |
|
| 310 | - $this->command['sourcemode'], |
|
| 311 | - ['table', 'array', 'tableau'] |
|
| 312 | - ) |
|
| 313 | - ) { |
|
| 314 | - if ( |
|
| 315 | - is_array($a = $src) |
|
| 316 | - or (is_string($a) |
|
| 317 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | - and is_array($a = @unserialize($a))) |
|
| 319 | - ) { |
|
| 320 | - $this->tableau = $a; |
|
| 321 | - } |
|
| 322 | - } else { |
|
| 323 | - $data = $src; |
|
| 324 | - if (is_string($src)) { |
|
| 325 | - if (tester_url_absolue($src)) { |
|
| 326 | - include_spip('inc/distant'); |
|
| 327 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | - $data = $data['page'] ?? ''; |
|
| 329 | - if (!$data) { |
|
| 330 | - throw new Exception('404'); |
|
| 331 | - } |
|
| 332 | - if (!isset($ttl)) { |
|
| 333 | - $ttl = 24 * 3600; |
|
| 334 | - } |
|
| 335 | - } elseif (@is_dir($src)) { |
|
| 336 | - $data = $src; |
|
| 337 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | - $data = spip_file_get_contents($src); |
|
| 339 | - } |
|
| 340 | - if (!isset($ttl)) { |
|
| 341 | - $ttl = 10; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ( |
|
| 346 | - !$this->err |
|
| 347 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | - ) { |
|
| 349 | - $args = $this->command['source']; |
|
| 350 | - $args[0] = $data; |
|
| 351 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | - $this->tableau = $a; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (!is_array($this->tableau)) { |
|
| 358 | - $this->err = true; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | - $this->cache_set($cle, $ttl); |
|
| 363 | - } |
|
| 364 | - } catch (Exception $e) { |
|
| 365 | - $e = $e->getMessage(); |
|
| 366 | - $err = sprintf( |
|
| 367 | - "[%s, %s] $e", |
|
| 368 | - $src, |
|
| 369 | - $this->command['sourcemode'] |
|
| 370 | - ); |
|
| 371 | - erreur_squelette([$err, []]); |
|
| 372 | - $this->err = true; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | - if ( |
|
| 378 | - $this->err |
|
| 379 | - and $cache |
|
| 380 | - ) { |
|
| 381 | - $this->tableau = $cache['data']; |
|
| 382 | - $this->err = false; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Retourne un tableau donne depuis un critère liste |
|
| 389 | - * |
|
| 390 | - * Critère `{liste X1, X2, X3}` |
|
| 391 | - * |
|
| 392 | - * @see critere_DATA_liste_dist() |
|
| 393 | - * |
|
| 394 | - **/ |
|
| 395 | - protected function select_liste() { |
|
| 396 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | - if (!isset($this->command['liste'][1])) { |
|
| 398 | - if (!is_array($this->command['liste'][0])) { |
|
| 399 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | - } else { |
|
| 401 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - $this->tableau = $this->command['liste']; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Retourne un tableau donne depuis un critere liste |
|
| 409 | - * Critere {enum Xmin, Xmax} |
|
| 410 | - * |
|
| 411 | - **/ |
|
| 412 | - protected function select_enum() { |
|
| 413 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | - if (!isset($this->command['enum'][1])) { |
|
| 415 | - if (!is_array($this->command['enum'][0])) { |
|
| 416 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | - } else { |
|
| 418 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - if (count($this->command['enum']) >= 3) { |
|
| 422 | - $enum = range( |
|
| 423 | - array_shift($this->command['enum']), |
|
| 424 | - array_shift($this->command['enum']), |
|
| 425 | - array_shift($this->command['enum']) |
|
| 426 | - ); |
|
| 427 | - } else { |
|
| 428 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | - } |
|
| 430 | - $this->tableau = $enum; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | - * {datapath query.results} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_datapath() { |
|
| 440 | - $base = reset($this->command['datapath']); |
|
| 441 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | - if (!is_array($this->tableau)) { |
|
| 444 | - $this->tableau = []; |
|
| 445 | - $this->err = true; |
|
| 446 | - spip_log("datapath '$base' absent"); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Ordonner les resultats |
|
| 453 | - * {par x} |
|
| 454 | - * |
|
| 455 | - **/ |
|
| 456 | - protected function select_orderby() { |
|
| 457 | - $sortfunc = ''; |
|
| 458 | - $aleas = 0; |
|
| 459 | - foreach ($this->command['orderby'] as $tri) { |
|
| 460 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | - $r = array_pad($r, 3, null); |
|
| 463 | - |
|
| 464 | - // tri par cle |
|
| 465 | - if ($r[1] == 'cle') { |
|
| 466 | - if (isset($r[2]) and $r[2]) { |
|
| 467 | - krsort($this->tableau); |
|
| 468 | - } else { |
|
| 469 | - ksort($this->tableau); |
|
| 470 | - } |
|
| 471 | - } # {par hasard} |
|
| 472 | - else { |
|
| 473 | - if ($r[1] == 'hasard') { |
|
| 474 | - $k = array_keys($this->tableau); |
|
| 475 | - shuffle($k); |
|
| 476 | - $v = []; |
|
| 477 | - foreach ($k as $cle) { |
|
| 478 | - $v[$cle] = $this->tableau[$cle]; |
|
| 479 | - } |
|
| 480 | - $this->tableau = $v; |
|
| 481 | - } else { |
|
| 482 | - # {par valeur} |
|
| 483 | - if ($r[1] == 'valeur') { |
|
| 484 | - $tv = '%s'; |
|
| 485 | - } # {par valeur/xx/yy} ?? |
|
| 486 | - else { |
|
| 487 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | - } |
|
| 489 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = []; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = []; |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = []) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind() : void { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = key($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return ['tableau']; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set( |
|
| 183 | + $cle, |
|
| 184 | + [ |
|
| 185 | + 'data' => $valeur, |
|
| 186 | + 'time' => time(), |
|
| 187 | + 'ttl' => $ttl |
|
| 188 | + ], |
|
| 189 | + 3600 + $ttl |
|
| 190 | + ); |
|
| 191 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Aller chercher les données de la boucle DATA |
|
| 197 | + * |
|
| 198 | + * @throws Exception |
|
| 199 | + * @param array $command |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + protected function select($command) { |
|
| 203 | + |
|
| 204 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | + // le type se retrouve dans la commande 'from' |
|
| 206 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | + if (isset($this->command['from'][0])) { |
|
| 208 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | + } |
|
| 211 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | + // les commandes connues pour l'iterateur DATA |
|
| 216 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | + |
|
| 218 | + // {source format, [URL], [arg2]...} |
|
| 219 | + if ( |
|
| 220 | + isset($this->command['source']) |
|
| 221 | + and isset($this->command['sourcemode']) |
|
| 222 | + ) { |
|
| 223 | + $this->select_source(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Critere {liste X1, X2, X3} |
|
| 227 | + if (isset($this->command['liste'])) { |
|
| 228 | + $this->select_liste(); |
|
| 229 | + } |
|
| 230 | + if (isset($this->command['enum'])) { |
|
| 231 | + $this->select_enum(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | + if (!is_array($this->tableau)) { |
|
| 236 | + $this->err = true; |
|
| 237 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // {datapath query.results} |
|
| 241 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | + if ( |
|
| 243 | + !$this->err |
|
| 244 | + and isset($this->command['datapath']) |
|
| 245 | + and is_array($this->command['datapath']) |
|
| 246 | + ) { |
|
| 247 | + $this->select_datapath(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // tri {par x} |
|
| 251 | + if ($this->command['orderby']) { |
|
| 252 | + $this->select_orderby(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | + if ($this->command['groupby']) { |
|
| 257 | + $this->select_groupby(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $this->rewind(); |
|
| 261 | + #var_dump($this->tableau); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Aller chercher les donnees de la boucle DATA |
|
| 267 | + * depuis une source |
|
| 268 | + * {source format, [URL], [arg2]...} |
|
| 269 | + */ |
|
| 270 | + protected function select_source() { |
|
| 271 | + # un peu crado : avant de charger le cache il faut charger |
|
| 272 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | + # l'objet en cache ; cf plugins/icalendar |
|
| 274 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | + if ( |
|
| 276 | + isset($this->command['sourcemode']) |
|
| 277 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | + ) { |
|
| 279 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + # le premier argument peut etre un array, une URL etc. |
|
| 283 | + $src = $this->command['source'][0]; |
|
| 284 | + |
|
| 285 | + # avons-nous un cache dispo ? |
|
| 286 | + $cle = null; |
|
| 287 | + if (is_string($src)) { |
|
| 288 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + $cache = $this->cache_get($cle); |
|
| 292 | + if (isset($this->command['datacache'])) { |
|
| 293 | + $ttl = intval($this->command['datacache']); |
|
| 294 | + } |
|
| 295 | + if ( |
|
| 296 | + $cache |
|
| 297 | + and ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 298 | + > time()) |
|
| 299 | + and !(_request('var_mode') === 'recalcul' |
|
| 300 | + and include_spip('inc/autoriser') |
|
| 301 | + and autoriser('recalcul') |
|
| 302 | + ) |
|
| 303 | + ) { |
|
| 304 | + $this->tableau = $cache['data']; |
|
| 305 | + } else { |
|
| 306 | + try { |
|
| 307 | + if ( |
|
| 308 | + isset($this->command['sourcemode']) |
|
| 309 | + and in_array( |
|
| 310 | + $this->command['sourcemode'], |
|
| 311 | + ['table', 'array', 'tableau'] |
|
| 312 | + ) |
|
| 313 | + ) { |
|
| 314 | + if ( |
|
| 315 | + is_array($a = $src) |
|
| 316 | + or (is_string($a) |
|
| 317 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | + and is_array($a = @unserialize($a))) |
|
| 319 | + ) { |
|
| 320 | + $this->tableau = $a; |
|
| 321 | + } |
|
| 322 | + } else { |
|
| 323 | + $data = $src; |
|
| 324 | + if (is_string($src)) { |
|
| 325 | + if (tester_url_absolue($src)) { |
|
| 326 | + include_spip('inc/distant'); |
|
| 327 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | + $data = $data['page'] ?? ''; |
|
| 329 | + if (!$data) { |
|
| 330 | + throw new Exception('404'); |
|
| 331 | + } |
|
| 332 | + if (!isset($ttl)) { |
|
| 333 | + $ttl = 24 * 3600; |
|
| 334 | + } |
|
| 335 | + } elseif (@is_dir($src)) { |
|
| 336 | + $data = $src; |
|
| 337 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | + $data = spip_file_get_contents($src); |
|
| 339 | + } |
|
| 340 | + if (!isset($ttl)) { |
|
| 341 | + $ttl = 10; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ( |
|
| 346 | + !$this->err |
|
| 347 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | + ) { |
|
| 349 | + $args = $this->command['source']; |
|
| 350 | + $args[0] = $data; |
|
| 351 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | + $this->tableau = $a; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!is_array($this->tableau)) { |
|
| 358 | + $this->err = true; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | + $this->cache_set($cle, $ttl); |
|
| 363 | + } |
|
| 364 | + } catch (Exception $e) { |
|
| 365 | + $e = $e->getMessage(); |
|
| 366 | + $err = sprintf( |
|
| 367 | + "[%s, %s] $e", |
|
| 368 | + $src, |
|
| 369 | + $this->command['sourcemode'] |
|
| 370 | + ); |
|
| 371 | + erreur_squelette([$err, []]); |
|
| 372 | + $this->err = true; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | + if ( |
|
| 378 | + $this->err |
|
| 379 | + and $cache |
|
| 380 | + ) { |
|
| 381 | + $this->tableau = $cache['data']; |
|
| 382 | + $this->err = false; |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Retourne un tableau donne depuis un critère liste |
|
| 389 | + * |
|
| 390 | + * Critère `{liste X1, X2, X3}` |
|
| 391 | + * |
|
| 392 | + * @see critere_DATA_liste_dist() |
|
| 393 | + * |
|
| 394 | + **/ |
|
| 395 | + protected function select_liste() { |
|
| 396 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | + if (!isset($this->command['liste'][1])) { |
|
| 398 | + if (!is_array($this->command['liste'][0])) { |
|
| 399 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | + } else { |
|
| 401 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + $this->tableau = $this->command['liste']; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Retourne un tableau donne depuis un critere liste |
|
| 409 | + * Critere {enum Xmin, Xmax} |
|
| 410 | + * |
|
| 411 | + **/ |
|
| 412 | + protected function select_enum() { |
|
| 413 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | + if (!isset($this->command['enum'][1])) { |
|
| 415 | + if (!is_array($this->command['enum'][0])) { |
|
| 416 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | + } else { |
|
| 418 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + if (count($this->command['enum']) >= 3) { |
|
| 422 | + $enum = range( |
|
| 423 | + array_shift($this->command['enum']), |
|
| 424 | + array_shift($this->command['enum']), |
|
| 425 | + array_shift($this->command['enum']) |
|
| 426 | + ); |
|
| 427 | + } else { |
|
| 428 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | + } |
|
| 430 | + $this->tableau = $enum; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | + * {datapath query.results} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_datapath() { |
|
| 440 | + $base = reset($this->command['datapath']); |
|
| 441 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | + if (!is_array($this->tableau)) { |
|
| 444 | + $this->tableau = []; |
|
| 445 | + $this->err = true; |
|
| 446 | + spip_log("datapath '$base' absent"); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Ordonner les resultats |
|
| 453 | + * {par x} |
|
| 454 | + * |
|
| 455 | + **/ |
|
| 456 | + protected function select_orderby() { |
|
| 457 | + $sortfunc = ''; |
|
| 458 | + $aleas = 0; |
|
| 459 | + foreach ($this->command['orderby'] as $tri) { |
|
| 460 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | + $r = array_pad($r, 3, null); |
|
| 463 | + |
|
| 464 | + // tri par cle |
|
| 465 | + if ($r[1] == 'cle') { |
|
| 466 | + if (isset($r[2]) and $r[2]) { |
|
| 467 | + krsort($this->tableau); |
|
| 468 | + } else { |
|
| 469 | + ksort($this->tableau); |
|
| 470 | + } |
|
| 471 | + } # {par hasard} |
|
| 472 | + else { |
|
| 473 | + if ($r[1] == 'hasard') { |
|
| 474 | + $k = array_keys($this->tableau); |
|
| 475 | + shuffle($k); |
|
| 476 | + $v = []; |
|
| 477 | + foreach ($k as $cle) { |
|
| 478 | + $v[$cle] = $this->tableau[$cle]; |
|
| 479 | + } |
|
| 480 | + $this->tableau = $v; |
|
| 481 | + } else { |
|
| 482 | + # {par valeur} |
|
| 483 | + if ($r[1] == 'valeur') { |
|
| 484 | + $tv = '%s'; |
|
| 485 | + } # {par valeur/xx/yy} ?? |
|
| 486 | + else { |
|
| 487 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | + } |
|
| 489 | + $sortfunc .= ' |
|
| 490 | 490 | $a = ' . sprintf($tv, '$aa') . '; |
| 491 | 491 | $b = ' . sprintf($tv, '$bb') . '; |
| 492 | 492 | if ($a <> $b) |
| 493 | 493 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 494 | - } |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - if ($sortfunc) { |
|
| 500 | - $sortfunc .= "\n return 0;"; |
|
| 501 | - uasort($this->tableau, function ($aa, $bb) use ($sortfunc) { |
|
| 502 | - return eval($sortfunc); |
|
| 503 | - }); |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Grouper les resultats |
|
| 510 | - * {fusion /x/y/z} |
|
| 511 | - * |
|
| 512 | - **/ |
|
| 513 | - protected function select_groupby() { |
|
| 514 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 515 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 516 | - $vu = []; |
|
| 517 | - foreach ($this->tableau as $k => $v) { |
|
| 518 | - $val = table_valeur($v, $fusion); |
|
| 519 | - if (isset($vu[$val])) { |
|
| 520 | - unset($this->tableau[$k]); |
|
| 521 | - } else { |
|
| 522 | - $vu[$val] = true; |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * L'iterateur est-il encore valide ? |
|
| 531 | - * |
|
| 532 | - * @return bool |
|
| 533 | - */ |
|
| 534 | - public function valid(): bool { |
|
| 535 | - return !is_null($this->cle); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Retourner la valeur |
|
| 540 | - * |
|
| 541 | - * @return mixed |
|
| 542 | - */ |
|
| 543 | - #[\ReturnTypeWillChange] |
|
| 544 | - public function current() { |
|
| 545 | - return $this->valeur; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Retourner la cle |
|
| 550 | - * |
|
| 551 | - * @return mixed |
|
| 552 | - */ |
|
| 553 | - #[\ReturnTypeWillChange] |
|
| 554 | - public function key() { |
|
| 555 | - return $this->cle; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Passer a la valeur suivante |
|
| 560 | - * |
|
| 561 | - * @return void |
|
| 562 | - */ |
|
| 563 | - public function next() : void { |
|
| 564 | - if ($this->valid()) { |
|
| 565 | - $this->cle = key($this->tableau); |
|
| 566 | - $this->valeur = current($this->tableau); |
|
| 567 | - next($this->tableau); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Compter le nombre total de resultats |
|
| 573 | - * |
|
| 574 | - * @return int |
|
| 575 | - */ |
|
| 576 | - public function count() { |
|
| 577 | - if (is_null($this->total)) { |
|
| 578 | - $this->total = count($this->tableau); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - return $this->total; |
|
| 582 | - } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + if ($sortfunc) { |
|
| 500 | + $sortfunc .= "\n return 0;"; |
|
| 501 | + uasort($this->tableau, function ($aa, $bb) use ($sortfunc) { |
|
| 502 | + return eval($sortfunc); |
|
| 503 | + }); |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Grouper les resultats |
|
| 510 | + * {fusion /x/y/z} |
|
| 511 | + * |
|
| 512 | + **/ |
|
| 513 | + protected function select_groupby() { |
|
| 514 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 515 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 516 | + $vu = []; |
|
| 517 | + foreach ($this->tableau as $k => $v) { |
|
| 518 | + $val = table_valeur($v, $fusion); |
|
| 519 | + if (isset($vu[$val])) { |
|
| 520 | + unset($this->tableau[$k]); |
|
| 521 | + } else { |
|
| 522 | + $vu[$val] = true; |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * L'iterateur est-il encore valide ? |
|
| 531 | + * |
|
| 532 | + * @return bool |
|
| 533 | + */ |
|
| 534 | + public function valid(): bool { |
|
| 535 | + return !is_null($this->cle); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Retourner la valeur |
|
| 540 | + * |
|
| 541 | + * @return mixed |
|
| 542 | + */ |
|
| 543 | + #[\ReturnTypeWillChange] |
|
| 544 | + public function current() { |
|
| 545 | + return $this->valeur; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Retourner la cle |
|
| 550 | + * |
|
| 551 | + * @return mixed |
|
| 552 | + */ |
|
| 553 | + #[\ReturnTypeWillChange] |
|
| 554 | + public function key() { |
|
| 555 | + return $this->cle; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * Passer a la valeur suivante |
|
| 560 | + * |
|
| 561 | + * @return void |
|
| 562 | + */ |
|
| 563 | + public function next() : void { |
|
| 564 | + if ($this->valid()) { |
|
| 565 | + $this->cle = key($this->tableau); |
|
| 566 | + $this->valeur = current($this->tableau); |
|
| 567 | + next($this->tableau); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Compter le nombre total de resultats |
|
| 573 | + * |
|
| 574 | + * @return int |
|
| 575 | + */ |
|
| 576 | + public function count() { |
|
| 577 | + if (is_null($this->total)) { |
|
| 578 | + $this->total = count($this->tableau); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + return $this->total; |
|
| 582 | + } |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | /* |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | * @return array |
| 594 | 594 | */ |
| 595 | 595 | function inc_file_to_array_dist($data) { |
| 596 | - return preg_split('/\r?\n/', $data); |
|
| 596 | + return preg_split('/\r?\n/', $data); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -602,9 +602,9 @@ discard block |
||
| 602 | 602 | * @return array |
| 603 | 603 | */ |
| 604 | 604 | function inc_plugins_to_array_dist() { |
| 605 | - include_spip('inc/plugin'); |
|
| 605 | + include_spip('inc/plugin'); |
|
| 606 | 606 | |
| 607 | - return liste_chemin_plugin_actifs(); |
|
| 607 | + return liste_chemin_plugin_actifs(); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | * @return array |
| 615 | 615 | */ |
| 616 | 616 | function inc_xml_to_array_dist($data) { |
| 617 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 617 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -626,14 +626,14 @@ discard block |
||
| 626 | 626 | * |
| 627 | 627 | */ |
| 628 | 628 | function inc_object_to_array($object) { |
| 629 | - if (!is_object($object) && !is_array($object)) { |
|
| 630 | - return $object; |
|
| 631 | - } |
|
| 632 | - if (is_object($object)) { |
|
| 633 | - $object = get_object_vars($object); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - return array_map('inc_object_to_array', $object); |
|
| 629 | + if (!is_object($object) && !is_array($object)) { |
|
| 630 | + return $object; |
|
| 631 | + } |
|
| 632 | + if (is_object($object)) { |
|
| 633 | + $object = get_object_vars($object); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + return array_map('inc_object_to_array', $object); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
@@ -643,20 +643,20 @@ discard block |
||
| 643 | 643 | * @return array|bool |
| 644 | 644 | */ |
| 645 | 645 | function inc_sql_to_array_dist($data) { |
| 646 | - # sortir le connecteur de $data |
|
| 647 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 648 | - $serveur = (string)$v[1]; |
|
| 649 | - $req = trim($v[2]); |
|
| 650 | - if ($s = sql_query($req, $serveur)) { |
|
| 651 | - $r = []; |
|
| 652 | - while ($t = sql_fetch($s)) { |
|
| 653 | - $r[] = $t; |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - return $r; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - return false; |
|
| 646 | + # sortir le connecteur de $data |
|
| 647 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 648 | + $serveur = (string)$v[1]; |
|
| 649 | + $req = trim($v[2]); |
|
| 650 | + if ($s = sql_query($req, $serveur)) { |
|
| 651 | + $r = []; |
|
| 652 | + while ($t = sql_fetch($s)) { |
|
| 653 | + $r[] = $t; |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + return $r; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + return false; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
@@ -666,9 +666,9 @@ discard block |
||
| 666 | 666 | * @return array|bool |
| 667 | 667 | */ |
| 668 | 668 | function inc_json_to_array_dist($data) { |
| 669 | - if (is_array($json = json_decode($data, true))) { |
|
| 670 | - return (array)$json; |
|
| 671 | - } |
|
| 669 | + if (is_array($json = json_decode($data, true))) { |
|
| 670 | + return (array)$json; |
|
| 671 | + } |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -678,30 +678,30 @@ discard block |
||
| 678 | 678 | * @return array|bool |
| 679 | 679 | */ |
| 680 | 680 | function inc_csv_to_array_dist($data) { |
| 681 | - include_spip('inc/csv'); |
|
| 682 | - list($entete, $csv) = analyse_csv($data); |
|
| 683 | - array_unshift($csv, $entete); |
|
| 684 | - |
|
| 685 | - include_spip('inc/charsets'); |
|
| 686 | - $i = 1; |
|
| 687 | - foreach ($entete as $k => $v) { |
|
| 688 | - if (trim($v) == '') { |
|
| 689 | - $v = 'col' . $i; |
|
| 690 | - } // reperer des eventuelles cases vides |
|
| 691 | - if (is_numeric($v) and $v < 0) { |
|
| 692 | - $v = '__' . $v; |
|
| 693 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 694 | - if (is_numeric($v)) { |
|
| 695 | - $v = '_' . $v; |
|
| 696 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 697 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 698 | - foreach ($csv as &$item) { |
|
| 699 | - $item[$v] = &$item[$k]; |
|
| 700 | - } |
|
| 701 | - $i++; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - return $csv; |
|
| 681 | + include_spip('inc/csv'); |
|
| 682 | + list($entete, $csv) = analyse_csv($data); |
|
| 683 | + array_unshift($csv, $entete); |
|
| 684 | + |
|
| 685 | + include_spip('inc/charsets'); |
|
| 686 | + $i = 1; |
|
| 687 | + foreach ($entete as $k => $v) { |
|
| 688 | + if (trim($v) == '') { |
|
| 689 | + $v = 'col' . $i; |
|
| 690 | + } // reperer des eventuelles cases vides |
|
| 691 | + if (is_numeric($v) and $v < 0) { |
|
| 692 | + $v = '__' . $v; |
|
| 693 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 694 | + if (is_numeric($v)) { |
|
| 695 | + $v = '_' . $v; |
|
| 696 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 697 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 698 | + foreach ($csv as &$item) { |
|
| 699 | + $item[$v] = &$item[$k]; |
|
| 700 | + } |
|
| 701 | + $i++; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + return $csv; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
@@ -711,12 +711,12 @@ discard block |
||
| 711 | 711 | * @return array|bool |
| 712 | 712 | */ |
| 713 | 713 | function inc_rss_to_array_dist($data) { |
| 714 | - include_spip('inc/syndic'); |
|
| 715 | - if (is_array($rss = analyser_backend($data))) { |
|
| 716 | - $tableau = $rss; |
|
| 717 | - } |
|
| 714 | + include_spip('inc/syndic'); |
|
| 715 | + if (is_array($rss = analyser_backend($data))) { |
|
| 716 | + $tableau = $rss; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - return $tableau; |
|
| 719 | + return $tableau; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | /** |
@@ -726,9 +726,9 @@ discard block |
||
| 726 | 726 | * @return array|bool |
| 727 | 727 | */ |
| 728 | 728 | function inc_atom_to_array_dist($data) { |
| 729 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 729 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 730 | 730 | |
| 731 | - return $rss_to_array($data); |
|
| 731 | + return $rss_to_array($data); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -739,12 +739,12 @@ discard block |
||
| 739 | 739 | * @return array|bool |
| 740 | 740 | */ |
| 741 | 741 | function inc_glob_to_array_dist($data) { |
| 742 | - $a = glob( |
|
| 743 | - $data, |
|
| 744 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 745 | - ); |
|
| 742 | + $a = glob( |
|
| 743 | + $data, |
|
| 744 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 745 | + ); |
|
| 746 | 746 | |
| 747 | - return $a ? $a : []; |
|
| 747 | + return $a ? $a : []; |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | /** |
@@ -755,14 +755,14 @@ discard block |
||
| 755 | 755 | * @throws Exception |
| 756 | 756 | */ |
| 757 | 757 | function inc_yaml_to_array_dist($data) { |
| 758 | - include_spip('inc/yaml-mini'); |
|
| 759 | - if (!function_exists('yaml_decode')) { |
|
| 760 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 758 | + include_spip('inc/yaml-mini'); |
|
| 759 | + if (!function_exists('yaml_decode')) { |
|
| 760 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 761 | 761 | |
| 762 | - return false; |
|
| 763 | - } |
|
| 762 | + return false; |
|
| 763 | + } |
|
| 764 | 764 | |
| 765 | - return yaml_decode($data); |
|
| 765 | + return yaml_decode($data); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | * @return array|bool |
| 778 | 778 | */ |
| 779 | 779 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 780 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 780 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | /** |
@@ -789,23 +789,23 @@ discard block |
||
| 789 | 789 | * @return array|bool |
| 790 | 790 | */ |
| 791 | 791 | function inc_ls_to_array_dist($data) { |
| 792 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 793 | - $a = $glob_to_array($data); |
|
| 794 | - foreach ($a as &$v) { |
|
| 795 | - $b = (array)@stat($v); |
|
| 796 | - foreach ($b as $k => $ignore) { |
|
| 797 | - if (is_numeric($k)) { |
|
| 798 | - unset($b[$k]); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 802 | - $v = array_merge( |
|
| 803 | - pathinfo($v), |
|
| 804 | - $b |
|
| 805 | - ); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - return $a; |
|
| 792 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 793 | + $a = $glob_to_array($data); |
|
| 794 | + foreach ($a as &$v) { |
|
| 795 | + $b = (array)@stat($v); |
|
| 796 | + foreach ($b as $k => $ignore) { |
|
| 797 | + if (is_numeric($k)) { |
|
| 798 | + unset($b[$k]); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 802 | + $v = array_merge( |
|
| 803 | + pathinfo($v), |
|
| 804 | + $b |
|
| 805 | + ); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + return $a; |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /** |
@@ -815,25 +815,25 @@ discard block |
||
| 815 | 815 | * @return array|bool |
| 816 | 816 | */ |
| 817 | 817 | function XMLObjectToArray($object) { |
| 818 | - $xml_array = []; |
|
| 819 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 820 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 821 | - $key .= '-' . uniqid(); |
|
| 822 | - } |
|
| 823 | - $vars = get_object_vars($object->current()); |
|
| 824 | - if (isset($vars['@attributes'])) { |
|
| 825 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 826 | - $xml_array[$key][$k] = $v; |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - if ($object->hasChildren()) { |
|
| 830 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 831 | - $object->current() |
|
| 832 | - ); |
|
| 833 | - } else { |
|
| 834 | - $xml_array[$key][] = strval($object->current()); |
|
| 835 | - } |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - return $xml_array; |
|
| 818 | + $xml_array = []; |
|
| 819 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 820 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 821 | + $key .= '-' . uniqid(); |
|
| 822 | + } |
|
| 823 | + $vars = get_object_vars($object->current()); |
|
| 824 | + if (isset($vars['@attributes'])) { |
|
| 825 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 826 | + $xml_array[$key][$k] = $v; |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + if ($object->hasChildren()) { |
|
| 830 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 831 | + $object->current() |
|
| 832 | + ); |
|
| 833 | + } else { |
|
| 834 | + $xml_array[$key][] = strval($object->current()); |
|
| 835 | + } |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + return $xml_array; |
|
| 839 | 839 | } |
@@ -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 | |
@@ -28,210 +28,210 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | class IterateurSQL implements Iterator { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * ressource sql |
|
| 33 | - * |
|
| 34 | - * @var resource|bool |
|
| 35 | - */ |
|
| 36 | - protected $sqlresult = false; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * row sql courante |
|
| 40 | - * |
|
| 41 | - * @var array|null |
|
| 42 | - */ |
|
| 43 | - protected $row = null; |
|
| 44 | - |
|
| 45 | - protected $firstseek = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Erreur presente ? |
|
| 49 | - * |
|
| 50 | - * @var bool |
|
| 51 | - **/ |
|
| 52 | - public $err = false; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Calcul du total des elements |
|
| 56 | - * |
|
| 57 | - * @var int|null |
|
| 58 | - **/ |
|
| 59 | - public $total = null; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * selectionner les donnees, ie faire la requete SQL |
|
| 63 | - * |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - protected function select() { |
|
| 67 | - $this->row = null; |
|
| 68 | - $v = &$this->command; |
|
| 69 | - $this->sqlresult = calculer_select( |
|
| 70 | - $v['select'], |
|
| 71 | - $v['from'], |
|
| 72 | - $v['type'], |
|
| 73 | - $v['where'], |
|
| 74 | - $v['join'], |
|
| 75 | - $v['groupby'], |
|
| 76 | - $v['orderby'], |
|
| 77 | - $v['limit'], |
|
| 78 | - $v['having'], |
|
| 79 | - $v['table'], |
|
| 80 | - $v['id'], |
|
| 81 | - $v['connect'], |
|
| 82 | - $this->info |
|
| 83 | - ); |
|
| 84 | - $this->err = !$this->sqlresult; |
|
| 85 | - $this->firstseek = false; |
|
| 86 | - $this->pos = -1; |
|
| 87 | - |
|
| 88 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 89 | - //$this->total = $this->count(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /* |
|
| 31 | + /** |
|
| 32 | + * ressource sql |
|
| 33 | + * |
|
| 34 | + * @var resource|bool |
|
| 35 | + */ |
|
| 36 | + protected $sqlresult = false; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * row sql courante |
|
| 40 | + * |
|
| 41 | + * @var array|null |
|
| 42 | + */ |
|
| 43 | + protected $row = null; |
|
| 44 | + |
|
| 45 | + protected $firstseek = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Erreur presente ? |
|
| 49 | + * |
|
| 50 | + * @var bool |
|
| 51 | + **/ |
|
| 52 | + public $err = false; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Calcul du total des elements |
|
| 56 | + * |
|
| 57 | + * @var int|null |
|
| 58 | + **/ |
|
| 59 | + public $total = null; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * selectionner les donnees, ie faire la requete SQL |
|
| 63 | + * |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + protected function select() { |
|
| 67 | + $this->row = null; |
|
| 68 | + $v = &$this->command; |
|
| 69 | + $this->sqlresult = calculer_select( |
|
| 70 | + $v['select'], |
|
| 71 | + $v['from'], |
|
| 72 | + $v['type'], |
|
| 73 | + $v['where'], |
|
| 74 | + $v['join'], |
|
| 75 | + $v['groupby'], |
|
| 76 | + $v['orderby'], |
|
| 77 | + $v['limit'], |
|
| 78 | + $v['having'], |
|
| 79 | + $v['table'], |
|
| 80 | + $v['id'], |
|
| 81 | + $v['connect'], |
|
| 82 | + $this->info |
|
| 83 | + ); |
|
| 84 | + $this->err = !$this->sqlresult; |
|
| 85 | + $this->firstseek = false; |
|
| 86 | + $this->pos = -1; |
|
| 87 | + |
|
| 88 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 89 | + //$this->total = $this->count(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /* |
|
| 93 | 93 | * array command: les commandes d'initialisation |
| 94 | 94 | * array info: les infos sur le squelette |
| 95 | 95 | */ |
| 96 | - public function __construct($command, $info = []) { |
|
| 97 | - $this->type = 'SQL'; |
|
| 98 | - $this->command = $command; |
|
| 99 | - $this->info = $info; |
|
| 100 | - $this->select(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Rembobiner |
|
| 105 | - * |
|
| 106 | - * @return bool |
|
| 107 | - */ |
|
| 108 | - public function rewind() : void { |
|
| 109 | - if ($this->pos > 0) { |
|
| 110 | - $this->seek(0); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Verifier l'etat de l'iterateur |
|
| 116 | - * |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - public function valid(): bool { |
|
| 120 | - if ($this->err) { |
|
| 121 | - return false; |
|
| 122 | - } |
|
| 123 | - if (!$this->firstseek) { |
|
| 124 | - $this->next(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return is_array($this->row); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Valeurs sur la position courante |
|
| 132 | - * |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - #[\ReturnTypeWillChange] |
|
| 136 | - public function current() { |
|
| 137 | - return $this->row; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - #[\ReturnTypeWillChange] |
|
| 141 | - public function key() { |
|
| 142 | - return $this->pos; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Sauter a une position absolue |
|
| 147 | - * |
|
| 148 | - * @param int $n |
|
| 149 | - * @param null|string $continue |
|
| 150 | - * @return bool |
|
| 151 | - */ |
|
| 152 | - public function seek($n = 0, $continue = null) { |
|
| 153 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 154 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 155 | - // si la position courante est apres la position visee |
|
| 156 | - // il faut relancer la requete |
|
| 157 | - if ($this->pos > $n) { |
|
| 158 | - $this->free(); |
|
| 159 | - $this->select(); |
|
| 160 | - $this->valid(); |
|
| 161 | - } |
|
| 162 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 163 | - // (sera fait en cas d'echec de cette fonction) |
|
| 164 | - return false; |
|
| 165 | - } |
|
| 166 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 167 | - $this->pos = min($n, $this->count()); |
|
| 168 | - |
|
| 169 | - return true; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Avancer d'un cran |
|
| 174 | - * |
|
| 175 | - * @return void |
|
| 176 | - */ |
|
| 177 | - public function next() : void { |
|
| 178 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 179 | - $this->pos++; |
|
| 180 | - $this->firstseek |= true; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Avancer et retourner les donnees pour le nouvel element |
|
| 185 | - * |
|
| 186 | - * @return array|bool|null |
|
| 187 | - */ |
|
| 188 | - public function fetch() { |
|
| 189 | - if ($this->valid()) { |
|
| 190 | - $r = $this->current(); |
|
| 191 | - $this->next(); |
|
| 192 | - } else { |
|
| 193 | - $r = false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return $r; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * liberer les ressources |
|
| 201 | - * |
|
| 202 | - * @return bool |
|
| 203 | - */ |
|
| 204 | - public function free() { |
|
| 205 | - if (!$this->sqlresult) { |
|
| 206 | - return true; |
|
| 207 | - } |
|
| 208 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 209 | - $this->sqlresult = null; |
|
| 210 | - |
|
| 211 | - return $a; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Compter le nombre de resultats |
|
| 216 | - * |
|
| 217 | - * @return int |
|
| 218 | - */ |
|
| 219 | - public function count() { |
|
| 220 | - if (is_null($this->total)) { |
|
| 221 | - if (!$this->sqlresult) { |
|
| 222 | - $this->total = 0; |
|
| 223 | - } else { |
|
| 224 | - # cas count(*) |
|
| 225 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 226 | - $this->valid(); |
|
| 227 | - $s = $this->current(); |
|
| 228 | - $this->total = $s['count(*)']; |
|
| 229 | - } else { |
|
| 230 | - $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $this->total; |
|
| 236 | - } |
|
| 96 | + public function __construct($command, $info = []) { |
|
| 97 | + $this->type = 'SQL'; |
|
| 98 | + $this->command = $command; |
|
| 99 | + $this->info = $info; |
|
| 100 | + $this->select(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Rembobiner |
|
| 105 | + * |
|
| 106 | + * @return bool |
|
| 107 | + */ |
|
| 108 | + public function rewind() : void { |
|
| 109 | + if ($this->pos > 0) { |
|
| 110 | + $this->seek(0); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Verifier l'etat de l'iterateur |
|
| 116 | + * |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + public function valid(): bool { |
|
| 120 | + if ($this->err) { |
|
| 121 | + return false; |
|
| 122 | + } |
|
| 123 | + if (!$this->firstseek) { |
|
| 124 | + $this->next(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return is_array($this->row); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Valeurs sur la position courante |
|
| 132 | + * |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + #[\ReturnTypeWillChange] |
|
| 136 | + public function current() { |
|
| 137 | + return $this->row; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + #[\ReturnTypeWillChange] |
|
| 141 | + public function key() { |
|
| 142 | + return $this->pos; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Sauter a une position absolue |
|
| 147 | + * |
|
| 148 | + * @param int $n |
|
| 149 | + * @param null|string $continue |
|
| 150 | + * @return bool |
|
| 151 | + */ |
|
| 152 | + public function seek($n = 0, $continue = null) { |
|
| 153 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 154 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 155 | + // si la position courante est apres la position visee |
|
| 156 | + // il faut relancer la requete |
|
| 157 | + if ($this->pos > $n) { |
|
| 158 | + $this->free(); |
|
| 159 | + $this->select(); |
|
| 160 | + $this->valid(); |
|
| 161 | + } |
|
| 162 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 163 | + // (sera fait en cas d'echec de cette fonction) |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 166 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 167 | + $this->pos = min($n, $this->count()); |
|
| 168 | + |
|
| 169 | + return true; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Avancer d'un cran |
|
| 174 | + * |
|
| 175 | + * @return void |
|
| 176 | + */ |
|
| 177 | + public function next() : void { |
|
| 178 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 179 | + $this->pos++; |
|
| 180 | + $this->firstseek |= true; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Avancer et retourner les donnees pour le nouvel element |
|
| 185 | + * |
|
| 186 | + * @return array|bool|null |
|
| 187 | + */ |
|
| 188 | + public function fetch() { |
|
| 189 | + if ($this->valid()) { |
|
| 190 | + $r = $this->current(); |
|
| 191 | + $this->next(); |
|
| 192 | + } else { |
|
| 193 | + $r = false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return $r; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * liberer les ressources |
|
| 201 | + * |
|
| 202 | + * @return bool |
|
| 203 | + */ |
|
| 204 | + public function free() { |
|
| 205 | + if (!$this->sqlresult) { |
|
| 206 | + return true; |
|
| 207 | + } |
|
| 208 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 209 | + $this->sqlresult = null; |
|
| 210 | + |
|
| 211 | + return $a; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Compter le nombre de resultats |
|
| 216 | + * |
|
| 217 | + * @return int |
|
| 218 | + */ |
|
| 219 | + public function count() { |
|
| 220 | + if (is_null($this->total)) { |
|
| 221 | + if (!$this->sqlresult) { |
|
| 222 | + $this->total = 0; |
|
| 223 | + } else { |
|
| 224 | + # cas count(*) |
|
| 225 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 226 | + $this->valid(); |
|
| 227 | + $s = $this->current(); |
|
| 228 | + $this->total = $s['count(*)']; |
|
| 229 | + } else { |
|
| 230 | + $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $this->total; |
|
| 236 | + } |
|
| 237 | 237 | } |
@@ -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 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 26 | 26 | // ne pas ecraser une definition perso dans mes_options |
| 27 | 27 | if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) { |
| 28 | - $GLOBALS['ldap_attributes'] = [ |
|
| 29 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | - 'nom' => 'cn', |
|
| 31 | - 'email' => 'mail', |
|
| 32 | - 'bio' => 'description' |
|
| 33 | - ]; |
|
| 28 | + $GLOBALS['ldap_attributes'] = [ |
|
| 29 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 30 | + 'nom' => 'cn', |
|
| 31 | + 'email' => 'mail', |
|
| 32 | + 'bio' => 'description' |
|
| 33 | + ]; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -56,50 +56,50 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | function auth_ldap_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 58 | 58 | |
| 59 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | - |
|
| 61 | - // Utilisateur connu ? |
|
| 62 | - // si http auth, inutile de reauthentifier: cela |
|
| 63 | - // ne marchera pas avec auth http autre que basic. |
|
| 64 | - $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 68 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | - |
|
| 70 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | - |
|
| 73 | - if ($r) { |
|
| 74 | - return array_merge($r, $credentials_ldap); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // sinon importer les infos depuis LDAP, |
|
| 78 | - |
|
| 79 | - if ( |
|
| 80 | - $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | - and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | - ) { |
|
| 83 | - // rajouter le statut indique a l'install |
|
| 84 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | - $desc['login'] = $login; |
|
| 86 | - $desc['source'] = 'ldap'; |
|
| 87 | - $desc['pass'] = ''; |
|
| 88 | - |
|
| 89 | - $r = sql_insertq('spip_auteurs', $desc, '', $serveur); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - if ($r) { |
|
| 93 | - return array_merge( |
|
| 94 | - $credentials_ldap, |
|
| 95 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | - ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // sinon echec |
|
| 100 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | - |
|
| 102 | - return []; |
|
| 59 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 60 | + |
|
| 61 | + // Utilisateur connu ? |
|
| 62 | + // si http auth, inutile de reauthentifier: cela |
|
| 63 | + // ne marchera pas avec auth http autre que basic. |
|
| 64 | + $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 65 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 69 | + |
|
| 70 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 71 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | + |
|
| 73 | + if ($r) { |
|
| 74 | + return array_merge($r, $credentials_ldap); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // sinon importer les infos depuis LDAP, |
|
| 78 | + |
|
| 79 | + if ( |
|
| 80 | + $GLOBALS['meta']['ldap_statut_import'] |
|
| 81 | + and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 82 | + ) { |
|
| 83 | + // rajouter le statut indique a l'install |
|
| 84 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 85 | + $desc['login'] = $login; |
|
| 86 | + $desc['source'] = 'ldap'; |
|
| 87 | + $desc['pass'] = ''; |
|
| 88 | + |
|
| 89 | + $r = sql_insertq('spip_auteurs', $desc, '', $serveur); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + if ($r) { |
|
| 93 | + return array_merge( |
|
| 94 | + $credentials_ldap, |
|
| 95 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 96 | + ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // sinon echec |
|
| 100 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 101 | + |
|
| 102 | + return []; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -113,36 +113,36 @@ discard block |
||
| 113 | 113 | * @return array |
| 114 | 114 | */ |
| 115 | 115 | function auth_ldap_connect($serveur = '') { |
| 116 | - include_spip('base/connect_sql'); |
|
| 117 | - static $connexions_ldap = []; |
|
| 118 | - if (isset($connexions_ldap[$serveur])) { |
|
| 119 | - return $connexions_ldap[$serveur]; |
|
| 120 | - } |
|
| 121 | - $connexion = spip_connect($serveur); |
|
| 122 | - if (!is_array($connexion['ldap'])) { |
|
| 123 | - if ($connexion['authentification']['ldap']) { |
|
| 124 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | - unset($GLOBALS['ldap_link']); |
|
| 126 | - if (is_readable($f)) { |
|
| 127 | - include_once($f); |
|
| 128 | - }; |
|
| 129 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | - $connexion['ldap'] = [ |
|
| 131 | - 'link' => $GLOBALS['ldap_link'], |
|
| 132 | - 'base' => $GLOBALS['ldap_base'] |
|
| 133 | - ]; |
|
| 134 | - } else { |
|
| 135 | - spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | - } |
|
| 137 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | - } |
|
| 140 | - } else { |
|
| 141 | - spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 116 | + include_spip('base/connect_sql'); |
|
| 117 | + static $connexions_ldap = []; |
|
| 118 | + if (isset($connexions_ldap[$serveur])) { |
|
| 119 | + return $connexions_ldap[$serveur]; |
|
| 120 | + } |
|
| 121 | + $connexion = spip_connect($serveur); |
|
| 122 | + if (!is_array($connexion['ldap'])) { |
|
| 123 | + if ($connexion['authentification']['ldap']) { |
|
| 124 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 125 | + unset($GLOBALS['ldap_link']); |
|
| 126 | + if (is_readable($f)) { |
|
| 127 | + include_once($f); |
|
| 128 | + }; |
|
| 129 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 130 | + $connexion['ldap'] = [ |
|
| 131 | + 'link' => $GLOBALS['ldap_link'], |
|
| 132 | + 'base' => $GLOBALS['ldap_base'] |
|
| 133 | + ]; |
|
| 134 | + } else { |
|
| 135 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 136 | + } |
|
| 137 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 138 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 139 | + } |
|
| 140 | + } else { |
|
| 141 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -156,52 +156,52 @@ discard block |
||
| 156 | 156 | * Le login trouvé ou chaine vide si non trouvé |
| 157 | 157 | */ |
| 158 | 158 | function auth_ldap_search($login, $pass, $checkpass = true, $serveur = '') { |
| 159 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | - if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | - return ''; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // verifier la connexion |
|
| 166 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | - return ''; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ldap_link = $ldap['link'] ?? null; |
|
| 171 | - $ldap_base = $ldap['base'] ?? null; |
|
| 172 | - $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 173 | - |
|
| 174 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | - |
|
| 176 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | - foreach ($logins as $att) { |
|
| 178 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | - // (on veut un attribut unique) |
|
| 182 | - |
|
| 183 | - if (is_array($info) and $info['count'] == 1) { |
|
| 184 | - $dn = $info[0]['dn']; |
|
| 185 | - if (!$checkpass) { |
|
| 186 | - return $dn; |
|
| 187 | - } |
|
| 188 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | - return $dn; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($checkpass and !isset($dn)) { |
|
| 195 | - // Si echec, essayer de deviner le DN |
|
| 196 | - foreach ($logins as $att) { |
|
| 197 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | - return "$att=$login_search, $ldap_base"; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return ''; |
|
| 159 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 160 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 161 | + if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 162 | + return ''; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // verifier la connexion |
|
| 166 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 167 | + return ''; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ldap_link = $ldap['link'] ?? null; |
|
| 171 | + $ldap_base = $ldap['base'] ?? null; |
|
| 172 | + $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 173 | + |
|
| 174 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 175 | + |
|
| 176 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 177 | + foreach ($logins as $att) { |
|
| 178 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 179 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 180 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 181 | + // (on veut un attribut unique) |
|
| 182 | + |
|
| 183 | + if (is_array($info) and $info['count'] == 1) { |
|
| 184 | + $dn = $info[0]['dn']; |
|
| 185 | + if (!$checkpass) { |
|
| 186 | + return $dn; |
|
| 187 | + } |
|
| 188 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 189 | + return $dn; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($checkpass and !isset($dn)) { |
|
| 195 | + // Si echec, essayer de deviner le DN |
|
| 196 | + foreach ($logins as $att) { |
|
| 197 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 198 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 199 | + return "$att=$login_search, $ldap_base"; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return ''; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -213,40 +213,40 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 216 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 216 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 217 | 217 | |
| 218 | - if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 219 | - spip_log("ldap $serveur injoignable"); |
|
| 218 | + if (!$ldap = spip_connect_ldap($serveur)) { |
|
| 219 | + spip_log("ldap $serveur injoignable"); |
|
| 220 | 220 | |
| 221 | - return []; |
|
| 222 | - } |
|
| 221 | + return []; |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - $ldap_link = $ldap['link']; |
|
| 225 | - if (!$desc) { |
|
| 226 | - $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 227 | - unset($desc['login']); |
|
| 228 | - } |
|
| 229 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 224 | + $ldap_link = $ldap['link']; |
|
| 225 | + if (!$desc) { |
|
| 226 | + $desc = $ldap['attributes'] ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 227 | + unset($desc['login']); |
|
| 228 | + } |
|
| 229 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 230 | 230 | |
| 231 | - if (!$result) { |
|
| 232 | - return []; |
|
| 233 | - } |
|
| 231 | + if (!$result) { |
|
| 232 | + return []; |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | - if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | - return []; |
|
| 239 | - } |
|
| 240 | - $val = $val[0]; |
|
| 235 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 236 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 237 | + if (!is_array($val) or !is_array($val[0])) { |
|
| 238 | + return []; |
|
| 239 | + } |
|
| 240 | + $val = $val[0]; |
|
| 241 | 241 | |
| 242 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | - include_spip('inc/charsets'); |
|
| 242 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 243 | + include_spip('inc/charsets'); |
|
| 244 | 244 | |
| 245 | - foreach ($desc as $k => $v) { |
|
| 246 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | - } |
|
| 245 | + foreach ($desc as $k => $v) { |
|
| 246 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - return $desc; |
|
| 249 | + return $desc; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return string |
| 259 | 259 | */ |
| 260 | 260 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 261 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 261 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -278,9 +278,9 @@ discard block |
||
| 278 | 278 | * Message d'erreur si login non valide, chaîne vide sinon |
| 279 | 279 | */ |
| 280 | 280 | function auth_ldap_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 281 | - include_spip('auth/spip'); |
|
| 281 | + include_spip('auth/spip'); |
|
| 282 | 282 | |
| 283 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 283 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * ``` |
| 302 | 302 | */ |
| 303 | 303 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 304 | - return true; |
|
| 304 | + return true; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -319,23 +319,23 @@ discard block |
||
| 319 | 319 | * Informe du succès ou de l'echec du changement du mot de passe |
| 320 | 320 | */ |
| 321 | 321 | function auth_ldap_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 322 | - if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | - return false; |
|
| 324 | - } |
|
| 325 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | - return ''; |
|
| 327 | - } |
|
| 328 | - $link = $ldap['link']; |
|
| 329 | - include_spip('inc/session'); |
|
| 330 | - $dn = session_get('ldap_dn'); |
|
| 331 | - if ('' == $dn) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | - $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | - |
|
| 340 | - return $success; |
|
| 322 | + if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 323 | + return false; |
|
| 324 | + } |
|
| 325 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 326 | + return ''; |
|
| 327 | + } |
|
| 328 | + $link = $ldap['link']; |
|
| 329 | + include_spip('inc/session'); |
|
| 330 | + $dn = session_get('ldap_dn'); |
|
| 331 | + if ('' == $dn) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | + $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 339 | + |
|
| 340 | + return $success; |
|
| 341 | 341 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
| 69 | 69 | |
| 70 | 70 | // Si l'utilisateur figure deja dans la base, y recuperer les infos |
| 71 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + $r = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login)." AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | 72 | |
| 73 | 73 | if ($r) { |
| 74 | 74 | return array_merge($r, $credentials_ldap); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | if ($r) { |
| 93 | 93 | return array_merge( |
| 94 | 94 | $credentials_ldap, |
| 95 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 95 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur='.intval($r), '', '', '', '', $serveur) |
|
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $connexion = spip_connect($serveur); |
| 122 | 122 | if (!is_array($connexion['ldap'])) { |
| 123 | 123 | if ($connexion['authentification']['ldap']) { |
| 124 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 124 | + $f = _DIR_CONNECT.$connexion['authentification']['ldap']; |
|
| 125 | 125 | unset($GLOBALS['ldap_link']); |
| 126 | 126 | if (is_readable($f)) { |
| 127 | 127 | include_once($f); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
| 335 | 335 | return false; |
| 336 | 336 | } |
| 337 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 337 | + $encoded_pass = '{MD5}'.base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | 338 | $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
| 339 | 339 | |
| 340 | 340 | return $success; |
@@ -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 | /** |
@@ -32,110 +32,110 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 34 | 34 | |
| 35 | - // retrouver le login |
|
| 36 | - $login = auth_spip_retrouver_login($login); |
|
| 37 | - // login inconnu, n'allons pas plus loin |
|
| 38 | - if (!$login) { |
|
| 39 | - return []; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $md5pass = ''; |
|
| 43 | - $shapass = $shanext = ''; |
|
| 44 | - |
|
| 45 | - if (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i', $pass, $regs)) { |
|
| 46 | - $shapass = $regs[1]; |
|
| 47 | - $shanext = $regs[2]; |
|
| 48 | - } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash |
|
| 49 | - elseif (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i', $pass, $regs)) { |
|
| 50 | - $shapass = $regs[1]; |
|
| 51 | - $shanext = $regs[2]; |
|
| 52 | - $md5pass = $regs[3]; |
|
| 53 | - //$md5next = $regs[4]; |
|
| 54 | - } // si envoi non crypte, crypter maintenant |
|
| 55 | - elseif ($pass) { |
|
| 56 | - $row = sql_fetsel( |
|
| 57 | - 'alea_actuel, alea_futur', |
|
| 58 | - 'spip_auteurs', |
|
| 59 | - 'login=' . sql_quote($login, $serveur, 'text'), |
|
| 60 | - '', |
|
| 61 | - '', |
|
| 62 | - '', |
|
| 63 | - '', |
|
| 64 | - $serveur |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - if ($row) { |
|
| 68 | - include_spip('auth/sha256.inc'); |
|
| 69 | - $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 70 | - $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 71 | - $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // login inexistant ou mot de passe vide |
|
| 76 | - if (!$shapass and !$md5pass) { |
|
| 77 | - return []; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $row = sql_fetsel( |
|
| 81 | - '*', |
|
| 82 | - 'spip_auteurs', |
|
| 83 | - 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 84 | - $shapass, |
|
| 85 | - $serveur, |
|
| 86 | - 'text' |
|
| 87 | - ) . " AND statut<>'5poubelle'", |
|
| 88 | - '', |
|
| 89 | - '', |
|
| 90 | - '', |
|
| 91 | - '', |
|
| 92 | - $serveur |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - // compat avec les anciennes bases en md5 |
|
| 96 | - if (!$row and $md5pass) { |
|
| 97 | - $row = sql_fetsel( |
|
| 98 | - '*', |
|
| 99 | - 'spip_auteurs', |
|
| 100 | - 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 101 | - $md5pass, |
|
| 102 | - $serveur, |
|
| 103 | - 'text' |
|
| 104 | - ) . " AND statut<>'5poubelle'", |
|
| 105 | - '', |
|
| 106 | - '', |
|
| 107 | - '', |
|
| 108 | - '', |
|
| 109 | - $serveur |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // login/mot de passe incorrect |
|
| 114 | - if (!$row) { |
|
| 115 | - return []; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // fait tourner le codage du pass dans la base |
|
| 119 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 120 | - if ($shanext and !$phpauth) { |
|
| 121 | - include_spip('inc/acces'); // pour creer_uniqid |
|
| 122 | - @sql_update('spip_auteurs', [ |
|
| 123 | - 'alea_actuel' => 'alea_futur', |
|
| 124 | - 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 125 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 126 | - ], 'id_auteur=' . $row['id_auteur'] . ' AND pass IN (' . sql_quote( |
|
| 127 | - $shapass, |
|
| 128 | - $serveur, |
|
| 129 | - 'text' |
|
| 130 | - ) . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); |
|
| 131 | - // En profiter pour verifier la securite de tmp/ |
|
| 132 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 133 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $row; |
|
| 35 | + // retrouver le login |
|
| 36 | + $login = auth_spip_retrouver_login($login); |
|
| 37 | + // login inconnu, n'allons pas plus loin |
|
| 38 | + if (!$login) { |
|
| 39 | + return []; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $md5pass = ''; |
|
| 43 | + $shapass = $shanext = ''; |
|
| 44 | + |
|
| 45 | + if (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i', $pass, $regs)) { |
|
| 46 | + $shapass = $regs[1]; |
|
| 47 | + $shanext = $regs[2]; |
|
| 48 | + } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash |
|
| 49 | + elseif (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i', $pass, $regs)) { |
|
| 50 | + $shapass = $regs[1]; |
|
| 51 | + $shanext = $regs[2]; |
|
| 52 | + $md5pass = $regs[3]; |
|
| 53 | + //$md5next = $regs[4]; |
|
| 54 | + } // si envoi non crypte, crypter maintenant |
|
| 55 | + elseif ($pass) { |
|
| 56 | + $row = sql_fetsel( |
|
| 57 | + 'alea_actuel, alea_futur', |
|
| 58 | + 'spip_auteurs', |
|
| 59 | + 'login=' . sql_quote($login, $serveur, 'text'), |
|
| 60 | + '', |
|
| 61 | + '', |
|
| 62 | + '', |
|
| 63 | + '', |
|
| 64 | + $serveur |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + if ($row) { |
|
| 68 | + include_spip('auth/sha256.inc'); |
|
| 69 | + $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 70 | + $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 71 | + $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // login inexistant ou mot de passe vide |
|
| 76 | + if (!$shapass and !$md5pass) { |
|
| 77 | + return []; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $row = sql_fetsel( |
|
| 81 | + '*', |
|
| 82 | + 'spip_auteurs', |
|
| 83 | + 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 84 | + $shapass, |
|
| 85 | + $serveur, |
|
| 86 | + 'text' |
|
| 87 | + ) . " AND statut<>'5poubelle'", |
|
| 88 | + '', |
|
| 89 | + '', |
|
| 90 | + '', |
|
| 91 | + '', |
|
| 92 | + $serveur |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + // compat avec les anciennes bases en md5 |
|
| 96 | + if (!$row and $md5pass) { |
|
| 97 | + $row = sql_fetsel( |
|
| 98 | + '*', |
|
| 99 | + 'spip_auteurs', |
|
| 100 | + 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 101 | + $md5pass, |
|
| 102 | + $serveur, |
|
| 103 | + 'text' |
|
| 104 | + ) . " AND statut<>'5poubelle'", |
|
| 105 | + '', |
|
| 106 | + '', |
|
| 107 | + '', |
|
| 108 | + '', |
|
| 109 | + $serveur |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // login/mot de passe incorrect |
|
| 114 | + if (!$row) { |
|
| 115 | + return []; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // fait tourner le codage du pass dans la base |
|
| 119 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 120 | + if ($shanext and !$phpauth) { |
|
| 121 | + include_spip('inc/acces'); // pour creer_uniqid |
|
| 122 | + @sql_update('spip_auteurs', [ |
|
| 123 | + 'alea_actuel' => 'alea_futur', |
|
| 124 | + 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 125 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 126 | + ], 'id_auteur=' . $row['id_auteur'] . ' AND pass IN (' . sql_quote( |
|
| 127 | + $shapass, |
|
| 128 | + $serveur, |
|
| 129 | + 'text' |
|
| 130 | + ) . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', '', $serveur); |
|
| 131 | + // En profiter pour verifier la securite de tmp/ |
|
| 132 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 133 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $row; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -145,41 +145,41 @@ discard block |
||
| 145 | 145 | * @return array |
| 146 | 146 | */ |
| 147 | 147 | function auth_spip_formulaire_login($flux) { |
| 148 | - // faut il encore envoyer md5 ? |
|
| 149 | - // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 150 | - // les hash md5 ont une longueur 32, les sha 64 |
|
| 151 | - // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 152 | - // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 153 | - $compat_md5 = false; |
|
| 154 | - if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 155 | - $compat_md5 = sql_countsel('spip_auteurs', "length(pass)=32 AND statut<>'poubelle'"); |
|
| 156 | - if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 157 | - effacer_meta('sha_256_only'); |
|
| 158 | - } |
|
| 159 | - if (!$compat_md5) { |
|
| 160 | - ecrire_meta('sha_256_only', 'oui'); |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 165 | - $flux['data'] .= |
|
| 166 | - ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 167 | - . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 168 | - . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 169 | - . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 170 | - . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 171 | - . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 172 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 173 | - . "'informe_auteur_en_cours':false," |
|
| 174 | - . "'attente_informe':0," |
|
| 175 | - . "'compat_md5':" . ($compat_md5 ? 'true' : 'false') . '};' |
|
| 176 | - . "jQuery(function(){ |
|
| 148 | + // faut il encore envoyer md5 ? |
|
| 149 | + // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 150 | + // les hash md5 ont une longueur 32, les sha 64 |
|
| 151 | + // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 152 | + // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 153 | + $compat_md5 = false; |
|
| 154 | + if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 155 | + $compat_md5 = sql_countsel('spip_auteurs', "length(pass)=32 AND statut<>'poubelle'"); |
|
| 156 | + if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 157 | + effacer_meta('sha_256_only'); |
|
| 158 | + } |
|
| 159 | + if (!$compat_md5) { |
|
| 160 | + ecrire_meta('sha_256_only', 'oui'); |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 165 | + $flux['data'] .= |
|
| 166 | + ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 167 | + . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 168 | + . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 169 | + . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 170 | + . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 171 | + . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 172 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 173 | + . "'informe_auteur_en_cours':false," |
|
| 174 | + . "'attente_informe':0," |
|
| 175 | + . "'compat_md5':" . ($compat_md5 ? 'true' : 'false') . '};' |
|
| 176 | + . "jQuery(function(){ |
|
| 177 | 177 | jQuery('#var_login').change(actualise_auteur); |
| 178 | 178 | jQuery('form#formulaire_login').submit(login_submit); |
| 179 | 179 | });" |
| 180 | - . '/*]]>*/</script>'; |
|
| 180 | + . '/*]]>*/</script>'; |
|
| 181 | 181 | |
| 182 | - return $flux; |
|
| 182 | + return $flux; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | * toujours true pour un auteur cree dans SPIP |
| 192 | 192 | */ |
| 193 | 193 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 194 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 195 | - if (strlen($serveur)) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - return true; |
|
| 194 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 195 | + if (strlen($serveur)) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + return true; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -209,25 +209,25 @@ discard block |
||
| 209 | 209 | * message d'erreur si login non valide, chaine vide sinon |
| 210 | 210 | */ |
| 211 | 211 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 212 | - // login et mot de passe |
|
| 213 | - if (strlen($new_login)) { |
|
| 214 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 215 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 216 | - } else { |
|
| 217 | - $n = sql_countsel( |
|
| 218 | - 'spip_auteurs', |
|
| 219 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - $serveur |
|
| 223 | - ); |
|
| 224 | - if ($n) { |
|
| 225 | - return _T('info_login_existant'); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return ''; |
|
| 212 | + // login et mot de passe |
|
| 213 | + if (strlen($new_login)) { |
|
| 214 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 215 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 216 | + } else { |
|
| 217 | + $n = sql_countsel( |
|
| 218 | + 'spip_auteurs', |
|
| 219 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + $serveur |
|
| 223 | + ); |
|
| 224 | + if ($n) { |
|
| 225 | + return _T('info_login_existant'); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return ''; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -239,41 +239,41 @@ discard block |
||
| 239 | 239 | * @return bool |
| 240 | 240 | */ |
| 241 | 241 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 242 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - if ( |
|
| 246 | - !$id_auteur = intval($id_auteur) |
|
| 247 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 248 | - ) { |
|
| 249 | - return false; |
|
| 250 | - } |
|
| 251 | - if ($new_login == $auteur['login']) { |
|
| 252 | - return true; |
|
| 253 | - } // on a rien fait mais c'est bon ! |
|
| 254 | - |
|
| 255 | - include_spip('action/editer_auteur'); |
|
| 256 | - |
|
| 257 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 258 | - if (strlen($new_login)) { |
|
| 259 | - $anciens = sql_allfetsel( |
|
| 260 | - 'id_auteur', |
|
| 261 | - 'spip_auteurs', |
|
| 262 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - '', |
|
| 267 | - $serveur |
|
| 268 | - ); |
|
| 269 | - while ($row = array_pop($anciens)) { |
|
| 270 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 275 | - |
|
| 276 | - return true; |
|
| 242 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + if ( |
|
| 246 | + !$id_auteur = intval($id_auteur) |
|
| 247 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 248 | + ) { |
|
| 249 | + return false; |
|
| 250 | + } |
|
| 251 | + if ($new_login == $auteur['login']) { |
|
| 252 | + return true; |
|
| 253 | + } // on a rien fait mais c'est bon ! |
|
| 254 | + |
|
| 255 | + include_spip('action/editer_auteur'); |
|
| 256 | + |
|
| 257 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 258 | + if (strlen($new_login)) { |
|
| 259 | + $anciens = sql_allfetsel( |
|
| 260 | + 'id_auteur', |
|
| 261 | + 'spip_auteurs', |
|
| 262 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + '', |
|
| 267 | + $serveur |
|
| 268 | + ); |
|
| 269 | + while ($row = array_pop($anciens)) { |
|
| 270 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 275 | + |
|
| 276 | + return true; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -285,44 +285,44 @@ discard block |
||
| 285 | 285 | * @return string |
| 286 | 286 | */ |
| 287 | 287 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 288 | - if (!strlen($login)) { |
|
| 289 | - return null; |
|
| 290 | - } // pas la peine de requeter |
|
| 291 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 292 | - if ( |
|
| 293 | - $r = sql_getfetsel( |
|
| 294 | - 'login', |
|
| 295 | - 'spip_auteurs', |
|
| 296 | - "statut<>'5poubelle'" . |
|
| 297 | - ' AND (length(pass)>0)' . |
|
| 298 | - " AND (login=$l)", |
|
| 299 | - '', |
|
| 300 | - '', |
|
| 301 | - '', |
|
| 302 | - '', |
|
| 303 | - $serveur |
|
| 304 | - ) |
|
| 305 | - ) { |
|
| 306 | - return $r; |
|
| 307 | - } |
|
| 308 | - // Si pas d'auteur avec ce login |
|
| 309 | - // regarder s'il a saisi son nom ou son mail. |
|
| 310 | - // Ne pas fusionner avec la requete precedente |
|
| 311 | - // car un nom peut etre homonyme d'un autre login |
|
| 312 | - else { |
|
| 313 | - return sql_getfetsel( |
|
| 314 | - 'login', |
|
| 315 | - 'spip_auteurs', |
|
| 316 | - "statut<>'5poubelle'" . |
|
| 317 | - ' AND (length(pass)>0)' . |
|
| 318 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 319 | - '', |
|
| 320 | - '', |
|
| 321 | - '', |
|
| 322 | - '', |
|
| 323 | - $serveur |
|
| 324 | - ); |
|
| 325 | - } |
|
| 288 | + if (!strlen($login)) { |
|
| 289 | + return null; |
|
| 290 | + } // pas la peine de requeter |
|
| 291 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 292 | + if ( |
|
| 293 | + $r = sql_getfetsel( |
|
| 294 | + 'login', |
|
| 295 | + 'spip_auteurs', |
|
| 296 | + "statut<>'5poubelle'" . |
|
| 297 | + ' AND (length(pass)>0)' . |
|
| 298 | + " AND (login=$l)", |
|
| 299 | + '', |
|
| 300 | + '', |
|
| 301 | + '', |
|
| 302 | + '', |
|
| 303 | + $serveur |
|
| 304 | + ) |
|
| 305 | + ) { |
|
| 306 | + return $r; |
|
| 307 | + } |
|
| 308 | + // Si pas d'auteur avec ce login |
|
| 309 | + // regarder s'il a saisi son nom ou son mail. |
|
| 310 | + // Ne pas fusionner avec la requete precedente |
|
| 311 | + // car un nom peut etre homonyme d'un autre login |
|
| 312 | + else { |
|
| 313 | + return sql_getfetsel( |
|
| 314 | + 'login', |
|
| 315 | + 'spip_auteurs', |
|
| 316 | + "statut<>'5poubelle'" . |
|
| 317 | + ' AND (length(pass)>0)' . |
|
| 318 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 319 | + '', |
|
| 320 | + '', |
|
| 321 | + '', |
|
| 322 | + '', |
|
| 323 | + $serveur |
|
| 324 | + ); |
|
| 325 | + } |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
@@ -340,11 +340,11 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | function auth_spip_informer_login($infos, $row, $serveur = '') { |
| 342 | 342 | |
| 343 | - // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 344 | - $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 345 | - $infos['alea_futur'] = $row['alea_futur']; |
|
| 343 | + // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 344 | + $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 345 | + $infos['alea_futur'] = $row['alea_futur']; |
|
| 346 | 346 | |
| 347 | - return $infos; |
|
| 347 | + return $infos; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -355,11 +355,11 @@ discard block |
||
| 355 | 355 | * toujours true pour un auteur cree dans SPIP |
| 356 | 356 | */ |
| 357 | 357 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 358 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 359 | - if (strlen($serveur)) { |
|
| 360 | - return false; |
|
| 361 | - } |
|
| 362 | - return true; |
|
| 358 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 359 | + if (strlen($serveur)) { |
|
| 360 | + return false; |
|
| 361 | + } |
|
| 362 | + return true; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | |
@@ -380,12 +380,12 @@ discard block |
||
| 380 | 380 | * message d'erreur si login non valide, chaine vide sinon |
| 381 | 381 | */ |
| 382 | 382 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 383 | - // login et mot de passe |
|
| 384 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 385 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 386 | - } |
|
| 383 | + // login et mot de passe |
|
| 384 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 385 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - return ''; |
|
| 388 | + return ''; |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | /** |
@@ -399,34 +399,34 @@ discard block |
||
| 399 | 399 | * @return bool |
| 400 | 400 | */ |
| 401 | 401 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 402 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 403 | - return false; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - if ( |
|
| 407 | - !$id_auteur = intval($id_auteur) |
|
| 408 | - or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 409 | - ) { |
|
| 410 | - return false; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - $c = []; |
|
| 414 | - include_spip('inc/acces'); |
|
| 415 | - include_spip('auth/sha256.inc'); |
|
| 416 | - $htpass = generer_htpass($new_pass); |
|
| 417 | - $alea_actuel = creer_uniqid(); |
|
| 418 | - $alea_futur = creer_uniqid(); |
|
| 419 | - $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 420 | - $c['pass'] = $pass; |
|
| 421 | - $c['htpass'] = $htpass; |
|
| 422 | - $c['alea_actuel'] = $alea_actuel; |
|
| 423 | - $c['alea_futur'] = $alea_futur; |
|
| 424 | - $c['low_sec'] = ''; |
|
| 425 | - |
|
| 426 | - include_spip('action/editer_auteur'); |
|
| 427 | - auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 428 | - |
|
| 429 | - return true; // on a bien modifie le pass |
|
| 402 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 403 | + return false; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + if ( |
|
| 407 | + !$id_auteur = intval($id_auteur) |
|
| 408 | + or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 409 | + ) { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + $c = []; |
|
| 414 | + include_spip('inc/acces'); |
|
| 415 | + include_spip('auth/sha256.inc'); |
|
| 416 | + $htpass = generer_htpass($new_pass); |
|
| 417 | + $alea_actuel = creer_uniqid(); |
|
| 418 | + $alea_futur = creer_uniqid(); |
|
| 419 | + $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 420 | + $c['pass'] = $pass; |
|
| 421 | + $c['htpass'] = $htpass; |
|
| 422 | + $c['alea_actuel'] = $alea_actuel; |
|
| 423 | + $c['alea_futur'] = $alea_futur; |
|
| 424 | + $c['low_sec'] = ''; |
|
| 425 | + |
|
| 426 | + include_spip('action/editer_auteur'); |
|
| 427 | + auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 428 | + |
|
| 429 | + return true; // on a bien modifie le pass |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -440,58 +440,58 @@ discard block |
||
| 440 | 440 | * @return void |
| 441 | 441 | */ |
| 442 | 442 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = '') : void { |
| 443 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 444 | - if (strlen($serveur)) { |
|
| 445 | - return; |
|
| 446 | - } |
|
| 447 | - // si un login, pass ou statut a ete modifie |
|
| 448 | - // regenerer les fichier htpass |
|
| 449 | - if ( |
|
| 450 | - isset($champs['login']) |
|
| 451 | - or isset($champs['pass']) |
|
| 452 | - or isset($champs['statut']) |
|
| 453 | - or (isset($options['all']) and $options['all']) |
|
| 454 | - ) { |
|
| 455 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 456 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 457 | - |
|
| 458 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 459 | - // par exemple acces_restreint ; |
|
| 460 | - // si .htaccess existe, outrepasser spip_meta |
|
| 461 | - if ( |
|
| 462 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 463 | - and !@file_exists($htaccess) |
|
| 464 | - ) { |
|
| 465 | - spip_unlink($htpasswd); |
|
| 466 | - spip_unlink($htpasswd . '-admin'); |
|
| 467 | - |
|
| 468 | - return; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 472 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 473 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 474 | - |
|
| 475 | - $p1 = ''; // login:htpass pour tous |
|
| 476 | - $p2 = ''; // login:htpass pour les admins |
|
| 477 | - $s = sql_select( |
|
| 478 | - 'login, htpass, statut', |
|
| 479 | - 'spip_auteurs', |
|
| 480 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 481 | - ); |
|
| 482 | - while ($t = sql_fetch($s)) { |
|
| 483 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 484 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 485 | - if ($t['statut'] == '0minirezo') { |
|
| 486 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - sql_free($s); |
|
| 491 | - if ($p1) { |
|
| 492 | - ecrire_fichier($htpasswd, $p1); |
|
| 493 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 494 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 495 | - } |
|
| 496 | - } |
|
| 443 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 444 | + if (strlen($serveur)) { |
|
| 445 | + return; |
|
| 446 | + } |
|
| 447 | + // si un login, pass ou statut a ete modifie |
|
| 448 | + // regenerer les fichier htpass |
|
| 449 | + if ( |
|
| 450 | + isset($champs['login']) |
|
| 451 | + or isset($champs['pass']) |
|
| 452 | + or isset($champs['statut']) |
|
| 453 | + or (isset($options['all']) and $options['all']) |
|
| 454 | + ) { |
|
| 455 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 456 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 457 | + |
|
| 458 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 459 | + // par exemple acces_restreint ; |
|
| 460 | + // si .htaccess existe, outrepasser spip_meta |
|
| 461 | + if ( |
|
| 462 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 463 | + and !@file_exists($htaccess) |
|
| 464 | + ) { |
|
| 465 | + spip_unlink($htpasswd); |
|
| 466 | + spip_unlink($htpasswd . '-admin'); |
|
| 467 | + |
|
| 468 | + return; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 472 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 473 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 474 | + |
|
| 475 | + $p1 = ''; // login:htpass pour tous |
|
| 476 | + $p2 = ''; // login:htpass pour les admins |
|
| 477 | + $s = sql_select( |
|
| 478 | + 'login, htpass, statut', |
|
| 479 | + 'spip_auteurs', |
|
| 480 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 481 | + ); |
|
| 482 | + while ($t = sql_fetch($s)) { |
|
| 483 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 484 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 485 | + if ($t['statut'] == '0minirezo') { |
|
| 486 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + sql_free($s); |
|
| 491 | + if ($p1) { |
|
| 492 | + ecrire_fichier($htpasswd, $p1); |
|
| 493 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 494 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | 497 | } |