@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Logos |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -37,31 +37,31 @@ discard block |
||
| 37 | 37 | **/ |
| 38 | 38 | function inc_chercher_logo_dist($id, $_id_objet, $mode = 'on') { |
| 39 | 39 | |
| 40 | - $mode = preg_replace(",\W,", '', $mode); |
|
| 41 | - if ($mode) { |
|
| 42 | - // chercher dans la base |
|
| 43 | - $mode_document = 'logo' . $mode; |
|
| 44 | - $objet = objet_type($_id_objet); |
|
| 45 | - $doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', "D.mode=".sql_quote($mode_document)." AND L.objet=".sql_quote($objet)." AND id_objet=".intval($id)); |
|
| 46 | - if ($doc) { |
|
| 47 | - $d = get_spip_doc($doc['fichier']); |
|
| 48 | - return array($d, _DIR_IMG, basename($d), $d['extension'], @filemtime($d), $doc); |
|
| 49 | - } |
|
| 40 | + $mode = preg_replace(",\W,", '', $mode); |
|
| 41 | + if ($mode) { |
|
| 42 | + // chercher dans la base |
|
| 43 | + $mode_document = 'logo' . $mode; |
|
| 44 | + $objet = objet_type($_id_objet); |
|
| 45 | + $doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', "D.mode=".sql_quote($mode_document)." AND L.objet=".sql_quote($objet)." AND id_objet=".intval($id)); |
|
| 46 | + if ($doc) { |
|
| 47 | + $d = get_spip_doc($doc['fichier']); |
|
| 48 | + return array($d, _DIR_IMG, basename($d), $d['extension'], @filemtime($d), $doc); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - # TODO : deprecated |
|
| 52 | - # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval() |
|
| 53 | - $type = type_du_logo($_id_objet); |
|
| 54 | - $nom = $type . $mode . intval($id); |
|
| 51 | + # TODO : deprecated |
|
| 52 | + # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval() |
|
| 53 | + $type = type_du_logo($_id_objet); |
|
| 54 | + $nom = $type . $mode . intval($id); |
|
| 55 | 55 | |
| 56 | - foreach ($GLOBALS['formats_logos'] as $format) { |
|
| 57 | - if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) { |
|
| 58 | - return array($d, _DIR_LOGOS, $nom, $format, @filemtime($d)); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 56 | + foreach ($GLOBALS['formats_logos'] as $format) { |
|
| 57 | + if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) { |
|
| 58 | + return array($d, _DIR_LOGOS, $nom, $format, @filemtime($d)); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - # coherence de type pour servir comme filtre (formulaire_login) |
|
| 64 | - return array(); |
|
| 63 | + # coherence de type pour servir comme filtre (formulaire_login) |
|
| 64 | + return array(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -80,15 +80,15 @@ discard block |
||
| 80 | 80 | * @deprecated MAIS NE PAS SUPPRIMER CAR SERT POUR L'UPGRADE des logos et leur mise en base |
| 81 | 81 | **/ |
| 82 | 82 | function type_du_logo($_id_objet) { |
| 83 | - return isset($GLOBALS['table_logos'][$_id_objet]) |
|
| 84 | - ? $GLOBALS['table_logos'][$_id_objet] |
|
| 85 | - : objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 83 | + return isset($GLOBALS['table_logos'][$_id_objet]) |
|
| 84 | + ? $GLOBALS['table_logos'][$_id_objet] |
|
| 85 | + : objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // Exceptions standards (historique) |
| 89 | 89 | $GLOBALS['table_logos'] = array( |
| 90 | - 'id_article' => 'art', |
|
| 91 | - 'id_auteur' => 'aut', |
|
| 92 | - 'id_rubrique' => 'rub', |
|
| 93 | - 'id_groupe' => 'groupe', |
|
| 90 | + 'id_article' => 'art', |
|
| 91 | + 'id_auteur' => 'aut', |
|
| 92 | + 'id_rubrique' => 'rub', |
|
| 93 | + 'id_groupe' => 'groupe', |
|
| 94 | 94 | ); |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -42,223 +42,223 @@ discard block |
||
| 42 | 42 | // http://code.spip.net/@public_composer_dist |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 44 | 44 | |
| 45 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | - |
|
| 47 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | - if (function_exists($nom)) { |
|
| 49 | - return $nom; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | - |
|
| 58 | - // si squelette est deja compile et perenne, le charger |
|
| 59 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | - include_once $phpfile; |
|
| 61 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | - ## eval('?'.'>'.$skel_code); |
|
| 65 | - # spip_log($skel_code, 'comp') |
|
| 66 | - #} |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | - include_once $lib; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | - |
|
| 75 | - if (function_exists($nom)) { |
|
| 76 | - return $nom; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // charger le source, si possible, et compiler |
|
| 80 | - $skel_code = ''; |
|
| 81 | - if (lire_fichier($source, $skel)) { |
|
| 82 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 83 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 87 | - if (!$skel_code) { |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - foreach ($skel_code as $id => $boucle) { |
|
| 92 | - $f = $boucle->return; |
|
| 93 | - if (@eval("return true; $f ;") === false) { |
|
| 94 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 95 | - $msg = _T('zbug_erreur_compilation'); |
|
| 96 | - erreur_squelette($msg, $boucle); |
|
| 97 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 98 | - // mais prevenir que c'est mort |
|
| 99 | - $nom = ''; |
|
| 100 | - } |
|
| 101 | - // Contexte de compil inutile a present |
|
| 102 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 103 | - $skel_code[$id] = $f; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $code = ''; |
|
| 107 | - if ($nom) { |
|
| 108 | - // Si le code est bon, concatener et mettre en cache |
|
| 109 | - if (function_exists($nom)) { |
|
| 110 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 111 | - } else { |
|
| 112 | - // code semantiquement faux: bug du compilateur |
|
| 113 | - // $boucle est en fait ici la fct principale du squelette |
|
| 114 | - $msg = _T('zbug_erreur_compilation'); |
|
| 115 | - erreur_squelette($msg, $boucle); |
|
| 116 | - $nom = ''; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 121 | - |
|
| 122 | - // Tracer ce qui vient d'etre compile |
|
| 123 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 124 | - |
|
| 125 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 126 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 127 | - and (_request('var_mode_objet') == $nom) |
|
| 128 | - and (_request('var_mode_affiche') == 'code') |
|
| 129 | - ) { |
|
| 130 | - erreur_squelette(); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $nom ? $nom : false; |
|
| 45 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | + |
|
| 47 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | + if (function_exists($nom)) { |
|
| 49 | + return $nom; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + |
|
| 58 | + // si squelette est deja compile et perenne, le charger |
|
| 59 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | + include_once $phpfile; |
|
| 61 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | + ## eval('?'.'>'.$skel_code); |
|
| 65 | + # spip_log($skel_code, 'comp') |
|
| 66 | + #} |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + include_once $lib; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | + |
|
| 75 | + if (function_exists($nom)) { |
|
| 76 | + return $nom; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // charger le source, si possible, et compiler |
|
| 80 | + $skel_code = ''; |
|
| 81 | + if (lire_fichier($source, $skel)) { |
|
| 82 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 83 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 87 | + if (!$skel_code) { |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + foreach ($skel_code as $id => $boucle) { |
|
| 92 | + $f = $boucle->return; |
|
| 93 | + if (@eval("return true; $f ;") === false) { |
|
| 94 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 95 | + $msg = _T('zbug_erreur_compilation'); |
|
| 96 | + erreur_squelette($msg, $boucle); |
|
| 97 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 98 | + // mais prevenir que c'est mort |
|
| 99 | + $nom = ''; |
|
| 100 | + } |
|
| 101 | + // Contexte de compil inutile a present |
|
| 102 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 103 | + $skel_code[$id] = $f; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $code = ''; |
|
| 107 | + if ($nom) { |
|
| 108 | + // Si le code est bon, concatener et mettre en cache |
|
| 109 | + if (function_exists($nom)) { |
|
| 110 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 111 | + } else { |
|
| 112 | + // code semantiquement faux: bug du compilateur |
|
| 113 | + // $boucle est en fait ici la fct principale du squelette |
|
| 114 | + $msg = _T('zbug_erreur_compilation'); |
|
| 115 | + erreur_squelette($msg, $boucle); |
|
| 116 | + $nom = ''; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 121 | + |
|
| 122 | + // Tracer ce qui vient d'etre compile |
|
| 123 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 124 | + |
|
| 125 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 126 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 127 | + and (_request('var_mode_objet') == $nom) |
|
| 128 | + and (_request('var_mode_affiche') == 'code') |
|
| 129 | + ) { |
|
| 130 | + erreur_squelette(); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $nom ? $nom : false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 138 | 138 | |
| 139 | - // Le dernier index est '' (fonction principale) |
|
| 140 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 141 | - if (CODE_COMMENTE) { |
|
| 142 | - $code = " |
|
| 139 | + // Le dernier index est '' (fonction principale) |
|
| 140 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 141 | + if (CODE_COMMENTE) { |
|
| 142 | + $code = " |
|
| 143 | 143 | /* |
| 144 | 144 | * Squelette : $sourcefile |
| 145 | 145 | * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
| 146 | 146 | * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
| 147 | 147 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
| 148 | 148 | */ "; |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 152 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 153 | - ecrire_fichier($phpfile, $code); |
|
| 154 | - } |
|
| 151 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 152 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 153 | + ecrire_fichier($phpfile, $code); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - return $code; |
|
| 156 | + return $code; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Le squelette compile est-il trop vieux ? |
| 160 | 160 | // http://code.spip.net/@squelette_obsolete |
| 161 | 161 | function squelette_obsolete($skel, $squelette) { |
| 162 | - static $date_change = null; |
|
| 163 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 164 | - // par hit |
|
| 165 | - if (is_null($date_change)) { |
|
| 166 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 167 | - $date_change = @filemtime($fonc); |
|
| 168 | - } # compatibilite |
|
| 169 | - if (defined('_FILE_OPTIONS')) { |
|
| 170 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return ( |
|
| 175 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 176 | - or !@file_exists($skel) |
|
| 177 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 178 | - > ($date = @filemtime($skel))) |
|
| 179 | - or ($date_change > $date) |
|
| 180 | - ); |
|
| 162 | + static $date_change = null; |
|
| 163 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 164 | + // par hit |
|
| 165 | + if (is_null($date_change)) { |
|
| 166 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 167 | + $date_change = @filemtime($fonc); |
|
| 168 | + } # compatibilite |
|
| 169 | + if (defined('_FILE_OPTIONS')) { |
|
| 170 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return ( |
|
| 175 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 176 | + or !@file_exists($skel) |
|
| 177 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 178 | + > ($date = @filemtime($skel))) |
|
| 179 | + or ($date_change > $date) |
|
| 180 | + ); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Activer l'invalideur de session |
| 184 | 184 | // http://code.spip.net/@invalideur_session |
| 185 | 185 | function invalideur_session(&$Cache, $code = null) { |
| 186 | - $Cache['session'] = spip_session(); |
|
| 186 | + $Cache['session'] = spip_session(); |
|
| 187 | 187 | |
| 188 | - return $code; |
|
| 188 | + return $code; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
| 192 | 192 | // http://code.spip.net/@analyse_resultat_skel |
| 193 | 193 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 194 | - static $filtres = array(); |
|
| 195 | - $headers = array(); |
|
| 196 | - |
|
| 197 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 198 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 199 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 200 | - if (stripos($corps, 'header') !== false |
|
| 201 | - and preg_match_all( |
|
| 202 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 203 | - $corps, $regs, PREG_SET_ORDER) |
|
| 204 | - ) { |
|
| 205 | - foreach ($regs as $r) { |
|
| 206 | - $corps = str_replace($r[0], '', $corps); |
|
| 207 | - # $j = Content-Type, et pas content-TYPE. |
|
| 208 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 209 | - |
|
| 210 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 211 | - $headers[$j] .= "|" . $r[3]; |
|
| 212 | - } else { |
|
| 213 | - $headers[$j] = $r[3]; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 218 | - $process_ins = ( |
|
| 219 | - strpos($corps, '<' . '?') === false |
|
| 220 | - or |
|
| 221 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 222 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 223 | - ) |
|
| 224 | - ? 'html' |
|
| 225 | - : 'php'; |
|
| 226 | - |
|
| 227 | - $skel = array( |
|
| 228 | - 'squelette' => $nom, |
|
| 229 | - 'source' => $source, |
|
| 230 | - 'process_ins' => $process_ins, |
|
| 231 | - 'invalideurs' => $cache, |
|
| 232 | - 'entetes' => $headers, |
|
| 233 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 234 | - ); |
|
| 235 | - |
|
| 236 | - // traiter #FILTRE{} et filtres |
|
| 237 | - if (!isset($filtres[$nom])) { |
|
| 238 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 239 | - } |
|
| 240 | - if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 241 | - include_spip('public/sandbox'); |
|
| 242 | - $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 243 | - strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 244 | - unset($headers['X-Spip-Filtre']); |
|
| 245 | - |
|
| 246 | - if ($process_ins == 'html') { |
|
| 247 | - $skel['process_ins'] = ( |
|
| 248 | - strpos($corps, '<' . '?') === false |
|
| 249 | - or |
|
| 250 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 251 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 252 | - ) |
|
| 253 | - ? 'html' |
|
| 254 | - : 'php'; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $skel['entetes'] = $headers; |
|
| 259 | - $skel['texte'] = $corps; |
|
| 260 | - |
|
| 261 | - return $skel; |
|
| 194 | + static $filtres = array(); |
|
| 195 | + $headers = array(); |
|
| 196 | + |
|
| 197 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 198 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 199 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 200 | + if (stripos($corps, 'header') !== false |
|
| 201 | + and preg_match_all( |
|
| 202 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 203 | + $corps, $regs, PREG_SET_ORDER) |
|
| 204 | + ) { |
|
| 205 | + foreach ($regs as $r) { |
|
| 206 | + $corps = str_replace($r[0], '', $corps); |
|
| 207 | + # $j = Content-Type, et pas content-TYPE. |
|
| 208 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 209 | + |
|
| 210 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 211 | + $headers[$j] .= "|" . $r[3]; |
|
| 212 | + } else { |
|
| 213 | + $headers[$j] = $r[3]; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 218 | + $process_ins = ( |
|
| 219 | + strpos($corps, '<' . '?') === false |
|
| 220 | + or |
|
| 221 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 222 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 223 | + ) |
|
| 224 | + ? 'html' |
|
| 225 | + : 'php'; |
|
| 226 | + |
|
| 227 | + $skel = array( |
|
| 228 | + 'squelette' => $nom, |
|
| 229 | + 'source' => $source, |
|
| 230 | + 'process_ins' => $process_ins, |
|
| 231 | + 'invalideurs' => $cache, |
|
| 232 | + 'entetes' => $headers, |
|
| 233 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 234 | + ); |
|
| 235 | + |
|
| 236 | + // traiter #FILTRE{} et filtres |
|
| 237 | + if (!isset($filtres[$nom])) { |
|
| 238 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 239 | + } |
|
| 240 | + if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 241 | + include_spip('public/sandbox'); |
|
| 242 | + $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 243 | + strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 244 | + unset($headers['X-Spip-Filtre']); |
|
| 245 | + |
|
| 246 | + if ($process_ins == 'html') { |
|
| 247 | + $skel['process_ins'] = ( |
|
| 248 | + strpos($corps, '<' . '?') === false |
|
| 249 | + or |
|
| 250 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 251 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 252 | + ) |
|
| 253 | + ? 'html' |
|
| 254 | + : 'php'; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $skel['entetes'] = $headers; |
|
| 259 | + $skel['texte'] = $corps; |
|
| 260 | + |
|
| 261 | + return $skel; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | // |
@@ -295,75 +295,75 @@ discard block |
||
| 295 | 295 | * Introduction calculée |
| 296 | 296 | **/ |
| 297 | 297 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 298 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 299 | - if (strlen($descriptif)) { |
|
| 300 | - return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // De preference ce qui est marque <intro>...</intro> |
|
| 304 | - $intro = ''; |
|
| 305 | - $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 306 | - while ($fin = strpos($texte, "</intro>")) { |
|
| 307 | - $zone = substr($texte, 0, $fin); |
|
| 308 | - $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 309 | - if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 310 | - $zone = substr($zone, $deb + 7); |
|
| 311 | - } |
|
| 312 | - $intro .= $zone; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 316 | - // qui inclus raccourcis et modeles |
|
| 317 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 318 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 319 | - // des surcharges et enrichissement de propre |
|
| 320 | - // couper doit se faire apres propre |
|
| 321 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 322 | - |
|
| 323 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 324 | - // large et en se mefiant des tableaux #1323 |
|
| 325 | - |
|
| 326 | - if (strlen($intro)) { |
|
| 327 | - $texte = $intro; |
|
| 328 | - } else { |
|
| 329 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 330 | - and strlen($texte) > 2.5 * $longueur |
|
| 331 | - ) { |
|
| 332 | - if (strpos($texte, "<multi") !== false) { |
|
| 333 | - $texte = extraire_multi($texte); |
|
| 334 | - } |
|
| 335 | - $texte = couper($texte, 2 * $longueur); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // ne pas tenir compte des notes |
|
| 340 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 341 | - $notes('', 'empiler'); |
|
| 342 | - } |
|
| 343 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 344 | - // dans l'introduction. |
|
| 345 | - $texte = supprime_img($texte, ''); |
|
| 346 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 347 | - |
|
| 348 | - if ($notes) { |
|
| 349 | - $notes('', 'depiler'); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 353 | - $suite = _INTRODUCTION_SUITE; |
|
| 354 | - } |
|
| 355 | - $texte = couper($texte, $longueur, $suite); |
|
| 356 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 357 | - $texte = typo($texte, true, $connect, array()); |
|
| 358 | - |
|
| 359 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 360 | - // une introduction a tojours un <p> |
|
| 361 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 362 | - { |
|
| 363 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return $texte; |
|
| 298 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 299 | + if (strlen($descriptif)) { |
|
| 300 | + return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // De preference ce qui est marque <intro>...</intro> |
|
| 304 | + $intro = ''; |
|
| 305 | + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 306 | + while ($fin = strpos($texte, "</intro>")) { |
|
| 307 | + $zone = substr($texte, 0, $fin); |
|
| 308 | + $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 309 | + if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 310 | + $zone = substr($zone, $deb + 7); |
|
| 311 | + } |
|
| 312 | + $intro .= $zone; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 316 | + // qui inclus raccourcis et modeles |
|
| 317 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 318 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 319 | + // des surcharges et enrichissement de propre |
|
| 320 | + // couper doit se faire apres propre |
|
| 321 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 322 | + |
|
| 323 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 324 | + // large et en se mefiant des tableaux #1323 |
|
| 325 | + |
|
| 326 | + if (strlen($intro)) { |
|
| 327 | + $texte = $intro; |
|
| 328 | + } else { |
|
| 329 | + if (strpos("\n" . $texte, "\n|") === false |
|
| 330 | + and strlen($texte) > 2.5 * $longueur |
|
| 331 | + ) { |
|
| 332 | + if (strpos($texte, "<multi") !== false) { |
|
| 333 | + $texte = extraire_multi($texte); |
|
| 334 | + } |
|
| 335 | + $texte = couper($texte, 2 * $longueur); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // ne pas tenir compte des notes |
|
| 340 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 341 | + $notes('', 'empiler'); |
|
| 342 | + } |
|
| 343 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 344 | + // dans l'introduction. |
|
| 345 | + $texte = supprime_img($texte, ''); |
|
| 346 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 347 | + |
|
| 348 | + if ($notes) { |
|
| 349 | + $notes('', 'depiler'); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 353 | + $suite = _INTRODUCTION_SUITE; |
|
| 354 | + } |
|
| 355 | + $texte = couper($texte, $longueur, $suite); |
|
| 356 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 357 | + $texte = typo($texte, true, $connect, array()); |
|
| 358 | + |
|
| 359 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 360 | + // une introduction a tojours un <p> |
|
| 361 | + if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 362 | + { |
|
| 363 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return $texte; |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 378 | 378 | if ($lang_select) lang_select(); |
| 379 | 379 | ?' |
| 380 | - . '>'); |
|
| 380 | + . '>'); |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -397,17 +397,17 @@ discard block |
||
| 397 | 397 | * Code PHP pour inclure le squelette de la balise dynamique |
| 398 | 398 | **/ |
| 399 | 399 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 400 | - if (strncmp($file, "/", 1) !== 0) { |
|
| 401 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 402 | - } |
|
| 403 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 404 | - $file, |
|
| 405 | - $context_compil[4] ? $context_compil[4] : '', |
|
| 406 | - $nom, |
|
| 407 | - join(', ', array_map('argumenter_squelette', $args)), |
|
| 408 | - join(', ', array_map('_q', $context_compil))); |
|
| 409 | - |
|
| 410 | - return $r; |
|
| 400 | + if (strncmp($file, "/", 1) !== 0) { |
|
| 401 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 402 | + } |
|
| 403 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 404 | + $file, |
|
| 405 | + $context_compil[4] ? $context_compil[4] : '', |
|
| 406 | + $nom, |
|
| 407 | + join(', ', array_map('argumenter_squelette', $args)), |
|
| 408 | + join(', ', array_map('_q', $context_compil))); |
|
| 409 | + |
|
| 410 | + return $r; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -425,16 +425,16 @@ discard block |
||
| 425 | 425 | **/ |
| 426 | 426 | function argumenter_squelette($v) { |
| 427 | 427 | |
| 428 | - if (!is_array($v)) { |
|
| 429 | - return "'" . texte_script($v) . "'"; |
|
| 430 | - } else { |
|
| 431 | - $out = array(); |
|
| 432 | - foreach ($v as $k => $val) { |
|
| 433 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 434 | - } |
|
| 428 | + if (!is_array($v)) { |
|
| 429 | + return "'" . texte_script($v) . "'"; |
|
| 430 | + } else { |
|
| 431 | + $out = array(); |
|
| 432 | + foreach ($v as $k => $val) { |
|
| 433 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - return 'array(' . join(", ", $out) . ')'; |
|
| 437 | - } |
|
| 436 | + return 'array(' . join(", ", $out) . ')'; |
|
| 437 | + } |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
@@ -465,69 +465,69 @@ discard block |
||
| 465 | 465 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 466 | 466 | **/ |
| 467 | 467 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 468 | - $nomfonction = $nom; |
|
| 469 | - $nomfonction_generique = ""; |
|
| 470 | - |
|
| 471 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 472 | - if (false !== ($p = strpos($nom, "_"))) { |
|
| 473 | - $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 477 | - if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 478 | - // et injecter en premier arg le nom de la balise |
|
| 479 | - array_unshift($args, $nom); |
|
| 480 | - $nomfonction = $nomfonction_generique; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if (!$fonction_balise) { |
|
| 485 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 486 | - erreur_squelette($msg, $context_compil); |
|
| 487 | - |
|
| 488 | - return ''; |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - // retrouver le fichier qui a déclaré la fonction |
|
| 492 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 493 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 494 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 495 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 496 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 497 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 501 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 502 | - |
|
| 503 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 504 | - |
|
| 505 | - if (!is_array($r)) { |
|
| 506 | - return $r; |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - // verifier que la fonction dyn est la, |
|
| 510 | - // sinon se replier sur la generique si elle existe |
|
| 511 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 512 | - if ($nomfonction_generique |
|
| 513 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 514 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 515 | - ) { |
|
| 516 | - // et lui injecter en premier arg le nom de la balise |
|
| 517 | - array_unshift($r, $nom); |
|
| 518 | - $nomfonction = $nomfonction_generique; |
|
| 519 | - if (!_DIR_RESTREINT) { |
|
| 520 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 521 | - } |
|
| 522 | - } else { |
|
| 523 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 524 | - erreur_squelette($msg, $context_compil); |
|
| 525 | - |
|
| 526 | - return ''; |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 468 | + $nomfonction = $nom; |
|
| 469 | + $nomfonction_generique = ""; |
|
| 470 | + |
|
| 471 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 472 | + if (false !== ($p = strpos($nom, "_"))) { |
|
| 473 | + $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 477 | + if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 478 | + // et injecter en premier arg le nom de la balise |
|
| 479 | + array_unshift($args, $nom); |
|
| 480 | + $nomfonction = $nomfonction_generique; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if (!$fonction_balise) { |
|
| 485 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 486 | + erreur_squelette($msg, $context_compil); |
|
| 487 | + |
|
| 488 | + return ''; |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + // retrouver le fichier qui a déclaré la fonction |
|
| 492 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 493 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 494 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 495 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 496 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 497 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 501 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 502 | + |
|
| 503 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 504 | + |
|
| 505 | + if (!is_array($r)) { |
|
| 506 | + return $r; |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + // verifier que la fonction dyn est la, |
|
| 510 | + // sinon se replier sur la generique si elle existe |
|
| 511 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 512 | + if ($nomfonction_generique |
|
| 513 | + and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 514 | + and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 515 | + ) { |
|
| 516 | + // et lui injecter en premier arg le nom de la balise |
|
| 517 | + array_unshift($r, $nom); |
|
| 518 | + $nomfonction = $nomfonction_generique; |
|
| 519 | + if (!_DIR_RESTREINT) { |
|
| 520 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 521 | + } |
|
| 522 | + } else { |
|
| 523 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 524 | + erreur_squelette($msg, $context_compil); |
|
| 525 | + |
|
| 526 | + return ''; |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 531 | 531 | |
| 532 | 532 | } |
| 533 | 533 | |
@@ -541,15 +541,15 @@ discard block |
||
| 541 | 541 | **/ |
| 542 | 542 | function lister_objets_avec_logos($type) { |
| 543 | 543 | |
| 544 | - $objet = objet_type($type); |
|
| 545 | - $ids = sql_allfetsel("L.id_objet", "spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document", "D.mode=".sql_quote('logoon')." AND L.objet=".sql_quote($objet)); |
|
| 546 | - if ($ids) { |
|
| 547 | - $ids = array_column($ids, 'id_objet'); |
|
| 548 | - return implode(',', $ids); |
|
| 549 | - } |
|
| 550 | - else { |
|
| 551 | - return "0"; |
|
| 552 | - } |
|
| 544 | + $objet = objet_type($type); |
|
| 545 | + $ids = sql_allfetsel("L.id_objet", "spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document", "D.mode=".sql_quote('logoon')." AND L.objet=".sql_quote($objet)); |
|
| 546 | + if ($ids) { |
|
| 547 | + $ids = array_column($ids, 'id_objet'); |
|
| 548 | + return implode(',', $ids); |
|
| 549 | + } |
|
| 550 | + else { |
|
| 551 | + return "0"; |
|
| 552 | + } |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | |
@@ -565,14 +565,14 @@ discard block |
||
| 565 | 565 | * Code HTML des notes |
| 566 | 566 | **/ |
| 567 | 567 | function calculer_notes() { |
| 568 | - $r = ''; |
|
| 569 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 570 | - $r = $notes(array()); |
|
| 571 | - $notes('', 'depiler'); |
|
| 572 | - $notes('', 'empiler'); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $r; |
|
| 568 | + $r = ''; |
|
| 569 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 570 | + $r = $notes(array()); |
|
| 571 | + $notes('', 'depiler'); |
|
| 572 | + $notes('', 'empiler'); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $r; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -595,27 +595,27 @@ discard block |
||
| 595 | 595 | * @return null; |
| 596 | 596 | **/ |
| 597 | 597 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 598 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 599 | - if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 600 | - and $lang_select !== 'oui' |
|
| 601 | - ) { |
|
| 602 | - $lang = $GLOBALS['spip_lang']; |
|
| 603 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 604 | - elseif (!strlen($lang)) { |
|
| 605 | - $lang = $GLOBALS['spip_lang']; |
|
| 606 | - } // Cas 3. l'objet est multilingue ! |
|
| 607 | - elseif ($lang_select !== 'oui' |
|
| 608 | - and strlen($titre) > 10 |
|
| 609 | - and strpos($titre, '<multi>') !== false |
|
| 610 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 611 | - ) { |
|
| 612 | - $lang = $GLOBALS['spip_lang']; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 616 | - lang_select($lang); |
|
| 617 | - |
|
| 618 | - return; |
|
| 598 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 599 | + if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 600 | + and $lang_select !== 'oui' |
|
| 601 | + ) { |
|
| 602 | + $lang = $GLOBALS['spip_lang']; |
|
| 603 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 604 | + elseif (!strlen($lang)) { |
|
| 605 | + $lang = $GLOBALS['spip_lang']; |
|
| 606 | + } // Cas 3. l'objet est multilingue ! |
|
| 607 | + elseif ($lang_select !== 'oui' |
|
| 608 | + and strlen($titre) > 10 |
|
| 609 | + and strpos($titre, '<multi>') !== false |
|
| 610 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 611 | + ) { |
|
| 612 | + $lang = $GLOBALS['spip_lang']; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 616 | + lang_select($lang); |
|
| 617 | + |
|
| 618 | + return; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | |
@@ -623,21 +623,21 @@ discard block |
||
| 623 | 623 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 624 | 624 | // http://code.spip.net/@nettoyer_env_doublons |
| 625 | 625 | function nettoyer_env_doublons($envd) { |
| 626 | - foreach ($envd as $table => $liste) { |
|
| 627 | - $n = ''; |
|
| 628 | - foreach (explode(',', $liste) as $val) { |
|
| 629 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 630 | - $n .= ',' . $val; |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - if (strlen($n)) { |
|
| 634 | - $envd[$table] = $n; |
|
| 635 | - } else { |
|
| 636 | - unset($envd[$table]); |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return $envd; |
|
| 626 | + foreach ($envd as $table => $liste) { |
|
| 627 | + $n = ''; |
|
| 628 | + foreach (explode(',', $liste) as $val) { |
|
| 629 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 630 | + $n .= ',' . $val; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + if (strlen($n)) { |
|
| 634 | + $envd[$table] = $n; |
|
| 635 | + } else { |
|
| 636 | + unset($envd[$table]); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return $envd; |
|
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | /** |
@@ -656,21 +656,21 @@ discard block |
||
| 656 | 656 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 657 | 657 | **/ |
| 658 | 658 | function match_self($w) { |
| 659 | - if (is_string($w)) { |
|
| 660 | - return false; |
|
| 661 | - } |
|
| 662 | - if (is_array($w)) { |
|
| 663 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 664 | - return $w; |
|
| 665 | - } |
|
| 666 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 667 | - if ($m = match_self($sw)) { |
|
| 668 | - return $m; |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - return false; |
|
| 659 | + if (is_string($w)) { |
|
| 660 | + return false; |
|
| 661 | + } |
|
| 662 | + if (is_array($w)) { |
|
| 663 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 664 | + return $w; |
|
| 665 | + } |
|
| 666 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 667 | + if ($m = match_self($sw)) { |
|
| 668 | + return $m; |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + return false; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
@@ -686,16 +686,16 @@ discard block |
||
| 686 | 686 | * est remplacée par son code. |
| 687 | 687 | **/ |
| 688 | 688 | function remplace_sous_requete($w, $sousrequete) { |
| 689 | - if (is_array($w)) { |
|
| 690 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 691 | - return $sousrequete; |
|
| 692 | - } |
|
| 693 | - foreach ($w as $k => $sw) { |
|
| 694 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - return $w; |
|
| 689 | + if (is_array($w)) { |
|
| 690 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 691 | + return $sousrequete; |
|
| 692 | + } |
|
| 693 | + foreach ($w as $k => $sw) { |
|
| 694 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + return $w; |
|
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | /** |
@@ -709,17 +709,17 @@ discard block |
||
| 709 | 709 | * - Conditions avec des sous requêtes |
| 710 | 710 | **/ |
| 711 | 711 | function trouver_sous_requetes($where) { |
| 712 | - $where_simples = array(); |
|
| 713 | - $where_sous = array(); |
|
| 714 | - foreach ($where as $k => $w) { |
|
| 715 | - if (match_self($w)) { |
|
| 716 | - $where_sous[$k] = $w; |
|
| 717 | - } else { |
|
| 718 | - $where_simples[$k] = $w; |
|
| 719 | - } |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - return array($where_simples, $where_sous); |
|
| 712 | + $where_simples = array(); |
|
| 713 | + $where_sous = array(); |
|
| 714 | + foreach ($where as $k => $w) { |
|
| 715 | + if (match_self($w)) { |
|
| 716 | + $where_sous[$k] = $w; |
|
| 717 | + } else { |
|
| 718 | + $where_simples[$k] = $w; |
|
| 719 | + } |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + return array($where_simples, $where_sous); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | |
@@ -745,258 +745,258 @@ discard block |
||
| 745 | 745 | * @return resource |
| 746 | 746 | */ |
| 747 | 747 | function calculer_select( |
| 748 | - $select = array(), |
|
| 749 | - $from = array(), |
|
| 750 | - $from_type = array(), |
|
| 751 | - $where = array(), |
|
| 752 | - $join = array(), |
|
| 753 | - $groupby = array(), |
|
| 754 | - $orderby = array(), |
|
| 755 | - $limit = '', |
|
| 756 | - $having = array(), |
|
| 757 | - $table = '', |
|
| 758 | - $id = '', |
|
| 759 | - $serveur = '', |
|
| 760 | - $requeter = true |
|
| 748 | + $select = array(), |
|
| 749 | + $from = array(), |
|
| 750 | + $from_type = array(), |
|
| 751 | + $where = array(), |
|
| 752 | + $join = array(), |
|
| 753 | + $groupby = array(), |
|
| 754 | + $orderby = array(), |
|
| 755 | + $limit = '', |
|
| 756 | + $having = array(), |
|
| 757 | + $table = '', |
|
| 758 | + $id = '', |
|
| 759 | + $serveur = '', |
|
| 760 | + $requeter = true |
|
| 761 | 761 | ) { |
| 762 | 762 | |
| 763 | - // retirer les criteres vides: |
|
| 764 | - // {X ?} avec X absent de l'URL |
|
| 765 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 766 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 767 | - $menage = false; |
|
| 768 | - foreach ($where as $k => $v) { |
|
| 769 | - if (is_array($v)) { |
|
| 770 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 771 | - $op = false; |
|
| 772 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 773 | - $op = false; |
|
| 774 | - } else { |
|
| 775 | - $op = $v[0] ? $v[0] : $v; |
|
| 776 | - } |
|
| 777 | - } else { |
|
| 778 | - $op = $v; |
|
| 779 | - } |
|
| 780 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 781 | - unset($where[$k]); |
|
| 782 | - $menage = true; |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 787 | - $groupby = array_diff($groupby, array('')); |
|
| 788 | - |
|
| 789 | - // remplacer les sous requetes recursives au calcul |
|
| 790 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 791 | - foreach ($where_sous as $k => $w) { |
|
| 792 | - $menage = true; |
|
| 793 | - // on recupere la sous requete |
|
| 794 | - $sous = match_self($w); |
|
| 795 | - if ($sous[0] == 'SELF') { |
|
| 796 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 797 | - array_push($where_simples, $sous[2]); |
|
| 798 | - $wheresub = array( |
|
| 799 | - $sous[2], |
|
| 800 | - '0=0' |
|
| 801 | - ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 802 | - $jsub = $join; |
|
| 803 | - // trouver les jointures utiles a |
|
| 804 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 805 | - // ie L1.objet='article' |
|
| 806 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 807 | - $i = 0; |
|
| 808 | - do { |
|
| 809 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 810 | - array($sous[1] . " AS id"), |
|
| 811 | - $from, |
|
| 812 | - $from_type, |
|
| 813 | - $wheresub, |
|
| 814 | - $jsub, |
|
| 815 | - array(), array(), '', |
|
| 816 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 817 | - if (!$i) { |
|
| 818 | - $i = 1; |
|
| 819 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 820 | - foreach ($join as $cle => $wj) { |
|
| 821 | - if (count($wj) == 4 |
|
| 822 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 823 | - ) { |
|
| 824 | - $i = 0; |
|
| 825 | - $wheresub[] = $wj[3]; |
|
| 826 | - unset($jsub[$cle][3]); |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - } |
|
| 830 | - } while ($i++ < 1); |
|
| 831 | - } |
|
| 832 | - if ($sous[0] == 'SUBSELECT') { |
|
| 833 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 834 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 835 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 836 | - $sous[1], # select |
|
| 837 | - $sous[2], #from |
|
| 838 | - array(), #from_type |
|
| 839 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 840 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 841 | - array(), #join |
|
| 842 | - $sous[4] ? $sous[4] : array(), #groupby |
|
| 843 | - $sous[5] ? $sous[5] : array(), #orderby |
|
| 844 | - $sous[6], #limit |
|
| 845 | - $sous[7] ? $sous[7] : array(), #having |
|
| 846 | - $table, $id, $serveur, false |
|
| 847 | - ) . ")"); |
|
| 848 | - } |
|
| 849 | - array_pop($where_simples); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - foreach ($having as $k => $v) { |
|
| 853 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 854 | - unset($having[$k]); |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - // Installer les jointures. |
|
| 859 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 860 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 861 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 862 | - |
|
| 863 | - $afrom = array(); |
|
| 864 | - $equiv = array(); |
|
| 865 | - $k = count($join); |
|
| 866 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 867 | - $cle = $cledef; |
|
| 868 | - // le format de join est : |
|
| 869 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 870 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 871 | - if (count($join[$cle]) == 2) { |
|
| 872 | - $join[$cle][] = $join[$cle][1]; |
|
| 873 | - } |
|
| 874 | - if (count($join[$cle]) == 3) { |
|
| 875 | - $join[$cle][] = ''; |
|
| 876 | - } |
|
| 877 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 878 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 879 | - // pour compat avec ancienne convention |
|
| 880 | - if (is_numeric($cle)) { |
|
| 881 | - $cle = "L$k"; |
|
| 882 | - } |
|
| 883 | - if (!$menage |
|
| 884 | - or isset($afrom[$cle]) |
|
| 885 | - or calculer_jointnul($cle, $select) |
|
| 886 | - or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 887 | - or calculer_jointnul($cle, $having) |
|
| 888 | - or calculer_jointnul($cle, $where_simples) |
|
| 889 | - ) { |
|
| 890 | - // corriger les references non explicites dans select |
|
| 891 | - // ou groupby |
|
| 892 | - foreach ($select as $i => $s) { |
|
| 893 | - if ($s == $c) { |
|
| 894 | - $select[$i] = "$cle.$c AS $c"; |
|
| 895 | - break; |
|
| 896 | - } |
|
| 897 | - } |
|
| 898 | - foreach ($groupby as $i => $g) { |
|
| 899 | - if ($g == $c) { |
|
| 900 | - $groupby[$i] = "$cle.$c"; |
|
| 901 | - break; |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 905 | - // sans recours a preg_match |
|
| 906 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 907 | - $afrom[$t][$cle] = array( |
|
| 908 | - "\n" . |
|
| 909 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 910 | - $from[$cle], |
|
| 911 | - "AS $cle", |
|
| 912 | - "ON (", |
|
| 913 | - "$cle.$c", |
|
| 914 | - "=", |
|
| 915 | - "$t.$carr", |
|
| 916 | - ($and ? "AND " . $and : "") . |
|
| 917 | - ")" |
|
| 918 | - ); |
|
| 919 | - if (isset($afrom[$cle])) { |
|
| 920 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 921 | - unset($afrom[$cle]); |
|
| 922 | - } |
|
| 923 | - $equiv[] = $carr; |
|
| 924 | - } else { |
|
| 925 | - unset($join[$cledef]); |
|
| 926 | - } |
|
| 927 | - unset($from[$cle]); |
|
| 928 | - $k--; |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - if (count($afrom)) { |
|
| 932 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 933 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 934 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 935 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 936 | - // ou dans |
|
| 937 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 938 | - // qui comporte plusieurs jointures |
|
| 939 | - // ou dans |
|
| 940 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 941 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 942 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 943 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 944 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 945 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 946 | - |
|
| 947 | - $t = key($from); |
|
| 948 | - $c = current($from); |
|
| 949 | - reset($from); |
|
| 950 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 951 | - if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 952 | - calculer_jointnul($t, $select, $e) or |
|
| 953 | - calculer_jointnul($t, $join, $e) or |
|
| 954 | - calculer_jointnul($t, $where, $e) or |
|
| 955 | - calculer_jointnul($t, $orderby, $e) or |
|
| 956 | - calculer_jointnul($t, $groupby, $e) or |
|
| 957 | - calculer_jointnul($t, $having, $e)) |
|
| 958 | - && count($afrom[$t]) |
|
| 959 | - ) { |
|
| 960 | - $nfrom = reset($afrom[$t]); |
|
| 961 | - $nt = key($afrom[$t]); |
|
| 962 | - unset($from[$t]); |
|
| 963 | - $from[$nt] = $nfrom[1]; |
|
| 964 | - unset($afrom[$t][$nt]); |
|
| 965 | - $afrom[$nt] = $afrom[$t]; |
|
| 966 | - unset($afrom[$t]); |
|
| 967 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 968 | - $t = $nfrom[4]; |
|
| 969 | - $alias = ""; |
|
| 970 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 971 | - $oldcle = explode('.', $nfrom[6]); |
|
| 972 | - $oldcle = end($oldcle); |
|
| 973 | - $newcle = explode('.', $nfrom[4]); |
|
| 974 | - $newcle = end($newcle); |
|
| 975 | - if ($newcle != $oldcle) { |
|
| 976 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 977 | - // reprendre simplement ce AS |
|
| 978 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 979 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 980 | - $alias = ""; |
|
| 981 | - } else { |
|
| 982 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 986 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 987 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 988 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 989 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 990 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 991 | - } |
|
| 992 | - $from = reinjecte_joint($afrom, $from); |
|
| 993 | - } |
|
| 994 | - $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 995 | - $r = sql_select($select, $from, $where, |
|
| 996 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 997 | - unset($GLOBALS['debug']['aucasou']); |
|
| 998 | - |
|
| 999 | - return $r; |
|
| 763 | + // retirer les criteres vides: |
|
| 764 | + // {X ?} avec X absent de l'URL |
|
| 765 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 766 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 767 | + $menage = false; |
|
| 768 | + foreach ($where as $k => $v) { |
|
| 769 | + if (is_array($v)) { |
|
| 770 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 771 | + $op = false; |
|
| 772 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 773 | + $op = false; |
|
| 774 | + } else { |
|
| 775 | + $op = $v[0] ? $v[0] : $v; |
|
| 776 | + } |
|
| 777 | + } else { |
|
| 778 | + $op = $v; |
|
| 779 | + } |
|
| 780 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 781 | + unset($where[$k]); |
|
| 782 | + $menage = true; |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 787 | + $groupby = array_diff($groupby, array('')); |
|
| 788 | + |
|
| 789 | + // remplacer les sous requetes recursives au calcul |
|
| 790 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 791 | + foreach ($where_sous as $k => $w) { |
|
| 792 | + $menage = true; |
|
| 793 | + // on recupere la sous requete |
|
| 794 | + $sous = match_self($w); |
|
| 795 | + if ($sous[0] == 'SELF') { |
|
| 796 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 797 | + array_push($where_simples, $sous[2]); |
|
| 798 | + $wheresub = array( |
|
| 799 | + $sous[2], |
|
| 800 | + '0=0' |
|
| 801 | + ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 802 | + $jsub = $join; |
|
| 803 | + // trouver les jointures utiles a |
|
| 804 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 805 | + // ie L1.objet='article' |
|
| 806 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 807 | + $i = 0; |
|
| 808 | + do { |
|
| 809 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 810 | + array($sous[1] . " AS id"), |
|
| 811 | + $from, |
|
| 812 | + $from_type, |
|
| 813 | + $wheresub, |
|
| 814 | + $jsub, |
|
| 815 | + array(), array(), '', |
|
| 816 | + $having, $table, $id, $serveur, false) . ")"); |
|
| 817 | + if (!$i) { |
|
| 818 | + $i = 1; |
|
| 819 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 820 | + foreach ($join as $cle => $wj) { |
|
| 821 | + if (count($wj) == 4 |
|
| 822 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 823 | + ) { |
|
| 824 | + $i = 0; |
|
| 825 | + $wheresub[] = $wj[3]; |
|
| 826 | + unset($jsub[$cle][3]); |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + } |
|
| 830 | + } while ($i++ < 1); |
|
| 831 | + } |
|
| 832 | + if ($sous[0] == 'SUBSELECT') { |
|
| 833 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 834 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 835 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 836 | + $sous[1], # select |
|
| 837 | + $sous[2], #from |
|
| 838 | + array(), #from_type |
|
| 839 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 840 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 841 | + array(), #join |
|
| 842 | + $sous[4] ? $sous[4] : array(), #groupby |
|
| 843 | + $sous[5] ? $sous[5] : array(), #orderby |
|
| 844 | + $sous[6], #limit |
|
| 845 | + $sous[7] ? $sous[7] : array(), #having |
|
| 846 | + $table, $id, $serveur, false |
|
| 847 | + ) . ")"); |
|
| 848 | + } |
|
| 849 | + array_pop($where_simples); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + foreach ($having as $k => $v) { |
|
| 853 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 854 | + unset($having[$k]); |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + // Installer les jointures. |
|
| 859 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 860 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 861 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 862 | + |
|
| 863 | + $afrom = array(); |
|
| 864 | + $equiv = array(); |
|
| 865 | + $k = count($join); |
|
| 866 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 867 | + $cle = $cledef; |
|
| 868 | + // le format de join est : |
|
| 869 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 870 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 871 | + if (count($join[$cle]) == 2) { |
|
| 872 | + $join[$cle][] = $join[$cle][1]; |
|
| 873 | + } |
|
| 874 | + if (count($join[$cle]) == 3) { |
|
| 875 | + $join[$cle][] = ''; |
|
| 876 | + } |
|
| 877 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 878 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 879 | + // pour compat avec ancienne convention |
|
| 880 | + if (is_numeric($cle)) { |
|
| 881 | + $cle = "L$k"; |
|
| 882 | + } |
|
| 883 | + if (!$menage |
|
| 884 | + or isset($afrom[$cle]) |
|
| 885 | + or calculer_jointnul($cle, $select) |
|
| 886 | + or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 887 | + or calculer_jointnul($cle, $having) |
|
| 888 | + or calculer_jointnul($cle, $where_simples) |
|
| 889 | + ) { |
|
| 890 | + // corriger les references non explicites dans select |
|
| 891 | + // ou groupby |
|
| 892 | + foreach ($select as $i => $s) { |
|
| 893 | + if ($s == $c) { |
|
| 894 | + $select[$i] = "$cle.$c AS $c"; |
|
| 895 | + break; |
|
| 896 | + } |
|
| 897 | + } |
|
| 898 | + foreach ($groupby as $i => $g) { |
|
| 899 | + if ($g == $c) { |
|
| 900 | + $groupby[$i] = "$cle.$c"; |
|
| 901 | + break; |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 905 | + // sans recours a preg_match |
|
| 906 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 907 | + $afrom[$t][$cle] = array( |
|
| 908 | + "\n" . |
|
| 909 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 910 | + $from[$cle], |
|
| 911 | + "AS $cle", |
|
| 912 | + "ON (", |
|
| 913 | + "$cle.$c", |
|
| 914 | + "=", |
|
| 915 | + "$t.$carr", |
|
| 916 | + ($and ? "AND " . $and : "") . |
|
| 917 | + ")" |
|
| 918 | + ); |
|
| 919 | + if (isset($afrom[$cle])) { |
|
| 920 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 921 | + unset($afrom[$cle]); |
|
| 922 | + } |
|
| 923 | + $equiv[] = $carr; |
|
| 924 | + } else { |
|
| 925 | + unset($join[$cledef]); |
|
| 926 | + } |
|
| 927 | + unset($from[$cle]); |
|
| 928 | + $k--; |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + if (count($afrom)) { |
|
| 932 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 933 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 934 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 935 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 936 | + // ou dans |
|
| 937 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 938 | + // qui comporte plusieurs jointures |
|
| 939 | + // ou dans |
|
| 940 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 941 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 942 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 943 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 944 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 945 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 946 | + |
|
| 947 | + $t = key($from); |
|
| 948 | + $c = current($from); |
|
| 949 | + reset($from); |
|
| 950 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 951 | + if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 952 | + calculer_jointnul($t, $select, $e) or |
|
| 953 | + calculer_jointnul($t, $join, $e) or |
|
| 954 | + calculer_jointnul($t, $where, $e) or |
|
| 955 | + calculer_jointnul($t, $orderby, $e) or |
|
| 956 | + calculer_jointnul($t, $groupby, $e) or |
|
| 957 | + calculer_jointnul($t, $having, $e)) |
|
| 958 | + && count($afrom[$t]) |
|
| 959 | + ) { |
|
| 960 | + $nfrom = reset($afrom[$t]); |
|
| 961 | + $nt = key($afrom[$t]); |
|
| 962 | + unset($from[$t]); |
|
| 963 | + $from[$nt] = $nfrom[1]; |
|
| 964 | + unset($afrom[$t][$nt]); |
|
| 965 | + $afrom[$nt] = $afrom[$t]; |
|
| 966 | + unset($afrom[$t]); |
|
| 967 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 968 | + $t = $nfrom[4]; |
|
| 969 | + $alias = ""; |
|
| 970 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 971 | + $oldcle = explode('.', $nfrom[6]); |
|
| 972 | + $oldcle = end($oldcle); |
|
| 973 | + $newcle = explode('.', $nfrom[4]); |
|
| 974 | + $newcle = end($newcle); |
|
| 975 | + if ($newcle != $oldcle) { |
|
| 976 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 977 | + // reprendre simplement ce AS |
|
| 978 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 979 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 980 | + $alias = ""; |
|
| 981 | + } else { |
|
| 982 | + $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 986 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 987 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 988 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 989 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 990 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 991 | + } |
|
| 992 | + $from = reinjecte_joint($afrom, $from); |
|
| 993 | + } |
|
| 994 | + $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 995 | + $r = sql_select($select, $from, $where, |
|
| 996 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 997 | + unset($GLOBALS['debug']['aucasou']); |
|
| 998 | + |
|
| 999 | + return $r; |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | /** |
@@ -1007,20 +1007,20 @@ discard block |
||
| 1007 | 1007 | * @return string |
| 1008 | 1008 | */ |
| 1009 | 1009 | function calculer_where_to_string($v, $join = 'AND') { |
| 1010 | - if (empty($v)) { |
|
| 1011 | - return ''; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - if (!is_array($v)) { |
|
| 1015 | - return $v; |
|
| 1016 | - } else { |
|
| 1017 | - $exp = ""; |
|
| 1018 | - if (strtoupper($join) === 'AND') { |
|
| 1019 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1020 | - } else { |
|
| 1021 | - return $exp . join($join, $v); |
|
| 1022 | - } |
|
| 1023 | - } |
|
| 1010 | + if (empty($v)) { |
|
| 1011 | + return ''; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + if (!is_array($v)) { |
|
| 1015 | + return $v; |
|
| 1016 | + } else { |
|
| 1017 | + $exp = ""; |
|
| 1018 | + if (strtoupper($join) === 'AND') { |
|
| 1019 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1020 | + } else { |
|
| 1021 | + return $exp . join($join, $v); |
|
| 1022 | + } |
|
| 1023 | + } |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | |
@@ -1028,62 +1028,62 @@ discard block |
||
| 1028 | 1028 | |
| 1029 | 1029 | // http://code.spip.net/@calculer_jointnul |
| 1030 | 1030 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1031 | - if (!is_array($exp)) { |
|
| 1032 | - if ($equiv) { |
|
| 1033 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1037 | - } else { |
|
| 1038 | - foreach ($exp as $v) { |
|
| 1039 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1040 | - return true; |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - return false; |
|
| 1045 | - } |
|
| 1031 | + if (!is_array($exp)) { |
|
| 1032 | + if ($equiv) { |
|
| 1033 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1037 | + } else { |
|
| 1038 | + foreach ($exp as $v) { |
|
| 1039 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1040 | + return true; |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + return false; |
|
| 1045 | + } |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | // http://code.spip.net/@reinjecte_joint |
| 1049 | 1049 | function reinjecte_joint($afrom, $from) { |
| 1050 | - $from_synth = array(); |
|
| 1051 | - foreach ($from as $k => $v) { |
|
| 1052 | - $from_synth[$k] = $from[$k]; |
|
| 1053 | - if (isset($afrom[$k])) { |
|
| 1054 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1055 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1056 | - } |
|
| 1057 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1058 | - unset($afrom[$k]); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - return $from_synth; |
|
| 1050 | + $from_synth = array(); |
|
| 1051 | + foreach ($from as $k => $v) { |
|
| 1052 | + $from_synth[$k] = $from[$k]; |
|
| 1053 | + if (isset($afrom[$k])) { |
|
| 1054 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1055 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1056 | + } |
|
| 1057 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1058 | + unset($afrom[$k]); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + return $from_synth; |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // http://code.spip.net/@remplacer_jointnul |
| 1066 | 1066 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1067 | - if (!is_array($exp)) { |
|
| 1068 | - return preg_replace($equiv, $cle, $exp); |
|
| 1069 | - } else { |
|
| 1070 | - foreach ($exp as $k => $v) { |
|
| 1071 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - return $exp; |
|
| 1075 | - } |
|
| 1067 | + if (!is_array($exp)) { |
|
| 1068 | + return preg_replace($equiv, $cle, $exp); |
|
| 1069 | + } else { |
|
| 1070 | + foreach ($exp as $k => $v) { |
|
| 1071 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + return $exp; |
|
| 1075 | + } |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | // calcul du nom du squelette |
| 1079 | 1079 | // http://code.spip.net/@calculer_nom_fonction_squel |
| 1080 | 1080 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 1081 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1082 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1083 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - return $mime_type |
|
| 1087 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1088 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1081 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1082 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1083 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + return $mime_type |
|
| 1087 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1088 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1089 | 1089 | } |
@@ -358,10 +358,12 @@ discard block |
||
| 358 | 358 | |
| 359 | 359 | // et reparagrapher si necessaire (coherence avec le cas descriptif) |
| 360 | 360 | // une introduction a tojours un <p> |
| 361 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 361 | + if ($GLOBALS['toujours_paragrapher']) { |
|
| 362 | + // Fermer les paragraphes |
|
| 362 | 363 | { |
| 363 | 364 | $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
| 364 | 365 | } |
| 366 | + } |
|
| 365 | 367 | |
| 366 | 368 | return $texte; |
| 367 | 369 | } |
@@ -546,8 +548,7 @@ discard block |
||
| 546 | 548 | if ($ids) { |
| 547 | 549 | $ids = array_column($ids, 'id_objet'); |
| 548 | 550 | return implode(',', $ids); |
| 549 | - } |
|
| 550 | - else { |
|
| 551 | + } else { |
|
| 551 | 552 | return "0"; |
| 552 | 553 | } |
| 553 | 554 | } |
@@ -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,15 +540,15 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $boucle = &$boucles[$idb]; |
|
| 544 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | - $serveur = $boucle->sql_serveur; |
|
| 543 | + $boucle = &$boucles[$idb]; |
|
| 544 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 545 | + $serveur = $boucle->sql_serveur; |
|
| 546 | 546 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | + $c = "sql_in('" . |
|
| 548 | + $boucle->id_table . '.' . $boucle->primary |
|
| 549 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 550 | 550 | |
| 551 | - $boucle->where[] = $c; |
|
| 551 | + $boucle->where[] = $c; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -570,31 +570,31 @@ discard block |
||
| 570 | 570 | * @return void |
| 571 | 571 | **/ |
| 572 | 572 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 573 | - if ($t = isset($crit->param[0])) { |
|
| 574 | - $t = $crit->param[0]; |
|
| 575 | - if ($t[0]->type == 'texte') { |
|
| 576 | - $t = $t[0]->texte; |
|
| 577 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | - $t = table_objet_sql($r[1]); |
|
| 579 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | - if ($t) { |
|
| 581 | - $t .= '.' . $r[2]; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - } else { |
|
| 585 | - $t = '".' |
|
| 586 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | - . '."'; |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - if ($t) { |
|
| 591 | - $boucles[$idb]->group[] = $t; |
|
| 592 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | - $boucles[$idb]->select[] = $t; |
|
| 594 | - } |
|
| 595 | - } else { |
|
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | - } |
|
| 573 | + if ($t = isset($crit->param[0])) { |
|
| 574 | + $t = $crit->param[0]; |
|
| 575 | + if ($t[0]->type == 'texte') { |
|
| 576 | + $t = $t[0]->texte; |
|
| 577 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 578 | + $t = table_objet_sql($r[1]); |
|
| 579 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 580 | + if ($t) { |
|
| 581 | + $t .= '.' . $r[2]; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + } else { |
|
| 585 | + $t = '".' |
|
| 586 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 587 | + . '."'; |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + if ($t) { |
|
| 591 | + $boucles[$idb]->group[] = $t; |
|
| 592 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 593 | + $boucles[$idb]->select[] = $t; |
|
| 594 | + } |
|
| 595 | + } else { |
|
| 596 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 597 | + } |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -631,45 +631,45 @@ discard block |
||
| 631 | 631 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 632 | 632 | */ |
| 633 | 633 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 634 | - if (isset($crit->param[0])) { |
|
| 635 | - $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 636 | - $boucle = $boucles[$idb]; |
|
| 637 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | - $n = count($boucle->order); |
|
| 639 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | - if ( |
|
| 643 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | - OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | - ) { |
|
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | - } else { |
|
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | - } |
|
| 634 | + if (isset($crit->param[0])) { |
|
| 635 | + $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 636 | + $boucle = $boucles[$idb]; |
|
| 637 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 638 | + $n = count($boucle->order); |
|
| 639 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 640 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 641 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 642 | + if ( |
|
| 643 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 644 | + OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 645 | + ) { |
|
| 646 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 647 | + } else { |
|
| 648 | + $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 653 | + } |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 657 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | - $boucle = $boucles[$idb]; |
|
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 661 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | - if (!$desc) { |
|
| 663 | - $desc = $boucle->show['field']; |
|
| 664 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | - } |
|
| 667 | - if ($desc) { |
|
| 668 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | - } |
|
| 670 | - $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 671 | - |
|
| 672 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 658 | + $boucle = $boucles[$idb]; |
|
| 659 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | + $var = '$champs_' . $idb; |
|
| 661 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 662 | + if (!$desc) { |
|
| 663 | + $desc = $boucle->show['field']; |
|
| 664 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 665 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 666 | + } |
|
| 667 | + if ($desc) { |
|
| 668 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 669 | + } |
|
| 670 | + $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 671 | + |
|
| 672 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 709 | 709 | */ |
| 710 | 710 | function critere_par_dist($idb, &$boucles, $crit) { |
| 711 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 711 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -730,93 +730,93 @@ discard block |
||
| 730 | 730 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 731 | 731 | */ |
| 732 | 732 | function critere_parinverse($idb, &$boucles, $crit) { |
| 733 | - $boucle = &$boucles[$idb]; |
|
| 734 | - |
|
| 735 | - $sens = $collecte = ''; |
|
| 736 | - if ($crit->not) { |
|
| 737 | - $sens = " . ' DESC'"; |
|
| 738 | - } |
|
| 739 | - if (isset($boucle->modificateur['collate'])) { |
|
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Pour chaque paramètre du critère |
|
| 744 | - foreach ($crit->param as $tri) { |
|
| 745 | - $order = $fct = ''; |
|
| 746 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | - if ($tri[0]->type != 'texte') { |
|
| 748 | - // calculer le order dynamique qui verifie les champs |
|
| 749 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | - } |
|
| 753 | - // tris textuels {par titre} |
|
| 754 | - else { |
|
| 755 | - $par = array_shift($tri); |
|
| 756 | - $par = $par->texte; |
|
| 757 | - |
|
| 758 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | - if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | - $expression = trim($m[1]); |
|
| 761 | - $champ = trim($m[2]); |
|
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | - } else { |
|
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | - // {par FONCTION(champ)} |
|
| 771 | - if (count($match) > 2) { |
|
| 772 | - $par = substr($match[2], 1, -1); |
|
| 773 | - $fct = $match[1]; |
|
| 774 | - } |
|
| 775 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | - if ($par == 'hasard') { |
|
| 777 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | - } else { |
|
| 781 | - // cas général {par champ}, {par table.champ}, ... |
|
| 782 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | - } |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - // on ne sait pas traiter… |
|
| 787 | - else { |
|
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | - if (is_array($order)) { |
|
| 793 | - return $order; |
|
| 794 | - } |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | - $t = $m[1]; |
|
| 799 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | - $boucle->select[] = $t; |
|
| 801 | - } |
|
| 802 | - } else { |
|
| 803 | - $sens = ''; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - if ($fct) { |
|
| 807 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | - } else { |
|
| 810 | - $order = "'$fct(' . $order . ')'"; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - $t = $order . $collecte . $sens; |
|
| 814 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | - $t = $r[1] . $r[2]; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - $boucle->order[] = $t; |
|
| 819 | - } |
|
| 733 | + $boucle = &$boucles[$idb]; |
|
| 734 | + |
|
| 735 | + $sens = $collecte = ''; |
|
| 736 | + if ($crit->not) { |
|
| 737 | + $sens = " . ' DESC'"; |
|
| 738 | + } |
|
| 739 | + if (isset($boucle->modificateur['collate'])) { |
|
| 740 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Pour chaque paramètre du critère |
|
| 744 | + foreach ($crit->param as $tri) { |
|
| 745 | + $order = $fct = ''; |
|
| 746 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 747 | + if ($tri[0]->type != 'texte') { |
|
| 748 | + // calculer le order dynamique qui verifie les champs |
|
| 749 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 750 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 751 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 752 | + } |
|
| 753 | + // tris textuels {par titre} |
|
| 754 | + else { |
|
| 755 | + $par = array_shift($tri); |
|
| 756 | + $par = $par->texte; |
|
| 757 | + |
|
| 758 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 759 | + if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 760 | + $expression = trim($m[1]); |
|
| 761 | + $champ = trim($m[2]); |
|
| 762 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 763 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 764 | + } else { |
|
| 765 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 769 | + } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 770 | + // {par FONCTION(champ)} |
|
| 771 | + if (count($match) > 2) { |
|
| 772 | + $par = substr($match[2], 1, -1); |
|
| 773 | + $fct = $match[1]; |
|
| 774 | + } |
|
| 775 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 776 | + if ($par == 'hasard') { |
|
| 777 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 778 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 779 | + $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 780 | + } else { |
|
| 781 | + // cas général {par champ}, {par table.champ}, ... |
|
| 782 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + // on ne sait pas traiter… |
|
| 787 | + else { |
|
| 788 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 792 | + if (is_array($order)) { |
|
| 793 | + return $order; |
|
| 794 | + } |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 798 | + $t = $m[1]; |
|
| 799 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 800 | + $boucle->select[] = $t; |
|
| 801 | + } |
|
| 802 | + } else { |
|
| 803 | + $sens = ''; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + if ($fct) { |
|
| 807 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 808 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 809 | + } else { |
|
| 810 | + $order = "'$fct(' . $order . ')'"; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + $t = $order . $collecte . $sens; |
|
| 814 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 815 | + $t = $r[1] . $r[2]; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + $boucle->order[] = $t; |
|
| 819 | + } |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -830,13 +830,13 @@ discard block |
||
| 830 | 830 | * @return string Clause pour le Order by |
| 831 | 831 | */ |
| 832 | 832 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 833 | - $boucle = &$boucles[$idb]; |
|
| 834 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | - $parha = "rand() AS hasard"; |
|
| 836 | - if (!in_array($parha, $boucle->select)) { |
|
| 837 | - $boucle->select[] = $parha; |
|
| 838 | - } |
|
| 839 | - return "'hasard'"; |
|
| 833 | + $boucle = &$boucles[$idb]; |
|
| 834 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 835 | + $parha = "rand() AS hasard"; |
|
| 836 | + if (!in_array($parha, $boucle->select)) { |
|
| 837 | + $boucle->select[] = $parha; |
|
| 838 | + } |
|
| 839 | + return "'hasard'"; |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | /** |
@@ -860,20 +860,20 @@ discard block |
||
| 860 | 860 | * @return string Clause pour le Order by |
| 861 | 861 | */ |
| 862 | 862 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | - if (is_array($_champ)) { |
|
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | - } |
|
| 867 | - $boucle = &$boucles[$idb]; |
|
| 868 | - $texte = '0+' . $_champ; |
|
| 869 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 870 | - if ($suite !== "''") { |
|
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | - } |
|
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 875 | - $order = "'$as'"; |
|
| 876 | - return $order; |
|
| 863 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 864 | + if (is_array($_champ)) { |
|
| 865 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 866 | + } |
|
| 867 | + $boucle = &$boucles[$idb]; |
|
| 868 | + $texte = '0+' . $_champ; |
|
| 869 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 870 | + if ($suite !== "''") { |
|
| 871 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 872 | + } |
|
| 873 | + $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | + $boucle->select[] = $texte . " AS $as"; |
|
| 875 | + $order = "'$as'"; |
|
| 876 | + return $order; |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | /** |
@@ -894,20 +894,20 @@ discard block |
||
| 894 | 894 | * @return string Clause pour le Order by |
| 895 | 895 | */ |
| 896 | 896 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | - if (is_array($_champ)) { |
|
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | - } |
|
| 901 | - $boucle = &$boucles[$idb]; |
|
| 902 | - $texte = '0+' . $_champ; |
|
| 903 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 904 | - if ($suite !== "''") { |
|
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | - } |
|
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | - $order = "'$as'"; |
|
| 910 | - return $order; |
|
| 897 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 898 | + if (is_array($_champ)) { |
|
| 899 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 900 | + } |
|
| 901 | + $boucle = &$boucles[$idb]; |
|
| 902 | + $texte = '0+' . $_champ; |
|
| 903 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 904 | + if ($suite !== "''") { |
|
| 905 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 906 | + } |
|
| 907 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | + $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 909 | + $order = "'$as'"; |
|
| 910 | + return $order; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | |
@@ -927,14 +927,14 @@ discard block |
||
| 927 | 927 | * @return string Clause pour le Order by |
| 928 | 928 | */ |
| 929 | 929 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | - if (is_array($_champ)) { |
|
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | - } |
|
| 934 | - $boucle = &$boucles[$idb]; |
|
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | - $order = "'multi'"; |
|
| 937 | - return $order; |
|
| 930 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 931 | + if (is_array($_champ)) { |
|
| 932 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 933 | + } |
|
| 934 | + $boucle = &$boucles[$idb]; |
|
| 935 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 936 | + $order = "'multi'"; |
|
| 937 | + return $order; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -953,56 +953,56 @@ discard block |
||
| 953 | 953 | * @return array|string |
| 954 | 954 | */ |
| 955 | 955 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 956 | - $boucle = &$boucles[$idb]; |
|
| 957 | - $desc = $boucle->show; |
|
| 958 | - |
|
| 959 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | - if (isset($desc['field'][$par])) { |
|
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 962 | - } |
|
| 963 | - // le champ est peut être une jointure |
|
| 964 | - else { |
|
| 965 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | - $champ = $par; |
|
| 967 | - |
|
| 968 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | - list(, $table, $champ) = $r; |
|
| 974 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | - $table = table_objet_sql($table); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 983 | - } elseif ( |
|
| 984 | - $boucle->jointures_explicites |
|
| 985 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | - ) { |
|
| 987 | - $par = $alias . "." . $champ; |
|
| 988 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | - $par = $alias . "." . $champ; |
|
| 990 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | - } elseif ( |
|
| 992 | - $table_alias |
|
| 993 | - and isset($boucle->from[$table_alias]) |
|
| 994 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | - ) { |
|
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 997 | - } elseif ($table) { |
|
| 998 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | - } else { |
|
| 1001 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return $raw ? $par : "'$par'"; |
|
| 956 | + $boucle = &$boucles[$idb]; |
|
| 957 | + $desc = $boucle->show; |
|
| 958 | + |
|
| 959 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 960 | + if (isset($desc['field'][$par])) { |
|
| 961 | + $par = $boucle->id_table . "." . $par; |
|
| 962 | + } |
|
| 963 | + // le champ est peut être une jointure |
|
| 964 | + else { |
|
| 965 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 966 | + $champ = $par; |
|
| 967 | + |
|
| 968 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 969 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 970 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 971 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 972 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 973 | + list(, $table, $champ) = $r; |
|
| 974 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 975 | + $table = table_objet_sql($table); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 979 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 980 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 981 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 982 | + $par = $infos['alias'] . "." . $champ; |
|
| 983 | + } elseif ( |
|
| 984 | + $boucle->jointures_explicites |
|
| 985 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 986 | + ) { |
|
| 987 | + $par = $alias . "." . $champ; |
|
| 988 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 989 | + $par = $alias . "." . $champ; |
|
| 990 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 991 | + } elseif ( |
|
| 992 | + $table_alias |
|
| 993 | + and isset($boucle->from[$table_alias]) |
|
| 994 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 995 | + ) { |
|
| 996 | + $par = $infos['alias'] . "." . $champ; |
|
| 997 | + } elseif ($table) { |
|
| 998 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 999 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1000 | + } else { |
|
| 1001 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return $raw ? $par : "'$par'"; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1016,11 +1016,11 @@ discard block |
||
| 1016 | 1016 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1017 | 1017 | */ |
| 1018 | 1018 | function critere_par_joint($table, $champ, &$boucle) { |
| 1019 | - $t = array_search($table, $boucle->from); |
|
| 1020 | - if (!$t) { |
|
| 1021 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | - } |
|
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1019 | + $t = array_search($table, $boucle->from); |
|
| 1020 | + if (!$t) { |
|
| 1021 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1022 | + } |
|
| 1023 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | /** |
@@ -1045,143 +1045,143 @@ discard block |
||
| 1045 | 1045 | */ |
| 1046 | 1046 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1047 | 1047 | |
| 1048 | - $boucle = &$boucles[$idb]; |
|
| 1049 | - // Classement par ordre inverse |
|
| 1050 | - if ($crit->not) { |
|
| 1051 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | - } else { |
|
| 1053 | - $order = "' DESC'"; |
|
| 1054 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | - if (isset($crit->param[0])) { |
|
| 1056 | - $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | - $order = "(($critere)?' DESC':'')"; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - $n = count($boucle->order); |
|
| 1061 | - if (!$n) { |
|
| 1062 | - if (isset($boucle->default_order[0])) { |
|
| 1063 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | - } else { |
|
| 1065 | - $boucle->default_order[] = ' DESC'; |
|
| 1066 | - } |
|
| 1067 | - } else { |
|
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1071 | - } |
|
| 1072 | - $boucle->order[$n - 1] = $t; |
|
| 1073 | - } |
|
| 1074 | - } |
|
| 1048 | + $boucle = &$boucles[$idb]; |
|
| 1049 | + // Classement par ordre inverse |
|
| 1050 | + if ($crit->not) { |
|
| 1051 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1052 | + } else { |
|
| 1053 | + $order = "' DESC'"; |
|
| 1054 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1055 | + if (isset($crit->param[0])) { |
|
| 1056 | + $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1057 | + $order = "(($critere)?' DESC':'')"; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + $n = count($boucle->order); |
|
| 1061 | + if (!$n) { |
|
| 1062 | + if (isset($boucle->default_order[0])) { |
|
| 1063 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1064 | + } else { |
|
| 1065 | + $boucle->default_order[] = ' DESC'; |
|
| 1066 | + } |
|
| 1067 | + } else { |
|
| 1068 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1069 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1070 | + $t = $r[1] . $r[2]; |
|
| 1071 | + } |
|
| 1072 | + $boucle->order[$n - 1] = $t; |
|
| 1073 | + } |
|
| 1074 | + } |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // http://code.spip.net/@critere_agenda_dist |
| 1078 | 1078 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1079 | - $params = $crit->param; |
|
| 1080 | - |
|
| 1081 | - if (count($params) < 1) { |
|
| 1082 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - $boucle = &$boucles[$idb]; |
|
| 1086 | - $parent = $boucle->id_parent; |
|
| 1087 | - $fields = $boucle->show['field']; |
|
| 1088 | - |
|
| 1089 | - $date = array_shift($params); |
|
| 1090 | - $type = array_shift($params); |
|
| 1091 | - |
|
| 1092 | - // la valeur $type doit etre connue a la compilation |
|
| 1093 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | - |
|
| 1096 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | - $date = $date[0]->texte; |
|
| 1102 | - if (!isset($fields[$date])) { |
|
| 1103 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | - } |
|
| 1105 | - } else { |
|
| 1106 | - $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1107 | - $noms = array_keys($fields); |
|
| 1108 | - $defaut = $noms[0]; |
|
| 1109 | - $noms = join(" ", $noms); |
|
| 1110 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | - } |
|
| 1114 | - $annee = $params ? array_shift($params) : ""; |
|
| 1115 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1117 | - ') ? $x : date("Y"))'; |
|
| 1118 | - |
|
| 1119 | - $mois = $params ? array_shift($params) : ""; |
|
| 1120 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1122 | - ') ? $x : date("m"))'; |
|
| 1123 | - |
|
| 1124 | - $jour = $params ? array_shift($params) : ""; |
|
| 1125 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1127 | - ') ? $x : date("d"))'; |
|
| 1128 | - |
|
| 1129 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1132 | - ') ? $x : date("Y"))'; |
|
| 1133 | - |
|
| 1134 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1137 | - ') ? $x : date("m"))'; |
|
| 1138 | - |
|
| 1139 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1142 | - ') ? $x : date("d"))'; |
|
| 1143 | - |
|
| 1144 | - $date = $boucle->id_table . ".$date"; |
|
| 1145 | - |
|
| 1146 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | - if ($type == 'jour') { |
|
| 1148 | - $boucle->where[] = array( |
|
| 1149 | - "'='", |
|
| 1150 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | - ); |
|
| 1153 | - } elseif ($type == 'mois') { |
|
| 1154 | - $boucle->where[] = array( |
|
| 1155 | - "'='", |
|
| 1156 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | - ); |
|
| 1159 | - } elseif ($type == 'semaine') { |
|
| 1160 | - $boucle->where[] = array( |
|
| 1161 | - "'AND'", |
|
| 1162 | - array( |
|
| 1163 | - "'>='", |
|
| 1164 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | - ), |
|
| 1167 | - array( |
|
| 1168 | - "'<='", |
|
| 1169 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | - ) |
|
| 1172 | - ); |
|
| 1173 | - } elseif (count($crit->param) > 2) { |
|
| 1174 | - $boucle->where[] = array( |
|
| 1175 | - "'AND'", |
|
| 1176 | - array( |
|
| 1177 | - "'>='", |
|
| 1178 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | - ), |
|
| 1181 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | - ); |
|
| 1183 | - } |
|
| 1184 | - // sinon on prend tout |
|
| 1079 | + $params = $crit->param; |
|
| 1080 | + |
|
| 1081 | + if (count($params) < 1) { |
|
| 1082 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + $boucle = &$boucles[$idb]; |
|
| 1086 | + $parent = $boucle->id_parent; |
|
| 1087 | + $fields = $boucle->show['field']; |
|
| 1088 | + |
|
| 1089 | + $date = array_shift($params); |
|
| 1090 | + $type = array_shift($params); |
|
| 1091 | + |
|
| 1092 | + // la valeur $type doit etre connue a la compilation |
|
| 1093 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1094 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1095 | + |
|
| 1096 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1097 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1098 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1099 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1100 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1101 | + $date = $date[0]->texte; |
|
| 1102 | + if (!isset($fields[$date])) { |
|
| 1103 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1104 | + } |
|
| 1105 | + } else { |
|
| 1106 | + $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1107 | + $noms = array_keys($fields); |
|
| 1108 | + $defaut = $noms[0]; |
|
| 1109 | + $noms = join(" ", $noms); |
|
| 1110 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1111 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1112 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1113 | + } |
|
| 1114 | + $annee = $params ? array_shift($params) : ""; |
|
| 1115 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | + calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1117 | + ') ? $x : date("Y"))'; |
|
| 1118 | + |
|
| 1119 | + $mois = $params ? array_shift($params) : ""; |
|
| 1120 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | + calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1122 | + ') ? $x : date("m"))'; |
|
| 1123 | + |
|
| 1124 | + $jour = $params ? array_shift($params) : ""; |
|
| 1125 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | + calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1127 | + ') ? $x : date("d"))'; |
|
| 1128 | + |
|
| 1129 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 1130 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | + calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1132 | + ') ? $x : date("Y"))'; |
|
| 1133 | + |
|
| 1134 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 1135 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | + calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1137 | + ') ? $x : date("m"))'; |
|
| 1138 | + |
|
| 1139 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 1140 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | + calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1142 | + ') ? $x : date("d"))'; |
|
| 1143 | + |
|
| 1144 | + $date = $boucle->id_table . ".$date"; |
|
| 1145 | + |
|
| 1146 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1147 | + if ($type == 'jour') { |
|
| 1148 | + $boucle->where[] = array( |
|
| 1149 | + "'='", |
|
| 1150 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1151 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1152 | + ); |
|
| 1153 | + } elseif ($type == 'mois') { |
|
| 1154 | + $boucle->where[] = array( |
|
| 1155 | + "'='", |
|
| 1156 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1157 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1158 | + ); |
|
| 1159 | + } elseif ($type == 'semaine') { |
|
| 1160 | + $boucle->where[] = array( |
|
| 1161 | + "'AND'", |
|
| 1162 | + array( |
|
| 1163 | + "'>='", |
|
| 1164 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1165 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1166 | + ), |
|
| 1167 | + array( |
|
| 1168 | + "'<='", |
|
| 1169 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1170 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1171 | + ) |
|
| 1172 | + ); |
|
| 1173 | + } elseif (count($crit->param) > 2) { |
|
| 1174 | + $boucle->where[] = array( |
|
| 1175 | + "'AND'", |
|
| 1176 | + array( |
|
| 1177 | + "'>='", |
|
| 1178 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1179 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1180 | + ), |
|
| 1181 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1182 | + ); |
|
| 1183 | + } |
|
| 1184 | + // sinon on prend tout |
|
| 1185 | 1185 | } |
| 1186 | 1186 | |
| 1187 | 1187 | |
@@ -1206,33 +1206,33 @@ discard block |
||
| 1206 | 1206 | * @return void |
| 1207 | 1207 | **/ |
| 1208 | 1208 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1209 | - $boucle = &$boucles[$idb]; |
|
| 1210 | - $a1 = $crit->param[0]; |
|
| 1211 | - $a2 = $crit->param[1]; |
|
| 1212 | - $op = $crit->op; |
|
| 1213 | - |
|
| 1214 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | - |
|
| 1217 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | - } else { |
|
| 1220 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | - $mode = (($op == '/') ? '/' : |
|
| 1225 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | - $boucle->limit = |
|
| 1229 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | - . ".','." |
|
| 1231 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | - } else { |
|
| 1233 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | - } |
|
| 1235 | - } |
|
| 1209 | + $boucle = &$boucles[$idb]; |
|
| 1210 | + $a1 = $crit->param[0]; |
|
| 1211 | + $a2 = $crit->param[1]; |
|
| 1212 | + $op = $crit->op; |
|
| 1213 | + |
|
| 1214 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1215 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1216 | + |
|
| 1217 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1218 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1219 | + } else { |
|
| 1220 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1221 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1222 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1223 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1224 | + $mode = (($op == '/') ? '/' : |
|
| 1225 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1226 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1227 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1228 | + $boucle->limit = |
|
| 1229 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1230 | + . ".','." |
|
| 1231 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1232 | + } else { |
|
| 1233 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1234 | + } |
|
| 1235 | + } |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1260,63 +1260,63 @@ discard block |
||
| 1260 | 1260 | * @return void |
| 1261 | 1261 | **/ |
| 1262 | 1262 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1263 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | - |
|
| 1265 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | - // {1/3} |
|
| 1269 | - if ($op1 == '/') { |
|
| 1270 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | - "($total_parties ? $total_parties : 1)"; |
|
| 1273 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | - } else { |
|
| 1276 | - // cas {n-1,x} |
|
| 1277 | - if ($op1 == '-') { |
|
| 1278 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - // cas {x,n-1} |
|
| 1282 | - if ($op2 == '-') { |
|
| 1283 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | - ($total_parties . ' - 1')); |
|
| 1286 | - } else { |
|
| 1287 | - // {x,1} ou {pagination} |
|
| 1288 | - $fin = '$debut_boucle' |
|
| 1289 | - . (is_numeric($total_parties) ? |
|
| 1290 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | - ('+' . $total_parties . ' - 1')); |
|
| 1292 | - } |
|
| 1293 | - |
|
| 1294 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | - if ($op1 == 'p') { |
|
| 1296 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | - } |
|
| 1300 | - } |
|
| 1301 | - |
|
| 1302 | - // Notes : |
|
| 1303 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | - |
|
| 1308 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 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);' |
|
| 1314 | - . "\n\tif (\$debut_boucle>0" |
|
| 1315 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | - |
|
| 1319 | - $boucles[$id_boucle]->partie = " |
|
| 1263 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1264 | + |
|
| 1265 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1266 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1267 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1268 | + // {1/3} |
|
| 1269 | + if ($op1 == '/') { |
|
| 1270 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1271 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | + "($total_parties ? $total_parties : 1)"; |
|
| 1273 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1274 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1275 | + } else { |
|
| 1276 | + // cas {n-1,x} |
|
| 1277 | + if ($op1 == '-') { |
|
| 1278 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + // cas {x,n-1} |
|
| 1282 | + if ($op2 == '-') { |
|
| 1283 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | + ($total_parties . ' - 1')); |
|
| 1286 | + } else { |
|
| 1287 | + // {x,1} ou {pagination} |
|
| 1288 | + $fin = '$debut_boucle' |
|
| 1289 | + . (is_numeric($total_parties) ? |
|
| 1290 | + (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | + ('+' . $total_parties . ' - 1')); |
|
| 1292 | + } |
|
| 1293 | + |
|
| 1294 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1295 | + if ($op1 == 'p') { |
|
| 1296 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1297 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1298 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1299 | + } |
|
| 1300 | + } |
|
| 1301 | + |
|
| 1302 | + // Notes : |
|
| 1303 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1304 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1305 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1306 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1307 | + |
|
| 1308 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1309 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1310 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 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);' |
|
| 1314 | + . "\n\tif (\$debut_boucle>0" |
|
| 1315 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1316 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1317 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1318 | + |
|
| 1319 | + $boucles[$id_boucle]->partie = " |
|
| 1320 | 1320 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1321 | 1321 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1322 | 1322 | } |
@@ -1333,26 +1333,26 @@ discard block |
||
| 1333 | 1333 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1334 | 1334 | **/ |
| 1335 | 1335 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1336 | - if ($param[0]->type != 'texte') { |
|
| 1337 | - $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | - if (isset($param[1]->texte)) { |
|
| 1339 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | - |
|
| 1341 | - return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | - } else { |
|
| 1343 | - return array("intval($a1)", 0); |
|
| 1344 | - } |
|
| 1345 | - } else { |
|
| 1346 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | - $a1 = $m[1]; |
|
| 1348 | - if (empty($m[3])) { |
|
| 1349 | - return array($a1, 0); |
|
| 1350 | - } elseif (!empty($m[4])) { |
|
| 1351 | - return array($a1, $m[4]); |
|
| 1352 | - } else { |
|
| 1353 | - return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1336 | + if ($param[0]->type != 'texte') { |
|
| 1337 | + $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1338 | + if (isset($param[1]->texte)) { |
|
| 1339 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1340 | + |
|
| 1341 | + return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1342 | + } else { |
|
| 1343 | + return array("intval($a1)", 0); |
|
| 1344 | + } |
|
| 1345 | + } else { |
|
| 1346 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1347 | + $a1 = $m[1]; |
|
| 1348 | + if (empty($m[3])) { |
|
| 1349 | + return array($a1, 0); |
|
| 1350 | + } elseif (!empty($m[4])) { |
|
| 1351 | + return array($a1, $m[4]); |
|
| 1352 | + } else { |
|
| 1353 | + return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | |
@@ -1379,47 +1379,47 @@ discard block |
||
| 1379 | 1379 | * array : Erreur sur un des critères |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function calculer_criteres($idb, &$boucles) { |
| 1382 | - $msg = ''; |
|
| 1383 | - $boucle = $boucles[$idb]; |
|
| 1384 | - $table = strtoupper($boucle->type_requete); |
|
| 1385 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | - |
|
| 1387 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | - if (!is_array($boucle->criteres)) { |
|
| 1390 | - return array(); |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - foreach ($boucle->criteres as $crit) { |
|
| 1394 | - $critere = $crit->op; |
|
| 1395 | - // critere personnalise ? |
|
| 1396 | - if ( |
|
| 1397 | - (!$serveur or |
|
| 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")) |
|
| 1402 | - ) |
|
| 1403 | - ) |
|
| 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")) |
|
| 1408 | - ) { |
|
| 1409 | - // fonction critere standard |
|
| 1410 | - $f = $defaut; |
|
| 1411 | - } |
|
| 1412 | - // compile le critere |
|
| 1413 | - $res = $f($idb, $boucles, $crit); |
|
| 1414 | - |
|
| 1415 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | - if (is_array($res)) { |
|
| 1417 | - $msg = $res; |
|
| 1418 | - erreur_squelette($msg, $boucle); |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - return $msg; |
|
| 1382 | + $msg = ''; |
|
| 1383 | + $boucle = $boucles[$idb]; |
|
| 1384 | + $table = strtoupper($boucle->type_requete); |
|
| 1385 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1386 | + |
|
| 1387 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1388 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1389 | + if (!is_array($boucle->criteres)) { |
|
| 1390 | + return array(); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + foreach ($boucle->criteres as $crit) { |
|
| 1394 | + $critere = $crit->op; |
|
| 1395 | + // critere personnalise ? |
|
| 1396 | + if ( |
|
| 1397 | + (!$serveur or |
|
| 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")) |
|
| 1402 | + ) |
|
| 1403 | + ) |
|
| 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")) |
|
| 1408 | + ) { |
|
| 1409 | + // fonction critere standard |
|
| 1410 | + $f = $defaut; |
|
| 1411 | + } |
|
| 1412 | + // compile le critere |
|
| 1413 | + $res = $f($idb, $boucles, $crit); |
|
| 1414 | + |
|
| 1415 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1416 | + if (is_array($res)) { |
|
| 1417 | + $msg = $res; |
|
| 1418 | + erreur_squelette($msg, $boucle); |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + return $msg; |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1436,11 +1436,11 @@ discard block |
||
| 1436 | 1436 | * @return string Code compilé rééchappé |
| 1437 | 1437 | */ |
| 1438 | 1438 | function kwote($lisp, $serveur = '', $type = '') { |
| 1439 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | - } else { |
|
| 1442 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | - } |
|
| 1439 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1440 | + return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1441 | + } else { |
|
| 1442 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1443 | + } |
|
| 1444 | 1444 | } |
| 1445 | 1445 | |
| 1446 | 1446 | |
@@ -1459,85 +1459,85 @@ discard block |
||
| 1459 | 1459 | * @return void |
| 1460 | 1460 | **/ |
| 1461 | 1461 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1462 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | - if (!$r) { |
|
| 1464 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | - } |
|
| 1466 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | - |
|
| 1468 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | - |
|
| 1470 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | - $where = $in; |
|
| 1472 | - if ($crit->cond) { |
|
| 1473 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | - $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | - { |
|
| 1477 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - if ($crit->exclus) { |
|
| 1481 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | - $where = array("'NOT'", $where); |
|
| 1483 | - } else |
|
| 1484 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | - { |
|
| 1487 | - $where = array( |
|
| 1488 | - "'NOT'", |
|
| 1489 | - array( |
|
| 1490 | - "'IN'", |
|
| 1491 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | - ) |
|
| 1494 | - ); |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - $boucles[$idb]->where[] = $where; |
|
| 1499 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | - { |
|
| 1501 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | - } |
|
| 1462 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1463 | + if (!$r) { |
|
| 1464 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1465 | + } |
|
| 1466 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1467 | + |
|
| 1468 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1469 | + |
|
| 1470 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1471 | + $where = $in; |
|
| 1472 | + if ($crit->cond) { |
|
| 1473 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1474 | + $where = array("'?'", $pred, $where, "''"); |
|
| 1475 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1476 | + { |
|
| 1477 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + if ($crit->exclus) { |
|
| 1481 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1482 | + $where = array("'NOT'", $where); |
|
| 1483 | + } else |
|
| 1484 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1485 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1486 | + { |
|
| 1487 | + $where = array( |
|
| 1488 | + "'NOT'", |
|
| 1489 | + array( |
|
| 1490 | + "'IN'", |
|
| 1491 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1493 | + ) |
|
| 1494 | + ); |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + $boucles[$idb]->where[] = $where; |
|
| 1499 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1500 | + { |
|
| 1501 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1502 | + } |
|
| 1503 | 1503 | } |
| 1504 | 1504 | |
| 1505 | 1505 | // http://code.spip.net/@critere_IN_cas |
| 1506 | 1506 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1507 | - static $num = array(); |
|
| 1508 | - $descr = $boucles[$idb]->descr; |
|
| 1509 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | - |
|
| 1511 | - $var = '$in' . $cpt++; |
|
| 1512 | - $x = "\n\t$var = array();"; |
|
| 1513 | - foreach ($val as $k => $v) { |
|
| 1514 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | - // optimiser le traitement des constantes |
|
| 1516 | - if (is_numeric($r[2])) { |
|
| 1517 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | - } else { |
|
| 1519 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | - } |
|
| 1521 | - } else { |
|
| 1522 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | - } |
|
| 1528 | - } |
|
| 1529 | - |
|
| 1530 | - $boucles[$idb]->in .= $x; |
|
| 1531 | - |
|
| 1532 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | - if (!$crit2) { |
|
| 1537 | - $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1507 | + static $num = array(); |
|
| 1508 | + $descr = $boucles[$idb]->descr; |
|
| 1509 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1510 | + |
|
| 1511 | + $var = '$in' . $cpt++; |
|
| 1512 | + $x = "\n\t$var = array();"; |
|
| 1513 | + foreach ($val as $k => $v) { |
|
| 1514 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1515 | + // optimiser le traitement des constantes |
|
| 1516 | + if (is_numeric($r[2])) { |
|
| 1517 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1518 | + } else { |
|
| 1519 | + $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1520 | + } |
|
| 1521 | + } else { |
|
| 1522 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1523 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1524 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1525 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1526 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | + } |
|
| 1528 | + } |
|
| 1529 | + |
|
| 1530 | + $boucles[$idb]->in .= $x; |
|
| 1531 | + |
|
| 1532 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1533 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1534 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1535 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1536 | + if (!$crit2) { |
|
| 1537 | + $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | 1543 | /** |
@@ -1553,22 +1553,22 @@ discard block |
||
| 1553 | 1553 | * @return void |
| 1554 | 1554 | */ |
| 1555 | 1555 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1556 | - $boucle = &$boucles[$idb]; |
|
| 1557 | - if (isset($crit->param[0])) { |
|
| 1558 | - $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1559 | - } else { |
|
| 1560 | - $_where = '@$Pile[0]["where"]'; |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - if ($crit->cond) { |
|
| 1564 | - $_where = "(($_where) ? ($_where) : '')"; |
|
| 1565 | - } |
|
| 1566 | - |
|
| 1567 | - if ($crit->not) { |
|
| 1568 | - $_where = "array('NOT',$_where)"; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $boucle->where[] = $_where; |
|
| 1556 | + $boucle = &$boucles[$idb]; |
|
| 1557 | + if (isset($crit->param[0])) { |
|
| 1558 | + $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1559 | + } else { |
|
| 1560 | + $_where = '@$Pile[0]["where"]'; |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + if ($crit->cond) { |
|
| 1564 | + $_where = "(($_where) ? ($_where) : '')"; |
|
| 1565 | + } |
|
| 1566 | + |
|
| 1567 | + if ($crit->not) { |
|
| 1568 | + $_where = "array('NOT',$_where)"; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $boucle->where[] = $_where; |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | /** |
@@ -1596,31 +1596,31 @@ discard block |
||
| 1596 | 1596 | * @return void |
| 1597 | 1597 | */ |
| 1598 | 1598 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1599 | - /** @var Boucle $boucle */ |
|
| 1600 | - $boucle = $boucles[$idb]; |
|
| 1601 | - |
|
| 1602 | - $champs = lister_champs_selection_conditionnelle( |
|
| 1603 | - $boucle->show['table'], |
|
| 1604 | - $boucle->show, |
|
| 1605 | - $boucle->sql_serveur |
|
| 1606 | - ); |
|
| 1607 | - |
|
| 1608 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | - } |
|
| 1612 | - // nous aider en mode debug. |
|
| 1613 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | - $boucle->modificateur['id_'] = $champs; |
|
| 1615 | - |
|
| 1616 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | - foreach ($champs as $champ) { |
|
| 1618 | - $critere_id_table = new Critere; |
|
| 1619 | - $critere_id_table->op = $champ; |
|
| 1620 | - $critere_id_table->cond = '?'; |
|
| 1621 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | - } |
|
| 1599 | + /** @var Boucle $boucle */ |
|
| 1600 | + $boucle = $boucles[$idb]; |
|
| 1601 | + |
|
| 1602 | + $champs = lister_champs_selection_conditionnelle( |
|
| 1603 | + $boucle->show['table'], |
|
| 1604 | + $boucle->show, |
|
| 1605 | + $boucle->sql_serveur |
|
| 1606 | + ); |
|
| 1607 | + |
|
| 1608 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1609 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1610 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1611 | + } |
|
| 1612 | + // nous aider en mode debug. |
|
| 1613 | + $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1614 | + $boucle->modificateur['id_'] = $champs; |
|
| 1615 | + |
|
| 1616 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1617 | + foreach ($champs as $champ) { |
|
| 1618 | + $critere_id_table = new Critere; |
|
| 1619 | + $critere_id_table->op = $champ; |
|
| 1620 | + $critere_id_table->cond = '?'; |
|
| 1621 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1622 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1623 | + } |
|
| 1624 | 1624 | } |
| 1625 | 1625 | |
| 1626 | 1626 | /** |
@@ -1640,67 +1640,67 @@ discard block |
||
| 1640 | 1640 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1641 | 1641 | */ |
| 1642 | 1642 | function lister_champs_selection_conditionnelle($table, $desc = null, $serveur = '') { |
| 1643 | - // calculer la description de la table |
|
| 1644 | - if (!is_array($desc)) { |
|
| 1645 | - $desc = description_table($table, $serveur); |
|
| 1646 | - } |
|
| 1647 | - if (!$desc) { |
|
| 1648 | - return []; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - // Les champs id_xx de la table demandée |
|
| 1652 | - $champs = array_filter( |
|
| 1653 | - array_keys($desc['field']), |
|
| 1654 | - function($champ){ |
|
| 1655 | - return |
|
| 1656 | - strpos($champ, 'id_') === 0 |
|
| 1657 | - or (in_array($champ, array('objet'))); |
|
| 1658 | - } |
|
| 1659 | - ); |
|
| 1660 | - |
|
| 1661 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1662 | - if ($serveur) { |
|
| 1663 | - return $champs; |
|
| 1664 | - } |
|
| 1665 | - |
|
| 1666 | - $primary = false; |
|
| 1667 | - $associable = false; |
|
| 1668 | - include_spip('action/editer_liens'); |
|
| 1669 | - |
|
| 1670 | - if (isset($desc['type'])) { |
|
| 1671 | - $primary = id_table_objet($desc['type']); |
|
| 1672 | - $associable = objet_associable($desc['type']); |
|
| 1673 | - } |
|
| 1674 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1675 | - $associable = true; |
|
| 1676 | - } |
|
| 1677 | - |
|
| 1678 | - // liste de toutes les tables principales, sauf la notre |
|
| 1679 | - $tables = lister_tables_objets_sql(); |
|
| 1680 | - unset($tables[$table]); |
|
| 1681 | - |
|
| 1682 | - foreach ($tables as $_table => $_desc) { |
|
| 1683 | - if ( |
|
| 1684 | - $associable |
|
| 1685 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1686 | - or objet_associable($_desc['type']) |
|
| 1687 | - ) { |
|
| 1688 | - $champs[] = id_table_objet($_table); |
|
| 1689 | - } |
|
| 1690 | - } |
|
| 1691 | - $champs = array_values(array_unique($champs)); |
|
| 1692 | - $champs = pipeline( |
|
| 1693 | - 'lister_champs_selection_conditionnelle', |
|
| 1694 | - array( |
|
| 1695 | - 'args' => array( |
|
| 1696 | - 'table' => $table, |
|
| 1697 | - 'id_table_objet' => $primary, |
|
| 1698 | - 'associable' => $associable, |
|
| 1699 | - ), |
|
| 1700 | - 'data' => $champs, |
|
| 1701 | - ) |
|
| 1702 | - ); |
|
| 1703 | - return $champs; |
|
| 1643 | + // calculer la description de la table |
|
| 1644 | + if (!is_array($desc)) { |
|
| 1645 | + $desc = description_table($table, $serveur); |
|
| 1646 | + } |
|
| 1647 | + if (!$desc) { |
|
| 1648 | + return []; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + // Les champs id_xx de la table demandée |
|
| 1652 | + $champs = array_filter( |
|
| 1653 | + array_keys($desc['field']), |
|
| 1654 | + function($champ){ |
|
| 1655 | + return |
|
| 1656 | + strpos($champ, 'id_') === 0 |
|
| 1657 | + or (in_array($champ, array('objet'))); |
|
| 1658 | + } |
|
| 1659 | + ); |
|
| 1660 | + |
|
| 1661 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1662 | + if ($serveur) { |
|
| 1663 | + return $champs; |
|
| 1664 | + } |
|
| 1665 | + |
|
| 1666 | + $primary = false; |
|
| 1667 | + $associable = false; |
|
| 1668 | + include_spip('action/editer_liens'); |
|
| 1669 | + |
|
| 1670 | + if (isset($desc['type'])) { |
|
| 1671 | + $primary = id_table_objet($desc['type']); |
|
| 1672 | + $associable = objet_associable($desc['type']); |
|
| 1673 | + } |
|
| 1674 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1675 | + $associable = true; |
|
| 1676 | + } |
|
| 1677 | + |
|
| 1678 | + // liste de toutes les tables principales, sauf la notre |
|
| 1679 | + $tables = lister_tables_objets_sql(); |
|
| 1680 | + unset($tables[$table]); |
|
| 1681 | + |
|
| 1682 | + foreach ($tables as $_table => $_desc) { |
|
| 1683 | + if ( |
|
| 1684 | + $associable |
|
| 1685 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1686 | + or objet_associable($_desc['type']) |
|
| 1687 | + ) { |
|
| 1688 | + $champs[] = id_table_objet($_table); |
|
| 1689 | + } |
|
| 1690 | + } |
|
| 1691 | + $champs = array_values(array_unique($champs)); |
|
| 1692 | + $champs = pipeline( |
|
| 1693 | + 'lister_champs_selection_conditionnelle', |
|
| 1694 | + array( |
|
| 1695 | + 'args' => array( |
|
| 1696 | + 'table' => $table, |
|
| 1697 | + 'id_table_objet' => $primary, |
|
| 1698 | + 'associable' => $associable, |
|
| 1699 | + ), |
|
| 1700 | + 'data' => $champs, |
|
| 1701 | + ) |
|
| 1702 | + ); |
|
| 1703 | + return $champs; |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | /** |
@@ -1755,27 +1755,27 @@ discard block |
||
| 1755 | 1755 | * @return void |
| 1756 | 1756 | */ |
| 1757 | 1757 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1758 | - $boucle = &$boucles[$idb]; |
|
| 1759 | - |
|
| 1760 | - // definition du champ par defaut |
|
| 1761 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1762 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1763 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1764 | - : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1765 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1766 | - : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1767 | - |
|
| 1768 | - $_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):'')"; |
|
| 1769 | - |
|
| 1770 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1771 | - $_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)"; |
|
| 1772 | - |
|
| 1773 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1774 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1775 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1776 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1777 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1778 | - $boucle->hash .= " |
|
| 1758 | + $boucle = &$boucles[$idb]; |
|
| 1759 | + |
|
| 1760 | + // definition du champ par defaut |
|
| 1761 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1762 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1763 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1764 | + : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1765 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1766 | + : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1767 | + |
|
| 1768 | + $_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):'')"; |
|
| 1769 | + |
|
| 1770 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1771 | + $_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)"; |
|
| 1772 | + |
|
| 1773 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1774 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1775 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1776 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1777 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1778 | + $boucle->hash .= " |
|
| 1779 | 1779 | \$senstri = ''; |
| 1780 | 1780 | \$tri = $_tri; |
| 1781 | 1781 | if (\$tri){ |
@@ -1783,8 +1783,8 @@ discard block |
||
| 1783 | 1783 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1784 | 1784 | }; |
| 1785 | 1785 | "; |
| 1786 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1787 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1786 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1787 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | 1790 | # Criteres de comparaison |
@@ -1801,20 +1801,20 @@ discard block |
||
| 1801 | 1801 | * @return void |
| 1802 | 1802 | **/ |
| 1803 | 1803 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1804 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1805 | - if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1806 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1810 | - if (!$r) { |
|
| 1811 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1812 | - # if (!$crit->cond) { |
|
| 1813 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1814 | - # } |
|
| 1815 | - } else { |
|
| 1816 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1817 | - } |
|
| 1804 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1805 | + if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1806 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1810 | + if (!$r) { |
|
| 1811 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1812 | + # if (!$crit->cond) { |
|
| 1813 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1814 | + # } |
|
| 1815 | + } else { |
|
| 1816 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1817 | + } |
|
| 1818 | 1818 | } |
| 1819 | 1819 | |
| 1820 | 1820 | |
@@ -1834,63 +1834,63 @@ discard block |
||
| 1834 | 1834 | * @return void |
| 1835 | 1835 | **/ |
| 1836 | 1836 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1837 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1838 | - |
|
| 1839 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1840 | - |
|
| 1841 | - // inserer la negation (cf !...) |
|
| 1842 | - |
|
| 1843 | - if ($crit->not) { |
|
| 1844 | - $where = array("'NOT'", $where); |
|
| 1845 | - } |
|
| 1846 | - if ($crit->exclus) { |
|
| 1847 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1848 | - $where = array("'NOT'", $where); |
|
| 1849 | - } else |
|
| 1850 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1851 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1852 | - { |
|
| 1853 | - $where = array( |
|
| 1854 | - "'NOT'", |
|
| 1855 | - array( |
|
| 1856 | - "'IN'", |
|
| 1857 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1858 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1859 | - ) |
|
| 1860 | - ); |
|
| 1861 | - } |
|
| 1862 | - } |
|
| 1863 | - |
|
| 1864 | - // inserer la condition (cf {lang?}) |
|
| 1865 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1866 | - if ($crit->cond) { |
|
| 1867 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1868 | - if ($col == "date" or $col == "date_redac") { |
|
| 1869 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1870 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1871 | - } |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - if ($op == '=' and !$crit->not) { |
|
| 1875 | - $where = array( |
|
| 1876 | - "'?'", |
|
| 1877 | - "(is_array($pred))", |
|
| 1878 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1879 | - $where |
|
| 1880 | - ); |
|
| 1881 | - } |
|
| 1882 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1883 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1884 | - { |
|
| 1885 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1886 | - } |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - $boucles[$idb]->where[] = $where; |
|
| 1890 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1891 | - { |
|
| 1892 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1893 | - } |
|
| 1837 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1838 | + |
|
| 1839 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1840 | + |
|
| 1841 | + // inserer la negation (cf !...) |
|
| 1842 | + |
|
| 1843 | + if ($crit->not) { |
|
| 1844 | + $where = array("'NOT'", $where); |
|
| 1845 | + } |
|
| 1846 | + if ($crit->exclus) { |
|
| 1847 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1848 | + $where = array("'NOT'", $where); |
|
| 1849 | + } else |
|
| 1850 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1851 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1852 | + { |
|
| 1853 | + $where = array( |
|
| 1854 | + "'NOT'", |
|
| 1855 | + array( |
|
| 1856 | + "'IN'", |
|
| 1857 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1858 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1859 | + ) |
|
| 1860 | + ); |
|
| 1861 | + } |
|
| 1862 | + } |
|
| 1863 | + |
|
| 1864 | + // inserer la condition (cf {lang?}) |
|
| 1865 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1866 | + if ($crit->cond) { |
|
| 1867 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1868 | + if ($col == "date" or $col == "date_redac") { |
|
| 1869 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1870 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1871 | + } |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + if ($op == '=' and !$crit->not) { |
|
| 1875 | + $where = array( |
|
| 1876 | + "'?'", |
|
| 1877 | + "(is_array($pred))", |
|
| 1878 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1879 | + $where |
|
| 1880 | + ); |
|
| 1881 | + } |
|
| 1882 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1883 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1884 | + { |
|
| 1885 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1886 | + } |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + $boucles[$idb]->where[] = $where; |
|
| 1890 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1891 | + { |
|
| 1892 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1893 | + } |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | |
@@ -1931,167 +1931,167 @@ discard block |
||
| 1931 | 1931 | **/ |
| 1932 | 1932 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1933 | 1933 | |
| 1934 | - $boucle = &$boucles[$idb]; |
|
| 1935 | - $type = $boucle->type_requete; |
|
| 1936 | - $table = $boucle->id_table; |
|
| 1937 | - $desc = $boucle->show; |
|
| 1938 | - $col_vraie = null; |
|
| 1939 | - |
|
| 1940 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1941 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1942 | - |
|
| 1943 | - $col_alias = $col; |
|
| 1944 | - $where_complement = false; |
|
| 1945 | - |
|
| 1946 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1947 | - if ($col == 'id_enfant') { |
|
| 1948 | - $col = $boucle->primary; |
|
| 1949 | - } |
|
| 1950 | - |
|
| 1951 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1952 | - if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1953 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1954 | - ) { |
|
| 1955 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1956 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1957 | - else { |
|
| 1958 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1959 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1960 | - } |
|
| 1961 | - |
|
| 1962 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1963 | - // sauf si exception declaree : sauter cette etape |
|
| 1964 | - else { |
|
| 1965 | - if ( |
|
| 1966 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1967 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1968 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1969 | - ) { |
|
| 1970 | - $e = decompose_champ_id_objet($col); |
|
| 1971 | - $col = array_shift($e); |
|
| 1972 | - $where_complement = primary_doublee($e, $table); |
|
| 1973 | - } // Cas particulier : expressions de date |
|
| 1974 | - else { |
|
| 1975 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1976 | - list($col, $col_vraie) = $c; |
|
| 1977 | - $table = ''; |
|
| 1978 | - } // table explicitée {mots.titre} |
|
| 1979 | - else { |
|
| 1980 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1981 | - list(, $table, $col) = $r; |
|
| 1982 | - $col_alias = $col; |
|
| 1983 | - |
|
| 1984 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1985 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1986 | - and isset($desc['field'][$col]) |
|
| 1987 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 1988 | - ) { |
|
| 1989 | - $table = $cle; |
|
| 1990 | - } else { |
|
| 1991 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1992 | - } |
|
| 1993 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1994 | - if (!$table) { |
|
| 1995 | - return ''; |
|
| 1996 | - } |
|
| 1997 | - } |
|
| 1998 | - // si le champ n'est pas trouvé dans la table, |
|
| 1999 | - // on cherche si une jointure peut l'obtenir |
|
| 2000 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2001 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2002 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2003 | - $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 |
|
| 2004 | - } |
|
| 2005 | - else { |
|
| 2006 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2007 | - if (!$r) { |
|
| 2008 | - return ''; |
|
| 2009 | - } |
|
| 2010 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2011 | - } |
|
| 2012 | - } |
|
| 2013 | - } |
|
| 2014 | - } |
|
| 2015 | - } |
|
| 2016 | - } |
|
| 2017 | - |
|
| 2018 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2019 | - // Dans tous les cas, |
|
| 2020 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2021 | - // et passer dans sql_quote avec le type si connu |
|
| 2022 | - // et int sinon si la valeur est numerique |
|
| 2023 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2024 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2025 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2026 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2027 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2028 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2029 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2030 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2031 | - } |
|
| 2032 | - // sinon expliciter les |
|
| 2033 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2034 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2035 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2036 | - // sans toucher aux |
|
| 2037 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2038 | - // sql_quote(truc,'','varchar') |
|
| 2039 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2040 | - // si pas deja un type |
|
| 2041 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2042 | - ) { |
|
| 2043 | - $r = $r[1] |
|
| 2044 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2045 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2046 | - $val[0] = "sql_quote($r)"; |
|
| 2047 | - } |
|
| 2048 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2049 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2050 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2051 | - } |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2055 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2056 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2057 | - } |
|
| 2058 | - |
|
| 2059 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2060 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2061 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2062 | - if ($table === $boucle->id_table) { |
|
| 2063 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2064 | - if ($col_alias != $col_vraie) { |
|
| 2065 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2066 | - } |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2070 | - // il faut alors interdire a la fonction de boucle |
|
| 2071 | - // de mettre ses propres criteres de statut |
|
| 2072 | - // http://www.spip.net/@statut (a documenter) |
|
| 2073 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2074 | - if ($col == 'statut') { |
|
| 2075 | - $boucles[$idb]->statut = true; |
|
| 2076 | - } |
|
| 2077 | - |
|
| 2078 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2079 | - if ($table) { |
|
| 2080 | - if ($col[0] == "`") { |
|
| 2081 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2082 | - } else { |
|
| 2083 | - $arg = "$table.$col"; |
|
| 2084 | - } |
|
| 2085 | - } else { |
|
| 2086 | - $arg = $col; |
|
| 2087 | - } |
|
| 2088 | - |
|
| 2089 | - // inserer la fonction SQL |
|
| 2090 | - if ($fct) { |
|
| 2091 | - $arg = "$fct($arg$args_sql)"; |
|
| 2092 | - } |
|
| 2093 | - |
|
| 2094 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1934 | + $boucle = &$boucles[$idb]; |
|
| 1935 | + $type = $boucle->type_requete; |
|
| 1936 | + $table = $boucle->id_table; |
|
| 1937 | + $desc = $boucle->show; |
|
| 1938 | + $col_vraie = null; |
|
| 1939 | + |
|
| 1940 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1941 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1942 | + |
|
| 1943 | + $col_alias = $col; |
|
| 1944 | + $where_complement = false; |
|
| 1945 | + |
|
| 1946 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1947 | + if ($col == 'id_enfant') { |
|
| 1948 | + $col = $boucle->primary; |
|
| 1949 | + } |
|
| 1950 | + |
|
| 1951 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1952 | + if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1953 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1954 | + ) { |
|
| 1955 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1956 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1957 | + else { |
|
| 1958 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1959 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1960 | + } |
|
| 1961 | + |
|
| 1962 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1963 | + // sauf si exception declaree : sauter cette etape |
|
| 1964 | + else { |
|
| 1965 | + if ( |
|
| 1966 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1967 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1968 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1969 | + ) { |
|
| 1970 | + $e = decompose_champ_id_objet($col); |
|
| 1971 | + $col = array_shift($e); |
|
| 1972 | + $where_complement = primary_doublee($e, $table); |
|
| 1973 | + } // Cas particulier : expressions de date |
|
| 1974 | + else { |
|
| 1975 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1976 | + list($col, $col_vraie) = $c; |
|
| 1977 | + $table = ''; |
|
| 1978 | + } // table explicitée {mots.titre} |
|
| 1979 | + else { |
|
| 1980 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1981 | + list(, $table, $col) = $r; |
|
| 1982 | + $col_alias = $col; |
|
| 1983 | + |
|
| 1984 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1985 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1986 | + and isset($desc['field'][$col]) |
|
| 1987 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 1988 | + ) { |
|
| 1989 | + $table = $cle; |
|
| 1990 | + } else { |
|
| 1991 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1992 | + } |
|
| 1993 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1994 | + if (!$table) { |
|
| 1995 | + return ''; |
|
| 1996 | + } |
|
| 1997 | + } |
|
| 1998 | + // si le champ n'est pas trouvé dans la table, |
|
| 1999 | + // on cherche si une jointure peut l'obtenir |
|
| 2000 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2001 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2002 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2003 | + $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 |
|
| 2004 | + } |
|
| 2005 | + else { |
|
| 2006 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2007 | + if (!$r) { |
|
| 2008 | + return ''; |
|
| 2009 | + } |
|
| 2010 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 2011 | + } |
|
| 2012 | + } |
|
| 2013 | + } |
|
| 2014 | + } |
|
| 2015 | + } |
|
| 2016 | + } |
|
| 2017 | + |
|
| 2018 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 2019 | + // Dans tous les cas, |
|
| 2020 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2021 | + // et passer dans sql_quote avec le type si connu |
|
| 2022 | + // et int sinon si la valeur est numerique |
|
| 2023 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2024 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2025 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2026 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 2027 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2028 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2029 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2030 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2031 | + } |
|
| 2032 | + // sinon expliciter les |
|
| 2033 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2034 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2035 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2036 | + // sans toucher aux |
|
| 2037 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2038 | + // sql_quote(truc,'','varchar') |
|
| 2039 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2040 | + // si pas deja un type |
|
| 2041 | + and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2042 | + ) { |
|
| 2043 | + $r = $r[1] |
|
| 2044 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2045 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2046 | + $val[0] = "sql_quote($r)"; |
|
| 2047 | + } |
|
| 2048 | + elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2049 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2050 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2051 | + } |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2055 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 2056 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2057 | + } |
|
| 2058 | + |
|
| 2059 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2060 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2061 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2062 | + if ($table === $boucle->id_table) { |
|
| 2063 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2064 | + if ($col_alias != $col_vraie) { |
|
| 2065 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2066 | + } |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 2070 | + // il faut alors interdire a la fonction de boucle |
|
| 2071 | + // de mettre ses propres criteres de statut |
|
| 2072 | + // http://www.spip.net/@statut (a documenter) |
|
| 2073 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 2074 | + if ($col == 'statut') { |
|
| 2075 | + $boucles[$idb]->statut = true; |
|
| 2076 | + } |
|
| 2077 | + |
|
| 2078 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2079 | + if ($table) { |
|
| 2080 | + if ($col[0] == "`") { |
|
| 2081 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2082 | + } else { |
|
| 2083 | + $arg = "$table.$col"; |
|
| 2084 | + } |
|
| 2085 | + } else { |
|
| 2086 | + $arg = $col; |
|
| 2087 | + } |
|
| 2088 | + |
|
| 2089 | + // inserer la fonction SQL |
|
| 2090 | + if ($fct) { |
|
| 2091 | + $arg = "$fct($arg$args_sql)"; |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 2095 | 2095 | } |
| 2096 | 2096 | |
| 2097 | 2097 | |
@@ -2120,77 +2120,77 @@ discard block |
||
| 2120 | 2120 | **/ |
| 2121 | 2121 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2122 | 2122 | |
| 2123 | - $where = ''; |
|
| 2124 | - |
|
| 2125 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2126 | - // gestion par les plugins des jointures tordues |
|
| 2127 | - // pas automatiques mais necessaires |
|
| 2128 | - $table_sql = table_objet_sql($table); |
|
| 2129 | - if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2130 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2131 | - and |
|
| 2132 | - ( |
|
| 2133 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2134 | - or |
|
| 2135 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2136 | - ) |
|
| 2137 | - ) { |
|
| 2138 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2139 | - $index = isset($t[$col]) |
|
| 2140 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2141 | - |
|
| 2142 | - if (count($index) == 3) { |
|
| 2143 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2144 | - } elseif (count($index) == 2) { |
|
| 2145 | - list($t, $col) = $t[$col]; |
|
| 2146 | - } elseif (count($index) == 1) { |
|
| 2147 | - list($calculer_critere_externe) = $index; |
|
| 2148 | - $t = $table; |
|
| 2149 | - } else { |
|
| 2150 | - $t = ''; |
|
| 2151 | - } // jointure non declaree. La trouver. |
|
| 2152 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2153 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2154 | - } else { |
|
| 2155 | - $t = ''; |
|
| 2156 | - } // jointure non declaree. La trouver. |
|
| 2157 | - |
|
| 2158 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2159 | - |
|
| 2160 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2161 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2162 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2163 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2164 | - $table = ""; |
|
| 2165 | - if ($boucle->jointures_explicites) { |
|
| 2166 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2167 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2168 | - } |
|
| 2169 | - |
|
| 2170 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2171 | - if (!$table) { |
|
| 2172 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2173 | - } |
|
| 2174 | - |
|
| 2175 | - if (!$table) { |
|
| 2176 | - return ''; |
|
| 2177 | - } |
|
| 2178 | - |
|
| 2179 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2180 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2181 | - |
|
| 2182 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2183 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2184 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2185 | - $e = decompose_champ_id_objet($col); |
|
| 2186 | - $col = array_shift($e); |
|
| 2187 | - $where = primary_doublee($e, $table); |
|
| 2188 | - } else { |
|
| 2189 | - $col = reset($cle); |
|
| 2190 | - } |
|
| 2191 | - } |
|
| 2192 | - |
|
| 2193 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 2123 | + $where = ''; |
|
| 2124 | + |
|
| 2125 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2126 | + // gestion par les plugins des jointures tordues |
|
| 2127 | + // pas automatiques mais necessaires |
|
| 2128 | + $table_sql = table_objet_sql($table); |
|
| 2129 | + if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2130 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2131 | + and |
|
| 2132 | + ( |
|
| 2133 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2134 | + or |
|
| 2135 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2136 | + ) |
|
| 2137 | + ) { |
|
| 2138 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2139 | + $index = isset($t[$col]) |
|
| 2140 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2141 | + |
|
| 2142 | + if (count($index) == 3) { |
|
| 2143 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2144 | + } elseif (count($index) == 2) { |
|
| 2145 | + list($t, $col) = $t[$col]; |
|
| 2146 | + } elseif (count($index) == 1) { |
|
| 2147 | + list($calculer_critere_externe) = $index; |
|
| 2148 | + $t = $table; |
|
| 2149 | + } else { |
|
| 2150 | + $t = ''; |
|
| 2151 | + } // jointure non declaree. La trouver. |
|
| 2152 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2153 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2154 | + } else { |
|
| 2155 | + $t = ''; |
|
| 2156 | + } // jointure non declaree. La trouver. |
|
| 2157 | + |
|
| 2158 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2159 | + |
|
| 2160 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2161 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2162 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2163 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2164 | + $table = ""; |
|
| 2165 | + if ($boucle->jointures_explicites) { |
|
| 2166 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2167 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2168 | + } |
|
| 2169 | + |
|
| 2170 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2171 | + if (!$table) { |
|
| 2172 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2173 | + } |
|
| 2174 | + |
|
| 2175 | + if (!$table) { |
|
| 2176 | + return ''; |
|
| 2177 | + } |
|
| 2178 | + |
|
| 2179 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2180 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2181 | + |
|
| 2182 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2183 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2184 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2185 | + $e = decompose_champ_id_objet($col); |
|
| 2186 | + $col = array_shift($e); |
|
| 2187 | + $where = primary_doublee($e, $table); |
|
| 2188 | + } else { |
|
| 2189 | + $col = reset($cle); |
|
| 2190 | + } |
|
| 2191 | + } |
|
| 2192 | + |
|
| 2193 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | 2196 | |
@@ -2211,10 +2211,10 @@ discard block |
||
| 2211 | 2211 | * - valeur |
| 2212 | 2212 | **/ |
| 2213 | 2213 | function primary_doublee($decompose, $table) { |
| 2214 | - $e1 = reset($decompose); |
|
| 2215 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2214 | + $e1 = reset($decompose); |
|
| 2215 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2216 | 2216 | |
| 2217 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2217 | + return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2218 | 2218 | } |
| 2219 | 2219 | |
| 2220 | 2220 | /** |
@@ -2245,56 +2245,56 @@ discard block |
||
| 2245 | 2245 | * Vide sinon. |
| 2246 | 2246 | */ |
| 2247 | 2247 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2248 | - // si on demande un truc du genre spip_mots |
|
| 2249 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2250 | - // et qu'on est la |
|
| 2251 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2252 | - if ($checkarrivee |
|
| 2253 | - and is_string($checkarrivee) |
|
| 2254 | - and $a = table_objet($checkarrivee) |
|
| 2255 | - and in_array($a . '_liens', $joints) |
|
| 2256 | - ) { |
|
| 2257 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2258 | - return $res; |
|
| 2259 | - } |
|
| 2260 | - } |
|
| 2261 | - foreach ($joints as $joint) { |
|
| 2262 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2263 | - // alias de table dans le from |
|
| 2264 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2265 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2266 | - $cols = $arrivee[2]; |
|
| 2267 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2268 | - if (count($cols) > 2) { |
|
| 2269 | - array_pop($cols); |
|
| 2270 | - } |
|
| 2271 | - if ($t) { |
|
| 2272 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2273 | - $joindre = false; |
|
| 2274 | - foreach ($cols as $col) { |
|
| 2275 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2276 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2277 | - $joindre = true; |
|
| 2278 | - } else { |
|
| 2279 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2280 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2281 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2282 | - $joindre = true; |
|
| 2283 | - } |
|
| 2284 | - } |
|
| 2285 | - } |
|
| 2286 | - if (!$joindre) { |
|
| 2287 | - return $t; |
|
| 2288 | - } |
|
| 2289 | - } |
|
| 2290 | - array_pop($arrivee); |
|
| 2291 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2292 | - return $res; |
|
| 2293 | - } |
|
| 2294 | - } |
|
| 2295 | - } |
|
| 2296 | - |
|
| 2297 | - return ''; |
|
| 2248 | + // si on demande un truc du genre spip_mots |
|
| 2249 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2250 | + // et qu'on est la |
|
| 2251 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2252 | + if ($checkarrivee |
|
| 2253 | + and is_string($checkarrivee) |
|
| 2254 | + and $a = table_objet($checkarrivee) |
|
| 2255 | + and in_array($a . '_liens', $joints) |
|
| 2256 | + ) { |
|
| 2257 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2258 | + return $res; |
|
| 2259 | + } |
|
| 2260 | + } |
|
| 2261 | + foreach ($joints as $joint) { |
|
| 2262 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2263 | + // alias de table dans le from |
|
| 2264 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2265 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2266 | + $cols = $arrivee[2]; |
|
| 2267 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2268 | + if (count($cols) > 2) { |
|
| 2269 | + array_pop($cols); |
|
| 2270 | + } |
|
| 2271 | + if ($t) { |
|
| 2272 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2273 | + $joindre = false; |
|
| 2274 | + foreach ($cols as $col) { |
|
| 2275 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2276 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2277 | + $joindre = true; |
|
| 2278 | + } else { |
|
| 2279 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2280 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2281 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2282 | + $joindre = true; |
|
| 2283 | + } |
|
| 2284 | + } |
|
| 2285 | + } |
|
| 2286 | + if (!$joindre) { |
|
| 2287 | + return $t; |
|
| 2288 | + } |
|
| 2289 | + } |
|
| 2290 | + array_pop($arrivee); |
|
| 2291 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2292 | + return $res; |
|
| 2293 | + } |
|
| 2294 | + } |
|
| 2295 | + } |
|
| 2296 | + |
|
| 2297 | + return ''; |
|
| 2298 | 2298 | |
| 2299 | 2299 | } |
| 2300 | 2300 | |
@@ -2321,29 +2321,29 @@ discard block |
||
| 2321 | 2321 | * Alias de la table de jointure (Lx) |
| 2322 | 2322 | */ |
| 2323 | 2323 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2324 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2325 | - |
|
| 2326 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2327 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2328 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2329 | - |
|
| 2330 | - if (!$intermediaire or !$arrivee) { |
|
| 2331 | - return ''; |
|
| 2332 | - } |
|
| 2333 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2334 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2335 | - |
|
| 2336 | - $res = fabrique_jointures($boucle, |
|
| 2337 | - array( |
|
| 2338 | - array( |
|
| 2339 | - $boucle->id_table, |
|
| 2340 | - $intermediaire, |
|
| 2341 | - array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2342 | - ), |
|
| 2343 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2344 | - ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2345 | - |
|
| 2346 | - return $res; |
|
| 2324 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2325 | + |
|
| 2326 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2327 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2328 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2329 | + |
|
| 2330 | + if (!$intermediaire or !$arrivee) { |
|
| 2331 | + return ''; |
|
| 2332 | + } |
|
| 2333 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2334 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2335 | + |
|
| 2336 | + $res = fabrique_jointures($boucle, |
|
| 2337 | + array( |
|
| 2338 | + array( |
|
| 2339 | + $boucle->id_table, |
|
| 2340 | + $intermediaire, |
|
| 2341 | + array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2342 | + ), |
|
| 2343 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2344 | + ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2345 | + |
|
| 2346 | + return $res; |
|
| 2347 | 2347 | } |
| 2348 | 2348 | |
| 2349 | 2349 | |
@@ -2360,17 +2360,17 @@ discard block |
||
| 2360 | 2360 | * false sinon. |
| 2361 | 2361 | **/ |
| 2362 | 2362 | function trouver_champ($champ, $where) { |
| 2363 | - if (!is_array($where)) { |
|
| 2364 | - return preg_match($champ, $where); |
|
| 2365 | - } else { |
|
| 2366 | - foreach ($where as $clause) { |
|
| 2367 | - if (trouver_champ($champ, $clause)) { |
|
| 2368 | - return true; |
|
| 2369 | - } |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - return false; |
|
| 2373 | - } |
|
| 2363 | + if (!is_array($where)) { |
|
| 2364 | + return preg_match($champ, $where); |
|
| 2365 | + } else { |
|
| 2366 | + foreach ($where as $clause) { |
|
| 2367 | + if (trouver_champ($champ, $clause)) { |
|
| 2368 | + return true; |
|
| 2369 | + } |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + return false; |
|
| 2373 | + } |
|
| 2374 | 2374 | } |
| 2375 | 2375 | |
| 2376 | 2376 | |
@@ -2396,129 +2396,129 @@ discard block |
||
| 2396 | 2396 | * - string $args_sql Suite des arguments du critère. ? |
| 2397 | 2397 | **/ |
| 2398 | 2398 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2399 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2400 | - if (count($crit->param) == 0) { |
|
| 2401 | - $op = '='; |
|
| 2402 | - $col = $val = $crit->op; |
|
| 2403 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2404 | - $val = $r[2]; |
|
| 2405 | - } |
|
| 2406 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2407 | - if ($val == 'lang') { |
|
| 2408 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2409 | - } else { |
|
| 2410 | - $defaut = null; |
|
| 2411 | - if ($val == 'id_parent') { |
|
| 2412 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2413 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2414 | - // pour eviter l'erreur SQL |
|
| 2415 | - $val = $boucles[$idb]->primary; |
|
| 2416 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2417 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2418 | - } elseif ($val == 'id_enfant') { |
|
| 2419 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2420 | - // de la boucle superieure |
|
| 2421 | - $val = 'id_parent'; |
|
| 2422 | - } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2423 | - // un critere conditionnel sur date est traite a part |
|
| 2424 | - // car la date est mise d'office par SPIP, |
|
| 2425 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2426 | - } |
|
| 2427 | - |
|
| 2428 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2429 | - $val = array(kwote($val)); |
|
| 2430 | - } |
|
| 2431 | - } else { |
|
| 2432 | - // comparaison explicite |
|
| 2433 | - // le phraseur impose que le premier param soit du texte |
|
| 2434 | - $params = $crit->param; |
|
| 2435 | - $op = $crit->op; |
|
| 2436 | - if ($op == '==') { |
|
| 2437 | - $op = 'REGEXP'; |
|
| 2438 | - } |
|
| 2439 | - $col = array_shift($params); |
|
| 2440 | - $col = $col[0]->texte; |
|
| 2441 | - |
|
| 2442 | - $val = array(); |
|
| 2443 | - $desc = array('id_mere' => $idb); |
|
| 2444 | - $parent = $boucles[$idb]->id_parent; |
|
| 2445 | - |
|
| 2446 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2447 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2448 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2449 | - if (count($params) == 1 |
|
| 2450 | - and count($params[0]) == 3 |
|
| 2451 | - and $params[0][0]->type == 'texte' |
|
| 2452 | - and $params[0][2]->type == 'texte' |
|
| 2453 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2454 | - and (($p == "'") or ($p == '"')) |
|
| 2455 | - and $params[0][1]->type == 'champ' |
|
| 2456 | - ) { |
|
| 2457 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2458 | - } else { |
|
| 2459 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2460 | - $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2461 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2462 | - $val[] = $a; |
|
| 2463 | - } else { |
|
| 2464 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2465 | - } // toujours quoter en char ici |
|
| 2466 | - } |
|
| 2467 | - } |
|
| 2468 | - } |
|
| 2469 | - |
|
| 2470 | - $fct = $args_sql = ''; |
|
| 2471 | - // fonction SQL ? |
|
| 2472 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2473 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2474 | - $fct = $m[1]; |
|
| 2475 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2476 | - $col = $a[1]; |
|
| 2477 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2478 | - $col = $m[1]; |
|
| 2479 | - $args_sql = $m[2]; |
|
| 2480 | - } |
|
| 2481 | - $args_sql .= $a[2]; |
|
| 2482 | - } |
|
| 2483 | - |
|
| 2484 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 2399 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2400 | + if (count($crit->param) == 0) { |
|
| 2401 | + $op = '='; |
|
| 2402 | + $col = $val = $crit->op; |
|
| 2403 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2404 | + $val = $r[2]; |
|
| 2405 | + } |
|
| 2406 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2407 | + if ($val == 'lang') { |
|
| 2408 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2409 | + } else { |
|
| 2410 | + $defaut = null; |
|
| 2411 | + if ($val == 'id_parent') { |
|
| 2412 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2413 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2414 | + // pour eviter l'erreur SQL |
|
| 2415 | + $val = $boucles[$idb]->primary; |
|
| 2416 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2417 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2418 | + } elseif ($val == 'id_enfant') { |
|
| 2419 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2420 | + // de la boucle superieure |
|
| 2421 | + $val = 'id_parent'; |
|
| 2422 | + } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2423 | + // un critere conditionnel sur date est traite a part |
|
| 2424 | + // car la date est mise d'office par SPIP, |
|
| 2425 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2426 | + } |
|
| 2427 | + |
|
| 2428 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2429 | + $val = array(kwote($val)); |
|
| 2430 | + } |
|
| 2431 | + } else { |
|
| 2432 | + // comparaison explicite |
|
| 2433 | + // le phraseur impose que le premier param soit du texte |
|
| 2434 | + $params = $crit->param; |
|
| 2435 | + $op = $crit->op; |
|
| 2436 | + if ($op == '==') { |
|
| 2437 | + $op = 'REGEXP'; |
|
| 2438 | + } |
|
| 2439 | + $col = array_shift($params); |
|
| 2440 | + $col = $col[0]->texte; |
|
| 2441 | + |
|
| 2442 | + $val = array(); |
|
| 2443 | + $desc = array('id_mere' => $idb); |
|
| 2444 | + $parent = $boucles[$idb]->id_parent; |
|
| 2445 | + |
|
| 2446 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2447 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2448 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2449 | + if (count($params) == 1 |
|
| 2450 | + and count($params[0]) == 3 |
|
| 2451 | + and $params[0][0]->type == 'texte' |
|
| 2452 | + and $params[0][2]->type == 'texte' |
|
| 2453 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2454 | + and (($p == "'") or ($p == '"')) |
|
| 2455 | + and $params[0][1]->type == 'champ' |
|
| 2456 | + ) { |
|
| 2457 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2458 | + } else { |
|
| 2459 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2460 | + $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2461 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2462 | + $val[] = $a; |
|
| 2463 | + } else { |
|
| 2464 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2465 | + } // toujours quoter en char ici |
|
| 2466 | + } |
|
| 2467 | + } |
|
| 2468 | + } |
|
| 2469 | + |
|
| 2470 | + $fct = $args_sql = ''; |
|
| 2471 | + // fonction SQL ? |
|
| 2472 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2473 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2474 | + $fct = $m[1]; |
|
| 2475 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2476 | + $col = $a[1]; |
|
| 2477 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2478 | + $col = $m[1]; |
|
| 2479 | + $args_sql = $m[2]; |
|
| 2480 | + } |
|
| 2481 | + $args_sql .= $a[2]; |
|
| 2482 | + } |
|
| 2483 | + |
|
| 2484 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 2485 | 2485 | } |
| 2486 | 2486 | |
| 2487 | 2487 | // compatibilite ancienne version |
| 2488 | 2488 | |
| 2489 | 2489 | // http://code.spip.net/@calculer_vieux_in |
| 2490 | 2490 | function calculer_vieux_in($params) { |
| 2491 | - $deb = $params[0][0]; |
|
| 2492 | - $k = count($params) - 1; |
|
| 2493 | - $last = $params[$k]; |
|
| 2494 | - $j = count($last) - 1; |
|
| 2495 | - $last = $last[$j]; |
|
| 2496 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2497 | - |
|
| 2498 | - if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2499 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2500 | - ) { |
|
| 2501 | - return $params; |
|
| 2502 | - } |
|
| 2503 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2504 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2505 | - $last = $params[$k][$j]; |
|
| 2506 | - $n = strlen($last->texte); |
|
| 2507 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2508 | - $newp = array(); |
|
| 2509 | - foreach ($params as $v) { |
|
| 2510 | - if ($v[0]->type != 'texte') { |
|
| 2511 | - $newp[] = $v; |
|
| 2512 | - } else { |
|
| 2513 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2514 | - $t = new Texte; |
|
| 2515 | - $t->texte = $x; |
|
| 2516 | - $newp[] = array($t); |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - return $newp; |
|
| 2491 | + $deb = $params[0][0]; |
|
| 2492 | + $k = count($params) - 1; |
|
| 2493 | + $last = $params[$k]; |
|
| 2494 | + $j = count($last) - 1; |
|
| 2495 | + $last = $last[$j]; |
|
| 2496 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2497 | + |
|
| 2498 | + if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2499 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2500 | + ) { |
|
| 2501 | + return $params; |
|
| 2502 | + } |
|
| 2503 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2504 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2505 | + $last = $params[$k][$j]; |
|
| 2506 | + $n = strlen($last->texte); |
|
| 2507 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2508 | + $newp = array(); |
|
| 2509 | + foreach ($params as $v) { |
|
| 2510 | + if ($v[0]->type != 'texte') { |
|
| 2511 | + $newp[] = $v; |
|
| 2512 | + } else { |
|
| 2513 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2514 | + $t = new Texte; |
|
| 2515 | + $t->texte = $x; |
|
| 2516 | + $newp[] = array($t); |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + return $newp; |
|
| 2522 | 2522 | } |
| 2523 | 2523 | |
| 2524 | 2524 | /** |
@@ -2537,89 +2537,89 @@ discard block |
||
| 2537 | 2537 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2538 | 2538 | **/ |
| 2539 | 2539 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2540 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2541 | - return ''; |
|
| 2542 | - } |
|
| 2543 | - |
|
| 2544 | - $boucle = $boucles[$idb]; |
|
| 2545 | - $table = $boucle->show; |
|
| 2546 | - |
|
| 2547 | - // si c'est une colonne de la table, ne rien faire |
|
| 2548 | - if (isset($table['field'][$col])) { |
|
| 2549 | - return ''; |
|
| 2550 | - } |
|
| 2551 | - |
|
| 2552 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2553 | - return ''; |
|
| 2554 | - } |
|
| 2555 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2556 | - |
|
| 2557 | - $col = $regs[1]; |
|
| 2558 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2559 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2560 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2561 | - |
|
| 2562 | - if (isset($table['field']["date$suite"])) { |
|
| 2563 | - $date_orig = 'date' . $suite; |
|
| 2564 | - } else { |
|
| 2565 | - $date_orig = substr($suite, 1); |
|
| 2566 | - } |
|
| 2567 | - $pred = $date_orig; |
|
| 2568 | - } else { |
|
| 2569 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2570 | - $pred = 'date'; |
|
| 2571 | - } |
|
| 2572 | - } |
|
| 2573 | - |
|
| 2574 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2575 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2576 | - ") . '\""; |
|
| 2577 | - |
|
| 2578 | - $col_vraie = $date_orig; |
|
| 2579 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2580 | - |
|
| 2581 | - switch ($col) { |
|
| 2582 | - case 'date': |
|
| 2583 | - $col = $date_orig; |
|
| 2584 | - break; |
|
| 2585 | - case 'jour': |
|
| 2586 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2587 | - break; |
|
| 2588 | - case 'mois': |
|
| 2589 | - $col = "MONTH($date_orig)"; |
|
| 2590 | - break; |
|
| 2591 | - case 'annee': |
|
| 2592 | - $col = "YEAR($date_orig)"; |
|
| 2593 | - break; |
|
| 2594 | - case 'heure': |
|
| 2595 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2596 | - break; |
|
| 2597 | - case 'age': |
|
| 2598 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 2599 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2600 | - break; |
|
| 2601 | - case 'age_relatif': |
|
| 2602 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2603 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2604 | - break; |
|
| 2605 | - case 'jour_relatif': |
|
| 2606 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2607 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2608 | - break; |
|
| 2609 | - case 'mois_relatif': |
|
| 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) |
|
| 2614 | - break; |
|
| 2615 | - case 'annee_relatif': |
|
| 2616 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2617 | - $date_orig . ")"; |
|
| 2618 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | - break; |
|
| 2620 | - } |
|
| 2621 | - |
|
| 2622 | - return array($col, $col_vraie); |
|
| 2540 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2541 | + return ''; |
|
| 2542 | + } |
|
| 2543 | + |
|
| 2544 | + $boucle = $boucles[$idb]; |
|
| 2545 | + $table = $boucle->show; |
|
| 2546 | + |
|
| 2547 | + // si c'est une colonne de la table, ne rien faire |
|
| 2548 | + if (isset($table['field'][$col])) { |
|
| 2549 | + return ''; |
|
| 2550 | + } |
|
| 2551 | + |
|
| 2552 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2553 | + return ''; |
|
| 2554 | + } |
|
| 2555 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2556 | + |
|
| 2557 | + $col = $regs[1]; |
|
| 2558 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2559 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2560 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2561 | + |
|
| 2562 | + if (isset($table['field']["date$suite"])) { |
|
| 2563 | + $date_orig = 'date' . $suite; |
|
| 2564 | + } else { |
|
| 2565 | + $date_orig = substr($suite, 1); |
|
| 2566 | + } |
|
| 2567 | + $pred = $date_orig; |
|
| 2568 | + } else { |
|
| 2569 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2570 | + $pred = 'date'; |
|
| 2571 | + } |
|
| 2572 | + } |
|
| 2573 | + |
|
| 2574 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2575 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2576 | + ") . '\""; |
|
| 2577 | + |
|
| 2578 | + $col_vraie = $date_orig; |
|
| 2579 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2580 | + |
|
| 2581 | + switch ($col) { |
|
| 2582 | + case 'date': |
|
| 2583 | + $col = $date_orig; |
|
| 2584 | + break; |
|
| 2585 | + case 'jour': |
|
| 2586 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2587 | + break; |
|
| 2588 | + case 'mois': |
|
| 2589 | + $col = "MONTH($date_orig)"; |
|
| 2590 | + break; |
|
| 2591 | + case 'annee': |
|
| 2592 | + $col = "YEAR($date_orig)"; |
|
| 2593 | + break; |
|
| 2594 | + case 'heure': |
|
| 2595 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2596 | + break; |
|
| 2597 | + case 'age': |
|
| 2598 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 2599 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2600 | + break; |
|
| 2601 | + case 'age_relatif': |
|
| 2602 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2603 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2604 | + break; |
|
| 2605 | + case 'jour_relatif': |
|
| 2606 | + $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2607 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2608 | + break; |
|
| 2609 | + case 'mois_relatif': |
|
| 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) |
|
| 2614 | + break; |
|
| 2615 | + case 'annee_relatif': |
|
| 2616 | + $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2617 | + $date_orig . ")"; |
|
| 2618 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2619 | + break; |
|
| 2620 | + } |
|
| 2621 | + |
|
| 2622 | + return array($col, $col_vraie); |
|
| 2623 | 2623 | } |
| 2624 | 2624 | |
| 2625 | 2625 | /** |
@@ -2638,16 +2638,16 @@ discard block |
||
| 2638 | 2638 | * de colonne SQL et une date. |
| 2639 | 2639 | **/ |
| 2640 | 2640 | function calculer_param_date($date_compare, $date_orig) { |
| 2641 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2642 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2643 | - $date_compare = '\'$x\''; |
|
| 2644 | - } else { |
|
| 2645 | - $init = $date_compare; |
|
| 2646 | - } |
|
| 2647 | - |
|
| 2648 | - return |
|
| 2649 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2650 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2641 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2642 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2643 | + $date_compare = '\'$x\''; |
|
| 2644 | + } else { |
|
| 2645 | + $init = $date_compare; |
|
| 2646 | + } |
|
| 2647 | + |
|
| 2648 | + return |
|
| 2649 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2650 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2651 | 2651 | } |
| 2652 | 2652 | |
| 2653 | 2653 | /** |
@@ -2665,18 +2665,18 @@ discard block |
||
| 2665 | 2665 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2666 | 2666 | */ |
| 2667 | 2667 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2668 | - $boucle = &$boucles[$idb]; |
|
| 2668 | + $boucle = &$boucles[$idb]; |
|
| 2669 | 2669 | |
| 2670 | - $args = array(); |
|
| 2671 | - foreach ($crit->param as &$param) { |
|
| 2672 | - array_push($args, |
|
| 2673 | - calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2674 | - } |
|
| 2670 | + $args = array(); |
|
| 2671 | + foreach ($crit->param as &$param) { |
|
| 2672 | + array_push($args, |
|
| 2673 | + calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2674 | + } |
|
| 2675 | 2675 | |
| 2676 | - $boucle->hash .= ' |
|
| 2676 | + $boucle->hash .= ' |
|
| 2677 | 2677 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2678 | 2678 | |
| 2679 | - $boucle->hash .= ' |
|
| 2679 | + $boucle->hash .= ' |
|
| 2680 | 2680 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2681 | 2681 | } |
| 2682 | 2682 | |
@@ -2693,8 +2693,8 @@ discard block |
||
| 2693 | 2693 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2694 | 2694 | */ |
| 2695 | 2695 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2696 | - $boucle = &$boucles[$idb]; |
|
| 2697 | - $boucle->hash .= ' |
|
| 2696 | + $boucle = &$boucles[$idb]; |
|
| 2697 | + $boucle->hash .= ' |
|
| 2698 | 2698 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2699 | 2699 | $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2700 | 2700 | } |
@@ -2714,8 +2714,8 @@ discard block |
||
| 2714 | 2714 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2715 | 2715 | */ |
| 2716 | 2716 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2717 | - $boucle = &$boucles[$idb]; |
|
| 2718 | - $boucle->hash .= ' |
|
| 2717 | + $boucle = &$boucles[$idb]; |
|
| 2718 | + $boucle->hash .= ' |
|
| 2719 | 2719 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2720 | 2720 | } |
| 2721 | 2721 | |
@@ -2731,12 +2731,12 @@ discard block |
||
| 2731 | 2731 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2732 | 2732 | */ |
| 2733 | 2733 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2734 | - $boucle = &$boucles[$idb]; |
|
| 2735 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2736 | - foreach ($crit->param as $param) { |
|
| 2737 | - $boucle->hash .= ' |
|
| 2734 | + $boucle = &$boucles[$idb]; |
|
| 2735 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2736 | + foreach ($crit->param as $param) { |
|
| 2737 | + $boucle->hash .= ' |
|
| 2738 | 2738 | $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2739 | - } |
|
| 2739 | + } |
|
| 2740 | 2740 | } |
| 2741 | 2741 | |
| 2742 | 2742 | /** |
@@ -2753,12 +2753,12 @@ discard block |
||
| 2753 | 2753 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2754 | 2754 | */ |
| 2755 | 2755 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2756 | - $boucle = &$boucles[$idb]; |
|
| 2757 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2758 | - foreach ($crit->param as $param) { |
|
| 2759 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2760 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2761 | - } |
|
| 2756 | + $boucle = &$boucles[$idb]; |
|
| 2757 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2758 | + foreach ($crit->param as $param) { |
|
| 2759 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2760 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2761 | + } |
|
| 2762 | 2762 | } |
| 2763 | 2763 | |
| 2764 | 2764 | /** |
@@ -2783,12 +2783,12 @@ discard block |
||
| 2783 | 2783 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2784 | 2784 | */ |
| 2785 | 2785 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2786 | - $boucle = &$boucles[$idb]; |
|
| 2787 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2788 | - foreach ($crit->param as $param) { |
|
| 2789 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2790 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2791 | - } |
|
| 2786 | + $boucle = &$boucles[$idb]; |
|
| 2787 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2788 | + foreach ($crit->param as $param) { |
|
| 2789 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2790 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2791 | + } |
|
| 2792 | 2792 | } |
| 2793 | 2793 | |
| 2794 | 2794 | /** |
@@ -2803,11 +2803,11 @@ discard block |
||
| 2803 | 2803 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2804 | 2804 | */ |
| 2805 | 2805 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2806 | - $boucle = &$boucles[$idb]; |
|
| 2807 | - foreach ($crit->param as $param) { |
|
| 2808 | - $boucle->hash .= ' |
|
| 2806 | + $boucle = &$boucles[$idb]; |
|
| 2807 | + foreach ($crit->param as $param) { |
|
| 2808 | + $boucle->hash .= ' |
|
| 2809 | 2809 | $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2810 | - } |
|
| 2810 | + } |
|
| 2811 | 2811 | } |
| 2812 | 2812 | |
| 2813 | 2813 | |
@@ -2839,20 +2839,20 @@ discard block |
||
| 2839 | 2839 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2840 | 2840 | */ |
| 2841 | 2841 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2842 | - $boucle = &$boucles[$idb]; |
|
| 2843 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2844 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2845 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2846 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2847 | - if ($crit->param) { |
|
| 2848 | - foreach ($crit->param as $param) { |
|
| 2849 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2850 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2851 | - } |
|
| 2852 | - // interdire {si 0} aussi ! |
|
| 2853 | - } else { |
|
| 2854 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2855 | - } |
|
| 2842 | + $boucle = &$boucles[$idb]; |
|
| 2843 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2844 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2845 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2846 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2847 | + if ($crit->param) { |
|
| 2848 | + foreach ($crit->param as $param) { |
|
| 2849 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2850 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2851 | + } |
|
| 2852 | + // interdire {si 0} aussi ! |
|
| 2853 | + } else { |
|
| 2854 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2855 | + } |
|
| 2856 | 2856 | } |
| 2857 | 2857 | |
| 2858 | 2858 | /** |
@@ -2868,8 +2868,8 @@ discard block |
||
| 2868 | 2868 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2869 | 2869 | */ |
| 2870 | 2870 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2871 | - $boucle = &$boucles[$idb]; |
|
| 2872 | - $boucle->hash .= ' |
|
| 2871 | + $boucle = &$boucles[$idb]; |
|
| 2872 | + $boucle->hash .= ' |
|
| 2873 | 2873 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2874 | 2874 | $command[\'sourcemode\'] = \'table\';'; |
| 2875 | 2875 | } |
@@ -2890,29 +2890,29 @@ discard block |
||
| 2890 | 2890 | */ |
| 2891 | 2891 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2892 | 2892 | |
| 2893 | - $not = $crit->not; |
|
| 2894 | - $boucle = &$boucles[$idb]; |
|
| 2895 | - $primary = $boucle->primary; |
|
| 2893 | + $not = $crit->not; |
|
| 2894 | + $boucle = &$boucles[$idb]; |
|
| 2895 | + $primary = $boucle->primary; |
|
| 2896 | 2896 | |
| 2897 | - if (!$primary or strpos($primary, ',')) { |
|
| 2898 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2897 | + if (!$primary or strpos($primary, ',')) { |
|
| 2898 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2899 | 2899 | |
| 2900 | - return; |
|
| 2901 | - } |
|
| 2902 | - $table = $boucle->type_requete; |
|
| 2903 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2900 | + return; |
|
| 2901 | + } |
|
| 2902 | + $table = $boucle->type_requete; |
|
| 2903 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2904 | 2904 | |
| 2905 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2906 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2907 | - 'id_parent'; |
|
| 2905 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2906 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2907 | + 'id_parent'; |
|
| 2908 | 2908 | |
| 2909 | - $in = "IN"; |
|
| 2910 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2911 | - if ($not) { |
|
| 2912 | - $where = array("'NOT'", $where); |
|
| 2913 | - } |
|
| 2909 | + $in = "IN"; |
|
| 2910 | + $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2911 | + if ($not) { |
|
| 2912 | + $where = array("'NOT'", $where); |
|
| 2913 | + } |
|
| 2914 | 2914 | |
| 2915 | - $boucle->where[] = $where; |
|
| 2915 | + $boucle->where[] = $where; |
|
| 2916 | 2916 | } |
| 2917 | 2917 | |
| 2918 | 2918 | /** |
@@ -2928,8 +2928,8 @@ discard block |
||
| 2928 | 2928 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2929 | 2929 | */ |
| 2930 | 2930 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2931 | - $not = $crit->not; |
|
| 2932 | - $crit->not = $not ? false : true; |
|
| 2933 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2934 | - $crit->not = $not; |
|
| 2931 | + $not = $crit->not; |
|
| 2932 | + $crit->not = $not ? false : true; |
|
| 2933 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2934 | + $crit->not = $not; |
|
| 2935 | 2935 | } |
@@ -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 | /** |
@@ -544,9 +541,9 @@ discard block |
||
| 544 | 541 | $not = ($crit->not ? 'NOT' : ''); |
| 545 | 542 | $serveur = $boucle->sql_serveur; |
| 546 | 543 | |
| 547 | - $c = "sql_in('" . |
|
| 548 | - $boucle->id_table . '.' . $boucle->primary |
|
| 549 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 544 | + $c = "sql_in('". |
|
| 545 | + $boucle->id_table.'.'.$boucle->primary |
|
| 546 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 550 | 547 | |
| 551 | 548 | $boucle->where[] = $c; |
| 552 | 549 | } |
@@ -578,7 +575,7 @@ discard block |
||
| 578 | 575 | $t = table_objet_sql($r[1]); |
| 579 | 576 | $t = array_search($t, $boucles[$idb]->from); |
| 580 | 577 | if ($t) { |
| 581 | - $t .= '.' . $r[2]; |
|
| 578 | + $t .= '.'.$r[2]; |
|
| 582 | 579 | } |
| 583 | 580 | } |
| 584 | 581 | } else { |
@@ -593,7 +590,7 @@ discard block |
||
| 593 | 590 | $boucles[$idb]->select[] = $t; |
| 594 | 591 | } |
| 595 | 592 | } else { |
| 596 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 593 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 597 | 594 | } |
| 598 | 595 | } |
| 599 | 596 | |
@@ -643,26 +640,26 @@ discard block |
||
| 643 | 640 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 644 | 641 | OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 645 | 642 | ) { |
| 646 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 643 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 647 | 644 | } else { |
| 648 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 645 | + $boucle->order[$n - 1] .= " . ".$boucle->modificateur['collate']; |
|
| 649 | 646 | } |
| 650 | 647 | } |
| 651 | 648 | } else { |
| 652 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 649 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 653 | 650 | } |
| 654 | 651 | } |
| 655 | 652 | |
| 656 | 653 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 657 | 654 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 658 | 655 | $boucle = $boucles[$idb]; |
| 659 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 660 | - $var = '$champs_' . $idb; |
|
| 656 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 657 | + $var = '$champs_'.$idb; |
|
| 661 | 658 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 662 | 659 | if (!$desc) { |
| 663 | 660 | $desc = $boucle->show['field']; |
| 664 | 661 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 665 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 662 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 666 | 663 | } |
| 667 | 664 | if ($desc) { |
| 668 | 665 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -737,7 +734,7 @@ discard block |
||
| 737 | 734 | $sens = " . ' DESC'"; |
| 738 | 735 | } |
| 739 | 736 | if (isset($boucle->modificateur['collate'])) { |
| 740 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 737 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 741 | 738 | } |
| 742 | 739 | |
| 743 | 740 | // Pour chaque paramètre du critère |
@@ -759,14 +756,14 @@ discard block |
||
| 759 | 756 | if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
| 760 | 757 | $expression = trim($m[1]); |
| 761 | 758 | $champ = trim($m[2]); |
| 762 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 759 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 763 | 760 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 764 | 761 | } else { |
| 765 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 762 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 766 | 763 | } |
| 767 | 764 | |
| 768 | 765 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 769 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 766 | + } elseif (preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 770 | 767 | // {par FONCTION(champ)} |
| 771 | 768 | if (count($match) > 2) { |
| 772 | 769 | $par = substr($match[2], 1, -1); |
@@ -776,7 +773,7 @@ discard block |
||
| 776 | 773 | if ($par == 'hasard') { |
| 777 | 774 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 778 | 775 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 779 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 776 | + $order = "'".$boucle->id_table.".".$boucle->show['date']."'"; |
|
| 780 | 777 | } else { |
| 781 | 778 | // cas général {par champ}, {par table.champ}, ... |
| 782 | 779 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -785,7 +782,7 @@ discard block |
||
| 785 | 782 | |
| 786 | 783 | // on ne sait pas traiter… |
| 787 | 784 | else { |
| 788 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 785 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 789 | 786 | } |
| 790 | 787 | |
| 791 | 788 | // En cas d'erreur de squelette retournée par une fonction |
@@ -805,14 +802,14 @@ discard block |
||
| 805 | 802 | |
| 806 | 803 | if ($fct) { |
| 807 | 804 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 808 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 805 | + $order = "'$fct(".$r[1].")'"; |
|
| 809 | 806 | } else { |
| 810 | 807 | $order = "'$fct(' . $order . ')'"; |
| 811 | 808 | } |
| 812 | 809 | } |
| 813 | - $t = $order . $collecte . $sens; |
|
| 810 | + $t = $order.$collecte.$sens; |
|
| 814 | 811 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 815 | - $t = $r[1] . $r[2]; |
|
| 812 | + $t = $r[1].$r[2]; |
|
| 816 | 813 | } |
| 817 | 814 | |
| 818 | 815 | $boucle->order[] = $t; |
@@ -862,16 +859,16 @@ discard block |
||
| 862 | 859 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 863 | 860 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 864 | 861 | if (is_array($_champ)) { |
| 865 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 862 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." num $champ")); |
|
| 866 | 863 | } |
| 867 | 864 | $boucle = &$boucles[$idb]; |
| 868 | - $texte = '0+' . $_champ; |
|
| 865 | + $texte = '0+'.$_champ; |
|
| 869 | 866 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 870 | 867 | if ($suite !== "''") { |
| 871 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 868 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 872 | 869 | } |
| 873 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 874 | - $boucle->select[] = $texte . " AS $as"; |
|
| 870 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 871 | + $boucle->select[] = $texte." AS $as"; |
|
| 875 | 872 | $order = "'$as'"; |
| 876 | 873 | return $order; |
| 877 | 874 | } |
@@ -896,16 +893,16 @@ discard block |
||
| 896 | 893 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 897 | 894 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 898 | 895 | if (is_array($_champ)) { |
| 899 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 896 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." sinum $champ")); |
|
| 900 | 897 | } |
| 901 | 898 | $boucle = &$boucles[$idb]; |
| 902 | - $texte = '0+' . $_champ; |
|
| 899 | + $texte = '0+'.$_champ; |
|
| 903 | 900 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 904 | 901 | if ($suite !== "''") { |
| 905 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 902 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 906 | 903 | } |
| 907 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 908 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 904 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ""); |
|
| 905 | + $boucle->select[] = 'CASE ('.$texte.') WHEN 0 THEN 1 ELSE 0 END AS '.$as; |
|
| 909 | 906 | $order = "'$as'"; |
| 910 | 907 | return $order; |
| 911 | 908 | } |
@@ -929,10 +926,10 @@ discard block |
||
| 929 | 926 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 930 | 927 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 931 | 928 | if (is_array($_champ)) { |
| 932 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 929 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." multi $champ")); |
|
| 933 | 930 | } |
| 934 | 931 | $boucle = &$boucles[$idb]; |
| 935 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 932 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 936 | 933 | $order = "'multi'"; |
| 937 | 934 | return $order; |
| 938 | 935 | } |
@@ -952,13 +949,13 @@ discard block |
||
| 952 | 949 | * @param bool $raw Retourne le champ pour le compilateur ("'alias.champ'") ou brut ('alias.champ') |
| 953 | 950 | * @return array|string |
| 954 | 951 | */ |
| 955 | -function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 952 | +function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 956 | 953 | $boucle = &$boucles[$idb]; |
| 957 | 954 | $desc = $boucle->show; |
| 958 | 955 | |
| 959 | 956 | // le champ existe dans la table, pas de souci (le plus commun) |
| 960 | 957 | if (isset($desc['field'][$par])) { |
| 961 | - $par = $boucle->id_table . "." . $par; |
|
| 958 | + $par = $boucle->id_table.".".$par; |
|
| 962 | 959 | } |
| 963 | 960 | // le champ est peut être une jointure |
| 964 | 961 | else { |
@@ -979,24 +976,24 @@ discard block |
||
| 979 | 976 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 980 | 977 | // Si la table est déjà dans le from, on la réutilise. |
| 981 | 978 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 982 | - $par = $infos['alias'] . "." . $champ; |
|
| 979 | + $par = $infos['alias'].".".$champ; |
|
| 983 | 980 | } elseif ( |
| 984 | 981 | $boucle->jointures_explicites |
| 985 | 982 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 986 | 983 | ) { |
| 987 | - $par = $alias . "." . $champ; |
|
| 984 | + $par = $alias.".".$champ; |
|
| 988 | 985 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 989 | - $par = $alias . "." . $champ; |
|
| 986 | + $par = $alias.".".$champ; |
|
| 990 | 987 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 991 | 988 | } elseif ( |
| 992 | 989 | $table_alias |
| 993 | 990 | and isset($boucle->from[$table_alias]) |
| 994 | 991 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 995 | 992 | ) { |
| 996 | - $par = $infos['alias'] . "." . $champ; |
|
| 993 | + $par = $infos['alias'].".".$champ; |
|
| 997 | 994 | } elseif ($table) { |
| 998 | 995 | // On avait table + champ, mais on ne les a pas trouvés |
| 999 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 996 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 1000 | 997 | } else { |
| 1001 | 998 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1002 | 999 | } |
@@ -1020,7 +1017,7 @@ discard block |
||
| 1020 | 1017 | if (!$t) { |
| 1021 | 1018 | $t = trouver_jointure_champ($champ, $boucle); |
| 1022 | 1019 | } |
| 1023 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1020 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1024 | 1021 | } |
| 1025 | 1022 | |
| 1026 | 1023 | /** |
@@ -1065,9 +1062,9 @@ discard block |
||
| 1065 | 1062 | $boucle->default_order[] = ' DESC'; |
| 1066 | 1063 | } |
| 1067 | 1064 | } else { |
| 1068 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1065 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1069 | 1066 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1070 | - $t = $r[1] . $r[2]; |
|
| 1067 | + $t = $r[1].$r[2]; |
|
| 1071 | 1068 | } |
| 1072 | 1069 | $boucle->order[$n - 1] = $t; |
| 1073 | 1070 | } |
@@ -1079,7 +1076,7 @@ discard block |
||
| 1079 | 1076 | $params = $crit->param; |
| 1080 | 1077 | |
| 1081 | 1078 | if (count($params) < 1) { |
| 1082 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1079 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ?")); |
|
| 1083 | 1080 | } |
| 1084 | 1081 | |
| 1085 | 1082 | $boucle = &$boucles[$idb]; |
@@ -1100,7 +1097,7 @@ discard block |
||
| 1100 | 1097 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1101 | 1098 | $date = $date[0]->texte; |
| 1102 | 1099 | if (!isset($fields[$date])) { |
| 1103 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1100 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ".$date)); |
|
| 1104 | 1101 | } |
| 1105 | 1102 | } else { |
| 1106 | 1103 | $a = calculer_liste($date, array(), $boucles, $parent); |
@@ -1112,38 +1109,38 @@ discard block |
||
| 1112 | 1109 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1113 | 1110 | } |
| 1114 | 1111 | $annee = $params ? array_shift($params) : ""; |
| 1115 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1116 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1112 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1113 | + calculer_liste($annee, array(), $boucles, $parent). |
|
| 1117 | 1114 | ') ? $x : date("Y"))'; |
| 1118 | 1115 | |
| 1119 | 1116 | $mois = $params ? array_shift($params) : ""; |
| 1120 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1121 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1117 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1118 | + calculer_liste($mois, array(), $boucles, $parent). |
|
| 1122 | 1119 | ') ? $x : date("m"))'; |
| 1123 | 1120 | |
| 1124 | 1121 | $jour = $params ? array_shift($params) : ""; |
| 1125 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1126 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1122 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1123 | + calculer_liste($jour, array(), $boucles, $parent). |
|
| 1127 | 1124 | ') ? $x : date("d"))'; |
| 1128 | 1125 | |
| 1129 | 1126 | $annee2 = $params ? array_shift($params) : ""; |
| 1130 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1131 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1127 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1128 | + calculer_liste($annee2, array(), $boucles, $parent). |
|
| 1132 | 1129 | ') ? $x : date("Y"))'; |
| 1133 | 1130 | |
| 1134 | 1131 | $mois2 = $params ? array_shift($params) : ""; |
| 1135 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1136 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1132 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1133 | + calculer_liste($mois2, array(), $boucles, $parent). |
|
| 1137 | 1134 | ') ? $x : date("m"))'; |
| 1138 | 1135 | |
| 1139 | 1136 | $jour2 = $params ? array_shift($params) : ""; |
| 1140 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1141 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1137 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1138 | + calculer_liste($jour2, array(), $boucles, $parent). |
|
| 1142 | 1139 | ') ? $x : date("d"))'; |
| 1143 | 1140 | |
| 1144 | - $date = $boucle->id_table . ".$date"; |
|
| 1141 | + $date = $boucle->id_table.".$date"; |
|
| 1145 | 1142 | |
| 1146 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1143 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1147 | 1144 | if ($type == 'jour') { |
| 1148 | 1145 | $boucle->where[] = array( |
| 1149 | 1146 | "'='", |
@@ -1215,14 +1212,13 @@ discard block |
||
| 1215 | 1212 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1216 | 1213 | |
| 1217 | 1214 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1218 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1215 | + $boucle->limit = $a11.','.$a21; |
|
| 1219 | 1216 | } else { |
| 1220 | 1217 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1221 | 1218 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1222 | 1219 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1223 | 1220 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1224 | - $mode = (($op == '/') ? '/' : |
|
| 1225 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1221 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1226 | 1222 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1227 | 1223 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
| 1228 | 1224 | $boucle->limit = |
@@ -1268,8 +1264,7 @@ discard block |
||
| 1268 | 1264 | // {1/3} |
| 1269 | 1265 | if ($op1 == '/') { |
| 1270 | 1266 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1271 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1272 | - "($total_parties ? $total_parties : 1)"; |
|
| 1267 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1273 | 1268 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1274 | 1269 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1275 | 1270 | } else { |
@@ -1280,15 +1275,13 @@ discard block |
||
| 1280 | 1275 | |
| 1281 | 1276 | // cas {x,n-1} |
| 1282 | 1277 | if ($op2 == '-') { |
| 1283 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1284 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1285 | - ($total_parties . ' - 1')); |
|
| 1278 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1279 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1286 | 1280 | } else { |
| 1287 | 1281 | // {x,1} ou {pagination} |
| 1288 | 1282 | $fin = '$debut_boucle' |
| 1289 | 1283 | . (is_numeric($total_parties) ? |
| 1290 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1291 | - ('+' . $total_parties . ' - 1')); |
|
| 1284 | + (($total_parties == 1) ? "" : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1292 | 1285 | } |
| 1293 | 1286 | |
| 1294 | 1287 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1306,11 +1299,11 @@ discard block |
||
| 1306 | 1299 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1307 | 1300 | |
| 1308 | 1301 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1309 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1302 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1310 | 1303 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 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);' |
|
| 1304 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1305 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1306 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1314 | 1307 | . "\n\tif (\$debut_boucle>0" |
| 1315 | 1308 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1316 | 1309 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1395,16 +1388,16 @@ discard block |
||
| 1395 | 1388 | // critere personnalise ? |
| 1396 | 1389 | if ( |
| 1397 | 1390 | (!$serveur or |
| 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")) |
|
| 1391 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 1392 | + and (!function_exists($f = $f."_dist")) |
|
| 1393 | + and (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 1394 | + and (!function_exists($f = $f."_dist")) |
|
| 1402 | 1395 | ) |
| 1403 | 1396 | ) |
| 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")) |
|
| 1397 | + and (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 1398 | + and (!function_exists($f = $f."_dist")) |
|
| 1399 | + and (!function_exists($f = "critere_".$critere)) |
|
| 1400 | + and (!function_exists($f = $f."_dist")) |
|
| 1408 | 1401 | ) { |
| 1409 | 1402 | // fonction critere standard |
| 1410 | 1403 | $f = $defaut; |
@@ -1437,9 +1430,9 @@ discard block |
||
| 1437 | 1430 | */ |
| 1438 | 1431 | function kwote($lisp, $serveur = '', $type = '') { |
| 1439 | 1432 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1440 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1433 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type)."\""; |
|
| 1441 | 1434 | } else { |
| 1442 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1435 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1443 | 1436 | } |
| 1444 | 1437 | } |
| 1445 | 1438 | |
@@ -1461,7 +1454,7 @@ discard block |
||
| 1461 | 1454 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1462 | 1455 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1463 | 1456 | if (!$r) { |
| 1464 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1457 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 1465 | 1458 | } |
| 1466 | 1459 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1467 | 1460 | |
@@ -1488,8 +1481,8 @@ discard block |
||
| 1488 | 1481 | "'NOT'", |
| 1489 | 1482 | array( |
| 1490 | 1483 | "'IN'", |
| 1491 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1492 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1484 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1485 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1493 | 1486 | ) |
| 1494 | 1487 | ); |
| 1495 | 1488 | } |
@@ -1508,22 +1501,22 @@ discard block |
||
| 1508 | 1501 | $descr = $boucles[$idb]->descr; |
| 1509 | 1502 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1510 | 1503 | |
| 1511 | - $var = '$in' . $cpt++; |
|
| 1504 | + $var = '$in'.$cpt++; |
|
| 1512 | 1505 | $x = "\n\t$var = array();"; |
| 1513 | 1506 | foreach ($val as $k => $v) { |
| 1514 | 1507 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1515 | 1508 | // optimiser le traitement des constantes |
| 1516 | 1509 | if (is_numeric($r[2])) { |
| 1517 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1510 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1518 | 1511 | } else { |
| 1519 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1512 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1520 | 1513 | } |
| 1521 | 1514 | } else { |
| 1522 | 1515 | // Pour permettre de passer des tableaux de valeurs |
| 1523 | 1516 | // on repere l'utilisation brute de #ENV**{X}, |
| 1524 | 1517 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1525 | 1518 | // et on deballe mais en rajoutant l'anti XSS |
| 1526 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1519 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1527 | 1520 | } |
| 1528 | 1521 | } |
| 1529 | 1522 | |
@@ -1537,7 +1530,7 @@ discard block |
||
| 1537 | 1530 | $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
| 1538 | 1531 | } |
| 1539 | 1532 | |
| 1540 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1533 | + return "sql_in('$arg',sql_quote($var)".($crit2 == 'NOT' ? ",'NOT'" : "").")"; |
|
| 1541 | 1534 | } |
| 1542 | 1535 | |
| 1543 | 1536 | /** |
@@ -1610,7 +1603,7 @@ discard block |
||
| 1610 | 1603 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1611 | 1604 | } |
| 1612 | 1605 | // nous aider en mode debug. |
| 1613 | - $boucle->debug[] = "id_ : " . implode(', ', $champs); |
|
| 1606 | + $boucle->debug[] = "id_ : ".implode(', ', $champs); |
|
| 1614 | 1607 | $boucle->modificateur['id_'] = $champs; |
| 1615 | 1608 | |
| 1616 | 1609 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1651,7 +1644,7 @@ discard block |
||
| 1651 | 1644 | // Les champs id_xx de la table demandée |
| 1652 | 1645 | $champs = array_filter( |
| 1653 | 1646 | array_keys($desc['field']), |
| 1654 | - function($champ){ |
|
| 1647 | + function($champ) { |
|
| 1655 | 1648 | return |
| 1656 | 1649 | strpos($champ, 'id_') === 0 |
| 1657 | 1650 | or (in_array($champ, array('objet'))); |
@@ -1854,8 +1847,8 @@ discard block |
||
| 1854 | 1847 | "'NOT'", |
| 1855 | 1848 | array( |
| 1856 | 1849 | "'IN'", |
| 1857 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1858 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1850 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1851 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1859 | 1852 | ) |
| 1860 | 1853 | ); |
| 1861 | 1854 | } |
@@ -1866,7 +1859,7 @@ discard block |
||
| 1866 | 1859 | if ($crit->cond) { |
| 1867 | 1860 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1868 | 1861 | if ($col == "date" or $col == "date_redac") { |
| 1869 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1862 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1870 | 1863 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1871 | 1864 | } |
| 1872 | 1865 | } |
@@ -2027,7 +2020,7 @@ discard block |
||
| 2027 | 2020 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2028 | 2021 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2029 | 2022 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2030 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2023 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2031 | 2024 | } |
| 2032 | 2025 | // sinon expliciter les |
| 2033 | 2026 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2038,22 +2031,22 @@ discard block |
||
| 2038 | 2031 | // sql_quote(truc,'','varchar') |
| 2039 | 2032 | elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
| 2040 | 2033 | // si pas deja un type |
| 2041 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 2034 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2042 | 2035 | ) { |
| 2043 | 2036 | $r = $r[1] |
| 2044 | 2037 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2045 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2038 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2046 | 2039 | $val[0] = "sql_quote($r)"; |
| 2047 | 2040 | } |
| 2048 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2041 | + elseif (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2049 | 2042 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2050 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2043 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2051 | 2044 | } |
| 2052 | 2045 | } |
| 2053 | 2046 | |
| 2054 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 2047 | + if (strpos($val[0], '@@defaultcast@@') !== false |
|
| 2055 | 2048 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 2056 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2049 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2057 | 2050 | } |
| 2058 | 2051 | |
| 2059 | 2052 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2078,7 +2071,7 @@ discard block |
||
| 2078 | 2071 | // inserer le nom de la table SQL devant le nom du champ |
| 2079 | 2072 | if ($table) { |
| 2080 | 2073 | if ($col[0] == "`") { |
| 2081 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2074 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2082 | 2075 | } else { |
| 2083 | 2076 | $arg = "$table.$col"; |
| 2084 | 2077 | } |
@@ -2212,9 +2205,9 @@ discard block |
||
| 2212 | 2205 | **/ |
| 2213 | 2206 | function primary_doublee($decompose, $table) { |
| 2214 | 2207 | $e1 = reset($decompose); |
| 2215 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2208 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2216 | 2209 | |
| 2217 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2210 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 2218 | 2211 | } |
| 2219 | 2212 | |
| 2220 | 2213 | /** |
@@ -2252,7 +2245,7 @@ discard block |
||
| 2252 | 2245 | if ($checkarrivee |
| 2253 | 2246 | and is_string($checkarrivee) |
| 2254 | 2247 | and $a = table_objet($checkarrivee) |
| 2255 | - and in_array($a . '_liens', $joints) |
|
| 2248 | + and in_array($a.'_liens', $joints) |
|
| 2256 | 2249 | ) { |
| 2257 | 2250 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2258 | 2251 | return $res; |
@@ -2272,12 +2265,12 @@ discard block |
||
| 2272 | 2265 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2273 | 2266 | $joindre = false; |
| 2274 | 2267 | foreach ($cols as $col) { |
| 2275 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2268 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2276 | 2269 | if (trouver_champ($c, $boucle->where)) { |
| 2277 | 2270 | $joindre = true; |
| 2278 | 2271 | } else { |
| 2279 | 2272 | // mais ca peut etre dans le FIELD pour le Having |
| 2280 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2273 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2281 | 2274 | if (trouver_champ($c, $boucle->select)) { |
| 2282 | 2275 | $joindre = true; |
| 2283 | 2276 | } |
@@ -2324,7 +2317,7 @@ discard block |
||
| 2324 | 2317 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2325 | 2318 | |
| 2326 | 2319 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2327 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2320 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 2328 | 2321 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2329 | 2322 | |
| 2330 | 2323 | if (!$intermediaire or !$arrivee) { |
@@ -2422,7 +2415,7 @@ discard block |
||
| 2422 | 2415 | } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
| 2423 | 2416 | // un critere conditionnel sur date est traite a part |
| 2424 | 2417 | // car la date est mise d'office par SPIP, |
| 2425 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2418 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2426 | 2419 | } |
| 2427 | 2420 | |
| 2428 | 2421 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2454,7 +2447,7 @@ discard block |
||
| 2454 | 2447 | and (($p == "'") or ($p == '"')) |
| 2455 | 2448 | and $params[0][1]->type == 'champ' |
| 2456 | 2449 | ) { |
| 2457 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2450 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2458 | 2451 | } else { |
| 2459 | 2452 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2460 | 2453 | $a = calculer_liste($p, $desc, $boucles, $parent); |
@@ -2470,7 +2463,7 @@ discard block |
||
| 2470 | 2463 | $fct = $args_sql = ''; |
| 2471 | 2464 | // fonction SQL ? |
| 2472 | 2465 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2473 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2466 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2474 | 2467 | $fct = $m[1]; |
| 2475 | 2468 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2476 | 2469 | $col = $a[1]; |
@@ -2560,7 +2553,7 @@ discard block |
||
| 2560 | 2553 | # si oui choisir ce champ, sinon choisir xxxx |
| 2561 | 2554 | |
| 2562 | 2555 | if (isset($table['field']["date$suite"])) { |
| 2563 | - $date_orig = 'date' . $suite; |
|
| 2556 | + $date_orig = 'date'.$suite; |
|
| 2564 | 2557 | } else { |
| 2565 | 2558 | $date_orig = substr($suite, 1); |
| 2566 | 2559 | } |
@@ -2571,12 +2564,12 @@ discard block |
||
| 2571 | 2564 | } |
| 2572 | 2565 | } |
| 2573 | 2566 | |
| 2574 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2575 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2567 | + $date_compare = "\"' . normaliser_date(". |
|
| 2568 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2576 | 2569 | ") . '\""; |
| 2577 | 2570 | |
| 2578 | 2571 | $col_vraie = $date_orig; |
| 2579 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2572 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2580 | 2573 | |
| 2581 | 2574 | switch ($col) { |
| 2582 | 2575 | case 'date': |
@@ -2596,26 +2589,26 @@ discard block |
||
| 2596 | 2589 | break; |
| 2597 | 2590 | case 'age': |
| 2598 | 2591 | $col = calculer_param_date("NOW()", $date_orig); |
| 2599 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2592 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2600 | 2593 | break; |
| 2601 | 2594 | case 'age_relatif': |
| 2602 | 2595 | $col = calculer_param_date($date_compare, $date_orig); |
| 2603 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2596 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2604 | 2597 | break; |
| 2605 | 2598 | case 'jour_relatif': |
| 2606 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2607 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2599 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 2600 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2608 | 2601 | break; |
| 2609 | 2602 | case 'mois_relatif': |
| 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) |
|
| 2603 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 2604 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 2605 | + ")-YEAR(".$date_orig."))"; |
|
| 2606 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2614 | 2607 | break; |
| 2615 | 2608 | case 'annee_relatif': |
| 2616 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2617 | - $date_orig . ")"; |
|
| 2618 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2609 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 2610 | + $date_orig.")"; |
|
| 2611 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2619 | 2612 | break; |
| 2620 | 2613 | } |
| 2621 | 2614 | |
@@ -2674,10 +2667,10 @@ discard block |
||
| 2674 | 2667 | } |
| 2675 | 2668 | |
| 2676 | 2669 | $boucle->hash .= ' |
| 2677 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2670 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2678 | 2671 | |
| 2679 | 2672 | $boucle->hash .= ' |
| 2680 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2673 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2681 | 2674 | } |
| 2682 | 2675 | |
| 2683 | 2676 | |
@@ -2695,8 +2688,8 @@ discard block |
||
| 2695 | 2688 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2696 | 2689 | $boucle = &$boucles[$idb]; |
| 2697 | 2690 | $boucle->hash .= ' |
| 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) . ';'; |
|
| 2691 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2692 | + $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2700 | 2693 | } |
| 2701 | 2694 | |
| 2702 | 2695 | |
@@ -2716,7 +2709,7 @@ discard block |
||
| 2716 | 2709 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2717 | 2710 | $boucle = &$boucles[$idb]; |
| 2718 | 2711 | $boucle->hash .= ' |
| 2719 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2712 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2720 | 2713 | } |
| 2721 | 2714 | |
| 2722 | 2715 | |
@@ -2735,7 +2728,7 @@ discard block |
||
| 2735 | 2728 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2736 | 2729 | foreach ($crit->param as $param) { |
| 2737 | 2730 | $boucle->hash .= ' |
| 2738 | - $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2731 | + $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2739 | 2732 | } |
| 2740 | 2733 | } |
| 2741 | 2734 | |
@@ -2754,10 +2747,10 @@ discard block |
||
| 2754 | 2747 | */ |
| 2755 | 2748 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2756 | 2749 | $boucle = &$boucles[$idb]; |
| 2757 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2750 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2758 | 2751 | foreach ($crit->param as $param) { |
| 2759 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2760 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2752 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2753 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2761 | 2754 | } |
| 2762 | 2755 | } |
| 2763 | 2756 | |
@@ -2784,10 +2777,10 @@ discard block |
||
| 2784 | 2777 | */ |
| 2785 | 2778 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2786 | 2779 | $boucle = &$boucles[$idb]; |
| 2787 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2780 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2788 | 2781 | foreach ($crit->param as $param) { |
| 2789 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2790 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2782 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2783 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2791 | 2784 | } |
| 2792 | 2785 | } |
| 2793 | 2786 | |
@@ -2806,7 +2799,7 @@ discard block |
||
| 2806 | 2799 | $boucle = &$boucles[$idb]; |
| 2807 | 2800 | foreach ($crit->param as $param) { |
| 2808 | 2801 | $boucle->hash .= ' |
| 2809 | - $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2802 | + $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2810 | 2803 | } |
| 2811 | 2804 | } |
| 2812 | 2805 | |
@@ -2847,7 +2840,7 @@ discard block |
||
| 2847 | 2840 | if ($crit->param) { |
| 2848 | 2841 | foreach ($crit->param as $param) { |
| 2849 | 2842 | $boucle->hash .= "\t\$command['si'][] = " |
| 2850 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2843 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2851 | 2844 | } |
| 2852 | 2845 | // interdire {si 0} aussi ! |
| 2853 | 2846 | } else { |
@@ -2870,7 +2863,7 @@ discard block |
||
| 2870 | 2863 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2871 | 2864 | $boucle = &$boucles[$idb]; |
| 2872 | 2865 | $boucle->hash .= ' |
| 2873 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2866 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2874 | 2867 | $command[\'sourcemode\'] = \'table\';'; |
| 2875 | 2868 | } |
| 2876 | 2869 | |
@@ -2903,11 +2896,10 @@ discard block |
||
| 2903 | 2896 | $table_sql = table_objet_sql(objet_type($table)); |
| 2904 | 2897 | |
| 2905 | 2898 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2906 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2907 | - 'id_parent'; |
|
| 2899 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2908 | 2900 | |
| 2909 | 2901 | $in = "IN"; |
| 2910 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2902 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2911 | 2903 | if ($not) { |
| 2912 | 2904 | $where = array("'NOT'", $where); |
| 2913 | 2905 | } |