@@ -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 | include_spip('inc/headers'); |
| 24 | 24 | |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | * Sortie du buffer |
| 36 | 36 | **/ |
| 37 | 37 | function action_tester_taille_error_handler($output) { |
| 38 | - // on est ici, donc echec lors de la creation de l'image |
|
| 39 | - if (!empty($GLOBALS['redirect'])) { |
|
| 40 | - return redirige_formulaire($GLOBALS['redirect']); |
|
| 41 | - } |
|
| 38 | + // on est ici, donc echec lors de la creation de l'image |
|
| 39 | + if (!empty($GLOBALS['redirect'])) { |
|
| 40 | + return redirige_formulaire($GLOBALS['redirect']); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - return $output; |
|
| 43 | + return $output; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -58,77 +58,77 @@ discard block |
||
| 58 | 58 | **/ |
| 59 | 59 | function action_tester_taille_dist() { |
| 60 | 60 | |
| 61 | - if (!autoriser('configurer')) { |
|
| 62 | - return; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $taille = _request('arg'); |
|
| 66 | - $taille = explode('-', $taille); |
|
| 67 | - |
|
| 68 | - $GLOBALS['taille_max'] = end($taille); |
|
| 69 | - $GLOBALS['taille_min'] = 0; |
|
| 70 | - if (count($taille) > 1) { |
|
| 71 | - $GLOBALS['taille_min'] = reset($taille); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // si l'intervalle est assez petit, on garde la valeur min |
|
| 75 | - if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) { |
|
| 76 | - $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
|
| 77 | - if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
|
| 78 | - $t = $t * 0.9; // marge de securite |
|
| 79 | - echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 80 | - } else { |
|
| 81 | - // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
|
| 82 | - $t = 0; |
|
| 83 | - echo '∞'; |
|
| 84 | - } |
|
| 85 | - ecrire_meta('max_taille_vignettes', $t, 'non'); |
|
| 86 | - die(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2); |
|
| 90 | - |
|
| 91 | - include_spip('inc/filtres'); |
|
| 92 | - // des inclusions representatives d'un hit prive et/ou public pour la conso memoire |
|
| 93 | - include_spip('public/assembler'); |
|
| 94 | - include_spip('public/balises'); |
|
| 95 | - include_spip('public/boucles'); |
|
| 96 | - include_spip('public/cacher'); |
|
| 97 | - include_spip('public/compiler'); |
|
| 98 | - include_spip('public/composer'); |
|
| 99 | - include_spip('public/criteres'); |
|
| 100 | - include_spip('public/interfaces'); |
|
| 101 | - include_spip('public/parametrer'); |
|
| 102 | - include_spip('public/phraser_html'); |
|
| 103 | - include_spip('public/references'); |
|
| 104 | - |
|
| 105 | - include_spip('inc/presentation'); |
|
| 106 | - include_spip('inc/charsets'); |
|
| 107 | - include_spip('inc/documents'); |
|
| 108 | - include_spip('inc/header'); |
|
| 109 | - propre('<doc1>'); // charger propre avec le trairement d'un modele |
|
| 110 | - |
|
| 111 | - $i = _request('i') + 1; |
|
| 112 | - $image_source = chemin_image('test.png'); |
|
| 113 | - $GLOBALS['redirect'] = generer_url_action( |
|
| 114 | - 'tester_taille', |
|
| 115 | - "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 116 | - ); |
|
| 117 | - |
|
| 118 | - ob_start('action_tester_taille_error_handler'); |
|
| 119 | - filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 120 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 121 | - |
|
| 122 | - // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
|
| 123 | - // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
|
| 124 | - if ($GLOBALS['taille_min'] == 0) { |
|
| 125 | - $taille = $GLOBALS['taille_max']; |
|
| 126 | - filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 127 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 128 | - } |
|
| 129 | - ob_end_clean(); |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - // on est ici, donc pas de plantage |
|
| 133 | - echo redirige_formulaire($GLOBALS['redirect']); |
|
| 61 | + if (!autoriser('configurer')) { |
|
| 62 | + return; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $taille = _request('arg'); |
|
| 66 | + $taille = explode('-', $taille); |
|
| 67 | + |
|
| 68 | + $GLOBALS['taille_max'] = end($taille); |
|
| 69 | + $GLOBALS['taille_min'] = 0; |
|
| 70 | + if (count($taille) > 1) { |
|
| 71 | + $GLOBALS['taille_min'] = reset($taille); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // si l'intervalle est assez petit, on garde la valeur min |
|
| 75 | + if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) { |
|
| 76 | + $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
|
| 77 | + if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
|
| 78 | + $t = $t * 0.9; // marge de securite |
|
| 79 | + echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 80 | + } else { |
|
| 81 | + // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
|
| 82 | + $t = 0; |
|
| 83 | + echo '∞'; |
|
| 84 | + } |
|
| 85 | + ecrire_meta('max_taille_vignettes', $t, 'non'); |
|
| 86 | + die(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2); |
|
| 90 | + |
|
| 91 | + include_spip('inc/filtres'); |
|
| 92 | + // des inclusions representatives d'un hit prive et/ou public pour la conso memoire |
|
| 93 | + include_spip('public/assembler'); |
|
| 94 | + include_spip('public/balises'); |
|
| 95 | + include_spip('public/boucles'); |
|
| 96 | + include_spip('public/cacher'); |
|
| 97 | + include_spip('public/compiler'); |
|
| 98 | + include_spip('public/composer'); |
|
| 99 | + include_spip('public/criteres'); |
|
| 100 | + include_spip('public/interfaces'); |
|
| 101 | + include_spip('public/parametrer'); |
|
| 102 | + include_spip('public/phraser_html'); |
|
| 103 | + include_spip('public/references'); |
|
| 104 | + |
|
| 105 | + include_spip('inc/presentation'); |
|
| 106 | + include_spip('inc/charsets'); |
|
| 107 | + include_spip('inc/documents'); |
|
| 108 | + include_spip('inc/header'); |
|
| 109 | + propre('<doc1>'); // charger propre avec le trairement d'un modele |
|
| 110 | + |
|
| 111 | + $i = _request('i') + 1; |
|
| 112 | + $image_source = chemin_image('test.png'); |
|
| 113 | + $GLOBALS['redirect'] = generer_url_action( |
|
| 114 | + 'tester_taille', |
|
| 115 | + "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 116 | + ); |
|
| 117 | + |
|
| 118 | + ob_start('action_tester_taille_error_handler'); |
|
| 119 | + filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 120 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 121 | + |
|
| 122 | + // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
|
| 123 | + // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
|
| 124 | + if ($GLOBALS['taille_min'] == 0) { |
|
| 125 | + $taille = $GLOBALS['taille_max']; |
|
| 126 | + filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 127 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 128 | + } |
|
| 129 | + ob_end_clean(); |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + // on est ici, donc pas de plantage |
|
| 133 | + echo redirige_formulaire($GLOBALS['redirect']); |
|
| 134 | 134 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
| 77 | 77 | if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
| 78 | 78 | $t = $t * 0.9; // marge de securite |
| 79 | - echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 79 | + echo round($t / 1_000_000, 3).' Mpx'; |
|
| 80 | 80 | } else { |
| 81 | 81 | // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
| 82 | 82 | $t = 0; |
@@ -112,19 +112,19 @@ discard block |
||
| 112 | 112 | $image_source = chemin_image('test.png'); |
| 113 | 113 | $GLOBALS['redirect'] = generer_url_action( |
| 114 | 114 | 'tester_taille', |
| 115 | - "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 115 | + "i=$i&arg=".$GLOBALS['taille_min'].'-'.$GLOBALS['taille_test'] |
|
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | 118 | ob_start('action_tester_taille_error_handler'); |
| 119 | 119 | filtrer('image_recadre', $image_source, $taille, $taille); |
| 120 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 120 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']); |
|
| 121 | 121 | |
| 122 | 122 | // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
| 123 | 123 | // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
| 124 | 124 | if ($GLOBALS['taille_min'] == 0) { |
| 125 | 125 | $taille = $GLOBALS['taille_max']; |
| 126 | 126 | filtrer('image_recadre', $image_source, $taille, $taille); |
| 127 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 127 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']); |
|
| 128 | 128 | } |
| 129 | 129 | ob_end_clean(); |
| 130 | 130 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | 36 | function action_ajouter_lien_dist($arg = null) { |
| 37 | - if (is_null($arg)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - } |
|
| 37 | + if (is_null($arg)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $arg = explode('-', $arg); |
|
| 43 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 42 | + $arg = explode('-', $arg); |
|
| 43 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 44 | 44 | |
| 45 | - include_spip('action/editer_liens'); |
|
| 46 | - objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 45 | + include_spip('action/editer_liens'); |
|
| 46 | + objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 47 | 47 | } |
@@ -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 | /** |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function action_debloquer_edition_dist() { |
| 33 | 33 | |
| 34 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 35 | - $arg = $securiser_action(); |
|
| 34 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 35 | + $arg = $securiser_action(); |
|
| 36 | 36 | |
| 37 | - if ($arg) { |
|
| 38 | - include_spip('inc/drapeau_edition'); |
|
| 39 | - if ($arg == 'tous') { |
|
| 40 | - debloquer_tous($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | - } else { |
|
| 42 | - $arg = explode('-', $arg); |
|
| 43 | - [$objet, $id_objet] = $arg; |
|
| 44 | - debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet); |
|
| 45 | - } |
|
| 46 | - } |
|
| 37 | + if ($arg) { |
|
| 38 | + include_spip('inc/drapeau_edition'); |
|
| 39 | + if ($arg == 'tous') { |
|
| 40 | + debloquer_tous($GLOBALS['visiteur_session']['id_auteur']); |
|
| 41 | + } else { |
|
| 42 | + $arg = explode('-', $arg); |
|
| 43 | + [$objet, $id_objet] = $arg; |
|
| 44 | + debloquer_edition($GLOBALS['visiteur_session']['id_auteur'], $id_objet, $objet); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -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 | include_spip('inc/actions'); |
@@ -33,93 +33,93 @@ discard block |
||
| 33 | 33 | * @return void |
| 34 | 34 | */ |
| 35 | 35 | function action_cookie_dist($set_cookie_admin = null, $change_session = null) { |
| 36 | - $redirect_echec = $redirect = null; |
|
| 37 | - $test_echec_cookie = null; |
|
| 38 | - $url = ''; |
|
| 39 | - if (is_null($set_cookie_admin)) { |
|
| 40 | - $set_cookie_admin = _request('cookie_admin'); |
|
| 41 | - $change_session = _request('change_session'); |
|
| 42 | - $test_echec_cookie = _request('test_echec_cookie'); |
|
| 36 | + $redirect_echec = $redirect = null; |
|
| 37 | + $test_echec_cookie = null; |
|
| 38 | + $url = ''; |
|
| 39 | + if (is_null($set_cookie_admin)) { |
|
| 40 | + $set_cookie_admin = _request('cookie_admin'); |
|
| 41 | + $change_session = _request('change_session'); |
|
| 42 | + $test_echec_cookie = _request('test_echec_cookie'); |
|
| 43 | 43 | |
| 44 | - // La cible de notre operation de connexion |
|
| 45 | - $url = securiser_redirect_action(_request('url')); |
|
| 46 | - $redirect = $url ?: generer_url_ecrire('accueil'); |
|
| 47 | - $redirect_echec = _request('url_echec'); |
|
| 48 | - if (!isset($redirect_echec)) { |
|
| 49 | - if (strpos($redirect, (string) _DIR_RESTREINT_ABS) !== false) { |
|
| 50 | - $redirect_echec = generer_url_public('login', '', true); |
|
| 51 | - } else { |
|
| 52 | - $redirect_echec = $redirect; |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 44 | + // La cible de notre operation de connexion |
|
| 45 | + $url = securiser_redirect_action(_request('url')); |
|
| 46 | + $redirect = $url ?: generer_url_ecrire('accueil'); |
|
| 47 | + $redirect_echec = _request('url_echec'); |
|
| 48 | + if (!isset($redirect_echec)) { |
|
| 49 | + if (strpos($redirect, (string) _DIR_RESTREINT_ABS) !== false) { |
|
| 50 | + $redirect_echec = generer_url_public('login', '', true); |
|
| 51 | + } else { |
|
| 52 | + $redirect_echec = $redirect; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - // rejoue le cookie pour renouveler spip_session |
|
| 59 | - if ($change_session == 'oui') { |
|
| 60 | - $session = charger_fonction('session', 'inc'); |
|
| 61 | - $session(true); |
|
| 62 | - spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 63 | - http_response_code(204); // No Content |
|
| 64 | - return; |
|
| 65 | - } |
|
| 58 | + // rejoue le cookie pour renouveler spip_session |
|
| 59 | + if ($change_session == 'oui') { |
|
| 60 | + $session = charger_fonction('session', 'inc'); |
|
| 61 | + $session(true); |
|
| 62 | + spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 63 | + http_response_code(204); // No Content |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // tentative de connexion en auth_http |
|
| 68 | - if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) { |
|
| 69 | - include_spip('inc/auth'); |
|
| 70 | - if ( |
|
| 71 | - @$_SERVER['PHP_AUTH_USER'] |
|
| 72 | - and @$_SERVER['PHP_AUTH_PW'] |
|
| 73 | - and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) |
|
| 74 | - ) { |
|
| 75 | - auth_loger($auteur); |
|
| 76 | - redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 77 | - } else { |
|
| 78 | - ask_php_auth( |
|
| 79 | - _T('info_connexion_refusee'), |
|
| 80 | - _T('login_login_pass_incorrect'), |
|
| 81 | - _T('login_retour_site'), |
|
| 82 | - 'url=' . rawurlencode($redirect), |
|
| 83 | - _T('login_nouvelle_tentative'), |
|
| 84 | - (strpos($url, (string) _DIR_RESTREINT_ABS) !== false) |
|
| 85 | - ); |
|
| 86 | - } |
|
| 87 | - } else { |
|
| 88 | - // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 89 | - // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 90 | - // le cas echeant. |
|
| 91 | - if ($test_echec_cookie == 'oui') { |
|
| 92 | - spip_setcookie('spip_session', 'test_echec_cookie'); |
|
| 93 | - if ($redirect) { |
|
| 94 | - $redirect = parametre_url( |
|
| 95 | - parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 96 | - 'url', |
|
| 97 | - rawurlencode($redirect), |
|
| 98 | - '&' |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - } else { |
|
| 102 | - $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 103 | - // Suppression cookie d'admin ? |
|
| 104 | - if ($set_cookie_admin == 'non') { |
|
| 105 | - if ($cook) { |
|
| 106 | - spip_setcookie('spip_admin', $cook, [ |
|
| 107 | - 'expires' => time() - 3600 * 24 |
|
| 108 | - ]); |
|
| 109 | - } |
|
| 110 | - } // Ajout de cookie d'admin |
|
| 111 | - else { |
|
| 112 | - if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) { |
|
| 113 | - spip_setcookie('spip_admin', $set_cookie_admin, [ |
|
| 114 | - 'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA) |
|
| 115 | - ]); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 67 | + // tentative de connexion en auth_http |
|
| 68 | + if (_request('essai_auth_http') and !$GLOBALS['ignore_auth_http']) { |
|
| 69 | + include_spip('inc/auth'); |
|
| 70 | + if ( |
|
| 71 | + @$_SERVER['PHP_AUTH_USER'] |
|
| 72 | + and @$_SERVER['PHP_AUTH_PW'] |
|
| 73 | + and $auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) |
|
| 74 | + ) { |
|
| 75 | + auth_loger($auteur); |
|
| 76 | + redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 77 | + } else { |
|
| 78 | + ask_php_auth( |
|
| 79 | + _T('info_connexion_refusee'), |
|
| 80 | + _T('login_login_pass_incorrect'), |
|
| 81 | + _T('login_retour_site'), |
|
| 82 | + 'url=' . rawurlencode($redirect), |
|
| 83 | + _T('login_nouvelle_tentative'), |
|
| 84 | + (strpos($url, (string) _DIR_RESTREINT_ABS) !== false) |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | + } else { |
|
| 88 | + // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 89 | + // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 90 | + // le cas echeant. |
|
| 91 | + if ($test_echec_cookie == 'oui') { |
|
| 92 | + spip_setcookie('spip_session', 'test_echec_cookie'); |
|
| 93 | + if ($redirect) { |
|
| 94 | + $redirect = parametre_url( |
|
| 95 | + parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 96 | + 'url', |
|
| 97 | + rawurlencode($redirect), |
|
| 98 | + '&' |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + } else { |
|
| 102 | + $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 103 | + // Suppression cookie d'admin ? |
|
| 104 | + if ($set_cookie_admin == 'non') { |
|
| 105 | + if ($cook) { |
|
| 106 | + spip_setcookie('spip_admin', $cook, [ |
|
| 107 | + 'expires' => time() - 3600 * 24 |
|
| 108 | + ]); |
|
| 109 | + } |
|
| 110 | + } // Ajout de cookie d'admin |
|
| 111 | + else { |
|
| 112 | + if ($set_cookie_admin and _DUREE_COOKIE_ADMIN) { |
|
| 113 | + spip_setcookie('spip_admin', $set_cookie_admin, [ |
|
| 114 | + 'expires' => time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA) |
|
| 115 | + ]); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - // Redirection finale |
|
| 122 | - if ($redirect) { |
|
| 123 | - redirige_par_entete($redirect, true); |
|
| 124 | - } |
|
| 121 | + // Redirection finale |
|
| 122 | + if ($redirect) { |
|
| 123 | + redirige_par_entete($redirect, true); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | if ($change_session == 'oui') { |
| 60 | 60 | $session = charger_fonction('session', 'inc'); |
| 61 | 61 | $session(true); |
| 62 | - spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 62 | + spip_log('statut 204 pour '.$_SERVER['REQUEST_URI']); |
|
| 63 | 63 | http_response_code(204); // No Content |
| 64 | 64 | return; |
| 65 | 65 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | _T('info_connexion_refusee'), |
| 80 | 80 | _T('login_login_pass_incorrect'), |
| 81 | 81 | _T('login_retour_site'), |
| 82 | - 'url=' . rawurlencode($redirect), |
|
| 82 | + 'url='.rawurlencode($redirect), |
|
| 83 | 83 | _T('login_nouvelle_tentative'), |
| 84 | 84 | (strpos($url, (string) _DIR_RESTREINT_ABS) !== false) |
| 85 | 85 | ); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -32,28 +32,28 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function action_desinstaller_plugin_dist() { |
| 34 | 34 | |
| 35 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | - $arg = $securiser_action(); |
|
| 37 | - [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | - $dir_type = '_DIR_PLUGINS'; |
|
| 39 | - if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | - $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | - } |
|
| 42 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | - $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | - if ($infos and !$infos['install_test'][0]) { |
|
| 45 | - include_spip('inc/plugin'); |
|
| 46 | - ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | - $erreur = ''; |
|
| 48 | - } else { |
|
| 49 | - $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | - } |
|
| 51 | - if ($redirect = _request('redirect')) { |
|
| 52 | - include_spip('inc/headers'); |
|
| 53 | - if ($erreur) { |
|
| 54 | - $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | - } |
|
| 56 | - $redirect = str_replace('&', '&', $redirect); |
|
| 57 | - redirige_par_entete($redirect); |
|
| 58 | - } |
|
| 35 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 36 | + $arg = $securiser_action(); |
|
| 37 | + [$dir_plugins, $plugin] = explode('::', $arg); |
|
| 38 | + $dir_type = '_DIR_PLUGINS'; |
|
| 39 | + if (defined('_DIR_PLUGINS_SUPPL') and $dir_plugins == _DIR_PLUGINS_SUPPL) { |
|
| 40 | + $dir_type = '_DIR_PLUGINS_SUPPL'; |
|
| 41 | + } |
|
| 42 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 43 | + $infos = $installer_plugins($plugin, 'uninstall', $dir_type); |
|
| 44 | + if ($infos and !$infos['install_test'][0]) { |
|
| 45 | + include_spip('inc/plugin'); |
|
| 46 | + ecrire_plugin_actifs([$plugin], false, 'enleve'); |
|
| 47 | + $erreur = ''; |
|
| 48 | + } else { |
|
| 49 | + $erreur = 'erreur_plugin_desinstalation_echouee'; |
|
| 50 | + } |
|
| 51 | + if ($redirect = _request('redirect')) { |
|
| 52 | + include_spip('inc/headers'); |
|
| 53 | + if ($erreur) { |
|
| 54 | + $redirect = parametre_url($redirect, 'erreur', $erreur); |
|
| 55 | + } |
|
| 56 | + $redirect = str_replace('&', '&', $redirect); |
|
| 57 | + redirige_par_entete($redirect); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -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 | /** |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * Pile complétée du code compilé |
| 37 | 37 | **/ |
| 38 | 38 | function balise_URL_LOGOUT($p) { |
| 39 | - return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 39 | + return calculer_balise_dynamique($p, 'URL_LOGOUT', []); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Liste (url) des arguments collectés. |
| 53 | 53 | */ |
| 54 | 54 | function balise_URL_LOGOUT_stat($args, $context_compil) { |
| 55 | - $url = $args[0] ?? ''; |
|
| 55 | + $url = $args[0] ?? ''; |
|
| 56 | 56 | |
| 57 | - return [$url]; |
|
| 57 | + return [$url]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function balise_URL_LOGOUT_dyn($cible) { |
| 71 | 71 | |
| 72 | - if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | - return ''; |
|
| 74 | - } |
|
| 72 | + if (empty($GLOBALS['visiteur_session']['login']) and empty($GLOBALS['visiteur_session']['statut'])) { |
|
| 73 | + return ''; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -73,5 +73,5 @@ |
||
| 73 | 73 | return ''; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - return generer_url_action('logout', 'logout=public&url=' . rawurlencode($cible ?: self('&'))); |
|
| 76 | + return generer_url_action('logout', 'logout=public&url='.rawurlencode($cible ?: self('&'))); |
|
| 77 | 77 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', string $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - [$id_rubrique, $lang] = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + [$id_rubrique, $lang] = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = $row['lang'] ?? ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = $row['lang'] ?? ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |
@@ -2071,8 +2071,7 @@ discard block |
||
| 2071 | 2071 | // Champ joker * des iterateurs DATA qui accepte tout |
| 2072 | 2072 | if (@array_key_exists('*', $desc['field'])) { |
| 2073 | 2073 | $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
| 2074 | - } |
|
| 2075 | - else { |
|
| 2074 | + } else { |
|
| 2076 | 2075 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 2077 | 2076 | if (!$r) { |
| 2078 | 2077 | return ''; |
@@ -2115,8 +2114,7 @@ discard block |
||
| 2115 | 2114 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2116 | 2115 | . ",'" . addslashes($type_cast_quote) . "'"; |
| 2117 | 2116 | $val[0] = "sql_quote($r)"; |
| 2118 | - } |
|
| 2119 | - elseif ( |
|
| 2117 | + } elseif ( |
|
| 2120 | 2118 | strpos($val[0], '@@defaultcast@@') !== false |
| 2121 | 2119 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2122 | 2120 | ) { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 48 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 50 | + $c = ["'='", "'$boucle->id_table."."$id_parent'", 0]; |
|
| 51 | 51 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -70,10 +70,10 @@ discard block |
||
| 70 | 70 | $id = $boucle->primary; |
| 71 | 71 | |
| 72 | 72 | if ($not or !$id) { |
| 73 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 73 | + return ['zbug_critere_inconnu', ['critere' => $not.$crit->op]]; |
|
| 74 | 74 | } |
| 75 | 75 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table."."$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | $not = ($crit->not ? '' : 'NOT'); |
| 105 | 105 | |
| 106 | 106 | // le doublon s'applique sur un type de boucle (article) |
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 107 | + $nom = "'".$boucle->type_requete."'"; |
|
| 108 | 108 | |
| 109 | 109 | // compléter le nom avec un nom précisé {doublons nom} |
| 110 | 110 | // on obtient $nom = "'article' . 'nom'" |
| 111 | 111 | if (isset($crit->param[0])) { |
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 112 | + $nom .= '.'.calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | // $doublons et son index, ici $nom |
| 122 | 122 | |
| 123 | 123 | // debut du code "sql_in('articles.id_article', " |
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 124 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 125 | 125 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 126 | 126 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 127 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons.'[]= ')); |
|
| 128 | 128 | |
| 129 | 129 | // le debut complet du code des doublons |
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 130 | + $debut_doub = $debut_in.$debut_doub; |
|
| 131 | 131 | |
| 132 | 132 | // nom du doublon "('article' . 'nom')]" |
| 133 | 133 | $fin_doub = "($nom)]"; |
@@ -137,22 +137,22 @@ discard block |
||
| 137 | 137 | foreach ($boucle->where as $k => $w) { |
| 138 | 138 | if (strpos($w[0], $debut_doub) === 0) { |
| 139 | 139 | // fusionner le sql_in (du where) |
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 140 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 141 | 141 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 142 | 142 | $x = strpos($boucle->hash, $init_comment); |
| 143 | 143 | $len = strlen($init_comment); |
| 144 | 144 | $boucle->hash = |
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 145 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 146 | 146 | |
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 152 | + $boucle->where[] = [$debut_doub.$fin_doub.", '".$not."')"]; |
|
| 153 | 153 | |
| 154 | 154 | // déclarer le doublon s'il n'existe pas encore |
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 155 | + $boucle->hash .= $init_comment.$init_code; |
|
| 156 | 156 | |
| 157 | 157 | |
| 158 | 158 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $deux = $deux[0]->texte; |
| 215 | 215 | if ($deux) { |
| 216 | 216 | $boucles[$idb]->limit = |
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 217 | + 'intval($Pile[0]["debut'.$un.'"]) . ",'.$deux.'"'; |
|
| 218 | 218 | } else { |
| 219 | 219 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
| 220 | 220 | } |
@@ -276,26 +276,26 @@ discard block |
||
| 276 | 276 | $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 280 | 280 | $boucle->modificateur['debut_nom'] = $type; |
| 281 | 281 | $partie = |
| 282 | 282 | // tester si le numero de page demande est de la forme '@yyy' |
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 283 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 284 | 284 | . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 285 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 286 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 287 | 287 | . "\t}\n" |
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 288 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 289 | 289 | |
| 290 | 290 | $boucle->hash .= ' |
| 291 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 291 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 292 | 292 | |
| 293 | 293 | $boucle->total_parties = $pas; |
| 294 | 294 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 295 | 295 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 296 | 296 | // sauf si pas de primaire, ou si primaire composee |
| 297 | 297 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 298 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 299 | 299 | if ( |
| 300 | 300 | $boucle->primary |
| 301 | 301 | and !preg_match('/[,\s]/', $boucle->primary) |
@@ -342,24 +342,24 @@ discard block |
||
| 342 | 342 | $boucle->hash .= ' |
| 343 | 343 | // RECHERCHE' |
| 344 | 344 | . ($crit->cond ? ' |
| 345 | - if (!strlen(' . $quoi . ')){ |
|
| 345 | + if (!strlen(' . $quoi.')){ |
|
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | - } else' : '') . ' |
|
| 347 | + } else' : '').' |
|
| 348 | 348 | { |
| 349 | 349 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 350 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 350 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 351 | 351 | } |
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 355 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 356 | 356 | if (!in_array($t, $boucles[$idb]->select)) { |
| 357 | 357 | $boucle->select[] = $t; |
| 358 | 358 | } # pour postgres, neuneu ici |
| 359 | 359 | // jointure uniquement sur le serveur principal |
| 360 | 360 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 361 | 361 | if (!$boucle->sql_serveur) { |
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 362 | + $boucle->join['resultats'] = ["'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"]; |
|
| 363 | 363 | $boucle->from['resultats'] = 'spip_resultats'; |
| 364 | 364 | } |
| 365 | 365 | $boucle->select[] = '$rech_select'; |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | $c = |
| 427 | 427 | [ |
| 428 | 428 | "'OR'", |
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 429 | + ["'='", "'$table."."id_trad'", "'$table.$prim'"], |
|
| 430 | 430 | ["'='", "'$table.id_trad'", "'0'"] |
| 431 | 431 | ]; |
| 432 | 432 | $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
@@ -449,13 +449,13 @@ discard block |
||
| 449 | 449 | $boucle = &$boucles[$idb]; |
| 450 | 450 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 451 | 451 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 452 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 453 | 453 | |
| 454 | 454 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 455 | 455 | $boucle->where[] = ["'='", "'$mparent'", $arg]; |
| 456 | 456 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 457 | 457 | else { |
| 458 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 458 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$boucle->type_requete]]; |
|
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
@@ -508,16 +508,15 @@ discard block |
||
| 508 | 508 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 509 | 509 | $decompose = decompose_champ_id_objet($champ); |
| 510 | 510 | $champ = array_shift($decompose); |
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 511 | + $boucle->where[] = ["'='", _q($cle.'.'.reset($decompose)), '"'.sql_quote(end($decompose)).'"']; |
|
| 512 | 512 | } |
| 513 | 513 | } else { |
| 514 | 514 | $cle = $boucle->id_table; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 517 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '').')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 521 | 520 | } |
| 522 | 521 | |
| 523 | 522 | /** |
@@ -537,9 +536,9 @@ discard block |
||
| 537 | 536 | $not = ($crit->not ? 'NOT' : ''); |
| 538 | 537 | $serveur = $boucle->sql_serveur; |
| 539 | 538 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 539 | + $c = "sql_in('". |
|
| 540 | + $boucle->id_table.'.'.$boucle->primary |
|
| 541 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '$not', '$serveur')"; |
|
| 543 | 542 | |
| 544 | 543 | $boucle->where[] = $c; |
| 545 | 544 | } |
@@ -571,7 +570,7 @@ discard block |
||
| 571 | 570 | $t = table_objet_sql($r[1]); |
| 572 | 571 | $t = array_search($t, $boucles[$idb]->from); |
| 573 | 572 | if ($t) { |
| 574 | - $t .= '.' . $r[2]; |
|
| 573 | + $t .= '.'.$r[2]; |
|
| 575 | 574 | } |
| 576 | 575 | } |
| 577 | 576 | } else { |
@@ -586,7 +585,7 @@ discard block |
||
| 586 | 585 | $boucles[$idb]->select[] = $t; |
| 587 | 586 | } |
| 588 | 587 | } else { |
| 589 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 588 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 590 | 589 | } |
| 591 | 590 | } |
| 592 | 591 | |
@@ -656,25 +655,25 @@ discard block |
||
| 656 | 655 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 657 | 656 | or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 658 | 657 | ) { |
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 658 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 660 | 659 | } else { |
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 660 | + $boucle->order[$n - 1] .= ' . '.$boucle->modificateur['collate']; |
|
| 662 | 661 | } |
| 663 | 662 | } |
| 664 | 663 | } else { |
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 664 | + return (['zbug_critere_inconnu', ['critere' => $crit->op.' '.(is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | 665 | } |
| 667 | 666 | } |
| 668 | 667 | |
| 669 | 668 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | 669 | $boucle = $boucles[$idb]; |
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 670 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 671 | + $var = '$champs_'.$idb; |
|
| 673 | 672 | $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
| 674 | 673 | if (!$desc) { |
| 675 | 674 | $desc = $boucle->show['field']; |
| 676 | 675 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 676 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.');'; |
|
| 678 | 677 | } |
| 679 | 678 | if ($desc) { |
| 680 | 679 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -749,7 +748,7 @@ discard block |
||
| 749 | 748 | $sens = " . ' DESC'"; |
| 750 | 749 | } |
| 751 | 750 | if (isset($boucle->modificateur['collate'])) { |
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 751 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 753 | 752 | } |
| 754 | 753 | |
| 755 | 754 | // Pour chaque paramètre du critère |
@@ -771,14 +770,14 @@ discard block |
||
| 771 | 770 | if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
| 772 | 771 | $expression = trim($m[1]); |
| 773 | 772 | $champ = trim($m[2]); |
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 773 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 775 | 774 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 776 | 775 | } else { |
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 776 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 778 | 777 | } |
| 779 | 778 | |
| 780 | 779 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 780 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^'.CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 782 | 781 | // {par FONCTION(champ)} |
| 783 | 782 | if (isset($match) and count($match) > 2) { |
| 784 | 783 | $par = substr($match[2], 1, -1); |
@@ -788,7 +787,7 @@ discard block |
||
| 788 | 787 | if ($par == 'hasard') { |
| 789 | 788 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 790 | 789 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 790 | + $order = "'".$boucle->id_table.'.'.$boucle->show['date']."'"; |
|
| 792 | 791 | } else { |
| 793 | 792 | // cas général {par champ}, {par table.champ}, ... |
| 794 | 793 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -797,7 +796,7 @@ discard block |
||
| 797 | 796 | |
| 798 | 797 | // on ne sait pas traiter… |
| 799 | 798 | else { |
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 799 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 801 | 800 | } |
| 802 | 801 | |
| 803 | 802 | // En cas d'erreur de squelette retournée par une fonction |
@@ -817,14 +816,14 @@ discard block |
||
| 817 | 816 | |
| 818 | 817 | if ($fct) { |
| 819 | 818 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 819 | + $order = "'$fct(".$r[1].")'"; |
|
| 821 | 820 | } else { |
| 822 | 821 | $order = "'$fct(' . $order . ')'"; |
| 823 | 822 | } |
| 824 | 823 | } |
| 825 | - $t = $order . $collecte . $sens; |
|
| 824 | + $t = $order.$collecte.$sens; |
|
| 826 | 825 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 827 | - $t = $r[1] . $r[2]; |
|
| 826 | + $t = $r[1].$r[2]; |
|
| 828 | 827 | } |
| 829 | 828 | |
| 830 | 829 | $boucle->order[] = $t; |
@@ -874,16 +873,16 @@ discard block |
||
| 874 | 873 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | 874 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 876 | 875 | if (is_array($_champ)) { |
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 876 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." num $champ"]]; |
|
| 878 | 877 | } |
| 879 | 878 | $boucle = &$boucles[$idb]; |
| 880 | - $texte = '0+' . $_champ; |
|
| 879 | + $texte = '0+'.$_champ; |
|
| 881 | 880 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 882 | 881 | if ($suite !== "''") { |
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 882 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 884 | 883 | } |
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 884 | + $asnum = 'num'.($boucle->order ? count($boucle->order) : ''); |
|
| 885 | + $boucle->select[] = $texte." AS $asnum"; |
|
| 887 | 886 | |
| 888 | 887 | $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
| 889 | 888 | $orderassinum = trim($orderassinum, "'"); |
@@ -912,13 +911,13 @@ discard block |
||
| 912 | 911 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | 912 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 914 | 913 | if (is_array($_champ)) { |
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 914 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." sinum $champ"]]; |
|
| 916 | 915 | } |
| 917 | 916 | $boucle = &$boucles[$idb]; |
| 918 | - $texte = '0+' . $_champ; |
|
| 917 | + $texte = '0+'.$_champ; |
|
| 919 | 918 | $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
| 920 | 919 | if ($suite !== "''") { |
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 920 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')".' . "'; |
|
| 922 | 921 | } |
| 923 | 922 | |
| 924 | 923 | $as = false; |
@@ -934,8 +933,8 @@ discard block |
||
| 934 | 933 | } |
| 935 | 934 | |
| 936 | 935 | if (!$as) { |
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 936 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ''); |
|
| 937 | + $boucle->select[] = $select.$as; |
|
| 939 | 938 | } |
| 940 | 939 | $order = "'$as'"; |
| 941 | 940 | return $order; |
@@ -960,10 +959,10 @@ discard block |
||
| 960 | 959 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | 960 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 962 | 961 | if (is_array($_champ)) { |
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 962 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." multi $champ"]]; |
|
| 964 | 963 | } |
| 965 | 964 | $boucle = &$boucles[$idb]; |
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 965 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 967 | 966 | $order = "'multi'"; |
| 968 | 967 | return $order; |
| 969 | 968 | } |
@@ -989,7 +988,7 @@ discard block |
||
| 989 | 988 | |
| 990 | 989 | // le champ existe dans la table, pas de souci (le plus commun) |
| 991 | 990 | if (isset($desc['field'][$par])) { |
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 991 | + $par = $boucle->id_table.'.'.$par; |
|
| 993 | 992 | } |
| 994 | 993 | // le champ est peut être une jointure |
| 995 | 994 | else { |
@@ -1010,24 +1009,24 @@ discard block |
||
| 1010 | 1009 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 1011 | 1010 | // Si la table est déjà dans le from, on la réutilise. |
| 1012 | 1011 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1012 | + $par = $infos['alias'].'.'.$champ; |
|
| 1014 | 1013 | } elseif ( |
| 1015 | 1014 | $boucle->jointures_explicites |
| 1016 | 1015 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 1017 | 1016 | ) { |
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1017 | + $par = $alias.'.'.$champ; |
|
| 1019 | 1018 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1019 | + $par = $alias.'.'.$champ; |
|
| 1021 | 1020 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 1022 | 1021 | } elseif ( |
| 1023 | 1022 | $table_alias |
| 1024 | 1023 | and isset($boucle->from[$table_alias]) |
| 1025 | 1024 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 1026 | 1025 | ) { |
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1026 | + $par = $infos['alias'].'.'.$champ; |
|
| 1028 | 1027 | } elseif ($table) { |
| 1029 | 1028 | // On avait table + champ, mais on ne les a pas trouvés |
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1029 | + return ['zbug_critere_inconnu', ['critere' => $crit->op." $par"]]; |
|
| 1031 | 1030 | } else { |
| 1032 | 1031 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1033 | 1032 | } |
@@ -1051,7 +1050,7 @@ discard block |
||
| 1051 | 1050 | if (!$t) { |
| 1052 | 1051 | $t = trouver_jointure_champ($champ, $boucle); |
| 1053 | 1052 | } |
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1053 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1055 | 1054 | } |
| 1056 | 1055 | |
| 1057 | 1056 | /** |
@@ -1096,9 +1095,9 @@ discard block |
||
| 1096 | 1095 | $boucle->default_order[] = ' DESC'; |
| 1097 | 1096 | } |
| 1098 | 1097 | } else { |
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1098 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1100 | 1099 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1100 | + $t = $r[1].$r[2]; |
|
| 1102 | 1101 | } |
| 1103 | 1102 | $boucle->order[$n - 1] = $t; |
| 1104 | 1103 | } |
@@ -1135,7 +1134,7 @@ discard block |
||
| 1135 | 1134 | |
| 1136 | 1135 | $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
| 1137 | 1136 | |
| 1138 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1137 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'".$boucle->sql_serveur."')) ? \$zl : '0').')'$sens"; |
|
| 1139 | 1138 | $boucle->order[] = $order; |
| 1140 | 1139 | } |
| 1141 | 1140 | |
@@ -1144,7 +1143,7 @@ discard block |
||
| 1144 | 1143 | $params = $crit->param; |
| 1145 | 1144 | |
| 1146 | 1145 | if ((is_countable($params) ? count($params) : 0) < 1) { |
| 1147 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1146 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1148 | 1147 | } |
| 1149 | 1148 | |
| 1150 | 1149 | $boucle = &$boucles[$idb]; |
@@ -1165,7 +1164,7 @@ discard block |
||
| 1165 | 1164 | if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
| 1166 | 1165 | $date = $date[0]->texte; |
| 1167 | 1166 | if (!isset($fields[$date])) { |
| 1168 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1167 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' '.$date]]; |
|
| 1169 | 1168 | } |
| 1170 | 1169 | } else { |
| 1171 | 1170 | $a = calculer_liste($date, $idb, $boucles, $parent); |
@@ -1177,38 +1176,38 @@ discard block |
||
| 1177 | 1176 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1178 | 1177 | } |
| 1179 | 1178 | $annee = $params ? array_shift($params) : ''; |
| 1180 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1181 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1180 | + calculer_liste($annee, $idb, $boucles, $parent). |
|
| 1182 | 1181 | ') ? $x : date("Y"))'; |
| 1183 | 1182 | |
| 1184 | 1183 | $mois = $params ? array_shift($params) : ''; |
| 1185 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1186 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1185 | + calculer_liste($mois, $idb, $boucles, $parent). |
|
| 1187 | 1186 | ') ? $x : date("m"))'; |
| 1188 | 1187 | |
| 1189 | 1188 | $jour = $params ? array_shift($params) : ''; |
| 1190 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1191 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1190 | + calculer_liste($jour, $idb, $boucles, $parent). |
|
| 1192 | 1191 | ') ? $x : date("d"))'; |
| 1193 | 1192 | |
| 1194 | 1193 | $annee2 = $params ? array_shift($params) : ''; |
| 1195 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1196 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1195 | + calculer_liste($annee2, $idb, $boucles, $parent). |
|
| 1197 | 1196 | ') ? $x : date("Y"))'; |
| 1198 | 1197 | |
| 1199 | 1198 | $mois2 = $params ? array_shift($params) : ''; |
| 1200 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1201 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1200 | + calculer_liste($mois2, $idb, $boucles, $parent). |
|
| 1202 | 1201 | ') ? $x : date("m"))'; |
| 1203 | 1202 | |
| 1204 | 1203 | $jour2 = $params ? array_shift($params) : ''; |
| 1205 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1206 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1205 | + calculer_liste($jour2, $idb, $boucles, $parent). |
|
| 1207 | 1206 | ') ? $x : date("d"))'; |
| 1208 | 1207 | |
| 1209 | - $date = $boucle->id_table . ".$date"; |
|
| 1208 | + $date = $boucle->id_table.".$date"; |
|
| 1210 | 1209 | |
| 1211 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1210 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1212 | 1211 | if ($type == 'jour') { |
| 1213 | 1212 | $boucle->where[] = [ |
| 1214 | 1213 | "'='", |
@@ -1280,14 +1279,13 @@ discard block |
||
| 1280 | 1279 | [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1281 | 1280 | |
| 1282 | 1281 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1283 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1282 | + $boucle->limit = $a11.','.$a21; |
|
| 1284 | 1283 | } else { |
| 1285 | 1284 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1286 | 1285 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1287 | 1286 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1288 | 1287 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1289 | - $mode = (($op == '/') ? '/' : |
|
| 1290 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1291 | 1289 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1292 | 1290 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
| 1293 | 1291 | $boucle->limit = |
@@ -1333,8 +1331,7 @@ discard block |
||
| 1333 | 1331 | // {1/3} |
| 1334 | 1332 | if ($op1 == '/') { |
| 1335 | 1333 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1336 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1337 | - "($total_parties ? $total_parties : 1)"; |
|
| 1334 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1338 | 1335 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1339 | 1336 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1340 | 1337 | } else { |
@@ -1345,15 +1342,13 @@ discard block |
||
| 1345 | 1342 | |
| 1346 | 1343 | // cas {x,n-1} |
| 1347 | 1344 | if ($op2 == '-') { |
| 1348 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1349 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1350 | - ($total_parties . ' - 1')); |
|
| 1345 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1346 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1351 | 1347 | } else { |
| 1352 | 1348 | // {x,1} ou {pagination} |
| 1353 | 1349 | $fin = '$debut_boucle' |
| 1354 | 1350 | . (is_numeric($total_parties) ? |
| 1355 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1356 | - ('+' . $total_parties . ' - 1')); |
|
| 1351 | + (($total_parties == 1) ? '' : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1357 | 1352 | } |
| 1358 | 1353 | |
| 1359 | 1354 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1371,11 +1366,11 @@ discard block |
||
| 1371 | 1366 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1372 | 1367 | |
| 1373 | 1368 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1374 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1369 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1375 | 1370 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1376 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1377 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1378 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1371 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1372 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1373 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1379 | 1374 | . "\n\tif (\$debut_boucle>0" |
| 1380 | 1375 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1381 | 1376 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1460,16 +1455,16 @@ discard block |
||
| 1460 | 1455 | // critere personnalise ? |
| 1461 | 1456 | if ( |
| 1462 | 1457 | (!$serveur or |
| 1463 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1464 | - and (!function_exists($f = $f . '_dist')) |
|
| 1465 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1466 | - and (!function_exists($f = $f . '_dist')) |
|
| 1458 | + ((!function_exists($f = 'critere_'.$serveur.'_'.$table.'_'.$critere)) |
|
| 1459 | + and (!function_exists($f = $f.'_dist')) |
|
| 1460 | + and (!function_exists($f = 'critere_'.$serveur.'_'.$critere)) |
|
| 1461 | + and (!function_exists($f = $f.'_dist')) |
|
| 1467 | 1462 | ) |
| 1468 | 1463 | ) |
| 1469 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1472 | - and (!function_exists($f = $f . '_dist')) |
|
| 1464 | + and (!function_exists($f = 'critere_'.$table.'_'.$critere)) |
|
| 1465 | + and (!function_exists($f = $f.'_dist')) |
|
| 1466 | + and (!function_exists($f = 'critere_'.$critere)) |
|
| 1467 | + and (!function_exists($f = $f.'_dist')) |
|
| 1473 | 1468 | ) { |
| 1474 | 1469 | // fonction critere standard |
| 1475 | 1470 | $f = $defaut; |
@@ -1500,9 +1495,9 @@ discard block |
||
| 1500 | 1495 | */ |
| 1501 | 1496 | function kwote($lisp, $serveur = '', $type = '') { |
| 1502 | 1497 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1503 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1498 | + return $r[1].'"'.sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type).'"'; |
|
| 1504 | 1499 | } else { |
| 1505 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1500 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1506 | 1501 | } |
| 1507 | 1502 | } |
| 1508 | 1503 | |
@@ -1524,7 +1519,7 @@ discard block |
||
| 1524 | 1519 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1525 | 1520 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1526 | 1521 | if (!$r) { |
| 1527 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1522 | + return ['zbug_critere_inconnu', ['critere' => $crit->op.' ?']]; |
|
| 1528 | 1523 | } |
| 1529 | 1524 | [$arg, $op, $val, $col, $where_complement] = $r; |
| 1530 | 1525 | |
@@ -1549,8 +1544,8 @@ discard block |
||
| 1549 | 1544 | "'NOT'", |
| 1550 | 1545 | [ |
| 1551 | 1546 | "'IN'", |
| 1552 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1553 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1547 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1548 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1554 | 1549 | ] |
| 1555 | 1550 | ]; |
| 1556 | 1551 | } |
@@ -1567,22 +1562,22 @@ discard block |
||
| 1567 | 1562 | $descr = $boucles[$idb]->descr; |
| 1568 | 1563 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1569 | 1564 | |
| 1570 | - $var = '$in' . $cpt++; |
|
| 1565 | + $var = '$in'.$cpt++; |
|
| 1571 | 1566 | $x = "\n\t$var = array();"; |
| 1572 | 1567 | foreach ($val as $k => $v) { |
| 1573 | 1568 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1574 | 1569 | // optimiser le traitement des constantes |
| 1575 | 1570 | if (is_numeric($r[2])) { |
| 1576 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1571 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1577 | 1572 | } else { |
| 1578 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1573 | + $x .= "\n\t$var".'[]= '.sql_quote($r[2]).';'; |
|
| 1579 | 1574 | } |
| 1580 | 1575 | } else { |
| 1581 | 1576 | // Pour permettre de passer des tableaux de valeurs |
| 1582 | 1577 | // on repere l'utilisation brute de #ENV**{X}, |
| 1583 | 1578 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1584 | 1579 | // et on deballe mais en rajoutant l'anti XSS |
| 1585 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1580 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1586 | 1581 | } |
| 1587 | 1582 | } |
| 1588 | 1583 | |
@@ -1596,7 +1591,7 @@ discard block |
||
| 1596 | 1591 | $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
| 1597 | 1592 | } |
| 1598 | 1593 | |
| 1599 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1594 | + return "sql_in('$arg', $var".($crit2 == 'NOT' ? ",'NOT'" : '').')'; |
|
| 1600 | 1595 | } |
| 1601 | 1596 | |
| 1602 | 1597 | /** |
@@ -1669,7 +1664,7 @@ discard block |
||
| 1669 | 1664 | $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
| 1670 | 1665 | } |
| 1671 | 1666 | // nous aider en mode debug. |
| 1672 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1667 | + $boucle->debug[] = 'id_ : '.implode(', ', $champs); |
|
| 1673 | 1668 | $boucle->modificateur['id_'] = $champs; |
| 1674 | 1669 | |
| 1675 | 1670 | // créer un critère {id_xxx?} de chaque champ retenu |
@@ -1921,8 +1916,8 @@ discard block |
||
| 1921 | 1916 | "'NOT'", |
| 1922 | 1917 | [ |
| 1923 | 1918 | "'IN'", |
| 1924 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1925 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1919 | + "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", |
|
| 1920 | + ["'SELF'", "'".$boucles[$idb]->id_table.'.'.$boucles[$idb]->primary."'", $where] |
|
| 1926 | 1921 | ] |
| 1927 | 1922 | ]; |
| 1928 | 1923 | } |
@@ -1933,7 +1928,7 @@ discard block |
||
| 1933 | 1928 | if ($crit->cond) { |
| 1934 | 1929 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1935 | 1930 | if ($col === 'date' or $col === 'date_redac') { |
| 1936 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1931 | + if ($pred === "\$Pile[0]['".$col."']") { |
|
| 1937 | 1932 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1938 | 1933 | } |
| 1939 | 1934 | } |
@@ -2096,7 +2091,7 @@ discard block |
||
| 2096 | 2091 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 2097 | 2092 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 2098 | 2093 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 2099 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2094 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 2100 | 2095 | } |
| 2101 | 2096 | // sinon expliciter les |
| 2102 | 2097 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -2112,14 +2107,14 @@ discard block |
||
| 2112 | 2107 | ) { |
| 2113 | 2108 | $r = $r[1] |
| 2114 | 2109 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 2115 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2110 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 2116 | 2111 | $val[0] = "sql_quote($r)"; |
| 2117 | 2112 | } |
| 2118 | 2113 | elseif ( |
| 2119 | 2114 | strpos($val[0], '@@defaultcast@@') !== false |
| 2120 | 2115 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2121 | 2116 | ) { |
| 2122 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2117 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 2123 | 2118 | } |
| 2124 | 2119 | } |
| 2125 | 2120 | |
@@ -2127,7 +2122,7 @@ discard block |
||
| 2127 | 2122 | strpos($val[0], '@@defaultcast@@') !== false |
| 2128 | 2123 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
| 2129 | 2124 | ) { |
| 2130 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2125 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 2131 | 2126 | } |
| 2132 | 2127 | |
| 2133 | 2128 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -2143,7 +2138,7 @@ discard block |
||
| 2143 | 2138 | // inserer le nom de la table SQL devant le nom du champ |
| 2144 | 2139 | if ($table) { |
| 2145 | 2140 | if ($col[0] == '`') { |
| 2146 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2141 | + $arg = "$table.".substr($col, 1, -1); |
|
| 2147 | 2142 | } else { |
| 2148 | 2143 | $arg = "$table.$col"; |
| 2149 | 2144 | } |
@@ -2277,9 +2272,9 @@ discard block |
||
| 2277 | 2272 | **/ |
| 2278 | 2273 | function primary_doublee($decompose, $table) { |
| 2279 | 2274 | $e1 = reset($decompose); |
| 2280 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2275 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2281 | 2276 | |
| 2282 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2277 | + return ["'='", "'$table.".$e1."'", $e2]; |
|
| 2283 | 2278 | } |
| 2284 | 2279 | |
| 2285 | 2280 | /** |
@@ -2318,7 +2313,7 @@ discard block |
||
| 2318 | 2313 | $checkarrivee |
| 2319 | 2314 | and is_string($checkarrivee) |
| 2320 | 2315 | and $a = table_objet($checkarrivee) |
| 2321 | - and in_array($a . '_liens', $joints) |
|
| 2316 | + and in_array($a.'_liens', $joints) |
|
| 2322 | 2317 | ) { |
| 2323 | 2318 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2324 | 2319 | return $res; |
@@ -2338,12 +2333,12 @@ discard block |
||
| 2338 | 2333 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2339 | 2334 | $joindre = false; |
| 2340 | 2335 | foreach ($cols as $col) { |
| 2341 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2336 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2342 | 2337 | if (trouver_champ($c, $boucle->where)) { |
| 2343 | 2338 | $joindre = true; |
| 2344 | 2339 | } else { |
| 2345 | 2340 | // mais ca peut etre dans le FIELD pour le Having |
| 2346 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2341 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2347 | 2342 | if (trouver_champ($c, $boucle->select)) { |
| 2348 | 2343 | $joindre = true; |
| 2349 | 2344 | } |
@@ -2389,7 +2384,7 @@ discard block |
||
| 2389 | 2384 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2390 | 2385 | |
| 2391 | 2386 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2392 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2387 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee.'_liens'); |
|
| 2393 | 2388 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2394 | 2389 | |
| 2395 | 2390 | if (!$intermediaire or !$arrivee) { |
@@ -2493,7 +2488,7 @@ discard block |
||
| 2493 | 2488 | } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
| 2494 | 2489 | // un critere conditionnel sur date est traite a part |
| 2495 | 2490 | // car la date est mise d'office par SPIP, |
| 2496 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2491 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2497 | 2492 | } |
| 2498 | 2493 | |
| 2499 | 2494 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2525,7 +2520,7 @@ discard block |
||
| 2525 | 2520 | and (($p == "'") or ($p == '"')) |
| 2526 | 2521 | and $params[0][1]->type == 'champ' |
| 2527 | 2522 | ) { |
| 2528 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2523 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2529 | 2524 | } else { |
| 2530 | 2525 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2531 | 2526 | $a = calculer_liste($p, $idb, $boucles, $parent); |
@@ -2541,7 +2536,7 @@ discard block |
||
| 2541 | 2536 | $fct = $args_sql = ''; |
| 2542 | 2537 | // fonction SQL ? |
| 2543 | 2538 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2544 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2539 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2545 | 2540 | $fct = $m[1]; |
| 2546 | 2541 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2547 | 2542 | $col = $a[1]; |
@@ -2628,7 +2623,7 @@ discard block |
||
| 2628 | 2623 | # Recherche de l'existence du champ date_xxxx, |
| 2629 | 2624 | # si oui choisir ce champ, sinon choisir xxxx |
| 2630 | 2625 | if (isset($table['field']["date$suite"])) { |
| 2631 | - $date_orig = 'date' . $suite; |
|
| 2626 | + $date_orig = 'date'.$suite; |
|
| 2632 | 2627 | } else { |
| 2633 | 2628 | $date_orig = substr($suite, 1); |
| 2634 | 2629 | } |
@@ -2648,12 +2643,12 @@ discard block |
||
| 2648 | 2643 | } |
| 2649 | 2644 | } |
| 2650 | 2645 | |
| 2651 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2652 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2646 | + $date_compare = "\"' . normaliser_date(". |
|
| 2647 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2653 | 2648 | ") . '\""; |
| 2654 | 2649 | |
| 2655 | 2650 | $col_vraie = $date_orig; |
| 2656 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2651 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2657 | 2652 | |
| 2658 | 2653 | switch ($col) { |
| 2659 | 2654 | case 'date': |
@@ -2673,26 +2668,26 @@ discard block |
||
| 2673 | 2668 | break; |
| 2674 | 2669 | case 'age': |
| 2675 | 2670 | $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
| 2676 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2677 | 2672 | break; |
| 2678 | 2673 | case 'age_relatif': |
| 2679 | 2674 | $col = calculer_param_date($date_compare, $date_orig); |
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2681 | 2676 | break; |
| 2682 | 2677 | case 'jour_relatif': |
| 2683 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2684 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2678 | + $col = '(TO_DAYS('.$date_compare.')-TO_DAYS('.$date_orig.'))'; |
|
| 2679 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2685 | 2680 | break; |
| 2686 | 2681 | case 'mois_relatif': |
| 2687 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2688 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2689 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2690 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + $col = 'MONTH('.$date_compare.')-MONTH('. |
|
| 2683 | + $date_orig.')+12*(YEAR('.$date_compare. |
|
| 2684 | + ')-YEAR('.$date_orig.'))'; |
|
| 2685 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2691 | 2686 | break; |
| 2692 | 2687 | case 'annee_relatif': |
| 2693 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2694 | - $date_orig . ')'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2688 | + $col = 'YEAR('.$date_compare.')-YEAR('. |
|
| 2689 | + $date_orig.')'; |
|
| 2690 | + $col_vraie = ''; // comparer a un int (par defaut) |
|
| 2696 | 2691 | break; |
| 2697 | 2692 | } |
| 2698 | 2693 | |
@@ -2753,10 +2748,10 @@ discard block |
||
| 2753 | 2748 | } |
| 2754 | 2749 | |
| 2755 | 2750 | $boucle->hash .= ' |
| 2756 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2751 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2757 | 2752 | |
| 2758 | 2753 | $boucle->hash .= ' |
| 2759 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2754 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2760 | 2755 | } |
| 2761 | 2756 | |
| 2762 | 2757 | /** |
@@ -2775,7 +2770,7 @@ discard block |
||
| 2775 | 2770 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2776 | 2771 | $boucle = &$boucles[$idb]; |
| 2777 | 2772 | $boucle->hash .= ' |
| 2778 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2773 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2779 | 2774 | } |
| 2780 | 2775 | |
| 2781 | 2776 | |
@@ -2794,7 +2789,7 @@ discard block |
||
| 2794 | 2789 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2795 | 2790 | foreach ($crit->param as $param) { |
| 2796 | 2791 | $boucle->hash .= ' |
| 2797 | - $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2792 | + $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2798 | 2793 | } |
| 2799 | 2794 | } |
| 2800 | 2795 | |
@@ -2813,14 +2808,14 @@ discard block |
||
| 2813 | 2808 | */ |
| 2814 | 2809 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2815 | 2810 | $boucle = &$boucles[$idb]; |
| 2816 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2811 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2817 | 2812 | foreach ($crit->param as $param) { |
| 2818 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2813 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste( |
|
| 2819 | 2814 | $param, |
| 2820 | 2815 | $idb, |
| 2821 | 2816 | $boucles, |
| 2822 | 2817 | $boucles[$idb]->id_parent |
| 2823 | - ) . ";\n"; |
|
| 2818 | + ).";\n"; |
|
| 2824 | 2819 | } |
| 2825 | 2820 | } |
| 2826 | 2821 | |
@@ -2847,14 +2842,14 @@ discard block |
||
| 2847 | 2842 | */ |
| 2848 | 2843 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2849 | 2844 | $boucle = &$boucles[$idb]; |
| 2850 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2845 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2851 | 2846 | foreach ($crit->param as $param) { |
| 2852 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2847 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste( |
|
| 2853 | 2848 | $param, |
| 2854 | 2849 | $idb, |
| 2855 | 2850 | $boucles, |
| 2856 | 2851 | $boucles[$idb]->id_parent |
| 2857 | - ) . ";\n"; |
|
| 2852 | + ).";\n"; |
|
| 2858 | 2853 | } |
| 2859 | 2854 | } |
| 2860 | 2855 | |
@@ -2873,7 +2868,7 @@ discard block |
||
| 2873 | 2868 | $boucle = &$boucles[$idb]; |
| 2874 | 2869 | foreach ($crit->param as $param) { |
| 2875 | 2870 | $boucle->hash .= ' |
| 2876 | - $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2871 | + $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2877 | 2872 | } |
| 2878 | 2873 | } |
| 2879 | 2874 | |
@@ -2914,7 +2909,7 @@ discard block |
||
| 2914 | 2909 | if ($crit->param) { |
| 2915 | 2910 | foreach ($crit->param as $param) { |
| 2916 | 2911 | $boucle->hash .= "\t\$command['si'][] = " |
| 2917 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2912 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2918 | 2913 | } |
| 2919 | 2914 | // interdire {si 0} aussi ! |
| 2920 | 2915 | } else { |
@@ -2938,7 +2933,7 @@ discard block |
||
| 2938 | 2933 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2939 | 2934 | $boucle = &$boucles[$idb]; |
| 2940 | 2935 | $boucle->hash .= ' |
| 2941 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2936 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent).'); |
|
| 2942 | 2937 | $command[\'sourcemode\'] = \'table\';'; |
| 2943 | 2938 | } |
| 2944 | 2939 | |
@@ -2973,7 +2968,7 @@ discard block |
||
| 2973 | 2968 | $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
| 2974 | 2969 | |
| 2975 | 2970 | $in = 'IN'; |
| 2976 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2971 | + $where = ["'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2977 | 2972 | if ($not) { |
| 2978 | 2973 | $where = ["'NOT'", $where]; |
| 2979 | 2974 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | **/ |
| 22 | 22 | |
| 23 | 23 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -47,12 +47,12 @@ discard block |
||
| 47 | 47 | **/ |
| 48 | 48 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 49 | 49 | |
| 50 | - $not = $crit->not; |
|
| 51 | - $boucle = &$boucles[$idb]; |
|
| 52 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 50 | + $not = $crit->not; |
|
| 51 | + $boucle = &$boucles[$idb]; |
|
| 52 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 53 | 53 | |
| 54 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 55 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 54 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 55 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | * @return void|array |
| 70 | 70 | **/ |
| 71 | 71 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 72 | - $not = $crit->not; |
|
| 73 | - $boucle = &$boucles[$idb]; |
|
| 74 | - $id = $boucle->primary; |
|
| 75 | - |
|
| 76 | - if ($not or !$id) { |
|
| 77 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 78 | - } |
|
| 79 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 80 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 72 | + $not = $crit->not; |
|
| 73 | + $boucle = &$boucles[$idb]; |
|
| 74 | + $id = $boucle->primary; |
|
| 75 | + |
|
| 76 | + if ($not or !$id) { |
|
| 77 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 78 | + } |
|
| 79 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 80 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
@@ -97,73 +97,73 @@ discard block |
||
| 97 | 97 | * @return void|array |
| 98 | 98 | **/ |
| 99 | 99 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 100 | - $boucle = &$boucles[$idb]; |
|
| 101 | - $primary = $boucle->primary; |
|
| 102 | - |
|
| 103 | - // la table nécessite une clé primaire, non composée |
|
| 104 | - if (!$primary or strpos($primary, ',')) { |
|
| 105 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 109 | - |
|
| 110 | - // le doublon s'applique sur un type de boucle (article) |
|
| 111 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 112 | - |
|
| 113 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 114 | - // on obtient $nom = "'article' . 'nom'" |
|
| 115 | - if (isset($crit->param[0])) { |
|
| 116 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 120 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 121 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 122 | - |
|
| 123 | - // on crée un sql_in avec la clé primaire de la table |
|
| 124 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 125 | - // $doublons et son index, ici $nom |
|
| 126 | - |
|
| 127 | - // debut du code "sql_in('articles.id_article', " |
|
| 128 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 129 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 130 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 131 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 132 | - |
|
| 133 | - // le debut complet du code des doublons |
|
| 134 | - $debut_doub = $debut_in . $debut_doub; |
|
| 135 | - |
|
| 136 | - // nom du doublon "('article' . 'nom')]" |
|
| 137 | - $fin_doub = "($nom)]"; |
|
| 138 | - |
|
| 139 | - // si on trouve un autre critère doublon, |
|
| 140 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 141 | - foreach ($boucle->where as $k => $w) { |
|
| 142 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 143 | - // fusionner le sql_in (du where) |
|
| 144 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 145 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 146 | - $x = strpos($boucle->hash, $init_comment); |
|
| 147 | - $len = strlen($init_comment); |
|
| 148 | - $boucle->hash = |
|
| 149 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 150 | - |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 156 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 157 | - |
|
| 158 | - // déclarer le doublon s'il n'existe pas encore |
|
| 159 | - $boucle->hash .= $init_comment . $init_code; |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 163 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 164 | - # {!doublons A}{doublons B} |
|
| 165 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 166 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 100 | + $boucle = &$boucles[$idb]; |
|
| 101 | + $primary = $boucle->primary; |
|
| 102 | + |
|
| 103 | + // la table nécessite une clé primaire, non composée |
|
| 104 | + if (!$primary or strpos($primary, ',')) { |
|
| 105 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 109 | + |
|
| 110 | + // le doublon s'applique sur un type de boucle (article) |
|
| 111 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 112 | + |
|
| 113 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 114 | + // on obtient $nom = "'article' . 'nom'" |
|
| 115 | + if (isset($crit->param[0])) { |
|
| 116 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 120 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 121 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 122 | + |
|
| 123 | + // on crée un sql_in avec la clé primaire de la table |
|
| 124 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 125 | + // $doublons et son index, ici $nom |
|
| 126 | + |
|
| 127 | + // debut du code "sql_in('articles.id_article', " |
|
| 128 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 129 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 130 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 131 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 132 | + |
|
| 133 | + // le debut complet du code des doublons |
|
| 134 | + $debut_doub = $debut_in . $debut_doub; |
|
| 135 | + |
|
| 136 | + // nom du doublon "('article' . 'nom')]" |
|
| 137 | + $fin_doub = "($nom)]"; |
|
| 138 | + |
|
| 139 | + // si on trouve un autre critère doublon, |
|
| 140 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 141 | + foreach ($boucle->where as $k => $w) { |
|
| 142 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 143 | + // fusionner le sql_in (du where) |
|
| 144 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 145 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 146 | + $x = strpos($boucle->hash, $init_comment); |
|
| 147 | + $len = strlen($init_comment); |
|
| 148 | + $boucle->hash = |
|
| 149 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 150 | + |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 156 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 157 | + |
|
| 158 | + // déclarer le doublon s'il n'existe pas encore |
|
| 159 | + $boucle->hash .= $init_comment . $init_code; |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 163 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 164 | + # {!doublons A}{doublons B} |
|
| 165 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 166 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | |
@@ -184,14 +184,14 @@ discard block |
||
| 184 | 184 | * @return void |
| 185 | 185 | **/ |
| 186 | 186 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 187 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 188 | - $param = 'oui'; |
|
| 189 | - } |
|
| 190 | - if ($crit->not) { |
|
| 191 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 192 | - } |
|
| 193 | - $boucle = &$boucles[$idb]; |
|
| 194 | - $boucle->lang_select = $param; |
|
| 187 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 188 | + $param = 'oui'; |
|
| 189 | + } |
|
| 190 | + if ($crit->not) { |
|
| 191 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 192 | + } |
|
| 193 | + $boucle = &$boucles[$idb]; |
|
| 194 | + $boucle->lang_select = $param; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | |
@@ -213,15 +213,15 @@ discard block |
||
| 213 | 213 | * @return void |
| 214 | 214 | **/ |
| 215 | 215 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 216 | - [$un, $deux] = $crit->param; |
|
| 217 | - $un = $un[0]->texte; |
|
| 218 | - $deux = $deux[0]->texte; |
|
| 219 | - if ($deux) { |
|
| 220 | - $boucles[$idb]->limit = |
|
| 221 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 222 | - } else { |
|
| 223 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 224 | - } |
|
| 216 | + [$un, $deux] = $crit->param; |
|
| 217 | + $un = $un[0]->texte; |
|
| 218 | + $deux = $deux[0]->texte; |
|
| 219 | + if ($deux) { |
|
| 220 | + $boucles[$idb]->limit = |
|
| 221 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 222 | + } else { |
|
| 223 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 224 | + } |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -255,58 +255,58 @@ discard block |
||
| 255 | 255 | **/ |
| 256 | 256 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 257 | 257 | |
| 258 | - $boucle = &$boucles[$idb]; |
|
| 259 | - // definition de la taille de la page |
|
| 260 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 261 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 262 | - |
|
| 263 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 264 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | - } else { |
|
| 266 | - $r = intval($r[2]); |
|
| 267 | - $pas = strval($r ?: 10); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Calcul du nommage de la pagination si il existe. |
|
| 271 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | - $type = "'$idb'"; |
|
| 274 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | - // Syntaxe {pagination 20, nom} |
|
| 276 | - if (isset($crit->param[0][1])) { |
|
| 277 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | - elseif (isset($crit->param[1][0])) { |
|
| 280 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 284 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | - $partie = |
|
| 286 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | - . "\tif (\$debut_boucle && \$debut_boucle[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" |
|
| 291 | - . "\t}\n" |
|
| 292 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | - |
|
| 294 | - $boucle->hash .= ' |
|
| 258 | + $boucle = &$boucles[$idb]; |
|
| 259 | + // definition de la taille de la page |
|
| 260 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 261 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 262 | + |
|
| 263 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 264 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 265 | + } else { |
|
| 266 | + $r = intval($r[2]); |
|
| 267 | + $pas = strval($r ?: 10); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Calcul du nommage de la pagination si il existe. |
|
| 271 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 272 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 273 | + $type = "'$idb'"; |
|
| 274 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 275 | + // Syntaxe {pagination 20, nom} |
|
| 276 | + if (isset($crit->param[0][1])) { |
|
| 277 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 278 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 279 | + elseif (isset($crit->param[1][0])) { |
|
| 280 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 284 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 285 | + $partie = |
|
| 286 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 287 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 288 | + . "\tif (\$debut_boucle && \$debut_boucle[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" |
|
| 291 | + . "\t}\n" |
|
| 292 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 293 | + |
|
| 294 | + $boucle->hash .= ' |
|
| 295 | 295 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 296 | 296 | |
| 297 | - $boucle->total_parties = $pas; |
|
| 298 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | - // sauf si pas de primaire, ou si primaire composee |
|
| 301 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | - if ( |
|
| 304 | - $boucle->primary |
|
| 305 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | - and !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 297 | + $boucle->total_parties = $pas; |
|
| 298 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 299 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 300 | + // sauf si pas de primaire, ou si primaire composee |
|
| 301 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 302 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 303 | + if ( |
|
| 304 | + $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', ['critere' => 'recherche']), $boucle); |
|
| 333 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = ["'" . $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'] = ["'" . $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 | - [ |
|
| 397 | - "'OR'", |
|
| 398 | - [ |
|
| 399 | - "'AND'", |
|
| 400 | - ["'='", "'$table.id_trad'", 0], |
|
| 401 | - ["'='", "'$table.$prim'", $dprim] |
|
| 402 | - ], |
|
| 403 | - [ |
|
| 404 | - "'AND'", |
|
| 405 | - ["'>'", "'$table.id_trad'", 0], |
|
| 406 | - ["'='", "'$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 | + [ |
|
| 397 | + "'OR'", |
|
| 398 | + [ |
|
| 399 | + "'AND'", |
|
| 400 | + ["'='", "'$table.id_trad'", 0], |
|
| 401 | + ["'='", "'$table.$prim'", $dprim] |
|
| 402 | + ], |
|
| 403 | + [ |
|
| 404 | + "'AND'", |
|
| 405 | + ["'>'", "'$table.id_trad'", 0], |
|
| 406 | + ["'='", "'$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 | - [ |
|
| 432 | - "'OR'", |
|
| 433 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | - ]; |
|
| 436 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + [ |
|
| 432 | + "'OR'", |
|
| 433 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 434 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 435 | + ]; |
|
| 436 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,17 +450,17 @@ 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 = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | - |
|
| 458 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | - else { |
|
| 462 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | - } |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 457 | + |
|
| 458 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 459 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 460 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 461 | + else { |
|
| 462 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 463 | + } |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -491,37 +491,37 @@ discard block |
||
| 491 | 491 | **/ |
| 492 | 492 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 493 | 493 | |
| 494 | - $not = $crit->not; |
|
| 495 | - $boucle = &$boucles[$idb]; |
|
| 496 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | - if (isset($crit->param[0])) { |
|
| 498 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | - // sinon on le prend chez une boucle parente |
|
| 500 | - } else { |
|
| 501 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - //Trouver une jointure |
|
| 505 | - $champ = 'id_rubrique'; |
|
| 506 | - $desc = $boucle->show; |
|
| 507 | - //Seulement si necessaire |
|
| 508 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | - $decompose = decompose_champ_id_objet($champ); |
|
| 514 | - $champ = array_shift($decompose); |
|
| 515 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | - } |
|
| 517 | - } else { |
|
| 518 | - $cle = $boucle->id_table; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 524 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 494 | + $not = $crit->not; |
|
| 495 | + $boucle = &$boucles[$idb]; |
|
| 496 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 497 | + if (isset($crit->param[0])) { |
|
| 498 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 499 | + // sinon on le prend chez une boucle parente |
|
| 500 | + } else { |
|
| 501 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + //Trouver une jointure |
|
| 505 | + $champ = 'id_rubrique'; |
|
| 506 | + $desc = $boucle->show; |
|
| 507 | + //Seulement si necessaire |
|
| 508 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 509 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 510 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 511 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 512 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 513 | + $decompose = decompose_champ_id_objet($champ); |
|
| 514 | + $champ = array_shift($decompose); |
|
| 515 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 516 | + } |
|
| 517 | + } else { |
|
| 518 | + $cle = $boucle->id_table; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 522 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 523 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 524 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | /** |
@@ -537,15 +537,15 @@ discard block |
||
| 537 | 537 | **/ |
| 538 | 538 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 539 | 539 | |
| 540 | - $boucle = &$boucles[$idb]; |
|
| 541 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 542 | - $serveur = $boucle->sql_serveur; |
|
| 540 | + $boucle = &$boucles[$idb]; |
|
| 541 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 542 | + $serveur = $boucle->sql_serveur; |
|
| 543 | 543 | |
| 544 | - $c = "sql_in('" . |
|
| 545 | - $boucle->id_table . '.' . $boucle->primary |
|
| 546 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 544 | + $c = "sql_in('" . |
|
| 545 | + $boucle->id_table . '.' . $boucle->primary |
|
| 546 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 547 | 547 | |
| 548 | - $boucle->where[] = $c; |
|
| 548 | + $boucle->where[] = $c; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | |
@@ -567,31 +567,31 @@ discard block |
||
| 567 | 567 | * @return void|array |
| 568 | 568 | **/ |
| 569 | 569 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 570 | - if ($t = isset($crit->param[0])) { |
|
| 571 | - $t = $crit->param[0]; |
|
| 572 | - if ($t[0]->type == 'texte') { |
|
| 573 | - $t = $t[0]->texte; |
|
| 574 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 575 | - $t = table_objet_sql($r[1]); |
|
| 576 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 577 | - if ($t) { |
|
| 578 | - $t .= '.' . $r[2]; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - } else { |
|
| 582 | - $t = '".' |
|
| 583 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 584 | - . '."'; |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - if ($t) { |
|
| 588 | - $boucles[$idb]->group[] = $t; |
|
| 589 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 590 | - $boucles[$idb]->select[] = $t; |
|
| 591 | - } |
|
| 592 | - } else { |
|
| 593 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 594 | - } |
|
| 570 | + if ($t = isset($crit->param[0])) { |
|
| 571 | + $t = $crit->param[0]; |
|
| 572 | + if ($t[0]->type == 'texte') { |
|
| 573 | + $t = $t[0]->texte; |
|
| 574 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 575 | + $t = table_objet_sql($r[1]); |
|
| 576 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 577 | + if ($t) { |
|
| 578 | + $t .= '.' . $r[2]; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + } else { |
|
| 582 | + $t = '".' |
|
| 583 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 584 | + . '."'; |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + if ($t) { |
|
| 588 | + $boucles[$idb]->group[] = $t; |
|
| 589 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 590 | + $boucles[$idb]->select[] = $t; |
|
| 591 | + } |
|
| 592 | + } else { |
|
| 593 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 594 | + } |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @return void |
| 612 | 612 | **/ |
| 613 | 613 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 614 | - $boucles[$idb]->group = []; |
|
| 614 | + $boucles[$idb]->group = []; |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -648,44 +648,44 @@ discard block |
||
| 648 | 648 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 649 | 649 | */ |
| 650 | 650 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 651 | - if (isset($crit->param[0])) { |
|
| 652 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 653 | - $boucle = $boucles[$idb]; |
|
| 654 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 655 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 656 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 657 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 658 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 659 | - if ( |
|
| 660 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 661 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 662 | - ) { |
|
| 663 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | - } else { |
|
| 665 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - } else { |
|
| 669 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 670 | - } |
|
| 651 | + if (isset($crit->param[0])) { |
|
| 652 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 653 | + $boucle = $boucles[$idb]; |
|
| 654 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 655 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 656 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 657 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 658 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 659 | + if ( |
|
| 660 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 661 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 662 | + ) { |
|
| 663 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 664 | + } else { |
|
| 665 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + } else { |
|
| 669 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 670 | + } |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 674 | - $boucle = $boucles[$idb]; |
|
| 675 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 676 | - $var = '$champs_' . $idb; |
|
| 677 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 678 | - if (!$desc) { |
|
| 679 | - $desc = $boucle->show['field']; |
|
| 680 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 681 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 682 | - } |
|
| 683 | - if ($desc) { |
|
| 684 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 685 | - } |
|
| 686 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 687 | - |
|
| 688 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 674 | + $boucle = $boucles[$idb]; |
|
| 675 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 676 | + $var = '$champs_' . $idb; |
|
| 677 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 678 | + if (!$desc) { |
|
| 679 | + $desc = $boucle->show['field']; |
|
| 680 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 681 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 682 | + } |
|
| 683 | + if ($desc) { |
|
| 684 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 685 | + } |
|
| 686 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 687 | + |
|
| 688 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 725 | 725 | */ |
| 726 | 726 | function critere_par_dist($idb, &$boucles, $crit) { |
| 727 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 727 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -746,93 +746,93 @@ discard block |
||
| 746 | 746 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 747 | 747 | */ |
| 748 | 748 | function critere_parinverse($idb, &$boucles, $crit) { |
| 749 | - $boucle = &$boucles[$idb]; |
|
| 750 | - |
|
| 751 | - $sens = $collecte = ''; |
|
| 752 | - if ($crit->not) { |
|
| 753 | - $sens = " . ' DESC'"; |
|
| 754 | - } |
|
| 755 | - if (isset($boucle->modificateur['collate'])) { |
|
| 756 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - // Pour chaque paramètre du critère |
|
| 760 | - foreach ($crit->param as $tri) { |
|
| 761 | - $order = $fct = ''; |
|
| 762 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 763 | - if ($tri[0]->type != 'texte') { |
|
| 764 | - // calculer le order dynamique qui verifie les champs |
|
| 765 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 766 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 767 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 768 | - } |
|
| 769 | - // tris textuels {par titre} |
|
| 770 | - else { |
|
| 771 | - $par = array_shift($tri); |
|
| 772 | - $par = $par->texte; |
|
| 773 | - |
|
| 774 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 775 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 776 | - $expression = trim($m[1]); |
|
| 777 | - $champ = trim($m[2]); |
|
| 778 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 779 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 780 | - } else { |
|
| 781 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 785 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 786 | - // {par FONCTION(champ)} |
|
| 787 | - if (isset($match) and count($match) > 2) { |
|
| 788 | - $par = substr($match[2], 1, -1); |
|
| 789 | - $fct = $match[1]; |
|
| 790 | - } |
|
| 791 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 792 | - if ($par == 'hasard') { |
|
| 793 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 794 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 795 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 796 | - } else { |
|
| 797 | - // cas général {par champ}, {par table.champ}, ... |
|
| 798 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - // on ne sait pas traiter… |
|
| 803 | - else { |
|
| 804 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 808 | - if (is_array($order)) { |
|
| 809 | - return $order; |
|
| 810 | - } |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 814 | - $t = $m[1]; |
|
| 815 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 816 | - $boucle->select[] = $t; |
|
| 817 | - } |
|
| 818 | - } else { |
|
| 819 | - $sens = ''; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - if ($fct) { |
|
| 823 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 824 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 825 | - } else { |
|
| 826 | - $order = "'$fct(' . $order . ')'"; |
|
| 827 | - } |
|
| 828 | - } |
|
| 829 | - $t = $order . $collecte . $sens; |
|
| 830 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 831 | - $t = $r[1] . $r[2]; |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - $boucle->order[] = $t; |
|
| 835 | - } |
|
| 749 | + $boucle = &$boucles[$idb]; |
|
| 750 | + |
|
| 751 | + $sens = $collecte = ''; |
|
| 752 | + if ($crit->not) { |
|
| 753 | + $sens = " . ' DESC'"; |
|
| 754 | + } |
|
| 755 | + if (isset($boucle->modificateur['collate'])) { |
|
| 756 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + // Pour chaque paramètre du critère |
|
| 760 | + foreach ($crit->param as $tri) { |
|
| 761 | + $order = $fct = ''; |
|
| 762 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 763 | + if ($tri[0]->type != 'texte') { |
|
| 764 | + // calculer le order dynamique qui verifie les champs |
|
| 765 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 766 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 767 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 768 | + } |
|
| 769 | + // tris textuels {par titre} |
|
| 770 | + else { |
|
| 771 | + $par = array_shift($tri); |
|
| 772 | + $par = $par->texte; |
|
| 773 | + |
|
| 774 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 775 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 776 | + $expression = trim($m[1]); |
|
| 777 | + $champ = trim($m[2]); |
|
| 778 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 779 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 780 | + } else { |
|
| 781 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 785 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 786 | + // {par FONCTION(champ)} |
|
| 787 | + if (isset($match) and count($match) > 2) { |
|
| 788 | + $par = substr($match[2], 1, -1); |
|
| 789 | + $fct = $match[1]; |
|
| 790 | + } |
|
| 791 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 792 | + if ($par == 'hasard') { |
|
| 793 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 794 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 795 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 796 | + } else { |
|
| 797 | + // cas général {par champ}, {par table.champ}, ... |
|
| 798 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + // on ne sait pas traiter… |
|
| 803 | + else { |
|
| 804 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 808 | + if (is_array($order)) { |
|
| 809 | + return $order; |
|
| 810 | + } |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 814 | + $t = $m[1]; |
|
| 815 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 816 | + $boucle->select[] = $t; |
|
| 817 | + } |
|
| 818 | + } else { |
|
| 819 | + $sens = ''; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + if ($fct) { |
|
| 823 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 824 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 825 | + } else { |
|
| 826 | + $order = "'$fct(' . $order . ')'"; |
|
| 827 | + } |
|
| 828 | + } |
|
| 829 | + $t = $order . $collecte . $sens; |
|
| 830 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 831 | + $t = $r[1] . $r[2]; |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + $boucle->order[] = $t; |
|
| 835 | + } |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | /** |
@@ -846,13 +846,13 @@ discard block |
||
| 846 | 846 | * @return string Clause pour le Order by |
| 847 | 847 | */ |
| 848 | 848 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 849 | - $boucle = &$boucles[$idb]; |
|
| 850 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 851 | - $parha = 'rand() AS hasard'; |
|
| 852 | - if (!in_array($parha, $boucle->select)) { |
|
| 853 | - $boucle->select[] = $parha; |
|
| 854 | - } |
|
| 855 | - return "'hasard'"; |
|
| 849 | + $boucle = &$boucles[$idb]; |
|
| 850 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 851 | + $parha = 'rand() AS hasard'; |
|
| 852 | + if (!in_array($parha, $boucle->select)) { |
|
| 853 | + $boucle->select[] = $parha; |
|
| 854 | + } |
|
| 855 | + return "'hasard'"; |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /** |
@@ -876,24 +876,24 @@ discard block |
||
| 876 | 876 | * @return string|array Clause pour le Order by (array si erreur) |
| 877 | 877 | */ |
| 878 | 878 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 879 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 880 | - if (is_array($_champ)) { |
|
| 881 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 882 | - } |
|
| 883 | - $boucle = &$boucles[$idb]; |
|
| 884 | - $texte = '0+' . $_champ; |
|
| 885 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 886 | - if ($suite !== "''") { |
|
| 887 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 888 | - } |
|
| 889 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 890 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 891 | - |
|
| 892 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 893 | - $orderassinum = trim($orderassinum, "'"); |
|
| 894 | - |
|
| 895 | - $order = "'$orderassinum, $asnum'"; |
|
| 896 | - return $order; |
|
| 879 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 880 | + if (is_array($_champ)) { |
|
| 881 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 882 | + } |
|
| 883 | + $boucle = &$boucles[$idb]; |
|
| 884 | + $texte = '0+' . $_champ; |
|
| 885 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 886 | + if ($suite !== "''") { |
|
| 887 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 888 | + } |
|
| 889 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 890 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 891 | + |
|
| 892 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 893 | + $orderassinum = trim($orderassinum, "'"); |
|
| 894 | + |
|
| 895 | + $order = "'$orderassinum, $asnum'"; |
|
| 896 | + return $order; |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -914,35 +914,35 @@ discard block |
||
| 914 | 914 | * @return string|array Clause pour le Order by (array si erreur) |
| 915 | 915 | */ |
| 916 | 916 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 917 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 918 | - if (is_array($_champ)) { |
|
| 919 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 920 | - } |
|
| 921 | - $boucle = &$boucles[$idb]; |
|
| 922 | - $texte = '0+' . $_champ; |
|
| 923 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 924 | - if ($suite !== "''") { |
|
| 925 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - $as = false; |
|
| 929 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 930 | - foreach ($boucle->select as $s) { |
|
| 931 | - if (strpos($s, $select) === 0) { |
|
| 932 | - $as = trim(substr($s, strlen($select))); |
|
| 933 | - if (!preg_match(',\W,', $as)) { |
|
| 934 | - break; |
|
| 935 | - } |
|
| 936 | - $as = false; |
|
| 937 | - } |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - if (!$as) { |
|
| 941 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 942 | - $boucle->select[] = $select . $as; |
|
| 943 | - } |
|
| 944 | - $order = "'$as'"; |
|
| 945 | - return $order; |
|
| 917 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 918 | + if (is_array($_champ)) { |
|
| 919 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 920 | + } |
|
| 921 | + $boucle = &$boucles[$idb]; |
|
| 922 | + $texte = '0+' . $_champ; |
|
| 923 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 924 | + if ($suite !== "''") { |
|
| 925 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + $as = false; |
|
| 929 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 930 | + foreach ($boucle->select as $s) { |
|
| 931 | + if (strpos($s, $select) === 0) { |
|
| 932 | + $as = trim(substr($s, strlen($select))); |
|
| 933 | + if (!preg_match(',\W,', $as)) { |
|
| 934 | + break; |
|
| 935 | + } |
|
| 936 | + $as = false; |
|
| 937 | + } |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + if (!$as) { |
|
| 941 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 942 | + $boucle->select[] = $select . $as; |
|
| 943 | + } |
|
| 944 | + $order = "'$as'"; |
|
| 945 | + return $order; |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | |
@@ -962,14 +962,14 @@ discard block |
||
| 962 | 962 | * @return string|array Clause pour le Order by (array si erreur) |
| 963 | 963 | */ |
| 964 | 964 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 965 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 966 | - if (is_array($_champ)) { |
|
| 967 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 968 | - } |
|
| 969 | - $boucle = &$boucles[$idb]; |
|
| 970 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 971 | - $order = "'multi'"; |
|
| 972 | - return $order; |
|
| 965 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 966 | + if (is_array($_champ)) { |
|
| 967 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 968 | + } |
|
| 969 | + $boucle = &$boucles[$idb]; |
|
| 970 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 971 | + $order = "'multi'"; |
|
| 972 | + return $order; |
|
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | /** |
@@ -988,56 +988,56 @@ discard block |
||
| 988 | 988 | * @return array|string |
| 989 | 989 | */ |
| 990 | 990 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 991 | - $boucle = &$boucles[$idb]; |
|
| 992 | - $desc = $boucle->show; |
|
| 993 | - |
|
| 994 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 995 | - if (isset($desc['field'][$par])) { |
|
| 996 | - $par = $boucle->id_table . '.' . $par; |
|
| 997 | - } |
|
| 998 | - // le champ est peut être une jointure |
|
| 999 | - else { |
|
| 1000 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1001 | - $champ = $par; |
|
| 1002 | - |
|
| 1003 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1004 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1005 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1006 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1007 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1008 | - [, $table, $champ] = $r; |
|
| 1009 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1010 | - $table = table_objet_sql($table); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1014 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1015 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1016 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1017 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1018 | - } elseif ( |
|
| 1019 | - $boucle->jointures_explicites |
|
| 1020 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1021 | - ) { |
|
| 1022 | - $par = $alias . '.' . $champ; |
|
| 1023 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1024 | - $par = $alias . '.' . $champ; |
|
| 1025 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1026 | - } elseif ( |
|
| 1027 | - $table_alias |
|
| 1028 | - and isset($boucle->from[$table_alias]) |
|
| 1029 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1030 | - ) { |
|
| 1031 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1032 | - } elseif ($table) { |
|
| 1033 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1034 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1035 | - } else { |
|
| 1036 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - return $raw ? $par : "'$par'"; |
|
| 991 | + $boucle = &$boucles[$idb]; |
|
| 992 | + $desc = $boucle->show; |
|
| 993 | + |
|
| 994 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 995 | + if (isset($desc['field'][$par])) { |
|
| 996 | + $par = $boucle->id_table . '.' . $par; |
|
| 997 | + } |
|
| 998 | + // le champ est peut être une jointure |
|
| 999 | + else { |
|
| 1000 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 1001 | + $champ = $par; |
|
| 1002 | + |
|
| 1003 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1004 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1005 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1006 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1007 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1008 | + [, $table, $champ] = $r; |
|
| 1009 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1010 | + $table = table_objet_sql($table); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1014 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1015 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1016 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1017 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1018 | + } elseif ( |
|
| 1019 | + $boucle->jointures_explicites |
|
| 1020 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1021 | + ) { |
|
| 1022 | + $par = $alias . '.' . $champ; |
|
| 1023 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1024 | + $par = $alias . '.' . $champ; |
|
| 1025 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1026 | + } elseif ( |
|
| 1027 | + $table_alias |
|
| 1028 | + and isset($boucle->from[$table_alias]) |
|
| 1029 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1030 | + ) { |
|
| 1031 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1032 | + } elseif ($table) { |
|
| 1033 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1034 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1035 | + } else { |
|
| 1036 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + return $raw ? $par : "'$par'"; |
|
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | /** |
@@ -1051,11 +1051,11 @@ discard block |
||
| 1051 | 1051 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1052 | 1052 | */ |
| 1053 | 1053 | function critere_par_joint($table, $champ, &$boucle) { |
| 1054 | - $t = array_search($table, $boucle->from); |
|
| 1055 | - if (!$t) { |
|
| 1056 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1057 | - } |
|
| 1058 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1054 | + $t = array_search($table, $boucle->from); |
|
| 1055 | + if (!$t) { |
|
| 1056 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1057 | + } |
|
| 1058 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
@@ -1080,33 +1080,33 @@ discard block |
||
| 1080 | 1080 | */ |
| 1081 | 1081 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1082 | 1082 | |
| 1083 | - $boucle = &$boucles[$idb]; |
|
| 1084 | - // Classement par ordre inverse |
|
| 1085 | - if ($crit->not) { |
|
| 1086 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1087 | - } else { |
|
| 1088 | - $order = "' DESC'"; |
|
| 1089 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1090 | - if (isset($crit->param[0])) { |
|
| 1091 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1092 | - $order = "(($critere)?' DESC':'')"; |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1096 | - if (!$n) { |
|
| 1097 | - if (isset($boucle->default_order[0])) { |
|
| 1098 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1099 | - } else { |
|
| 1100 | - $boucle->default_order[] = ' DESC'; |
|
| 1101 | - } |
|
| 1102 | - } else { |
|
| 1103 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1104 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1105 | - $t = $r[1] . $r[2]; |
|
| 1106 | - } |
|
| 1107 | - $boucle->order[$n - 1] = $t; |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1083 | + $boucle = &$boucles[$idb]; |
|
| 1084 | + // Classement par ordre inverse |
|
| 1085 | + if ($crit->not) { |
|
| 1086 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1087 | + } else { |
|
| 1088 | + $order = "' DESC'"; |
|
| 1089 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1090 | + if (isset($crit->param[0])) { |
|
| 1091 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1092 | + $order = "(($critere)?' DESC':'')"; |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1096 | + if (!$n) { |
|
| 1097 | + if (isset($boucle->default_order[0])) { |
|
| 1098 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1099 | + } else { |
|
| 1100 | + $boucle->default_order[] = ' DESC'; |
|
| 1101 | + } |
|
| 1102 | + } else { |
|
| 1103 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1104 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1105 | + $t = $r[1] . $r[2]; |
|
| 1106 | + } |
|
| 1107 | + $boucle->order[$n - 1] = $t; |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | /** |
@@ -1118,139 +1118,139 @@ discard block |
||
| 1118 | 1118 | * @return void|array |
| 1119 | 1119 | */ |
| 1120 | 1120 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1121 | - $boucle = &$boucles[$idb]; |
|
| 1121 | + $boucle = &$boucles[$idb]; |
|
| 1122 | 1122 | |
| 1123 | - $sens = $collecte = ''; |
|
| 1124 | - if ($crit->not) { |
|
| 1125 | - $sens = " . ' DESC'"; |
|
| 1126 | - } |
|
| 1123 | + $sens = $collecte = ''; |
|
| 1124 | + if ($crit->not) { |
|
| 1125 | + $sens = " . ' DESC'"; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - $crit2 = clone $crit; |
|
| 1129 | - $crit2->not = false; |
|
| 1130 | - $crit2->param = [reset($crit->param)]; |
|
| 1131 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1128 | + $crit2 = clone $crit; |
|
| 1129 | + $crit2->not = false; |
|
| 1130 | + $crit2->param = [reset($crit->param)]; |
|
| 1131 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1132 | 1132 | |
| 1133 | - // erreur ? |
|
| 1134 | - if (is_array($res)) { |
|
| 1135 | - return $res; |
|
| 1136 | - } |
|
| 1133 | + // erreur ? |
|
| 1134 | + if (is_array($res)) { |
|
| 1135 | + return $res; |
|
| 1136 | + } |
|
| 1137 | 1137 | |
| 1138 | - $_order = array_pop($boucle->order); |
|
| 1138 | + $_order = array_pop($boucle->order); |
|
| 1139 | 1139 | |
| 1140 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1140 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1141 | 1141 | |
| 1142 | - $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1143 | - $boucle->order[] = $order; |
|
| 1142 | + $order = "'-FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste(array_reverse($_liste),'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1143 | + $boucle->order[] = $order; |
|
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | 1146 | |
| 1147 | 1147 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1148 | - $params = $crit->param; |
|
| 1149 | - |
|
| 1150 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1151 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - $boucle = &$boucles[$idb]; |
|
| 1155 | - $parent = $boucle->id_parent; |
|
| 1156 | - $fields = $boucle->show['field']; |
|
| 1157 | - |
|
| 1158 | - $date = array_shift($params); |
|
| 1159 | - $type = array_shift($params); |
|
| 1160 | - |
|
| 1161 | - // la valeur $type doit etre connue a la compilation |
|
| 1162 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1163 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1164 | - |
|
| 1165 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1166 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1167 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1168 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1169 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1170 | - $date = $date[0]->texte; |
|
| 1171 | - if (!isset($fields[$date])) { |
|
| 1172 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1173 | - } |
|
| 1174 | - } else { |
|
| 1175 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1176 | - $noms = array_keys($fields); |
|
| 1177 | - $defaut = $noms[0]; |
|
| 1178 | - $noms = join(' ', $noms); |
|
| 1179 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1180 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1181 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1182 | - } |
|
| 1183 | - $annee = $params ? array_shift($params) : ''; |
|
| 1184 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1185 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1186 | - ') ? $x : date("Y"))'; |
|
| 1187 | - |
|
| 1188 | - $mois = $params ? array_shift($params) : ''; |
|
| 1189 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1190 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1191 | - ') ? $x : date("m"))'; |
|
| 1192 | - |
|
| 1193 | - $jour = $params ? array_shift($params) : ''; |
|
| 1194 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1195 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1196 | - ') ? $x : date("d"))'; |
|
| 1197 | - |
|
| 1198 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1199 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1200 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1201 | - ') ? $x : date("Y"))'; |
|
| 1202 | - |
|
| 1203 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1204 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1205 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1206 | - ') ? $x : date("m"))'; |
|
| 1207 | - |
|
| 1208 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1209 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1210 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1211 | - ') ? $x : date("d"))'; |
|
| 1212 | - |
|
| 1213 | - $date = $boucle->id_table . ".$date"; |
|
| 1214 | - |
|
| 1215 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1216 | - if ($type == 'jour') { |
|
| 1217 | - $boucle->where[] = [ |
|
| 1218 | - "'='", |
|
| 1219 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1220 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1221 | - ]; |
|
| 1222 | - } elseif ($type == 'mois') { |
|
| 1223 | - $boucle->where[] = [ |
|
| 1224 | - "'='", |
|
| 1225 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1226 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1227 | - ]; |
|
| 1228 | - } elseif ($type == 'semaine') { |
|
| 1229 | - $boucle->where[] = [ |
|
| 1230 | - "'AND'", |
|
| 1231 | - [ |
|
| 1232 | - "'>='", |
|
| 1233 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1234 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1235 | - ], |
|
| 1236 | - [ |
|
| 1237 | - "'<='", |
|
| 1238 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1239 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1240 | - ] |
|
| 1241 | - ]; |
|
| 1242 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1243 | - $boucle->where[] = [ |
|
| 1244 | - "'AND'", |
|
| 1245 | - [ |
|
| 1246 | - "'>='", |
|
| 1247 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1248 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1249 | - ], |
|
| 1250 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1251 | - ]; |
|
| 1252 | - } |
|
| 1253 | - // sinon on prend tout |
|
| 1148 | + $params = $crit->param; |
|
| 1149 | + |
|
| 1150 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1151 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + $boucle = &$boucles[$idb]; |
|
| 1155 | + $parent = $boucle->id_parent; |
|
| 1156 | + $fields = $boucle->show['field']; |
|
| 1157 | + |
|
| 1158 | + $date = array_shift($params); |
|
| 1159 | + $type = array_shift($params); |
|
| 1160 | + |
|
| 1161 | + // la valeur $type doit etre connue a la compilation |
|
| 1162 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1163 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1164 | + |
|
| 1165 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1166 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1167 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1168 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1169 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1170 | + $date = $date[0]->texte; |
|
| 1171 | + if (!isset($fields[$date])) { |
|
| 1172 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1173 | + } |
|
| 1174 | + } else { |
|
| 1175 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1176 | + $noms = array_keys($fields); |
|
| 1177 | + $defaut = $noms[0]; |
|
| 1178 | + $noms = join(' ', $noms); |
|
| 1179 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1180 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1181 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1182 | + } |
|
| 1183 | + $annee = $params ? array_shift($params) : ''; |
|
| 1184 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1185 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1186 | + ') ? $x : date("Y"))'; |
|
| 1187 | + |
|
| 1188 | + $mois = $params ? array_shift($params) : ''; |
|
| 1189 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1190 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1191 | + ') ? $x : date("m"))'; |
|
| 1192 | + |
|
| 1193 | + $jour = $params ? array_shift($params) : ''; |
|
| 1194 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1195 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1196 | + ') ? $x : date("d"))'; |
|
| 1197 | + |
|
| 1198 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1199 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1200 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1201 | + ') ? $x : date("Y"))'; |
|
| 1202 | + |
|
| 1203 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1204 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1205 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1206 | + ') ? $x : date("m"))'; |
|
| 1207 | + |
|
| 1208 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1209 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1210 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1211 | + ') ? $x : date("d"))'; |
|
| 1212 | + |
|
| 1213 | + $date = $boucle->id_table . ".$date"; |
|
| 1214 | + |
|
| 1215 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1216 | + if ($type == 'jour') { |
|
| 1217 | + $boucle->where[] = [ |
|
| 1218 | + "'='", |
|
| 1219 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1220 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1221 | + ]; |
|
| 1222 | + } elseif ($type == 'mois') { |
|
| 1223 | + $boucle->where[] = [ |
|
| 1224 | + "'='", |
|
| 1225 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1226 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1227 | + ]; |
|
| 1228 | + } elseif ($type == 'semaine') { |
|
| 1229 | + $boucle->where[] = [ |
|
| 1230 | + "'AND'", |
|
| 1231 | + [ |
|
| 1232 | + "'>='", |
|
| 1233 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1234 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1235 | + ], |
|
| 1236 | + [ |
|
| 1237 | + "'<='", |
|
| 1238 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1239 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1240 | + ] |
|
| 1241 | + ]; |
|
| 1242 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1243 | + $boucle->where[] = [ |
|
| 1244 | + "'AND'", |
|
| 1245 | + [ |
|
| 1246 | + "'>='", |
|
| 1247 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1248 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1249 | + ], |
|
| 1250 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1251 | + ]; |
|
| 1252 | + } |
|
| 1253 | + // sinon on prend tout |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | |
@@ -1275,33 +1275,33 @@ discard block |
||
| 1275 | 1275 | * @return void |
| 1276 | 1276 | **/ |
| 1277 | 1277 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1278 | - $boucle = &$boucles[$idb]; |
|
| 1279 | - $a1 = $crit->param[0]; |
|
| 1280 | - $a2 = $crit->param[1]; |
|
| 1281 | - $op = $crit->op; |
|
| 1282 | - |
|
| 1283 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1284 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1285 | - |
|
| 1286 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1287 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1288 | - } else { |
|
| 1289 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1290 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1291 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1292 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1293 | - $mode = (($op == '/') ? '/' : |
|
| 1294 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1295 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1296 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1297 | - $boucle->limit = |
|
| 1298 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1299 | - . ".','." |
|
| 1300 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1301 | - } else { |
|
| 1302 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1303 | - } |
|
| 1304 | - } |
|
| 1278 | + $boucle = &$boucles[$idb]; |
|
| 1279 | + $a1 = $crit->param[0]; |
|
| 1280 | + $a2 = $crit->param[1]; |
|
| 1281 | + $op = $crit->op; |
|
| 1282 | + |
|
| 1283 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1284 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1285 | + |
|
| 1286 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1287 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1288 | + } else { |
|
| 1289 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1290 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1291 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1292 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1293 | + $mode = (($op == '/') ? '/' : |
|
| 1294 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1295 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1296 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1297 | + $boucle->limit = |
|
| 1298 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1299 | + . ".','." |
|
| 1300 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1301 | + } else { |
|
| 1302 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1303 | + } |
|
| 1304 | + } |
|
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | 1307 | /** |
@@ -1329,63 +1329,63 @@ discard block |
||
| 1329 | 1329 | * @return void |
| 1330 | 1330 | **/ |
| 1331 | 1331 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1332 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1333 | - |
|
| 1334 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1335 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1336 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1337 | - // {1/3} |
|
| 1338 | - if ($op1 == '/') { |
|
| 1339 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1340 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1341 | - "($total_parties ? $total_parties : 1)"; |
|
| 1342 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1343 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1344 | - } else { |
|
| 1345 | - // cas {n-1,x} |
|
| 1346 | - if ($op1 == '-') { |
|
| 1347 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - // cas {x,n-1} |
|
| 1351 | - if ($op2 == '-') { |
|
| 1352 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1353 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1354 | - ($total_parties . ' - 1')); |
|
| 1355 | - } else { |
|
| 1356 | - // {x,1} ou {pagination} |
|
| 1357 | - $fin = '$debut_boucle' |
|
| 1358 | - . (is_numeric($total_parties) ? |
|
| 1359 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1360 | - ('+' . $total_parties . ' - 1')); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1364 | - if ($op1 == 'p') { |
|
| 1365 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1366 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1367 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1368 | - } |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - // Notes : |
|
| 1372 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1373 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1374 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1375 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1376 | - |
|
| 1377 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1378 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1379 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1380 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1381 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1382 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1383 | - . "\n\tif (\$debut_boucle>0" |
|
| 1384 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1385 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1386 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1387 | - |
|
| 1388 | - $boucles[$id_boucle]->partie = " |
|
| 1332 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1333 | + |
|
| 1334 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1335 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1336 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1337 | + // {1/3} |
|
| 1338 | + if ($op1 == '/') { |
|
| 1339 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1340 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1341 | + "($total_parties ? $total_parties : 1)"; |
|
| 1342 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1343 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1344 | + } else { |
|
| 1345 | + // cas {n-1,x} |
|
| 1346 | + if ($op1 == '-') { |
|
| 1347 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + // cas {x,n-1} |
|
| 1351 | + if ($op2 == '-') { |
|
| 1352 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1353 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1354 | + ($total_parties . ' - 1')); |
|
| 1355 | + } else { |
|
| 1356 | + // {x,1} ou {pagination} |
|
| 1357 | + $fin = '$debut_boucle' |
|
| 1358 | + . (is_numeric($total_parties) ? |
|
| 1359 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1360 | + ('+' . $total_parties . ' - 1')); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1364 | + if ($op1 == 'p') { |
|
| 1365 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1366 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1367 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + // Notes : |
|
| 1372 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1373 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1374 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1375 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1376 | + |
|
| 1377 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1378 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1379 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1380 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1381 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1382 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1383 | + . "\n\tif (\$debut_boucle>0" |
|
| 1384 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1385 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1386 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1387 | + |
|
| 1388 | + $boucles[$id_boucle]->partie = " |
|
| 1389 | 1389 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1390 | 1390 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1391 | 1391 | } |
@@ -1402,26 +1402,26 @@ discard block |
||
| 1402 | 1402 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1403 | 1403 | **/ |
| 1404 | 1404 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1405 | - if ($param[0]->type != 'texte') { |
|
| 1406 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1407 | - if (isset($param[1]->texte)) { |
|
| 1408 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1409 | - |
|
| 1410 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1411 | - } else { |
|
| 1412 | - return ["intval($a1)", 0]; |
|
| 1413 | - } |
|
| 1414 | - } else { |
|
| 1415 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1416 | - $a1 = $m[1]; |
|
| 1417 | - if (empty($m[3])) { |
|
| 1418 | - return [$a1, 0]; |
|
| 1419 | - } elseif (!empty($m[4])) { |
|
| 1420 | - return [$a1, $m[4]]; |
|
| 1421 | - } else { |
|
| 1422 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1423 | - } |
|
| 1424 | - } |
|
| 1405 | + if ($param[0]->type != 'texte') { |
|
| 1406 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1407 | + if (isset($param[1]->texte)) { |
|
| 1408 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1409 | + |
|
| 1410 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1411 | + } else { |
|
| 1412 | + return ["intval($a1)", 0]; |
|
| 1413 | + } |
|
| 1414 | + } else { |
|
| 1415 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1416 | + $a1 = $m[1]; |
|
| 1417 | + if (empty($m[3])) { |
|
| 1418 | + return [$a1, 0]; |
|
| 1419 | + } elseif (!empty($m[4])) { |
|
| 1420 | + return [$a1, $m[4]]; |
|
| 1421 | + } else { |
|
| 1422 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1423 | + } |
|
| 1424 | + } |
|
| 1425 | 1425 | } |
| 1426 | 1426 | |
| 1427 | 1427 | |
@@ -1448,47 +1448,47 @@ discard block |
||
| 1448 | 1448 | * array : Erreur sur un des critères |
| 1449 | 1449 | **/ |
| 1450 | 1450 | function calculer_criteres($idb, &$boucles) { |
| 1451 | - $msg = ''; |
|
| 1452 | - $boucle = $boucles[$idb]; |
|
| 1453 | - $table = strtoupper($boucle->type_requete); |
|
| 1454 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1455 | - |
|
| 1456 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1457 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1458 | - if (!is_array($boucle->criteres)) { |
|
| 1459 | - return []; |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - foreach ($boucle->criteres as $crit) { |
|
| 1463 | - $critere = $crit->op; |
|
| 1464 | - // critere personnalise ? |
|
| 1465 | - if ( |
|
| 1466 | - (!$serveur or |
|
| 1467 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1468 | - and (!function_exists($f = $f . '_dist')) |
|
| 1469 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1470 | - and (!function_exists($f = $f . '_dist')) |
|
| 1471 | - ) |
|
| 1472 | - ) |
|
| 1473 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1474 | - and (!function_exists($f = $f . '_dist')) |
|
| 1475 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1476 | - and (!function_exists($f = $f . '_dist')) |
|
| 1477 | - ) { |
|
| 1478 | - // fonction critere standard |
|
| 1479 | - $f = $defaut; |
|
| 1480 | - } |
|
| 1481 | - // compile le critere |
|
| 1482 | - $res = $f($idb, $boucles, $crit); |
|
| 1483 | - |
|
| 1484 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1485 | - if (is_array($res)) { |
|
| 1486 | - $msg = $res; |
|
| 1487 | - erreur_squelette($msg, $boucle); |
|
| 1488 | - } |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - return $msg; |
|
| 1451 | + $msg = ''; |
|
| 1452 | + $boucle = $boucles[$idb]; |
|
| 1453 | + $table = strtoupper($boucle->type_requete); |
|
| 1454 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1455 | + |
|
| 1456 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1457 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1458 | + if (!is_array($boucle->criteres)) { |
|
| 1459 | + return []; |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + foreach ($boucle->criteres as $crit) { |
|
| 1463 | + $critere = $crit->op; |
|
| 1464 | + // critere personnalise ? |
|
| 1465 | + if ( |
|
| 1466 | + (!$serveur or |
|
| 1467 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1468 | + and (!function_exists($f = $f . '_dist')) |
|
| 1469 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1470 | + and (!function_exists($f = $f . '_dist')) |
|
| 1471 | + ) |
|
| 1472 | + ) |
|
| 1473 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1474 | + and (!function_exists($f = $f . '_dist')) |
|
| 1475 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1476 | + and (!function_exists($f = $f . '_dist')) |
|
| 1477 | + ) { |
|
| 1478 | + // fonction critere standard |
|
| 1479 | + $f = $defaut; |
|
| 1480 | + } |
|
| 1481 | + // compile le critere |
|
| 1482 | + $res = $f($idb, $boucles, $crit); |
|
| 1483 | + |
|
| 1484 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1485 | + if (is_array($res)) { |
|
| 1486 | + $msg = $res; |
|
| 1487 | + erreur_squelette($msg, $boucle); |
|
| 1488 | + } |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + return $msg; |
|
| 1492 | 1492 | } |
| 1493 | 1493 | |
| 1494 | 1494 | /** |
@@ -1503,11 +1503,11 @@ discard block |
||
| 1503 | 1503 | * @return string Code compilé rééchappé |
| 1504 | 1504 | */ |
| 1505 | 1505 | function kwote($lisp, $serveur = '', $type = '') { |
| 1506 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1507 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1508 | - } else { |
|
| 1509 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1510 | - } |
|
| 1506 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1507 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1508 | + } else { |
|
| 1509 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1510 | + } |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | |
@@ -1526,81 +1526,81 @@ discard block |
||
| 1526 | 1526 | * @return void|array |
| 1527 | 1527 | **/ |
| 1528 | 1528 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1529 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1530 | - if (!$r) { |
|
| 1531 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1532 | - } |
|
| 1533 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1534 | - |
|
| 1535 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1536 | - |
|
| 1537 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1538 | - $where = $in; |
|
| 1539 | - if ($crit->cond) { |
|
| 1540 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1541 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1542 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1543 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 1546 | - if ($crit->exclus) { |
|
| 1547 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1548 | - $where = ["'NOT'", $where]; |
|
| 1549 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1550 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1551 | - { |
|
| 1552 | - $where = [ |
|
| 1553 | - "'NOT'", |
|
| 1554 | - [ |
|
| 1555 | - "'IN'", |
|
| 1556 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1557 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1558 | - ] |
|
| 1559 | - ]; |
|
| 1560 | - } |
|
| 1561 | - } |
|
| 1562 | - |
|
| 1563 | - $boucles[$idb]->where[] = $where; |
|
| 1564 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1565 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1566 | - } |
|
| 1529 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1530 | + if (!$r) { |
|
| 1531 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1532 | + } |
|
| 1533 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1534 | + |
|
| 1535 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1536 | + |
|
| 1537 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1538 | + $where = $in; |
|
| 1539 | + if ($crit->cond) { |
|
| 1540 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1541 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1542 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1543 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1544 | + } |
|
| 1545 | + } |
|
| 1546 | + if ($crit->exclus) { |
|
| 1547 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1548 | + $where = ["'NOT'", $where]; |
|
| 1549 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1550 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1551 | + { |
|
| 1552 | + $where = [ |
|
| 1553 | + "'NOT'", |
|
| 1554 | + [ |
|
| 1555 | + "'IN'", |
|
| 1556 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1557 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1558 | + ] |
|
| 1559 | + ]; |
|
| 1560 | + } |
|
| 1561 | + } |
|
| 1562 | + |
|
| 1563 | + $boucles[$idb]->where[] = $where; |
|
| 1564 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1565 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1566 | + } |
|
| 1567 | 1567 | } |
| 1568 | 1568 | |
| 1569 | 1569 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1570 | - static $num = []; |
|
| 1571 | - $descr = $boucles[$idb]->descr; |
|
| 1572 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1573 | - |
|
| 1574 | - $var = '$in' . $cpt++; |
|
| 1575 | - $x = "\n\t$var = array();"; |
|
| 1576 | - foreach ($val as $k => $v) { |
|
| 1577 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1578 | - // optimiser le traitement des constantes |
|
| 1579 | - if (is_numeric($r[2])) { |
|
| 1580 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1581 | - } else { |
|
| 1582 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1583 | - } |
|
| 1584 | - } else { |
|
| 1585 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1586 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1587 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1588 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1589 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - $boucles[$idb]->in .= $x; |
|
| 1594 | - |
|
| 1595 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1596 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1597 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1598 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1599 | - if (!$crit2) { |
|
| 1600 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1570 | + static $num = []; |
|
| 1571 | + $descr = $boucles[$idb]->descr; |
|
| 1572 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1573 | + |
|
| 1574 | + $var = '$in' . $cpt++; |
|
| 1575 | + $x = "\n\t$var = array();"; |
|
| 1576 | + foreach ($val as $k => $v) { |
|
| 1577 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1578 | + // optimiser le traitement des constantes |
|
| 1579 | + if (is_numeric($r[2])) { |
|
| 1580 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1581 | + } else { |
|
| 1582 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1583 | + } |
|
| 1584 | + } else { |
|
| 1585 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1586 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1587 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1588 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1589 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + $boucles[$idb]->in .= $x; |
|
| 1594 | + |
|
| 1595 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1596 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1597 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1598 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1599 | + if (!$crit2) { |
|
| 1600 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1604 | 1604 | } |
| 1605 | 1605 | |
| 1606 | 1606 | /** |
@@ -1616,22 +1616,22 @@ discard block |
||
| 1616 | 1616 | * @return void |
| 1617 | 1617 | */ |
| 1618 | 1618 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1619 | - $boucle = &$boucles[$idb]; |
|
| 1620 | - if (isset($crit->param[0])) { |
|
| 1621 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1622 | - } else { |
|
| 1623 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1624 | - } |
|
| 1625 | - |
|
| 1626 | - if ($crit->cond) { |
|
| 1627 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - if ($crit->not) { |
|
| 1631 | - $_where = "array('NOT',$_where)"; |
|
| 1632 | - } |
|
| 1633 | - |
|
| 1634 | - $boucle->where[] = $_where; |
|
| 1619 | + $boucle = &$boucles[$idb]; |
|
| 1620 | + if (isset($crit->param[0])) { |
|
| 1621 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1622 | + } else { |
|
| 1623 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1624 | + } |
|
| 1625 | + |
|
| 1626 | + if ($crit->cond) { |
|
| 1627 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + if ($crit->not) { |
|
| 1631 | + $_where = "array('NOT',$_where)"; |
|
| 1632 | + } |
|
| 1633 | + |
|
| 1634 | + $boucle->where[] = $_where; |
|
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | /** |
@@ -1659,31 +1659,31 @@ discard block |
||
| 1659 | 1659 | * @return void |
| 1660 | 1660 | */ |
| 1661 | 1661 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1662 | - /** @var Boucle $boucle */ |
|
| 1663 | - $boucle = $boucles[$idb]; |
|
| 1664 | - |
|
| 1665 | - $champs = lister_champs_id_conditionnel( |
|
| 1666 | - $boucle->show['table'], |
|
| 1667 | - $boucle->show, |
|
| 1668 | - $boucle->sql_serveur |
|
| 1669 | - ); |
|
| 1670 | - |
|
| 1671 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1672 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1673 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1674 | - } |
|
| 1675 | - // nous aider en mode debug. |
|
| 1676 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1677 | - $boucle->modificateur['id_'] = $champs; |
|
| 1678 | - |
|
| 1679 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1680 | - foreach ($champs as $champ) { |
|
| 1681 | - $critere_id_table = new Critere(); |
|
| 1682 | - $critere_id_table->op = $champ; |
|
| 1683 | - $critere_id_table->cond = '?'; |
|
| 1684 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1685 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1686 | - } |
|
| 1662 | + /** @var Boucle $boucle */ |
|
| 1663 | + $boucle = $boucles[$idb]; |
|
| 1664 | + |
|
| 1665 | + $champs = lister_champs_id_conditionnel( |
|
| 1666 | + $boucle->show['table'], |
|
| 1667 | + $boucle->show, |
|
| 1668 | + $boucle->sql_serveur |
|
| 1669 | + ); |
|
| 1670 | + |
|
| 1671 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1672 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1673 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1674 | + } |
|
| 1675 | + // nous aider en mode debug. |
|
| 1676 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1677 | + $boucle->modificateur['id_'] = $champs; |
|
| 1678 | + |
|
| 1679 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1680 | + foreach ($champs as $champ) { |
|
| 1681 | + $critere_id_table = new Critere(); |
|
| 1682 | + $critere_id_table->op = $champ; |
|
| 1683 | + $critere_id_table->cond = '?'; |
|
| 1684 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1685 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1686 | + } |
|
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | 1689 | /** |
@@ -1703,75 +1703,75 @@ discard block |
||
| 1703 | 1703 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1704 | 1704 | */ |
| 1705 | 1705 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1706 | - // calculer la description de la table |
|
| 1707 | - if (!is_array($desc)) { |
|
| 1708 | - $desc = description_table($table, $serveur); |
|
| 1709 | - } |
|
| 1710 | - if (!$desc) { |
|
| 1711 | - return []; |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - // Les champs id_xx de la table demandée |
|
| 1715 | - $champs = array_filter( |
|
| 1716 | - array_keys($desc['field']), |
|
| 1717 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1718 | - ); |
|
| 1719 | - |
|
| 1720 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1721 | - if ( |
|
| 1722 | - in_array('id_rubrique', $champs) |
|
| 1723 | - and !in_array('id_secteur', $champs) |
|
| 1724 | - ) { |
|
| 1725 | - $champs[] = 'id_secteur'; |
|
| 1726 | - } |
|
| 1727 | - |
|
| 1728 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1729 | - if ($serveur) { |
|
| 1730 | - return $champs; |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - $primary = false; |
|
| 1734 | - $associable = false; |
|
| 1735 | - include_spip('action/editer_liens'); |
|
| 1736 | - |
|
| 1737 | - if (isset($desc['type'])) { |
|
| 1738 | - $primary = id_table_objet($desc['type']); |
|
| 1739 | - $associable = objet_associable($desc['type']); |
|
| 1740 | - } |
|
| 1741 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1742 | - $associable = true; |
|
| 1743 | - } |
|
| 1744 | - |
|
| 1745 | - // liste de toutes les tables principales, sauf la notre |
|
| 1746 | - $tables = lister_tables_objets_sql(); |
|
| 1747 | - unset($tables[$table]); |
|
| 1748 | - |
|
| 1749 | - foreach ($tables as $_table => $_desc) { |
|
| 1750 | - if ( |
|
| 1751 | - $associable |
|
| 1752 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1753 | - or objet_associable($_desc['type']) |
|
| 1754 | - ) { |
|
| 1755 | - $champs[] = id_table_objet($_table); |
|
| 1756 | - } |
|
| 1757 | - } |
|
| 1758 | - $champs = array_values(array_unique($champs)); |
|
| 1759 | - |
|
| 1760 | - // Exclusions de certains id |
|
| 1761 | - $exclusions = pipeline( |
|
| 1762 | - 'exclure_id_conditionnel', |
|
| 1763 | - [ |
|
| 1764 | - 'args' => [ |
|
| 1765 | - 'table' => $table, |
|
| 1766 | - 'id_table_objet' => $primary, |
|
| 1767 | - 'associable' => $associable, |
|
| 1768 | - ], |
|
| 1769 | - 'data' => [], |
|
| 1770 | - ] |
|
| 1771 | - ); |
|
| 1772 | - $champs = array_diff($champs, $exclusions); |
|
| 1773 | - |
|
| 1774 | - return $champs; |
|
| 1706 | + // calculer la description de la table |
|
| 1707 | + if (!is_array($desc)) { |
|
| 1708 | + $desc = description_table($table, $serveur); |
|
| 1709 | + } |
|
| 1710 | + if (!$desc) { |
|
| 1711 | + return []; |
|
| 1712 | + } |
|
| 1713 | + |
|
| 1714 | + // Les champs id_xx de la table demandée |
|
| 1715 | + $champs = array_filter( |
|
| 1716 | + array_keys($desc['field']), |
|
| 1717 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1718 | + ); |
|
| 1719 | + |
|
| 1720 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1721 | + if ( |
|
| 1722 | + in_array('id_rubrique', $champs) |
|
| 1723 | + and !in_array('id_secteur', $champs) |
|
| 1724 | + ) { |
|
| 1725 | + $champs[] = 'id_secteur'; |
|
| 1726 | + } |
|
| 1727 | + |
|
| 1728 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1729 | + if ($serveur) { |
|
| 1730 | + return $champs; |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + $primary = false; |
|
| 1734 | + $associable = false; |
|
| 1735 | + include_spip('action/editer_liens'); |
|
| 1736 | + |
|
| 1737 | + if (isset($desc['type'])) { |
|
| 1738 | + $primary = id_table_objet($desc['type']); |
|
| 1739 | + $associable = objet_associable($desc['type']); |
|
| 1740 | + } |
|
| 1741 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1742 | + $associable = true; |
|
| 1743 | + } |
|
| 1744 | + |
|
| 1745 | + // liste de toutes les tables principales, sauf la notre |
|
| 1746 | + $tables = lister_tables_objets_sql(); |
|
| 1747 | + unset($tables[$table]); |
|
| 1748 | + |
|
| 1749 | + foreach ($tables as $_table => $_desc) { |
|
| 1750 | + if ( |
|
| 1751 | + $associable |
|
| 1752 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1753 | + or objet_associable($_desc['type']) |
|
| 1754 | + ) { |
|
| 1755 | + $champs[] = id_table_objet($_table); |
|
| 1756 | + } |
|
| 1757 | + } |
|
| 1758 | + $champs = array_values(array_unique($champs)); |
|
| 1759 | + |
|
| 1760 | + // Exclusions de certains id |
|
| 1761 | + $exclusions = pipeline( |
|
| 1762 | + 'exclure_id_conditionnel', |
|
| 1763 | + [ |
|
| 1764 | + 'args' => [ |
|
| 1765 | + 'table' => $table, |
|
| 1766 | + 'id_table_objet' => $primary, |
|
| 1767 | + 'associable' => $associable, |
|
| 1768 | + ], |
|
| 1769 | + 'data' => [], |
|
| 1770 | + ] |
|
| 1771 | + ); |
|
| 1772 | + $champs = array_diff($champs, $exclusions); |
|
| 1773 | + |
|
| 1774 | + return $champs; |
|
| 1775 | 1775 | } |
| 1776 | 1776 | |
| 1777 | 1777 | /** |
@@ -1826,28 +1826,28 @@ discard block |
||
| 1826 | 1826 | * @return void |
| 1827 | 1827 | */ |
| 1828 | 1828 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1829 | - $boucle = &$boucles[$idb]; |
|
| 1830 | - |
|
| 1831 | - // definition du champ par defaut |
|
| 1832 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1833 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | - $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1835 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1836 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1837 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1838 | - |
|
| 1839 | - $_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):'')"; |
|
| 1840 | - |
|
| 1841 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1842 | - $_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)"; |
|
| 1843 | - |
|
| 1844 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1845 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1846 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1847 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1848 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1849 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1850 | - $boucle->hash .= " |
|
| 1829 | + $boucle = &$boucles[$idb]; |
|
| 1830 | + |
|
| 1831 | + // definition du champ par defaut |
|
| 1832 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1833 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1834 | + $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1835 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1836 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1837 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1838 | + |
|
| 1839 | + $_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):'')"; |
|
| 1840 | + |
|
| 1841 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1842 | + $_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)"; |
|
| 1843 | + |
|
| 1844 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1845 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1846 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1847 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1848 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1849 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1850 | + $boucle->hash .= " |
|
| 1851 | 1851 | \$senstri = ''; |
| 1852 | 1852 | \$tri = $_tri; |
| 1853 | 1853 | if (\$tri){ |
@@ -1855,8 +1855,8 @@ discard block |
||
| 1855 | 1855 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1856 | 1856 | }; |
| 1857 | 1857 | "; |
| 1858 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1859 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1858 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1859 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | # criteres de comparaison |
@@ -1873,21 +1873,21 @@ discard block |
||
| 1873 | 1873 | * @return void|array |
| 1874 | 1874 | **/ |
| 1875 | 1875 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1876 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1877 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1878 | - calculer_critere_parties($idb, $boucles, $crit); |
|
| 1879 | - return; |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1883 | - if (!$r) { |
|
| 1884 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1885 | - # if (!$crit->cond) { |
|
| 1886 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1887 | - # } |
|
| 1888 | - } else { |
|
| 1889 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1890 | - } |
|
| 1876 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1877 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1878 | + calculer_critere_parties($idb, $boucles, $crit); |
|
| 1879 | + return; |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1883 | + if (!$r) { |
|
| 1884 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1885 | + # if (!$crit->cond) { |
|
| 1886 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1887 | + # } |
|
| 1888 | + } else { |
|
| 1889 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1890 | + } |
|
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | 1893 | |
@@ -1907,62 +1907,62 @@ discard block |
||
| 1907 | 1907 | * @return void |
| 1908 | 1908 | **/ |
| 1909 | 1909 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1910 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1911 | - |
|
| 1912 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1913 | - |
|
| 1914 | - // inserer la negation (cf !...) |
|
| 1915 | - |
|
| 1916 | - if ($crit->not) { |
|
| 1917 | - $where = ["'NOT'", $where]; |
|
| 1918 | - } |
|
| 1919 | - if ($crit->exclus) { |
|
| 1920 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1921 | - $where = ["'NOT'", $where]; |
|
| 1922 | - } else { |
|
| 1923 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1924 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1925 | - $where = [ |
|
| 1926 | - "'NOT'", |
|
| 1927 | - [ |
|
| 1928 | - "'IN'", |
|
| 1929 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1930 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1931 | - ] |
|
| 1932 | - ]; |
|
| 1933 | - } |
|
| 1934 | - } |
|
| 1935 | - |
|
| 1936 | - // inserer la condition (cf {lang?}) |
|
| 1937 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1938 | - if ($crit->cond) { |
|
| 1939 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1940 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1941 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1942 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1943 | - } |
|
| 1944 | - } |
|
| 1945 | - |
|
| 1946 | - if ($op === '=' and !$crit->not) { |
|
| 1947 | - $where = [ |
|
| 1948 | - "'?'", |
|
| 1949 | - "(is_array($pred))", |
|
| 1950 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1951 | - $where |
|
| 1952 | - ]; |
|
| 1953 | - } |
|
| 1954 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1955 | - if ($where_complement) { |
|
| 1956 | - // condition annexe du type "AND (objet='article')" |
|
| 1957 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1958 | - } |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - $boucles[$idb]->where[] = $where; |
|
| 1962 | - if ($where_complement) { |
|
| 1963 | - // condition annexe du type "AND (objet='article')" |
|
| 1964 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1965 | - } |
|
| 1910 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1911 | + |
|
| 1912 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1913 | + |
|
| 1914 | + // inserer la negation (cf !...) |
|
| 1915 | + |
|
| 1916 | + if ($crit->not) { |
|
| 1917 | + $where = ["'NOT'", $where]; |
|
| 1918 | + } |
|
| 1919 | + if ($crit->exclus) { |
|
| 1920 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1921 | + $where = ["'NOT'", $where]; |
|
| 1922 | + } else { |
|
| 1923 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1924 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1925 | + $where = [ |
|
| 1926 | + "'NOT'", |
|
| 1927 | + [ |
|
| 1928 | + "'IN'", |
|
| 1929 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1930 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1931 | + ] |
|
| 1932 | + ]; |
|
| 1933 | + } |
|
| 1934 | + } |
|
| 1935 | + |
|
| 1936 | + // inserer la condition (cf {lang?}) |
|
| 1937 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1938 | + if ($crit->cond) { |
|
| 1939 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1940 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1941 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1942 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1943 | + } |
|
| 1944 | + } |
|
| 1945 | + |
|
| 1946 | + if ($op === '=' and !$crit->not) { |
|
| 1947 | + $where = [ |
|
| 1948 | + "'?'", |
|
| 1949 | + "(is_array($pred))", |
|
| 1950 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1951 | + $where |
|
| 1952 | + ]; |
|
| 1953 | + } |
|
| 1954 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1955 | + if ($where_complement) { |
|
| 1956 | + // condition annexe du type "AND (objet='article')" |
|
| 1957 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1958 | + } |
|
| 1959 | + } |
|
| 1960 | + |
|
| 1961 | + $boucles[$idb]->where[] = $where; |
|
| 1962 | + if ($where_complement) { |
|
| 1963 | + // condition annexe du type "AND (objet='article')" |
|
| 1964 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1965 | + } |
|
| 1966 | 1966 | } |
| 1967 | 1967 | |
| 1968 | 1968 | |
@@ -2003,165 +2003,165 @@ discard block |
||
| 2003 | 2003 | **/ |
| 2004 | 2004 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 2005 | 2005 | |
| 2006 | - $boucle = &$boucles[$idb]; |
|
| 2007 | - $type = $boucle->type_requete; |
|
| 2008 | - $table = $boucle->id_table; |
|
| 2009 | - $desc = $boucle->show; |
|
| 2010 | - $col_vraie = null; |
|
| 2011 | - |
|
| 2012 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2013 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2014 | - |
|
| 2015 | - $col_alias = $col; |
|
| 2016 | - $where_complement = false; |
|
| 2017 | - |
|
| 2018 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2019 | - if ($col == 'id_enfant') { |
|
| 2020 | - $col = $boucle->primary; |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2024 | - if ( |
|
| 2025 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2026 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2027 | - ) { |
|
| 2028 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2029 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2030 | - else { |
|
| 2031 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2032 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2033 | - } |
|
| 2034 | - |
|
| 2035 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2036 | - // sauf si exception declaree : sauter cette etape |
|
| 2037 | - else { |
|
| 2038 | - if ( |
|
| 2039 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2040 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2041 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2042 | - ) { |
|
| 2043 | - $e = decompose_champ_id_objet($col); |
|
| 2044 | - $col = array_shift($e); |
|
| 2045 | - $where_complement = primary_doublee($e, $table); |
|
| 2046 | - } // Cas particulier : expressions de date |
|
| 2047 | - else { |
|
| 2048 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2049 | - [$col, $col_vraie] = $c; |
|
| 2050 | - $table = ''; |
|
| 2051 | - } // table explicitée {mots.titre} |
|
| 2052 | - else { |
|
| 2053 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2054 | - [, $table, $col] = $r; |
|
| 2055 | - $col_alias = $col; |
|
| 2056 | - |
|
| 2057 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2058 | - if ( |
|
| 2059 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2060 | - and isset($desc['field'][$col]) |
|
| 2061 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2062 | - ) { |
|
| 2063 | - $table = $cle; |
|
| 2064 | - } else { |
|
| 2065 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2066 | - } |
|
| 2067 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2068 | - if (!$table) { |
|
| 2069 | - return ''; |
|
| 2070 | - } |
|
| 2071 | - } |
|
| 2072 | - // si le champ n'est pas trouvé dans la table, |
|
| 2073 | - // on cherche si une jointure peut l'obtenir |
|
| 2074 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2075 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2076 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2077 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2078 | - } |
|
| 2079 | - else { |
|
| 2080 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2081 | - if (!$r) { |
|
| 2082 | - return ''; |
|
| 2083 | - } |
|
| 2084 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2085 | - } |
|
| 2086 | - } |
|
| 2087 | - } |
|
| 2088 | - } |
|
| 2089 | - } |
|
| 2090 | - } |
|
| 2091 | - |
|
| 2092 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2093 | - // Dans tous les cas, |
|
| 2094 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2095 | - // et passer dans sql_quote avec le type si connu |
|
| 2096 | - // et int sinon si la valeur est numerique |
|
| 2097 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2098 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2099 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2100 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2101 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2102 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2103 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2104 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2105 | - } |
|
| 2106 | - // sinon expliciter les |
|
| 2107 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2108 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2109 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2110 | - // sans toucher aux |
|
| 2111 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2112 | - // sql_quote(truc,'','varchar') |
|
| 2113 | - elseif ( |
|
| 2114 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2115 | - // si pas deja un type |
|
| 2116 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2117 | - ) { |
|
| 2118 | - $r = $r[1] |
|
| 2119 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2120 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2121 | - $val[0] = "sql_quote($r)"; |
|
| 2122 | - } |
|
| 2123 | - elseif ( |
|
| 2124 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2125 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2126 | - ) { |
|
| 2127 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2128 | - } |
|
| 2129 | - } |
|
| 2130 | - |
|
| 2131 | - if ( |
|
| 2132 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2133 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2134 | - ) { |
|
| 2135 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2139 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2140 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2141 | - if ($table === $boucle->id_table) { |
|
| 2142 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2143 | - if ($col_alias != $col_vraie) { |
|
| 2144 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2145 | - } |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2149 | - if ($table) { |
|
| 2150 | - if ($col[0] == '`') { |
|
| 2151 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2152 | - } else { |
|
| 2153 | - $arg = "$table.$col"; |
|
| 2154 | - } |
|
| 2155 | - } else { |
|
| 2156 | - $arg = $col; |
|
| 2157 | - } |
|
| 2158 | - |
|
| 2159 | - // inserer la fonction SQL |
|
| 2160 | - if ($fct) { |
|
| 2161 | - $arg = "$fct($arg$args_sql)"; |
|
| 2162 | - } |
|
| 2163 | - |
|
| 2164 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2006 | + $boucle = &$boucles[$idb]; |
|
| 2007 | + $type = $boucle->type_requete; |
|
| 2008 | + $table = $boucle->id_table; |
|
| 2009 | + $desc = $boucle->show; |
|
| 2010 | + $col_vraie = null; |
|
| 2011 | + |
|
| 2012 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2013 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2014 | + |
|
| 2015 | + $col_alias = $col; |
|
| 2016 | + $where_complement = false; |
|
| 2017 | + |
|
| 2018 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2019 | + if ($col == 'id_enfant') { |
|
| 2020 | + $col = $boucle->primary; |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2024 | + if ( |
|
| 2025 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2026 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2027 | + ) { |
|
| 2028 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2029 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2030 | + else { |
|
| 2031 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2032 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2033 | + } |
|
| 2034 | + |
|
| 2035 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2036 | + // sauf si exception declaree : sauter cette etape |
|
| 2037 | + else { |
|
| 2038 | + if ( |
|
| 2039 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2040 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2041 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2042 | + ) { |
|
| 2043 | + $e = decompose_champ_id_objet($col); |
|
| 2044 | + $col = array_shift($e); |
|
| 2045 | + $where_complement = primary_doublee($e, $table); |
|
| 2046 | + } // Cas particulier : expressions de date |
|
| 2047 | + else { |
|
| 2048 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2049 | + [$col, $col_vraie] = $c; |
|
| 2050 | + $table = ''; |
|
| 2051 | + } // table explicitée {mots.titre} |
|
| 2052 | + else { |
|
| 2053 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2054 | + [, $table, $col] = $r; |
|
| 2055 | + $col_alias = $col; |
|
| 2056 | + |
|
| 2057 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2058 | + if ( |
|
| 2059 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2060 | + and isset($desc['field'][$col]) |
|
| 2061 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2062 | + ) { |
|
| 2063 | + $table = $cle; |
|
| 2064 | + } else { |
|
| 2065 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2066 | + } |
|
| 2067 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2068 | + if (!$table) { |
|
| 2069 | + return ''; |
|
| 2070 | + } |
|
| 2071 | + } |
|
| 2072 | + // si le champ n'est pas trouvé dans la table, |
|
| 2073 | + // on cherche si une jointure peut l'obtenir |
|
| 2074 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2075 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2076 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2077 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2078 | + } |
|
| 2079 | + else { |
|
| 2080 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2081 | + if (!$r) { |
|
| 2082 | + return ''; |
|
| 2083 | + } |
|
| 2084 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2085 | + } |
|
| 2086 | + } |
|
| 2087 | + } |
|
| 2088 | + } |
|
| 2089 | + } |
|
| 2090 | + } |
|
| 2091 | + |
|
| 2092 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2093 | + // Dans tous les cas, |
|
| 2094 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2095 | + // et passer dans sql_quote avec le type si connu |
|
| 2096 | + // et int sinon si la valeur est numerique |
|
| 2097 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2098 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2099 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2100 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2101 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2102 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2103 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2104 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2105 | + } |
|
| 2106 | + // sinon expliciter les |
|
| 2107 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2108 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2109 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2110 | + // sans toucher aux |
|
| 2111 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2112 | + // sql_quote(truc,'','varchar') |
|
| 2113 | + elseif ( |
|
| 2114 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2115 | + // si pas deja un type |
|
| 2116 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2117 | + ) { |
|
| 2118 | + $r = $r[1] |
|
| 2119 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2120 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2121 | + $val[0] = "sql_quote($r)"; |
|
| 2122 | + } |
|
| 2123 | + elseif ( |
|
| 2124 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2125 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2126 | + ) { |
|
| 2127 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2128 | + } |
|
| 2129 | + } |
|
| 2130 | + |
|
| 2131 | + if ( |
|
| 2132 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2133 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2134 | + ) { |
|
| 2135 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2139 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2140 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2141 | + if ($table === $boucle->id_table) { |
|
| 2142 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2143 | + if ($col_alias != $col_vraie) { |
|
| 2144 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2145 | + } |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2149 | + if ($table) { |
|
| 2150 | + if ($col[0] == '`') { |
|
| 2151 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2152 | + } else { |
|
| 2153 | + $arg = "$table.$col"; |
|
| 2154 | + } |
|
| 2155 | + } else { |
|
| 2156 | + $arg = $col; |
|
| 2157 | + } |
|
| 2158 | + |
|
| 2159 | + // inserer la fonction SQL |
|
| 2160 | + if ($fct) { |
|
| 2161 | + $arg = "$fct($arg$args_sql)"; |
|
| 2162 | + } |
|
| 2163 | + |
|
| 2164 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2165 | 2165 | } |
| 2166 | 2166 | |
| 2167 | 2167 | |
@@ -2190,77 +2190,77 @@ discard block |
||
| 2190 | 2190 | **/ |
| 2191 | 2191 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2192 | 2192 | |
| 2193 | - $where = ''; |
|
| 2194 | - |
|
| 2195 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2196 | - // gestion par les plugins des jointures tordues |
|
| 2197 | - // pas automatiques mais necessaires |
|
| 2198 | - $table_sql = table_objet_sql($table); |
|
| 2199 | - if ( |
|
| 2200 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2201 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2202 | - and |
|
| 2203 | - ( |
|
| 2204 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2205 | - or |
|
| 2206 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2207 | - ) |
|
| 2208 | - ) { |
|
| 2209 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2210 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2211 | - |
|
| 2212 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2213 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2214 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2215 | - [$t, $col] = $t[$col]; |
|
| 2216 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2217 | - [$calculer_critere_externe] = $index; |
|
| 2218 | - $t = $table; |
|
| 2219 | - } else { |
|
| 2220 | - $t = ''; |
|
| 2221 | - } // jointure non declaree. La trouver. |
|
| 2222 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2223 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2224 | - } else { |
|
| 2225 | - $t = ''; |
|
| 2226 | - } // jointure non declaree. La trouver. |
|
| 2227 | - |
|
| 2228 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2229 | - |
|
| 2230 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2231 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2232 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2233 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2234 | - $table = ''; |
|
| 2235 | - if ($boucle->jointures_explicites) { |
|
| 2236 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2237 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2241 | - if (!$table) { |
|
| 2242 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2243 | - } |
|
| 2244 | - |
|
| 2245 | - if (!$table) { |
|
| 2246 | - return ''; |
|
| 2247 | - } |
|
| 2248 | - |
|
| 2249 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2250 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2251 | - |
|
| 2252 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2253 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2254 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2255 | - $e = decompose_champ_id_objet($col); |
|
| 2256 | - $col = array_shift($e); |
|
| 2257 | - $where = primary_doublee($e, $table); |
|
| 2258 | - } else { |
|
| 2259 | - $col = reset($cle); |
|
| 2260 | - } |
|
| 2261 | - } |
|
| 2262 | - |
|
| 2263 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2193 | + $where = ''; |
|
| 2194 | + |
|
| 2195 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2196 | + // gestion par les plugins des jointures tordues |
|
| 2197 | + // pas automatiques mais necessaires |
|
| 2198 | + $table_sql = table_objet_sql($table); |
|
| 2199 | + if ( |
|
| 2200 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2201 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2202 | + and |
|
| 2203 | + ( |
|
| 2204 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2205 | + or |
|
| 2206 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2207 | + ) |
|
| 2208 | + ) { |
|
| 2209 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2210 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2211 | + |
|
| 2212 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2213 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2214 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2215 | + [$t, $col] = $t[$col]; |
|
| 2216 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2217 | + [$calculer_critere_externe] = $index; |
|
| 2218 | + $t = $table; |
|
| 2219 | + } else { |
|
| 2220 | + $t = ''; |
|
| 2221 | + } // jointure non declaree. La trouver. |
|
| 2222 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2223 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2224 | + } else { |
|
| 2225 | + $t = ''; |
|
| 2226 | + } // jointure non declaree. La trouver. |
|
| 2227 | + |
|
| 2228 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2229 | + |
|
| 2230 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2231 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2232 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2233 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2234 | + $table = ''; |
|
| 2235 | + if ($boucle->jointures_explicites) { |
|
| 2236 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2237 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2241 | + if (!$table) { |
|
| 2242 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2243 | + } |
|
| 2244 | + |
|
| 2245 | + if (!$table) { |
|
| 2246 | + return ''; |
|
| 2247 | + } |
|
| 2248 | + |
|
| 2249 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2250 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2251 | + |
|
| 2252 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2253 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2254 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2255 | + $e = decompose_champ_id_objet($col); |
|
| 2256 | + $col = array_shift($e); |
|
| 2257 | + $where = primary_doublee($e, $table); |
|
| 2258 | + } else { |
|
| 2259 | + $col = reset($cle); |
|
| 2260 | + } |
|
| 2261 | + } |
|
| 2262 | + |
|
| 2263 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2264 | 2264 | } |
| 2265 | 2265 | |
| 2266 | 2266 | |
@@ -2281,10 +2281,10 @@ discard block |
||
| 2281 | 2281 | * - valeur |
| 2282 | 2282 | **/ |
| 2283 | 2283 | function primary_doublee($decompose, $table) { |
| 2284 | - $e1 = reset($decompose); |
|
| 2285 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2284 | + $e1 = reset($decompose); |
|
| 2285 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2286 | 2286 | |
| 2287 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2287 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2288 | 2288 | } |
| 2289 | 2289 | |
| 2290 | 2290 | /** |
@@ -2315,57 +2315,57 @@ discard block |
||
| 2315 | 2315 | * Vide sinon. |
| 2316 | 2316 | */ |
| 2317 | 2317 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2318 | - // si on demande un truc du genre spip_mots |
|
| 2319 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2320 | - // et qu'on est la |
|
| 2321 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2322 | - if ( |
|
| 2323 | - $checkarrivee |
|
| 2324 | - and is_string($checkarrivee) |
|
| 2325 | - and $a = table_objet($checkarrivee) |
|
| 2326 | - and in_array($a . '_liens', $joints) |
|
| 2327 | - ) { |
|
| 2328 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2329 | - return $res; |
|
| 2330 | - } |
|
| 2331 | - } |
|
| 2332 | - foreach ($joints as $joint) { |
|
| 2333 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2334 | - // alias de table dans le from |
|
| 2335 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2336 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2337 | - $cols = $arrivee[2]; |
|
| 2338 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2339 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2340 | - array_pop($cols); |
|
| 2341 | - } |
|
| 2342 | - if ($t) { |
|
| 2343 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2344 | - $joindre = false; |
|
| 2345 | - foreach ($cols as $col) { |
|
| 2346 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2347 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2348 | - $joindre = true; |
|
| 2349 | - } else { |
|
| 2350 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2351 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2352 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2353 | - $joindre = true; |
|
| 2354 | - } |
|
| 2355 | - } |
|
| 2356 | - } |
|
| 2357 | - if (!$joindre) { |
|
| 2358 | - return $t; |
|
| 2359 | - } |
|
| 2360 | - } |
|
| 2361 | - array_pop($arrivee); |
|
| 2362 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2363 | - return $res; |
|
| 2364 | - } |
|
| 2365 | - } |
|
| 2366 | - } |
|
| 2367 | - |
|
| 2368 | - return ''; |
|
| 2318 | + // si on demande un truc du genre spip_mots |
|
| 2319 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2320 | + // et qu'on est la |
|
| 2321 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2322 | + if ( |
|
| 2323 | + $checkarrivee |
|
| 2324 | + and is_string($checkarrivee) |
|
| 2325 | + and $a = table_objet($checkarrivee) |
|
| 2326 | + and in_array($a . '_liens', $joints) |
|
| 2327 | + ) { |
|
| 2328 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2329 | + return $res; |
|
| 2330 | + } |
|
| 2331 | + } |
|
| 2332 | + foreach ($joints as $joint) { |
|
| 2333 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2334 | + // alias de table dans le from |
|
| 2335 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2336 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2337 | + $cols = $arrivee[2]; |
|
| 2338 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2339 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2340 | + array_pop($cols); |
|
| 2341 | + } |
|
| 2342 | + if ($t) { |
|
| 2343 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2344 | + $joindre = false; |
|
| 2345 | + foreach ($cols as $col) { |
|
| 2346 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2347 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2348 | + $joindre = true; |
|
| 2349 | + } else { |
|
| 2350 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2351 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2352 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2353 | + $joindre = true; |
|
| 2354 | + } |
|
| 2355 | + } |
|
| 2356 | + } |
|
| 2357 | + if (!$joindre) { |
|
| 2358 | + return $t; |
|
| 2359 | + } |
|
| 2360 | + } |
|
| 2361 | + array_pop($arrivee); |
|
| 2362 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2363 | + return $res; |
|
| 2364 | + } |
|
| 2365 | + } |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + return ''; |
|
| 2369 | 2369 | } |
| 2370 | 2370 | |
| 2371 | 2371 | /** |
@@ -2391,35 +2391,35 @@ discard block |
||
| 2391 | 2391 | * Alias de la table de jointure (Lx) |
| 2392 | 2392 | */ |
| 2393 | 2393 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2394 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2395 | - |
|
| 2396 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2397 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2398 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2399 | - |
|
| 2400 | - if (!$intermediaire or !$arrivee) { |
|
| 2401 | - return ''; |
|
| 2402 | - } |
|
| 2403 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2404 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2405 | - |
|
| 2406 | - $res = fabrique_jointures( |
|
| 2407 | - $boucle, |
|
| 2408 | - [ |
|
| 2409 | - [ |
|
| 2410 | - $boucle->id_table, |
|
| 2411 | - $intermediaire, |
|
| 2412 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2413 | - ], |
|
| 2414 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2415 | - ], |
|
| 2416 | - $cond, |
|
| 2417 | - $desc, |
|
| 2418 | - $boucle->id_table, |
|
| 2419 | - [$col] |
|
| 2420 | - ); |
|
| 2421 | - |
|
| 2422 | - return $res; |
|
| 2394 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2395 | + |
|
| 2396 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2397 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2398 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2399 | + |
|
| 2400 | + if (!$intermediaire or !$arrivee) { |
|
| 2401 | + return ''; |
|
| 2402 | + } |
|
| 2403 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2404 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2405 | + |
|
| 2406 | + $res = fabrique_jointures( |
|
| 2407 | + $boucle, |
|
| 2408 | + [ |
|
| 2409 | + [ |
|
| 2410 | + $boucle->id_table, |
|
| 2411 | + $intermediaire, |
|
| 2412 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2413 | + ], |
|
| 2414 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2415 | + ], |
|
| 2416 | + $cond, |
|
| 2417 | + $desc, |
|
| 2418 | + $boucle->id_table, |
|
| 2419 | + [$col] |
|
| 2420 | + ); |
|
| 2421 | + |
|
| 2422 | + return $res; |
|
| 2423 | 2423 | } |
| 2424 | 2424 | |
| 2425 | 2425 | |
@@ -2436,17 +2436,17 @@ discard block |
||
| 2436 | 2436 | * false sinon. |
| 2437 | 2437 | **/ |
| 2438 | 2438 | function trouver_champ($champ, $where) { |
| 2439 | - if (!is_array($where)) { |
|
| 2440 | - return preg_match($champ, $where); |
|
| 2441 | - } else { |
|
| 2442 | - foreach ($where as $clause) { |
|
| 2443 | - if (trouver_champ($champ, $clause)) { |
|
| 2444 | - return true; |
|
| 2445 | - } |
|
| 2446 | - } |
|
| 2447 | - |
|
| 2448 | - return false; |
|
| 2449 | - } |
|
| 2439 | + if (!is_array($where)) { |
|
| 2440 | + return preg_match($champ, $where); |
|
| 2441 | + } else { |
|
| 2442 | + foreach ($where as $clause) { |
|
| 2443 | + if (trouver_champ($champ, $clause)) { |
|
| 2444 | + return true; |
|
| 2445 | + } |
|
| 2446 | + } |
|
| 2447 | + |
|
| 2448 | + return false; |
|
| 2449 | + } |
|
| 2450 | 2450 | } |
| 2451 | 2451 | |
| 2452 | 2452 | |
@@ -2472,129 +2472,129 @@ discard block |
||
| 2472 | 2472 | * - string $args_sql Suite des arguments du critère. ? |
| 2473 | 2473 | **/ |
| 2474 | 2474 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2475 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2476 | - if (count($crit->param) == 0) { |
|
| 2477 | - $op = '='; |
|
| 2478 | - $col = $val = $crit->op; |
|
| 2479 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2480 | - $val = $r[2]; |
|
| 2481 | - } |
|
| 2482 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2483 | - if ($val == 'lang') { |
|
| 2484 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2485 | - } else { |
|
| 2486 | - $defaut = null; |
|
| 2487 | - if ($val == 'id_parent') { |
|
| 2488 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2489 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2490 | - // pour eviter l'erreur SQL |
|
| 2491 | - $val = $boucles[$idb]->primary; |
|
| 2492 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2493 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2494 | - } elseif ($val == 'id_enfant') { |
|
| 2495 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2496 | - // de la boucle superieure |
|
| 2497 | - $val = 'id_parent'; |
|
| 2498 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2499 | - // un critere conditionnel sur date est traite a part |
|
| 2500 | - // car la date est mise d'office par SPIP, |
|
| 2501 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2502 | - } |
|
| 2503 | - |
|
| 2504 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2505 | - $val = [kwote($val)]; |
|
| 2506 | - } |
|
| 2507 | - } else { |
|
| 2508 | - // comparaison explicite |
|
| 2509 | - // le phraseur impose que le premier param soit du texte |
|
| 2510 | - $params = $crit->param; |
|
| 2511 | - $op = $crit->op; |
|
| 2512 | - if ($op == '==') { |
|
| 2513 | - $op = 'REGEXP'; |
|
| 2514 | - } |
|
| 2515 | - $col = array_shift($params); |
|
| 2516 | - $col = $col[0]->texte; |
|
| 2517 | - |
|
| 2518 | - $val = []; |
|
| 2519 | - $parent = $boucles[$idb]->id_parent; |
|
| 2520 | - |
|
| 2521 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2522 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2523 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2524 | - if ( |
|
| 2525 | - count($params) == 1 |
|
| 2526 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2527 | - and $params[0][0]->type == 'texte' |
|
| 2528 | - and $params[0][2]->type == 'texte' |
|
| 2529 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2530 | - and (($p == "'") or ($p == '"')) |
|
| 2531 | - and $params[0][1]->type == 'champ' |
|
| 2532 | - ) { |
|
| 2533 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2534 | - } else { |
|
| 2535 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2536 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2537 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2538 | - $val[] = $a; |
|
| 2539 | - } else { |
|
| 2540 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2541 | - } // toujours quoter en char ici |
|
| 2542 | - } |
|
| 2543 | - } |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - $fct = $args_sql = ''; |
|
| 2547 | - // fonction SQL ? |
|
| 2548 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2549 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2550 | - $fct = $m[1]; |
|
| 2551 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2552 | - $col = $a[1]; |
|
| 2553 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2554 | - $col = $m[1]; |
|
| 2555 | - $args_sql = $m[2]; |
|
| 2556 | - } |
|
| 2557 | - $args_sql .= $a[2]; |
|
| 2558 | - } |
|
| 2559 | - |
|
| 2560 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2475 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2476 | + if (count($crit->param) == 0) { |
|
| 2477 | + $op = '='; |
|
| 2478 | + $col = $val = $crit->op; |
|
| 2479 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2480 | + $val = $r[2]; |
|
| 2481 | + } |
|
| 2482 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2483 | + if ($val == 'lang') { |
|
| 2484 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2485 | + } else { |
|
| 2486 | + $defaut = null; |
|
| 2487 | + if ($val == 'id_parent') { |
|
| 2488 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2489 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2490 | + // pour eviter l'erreur SQL |
|
| 2491 | + $val = $boucles[$idb]->primary; |
|
| 2492 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2493 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2494 | + } elseif ($val == 'id_enfant') { |
|
| 2495 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2496 | + // de la boucle superieure |
|
| 2497 | + $val = 'id_parent'; |
|
| 2498 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2499 | + // un critere conditionnel sur date est traite a part |
|
| 2500 | + // car la date est mise d'office par SPIP, |
|
| 2501 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2502 | + } |
|
| 2503 | + |
|
| 2504 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2505 | + $val = [kwote($val)]; |
|
| 2506 | + } |
|
| 2507 | + } else { |
|
| 2508 | + // comparaison explicite |
|
| 2509 | + // le phraseur impose que le premier param soit du texte |
|
| 2510 | + $params = $crit->param; |
|
| 2511 | + $op = $crit->op; |
|
| 2512 | + if ($op == '==') { |
|
| 2513 | + $op = 'REGEXP'; |
|
| 2514 | + } |
|
| 2515 | + $col = array_shift($params); |
|
| 2516 | + $col = $col[0]->texte; |
|
| 2517 | + |
|
| 2518 | + $val = []; |
|
| 2519 | + $parent = $boucles[$idb]->id_parent; |
|
| 2520 | + |
|
| 2521 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2522 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2523 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2524 | + if ( |
|
| 2525 | + count($params) == 1 |
|
| 2526 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2527 | + and $params[0][0]->type == 'texte' |
|
| 2528 | + and $params[0][2]->type == 'texte' |
|
| 2529 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2530 | + and (($p == "'") or ($p == '"')) |
|
| 2531 | + and $params[0][1]->type == 'champ' |
|
| 2532 | + ) { |
|
| 2533 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2534 | + } else { |
|
| 2535 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2536 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2537 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2538 | + $val[] = $a; |
|
| 2539 | + } else { |
|
| 2540 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2541 | + } // toujours quoter en char ici |
|
| 2542 | + } |
|
| 2543 | + } |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + $fct = $args_sql = ''; |
|
| 2547 | + // fonction SQL ? |
|
| 2548 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2549 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2550 | + $fct = $m[1]; |
|
| 2551 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2552 | + $col = $a[1]; |
|
| 2553 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2554 | + $col = $m[1]; |
|
| 2555 | + $args_sql = $m[2]; |
|
| 2556 | + } |
|
| 2557 | + $args_sql .= $a[2]; |
|
| 2558 | + } |
|
| 2559 | + |
|
| 2560 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2561 | 2561 | } |
| 2562 | 2562 | |
| 2563 | 2563 | // compatibilite ancienne version |
| 2564 | 2564 | |
| 2565 | 2565 | function calculer_vieux_in($params) { |
| 2566 | - $deb = $params[0][0]; |
|
| 2567 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2568 | - $last = $params[$k]; |
|
| 2569 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2570 | - $last = $last[$j]; |
|
| 2571 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2572 | - |
|
| 2573 | - if ( |
|
| 2574 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2575 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2576 | - ) { |
|
| 2577 | - return $params; |
|
| 2578 | - } |
|
| 2579 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2580 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2581 | - $last = $params[$k][$j]; |
|
| 2582 | - $n = strlen($last->texte); |
|
| 2583 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2584 | - $newp = []; |
|
| 2585 | - foreach ($params as $v) { |
|
| 2586 | - if ($v[0]->type != 'texte') { |
|
| 2587 | - $newp[] = $v; |
|
| 2588 | - } else { |
|
| 2589 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2590 | - $t = new Texte(); |
|
| 2591 | - $t->texte = $x; |
|
| 2592 | - $newp[] = [$t]; |
|
| 2593 | - } |
|
| 2594 | - } |
|
| 2595 | - } |
|
| 2596 | - |
|
| 2597 | - return $newp; |
|
| 2566 | + $deb = $params[0][0]; |
|
| 2567 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2568 | + $last = $params[$k]; |
|
| 2569 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2570 | + $last = $last[$j]; |
|
| 2571 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2572 | + |
|
| 2573 | + if ( |
|
| 2574 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2575 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2576 | + ) { |
|
| 2577 | + return $params; |
|
| 2578 | + } |
|
| 2579 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2580 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2581 | + $last = $params[$k][$j]; |
|
| 2582 | + $n = strlen($last->texte); |
|
| 2583 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2584 | + $newp = []; |
|
| 2585 | + foreach ($params as $v) { |
|
| 2586 | + if ($v[0]->type != 'texte') { |
|
| 2587 | + $newp[] = $v; |
|
| 2588 | + } else { |
|
| 2589 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2590 | + $t = new Texte(); |
|
| 2591 | + $t->texte = $x; |
|
| 2592 | + $newp[] = [$t]; |
|
| 2593 | + } |
|
| 2594 | + } |
|
| 2595 | + } |
|
| 2596 | + |
|
| 2597 | + return $newp; |
|
| 2598 | 2598 | } |
| 2599 | 2599 | |
| 2600 | 2600 | /** |
@@ -2613,95 +2613,95 @@ discard block |
||
| 2613 | 2613 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2614 | 2614 | **/ |
| 2615 | 2615 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2616 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2617 | - return ''; |
|
| 2618 | - } |
|
| 2619 | - |
|
| 2620 | - $boucle = $boucles[$idb]; |
|
| 2621 | - $table = $boucle->show; |
|
| 2622 | - |
|
| 2623 | - // si c'est une colonne de la table, ne rien faire |
|
| 2624 | - if (isset($table['field'][$col])) { |
|
| 2625 | - return ''; |
|
| 2626 | - } |
|
| 2627 | - |
|
| 2628 | - // Le type de critère à prendre en compte |
|
| 2629 | - $col = $regs[1]; |
|
| 2630 | - |
|
| 2631 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2632 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2633 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2634 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2635 | - if (isset($table['field']["date$suite"])) { |
|
| 2636 | - $date_orig = 'date' . $suite; |
|
| 2637 | - } else { |
|
| 2638 | - $date_orig = substr($suite, 1); |
|
| 2639 | - } |
|
| 2640 | - |
|
| 2641 | - $pred = $date_orig; |
|
| 2642 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2643 | - // Si aucune déclaration trouvée, on quitte |
|
| 2644 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2645 | - return ''; |
|
| 2646 | - } |
|
| 2647 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2648 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2649 | - |
|
| 2650 | - // Si c'est pour du relatif |
|
| 2651 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2652 | - $pred = 'date'; |
|
| 2653 | - } |
|
| 2654 | - } |
|
| 2655 | - |
|
| 2656 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2657 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2658 | - ") . '\""; |
|
| 2659 | - |
|
| 2660 | - $col_vraie = $date_orig; |
|
| 2661 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2662 | - |
|
| 2663 | - switch ($col) { |
|
| 2664 | - case 'date': |
|
| 2665 | - $col = $date_orig; |
|
| 2666 | - break; |
|
| 2667 | - case 'jour': |
|
| 2668 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2669 | - break; |
|
| 2670 | - case 'mois': |
|
| 2671 | - $col = "MONTH($date_orig)"; |
|
| 2672 | - break; |
|
| 2673 | - case 'annee': |
|
| 2674 | - $col = "YEAR($date_orig)"; |
|
| 2675 | - break; |
|
| 2676 | - case 'heure': |
|
| 2677 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2678 | - break; |
|
| 2679 | - case 'age': |
|
| 2680 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2681 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | - break; |
|
| 2683 | - case 'age_relatif': |
|
| 2684 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | - break; |
|
| 2687 | - case 'jour_relatif': |
|
| 2688 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2689 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2690 | - break; |
|
| 2691 | - case 'mois_relatif': |
|
| 2692 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2693 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2694 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2695 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | - break; |
|
| 2697 | - case 'annee_relatif': |
|
| 2698 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2699 | - $date_orig . ')'; |
|
| 2700 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2701 | - break; |
|
| 2702 | - } |
|
| 2703 | - |
|
| 2704 | - return [$col, $col_vraie]; |
|
| 2616 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2617 | + return ''; |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + $boucle = $boucles[$idb]; |
|
| 2621 | + $table = $boucle->show; |
|
| 2622 | + |
|
| 2623 | + // si c'est une colonne de la table, ne rien faire |
|
| 2624 | + if (isset($table['field'][$col])) { |
|
| 2625 | + return ''; |
|
| 2626 | + } |
|
| 2627 | + |
|
| 2628 | + // Le type de critère à prendre en compte |
|
| 2629 | + $col = $regs[1]; |
|
| 2630 | + |
|
| 2631 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2632 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2633 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2634 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2635 | + if (isset($table['field']["date$suite"])) { |
|
| 2636 | + $date_orig = 'date' . $suite; |
|
| 2637 | + } else { |
|
| 2638 | + $date_orig = substr($suite, 1); |
|
| 2639 | + } |
|
| 2640 | + |
|
| 2641 | + $pred = $date_orig; |
|
| 2642 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2643 | + // Si aucune déclaration trouvée, on quitte |
|
| 2644 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2645 | + return ''; |
|
| 2646 | + } |
|
| 2647 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2648 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2649 | + |
|
| 2650 | + // Si c'est pour du relatif |
|
| 2651 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2652 | + $pred = 'date'; |
|
| 2653 | + } |
|
| 2654 | + } |
|
| 2655 | + |
|
| 2656 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2657 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2658 | + ") . '\""; |
|
| 2659 | + |
|
| 2660 | + $col_vraie = $date_orig; |
|
| 2661 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2662 | + |
|
| 2663 | + switch ($col) { |
|
| 2664 | + case 'date': |
|
| 2665 | + $col = $date_orig; |
|
| 2666 | + break; |
|
| 2667 | + case 'jour': |
|
| 2668 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2669 | + break; |
|
| 2670 | + case 'mois': |
|
| 2671 | + $col = "MONTH($date_orig)"; |
|
| 2672 | + break; |
|
| 2673 | + case 'annee': |
|
| 2674 | + $col = "YEAR($date_orig)"; |
|
| 2675 | + break; |
|
| 2676 | + case 'heure': |
|
| 2677 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2678 | + break; |
|
| 2679 | + case 'age': |
|
| 2680 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2681 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + break; |
|
| 2683 | + case 'age_relatif': |
|
| 2684 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2685 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | + break; |
|
| 2687 | + case 'jour_relatif': |
|
| 2688 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2689 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2690 | + break; |
|
| 2691 | + case 'mois_relatif': |
|
| 2692 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2693 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2694 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2695 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2696 | + break; |
|
| 2697 | + case 'annee_relatif': |
|
| 2698 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2699 | + $date_orig . ')'; |
|
| 2700 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2701 | + break; |
|
| 2702 | + } |
|
| 2703 | + |
|
| 2704 | + return [$col, $col_vraie]; |
|
| 2705 | 2705 | } |
| 2706 | 2706 | |
| 2707 | 2707 | /** |
@@ -2720,16 +2720,16 @@ discard block |
||
| 2720 | 2720 | * de colonne SQL et une date. |
| 2721 | 2721 | **/ |
| 2722 | 2722 | function calculer_param_date($date_compare, $date_orig) { |
| 2723 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2724 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2725 | - $date_compare = '\'$x\''; |
|
| 2726 | - } else { |
|
| 2727 | - $init = $date_compare; |
|
| 2728 | - } |
|
| 2729 | - |
|
| 2730 | - return |
|
| 2731 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2732 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2723 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2724 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2725 | + $date_compare = '\'$x\''; |
|
| 2726 | + } else { |
|
| 2727 | + $init = $date_compare; |
|
| 2728 | + } |
|
| 2729 | + |
|
| 2730 | + return |
|
| 2731 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2732 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2733 | 2733 | } |
| 2734 | 2734 | |
| 2735 | 2735 | /** |
@@ -2747,20 +2747,20 @@ discard block |
||
| 2747 | 2747 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2748 | 2748 | */ |
| 2749 | 2749 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2750 | - $boucle = &$boucles[$idb]; |
|
| 2751 | - |
|
| 2752 | - $args = []; |
|
| 2753 | - foreach ($crit->param as &$param) { |
|
| 2754 | - array_push( |
|
| 2755 | - $args, |
|
| 2756 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2757 | - ); |
|
| 2758 | - } |
|
| 2750 | + $boucle = &$boucles[$idb]; |
|
| 2759 | 2751 | |
| 2760 | - $boucle->hash .= ' |
|
| 2752 | + $args = []; |
|
| 2753 | + foreach ($crit->param as &$param) { |
|
| 2754 | + array_push( |
|
| 2755 | + $args, |
|
| 2756 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2757 | + ); |
|
| 2758 | + } |
|
| 2759 | + |
|
| 2760 | + $boucle->hash .= ' |
|
| 2761 | 2761 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2762 | 2762 | |
| 2763 | - $boucle->hash .= ' |
|
| 2763 | + $boucle->hash .= ' |
|
| 2764 | 2764 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2765 | 2765 | } |
| 2766 | 2766 | |
@@ -2778,8 +2778,8 @@ discard block |
||
| 2778 | 2778 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2779 | 2779 | */ |
| 2780 | 2780 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2781 | - $boucle = &$boucles[$idb]; |
|
| 2782 | - $boucle->hash .= ' |
|
| 2781 | + $boucle = &$boucles[$idb]; |
|
| 2782 | + $boucle->hash .= ' |
|
| 2783 | 2783 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2784 | 2784 | } |
| 2785 | 2785 | |
@@ -2795,12 +2795,12 @@ discard block |
||
| 2795 | 2795 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2796 | 2796 | */ |
| 2797 | 2797 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2798 | - $boucle = &$boucles[$idb]; |
|
| 2799 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2800 | - foreach ($crit->param as $param) { |
|
| 2801 | - $boucle->hash .= ' |
|
| 2798 | + $boucle = &$boucles[$idb]; |
|
| 2799 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2800 | + foreach ($crit->param as $param) { |
|
| 2801 | + $boucle->hash .= ' |
|
| 2802 | 2802 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2803 | - } |
|
| 2803 | + } |
|
| 2804 | 2804 | } |
| 2805 | 2805 | |
| 2806 | 2806 | /** |
@@ -2817,16 +2817,16 @@ discard block |
||
| 2817 | 2817 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2818 | 2818 | */ |
| 2819 | 2819 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2820 | - $boucle = &$boucles[$idb]; |
|
| 2821 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2822 | - foreach ($crit->param as $param) { |
|
| 2823 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2824 | - $param, |
|
| 2825 | - $idb, |
|
| 2826 | - $boucles, |
|
| 2827 | - $boucles[$idb]->id_parent |
|
| 2828 | - ) . ";\n"; |
|
| 2829 | - } |
|
| 2820 | + $boucle = &$boucles[$idb]; |
|
| 2821 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2822 | + foreach ($crit->param as $param) { |
|
| 2823 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2824 | + $param, |
|
| 2825 | + $idb, |
|
| 2826 | + $boucles, |
|
| 2827 | + $boucles[$idb]->id_parent |
|
| 2828 | + ) . ";\n"; |
|
| 2829 | + } |
|
| 2830 | 2830 | } |
| 2831 | 2831 | |
| 2832 | 2832 | /** |
@@ -2851,16 +2851,16 @@ discard block |
||
| 2851 | 2851 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2852 | 2852 | */ |
| 2853 | 2853 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2854 | - $boucle = &$boucles[$idb]; |
|
| 2855 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2856 | - foreach ($crit->param as $param) { |
|
| 2857 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2858 | - $param, |
|
| 2859 | - $idb, |
|
| 2860 | - $boucles, |
|
| 2861 | - $boucles[$idb]->id_parent |
|
| 2862 | - ) . ";\n"; |
|
| 2863 | - } |
|
| 2854 | + $boucle = &$boucles[$idb]; |
|
| 2855 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2856 | + foreach ($crit->param as $param) { |
|
| 2857 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2858 | + $param, |
|
| 2859 | + $idb, |
|
| 2860 | + $boucles, |
|
| 2861 | + $boucles[$idb]->id_parent |
|
| 2862 | + ) . ";\n"; |
|
| 2863 | + } |
|
| 2864 | 2864 | } |
| 2865 | 2865 | |
| 2866 | 2866 | /** |
@@ -2875,11 +2875,11 @@ discard block |
||
| 2875 | 2875 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2876 | 2876 | */ |
| 2877 | 2877 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2878 | - $boucle = &$boucles[$idb]; |
|
| 2879 | - foreach ($crit->param as $param) { |
|
| 2880 | - $boucle->hash .= ' |
|
| 2878 | + $boucle = &$boucles[$idb]; |
|
| 2879 | + foreach ($crit->param as $param) { |
|
| 2880 | + $boucle->hash .= ' |
|
| 2881 | 2881 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2882 | - } |
|
| 2882 | + } |
|
| 2883 | 2883 | } |
| 2884 | 2884 | |
| 2885 | 2885 | |
@@ -2911,20 +2911,20 @@ discard block |
||
| 2911 | 2911 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2912 | 2912 | */ |
| 2913 | 2913 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2914 | - $boucle = &$boucles[$idb]; |
|
| 2915 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2916 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2917 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2918 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2919 | - if ($crit->param) { |
|
| 2920 | - foreach ($crit->param as $param) { |
|
| 2921 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2922 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2923 | - } |
|
| 2924 | - // interdire {si 0} aussi ! |
|
| 2925 | - } else { |
|
| 2926 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2927 | - } |
|
| 2914 | + $boucle = &$boucles[$idb]; |
|
| 2915 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2916 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2917 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2918 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2919 | + if ($crit->param) { |
|
| 2920 | + foreach ($crit->param as $param) { |
|
| 2921 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2922 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2923 | + } |
|
| 2924 | + // interdire {si 0} aussi ! |
|
| 2925 | + } else { |
|
| 2926 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2927 | + } |
|
| 2928 | 2928 | } |
| 2929 | 2929 | |
| 2930 | 2930 | /** |
@@ -2941,8 +2941,8 @@ discard block |
||
| 2941 | 2941 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2942 | 2942 | */ |
| 2943 | 2943 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2944 | - $boucle = &$boucles[$idb]; |
|
| 2945 | - $boucle->hash .= ' |
|
| 2944 | + $boucle = &$boucles[$idb]; |
|
| 2945 | + $boucle->hash .= ' |
|
| 2946 | 2946 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2947 | 2947 | $command[\'sourcemode\'] = \'table\';'; |
| 2948 | 2948 | } |
@@ -2963,27 +2963,27 @@ discard block |
||
| 2963 | 2963 | */ |
| 2964 | 2964 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2965 | 2965 | |
| 2966 | - $not = $crit->not; |
|
| 2967 | - $boucle = &$boucles[$idb]; |
|
| 2968 | - $primary = $boucle->primary; |
|
| 2966 | + $not = $crit->not; |
|
| 2967 | + $boucle = &$boucles[$idb]; |
|
| 2968 | + $primary = $boucle->primary; |
|
| 2969 | 2969 | |
| 2970 | - if (!$primary or strpos($primary, ',')) { |
|
| 2971 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2970 | + if (!$primary or strpos($primary, ',')) { |
|
| 2971 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2972 | 2972 | |
| 2973 | - return; |
|
| 2974 | - } |
|
| 2975 | - $table = $boucle->type_requete; |
|
| 2976 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2973 | + return; |
|
| 2974 | + } |
|
| 2975 | + $table = $boucle->type_requete; |
|
| 2976 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2977 | 2977 | |
| 2978 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2978 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2979 | 2979 | |
| 2980 | - $in = 'IN'; |
|
| 2981 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2982 | - if ($not) { |
|
| 2983 | - $where = ["'NOT'", $where]; |
|
| 2984 | - } |
|
| 2980 | + $in = 'IN'; |
|
| 2981 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2982 | + if ($not) { |
|
| 2983 | + $where = ["'NOT'", $where]; |
|
| 2984 | + } |
|
| 2985 | 2985 | |
| 2986 | - $boucle->where[] = $where; |
|
| 2986 | + $boucle->where[] = $where; |
|
| 2987 | 2987 | } |
| 2988 | 2988 | |
| 2989 | 2989 | /** |
@@ -2999,8 +2999,8 @@ discard block |
||
| 2999 | 2999 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 3000 | 3000 | */ |
| 3001 | 3001 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 3002 | - $not = $crit->not; |
|
| 3003 | - $crit->not = $not ? false : true; |
|
| 3004 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 3005 | - $crit->not = $not; |
|
| 3002 | + $not = $crit->not; |
|
| 3003 | + $crit->not = $not ? false : true; |
|
| 3004 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 3005 | + $crit->not = $not; |
|
| 3006 | 3006 | } |
@@ -11,127 +11,127 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function format_boucle_html($preaff, $avant, $nom, $type, $crit, $corps, $apres, $altern, $postaff, $prof) { |
| 18 | - $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | - $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | - $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | - $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | - $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | - if (!$corps) { |
|
| 24 | - $corps = ' />'; |
|
| 25 | - } else { |
|
| 26 | - $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 18 | + $preaff = $preaff ? "<BB$nom>$preaff" : ''; |
|
| 19 | + $avant = $avant ? "<B$nom>$avant" : ''; |
|
| 20 | + $apres = $apres ? "$apres</B$nom>" : ''; |
|
| 21 | + $altern = $altern ? "$altern<//B$nom>" : ''; |
|
| 22 | + $postaff = $postaff ? "$postaff</BB$nom>" : ''; |
|
| 23 | + if (!$corps) { |
|
| 24 | + $corps = ' />'; |
|
| 25 | + } else { |
|
| 26 | + $corps = ">$corps</BOUCLE$nom>"; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return "$preaff$avant<BOUCLE$nom($type)$crit$corps$apres$altern$postaff"; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | - if (strpos($file, '#') === false) { |
|
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | - } else { |
|
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 37 | - } |
|
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | - |
|
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 33 | + if (strpos($file, '#') === false) { |
|
| 34 | + $t = $file ? ('(' . $file . ')') : ''; |
|
| 35 | + } else { |
|
| 36 | + $t = '{fond=' . $file . '}'; |
|
| 37 | + } |
|
| 38 | + $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 39 | + |
|
| 40 | + return ('<INCLURE' . $t . $args . '>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | - $contenu = []; |
|
| 45 | - foreach ($args as $l => $t) { |
|
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | - } |
|
| 44 | + $contenu = []; |
|
| 45 | + foreach ($args as $l => $t) { |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | - foreach ($args as $k => $v) { |
|
| 54 | - $args[$k] = "$k=$v"; |
|
| 55 | - } |
|
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 53 | + foreach ($args as $k => $v) { |
|
| 54 | + $args[$k] = "$k=$v"; |
|
| 55 | + } |
|
| 56 | + $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | - $nom = '#' |
|
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 64 | - . $nom |
|
| 65 | - . $etoile |
|
| 66 | - . $args |
|
| 67 | - . $filtres; |
|
| 62 | + $nom = '#' |
|
| 63 | + . ($boucle ? ($boucle . ':') : '') |
|
| 64 | + . $nom |
|
| 65 | + . $etoile |
|
| 66 | + . $args |
|
| 67 | + . $filtres; |
|
| 68 | 68 | |
| 69 | - // Determiner si c'est un champ etendu, |
|
| 69 | + // Determiner si c'est un champ etendu, |
|
| 70 | 70 | |
| 71 | - $s = ($avant or $apres or $filtres |
|
| 72 | - or (strpos($args, '(#') !== false)); |
|
| 71 | + $s = ($avant or $apres or $filtres |
|
| 72 | + or (strpos($args, '(#') !== false)); |
|
| 73 | 73 | |
| 74 | - return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 74 | + return ($s ? "[$avant($nom)$apres]" : $nom); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function format_critere_html($critere) { |
| 78 | - foreach ($critere as $k => $crit) { |
|
| 79 | - $crit_s = ''; |
|
| 80 | - foreach ($crit as $operande) { |
|
| 81 | - [$type, $valeur] = $operande; |
|
| 82 | - if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | - $valeur = substr($valeur, 1, -1); |
|
| 84 | - if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | - $valeur = substr($valeur, 1, -1); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - $crit_s .= $valeur; |
|
| 89 | - } |
|
| 90 | - $critere[$k] = $crit_s; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 78 | + foreach ($critere as $k => $crit) { |
|
| 79 | + $crit_s = ''; |
|
| 80 | + foreach ($crit as $operande) { |
|
| 81 | + [$type, $valeur] = $operande; |
|
| 82 | + if ($type == 'champ' and $valeur[0] == '[') { |
|
| 83 | + $valeur = substr($valeur, 1, -1); |
|
| 84 | + if (preg_match(',^[(](#[^|]*)[)]$,sS', $valeur)) { |
|
| 85 | + $valeur = substr($valeur, 1, -1); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + $crit_s .= $valeur; |
|
| 89 | + } |
|
| 90 | + $critere[$k] = $crit_s; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | - return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 97 | + return ((($fonc !== '') ? "|$fonc" : $fonc) |
|
| 98 | + . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
| 102 | 102 | function format_suite_html($args) { |
| 103 | - for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | - [$texte, $type] = $args[$i]; |
|
| 105 | - [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | - if (!$texte or !$texte2) { |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 109 | - $c1 = substr($texte, -1); |
|
| 110 | - if ($type2 !== 'texte') { |
|
| 111 | - // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | - // ou assimiles, forcer la notation pleine |
|
| 113 | - if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | - } |
|
| 116 | - } else { |
|
| 117 | - if ($type == 'texte') { |
|
| 118 | - continue; |
|
| 119 | - } |
|
| 120 | - // si un champ ou assimiles est suivi d'un texte |
|
| 121 | - // et si celui-ci commence par un caractere de champ |
|
| 122 | - // forcer la notation pleine |
|
| 123 | - if ( |
|
| 124 | - ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | - or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | - ) { |
|
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 103 | + for ($i = 0; $i < (is_countable($args) ? count($args) : 0) - 1; $i++) { |
|
| 104 | + [$texte, $type] = $args[$i]; |
|
| 105 | + [$texte2, $type2] = $args[$i + 1]; |
|
| 106 | + if (!$texte or !$texte2) { |
|
| 107 | + continue; |
|
| 108 | + } |
|
| 109 | + $c1 = substr($texte, -1); |
|
| 110 | + if ($type2 !== 'texte') { |
|
| 111 | + // si un texte se termine par ( et est suivi d'un champ |
|
| 112 | + // ou assimiles, forcer la notation pleine |
|
| 113 | + if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
|
| 114 | + $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 115 | + } |
|
| 116 | + } else { |
|
| 117 | + if ($type == 'texte') { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 120 | + // si un champ ou assimiles est suivi d'un texte |
|
| 121 | + // et si celui-ci commence par un caractere de champ |
|
| 122 | + // forcer la notation pleine |
|
| 123 | + if ( |
|
| 124 | + ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
|
| 125 | + or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
|
| 126 | + ) { |
|
| 127 | + $args[$i][0] = '[(' . $texte . ')]'; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return join('', array_map(fn($arg) => reset($arg), $args)); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | function format_texte_html($texte) { |
| 136 | - return $texte; |
|
| 136 | + return $texte; |
|
| 137 | 137 | } |
@@ -31,36 +31,36 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | function format_inclure_html($file, $args, $prof) { |
| 33 | 33 | if (strpos($file, '#') === false) { |
| 34 | - $t = $file ? ('(' . $file . ')') : ''; |
|
| 34 | + $t = $file ? ('('.$file.')') : ''; |
|
| 35 | 35 | } else { |
| 36 | - $t = '{fond=' . $file . '}'; |
|
| 36 | + $t = '{fond='.$file.'}'; |
|
| 37 | 37 | } |
| 38 | - $args = !$args ? '' : ('{' . join(', ', $args) . '}'); |
|
| 38 | + $args = !$args ? '' : ('{'.join(', ', $args).'}'); |
|
| 39 | 39 | |
| 40 | - return ('<INCLURE' . $t . $args . '>'); |
|
| 40 | + return ('<INCLURE'.$t.$args.'>'); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | function format_polyglotte_html($args, $prof) { |
| 44 | 44 | $contenu = []; |
| 45 | 45 | foreach ($args as $l => $t) { |
| 46 | - $contenu[] = ($l ? "[$l]" : '') . $t; |
|
| 46 | + $contenu[] = ($l ? "[$l]" : '').$t; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - return ('<multi>' . join(' ', $contenu) . '</multi>'); |
|
| 49 | + return ('<multi>'.join(' ', $contenu).'</multi>'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | function format_idiome_html($nom, $module, $args, $filtres, $prof) { |
| 53 | 53 | foreach ($args as $k => $v) { |
| 54 | 54 | $args[$k] = "$k=$v"; |
| 55 | 55 | } |
| 56 | - $args = (!$args ? '' : ('{' . join(',', $args) . '}')); |
|
| 56 | + $args = (!$args ? '' : ('{'.join(',', $args).'}')); |
|
| 57 | 57 | |
| 58 | - return ('<:' . ($module ? "$module:" : '') . $nom . $args . $filtres . ':>'); |
|
| 58 | + return ('<:'.($module ? "$module:" : '').$nom.$args.$filtres.':>'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | function format_champ_html($nom, $boucle, $etoile, $avant, $apres, $args, $filtres, $prof) { |
| 62 | 62 | $nom = '#' |
| 63 | - . ($boucle ? ($boucle . ':') : '') |
|
| 63 | + . ($boucle ? ($boucle.':') : '') |
|
| 64 | 64 | . $nom |
| 65 | 65 | . $etoile |
| 66 | 66 | . $args |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | $critere[$k] = $crit_s; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - return (!$critere ? '' : ('{' . join(',', $critere) . '}')); |
|
| 93 | + return (!$critere ? '' : ('{'.join(',', $critere).'}')); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function format_liste_html($fonc, $args, $prof) { |
| 97 | 97 | return ((($fonc !== '') ? "|$fonc" : $fonc) |
| 98 | - . (!$args ? '' : ('{' . join(',', $args) . '}'))); |
|
| 98 | + . (!$args ? '' : ('{'.join(',', $args).'}'))); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Concatenation sans separateur: verifier qu'on ne cree pas de faux lexemes |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | // si un texte se termine par ( et est suivi d'un champ |
| 112 | 112 | // ou assimiles, forcer la notation pleine |
| 113 | 113 | if ($c1 == '(' and substr($texte2, 0, 1) == '#') { |
| 114 | - $args[$i + 1][0] = '[(' . $texte2 . ')]'; |
|
| 114 | + $args[$i + 1][0] = '[('.$texte2.')]'; |
|
| 115 | 115 | } |
| 116 | 116 | } else { |
| 117 | 117 | if ($type == 'texte') { |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | ($c1 == '}' and substr(ltrim($texte2), 0, 1) == '|') |
| 125 | 125 | or (preg_match('/[\w\d_*]/', $c1) and preg_match('/^[\w\d_*{|]/', $texte2)) |
| 126 | 126 | ) { |
| 127 | - $args[$i][0] = '[(' . $texte . ')]'; |
|
| 127 | + $args[$i][0] = '[('.$texte.')]'; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |