@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -28,24 +28,24 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | function action_instituer_objet_dist($arg = null) { |
| 30 | 30 | |
| 31 | - if (is_null($arg)) { |
|
| 32 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 33 | - $arg = $securiser_action(); |
|
| 34 | - } |
|
| 31 | + if (is_null($arg)) { |
|
| 32 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 33 | + $arg = $securiser_action(); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - [$objet, $id_objet, $statut] = preg_split('/\W/', (string) $arg); |
|
| 37 | - if (!$statut) { |
|
| 38 | - $statut = _request('statut_nouv'); |
|
| 39 | - } // cas POST |
|
| 40 | - if (!$statut) { |
|
| 41 | - return; |
|
| 42 | - } // impossible mais sait-on jamais |
|
| 36 | + [$objet, $id_objet, $statut] = preg_split('/\W/', (string) $arg); |
|
| 37 | + if (!$statut) { |
|
| 38 | + $statut = _request('statut_nouv'); |
|
| 39 | + } // cas POST |
|
| 40 | + if (!$statut) { |
|
| 41 | + return; |
|
| 42 | + } // impossible mais sait-on jamais |
|
| 43 | 43 | |
| 44 | - if ( |
|
| 45 | - ($id_objet = (int) $id_objet) |
|
| 46 | - && autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 47 | - ) { |
|
| 48 | - include_spip('action/editer_objet'); |
|
| 49 | - objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 50 | - } |
|
| 44 | + if ( |
|
| 45 | + ($id_objet = (int) $id_objet) |
|
| 46 | + && autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 47 | + ) { |
|
| 48 | + include_spip('action/editer_objet'); |
|
| 49 | + objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,13 +25,13 @@ discard block |
||
| 25 | 25 | * @return void |
| 26 | 26 | */ |
| 27 | 27 | function action_annuler_job_dist() { |
| 28 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | - $id_job = $securiser_action(); |
|
| 28 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | + $id_job = $securiser_action(); |
|
| 30 | 30 | |
| 31 | - if ( |
|
| 32 | - ($id_job = (int) $id_job) |
|
| 33 | - && autoriser('annuler', 'job', $id_job) |
|
| 34 | - ) { |
|
| 35 | - job_queue_remove($id_job); |
|
| 36 | - } |
|
| 31 | + if ( |
|
| 32 | + ($id_job = (int) $id_job) |
|
| 33 | + && autoriser('annuler', 'job', $id_job) |
|
| 34 | + ) { |
|
| 35 | + job_queue_remove($id_job); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -27,49 +27,49 @@ discard block |
||
| 27 | 27 | * @return void |
| 28 | 28 | */ |
| 29 | 29 | function enregistre_modif_plugin() { |
| 30 | - include_spip('inc/plugin'); |
|
| 31 | - // recuperer les plugins dans l'ordre des $_POST |
|
| 32 | - $test = []; |
|
| 33 | - foreach (liste_plugin_files() as $file) { |
|
| 34 | - $test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file; |
|
| 35 | - } |
|
| 36 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 37 | - foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) { |
|
| 38 | - $test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file; |
|
| 39 | - } |
|
| 40 | - } |
|
| 30 | + include_spip('inc/plugin'); |
|
| 31 | + // recuperer les plugins dans l'ordre des $_POST |
|
| 32 | + $test = []; |
|
| 33 | + foreach (liste_plugin_files() as $file) { |
|
| 34 | + $test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file; |
|
| 35 | + } |
|
| 36 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 37 | + foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) { |
|
| 38 | + $test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $plugin = []; |
|
| 42 | + $plugin = []; |
|
| 43 | 43 | |
| 44 | - foreach ($_POST as $choix => $val) { |
|
| 45 | - if (isset($test[$choix]) && $val == 'O') { |
|
| 46 | - $plugin[] = $test[$choix]; |
|
| 47 | - } |
|
| 48 | - } |
|
| 44 | + foreach ($_POST as $choix => $val) { |
|
| 45 | + if (isset($test[$choix]) && $val == 'O') { |
|
| 46 | + $plugin[] = $test[$choix]; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ': ' . implode( |
|
| 51 | - ',', |
|
| 52 | - $plugin |
|
| 53 | - )); |
|
| 54 | - ecrire_plugin_actifs($plugin); |
|
| 50 | + spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ': ' . implode( |
|
| 51 | + ',', |
|
| 52 | + $plugin |
|
| 53 | + )); |
|
| 54 | + ecrire_plugin_actifs($plugin); |
|
| 55 | 55 | |
| 56 | - // Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli. |
|
| 57 | - $plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']); |
|
| 58 | - if (!is_array($plugins_interessants)) { |
|
| 59 | - $plugins_interessants = []; |
|
| 60 | - } |
|
| 56 | + // Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli. |
|
| 57 | + $plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']); |
|
| 58 | + if (!is_array($plugins_interessants)) { |
|
| 59 | + $plugins_interessants = []; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $plugins_interessants2 = []; |
|
| 62 | + $plugins_interessants2 = []; |
|
| 63 | 63 | |
| 64 | - foreach ($plugins_interessants as $plug => $score) { |
|
| 65 | - if ($score > 1) { |
|
| 66 | - $plugins_interessants2[$plug] = $score - 1; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - foreach ($plugin as $plug) { |
|
| 70 | - $plugins_interessants2[$plug] = 10; |
|
| 71 | - } // score initial |
|
| 72 | - ecrire_meta('plugins_interessants', serialize($plugins_interessants2)); |
|
| 64 | + foreach ($plugins_interessants as $plug => $score) { |
|
| 65 | + if ($score > 1) { |
|
| 66 | + $plugins_interessants2[$plug] = $score - 1; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + foreach ($plugin as $plug) { |
|
| 70 | + $plugins_interessants2[$plug] = 10; |
|
| 71 | + } // score initial |
|
| 72 | + ecrire_meta('plugins_interessants', serialize($plugins_interessants2)); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | function action_activer_plugins_dist() { |
| 83 | 83 | |
| 84 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 85 | - $securiser_action(); |
|
| 84 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 85 | + $securiser_action(); |
|
| 86 | 86 | |
| 87 | - if (!autoriser('configurer', '_plugins')) { |
|
| 88 | - die('erreur'); |
|
| 89 | - } |
|
| 90 | - // forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin |
|
| 91 | - lire_metas(); |
|
| 92 | - enregistre_modif_plugin(); |
|
| 87 | + if (!autoriser('configurer', '_plugins')) { |
|
| 88 | + die('erreur'); |
|
| 89 | + } |
|
| 90 | + // forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin |
|
| 91 | + lire_metas(); |
|
| 92 | + enregistre_modif_plugin(); |
|
| 93 | 93 | } |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | // recuperer les plugins dans l'ordre des $_POST |
| 32 | 32 | $test = []; |
| 33 | 33 | foreach (liste_plugin_files() as $file) { |
| 34 | - $test['s' . substr(md5(_DIR_PLUGINS . $file), 0, 16)] = $file; |
|
| 34 | + $test['s'.substr(md5(_DIR_PLUGINS.$file), 0, 16)] = $file; |
|
| 35 | 35 | } |
| 36 | 36 | if (defined('_DIR_PLUGINS_SUPPL')) { |
| 37 | 37 | foreach (liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file) { |
| 38 | - $test['s' . substr(md5(_DIR_PLUGINS_SUPPL . $file), 0, 16)] = $file; |
|
| 38 | + $test['s'.substr(md5(_DIR_PLUGINS_SUPPL.$file), 0, 16)] = $file; |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ': ' . implode( |
|
| 50 | + spip_log("Changement des plugins actifs par l'auteur ".$GLOBALS['visiteur_session']['id_auteur'].': '.implode( |
|
| 51 | 51 | ',', |
| 52 | 52 | $plugin |
| 53 | 53 | )); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | if ($change_session == 'oui') { |
| 59 | 59 | $session = charger_fonction('session', 'inc'); |
| 60 | 60 | $session(true); |
| 61 | - spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 61 | + spip_log('statut 204 pour '.$_SERVER['REQUEST_URI']); |
|
| 62 | 62 | http_response_code(204); // No Content |
| 63 | 63 | return; |
| 64 | 64 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | _T('info_connexion_refusee'), |
| 79 | 79 | _T('login_login_pass_incorrect'), |
| 80 | 80 | _T('login_retour_site'), |
| 81 | - 'url=' . rawurlencode((string) $redirect), |
|
| 81 | + 'url='.rawurlencode((string) $redirect), |
|
| 82 | 82 | _T('login_nouvelle_tentative'), |
| 83 | 83 | (str_contains((string) $url, (string) _DIR_RESTREINT_ABS)) |
| 84 | 84 | ); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/actions'); |
@@ -32,94 +32,94 @@ discard block |
||
| 32 | 32 | * @return void |
| 33 | 33 | */ |
| 34 | 34 | function action_cookie_dist($set_cookie_admin = null, $change_session = null) { |
| 35 | - $redirect_echec = $redirect = null; |
|
| 36 | - $test_echec_cookie = null; |
|
| 37 | - $url = ''; |
|
| 38 | - if (is_null($set_cookie_admin)) { |
|
| 39 | - $set_cookie_admin = _request('cookie_admin'); |
|
| 40 | - $change_session = _request('change_session'); |
|
| 41 | - $test_echec_cookie = _request('test_echec_cookie'); |
|
| 35 | + $redirect_echec = $redirect = null; |
|
| 36 | + $test_echec_cookie = null; |
|
| 37 | + $url = ''; |
|
| 38 | + if (is_null($set_cookie_admin)) { |
|
| 39 | + $set_cookie_admin = _request('cookie_admin'); |
|
| 40 | + $change_session = _request('change_session'); |
|
| 41 | + $test_echec_cookie = _request('test_echec_cookie'); |
|
| 42 | 42 | |
| 43 | - // La cible de notre operation de connexion |
|
| 44 | - $url = securiser_redirect_action(_request('url')); |
|
| 45 | - $redirect = $url ?: generer_url_ecrire('accueil'); |
|
| 46 | - $redirect_echec = _request('url_echec'); |
|
| 47 | - if (!isset($redirect_echec)) { |
|
| 48 | - if (str_contains((string) $redirect, (string) _DIR_RESTREINT_ABS)) { |
|
| 49 | - $redirect_echec = generer_url_public('login', '', true); |
|
| 50 | - } else { |
|
| 51 | - $redirect_echec = $redirect; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 43 | + // La cible de notre operation de connexion |
|
| 44 | + $url = securiser_redirect_action(_request('url')); |
|
| 45 | + $redirect = $url ?: generer_url_ecrire('accueil'); |
|
| 46 | + $redirect_echec = _request('url_echec'); |
|
| 47 | + if (!isset($redirect_echec)) { |
|
| 48 | + if (str_contains((string) $redirect, (string) _DIR_RESTREINT_ABS)) { |
|
| 49 | + $redirect_echec = generer_url_public('login', '', true); |
|
| 50 | + } else { |
|
| 51 | + $redirect_echec = $redirect; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - // rejoue le cookie pour renouveler spip_session |
|
| 58 | - if ($change_session == 'oui') { |
|
| 59 | - $session = charger_fonction('session', 'inc'); |
|
| 60 | - $session(true); |
|
| 61 | - spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 62 | - http_response_code(204); // No Content |
|
| 63 | - return; |
|
| 64 | - } |
|
| 57 | + // rejoue le cookie pour renouveler spip_session |
|
| 58 | + if ($change_session == 'oui') { |
|
| 59 | + $session = charger_fonction('session', 'inc'); |
|
| 60 | + $session(true); |
|
| 61 | + spip_log('statut 204 pour ' . $_SERVER['REQUEST_URI']); |
|
| 62 | + http_response_code(204); // No Content |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - // tentative de connexion en auth_http |
|
| 67 | - if (_request('essai_auth_http') && !$GLOBALS['ignore_auth_http']) { |
|
| 68 | - include_spip('inc/auth'); |
|
| 69 | - if ( |
|
| 70 | - @$_SERVER['PHP_AUTH_USER'] |
|
| 71 | - && @$_SERVER['PHP_AUTH_PW'] |
|
| 72 | - && ($auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 73 | - ) { |
|
| 74 | - auth_loger($auteur); |
|
| 75 | - redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 76 | - } else { |
|
| 77 | - ask_php_auth( |
|
| 78 | - _T('info_connexion_refusee'), |
|
| 79 | - _T('login_login_pass_incorrect'), |
|
| 80 | - _T('login_retour_site'), |
|
| 81 | - 'url=' . rawurlencode((string) $redirect), |
|
| 82 | - _T('login_nouvelle_tentative'), |
|
| 83 | - (str_contains((string) $url, (string) _DIR_RESTREINT_ABS)) |
|
| 84 | - ); |
|
| 85 | - } |
|
| 86 | - } else { |
|
| 87 | - // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 88 | - // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 89 | - // le cas echeant. |
|
| 90 | - if ($test_echec_cookie == 'oui') { |
|
| 91 | - spip_setcookie('spip_session', 'test_echec_cookie', httponly: true); |
|
| 92 | - if ($redirect) { |
|
| 93 | - $redirect = parametre_url( |
|
| 94 | - parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 95 | - 'url', |
|
| 96 | - rawurlencode((string) $redirect), |
|
| 97 | - '&' |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - } else { |
|
| 101 | - $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 102 | - // Suppression cookie d'admin ? |
|
| 103 | - if ($set_cookie_admin == 'non') { |
|
| 104 | - if ($cook) { |
|
| 105 | - spip_setcookie('spip_admin', $cook, time() - 3600 * 24, httponly: true); |
|
| 106 | - } |
|
| 107 | - } // Ajout de cookie d'admin |
|
| 108 | - else { |
|
| 109 | - if ($set_cookie_admin && _DUREE_COOKIE_ADMIN) { |
|
| 110 | - spip_setcookie( |
|
| 111 | - 'spip_admin', |
|
| 112 | - $set_cookie_admin, |
|
| 113 | - time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA), |
|
| 114 | - httponly: true |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 66 | + // tentative de connexion en auth_http |
|
| 67 | + if (_request('essai_auth_http') && !$GLOBALS['ignore_auth_http']) { |
|
| 68 | + include_spip('inc/auth'); |
|
| 69 | + if ( |
|
| 70 | + @$_SERVER['PHP_AUTH_USER'] |
|
| 71 | + && @$_SERVER['PHP_AUTH_PW'] |
|
| 72 | + && ($auteur = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 73 | + ) { |
|
| 74 | + auth_loger($auteur); |
|
| 75 | + redirige_par_entete(parametre_url($redirect, 't', time(), '&')); |
|
| 76 | + } else { |
|
| 77 | + ask_php_auth( |
|
| 78 | + _T('info_connexion_refusee'), |
|
| 79 | + _T('login_login_pass_incorrect'), |
|
| 80 | + _T('login_retour_site'), |
|
| 81 | + 'url=' . rawurlencode((string) $redirect), |
|
| 82 | + _T('login_nouvelle_tentative'), |
|
| 83 | + (str_contains((string) $url, (string) _DIR_RESTREINT_ABS)) |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | + } else { |
|
| 87 | + // en cas de login sur bonjour=oui, on tente de poser un cookie |
|
| 88 | + // puis de passer au login qui diagnostiquera l'echec de cookie |
|
| 89 | + // le cas echeant. |
|
| 90 | + if ($test_echec_cookie == 'oui') { |
|
| 91 | + spip_setcookie('spip_session', 'test_echec_cookie', httponly: true); |
|
| 92 | + if ($redirect) { |
|
| 93 | + $redirect = parametre_url( |
|
| 94 | + parametre_url($redirect_echec, 'var_echec_cookie', 'oui', '&'), |
|
| 95 | + 'url', |
|
| 96 | + rawurlencode((string) $redirect), |
|
| 97 | + '&' |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + } else { |
|
| 101 | + $cook = $_COOKIE['spip_admin'] ?? ''; |
|
| 102 | + // Suppression cookie d'admin ? |
|
| 103 | + if ($set_cookie_admin == 'non') { |
|
| 104 | + if ($cook) { |
|
| 105 | + spip_setcookie('spip_admin', $cook, time() - 3600 * 24, httponly: true); |
|
| 106 | + } |
|
| 107 | + } // Ajout de cookie d'admin |
|
| 108 | + else { |
|
| 109 | + if ($set_cookie_admin && _DUREE_COOKIE_ADMIN) { |
|
| 110 | + spip_setcookie( |
|
| 111 | + 'spip_admin', |
|
| 112 | + $set_cookie_admin, |
|
| 113 | + time() + max(_DUREE_COOKIE_ADMIN, 2 * _RENOUVELLE_ALEA), |
|
| 114 | + httponly: true |
|
| 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 | } |
@@ -9,195 +9,195 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Traducteur |
| 11 | 11 | { |
| 12 | - /** Pour les corrections à effectuer sur les requêtes : array(code=>'texte') trouvé |
|
| 13 | - * |
|
| 14 | - * @var array |
|
| 15 | - */ |
|
| 16 | - public $textes = []; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Constructeur |
|
| 20 | - */ |
|
| 21 | - public function __construct( |
|
| 22 | - /** Requête à préparer */ |
|
| 23 | - public string $query, |
|
| 24 | - /** Prefixe des tables à utiliser */ |
|
| 25 | - public string $prefixe, |
|
| 26 | - /** Version SQLite (2 ou 3) */ |
|
| 27 | - public string $sqlite_version |
|
| 28 | - ) { |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Transformer la requete pour SQLite |
|
| 33 | - * |
|
| 34 | - * Enlève les textes, transforme la requête pour quelle soit |
|
| 35 | - * bien interprétée par SQLite, puis remet les textes |
|
| 36 | - * la fonction affecte `$this->query` |
|
| 37 | - */ |
|
| 38 | - public function traduire_requete() { |
|
| 39 | - // |
|
| 40 | - // 1) Protection des textes en les remplacant par des codes |
|
| 41 | - // |
|
| 42 | - // enlever les 'textes' et initialiser avec |
|
| 43 | - [$this->query, $textes] = query_echappe_textes($this->query); |
|
| 44 | - |
|
| 45 | - // |
|
| 46 | - // 2) Corrections de la requete |
|
| 47 | - // |
|
| 48 | - // Correction Create Database |
|
| 49 | - // Create Database -> requete ignoree |
|
| 50 | - if (str_starts_with((string) $this->query, 'CREATE DATABASE')) { |
|
| 51 | - spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.' . _LOG_AVERTISSEMENT); |
|
| 52 | - $this->query = 'SELECT 1'; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Correction Insert Ignore |
|
| 56 | - // INSERT IGNORE -> insert (tout court et pas 'insert or replace') |
|
| 57 | - if (str_starts_with((string) $this->query, 'INSERT IGNORE')) { |
|
| 58 | - spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.' . _LOG_DEBUG); |
|
| 59 | - $this->query = 'INSERT ' . substr((string) $this->query, '13'); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Correction des dates avec INTERVAL |
|
| 63 | - // utiliser sql_date_proche() de preference |
|
| 64 | - if (str_contains((string) $this->query, 'INTERVAL')) { |
|
| 65 | - $this->query = preg_replace_callback( |
|
| 66 | - '/DATE_(ADD|SUB)(.*)INTERVAL\s+(\d+)\s+([a-zA-Z]+)\)/U', |
|
| 67 | - fn(array $matches): string => $this->_remplacerDateParTime($matches), |
|
| 68 | - (string) $this->query |
|
| 69 | - ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - if (str_contains((string) $this->query, 'LEFT(')) { |
|
| 73 | - $this->query = str_replace('LEFT(', '_LEFT(', (string) $this->query); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (str_contains((string) $this->query, 'TIMESTAMPDIFF(')) { |
|
| 77 | - $this->query = preg_replace('/TIMESTAMPDIFF\(\s*([^,]*)\s*,/Uims', "TIMESTAMPDIFF('\\1',", (string) $this->query); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - // Correction Using |
|
| 82 | - // USING (non reconnu en sqlite2) |
|
| 83 | - // problematique car la jointure ne se fait pas du coup. |
|
| 84 | - if (($this->sqlite_version == 2) && (str_contains((string) $this->query, 'USING'))) { |
|
| 85 | - spip_log( |
|
| 86 | - "'USING (champ)' n'est pas reconnu en SQLite 2. Utilisez 'ON table1.champ = table2.champ'", |
|
| 87 | - 'sqlite.' . _LOG_ERREUR |
|
| 88 | - ); |
|
| 89 | - $this->query = preg_replace('/USING\s*\([^\)]*\)/', '', (string) $this->query); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Correction Field |
|
| 93 | - // remplace FIELD(table,i,j,k...) par CASE WHEN table=i THEN n ... ELSE 0 END |
|
| 94 | - if (str_contains((string) $this->query, 'FIELD')) { |
|
| 95 | - $this->query = preg_replace_callback( |
|
| 96 | - '/FIELD\s*\(([^\)]*)\)/', |
|
| 97 | - fn(array $matches): string => $this->_remplacerFieldParCase($matches), |
|
| 98 | - (string) $this->query |
|
| 99 | - ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // Correction des noms de tables FROM |
|
| 103 | - // mettre les bons noms de table dans from, update, insert, replace... |
|
| 104 | - if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/iS', (string) $this->query, $regs)) { |
|
| 105 | - $suite = strstr((string) $this->query, $regs[0]); |
|
| 106 | - $this->query = substr((string) $this->query, 0, -strlen($suite)); |
|
| 107 | - } else { |
|
| 108 | - $suite = ''; |
|
| 109 | - } |
|
| 110 | - $pref = ($this->prefixe) ? $this->prefixe . '_' : ''; |
|
| 111 | - $this->query = preg_replace('/([,\s])spip_/S', '\1' . $pref, (string) $this->query) . $suite; |
|
| 112 | - |
|
| 113 | - // Correction zero AS x |
|
| 114 | - // pg n'aime pas 0+x AS alias, sqlite, dans le meme style, |
|
| 115 | - // n'apprecie pas du tout SELECT 0 as x ... ORDER BY x |
|
| 116 | - // il dit que x ne doit pas être un integer dans le order by ! |
|
| 117 | - // on remplace du coup x par vide() dans ce cas uniquement |
|
| 118 | - // |
|
| 119 | - // apparait dans public/vertebrer.php et dans le plugin menu aussi qui genere aussi ce genre de requete via un {par num #GET{tri_num}} |
|
| 120 | - // mais est-ce encore un soucis pour sqlite en 2021 ? (ie commenter le preg_replace marche très bien en sqlite 3.28) |
|
| 121 | - // on ne remplace que dans ORDER BY ou GROUP BY |
|
| 122 | - if (str_contains($this->query, '0 AS') && preg_match('/\s(ORDER|GROUP) BY\s/i', $this->query, $regs)) { |
|
| 123 | - $suite = strstr($this->query, $regs[0]); |
|
| 124 | - $this->query = substr($this->query, 0, -strlen($suite)); |
|
| 125 | - // on cherche les noms des x dans 0 AS x |
|
| 126 | - // on remplace dans $suite le nom par vide() |
|
| 127 | - preg_match_all('/\b0 AS\s*([^\s,]+)/', $this->query, $matches, PREG_PATTERN_ORDER); |
|
| 128 | - foreach ($matches[1] as $m) { |
|
| 129 | - if (str_contains($suite, $m)) { |
|
| 130 | - $suite = preg_replace(",\b$m\b,", 'VIDE()', $suite); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - $this->query .= $suite; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // Correction possible des divisions entieres |
|
| 137 | - // Le standard SQL (lequel? ou?) semble indiquer que |
|
| 138 | - // a/b=c doit donner c entier si a et b sont entiers 4/3=1. |
|
| 139 | - // C'est ce que retournent effectivement SQL Server et SQLite |
|
| 140 | - // Ce n'est pas ce qu'applique MySQL qui retourne un reel : 4/3=1.333... |
|
| 141 | - // |
|
| 142 | - // On peut forcer la conversion en multipliant par 1.0 avant la division |
|
| 143 | - // /!\ SQLite 3.5.9 Debian/Ubuntu est victime d'un bug en plus ! |
|
| 144 | - // cf. https://bugs.launchpad.net/ubuntu/+source/sqlite3/+bug/254228 |
|
| 145 | - // http://www.sqlite.org/cvstrac/tktview?tn=3202 |
|
| 146 | - // (4*1.0/3) n'est pas rendu dans ce cas ! |
|
| 147 | - # $this->query = str_replace('/','* 1.00 / ',$this->query); |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - // Correction critere REGEXP, non reconnu en sqlite2 |
|
| 151 | - if (($this->sqlite_version == 2) && (str_contains($this->query, 'REGEXP'))) { |
|
| 152 | - $this->query = preg_replace('/([^\s\(]*)(\s*)REGEXP(\s*)([^\s\)]*)/', 'REGEXP($4, $1)', $this->query); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // |
|
| 156 | - // 3) Remise en place des textes d'origine |
|
| 157 | - // |
|
| 158 | - // Correction Antiquotes et echappements |
|
| 159 | - // ` => rien |
|
| 160 | - if (str_contains($this->query, '`')) { |
|
| 161 | - $this->query = str_replace('`', '', $this->query); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $this->query = query_reinjecte_textes($this->query, $textes); |
|
| 165 | - |
|
| 166 | - return $this->query; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Callback pour remplacer `DATE_` / `INTERVAL` |
|
| 171 | - * par `DATE ... strtotime` |
|
| 172 | - * |
|
| 173 | - * @param array $matches Captures |
|
| 174 | - * @return string texte de date compris par SQLite |
|
| 175 | - */ |
|
| 176 | - public function _remplacerDateParTime($matches) { |
|
| 177 | - $op = strtoupper($matches[1] == 'ADD') ? '+' : '-'; |
|
| 178 | - |
|
| 179 | - return "datetime$matches[2] '$op$matches[3] $matches[4]')"; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Callback pour remplacer `FIELD(table,i,j,k...)` |
|
| 184 | - * par `CASE WHEN table=i THEN n ... ELSE 0 END` |
|
| 185 | - * |
|
| 186 | - * @param array $matches Captures |
|
| 187 | - * @return string texte de liste ordonnée compris par SQLite |
|
| 188 | - */ |
|
| 189 | - public function _remplacerFieldParCase($matches) { |
|
| 190 | - $fields = substr((string) $matches[0], 6, -1); // ne recuperer que l'interieur X de field(X) |
|
| 191 | - $t = explode(',', $fields); |
|
| 192 | - $index = array_shift($t); |
|
| 193 | - |
|
| 194 | - $res = ''; |
|
| 195 | - $n = 0; |
|
| 196 | - foreach ($t as $v) { |
|
| 197 | - $n++; |
|
| 198 | - $res .= "\nWHEN $index=$v THEN $n"; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return "CASE $res ELSE 0 END "; |
|
| 202 | - } |
|
| 12 | + /** Pour les corrections à effectuer sur les requêtes : array(code=>'texte') trouvé |
|
| 13 | + * |
|
| 14 | + * @var array |
|
| 15 | + */ |
|
| 16 | + public $textes = []; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Constructeur |
|
| 20 | + */ |
|
| 21 | + public function __construct( |
|
| 22 | + /** Requête à préparer */ |
|
| 23 | + public string $query, |
|
| 24 | + /** Prefixe des tables à utiliser */ |
|
| 25 | + public string $prefixe, |
|
| 26 | + /** Version SQLite (2 ou 3) */ |
|
| 27 | + public string $sqlite_version |
|
| 28 | + ) { |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Transformer la requete pour SQLite |
|
| 33 | + * |
|
| 34 | + * Enlève les textes, transforme la requête pour quelle soit |
|
| 35 | + * bien interprétée par SQLite, puis remet les textes |
|
| 36 | + * la fonction affecte `$this->query` |
|
| 37 | + */ |
|
| 38 | + public function traduire_requete() { |
|
| 39 | + // |
|
| 40 | + // 1) Protection des textes en les remplacant par des codes |
|
| 41 | + // |
|
| 42 | + // enlever les 'textes' et initialiser avec |
|
| 43 | + [$this->query, $textes] = query_echappe_textes($this->query); |
|
| 44 | + |
|
| 45 | + // |
|
| 46 | + // 2) Corrections de la requete |
|
| 47 | + // |
|
| 48 | + // Correction Create Database |
|
| 49 | + // Create Database -> requete ignoree |
|
| 50 | + if (str_starts_with((string) $this->query, 'CREATE DATABASE')) { |
|
| 51 | + spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.' . _LOG_AVERTISSEMENT); |
|
| 52 | + $this->query = 'SELECT 1'; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Correction Insert Ignore |
|
| 56 | + // INSERT IGNORE -> insert (tout court et pas 'insert or replace') |
|
| 57 | + if (str_starts_with((string) $this->query, 'INSERT IGNORE')) { |
|
| 58 | + spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.' . _LOG_DEBUG); |
|
| 59 | + $this->query = 'INSERT ' . substr((string) $this->query, '13'); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Correction des dates avec INTERVAL |
|
| 63 | + // utiliser sql_date_proche() de preference |
|
| 64 | + if (str_contains((string) $this->query, 'INTERVAL')) { |
|
| 65 | + $this->query = preg_replace_callback( |
|
| 66 | + '/DATE_(ADD|SUB)(.*)INTERVAL\s+(\d+)\s+([a-zA-Z]+)\)/U', |
|
| 67 | + fn(array $matches): string => $this->_remplacerDateParTime($matches), |
|
| 68 | + (string) $this->query |
|
| 69 | + ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + if (str_contains((string) $this->query, 'LEFT(')) { |
|
| 73 | + $this->query = str_replace('LEFT(', '_LEFT(', (string) $this->query); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (str_contains((string) $this->query, 'TIMESTAMPDIFF(')) { |
|
| 77 | + $this->query = preg_replace('/TIMESTAMPDIFF\(\s*([^,]*)\s*,/Uims', "TIMESTAMPDIFF('\\1',", (string) $this->query); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + // Correction Using |
|
| 82 | + // USING (non reconnu en sqlite2) |
|
| 83 | + // problematique car la jointure ne se fait pas du coup. |
|
| 84 | + if (($this->sqlite_version == 2) && (str_contains((string) $this->query, 'USING'))) { |
|
| 85 | + spip_log( |
|
| 86 | + "'USING (champ)' n'est pas reconnu en SQLite 2. Utilisez 'ON table1.champ = table2.champ'", |
|
| 87 | + 'sqlite.' . _LOG_ERREUR |
|
| 88 | + ); |
|
| 89 | + $this->query = preg_replace('/USING\s*\([^\)]*\)/', '', (string) $this->query); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Correction Field |
|
| 93 | + // remplace FIELD(table,i,j,k...) par CASE WHEN table=i THEN n ... ELSE 0 END |
|
| 94 | + if (str_contains((string) $this->query, 'FIELD')) { |
|
| 95 | + $this->query = preg_replace_callback( |
|
| 96 | + '/FIELD\s*\(([^\)]*)\)/', |
|
| 97 | + fn(array $matches): string => $this->_remplacerFieldParCase($matches), |
|
| 98 | + (string) $this->query |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // Correction des noms de tables FROM |
|
| 103 | + // mettre les bons noms de table dans from, update, insert, replace... |
|
| 104 | + if (preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/iS', (string) $this->query, $regs)) { |
|
| 105 | + $suite = strstr((string) $this->query, $regs[0]); |
|
| 106 | + $this->query = substr((string) $this->query, 0, -strlen($suite)); |
|
| 107 | + } else { |
|
| 108 | + $suite = ''; |
|
| 109 | + } |
|
| 110 | + $pref = ($this->prefixe) ? $this->prefixe . '_' : ''; |
|
| 111 | + $this->query = preg_replace('/([,\s])spip_/S', '\1' . $pref, (string) $this->query) . $suite; |
|
| 112 | + |
|
| 113 | + // Correction zero AS x |
|
| 114 | + // pg n'aime pas 0+x AS alias, sqlite, dans le meme style, |
|
| 115 | + // n'apprecie pas du tout SELECT 0 as x ... ORDER BY x |
|
| 116 | + // il dit que x ne doit pas être un integer dans le order by ! |
|
| 117 | + // on remplace du coup x par vide() dans ce cas uniquement |
|
| 118 | + // |
|
| 119 | + // apparait dans public/vertebrer.php et dans le plugin menu aussi qui genere aussi ce genre de requete via un {par num #GET{tri_num}} |
|
| 120 | + // mais est-ce encore un soucis pour sqlite en 2021 ? (ie commenter le preg_replace marche très bien en sqlite 3.28) |
|
| 121 | + // on ne remplace que dans ORDER BY ou GROUP BY |
|
| 122 | + if (str_contains($this->query, '0 AS') && preg_match('/\s(ORDER|GROUP) BY\s/i', $this->query, $regs)) { |
|
| 123 | + $suite = strstr($this->query, $regs[0]); |
|
| 124 | + $this->query = substr($this->query, 0, -strlen($suite)); |
|
| 125 | + // on cherche les noms des x dans 0 AS x |
|
| 126 | + // on remplace dans $suite le nom par vide() |
|
| 127 | + preg_match_all('/\b0 AS\s*([^\s,]+)/', $this->query, $matches, PREG_PATTERN_ORDER); |
|
| 128 | + foreach ($matches[1] as $m) { |
|
| 129 | + if (str_contains($suite, $m)) { |
|
| 130 | + $suite = preg_replace(",\b$m\b,", 'VIDE()', $suite); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + $this->query .= $suite; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // Correction possible des divisions entieres |
|
| 137 | + // Le standard SQL (lequel? ou?) semble indiquer que |
|
| 138 | + // a/b=c doit donner c entier si a et b sont entiers 4/3=1. |
|
| 139 | + // C'est ce que retournent effectivement SQL Server et SQLite |
|
| 140 | + // Ce n'est pas ce qu'applique MySQL qui retourne un reel : 4/3=1.333... |
|
| 141 | + // |
|
| 142 | + // On peut forcer la conversion en multipliant par 1.0 avant la division |
|
| 143 | + // /!\ SQLite 3.5.9 Debian/Ubuntu est victime d'un bug en plus ! |
|
| 144 | + // cf. https://bugs.launchpad.net/ubuntu/+source/sqlite3/+bug/254228 |
|
| 145 | + // http://www.sqlite.org/cvstrac/tktview?tn=3202 |
|
| 146 | + // (4*1.0/3) n'est pas rendu dans ce cas ! |
|
| 147 | + # $this->query = str_replace('/','* 1.00 / ',$this->query); |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + // Correction critere REGEXP, non reconnu en sqlite2 |
|
| 151 | + if (($this->sqlite_version == 2) && (str_contains($this->query, 'REGEXP'))) { |
|
| 152 | + $this->query = preg_replace('/([^\s\(]*)(\s*)REGEXP(\s*)([^\s\)]*)/', 'REGEXP($4, $1)', $this->query); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // |
|
| 156 | + // 3) Remise en place des textes d'origine |
|
| 157 | + // |
|
| 158 | + // Correction Antiquotes et echappements |
|
| 159 | + // ` => rien |
|
| 160 | + if (str_contains($this->query, '`')) { |
|
| 161 | + $this->query = str_replace('`', '', $this->query); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $this->query = query_reinjecte_textes($this->query, $textes); |
|
| 165 | + |
|
| 166 | + return $this->query; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Callback pour remplacer `DATE_` / `INTERVAL` |
|
| 171 | + * par `DATE ... strtotime` |
|
| 172 | + * |
|
| 173 | + * @param array $matches Captures |
|
| 174 | + * @return string texte de date compris par SQLite |
|
| 175 | + */ |
|
| 176 | + public function _remplacerDateParTime($matches) { |
|
| 177 | + $op = strtoupper($matches[1] == 'ADD') ? '+' : '-'; |
|
| 178 | + |
|
| 179 | + return "datetime$matches[2] '$op$matches[3] $matches[4]')"; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Callback pour remplacer `FIELD(table,i,j,k...)` |
|
| 184 | + * par `CASE WHEN table=i THEN n ... ELSE 0 END` |
|
| 185 | + * |
|
| 186 | + * @param array $matches Captures |
|
| 187 | + * @return string texte de liste ordonnée compris par SQLite |
|
| 188 | + */ |
|
| 189 | + public function _remplacerFieldParCase($matches) { |
|
| 190 | + $fields = substr((string) $matches[0], 6, -1); // ne recuperer que l'interieur X de field(X) |
|
| 191 | + $t = explode(',', $fields); |
|
| 192 | + $index = array_shift($t); |
|
| 193 | + |
|
| 194 | + $res = ''; |
|
| 195 | + $n = 0; |
|
| 196 | + foreach ($t as $v) { |
|
| 197 | + $n++; |
|
| 198 | + $res .= "\nWHEN $index=$v THEN $n"; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return "CASE $res ELSE 0 END "; |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -48,15 +48,15 @@ discard block |
||
| 48 | 48 | // Correction Create Database |
| 49 | 49 | // Create Database -> requete ignoree |
| 50 | 50 | if (str_starts_with((string) $this->query, 'CREATE DATABASE')) { |
| 51 | - spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.' . _LOG_AVERTISSEMENT); |
|
| 51 | + spip_log("Sqlite : requete non executee -> $this->query", 'sqlite.'._LOG_AVERTISSEMENT); |
|
| 52 | 52 | $this->query = 'SELECT 1'; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Correction Insert Ignore |
| 56 | 56 | // INSERT IGNORE -> insert (tout court et pas 'insert or replace') |
| 57 | 57 | if (str_starts_with((string) $this->query, 'INSERT IGNORE')) { |
| 58 | - spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.' . _LOG_DEBUG); |
|
| 59 | - $this->query = 'INSERT ' . substr((string) $this->query, '13'); |
|
| 58 | + spip_log("Sqlite : requete transformee -> $this->query", 'sqlite.'._LOG_DEBUG); |
|
| 59 | + $this->query = 'INSERT '.substr((string) $this->query, '13'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | // Correction des dates avec INTERVAL |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | if (($this->sqlite_version == 2) && (str_contains((string) $this->query, 'USING'))) { |
| 85 | 85 | spip_log( |
| 86 | 86 | "'USING (champ)' n'est pas reconnu en SQLite 2. Utilisez 'ON table1.champ = table2.champ'", |
| 87 | - 'sqlite.' . _LOG_ERREUR |
|
| 87 | + 'sqlite.'._LOG_ERREUR |
|
| 88 | 88 | ); |
| 89 | 89 | $this->query = preg_replace('/USING\s*\([^\)]*\)/', '', (string) $this->query); |
| 90 | 90 | } |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | } else { |
| 108 | 108 | $suite = ''; |
| 109 | 109 | } |
| 110 | - $pref = ($this->prefixe) ? $this->prefixe . '_' : ''; |
|
| 111 | - $this->query = preg_replace('/([,\s])spip_/S', '\1' . $pref, (string) $this->query) . $suite; |
|
| 110 | + $pref = ($this->prefixe) ? $this->prefixe.'_' : ''; |
|
| 111 | + $this->query = preg_replace('/([,\s])spip_/S', '\1'.$pref, (string) $this->query).$suite; |
|
| 112 | 112 | |
| 113 | 113 | // Correction zero AS x |
| 114 | 114 | // pg n'aime pas 0+x AS alias, sqlite, dans le meme style, |
@@ -15,98 +15,98 @@ |
||
| 15 | 15 | * Collecte les raccourcis liens [titre->url] de SPIP |
| 16 | 16 | */ |
| 17 | 17 | class Liens extends AbstractCollecteur { |
| 18 | - protected static string $markPrefix = 'LIEN'; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * La preg pour découper et collecter les modèles |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected string $preg_lien; |
|
| 25 | - |
|
| 26 | - public function __construct(?string $preg = null) { |
|
| 27 | - |
|
| 28 | - // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
|
| 29 | - // Laisser passer des paires de crochets pour la balise multi |
|
| 30 | - // mais refuser plus d'imbrications ou de mauvaises imbrications |
|
| 31 | - // sinon les crochets ne peuvent plus servir qu'a ce type de raccourci |
|
| 32 | - $this->preg_lien = ($preg ?: '/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS'); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Sanitizer une collection d'occurences de liens : il faut sanitizer le href et le texte uniquement |
|
| 38 | - * |
|
| 39 | - * @param array $collection |
|
| 40 | - * @param string $sanitize_callback |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 44 | - foreach ($collection as &$lien) { |
|
| 45 | - $t = $sanitize_callback($lien['texte']); |
|
| 46 | - if ($t !== $lien['texte']) { |
|
| 47 | - $lien['raw'] = str_replace($lien['texte'], $t, (string) $lien['raw']); |
|
| 48 | - $lien['texte'] = $t; |
|
| 49 | - } |
|
| 50 | - $href = $sanitize_callback($lien['href']); |
|
| 51 | - if ($href !== $lien['href']) { |
|
| 52 | - $lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']); |
|
| 53 | - $lien['href'] = $href; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - return $collection; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param string $texte |
|
| 62 | - * @param array $options |
|
| 63 | - * bool $collecter_liens |
|
| 64 | - * @return array |
|
| 65 | - */ |
|
| 66 | - public function collecter(string $texte, array $options = []): array { |
|
| 67 | - if (!$texte) { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $liens = []; |
|
| 72 | - if (str_contains($texte, '->')) { |
|
| 73 | - $desechappe_crochets = false; |
|
| 74 | - // si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer |
|
| 75 | - if (str_contains($texte, '\[') || str_contains($texte, '\]')) { |
|
| 76 | - $texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte); |
|
| 77 | - $desechappe_crochets = true; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // collecter les matchs de la preg |
|
| 81 | - $liens = static::collecteur($texte, '->', '[', $this->preg_lien, empty($options['detecter_presence']) ? 0 : 1); |
|
| 82 | - |
|
| 83 | - // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 84 | - if (empty($options['detecter_presence'])) { |
|
| 85 | - foreach ($liens as $k => &$lien) { |
|
| 86 | - $lien['href'] = end($lien['match']); |
|
| 87 | - $lien['texte'] = $lien['match'][1]; |
|
| 88 | - $lien['ouvrant'] = $lien['match'][3] ?? ''; |
|
| 89 | - |
|
| 90 | - // la mise en lien automatique est passee par la a tort ! |
|
| 91 | - // corrigeons pour eviter d'avoir un <a...> dans un href... |
|
| 92 | - if (str_starts_with((string) $lien['href'], '<a')) { |
|
| 93 | - $href = extraire_attribut($lien['href'], 'href'); |
|
| 94 | - // remplacons dans la source qui peut etre reinjectee dans les arguments |
|
| 95 | - // d'un modele |
|
| 96 | - $lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']); |
|
| 97 | - // et prenons le href comme la vraie url a linker |
|
| 98 | - $lien['href'] = $href; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ($desechappe_crochets && str_contains((string) $lien['raw'], "\x1")) { |
|
| 102 | - $lien['raw'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['raw']); |
|
| 103 | - $lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['texte']); |
|
| 104 | - $lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['href']); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $liens; |
|
| 111 | - } |
|
| 18 | + protected static string $markPrefix = 'LIEN'; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * La preg pour découper et collecter les modèles |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected string $preg_lien; |
|
| 25 | + |
|
| 26 | + public function __construct(?string $preg = null) { |
|
| 27 | + |
|
| 28 | + // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
|
| 29 | + // Laisser passer des paires de crochets pour la balise multi |
|
| 30 | + // mais refuser plus d'imbrications ou de mauvaises imbrications |
|
| 31 | + // sinon les crochets ne peuvent plus servir qu'a ce type de raccourci |
|
| 32 | + $this->preg_lien = ($preg ?: '/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS'); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Sanitizer une collection d'occurences de liens : il faut sanitizer le href et le texte uniquement |
|
| 38 | + * |
|
| 39 | + * @param array $collection |
|
| 40 | + * @param string $sanitize_callback |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + protected function sanitizer_collection(array $collection, string $sanitize_callback): array { |
|
| 44 | + foreach ($collection as &$lien) { |
|
| 45 | + $t = $sanitize_callback($lien['texte']); |
|
| 46 | + if ($t !== $lien['texte']) { |
|
| 47 | + $lien['raw'] = str_replace($lien['texte'], $t, (string) $lien['raw']); |
|
| 48 | + $lien['texte'] = $t; |
|
| 49 | + } |
|
| 50 | + $href = $sanitize_callback($lien['href']); |
|
| 51 | + if ($href !== $lien['href']) { |
|
| 52 | + $lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']); |
|
| 53 | + $lien['href'] = $href; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + return $collection; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param string $texte |
|
| 62 | + * @param array $options |
|
| 63 | + * bool $collecter_liens |
|
| 64 | + * @return array |
|
| 65 | + */ |
|
| 66 | + public function collecter(string $texte, array $options = []): array { |
|
| 67 | + if (!$texte) { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $liens = []; |
|
| 72 | + if (str_contains($texte, '->')) { |
|
| 73 | + $desechappe_crochets = false; |
|
| 74 | + // si il y a un crochet ouvrant échappé ou un crochet fermant échappé, les substituer pour les ignorer |
|
| 75 | + if (str_contains($texte, '\[') || str_contains($texte, '\]')) { |
|
| 76 | + $texte = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $texte); |
|
| 77 | + $desechappe_crochets = true; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // collecter les matchs de la preg |
|
| 81 | + $liens = static::collecteur($texte, '->', '[', $this->preg_lien, empty($options['detecter_presence']) ? 0 : 1); |
|
| 82 | + |
|
| 83 | + // si on veut seulement detecter la présence, on peut retourner tel quel |
|
| 84 | + if (empty($options['detecter_presence'])) { |
|
| 85 | + foreach ($liens as $k => &$lien) { |
|
| 86 | + $lien['href'] = end($lien['match']); |
|
| 87 | + $lien['texte'] = $lien['match'][1]; |
|
| 88 | + $lien['ouvrant'] = $lien['match'][3] ?? ''; |
|
| 89 | + |
|
| 90 | + // la mise en lien automatique est passee par la a tort ! |
|
| 91 | + // corrigeons pour eviter d'avoir un <a...> dans un href... |
|
| 92 | + if (str_starts_with((string) $lien['href'], '<a')) { |
|
| 93 | + $href = extraire_attribut($lien['href'], 'href'); |
|
| 94 | + // remplacons dans la source qui peut etre reinjectee dans les arguments |
|
| 95 | + // d'un modele |
|
| 96 | + $lien['raw'] = str_replace($lien['href'], $href, (string) $lien['raw']); |
|
| 97 | + // et prenons le href comme la vraie url a linker |
|
| 98 | + $lien['href'] = $href; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ($desechappe_crochets && str_contains((string) $lien['raw'], "\x1")) { |
|
| 102 | + $lien['raw'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['raw']); |
|
| 103 | + $lien['texte'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['texte']); |
|
| 104 | + $lien['href'] = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], (string) $lien['href']); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $liens; |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -65,17 +65,17 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | $page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']); |
| 67 | 67 | $doctype = ($options['doctype'] ?? '<!DOCTYPE html>'); |
| 68 | - $doctype = trim((string) $doctype) . "\n"; |
|
| 68 | + $doctype = trim((string) $doctype)."\n"; |
|
| 69 | 69 | $charset = ($options['charset'] ?? 'utf-8'); |
| 70 | 70 | $all_inline = ($options['all_inline'] ?? true); |
| 71 | 71 | $onLoad = ($options['onLoad'] ?? ''); |
| 72 | 72 | if ($onLoad) { |
| 73 | - $onLoad = ' onload="' . attribut_html($onLoad) . '"'; |
|
| 73 | + $onLoad = ' onload="'.attribut_html($onLoad).'"'; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | # envoyer le charset |
| 77 | 77 | if (!headers_sent()) { |
| 78 | - header('Content-Type: text/html; charset=' . $charset); |
|
| 78 | + header('Content-Type: text/html; charset='.$charset); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | $css = ''; |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | . "--minipage-color-theme--s: $s;" |
| 95 | 95 | . "--minipage-color-theme--l: $l;}"; |
| 96 | 96 | $vars = file_get_contents(find_in_theme('minipage.vars.css')); |
| 97 | - $inline .= "\n" . trim($vars); |
|
| 97 | + $inline .= "\n".trim($vars); |
|
| 98 | 98 | if (function_exists('minifier')) { |
| 99 | 99 | $inline = minifier($inline, 'css'); |
| 100 | 100 | } |
@@ -121,31 +121,31 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | $css = "$inline\n$css"; |
| 123 | 123 | if (!empty($options['css'])) { |
| 124 | - $css .= "\n" . $options['css']; |
|
| 124 | + $css .= "\n".$options['css']; |
|
| 125 | 125 | } |
| 126 | 126 | $css = "<style type='text/css'>$css</style>"; |
| 127 | 127 | } else { |
| 128 | 128 | $css = "<style type='text/css'>$inline</style>"; |
| 129 | 129 | foreach ($files as $name) { |
| 130 | 130 | $file = timestamp(direction_css($name)); |
| 131 | - $css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n"; |
|
| 131 | + $css .= "<link rel='stylesheet' href='".attribut_html($file)."' type='text/css' />\n"; |
|
| 132 | 132 | } |
| 133 | 133 | if (!empty($options['css'])) { |
| 134 | - $css .= "<style type='text/css'>" . $options['css'] . '</style>'; |
|
| 134 | + $css .= "<style type='text/css'>".$options['css'].'</style>'; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - return $doctype . |
|
| 139 | - html_lang_attributes() . |
|
| 140 | - "<head>\n" . |
|
| 141 | - '<title>' . |
|
| 142 | - textebrut($page_title) . |
|
| 143 | - "</title>\n" . |
|
| 144 | - "<meta name=\"viewport\" content=\"width=device-width\" />\n" . |
|
| 145 | - $css . |
|
| 146 | - (empty($options['head']) ? '' : $options['head']) . |
|
| 147 | - "</head>\n" . |
|
| 148 | - "<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" . |
|
| 138 | + return $doctype. |
|
| 139 | + html_lang_attributes(). |
|
| 140 | + "<head>\n". |
|
| 141 | + '<title>'. |
|
| 142 | + textebrut($page_title). |
|
| 143 | + "</title>\n". |
|
| 144 | + "<meta name=\"viewport\" content=\"width=device-width\" />\n". |
|
| 145 | + $css. |
|
| 146 | + (empty($options['head']) ? '' : $options['head']). |
|
| 147 | + "</head>\n". |
|
| 148 | + "<body{$onLoad} class=\"minipage".($this::TYPE ? ' minipage--'.$this::TYPE : '')."\">\n". |
|
| 149 | 149 | "\t<div class=\"minipage-bloc\">\n"; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -156,16 +156,16 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function ouvreCorps($options = []) { |
| 158 | 158 | $url_site = url_de_base(); |
| 159 | - $header = "<header>\n" . |
|
| 160 | - '<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n"; |
|
| 159 | + $header = "<header>\n". |
|
| 160 | + '<h1><a href="'.attribut_html($url_site).'">'.interdire_scripts($GLOBALS['meta']['nom_site'] ?? '')."</a></h1>\n"; |
|
| 161 | 161 | |
| 162 | 162 | $titre = ($options['titre'] ?? ''); |
| 163 | 163 | if ($titre) { |
| 164 | - $header .= '<h2>' . interdire_scripts($titre) . '</h2>'; |
|
| 164 | + $header .= '<h2>'.interdire_scripts($titre).'</h2>'; |
|
| 165 | 165 | } |
| 166 | 166 | $header .= '</header>'; |
| 167 | 167 | |
| 168 | - return $header . "<div class='corps'>\n"; |
|
| 168 | + return $header."<div class='corps'>\n"; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -179,13 +179,13 @@ discard block |
||
| 179 | 179 | if (isset($options['footer'])) { |
| 180 | 180 | $footer = $options['footer']; |
| 181 | 181 | } else { |
| 182 | - $footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n"; |
|
| 182 | + $footer = '<a href="'.attribut_html($url_site).'">'._T('retour')."</a>\n"; |
|
| 183 | 183 | } |
| 184 | 184 | if (!empty($footer)) { |
| 185 | 185 | $footer = "<footer>\n{$footer}</footer>"; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - return "</div>\n" . $footer; |
|
| 188 | + return "</div>\n".$footer; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -15,265 +15,265 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées |
| 16 | 16 | **/ |
| 17 | 17 | abstract class AbstractPage { |
| 18 | - public const TYPE = ''; |
|
| 18 | + public const TYPE = ''; |
|
| 19 | 19 | |
| 20 | - public function __construct() { |
|
| 21 | - include_fichiers_fonctions(); |
|
| 22 | - include_spip('inc/headers'); |
|
| 23 | - include_spip('inc/texte'); //inclue inc/lang et inc/filtres |
|
| 24 | - include_spip('inc/filtres_images_mini'); |
|
| 25 | - } |
|
| 20 | + public function __construct() { |
|
| 21 | + include_fichiers_fonctions(); |
|
| 22 | + include_spip('inc/headers'); |
|
| 23 | + include_spip('inc/texte'); //inclue inc/lang et inc/filtres |
|
| 24 | + include_spip('inc/filtres_images_mini'); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Retourne le début d'une page HTML minimale |
|
| 29 | - * |
|
| 30 | - * Le contenu de CSS minimales (reset.css, clear.css, minipage.css) est inséré |
|
| 31 | - * dans une balise script inline (compactée si possible) |
|
| 32 | - * |
|
| 33 | - * @param array $options |
|
| 34 | - * string $lang : forcer la langue utilisateur |
|
| 35 | - * string $page_title : titre éventuel de la page (nom du site par défaut) |
|
| 36 | - * string $couleur_fond : pour la couleur dominante de la page (par défaut on reprend le réglage de la page de login) |
|
| 37 | - * bool $all_inline : inliner les CSS pour envoyer toute la page en 1 hit |
|
| 38 | - * string $doctype |
|
| 39 | - * string $charset |
|
| 40 | - * string $onload |
|
| 41 | - * array $css_files : ajouter des fichiers css |
|
| 42 | - * string $css : ajouter du CSS inline |
|
| 43 | - * string $head : contenu à ajouter à la fin <head> (pour inclusion de JS ou JS inline...) |
|
| 44 | - * @return string |
|
| 45 | - * Code HTML |
|
| 46 | - * |
|
| 47 | - * @uses html_lang_attributes() |
|
| 48 | - * @uses minifier() si le plugin compresseur est présent |
|
| 49 | - * @uses url_absolue_css() |
|
| 50 | - * |
|
| 51 | - * @uses utiliser_langue_visiteur() |
|
| 52 | - * @uses http_no_cache() |
|
| 53 | - */ |
|
| 54 | - protected function ouvreBody($options = []) { |
|
| 55 | - $h = null; |
|
| 56 | - $s = null; |
|
| 57 | - $l = null; |
|
| 58 | - if (empty($options['lang'])) { |
|
| 59 | - // on se limite sur une langue de $GLOBALS['meta']['langues_multilingue'] car on est dans le public |
|
| 60 | - utiliser_langue_visiteur($GLOBALS['meta']['langues_multilingue'] ?? null); |
|
| 61 | - } else { |
|
| 62 | - changer_langue($options['lang']); |
|
| 63 | - } |
|
| 64 | - http_no_cache(); |
|
| 27 | + /** |
|
| 28 | + * Retourne le début d'une page HTML minimale |
|
| 29 | + * |
|
| 30 | + * Le contenu de CSS minimales (reset.css, clear.css, minipage.css) est inséré |
|
| 31 | + * dans une balise script inline (compactée si possible) |
|
| 32 | + * |
|
| 33 | + * @param array $options |
|
| 34 | + * string $lang : forcer la langue utilisateur |
|
| 35 | + * string $page_title : titre éventuel de la page (nom du site par défaut) |
|
| 36 | + * string $couleur_fond : pour la couleur dominante de la page (par défaut on reprend le réglage de la page de login) |
|
| 37 | + * bool $all_inline : inliner les CSS pour envoyer toute la page en 1 hit |
|
| 38 | + * string $doctype |
|
| 39 | + * string $charset |
|
| 40 | + * string $onload |
|
| 41 | + * array $css_files : ajouter des fichiers css |
|
| 42 | + * string $css : ajouter du CSS inline |
|
| 43 | + * string $head : contenu à ajouter à la fin <head> (pour inclusion de JS ou JS inline...) |
|
| 44 | + * @return string |
|
| 45 | + * Code HTML |
|
| 46 | + * |
|
| 47 | + * @uses html_lang_attributes() |
|
| 48 | + * @uses minifier() si le plugin compresseur est présent |
|
| 49 | + * @uses url_absolue_css() |
|
| 50 | + * |
|
| 51 | + * @uses utiliser_langue_visiteur() |
|
| 52 | + * @uses http_no_cache() |
|
| 53 | + */ |
|
| 54 | + protected function ouvreBody($options = []) { |
|
| 55 | + $h = null; |
|
| 56 | + $s = null; |
|
| 57 | + $l = null; |
|
| 58 | + if (empty($options['lang'])) { |
|
| 59 | + // on se limite sur une langue de $GLOBALS['meta']['langues_multilingue'] car on est dans le public |
|
| 60 | + utiliser_langue_visiteur($GLOBALS['meta']['langues_multilingue'] ?? null); |
|
| 61 | + } else { |
|
| 62 | + changer_langue($options['lang']); |
|
| 63 | + } |
|
| 64 | + http_no_cache(); |
|
| 65 | 65 | |
| 66 | - $page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']); |
|
| 67 | - $doctype = ($options['doctype'] ?? '<!DOCTYPE html>'); |
|
| 68 | - $doctype = trim((string) $doctype) . "\n"; |
|
| 69 | - $charset = ($options['charset'] ?? 'utf-8'); |
|
| 70 | - $all_inline = ($options['all_inline'] ?? true); |
|
| 71 | - $onLoad = ($options['onLoad'] ?? ''); |
|
| 72 | - if ($onLoad) { |
|
| 73 | - $onLoad = ' onload="' . attribut_html($onLoad) . '"'; |
|
| 74 | - } |
|
| 66 | + $page_title = ($options['page_title'] ?? $GLOBALS['meta']['nom_site']); |
|
| 67 | + $doctype = ($options['doctype'] ?? '<!DOCTYPE html>'); |
|
| 68 | + $doctype = trim((string) $doctype) . "\n"; |
|
| 69 | + $charset = ($options['charset'] ?? 'utf-8'); |
|
| 70 | + $all_inline = ($options['all_inline'] ?? true); |
|
| 71 | + $onLoad = ($options['onLoad'] ?? ''); |
|
| 72 | + if ($onLoad) { |
|
| 73 | + $onLoad = ' onload="' . attribut_html($onLoad) . '"'; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - # envoyer le charset |
|
| 77 | - if (!headers_sent()) { |
|
| 78 | - header('Content-Type: text/html; charset=' . $charset); |
|
| 79 | - } |
|
| 76 | + # envoyer le charset |
|
| 77 | + if (!headers_sent()) { |
|
| 78 | + header('Content-Type: text/html; charset=' . $charset); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $css = ''; |
|
| 81 | + $css = ''; |
|
| 82 | 82 | |
| 83 | - if (function_exists('couleur_hex_to_hsl')) { |
|
| 84 | - $couleur_fond = empty($options['couleur_fond']) |
|
| 85 | - ? lire_config('couleur_login', '#db1762') |
|
| 86 | - : $options['couleur_fond']; |
|
| 87 | - $h = couleur_hex_to_hsl($couleur_fond, 'h'); |
|
| 88 | - $s = couleur_hex_to_hsl($couleur_fond, 's'); |
|
| 89 | - $l = couleur_hex_to_hsl($couleur_fond, 'l'); |
|
| 90 | - } |
|
| 83 | + if (function_exists('couleur_hex_to_hsl')) { |
|
| 84 | + $couleur_fond = empty($options['couleur_fond']) |
|
| 85 | + ? lire_config('couleur_login', '#db1762') |
|
| 86 | + : $options['couleur_fond']; |
|
| 87 | + $h = couleur_hex_to_hsl($couleur_fond, 'h'); |
|
| 88 | + $s = couleur_hex_to_hsl($couleur_fond, 's'); |
|
| 89 | + $l = couleur_hex_to_hsl($couleur_fond, 'l'); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $inline = ':root {' |
|
| 93 | - . "--minipage-color-theme--h: $h;" |
|
| 94 | - . "--minipage-color-theme--s: $s;" |
|
| 95 | - . "--minipage-color-theme--l: $l;}"; |
|
| 96 | - $vars = file_get_contents(find_in_theme('minipage.vars.css')); |
|
| 97 | - $inline .= "\n" . trim($vars); |
|
| 98 | - if (function_exists('minifier')) { |
|
| 99 | - $inline = minifier($inline, 'css'); |
|
| 100 | - } |
|
| 101 | - $files = [ |
|
| 102 | - find_in_theme('reset.css'), |
|
| 103 | - find_in_theme('clear.css'), |
|
| 104 | - find_in_theme('minipage.css'), |
|
| 105 | - ]; |
|
| 106 | - if (!empty($options['css_files'])) { |
|
| 107 | - foreach ($options['css_files'] as $css_file) { |
|
| 108 | - $files[] = $css_file; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - if ($all_inline) { |
|
| 112 | - // inliner les CSS (optimisation de la page minipage qui passe en un seul hit a la demande) |
|
| 113 | - foreach ($files as $name) { |
|
| 114 | - $file = direction_css($name); |
|
| 115 | - if (function_exists('minifier')) { |
|
| 116 | - $file = minifier($file); |
|
| 117 | - } else { |
|
| 118 | - $file = url_absolue_css($file); // precaution |
|
| 119 | - } |
|
| 120 | - $css .= file_get_contents($file); |
|
| 121 | - } |
|
| 122 | - $css = "$inline\n$css"; |
|
| 123 | - if (!empty($options['css'])) { |
|
| 124 | - $css .= "\n" . $options['css']; |
|
| 125 | - } |
|
| 126 | - $css = "<style type='text/css'>$css</style>"; |
|
| 127 | - } else { |
|
| 128 | - $css = "<style type='text/css'>$inline</style>"; |
|
| 129 | - foreach ($files as $name) { |
|
| 130 | - $file = timestamp(direction_css($name)); |
|
| 131 | - $css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n"; |
|
| 132 | - } |
|
| 133 | - if (!empty($options['css'])) { |
|
| 134 | - $css .= "<style type='text/css'>" . $options['css'] . '</style>'; |
|
| 135 | - } |
|
| 136 | - } |
|
| 92 | + $inline = ':root {' |
|
| 93 | + . "--minipage-color-theme--h: $h;" |
|
| 94 | + . "--minipage-color-theme--s: $s;" |
|
| 95 | + . "--minipage-color-theme--l: $l;}"; |
|
| 96 | + $vars = file_get_contents(find_in_theme('minipage.vars.css')); |
|
| 97 | + $inline .= "\n" . trim($vars); |
|
| 98 | + if (function_exists('minifier')) { |
|
| 99 | + $inline = minifier($inline, 'css'); |
|
| 100 | + } |
|
| 101 | + $files = [ |
|
| 102 | + find_in_theme('reset.css'), |
|
| 103 | + find_in_theme('clear.css'), |
|
| 104 | + find_in_theme('minipage.css'), |
|
| 105 | + ]; |
|
| 106 | + if (!empty($options['css_files'])) { |
|
| 107 | + foreach ($options['css_files'] as $css_file) { |
|
| 108 | + $files[] = $css_file; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + if ($all_inline) { |
|
| 112 | + // inliner les CSS (optimisation de la page minipage qui passe en un seul hit a la demande) |
|
| 113 | + foreach ($files as $name) { |
|
| 114 | + $file = direction_css($name); |
|
| 115 | + if (function_exists('minifier')) { |
|
| 116 | + $file = minifier($file); |
|
| 117 | + } else { |
|
| 118 | + $file = url_absolue_css($file); // precaution |
|
| 119 | + } |
|
| 120 | + $css .= file_get_contents($file); |
|
| 121 | + } |
|
| 122 | + $css = "$inline\n$css"; |
|
| 123 | + if (!empty($options['css'])) { |
|
| 124 | + $css .= "\n" . $options['css']; |
|
| 125 | + } |
|
| 126 | + $css = "<style type='text/css'>$css</style>"; |
|
| 127 | + } else { |
|
| 128 | + $css = "<style type='text/css'>$inline</style>"; |
|
| 129 | + foreach ($files as $name) { |
|
| 130 | + $file = timestamp(direction_css($name)); |
|
| 131 | + $css .= "<link rel='stylesheet' href='" . attribut_html($file) . "' type='text/css' />\n"; |
|
| 132 | + } |
|
| 133 | + if (!empty($options['css'])) { |
|
| 134 | + $css .= "<style type='text/css'>" . $options['css'] . '</style>'; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - return $doctype . |
|
| 139 | - html_lang_attributes() . |
|
| 140 | - "<head>\n" . |
|
| 141 | - '<title>' . |
|
| 142 | - textebrut($page_title) . |
|
| 143 | - "</title>\n" . |
|
| 144 | - "<meta name=\"viewport\" content=\"width=device-width\" />\n" . |
|
| 145 | - $css . |
|
| 146 | - (empty($options['head']) ? '' : $options['head']) . |
|
| 147 | - "</head>\n" . |
|
| 148 | - "<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" . |
|
| 149 | - "\t<div class=\"minipage-bloc\">\n"; |
|
| 150 | - } |
|
| 138 | + return $doctype . |
|
| 139 | + html_lang_attributes() . |
|
| 140 | + "<head>\n" . |
|
| 141 | + '<title>' . |
|
| 142 | + textebrut($page_title) . |
|
| 143 | + "</title>\n" . |
|
| 144 | + "<meta name=\"viewport\" content=\"width=device-width\" />\n" . |
|
| 145 | + $css . |
|
| 146 | + (empty($options['head']) ? '' : $options['head']) . |
|
| 147 | + "</head>\n" . |
|
| 148 | + "<body{$onLoad} class=\"minipage" . ($this::TYPE ? ' minipage--' . $this::TYPE : '') . "\">\n" . |
|
| 149 | + "\t<div class=\"minipage-bloc\">\n"; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Ouvre le corps : affiche le header avec un éventuel titre + ouvre le div corps |
|
| 154 | - * @param array options |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - protected function ouvreCorps($options = []) { |
|
| 158 | - $url_site = url_de_base(); |
|
| 159 | - $header = "<header>\n" . |
|
| 160 | - '<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n"; |
|
| 152 | + /** |
|
| 153 | + * Ouvre le corps : affiche le header avec un éventuel titre + ouvre le div corps |
|
| 154 | + * @param array options |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + protected function ouvreCorps($options = []) { |
|
| 158 | + $url_site = url_de_base(); |
|
| 159 | + $header = "<header>\n" . |
|
| 160 | + '<h1><a href="' . attribut_html($url_site) . '">' . interdire_scripts($GLOBALS['meta']['nom_site'] ?? '') . "</a></h1>\n"; |
|
| 161 | 161 | |
| 162 | - $titre = ($options['titre'] ?? ''); |
|
| 163 | - if ($titre) { |
|
| 164 | - $header .= '<h2>' . interdire_scripts($titre) . '</h2>'; |
|
| 165 | - } |
|
| 166 | - $header .= '</header>'; |
|
| 162 | + $titre = ($options['titre'] ?? ''); |
|
| 163 | + if ($titre) { |
|
| 164 | + $header .= '<h2>' . interdire_scripts($titre) . '</h2>'; |
|
| 165 | + } |
|
| 166 | + $header .= '</header>'; |
|
| 167 | 167 | |
| 168 | - return $header . "<div class='corps'>\n"; |
|
| 169 | - } |
|
| 168 | + return $header . "<div class='corps'>\n"; |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Ferme le corps : affiche le footer par défaut ou custom et ferme le div corps |
|
| 173 | - * @param array $options |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - protected function fermeCorps($options = []) { |
|
| 177 | - $url_site = url_de_base(); |
|
| 171 | + /** |
|
| 172 | + * Ferme le corps : affiche le footer par défaut ou custom et ferme le div corps |
|
| 173 | + * @param array $options |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + protected function fermeCorps($options = []) { |
|
| 177 | + $url_site = url_de_base(); |
|
| 178 | 178 | |
| 179 | - if (isset($options['footer'])) { |
|
| 180 | - $footer = $options['footer']; |
|
| 181 | - } else { |
|
| 182 | - $footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n"; |
|
| 183 | - } |
|
| 184 | - if (!empty($footer)) { |
|
| 185 | - $footer = "<footer>\n{$footer}</footer>"; |
|
| 186 | - } |
|
| 179 | + if (isset($options['footer'])) { |
|
| 180 | + $footer = $options['footer']; |
|
| 181 | + } else { |
|
| 182 | + $footer = '<a href="' . attribut_html($url_site) . '">' . _T('retour') . "</a>\n"; |
|
| 183 | + } |
|
| 184 | + if (!empty($footer)) { |
|
| 185 | + $footer = "<footer>\n{$footer}</footer>"; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - return "</div>\n" . $footer; |
|
| 189 | - } |
|
| 188 | + return "</div>\n" . $footer; |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Retourne la fin d'une page HTML minimale |
|
| 194 | - * |
|
| 195 | - * @return string Code HTML |
|
| 196 | - */ |
|
| 197 | - protected function fermeBody() { |
|
| 198 | - return "\n\t</div>\n</body>\n</html>"; |
|
| 199 | - } |
|
| 192 | + /** |
|
| 193 | + * Retourne la fin d'une page HTML minimale |
|
| 194 | + * |
|
| 195 | + * @return string Code HTML |
|
| 196 | + */ |
|
| 197 | + protected function fermeBody() { |
|
| 198 | + return "\n\t</div>\n</body>\n</html>"; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 204 | - * le contenu transmis dans `$corps`. |
|
| 205 | - * |
|
| 206 | - * Appelée pour afficher un message ou une demande de confirmation simple et rapide |
|
| 207 | - * |
|
| 208 | - * @param string $corps |
|
| 209 | - * Corps de la page |
|
| 210 | - * @param array $options |
|
| 211 | - * @return string |
|
| 212 | - * HTML de la page |
|
| 213 | - * @see ouvreBody() |
|
| 214 | - * @see ouvreCorps() |
|
| 215 | - * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 216 | - * int $status : status de la page |
|
| 217 | - * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 218 | - * @uses ouvreBody() |
|
| 219 | - * @uses ouvreCorps() |
|
| 220 | - * @uses fermeCorps() |
|
| 221 | - * @uses fermeBody() |
|
| 222 | - * |
|
| 223 | - */ |
|
| 224 | - public function page($corps, $options = []) { |
|
| 202 | + /** |
|
| 203 | + * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 204 | + * le contenu transmis dans `$corps`. |
|
| 205 | + * |
|
| 206 | + * Appelée pour afficher un message ou une demande de confirmation simple et rapide |
|
| 207 | + * |
|
| 208 | + * @param string $corps |
|
| 209 | + * Corps de la page |
|
| 210 | + * @param array $options |
|
| 211 | + * @return string |
|
| 212 | + * HTML de la page |
|
| 213 | + * @see ouvreBody() |
|
| 214 | + * @see ouvreCorps() |
|
| 215 | + * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 216 | + * int $status : status de la page |
|
| 217 | + * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 218 | + * @uses ouvreBody() |
|
| 219 | + * @uses ouvreCorps() |
|
| 220 | + * @uses fermeCorps() |
|
| 221 | + * @uses fermeBody() |
|
| 222 | + * |
|
| 223 | + */ |
|
| 224 | + public function page($corps, $options = []) { |
|
| 225 | 225 | |
| 226 | - // par securite |
|
| 227 | - if (!defined('_AJAX')) { |
|
| 228 | - define('_AJAX', false); |
|
| 229 | - } |
|
| 226 | + // par securite |
|
| 227 | + if (!defined('_AJAX')) { |
|
| 228 | + define('_AJAX', false); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $status = ((int) ($options['status'] ?? 200)) ?: 200; |
|
| 231 | + $status = ((int) ($options['status'] ?? 200)) ?: 200; |
|
| 232 | 232 | |
| 233 | - http_response_code($status); |
|
| 233 | + http_response_code($status); |
|
| 234 | 234 | |
| 235 | - $html = $this->ouvreBody($options) |
|
| 236 | - . $this->ouvreCorps($options) |
|
| 237 | - . $corps |
|
| 238 | - . $this->fermeCorps($options) |
|
| 239 | - . $this->fermeBody(); |
|
| 235 | + $html = $this->ouvreBody($options) |
|
| 236 | + . $this->ouvreCorps($options) |
|
| 237 | + . $corps |
|
| 238 | + . $this->fermeCorps($options) |
|
| 239 | + . $this->fermeBody(); |
|
| 240 | 240 | |
| 241 | - if ( |
|
| 242 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 243 | - && empty($options['all_inline']) |
|
| 244 | - ) { |
|
| 245 | - define('_SET_HTML_BASE', true); |
|
| 246 | - include_spip('public/assembler'); |
|
| 247 | - $GLOBALS['html'] = true; |
|
| 248 | - page_base_href($html); |
|
| 249 | - } |
|
| 250 | - return $html; |
|
| 251 | - } |
|
| 241 | + if ( |
|
| 242 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 243 | + && empty($options['all_inline']) |
|
| 244 | + ) { |
|
| 245 | + define('_SET_HTML_BASE', true); |
|
| 246 | + include_spip('public/assembler'); |
|
| 247 | + $GLOBALS['html'] = true; |
|
| 248 | + page_base_href($html); |
|
| 249 | + } |
|
| 250 | + return $html; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Fonction helper pour les erreurs |
|
| 255 | - * @param ?string $message_erreur |
|
| 256 | - * @param array $options |
|
| 257 | - * @see page() |
|
| 258 | - * @return string |
|
| 259 | - * |
|
| 260 | - */ |
|
| 261 | - public function pageErreur($message_erreur = null, $options = []) { |
|
| 253 | + /** |
|
| 254 | + * Fonction helper pour les erreurs |
|
| 255 | + * @param ?string $message_erreur |
|
| 256 | + * @param array $options |
|
| 257 | + * @see page() |
|
| 258 | + * @return string |
|
| 259 | + * |
|
| 260 | + */ |
|
| 261 | + public function pageErreur($message_erreur = null, $options = []) { |
|
| 262 | 262 | |
| 263 | - if (empty($message_erreur)) { |
|
| 264 | - if (empty($options['lang'])) { |
|
| 265 | - utiliser_langue_visiteur(); |
|
| 266 | - } else { |
|
| 267 | - changer_langue($options['lang']); |
|
| 268 | - } |
|
| 269 | - $message_erreur = _T('info_acces_interdit'); |
|
| 270 | - } |
|
| 271 | - $corps = "<div class='msg-alert error'>" |
|
| 272 | - . $message_erreur |
|
| 273 | - . '</div>'; |
|
| 274 | - if (empty($options['status'])) { |
|
| 275 | - $options['status'] = 403; |
|
| 276 | - } |
|
| 277 | - return $this->page($corps, $options); |
|
| 278 | - } |
|
| 263 | + if (empty($message_erreur)) { |
|
| 264 | + if (empty($options['lang'])) { |
|
| 265 | + utiliser_langue_visiteur(); |
|
| 266 | + } else { |
|
| 267 | + changer_langue($options['lang']); |
|
| 268 | + } |
|
| 269 | + $message_erreur = _T('info_acces_interdit'); |
|
| 270 | + } |
|
| 271 | + $corps = "<div class='msg-alert error'>" |
|
| 272 | + . $message_erreur |
|
| 273 | + . '</div>'; |
|
| 274 | + if (empty($options['status'])) { |
|
| 275 | + $options['status'] = 403; |
|
| 276 | + } |
|
| 277 | + return $this->page($corps, $options); |
|
| 278 | + } |
|
| 279 | 279 | } |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | return $this->iter->{$nom}(); |
| 136 | 136 | } catch (Exception) { |
| 137 | 137 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 138 | - spip_log("Methode {$nom} en echec sur " . $this->iter::class); |
|
| 138 | + spip_log("Methode {$nom} en echec sur ".$this->iter::class); |
|
| 139 | 139 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 140 | 140 | |
| 141 | 141 | return ''; |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | return null; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - return '(' . implode(") {$operateur} (", $filtres_string) . ')'; |
|
| 359 | + return '('.implode(") {$operateur} (", $filtres_string).')'; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | return $this->composer_filtre($v[1], $v[0], $v[2]); |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - return null; // sera ignore |
|
| 442 | + return null; // sera ignore |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -468,28 +468,28 @@ discard block |
||
| 468 | 468 | // if (!in_array($cle, array('cle', 'valeur'))) |
| 469 | 469 | // return; |
| 470 | 470 | |
| 471 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 471 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 472 | 472 | |
| 473 | 473 | $filtre = ''; |
| 474 | 474 | |
| 475 | 475 | if ('REGEXP' == $op) { |
| 476 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', (string) $valeur) . ')'; |
|
| 476 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', (string) $valeur).')'; |
|
| 477 | 477 | $op = ''; |
| 478 | 478 | } else { |
| 479 | 479 | if ('LIKE' == $op) { |
| 480 | 480 | $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote((string) $valeur)); |
| 481 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 481 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 482 | 482 | $op = ''; |
| 483 | 483 | } else { |
| 484 | 484 | if ('=' == $op) { |
| 485 | 485 | $op = '=='; |
| 486 | 486 | } else { |
| 487 | 487 | if ('IN' == $op) { |
| 488 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 488 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 489 | 489 | $op = ''; |
| 490 | 490 | } else { |
| 491 | 491 | if (!in_array($op, ['<', '<=', '>', '>='])) { |
| 492 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 492 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 493 | 493 | $op = ''; |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | if ($op) { |
| 501 | - $filtre = $a . $op . str_replace('\"', '"', (string) $valeur); |
|
| 501 | + $filtre = $a.$op.str_replace('\"', '"', (string) $valeur); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | if ($not) { |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | // Creer la fonction de filtrage sur $this |
| 548 | 548 | if ($this->filtre) { |
| 549 | 549 | if ($filtres = $this->assembler_filtres($this->filtre)) { |
| 550 | - $filtres = 'return ' . $filtres . ';'; |
|
| 550 | + $filtres = 'return '.$filtres.';'; |
|
| 551 | 551 | $this->func_filtre = fn () => eval($filtres); |
| 552 | 552 | } else { |
| 553 | 553 | $this->func_filtre = null; |
@@ -8,566 +8,566 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Decorator extends FilterIterator |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Conditions de filtrage |
|
| 13 | - * ie criteres de selection. |
|
| 14 | - * |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - protected $filtre = []; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Fonction de filtrage compilee a partir des criteres de filtre. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $func_filtre; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Critere {offset, limit}. |
|
| 28 | - * |
|
| 29 | - * @var int |
|
| 30 | - * @var int |
|
| 31 | - */ |
|
| 32 | - protected $offset; |
|
| 33 | - protected $limit; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * nombre d'elements recuperes depuis la position 0, |
|
| 37 | - * en tenant compte des filtres. |
|
| 38 | - * |
|
| 39 | - * @var int |
|
| 40 | - */ |
|
| 41 | - protected $fetched = 0; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Y a t'il une erreur ? |
|
| 45 | - * |
|
| 46 | - * @var bool |
|
| 47 | - */ |
|
| 48 | - protected $err = false; |
|
| 49 | - |
|
| 50 | - // Extension SPIP des iterateurs PHP |
|
| 51 | - /** |
|
| 52 | - * type de l'iterateur. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $type; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * position courante de l'iterateur. |
|
| 60 | - * |
|
| 61 | - * @var int |
|
| 62 | - */ |
|
| 63 | - protected $pos = 0; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * nombre total resultats dans l'iterateur. |
|
| 67 | - * |
|
| 68 | - * @var int |
|
| 69 | - */ |
|
| 70 | - protected $total; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * nombre maximal de recherche pour $total |
|
| 74 | - * si l'iterateur n'implemente pas de fonction specifique. |
|
| 75 | - */ |
|
| 76 | - protected $max = 100000; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Liste des champs a inserer dans les $row |
|
| 80 | - * retournes par ->fetch(). |
|
| 81 | - */ |
|
| 82 | - protected $select = []; |
|
| 83 | - private readonly Iterator $iter; |
|
| 84 | - |
|
| 85 | - public function __construct( |
|
| 86 | - Iterator $iter, |
|
| 87 | - /** Parametres de l'iterateur */ |
|
| 88 | - protected array $command, |
|
| 89 | - /** Infos du compilateur */ |
|
| 90 | - protected array $info |
|
| 91 | - ) { |
|
| 92 | - parent::__construct($iter); |
|
| 93 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 94 | - |
|
| 95 | - // recuperer l'iterateur transmis |
|
| 96 | - $this->iter = $this->getInnerIterator(); |
|
| 97 | - |
|
| 98 | - // chercher la liste des champs a retourner par |
|
| 99 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 100 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 101 | - $this->calculer_select(); |
|
| 102 | - $this->calculer_filtres(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 106 | - if (property_exists($this->iter, 'err') && $this->iter->err !== null) { |
|
| 107 | - $this->err = $this->iter->err; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 111 | - //$this->total = $this->count(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Drapeau a activer en cas d'echec |
|
| 116 | - * (select SQL errone, non chargement des DATA, etc). |
|
| 117 | - */ |
|
| 118 | - public function err() { |
|
| 119 | - if (method_exists($this->iter, 'err')) { |
|
| 120 | - return $this->iter->err(); |
|
| 121 | - } |
|
| 122 | - if (property_exists($this->iter, 'err')) { |
|
| 123 | - return $this->iter->err; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return false; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // recuperer la valeur d'une balise #X |
|
| 130 | - // en fonction des methodes |
|
| 131 | - // et proprietes disponibles |
|
| 132 | - public function get_select($nom) { |
|
| 133 | - if (is_object($this->iter) && method_exists($this->iter, $nom)) { |
|
| 134 | - try { |
|
| 135 | - return $this->iter->{$nom}(); |
|
| 136 | - } catch (Exception) { |
|
| 137 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 138 | - spip_log("Methode {$nom} en echec sur " . $this->iter::class); |
|
| 139 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 140 | - |
|
| 141 | - return ''; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - /* |
|
| 11 | + /** |
|
| 12 | + * Conditions de filtrage |
|
| 13 | + * ie criteres de selection. |
|
| 14 | + * |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + protected $filtre = []; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Fonction de filtrage compilee a partir des criteres de filtre. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $func_filtre; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Critere {offset, limit}. |
|
| 28 | + * |
|
| 29 | + * @var int |
|
| 30 | + * @var int |
|
| 31 | + */ |
|
| 32 | + protected $offset; |
|
| 33 | + protected $limit; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * nombre d'elements recuperes depuis la position 0, |
|
| 37 | + * en tenant compte des filtres. |
|
| 38 | + * |
|
| 39 | + * @var int |
|
| 40 | + */ |
|
| 41 | + protected $fetched = 0; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Y a t'il une erreur ? |
|
| 45 | + * |
|
| 46 | + * @var bool |
|
| 47 | + */ |
|
| 48 | + protected $err = false; |
|
| 49 | + |
|
| 50 | + // Extension SPIP des iterateurs PHP |
|
| 51 | + /** |
|
| 52 | + * type de l'iterateur. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $type; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * position courante de l'iterateur. |
|
| 60 | + * |
|
| 61 | + * @var int |
|
| 62 | + */ |
|
| 63 | + protected $pos = 0; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * nombre total resultats dans l'iterateur. |
|
| 67 | + * |
|
| 68 | + * @var int |
|
| 69 | + */ |
|
| 70 | + protected $total; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * nombre maximal de recherche pour $total |
|
| 74 | + * si l'iterateur n'implemente pas de fonction specifique. |
|
| 75 | + */ |
|
| 76 | + protected $max = 100000; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Liste des champs a inserer dans les $row |
|
| 80 | + * retournes par ->fetch(). |
|
| 81 | + */ |
|
| 82 | + protected $select = []; |
|
| 83 | + private readonly Iterator $iter; |
|
| 84 | + |
|
| 85 | + public function __construct( |
|
| 86 | + Iterator $iter, |
|
| 87 | + /** Parametres de l'iterateur */ |
|
| 88 | + protected array $command, |
|
| 89 | + /** Infos du compilateur */ |
|
| 90 | + protected array $info |
|
| 91 | + ) { |
|
| 92 | + parent::__construct($iter); |
|
| 93 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 94 | + |
|
| 95 | + // recuperer l'iterateur transmis |
|
| 96 | + $this->iter = $this->getInnerIterator(); |
|
| 97 | + |
|
| 98 | + // chercher la liste des champs a retourner par |
|
| 99 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 100 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 101 | + $this->calculer_select(); |
|
| 102 | + $this->calculer_filtres(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 106 | + if (property_exists($this->iter, 'err') && $this->iter->err !== null) { |
|
| 107 | + $this->err = $this->iter->err; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 111 | + //$this->total = $this->count(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Drapeau a activer en cas d'echec |
|
| 116 | + * (select SQL errone, non chargement des DATA, etc). |
|
| 117 | + */ |
|
| 118 | + public function err() { |
|
| 119 | + if (method_exists($this->iter, 'err')) { |
|
| 120 | + return $this->iter->err(); |
|
| 121 | + } |
|
| 122 | + if (property_exists($this->iter, 'err')) { |
|
| 123 | + return $this->iter->err; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // recuperer la valeur d'une balise #X |
|
| 130 | + // en fonction des methodes |
|
| 131 | + // et proprietes disponibles |
|
| 132 | + public function get_select($nom) { |
|
| 133 | + if (is_object($this->iter) && method_exists($this->iter, $nom)) { |
|
| 134 | + try { |
|
| 135 | + return $this->iter->{$nom}(); |
|
| 136 | + } catch (Exception) { |
|
| 137 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 138 | + spip_log("Methode {$nom} en echec sur " . $this->iter::class); |
|
| 139 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 140 | + |
|
| 141 | + return ''; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + /* |
|
| 145 | 145 | if (property_exists($this->iter, $nom)) { |
| 146 | 146 | return $this->iter->$nom; |
| 147 | 147 | }*/ |
| 148 | - // cle et valeur par defaut |
|
| 149 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 150 | - if ( |
|
| 151 | - in_array($nom, ['cle', 'valeur']) |
|
| 152 | - && method_exists($this, $nom) |
|
| 153 | - ) { |
|
| 154 | - return $this->{$nom}(); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Par defaut chercher en xpath dans la valeur() |
|
| 158 | - return table_valeur($this->valeur(), $nom, null); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - public function next(): void { |
|
| 162 | - ++$this->pos; |
|
| 163 | - parent::next(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * revient au depart. |
|
| 168 | - */ |
|
| 169 | - public function rewind(): void { |
|
| 170 | - $this->pos = 0; |
|
| 171 | - $this->fetched = 0; |
|
| 172 | - parent::rewind(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * aller a la position absolue n, |
|
| 177 | - * comptee depuis le debut. |
|
| 178 | - * |
|
| 179 | - * @param int $n |
|
| 180 | - * absolute pos |
|
| 181 | - * @param string $continue |
|
| 182 | - * param for sql_ api |
|
| 183 | - * |
|
| 184 | - * @return bool |
|
| 185 | - * success or fail if not implemented |
|
| 186 | - */ |
|
| 187 | - public function seek($n = 0, $continue = null) { |
|
| 188 | - if ($this->func_filtre || !method_exists($this->iter, 'seek') || !$this->iter->seek($n)) { |
|
| 189 | - $this->seek_loop($n); |
|
| 190 | - } |
|
| 191 | - $this->pos = $n; |
|
| 192 | - $this->fetched = $n; |
|
| 193 | - |
|
| 194 | - return true; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Avancer de $saut pas. |
|
| 199 | - * |
|
| 200 | - * @param int $saut |
|
| 201 | - * @param int|null $max |
|
| 202 | - * |
|
| 203 | - * @return int |
|
| 204 | - */ |
|
| 205 | - public function skip($saut, $max = null) { |
|
| 206 | - // pas de saut en arriere autorise pour cette fonction |
|
| 207 | - if (($saut = (int) $saut) <= 0) { |
|
| 208 | - return $this->pos; |
|
| 209 | - } |
|
| 210 | - $seek = $this->pos + $saut; |
|
| 211 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 212 | - // et on sort |
|
| 213 | - if (is_null($max)) { |
|
| 214 | - $max = $this->count(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - if ($seek >= $max || $seek >= $this->count()) { |
|
| 218 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 219 | - $this->free(); |
|
| 220 | - |
|
| 221 | - return $max; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $this->seek($seek); |
|
| 225 | - |
|
| 226 | - return $this->pos; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Renvoyer un tableau des donnees correspondantes |
|
| 231 | - * a la position courante de l'iterateur |
|
| 232 | - * en controlant si on respecte le filtre |
|
| 233 | - * Appliquer aussi le critere {offset,limit}. |
|
| 234 | - * |
|
| 235 | - * @return array|bool |
|
| 236 | - */ |
|
| 237 | - public function fetch() { |
|
| 238 | - if (method_exists($this->iter, 'fetch')) { |
|
| 239 | - return $this->iter->fetch(); |
|
| 240 | - } |
|
| 241 | - while ( |
|
| 242 | - $this->valid() |
|
| 243 | - && (!$this->accept() || $this->offset !== null && $this->fetched++ < $this->offset) |
|
| 244 | - ) { |
|
| 245 | - $this->next(); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - if (!$this->valid()) { |
|
| 249 | - return false; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - if ( |
|
| 253 | - $this->limit !== null |
|
| 254 | - && $this->fetched > $this->offset + $this->limit |
|
| 255 | - ) { |
|
| 256 | - return false; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $r = []; |
|
| 260 | - foreach ($this->select as $nom) { |
|
| 261 | - $r[$nom] = $this->get_select($nom); |
|
| 262 | - } |
|
| 263 | - $this->next(); |
|
| 264 | - |
|
| 265 | - return $r; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - // retourner la cle pour #CLE |
|
| 269 | - public function cle() { |
|
| 270 | - return $this->key(); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // retourner la valeur pour #VALEUR |
|
| 274 | - public function valeur() { |
|
| 275 | - return $this->current(); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Accepte-t-on l'entree courante lue ? |
|
| 280 | - * On execute les filtres pour le savoir. |
|
| 281 | - */ |
|
| 282 | - public function accept(): bool { |
|
| 283 | - if ($f = $this->func_filtre) { |
|
| 284 | - return $f(); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return true; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * liberer la ressource. |
|
| 292 | - * |
|
| 293 | - * @return bool |
|
| 294 | - */ |
|
| 295 | - public function free() { |
|
| 296 | - if (method_exists($this->iter, 'free')) { |
|
| 297 | - $this->iter->free(); |
|
| 298 | - } |
|
| 299 | - $this->pos = $this->total = 0; |
|
| 300 | - |
|
| 301 | - return true; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Compter le nombre total de resultats |
|
| 306 | - * pour #TOTAL_BOUCLE. |
|
| 307 | - * |
|
| 308 | - * @return int |
|
| 309 | - */ |
|
| 310 | - public function count() { |
|
| 311 | - if (is_null($this->total)) { |
|
| 312 | - if ( |
|
| 313 | - method_exists($this->iter, 'count') |
|
| 314 | - && !$this->func_filtre |
|
| 315 | - ) { |
|
| 316 | - return $this->total = $this->iter->count(); |
|
| 317 | - } |
|
| 318 | - // compter les lignes et rembobiner |
|
| 319 | - $total = 0; |
|
| 320 | - $pos = $this->pos; // sauver la position |
|
| 321 | - $this->rewind(); |
|
| 322 | - while ($this->fetch() && $total < $this->max) { |
|
| 323 | - ++$total; |
|
| 324 | - } |
|
| 325 | - $this->seek($pos); |
|
| 326 | - $this->total = $total; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return $this->total; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 334 | - * les filtres vides ou null sont ignores. |
|
| 335 | - * |
|
| 336 | - * @param array $filtres |
|
| 337 | - * @param string $operateur |
|
| 338 | - * |
|
| 339 | - * @return null|string |
|
| 340 | - */ |
|
| 341 | - protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 342 | - $filtres_string = []; |
|
| 343 | - foreach ($filtres as $k => $v) { |
|
| 344 | - // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 345 | - if (is_array($v) && in_array(reset($v), ['OR', 'AND'])) { |
|
| 346 | - $op = array_shift($v); |
|
| 347 | - $v = $this->assembler_filtres($v, $op); |
|
| 348 | - } |
|
| 349 | - if (is_null($v) || !is_string($v) || empty($v)) { |
|
| 350 | - continue; |
|
| 351 | - } |
|
| 352 | - $filtres_string[] = $v; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if ($filtres_string === []) { |
|
| 356 | - return null; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - return '(' . implode(") {$operateur} (", $filtres_string) . ')'; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Traduire un element du tableau where SQL en un filtre. |
|
| 364 | - * |
|
| 365 | - * @param array|string $v |
|
| 366 | - * |
|
| 367 | - * @return null|array|string |
|
| 368 | - */ |
|
| 369 | - protected function traduire_condition_sql_en_filtre($v) { |
|
| 370 | - if (is_array($v)) { |
|
| 371 | - if ((count($v) >= 2) && ('REGEXP' == $v[0]) && ("'.*'" == $v[2])) { |
|
| 372 | - return 'true'; |
|
| 373 | - } |
|
| 374 | - if ((count($v) >= 2) && ('LIKE' == $v[0]) && ("'%'" == $v[2])) { |
|
| 375 | - return 'true'; |
|
| 376 | - } |
|
| 377 | - $op = $v[0] ?: $v; |
|
| 378 | - } else { |
|
| 379 | - $op = $v; |
|
| 380 | - } |
|
| 381 | - if (!$op || 1 == $op || '0=0' == $op) { |
|
| 382 | - return 'true'; |
|
| 383 | - } |
|
| 384 | - if ('0=1' === $op) { |
|
| 385 | - return 'false'; |
|
| 386 | - } |
|
| 387 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 388 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', (string) $op, $regs)) { |
|
| 389 | - return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - // 3 possibilites : count($v) = |
|
| 393 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 394 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 395 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 396 | - |
|
| 397 | - // 1 : forcement traite par un critere, on passe |
|
| 398 | - if (!$v || !is_array($v) || 1 == count($v)) { |
|
| 399 | - return null; // sera ignore |
|
| 400 | - } |
|
| 401 | - if (2 == count($v) && is_array($v[1])) { |
|
| 402 | - return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 403 | - } |
|
| 404 | - if (3 == count($v)) { |
|
| 405 | - // traiter le OR/AND suivi de 2 valeurs |
|
| 406 | - if (in_array($op, ['OR', 'AND'])) { |
|
| 407 | - array_shift($v); |
|
| 408 | - foreach (array_keys($v) as $k) { |
|
| 409 | - $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 410 | - if (null === $v[$k]) { |
|
| 411 | - unset($v[$k]); |
|
| 412 | - } elseif ('true' === $v[$k]) { |
|
| 413 | - if ('OR' === $op) { |
|
| 414 | - return 'true'; |
|
| 415 | - } |
|
| 416 | - if ('AND' === $op) { |
|
| 417 | - unset($v[$k]); |
|
| 418 | - } |
|
| 419 | - } elseif ('false' === $v[$k]) { |
|
| 420 | - if ('OR' === $op) { |
|
| 421 | - unset($v[$k]); |
|
| 422 | - } |
|
| 423 | - if ('AND' === $op) { |
|
| 424 | - return 'false'; |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - if ($v === []) { |
|
| 429 | - return null; |
|
| 430 | - } |
|
| 431 | - if (1 === count($v)) { |
|
| 432 | - return reset($v); |
|
| 433 | - } |
|
| 434 | - array_unshift($v, $op); |
|
| 435 | - |
|
| 436 | - return $v; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return null; // sera ignore |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Calculer un filtre sur un champ du tableau. |
|
| 447 | - * |
|
| 448 | - * @param string $cle |
|
| 449 | - * @param string $op |
|
| 450 | - * @param string $valeur |
|
| 451 | - * @param bool $not |
|
| 452 | - * |
|
| 453 | - * @return null|string |
|
| 454 | - */ |
|
| 455 | - protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 456 | - if ( |
|
| 457 | - method_exists($this->iter, 'exception_des_criteres') |
|
| 458 | - && in_array($cle, $this->iter->exception_des_criteres()) |
|
| 459 | - ) { |
|
| 460 | - return null; |
|
| 461 | - } |
|
| 462 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 463 | - // mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 464 | - // qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 465 | - // ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 466 | - // il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 467 | - |
|
| 468 | - // if (!in_array($cle, array('cle', 'valeur'))) |
|
| 469 | - // return; |
|
| 470 | - |
|
| 471 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 472 | - |
|
| 473 | - $filtre = ''; |
|
| 474 | - |
|
| 475 | - if ('REGEXP' == $op) { |
|
| 476 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', (string) $valeur) . ')'; |
|
| 477 | - $op = ''; |
|
| 478 | - } else { |
|
| 479 | - if ('LIKE' == $op) { |
|
| 480 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote((string) $valeur)); |
|
| 481 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 482 | - $op = ''; |
|
| 483 | - } else { |
|
| 484 | - if ('=' == $op) { |
|
| 485 | - $op = '=='; |
|
| 486 | - } else { |
|
| 487 | - if ('IN' == $op) { |
|
| 488 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 489 | - $op = ''; |
|
| 490 | - } else { |
|
| 491 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 492 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 493 | - $op = ''; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - if ($op) { |
|
| 501 | - $filtre = $a . $op . str_replace('\"', '"', (string) $valeur); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - if ($not) { |
|
| 505 | - $filtre = "!({$filtre})"; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - return $filtre; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - // calcule les elements a retournes par fetch() |
|
| 512 | - // enleve les elements inutiles du select() |
|
| 513 | - // |
|
| 514 | - private function calculer_select() { |
|
| 515 | - if ($select = &$this->command['select']) { |
|
| 516 | - foreach ($select as $s) { |
|
| 517 | - // /!\ $s = '.nom' |
|
| 518 | - if ('.' == $s[0]) { |
|
| 519 | - $s = substr((string) $s, 1); |
|
| 520 | - } |
|
| 521 | - $this->select[] = $s; |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - private function calculer_filtres() { |
|
| 527 | - // Issu de calculer_select() de public/composer L.519 |
|
| 528 | - // TODO: externaliser... |
|
| 529 | - // |
|
| 530 | - // retirer les criteres vides: |
|
| 531 | - // {X ?} avec X absent de l'URL |
|
| 532 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 533 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 534 | - if ($where = &$this->command['where']) { |
|
| 535 | - foreach ($where as $k => $v) { |
|
| 536 | - $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // critere {2,7} |
|
| 541 | - if (isset($this->command['limit']) && $this->command['limit']) { |
|
| 542 | - $limit = explode(',', (string) $this->command['limit']); |
|
| 543 | - $this->offset = $limit[0]; |
|
| 544 | - $this->limit = $limit[1]; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // Creer la fonction de filtrage sur $this |
|
| 548 | - if ($this->filtre) { |
|
| 549 | - if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 550 | - $filtres = 'return ' . $filtres . ';'; |
|
| 551 | - $this->func_filtre = fn () => eval($filtres); |
|
| 552 | - } else { |
|
| 553 | - $this->func_filtre = null; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /* |
|
| 148 | + // cle et valeur par defaut |
|
| 149 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 150 | + if ( |
|
| 151 | + in_array($nom, ['cle', 'valeur']) |
|
| 152 | + && method_exists($this, $nom) |
|
| 153 | + ) { |
|
| 154 | + return $this->{$nom}(); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Par defaut chercher en xpath dans la valeur() |
|
| 158 | + return table_valeur($this->valeur(), $nom, null); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + public function next(): void { |
|
| 162 | + ++$this->pos; |
|
| 163 | + parent::next(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * revient au depart. |
|
| 168 | + */ |
|
| 169 | + public function rewind(): void { |
|
| 170 | + $this->pos = 0; |
|
| 171 | + $this->fetched = 0; |
|
| 172 | + parent::rewind(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * aller a la position absolue n, |
|
| 177 | + * comptee depuis le debut. |
|
| 178 | + * |
|
| 179 | + * @param int $n |
|
| 180 | + * absolute pos |
|
| 181 | + * @param string $continue |
|
| 182 | + * param for sql_ api |
|
| 183 | + * |
|
| 184 | + * @return bool |
|
| 185 | + * success or fail if not implemented |
|
| 186 | + */ |
|
| 187 | + public function seek($n = 0, $continue = null) { |
|
| 188 | + if ($this->func_filtre || !method_exists($this->iter, 'seek') || !$this->iter->seek($n)) { |
|
| 189 | + $this->seek_loop($n); |
|
| 190 | + } |
|
| 191 | + $this->pos = $n; |
|
| 192 | + $this->fetched = $n; |
|
| 193 | + |
|
| 194 | + return true; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Avancer de $saut pas. |
|
| 199 | + * |
|
| 200 | + * @param int $saut |
|
| 201 | + * @param int|null $max |
|
| 202 | + * |
|
| 203 | + * @return int |
|
| 204 | + */ |
|
| 205 | + public function skip($saut, $max = null) { |
|
| 206 | + // pas de saut en arriere autorise pour cette fonction |
|
| 207 | + if (($saut = (int) $saut) <= 0) { |
|
| 208 | + return $this->pos; |
|
| 209 | + } |
|
| 210 | + $seek = $this->pos + $saut; |
|
| 211 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 212 | + // et on sort |
|
| 213 | + if (is_null($max)) { |
|
| 214 | + $max = $this->count(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + if ($seek >= $max || $seek >= $this->count()) { |
|
| 218 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 219 | + $this->free(); |
|
| 220 | + |
|
| 221 | + return $max; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $this->seek($seek); |
|
| 225 | + |
|
| 226 | + return $this->pos; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Renvoyer un tableau des donnees correspondantes |
|
| 231 | + * a la position courante de l'iterateur |
|
| 232 | + * en controlant si on respecte le filtre |
|
| 233 | + * Appliquer aussi le critere {offset,limit}. |
|
| 234 | + * |
|
| 235 | + * @return array|bool |
|
| 236 | + */ |
|
| 237 | + public function fetch() { |
|
| 238 | + if (method_exists($this->iter, 'fetch')) { |
|
| 239 | + return $this->iter->fetch(); |
|
| 240 | + } |
|
| 241 | + while ( |
|
| 242 | + $this->valid() |
|
| 243 | + && (!$this->accept() || $this->offset !== null && $this->fetched++ < $this->offset) |
|
| 244 | + ) { |
|
| 245 | + $this->next(); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + if (!$this->valid()) { |
|
| 249 | + return false; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + if ( |
|
| 253 | + $this->limit !== null |
|
| 254 | + && $this->fetched > $this->offset + $this->limit |
|
| 255 | + ) { |
|
| 256 | + return false; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $r = []; |
|
| 260 | + foreach ($this->select as $nom) { |
|
| 261 | + $r[$nom] = $this->get_select($nom); |
|
| 262 | + } |
|
| 263 | + $this->next(); |
|
| 264 | + |
|
| 265 | + return $r; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + // retourner la cle pour #CLE |
|
| 269 | + public function cle() { |
|
| 270 | + return $this->key(); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // retourner la valeur pour #VALEUR |
|
| 274 | + public function valeur() { |
|
| 275 | + return $this->current(); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Accepte-t-on l'entree courante lue ? |
|
| 280 | + * On execute les filtres pour le savoir. |
|
| 281 | + */ |
|
| 282 | + public function accept(): bool { |
|
| 283 | + if ($f = $this->func_filtre) { |
|
| 284 | + return $f(); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return true; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * liberer la ressource. |
|
| 292 | + * |
|
| 293 | + * @return bool |
|
| 294 | + */ |
|
| 295 | + public function free() { |
|
| 296 | + if (method_exists($this->iter, 'free')) { |
|
| 297 | + $this->iter->free(); |
|
| 298 | + } |
|
| 299 | + $this->pos = $this->total = 0; |
|
| 300 | + |
|
| 301 | + return true; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Compter le nombre total de resultats |
|
| 306 | + * pour #TOTAL_BOUCLE. |
|
| 307 | + * |
|
| 308 | + * @return int |
|
| 309 | + */ |
|
| 310 | + public function count() { |
|
| 311 | + if (is_null($this->total)) { |
|
| 312 | + if ( |
|
| 313 | + method_exists($this->iter, 'count') |
|
| 314 | + && !$this->func_filtre |
|
| 315 | + ) { |
|
| 316 | + return $this->total = $this->iter->count(); |
|
| 317 | + } |
|
| 318 | + // compter les lignes et rembobiner |
|
| 319 | + $total = 0; |
|
| 320 | + $pos = $this->pos; // sauver la position |
|
| 321 | + $this->rewind(); |
|
| 322 | + while ($this->fetch() && $total < $this->max) { |
|
| 323 | + ++$total; |
|
| 324 | + } |
|
| 325 | + $this->seek($pos); |
|
| 326 | + $this->total = $total; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return $this->total; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 334 | + * les filtres vides ou null sont ignores. |
|
| 335 | + * |
|
| 336 | + * @param array $filtres |
|
| 337 | + * @param string $operateur |
|
| 338 | + * |
|
| 339 | + * @return null|string |
|
| 340 | + */ |
|
| 341 | + protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 342 | + $filtres_string = []; |
|
| 343 | + foreach ($filtres as $k => $v) { |
|
| 344 | + // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 345 | + if (is_array($v) && in_array(reset($v), ['OR', 'AND'])) { |
|
| 346 | + $op = array_shift($v); |
|
| 347 | + $v = $this->assembler_filtres($v, $op); |
|
| 348 | + } |
|
| 349 | + if (is_null($v) || !is_string($v) || empty($v)) { |
|
| 350 | + continue; |
|
| 351 | + } |
|
| 352 | + $filtres_string[] = $v; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if ($filtres_string === []) { |
|
| 356 | + return null; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + return '(' . implode(") {$operateur} (", $filtres_string) . ')'; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Traduire un element du tableau where SQL en un filtre. |
|
| 364 | + * |
|
| 365 | + * @param array|string $v |
|
| 366 | + * |
|
| 367 | + * @return null|array|string |
|
| 368 | + */ |
|
| 369 | + protected function traduire_condition_sql_en_filtre($v) { |
|
| 370 | + if (is_array($v)) { |
|
| 371 | + if ((count($v) >= 2) && ('REGEXP' == $v[0]) && ("'.*'" == $v[2])) { |
|
| 372 | + return 'true'; |
|
| 373 | + } |
|
| 374 | + if ((count($v) >= 2) && ('LIKE' == $v[0]) && ("'%'" == $v[2])) { |
|
| 375 | + return 'true'; |
|
| 376 | + } |
|
| 377 | + $op = $v[0] ?: $v; |
|
| 378 | + } else { |
|
| 379 | + $op = $v; |
|
| 380 | + } |
|
| 381 | + if (!$op || 1 == $op || '0=0' == $op) { |
|
| 382 | + return 'true'; |
|
| 383 | + } |
|
| 384 | + if ('0=1' === $op) { |
|
| 385 | + return 'false'; |
|
| 386 | + } |
|
| 387 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 388 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', (string) $op, $regs)) { |
|
| 389 | + return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + // 3 possibilites : count($v) = |
|
| 393 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 394 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 395 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 396 | + |
|
| 397 | + // 1 : forcement traite par un critere, on passe |
|
| 398 | + if (!$v || !is_array($v) || 1 == count($v)) { |
|
| 399 | + return null; // sera ignore |
|
| 400 | + } |
|
| 401 | + if (2 == count($v) && is_array($v[1])) { |
|
| 402 | + return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 403 | + } |
|
| 404 | + if (3 == count($v)) { |
|
| 405 | + // traiter le OR/AND suivi de 2 valeurs |
|
| 406 | + if (in_array($op, ['OR', 'AND'])) { |
|
| 407 | + array_shift($v); |
|
| 408 | + foreach (array_keys($v) as $k) { |
|
| 409 | + $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 410 | + if (null === $v[$k]) { |
|
| 411 | + unset($v[$k]); |
|
| 412 | + } elseif ('true' === $v[$k]) { |
|
| 413 | + if ('OR' === $op) { |
|
| 414 | + return 'true'; |
|
| 415 | + } |
|
| 416 | + if ('AND' === $op) { |
|
| 417 | + unset($v[$k]); |
|
| 418 | + } |
|
| 419 | + } elseif ('false' === $v[$k]) { |
|
| 420 | + if ('OR' === $op) { |
|
| 421 | + unset($v[$k]); |
|
| 422 | + } |
|
| 423 | + if ('AND' === $op) { |
|
| 424 | + return 'false'; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + if ($v === []) { |
|
| 429 | + return null; |
|
| 430 | + } |
|
| 431 | + if (1 === count($v)) { |
|
| 432 | + return reset($v); |
|
| 433 | + } |
|
| 434 | + array_unshift($v, $op); |
|
| 435 | + |
|
| 436 | + return $v; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return null; // sera ignore |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Calculer un filtre sur un champ du tableau. |
|
| 447 | + * |
|
| 448 | + * @param string $cle |
|
| 449 | + * @param string $op |
|
| 450 | + * @param string $valeur |
|
| 451 | + * @param bool $not |
|
| 452 | + * |
|
| 453 | + * @return null|string |
|
| 454 | + */ |
|
| 455 | + protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 456 | + if ( |
|
| 457 | + method_exists($this->iter, 'exception_des_criteres') |
|
| 458 | + && in_array($cle, $this->iter->exception_des_criteres()) |
|
| 459 | + ) { |
|
| 460 | + return null; |
|
| 461 | + } |
|
| 462 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 463 | + // mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 464 | + // qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 465 | + // ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 466 | + // il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 467 | + |
|
| 468 | + // if (!in_array($cle, array('cle', 'valeur'))) |
|
| 469 | + // return; |
|
| 470 | + |
|
| 471 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 472 | + |
|
| 473 | + $filtre = ''; |
|
| 474 | + |
|
| 475 | + if ('REGEXP' == $op) { |
|
| 476 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', (string) $valeur) . ')'; |
|
| 477 | + $op = ''; |
|
| 478 | + } else { |
|
| 479 | + if ('LIKE' == $op) { |
|
| 480 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote((string) $valeur)); |
|
| 481 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 482 | + $op = ''; |
|
| 483 | + } else { |
|
| 484 | + if ('=' == $op) { |
|
| 485 | + $op = '=='; |
|
| 486 | + } else { |
|
| 487 | + if ('IN' == $op) { |
|
| 488 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 489 | + $op = ''; |
|
| 490 | + } else { |
|
| 491 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 492 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 493 | + $op = ''; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + if ($op) { |
|
| 501 | + $filtre = $a . $op . str_replace('\"', '"', (string) $valeur); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + if ($not) { |
|
| 505 | + $filtre = "!({$filtre})"; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + return $filtre; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + // calcule les elements a retournes par fetch() |
|
| 512 | + // enleve les elements inutiles du select() |
|
| 513 | + // |
|
| 514 | + private function calculer_select() { |
|
| 515 | + if ($select = &$this->command['select']) { |
|
| 516 | + foreach ($select as $s) { |
|
| 517 | + // /!\ $s = '.nom' |
|
| 518 | + if ('.' == $s[0]) { |
|
| 519 | + $s = substr((string) $s, 1); |
|
| 520 | + } |
|
| 521 | + $this->select[] = $s; |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + private function calculer_filtres() { |
|
| 527 | + // Issu de calculer_select() de public/composer L.519 |
|
| 528 | + // TODO: externaliser... |
|
| 529 | + // |
|
| 530 | + // retirer les criteres vides: |
|
| 531 | + // {X ?} avec X absent de l'URL |
|
| 532 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 533 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 534 | + if ($where = &$this->command['where']) { |
|
| 535 | + foreach ($where as $k => $v) { |
|
| 536 | + $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // critere {2,7} |
|
| 541 | + if (isset($this->command['limit']) && $this->command['limit']) { |
|
| 542 | + $limit = explode(',', (string) $this->command['limit']); |
|
| 543 | + $this->offset = $limit[0]; |
|
| 544 | + $this->limit = $limit[1]; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // Creer la fonction de filtrage sur $this |
|
| 548 | + if ($this->filtre) { |
|
| 549 | + if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 550 | + $filtres = 'return ' . $filtres . ';'; |
|
| 551 | + $this->func_filtre = fn () => eval($filtres); |
|
| 552 | + } else { |
|
| 553 | + $this->func_filtre = null; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + /* |
|
| 559 | 559 | * aller a la position $n en parcourant |
| 560 | 560 | * un par un tous les elements |
| 561 | 561 | */ |
| 562 | - private function seek_loop($n) { |
|
| 563 | - if ($this->pos > $n) { |
|
| 564 | - $this->rewind(); |
|
| 565 | - } |
|
| 562 | + private function seek_loop($n) { |
|
| 563 | + if ($this->pos > $n) { |
|
| 564 | + $this->rewind(); |
|
| 565 | + } |
|
| 566 | 566 | |
| 567 | - while ($this->pos < $n && $this->valid()) { |
|
| 568 | - $this->next(); |
|
| 569 | - } |
|
| 567 | + while ($this->pos < $n && $this->valid()) { |
|
| 568 | + $this->next(); |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - return true; |
|
| 572 | - } |
|
| 571 | + return true; |
|
| 572 | + } |
|
| 573 | 573 | } |
@@ -12,6 +12,6 @@ |
||
| 12 | 12 | * @return string Le SHA de la chaîne |
| 13 | 13 | */ |
| 14 | 14 | function spip_sha256($str) { |
| 15 | - trigger_deprecation('spip', '5.0', 'Using "%s" is deprecated, use "%s" instead.', 'spip_sha256($str)', 'hash(\'sha256\', $str)'); |
|
| 16 | - return hash('sha256', $str); |
|
| 15 | + trigger_deprecation('spip', '5.0', 'Using "%s" is deprecated, use "%s" instead.', 'spip_sha256($str)', 'hash(\'sha256\', $str)'); |
|
| 16 | + return hash('sha256', $str); |
|
| 17 | 17 | } |