@@ -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], array(), $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], array(), $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]), array(), $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]), array(), $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]), array(), $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]), array(), $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]), array(), $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]), array(), $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], array(), $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], array(), $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], array(), $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], array(), $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,22 +540,22 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $not = $crit->not; |
|
| 544 | - $boucle = &$boucles[$idb]; |
|
| 543 | + $not = $crit->not; |
|
| 544 | + $boucle = &$boucles[$idb]; |
|
| 545 | 545 | |
| 546 | - $c = "sql_in('" . |
|
| 547 | - $boucle->id_table . '.' . $boucle->primary |
|
| 548 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '')"; |
|
| 546 | + $c = "sql_in('" . |
|
| 547 | + $boucle->id_table . '.' . $boucle->primary |
|
| 548 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '')"; |
|
| 549 | 549 | |
| 550 | - if ($crit->cond) { |
|
| 551 | - $c = "($arg ? $c : 1)"; |
|
| 552 | - } |
|
| 550 | + if ($crit->cond) { |
|
| 551 | + $c = "($arg ? $c : 1)"; |
|
| 552 | + } |
|
| 553 | 553 | |
| 554 | - if ($not) { |
|
| 555 | - $boucle->where[] = array("'NOT'", $c); |
|
| 556 | - } else { |
|
| 557 | - $boucle->where[] = $c; |
|
| 558 | - } |
|
| 554 | + if ($not) { |
|
| 555 | + $boucle->where[] = array("'NOT'", $c); |
|
| 556 | + } else { |
|
| 557 | + $boucle->where[] = $c; |
|
| 558 | + } |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | |
@@ -577,31 +577,31 @@ discard block |
||
| 577 | 577 | * @return void |
| 578 | 578 | **/ |
| 579 | 579 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 580 | - if ($t = isset($crit->param[0])) { |
|
| 581 | - $t = $crit->param[0]; |
|
| 582 | - if ($t[0]->type == 'texte') { |
|
| 583 | - $t = $t[0]->texte; |
|
| 584 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 585 | - $t = table_objet_sql($r[1]); |
|
| 586 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 587 | - if ($t) { |
|
| 588 | - $t .= '.' . $r[2]; |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - $t = '".' |
|
| 593 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 594 | - . '."'; |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - if ($t) { |
|
| 598 | - $boucles[$idb]->group[] = $t; |
|
| 599 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 600 | - $boucles[$idb]->select[] = $t; |
|
| 601 | - } |
|
| 602 | - } else { |
|
| 603 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 604 | - } |
|
| 580 | + if ($t = isset($crit->param[0])) { |
|
| 581 | + $t = $crit->param[0]; |
|
| 582 | + if ($t[0]->type == 'texte') { |
|
| 583 | + $t = $t[0]->texte; |
|
| 584 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 585 | + $t = table_objet_sql($r[1]); |
|
| 586 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 587 | + if ($t) { |
|
| 588 | + $t .= '.' . $r[2]; |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + $t = '".' |
|
| 593 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 594 | + . '."'; |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + if ($t) { |
|
| 598 | + $boucles[$idb]->group[] = $t; |
|
| 599 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 600 | + $boucles[$idb]->select[] = $t; |
|
| 601 | + } |
|
| 602 | + } else { |
|
| 603 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 604 | + } |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -638,45 +638,45 @@ discard block |
||
| 638 | 638 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 639 | 639 | */ |
| 640 | 640 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 641 | - if (isset($crit->param[0])) { |
|
| 642 | - $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 643 | - $boucle = $boucles[$idb]; |
|
| 644 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 645 | - $n = count($boucle->order); |
|
| 646 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 647 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 648 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 649 | - if ( |
|
| 650 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 651 | - OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 652 | - ) { |
|
| 653 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 654 | - } else { |
|
| 655 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - } else { |
|
| 659 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 660 | - } |
|
| 641 | + if (isset($crit->param[0])) { |
|
| 642 | + $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 643 | + $boucle = $boucles[$idb]; |
|
| 644 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 645 | + $n = count($boucle->order); |
|
| 646 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 647 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 648 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 649 | + if ( |
|
| 650 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 651 | + OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 652 | + ) { |
|
| 653 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 654 | + } else { |
|
| 655 | + $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + } else { |
|
| 659 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 660 | + } |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 664 | 664 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 665 | - $boucle = $boucles[$idb]; |
|
| 666 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 667 | - $var = '$champs_' . $idb; |
|
| 668 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 669 | - if (!$desc) { |
|
| 670 | - $desc = $boucle->show['field']; |
|
| 671 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 672 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 673 | - } |
|
| 674 | - if ($desc) { |
|
| 675 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 676 | - } |
|
| 677 | - $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 678 | - |
|
| 679 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 665 | + $boucle = $boucles[$idb]; |
|
| 666 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 667 | + $var = '$champs_' . $idb; |
|
| 668 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 669 | + if (!$desc) { |
|
| 670 | + $desc = $boucle->show['field']; |
|
| 671 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 672 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 673 | + } |
|
| 674 | + if ($desc) { |
|
| 675 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 676 | + } |
|
| 677 | + $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 678 | + |
|
| 679 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | /** |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 716 | 716 | */ |
| 717 | 717 | function critere_par_dist($idb, &$boucles, $crit) { |
| 718 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 718 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -737,93 +737,93 @@ discard block |
||
| 737 | 737 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 738 | 738 | */ |
| 739 | 739 | function critere_parinverse($idb, &$boucles, $crit) { |
| 740 | - $boucle = &$boucles[$idb]; |
|
| 741 | - |
|
| 742 | - $sens = $collecte = ''; |
|
| 743 | - if ($crit->not) { |
|
| 744 | - $sens = " . ' DESC'"; |
|
| 745 | - } |
|
| 746 | - if (isset($boucle->modificateur['collate'])) { |
|
| 747 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - // Pour chaque paramètre du critère |
|
| 751 | - foreach ($crit->param as $tri) { |
|
| 752 | - $order = $fct = ''; |
|
| 753 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 754 | - if ($tri[0]->type != 'texte') { |
|
| 755 | - // calculer le order dynamique qui verifie les champs |
|
| 756 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 757 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 758 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 759 | - } |
|
| 760 | - // tris textuels {par titre} |
|
| 761 | - else { |
|
| 762 | - $par = array_shift($tri); |
|
| 763 | - $par = $par->texte; |
|
| 764 | - |
|
| 765 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 766 | - if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 767 | - $expression = trim($m[1]); |
|
| 768 | - $champ = trim($m[2]); |
|
| 769 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 770 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 771 | - } else { |
|
| 772 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 776 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 777 | - // {par FONCTION(champ)} |
|
| 778 | - if (count($match) > 2) { |
|
| 779 | - $par = substr($match[2], 1, -1); |
|
| 780 | - $fct = $match[1]; |
|
| 781 | - } |
|
| 782 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 783 | - if ($par == 'hasard') { |
|
| 784 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 785 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 786 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 787 | - } else { |
|
| 788 | - // cas général {par champ}, {par table.champ}, ... |
|
| 789 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - // on ne sait pas traiter… |
|
| 794 | - else { |
|
| 795 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 799 | - if (is_array($order)) { |
|
| 800 | - return $order; |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 805 | - $t = $m[1]; |
|
| 806 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 807 | - $boucle->select[] = $t; |
|
| 808 | - } |
|
| 809 | - } else { |
|
| 810 | - $sens = ''; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - if ($fct) { |
|
| 814 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 815 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 816 | - } else { |
|
| 817 | - $order = "'$fct(' . $order . ')'"; |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - $t = $order . $collecte . $sens; |
|
| 821 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 822 | - $t = $r[1] . $r[2]; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - $boucle->order[] = $t; |
|
| 826 | - } |
|
| 740 | + $boucle = &$boucles[$idb]; |
|
| 741 | + |
|
| 742 | + $sens = $collecte = ''; |
|
| 743 | + if ($crit->not) { |
|
| 744 | + $sens = " . ' DESC'"; |
|
| 745 | + } |
|
| 746 | + if (isset($boucle->modificateur['collate'])) { |
|
| 747 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + // Pour chaque paramètre du critère |
|
| 751 | + foreach ($crit->param as $tri) { |
|
| 752 | + $order = $fct = ''; |
|
| 753 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 754 | + if ($tri[0]->type != 'texte') { |
|
| 755 | + // calculer le order dynamique qui verifie les champs |
|
| 756 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 757 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 758 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 759 | + } |
|
| 760 | + // tris textuels {par titre} |
|
| 761 | + else { |
|
| 762 | + $par = array_shift($tri); |
|
| 763 | + $par = $par->texte; |
|
| 764 | + |
|
| 765 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 766 | + if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 767 | + $expression = trim($m[1]); |
|
| 768 | + $champ = trim($m[2]); |
|
| 769 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 770 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 771 | + } else { |
|
| 772 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 776 | + } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 777 | + // {par FONCTION(champ)} |
|
| 778 | + if (count($match) > 2) { |
|
| 779 | + $par = substr($match[2], 1, -1); |
|
| 780 | + $fct = $match[1]; |
|
| 781 | + } |
|
| 782 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 783 | + if ($par == 'hasard') { |
|
| 784 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 785 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 786 | + $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 787 | + } else { |
|
| 788 | + // cas général {par champ}, {par table.champ}, ... |
|
| 789 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + // on ne sait pas traiter… |
|
| 794 | + else { |
|
| 795 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 799 | + if (is_array($order)) { |
|
| 800 | + return $order; |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 805 | + $t = $m[1]; |
|
| 806 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 807 | + $boucle->select[] = $t; |
|
| 808 | + } |
|
| 809 | + } else { |
|
| 810 | + $sens = ''; |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + if ($fct) { |
|
| 814 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 815 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 816 | + } else { |
|
| 817 | + $order = "'$fct(' . $order . ')'"; |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + $t = $order . $collecte . $sens; |
|
| 821 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 822 | + $t = $r[1] . $r[2]; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + $boucle->order[] = $t; |
|
| 826 | + } |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | /** |
@@ -837,13 +837,13 @@ discard block |
||
| 837 | 837 | * @return string Clause pour le Order by |
| 838 | 838 | */ |
| 839 | 839 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 840 | - $boucle = &$boucles[$idb]; |
|
| 841 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 842 | - $parha = "rand() AS hasard"; |
|
| 843 | - if (!in_array($parha, $boucle->select)) { |
|
| 844 | - $boucle->select[] = $parha; |
|
| 845 | - } |
|
| 846 | - return "'hasard'"; |
|
| 840 | + $boucle = &$boucles[$idb]; |
|
| 841 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 842 | + $parha = "rand() AS hasard"; |
|
| 843 | + if (!in_array($parha, $boucle->select)) { |
|
| 844 | + $boucle->select[] = $parha; |
|
| 845 | + } |
|
| 846 | + return "'hasard'"; |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -867,20 +867,20 @@ discard block |
||
| 867 | 867 | * @return string Clause pour le Order by |
| 868 | 868 | */ |
| 869 | 869 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 870 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 871 | - if (is_array($_champ)) { |
|
| 872 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 873 | - } |
|
| 874 | - $boucle = &$boucles[$idb]; |
|
| 875 | - $texte = '0+' . $_champ; |
|
| 876 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 877 | - if ($suite !== "''") { |
|
| 878 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 879 | - } |
|
| 880 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 881 | - $boucle->select[] = $texte . " AS $as"; |
|
| 882 | - $order = "'$as'"; |
|
| 883 | - return $order; |
|
| 870 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 871 | + if (is_array($_champ)) { |
|
| 872 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 873 | + } |
|
| 874 | + $boucle = &$boucles[$idb]; |
|
| 875 | + $texte = '0+' . $_champ; |
|
| 876 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 877 | + if ($suite !== "''") { |
|
| 878 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 879 | + } |
|
| 880 | + $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 881 | + $boucle->select[] = $texte . " AS $as"; |
|
| 882 | + $order = "'$as'"; |
|
| 883 | + return $order; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | /** |
@@ -901,20 +901,20 @@ discard block |
||
| 901 | 901 | * @return string Clause pour le Order by |
| 902 | 902 | */ |
| 903 | 903 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 904 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 905 | - if (is_array($_champ)) { |
|
| 906 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 907 | - } |
|
| 908 | - $boucle = &$boucles[$idb]; |
|
| 909 | - $texte = '0+' . $_champ; |
|
| 910 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 911 | - if ($suite !== "''") { |
|
| 912 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 913 | - } |
|
| 914 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 915 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 916 | - $order = "'$as'"; |
|
| 917 | - return $order; |
|
| 904 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 905 | + if (is_array($_champ)) { |
|
| 906 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 907 | + } |
|
| 908 | + $boucle = &$boucles[$idb]; |
|
| 909 | + $texte = '0+' . $_champ; |
|
| 910 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 911 | + if ($suite !== "''") { |
|
| 912 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 913 | + } |
|
| 914 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 915 | + $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 916 | + $order = "'$as'"; |
|
| 917 | + return $order; |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | |
@@ -934,14 +934,14 @@ discard block |
||
| 934 | 934 | * @return string Clause pour le Order by |
| 935 | 935 | */ |
| 936 | 936 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 937 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 938 | - if (is_array($_champ)) { |
|
| 939 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 940 | - } |
|
| 941 | - $boucle = &$boucles[$idb]; |
|
| 942 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 943 | - $order = "'multi'"; |
|
| 944 | - return $order; |
|
| 937 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 938 | + if (is_array($_champ)) { |
|
| 939 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 940 | + } |
|
| 941 | + $boucle = &$boucles[$idb]; |
|
| 942 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 943 | + $order = "'multi'"; |
|
| 944 | + return $order; |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | /** |
@@ -960,56 +960,56 @@ discard block |
||
| 960 | 960 | * @return array|string |
| 961 | 961 | */ |
| 962 | 962 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 963 | - $boucle = &$boucles[$idb]; |
|
| 964 | - $desc = $boucle->show; |
|
| 965 | - |
|
| 966 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 967 | - if (isset($desc['field'][$par])) { |
|
| 968 | - $par = $boucle->id_table . "." . $par; |
|
| 969 | - } |
|
| 970 | - // le champ est peut être une jointure |
|
| 971 | - else { |
|
| 972 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 973 | - $champ = $par; |
|
| 974 | - |
|
| 975 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 976 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 977 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 978 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 979 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 980 | - list(, $table, $champ) = $r; |
|
| 981 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 982 | - $table = table_objet_sql($table); |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 986 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 987 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 988 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 989 | - $par = $infos['alias'] . "." . $champ; |
|
| 990 | - } elseif ( |
|
| 991 | - $boucle->jointures_explicites |
|
| 992 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 993 | - ) { |
|
| 994 | - $par = $alias . "." . $champ; |
|
| 995 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 996 | - $par = $alias . "." . $champ; |
|
| 997 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 998 | - } elseif ( |
|
| 999 | - $table_alias |
|
| 1000 | - and isset($boucle->from[$table_alias]) |
|
| 1001 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1002 | - ) { |
|
| 1003 | - $par = $infos['alias'] . "." . $champ; |
|
| 1004 | - } elseif ($table) { |
|
| 1005 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1006 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1007 | - } else { |
|
| 1008 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1009 | - } |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - return $raw ? $par : "'$par'"; |
|
| 963 | + $boucle = &$boucles[$idb]; |
|
| 964 | + $desc = $boucle->show; |
|
| 965 | + |
|
| 966 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 967 | + if (isset($desc['field'][$par])) { |
|
| 968 | + $par = $boucle->id_table . "." . $par; |
|
| 969 | + } |
|
| 970 | + // le champ est peut être une jointure |
|
| 971 | + else { |
|
| 972 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 973 | + $champ = $par; |
|
| 974 | + |
|
| 975 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 976 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 977 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 978 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 979 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 980 | + list(, $table, $champ) = $r; |
|
| 981 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 982 | + $table = table_objet_sql($table); |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 986 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 987 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 988 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 989 | + $par = $infos['alias'] . "." . $champ; |
|
| 990 | + } elseif ( |
|
| 991 | + $boucle->jointures_explicites |
|
| 992 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 993 | + ) { |
|
| 994 | + $par = $alias . "." . $champ; |
|
| 995 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 996 | + $par = $alias . "." . $champ; |
|
| 997 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 998 | + } elseif ( |
|
| 999 | + $table_alias |
|
| 1000 | + and isset($boucle->from[$table_alias]) |
|
| 1001 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1002 | + ) { |
|
| 1003 | + $par = $infos['alias'] . "." . $champ; |
|
| 1004 | + } elseif ($table) { |
|
| 1005 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1006 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1007 | + } else { |
|
| 1008 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1009 | + } |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + return $raw ? $par : "'$par'"; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | /** |
@@ -1023,11 +1023,11 @@ discard block |
||
| 1023 | 1023 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1024 | 1024 | */ |
| 1025 | 1025 | function critere_par_joint($table, $champ, &$boucle) { |
| 1026 | - $t = array_search($table, $boucle->from); |
|
| 1027 | - if (!$t) { |
|
| 1028 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1029 | - } |
|
| 1030 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1026 | + $t = array_search($table, $boucle->from); |
|
| 1027 | + if (!$t) { |
|
| 1028 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1029 | + } |
|
| 1030 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | /** |
@@ -1052,143 +1052,143 @@ discard block |
||
| 1052 | 1052 | */ |
| 1053 | 1053 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1054 | 1054 | |
| 1055 | - $boucle = &$boucles[$idb]; |
|
| 1056 | - // Classement par ordre inverse |
|
| 1057 | - if ($crit->not) { |
|
| 1058 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1059 | - } else { |
|
| 1060 | - $order = "' DESC'"; |
|
| 1061 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1062 | - if (isset($crit->param[0])) { |
|
| 1063 | - $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1064 | - $order = "(($critere)?' DESC':'')"; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - $n = count($boucle->order); |
|
| 1068 | - if (!$n) { |
|
| 1069 | - if (isset($boucle->default_order[0])) { |
|
| 1070 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1071 | - } else { |
|
| 1072 | - $boucle->default_order[] = ' DESC'; |
|
| 1073 | - } |
|
| 1074 | - } else { |
|
| 1075 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1076 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1077 | - $t = $r[1] . $r[2]; |
|
| 1078 | - } |
|
| 1079 | - $boucle->order[$n - 1] = $t; |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1055 | + $boucle = &$boucles[$idb]; |
|
| 1056 | + // Classement par ordre inverse |
|
| 1057 | + if ($crit->not) { |
|
| 1058 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1059 | + } else { |
|
| 1060 | + $order = "' DESC'"; |
|
| 1061 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1062 | + if (isset($crit->param[0])) { |
|
| 1063 | + $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1064 | + $order = "(($critere)?' DESC':'')"; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + $n = count($boucle->order); |
|
| 1068 | + if (!$n) { |
|
| 1069 | + if (isset($boucle->default_order[0])) { |
|
| 1070 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1071 | + } else { |
|
| 1072 | + $boucle->default_order[] = ' DESC'; |
|
| 1073 | + } |
|
| 1074 | + } else { |
|
| 1075 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1076 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1077 | + $t = $r[1] . $r[2]; |
|
| 1078 | + } |
|
| 1079 | + $boucle->order[$n - 1] = $t; |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | // http://code.spip.net/@critere_agenda_dist |
| 1085 | 1085 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1086 | - $params = $crit->param; |
|
| 1087 | - |
|
| 1088 | - if (count($params) < 1) { |
|
| 1089 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - $boucle = &$boucles[$idb]; |
|
| 1093 | - $parent = $boucle->id_parent; |
|
| 1094 | - $fields = $boucle->show['field']; |
|
| 1095 | - |
|
| 1096 | - $date = array_shift($params); |
|
| 1097 | - $type = array_shift($params); |
|
| 1098 | - |
|
| 1099 | - // la valeur $type doit etre connue a la compilation |
|
| 1100 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1101 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1102 | - |
|
| 1103 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1104 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1105 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1106 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1107 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1108 | - $date = $date[0]->texte; |
|
| 1109 | - if (!isset($fields[$date])) { |
|
| 1110 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1111 | - } |
|
| 1112 | - } else { |
|
| 1113 | - $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1114 | - $noms = array_keys($fields); |
|
| 1115 | - $defaut = $noms[0]; |
|
| 1116 | - $noms = join(" ", $noms); |
|
| 1117 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1118 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1119 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1120 | - } |
|
| 1121 | - $annee = $params ? array_shift($params) : ""; |
|
| 1122 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1123 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1124 | - ') ? $x : date("Y"))'; |
|
| 1125 | - |
|
| 1126 | - $mois = $params ? array_shift($params) : ""; |
|
| 1127 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1128 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1129 | - ') ? $x : date("m"))'; |
|
| 1130 | - |
|
| 1131 | - $jour = $params ? array_shift($params) : ""; |
|
| 1132 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1133 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1134 | - ') ? $x : date("d"))'; |
|
| 1135 | - |
|
| 1136 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 1137 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1138 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1139 | - ') ? $x : date("Y"))'; |
|
| 1140 | - |
|
| 1141 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 1142 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1143 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1144 | - ') ? $x : date("m"))'; |
|
| 1145 | - |
|
| 1146 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 1147 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1148 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1149 | - ') ? $x : date("d"))'; |
|
| 1150 | - |
|
| 1151 | - $date = $boucle->id_table . ".$date"; |
|
| 1152 | - |
|
| 1153 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1154 | - if ($type == 'jour') { |
|
| 1155 | - $boucle->where[] = array( |
|
| 1156 | - "'='", |
|
| 1157 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1158 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1159 | - ); |
|
| 1160 | - } elseif ($type == 'mois') { |
|
| 1161 | - $boucle->where[] = array( |
|
| 1162 | - "'='", |
|
| 1163 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1164 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1165 | - ); |
|
| 1166 | - } elseif ($type == 'semaine') { |
|
| 1167 | - $boucle->where[] = array( |
|
| 1168 | - "'AND'", |
|
| 1169 | - array( |
|
| 1170 | - "'>='", |
|
| 1171 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1172 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1173 | - ), |
|
| 1174 | - array( |
|
| 1175 | - "'<='", |
|
| 1176 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1177 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1178 | - ) |
|
| 1179 | - ); |
|
| 1180 | - } elseif (count($crit->param) > 2) { |
|
| 1181 | - $boucle->where[] = array( |
|
| 1182 | - "'AND'", |
|
| 1183 | - array( |
|
| 1184 | - "'>='", |
|
| 1185 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1186 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1187 | - ), |
|
| 1188 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1189 | - ); |
|
| 1190 | - } |
|
| 1191 | - // sinon on prend tout |
|
| 1086 | + $params = $crit->param; |
|
| 1087 | + |
|
| 1088 | + if (count($params) < 1) { |
|
| 1089 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + $boucle = &$boucles[$idb]; |
|
| 1093 | + $parent = $boucle->id_parent; |
|
| 1094 | + $fields = $boucle->show['field']; |
|
| 1095 | + |
|
| 1096 | + $date = array_shift($params); |
|
| 1097 | + $type = array_shift($params); |
|
| 1098 | + |
|
| 1099 | + // la valeur $type doit etre connue a la compilation |
|
| 1100 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1101 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1102 | + |
|
| 1103 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1104 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1105 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1106 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1107 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1108 | + $date = $date[0]->texte; |
|
| 1109 | + if (!isset($fields[$date])) { |
|
| 1110 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1111 | + } |
|
| 1112 | + } else { |
|
| 1113 | + $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1114 | + $noms = array_keys($fields); |
|
| 1115 | + $defaut = $noms[0]; |
|
| 1116 | + $noms = join(" ", $noms); |
|
| 1117 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1118 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1119 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1120 | + } |
|
| 1121 | + $annee = $params ? array_shift($params) : ""; |
|
| 1122 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1123 | + calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1124 | + ') ? $x : date("Y"))'; |
|
| 1125 | + |
|
| 1126 | + $mois = $params ? array_shift($params) : ""; |
|
| 1127 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1128 | + calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1129 | + ') ? $x : date("m"))'; |
|
| 1130 | + |
|
| 1131 | + $jour = $params ? array_shift($params) : ""; |
|
| 1132 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1133 | + calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1134 | + ') ? $x : date("d"))'; |
|
| 1135 | + |
|
| 1136 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 1137 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1138 | + calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1139 | + ') ? $x : date("Y"))'; |
|
| 1140 | + |
|
| 1141 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 1142 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1143 | + calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1144 | + ') ? $x : date("m"))'; |
|
| 1145 | + |
|
| 1146 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 1147 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1148 | + calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1149 | + ') ? $x : date("d"))'; |
|
| 1150 | + |
|
| 1151 | + $date = $boucle->id_table . ".$date"; |
|
| 1152 | + |
|
| 1153 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1154 | + if ($type == 'jour') { |
|
| 1155 | + $boucle->where[] = array( |
|
| 1156 | + "'='", |
|
| 1157 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1158 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1159 | + ); |
|
| 1160 | + } elseif ($type == 'mois') { |
|
| 1161 | + $boucle->where[] = array( |
|
| 1162 | + "'='", |
|
| 1163 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1164 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1165 | + ); |
|
| 1166 | + } elseif ($type == 'semaine') { |
|
| 1167 | + $boucle->where[] = array( |
|
| 1168 | + "'AND'", |
|
| 1169 | + array( |
|
| 1170 | + "'>='", |
|
| 1171 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1172 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1173 | + ), |
|
| 1174 | + array( |
|
| 1175 | + "'<='", |
|
| 1176 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1177 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1178 | + ) |
|
| 1179 | + ); |
|
| 1180 | + } elseif (count($crit->param) > 2) { |
|
| 1181 | + $boucle->where[] = array( |
|
| 1182 | + "'AND'", |
|
| 1183 | + array( |
|
| 1184 | + "'>='", |
|
| 1185 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1186 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1187 | + ), |
|
| 1188 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1189 | + ); |
|
| 1190 | + } |
|
| 1191 | + // sinon on prend tout |
|
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | 1194 | |
@@ -1213,33 +1213,33 @@ discard block |
||
| 1213 | 1213 | * @return void |
| 1214 | 1214 | **/ |
| 1215 | 1215 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1216 | - $boucle = &$boucles[$idb]; |
|
| 1217 | - $a1 = $crit->param[0]; |
|
| 1218 | - $a2 = $crit->param[1]; |
|
| 1219 | - $op = $crit->op; |
|
| 1220 | - |
|
| 1221 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1222 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1223 | - |
|
| 1224 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1225 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1226 | - } else { |
|
| 1227 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1228 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1229 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1230 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1231 | - $mode = (($op == '/') ? '/' : |
|
| 1232 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1233 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1234 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1235 | - $boucle->limit = |
|
| 1236 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1237 | - . ".','." |
|
| 1238 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1239 | - } else { |
|
| 1240 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1216 | + $boucle = &$boucles[$idb]; |
|
| 1217 | + $a1 = $crit->param[0]; |
|
| 1218 | + $a2 = $crit->param[1]; |
|
| 1219 | + $op = $crit->op; |
|
| 1220 | + |
|
| 1221 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1222 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1223 | + |
|
| 1224 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1225 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1226 | + } else { |
|
| 1227 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1228 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1229 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1230 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1231 | + $mode = (($op == '/') ? '/' : |
|
| 1232 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1233 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1234 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1235 | + $boucle->limit = |
|
| 1236 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1237 | + . ".','." |
|
| 1238 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1239 | + } else { |
|
| 1240 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | /** |
@@ -1267,63 +1267,63 @@ discard block |
||
| 1267 | 1267 | * @return void |
| 1268 | 1268 | **/ |
| 1269 | 1269 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1270 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1271 | - |
|
| 1272 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1273 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1274 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1275 | - // {1/3} |
|
| 1276 | - if ($op1 == '/') { |
|
| 1277 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1278 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1279 | - "($total_parties ? $total_parties : 1)"; |
|
| 1280 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1281 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1282 | - } else { |
|
| 1283 | - // cas {n-1,x} |
|
| 1284 | - if ($op1 == '-') { |
|
| 1285 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - // cas {x,n-1} |
|
| 1289 | - if ($op2 == '-') { |
|
| 1290 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1291 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1292 | - ($total_parties . ' - 1')); |
|
| 1293 | - } else { |
|
| 1294 | - // {x,1} ou {pagination} |
|
| 1295 | - $fin = '$debut_boucle' |
|
| 1296 | - . (is_numeric($total_parties) ? |
|
| 1297 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1298 | - ('+' . $total_parties . ' - 1')); |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1302 | - if ($op1 == 'p') { |
|
| 1303 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1304 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1305 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1306 | - } |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - // Notes : |
|
| 1310 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1311 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1312 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1313 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1314 | - |
|
| 1315 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1316 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1317 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1318 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1319 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1320 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1321 | - . "\n\tif (\$debut_boucle>0" |
|
| 1322 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1323 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1324 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1325 | - |
|
| 1326 | - $boucles[$id_boucle]->partie = " |
|
| 1270 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1271 | + |
|
| 1272 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1273 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1274 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1275 | + // {1/3} |
|
| 1276 | + if ($op1 == '/') { |
|
| 1277 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1278 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1279 | + "($total_parties ? $total_parties : 1)"; |
|
| 1280 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1281 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1282 | + } else { |
|
| 1283 | + // cas {n-1,x} |
|
| 1284 | + if ($op1 == '-') { |
|
| 1285 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + // cas {x,n-1} |
|
| 1289 | + if ($op2 == '-') { |
|
| 1290 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1291 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1292 | + ($total_parties . ' - 1')); |
|
| 1293 | + } else { |
|
| 1294 | + // {x,1} ou {pagination} |
|
| 1295 | + $fin = '$debut_boucle' |
|
| 1296 | + . (is_numeric($total_parties) ? |
|
| 1297 | + (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1298 | + ('+' . $total_parties . ' - 1')); |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1302 | + if ($op1 == 'p') { |
|
| 1303 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1304 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1305 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1306 | + } |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + // Notes : |
|
| 1310 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1311 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1312 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1313 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1314 | + |
|
| 1315 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1316 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1317 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1318 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1319 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1320 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1321 | + . "\n\tif (\$debut_boucle>0" |
|
| 1322 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1323 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1324 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1325 | + |
|
| 1326 | + $boucles[$id_boucle]->partie = " |
|
| 1327 | 1327 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1328 | 1328 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1329 | 1329 | } |
@@ -1340,26 +1340,26 @@ discard block |
||
| 1340 | 1340 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1341 | 1341 | **/ |
| 1342 | 1342 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1343 | - if ($param[0]->type != 'texte') { |
|
| 1344 | - $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1345 | - if (isset($param[1]->texte)) { |
|
| 1346 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1347 | - |
|
| 1348 | - return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1349 | - } else { |
|
| 1350 | - return array("intval($a1)", 0); |
|
| 1351 | - } |
|
| 1352 | - } else { |
|
| 1353 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1354 | - $a1 = $m[1]; |
|
| 1355 | - if (empty($m[3])) { |
|
| 1356 | - return array($a1, 0); |
|
| 1357 | - } elseif (!empty($m[4])) { |
|
| 1358 | - return array($a1, $m[4]); |
|
| 1359 | - } else { |
|
| 1360 | - return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1361 | - } |
|
| 1362 | - } |
|
| 1343 | + if ($param[0]->type != 'texte') { |
|
| 1344 | + $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1345 | + if (isset($param[1]->texte)) { |
|
| 1346 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1347 | + |
|
| 1348 | + return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1349 | + } else { |
|
| 1350 | + return array("intval($a1)", 0); |
|
| 1351 | + } |
|
| 1352 | + } else { |
|
| 1353 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1354 | + $a1 = $m[1]; |
|
| 1355 | + if (empty($m[3])) { |
|
| 1356 | + return array($a1, 0); |
|
| 1357 | + } elseif (!empty($m[4])) { |
|
| 1358 | + return array($a1, $m[4]); |
|
| 1359 | + } else { |
|
| 1360 | + return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | 1363 | } |
| 1364 | 1364 | |
| 1365 | 1365 | |
@@ -1386,47 +1386,47 @@ discard block |
||
| 1386 | 1386 | * array : Erreur sur un des critères |
| 1387 | 1387 | **/ |
| 1388 | 1388 | function calculer_criteres($idb, &$boucles) { |
| 1389 | - $msg = ''; |
|
| 1390 | - $boucle = $boucles[$idb]; |
|
| 1391 | - $table = strtoupper($boucle->type_requete); |
|
| 1392 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1393 | - |
|
| 1394 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1395 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1396 | - if (!is_array($boucle->criteres)) { |
|
| 1397 | - return array(); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - foreach ($boucle->criteres as $crit) { |
|
| 1401 | - $critere = $crit->op; |
|
| 1402 | - // critere personnalise ? |
|
| 1403 | - if ( |
|
| 1404 | - (!$serveur or |
|
| 1405 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1406 | - and (!function_exists($f = $f . "_dist")) |
|
| 1407 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1408 | - and (!function_exists($f = $f . "_dist")) |
|
| 1409 | - ) |
|
| 1410 | - ) |
|
| 1411 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1412 | - and (!function_exists($f = $f . "_dist")) |
|
| 1413 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1414 | - and (!function_exists($f = $f . "_dist")) |
|
| 1415 | - ) { |
|
| 1416 | - // fonction critere standard |
|
| 1417 | - $f = $defaut; |
|
| 1418 | - } |
|
| 1419 | - // compile le critere |
|
| 1420 | - $res = $f($idb, $boucles, $crit); |
|
| 1421 | - |
|
| 1422 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1423 | - if (is_array($res)) { |
|
| 1424 | - $msg = $res; |
|
| 1425 | - erreur_squelette($msg, $boucle); |
|
| 1426 | - } |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - return $msg; |
|
| 1389 | + $msg = ''; |
|
| 1390 | + $boucle = $boucles[$idb]; |
|
| 1391 | + $table = strtoupper($boucle->type_requete); |
|
| 1392 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1393 | + |
|
| 1394 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1395 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1396 | + if (!is_array($boucle->criteres)) { |
|
| 1397 | + return array(); |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + foreach ($boucle->criteres as $crit) { |
|
| 1401 | + $critere = $crit->op; |
|
| 1402 | + // critere personnalise ? |
|
| 1403 | + if ( |
|
| 1404 | + (!$serveur or |
|
| 1405 | + ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1406 | + and (!function_exists($f = $f . "_dist")) |
|
| 1407 | + and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1408 | + and (!function_exists($f = $f . "_dist")) |
|
| 1409 | + ) |
|
| 1410 | + ) |
|
| 1411 | + and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1412 | + and (!function_exists($f = $f . "_dist")) |
|
| 1413 | + and (!function_exists($f = "critere_" . $critere)) |
|
| 1414 | + and (!function_exists($f = $f . "_dist")) |
|
| 1415 | + ) { |
|
| 1416 | + // fonction critere standard |
|
| 1417 | + $f = $defaut; |
|
| 1418 | + } |
|
| 1419 | + // compile le critere |
|
| 1420 | + $res = $f($idb, $boucles, $crit); |
|
| 1421 | + |
|
| 1422 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1423 | + if (is_array($res)) { |
|
| 1424 | + $msg = $res; |
|
| 1425 | + erreur_squelette($msg, $boucle); |
|
| 1426 | + } |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + return $msg; |
|
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | 1432 | /** |
@@ -1443,11 +1443,11 @@ discard block |
||
| 1443 | 1443 | * @return string Code compilé rééchappé |
| 1444 | 1444 | */ |
| 1445 | 1445 | function kwote($lisp, $serveur = '', $type = '') { |
| 1446 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1447 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1448 | - } else { |
|
| 1449 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1450 | - } |
|
| 1446 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1447 | + return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1448 | + } else { |
|
| 1449 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1450 | + } |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | |
@@ -1466,85 +1466,85 @@ discard block |
||
| 1466 | 1466 | * @return void |
| 1467 | 1467 | **/ |
| 1468 | 1468 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1469 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1470 | - if (!$r) { |
|
| 1471 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1472 | - } |
|
| 1473 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1474 | - |
|
| 1475 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1476 | - |
|
| 1477 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1478 | - $where = $in; |
|
| 1479 | - if ($crit->cond) { |
|
| 1480 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1481 | - $where = array("'?'", $pred, $where, "''"); |
|
| 1482 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1483 | - { |
|
| 1484 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1485 | - } |
|
| 1486 | - } |
|
| 1487 | - if ($crit->exclus) { |
|
| 1488 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1489 | - $where = array("'NOT'", $where); |
|
| 1490 | - } else |
|
| 1491 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1492 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1493 | - { |
|
| 1494 | - $where = array( |
|
| 1495 | - "'NOT'", |
|
| 1496 | - array( |
|
| 1497 | - "'IN'", |
|
| 1498 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1499 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1500 | - ) |
|
| 1501 | - ); |
|
| 1502 | - } |
|
| 1503 | - } |
|
| 1504 | - |
|
| 1505 | - $boucles[$idb]->where[] = $where; |
|
| 1506 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1507 | - { |
|
| 1508 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1509 | - } |
|
| 1469 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1470 | + if (!$r) { |
|
| 1471 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1472 | + } |
|
| 1473 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1474 | + |
|
| 1475 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1476 | + |
|
| 1477 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1478 | + $where = $in; |
|
| 1479 | + if ($crit->cond) { |
|
| 1480 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1481 | + $where = array("'?'", $pred, $where, "''"); |
|
| 1482 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1483 | + { |
|
| 1484 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1485 | + } |
|
| 1486 | + } |
|
| 1487 | + if ($crit->exclus) { |
|
| 1488 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1489 | + $where = array("'NOT'", $where); |
|
| 1490 | + } else |
|
| 1491 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1492 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1493 | + { |
|
| 1494 | + $where = array( |
|
| 1495 | + "'NOT'", |
|
| 1496 | + array( |
|
| 1497 | + "'IN'", |
|
| 1498 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1499 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1500 | + ) |
|
| 1501 | + ); |
|
| 1502 | + } |
|
| 1503 | + } |
|
| 1504 | + |
|
| 1505 | + $boucles[$idb]->where[] = $where; |
|
| 1506 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1507 | + { |
|
| 1508 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1509 | + } |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | // http://code.spip.net/@critere_IN_cas |
| 1513 | 1513 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1514 | - static $num = array(); |
|
| 1515 | - $descr = $boucles[$idb]->descr; |
|
| 1516 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1517 | - |
|
| 1518 | - $var = '$in' . $cpt++; |
|
| 1519 | - $x = "\n\t$var = array();"; |
|
| 1520 | - foreach ($val as $k => $v) { |
|
| 1521 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1522 | - // optimiser le traitement des constantes |
|
| 1523 | - if (is_numeric($r[2])) { |
|
| 1524 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1525 | - } else { |
|
| 1526 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1527 | - } |
|
| 1528 | - } else { |
|
| 1529 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1530 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1531 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1532 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1533 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1534 | - } |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - $boucles[$idb]->in .= $x; |
|
| 1538 | - |
|
| 1539 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1540 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1541 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1542 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1543 | - if (!$crit2) { |
|
| 1544 | - $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1514 | + static $num = array(); |
|
| 1515 | + $descr = $boucles[$idb]->descr; |
|
| 1516 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1517 | + |
|
| 1518 | + $var = '$in' . $cpt++; |
|
| 1519 | + $x = "\n\t$var = array();"; |
|
| 1520 | + foreach ($val as $k => $v) { |
|
| 1521 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1522 | + // optimiser le traitement des constantes |
|
| 1523 | + if (is_numeric($r[2])) { |
|
| 1524 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1525 | + } else { |
|
| 1526 | + $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1527 | + } |
|
| 1528 | + } else { |
|
| 1529 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1530 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1531 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1532 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1533 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + $boucles[$idb]->in .= $x; |
|
| 1538 | + |
|
| 1539 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1540 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1541 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1542 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1543 | + if (!$crit2) { |
|
| 1544 | + $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1548 | 1548 | } |
| 1549 | 1549 | |
| 1550 | 1550 | /** |
@@ -1560,22 +1560,22 @@ discard block |
||
| 1560 | 1560 | * @return void |
| 1561 | 1561 | */ |
| 1562 | 1562 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1563 | - $boucle = &$boucles[$idb]; |
|
| 1564 | - if (isset($crit->param[0])) { |
|
| 1565 | - $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1566 | - } else { |
|
| 1567 | - $_where = '@$Pile[0]["where"]'; |
|
| 1568 | - } |
|
| 1569 | - |
|
| 1570 | - if ($crit->cond) { |
|
| 1571 | - $_where = "(($_where) ? ($_where) : '')"; |
|
| 1572 | - } |
|
| 1573 | - |
|
| 1574 | - if ($crit->not) { |
|
| 1575 | - $_where = "array('NOT',$_where)"; |
|
| 1576 | - } |
|
| 1577 | - |
|
| 1578 | - $boucle->where[] = $_where; |
|
| 1563 | + $boucle = &$boucles[$idb]; |
|
| 1564 | + if (isset($crit->param[0])) { |
|
| 1565 | + $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1566 | + } else { |
|
| 1567 | + $_where = '@$Pile[0]["where"]'; |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + if ($crit->cond) { |
|
| 1571 | + $_where = "(($_where) ? ($_where) : '')"; |
|
| 1572 | + } |
|
| 1573 | + |
|
| 1574 | + if ($crit->not) { |
|
| 1575 | + $_where = "array('NOT',$_where)"; |
|
| 1576 | + } |
|
| 1577 | + |
|
| 1578 | + $boucle->where[] = $_where; |
|
| 1579 | 1579 | } |
| 1580 | 1580 | |
| 1581 | 1581 | /** |
@@ -1603,31 +1603,31 @@ discard block |
||
| 1603 | 1603 | * @return void |
| 1604 | 1604 | */ |
| 1605 | 1605 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1606 | - /** @var Boucle $boucle */ |
|
| 1607 | - $boucle = $boucles[$idb]; |
|
| 1608 | - |
|
| 1609 | - $champs = lister_champs_selection_conditionnelle( |
|
| 1610 | - $boucle->show['table'], |
|
| 1611 | - $boucle->show, |
|
| 1612 | - $boucle->sql_serveur |
|
| 1613 | - ); |
|
| 1614 | - |
|
| 1615 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1616 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1617 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1618 | - } |
|
| 1619 | - // nous aider en mode debug. |
|
| 1620 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1621 | - $boucle->modificateur['id_'] = $champs; |
|
| 1622 | - |
|
| 1623 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1624 | - foreach ($champs as $champ) { |
|
| 1625 | - $critere_id_table = new Critere; |
|
| 1626 | - $critere_id_table->op = $champ; |
|
| 1627 | - $critere_id_table->cond = '?'; |
|
| 1628 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1629 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1630 | - } |
|
| 1606 | + /** @var Boucle $boucle */ |
|
| 1607 | + $boucle = $boucles[$idb]; |
|
| 1608 | + |
|
| 1609 | + $champs = lister_champs_selection_conditionnelle( |
|
| 1610 | + $boucle->show['table'], |
|
| 1611 | + $boucle->show, |
|
| 1612 | + $boucle->sql_serveur |
|
| 1613 | + ); |
|
| 1614 | + |
|
| 1615 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1616 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1617 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1618 | + } |
|
| 1619 | + // nous aider en mode debug. |
|
| 1620 | + $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1621 | + $boucle->modificateur['id_'] = $champs; |
|
| 1622 | + |
|
| 1623 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1624 | + foreach ($champs as $champ) { |
|
| 1625 | + $critere_id_table = new Critere; |
|
| 1626 | + $critere_id_table->op = $champ; |
|
| 1627 | + $critere_id_table->cond = '?'; |
|
| 1628 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1629 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1630 | + } |
|
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | /** |
@@ -1647,67 +1647,67 @@ discard block |
||
| 1647 | 1647 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1648 | 1648 | */ |
| 1649 | 1649 | function lister_champs_selection_conditionnelle($table, $desc = null, $serveur = '') { |
| 1650 | - // calculer la description de la table |
|
| 1651 | - if (!is_array($desc)) { |
|
| 1652 | - $desc = description_table($table, $serveur); |
|
| 1653 | - } |
|
| 1654 | - if (!$desc) { |
|
| 1655 | - return []; |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - // Les champs id_xx de la table demandée |
|
| 1659 | - $champs = array_filter( |
|
| 1660 | - array_keys($desc['field']), |
|
| 1661 | - function($champ){ |
|
| 1662 | - return |
|
| 1663 | - strpos($champ, 'id_') === 0 |
|
| 1664 | - or (in_array($champ, array('objet'))); |
|
| 1665 | - } |
|
| 1666 | - ); |
|
| 1667 | - |
|
| 1668 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1669 | - if ($serveur) { |
|
| 1670 | - return $champs; |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - $primary = false; |
|
| 1674 | - $associable = false; |
|
| 1675 | - include_spip('action/editer_liens'); |
|
| 1676 | - |
|
| 1677 | - if (isset($desc['type'])) { |
|
| 1678 | - $primary = id_table_objet($desc['type']); |
|
| 1679 | - $associable = objet_associable($desc['type']); |
|
| 1680 | - } |
|
| 1681 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1682 | - $associable = true; |
|
| 1683 | - } |
|
| 1684 | - |
|
| 1685 | - // liste de toutes les tables principales, sauf la notre |
|
| 1686 | - $tables = lister_tables_objets_sql(); |
|
| 1687 | - unset($tables[$table]); |
|
| 1688 | - |
|
| 1689 | - foreach ($tables as $_table => $_desc) { |
|
| 1690 | - if ( |
|
| 1691 | - $associable |
|
| 1692 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1693 | - or objet_associable($_desc['type']) |
|
| 1694 | - ) { |
|
| 1695 | - $champs[] = id_table_objet($_table); |
|
| 1696 | - } |
|
| 1697 | - } |
|
| 1698 | - $champs = array_values(array_unique($champs)); |
|
| 1699 | - $champs = pipeline( |
|
| 1700 | - 'lister_champs_selection_conditionnelle', |
|
| 1701 | - array( |
|
| 1702 | - 'args' => array( |
|
| 1703 | - 'table' => $table, |
|
| 1704 | - 'id_table_objet' => $primary, |
|
| 1705 | - 'associable' => $associable, |
|
| 1706 | - ), |
|
| 1707 | - 'data' => $champs, |
|
| 1708 | - ) |
|
| 1709 | - ); |
|
| 1710 | - return $champs; |
|
| 1650 | + // calculer la description de la table |
|
| 1651 | + if (!is_array($desc)) { |
|
| 1652 | + $desc = description_table($table, $serveur); |
|
| 1653 | + } |
|
| 1654 | + if (!$desc) { |
|
| 1655 | + return []; |
|
| 1656 | + } |
|
| 1657 | + |
|
| 1658 | + // Les champs id_xx de la table demandée |
|
| 1659 | + $champs = array_filter( |
|
| 1660 | + array_keys($desc['field']), |
|
| 1661 | + function($champ){ |
|
| 1662 | + return |
|
| 1663 | + strpos($champ, 'id_') === 0 |
|
| 1664 | + or (in_array($champ, array('objet'))); |
|
| 1665 | + } |
|
| 1666 | + ); |
|
| 1667 | + |
|
| 1668 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1669 | + if ($serveur) { |
|
| 1670 | + return $champs; |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + $primary = false; |
|
| 1674 | + $associable = false; |
|
| 1675 | + include_spip('action/editer_liens'); |
|
| 1676 | + |
|
| 1677 | + if (isset($desc['type'])) { |
|
| 1678 | + $primary = id_table_objet($desc['type']); |
|
| 1679 | + $associable = objet_associable($desc['type']); |
|
| 1680 | + } |
|
| 1681 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1682 | + $associable = true; |
|
| 1683 | + } |
|
| 1684 | + |
|
| 1685 | + // liste de toutes les tables principales, sauf la notre |
|
| 1686 | + $tables = lister_tables_objets_sql(); |
|
| 1687 | + unset($tables[$table]); |
|
| 1688 | + |
|
| 1689 | + foreach ($tables as $_table => $_desc) { |
|
| 1690 | + if ( |
|
| 1691 | + $associable |
|
| 1692 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1693 | + or objet_associable($_desc['type']) |
|
| 1694 | + ) { |
|
| 1695 | + $champs[] = id_table_objet($_table); |
|
| 1696 | + } |
|
| 1697 | + } |
|
| 1698 | + $champs = array_values(array_unique($champs)); |
|
| 1699 | + $champs = pipeline( |
|
| 1700 | + 'lister_champs_selection_conditionnelle', |
|
| 1701 | + array( |
|
| 1702 | + 'args' => array( |
|
| 1703 | + 'table' => $table, |
|
| 1704 | + 'id_table_objet' => $primary, |
|
| 1705 | + 'associable' => $associable, |
|
| 1706 | + ), |
|
| 1707 | + 'data' => $champs, |
|
| 1708 | + ) |
|
| 1709 | + ); |
|
| 1710 | + return $champs; |
|
| 1711 | 1711 | } |
| 1712 | 1712 | |
| 1713 | 1713 | /** |
@@ -1762,27 +1762,27 @@ discard block |
||
| 1762 | 1762 | * @return void |
| 1763 | 1763 | */ |
| 1764 | 1764 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1765 | - $boucle = &$boucles[$idb]; |
|
| 1766 | - |
|
| 1767 | - // definition du champ par defaut |
|
| 1768 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1769 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1770 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1771 | - : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1772 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1773 | - : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1774 | - |
|
| 1775 | - $_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):'')"; |
|
| 1776 | - |
|
| 1777 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1778 | - $_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)"; |
|
| 1779 | - |
|
| 1780 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1781 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1782 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1783 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1784 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1785 | - $boucle->hash .= " |
|
| 1765 | + $boucle = &$boucles[$idb]; |
|
| 1766 | + |
|
| 1767 | + // definition du champ par defaut |
|
| 1768 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1769 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1770 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1771 | + : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1772 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1773 | + : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1774 | + |
|
| 1775 | + $_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):'')"; |
|
| 1776 | + |
|
| 1777 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1778 | + $_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)"; |
|
| 1779 | + |
|
| 1780 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1781 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1782 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1783 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1784 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1785 | + $boucle->hash .= " |
|
| 1786 | 1786 | \$senstri = ''; |
| 1787 | 1787 | \$tri = $_tri; |
| 1788 | 1788 | if (\$tri){ |
@@ -1790,8 +1790,8 @@ discard block |
||
| 1790 | 1790 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1791 | 1791 | }; |
| 1792 | 1792 | "; |
| 1793 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1794 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1793 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1794 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1795 | 1795 | } |
| 1796 | 1796 | |
| 1797 | 1797 | # Criteres de comparaison |
@@ -1808,20 +1808,20 @@ discard block |
||
| 1808 | 1808 | * @return void |
| 1809 | 1809 | **/ |
| 1810 | 1810 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1811 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1812 | - if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1813 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1814 | - } |
|
| 1815 | - |
|
| 1816 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1817 | - if (!$r) { |
|
| 1818 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1819 | - # if (!$crit->cond) { |
|
| 1820 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1821 | - # } |
|
| 1822 | - } else { |
|
| 1823 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1824 | - } |
|
| 1811 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1812 | + if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1813 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1814 | + } |
|
| 1815 | + |
|
| 1816 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1817 | + if (!$r) { |
|
| 1818 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1819 | + # if (!$crit->cond) { |
|
| 1820 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1821 | + # } |
|
| 1822 | + } else { |
|
| 1823 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1824 | + } |
|
| 1825 | 1825 | } |
| 1826 | 1826 | |
| 1827 | 1827 | |
@@ -1841,63 +1841,63 @@ discard block |
||
| 1841 | 1841 | * @return void |
| 1842 | 1842 | **/ |
| 1843 | 1843 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1844 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1845 | - |
|
| 1846 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1847 | - |
|
| 1848 | - // inserer la negation (cf !...) |
|
| 1849 | - |
|
| 1850 | - if ($crit->not) { |
|
| 1851 | - $where = array("'NOT'", $where); |
|
| 1852 | - } |
|
| 1853 | - if ($crit->exclus) { |
|
| 1854 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1855 | - $where = array("'NOT'", $where); |
|
| 1856 | - } else |
|
| 1857 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1858 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1859 | - { |
|
| 1860 | - $where = array( |
|
| 1861 | - "'NOT'", |
|
| 1862 | - array( |
|
| 1863 | - "'IN'", |
|
| 1864 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1865 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1866 | - ) |
|
| 1867 | - ); |
|
| 1868 | - } |
|
| 1869 | - } |
|
| 1870 | - |
|
| 1871 | - // inserer la condition (cf {lang?}) |
|
| 1872 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1873 | - if ($crit->cond) { |
|
| 1874 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1875 | - if ($col == "date" or $col == "date_redac") { |
|
| 1876 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1877 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1878 | - } |
|
| 1879 | - } |
|
| 1880 | - |
|
| 1881 | - if ($op == '=' and !$crit->not) { |
|
| 1882 | - $where = array( |
|
| 1883 | - "'?'", |
|
| 1884 | - "(is_array($pred))", |
|
| 1885 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1886 | - $where |
|
| 1887 | - ); |
|
| 1888 | - } |
|
| 1889 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1890 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1891 | - { |
|
| 1892 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1893 | - } |
|
| 1894 | - } |
|
| 1895 | - |
|
| 1896 | - $boucles[$idb]->where[] = $where; |
|
| 1897 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1898 | - { |
|
| 1899 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1900 | - } |
|
| 1844 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1845 | + |
|
| 1846 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1847 | + |
|
| 1848 | + // inserer la negation (cf !...) |
|
| 1849 | + |
|
| 1850 | + if ($crit->not) { |
|
| 1851 | + $where = array("'NOT'", $where); |
|
| 1852 | + } |
|
| 1853 | + if ($crit->exclus) { |
|
| 1854 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1855 | + $where = array("'NOT'", $where); |
|
| 1856 | + } else |
|
| 1857 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1858 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1859 | + { |
|
| 1860 | + $where = array( |
|
| 1861 | + "'NOT'", |
|
| 1862 | + array( |
|
| 1863 | + "'IN'", |
|
| 1864 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1865 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1866 | + ) |
|
| 1867 | + ); |
|
| 1868 | + } |
|
| 1869 | + } |
|
| 1870 | + |
|
| 1871 | + // inserer la condition (cf {lang?}) |
|
| 1872 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1873 | + if ($crit->cond) { |
|
| 1874 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1875 | + if ($col == "date" or $col == "date_redac") { |
|
| 1876 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1877 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1878 | + } |
|
| 1879 | + } |
|
| 1880 | + |
|
| 1881 | + if ($op == '=' and !$crit->not) { |
|
| 1882 | + $where = array( |
|
| 1883 | + "'?'", |
|
| 1884 | + "(is_array($pred))", |
|
| 1885 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1886 | + $where |
|
| 1887 | + ); |
|
| 1888 | + } |
|
| 1889 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1890 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1891 | + { |
|
| 1892 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1893 | + } |
|
| 1894 | + } |
|
| 1895 | + |
|
| 1896 | + $boucles[$idb]->where[] = $where; |
|
| 1897 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1898 | + { |
|
| 1899 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1900 | + } |
|
| 1901 | 1901 | } |
| 1902 | 1902 | |
| 1903 | 1903 | |
@@ -1938,167 +1938,167 @@ discard block |
||
| 1938 | 1938 | **/ |
| 1939 | 1939 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1940 | 1940 | |
| 1941 | - $boucle = &$boucles[$idb]; |
|
| 1942 | - $type = $boucle->type_requete; |
|
| 1943 | - $table = $boucle->id_table; |
|
| 1944 | - $desc = $boucle->show; |
|
| 1945 | - $col_vraie = null; |
|
| 1946 | - |
|
| 1947 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1948 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1949 | - |
|
| 1950 | - $col_alias = $col; |
|
| 1951 | - $where_complement = false; |
|
| 1952 | - |
|
| 1953 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1954 | - if ($col == 'id_enfant') { |
|
| 1955 | - $col = $boucle->primary; |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1959 | - if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1960 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1961 | - ) { |
|
| 1962 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1963 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1964 | - else { |
|
| 1965 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1966 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1970 | - // sauf si exception declaree : sauter cette etape |
|
| 1971 | - else { |
|
| 1972 | - if ( |
|
| 1973 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1974 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1975 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1976 | - ) { |
|
| 1977 | - $e = decompose_champ_id_objet($col); |
|
| 1978 | - $col = array_shift($e); |
|
| 1979 | - $where_complement = primary_doublee($e, $table); |
|
| 1980 | - } // Cas particulier : expressions de date |
|
| 1981 | - else { |
|
| 1982 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1983 | - list($col, $col_vraie) = $c; |
|
| 1984 | - $table = ''; |
|
| 1985 | - } // table explicitée {mots.titre} |
|
| 1986 | - else { |
|
| 1987 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1988 | - list(, $table, $col) = $r; |
|
| 1989 | - $col_alias = $col; |
|
| 1990 | - |
|
| 1991 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1992 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1993 | - and isset($desc['field'][$col]) |
|
| 1994 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 1995 | - ) { |
|
| 1996 | - $table = $cle; |
|
| 1997 | - } else { |
|
| 1998 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1999 | - } |
|
| 2000 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2001 | - if (!$table) { |
|
| 2002 | - return ''; |
|
| 2003 | - } |
|
| 2004 | - } |
|
| 2005 | - // si le champ n'est pas trouvé dans la table, |
|
| 2006 | - // on cherche si une jointure peut l'obtenir |
|
| 2007 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2008 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2009 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2010 | - $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 |
|
| 2011 | - } |
|
| 2012 | - else { |
|
| 2013 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2014 | - if (!$r) { |
|
| 2015 | - return ''; |
|
| 2016 | - } |
|
| 2017 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2018 | - } |
|
| 2019 | - } |
|
| 2020 | - } |
|
| 2021 | - } |
|
| 2022 | - } |
|
| 2023 | - } |
|
| 2024 | - |
|
| 2025 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2026 | - // Dans tous les cas, |
|
| 2027 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2028 | - // et passer dans sql_quote avec le type si connu |
|
| 2029 | - // et int sinon si la valeur est numerique |
|
| 2030 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2031 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2032 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2033 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2034 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2035 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2036 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2037 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2038 | - } |
|
| 2039 | - // sinon expliciter les |
|
| 2040 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2041 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2042 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2043 | - // sans toucher aux |
|
| 2044 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2045 | - // sql_quote(truc,'','varchar') |
|
| 2046 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2047 | - // si pas deja un type |
|
| 2048 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2049 | - ) { |
|
| 2050 | - $r = $r[1] |
|
| 2051 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2052 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2053 | - $val[0] = "sql_quote($r)"; |
|
| 2054 | - } |
|
| 2055 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2056 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2057 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2058 | - } |
|
| 2059 | - } |
|
| 2060 | - |
|
| 2061 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2062 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2063 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2067 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2068 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2069 | - if ($table === $boucle->id_table) { |
|
| 2070 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2071 | - if ($col_alias != $col_vraie) { |
|
| 2072 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2073 | - } |
|
| 2074 | - } |
|
| 2075 | - |
|
| 2076 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2077 | - // il faut alors interdire a la fonction de boucle |
|
| 2078 | - // de mettre ses propres criteres de statut |
|
| 2079 | - // http://www.spip.net/@statut (a documenter) |
|
| 2080 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2081 | - if ($col == 'statut') { |
|
| 2082 | - $boucles[$idb]->statut = true; |
|
| 2083 | - } |
|
| 2084 | - |
|
| 2085 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2086 | - if ($table) { |
|
| 2087 | - if ($col[0] == "`") { |
|
| 2088 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2089 | - } else { |
|
| 2090 | - $arg = "$table.$col"; |
|
| 2091 | - } |
|
| 2092 | - } else { |
|
| 2093 | - $arg = $col; |
|
| 2094 | - } |
|
| 2095 | - |
|
| 2096 | - // inserer la fonction SQL |
|
| 2097 | - if ($fct) { |
|
| 2098 | - $arg = "$fct($arg$args_sql)"; |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1941 | + $boucle = &$boucles[$idb]; |
|
| 1942 | + $type = $boucle->type_requete; |
|
| 1943 | + $table = $boucle->id_table; |
|
| 1944 | + $desc = $boucle->show; |
|
| 1945 | + $col_vraie = null; |
|
| 1946 | + |
|
| 1947 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1948 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1949 | + |
|
| 1950 | + $col_alias = $col; |
|
| 1951 | + $where_complement = false; |
|
| 1952 | + |
|
| 1953 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1954 | + if ($col == 'id_enfant') { |
|
| 1955 | + $col = $boucle->primary; |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1959 | + if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1960 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1961 | + ) { |
|
| 1962 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1963 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1964 | + else { |
|
| 1965 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1966 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1970 | + // sauf si exception declaree : sauter cette etape |
|
| 1971 | + else { |
|
| 1972 | + if ( |
|
| 1973 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1974 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1975 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1976 | + ) { |
|
| 1977 | + $e = decompose_champ_id_objet($col); |
|
| 1978 | + $col = array_shift($e); |
|
| 1979 | + $where_complement = primary_doublee($e, $table); |
|
| 1980 | + } // Cas particulier : expressions de date |
|
| 1981 | + else { |
|
| 1982 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1983 | + list($col, $col_vraie) = $c; |
|
| 1984 | + $table = ''; |
|
| 1985 | + } // table explicitée {mots.titre} |
|
| 1986 | + else { |
|
| 1987 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1988 | + list(, $table, $col) = $r; |
|
| 1989 | + $col_alias = $col; |
|
| 1990 | + |
|
| 1991 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1992 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1993 | + and isset($desc['field'][$col]) |
|
| 1994 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 1995 | + ) { |
|
| 1996 | + $table = $cle; |
|
| 1997 | + } else { |
|
| 1998 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1999 | + } |
|
| 2000 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2001 | + if (!$table) { |
|
| 2002 | + return ''; |
|
| 2003 | + } |
|
| 2004 | + } |
|
| 2005 | + // si le champ n'est pas trouvé dans la table, |
|
| 2006 | + // on cherche si une jointure peut l'obtenir |
|
| 2007 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2008 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2009 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2010 | + $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 |
|
| 2011 | + } |
|
| 2012 | + else { |
|
| 2013 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2014 | + if (!$r) { |
|
| 2015 | + return ''; |
|
| 2016 | + } |
|
| 2017 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2018 | + } |
|
| 2019 | + } |
|
| 2020 | + } |
|
| 2021 | + } |
|
| 2022 | + } |
|
| 2023 | + } |
|
| 2024 | + |
|
| 2025 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2026 | + // Dans tous les cas, |
|
| 2027 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2028 | + // et passer dans sql_quote avec le type si connu |
|
| 2029 | + // et int sinon si la valeur est numerique |
|
| 2030 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2031 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2032 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2033 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2034 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2035 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2036 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2037 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2038 | + } |
|
| 2039 | + // sinon expliciter les |
|
| 2040 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2041 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2042 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2043 | + // sans toucher aux |
|
| 2044 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2045 | + // sql_quote(truc,'','varchar') |
|
| 2046 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2047 | + // si pas deja un type |
|
| 2048 | + and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2049 | + ) { |
|
| 2050 | + $r = $r[1] |
|
| 2051 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2052 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2053 | + $val[0] = "sql_quote($r)"; |
|
| 2054 | + } |
|
| 2055 | + elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2056 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2057 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2058 | + } |
|
| 2059 | + } |
|
| 2060 | + |
|
| 2061 | + if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2062 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2063 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2067 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2068 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2069 | + if ($table === $boucle->id_table) { |
|
| 2070 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2071 | + if ($col_alias != $col_vraie) { |
|
| 2072 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2073 | + } |
|
| 2074 | + } |
|
| 2075 | + |
|
| 2076 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2077 | + // il faut alors interdire a la fonction de boucle |
|
| 2078 | + // de mettre ses propres criteres de statut |
|
| 2079 | + // http://www.spip.net/@statut (a documenter) |
|
| 2080 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2081 | + if ($col == 'statut') { |
|
| 2082 | + $boucles[$idb]->statut = true; |
|
| 2083 | + } |
|
| 2084 | + |
|
| 2085 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2086 | + if ($table) { |
|
| 2087 | + if ($col[0] == "`") { |
|
| 2088 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2089 | + } else { |
|
| 2090 | + $arg = "$table.$col"; |
|
| 2091 | + } |
|
| 2092 | + } else { |
|
| 2093 | + $arg = $col; |
|
| 2094 | + } |
|
| 2095 | + |
|
| 2096 | + // inserer la fonction SQL |
|
| 2097 | + if ($fct) { |
|
| 2098 | + $arg = "$fct($arg$args_sql)"; |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 2102 | 2102 | } |
| 2103 | 2103 | |
| 2104 | 2104 | |
@@ -2127,77 +2127,77 @@ discard block |
||
| 2127 | 2127 | **/ |
| 2128 | 2128 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2129 | 2129 | |
| 2130 | - $where = ''; |
|
| 2131 | - |
|
| 2132 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2133 | - // gestion par les plugins des jointures tordues |
|
| 2134 | - // pas automatiques mais necessaires |
|
| 2135 | - $table_sql = table_objet_sql($table); |
|
| 2136 | - if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2137 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2138 | - and |
|
| 2139 | - ( |
|
| 2140 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2141 | - or |
|
| 2142 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2143 | - ) |
|
| 2144 | - ) { |
|
| 2145 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2146 | - $index = isset($t[$col]) |
|
| 2147 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2148 | - |
|
| 2149 | - if (count($index) == 3) { |
|
| 2150 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2151 | - } elseif (count($index) == 2) { |
|
| 2152 | - list($t, $col) = $t[$col]; |
|
| 2153 | - } elseif (count($index) == 1) { |
|
| 2154 | - list($calculer_critere_externe) = $index; |
|
| 2155 | - $t = $table; |
|
| 2156 | - } else { |
|
| 2157 | - $t = ''; |
|
| 2158 | - } // jointure non declaree. La trouver. |
|
| 2159 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2160 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2161 | - } else { |
|
| 2162 | - $t = ''; |
|
| 2163 | - } // jointure non declaree. La trouver. |
|
| 2164 | - |
|
| 2165 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2166 | - |
|
| 2167 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2168 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2169 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2170 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2171 | - $table = ""; |
|
| 2172 | - if ($boucle->jointures_explicites) { |
|
| 2173 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2174 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2175 | - } |
|
| 2176 | - |
|
| 2177 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2178 | - if (!$table) { |
|
| 2179 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2180 | - } |
|
| 2181 | - |
|
| 2182 | - if (!$table) { |
|
| 2183 | - return ''; |
|
| 2184 | - } |
|
| 2185 | - |
|
| 2186 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2187 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2188 | - |
|
| 2189 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2190 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2191 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2192 | - $e = decompose_champ_id_objet($col); |
|
| 2193 | - $col = array_shift($e); |
|
| 2194 | - $where = primary_doublee($e, $table); |
|
| 2195 | - } else { |
|
| 2196 | - $col = reset($cle); |
|
| 2197 | - } |
|
| 2198 | - } |
|
| 2199 | - |
|
| 2200 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 2130 | + $where = ''; |
|
| 2131 | + |
|
| 2132 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2133 | + // gestion par les plugins des jointures tordues |
|
| 2134 | + // pas automatiques mais necessaires |
|
| 2135 | + $table_sql = table_objet_sql($table); |
|
| 2136 | + if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2137 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2138 | + and |
|
| 2139 | + ( |
|
| 2140 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2141 | + or |
|
| 2142 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2143 | + ) |
|
| 2144 | + ) { |
|
| 2145 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2146 | + $index = isset($t[$col]) |
|
| 2147 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2148 | + |
|
| 2149 | + if (count($index) == 3) { |
|
| 2150 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2151 | + } elseif (count($index) == 2) { |
|
| 2152 | + list($t, $col) = $t[$col]; |
|
| 2153 | + } elseif (count($index) == 1) { |
|
| 2154 | + list($calculer_critere_externe) = $index; |
|
| 2155 | + $t = $table; |
|
| 2156 | + } else { |
|
| 2157 | + $t = ''; |
|
| 2158 | + } // jointure non declaree. La trouver. |
|
| 2159 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2160 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2161 | + } else { |
|
| 2162 | + $t = ''; |
|
| 2163 | + } // jointure non declaree. La trouver. |
|
| 2164 | + |
|
| 2165 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2166 | + |
|
| 2167 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2168 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2169 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2170 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2171 | + $table = ""; |
|
| 2172 | + if ($boucle->jointures_explicites) { |
|
| 2173 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2174 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2175 | + } |
|
| 2176 | + |
|
| 2177 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2178 | + if (!$table) { |
|
| 2179 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2180 | + } |
|
| 2181 | + |
|
| 2182 | + if (!$table) { |
|
| 2183 | + return ''; |
|
| 2184 | + } |
|
| 2185 | + |
|
| 2186 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2187 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2188 | + |
|
| 2189 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2190 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2191 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2192 | + $e = decompose_champ_id_objet($col); |
|
| 2193 | + $col = array_shift($e); |
|
| 2194 | + $where = primary_doublee($e, $table); |
|
| 2195 | + } else { |
|
| 2196 | + $col = reset($cle); |
|
| 2197 | + } |
|
| 2198 | + } |
|
| 2199 | + |
|
| 2200 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 2201 | 2201 | } |
| 2202 | 2202 | |
| 2203 | 2203 | |
@@ -2218,10 +2218,10 @@ discard block |
||
| 2218 | 2218 | * - valeur |
| 2219 | 2219 | **/ |
| 2220 | 2220 | function primary_doublee($decompose, $table) { |
| 2221 | - $e1 = reset($decompose); |
|
| 2222 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2221 | + $e1 = reset($decompose); |
|
| 2222 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2223 | 2223 | |
| 2224 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2224 | + return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2225 | 2225 | } |
| 2226 | 2226 | |
| 2227 | 2227 | /** |
@@ -2252,56 +2252,56 @@ discard block |
||
| 2252 | 2252 | * Vide sinon. |
| 2253 | 2253 | */ |
| 2254 | 2254 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2255 | - // si on demande un truc du genre spip_mots |
|
| 2256 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2257 | - // et qu'on est la |
|
| 2258 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2259 | - if ($checkarrivee |
|
| 2260 | - and is_string($checkarrivee) |
|
| 2261 | - and $a = table_objet($checkarrivee) |
|
| 2262 | - and in_array($a . '_liens', $joints) |
|
| 2263 | - ) { |
|
| 2264 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2265 | - return $res; |
|
| 2266 | - } |
|
| 2267 | - } |
|
| 2268 | - foreach ($joints as $joint) { |
|
| 2269 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2270 | - // alias de table dans le from |
|
| 2271 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2272 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2273 | - $cols = $arrivee[2]; |
|
| 2274 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2275 | - if (count($cols) > 2) { |
|
| 2276 | - array_pop($cols); |
|
| 2277 | - } |
|
| 2278 | - if ($t) { |
|
| 2279 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2280 | - $joindre = false; |
|
| 2281 | - foreach ($cols as $col) { |
|
| 2282 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2283 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2284 | - $joindre = true; |
|
| 2285 | - } else { |
|
| 2286 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2287 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2288 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2289 | - $joindre = true; |
|
| 2290 | - } |
|
| 2291 | - } |
|
| 2292 | - } |
|
| 2293 | - if (!$joindre) { |
|
| 2294 | - return $t; |
|
| 2295 | - } |
|
| 2296 | - } |
|
| 2297 | - array_pop($arrivee); |
|
| 2298 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2299 | - return $res; |
|
| 2300 | - } |
|
| 2301 | - } |
|
| 2302 | - } |
|
| 2303 | - |
|
| 2304 | - return ''; |
|
| 2255 | + // si on demande un truc du genre spip_mots |
|
| 2256 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2257 | + // et qu'on est la |
|
| 2258 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2259 | + if ($checkarrivee |
|
| 2260 | + and is_string($checkarrivee) |
|
| 2261 | + and $a = table_objet($checkarrivee) |
|
| 2262 | + and in_array($a . '_liens', $joints) |
|
| 2263 | + ) { |
|
| 2264 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2265 | + return $res; |
|
| 2266 | + } |
|
| 2267 | + } |
|
| 2268 | + foreach ($joints as $joint) { |
|
| 2269 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2270 | + // alias de table dans le from |
|
| 2271 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2272 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2273 | + $cols = $arrivee[2]; |
|
| 2274 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2275 | + if (count($cols) > 2) { |
|
| 2276 | + array_pop($cols); |
|
| 2277 | + } |
|
| 2278 | + if ($t) { |
|
| 2279 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2280 | + $joindre = false; |
|
| 2281 | + foreach ($cols as $col) { |
|
| 2282 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2283 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2284 | + $joindre = true; |
|
| 2285 | + } else { |
|
| 2286 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2287 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2288 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2289 | + $joindre = true; |
|
| 2290 | + } |
|
| 2291 | + } |
|
| 2292 | + } |
|
| 2293 | + if (!$joindre) { |
|
| 2294 | + return $t; |
|
| 2295 | + } |
|
| 2296 | + } |
|
| 2297 | + array_pop($arrivee); |
|
| 2298 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2299 | + return $res; |
|
| 2300 | + } |
|
| 2301 | + } |
|
| 2302 | + } |
|
| 2303 | + |
|
| 2304 | + return ''; |
|
| 2305 | 2305 | |
| 2306 | 2306 | } |
| 2307 | 2307 | |
@@ -2328,29 +2328,29 @@ discard block |
||
| 2328 | 2328 | * Alias de la table de jointure (Lx) |
| 2329 | 2329 | */ |
| 2330 | 2330 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2331 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2332 | - |
|
| 2333 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2334 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2335 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2336 | - |
|
| 2337 | - if (!$intermediaire or !$arrivee) { |
|
| 2338 | - return ''; |
|
| 2339 | - } |
|
| 2340 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2341 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2342 | - |
|
| 2343 | - $res = fabrique_jointures($boucle, |
|
| 2344 | - array( |
|
| 2345 | - array( |
|
| 2346 | - $boucle->id_table, |
|
| 2347 | - $intermediaire, |
|
| 2348 | - array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2349 | - ), |
|
| 2350 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2351 | - ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2352 | - |
|
| 2353 | - return $res; |
|
| 2331 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2332 | + |
|
| 2333 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2334 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2335 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2336 | + |
|
| 2337 | + if (!$intermediaire or !$arrivee) { |
|
| 2338 | + return ''; |
|
| 2339 | + } |
|
| 2340 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2341 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2342 | + |
|
| 2343 | + $res = fabrique_jointures($boucle, |
|
| 2344 | + array( |
|
| 2345 | + array( |
|
| 2346 | + $boucle->id_table, |
|
| 2347 | + $intermediaire, |
|
| 2348 | + array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2349 | + ), |
|
| 2350 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2351 | + ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2352 | + |
|
| 2353 | + return $res; |
|
| 2354 | 2354 | } |
| 2355 | 2355 | |
| 2356 | 2356 | |
@@ -2367,17 +2367,17 @@ discard block |
||
| 2367 | 2367 | * false sinon. |
| 2368 | 2368 | **/ |
| 2369 | 2369 | function trouver_champ($champ, $where) { |
| 2370 | - if (!is_array($where)) { |
|
| 2371 | - return preg_match($champ, $where); |
|
| 2372 | - } else { |
|
| 2373 | - foreach ($where as $clause) { |
|
| 2374 | - if (trouver_champ($champ, $clause)) { |
|
| 2375 | - return true; |
|
| 2376 | - } |
|
| 2377 | - } |
|
| 2378 | - |
|
| 2379 | - return false; |
|
| 2380 | - } |
|
| 2370 | + if (!is_array($where)) { |
|
| 2371 | + return preg_match($champ, $where); |
|
| 2372 | + } else { |
|
| 2373 | + foreach ($where as $clause) { |
|
| 2374 | + if (trouver_champ($champ, $clause)) { |
|
| 2375 | + return true; |
|
| 2376 | + } |
|
| 2377 | + } |
|
| 2378 | + |
|
| 2379 | + return false; |
|
| 2380 | + } |
|
| 2381 | 2381 | } |
| 2382 | 2382 | |
| 2383 | 2383 | |
@@ -2403,129 +2403,129 @@ discard block |
||
| 2403 | 2403 | * - string $args_sql Suite des arguments du critère. ? |
| 2404 | 2404 | **/ |
| 2405 | 2405 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2406 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2407 | - if (count($crit->param) == 0) { |
|
| 2408 | - $op = '='; |
|
| 2409 | - $col = $val = $crit->op; |
|
| 2410 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2411 | - $val = $r[2]; |
|
| 2412 | - } |
|
| 2413 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2414 | - if ($val == 'lang') { |
|
| 2415 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2416 | - } else { |
|
| 2417 | - $defaut = null; |
|
| 2418 | - if ($val == 'id_parent') { |
|
| 2419 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2420 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2421 | - // pour eviter l'erreur SQL |
|
| 2422 | - $val = $boucles[$idb]->primary; |
|
| 2423 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2424 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2425 | - } elseif ($val == 'id_enfant') { |
|
| 2426 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2427 | - // de la boucle superieure |
|
| 2428 | - $val = 'id_parent'; |
|
| 2429 | - } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2430 | - // un critere conditionnel sur date est traite a part |
|
| 2431 | - // car la date est mise d'office par SPIP, |
|
| 2432 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2433 | - } |
|
| 2434 | - |
|
| 2435 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2436 | - $val = array(kwote($val)); |
|
| 2437 | - } |
|
| 2438 | - } else { |
|
| 2439 | - // comparaison explicite |
|
| 2440 | - // le phraseur impose que le premier param soit du texte |
|
| 2441 | - $params = $crit->param; |
|
| 2442 | - $op = $crit->op; |
|
| 2443 | - if ($op == '==') { |
|
| 2444 | - $op = 'REGEXP'; |
|
| 2445 | - } |
|
| 2446 | - $col = array_shift($params); |
|
| 2447 | - $col = $col[0]->texte; |
|
| 2448 | - |
|
| 2449 | - $val = array(); |
|
| 2450 | - $desc = array('id_mere' => $idb); |
|
| 2451 | - $parent = $boucles[$idb]->id_parent; |
|
| 2452 | - |
|
| 2453 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2454 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2455 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2456 | - if (count($params) == 1 |
|
| 2457 | - and count($params[0]) == 3 |
|
| 2458 | - and $params[0][0]->type == 'texte' |
|
| 2459 | - and $params[0][2]->type == 'texte' |
|
| 2460 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2461 | - and (($p == "'") or ($p == '"')) |
|
| 2462 | - and $params[0][1]->type == 'champ' |
|
| 2463 | - ) { |
|
| 2464 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2465 | - } else { |
|
| 2466 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2467 | - $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2468 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2469 | - $val[] = $a; |
|
| 2470 | - } else { |
|
| 2471 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2472 | - } // toujours quoter en char ici |
|
| 2473 | - } |
|
| 2474 | - } |
|
| 2475 | - } |
|
| 2476 | - |
|
| 2477 | - $fct = $args_sql = ''; |
|
| 2478 | - // fonction SQL ? |
|
| 2479 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2480 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2481 | - $fct = $m[1]; |
|
| 2482 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2483 | - $col = $a[1]; |
|
| 2484 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2485 | - $col = $m[1]; |
|
| 2486 | - $args_sql = $m[2]; |
|
| 2487 | - } |
|
| 2488 | - $args_sql .= $a[2]; |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 2406 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2407 | + if (count($crit->param) == 0) { |
|
| 2408 | + $op = '='; |
|
| 2409 | + $col = $val = $crit->op; |
|
| 2410 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2411 | + $val = $r[2]; |
|
| 2412 | + } |
|
| 2413 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2414 | + if ($val == 'lang') { |
|
| 2415 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2416 | + } else { |
|
| 2417 | + $defaut = null; |
|
| 2418 | + if ($val == 'id_parent') { |
|
| 2419 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2420 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2421 | + // pour eviter l'erreur SQL |
|
| 2422 | + $val = $boucles[$idb]->primary; |
|
| 2423 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2424 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2425 | + } elseif ($val == 'id_enfant') { |
|
| 2426 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2427 | + // de la boucle superieure |
|
| 2428 | + $val = 'id_parent'; |
|
| 2429 | + } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2430 | + // un critere conditionnel sur date est traite a part |
|
| 2431 | + // car la date est mise d'office par SPIP, |
|
| 2432 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2433 | + } |
|
| 2434 | + |
|
| 2435 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2436 | + $val = array(kwote($val)); |
|
| 2437 | + } |
|
| 2438 | + } else { |
|
| 2439 | + // comparaison explicite |
|
| 2440 | + // le phraseur impose que le premier param soit du texte |
|
| 2441 | + $params = $crit->param; |
|
| 2442 | + $op = $crit->op; |
|
| 2443 | + if ($op == '==') { |
|
| 2444 | + $op = 'REGEXP'; |
|
| 2445 | + } |
|
| 2446 | + $col = array_shift($params); |
|
| 2447 | + $col = $col[0]->texte; |
|
| 2448 | + |
|
| 2449 | + $val = array(); |
|
| 2450 | + $desc = array('id_mere' => $idb); |
|
| 2451 | + $parent = $boucles[$idb]->id_parent; |
|
| 2452 | + |
|
| 2453 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2454 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2455 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2456 | + if (count($params) == 1 |
|
| 2457 | + and count($params[0]) == 3 |
|
| 2458 | + and $params[0][0]->type == 'texte' |
|
| 2459 | + and $params[0][2]->type == 'texte' |
|
| 2460 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2461 | + and (($p == "'") or ($p == '"')) |
|
| 2462 | + and $params[0][1]->type == 'champ' |
|
| 2463 | + ) { |
|
| 2464 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2465 | + } else { |
|
| 2466 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2467 | + $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2468 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2469 | + $val[] = $a; |
|
| 2470 | + } else { |
|
| 2471 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2472 | + } // toujours quoter en char ici |
|
| 2473 | + } |
|
| 2474 | + } |
|
| 2475 | + } |
|
| 2476 | + |
|
| 2477 | + $fct = $args_sql = ''; |
|
| 2478 | + // fonction SQL ? |
|
| 2479 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2480 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2481 | + $fct = $m[1]; |
|
| 2482 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2483 | + $col = $a[1]; |
|
| 2484 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2485 | + $col = $m[1]; |
|
| 2486 | + $args_sql = $m[2]; |
|
| 2487 | + } |
|
| 2488 | + $args_sql .= $a[2]; |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 2492 | 2492 | } |
| 2493 | 2493 | |
| 2494 | 2494 | // compatibilite ancienne version |
| 2495 | 2495 | |
| 2496 | 2496 | // http://code.spip.net/@calculer_vieux_in |
| 2497 | 2497 | function calculer_vieux_in($params) { |
| 2498 | - $deb = $params[0][0]; |
|
| 2499 | - $k = count($params) - 1; |
|
| 2500 | - $last = $params[$k]; |
|
| 2501 | - $j = count($last) - 1; |
|
| 2502 | - $last = $last[$j]; |
|
| 2503 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2504 | - |
|
| 2505 | - if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2506 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2507 | - ) { |
|
| 2508 | - return $params; |
|
| 2509 | - } |
|
| 2510 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2511 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2512 | - $last = $params[$k][$j]; |
|
| 2513 | - $n = strlen($last->texte); |
|
| 2514 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2515 | - $newp = array(); |
|
| 2516 | - foreach ($params as $v) { |
|
| 2517 | - if ($v[0]->type != 'texte') { |
|
| 2518 | - $newp[] = $v; |
|
| 2519 | - } else { |
|
| 2520 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2521 | - $t = new Texte; |
|
| 2522 | - $t->texte = $x; |
|
| 2523 | - $newp[] = array($t); |
|
| 2524 | - } |
|
| 2525 | - } |
|
| 2526 | - } |
|
| 2527 | - |
|
| 2528 | - return $newp; |
|
| 2498 | + $deb = $params[0][0]; |
|
| 2499 | + $k = count($params) - 1; |
|
| 2500 | + $last = $params[$k]; |
|
| 2501 | + $j = count($last) - 1; |
|
| 2502 | + $last = $last[$j]; |
|
| 2503 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2504 | + |
|
| 2505 | + if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2506 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2507 | + ) { |
|
| 2508 | + return $params; |
|
| 2509 | + } |
|
| 2510 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2511 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2512 | + $last = $params[$k][$j]; |
|
| 2513 | + $n = strlen($last->texte); |
|
| 2514 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2515 | + $newp = array(); |
|
| 2516 | + foreach ($params as $v) { |
|
| 2517 | + if ($v[0]->type != 'texte') { |
|
| 2518 | + $newp[] = $v; |
|
| 2519 | + } else { |
|
| 2520 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2521 | + $t = new Texte; |
|
| 2522 | + $t->texte = $x; |
|
| 2523 | + $newp[] = array($t); |
|
| 2524 | + } |
|
| 2525 | + } |
|
| 2526 | + } |
|
| 2527 | + |
|
| 2528 | + return $newp; |
|
| 2529 | 2529 | } |
| 2530 | 2530 | |
| 2531 | 2531 | /** |
@@ -2544,89 +2544,89 @@ discard block |
||
| 2544 | 2544 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2545 | 2545 | **/ |
| 2546 | 2546 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2547 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2548 | - return ''; |
|
| 2549 | - } |
|
| 2550 | - |
|
| 2551 | - $boucle = $boucles[$idb]; |
|
| 2552 | - $table = $boucle->show; |
|
| 2553 | - |
|
| 2554 | - // si c'est une colonne de la table, ne rien faire |
|
| 2555 | - if (isset($table['field'][$col])) { |
|
| 2556 | - return ''; |
|
| 2557 | - } |
|
| 2558 | - |
|
| 2559 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2560 | - return ''; |
|
| 2561 | - } |
|
| 2562 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2563 | - |
|
| 2564 | - $col = $regs[1]; |
|
| 2565 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2566 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2567 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2568 | - |
|
| 2569 | - if (isset($table['field']["date$suite"])) { |
|
| 2570 | - $date_orig = 'date' . $suite; |
|
| 2571 | - } else { |
|
| 2572 | - $date_orig = substr($suite, 1); |
|
| 2573 | - } |
|
| 2574 | - $pred = $date_orig; |
|
| 2575 | - } else { |
|
| 2576 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2577 | - $pred = 'date'; |
|
| 2578 | - } |
|
| 2579 | - } |
|
| 2580 | - |
|
| 2581 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2582 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2583 | - ") . '\""; |
|
| 2584 | - |
|
| 2585 | - $col_vraie = $date_orig; |
|
| 2586 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2587 | - |
|
| 2588 | - switch ($col) { |
|
| 2589 | - case 'date': |
|
| 2590 | - $col = $date_orig; |
|
| 2591 | - break; |
|
| 2592 | - case 'jour': |
|
| 2593 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2594 | - break; |
|
| 2595 | - case 'mois': |
|
| 2596 | - $col = "MONTH($date_orig)"; |
|
| 2597 | - break; |
|
| 2598 | - case 'annee': |
|
| 2599 | - $col = "YEAR($date_orig)"; |
|
| 2600 | - break; |
|
| 2601 | - case 'heure': |
|
| 2602 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2603 | - break; |
|
| 2604 | - case 'age': |
|
| 2605 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 2606 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2607 | - break; |
|
| 2608 | - case 'age_relatif': |
|
| 2609 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2610 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2611 | - break; |
|
| 2612 | - case 'jour_relatif': |
|
| 2613 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2614 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2615 | - break; |
|
| 2616 | - case 'mois_relatif': |
|
| 2617 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2618 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2619 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2620 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2621 | - break; |
|
| 2622 | - case 'annee_relatif': |
|
| 2623 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2624 | - $date_orig . ")"; |
|
| 2625 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2626 | - break; |
|
| 2627 | - } |
|
| 2628 | - |
|
| 2629 | - return array($col, $col_vraie); |
|
| 2547 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2548 | + return ''; |
|
| 2549 | + } |
|
| 2550 | + |
|
| 2551 | + $boucle = $boucles[$idb]; |
|
| 2552 | + $table = $boucle->show; |
|
| 2553 | + |
|
| 2554 | + // si c'est une colonne de la table, ne rien faire |
|
| 2555 | + if (isset($table['field'][$col])) { |
|
| 2556 | + return ''; |
|
| 2557 | + } |
|
| 2558 | + |
|
| 2559 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2560 | + return ''; |
|
| 2561 | + } |
|
| 2562 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2563 | + |
|
| 2564 | + $col = $regs[1]; |
|
| 2565 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2566 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2567 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2568 | + |
|
| 2569 | + if (isset($table['field']["date$suite"])) { |
|
| 2570 | + $date_orig = 'date' . $suite; |
|
| 2571 | + } else { |
|
| 2572 | + $date_orig = substr($suite, 1); |
|
| 2573 | + } |
|
| 2574 | + $pred = $date_orig; |
|
| 2575 | + } else { |
|
| 2576 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2577 | + $pred = 'date'; |
|
| 2578 | + } |
|
| 2579 | + } |
|
| 2580 | + |
|
| 2581 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2582 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2583 | + ") . '\""; |
|
| 2584 | + |
|
| 2585 | + $col_vraie = $date_orig; |
|
| 2586 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2587 | + |
|
| 2588 | + switch ($col) { |
|
| 2589 | + case 'date': |
|
| 2590 | + $col = $date_orig; |
|
| 2591 | + break; |
|
| 2592 | + case 'jour': |
|
| 2593 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2594 | + break; |
|
| 2595 | + case 'mois': |
|
| 2596 | + $col = "MONTH($date_orig)"; |
|
| 2597 | + break; |
|
| 2598 | + case 'annee': |
|
| 2599 | + $col = "YEAR($date_orig)"; |
|
| 2600 | + break; |
|
| 2601 | + case 'heure': |
|
| 2602 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2603 | + break; |
|
| 2604 | + case 'age': |
|
| 2605 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 2606 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2607 | + break; |
|
| 2608 | + case 'age_relatif': |
|
| 2609 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2610 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2611 | + break; |
|
| 2612 | + case 'jour_relatif': |
|
| 2613 | + $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2614 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2615 | + break; |
|
| 2616 | + case 'mois_relatif': |
|
| 2617 | + $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2618 | + $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2619 | + ")-YEAR(" . $date_orig . "))"; |
|
| 2620 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2621 | + break; |
|
| 2622 | + case 'annee_relatif': |
|
| 2623 | + $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2624 | + $date_orig . ")"; |
|
| 2625 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2626 | + break; |
|
| 2627 | + } |
|
| 2628 | + |
|
| 2629 | + return array($col, $col_vraie); |
|
| 2630 | 2630 | } |
| 2631 | 2631 | |
| 2632 | 2632 | /** |
@@ -2645,16 +2645,16 @@ discard block |
||
| 2645 | 2645 | * de colonne SQL et une date. |
| 2646 | 2646 | **/ |
| 2647 | 2647 | function calculer_param_date($date_compare, $date_orig) { |
| 2648 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2649 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2650 | - $date_compare = '\'$x\''; |
|
| 2651 | - } else { |
|
| 2652 | - $init = $date_compare; |
|
| 2653 | - } |
|
| 2654 | - |
|
| 2655 | - return |
|
| 2656 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2657 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2648 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2649 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2650 | + $date_compare = '\'$x\''; |
|
| 2651 | + } else { |
|
| 2652 | + $init = $date_compare; |
|
| 2653 | + } |
|
| 2654 | + |
|
| 2655 | + return |
|
| 2656 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2657 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2658 | 2658 | } |
| 2659 | 2659 | |
| 2660 | 2660 | /** |
@@ -2672,18 +2672,18 @@ discard block |
||
| 2672 | 2672 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2673 | 2673 | */ |
| 2674 | 2674 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2675 | - $boucle = &$boucles[$idb]; |
|
| 2675 | + $boucle = &$boucles[$idb]; |
|
| 2676 | 2676 | |
| 2677 | - $args = array(); |
|
| 2678 | - foreach ($crit->param as &$param) { |
|
| 2679 | - array_push($args, |
|
| 2680 | - calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2681 | - } |
|
| 2677 | + $args = array(); |
|
| 2678 | + foreach ($crit->param as &$param) { |
|
| 2679 | + array_push($args, |
|
| 2680 | + calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2681 | + } |
|
| 2682 | 2682 | |
| 2683 | - $boucle->hash .= ' |
|
| 2683 | + $boucle->hash .= ' |
|
| 2684 | 2684 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2685 | 2685 | |
| 2686 | - $boucle->hash .= ' |
|
| 2686 | + $boucle->hash .= ' |
|
| 2687 | 2687 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2688 | 2688 | } |
| 2689 | 2689 | |
@@ -2700,8 +2700,8 @@ discard block |
||
| 2700 | 2700 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2701 | 2701 | */ |
| 2702 | 2702 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2703 | - $boucle = &$boucles[$idb]; |
|
| 2704 | - $boucle->hash .= ' |
|
| 2703 | + $boucle = &$boucles[$idb]; |
|
| 2704 | + $boucle->hash .= ' |
|
| 2705 | 2705 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2706 | 2706 | $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2707 | 2707 | } |
@@ -2721,8 +2721,8 @@ discard block |
||
| 2721 | 2721 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2722 | 2722 | */ |
| 2723 | 2723 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2724 | - $boucle = &$boucles[$idb]; |
|
| 2725 | - $boucle->hash .= ' |
|
| 2724 | + $boucle = &$boucles[$idb]; |
|
| 2725 | + $boucle->hash .= ' |
|
| 2726 | 2726 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2727 | 2727 | } |
| 2728 | 2728 | |
@@ -2738,12 +2738,12 @@ discard block |
||
| 2738 | 2738 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2739 | 2739 | */ |
| 2740 | 2740 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2741 | - $boucle = &$boucles[$idb]; |
|
| 2742 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2743 | - foreach ($crit->param as $param) { |
|
| 2744 | - $boucle->hash .= ' |
|
| 2741 | + $boucle = &$boucles[$idb]; |
|
| 2742 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2743 | + foreach ($crit->param as $param) { |
|
| 2744 | + $boucle->hash .= ' |
|
| 2745 | 2745 | $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2746 | - } |
|
| 2746 | + } |
|
| 2747 | 2747 | } |
| 2748 | 2748 | |
| 2749 | 2749 | /** |
@@ -2760,12 +2760,12 @@ discard block |
||
| 2760 | 2760 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2761 | 2761 | */ |
| 2762 | 2762 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2763 | - $boucle = &$boucles[$idb]; |
|
| 2764 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2765 | - foreach ($crit->param as $param) { |
|
| 2766 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2767 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2768 | - } |
|
| 2763 | + $boucle = &$boucles[$idb]; |
|
| 2764 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2765 | + foreach ($crit->param as $param) { |
|
| 2766 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2767 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2768 | + } |
|
| 2769 | 2769 | } |
| 2770 | 2770 | |
| 2771 | 2771 | /** |
@@ -2790,12 +2790,12 @@ discard block |
||
| 2790 | 2790 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2791 | 2791 | */ |
| 2792 | 2792 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2793 | - $boucle = &$boucles[$idb]; |
|
| 2794 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2795 | - foreach ($crit->param as $param) { |
|
| 2796 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2797 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2798 | - } |
|
| 2793 | + $boucle = &$boucles[$idb]; |
|
| 2794 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2795 | + foreach ($crit->param as $param) { |
|
| 2796 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2797 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2798 | + } |
|
| 2799 | 2799 | } |
| 2800 | 2800 | |
| 2801 | 2801 | /** |
@@ -2810,11 +2810,11 @@ discard block |
||
| 2810 | 2810 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2811 | 2811 | */ |
| 2812 | 2812 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2813 | - $boucle = &$boucles[$idb]; |
|
| 2814 | - foreach ($crit->param as $param) { |
|
| 2815 | - $boucle->hash .= ' |
|
| 2813 | + $boucle = &$boucles[$idb]; |
|
| 2814 | + foreach ($crit->param as $param) { |
|
| 2815 | + $boucle->hash .= ' |
|
| 2816 | 2816 | $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2817 | - } |
|
| 2817 | + } |
|
| 2818 | 2818 | } |
| 2819 | 2819 | |
| 2820 | 2820 | |
@@ -2846,20 +2846,20 @@ discard block |
||
| 2846 | 2846 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2847 | 2847 | */ |
| 2848 | 2848 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2849 | - $boucle = &$boucles[$idb]; |
|
| 2850 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2851 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2852 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2853 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2854 | - if ($crit->param) { |
|
| 2855 | - foreach ($crit->param as $param) { |
|
| 2856 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2857 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2858 | - } |
|
| 2859 | - // interdire {si 0} aussi ! |
|
| 2860 | - } else { |
|
| 2861 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2862 | - } |
|
| 2849 | + $boucle = &$boucles[$idb]; |
|
| 2850 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2851 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2852 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2853 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2854 | + if ($crit->param) { |
|
| 2855 | + foreach ($crit->param as $param) { |
|
| 2856 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2857 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2858 | + } |
|
| 2859 | + // interdire {si 0} aussi ! |
|
| 2860 | + } else { |
|
| 2861 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2862 | + } |
|
| 2863 | 2863 | } |
| 2864 | 2864 | |
| 2865 | 2865 | /** |
@@ -2875,8 +2875,8 @@ discard block |
||
| 2875 | 2875 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2876 | 2876 | */ |
| 2877 | 2877 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2878 | - $boucle = &$boucles[$idb]; |
|
| 2879 | - $boucle->hash .= ' |
|
| 2878 | + $boucle = &$boucles[$idb]; |
|
| 2879 | + $boucle->hash .= ' |
|
| 2880 | 2880 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2881 | 2881 | $command[\'sourcemode\'] = \'table\';'; |
| 2882 | 2882 | } |
@@ -2897,29 +2897,29 @@ discard block |
||
| 2897 | 2897 | */ |
| 2898 | 2898 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2899 | 2899 | |
| 2900 | - $not = $crit->not; |
|
| 2901 | - $boucle = &$boucles[$idb]; |
|
| 2902 | - $primary = $boucle->primary; |
|
| 2900 | + $not = $crit->not; |
|
| 2901 | + $boucle = &$boucles[$idb]; |
|
| 2902 | + $primary = $boucle->primary; |
|
| 2903 | 2903 | |
| 2904 | - if (!$primary or strpos($primary, ',')) { |
|
| 2905 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2904 | + if (!$primary or strpos($primary, ',')) { |
|
| 2905 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2906 | 2906 | |
| 2907 | - return; |
|
| 2908 | - } |
|
| 2909 | - $table = $boucle->type_requete; |
|
| 2910 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2907 | + return; |
|
| 2908 | + } |
|
| 2909 | + $table = $boucle->type_requete; |
|
| 2910 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2911 | 2911 | |
| 2912 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2913 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2914 | - 'id_parent'; |
|
| 2912 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2913 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2914 | + 'id_parent'; |
|
| 2915 | 2915 | |
| 2916 | - $in = "IN"; |
|
| 2917 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2918 | - if ($not) { |
|
| 2919 | - $where = array("'NOT'", $where); |
|
| 2920 | - } |
|
| 2916 | + $in = "IN"; |
|
| 2917 | + $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2918 | + if ($not) { |
|
| 2919 | + $where = array("'NOT'", $where); |
|
| 2920 | + } |
|
| 2921 | 2921 | |
| 2922 | - $boucle->where[] = $where; |
|
| 2922 | + $boucle->where[] = $where; |
|
| 2923 | 2923 | } |
| 2924 | 2924 | |
| 2925 | 2925 | /** |
@@ -2935,8 +2935,8 @@ discard block |
||
| 2935 | 2935 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2936 | 2936 | */ |
| 2937 | 2937 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2938 | - $not = $crit->not; |
|
| 2939 | - $crit->not = $not ? false : true; |
|
| 2940 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2941 | - $crit->not = $not; |
|
| 2938 | + $not = $crit->not; |
|
| 2939 | + $crit->not = $not ? false : true; |
|
| 2940 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2941 | + $crit->not = $not; |
|
| 2942 | 2942 | } |
@@ -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], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + $nom .= ".".calculer_liste($crit->param[0], array(), $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]), array(), $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 | /** |
@@ -543,9 +540,9 @@ discard block |
||
| 543 | 540 | $not = $crit->not; |
| 544 | 541 | $boucle = &$boucles[$idb]; |
| 545 | 542 | |
| 546 | - $c = "sql_in('" . |
|
| 547 | - $boucle->id_table . '.' . $boucle->primary |
|
| 548 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '')"; |
|
| 543 | + $c = "sql_in('". |
|
| 544 | + $boucle->id_table.'.'.$boucle->primary |
|
| 545 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '')"; |
|
| 549 | 546 | |
| 550 | 547 | if ($crit->cond) { |
| 551 | 548 | $c = "($arg ? $c : 1)"; |
@@ -585,7 +582,7 @@ discard block |
||
| 585 | 582 | $t = table_objet_sql($r[1]); |
| 586 | 583 | $t = array_search($t, $boucles[$idb]->from); |
| 587 | 584 | if ($t) { |
| 588 | - $t .= '.' . $r[2]; |
|
| 585 | + $t .= '.'.$r[2]; |
|
| 589 | 586 | } |
| 590 | 587 | } |
| 591 | 588 | } else { |
@@ -600,7 +597,7 @@ discard block |
||
| 600 | 597 | $boucles[$idb]->select[] = $t; |
| 601 | 598 | } |
| 602 | 599 | } else { |
| 603 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 600 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 604 | 601 | } |
| 605 | 602 | } |
| 606 | 603 | |
@@ -650,26 +647,26 @@ discard block |
||
| 650 | 647 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 651 | 648 | OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 652 | 649 | ) { |
| 653 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 650 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 654 | 651 | } else { |
| 655 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 652 | + $boucle->order[$n - 1] .= " . ".$boucle->modificateur['collate']; |
|
| 656 | 653 | } |
| 657 | 654 | } |
| 658 | 655 | } else { |
| 659 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 656 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 660 | 657 | } |
| 661 | 658 | } |
| 662 | 659 | |
| 663 | 660 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 664 | 661 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 665 | 662 | $boucle = $boucles[$idb]; |
| 666 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 667 | - $var = '$champs_' . $idb; |
|
| 663 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 664 | + $var = '$champs_'.$idb; |
|
| 668 | 665 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 669 | 666 | if (!$desc) { |
| 670 | 667 | $desc = $boucle->show['field']; |
| 671 | 668 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 672 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 669 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 673 | 670 | } |
| 674 | 671 | if ($desc) { |
| 675 | 672 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -744,7 +741,7 @@ discard block |
||
| 744 | 741 | $sens = " . ' DESC'"; |
| 745 | 742 | } |
| 746 | 743 | if (isset($boucle->modificateur['collate'])) { |
| 747 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 744 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 748 | 745 | } |
| 749 | 746 | |
| 750 | 747 | // Pour chaque paramètre du critère |
@@ -766,14 +763,14 @@ discard block |
||
| 766 | 763 | if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
| 767 | 764 | $expression = trim($m[1]); |
| 768 | 765 | $champ = trim($m[2]); |
| 769 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 766 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 770 | 767 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 771 | 768 | } else { |
| 772 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 769 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 773 | 770 | } |
| 774 | 771 | |
| 775 | 772 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 776 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 773 | + } elseif (preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 777 | 774 | // {par FONCTION(champ)} |
| 778 | 775 | if (count($match) > 2) { |
| 779 | 776 | $par = substr($match[2], 1, -1); |
@@ -783,7 +780,7 @@ discard block |
||
| 783 | 780 | if ($par == 'hasard') { |
| 784 | 781 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 785 | 782 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 786 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 783 | + $order = "'".$boucle->id_table.".".$boucle->show['date']."'"; |
|
| 787 | 784 | } else { |
| 788 | 785 | // cas général {par champ}, {par table.champ}, ... |
| 789 | 786 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -792,7 +789,7 @@ discard block |
||
| 792 | 789 | |
| 793 | 790 | // on ne sait pas traiter… |
| 794 | 791 | else { |
| 795 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 792 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 796 | 793 | } |
| 797 | 794 | |
| 798 | 795 | // En cas d'erreur de squelette retournée par une fonction |
@@ -812,14 +809,14 @@ discard block |
||
| 812 | 809 | |
| 813 | 810 | if ($fct) { |
| 814 | 811 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 815 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 812 | + $order = "'$fct(".$r[1].")'"; |
|
| 816 | 813 | } else { |
| 817 | 814 | $order = "'$fct(' . $order . ')'"; |
| 818 | 815 | } |
| 819 | 816 | } |
| 820 | - $t = $order . $collecte . $sens; |
|
| 817 | + $t = $order.$collecte.$sens; |
|
| 821 | 818 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 822 | - $t = $r[1] . $r[2]; |
|
| 819 | + $t = $r[1].$r[2]; |
|
| 823 | 820 | } |
| 824 | 821 | |
| 825 | 822 | $boucle->order[] = $t; |
@@ -869,16 +866,16 @@ discard block |
||
| 869 | 866 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 870 | 867 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 871 | 868 | if (is_array($_champ)) { |
| 872 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 869 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." num $champ")); |
|
| 873 | 870 | } |
| 874 | 871 | $boucle = &$boucles[$idb]; |
| 875 | - $texte = '0+' . $_champ; |
|
| 872 | + $texte = '0+'.$_champ; |
|
| 876 | 873 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 877 | 874 | if ($suite !== "''") { |
| 878 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 875 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 879 | 876 | } |
| 880 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 881 | - $boucle->select[] = $texte . " AS $as"; |
|
| 877 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 878 | + $boucle->select[] = $texte." AS $as"; |
|
| 882 | 879 | $order = "'$as'"; |
| 883 | 880 | return $order; |
| 884 | 881 | } |
@@ -903,16 +900,16 @@ discard block |
||
| 903 | 900 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 904 | 901 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 905 | 902 | if (is_array($_champ)) { |
| 906 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 903 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." sinum $champ")); |
|
| 907 | 904 | } |
| 908 | 905 | $boucle = &$boucles[$idb]; |
| 909 | - $texte = '0+' . $_champ; |
|
| 906 | + $texte = '0+'.$_champ; |
|
| 910 | 907 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 911 | 908 | if ($suite !== "''") { |
| 912 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 909 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 913 | 910 | } |
| 914 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 915 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 911 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ""); |
|
| 912 | + $boucle->select[] = 'CASE ('.$texte.') WHEN 0 THEN 1 ELSE 0 END AS '.$as; |
|
| 916 | 913 | $order = "'$as'"; |
| 917 | 914 | return $order; |
| 918 | 915 | } |
@@ -936,10 +933,10 @@ discard block |
||
| 936 | 933 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 937 | 934 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 938 | 935 | if (is_array($_champ)) { |
| 939 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 936 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." multi $champ")); |
|
| 940 | 937 | } |
| 941 | 938 | $boucle = &$boucles[$idb]; |
| 942 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 939 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 943 | 940 | $order = "'multi'"; |
| 944 | 941 | return $order; |
| 945 | 942 | } |
@@ -959,13 +956,13 @@ discard block |
||
| 959 | 956 | * @param bool $raw Retourne le champ pour le compilateur ("'alias.champ'") ou brut ('alias.champ') |
| 960 | 957 | * @return array|string |
| 961 | 958 | */ |
| 962 | -function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 959 | +function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 963 | 960 | $boucle = &$boucles[$idb]; |
| 964 | 961 | $desc = $boucle->show; |
| 965 | 962 | |
| 966 | 963 | // le champ existe dans la table, pas de souci (le plus commun) |
| 967 | 964 | if (isset($desc['field'][$par])) { |
| 968 | - $par = $boucle->id_table . "." . $par; |
|
| 965 | + $par = $boucle->id_table.".".$par; |
|
| 969 | 966 | } |
| 970 | 967 | // le champ est peut être une jointure |
| 971 | 968 | else { |
@@ -986,24 +983,24 @@ discard block |
||
| 986 | 983 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 987 | 984 | // Si la table est déjà dans le from, on la réutilise. |
| 988 | 985 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 989 | - $par = $infos['alias'] . "." . $champ; |
|
| 986 | + $par = $infos['alias'].".".$champ; |
|
| 990 | 987 | } elseif ( |
| 991 | 988 | $boucle->jointures_explicites |
| 992 | 989 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 993 | 990 | ) { |
| 994 | - $par = $alias . "." . $champ; |
|
| 991 | + $par = $alias.".".$champ; |
|
| 995 | 992 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 996 | - $par = $alias . "." . $champ; |
|
| 993 | + $par = $alias.".".$champ; |
|
| 997 | 994 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 998 | 995 | } elseif ( |
| 999 | 996 | $table_alias |
| 1000 | 997 | and isset($boucle->from[$table_alias]) |
| 1001 | 998 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 1002 | 999 | ) { |
| 1003 | - $par = $infos['alias'] . "." . $champ; |
|
| 1000 | + $par = $infos['alias'].".".$champ; |
|
| 1004 | 1001 | } elseif ($table) { |
| 1005 | 1002 | // On avait table + champ, mais on ne les a pas trouvés |
| 1006 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1003 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 1007 | 1004 | } else { |
| 1008 | 1005 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1009 | 1006 | } |
@@ -1027,7 +1024,7 @@ discard block |
||
| 1027 | 1024 | if (!$t) { |
| 1028 | 1025 | $t = trouver_jointure_champ($champ, $boucle); |
| 1029 | 1026 | } |
| 1030 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1027 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1031 | 1028 | } |
| 1032 | 1029 | |
| 1033 | 1030 | /** |
@@ -1072,9 +1069,9 @@ discard block |
||
| 1072 | 1069 | $boucle->default_order[] = ' DESC'; |
| 1073 | 1070 | } |
| 1074 | 1071 | } else { |
| 1075 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1072 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1076 | 1073 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1077 | - $t = $r[1] . $r[2]; |
|
| 1074 | + $t = $r[1].$r[2]; |
|
| 1078 | 1075 | } |
| 1079 | 1076 | $boucle->order[$n - 1] = $t; |
| 1080 | 1077 | } |
@@ -1086,7 +1083,7 @@ discard block |
||
| 1086 | 1083 | $params = $crit->param; |
| 1087 | 1084 | |
| 1088 | 1085 | if (count($params) < 1) { |
| 1089 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1086 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ?")); |
|
| 1090 | 1087 | } |
| 1091 | 1088 | |
| 1092 | 1089 | $boucle = &$boucles[$idb]; |
@@ -1107,7 +1104,7 @@ discard block |
||
| 1107 | 1104 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1108 | 1105 | $date = $date[0]->texte; |
| 1109 | 1106 | if (!isset($fields[$date])) { |
| 1110 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1107 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ".$date)); |
|
| 1111 | 1108 | } |
| 1112 | 1109 | } else { |
| 1113 | 1110 | $a = calculer_liste($date, array(), $boucles, $parent); |
@@ -1119,38 +1116,38 @@ discard block |
||
| 1119 | 1116 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1120 | 1117 | } |
| 1121 | 1118 | $annee = $params ? array_shift($params) : ""; |
| 1122 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1123 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1119 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1120 | + calculer_liste($annee, array(), $boucles, $parent). |
|
| 1124 | 1121 | ') ? $x : date("Y"))'; |
| 1125 | 1122 | |
| 1126 | 1123 | $mois = $params ? array_shift($params) : ""; |
| 1127 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1128 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1124 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1125 | + calculer_liste($mois, array(), $boucles, $parent). |
|
| 1129 | 1126 | ') ? $x : date("m"))'; |
| 1130 | 1127 | |
| 1131 | 1128 | $jour = $params ? array_shift($params) : ""; |
| 1132 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1133 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1129 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1130 | + calculer_liste($jour, array(), $boucles, $parent). |
|
| 1134 | 1131 | ') ? $x : date("d"))'; |
| 1135 | 1132 | |
| 1136 | 1133 | $annee2 = $params ? array_shift($params) : ""; |
| 1137 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1138 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1134 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1135 | + calculer_liste($annee2, array(), $boucles, $parent). |
|
| 1139 | 1136 | ') ? $x : date("Y"))'; |
| 1140 | 1137 | |
| 1141 | 1138 | $mois2 = $params ? array_shift($params) : ""; |
| 1142 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1143 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1139 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1140 | + calculer_liste($mois2, array(), $boucles, $parent). |
|
| 1144 | 1141 | ') ? $x : date("m"))'; |
| 1145 | 1142 | |
| 1146 | 1143 | $jour2 = $params ? array_shift($params) : ""; |
| 1147 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1148 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1144 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1145 | + calculer_liste($jour2, array(), $boucles, $parent). |
|
| 1149 | 1146 | ') ? $x : date("d"))'; |
| 1150 | 1147 | |
| 1151 | - $date = $boucle->id_table . ".$date"; |
|
| 1148 | + $date = $boucle->id_table.".$date"; |
|
| 1152 | 1149 | |
| 1153 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1150 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1154 | 1151 | if ($type == 'jour') { |
| 1155 | 1152 | $boucle->where[] = array( |
| 1156 | 1153 | "'='", |
@@ -1222,14 +1219,13 @@ discard block |
||
| 1222 | 1219 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1223 | 1220 | |
| 1224 | 1221 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1225 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1222 | + $boucle->limit = $a11.','.$a21; |
|
| 1226 | 1223 | } else { |
| 1227 | 1224 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1228 | 1225 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1229 | 1226 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1230 | 1227 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1231 | - $mode = (($op == '/') ? '/' : |
|
| 1232 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1228 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1233 | 1229 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1234 | 1230 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
| 1235 | 1231 | $boucle->limit = |
@@ -1275,8 +1271,7 @@ discard block |
||
| 1275 | 1271 | // {1/3} |
| 1276 | 1272 | if ($op1 == '/') { |
| 1277 | 1273 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1278 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1279 | - "($total_parties ? $total_parties : 1)"; |
|
| 1274 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1280 | 1275 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1281 | 1276 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1282 | 1277 | } else { |
@@ -1287,15 +1282,13 @@ discard block |
||
| 1287 | 1282 | |
| 1288 | 1283 | // cas {x,n-1} |
| 1289 | 1284 | if ($op2 == '-') { |
| 1290 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1291 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1292 | - ($total_parties . ' - 1')); |
|
| 1285 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1286 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1293 | 1287 | } else { |
| 1294 | 1288 | // {x,1} ou {pagination} |
| 1295 | 1289 | $fin = '$debut_boucle' |
| 1296 | 1290 | . (is_numeric($total_parties) ? |
| 1297 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1298 | - ('+' . $total_parties . ' - 1')); |
|
| 1291 | + (($total_parties == 1) ? "" : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1299 | 1292 | } |
| 1300 | 1293 | |
| 1301 | 1294 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1313,11 +1306,11 @@ discard block |
||
| 1313 | 1306 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1314 | 1307 | |
| 1315 | 1308 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1316 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1309 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1317 | 1310 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1318 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1319 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1320 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1311 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1312 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1313 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1321 | 1314 | . "\n\tif (\$debut_boucle>0" |
| 1322 | 1315 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1323 | 1316 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1402,16 +1395,16 @@ discard block |
||
| 1402 | 1395 | // critere personnalise ? |
| 1403 | 1396 | if ( |
| 1404 | 1397 | (!$serveur or |
| 1405 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1406 | - and (!function_exists($f = $f . "_dist")) |
|
| 1407 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1408 | - and (!function_exists($f = $f . "_dist")) |
|
| 1398 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 1399 | + and (!function_exists($f = $f."_dist")) |
|
| 1400 | + and (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 1401 | + and (!function_exists($f = $f."_dist")) |
|
| 1409 | 1402 | ) |
| 1410 | 1403 | ) |
| 1411 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1412 | - and (!function_exists($f = $f . "_dist")) |
|
| 1413 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1414 | - and (!function_exists($f = $f . "_dist")) |
|
| 1404 | + and (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 1405 | + and (!function_exists($f = $f."_dist")) |
|
| 1406 | + and (!function_exists($f = "critere_".$critere)) |
|
| 1407 | + and (!function_exists($f = $f."_dist")) |
|
| 1415 | 1408 | ) { |
| 1416 | 1409 | // fonction critere standard |
| 1417 | 1410 | $f = $defaut; |
@@ -1444,9 +1437,9 @@ discard block |
||
| 1444 | 1437 | */ |
| 1445 | 1438 | function kwote($lisp, $serveur = '', $type = '') { |
| 1446 | 1439 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1447 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1440 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type)."\""; |
|
| 1448 | 1441 | } else { |
| 1449 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1442 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1450 | 1443 | } |
| 1451 | 1444 | } |
| 1452 | 1445 | |
@@ -1468,7 +1461,7 @@ discard block |
||
| 1468 | 1461 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1469 | 1462 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1470 | 1463 | if (!$r) { |
| 1471 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1464 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 1472 | 1465 | } |
| 1473 | 1466 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1474 | 1467 | |
@@ -1495,8 +1488,8 @@ discard block |
||
| 1495 | 1488 | "'NOT'", |
| 1496 | 1489 | array( |
| 1497 | 1490 | "'IN'", |
| 1498 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1499 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1491 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1492 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1500 | 1493 | ) |
| 1501 | 1494 | ); |
| 1502 | 1495 | } |
@@ -1515,22 +1508,22 @@ discard block |
||
| 1515 | 1508 | $descr = $boucles[$idb]->descr; |
| 1516 | 1509 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1517 | 1510 | |
| 1518 | - $var = '$in' . $cpt++; |
|
| 1511 | + $var = '$in'.$cpt++; |
|
| 1519 | 1512 | $x = "\n\t$var = array();"; |
| 1520 | 1513 | foreach ($val as $k => $v) { |
| 1521 | 1514 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1522 | 1515 | // optimiser le traitement des constantes |
| 1523 | 1516 | if (is_numeric($r[2])) { |
| 1524 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1517 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1525 | 1518 | } else { |
| 1526 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1519 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1527 | 1520 | } |
| 1528 | 1521 | } else { |
| 1529 | 1522 | // Pour permettre de passer des tableaux de valeurs |
| 1530 | 1523 | // on repere l'utilisation brute de #ENV**{X}, |
| 1531 | 1524 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1532 | 1525 | // et on deballe mais en rajoutant l'anti XSS |
| 1533 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1526 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1534 | 1527 | } |
| 1535 | 1528 | } |
| 1536 | 1529 | |
@@ -1544,7 +1537,7 @@ discard block |
||
| 1544 | 1537 | $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
| 1545 | 1538 | } |
| 1546 | 1539 | |
| 1547 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1540 | + return "sql_in('$arg',sql_quote($var)".($crit2 == 'NOT' ? ",'NOT'" : "").")"; |
|
| 1548 | 1541 | } |
| 1549 | 1542 | |
| 1550 | 1543 | /** |
@@ -1617,7 +1610,7 @@ discard block |
||
| 1617 | 1610 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1618 | 1611 | } |
| 1619 | 1612 | // nous aider en mode debug. |
| 1620 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1613 | + $boucle->debug[] = "id_ : ".implode(', ', $champs); |
|
| 1621 | 1614 | $boucle->modificateur['id_'] = $champs; |
| 1622 | 1615 | |
| 1623 | 1616 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1658,7 +1651,7 @@ discard block |
||
| 1658 | 1651 | // Les champs id_xx de la table demandée |
| 1659 | 1652 | $champs = array_filter( |
| 1660 | 1653 | array_keys($desc['field']), |
| 1661 | - function($champ){ |
|
| 1654 | + function($champ) { |
|
| 1662 | 1655 | return |
| 1663 | 1656 | strpos($champ, 'id_') === 0 |
| 1664 | 1657 | or (in_array($champ, array('objet'))); |
@@ -1861,8 +1854,8 @@ discard block |
||
| 1861 | 1854 | "'NOT'", |
| 1862 | 1855 | array( |
| 1863 | 1856 | "'IN'", |
| 1864 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1865 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1857 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1858 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1866 | 1859 | ) |
| 1867 | 1860 | ); |
| 1868 | 1861 | } |
@@ -1873,7 +1866,7 @@ discard block |
||
| 1873 | 1866 | if ($crit->cond) { |
| 1874 | 1867 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1875 | 1868 | if ($col == "date" or $col == "date_redac") { |
| 1876 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1869 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1877 | 1870 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1878 | 1871 | } |
| 1879 | 1872 | } |
@@ -2034,7 +2027,7 @@ discard block |
||
| 2034 | 2027 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2035 | 2028 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2036 | 2029 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2037 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2030 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2038 | 2031 | } |
| 2039 | 2032 | // sinon expliciter les |
| 2040 | 2033 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2045,22 +2038,22 @@ discard block |
||
| 2045 | 2038 | // sql_quote(truc,'','varchar') |
| 2046 | 2039 | elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
| 2047 | 2040 | // si pas deja un type |
| 2048 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2041 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2049 | 2042 | ) { |
| 2050 | 2043 | $r = $r[1] |
| 2051 | 2044 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2052 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2045 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2053 | 2046 | $val[0] = "sql_quote($r)"; |
| 2054 | 2047 | } |
| 2055 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2048 | + elseif (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2056 | 2049 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2057 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2050 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2058 | 2051 | } |
| 2059 | 2052 | } |
| 2060 | 2053 | |
| 2061 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2054 | + if (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2062 | 2055 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2063 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2056 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2064 | 2057 | } |
| 2065 | 2058 | |
| 2066 | 2059 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2085,7 +2078,7 @@ discard block |
||
| 2085 | 2078 | // inserer le nom de la table SQL devant le nom du champ |
| 2086 | 2079 | if ($table) { |
| 2087 | 2080 | if ($col[0] == "`") { |
| 2088 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2081 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2089 | 2082 | } else { |
| 2090 | 2083 | $arg = "$table.$col"; |
| 2091 | 2084 | } |
@@ -2219,9 +2212,9 @@ discard block |
||
| 2219 | 2212 | **/ |
| 2220 | 2213 | function primary_doublee($decompose, $table) { |
| 2221 | 2214 | $e1 = reset($decompose); |
| 2222 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2215 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2223 | 2216 | |
| 2224 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2217 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 2225 | 2218 | } |
| 2226 | 2219 | |
| 2227 | 2220 | /** |
@@ -2259,7 +2252,7 @@ discard block |
||
| 2259 | 2252 | if ($checkarrivee |
| 2260 | 2253 | and is_string($checkarrivee) |
| 2261 | 2254 | and $a = table_objet($checkarrivee) |
| 2262 | - and in_array($a . '_liens', $joints) |
|
| 2255 | + and in_array($a.'_liens', $joints) |
|
| 2263 | 2256 | ) { |
| 2264 | 2257 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2265 | 2258 | return $res; |
@@ -2279,12 +2272,12 @@ discard block |
||
| 2279 | 2272 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2280 | 2273 | $joindre = false; |
| 2281 | 2274 | foreach ($cols as $col) { |
| 2282 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2275 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2283 | 2276 | if (trouver_champ($c, $boucle->where)) { |
| 2284 | 2277 | $joindre = true; |
| 2285 | 2278 | } else { |
| 2286 | 2279 | // mais ca peut etre dans le FIELD pour le Having |
| 2287 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2280 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2288 | 2281 | if (trouver_champ($c, $boucle->select)) { |
| 2289 | 2282 | $joindre = true; |
| 2290 | 2283 | } |
@@ -2331,7 +2324,7 @@ discard block |
||
| 2331 | 2324 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2332 | 2325 | |
| 2333 | 2326 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2334 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2327 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 2335 | 2328 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2336 | 2329 | |
| 2337 | 2330 | if (!$intermediaire or !$arrivee) { |
@@ -2429,7 +2422,7 @@ discard block |
||
| 2429 | 2422 | } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
| 2430 | 2423 | // un critere conditionnel sur date est traite a part |
| 2431 | 2424 | // car la date est mise d'office par SPIP, |
| 2432 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2425 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2433 | 2426 | } |
| 2434 | 2427 | |
| 2435 | 2428 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2461,7 +2454,7 @@ discard block |
||
| 2461 | 2454 | and (($p == "'") or ($p == '"')) |
| 2462 | 2455 | and $params[0][1]->type == 'champ' |
| 2463 | 2456 | ) { |
| 2464 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2457 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2465 | 2458 | } else { |
| 2466 | 2459 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2467 | 2460 | $a = calculer_liste($p, $desc, $boucles, $parent); |
@@ -2477,7 +2470,7 @@ discard block |
||
| 2477 | 2470 | $fct = $args_sql = ''; |
| 2478 | 2471 | // fonction SQL ? |
| 2479 | 2472 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2480 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2473 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2481 | 2474 | $fct = $m[1]; |
| 2482 | 2475 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2483 | 2476 | $col = $a[1]; |
@@ -2567,7 +2560,7 @@ discard block |
||
| 2567 | 2560 | # si oui choisir ce champ, sinon choisir xxxx |
| 2568 | 2561 | |
| 2569 | 2562 | if (isset($table['field']["date$suite"])) { |
| 2570 | - $date_orig = 'date' . $suite; |
|
| 2563 | + $date_orig = 'date'.$suite; |
|
| 2571 | 2564 | } else { |
| 2572 | 2565 | $date_orig = substr($suite, 1); |
| 2573 | 2566 | } |
@@ -2578,12 +2571,12 @@ discard block |
||
| 2578 | 2571 | } |
| 2579 | 2572 | } |
| 2580 | 2573 | |
| 2581 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2582 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2574 | + $date_compare = "\"' . normaliser_date(". |
|
| 2575 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2583 | 2576 | ") . '\""; |
| 2584 | 2577 | |
| 2585 | 2578 | $col_vraie = $date_orig; |
| 2586 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2579 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2587 | 2580 | |
| 2588 | 2581 | switch ($col) { |
| 2589 | 2582 | case 'date': |
@@ -2603,26 +2596,26 @@ discard block |
||
| 2603 | 2596 | break; |
| 2604 | 2597 | case 'age': |
| 2605 | 2598 | $col = calculer_param_date("NOW()", $date_orig); |
| 2606 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2599 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2607 | 2600 | break; |
| 2608 | 2601 | case 'age_relatif': |
| 2609 | 2602 | $col = calculer_param_date($date_compare, $date_orig); |
| 2610 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2603 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2611 | 2604 | break; |
| 2612 | 2605 | case 'jour_relatif': |
| 2613 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2614 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2606 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 2607 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2615 | 2608 | break; |
| 2616 | 2609 | case 'mois_relatif': |
| 2617 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2618 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2619 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2620 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2610 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 2611 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 2612 | + ")-YEAR(".$date_orig."))"; |
|
| 2613 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2621 | 2614 | break; |
| 2622 | 2615 | case 'annee_relatif': |
| 2623 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2624 | - $date_orig . ")"; |
|
| 2625 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2616 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 2617 | + $date_orig.")"; |
|
| 2618 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2626 | 2619 | break; |
| 2627 | 2620 | } |
| 2628 | 2621 | |
@@ -2681,10 +2674,10 @@ discard block |
||
| 2681 | 2674 | } |
| 2682 | 2675 | |
| 2683 | 2676 | $boucle->hash .= ' |
| 2684 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2677 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2685 | 2678 | |
| 2686 | 2679 | $boucle->hash .= ' |
| 2687 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2680 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2688 | 2681 | } |
| 2689 | 2682 | |
| 2690 | 2683 | |
@@ -2702,8 +2695,8 @@ discard block |
||
| 2702 | 2695 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2703 | 2696 | $boucle = &$boucles[$idb]; |
| 2704 | 2697 | $boucle->hash .= ' |
| 2705 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2706 | - $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2698 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2699 | + $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2707 | 2700 | } |
| 2708 | 2701 | |
| 2709 | 2702 | |
@@ -2723,7 +2716,7 @@ discard block |
||
| 2723 | 2716 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2724 | 2717 | $boucle = &$boucles[$idb]; |
| 2725 | 2718 | $boucle->hash .= ' |
| 2726 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2719 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2727 | 2720 | } |
| 2728 | 2721 | |
| 2729 | 2722 | |
@@ -2742,7 +2735,7 @@ discard block |
||
| 2742 | 2735 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2743 | 2736 | foreach ($crit->param as $param) { |
| 2744 | 2737 | $boucle->hash .= ' |
| 2745 | - $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2738 | + $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2746 | 2739 | } |
| 2747 | 2740 | } |
| 2748 | 2741 | |
@@ -2761,10 +2754,10 @@ discard block |
||
| 2761 | 2754 | */ |
| 2762 | 2755 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2763 | 2756 | $boucle = &$boucles[$idb]; |
| 2764 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2757 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2765 | 2758 | foreach ($crit->param as $param) { |
| 2766 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2767 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2759 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2760 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2768 | 2761 | } |
| 2769 | 2762 | } |
| 2770 | 2763 | |
@@ -2791,10 +2784,10 @@ discard block |
||
| 2791 | 2784 | */ |
| 2792 | 2785 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2793 | 2786 | $boucle = &$boucles[$idb]; |
| 2794 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2787 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2795 | 2788 | foreach ($crit->param as $param) { |
| 2796 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2797 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2789 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2790 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2798 | 2791 | } |
| 2799 | 2792 | } |
| 2800 | 2793 | |
@@ -2813,7 +2806,7 @@ discard block |
||
| 2813 | 2806 | $boucle = &$boucles[$idb]; |
| 2814 | 2807 | foreach ($crit->param as $param) { |
| 2815 | 2808 | $boucle->hash .= ' |
| 2816 | - $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2809 | + $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2817 | 2810 | } |
| 2818 | 2811 | } |
| 2819 | 2812 | |
@@ -2854,7 +2847,7 @@ discard block |
||
| 2854 | 2847 | if ($crit->param) { |
| 2855 | 2848 | foreach ($crit->param as $param) { |
| 2856 | 2849 | $boucle->hash .= "\t\$command['si'][] = " |
| 2857 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2850 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2858 | 2851 | } |
| 2859 | 2852 | // interdire {si 0} aussi ! |
| 2860 | 2853 | } else { |
@@ -2877,7 +2870,7 @@ discard block |
||
| 2877 | 2870 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2878 | 2871 | $boucle = &$boucles[$idb]; |
| 2879 | 2872 | $boucle->hash .= ' |
| 2880 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2873 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2881 | 2874 | $command[\'sourcemode\'] = \'table\';'; |
| 2882 | 2875 | } |
| 2883 | 2876 | |
@@ -2910,11 +2903,10 @@ discard block |
||
| 2910 | 2903 | $table_sql = table_objet_sql(objet_type($table)); |
| 2911 | 2904 | |
| 2912 | 2905 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2913 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2914 | - 'id_parent'; |
|
| 2906 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2915 | 2907 | |
| 2916 | 2908 | $in = "IN"; |
| 2917 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2909 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2918 | 2910 | if ($not) { |
| 2919 | 2911 | $where = array("'NOT'", $where); |
| 2920 | 2912 | } |