@@ -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 = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 52 | + $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | + $boucle->where[] = ($crit->not ? array("'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 (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = array("'!='", "'$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 (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = array("'!='", "'$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 (array('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[] = array($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 (array('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[] = array($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,18 +211,18 @@ 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 = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 222 | - '"'; |
|
| 223 | - } else { |
|
| 224 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | + $un . |
|
| 220 | + '"]) . ",' . |
|
| 221 | + $deux . |
|
| 222 | + '"'; |
|
| 223 | + } else { |
|
| 224 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -256,57 +256,57 @@ discard block |
||
| 256 | 256 | **/ |
| 257 | 257 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 258 | 258 | |
| 259 | - $boucle = &$boucles[$idb]; |
|
| 260 | - // definition de la taille de la page |
|
| 261 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | - : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 263 | - |
|
| 264 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | - } else { |
|
| 267 | - $r = intval($r[2]); |
|
| 268 | - $pas = strval($r ? $r : 10); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Calcul du nommage de la pagination si il existe. |
|
| 272 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | - $type = "'$idb'"; |
|
| 275 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | - // Syntaxe {pagination 20, nom} |
|
| 277 | - if (isset($crit->param[0][1])) { |
|
| 278 | - $type = calculer_liste(array($crit->param[0][1]), $idb, $boucles, $boucle->id_parent); |
|
| 279 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | - elseif (isset($crit->param[1][0])) { |
|
| 281 | - $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | - $partie = |
|
| 287 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | - . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | - . "\t}\n" |
|
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | - |
|
| 295 | - $boucle->hash .= ' |
|
| 259 | + $boucle = &$boucles[$idb]; |
|
| 260 | + // definition de la taille de la page |
|
| 261 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | + : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 263 | + |
|
| 264 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | + } else { |
|
| 267 | + $r = intval($r[2]); |
|
| 268 | + $pas = strval($r ? $r : 10); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Calcul du nommage de la pagination si il existe. |
|
| 272 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | + $type = "'$idb'"; |
|
| 275 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | + // Syntaxe {pagination 20, nom} |
|
| 277 | + if (isset($crit->param[0][1])) { |
|
| 278 | + $type = calculer_liste(array($crit->param[0][1]), $idb, $boucles, $boucle->id_parent); |
|
| 279 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | + elseif (isset($crit->param[1][0])) { |
|
| 281 | + $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | + $partie = |
|
| 287 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | + . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | + . "\t}\n" |
|
| 293 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | + |
|
| 295 | + $boucle->hash .= ' |
|
| 296 | 296 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 297 | 297 | |
| 298 | - $boucle->total_parties = $pas; |
|
| 299 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | - // sauf si pas de primaire, ou si primaire composee |
|
| 302 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | - if ($boucle->primary |
|
| 305 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | - and !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 298 | + $boucle->total_parties = $pas; |
|
| 299 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | + // sauf si pas de primaire, ou si primaire composee |
|
| 302 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | + if ($boucle->primary |
|
| 305 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | + and !in_array($t, $boucle->select) |
|
| 307 | + ) { |
|
| 308 | + $boucle->select[] = $t; |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | **/ |
| 329 | 329 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 330 | 330 | |
| 331 | - $boucle = &$boucles[$idb]; |
|
| 331 | + $boucle = &$boucles[$idb]; |
|
| 332 | 332 | |
| 333 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 333 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | - } |
|
| 369 | - $boucle->select[] = '$rech_select'; |
|
| 370 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | - |
|
| 372 | - // et la recherche trouve |
|
| 373 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 359 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | + $boucle->select[] = $t; |
|
| 362 | + } # pour postgres, neuneu ici |
|
| 363 | + // jointure uniquement sur le serveur principal |
|
| 364 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | + if (!$boucle->sql_serveur) { |
|
| 366 | + $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | + } |
|
| 369 | + $boucle->select[] = '$rech_select'; |
|
| 370 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | + |
|
| 372 | + // et la recherche trouve |
|
| 373 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | **/ |
| 389 | 389 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 390 | - $boucle = &$boucles[$idb]; |
|
| 391 | - $prim = $boucle->primary; |
|
| 392 | - $table = $boucle->id_table; |
|
| 393 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | - $boucle->where[] = |
|
| 396 | - array( |
|
| 397 | - "'OR'", |
|
| 398 | - array( |
|
| 399 | - "'AND'", |
|
| 400 | - array("'='", "'$table.id_trad'", 0), |
|
| 401 | - array("'='", "'$table.$prim'", $dprim) |
|
| 402 | - ), |
|
| 403 | - array( |
|
| 404 | - "'AND'", |
|
| 405 | - array("'>'", "'$table.id_trad'", 0), |
|
| 406 | - array("'='", "'$table.id_trad'", $arg) |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 390 | + $boucle = &$boucles[$idb]; |
|
| 391 | + $prim = $boucle->primary; |
|
| 392 | + $table = $boucle->id_table; |
|
| 393 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | + $boucle->where[] = |
|
| 396 | + array( |
|
| 397 | + "'OR'", |
|
| 398 | + array( |
|
| 399 | + "'AND'", |
|
| 400 | + array("'='", "'$table.id_trad'", 0), |
|
| 401 | + array("'='", "'$table.$prim'", $dprim) |
|
| 402 | + ), |
|
| 403 | + array( |
|
| 404 | + "'AND'", |
|
| 405 | + array("'>'", "'$table.id_trad'", 0), |
|
| 406 | + array("'='", "'$table.id_trad'", $arg) |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return void |
| 424 | 424 | **/ |
| 425 | 425 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 426 | - $boucle = &$boucles[$idb]; |
|
| 427 | - $prim = $boucle->primary; |
|
| 428 | - $table = $boucle->id_table; |
|
| 429 | - |
|
| 430 | - $c = |
|
| 431 | - array( |
|
| 432 | - "'OR'", |
|
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | - array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | - ); |
|
| 436 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + array( |
|
| 432 | + "'OR'", |
|
| 433 | + array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | + array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | + ); |
|
| 436 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,20 +450,20 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 452 | 452 | |
| 453 | - $boucle = &$boucles[$idb]; |
|
| 454 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | + 'id_parent'; |
|
| 458 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 459 | 459 | |
| 460 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | - $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 460 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | + $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 462 | 462 | |
| 463 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | - else { |
|
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | - } |
|
| 463 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | + else { |
|
| 465 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -494,37 +494,37 @@ discard block |
||
| 494 | 494 | **/ |
| 495 | 495 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 496 | 496 | |
| 497 | - $not = $crit->not; |
|
| 498 | - $boucle = &$boucles[$idb]; |
|
| 499 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | - if (isset($crit->param[0])) { |
|
| 501 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | - // sinon on le prend chez une boucle parente |
|
| 503 | - } else { |
|
| 504 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Trouver une jointure |
|
| 508 | - $champ = "id_rubrique"; |
|
| 509 | - $desc = $boucle->show; |
|
| 510 | - //Seulement si necessaire |
|
| 511 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | - $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | - $decompose = decompose_champ_id_objet($champ); |
|
| 517 | - $champ = array_shift($decompose); |
|
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | - } |
|
| 520 | - } else { |
|
| 521 | - $cle = $boucle->id_table; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 497 | + $not = $crit->not; |
|
| 498 | + $boucle = &$boucles[$idb]; |
|
| 499 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | + if (isset($crit->param[0])) { |
|
| 501 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 502 | + // sinon on le prend chez une boucle parente |
|
| 503 | + } else { |
|
| 504 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Trouver une jointure |
|
| 508 | + $champ = "id_rubrique"; |
|
| 509 | + $desc = $boucle->show; |
|
| 510 | + //Seulement si necessaire |
|
| 511 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | + $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | + $decompose = decompose_champ_id_objet($champ); |
|
| 517 | + $champ = array_shift($decompose); |
|
| 518 | + $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | + } |
|
| 520 | + } else { |
|
| 521 | + $cle = $boucle->id_table; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | + . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -540,15 +540,15 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $boucle = &$boucles[$idb]; |
|
| 544 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | - $serveur = $boucle->sql_serveur; |
|
| 543 | + $boucle = &$boucles[$idb]; |
|
| 544 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | + $serveur = $boucle->sql_serveur; |
|
| 546 | 546 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | + $c = "sql_in('" . |
|
| 548 | + $boucle->id_table . '.' . $boucle->primary |
|
| 549 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 550 | 550 | |
| 551 | - $boucle->where[] = $c; |
|
| 551 | + $boucle->where[] = $c; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -570,31 +570,31 @@ discard block |
||
| 570 | 570 | * @return void |
| 571 | 571 | **/ |
| 572 | 572 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 573 | - if ($t = isset($crit->param[0])) { |
|
| 574 | - $t = $crit->param[0]; |
|
| 575 | - if ($t[0]->type == 'texte') { |
|
| 576 | - $t = $t[0]->texte; |
|
| 577 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | - $t = table_objet_sql($r[1]); |
|
| 579 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | - if ($t) { |
|
| 581 | - $t .= '.' . $r[2]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } else { |
|
| 585 | - $t = '".' |
|
| 586 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | - . '."'; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if ($t) { |
|
| 591 | - $boucles[$idb]->group[] = $t; |
|
| 592 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | - $boucles[$idb]->select[] = $t; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | - } |
|
| 573 | + if ($t = isset($crit->param[0])) { |
|
| 574 | + $t = $crit->param[0]; |
|
| 575 | + if ($t[0]->type == 'texte') { |
|
| 576 | + $t = $t[0]->texte; |
|
| 577 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | + $t = table_objet_sql($r[1]); |
|
| 579 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | + if ($t) { |
|
| 581 | + $t .= '.' . $r[2]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } else { |
|
| 585 | + $t = '".' |
|
| 586 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | + . '."'; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if ($t) { |
|
| 591 | + $boucles[$idb]->group[] = $t; |
|
| 592 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | + $boucles[$idb]->select[] = $t; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | + } |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -631,45 +631,45 @@ discard block |
||
| 631 | 631 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 632 | 632 | */ |
| 633 | 633 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 634 | - if (isset($crit->param[0])) { |
|
| 635 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 636 | - $boucle = $boucles[$idb]; |
|
| 637 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | - $n = count($boucle->order); |
|
| 639 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | - if ( |
|
| 643 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | - OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | - ) { |
|
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | - } else { |
|
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | - } |
|
| 634 | + if (isset($crit->param[0])) { |
|
| 635 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 636 | + $boucle = $boucles[$idb]; |
|
| 637 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | + $n = count($boucle->order); |
|
| 639 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | + if ( |
|
| 643 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | + OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | + ) { |
|
| 646 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | + } else { |
|
| 648 | + $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | + } |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 657 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | - $boucle = $boucles[$idb]; |
|
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 661 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | - if (!$desc) { |
|
| 663 | - $desc = $boucle->show['field']; |
|
| 664 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | - } |
|
| 667 | - if ($desc) { |
|
| 668 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | - } |
|
| 670 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 671 | - |
|
| 672 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 658 | + $boucle = $boucles[$idb]; |
|
| 659 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | + $var = '$champs_' . $idb; |
|
| 661 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | + if (!$desc) { |
|
| 663 | + $desc = $boucle->show['field']; |
|
| 664 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | + } |
|
| 667 | + if ($desc) { |
|
| 668 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | + } |
|
| 670 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 671 | + |
|
| 672 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 709 | 709 | */ |
| 710 | 710 | function critere_par_dist($idb, &$boucles, $crit) { |
| 711 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 711 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -730,93 +730,93 @@ discard block |
||
| 730 | 730 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 731 | 731 | */ |
| 732 | 732 | function critere_parinverse($idb, &$boucles, $crit) { |
| 733 | - $boucle = &$boucles[$idb]; |
|
| 734 | - |
|
| 735 | - $sens = $collecte = ''; |
|
| 736 | - if ($crit->not) { |
|
| 737 | - $sens = " . ' DESC'"; |
|
| 738 | - } |
|
| 739 | - if (isset($boucle->modificateur['collate'])) { |
|
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Pour chaque paramètre du critère |
|
| 744 | - foreach ($crit->param as $tri) { |
|
| 745 | - $order = $fct = ''; |
|
| 746 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | - if ($tri[0]->type != 'texte') { |
|
| 748 | - // calculer le order dynamique qui verifie les champs |
|
| 749 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | - } |
|
| 753 | - // tris textuels {par titre} |
|
| 754 | - else { |
|
| 755 | - $par = array_shift($tri); |
|
| 756 | - $par = $par->texte; |
|
| 757 | - |
|
| 758 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | - if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | - $expression = trim($m[1]); |
|
| 761 | - $champ = trim($m[2]); |
|
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | - } else { |
|
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | - // {par FONCTION(champ)} |
|
| 771 | - if (count($match) > 2) { |
|
| 772 | - $par = substr($match[2], 1, -1); |
|
| 773 | - $fct = $match[1]; |
|
| 774 | - } |
|
| 775 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | - if ($par == 'hasard') { |
|
| 777 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | - } else { |
|
| 781 | - // cas général {par champ}, {par table.champ}, ... |
|
| 782 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // on ne sait pas traiter… |
|
| 787 | - else { |
|
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | - if (is_array($order)) { |
|
| 793 | - return $order; |
|
| 794 | - } |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | - $t = $m[1]; |
|
| 799 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | - $boucle->select[] = $t; |
|
| 801 | - } |
|
| 802 | - } else { |
|
| 803 | - $sens = ''; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - if ($fct) { |
|
| 807 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | - } else { |
|
| 810 | - $order = "'$fct(' . $order . ')'"; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - $t = $order . $collecte . $sens; |
|
| 814 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | - $t = $r[1] . $r[2]; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - $boucle->order[] = $t; |
|
| 819 | - } |
|
| 733 | + $boucle = &$boucles[$idb]; |
|
| 734 | + |
|
| 735 | + $sens = $collecte = ''; |
|
| 736 | + if ($crit->not) { |
|
| 737 | + $sens = " . ' DESC'"; |
|
| 738 | + } |
|
| 739 | + if (isset($boucle->modificateur['collate'])) { |
|
| 740 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Pour chaque paramètre du critère |
|
| 744 | + foreach ($crit->param as $tri) { |
|
| 745 | + $order = $fct = ''; |
|
| 746 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | + if ($tri[0]->type != 'texte') { |
|
| 748 | + // calculer le order dynamique qui verifie les champs |
|
| 749 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | + } |
|
| 753 | + // tris textuels {par titre} |
|
| 754 | + else { |
|
| 755 | + $par = array_shift($tri); |
|
| 756 | + $par = $par->texte; |
|
| 757 | + |
|
| 758 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | + if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | + $expression = trim($m[1]); |
|
| 761 | + $champ = trim($m[2]); |
|
| 762 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | + } else { |
|
| 765 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | + } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | + // {par FONCTION(champ)} |
|
| 771 | + if (count($match) > 2) { |
|
| 772 | + $par = substr($match[2], 1, -1); |
|
| 773 | + $fct = $match[1]; |
|
| 774 | + } |
|
| 775 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | + if ($par == 'hasard') { |
|
| 777 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | + $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | + } else { |
|
| 781 | + // cas général {par champ}, {par table.champ}, ... |
|
| 782 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // on ne sait pas traiter… |
|
| 787 | + else { |
|
| 788 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | + if (is_array($order)) { |
|
| 793 | + return $order; |
|
| 794 | + } |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | + $t = $m[1]; |
|
| 799 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | + $boucle->select[] = $t; |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + $sens = ''; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + if ($fct) { |
|
| 807 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | + } else { |
|
| 810 | + $order = "'$fct(' . $order . ')'"; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + $t = $order . $collecte . $sens; |
|
| 814 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | + $t = $r[1] . $r[2]; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + $boucle->order[] = $t; |
|
| 819 | + } |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -830,13 +830,13 @@ discard block |
||
| 830 | 830 | * @return string Clause pour le Order by |
| 831 | 831 | */ |
| 832 | 832 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 833 | - $boucle = &$boucles[$idb]; |
|
| 834 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | - $parha = "rand() AS hasard"; |
|
| 836 | - if (!in_array($parha, $boucle->select)) { |
|
| 837 | - $boucle->select[] = $parha; |
|
| 838 | - } |
|
| 839 | - return "'hasard'"; |
|
| 833 | + $boucle = &$boucles[$idb]; |
|
| 834 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | + $parha = "rand() AS hasard"; |
|
| 836 | + if (!in_array($parha, $boucle->select)) { |
|
| 837 | + $boucle->select[] = $parha; |
|
| 838 | + } |
|
| 839 | + return "'hasard'"; |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -860,20 +860,20 @@ discard block |
||
| 860 | 860 | * @return string Clause pour le Order by |
| 861 | 861 | */ |
| 862 | 862 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | - if (is_array($_champ)) { |
|
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | - } |
|
| 867 | - $boucle = &$boucles[$idb]; |
|
| 868 | - $texte = '0+' . $_champ; |
|
| 869 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 870 | - if ($suite !== "''") { |
|
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | - } |
|
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 875 | - $order = "'$as'"; |
|
| 876 | - return $order; |
|
| 863 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | + if (is_array($_champ)) { |
|
| 865 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | + } |
|
| 867 | + $boucle = &$boucles[$idb]; |
|
| 868 | + $texte = '0+' . $_champ; |
|
| 869 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 870 | + if ($suite !== "''") { |
|
| 871 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | + } |
|
| 873 | + $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | + $boucle->select[] = $texte . " AS $as"; |
|
| 875 | + $order = "'$as'"; |
|
| 876 | + return $order; |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | /** |
@@ -894,20 +894,20 @@ discard block |
||
| 894 | 894 | * @return string Clause pour le Order by |
| 895 | 895 | */ |
| 896 | 896 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | - if (is_array($_champ)) { |
|
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | - } |
|
| 901 | - $boucle = &$boucles[$idb]; |
|
| 902 | - $texte = '0+' . $_champ; |
|
| 903 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 904 | - if ($suite !== "''") { |
|
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | - } |
|
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | - $order = "'$as'"; |
|
| 910 | - return $order; |
|
| 897 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | + if (is_array($_champ)) { |
|
| 899 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | + } |
|
| 901 | + $boucle = &$boucles[$idb]; |
|
| 902 | + $texte = '0+' . $_champ; |
|
| 903 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 904 | + if ($suite !== "''") { |
|
| 905 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | + } |
|
| 907 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | + $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | + $order = "'$as'"; |
|
| 910 | + return $order; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | |
@@ -927,14 +927,14 @@ discard block |
||
| 927 | 927 | * @return string Clause pour le Order by |
| 928 | 928 | */ |
| 929 | 929 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | - if (is_array($_champ)) { |
|
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | - } |
|
| 934 | - $boucle = &$boucles[$idb]; |
|
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | - $order = "'multi'"; |
|
| 937 | - return $order; |
|
| 930 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | + if (is_array($_champ)) { |
|
| 932 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | + } |
|
| 934 | + $boucle = &$boucles[$idb]; |
|
| 935 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | + $order = "'multi'"; |
|
| 937 | + return $order; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -953,56 +953,56 @@ discard block |
||
| 953 | 953 | * @return array|string |
| 954 | 954 | */ |
| 955 | 955 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 956 | - $boucle = &$boucles[$idb]; |
|
| 957 | - $desc = $boucle->show; |
|
| 958 | - |
|
| 959 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | - if (isset($desc['field'][$par])) { |
|
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 962 | - } |
|
| 963 | - // le champ est peut être une jointure |
|
| 964 | - else { |
|
| 965 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | - $champ = $par; |
|
| 967 | - |
|
| 968 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | - list(, $table, $champ) = $r; |
|
| 974 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | - $table = table_objet_sql($table); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 983 | - } elseif ( |
|
| 984 | - $boucle->jointures_explicites |
|
| 985 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | - ) { |
|
| 987 | - $par = $alias . "." . $champ; |
|
| 988 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | - $par = $alias . "." . $champ; |
|
| 990 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | - } elseif ( |
|
| 992 | - $table_alias |
|
| 993 | - and isset($boucle->from[$table_alias]) |
|
| 994 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | - ) { |
|
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 997 | - } elseif ($table) { |
|
| 998 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | - } else { |
|
| 1001 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return $raw ? $par : "'$par'"; |
|
| 956 | + $boucle = &$boucles[$idb]; |
|
| 957 | + $desc = $boucle->show; |
|
| 958 | + |
|
| 959 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | + if (isset($desc['field'][$par])) { |
|
| 961 | + $par = $boucle->id_table . "." . $par; |
|
| 962 | + } |
|
| 963 | + // le champ est peut être une jointure |
|
| 964 | + else { |
|
| 965 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | + $champ = $par; |
|
| 967 | + |
|
| 968 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | + list(, $table, $champ) = $r; |
|
| 974 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | + $table = table_objet_sql($table); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | + $par = $infos['alias'] . "." . $champ; |
|
| 983 | + } elseif ( |
|
| 984 | + $boucle->jointures_explicites |
|
| 985 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | + ) { |
|
| 987 | + $par = $alias . "." . $champ; |
|
| 988 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | + $par = $alias . "." . $champ; |
|
| 990 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | + } elseif ( |
|
| 992 | + $table_alias |
|
| 993 | + and isset($boucle->from[$table_alias]) |
|
| 994 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | + ) { |
|
| 996 | + $par = $infos['alias'] . "." . $champ; |
|
| 997 | + } elseif ($table) { |
|
| 998 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | + } else { |
|
| 1001 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return $raw ? $par : "'$par'"; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1016,11 +1016,11 @@ discard block |
||
| 1016 | 1016 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1017 | 1017 | */ |
| 1018 | 1018 | function critere_par_joint($table, $champ, &$boucle) { |
| 1019 | - $t = array_search($table, $boucle->from); |
|
| 1020 | - if (!$t) { |
|
| 1021 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | - } |
|
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1019 | + $t = array_search($table, $boucle->from); |
|
| 1020 | + if (!$t) { |
|
| 1021 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | + } |
|
| 1023 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
@@ -1045,33 +1045,33 @@ discard block |
||
| 1045 | 1045 | */ |
| 1046 | 1046 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1047 | 1047 | |
| 1048 | - $boucle = &$boucles[$idb]; |
|
| 1049 | - // Classement par ordre inverse |
|
| 1050 | - if ($crit->not) { |
|
| 1051 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | - } else { |
|
| 1053 | - $order = "' DESC'"; |
|
| 1054 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | - if (isset($crit->param[0])) { |
|
| 1056 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | - $order = "(($critere)?' DESC':'')"; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - $n = count($boucle->order); |
|
| 1061 | - if (!$n) { |
|
| 1062 | - if (isset($boucle->default_order[0])) { |
|
| 1063 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | - } else { |
|
| 1065 | - $boucle->default_order[] = ' DESC'; |
|
| 1066 | - } |
|
| 1067 | - } else { |
|
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1071 | - } |
|
| 1072 | - $boucle->order[$n - 1] = $t; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1048 | + $boucle = &$boucles[$idb]; |
|
| 1049 | + // Classement par ordre inverse |
|
| 1050 | + if ($crit->not) { |
|
| 1051 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | + } else { |
|
| 1053 | + $order = "' DESC'"; |
|
| 1054 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | + if (isset($crit->param[0])) { |
|
| 1056 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | + $order = "(($critere)?' DESC':'')"; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + $n = count($boucle->order); |
|
| 1061 | + if (!$n) { |
|
| 1062 | + if (isset($boucle->default_order[0])) { |
|
| 1063 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | + } else { |
|
| 1065 | + $boucle->default_order[] = ' DESC'; |
|
| 1066 | + } |
|
| 1067 | + } else { |
|
| 1068 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | + $t = $r[1] . $r[2]; |
|
| 1071 | + } |
|
| 1072 | + $boucle->order[$n - 1] = $t; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | /** |
@@ -1082,138 +1082,138 @@ discard block |
||
| 1082 | 1082 | * @return array|string |
| 1083 | 1083 | */ |
| 1084 | 1084 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit){ |
| 1085 | - $boucle = &$boucles[$idb]; |
|
| 1085 | + $boucle = &$boucles[$idb]; |
|
| 1086 | 1086 | |
| 1087 | - $sens = $collecte = ''; |
|
| 1088 | - if ($crit->not){ |
|
| 1089 | - $sens = " . ' DESC'"; |
|
| 1090 | - } |
|
| 1087 | + $sens = $collecte = ''; |
|
| 1088 | + if ($crit->not){ |
|
| 1089 | + $sens = " . ' DESC'"; |
|
| 1090 | + } |
|
| 1091 | 1091 | |
| 1092 | - $crit2 = clone $crit; |
|
| 1093 | - $crit2->not = false; |
|
| 1094 | - $crit2->param = [reset($crit->param)]; |
|
| 1095 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1092 | + $crit2 = clone $crit; |
|
| 1093 | + $crit2->not = false; |
|
| 1094 | + $crit2->param = [reset($crit->param)]; |
|
| 1095 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1096 | 1096 | |
| 1097 | - // erreur ? |
|
| 1098 | - if (is_array($res)){ |
|
| 1099 | - return $res; |
|
| 1100 | - } |
|
| 1097 | + // erreur ? |
|
| 1098 | + if (is_array($res)){ |
|
| 1099 | + return $res; |
|
| 1100 | + } |
|
| 1101 | 1101 | |
| 1102 | - $_order = array_pop($boucle->order); |
|
| 1102 | + $_order = array_pop($boucle->order); |
|
| 1103 | 1103 | |
| 1104 | - $_liste = calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1105 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1104 | + $_liste = calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1105 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | |
| 1109 | 1109 | // https://code.spip.net/@critere_agenda_dist |
| 1110 | 1110 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1111 | - $params = $crit->param; |
|
| 1112 | - |
|
| 1113 | - if (count($params) < 1) { |
|
| 1114 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - $boucle = &$boucles[$idb]; |
|
| 1118 | - $parent = $boucle->id_parent; |
|
| 1119 | - $fields = $boucle->show['field']; |
|
| 1120 | - |
|
| 1121 | - $date = array_shift($params); |
|
| 1122 | - $type = array_shift($params); |
|
| 1123 | - |
|
| 1124 | - // la valeur $type doit etre connue a la compilation |
|
| 1125 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1126 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1127 | - |
|
| 1128 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1129 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1130 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1131 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1132 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1133 | - $date = $date[0]->texte; |
|
| 1134 | - if (!isset($fields[$date])) { |
|
| 1135 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1136 | - } |
|
| 1137 | - } else { |
|
| 1138 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1139 | - $noms = array_keys($fields); |
|
| 1140 | - $defaut = $noms[0]; |
|
| 1141 | - $noms = join(" ", $noms); |
|
| 1142 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1143 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1144 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1145 | - } |
|
| 1146 | - $annee = $params ? array_shift($params) : ""; |
|
| 1147 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1148 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1149 | - ') ? $x : date("Y"))'; |
|
| 1150 | - |
|
| 1151 | - $mois = $params ? array_shift($params) : ""; |
|
| 1152 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1153 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1154 | - ') ? $x : date("m"))'; |
|
| 1155 | - |
|
| 1156 | - $jour = $params ? array_shift($params) : ""; |
|
| 1157 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1158 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1159 | - ') ? $x : date("d"))'; |
|
| 1160 | - |
|
| 1161 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 1162 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1163 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1164 | - ') ? $x : date("Y"))'; |
|
| 1165 | - |
|
| 1166 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 1167 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1168 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1169 | - ') ? $x : date("m"))'; |
|
| 1170 | - |
|
| 1171 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 1172 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1173 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1174 | - ') ? $x : date("d"))'; |
|
| 1175 | - |
|
| 1176 | - $date = $boucle->id_table . ".$date"; |
|
| 1177 | - |
|
| 1178 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1179 | - if ($type == 'jour') { |
|
| 1180 | - $boucle->where[] = array( |
|
| 1181 | - "'='", |
|
| 1182 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1183 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1184 | - ); |
|
| 1185 | - } elseif ($type == 'mois') { |
|
| 1186 | - $boucle->where[] = array( |
|
| 1187 | - "'='", |
|
| 1188 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1189 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1190 | - ); |
|
| 1191 | - } elseif ($type == 'semaine') { |
|
| 1192 | - $boucle->where[] = array( |
|
| 1193 | - "'AND'", |
|
| 1194 | - array( |
|
| 1195 | - "'>='", |
|
| 1196 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1197 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1198 | - ), |
|
| 1199 | - array( |
|
| 1200 | - "'<='", |
|
| 1201 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1202 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1203 | - ) |
|
| 1204 | - ); |
|
| 1205 | - } elseif (count($crit->param) > 2) { |
|
| 1206 | - $boucle->where[] = array( |
|
| 1207 | - "'AND'", |
|
| 1208 | - array( |
|
| 1209 | - "'>='", |
|
| 1210 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1211 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1212 | - ), |
|
| 1213 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1214 | - ); |
|
| 1215 | - } |
|
| 1216 | - // sinon on prend tout |
|
| 1111 | + $params = $crit->param; |
|
| 1112 | + |
|
| 1113 | + if (count($params) < 1) { |
|
| 1114 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + $boucle = &$boucles[$idb]; |
|
| 1118 | + $parent = $boucle->id_parent; |
|
| 1119 | + $fields = $boucle->show['field']; |
|
| 1120 | + |
|
| 1121 | + $date = array_shift($params); |
|
| 1122 | + $type = array_shift($params); |
|
| 1123 | + |
|
| 1124 | + // la valeur $type doit etre connue a la compilation |
|
| 1125 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1126 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1127 | + |
|
| 1128 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1129 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1130 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1131 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1132 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1133 | + $date = $date[0]->texte; |
|
| 1134 | + if (!isset($fields[$date])) { |
|
| 1135 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1136 | + } |
|
| 1137 | + } else { |
|
| 1138 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1139 | + $noms = array_keys($fields); |
|
| 1140 | + $defaut = $noms[0]; |
|
| 1141 | + $noms = join(" ", $noms); |
|
| 1142 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1143 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1144 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1145 | + } |
|
| 1146 | + $annee = $params ? array_shift($params) : ""; |
|
| 1147 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1148 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1149 | + ') ? $x : date("Y"))'; |
|
| 1150 | + |
|
| 1151 | + $mois = $params ? array_shift($params) : ""; |
|
| 1152 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1153 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1154 | + ') ? $x : date("m"))'; |
|
| 1155 | + |
|
| 1156 | + $jour = $params ? array_shift($params) : ""; |
|
| 1157 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1158 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1159 | + ') ? $x : date("d"))'; |
|
| 1160 | + |
|
| 1161 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 1162 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1163 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1164 | + ') ? $x : date("Y"))'; |
|
| 1165 | + |
|
| 1166 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 1167 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1168 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1169 | + ') ? $x : date("m"))'; |
|
| 1170 | + |
|
| 1171 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 1172 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1173 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1174 | + ') ? $x : date("d"))'; |
|
| 1175 | + |
|
| 1176 | + $date = $boucle->id_table . ".$date"; |
|
| 1177 | + |
|
| 1178 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1179 | + if ($type == 'jour') { |
|
| 1180 | + $boucle->where[] = array( |
|
| 1181 | + "'='", |
|
| 1182 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1183 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1184 | + ); |
|
| 1185 | + } elseif ($type == 'mois') { |
|
| 1186 | + $boucle->where[] = array( |
|
| 1187 | + "'='", |
|
| 1188 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1189 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1190 | + ); |
|
| 1191 | + } elseif ($type == 'semaine') { |
|
| 1192 | + $boucle->where[] = array( |
|
| 1193 | + "'AND'", |
|
| 1194 | + array( |
|
| 1195 | + "'>='", |
|
| 1196 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1197 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1198 | + ), |
|
| 1199 | + array( |
|
| 1200 | + "'<='", |
|
| 1201 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1202 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1203 | + ) |
|
| 1204 | + ); |
|
| 1205 | + } elseif (count($crit->param) > 2) { |
|
| 1206 | + $boucle->where[] = array( |
|
| 1207 | + "'AND'", |
|
| 1208 | + array( |
|
| 1209 | + "'>='", |
|
| 1210 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1211 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1212 | + ), |
|
| 1213 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1214 | + ); |
|
| 1215 | + } |
|
| 1216 | + // sinon on prend tout |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | |
@@ -1238,33 +1238,33 @@ discard block |
||
| 1238 | 1238 | * @return void |
| 1239 | 1239 | **/ |
| 1240 | 1240 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1241 | - $boucle = &$boucles[$idb]; |
|
| 1242 | - $a1 = $crit->param[0]; |
|
| 1243 | - $a2 = $crit->param[1]; |
|
| 1244 | - $op = $crit->op; |
|
| 1245 | - |
|
| 1246 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1247 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1248 | - |
|
| 1249 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1250 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1251 | - } else { |
|
| 1252 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1253 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1254 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1255 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1256 | - $mode = (($op == '/') ? '/' : |
|
| 1257 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1258 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1259 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1260 | - $boucle->limit = |
|
| 1261 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1262 | - . ".','." |
|
| 1263 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1264 | - } else { |
|
| 1265 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1241 | + $boucle = &$boucles[$idb]; |
|
| 1242 | + $a1 = $crit->param[0]; |
|
| 1243 | + $a2 = $crit->param[1]; |
|
| 1244 | + $op = $crit->op; |
|
| 1245 | + |
|
| 1246 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1247 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1248 | + |
|
| 1249 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1250 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1251 | + } else { |
|
| 1252 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1253 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1254 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1255 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1256 | + $mode = (($op == '/') ? '/' : |
|
| 1257 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1258 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1259 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1260 | + $boucle->limit = |
|
| 1261 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1262 | + . ".','." |
|
| 1263 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1264 | + } else { |
|
| 1265 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | 1268 | } |
| 1269 | 1269 | |
| 1270 | 1270 | /** |
@@ -1292,63 +1292,63 @@ discard block |
||
| 1292 | 1292 | * @return void |
| 1293 | 1293 | **/ |
| 1294 | 1294 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1295 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1296 | - |
|
| 1297 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1298 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1299 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1300 | - // {1/3} |
|
| 1301 | - if ($op1 == '/') { |
|
| 1302 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1303 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1304 | - "($total_parties ? $total_parties : 1)"; |
|
| 1305 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1306 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1307 | - } else { |
|
| 1308 | - // cas {n-1,x} |
|
| 1309 | - if ($op1 == '-') { |
|
| 1310 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - // cas {x,n-1} |
|
| 1314 | - if ($op2 == '-') { |
|
| 1315 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1316 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1317 | - ($total_parties . ' - 1')); |
|
| 1318 | - } else { |
|
| 1319 | - // {x,1} ou {pagination} |
|
| 1320 | - $fin = '$debut_boucle' |
|
| 1321 | - . (is_numeric($total_parties) ? |
|
| 1322 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1323 | - ('+' . $total_parties . ' - 1')); |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1327 | - if ($op1 == 'p') { |
|
| 1328 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1329 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1330 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - // Notes : |
|
| 1335 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1336 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1337 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1338 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1339 | - |
|
| 1340 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1341 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1342 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1343 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1344 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1345 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1346 | - . "\n\tif (\$debut_boucle>0" |
|
| 1347 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1348 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1349 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1350 | - |
|
| 1351 | - $boucles[$id_boucle]->partie = " |
|
| 1295 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1296 | + |
|
| 1297 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1298 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1299 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1300 | + // {1/3} |
|
| 1301 | + if ($op1 == '/') { |
|
| 1302 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1303 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1304 | + "($total_parties ? $total_parties : 1)"; |
|
| 1305 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1306 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1307 | + } else { |
|
| 1308 | + // cas {n-1,x} |
|
| 1309 | + if ($op1 == '-') { |
|
| 1310 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + // cas {x,n-1} |
|
| 1314 | + if ($op2 == '-') { |
|
| 1315 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1316 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1317 | + ($total_parties . ' - 1')); |
|
| 1318 | + } else { |
|
| 1319 | + // {x,1} ou {pagination} |
|
| 1320 | + $fin = '$debut_boucle' |
|
| 1321 | + . (is_numeric($total_parties) ? |
|
| 1322 | + (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1323 | + ('+' . $total_parties . ' - 1')); |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1327 | + if ($op1 == 'p') { |
|
| 1328 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1329 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1330 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + // Notes : |
|
| 1335 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1336 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1337 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1338 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1339 | + |
|
| 1340 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1341 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1342 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1343 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1344 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1345 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1346 | + . "\n\tif (\$debut_boucle>0" |
|
| 1347 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1348 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1349 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1350 | + |
|
| 1351 | + $boucles[$id_boucle]->partie = " |
|
| 1352 | 1352 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1353 | 1353 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1354 | 1354 | } |
@@ -1365,26 +1365,26 @@ discard block |
||
| 1365 | 1365 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1366 | 1366 | **/ |
| 1367 | 1367 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1368 | - if ($param[0]->type != 'texte') { |
|
| 1369 | - $a1 = calculer_liste(array($param[0]), $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1370 | - if (isset($param[1]->texte)) { |
|
| 1371 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1372 | - |
|
| 1373 | - return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1374 | - } else { |
|
| 1375 | - return array("intval($a1)", 0); |
|
| 1376 | - } |
|
| 1377 | - } else { |
|
| 1378 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1379 | - $a1 = $m[1]; |
|
| 1380 | - if (empty($m[3])) { |
|
| 1381 | - return array($a1, 0); |
|
| 1382 | - } elseif (!empty($m[4])) { |
|
| 1383 | - return array($a1, $m[4]); |
|
| 1384 | - } else { |
|
| 1385 | - return array($a1, calculer_liste(array($param[1]), $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 1386 | - } |
|
| 1387 | - } |
|
| 1368 | + if ($param[0]->type != 'texte') { |
|
| 1369 | + $a1 = calculer_liste(array($param[0]), $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1370 | + if (isset($param[1]->texte)) { |
|
| 1371 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1372 | + |
|
| 1373 | + return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1374 | + } else { |
|
| 1375 | + return array("intval($a1)", 0); |
|
| 1376 | + } |
|
| 1377 | + } else { |
|
| 1378 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1379 | + $a1 = $m[1]; |
|
| 1380 | + if (empty($m[3])) { |
|
| 1381 | + return array($a1, 0); |
|
| 1382 | + } elseif (!empty($m[4])) { |
|
| 1383 | + return array($a1, $m[4]); |
|
| 1384 | + } else { |
|
| 1385 | + return array($a1, calculer_liste(array($param[1]), $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 1386 | + } |
|
| 1387 | + } |
|
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | 1390 | |
@@ -1411,47 +1411,47 @@ discard block |
||
| 1411 | 1411 | * array : Erreur sur un des critères |
| 1412 | 1412 | **/ |
| 1413 | 1413 | function calculer_criteres($idb, &$boucles) { |
| 1414 | - $msg = ''; |
|
| 1415 | - $boucle = $boucles[$idb]; |
|
| 1416 | - $table = strtoupper($boucle->type_requete); |
|
| 1417 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1418 | - |
|
| 1419 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1420 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1421 | - if (!is_array($boucle->criteres)) { |
|
| 1422 | - return array(); |
|
| 1423 | - } |
|
| 1424 | - |
|
| 1425 | - foreach ($boucle->criteres as $crit) { |
|
| 1426 | - $critere = $crit->op; |
|
| 1427 | - // critere personnalise ? |
|
| 1428 | - if ( |
|
| 1429 | - (!$serveur or |
|
| 1430 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1431 | - and (!function_exists($f = $f . "_dist")) |
|
| 1432 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1433 | - and (!function_exists($f = $f . "_dist")) |
|
| 1434 | - ) |
|
| 1435 | - ) |
|
| 1436 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1437 | - and (!function_exists($f = $f . "_dist")) |
|
| 1438 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1439 | - and (!function_exists($f = $f . "_dist")) |
|
| 1440 | - ) { |
|
| 1441 | - // fonction critere standard |
|
| 1442 | - $f = $defaut; |
|
| 1443 | - } |
|
| 1444 | - // compile le critere |
|
| 1445 | - $res = $f($idb, $boucles, $crit); |
|
| 1446 | - |
|
| 1447 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1448 | - if (is_array($res)) { |
|
| 1449 | - $msg = $res; |
|
| 1450 | - erreur_squelette($msg, $boucle); |
|
| 1451 | - } |
|
| 1452 | - } |
|
| 1453 | - |
|
| 1454 | - return $msg; |
|
| 1414 | + $msg = ''; |
|
| 1415 | + $boucle = $boucles[$idb]; |
|
| 1416 | + $table = strtoupper($boucle->type_requete); |
|
| 1417 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1418 | + |
|
| 1419 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1420 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1421 | + if (!is_array($boucle->criteres)) { |
|
| 1422 | + return array(); |
|
| 1423 | + } |
|
| 1424 | + |
|
| 1425 | + foreach ($boucle->criteres as $crit) { |
|
| 1426 | + $critere = $crit->op; |
|
| 1427 | + // critere personnalise ? |
|
| 1428 | + if ( |
|
| 1429 | + (!$serveur or |
|
| 1430 | + ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1431 | + and (!function_exists($f = $f . "_dist")) |
|
| 1432 | + and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1433 | + and (!function_exists($f = $f . "_dist")) |
|
| 1434 | + ) |
|
| 1435 | + ) |
|
| 1436 | + and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1437 | + and (!function_exists($f = $f . "_dist")) |
|
| 1438 | + and (!function_exists($f = "critere_" . $critere)) |
|
| 1439 | + and (!function_exists($f = $f . "_dist")) |
|
| 1440 | + ) { |
|
| 1441 | + // fonction critere standard |
|
| 1442 | + $f = $defaut; |
|
| 1443 | + } |
|
| 1444 | + // compile le critere |
|
| 1445 | + $res = $f($idb, $boucles, $crit); |
|
| 1446 | + |
|
| 1447 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1448 | + if (is_array($res)) { |
|
| 1449 | + $msg = $res; |
|
| 1450 | + erreur_squelette($msg, $boucle); |
|
| 1451 | + } |
|
| 1452 | + } |
|
| 1453 | + |
|
| 1454 | + return $msg; |
|
| 1455 | 1455 | } |
| 1456 | 1456 | |
| 1457 | 1457 | /** |
@@ -1468,11 +1468,11 @@ discard block |
||
| 1468 | 1468 | * @return string Code compilé rééchappé |
| 1469 | 1469 | */ |
| 1470 | 1470 | function kwote($lisp, $serveur = '', $type = '') { |
| 1471 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1472 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1473 | - } else { |
|
| 1474 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1475 | - } |
|
| 1471 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1472 | + return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1473 | + } else { |
|
| 1474 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1475 | + } |
|
| 1476 | 1476 | } |
| 1477 | 1477 | |
| 1478 | 1478 | |
@@ -1491,85 +1491,85 @@ discard block |
||
| 1491 | 1491 | * @return void |
| 1492 | 1492 | **/ |
| 1493 | 1493 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1494 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1495 | - if (!$r) { |
|
| 1496 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1497 | - } |
|
| 1498 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1499 | - |
|
| 1500 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1501 | - |
|
| 1502 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1503 | - $where = $in; |
|
| 1504 | - if ($crit->cond) { |
|
| 1505 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1506 | - $where = array("'?'", $pred, $where, "''"); |
|
| 1507 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1508 | - { |
|
| 1509 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1510 | - } |
|
| 1511 | - } |
|
| 1512 | - if ($crit->exclus) { |
|
| 1513 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1514 | - $where = array("'NOT'", $where); |
|
| 1515 | - } else |
|
| 1516 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1517 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1518 | - { |
|
| 1519 | - $where = array( |
|
| 1520 | - "'NOT'", |
|
| 1521 | - array( |
|
| 1522 | - "'IN'", |
|
| 1523 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1524 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1525 | - ) |
|
| 1526 | - ); |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - $boucles[$idb]->where[] = $where; |
|
| 1531 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1532 | - { |
|
| 1533 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1534 | - } |
|
| 1494 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1495 | + if (!$r) { |
|
| 1496 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1497 | + } |
|
| 1498 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1499 | + |
|
| 1500 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1501 | + |
|
| 1502 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1503 | + $where = $in; |
|
| 1504 | + if ($crit->cond) { |
|
| 1505 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1506 | + $where = array("'?'", $pred, $where, "''"); |
|
| 1507 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1508 | + { |
|
| 1509 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1510 | + } |
|
| 1511 | + } |
|
| 1512 | + if ($crit->exclus) { |
|
| 1513 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1514 | + $where = array("'NOT'", $where); |
|
| 1515 | + } else |
|
| 1516 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1517 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1518 | + { |
|
| 1519 | + $where = array( |
|
| 1520 | + "'NOT'", |
|
| 1521 | + array( |
|
| 1522 | + "'IN'", |
|
| 1523 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1524 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1525 | + ) |
|
| 1526 | + ); |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + $boucles[$idb]->where[] = $where; |
|
| 1531 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1532 | + { |
|
| 1533 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1534 | + } |
|
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | // https://code.spip.net/@critere_IN_cas |
| 1538 | 1538 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1539 | - static $num = array(); |
|
| 1540 | - $descr = $boucles[$idb]->descr; |
|
| 1541 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1542 | - |
|
| 1543 | - $var = '$in' . $cpt++; |
|
| 1544 | - $x = "\n\t$var = array();"; |
|
| 1545 | - foreach ($val as $k => $v) { |
|
| 1546 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1547 | - // optimiser le traitement des constantes |
|
| 1548 | - if (is_numeric($r[2])) { |
|
| 1549 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1550 | - } else { |
|
| 1551 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1552 | - } |
|
| 1553 | - } else { |
|
| 1554 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1555 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1556 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1557 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1558 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1559 | - } |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - $boucles[$idb]->in .= $x; |
|
| 1563 | - |
|
| 1564 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1565 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1566 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1567 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1568 | - if (!$crit2) { |
|
| 1569 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1539 | + static $num = array(); |
|
| 1540 | + $descr = $boucles[$idb]->descr; |
|
| 1541 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1542 | + |
|
| 1543 | + $var = '$in' . $cpt++; |
|
| 1544 | + $x = "\n\t$var = array();"; |
|
| 1545 | + foreach ($val as $k => $v) { |
|
| 1546 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1547 | + // optimiser le traitement des constantes |
|
| 1548 | + if (is_numeric($r[2])) { |
|
| 1549 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1550 | + } else { |
|
| 1551 | + $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1552 | + } |
|
| 1553 | + } else { |
|
| 1554 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1555 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1556 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1557 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1558 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1559 | + } |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + $boucles[$idb]->in .= $x; |
|
| 1563 | + |
|
| 1564 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1565 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1566 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1567 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1568 | + if (!$crit2) { |
|
| 1569 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1573 | 1573 | } |
| 1574 | 1574 | |
| 1575 | 1575 | /** |
@@ -1585,22 +1585,22 @@ discard block |
||
| 1585 | 1585 | * @return void |
| 1586 | 1586 | */ |
| 1587 | 1587 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1588 | - $boucle = &$boucles[$idb]; |
|
| 1589 | - if (isset($crit->param[0])) { |
|
| 1590 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1591 | - } else { |
|
| 1592 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1593 | - } |
|
| 1594 | - |
|
| 1595 | - if ($crit->cond) { |
|
| 1596 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1597 | - } |
|
| 1598 | - |
|
| 1599 | - if ($crit->not) { |
|
| 1600 | - $_where = "array('NOT',$_where)"; |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - $boucle->where[] = $_where; |
|
| 1588 | + $boucle = &$boucles[$idb]; |
|
| 1589 | + if (isset($crit->param[0])) { |
|
| 1590 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1591 | + } else { |
|
| 1592 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + if ($crit->cond) { |
|
| 1596 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1597 | + } |
|
| 1598 | + |
|
| 1599 | + if ($crit->not) { |
|
| 1600 | + $_where = "array('NOT',$_where)"; |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + $boucle->where[] = $_where; |
|
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | 1606 | /** |
@@ -1628,31 +1628,31 @@ discard block |
||
| 1628 | 1628 | * @return void |
| 1629 | 1629 | */ |
| 1630 | 1630 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1631 | - /** @var Boucle $boucle */ |
|
| 1632 | - $boucle = $boucles[$idb]; |
|
| 1633 | - |
|
| 1634 | - $champs = lister_champs_id_conditionnel( |
|
| 1635 | - $boucle->show['table'], |
|
| 1636 | - $boucle->show, |
|
| 1637 | - $boucle->sql_serveur |
|
| 1638 | - ); |
|
| 1639 | - |
|
| 1640 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1641 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1642 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1643 | - } |
|
| 1644 | - // nous aider en mode debug. |
|
| 1645 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1646 | - $boucle->modificateur['id_'] = $champs; |
|
| 1647 | - |
|
| 1648 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1649 | - foreach ($champs as $champ) { |
|
| 1650 | - $critere_id_table = new Critere; |
|
| 1651 | - $critere_id_table->op = $champ; |
|
| 1652 | - $critere_id_table->cond = '?'; |
|
| 1653 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1654 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1655 | - } |
|
| 1631 | + /** @var Boucle $boucle */ |
|
| 1632 | + $boucle = $boucles[$idb]; |
|
| 1633 | + |
|
| 1634 | + $champs = lister_champs_id_conditionnel( |
|
| 1635 | + $boucle->show['table'], |
|
| 1636 | + $boucle->show, |
|
| 1637 | + $boucle->sql_serveur |
|
| 1638 | + ); |
|
| 1639 | + |
|
| 1640 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1641 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1642 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1643 | + } |
|
| 1644 | + // nous aider en mode debug. |
|
| 1645 | + $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1646 | + $boucle->modificateur['id_'] = $champs; |
|
| 1647 | + |
|
| 1648 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1649 | + foreach ($champs as $champ) { |
|
| 1650 | + $critere_id_table = new Critere; |
|
| 1651 | + $critere_id_table->op = $champ; |
|
| 1652 | + $critere_id_table->cond = '?'; |
|
| 1653 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1654 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1655 | + } |
|
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | 1658 | /** |
@@ -1672,79 +1672,79 @@ discard block |
||
| 1672 | 1672 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1673 | 1673 | */ |
| 1674 | 1674 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1675 | - // calculer la description de la table |
|
| 1676 | - if (!is_array($desc)) { |
|
| 1677 | - $desc = description_table($table, $serveur); |
|
| 1678 | - } |
|
| 1679 | - if (!$desc) { |
|
| 1680 | - return []; |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - // Les champs id_xx de la table demandée |
|
| 1684 | - $champs = array_filter( |
|
| 1685 | - array_keys($desc['field']), |
|
| 1686 | - function($champ){ |
|
| 1687 | - return |
|
| 1688 | - strpos($champ, 'id_') === 0 |
|
| 1689 | - or (in_array($champ, array('objet'))); |
|
| 1690 | - } |
|
| 1691 | - ); |
|
| 1692 | - |
|
| 1693 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1694 | - if ( |
|
| 1695 | - in_array('id_rubrique', $champs) |
|
| 1696 | - and !in_array('id_secteur', $champs) |
|
| 1697 | - ) { |
|
| 1698 | - $champs[] = 'id_secteur'; |
|
| 1699 | - } |
|
| 1700 | - |
|
| 1701 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1702 | - if ($serveur) { |
|
| 1703 | - return $champs; |
|
| 1704 | - } |
|
| 1705 | - |
|
| 1706 | - $primary = false; |
|
| 1707 | - $associable = false; |
|
| 1708 | - include_spip('action/editer_liens'); |
|
| 1709 | - |
|
| 1710 | - if (isset($desc['type'])) { |
|
| 1711 | - $primary = id_table_objet($desc['type']); |
|
| 1712 | - $associable = objet_associable($desc['type']); |
|
| 1713 | - } |
|
| 1714 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1715 | - $associable = true; |
|
| 1716 | - } |
|
| 1717 | - |
|
| 1718 | - // liste de toutes les tables principales, sauf la notre |
|
| 1719 | - $tables = lister_tables_objets_sql(); |
|
| 1720 | - unset($tables[$table]); |
|
| 1721 | - |
|
| 1722 | - foreach ($tables as $_table => $_desc) { |
|
| 1723 | - if ( |
|
| 1724 | - $associable |
|
| 1725 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1726 | - or objet_associable($_desc['type']) |
|
| 1727 | - ) { |
|
| 1728 | - $champs[] = id_table_objet($_table); |
|
| 1729 | - } |
|
| 1730 | - } |
|
| 1731 | - $champs = array_values(array_unique($champs)); |
|
| 1732 | - |
|
| 1733 | - // Exclusions de certains id |
|
| 1734 | - $exclusions = pipeline( |
|
| 1735 | - 'exclure_id_conditionnel', |
|
| 1736 | - array( |
|
| 1737 | - 'args' => array( |
|
| 1738 | - 'table' => $table, |
|
| 1739 | - 'id_table_objet' => $primary, |
|
| 1740 | - 'associable' => $associable, |
|
| 1741 | - ), |
|
| 1742 | - 'data' => array(), |
|
| 1743 | - ) |
|
| 1744 | - ); |
|
| 1745 | - $champs = array_diff($champs, $exclusions); |
|
| 1746 | - |
|
| 1747 | - return $champs; |
|
| 1675 | + // calculer la description de la table |
|
| 1676 | + if (!is_array($desc)) { |
|
| 1677 | + $desc = description_table($table, $serveur); |
|
| 1678 | + } |
|
| 1679 | + if (!$desc) { |
|
| 1680 | + return []; |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + // Les champs id_xx de la table demandée |
|
| 1684 | + $champs = array_filter( |
|
| 1685 | + array_keys($desc['field']), |
|
| 1686 | + function($champ){ |
|
| 1687 | + return |
|
| 1688 | + strpos($champ, 'id_') === 0 |
|
| 1689 | + or (in_array($champ, array('objet'))); |
|
| 1690 | + } |
|
| 1691 | + ); |
|
| 1692 | + |
|
| 1693 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1694 | + if ( |
|
| 1695 | + in_array('id_rubrique', $champs) |
|
| 1696 | + and !in_array('id_secteur', $champs) |
|
| 1697 | + ) { |
|
| 1698 | + $champs[] = 'id_secteur'; |
|
| 1699 | + } |
|
| 1700 | + |
|
| 1701 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1702 | + if ($serveur) { |
|
| 1703 | + return $champs; |
|
| 1704 | + } |
|
| 1705 | + |
|
| 1706 | + $primary = false; |
|
| 1707 | + $associable = false; |
|
| 1708 | + include_spip('action/editer_liens'); |
|
| 1709 | + |
|
| 1710 | + if (isset($desc['type'])) { |
|
| 1711 | + $primary = id_table_objet($desc['type']); |
|
| 1712 | + $associable = objet_associable($desc['type']); |
|
| 1713 | + } |
|
| 1714 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1715 | + $associable = true; |
|
| 1716 | + } |
|
| 1717 | + |
|
| 1718 | + // liste de toutes les tables principales, sauf la notre |
|
| 1719 | + $tables = lister_tables_objets_sql(); |
|
| 1720 | + unset($tables[$table]); |
|
| 1721 | + |
|
| 1722 | + foreach ($tables as $_table => $_desc) { |
|
| 1723 | + if ( |
|
| 1724 | + $associable |
|
| 1725 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1726 | + or objet_associable($_desc['type']) |
|
| 1727 | + ) { |
|
| 1728 | + $champs[] = id_table_objet($_table); |
|
| 1729 | + } |
|
| 1730 | + } |
|
| 1731 | + $champs = array_values(array_unique($champs)); |
|
| 1732 | + |
|
| 1733 | + // Exclusions de certains id |
|
| 1734 | + $exclusions = pipeline( |
|
| 1735 | + 'exclure_id_conditionnel', |
|
| 1736 | + array( |
|
| 1737 | + 'args' => array( |
|
| 1738 | + 'table' => $table, |
|
| 1739 | + 'id_table_objet' => $primary, |
|
| 1740 | + 'associable' => $associable, |
|
| 1741 | + ), |
|
| 1742 | + 'data' => array(), |
|
| 1743 | + ) |
|
| 1744 | + ); |
|
| 1745 | + $champs = array_diff($champs, $exclusions); |
|
| 1746 | + |
|
| 1747 | + return $champs; |
|
| 1748 | 1748 | } |
| 1749 | 1749 | |
| 1750 | 1750 | /** |
@@ -1799,27 +1799,27 @@ discard block |
||
| 1799 | 1799 | * @return void |
| 1800 | 1800 | */ |
| 1801 | 1801 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1802 | - $boucle = &$boucles[$idb]; |
|
| 1803 | - |
|
| 1804 | - // definition du champ par defaut |
|
| 1805 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1806 | - : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1807 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1808 | - : calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1809 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1810 | - : calculer_liste(array($crit->param[2][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1811 | - |
|
| 1812 | - $_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):'')"; |
|
| 1813 | - |
|
| 1814 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1815 | - $_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)"; |
|
| 1816 | - |
|
| 1817 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1818 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1819 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1820 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1821 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1822 | - $boucle->hash .= " |
|
| 1802 | + $boucle = &$boucles[$idb]; |
|
| 1803 | + |
|
| 1804 | + // definition du champ par defaut |
|
| 1805 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1806 | + : calculer_liste(array($crit->param[0][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1807 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1808 | + : calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1809 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1810 | + : calculer_liste(array($crit->param[2][0]), $idb, $boucles, $boucle->id_parent); |
|
| 1811 | + |
|
| 1812 | + $_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):'')"; |
|
| 1813 | + |
|
| 1814 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1815 | + $_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)"; |
|
| 1816 | + |
|
| 1817 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1818 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1819 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1820 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1821 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1822 | + $boucle->hash .= " |
|
| 1823 | 1823 | \$senstri = ''; |
| 1824 | 1824 | \$tri = $_tri; |
| 1825 | 1825 | if (\$tri){ |
@@ -1827,8 +1827,8 @@ discard block |
||
| 1827 | 1827 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1828 | 1828 | }; |
| 1829 | 1829 | "; |
| 1830 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1831 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1830 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1831 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | 1834 | # Criteres de comparaison |
@@ -1845,20 +1845,20 @@ discard block |
||
| 1845 | 1845 | * @return void |
| 1846 | 1846 | **/ |
| 1847 | 1847 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1848 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1849 | - if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1850 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1854 | - if (!$r) { |
|
| 1855 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1856 | - # if (!$crit->cond) { |
|
| 1857 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1858 | - # } |
|
| 1859 | - } else { |
|
| 1860 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1861 | - } |
|
| 1848 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1849 | + if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1850 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1851 | + } |
|
| 1852 | + |
|
| 1853 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1854 | + if (!$r) { |
|
| 1855 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1856 | + # if (!$crit->cond) { |
|
| 1857 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1858 | + # } |
|
| 1859 | + } else { |
|
| 1860 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1861 | + } |
|
| 1862 | 1862 | } |
| 1863 | 1863 | |
| 1864 | 1864 | |
@@ -1878,63 +1878,63 @@ discard block |
||
| 1878 | 1878 | * @return void |
| 1879 | 1879 | **/ |
| 1880 | 1880 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1881 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1882 | - |
|
| 1883 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1884 | - |
|
| 1885 | - // inserer la negation (cf !...) |
|
| 1886 | - |
|
| 1887 | - if ($crit->not) { |
|
| 1888 | - $where = array("'NOT'", $where); |
|
| 1889 | - } |
|
| 1890 | - if ($crit->exclus) { |
|
| 1891 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1892 | - $where = array("'NOT'", $where); |
|
| 1893 | - } else |
|
| 1894 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1895 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1896 | - { |
|
| 1897 | - $where = array( |
|
| 1898 | - "'NOT'", |
|
| 1899 | - array( |
|
| 1900 | - "'IN'", |
|
| 1901 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1902 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1903 | - ) |
|
| 1904 | - ); |
|
| 1905 | - } |
|
| 1906 | - } |
|
| 1907 | - |
|
| 1908 | - // inserer la condition (cf {lang?}) |
|
| 1909 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1910 | - if ($crit->cond) { |
|
| 1911 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1912 | - if ($col == "date" or $col == "date_redac") { |
|
| 1913 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1914 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1915 | - } |
|
| 1916 | - } |
|
| 1917 | - |
|
| 1918 | - if ($op == '=' and !$crit->not) { |
|
| 1919 | - $where = array( |
|
| 1920 | - "'?'", |
|
| 1921 | - "(is_array($pred))", |
|
| 1922 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1923 | - $where |
|
| 1924 | - ); |
|
| 1925 | - } |
|
| 1926 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1927 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1928 | - { |
|
| 1929 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1930 | - } |
|
| 1931 | - } |
|
| 1932 | - |
|
| 1933 | - $boucles[$idb]->where[] = $where; |
|
| 1934 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1935 | - { |
|
| 1936 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1937 | - } |
|
| 1881 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1882 | + |
|
| 1883 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1884 | + |
|
| 1885 | + // inserer la negation (cf !...) |
|
| 1886 | + |
|
| 1887 | + if ($crit->not) { |
|
| 1888 | + $where = array("'NOT'", $where); |
|
| 1889 | + } |
|
| 1890 | + if ($crit->exclus) { |
|
| 1891 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1892 | + $where = array("'NOT'", $where); |
|
| 1893 | + } else |
|
| 1894 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1895 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1896 | + { |
|
| 1897 | + $where = array( |
|
| 1898 | + "'NOT'", |
|
| 1899 | + array( |
|
| 1900 | + "'IN'", |
|
| 1901 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1902 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1903 | + ) |
|
| 1904 | + ); |
|
| 1905 | + } |
|
| 1906 | + } |
|
| 1907 | + |
|
| 1908 | + // inserer la condition (cf {lang?}) |
|
| 1909 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1910 | + if ($crit->cond) { |
|
| 1911 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1912 | + if ($col == "date" or $col == "date_redac") { |
|
| 1913 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1914 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1915 | + } |
|
| 1916 | + } |
|
| 1917 | + |
|
| 1918 | + if ($op == '=' and !$crit->not) { |
|
| 1919 | + $where = array( |
|
| 1920 | + "'?'", |
|
| 1921 | + "(is_array($pred))", |
|
| 1922 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1923 | + $where |
|
| 1924 | + ); |
|
| 1925 | + } |
|
| 1926 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1927 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1928 | + { |
|
| 1929 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1930 | + } |
|
| 1931 | + } |
|
| 1932 | + |
|
| 1933 | + $boucles[$idb]->where[] = $where; |
|
| 1934 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1935 | + { |
|
| 1936 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1937 | + } |
|
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | 1940 | |
@@ -1975,167 +1975,167 @@ discard block |
||
| 1975 | 1975 | **/ |
| 1976 | 1976 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1977 | 1977 | |
| 1978 | - $boucle = &$boucles[$idb]; |
|
| 1979 | - $type = $boucle->type_requete; |
|
| 1980 | - $table = $boucle->id_table; |
|
| 1981 | - $desc = $boucle->show; |
|
| 1982 | - $col_vraie = null; |
|
| 1983 | - |
|
| 1984 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1985 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1986 | - |
|
| 1987 | - $col_alias = $col; |
|
| 1988 | - $where_complement = false; |
|
| 1989 | - |
|
| 1990 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1991 | - if ($col == 'id_enfant') { |
|
| 1992 | - $col = $boucle->primary; |
|
| 1993 | - } |
|
| 1994 | - |
|
| 1995 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1996 | - if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1997 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1998 | - ) { |
|
| 1999 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2000 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2001 | - else { |
|
| 2002 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 2003 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2004 | - } |
|
| 2005 | - |
|
| 2006 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2007 | - // sauf si exception declaree : sauter cette etape |
|
| 2008 | - else { |
|
| 2009 | - if ( |
|
| 2010 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2011 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2012 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2013 | - ) { |
|
| 2014 | - $e = decompose_champ_id_objet($col); |
|
| 2015 | - $col = array_shift($e); |
|
| 2016 | - $where_complement = primary_doublee($e, $table); |
|
| 2017 | - } // Cas particulier : expressions de date |
|
| 2018 | - else { |
|
| 2019 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2020 | - list($col, $col_vraie) = $c; |
|
| 2021 | - $table = ''; |
|
| 2022 | - } // table explicitée {mots.titre} |
|
| 2023 | - else { |
|
| 2024 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2025 | - list(, $table, $col) = $r; |
|
| 2026 | - $col_alias = $col; |
|
| 2027 | - |
|
| 2028 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2029 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2030 | - and isset($desc['field'][$col]) |
|
| 2031 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2032 | - ) { |
|
| 2033 | - $table = $cle; |
|
| 2034 | - } else { |
|
| 2035 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 2036 | - } |
|
| 2037 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2038 | - if (!$table) { |
|
| 2039 | - return ''; |
|
| 2040 | - } |
|
| 2041 | - } |
|
| 2042 | - // si le champ n'est pas trouvé dans la table, |
|
| 2043 | - // on cherche si une jointure peut l'obtenir |
|
| 2044 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2045 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2046 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2047 | - $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 |
|
| 2048 | - } |
|
| 2049 | - else { |
|
| 2050 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2051 | - if (!$r) { |
|
| 2052 | - return ''; |
|
| 2053 | - } |
|
| 2054 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2055 | - } |
|
| 2056 | - } |
|
| 2057 | - } |
|
| 2058 | - } |
|
| 2059 | - } |
|
| 2060 | - } |
|
| 2061 | - |
|
| 2062 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2063 | - // Dans tous les cas, |
|
| 2064 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2065 | - // et passer dans sql_quote avec le type si connu |
|
| 2066 | - // et int sinon si la valeur est numerique |
|
| 2067 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2068 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2069 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2070 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2071 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2072 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2073 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2074 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2075 | - } |
|
| 2076 | - // sinon expliciter les |
|
| 2077 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2078 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2079 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2080 | - // sans toucher aux |
|
| 2081 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2082 | - // sql_quote(truc,'','varchar') |
|
| 2083 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2084 | - // si pas deja un type |
|
| 2085 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2086 | - ) { |
|
| 2087 | - $r = $r[1] |
|
| 2088 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2089 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2090 | - $val[0] = "sql_quote($r)"; |
|
| 2091 | - } |
|
| 2092 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2093 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2094 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2095 | - } |
|
| 2096 | - } |
|
| 2097 | - |
|
| 2098 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2099 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2100 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2104 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2105 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2106 | - if ($table === $boucle->id_table) { |
|
| 2107 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2108 | - if ($col_alias != $col_vraie) { |
|
| 2109 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2110 | - } |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2114 | - // il faut alors interdire a la fonction de boucle |
|
| 2115 | - // de mettre ses propres criteres de statut |
|
| 2116 | - // https://www.spip.net/@statut (a documenter) |
|
| 2117 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2118 | - if ($col == 'statut') { |
|
| 2119 | - $boucles[$idb]->statut = true; |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2123 | - if ($table) { |
|
| 2124 | - if ($col[0] == "`") { |
|
| 2125 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2126 | - } else { |
|
| 2127 | - $arg = "$table.$col"; |
|
| 2128 | - } |
|
| 2129 | - } else { |
|
| 2130 | - $arg = $col; |
|
| 2131 | - } |
|
| 2132 | - |
|
| 2133 | - // inserer la fonction SQL |
|
| 2134 | - if ($fct) { |
|
| 2135 | - $arg = "$fct($arg$args_sql)"; |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1978 | + $boucle = &$boucles[$idb]; |
|
| 1979 | + $type = $boucle->type_requete; |
|
| 1980 | + $table = $boucle->id_table; |
|
| 1981 | + $desc = $boucle->show; |
|
| 1982 | + $col_vraie = null; |
|
| 1983 | + |
|
| 1984 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1985 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1986 | + |
|
| 1987 | + $col_alias = $col; |
|
| 1988 | + $where_complement = false; |
|
| 1989 | + |
|
| 1990 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1991 | + if ($col == 'id_enfant') { |
|
| 1992 | + $col = $boucle->primary; |
|
| 1993 | + } |
|
| 1994 | + |
|
| 1995 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1996 | + if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1997 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1998 | + ) { |
|
| 1999 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2000 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2001 | + else { |
|
| 2002 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 2003 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2004 | + } |
|
| 2005 | + |
|
| 2006 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2007 | + // sauf si exception declaree : sauter cette etape |
|
| 2008 | + else { |
|
| 2009 | + if ( |
|
| 2010 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2011 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2012 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2013 | + ) { |
|
| 2014 | + $e = decompose_champ_id_objet($col); |
|
| 2015 | + $col = array_shift($e); |
|
| 2016 | + $where_complement = primary_doublee($e, $table); |
|
| 2017 | + } // Cas particulier : expressions de date |
|
| 2018 | + else { |
|
| 2019 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2020 | + list($col, $col_vraie) = $c; |
|
| 2021 | + $table = ''; |
|
| 2022 | + } // table explicitée {mots.titre} |
|
| 2023 | + else { |
|
| 2024 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2025 | + list(, $table, $col) = $r; |
|
| 2026 | + $col_alias = $col; |
|
| 2027 | + |
|
| 2028 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2029 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2030 | + and isset($desc['field'][$col]) |
|
| 2031 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2032 | + ) { |
|
| 2033 | + $table = $cle; |
|
| 2034 | + } else { |
|
| 2035 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 2036 | + } |
|
| 2037 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2038 | + if (!$table) { |
|
| 2039 | + return ''; |
|
| 2040 | + } |
|
| 2041 | + } |
|
| 2042 | + // si le champ n'est pas trouvé dans la table, |
|
| 2043 | + // on cherche si une jointure peut l'obtenir |
|
| 2044 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2045 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2046 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2047 | + $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 |
|
| 2048 | + } |
|
| 2049 | + else { |
|
| 2050 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2051 | + if (!$r) { |
|
| 2052 | + return ''; |
|
| 2053 | + } |
|
| 2054 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2055 | + } |
|
| 2056 | + } |
|
| 2057 | + } |
|
| 2058 | + } |
|
| 2059 | + } |
|
| 2060 | + } |
|
| 2061 | + |
|
| 2062 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2063 | + // Dans tous les cas, |
|
| 2064 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2065 | + // et passer dans sql_quote avec le type si connu |
|
| 2066 | + // et int sinon si la valeur est numerique |
|
| 2067 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2068 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2069 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2070 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2071 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2072 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2073 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2074 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2075 | + } |
|
| 2076 | + // sinon expliciter les |
|
| 2077 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2078 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2079 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2080 | + // sans toucher aux |
|
| 2081 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2082 | + // sql_quote(truc,'','varchar') |
|
| 2083 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2084 | + // si pas deja un type |
|
| 2085 | + and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2086 | + ) { |
|
| 2087 | + $r = $r[1] |
|
| 2088 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2089 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2090 | + $val[0] = "sql_quote($r)"; |
|
| 2091 | + } |
|
| 2092 | + elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2093 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2094 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2095 | + } |
|
| 2096 | + } |
|
| 2097 | + |
|
| 2098 | + if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2099 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2100 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2104 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2105 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2106 | + if ($table === $boucle->id_table) { |
|
| 2107 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2108 | + if ($col_alias != $col_vraie) { |
|
| 2109 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2110 | + } |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2114 | + // il faut alors interdire a la fonction de boucle |
|
| 2115 | + // de mettre ses propres criteres de statut |
|
| 2116 | + // https://www.spip.net/@statut (a documenter) |
|
| 2117 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2118 | + if ($col == 'statut') { |
|
| 2119 | + $boucles[$idb]->statut = true; |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2123 | + if ($table) { |
|
| 2124 | + if ($col[0] == "`") { |
|
| 2125 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2126 | + } else { |
|
| 2127 | + $arg = "$table.$col"; |
|
| 2128 | + } |
|
| 2129 | + } else { |
|
| 2130 | + $arg = $col; |
|
| 2131 | + } |
|
| 2132 | + |
|
| 2133 | + // inserer la fonction SQL |
|
| 2134 | + if ($fct) { |
|
| 2135 | + $arg = "$fct($arg$args_sql)"; |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | |
@@ -2164,77 +2164,77 @@ discard block |
||
| 2164 | 2164 | **/ |
| 2165 | 2165 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2166 | 2166 | |
| 2167 | - $where = ''; |
|
| 2168 | - |
|
| 2169 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2170 | - // gestion par les plugins des jointures tordues |
|
| 2171 | - // pas automatiques mais necessaires |
|
| 2172 | - $table_sql = table_objet_sql($table); |
|
| 2173 | - if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2174 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2175 | - and |
|
| 2176 | - ( |
|
| 2177 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2178 | - or |
|
| 2179 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2180 | - ) |
|
| 2181 | - ) { |
|
| 2182 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2183 | - $index = isset($t[$col]) |
|
| 2184 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2185 | - |
|
| 2186 | - if (count($index) == 3) { |
|
| 2187 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2188 | - } elseif (count($index) == 2) { |
|
| 2189 | - list($t, $col) = $t[$col]; |
|
| 2190 | - } elseif (count($index) == 1) { |
|
| 2191 | - list($calculer_critere_externe) = $index; |
|
| 2192 | - $t = $table; |
|
| 2193 | - } else { |
|
| 2194 | - $t = ''; |
|
| 2195 | - } // jointure non declaree. La trouver. |
|
| 2196 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2197 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2198 | - } else { |
|
| 2199 | - $t = ''; |
|
| 2200 | - } // jointure non declaree. La trouver. |
|
| 2201 | - |
|
| 2202 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2203 | - |
|
| 2204 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2205 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2206 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2207 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2208 | - $table = ""; |
|
| 2209 | - if ($boucle->jointures_explicites) { |
|
| 2210 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2211 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2212 | - } |
|
| 2213 | - |
|
| 2214 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2215 | - if (!$table) { |
|
| 2216 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2217 | - } |
|
| 2218 | - |
|
| 2219 | - if (!$table) { |
|
| 2220 | - return ''; |
|
| 2221 | - } |
|
| 2222 | - |
|
| 2223 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2224 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2225 | - |
|
| 2226 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2227 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2228 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2229 | - $e = decompose_champ_id_objet($col); |
|
| 2230 | - $col = array_shift($e); |
|
| 2231 | - $where = primary_doublee($e, $table); |
|
| 2232 | - } else { |
|
| 2233 | - $col = reset($cle); |
|
| 2234 | - } |
|
| 2235 | - } |
|
| 2236 | - |
|
| 2237 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 2167 | + $where = ''; |
|
| 2168 | + |
|
| 2169 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2170 | + // gestion par les plugins des jointures tordues |
|
| 2171 | + // pas automatiques mais necessaires |
|
| 2172 | + $table_sql = table_objet_sql($table); |
|
| 2173 | + if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2174 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2175 | + and |
|
| 2176 | + ( |
|
| 2177 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2178 | + or |
|
| 2179 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2180 | + ) |
|
| 2181 | + ) { |
|
| 2182 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2183 | + $index = isset($t[$col]) |
|
| 2184 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2185 | + |
|
| 2186 | + if (count($index) == 3) { |
|
| 2187 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2188 | + } elseif (count($index) == 2) { |
|
| 2189 | + list($t, $col) = $t[$col]; |
|
| 2190 | + } elseif (count($index) == 1) { |
|
| 2191 | + list($calculer_critere_externe) = $index; |
|
| 2192 | + $t = $table; |
|
| 2193 | + } else { |
|
| 2194 | + $t = ''; |
|
| 2195 | + } // jointure non declaree. La trouver. |
|
| 2196 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2197 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2198 | + } else { |
|
| 2199 | + $t = ''; |
|
| 2200 | + } // jointure non declaree. La trouver. |
|
| 2201 | + |
|
| 2202 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2203 | + |
|
| 2204 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2205 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2206 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2207 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2208 | + $table = ""; |
|
| 2209 | + if ($boucle->jointures_explicites) { |
|
| 2210 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2211 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2212 | + } |
|
| 2213 | + |
|
| 2214 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2215 | + if (!$table) { |
|
| 2216 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2217 | + } |
|
| 2218 | + |
|
| 2219 | + if (!$table) { |
|
| 2220 | + return ''; |
|
| 2221 | + } |
|
| 2222 | + |
|
| 2223 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2224 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2225 | + |
|
| 2226 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2227 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2228 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2229 | + $e = decompose_champ_id_objet($col); |
|
| 2230 | + $col = array_shift($e); |
|
| 2231 | + $where = primary_doublee($e, $table); |
|
| 2232 | + } else { |
|
| 2233 | + $col = reset($cle); |
|
| 2234 | + } |
|
| 2235 | + } |
|
| 2236 | + |
|
| 2237 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | 2240 | |
@@ -2255,10 +2255,10 @@ discard block |
||
| 2255 | 2255 | * - valeur |
| 2256 | 2256 | **/ |
| 2257 | 2257 | function primary_doublee($decompose, $table) { |
| 2258 | - $e1 = reset($decompose); |
|
| 2259 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2258 | + $e1 = reset($decompose); |
|
| 2259 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2260 | 2260 | |
| 2261 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2261 | + return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | 2264 | /** |
@@ -2289,56 +2289,56 @@ discard block |
||
| 2289 | 2289 | * Vide sinon. |
| 2290 | 2290 | */ |
| 2291 | 2291 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2292 | - // si on demande un truc du genre spip_mots |
|
| 2293 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2294 | - // et qu'on est la |
|
| 2295 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2296 | - if ($checkarrivee |
|
| 2297 | - and is_string($checkarrivee) |
|
| 2298 | - and $a = table_objet($checkarrivee) |
|
| 2299 | - and in_array($a . '_liens', $joints) |
|
| 2300 | - ) { |
|
| 2301 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2302 | - return $res; |
|
| 2303 | - } |
|
| 2304 | - } |
|
| 2305 | - foreach ($joints as $joint) { |
|
| 2306 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2307 | - // alias de table dans le from |
|
| 2308 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2309 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2310 | - $cols = $arrivee[2]; |
|
| 2311 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2312 | - if (count($cols) > 2) { |
|
| 2313 | - array_pop($cols); |
|
| 2314 | - } |
|
| 2315 | - if ($t) { |
|
| 2316 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2317 | - $joindre = false; |
|
| 2318 | - foreach ($cols as $col) { |
|
| 2319 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2320 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2321 | - $joindre = true; |
|
| 2322 | - } else { |
|
| 2323 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2324 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2325 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2326 | - $joindre = true; |
|
| 2327 | - } |
|
| 2328 | - } |
|
| 2329 | - } |
|
| 2330 | - if (!$joindre) { |
|
| 2331 | - return $t; |
|
| 2332 | - } |
|
| 2333 | - } |
|
| 2334 | - array_pop($arrivee); |
|
| 2335 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2336 | - return $res; |
|
| 2337 | - } |
|
| 2338 | - } |
|
| 2339 | - } |
|
| 2340 | - |
|
| 2341 | - return ''; |
|
| 2292 | + // si on demande un truc du genre spip_mots |
|
| 2293 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2294 | + // et qu'on est la |
|
| 2295 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2296 | + if ($checkarrivee |
|
| 2297 | + and is_string($checkarrivee) |
|
| 2298 | + and $a = table_objet($checkarrivee) |
|
| 2299 | + and in_array($a . '_liens', $joints) |
|
| 2300 | + ) { |
|
| 2301 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2302 | + return $res; |
|
| 2303 | + } |
|
| 2304 | + } |
|
| 2305 | + foreach ($joints as $joint) { |
|
| 2306 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2307 | + // alias de table dans le from |
|
| 2308 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2309 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2310 | + $cols = $arrivee[2]; |
|
| 2311 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2312 | + if (count($cols) > 2) { |
|
| 2313 | + array_pop($cols); |
|
| 2314 | + } |
|
| 2315 | + if ($t) { |
|
| 2316 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2317 | + $joindre = false; |
|
| 2318 | + foreach ($cols as $col) { |
|
| 2319 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2320 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2321 | + $joindre = true; |
|
| 2322 | + } else { |
|
| 2323 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2324 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2325 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2326 | + $joindre = true; |
|
| 2327 | + } |
|
| 2328 | + } |
|
| 2329 | + } |
|
| 2330 | + if (!$joindre) { |
|
| 2331 | + return $t; |
|
| 2332 | + } |
|
| 2333 | + } |
|
| 2334 | + array_pop($arrivee); |
|
| 2335 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2336 | + return $res; |
|
| 2337 | + } |
|
| 2338 | + } |
|
| 2339 | + } |
|
| 2340 | + |
|
| 2341 | + return ''; |
|
| 2342 | 2342 | |
| 2343 | 2343 | } |
| 2344 | 2344 | |
@@ -2365,29 +2365,29 @@ discard block |
||
| 2365 | 2365 | * Alias de la table de jointure (Lx) |
| 2366 | 2366 | */ |
| 2367 | 2367 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2368 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2369 | - |
|
| 2370 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2371 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2372 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2373 | - |
|
| 2374 | - if (!$intermediaire or !$arrivee) { |
|
| 2375 | - return ''; |
|
| 2376 | - } |
|
| 2377 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2378 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2379 | - |
|
| 2380 | - $res = fabrique_jointures($boucle, |
|
| 2381 | - array( |
|
| 2382 | - array( |
|
| 2383 | - $boucle->id_table, |
|
| 2384 | - $intermediaire, |
|
| 2385 | - array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2386 | - ), |
|
| 2387 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2388 | - ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2389 | - |
|
| 2390 | - return $res; |
|
| 2368 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2369 | + |
|
| 2370 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2371 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2372 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2373 | + |
|
| 2374 | + if (!$intermediaire or !$arrivee) { |
|
| 2375 | + return ''; |
|
| 2376 | + } |
|
| 2377 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2378 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2379 | + |
|
| 2380 | + $res = fabrique_jointures($boucle, |
|
| 2381 | + array( |
|
| 2382 | + array( |
|
| 2383 | + $boucle->id_table, |
|
| 2384 | + $intermediaire, |
|
| 2385 | + array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2386 | + ), |
|
| 2387 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2388 | + ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2389 | + |
|
| 2390 | + return $res; |
|
| 2391 | 2391 | } |
| 2392 | 2392 | |
| 2393 | 2393 | |
@@ -2404,17 +2404,17 @@ discard block |
||
| 2404 | 2404 | * false sinon. |
| 2405 | 2405 | **/ |
| 2406 | 2406 | function trouver_champ($champ, $where) { |
| 2407 | - if (!is_array($where)) { |
|
| 2408 | - return preg_match($champ, $where); |
|
| 2409 | - } else { |
|
| 2410 | - foreach ($where as $clause) { |
|
| 2411 | - if (trouver_champ($champ, $clause)) { |
|
| 2412 | - return true; |
|
| 2413 | - } |
|
| 2414 | - } |
|
| 2415 | - |
|
| 2416 | - return false; |
|
| 2417 | - } |
|
| 2407 | + if (!is_array($where)) { |
|
| 2408 | + return preg_match($champ, $where); |
|
| 2409 | + } else { |
|
| 2410 | + foreach ($where as $clause) { |
|
| 2411 | + if (trouver_champ($champ, $clause)) { |
|
| 2412 | + return true; |
|
| 2413 | + } |
|
| 2414 | + } |
|
| 2415 | + |
|
| 2416 | + return false; |
|
| 2417 | + } |
|
| 2418 | 2418 | } |
| 2419 | 2419 | |
| 2420 | 2420 | |
@@ -2440,128 +2440,128 @@ discard block |
||
| 2440 | 2440 | * - string $args_sql Suite des arguments du critère. ? |
| 2441 | 2441 | **/ |
| 2442 | 2442 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2443 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2444 | - if (count($crit->param) == 0) { |
|
| 2445 | - $op = '='; |
|
| 2446 | - $col = $val = $crit->op; |
|
| 2447 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2448 | - $val = $r[2]; |
|
| 2449 | - } |
|
| 2450 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2451 | - if ($val == 'lang') { |
|
| 2452 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2453 | - } else { |
|
| 2454 | - $defaut = null; |
|
| 2455 | - if ($val == 'id_parent') { |
|
| 2456 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2457 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2458 | - // pour eviter l'erreur SQL |
|
| 2459 | - $val = $boucles[$idb]->primary; |
|
| 2460 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2461 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2462 | - } elseif ($val == 'id_enfant') { |
|
| 2463 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2464 | - // de la boucle superieure |
|
| 2465 | - $val = 'id_parent'; |
|
| 2466 | - } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2467 | - // un critere conditionnel sur date est traite a part |
|
| 2468 | - // car la date est mise d'office par SPIP, |
|
| 2469 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2473 | - $val = array(kwote($val)); |
|
| 2474 | - } |
|
| 2475 | - } else { |
|
| 2476 | - // comparaison explicite |
|
| 2477 | - // le phraseur impose que le premier param soit du texte |
|
| 2478 | - $params = $crit->param; |
|
| 2479 | - $op = $crit->op; |
|
| 2480 | - if ($op == '==') { |
|
| 2481 | - $op = 'REGEXP'; |
|
| 2482 | - } |
|
| 2483 | - $col = array_shift($params); |
|
| 2484 | - $col = $col[0]->texte; |
|
| 2485 | - |
|
| 2486 | - $val = array(); |
|
| 2487 | - $parent = $boucles[$idb]->id_parent; |
|
| 2488 | - |
|
| 2489 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2490 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2491 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2492 | - if (count($params) == 1 |
|
| 2493 | - and count($params[0]) == 3 |
|
| 2494 | - and $params[0][0]->type == 'texte' |
|
| 2495 | - and $params[0][2]->type == 'texte' |
|
| 2496 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2497 | - and (($p == "'") or ($p == '"')) |
|
| 2498 | - and $params[0][1]->type == 'champ' |
|
| 2499 | - ) { |
|
| 2500 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2501 | - } else { |
|
| 2502 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2503 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2504 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2505 | - $val[] = $a; |
|
| 2506 | - } else { |
|
| 2507 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2508 | - } // toujours quoter en char ici |
|
| 2509 | - } |
|
| 2510 | - } |
|
| 2511 | - } |
|
| 2512 | - |
|
| 2513 | - $fct = $args_sql = ''; |
|
| 2514 | - // fonction SQL ? |
|
| 2515 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2516 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2517 | - $fct = $m[1]; |
|
| 2518 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2519 | - $col = $a[1]; |
|
| 2520 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2521 | - $col = $m[1]; |
|
| 2522 | - $args_sql = $m[2]; |
|
| 2523 | - } |
|
| 2524 | - $args_sql .= $a[2]; |
|
| 2525 | - } |
|
| 2526 | - |
|
| 2527 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 2443 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2444 | + if (count($crit->param) == 0) { |
|
| 2445 | + $op = '='; |
|
| 2446 | + $col = $val = $crit->op; |
|
| 2447 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2448 | + $val = $r[2]; |
|
| 2449 | + } |
|
| 2450 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2451 | + if ($val == 'lang') { |
|
| 2452 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2453 | + } else { |
|
| 2454 | + $defaut = null; |
|
| 2455 | + if ($val == 'id_parent') { |
|
| 2456 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2457 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2458 | + // pour eviter l'erreur SQL |
|
| 2459 | + $val = $boucles[$idb]->primary; |
|
| 2460 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2461 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2462 | + } elseif ($val == 'id_enfant') { |
|
| 2463 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2464 | + // de la boucle superieure |
|
| 2465 | + $val = 'id_parent'; |
|
| 2466 | + } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2467 | + // un critere conditionnel sur date est traite a part |
|
| 2468 | + // car la date est mise d'office par SPIP, |
|
| 2469 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2473 | + $val = array(kwote($val)); |
|
| 2474 | + } |
|
| 2475 | + } else { |
|
| 2476 | + // comparaison explicite |
|
| 2477 | + // le phraseur impose que le premier param soit du texte |
|
| 2478 | + $params = $crit->param; |
|
| 2479 | + $op = $crit->op; |
|
| 2480 | + if ($op == '==') { |
|
| 2481 | + $op = 'REGEXP'; |
|
| 2482 | + } |
|
| 2483 | + $col = array_shift($params); |
|
| 2484 | + $col = $col[0]->texte; |
|
| 2485 | + |
|
| 2486 | + $val = array(); |
|
| 2487 | + $parent = $boucles[$idb]->id_parent; |
|
| 2488 | + |
|
| 2489 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2490 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2491 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2492 | + if (count($params) == 1 |
|
| 2493 | + and count($params[0]) == 3 |
|
| 2494 | + and $params[0][0]->type == 'texte' |
|
| 2495 | + and $params[0][2]->type == 'texte' |
|
| 2496 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2497 | + and (($p == "'") or ($p == '"')) |
|
| 2498 | + and $params[0][1]->type == 'champ' |
|
| 2499 | + ) { |
|
| 2500 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2501 | + } else { |
|
| 2502 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2503 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2504 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2505 | + $val[] = $a; |
|
| 2506 | + } else { |
|
| 2507 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2508 | + } // toujours quoter en char ici |
|
| 2509 | + } |
|
| 2510 | + } |
|
| 2511 | + } |
|
| 2512 | + |
|
| 2513 | + $fct = $args_sql = ''; |
|
| 2514 | + // fonction SQL ? |
|
| 2515 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2516 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2517 | + $fct = $m[1]; |
|
| 2518 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2519 | + $col = $a[1]; |
|
| 2520 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2521 | + $col = $m[1]; |
|
| 2522 | + $args_sql = $m[2]; |
|
| 2523 | + } |
|
| 2524 | + $args_sql .= $a[2]; |
|
| 2525 | + } |
|
| 2526 | + |
|
| 2527 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 2528 | 2528 | } |
| 2529 | 2529 | |
| 2530 | 2530 | // compatibilite ancienne version |
| 2531 | 2531 | |
| 2532 | 2532 | // https://code.spip.net/@calculer_vieux_in |
| 2533 | 2533 | function calculer_vieux_in($params) { |
| 2534 | - $deb = $params[0][0]; |
|
| 2535 | - $k = count($params) - 1; |
|
| 2536 | - $last = $params[$k]; |
|
| 2537 | - $j = count($last) - 1; |
|
| 2538 | - $last = $last[$j]; |
|
| 2539 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2540 | - |
|
| 2541 | - if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2542 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2543 | - ) { |
|
| 2544 | - return $params; |
|
| 2545 | - } |
|
| 2546 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2547 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2548 | - $last = $params[$k][$j]; |
|
| 2549 | - $n = strlen($last->texte); |
|
| 2550 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2551 | - $newp = array(); |
|
| 2552 | - foreach ($params as $v) { |
|
| 2553 | - if ($v[0]->type != 'texte') { |
|
| 2554 | - $newp[] = $v; |
|
| 2555 | - } else { |
|
| 2556 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2557 | - $t = new Texte; |
|
| 2558 | - $t->texte = $x; |
|
| 2559 | - $newp[] = array($t); |
|
| 2560 | - } |
|
| 2561 | - } |
|
| 2562 | - } |
|
| 2563 | - |
|
| 2564 | - return $newp; |
|
| 2534 | + $deb = $params[0][0]; |
|
| 2535 | + $k = count($params) - 1; |
|
| 2536 | + $last = $params[$k]; |
|
| 2537 | + $j = count($last) - 1; |
|
| 2538 | + $last = $last[$j]; |
|
| 2539 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2540 | + |
|
| 2541 | + if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2542 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2543 | + ) { |
|
| 2544 | + return $params; |
|
| 2545 | + } |
|
| 2546 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2547 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2548 | + $last = $params[$k][$j]; |
|
| 2549 | + $n = strlen($last->texte); |
|
| 2550 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2551 | + $newp = array(); |
|
| 2552 | + foreach ($params as $v) { |
|
| 2553 | + if ($v[0]->type != 'texte') { |
|
| 2554 | + $newp[] = $v; |
|
| 2555 | + } else { |
|
| 2556 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2557 | + $t = new Texte; |
|
| 2558 | + $t->texte = $x; |
|
| 2559 | + $newp[] = array($t); |
|
| 2560 | + } |
|
| 2561 | + } |
|
| 2562 | + } |
|
| 2563 | + |
|
| 2564 | + return $newp; |
|
| 2565 | 2565 | } |
| 2566 | 2566 | |
| 2567 | 2567 | /** |
@@ -2580,89 +2580,89 @@ discard block |
||
| 2580 | 2580 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2581 | 2581 | **/ |
| 2582 | 2582 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2583 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,", $col, $regs)) { |
|
| 2584 | - return ''; |
|
| 2585 | - } |
|
| 2586 | - |
|
| 2587 | - $boucle = $boucles[$idb]; |
|
| 2588 | - $table = $boucle->show; |
|
| 2589 | - |
|
| 2590 | - // si c'est une colonne de la table, ne rien faire |
|
| 2591 | - if (isset($table['field'][$col])) { |
|
| 2592 | - return ''; |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2596 | - return ''; |
|
| 2597 | - } |
|
| 2598 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2599 | - |
|
| 2600 | - $col = $regs[1]; |
|
| 2601 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2602 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2603 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2604 | - |
|
| 2605 | - if (isset($table['field']["date$suite"])) { |
|
| 2606 | - $date_orig = 'date' . $suite; |
|
| 2607 | - } else { |
|
| 2608 | - $date_orig = substr($suite, 1); |
|
| 2609 | - } |
|
| 2610 | - $pred = $date_orig; |
|
| 2611 | - } else { |
|
| 2612 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2613 | - $pred = 'date'; |
|
| 2614 | - } |
|
| 2615 | - } |
|
| 2616 | - |
|
| 2617 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2618 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2619 | - ") . '\""; |
|
| 2620 | - |
|
| 2621 | - $col_vraie = $date_orig; |
|
| 2622 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2623 | - |
|
| 2624 | - switch ($col) { |
|
| 2625 | - case 'date': |
|
| 2626 | - $col = $date_orig; |
|
| 2627 | - break; |
|
| 2628 | - case 'jour': |
|
| 2629 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2630 | - break; |
|
| 2631 | - case 'mois': |
|
| 2632 | - $col = "MONTH($date_orig)"; |
|
| 2633 | - break; |
|
| 2634 | - case 'annee': |
|
| 2635 | - $col = "YEAR($date_orig)"; |
|
| 2636 | - break; |
|
| 2637 | - case 'heure': |
|
| 2638 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2639 | - break; |
|
| 2640 | - case 'age': |
|
| 2641 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 2642 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2643 | - break; |
|
| 2644 | - case 'age_relatif': |
|
| 2645 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2646 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2647 | - break; |
|
| 2648 | - case 'jour_relatif': |
|
| 2649 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2650 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2651 | - break; |
|
| 2652 | - case 'mois_relatif': |
|
| 2653 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2654 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2655 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2656 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2657 | - break; |
|
| 2658 | - case 'annee_relatif': |
|
| 2659 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2660 | - $date_orig . ")"; |
|
| 2661 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2662 | - break; |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - return array($col, $col_vraie); |
|
| 2583 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,", $col, $regs)) { |
|
| 2584 | + return ''; |
|
| 2585 | + } |
|
| 2586 | + |
|
| 2587 | + $boucle = $boucles[$idb]; |
|
| 2588 | + $table = $boucle->show; |
|
| 2589 | + |
|
| 2590 | + // si c'est une colonne de la table, ne rien faire |
|
| 2591 | + if (isset($table['field'][$col])) { |
|
| 2592 | + return ''; |
|
| 2593 | + } |
|
| 2594 | + |
|
| 2595 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2596 | + return ''; |
|
| 2597 | + } |
|
| 2598 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2599 | + |
|
| 2600 | + $col = $regs[1]; |
|
| 2601 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2602 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2603 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2604 | + |
|
| 2605 | + if (isset($table['field']["date$suite"])) { |
|
| 2606 | + $date_orig = 'date' . $suite; |
|
| 2607 | + } else { |
|
| 2608 | + $date_orig = substr($suite, 1); |
|
| 2609 | + } |
|
| 2610 | + $pred = $date_orig; |
|
| 2611 | + } else { |
|
| 2612 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2613 | + $pred = 'date'; |
|
| 2614 | + } |
|
| 2615 | + } |
|
| 2616 | + |
|
| 2617 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2618 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2619 | + ") . '\""; |
|
| 2620 | + |
|
| 2621 | + $col_vraie = $date_orig; |
|
| 2622 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2623 | + |
|
| 2624 | + switch ($col) { |
|
| 2625 | + case 'date': |
|
| 2626 | + $col = $date_orig; |
|
| 2627 | + break; |
|
| 2628 | + case 'jour': |
|
| 2629 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2630 | + break; |
|
| 2631 | + case 'mois': |
|
| 2632 | + $col = "MONTH($date_orig)"; |
|
| 2633 | + break; |
|
| 2634 | + case 'annee': |
|
| 2635 | + $col = "YEAR($date_orig)"; |
|
| 2636 | + break; |
|
| 2637 | + case 'heure': |
|
| 2638 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2639 | + break; |
|
| 2640 | + case 'age': |
|
| 2641 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 2642 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2643 | + break; |
|
| 2644 | + case 'age_relatif': |
|
| 2645 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2646 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2647 | + break; |
|
| 2648 | + case 'jour_relatif': |
|
| 2649 | + $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2650 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2651 | + break; |
|
| 2652 | + case 'mois_relatif': |
|
| 2653 | + $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2654 | + $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2655 | + ")-YEAR(" . $date_orig . "))"; |
|
| 2656 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2657 | + break; |
|
| 2658 | + case 'annee_relatif': |
|
| 2659 | + $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2660 | + $date_orig . ")"; |
|
| 2661 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2662 | + break; |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + return array($col, $col_vraie); |
|
| 2666 | 2666 | } |
| 2667 | 2667 | |
| 2668 | 2668 | /** |
@@ -2681,16 +2681,16 @@ discard block |
||
| 2681 | 2681 | * de colonne SQL et une date. |
| 2682 | 2682 | **/ |
| 2683 | 2683 | function calculer_param_date($date_compare, $date_orig) { |
| 2684 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2685 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2686 | - $date_compare = '\'$x\''; |
|
| 2687 | - } else { |
|
| 2688 | - $init = $date_compare; |
|
| 2689 | - } |
|
| 2690 | - |
|
| 2691 | - return |
|
| 2692 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2693 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2684 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2685 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2686 | + $date_compare = '\'$x\''; |
|
| 2687 | + } else { |
|
| 2688 | + $init = $date_compare; |
|
| 2689 | + } |
|
| 2690 | + |
|
| 2691 | + return |
|
| 2692 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2693 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2694 | 2694 | } |
| 2695 | 2695 | |
| 2696 | 2696 | /** |
@@ -2708,18 +2708,18 @@ discard block |
||
| 2708 | 2708 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2709 | 2709 | */ |
| 2710 | 2710 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2711 | - $boucle = &$boucles[$idb]; |
|
| 2711 | + $boucle = &$boucles[$idb]; |
|
| 2712 | 2712 | |
| 2713 | - $args = array(); |
|
| 2714 | - foreach ($crit->param as &$param) { |
|
| 2715 | - array_push($args, |
|
| 2716 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 2717 | - } |
|
| 2713 | + $args = array(); |
|
| 2714 | + foreach ($crit->param as &$param) { |
|
| 2715 | + array_push($args, |
|
| 2716 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent)); |
|
| 2717 | + } |
|
| 2718 | 2718 | |
| 2719 | - $boucle->hash .= ' |
|
| 2719 | + $boucle->hash .= ' |
|
| 2720 | 2720 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2721 | 2721 | |
| 2722 | - $boucle->hash .= ' |
|
| 2722 | + $boucle->hash .= ' |
|
| 2723 | 2723 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2724 | 2724 | } |
| 2725 | 2725 | |
@@ -2736,8 +2736,8 @@ discard block |
||
| 2736 | 2736 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2737 | 2737 | */ |
| 2738 | 2738 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2739 | - $boucle = &$boucles[$idb]; |
|
| 2740 | - $boucle->hash .= ' |
|
| 2739 | + $boucle = &$boucles[$idb]; |
|
| 2740 | + $boucle->hash .= ' |
|
| 2741 | 2741 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2742 | 2742 | $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2743 | 2743 | } |
@@ -2757,8 +2757,8 @@ discard block |
||
| 2757 | 2757 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2758 | 2758 | */ |
| 2759 | 2759 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2760 | - $boucle = &$boucles[$idb]; |
|
| 2761 | - $boucle->hash .= ' |
|
| 2760 | + $boucle = &$boucles[$idb]; |
|
| 2761 | + $boucle->hash .= ' |
|
| 2762 | 2762 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2763 | 2763 | } |
| 2764 | 2764 | |
@@ -2774,12 +2774,12 @@ discard block |
||
| 2774 | 2774 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2775 | 2775 | */ |
| 2776 | 2776 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2777 | - $boucle = &$boucles[$idb]; |
|
| 2778 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2779 | - foreach ($crit->param as $param) { |
|
| 2780 | - $boucle->hash .= ' |
|
| 2777 | + $boucle = &$boucles[$idb]; |
|
| 2778 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2779 | + foreach ($crit->param as $param) { |
|
| 2780 | + $boucle->hash .= ' |
|
| 2781 | 2781 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2782 | - } |
|
| 2782 | + } |
|
| 2783 | 2783 | } |
| 2784 | 2784 | |
| 2785 | 2785 | /** |
@@ -2796,12 +2796,12 @@ discard block |
||
| 2796 | 2796 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2797 | 2797 | */ |
| 2798 | 2798 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2799 | - $boucle = &$boucles[$idb]; |
|
| 2800 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2801 | - foreach ($crit->param as $param) { |
|
| 2802 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2803 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2804 | - } |
|
| 2799 | + $boucle = &$boucles[$idb]; |
|
| 2800 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2801 | + foreach ($crit->param as $param) { |
|
| 2802 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2803 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2804 | + } |
|
| 2805 | 2805 | } |
| 2806 | 2806 | |
| 2807 | 2807 | /** |
@@ -2826,12 +2826,12 @@ discard block |
||
| 2826 | 2826 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2827 | 2827 | */ |
| 2828 | 2828 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2829 | - $boucle = &$boucles[$idb]; |
|
| 2830 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2831 | - foreach ($crit->param as $param) { |
|
| 2832 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2833 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2834 | - } |
|
| 2829 | + $boucle = &$boucles[$idb]; |
|
| 2830 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2831 | + foreach ($crit->param as $param) { |
|
| 2832 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2833 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2834 | + } |
|
| 2835 | 2835 | } |
| 2836 | 2836 | |
| 2837 | 2837 | /** |
@@ -2846,11 +2846,11 @@ discard block |
||
| 2846 | 2846 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2847 | 2847 | */ |
| 2848 | 2848 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2849 | - $boucle = &$boucles[$idb]; |
|
| 2850 | - foreach ($crit->param as $param) { |
|
| 2851 | - $boucle->hash .= ' |
|
| 2849 | + $boucle = &$boucles[$idb]; |
|
| 2850 | + foreach ($crit->param as $param) { |
|
| 2851 | + $boucle->hash .= ' |
|
| 2852 | 2852 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2853 | - } |
|
| 2853 | + } |
|
| 2854 | 2854 | } |
| 2855 | 2855 | |
| 2856 | 2856 | |
@@ -2882,20 +2882,20 @@ discard block |
||
| 2882 | 2882 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2883 | 2883 | */ |
| 2884 | 2884 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2885 | - $boucle = &$boucles[$idb]; |
|
| 2886 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2887 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2888 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2889 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2890 | - if ($crit->param) { |
|
| 2891 | - foreach ($crit->param as $param) { |
|
| 2892 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2893 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2894 | - } |
|
| 2895 | - // interdire {si 0} aussi ! |
|
| 2896 | - } else { |
|
| 2897 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2898 | - } |
|
| 2885 | + $boucle = &$boucles[$idb]; |
|
| 2886 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2887 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2888 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2889 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2890 | + if ($crit->param) { |
|
| 2891 | + foreach ($crit->param as $param) { |
|
| 2892 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2893 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2894 | + } |
|
| 2895 | + // interdire {si 0} aussi ! |
|
| 2896 | + } else { |
|
| 2897 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2898 | + } |
|
| 2899 | 2899 | } |
| 2900 | 2900 | |
| 2901 | 2901 | /** |
@@ -2911,8 +2911,8 @@ discard block |
||
| 2911 | 2911 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2912 | 2912 | */ |
| 2913 | 2913 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2914 | - $boucle = &$boucles[$idb]; |
|
| 2915 | - $boucle->hash .= ' |
|
| 2914 | + $boucle = &$boucles[$idb]; |
|
| 2915 | + $boucle->hash .= ' |
|
| 2916 | 2916 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2917 | 2917 | $command[\'sourcemode\'] = \'table\';'; |
| 2918 | 2918 | } |
@@ -2933,29 +2933,29 @@ discard block |
||
| 2933 | 2933 | */ |
| 2934 | 2934 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2935 | 2935 | |
| 2936 | - $not = $crit->not; |
|
| 2937 | - $boucle = &$boucles[$idb]; |
|
| 2938 | - $primary = $boucle->primary; |
|
| 2936 | + $not = $crit->not; |
|
| 2937 | + $boucle = &$boucles[$idb]; |
|
| 2938 | + $primary = $boucle->primary; |
|
| 2939 | 2939 | |
| 2940 | - if (!$primary or strpos($primary, ',')) { |
|
| 2941 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2940 | + if (!$primary or strpos($primary, ',')) { |
|
| 2941 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2942 | 2942 | |
| 2943 | - return; |
|
| 2944 | - } |
|
| 2945 | - $table = $boucle->type_requete; |
|
| 2946 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2943 | + return; |
|
| 2944 | + } |
|
| 2945 | + $table = $boucle->type_requete; |
|
| 2946 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2947 | 2947 | |
| 2948 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2949 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2950 | - 'id_parent'; |
|
| 2948 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2949 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2950 | + 'id_parent'; |
|
| 2951 | 2951 | |
| 2952 | - $in = "IN"; |
|
| 2953 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2954 | - if ($not) { |
|
| 2955 | - $where = array("'NOT'", $where); |
|
| 2956 | - } |
|
| 2952 | + $in = "IN"; |
|
| 2953 | + $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2954 | + if ($not) { |
|
| 2955 | + $where = array("'NOT'", $where); |
|
| 2956 | + } |
|
| 2957 | 2957 | |
| 2958 | - $boucle->where[] = $where; |
|
| 2958 | + $boucle->where[] = $where; |
|
| 2959 | 2959 | } |
| 2960 | 2960 | |
| 2961 | 2961 | /** |
@@ -2971,8 +2971,8 @@ discard block |
||
| 2971 | 2971 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2972 | 2972 | */ |
| 2973 | 2973 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2974 | - $not = $crit->not; |
|
| 2975 | - $crit->not = $not ? false : true; |
|
| 2976 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2977 | - $crit->not = $not; |
|
| 2974 | + $not = $crit->not; |
|
| 2975 | + $crit->not = $not ? false : true; |
|
| 2976 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2977 | + $crit->not = $not; |
|
| 2978 | 2978 | } |
@@ -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 = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 51 | + $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 53 | 52 | $boucle->where[] = ($crit->not ? array("'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 (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 74 | + return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 76 | 75 | } |
| 77 | 76 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 77 | + $boucle->where[] = array("'!='", "'$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[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 153 | + $boucle->where[] = array($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 |
@@ -215,10 +214,10 @@ discard block |
||
| 215 | 214 | $un = $un[0]->texte; |
| 216 | 215 | $deux = $deux[0]->texte; |
| 217 | 216 | if ($deux) { |
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 217 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 218 | + $un. |
|
| 219 | + '"]) . ",'. |
|
| 220 | + $deux. |
|
| 222 | 221 | '"'; |
| 223 | 222 | } else { |
| 224 | 223 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
@@ -281,26 +280,26 @@ discard block |
||
| 281 | 280 | $type = calculer_liste(array($crit->param[1][0]), $idb, $boucles, $boucle->id_parent); |
| 282 | 281 | } |
| 283 | 282 | |
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 285 | 284 | $boucle->modificateur['debut_nom'] = $type; |
| 286 | 285 | $partie = |
| 287 | 286 | // tester si le numero de page demande est de la forme '@yyy' |
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 289 | 288 | . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 289 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 290 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 292 | 291 | . "\t}\n" |
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 294 | 293 | |
| 295 | 294 | $boucle->hash .= ' |
| 296 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 295 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 297 | 296 | |
| 298 | 297 | $boucle->total_parties = $pas; |
| 299 | 298 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 300 | 299 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 301 | 300 | // sauf si pas de primaire, ou si primaire composee |
| 302 | 301 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 304 | 303 | if ($boucle->primary |
| 305 | 304 | and !preg_match('/[,\s]/', $boucle->primary) |
| 306 | 305 | and !in_array($t, $boucle->select) |
@@ -346,24 +345,24 @@ discard block |
||
| 346 | 345 | $boucle->hash .= ' |
| 347 | 346 | // RECHERCHE' |
| 348 | 347 | . ($crit->cond ? ' |
| 349 | - if (!strlen(' . $quoi . ')){ |
|
| 348 | + if (!strlen(' . $quoi.')){ |
|
| 350 | 349 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | - } else' : '') . ' |
|
| 350 | + } else' : '').' |
|
| 352 | 351 | { |
| 353 | 352 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 354 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 353 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 355 | 354 | } |
| 356 | 355 | '; |
| 357 | 356 | |
| 358 | 357 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 358 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 360 | 359 | if (!in_array($t, $boucles[$idb]->select)) { |
| 361 | 360 | $boucle->select[] = $t; |
| 362 | 361 | } # pour postgres, neuneu ici |
| 363 | 362 | // jointure uniquement sur le serveur principal |
| 364 | 363 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 365 | 364 | if (!$boucle->sql_serveur) { |
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 365 | + $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 367 | 366 | $boucle->from['resultats'] = 'spip_resultats'; |
| 368 | 367 | } |
| 369 | 368 | $boucle->select[] = '$rech_select'; |
@@ -430,7 +429,7 @@ discard block |
||
| 430 | 429 | $c = |
| 431 | 430 | array( |
| 432 | 431 | "'OR'", |
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 432 | + array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 434 | 433 | array("'='", "'$table.id_trad'", "'0'") |
| 435 | 434 | ); |
| 436 | 435 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
@@ -453,16 +452,15 @@ discard block |
||
| 453 | 452 | $boucle = &$boucles[$idb]; |
| 454 | 453 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 455 | 454 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 455 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 459 | 457 | |
| 460 | 458 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 461 | 459 | $boucle->where[] = array("'='", "'$mparent'", $arg); |
| 462 | 460 | |
| 463 | 461 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 464 | 462 | else { |
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 463 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 466 | 464 | } |
| 467 | 465 | } |
| 468 | 466 | |
@@ -515,16 +513,15 @@ discard block |
||
| 515 | 513 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 516 | 514 | $decompose = decompose_champ_id_objet($champ); |
| 517 | 515 | $champ = array_shift($decompose); |
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 516 | + $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 519 | 517 | } |
| 520 | 518 | } else { |
| 521 | 519 | $cle = $boucle->id_table; |
| 522 | 520 | } |
| 523 | 521 | |
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 522 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 523 | + . ($not ? ", 'NOT'" : '').")"; |
|
| 524 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 528 | 525 | } |
| 529 | 526 | |
| 530 | 527 | /** |
@@ -544,9 +541,9 @@ discard block |
||
| 544 | 541 | $not = ($crit->not ? 'NOT' : ''); |
| 545 | 542 | $serveur = $boucle->sql_serveur; |
| 546 | 543 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', 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')"; |
|
| 550 | 547 | |
| 551 | 548 | $boucle->where[] = $c; |
| 552 | 549 | } |
@@ -578,7 +575,7 @@ discard block |
||
| 578 | 575 | $t = table_objet_sql($r[1]); |
| 579 | 576 | $t = array_search($t, $boucles[$idb]->from); |
| 580 | 577 | if ($t) { |
| 581 | - $t .= '.' . $r[2]; |
|
| 578 | + $t .= '.'.$r[2]; |
|
| 582 | 579 | } |
| 583 | 580 | } |
| 584 | 581 | } else { |
@@ -593,7 +590,7 @@ discard block |
||
| 593 | 590 | $boucles[$idb]->select[] = $t; |
| 594 | 591 | } |
| 595 | 592 | } else { |
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 593 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 597 | 594 | } |
| 598 | 595 | } |
| 599 | 596 | |
@@ -643,26 +640,26 @@ discard block |
||
| 643 | 640 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 644 | 641 | OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 645 | 642 | ) { |
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 643 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 647 | 644 | } else { |
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 645 | + $boucle->order[$n - 1] .= " . ".$boucle->modificateur['collate']; |
|
| 649 | 646 | } |
| 650 | 647 | } |
| 651 | 648 | } else { |
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 649 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 653 | 650 | } |
| 654 | 651 | } |
| 655 | 652 | |
| 656 | 653 | // https://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 654 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | 655 | $boucle = $boucles[$idb]; |
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 656 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 657 | + $var = '$champs_'.$idb; |
|
| 661 | 658 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 662 | 659 | if (!$desc) { |
| 663 | 660 | $desc = $boucle->show['field']; |
| 664 | 661 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 662 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 666 | 663 | } |
| 667 | 664 | if ($desc) { |
| 668 | 665 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -737,7 +734,7 @@ discard block |
||
| 737 | 734 | $sens = " . ' DESC'"; |
| 738 | 735 | } |
| 739 | 736 | if (isset($boucle->modificateur['collate'])) { |
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 737 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 741 | 738 | } |
| 742 | 739 | |
| 743 | 740 | // Pour chaque paramètre du critère |
@@ -759,14 +756,14 @@ discard block |
||
| 759 | 756 | if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
| 760 | 757 | $expression = trim($m[1]); |
| 761 | 758 | $champ = trim($m[2]); |
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 759 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 763 | 760 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 764 | 761 | } else { |
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 762 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 766 | 763 | } |
| 767 | 764 | |
| 768 | 765 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 766 | + } elseif (preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 770 | 767 | // {par FONCTION(champ)} |
| 771 | 768 | if (count($match) > 2) { |
| 772 | 769 | $par = substr($match[2], 1, -1); |
@@ -776,7 +773,7 @@ discard block |
||
| 776 | 773 | if ($par == 'hasard') { |
| 777 | 774 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 778 | 775 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 776 | + $order = "'".$boucle->id_table.".".$boucle->show['date']."'"; |
|
| 780 | 777 | } else { |
| 781 | 778 | // cas général {par champ}, {par table.champ}, ... |
| 782 | 779 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -785,7 +782,7 @@ discard block |
||
| 785 | 782 | |
| 786 | 783 | // on ne sait pas traiter… |
| 787 | 784 | else { |
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 785 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 789 | 786 | } |
| 790 | 787 | |
| 791 | 788 | // En cas d'erreur de squelette retournée par une fonction |
@@ -805,14 +802,14 @@ discard block |
||
| 805 | 802 | |
| 806 | 803 | if ($fct) { |
| 807 | 804 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 805 | + $order = "'$fct(".$r[1].")'"; |
|
| 809 | 806 | } else { |
| 810 | 807 | $order = "'$fct(' . $order . ')'"; |
| 811 | 808 | } |
| 812 | 809 | } |
| 813 | - $t = $order . $collecte . $sens; |
|
| 810 | + $t = $order.$collecte.$sens; |
|
| 814 | 811 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 815 | - $t = $r[1] . $r[2]; |
|
| 812 | + $t = $r[1].$r[2]; |
|
| 816 | 813 | } |
| 817 | 814 | |
| 818 | 815 | $boucle->order[] = $t; |
@@ -862,16 +859,16 @@ discard block |
||
| 862 | 859 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | 860 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 864 | 861 | if (is_array($_champ)) { |
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 862 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." num $champ")); |
|
| 866 | 863 | } |
| 867 | 864 | $boucle = &$boucles[$idb]; |
| 868 | - $texte = '0+' . $_champ; |
|
| 865 | + $texte = '0+'.$_champ; |
|
| 869 | 866 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 870 | 867 | if ($suite !== "''") { |
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 868 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 872 | 869 | } |
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 870 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 871 | + $boucle->select[] = $texte." AS $as"; |
|
| 875 | 872 | $order = "'$as'"; |
| 876 | 873 | return $order; |
| 877 | 874 | } |
@@ -896,16 +893,16 @@ discard block |
||
| 896 | 893 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | 894 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 898 | 895 | if (is_array($_champ)) { |
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 896 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." sinum $champ")); |
|
| 900 | 897 | } |
| 901 | 898 | $boucle = &$boucles[$idb]; |
| 902 | - $texte = '0+' . $_champ; |
|
| 899 | + $texte = '0+'.$_champ; |
|
| 903 | 900 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 904 | 901 | if ($suite !== "''") { |
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 902 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 906 | 903 | } |
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 904 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ""); |
|
| 905 | + $boucle->select[] = 'CASE ('.$texte.') WHEN 0 THEN 1 ELSE 0 END AS '.$as; |
|
| 909 | 906 | $order = "'$as'"; |
| 910 | 907 | return $order; |
| 911 | 908 | } |
@@ -929,10 +926,10 @@ discard block |
||
| 929 | 926 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | 927 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 931 | 928 | if (is_array($_champ)) { |
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 929 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." multi $champ")); |
|
| 933 | 930 | } |
| 934 | 931 | $boucle = &$boucles[$idb]; |
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 932 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 936 | 933 | $order = "'multi'"; |
| 937 | 934 | return $order; |
| 938 | 935 | } |
@@ -952,13 +949,13 @@ discard block |
||
| 952 | 949 | * @param bool $raw Retourne le champ pour le compilateur ("'alias.champ'") ou brut ('alias.champ') |
| 953 | 950 | * @return array|string |
| 954 | 951 | */ |
| 955 | -function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 952 | +function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 956 | 953 | $boucle = &$boucles[$idb]; |
| 957 | 954 | $desc = $boucle->show; |
| 958 | 955 | |
| 959 | 956 | // le champ existe dans la table, pas de souci (le plus commun) |
| 960 | 957 | if (isset($desc['field'][$par])) { |
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 958 | + $par = $boucle->id_table.".".$par; |
|
| 962 | 959 | } |
| 963 | 960 | // le champ est peut être une jointure |
| 964 | 961 | else { |
@@ -979,24 +976,24 @@ discard block |
||
| 979 | 976 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 980 | 977 | // Si la table est déjà dans le from, on la réutilise. |
| 981 | 978 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 979 | + $par = $infos['alias'].".".$champ; |
|
| 983 | 980 | } elseif ( |
| 984 | 981 | $boucle->jointures_explicites |
| 985 | 982 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 986 | 983 | ) { |
| 987 | - $par = $alias . "." . $champ; |
|
| 984 | + $par = $alias.".".$champ; |
|
| 988 | 985 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 989 | - $par = $alias . "." . $champ; |
|
| 986 | + $par = $alias.".".$champ; |
|
| 990 | 987 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 991 | 988 | } elseif ( |
| 992 | 989 | $table_alias |
| 993 | 990 | and isset($boucle->from[$table_alias]) |
| 994 | 991 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 995 | 992 | ) { |
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 993 | + $par = $infos['alias'].".".$champ; |
|
| 997 | 994 | } elseif ($table) { |
| 998 | 995 | // On avait table + champ, mais on ne les a pas trouvés |
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 996 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 1000 | 997 | } else { |
| 1001 | 998 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1002 | 999 | } |
@@ -1020,7 +1017,7 @@ discard block |
||
| 1020 | 1017 | if (!$t) { |
| 1021 | 1018 | $t = trouver_jointure_champ($champ, $boucle); |
| 1022 | 1019 | } |
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1020 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1024 | 1021 | } |
| 1025 | 1022 | |
| 1026 | 1023 | /** |
@@ -1065,9 +1062,9 @@ discard block |
||
| 1065 | 1062 | $boucle->default_order[] = ' DESC'; |
| 1066 | 1063 | } |
| 1067 | 1064 | } else { |
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1065 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1069 | 1066 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1067 | + $t = $r[1].$r[2]; |
|
| 1071 | 1068 | } |
| 1072 | 1069 | $boucle->order[$n - 1] = $t; |
| 1073 | 1070 | } |
@@ -1081,11 +1078,11 @@ discard block |
||
| 1081 | 1078 | * @param $crit |
| 1082 | 1079 | * @return array|string |
| 1083 | 1080 | */ |
| 1084 | -function critere_par_ordre_liste_dist($idb, &$boucles, $crit){ |
|
| 1081 | +function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
|
| 1085 | 1082 | $boucle = &$boucles[$idb]; |
| 1086 | 1083 | |
| 1087 | 1084 | $sens = $collecte = ''; |
| 1088 | - if ($crit->not){ |
|
| 1085 | + if ($crit->not) { |
|
| 1089 | 1086 | $sens = " . ' DESC'"; |
| 1090 | 1087 | } |
| 1091 | 1088 | |
@@ -1095,14 +1092,14 @@ discard block |
||
| 1095 | 1092 | $res = critere_parinverse($idb, $boucles, $crit2); |
| 1096 | 1093 | |
| 1097 | 1094 | // erreur ? |
| 1098 | - if (is_array($res)){ |
|
| 1095 | + if (is_array($res)) { |
|
| 1099 | 1096 | return $res; |
| 1100 | 1097 | } |
| 1101 | 1098 | |
| 1102 | 1099 | $_order = array_pop($boucle->order); |
| 1103 | 1100 | |
| 1104 | 1101 | $_liste = calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent); |
| 1105 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1102 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1106 | 1103 | } |
| 1107 | 1104 | |
| 1108 | 1105 | |
@@ -1111,7 +1108,7 @@ discard block |
||
| 1111 | 1108 | $params = $crit->param; |
| 1112 | 1109 | |
| 1113 | 1110 | if (count($params) < 1) { |
| 1114 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1111 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ?")); |
|
| 1115 | 1112 | } |
| 1116 | 1113 | |
| 1117 | 1114 | $boucle = &$boucles[$idb]; |
@@ -1132,7 +1129,7 @@ discard block |
||
| 1132 | 1129 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1133 | 1130 | $date = $date[0]->texte; |
| 1134 | 1131 | if (!isset($fields[$date])) { |
| 1135 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1132 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ".$date)); |
|
| 1136 | 1133 | } |
| 1137 | 1134 | } else { |
| 1138 | 1135 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1144,38 +1141,38 @@ discard block |
||
| 1144 | 1141 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1145 | 1142 | } |
| 1146 | 1143 | $annee = $params ? array_shift($params) : ""; |
| 1147 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1148 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1144 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1145 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1149 | 1146 | ') ? $x : date("Y"))'; |
| 1150 | 1147 | |
| 1151 | 1148 | $mois = $params ? array_shift($params) : ""; |
| 1152 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1153 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1149 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1150 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1154 | 1151 | ') ? $x : date("m"))'; |
| 1155 | 1152 | |
| 1156 | 1153 | $jour = $params ? array_shift($params) : ""; |
| 1157 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1158 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1154 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1155 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1159 | 1156 | ') ? $x : date("d"))'; |
| 1160 | 1157 | |
| 1161 | 1158 | $annee2 = $params ? array_shift($params) : ""; |
| 1162 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1163 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1159 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1160 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1164 | 1161 | ') ? $x : date("Y"))'; |
| 1165 | 1162 | |
| 1166 | 1163 | $mois2 = $params ? array_shift($params) : ""; |
| 1167 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1168 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1164 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1165 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1169 | 1166 | ') ? $x : date("m"))'; |
| 1170 | 1167 | |
| 1171 | 1168 | $jour2 = $params ? array_shift($params) : ""; |
| 1172 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1173 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1169 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1170 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1174 | 1171 | ') ? $x : date("d"))'; |
| 1175 | 1172 | |
| 1176 | - $date = $boucle->id_table . ".$date"; |
|
| 1173 | + $date = $boucle->id_table.".$date"; |
|
| 1177 | 1174 | |
| 1178 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1175 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1179 | 1176 | if ($type == 'jour') { |
| 1180 | 1177 | $boucle->where[] = array( |
| 1181 | 1178 | "'='", |
@@ -1247,14 +1244,13 @@ discard block |
||
| 1247 | 1244 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1248 | 1245 | |
| 1249 | 1246 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1250 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1247 | + $boucle->limit = $a11.','.$a21; |
|
| 1251 | 1248 | } else { |
| 1252 | 1249 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1253 | 1250 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1254 | 1251 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1255 | 1252 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1256 | - $mode = (($op == '/') ? '/' : |
|
| 1257 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1253 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1258 | 1254 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1259 | 1255 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
| 1260 | 1256 | $boucle->limit = |
@@ -1300,8 +1296,7 @@ discard block |
||
| 1300 | 1296 | // {1/3} |
| 1301 | 1297 | if ($op1 == '/') { |
| 1302 | 1298 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1303 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1304 | - "($total_parties ? $total_parties : 1)"; |
|
| 1299 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1305 | 1300 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1306 | 1301 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1307 | 1302 | } else { |
@@ -1312,15 +1307,13 @@ discard block |
||
| 1312 | 1307 | |
| 1313 | 1308 | // cas {x,n-1} |
| 1314 | 1309 | if ($op2 == '-') { |
| 1315 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1316 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1317 | - ($total_parties . ' - 1')); |
|
| 1310 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1311 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1318 | 1312 | } else { |
| 1319 | 1313 | // {x,1} ou {pagination} |
| 1320 | 1314 | $fin = '$debut_boucle' |
| 1321 | 1315 | . (is_numeric($total_parties) ? |
| 1322 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1323 | - ('+' . $total_parties . ' - 1')); |
|
| 1316 | + (($total_parties == 1) ? "" : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1324 | 1317 | } |
| 1325 | 1318 | |
| 1326 | 1319 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1338,11 +1331,11 @@ discard block |
||
| 1338 | 1331 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1339 | 1332 | |
| 1340 | 1333 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1341 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1334 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1342 | 1335 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1343 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1344 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1345 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1336 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1337 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1338 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1346 | 1339 | . "\n\tif (\$debut_boucle>0" |
| 1347 | 1340 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1348 | 1341 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1427,16 +1420,16 @@ discard block |
||
| 1427 | 1420 | // critere personnalise ? |
| 1428 | 1421 | if ( |
| 1429 | 1422 | (!$serveur or |
| 1430 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1431 | - and (!function_exists($f = $f . "_dist")) |
|
| 1432 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1433 | - and (!function_exists($f = $f . "_dist")) |
|
| 1423 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 1424 | + and (!function_exists($f = $f."_dist")) |
|
| 1425 | + and (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 1426 | + and (!function_exists($f = $f."_dist")) |
|
| 1434 | 1427 | ) |
| 1435 | 1428 | ) |
| 1436 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1437 | - and (!function_exists($f = $f . "_dist")) |
|
| 1438 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1439 | - and (!function_exists($f = $f . "_dist")) |
|
| 1429 | + and (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 1430 | + and (!function_exists($f = $f."_dist")) |
|
| 1431 | + and (!function_exists($f = "critere_".$critere)) |
|
| 1432 | + and (!function_exists($f = $f."_dist")) |
|
| 1440 | 1433 | ) { |
| 1441 | 1434 | // fonction critere standard |
| 1442 | 1435 | $f = $defaut; |
@@ -1469,9 +1462,9 @@ discard block |
||
| 1469 | 1462 | */ |
| 1470 | 1463 | function kwote($lisp, $serveur = '', $type = '') { |
| 1471 | 1464 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1472 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1465 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type)."\""; |
|
| 1473 | 1466 | } else { |
| 1474 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1467 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1475 | 1468 | } |
| 1476 | 1469 | } |
| 1477 | 1470 | |
@@ -1493,7 +1486,7 @@ discard block |
||
| 1493 | 1486 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1494 | 1487 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1495 | 1488 | if (!$r) { |
| 1496 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1489 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 1497 | 1490 | } |
| 1498 | 1491 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1499 | 1492 | |
@@ -1520,8 +1513,8 @@ discard block |
||
| 1520 | 1513 | "'NOT'", |
| 1521 | 1514 | array( |
| 1522 | 1515 | "'IN'", |
| 1523 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1524 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1516 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1517 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1525 | 1518 | ) |
| 1526 | 1519 | ); |
| 1527 | 1520 | } |
@@ -1540,22 +1533,22 @@ discard block |
||
| 1540 | 1533 | $descr = $boucles[$idb]->descr; |
| 1541 | 1534 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1542 | 1535 | |
| 1543 | - $var = '$in' . $cpt++; |
|
| 1536 | + $var = '$in'.$cpt++; |
|
| 1544 | 1537 | $x = "\n\t$var = array();"; |
| 1545 | 1538 | foreach ($val as $k => $v) { |
| 1546 | 1539 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1547 | 1540 | // optimiser le traitement des constantes |
| 1548 | 1541 | if (is_numeric($r[2])) { |
| 1549 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1542 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1550 | 1543 | } else { |
| 1551 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1544 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1552 | 1545 | } |
| 1553 | 1546 | } else { |
| 1554 | 1547 | // Pour permettre de passer des tableaux de valeurs |
| 1555 | 1548 | // on repere l'utilisation brute de #ENV**{X}, |
| 1556 | 1549 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1557 | 1550 | // et on deballe mais en rajoutant l'anti XSS |
| 1558 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1551 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1559 | 1552 | } |
| 1560 | 1553 | } |
| 1561 | 1554 | |
@@ -1569,7 +1562,7 @@ discard block |
||
| 1569 | 1562 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1570 | 1563 | } |
| 1571 | 1564 | |
| 1572 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1565 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : "").")"; |
|
| 1573 | 1566 | } |
| 1574 | 1567 | |
| 1575 | 1568 | /** |
@@ -1642,7 +1635,7 @@ discard block |
||
| 1642 | 1635 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1643 | 1636 | } |
| 1644 | 1637 | // nous aider en mode debug. |
| 1645 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1638 | + $boucle->debug[] = "id_ : ".implode(', ', $champs); |
|
| 1646 | 1639 | $boucle->modificateur['id_'] = $champs; |
| 1647 | 1640 | |
| 1648 | 1641 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1683,7 +1676,7 @@ discard block |
||
| 1683 | 1676 | // Les champs id_xx de la table demandée |
| 1684 | 1677 | $champs = array_filter( |
| 1685 | 1678 | array_keys($desc['field']), |
| 1686 | - function($champ){ |
|
| 1679 | + function($champ) { |
|
| 1687 | 1680 | return |
| 1688 | 1681 | strpos($champ, 'id_') === 0 |
| 1689 | 1682 | or (in_array($champ, array('objet'))); |
@@ -1898,8 +1891,8 @@ discard block |
||
| 1898 | 1891 | "'NOT'", |
| 1899 | 1892 | array( |
| 1900 | 1893 | "'IN'", |
| 1901 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1902 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1894 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1895 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1903 | 1896 | ) |
| 1904 | 1897 | ); |
| 1905 | 1898 | } |
@@ -1910,7 +1903,7 @@ discard block |
||
| 1910 | 1903 | if ($crit->cond) { |
| 1911 | 1904 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1912 | 1905 | if ($col == "date" or $col == "date_redac") { |
| 1913 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1906 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1914 | 1907 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1915 | 1908 | } |
| 1916 | 1909 | } |
@@ -2071,7 +2064,7 @@ discard block |
||
| 2071 | 2064 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2072 | 2065 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2073 | 2066 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2074 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2067 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2075 | 2068 | } |
| 2076 | 2069 | // sinon expliciter les |
| 2077 | 2070 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2082,22 +2075,22 @@ discard block |
||
| 2082 | 2075 | // sql_quote(truc,'','varchar') |
| 2083 | 2076 | elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
| 2084 | 2077 | // si pas deja un type |
| 2085 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2078 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2086 | 2079 | ) { |
| 2087 | 2080 | $r = $r[1] |
| 2088 | 2081 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2089 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2082 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2090 | 2083 | $val[0] = "sql_quote($r)"; |
| 2091 | 2084 | } |
| 2092 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2085 | + elseif (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2093 | 2086 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2094 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2087 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2095 | 2088 | } |
| 2096 | 2089 | } |
| 2097 | 2090 | |
| 2098 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2091 | + if (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2099 | 2092 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2100 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2093 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2101 | 2094 | } |
| 2102 | 2095 | |
| 2103 | 2096 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2122,7 +2115,7 @@ discard block |
||
| 2122 | 2115 | // inserer le nom de la table SQL devant le nom du champ |
| 2123 | 2116 | if ($table) { |
| 2124 | 2117 | if ($col[0] == "`") { |
| 2125 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2118 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2126 | 2119 | } else { |
| 2127 | 2120 | $arg = "$table.$col"; |
| 2128 | 2121 | } |
@@ -2256,9 +2249,9 @@ discard block |
||
| 2256 | 2249 | **/ |
| 2257 | 2250 | function primary_doublee($decompose, $table) { |
| 2258 | 2251 | $e1 = reset($decompose); |
| 2259 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2252 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2260 | 2253 | |
| 2261 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2254 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 2262 | 2255 | } |
| 2263 | 2256 | |
| 2264 | 2257 | /** |
@@ -2296,7 +2289,7 @@ discard block |
||
| 2296 | 2289 | if ($checkarrivee |
| 2297 | 2290 | and is_string($checkarrivee) |
| 2298 | 2291 | and $a = table_objet($checkarrivee) |
| 2299 | - and in_array($a . '_liens', $joints) |
|
| 2292 | + and in_array($a.'_liens', $joints) |
|
| 2300 | 2293 | ) { |
| 2301 | 2294 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2302 | 2295 | return $res; |
@@ -2316,12 +2309,12 @@ discard block |
||
| 2316 | 2309 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2317 | 2310 | $joindre = false; |
| 2318 | 2311 | foreach ($cols as $col) { |
| 2319 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2312 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2320 | 2313 | if (trouver_champ($c, $boucle->where)) { |
| 2321 | 2314 | $joindre = true; |
| 2322 | 2315 | } else { |
| 2323 | 2316 | // mais ca peut etre dans le FIELD pour le Having |
| 2324 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2317 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2325 | 2318 | if (trouver_champ($c, $boucle->select)) { |
| 2326 | 2319 | $joindre = true; |
| 2327 | 2320 | } |
@@ -2368,7 +2361,7 @@ discard block |
||
| 2368 | 2361 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2369 | 2362 | |
| 2370 | 2363 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2371 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2364 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 2372 | 2365 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2373 | 2366 | |
| 2374 | 2367 | if (!$intermediaire or !$arrivee) { |
@@ -2466,7 +2459,7 @@ discard block |
||
| 2466 | 2459 | } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
| 2467 | 2460 | // un critere conditionnel sur date est traite a part |
| 2468 | 2461 | // car la date est mise d'office par SPIP, |
| 2469 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2462 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2470 | 2463 | } |
| 2471 | 2464 | |
| 2472 | 2465 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2497,7 +2490,7 @@ discard block |
||
| 2497 | 2490 | and (($p == "'") or ($p == '"')) |
| 2498 | 2491 | and $params[0][1]->type == 'champ' |
| 2499 | 2492 | ) { |
| 2500 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2493 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2501 | 2494 | } else { |
| 2502 | 2495 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2503 | 2496 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2513,7 +2506,7 @@ discard block |
||
| 2513 | 2506 | $fct = $args_sql = ''; |
| 2514 | 2507 | // fonction SQL ? |
| 2515 | 2508 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2516 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2509 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2517 | 2510 | $fct = $m[1]; |
| 2518 | 2511 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2519 | 2512 | $col = $a[1]; |
@@ -2603,7 +2596,7 @@ discard block |
||
| 2603 | 2596 | # si oui choisir ce champ, sinon choisir xxxx |
| 2604 | 2597 | |
| 2605 | 2598 | if (isset($table['field']["date$suite"])) { |
| 2606 | - $date_orig = 'date' . $suite; |
|
| 2599 | + $date_orig = 'date'.$suite; |
|
| 2607 | 2600 | } else { |
| 2608 | 2601 | $date_orig = substr($suite, 1); |
| 2609 | 2602 | } |
@@ -2614,12 +2607,12 @@ discard block |
||
| 2614 | 2607 | } |
| 2615 | 2608 | } |
| 2616 | 2609 | |
| 2617 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2618 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2610 | + $date_compare = "\"' . normaliser_date(". |
|
| 2611 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2619 | 2612 | ") . '\""; |
| 2620 | 2613 | |
| 2621 | 2614 | $col_vraie = $date_orig; |
| 2622 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2615 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2623 | 2616 | |
| 2624 | 2617 | switch ($col) { |
| 2625 | 2618 | case 'date': |
@@ -2639,26 +2632,26 @@ discard block |
||
| 2639 | 2632 | break; |
| 2640 | 2633 | case 'age': |
| 2641 | 2634 | $col = calculer_param_date("NOW()", $date_orig); |
| 2642 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2635 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2643 | 2636 | break; |
| 2644 | 2637 | case 'age_relatif': |
| 2645 | 2638 | $col = calculer_param_date($date_compare, $date_orig); |
| 2646 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2639 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2647 | 2640 | break; |
| 2648 | 2641 | case 'jour_relatif': |
| 2649 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2650 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2642 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 2643 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2651 | 2644 | break; |
| 2652 | 2645 | case 'mois_relatif': |
| 2653 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2654 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2655 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2656 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2646 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 2647 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 2648 | + ")-YEAR(".$date_orig."))"; |
|
| 2649 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2657 | 2650 | break; |
| 2658 | 2651 | case 'annee_relatif': |
| 2659 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2660 | - $date_orig . ")"; |
|
| 2661 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2652 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 2653 | + $date_orig.")"; |
|
| 2654 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2662 | 2655 | break; |
| 2663 | 2656 | } |
| 2664 | 2657 | |
@@ -2717,10 +2710,10 @@ discard block |
||
| 2717 | 2710 | } |
| 2718 | 2711 | |
| 2719 | 2712 | $boucle->hash .= ' |
| 2720 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2713 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2721 | 2714 | |
| 2722 | 2715 | $boucle->hash .= ' |
| 2723 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2716 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2724 | 2717 | } |
| 2725 | 2718 | |
| 2726 | 2719 | |
@@ -2738,8 +2731,8 @@ discard block |
||
| 2738 | 2731 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2739 | 2732 | $boucle = &$boucles[$idb]; |
| 2740 | 2733 | $boucle->hash .= ' |
| 2741 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2742 | - $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2734 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2735 | + $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2743 | 2736 | } |
| 2744 | 2737 | |
| 2745 | 2738 | |
@@ -2759,7 +2752,7 @@ discard block |
||
| 2759 | 2752 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2760 | 2753 | $boucle = &$boucles[$idb]; |
| 2761 | 2754 | $boucle->hash .= ' |
| 2762 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2755 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2763 | 2756 | } |
| 2764 | 2757 | |
| 2765 | 2758 | |
@@ -2778,7 +2771,7 @@ discard block |
||
| 2778 | 2771 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2779 | 2772 | foreach ($crit->param as $param) { |
| 2780 | 2773 | $boucle->hash .= ' |
| 2781 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2774 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2782 | 2775 | } |
| 2783 | 2776 | } |
| 2784 | 2777 | |
@@ -2797,10 +2790,10 @@ discard block |
||
| 2797 | 2790 | */ |
| 2798 | 2791 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2799 | 2792 | $boucle = &$boucles[$idb]; |
| 2800 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2793 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2801 | 2794 | foreach ($crit->param as $param) { |
| 2802 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2803 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2795 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, $idb, $boucles, |
|
| 2796 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2804 | 2797 | } |
| 2805 | 2798 | } |
| 2806 | 2799 | |
@@ -2827,10 +2820,10 @@ discard block |
||
| 2827 | 2820 | */ |
| 2828 | 2821 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2829 | 2822 | $boucle = &$boucles[$idb]; |
| 2830 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2823 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2831 | 2824 | foreach ($crit->param as $param) { |
| 2832 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, $idb, $boucles, |
|
| 2833 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2825 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, $idb, $boucles, |
|
| 2826 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2834 | 2827 | } |
| 2835 | 2828 | } |
| 2836 | 2829 | |
@@ -2849,7 +2842,7 @@ discard block |
||
| 2849 | 2842 | $boucle = &$boucles[$idb]; |
| 2850 | 2843 | foreach ($crit->param as $param) { |
| 2851 | 2844 | $boucle->hash .= ' |
| 2852 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2845 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2853 | 2846 | } |
| 2854 | 2847 | } |
| 2855 | 2848 | |
@@ -2890,7 +2883,7 @@ discard block |
||
| 2890 | 2883 | if ($crit->param) { |
| 2891 | 2884 | foreach ($crit->param as $param) { |
| 2892 | 2885 | $boucle->hash .= "\t\$command['si'][] = " |
| 2893 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2886 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2894 | 2887 | } |
| 2895 | 2888 | // interdire {si 0} aussi ! |
| 2896 | 2889 | } else { |
@@ -2913,7 +2906,7 @@ discard block |
||
| 2913 | 2906 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2914 | 2907 | $boucle = &$boucles[$idb]; |
| 2915 | 2908 | $boucle->hash .= ' |
| 2916 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2909 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2917 | 2910 | $command[\'sourcemode\'] = \'table\';'; |
| 2918 | 2911 | } |
| 2919 | 2912 | |
@@ -2946,11 +2939,10 @@ discard block |
||
| 2946 | 2939 | $table_sql = table_objet_sql(objet_type($table)); |
| 2947 | 2940 | |
| 2948 | 2941 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2949 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2950 | - 'id_parent'; |
|
| 2942 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2951 | 2943 | |
| 2952 | 2944 | $in = "IN"; |
| 2953 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2945 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2954 | 2946 | if ($not) { |
| 2955 | 2947 | $where = array("'NOT'", $where); |
| 2956 | 2948 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -52,75 +52,75 @@ discard block |
||
| 52 | 52 | * Introduction calculée |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 55 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | - if (strlen($descriptif)) { |
|
| 57 | - return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // De preference ce qui est marque <intro>...</intro> |
|
| 61 | - $intro = ''; |
|
| 62 | - $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 63 | - while ($fin = strpos($texte, "</intro>")) { |
|
| 64 | - $zone = substr($texte, 0, $fin); |
|
| 65 | - $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 66 | - if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 67 | - $zone = substr($zone, $deb + 7); |
|
| 68 | - } |
|
| 69 | - $intro .= $zone; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | - // qui inclus raccourcis et modeles |
|
| 74 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | - // des surcharges et enrichissement de propre |
|
| 77 | - // couper doit se faire apres propre |
|
| 78 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | - |
|
| 80 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | - // large et en se mefiant des tableaux #1323 |
|
| 82 | - |
|
| 83 | - if (strlen($intro)) { |
|
| 84 | - $texte = $intro; |
|
| 85 | - } else { |
|
| 86 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 87 | - and strlen($texte) > 2.5 * $longueur |
|
| 88 | - ) { |
|
| 89 | - if (strpos($texte, "<multi") !== false) { |
|
| 90 | - $texte = extraire_multi($texte); |
|
| 91 | - } |
|
| 92 | - $texte = couper($texte, 2 * $longueur); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // ne pas tenir compte des notes |
|
| 97 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 98 | - $notes('', 'empiler'); |
|
| 99 | - } |
|
| 100 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 101 | - // dans l'introduction. |
|
| 102 | - $texte = supprime_img($texte, ''); |
|
| 103 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 104 | - |
|
| 105 | - if ($notes) { |
|
| 106 | - $notes('', 'depiler'); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 110 | - $suite = _INTRODUCTION_SUITE; |
|
| 111 | - } |
|
| 112 | - $texte = couper($texte, $longueur, $suite); |
|
| 113 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 114 | - $texte = typo($texte, true, $connect, array()); |
|
| 115 | - |
|
| 116 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 117 | - // une introduction a tojours un <p> |
|
| 118 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 119 | - { |
|
| 120 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $texte; |
|
| 55 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | + if (strlen($descriptif)) { |
|
| 57 | + return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // De preference ce qui est marque <intro>...</intro> |
|
| 61 | + $intro = ''; |
|
| 62 | + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 63 | + while ($fin = strpos($texte, "</intro>")) { |
|
| 64 | + $zone = substr($texte, 0, $fin); |
|
| 65 | + $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 66 | + if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 67 | + $zone = substr($zone, $deb + 7); |
|
| 68 | + } |
|
| 69 | + $intro .= $zone; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | + // qui inclus raccourcis et modeles |
|
| 74 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | + // des surcharges et enrichissement de propre |
|
| 77 | + // couper doit se faire apres propre |
|
| 78 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | + |
|
| 80 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | + // large et en se mefiant des tableaux #1323 |
|
| 82 | + |
|
| 83 | + if (strlen($intro)) { |
|
| 84 | + $texte = $intro; |
|
| 85 | + } else { |
|
| 86 | + if (strpos("\n" . $texte, "\n|") === false |
|
| 87 | + and strlen($texte) > 2.5 * $longueur |
|
| 88 | + ) { |
|
| 89 | + if (strpos($texte, "<multi") !== false) { |
|
| 90 | + $texte = extraire_multi($texte); |
|
| 91 | + } |
|
| 92 | + $texte = couper($texte, 2 * $longueur); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // ne pas tenir compte des notes |
|
| 97 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 98 | + $notes('', 'empiler'); |
|
| 99 | + } |
|
| 100 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 101 | + // dans l'introduction. |
|
| 102 | + $texte = supprime_img($texte, ''); |
|
| 103 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 104 | + |
|
| 105 | + if ($notes) { |
|
| 106 | + $notes('', 'depiler'); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 110 | + $suite = _INTRODUCTION_SUITE; |
|
| 111 | + } |
|
| 112 | + $texte = couper($texte, $longueur, $suite); |
|
| 113 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 114 | + $texte = typo($texte, true, $connect, array()); |
|
| 115 | + |
|
| 116 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 117 | + // une introduction a tojours un <p> |
|
| 118 | + if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 119 | + { |
|
| 120 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $texte; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
@@ -134,15 +134,15 @@ discard block |
||
| 134 | 134 | **/ |
| 135 | 135 | function lister_objets_avec_logos($type) { |
| 136 | 136 | |
| 137 | - $objet = objet_type($type); |
|
| 138 | - $ids = sql_allfetsel("L.id_objet", "spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document", "D.mode=".sql_quote('logoon')." AND L.objet=".sql_quote($objet)); |
|
| 139 | - if ($ids) { |
|
| 140 | - $ids = array_column($ids, 'id_objet'); |
|
| 141 | - return implode(',', $ids); |
|
| 142 | - } |
|
| 143 | - else { |
|
| 144 | - return "0"; |
|
| 145 | - } |
|
| 137 | + $objet = objet_type($type); |
|
| 138 | + $ids = sql_allfetsel("L.id_objet", "spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document", "D.mode=".sql_quote('logoon')." AND L.objet=".sql_quote($objet)); |
|
| 139 | + if ($ids) { |
|
| 140 | + $ids = array_column($ids, 'id_objet'); |
|
| 141 | + return implode(',', $ids); |
|
| 142 | + } |
|
| 143 | + else { |
|
| 144 | + return "0"; |
|
| 145 | + } |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
@@ -158,14 +158,14 @@ discard block |
||
| 158 | 158 | * Code HTML des notes |
| 159 | 159 | **/ |
| 160 | 160 | function calculer_notes() { |
| 161 | - $r = ''; |
|
| 162 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 163 | - $r = $notes(array()); |
|
| 164 | - $notes('', 'depiler'); |
|
| 165 | - $notes('', 'empiler'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return $r; |
|
| 161 | + $r = ''; |
|
| 162 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 163 | + $r = $notes(array()); |
|
| 164 | + $notes('', 'depiler'); |
|
| 165 | + $notes('', 'empiler'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return $r; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | |
@@ -182,10 +182,10 @@ discard block |
||
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | 184 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien){ |
| 185 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 186 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 185 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 186 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 187 | 187 | |
| 188 | - return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 188 | + return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -202,19 +202,19 @@ discard block |
||
| 202 | 202 | * @private |
| 203 | 203 | */ |
| 204 | 204 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 205 | - static $liens = array(); |
|
| 206 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 207 | - include_spip('action/editer_liens'); |
|
| 208 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 209 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 210 | - $res = objet_trouver_liens(array($objet => $id_objet), array($objet_source => '*')); |
|
| 211 | - } else { |
|
| 212 | - $res = objet_trouver_liens(array($objet_source => '*'), array($objet => $id_objet)); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 216 | - } |
|
| 217 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 205 | + static $liens = array(); |
|
| 206 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 207 | + include_spip('action/editer_liens'); |
|
| 208 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 209 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 210 | + $res = objet_trouver_liens(array($objet => $id_objet), array($objet_source => '*')); |
|
| 211 | + } else { |
|
| 212 | + $res = objet_trouver_liens(array($objet_source => '*'), array($objet => $id_objet)); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 216 | + } |
|
| 217 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -228,23 +228,23 @@ discard block |
||
| 228 | 228 | * @return int|string |
| 229 | 229 | */ |
| 230 | 230 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 231 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 232 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 233 | - if (isset($env['form']) and $env['form'] |
|
| 234 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 235 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 236 | - and $r = objet_associable($env['_objet_lien']) |
|
| 237 | - and list($p, $table_lien) = $r |
|
| 238 | - and lien_triables($table_lien) |
|
| 239 | - and isset($env['objet']) and $env['objet'] |
|
| 240 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 241 | - and $objet_source |
|
| 242 | - and $id = intval($id) |
|
| 243 | - ) { |
|
| 244 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 245 | - return ($rang ? $rang : ''); |
|
| 246 | - } |
|
| 247 | - return recuperer_numero($titre); |
|
| 231 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 232 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 233 | + if (isset($env['form']) and $env['form'] |
|
| 234 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 235 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 236 | + and $r = objet_associable($env['_objet_lien']) |
|
| 237 | + and list($p, $table_lien) = $r |
|
| 238 | + and lien_triables($table_lien) |
|
| 239 | + and isset($env['objet']) and $env['objet'] |
|
| 240 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 241 | + and $objet_source |
|
| 242 | + and $id = intval($id) |
|
| 243 | + ) { |
|
| 244 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 245 | + return ($rang ? $rang : ''); |
|
| 246 | + } |
|
| 247 | + return recuperer_numero($titre); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | 258 | function tri_protege_champ($t) { |
| 259 | - return preg_replace(',[^\s\w.+],', '', $t); |
|
| 259 | + return preg_replace(',[^\s\w.+],', '', $t); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -269,34 +269,34 @@ discard block |
||
| 269 | 269 | * @return string |
| 270 | 270 | */ |
| 271 | 271 | function tri_champ_order($t, $from = null) { |
| 272 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 273 | - return "multi"; |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - $champ = $t; |
|
| 277 | - |
|
| 278 | - if (strncmp($t, 'num ', 4) == 0) { |
|
| 279 | - $champ = substr($t, 4); |
|
| 280 | - } |
|
| 281 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 282 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 283 | - |
|
| 284 | - if (is_array($from)) { |
|
| 285 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 286 | - foreach ($from as $idt => $table_sql) { |
|
| 287 | - if ($desc = $trouver_table($table_sql) |
|
| 288 | - and isset($desc['field'][$champ]) |
|
| 289 | - ) { |
|
| 290 | - $champ = "$idt.$champ"; |
|
| 291 | - break; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - if (strncmp($t, 'num ', 4) == 0) { |
|
| 296 | - return "0+$champ"; |
|
| 297 | - } else { |
|
| 298 | - return $champ; |
|
| 299 | - } |
|
| 272 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 273 | + return "multi"; |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + $champ = $t; |
|
| 277 | + |
|
| 278 | + if (strncmp($t, 'num ', 4) == 0) { |
|
| 279 | + $champ = substr($t, 4); |
|
| 280 | + } |
|
| 281 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 282 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 283 | + |
|
| 284 | + if (is_array($from)) { |
|
| 285 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 286 | + foreach ($from as $idt => $table_sql) { |
|
| 287 | + if ($desc = $trouver_table($table_sql) |
|
| 288 | + and isset($desc['field'][$champ]) |
|
| 289 | + ) { |
|
| 290 | + $champ = "$idt.$champ"; |
|
| 291 | + break; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + if (strncmp($t, 'num ', 4) == 0) { |
|
| 296 | + return "0+$champ"; |
|
| 297 | + } else { |
|
| 298 | + return $champ; |
|
| 299 | + } |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -310,18 +310,18 @@ discard block |
||
| 310 | 310 | * @return string |
| 311 | 311 | */ |
| 312 | 312 | function tri_champ_select($t) { |
| 313 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 314 | - $t = substr($t, 6); |
|
| 315 | - $t = preg_replace(',\s,', '', $t); |
|
| 316 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 317 | - |
|
| 318 | - return $t; |
|
| 319 | - } |
|
| 320 | - if (trim($t) == 'hasard') { |
|
| 321 | - return 'rand() AS hasard'; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return "''"; |
|
| 313 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 314 | + $t = substr($t, 6); |
|
| 315 | + $t = preg_replace(',\s,', '', $t); |
|
| 316 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 317 | + |
|
| 318 | + return $t; |
|
| 319 | + } |
|
| 320 | + if (trim($t) == 'hasard') { |
|
| 321 | + return 'rand() AS hasard'; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return "''"; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** |
@@ -333,14 +333,14 @@ discard block |
||
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | 335 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = ''){ |
| 336 | - if (!is_array($valeurs)){ |
|
| 337 | - return ''; |
|
| 338 | - } |
|
| 339 | - $f = sql_serveur('quote', $serveur, true); |
|
| 340 | - if (!is_string($f) or !$f){ |
|
| 341 | - return ''; |
|
| 342 | - } |
|
| 343 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 344 | - |
|
| 345 | - return $valeurs; |
|
| 336 | + if (!is_array($valeurs)){ |
|
| 337 | + return ''; |
|
| 338 | + } |
|
| 339 | + $f = sql_serveur('quote', $serveur, true); |
|
| 340 | + if (!is_string($f) or !$f){ |
|
| 341 | + return ''; |
|
| 342 | + } |
|
| 343 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 344 | + |
|
| 345 | + return $valeurs; |
|
| 346 | 346 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | if (strlen($intro)) { |
| 84 | 84 | $texte = $intro; |
| 85 | 85 | } else { |
| 86 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 86 | + if (strpos("\n".$texte, "\n|") === false |
|
| 87 | 87 | and strlen($texte) > 2.5 * $longueur |
| 88 | 88 | ) { |
| 89 | 89 | if (strpos($texte, "<multi") !== false) { |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param $objet_lien |
| 182 | 182 | * @return string |
| 183 | 183 | */ |
| 184 | -function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien){ |
|
| 184 | +function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
|
| 185 | 185 | $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
| 186 | 186 | $res = array_column($res, 'rang_lien', $objet_source); |
| 187 | 187 | |
@@ -332,12 +332,12 @@ discard block |
||
| 332 | 332 | * @param string $serveur |
| 333 | 333 | * @return string |
| 334 | 334 | */ |
| 335 | -function formate_liste_critere_par_ordre_liste($valeurs, $serveur = ''){ |
|
| 336 | - if (!is_array($valeurs)){ |
|
| 335 | +function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
|
| 336 | + if (!is_array($valeurs)) { |
|
| 337 | 337 | return ''; |
| 338 | 338 | } |
| 339 | 339 | $f = sql_serveur('quote', $serveur, true); |
| 340 | - if (!is_string($f) or !$f){ |
|
| 340 | + if (!is_string($f) or !$f) { |
|
| 341 | 341 | return ''; |
| 342 | 342 | } |
| 343 | 343 | $valeurs = implode(',', array_map($f, array_unique($valeurs))); |